00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkIpPic.h"
00020 #include "mitkPixelType.h"
00021 #include <itkVector.h>
00022 #include <itkRGBPixel.h>
00023 #include <itkRGBAPixel.h>
00024 #include <itkCovariantVector.h>
00025 #include "itkDiffusionTensor3D.h"
00026
00027 #define HUNDRED_VECS(HUN) \
00028 TEN_VECS(HUN) \
00029 TEN_VECS(HUN+10) \
00030 TEN_VECS(HUN+20) \
00031 TEN_VECS(HUN+30) \
00032 TEN_VECS(HUN+40) \
00033 TEN_VECS(HUN+50) \
00034 TEN_VECS(HUN+60) \
00035 TEN_VECS(HUN+70) \
00036 TEN_VECS(HUN+80) \
00037 TEN_VECS(HUN+90) \
00038
00039 #define TEN_VECS(TEN) \
00040 if(false){} \
00041 N_VEC(TEN+ 1) \
00042 N_VEC(TEN+ 2) \
00043 N_VEC(TEN+ 3) \
00044 N_VEC(TEN+ 4) \
00045 N_VEC(TEN+ 5) \
00046 N_VEC(TEN+ 6) \
00047 N_VEC(TEN+ 7) \
00048 N_VEC(TEN+ 8) \
00049 N_VEC(TEN+ 9) \
00050 N_VEC(TEN+10) \
00051
00052 #define N_VEC(N_DIRS) \
00053 _N_VEC(N_DIRS,double) \
00054 _N_VEC(N_DIRS,float) \
00055
00056 #define _N_VEC(N_DIRS,PIXTYPE) \
00057 else if ( *m_TypeId == typeid( itk::Vector<PIXTYPE,N_DIRS> )) \
00058 { \
00059 found = true; \
00060 m_TypeId = & typeid( PIXTYPE ); \
00061 m_NumberOfComponents *= N_DIRS; \
00062 m_Type = mitkIpPicFloat; \
00063 m_Bpe = sizeof(PIXTYPE) * 8 * m_NumberOfComponents; \
00064 m_ItkTypeId = &typeid( itk::Vector<PIXTYPE,N_DIRS> ); \
00065 } \
00066
00067
00068 mitk::PixelType::PixelType() : m_TypeId( NULL ), m_Type( mitkIpPicUnknown ), m_Bpe( 0 ), m_NumberOfComponents( 1 )
00069 {
00070
00071 }
00072
00073 mitk::PixelType::PixelType( const mitk::PixelType& aPixelType )
00074 {
00075 Initialize( *aPixelType.GetTypeId(), aPixelType.GetNumberOfComponents() );
00076 }
00077
00078 mitk::PixelType::PixelType( const std::type_info& aTypeId, int numberOfComponents, ItkIOPixelType anItkIoPixelType ) : m_TypeId( &aTypeId ), m_NumberOfComponents( numberOfComponents )
00079 {
00080 Initialize( aTypeId, numberOfComponents, anItkIoPixelType );
00081 }
00082
00083 mitk::PixelType::PixelType( mitkIpPicType_t type, int bpe, int numberOfComponents ) : m_Type( type ), m_Bpe( bpe ), m_NumberOfComponents( numberOfComponents )
00084 {
00085 Initialize( type, bpe, numberOfComponents );
00086 }
00087
00088 mitk::PixelType::PixelType( const mitkIpPicDescriptor* pic ) : m_NumberOfComponents( 1 )
00089 {
00090 if ( pic != NULL )
00091 Initialize( pic->type, pic->bpe );
00092 else
00093 {
00094 m_TypeId = NULL;
00095
00096 }
00097 }
00098
00099 bool mitk::PixelType::operator==(const mitk::PixelType& rhs) const
00100 {
00101 MITK_INFO << "operator==" << std::endl;
00102
00103 MITK_INFO << "m_Type = " << m_Type << " " << rhs.m_Type << std::endl;
00104 MITK_INFO << "m_Bpe = " << m_Bpe << " " << rhs.m_Bpe << std::endl;
00105 MITK_INFO << "m_NumberOfComponents = " << m_NumberOfComponents << " " << rhs.m_NumberOfComponents << std::endl;
00106 MITK_INFO << "m_BitsPerComponent = " << m_BitsPerComponent << " " << rhs.m_BitsPerComponent << std::endl;
00107
00108 return (
00109 *(this->m_TypeId) == *(rhs.m_TypeId)
00110 && this->m_Type == rhs.m_Type
00111 && this->m_Bpe == rhs.m_Bpe
00112 && this->m_NumberOfComponents == rhs.m_NumberOfComponents
00113 && this->m_BitsPerComponent == rhs.m_BitsPerComponent
00114 );
00115 }
00116
00117 bool mitk::PixelType::operator!=(const mitk::PixelType& rhs) const
00118 {
00119 return !(this->operator==(rhs));
00120 }
00121
00122 bool mitk::PixelType::operator==(const std::type_info& typeId) const
00123 {
00124 if (GetItkTypeId() == NULL)
00125 return false;
00126 return (*GetItkTypeId() == typeId);
00127 }
00128
00129 bool mitk::PixelType::operator!=(const std::type_info& typeId) const
00130 {
00131 return !(this->operator==(typeId));
00132 }
00133
00134 #define SET_ITK_TYPE_ID(anItkIoPixelType_test, numberOfComponents_test, ITK_TYPE) \
00135 if ( (itk::ImageIOBase::anItkIoPixelType_test == anItkIoPixelType ) && \
00136 (numberOfComponents_test == m_NumberOfComponents) \
00137 ) \
00138 { \
00139 m_ItkTypeId = &typeid(ITK_TYPE); \
00140 }
00141
00142 #define SET_TYPE(TYPE, IPPIC_TYPE) \
00143 if ( *m_TypeId == typeid( TYPE ) ) \
00144 { \
00145 m_Type = IPPIC_TYPE; \
00146 m_Bpe = sizeof(TYPE) * 8 * m_NumberOfComponents; \
00147 \
00148 typedef itk::Vector<TYPE, 3> Vector3Type; \
00149 typedef itk::CovariantVector<TYPE, 3> CovariantVector3Type; \
00150 typedef itk::Point<TYPE, 3> Point3Type; \
00151 typedef itk::Vector<TYPE, 2> Vector2Type; \
00152 typedef itk::CovariantVector<TYPE, 2> CovariantVector2Type; \
00153 typedef itk::Point<TYPE, 2> Point2Type; \
00154 \
00155 SET_ITK_TYPE_ID(UNKNOWNPIXELTYPE, 1, TYPE ) else \
00156 SET_ITK_TYPE_ID(SCALAR, 1, TYPE ) else \
00157 \
00158 SET_ITK_TYPE_ID(VECTOR, 2, Vector2Type ) else \
00159 SET_ITK_TYPE_ID(COVARIANTVECTOR, 2, CovariantVector2Type ) else \
00160 SET_ITK_TYPE_ID(POINT, 2, Point2Type ) else \
00161 \
00162 SET_ITK_TYPE_ID(RGB, 3, itk::RGBPixel<TYPE> ) else \
00163 \
00164 SET_ITK_TYPE_ID(VECTOR, 3, Vector3Type ) else \
00165 SET_ITK_TYPE_ID(COVARIANTVECTOR, 3, CovariantVector3Type ) else \
00166 SET_ITK_TYPE_ID(POINT, 3, Point3Type ) else \
00167 \
00168 SET_ITK_TYPE_ID(RGBA, 4, itk::RGBAPixel<TYPE> ) else \
00169 { \
00170 } \
00171 } \
00172 else
00173
00174 void mitk::PixelType::Initialize( const std::type_info& aTypeId, int numberOfComponents, ItkIOPixelType anItkIoPixelType )
00175 {
00176 m_TypeId = &aTypeId;
00177 m_NumberOfComponents = numberOfComponents;
00178 if(m_NumberOfComponents == 1)
00179 m_ItkTypeId = &aTypeId;
00180 else
00181 m_ItkTypeId = NULL;
00182 SET_TYPE(double, mitkIpPicFloat)
00183 SET_TYPE(float, mitkIpPicFloat)
00184 SET_TYPE(long, mitkIpPicInt)
00185 SET_TYPE(unsigned long, mitkIpPicUInt)
00186 SET_TYPE(int, mitkIpPicInt)
00187 SET_TYPE(unsigned int, mitkIpPicUInt)
00188 SET_TYPE(short, mitkIpPicInt)
00189 SET_TYPE(unsigned short, mitkIpPicUInt)
00190 SET_TYPE(char, mitkIpPicInt)
00191 SET_TYPE(unsigned char, mitkIpPicUInt)
00192
00193
00194 if ( *m_TypeId == typeid( itk::DiffusionTensor3D<float> ) )
00195 {
00196 m_TypeId = & typeid( float );
00197 m_NumberOfComponents *= 6;
00198 m_Type = mitkIpPicFloat;
00199 m_Bpe = sizeof(float) * 8 * m_NumberOfComponents;
00200 m_ItkTypeId = &typeid( itk::DiffusionTensor3D<float> );
00201 }
00202 else if ( *m_TypeId == typeid( itk::DiffusionTensor3D<double> ) )
00203 {
00204 m_TypeId = & typeid( double );
00205 m_NumberOfComponents *= 6;
00206 m_Type = mitkIpPicFloat;
00207 m_Bpe = sizeof(double) * 8 * m_NumberOfComponents;
00208 m_ItkTypeId = &typeid( itk::DiffusionTensor3D<double> );
00209 }
00210 else if ( *m_TypeId == typeid( itk::RGBPixel<unsigned char> ) )
00211 {
00212 m_Type = mitkIpPicUInt;
00213 m_NumberOfComponents = 3;
00214 m_Bpe = sizeof(unsigned char) * 8 * m_NumberOfComponents;
00215 m_ItkTypeId = &typeid( itk::RGBPixel<unsigned char> );
00216 }
00217 else if ( *m_TypeId == typeid( itk::RGBAPixel<unsigned char> ) )
00218 {
00219 m_Type = mitkIpPicUInt;
00220 m_NumberOfComponents = 4;
00221 m_Bpe = sizeof(unsigned char) * 8 * m_NumberOfComponents;
00222 m_ItkTypeId = &typeid( itk::RGBAPixel<unsigned char> );
00223 }
00224 else
00225 {
00226 bool found = false;
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 if(false){}
00245 N_VEC(3)
00246 N_VEC(6)
00247 N_VEC(42)
00248 N_VEC(92)
00249 N_VEC(162)
00250 N_VEC(252)
00251 N_VEC(362)
00252 N_VEC(492)
00253 N_VEC(642)
00254 N_VEC(812)
00255 N_VEC(1002)
00256
00257 if(!found)
00258 itkExceptionMacro( "Pixel type currently not supported." );
00259 }
00260 m_BitsPerComponent = m_Bpe / m_NumberOfComponents;
00261 }
00262
00263 void mitk::PixelType::Initialize( mitkIpPicType_t type, int bpe, int numberOfComponents )
00264 {
00265 m_Type = type;
00266 m_Bpe = bpe;
00267 m_NumberOfComponents = numberOfComponents;
00268 switch ( type )
00269 {
00270 case mitkIpPicUnknown:
00271 m_TypeId = &typeid( void* );
00272 break;
00273 case mitkIpPicBool:
00274 m_TypeId = &typeid( bool );
00275 m_Bpe = sizeof(bool) * 8 * numberOfComponents;
00276 break;
00277 case mitkIpPicASCII:
00278 m_TypeId = &typeid( char );
00279 m_Bpe = sizeof(char) * 8 * numberOfComponents;
00280 break;
00281 case mitkIpPicInt:
00282 switch ( bpe / numberOfComponents )
00283 {
00284 case 8:
00285 m_TypeId = &typeid( char );
00286 break;
00287 case 16:
00288 m_TypeId = &typeid( short );
00289 break;
00290 case 32:
00291 m_TypeId = &typeid( int );
00292 break;
00293 case 64:
00294 m_TypeId = &typeid( long );
00295 break;
00296 default:
00297 m_TypeId = NULL;
00298 itkExceptionMacro( "Pixel type currently not supported." );
00299 }
00300 break;
00301 case mitkIpPicUInt:
00302 switch ( bpe / numberOfComponents )
00303 {
00304 case 8:
00305 m_TypeId = &typeid( unsigned char );
00306 break;
00307 case 16:
00308 m_TypeId = &typeid( unsigned short );
00309 break;
00310 case 24:
00311 m_TypeId = &typeid( unsigned char );
00312 m_NumberOfComponents = numberOfComponents = 3;
00313 break;
00314 case 32:
00315 m_TypeId = &typeid( unsigned int );
00316 break;
00317 case 64:
00318 m_TypeId = &typeid( unsigned long );
00319 break;
00320 default:
00321 m_TypeId = NULL;
00322 itkExceptionMacro( "Pixel type currently not supported." );
00323 }
00324 break;
00325 case mitkIpPicFloat:
00326 switch ( bpe / numberOfComponents )
00327 {
00328 case 32:
00329 m_TypeId = &typeid( float );
00330 break;
00331 case 64:
00332 m_TypeId = &typeid( double );
00333 break;
00334 default:
00335 m_TypeId = NULL;
00336 itkExceptionMacro( "Pixel type currently not supported." );
00337 }
00338 break;
00339 case mitkIpPicNonUniform:
00340 m_TypeId = &typeid( void* );
00341 break;
00342 case mitkIpPicTSV:
00343 m_TypeId = &typeid( void* );
00344 break;
00345 default:
00346 m_TypeId = NULL;
00347 itkExceptionMacro( "Pixel type currently not supported." );
00348 break;
00349 }
00350 m_BitsPerComponent = m_Bpe / numberOfComponents;
00351
00352 if(m_NumberOfComponents == 1)
00353 m_ItkTypeId = m_TypeId;
00354 else
00355 m_ItkTypeId = NULL;
00356 }
00357
00358 std::string mitk::PixelType::GetItkTypeAsString() const
00359 {
00360 if (GetItkTypeId()==NULL)
00361 {
00362 return "unknown";
00363 }
00364 else
00365 {
00366 return GetItkTypeId()->name();
00367 }
00368 }