18 #pragma warning ( disable : 4786 )
37 m_ComponentType(UNKNOWNCOMPONENTTYPE),
38 m_ByteOrder(OrderNotApplicable),
39 m_FileType(TypeNotApplicable),
40 m_NumberOfDimensions(0)
56 m_NumberOfDimensions = 0;
89 const unsigned int* dimensions)
92 if (dimensions !=
NULL)
106 itkWarningMacro(
"Index: " << i <<
107 " is out of bounds, expected maximum is " <<
109 itkExceptionMacro(
"Index: " << i <<
110 " is out of bounds, expected maximum is " <<
121 itkWarningMacro(
"Index: " << i <<
122 " is out of bounds, expected maximum is " <<
124 itkExceptionMacro(
"Index: " << i <<
125 " is out of bounds, expected maximum is " <<
136 itkWarningMacro(
"Index: " << i <<
137 " is out of bounds, expected maximum is " <<
139 itkExceptionMacro(
"Index: " << i <<
140 " is out of bounds, expected maximum is " <<
151 itkWarningMacro(
"Index: " << i <<
152 " is out of bounds, expected maximum is " <<
154 itkExceptionMacro(
"Index: " << i <<
155 " is out of bounds, expected maximum is " <<
166 itkWarningMacro(
"Index: " << i <<
167 " is out of bounds, expected maximum is " <<
169 itkExceptionMacro(
"Index: " << i <<
170 " is out of bounds, expected maximum is " <<
174 std::vector<double> v;
176 for (
unsigned int j=0; j < v.size(); j++)
188 return typeid(
unsigned char);
192 return typeid(
unsigned short);
194 return typeid(short);
196 return typeid(
unsigned int);
200 return typeid(
unsigned long);
204 return typeid(float);
206 return typeid(double);
208 return typeid(std::complex<short>);
210 return typeid(std::complex<int>);
212 return typeid(std::complex<float>);
214 return typeid(std::complex<double>);
226 template <
typename T>
229 const std::type_info &ptype,
231 T itkNotUsed( dummy ) )
233 if( ptype ==
typeid(T) )
429 template <
typename T>
432 const std::type_info &ptype,
434 std::complex<T> itkNotUsed( dummy ) )
440 if (ptype ==
typeid(std::complex<short>))
442 std::cout <<
"complex short detected" << std::endl;
448 if (ptype ==
typeid(std::complex<int>))
456 if (ptype ==
typeid(std::complex<float>))
464 if (ptype ==
typeid(std::complex<double>))
522 itkExceptionMacro(
"Pixel type currently not supported. typeid.name = " << ptype.name() );
528 itkExceptionMacro(
"Pixel Component type currently not supported. typeid.name = " << ptype.name() );
560 for (i = 0; i < m_NumberOfDimensions; i++)
562 numPixels *= m_Dimensions[i];
572 return (this->GetImageSizeInPixels() * m_NumberOfComponents);
579 return (this->GetImageSizeInComponents() * this->GetComponentSize());
621 std::vector<double> axis( dim );
622 for (
unsigned int i=0; i<dim; i++)
624 for (
unsigned int j=0; j < dim; j++)
648 const std::streamsize numberOfBytesToBeRead = Math::CastWithRangeCheck< std::streamsize>( num );
650 is.read( static_cast<char *>( buffer ), numberOfBytesToBeRead );
652 const std::streamsize numberOfBytesRead = is.gcount();
656 if ( numberOfBytesRead != numberOfBytesToBeRead )
658 if ( ( numberOfBytesRead != numberOfBytesToBeRead ) || is.fail() )
674 itkExceptionMacro (
"Unknown pixel or component type: ("
688 return sizeof(
unsigned char);
692 return sizeof(
unsigned short);
694 return sizeof(short);
696 return sizeof(
unsigned int);
700 return sizeof(
unsigned long);
704 return sizeof(float);
706 return sizeof(double);
708 return sizeof(std::complex<short>);
710 return sizeof(std::complex<int>);
712 return sizeof(std::complex<float>);
714 return sizeof(std::complex<double>);
734 return s =
"TypeNotApplicable";
736 return s=
"TypeNotApplicable";
745 return s =
"BigEndian";
747 return s =
"LittleEndian";
750 return s =
"OrderNotApplicable";
752 return s=
"OrderNotApplicable";
761 return (s =
"unsigned_char");
765 return (s =
"unsigned_short");
767 return (s =
"short");
769 return (s =
"unsigned_int");
773 return (s =
"unsigned_long");
777 return (s =
"float");
779 return (s =
"double");
781 return (s =
"complex_short");
783 return (s =
"complex_int");
785 return (s =
"complex_float");
787 return (s =
"complex_double");
790 return (s =
"unknown");
792 return (s=
"unknown");
802 return (s =
"scalar");
804 return (s =
"vector");
806 return (s =
"covariant_vector");
808 return (s =
"point");
810 return (s =
"offset");
816 return (s =
"symmetric_second_rank_tensor");
818 return (s =
"diffusion_tensor_3D");
820 return (s =
"complex");
823 itkExceptionMacro (
"Unknown pixel type: " << t);
825 return (s=
"unknown");
830 template <
class TComponent>
833 const TComponent *ptr = buffer;
834 typedef typename itk::NumericTraits<TComponent>::PrintType PrintType;
839 os << PrintType(*ptr++) <<
" ";
851 typedef const unsigned char * Type;
852 Type buf =
reinterpret_cast<Type
>(buffer);
853 WriteBuffer(os, buf, numComp);
858 typedef const char * Type;
859 Type buf =
reinterpret_cast<Type
>(buffer);
860 WriteBuffer(os, buf, numComp);
866 typedef const unsigned short * Type;
867 Type buf =
reinterpret_cast<Type
>(buffer);
868 WriteBuffer(os, buf, numComp);
874 typedef const short * Type;
875 Type buf =
reinterpret_cast<Type
>(buffer);
876 WriteBuffer(os, buf, numComp);
882 typedef const unsigned int * Type;
883 Type buf =
reinterpret_cast<Type
>(buffer);
884 WriteBuffer(os, buf, numComp);
890 typedef const int * Type;
891 Type buf =
reinterpret_cast<Type
>(buffer);
892 WriteBuffer(os, buf, numComp);
898 typedef const unsigned long * Type;
899 Type buf =
reinterpret_cast<Type
>(buffer);
900 WriteBuffer(os, buf, numComp);
906 typedef const long * Type;
907 Type buf =
reinterpret_cast<Type
>(buffer);
908 WriteBuffer(os, buf, numComp);
914 typedef const float * Type;
915 Type buf =
reinterpret_cast<Type
>(buffer);
916 WriteBuffer(os, buf, numComp);
922 typedef const double * Type;
923 Type buf =
reinterpret_cast<Type
>(buffer);
924 WriteBuffer(os, buf, numComp);
930 typedef const std::complex<short> * Type;
931 Type buf =
reinterpret_cast<Type
>(buffer);
932 WriteBuffer(os, buf, numComp);
938 typedef const std::complex<int> * Type;
939 Type buf =
reinterpret_cast<Type
>(buffer);
940 WriteBuffer(os, buf, numComp);
946 typedef const std::complex<float> * Type;
947 Type buf =
reinterpret_cast<Type
>(buffer);
948 WriteBuffer(os, buf, numComp);
954 typedef const std::complex<double> * Type;
955 Type buf =
reinterpret_cast<Type
>(buffer);
956 WriteBuffer(os, buf, numComp);
967 template <
class TComponent>
971 typedef typename itk::NumericTraits<TComponent>::PrintType PrintType;
973 TComponent *ptr = buffer;
977 *ptr =
static_cast<TComponent
>( temp );
989 unsigned char *buf =
reinterpret_cast<unsigned char*
>(buffer);
995 char *buf =
reinterpret_cast<char*
>(buffer);
1002 unsigned short *buf =
reinterpret_cast<unsigned short*
>(buffer);
1009 short *buf =
reinterpret_cast<short*
>(buffer);
1016 unsigned int *buf =
reinterpret_cast<unsigned int*
>(buffer);
1023 int *buf =
reinterpret_cast<int*
>(buffer);
1030 unsigned long *buf =
reinterpret_cast<unsigned long*
>(buffer);
1037 long *buf =
reinterpret_cast<long*
>(buffer);
1044 float *buf =
reinterpret_cast<float*
>(buffer);
1051 double *buf =
reinterpret_cast<double*
>(buffer);
1058 std::complex<short> *buf =
reinterpret_cast<std::complex<short>*
>(buffer);
1065 std::complex<int> *buf =
reinterpret_cast<std::complex<int>*
>(buffer);
1072 std::complex<float> *buf =
reinterpret_cast<std::complex<float>*
>(buffer);
1079 std::complex<double> *buf =
reinterpret_cast<std::complex<double>*
>(buffer);
1103 while (regionSize[splitAxis] == 1)
1108 itkDebugMacro(
" Cannot Split");
1115 int valuesPerPiece = Math::Ceil<int>(range/double(numberOfRequestedSplits));
1116 int maxPieceUsed = Math::Ceil<int>(range/double(valuesPerPiece)) - 1;
1118 return maxPieceUsed+1;
1130 if (pasteRegion != largestPossibleRegion)
1132 itkExceptionMacro(
"Pasting is not supported! Can't write:" << this->
GetFileName());
1134 if (numberOfRequestedSplits != 1)
1136 itkDebugMacro(
"Requested more then 1 splits for streaming");
1137 itkDebugMacro(
"This IO class does not support streaming!");
1144 unsigned int numberOfActualSplits,
1154 splitRegion = pasteRegion;
1155 splitIndex = splitRegion.
GetIndex();
1156 splitSize = splitRegion.
GetSize();
1158 regionSize = pasteRegion.
GetSize();
1162 while (regionSize[splitAxis] == 1)
1167 itkDebugMacro(
" Cannot Split");
1174 int valuesPerPiece = Math::Ceil<int>(range/(double)numberOfActualSplits);
1175 int maxPieceUsed = Math::Ceil<int>(range/(double)valuesPerPiece) - 1;
1178 if ((
int) ithPiece < maxPieceUsed)
1180 splitIndex[splitAxis] += ithPiece*valuesPerPiece;
1181 splitSize[splitAxis] = valuesPerPiece;
1183 if ((
int) ithPiece == maxPieceUsed)
1185 splitIndex[splitAxis] += ithPiece*valuesPerPiece;
1187 splitSize[splitAxis] = splitSize[splitAxis] - ithPiece*valuesPerPiece;
1191 splitRegion.
SetIndex( splitIndex );
1192 splitRegion.
SetSize( splitSize );
1194 itkDebugMacro(
" Split Piece: " << splitRegion );
1201 unsigned int numberOfActualSplits,
1209 return largestPossibleRegion;
1233 unsigned int minIODimension = this->m_NumberOfDimensions;
1234 while (minIODimension)
1236 if (this->m_Dimensions[minIODimension-1] == 1)
1247 unsigned int maxDimension =
1254 for(
unsigned int i=0; i < minIODimension; i++ )
1256 streamableRegion.
SetSize( i, this->m_Dimensions[i] );
1261 for(
unsigned int j=minIODimension; j<streamableRegion.
GetImageDimension(); j++ )
1263 streamableRegion.
SetSize( j, 1 );
1268 return streamableRegion;
1278 std::vector<double> axis;
1279 axis.resize( this->GetNumberOfDimensions() );
1282 for(
unsigned int r=0; r<axis.size(); r++ )
1296 os << indent <<
"FileName: " <<
m_FileName << std::endl;
1299 os << indent <<
"IORegion: " << std::endl;
1305 os << indent <<
"Dimensions: ( ";
1310 os <<
")" << std::endl;
1311 os << indent <<
"Origin: ( ";
1316 os <<
")" << std::endl;
1320 os << indent <<
"UseCompression: On" << std::endl;
1324 os << indent <<
"UseCompression: Off" << std::endl;
1328 os << indent <<
"UseStreamedReading: On" << std::endl;
1332 os << indent <<
"UseStreamedReading: Off" << std::endl;
1336 os << indent <<
"UseStreamedWriting: On" << std::endl;
1340 os << indent <<
"UseStreamedWriting: Off" << std::endl;