/* * Copyright (c) ICG. All rights reserved. * See copyright.txt for more information. * * Institute for Computer Graphics and Vision * Graz, University of Technology / Austria * * * This software is distributed WITHOUT ANY WARRANTY; without even * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the above copyright notices for more information. * * * Project : MIPItkProjects * Module : CommonItkUtilities * Class : $RCSfile: commonItkTypedefs.h,v $ * Language : C++ * Description : * * Author : Martin Urschler * EMail : urschler@icg.tu-graz.ac.at * Date : $Date: 2007-04-24 11:31:16 $ * Version : $Revision: 1.31 $ * Full Id : $Id: commonItkTypedefs.h,v 1.31 2007-04-24 11:31:16 urschler Exp $ * */ #ifndef __COMMON_ITK_TYPEDEFS__ #define __COMMON_ITK_TYPEDEFS__ #include #ifdef VCL_WIN32 #pragma warning(disable:4786) #endif // include files #include "itkImage.h" #include "itkVector.h" #include "itkMesh.h" #include "itkTriangleCell.h" // a template that checks if two types are convertible to each other // or if they are equal #if defined(VCL_WIN32) && (defined(VCL_VC_6) || defined(VCL_VC_7)) template struct SameType { private: template struct In { enum { value = false }; }; template<> struct In { enum { value = true }; }; public: enum { value = In::value }; }; #else template struct SameType { enum { value = false }; }; template struct SameType { enum { value = true }; }; #endif template struct Int2Type { enum { value = v }; }; // typedefs #define _BSPLINE_ORDER_ 3 // ----------------------------- floating point images ------------------------------------------------------- typedef float FloatPixelType; typedef itk::Image< FloatPixelType, 2 > FloatImageType2D; typedef itk::Image< FloatPixelType, 3 > FloatImageType3D; // default is 3D! typedef FloatImageType3D FloatImageType; typedef double DoublePixelType; typedef itk::Image< DoublePixelType, 2 > DoubleImageType2D; typedef itk::Image< DoublePixelType, 3 > DoubleImageType3D; // default is 3D! typedef DoubleImageType3D DoubleImageType; // ----------------------------- integer valued images ------------------------------------------------------- typedef signed short Int16PixelType; typedef itk::Image< Int16PixelType, 2 > Int16ImageType2D; typedef itk::Image< Int16PixelType, 3 > Int16ImageType3D; // default is 3D! typedef Int16ImageType3D Int16ImageType; typedef unsigned short UInt16PixelType; typedef itk::Image< UInt16PixelType, 2 > UInt16ImageType2D; typedef itk::Image< UInt16PixelType, 3 > UInt16ImageType3D; // default is 3D! typedef UInt16ImageType3D UInt16ImageType; typedef unsigned char MaskPixelType; typedef itk::Image< MaskPixelType, 2 > MaskImageType2D; typedef itk::Image< MaskPixelType, 3 > MaskImageType3D; // default is 3D! typedef MaskImageType3D MaskImageType; typedef MaskImageType UInt8ImageType; typedef MaskImageType2D UInt8ImageType2D; //class MIPItkProjectsConstants //{ //public: // inline static signed short resampleDefaultValue() // { // return -1100; // } //}; typedef itk::Vector< float, 2 > VectorPixelType2D; typedef itk::Vector< float, 3 > VectorPixelType3D; // default is 3D! typedef VectorPixelType3D VectorPixelType; typedef itk::Image< VectorPixelType2D, 2 > DeformationFieldType2D; typedef itk::Image< VectorPixelType3D, 3 > DeformationFieldType3D; // default is 3D! typedef DeformationFieldType3D DeformationFieldType; template class VectorPixelConstants { public: inline static itk::Vector< TRealType, Dimension > zero() { itk::Vector< TRealType, Dimension > zero; for (unsigned int dim=0; dim::Zero; return zero; } inline static itk::Vector< TRealType, Dimension > undefined() { itk::Vector< TRealType, Dimension > undefined; for (unsigned int dim=0; dim::max(); return undefined; } }; typedef itk::Mesh MeshType; typedef MeshType::CellType CellType; typedef MeshType::PointsContainer PointsContainer; typedef itk::TriangleCell TriangleType; typedef itk::PointSet< UInt16PixelType, 2 > PointSetType2D; typedef itk::PointSet< UInt16PixelType, 3 > PointSetType3D; // default is 3D! typedef PointSetType3D PointSetType; // taken from mlmath.hpp #ifndef __MLMATH_HPP__ // our rounding strategy is "round-half-up", we round half values x.5 always // to the larger value independent of its sign (ex: 1.5 -> 2; -1.5 -> 1) /// Round a double number to specified datatype template inline C ROUND_DBL( double d ) { // complicated expression is to make sure that -x.5 is rounded to -x // not to -(x+1) like is the case with 'static_cast(d-0.5)' return (d >= 0.0) ? static_cast(d+0.5) : static_cast( d - (static_cast(d)-1) + 0.5 ) + (static_cast(d)-1); } /// Round a float number to specified datatype template inline C ROUND_FLT( float d ) { // complicated expression is to make sure that -x.5 is rounded to -x // not to -(x+1) like is the case with 'static_cast(d-0.5)' return (d >= 0.0) ? static_cast(d+0.5f) : static_cast( d - (static_cast(d)-1) + 0.5f ) + (static_cast(d)-1); } #endif // __MLMATH_HPP__ // some macros #define ITK_EXCEPTION_CHECKED( message, arg, return_value ) \ try \ { \ if (message != std::string("")) \ std::cout << message << std::endl; \ arg; \ } \ catch( itk::MemoryAllocationError& err ) \ { \ std::cout << "ITK Memory Allocation Error caught!" << std::endl; \ std::cout << err << std::endl; \ return return_value; \ } \ catch( itk::ExceptionObject& err ) \ { \ std::cout << "ITK Exception Object caught!" << std::endl; \ std::cout << err << std::endl; \ return return_value; \ } #define ITK_EXCEPTION_CHECKED_NO_RETURN_VAL( message, arg ) \ try \ { \ if (message != std::string("")) \ std::cout << message << std::endl; \ arg; \ } \ catch( itk::MemoryAllocationError& err ) \ { \ std::cout << "ITK Memory Allocation Error caught!" << std::endl; \ std::cout << err << std::endl; \ return; \ } \ catch( itk::ExceptionObject& err ) \ { \ std::cout << "ITK Exception Object caught!" << std::endl; \ std::cout << err << std::endl; \ return; \ } #define ITK_IMAGE_ALLOCATE_MACRO( NewImageType, newImage, \ PrototypeImageType, prototypeImage ) \ NewImageType::Pointer newImage = NewImageType::New(); \ newImage->SetLargestPossibleRegion( \ prototypeImage->GetLargestPossibleRegion() ); \ newImage->SetRequestedRegion( \ prototypeImage->GetRequestedRegion() ); \ newImage->SetBufferedRegion( \ prototypeImage->GetBufferedRegion() ); \ newImage->SetSpacing( prototypeImage->GetSpacing() ); \ newImage->SetOrigin( prototypeImage->GetOrigin() ); \ newImage->SetDirection( prototypeImage->GetDirection() ); \ newImage->Allocate(); #define ITK_IMAGE_ALLOCATE_MACRO_TN( NewImageType, newImage, \ PrototypeImageType, prototypeImage ) \ typename NewImageType::Pointer newImage = NewImageType::New(); \ newImage->SetLargestPossibleRegion( \ prototypeImage->GetLargestPossibleRegion() ); \ newImage->SetRequestedRegion( \ prototypeImage->GetRequestedRegion() ); \ newImage->SetBufferedRegion( \ prototypeImage->GetBufferedRegion() ); \ newImage->SetSpacing( prototypeImage->GetSpacing() ); \ newImage->SetOrigin( prototypeImage->GetOrigin() ); \ newImage->SetDirection( prototypeImage->GetDirection() ); \ newImage->Allocate(); #define ITK_IMAGE_COPY_MACRO( SourceImageType, src, TargetImageType, target ) \ { \ typedef itk::ImageRegionConstIterator< SourceImageType > SourceIteratorType;\ SourceIteratorType srcIter = SourceIteratorType( src, \ src->GetLargestPossibleRegion() ); \ typedef itk::ImageRegionIterator< TargetImageType > TargetIteratorType;\ TargetIteratorType targetIter = TargetIteratorType( target, \ target->GetLargestPossibleRegion() ); \ for ( srcIter.GoToBegin(), targetIter.GoToBegin(); \ !srcIter.IsAtEnd(); \ ++srcIter, ++targetIter ) \ { \ targetIter.Set( \ static_cast(srcIter.Get()) ); \ } \ } #define ITK_IMAGE_COPY_MACRO_TN( SourceImageType, src, TargetImageType, target ) \ { \ typedef itk::ImageRegionConstIterator< SourceImageType > SourceIteratorType;\ SourceIteratorType srcIter = SourceIteratorType( src, \ src->GetLargestPossibleRegion() ); \ typedef itk::ImageRegionIterator< TargetImageType > TargetIteratorType;\ TargetIteratorType targetIter = TargetIteratorType( target, \ target->GetLargestPossibleRegion() ); \ for ( srcIter.GoToBegin(), targetIter.GoToBegin(); \ !srcIter.IsAtEnd(); \ ++srcIter, ++targetIter ) \ { \ targetIter.Set( \ static_cast(srcIter.Get()) ); \ } \ } #endif // __COMMON_ITK_TYPEDEFS__