18#ifndef itkMeshIOTestHelper_h
19#define itkMeshIOTestHelper_h
42#define LOCAL_ITK_TEST_SET_GET_VALUE(variable, command) \
44 ITK_GCC_SUPPRESS_Wfloat_equal \
45 if (variable != command) \
47 std::cerr << "Error in " << #command << std::endl; \
48 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
49 std::cerr << "Expected " << variable << std::endl; \
50 std::cerr << "but got " << command << std::endl; \
51 return EXIT_FAILURE; \
54 ITK_MACROEND_NOOP_STATEMENT
57template <
typename TMeshIO>
61 using FloatType = float;
63 FloatType floatValue = 1.0;
64 bool usePointPixel =
true;
65 meshIO->SetPixelType(floatValue, usePointPixel);
68 meshIO->GetPointPixelComponentType());
71 usePointPixel =
false;
72 meshIO->SetPixelType(floatValue, usePointPixel);
75 meshIO->GetCellPixelComponentType());
81 RGBPixelType rgbValue{ 1.0 };
83 meshIO->SetPixelType(rgbValue, usePointPixel);
86 meshIO->GetPointPixelComponentType());
89 usePointPixel =
false;
90 meshIO->SetPixelType(rgbValue, usePointPixel);
93 meshIO->GetCellPixelComponentType());
99 auto rgbaValue = itk::MakeFilled<RGBAPixelType>(1.0);
100 usePointPixel =
true;
101 meshIO->SetPixelType(rgbaValue, usePointPixel);
104 meshIO->GetPointPixelComponentType());
107 usePointPixel =
false;
108 meshIO->SetPixelType(rgbaValue, usePointPixel);
111 meshIO->GetCellPixelComponentType());
118 auto vectorValue = itk::MakeFilled<VectorPixelType>(1.0);
119 usePointPixel =
true;
120 meshIO->SetPixelType(vectorValue, usePointPixel);
123 meshIO->GetPointPixelComponentType());
126 usePointPixel =
false;
127 meshIO->SetPixelType(vectorValue, usePointPixel);
130 meshIO->GetCellPixelComponentType());
136 auto covariantVectorValue = itk::MakeFilled<CovariantVectorPixelType>(1.0);
137 usePointPixel =
true;
138 meshIO->SetPixelType(covariantVectorValue, usePointPixel);
141 meshIO->GetPointPixelComponentType());
144 usePointPixel =
false;
145 meshIO->SetPixelType(covariantVectorValue, usePointPixel);
148 meshIO->GetCellPixelComponentType());
154 auto fixedArrayValue = itk::MakeFilled<FixedArrayPixelType>(1.0);
155 usePointPixel =
true;
156 meshIO->SetPixelType(fixedArrayValue, usePointPixel);
159 meshIO->GetPointPixelComponentType());
162 usePointPixel =
false;
163 meshIO->SetPixelType(fixedArrayValue, usePointPixel);
166 meshIO->GetCellPixelComponentType());
172 auto symmetricSecondRankTensorValue = itk::MakeFilled<SymmetricSecondRankTensorPixelType>(1.0);
173 usePointPixel =
true;
174 meshIO->SetPixelType(symmetricSecondRankTensorValue, usePointPixel);
177 meshIO->GetPointPixelComponentType());
180 usePointPixel =
false;
181 meshIO->SetPixelType(symmetricSecondRankTensorValue, usePointPixel);
184 meshIO->GetCellPixelComponentType());
190 auto diffusionTensor3DPixelValue = itk::MakeFilled<DiffusionTensor3DPixelType>(1.0);
191 usePointPixel =
true;
192 meshIO->SetPixelType(diffusionTensor3DPixelValue, usePointPixel);
195 meshIO->GetPointPixelComponentType());
198 usePointPixel =
false;
199 meshIO->SetPixelType(diffusionTensor3DPixelValue, usePointPixel);
202 meshIO->GetCellPixelComponentType());
210 auto matrixPixelValue = itk::MakeFilled<MatrixPixelType>(1.0);
211 usePointPixel =
true;
212 meshIO->SetPixelType(matrixPixelValue, usePointPixel);
215 meshIO->GetPointPixelComponentType());
218 usePointPixel =
false;
219 meshIO->SetPixelType(matrixPixelValue, usePointPixel);
222 meshIO->GetCellPixelComponentType());
226 using ComplexPixelType = std::complex<FloatType>;
228 ComplexPixelType complexPixelValue(1.0, 1.0);
229 usePointPixel =
true;
230 meshIO->SetPixelType(complexPixelValue, usePointPixel);
233 meshIO->GetPointPixelComponentType());
236 usePointPixel =
false;
237 meshIO->SetPixelType(complexPixelValue, usePointPixel);
240 meshIO->GetCellPixelComponentType());
246 ArrayPixelType arrayPixelValue{};
247 usePointPixel =
true;
248 meshIO->SetPixelType(arrayPixelValue, usePointPixel);
251 meshIO->GetPointPixelComponentType());
254 usePointPixel =
false;
255 meshIO->SetPixelType(arrayPixelValue, usePointPixel);
258 meshIO->GetCellPixelComponentType());
264 VariableLengthVectorPixelType variableLengthVectorValue{};
265 usePointPixel =
true;
266 meshIO->SetPixelType(variableLengthVectorValue, usePointPixel);
269 meshIO->GetPointPixelComponentType());
272 usePointPixel =
false;
273 meshIO->SetPixelType(variableLengthVectorValue, usePointPixel);
276 meshIO->GetCellPixelComponentType());
282 VariableSizeMatrixType matrix{};
283 usePointPixel =
true;
284 meshIO->SetPixelType(matrix, usePointPixel);
287 meshIO->GetPointPixelComponentType());
290 usePointPixel =
false;
291 meshIO->SetPixelType(matrix, usePointPixel);
294 meshIO->GetCellPixelComponentType());
301 std::cout <<
"ComponentSize: " << meshIO->GetComponentSize(floatComponent) << std::endl;
303 std::cout <<
"ComponentTypeAsString: " << meshIO->GetComponentTypeAsString(floatComponent) << std::endl;
306 std::cout <<
"PixelTypeAsString: " << meshIO->GetPixelTypeAsString(pixelType) << std::endl;
309 meshIO->SetPointComponentType(pointComponentType);
313 meshIO->SetCellComponentType(cellComponentType);
316 unsigned int pointDimension = 2;
317 meshIO->SetPointDimension(pointDimension);
321 meshIO->SetNumberOfPoints(numberOfPoints);
325 meshIO->SetNumberOfCells(numberOfCells);
329 meshIO->SetNumberOfPointPixels(numberOfPointPixels);
333 meshIO->SetNumberOfCellPixels(numberOfCellPixels);
337 meshIO->SetCellBufferSize(cellBufferSize);
341 meshIO->SetFileType(fileType);
344 std::cout <<
"FileTypeAsString: " << meshIO->GetFileTypeAsString(fileType) << std::endl;
347 meshIO->SetByteOrder(ioByteOrder);
350 std::cout <<
"ByteOrderAsString: " << meshIO->GetByteOrderAsString(ioByteOrder) << std::endl;
353 std::cout <<
"SupportedReadExtensions: " << std::endl;
354 for (
auto ext : supportedReadExtensions)
356 std::cout << ext << std::endl;
360 std::cout <<
"SupportedWriteExtensions: " << std::endl;
361 for (
auto ext : supportedWriteExtensions)
363 std::cout << ext << std::endl;
372namespace MeshIOTestHelper
379 return std::shared_ptr<void>(
new T[bufferSize], std::default_delete<T[]>());
382inline std::shared_ptr<void>
385 switch (componentType)
388 return MakeSharedArray<char>(bufferSize);
390 return MakeSharedArray<unsigned char>(bufferSize);
392 return MakeSharedArray<unsigned short>(bufferSize);
394 return MakeSharedArray<short>(bufferSize);
396 return MakeSharedArray<unsigned int>(bufferSize);
398 return MakeSharedArray<int>(bufferSize);
400 return MakeSharedArray<unsigned long>(bufferSize);
402 return MakeSharedArray<long>(bufferSize);
404 return MakeSharedArray<long long>(bufferSize);
406 return MakeSharedArray<unsigned long long>(bufferSize);
408 return MakeSharedArray<float>(bufferSize);
410 return MakeSharedArray<double>(bufferSize);
412 return MakeSharedArray<long double>(bufferSize);
Array class with size defined at construction time.
A templated class holding a n-Dimensional covariant vector.
Represent a diffusion tensor as used in DTI images.
Simulate a standard C array with copy semantics.
A templated class holding a M x N size Matrix.
IdentifierType SizeValueType
std::vector< std::string > ArrayOfExtensionsType
Represent Red, Green, Blue and Alpha components for color images.
Represent Red, Green and Blue components for color images.
Represent a symmetric tensor of second rank.
A templated class holding a M x N size Matrix.
A templated class holding a n-Dimensional vector.
@ SYMMETRICSECONDRANKTENSOR
SmartPointer< Self > Pointer
int TestBaseClassMethodsMeshIO(typename TMeshIO::Pointer meshIO)
#define LOCAL_ITK_TEST_SET_GET_VALUE(variable, command)
std::shared_ptr< void > MakeSharedArray(const std::vcl_size_t bufferSize)
std::shared_ptr< void > AllocateBuffer(itk::IOComponentEnum componentType, itk::SizeValueType bufferSize)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType