18 #ifndef itkMeshFileTestHelper_h
19 #define itkMeshFileTestHelper_h
29 #include "itksys/SystemTools.hxx"
31 template <
typename TMesh>
33 TestPointsContainer(
typename TMesh::PointsContainerPointer points0,
typename TMesh::PointsContainerPointer points1)
35 using MeshType = TMesh;
36 using PointsContainerConstIterator =
typename MeshType::PointsContainerConstIterator;
38 if (points0.IsNotNull() && points1.IsNotNull())
40 if (points0->Size() != points1->Size())
42 std::cerr <<
"Input mesh and output mesh have different number of points!" << std::endl;
46 PointsContainerConstIterator pt0 = points0->Begin();
47 PointsContainerConstIterator pt1 = points1->Begin();
49 const double tol = 1
e-6;
50 while ((pt0 != points0->End()) && (pt1 != points1->End()))
52 if (pt0->Index() != pt1->Index())
54 std::cerr <<
"Input mesh and output mesh are different in points!" << std::endl;
55 std::cerr <<
"Input point ID = " << pt0.Index() << std::endl;
56 std::cerr <<
"Output point ID = " << pt1.Index() << std::endl;
59 if (pt0.Value().SquaredEuclideanDistanceTo(pt1.Value()) > tol)
61 std::cerr <<
"Input mesh and output mesh are different in points!" << std::endl;
62 std::cerr <<
"Input point = " << pt0.Value() << std::endl;
63 std::cerr <<
"Output point = " << pt1.Value() << std::endl;
72 if (points0 != points1.GetPointer())
74 std::cerr <<
"Input mesh and output mesh are different in points!" << std::endl;
75 std::cerr <<
"points0 = " << points0.GetPointer() << std::endl;
76 std::cerr <<
"points1 = " << points1.GetPointer() << std::endl;
84 template <
typename TMesh>
86 TestCellsContainer(
typename TMesh::CellsContainerPointer cells0,
typename TMesh::CellsContainerPointer cells1)
88 using MeshType = TMesh;
89 using CellsContainerConstIterator =
typename MeshType::CellsContainerConstIterator;
90 using CellPointIdIterator =
typename MeshType::CellType::PointIdIterator;
92 if (cells0.IsNotNull() && cells1.IsNotNull())
94 if (cells0->Size() != cells1->Size())
96 std::cerr <<
"Input mesh and output mesh have different number of cells!" << std::endl;
99 CellsContainerConstIterator ceIt0 = cells0->Begin();
100 CellsContainerConstIterator ceIt1 = cells1->Begin();
102 while ((ceIt0 != cells0->End()) && (ceIt1 != cells1->End()))
104 if (ceIt0.Value()->GetType() != ceIt1.Value()->GetType())
106 std::cerr <<
"Input mesh and output mesh are different in cell type!" << std::endl;
109 if (ceIt0.Index() != ceIt1.Index())
111 std::cerr <<
"Input mesh and output mesh have different cell IDs" << std::endl;
112 std::cerr <<
"Input mesh cell ID: " << ceIt0.Index() << std::endl;
113 std::cerr <<
"Output mesh cell ID: " << ceIt1.Index() << std::endl;
116 CellPointIdIterator pit0 = ceIt0.Value()->PointIdsBegin();
117 CellPointIdIterator pit1 = ceIt1.Value()->PointIdsBegin();
118 while (pit0 != ceIt0.Value()->PointIdsEnd())
122 std::cerr <<
"Input mesh and output mesh are different in cells!" << std::endl;
134 if (cells0 != cells1.GetPointer())
136 std::cerr <<
"Input mesh and output mesh are different in cells!" << std::endl;
137 std::cerr <<
"cells0 = " << cells0.GetPointer() << std::endl;
138 std::cerr <<
"cells1 = " << cells1.GetPointer() << std::endl;
146 template <
typename TMesh>
149 typename TMesh::PointDataContainerPointer pointData1)
151 using MeshType = TMesh;
152 using PointDataContainerIterator =
typename MeshType::PointDataContainerIterator;
154 if (pointData0.IsNotNull() && pointData1.IsNotNull())
156 if (pointData0->Size() != pointData1->Size())
158 std::cerr <<
"Input mesh and output mesh have different number of point data!" << std::endl;
161 PointDataContainerIterator pdIt0 = pointData0->Begin();
162 PointDataContainerIterator pdIt1 = pointData1->Begin();
164 while ((pdIt0 != pointData0->End()) && (pdIt1 != pointData1->End()))
166 if (pdIt0->Index() != pdIt1->Index())
168 std::cerr <<
"Input mesh and output mesh are different in point data!" << std::endl;
169 std::cerr <<
"Input point ID = " << pdIt0.Index() << std::endl;
170 std::cerr <<
"Output point ID = " << pdIt1.Index() << std::endl;
175 std::cerr <<
"Input mesh and output mesh are different in point data!" << std::endl;
176 std::cerr <<
"Input = " << pdIt0.Value() << std::endl;
177 std::cerr <<
"Output = " << pdIt1.Value() << std::endl;
186 if (pointData0 != pointData1.GetPointer())
188 std::cerr <<
"Input mesh and output mesh are different in point data!" << std::endl;
189 std::cerr <<
"pointData0 = " << pointData0.GetPointer() << std::endl;
190 std::cerr <<
"pointData1 = " << pointData1.GetPointer() << std::endl;
197 template <
typename TMesh>
200 typename TMesh::CellDataContainerPointer cellData1)
202 using MeshType = TMesh;
203 using CellDataContainerIterator =
typename MeshType::CellDataContainerIterator;
205 if (cellData0.IsNotNull() && cellData1.IsNotNull())
207 if (cellData0->Size() != cellData1->Size())
209 std::cerr <<
"Input mesh and output mesh have different number of cell data!" << std::endl;
213 CellDataContainerIterator cdIt0 = cellData0->Begin();
214 CellDataContainerIterator cdIt1 = cellData1->Begin();
215 while (cdIt0 != cellData0->End())
217 if (cdIt0->Index() != cdIt1->Index())
219 std::cerr <<
"Input mesh and output mesh are different in cell data!" << std::endl;
220 std::cerr <<
"Input cell ID = " << cdIt0.Index() << std::endl;
221 std::cerr <<
"Output cell ID = " << cdIt1.Index() << std::endl;
226 std::cerr <<
"Input mesh and output mesh are different in cell data!" << std::endl;
227 std::cerr <<
"Input = " << cdIt0.Value() << std::endl;
228 std::cerr <<
"Output = " << cdIt1.Value() << std::endl;
237 if (cellData0 != cellData1.GetPointer())
239 std::cerr <<
"Input mesh and output mesh are different in cell data!" << std::endl;
240 std::cerr <<
"pointData0 = " << cellData0.GetPointer() << std::endl;
241 std::cerr <<
"pointData1 = " << cellData1.GetPointer() << std::endl;
248 template <
typename TMesh>
250 test(
char * inputFileName,
char * outputFileName,
bool isBinary)
252 using MeshType = TMesh;
261 reader->SetFileName(inputFileName);
266 catch (
const itk::ExceptionObject & err)
268 std::cerr <<
"Read file " << inputFileName <<
" failed " << std::endl;
269 std::cerr << err << std::endl;
272 reader->GetMeshIO()->Print(std::cout);
274 if (TMesh::PointDimension != reader->GetMeshIO()->GetPointDimension())
276 std::cerr <<
"Unexpected PointDimension" << std::endl;
281 if (itksys::SystemTools::GetFilenameLastExtension(inputFileName) ==
282 itksys::SystemTools::GetFilenameLastExtension(outputFileName))
284 writer->SetMeshIO(reader->GetModifiableMeshIO());
286 writer->SetFileName(outputFileName);
287 writer->SetInput(reader->GetOutput());
292 writer->SetFileTypeAsBINARY();
299 catch (
const itk::ExceptionObject & err)
301 std::cerr <<
"Write file " << outputFileName <<
" failed " << std::endl;
302 std::cerr << err << std::endl;
306 if (!itksys::SystemTools::FilesDiffer(inputFileName, outputFileName))
312 reader1->SetFileName(outputFileName);
317 catch (
const itk::ExceptionObject & err)
319 std::cerr <<
"Read file " << outputFileName <<
" failed " << std::endl;
320 std::cerr << err << std::endl;
325 if (TestPointsContainer<MeshType>(reader->GetOutput()->GetPoints(), reader1->GetOutput()->GetPoints()) ==
333 if (TestCellsContainer<MeshType>(reader->GetOutput()->GetCells(), reader1->GetOutput()->GetCells()) == EXIT_FAILURE)
340 if (TestPointDataContainer<MeshType>(reader->GetOutput()->GetPointData(), reader1->GetOutput()->GetPointData()) ==
348 if (TestCellDataContainer<MeshType>(reader->GetOutput()->GetCellData(), reader1->GetOutput()->GetCellData()) ==