18 #ifndef itkMeshFileTestHelper_h
19 #define itkMeshFileTestHelper_h
29 #include <itksys/SystemTools.hxx>
31 template<
typename TMesh >
34 typename TMesh::PointsContainerPointer points1 )
36 using MeshType = TMesh;
37 using PointsContainerConstIterator =
typename MeshType::PointsContainerConstIterator;
39 if ( points0.IsNotNull() && points1.IsNotNull() )
41 if( points0->Size() != points1->Size() )
43 std::cerr <<
"Input mesh and output mesh have different number of cells!" <<std::endl;
47 PointsContainerConstIterator pt0 = points0->Begin();
48 PointsContainerConstIterator pt1 = points1->Begin();
50 const double tol = 1
e-6;
51 while ( ( pt0 != points0->End() ) && ( pt1 != points1->End() ) )
53 if( pt0->Index() != pt1->Index() )
55 std::cerr <<
"Input mesh and output mesh are different in points!" << std::endl;
56 std::cerr <<
"Input point ID = " << pt0.Index() << std::endl;
57 std::cerr <<
"Output point ID = " << pt1.Index() << std::endl;
60 if ( pt0.Value().SquaredEuclideanDistanceTo( pt1.Value() ) > tol )
62 std::cerr <<
"Input mesh and output mesh are different in points!" << std::endl;
63 std::cerr <<
"Input point = " << pt0.Value() << std::endl;
64 std::cerr <<
"Output point = " << pt1.Value() << std::endl;
73 if ( points0 != points1.GetPointer() )
75 std::cerr <<
"Input mesh and output mesh are different in points!" << std::endl;
76 std::cerr <<
"points0 = " << points0.GetPointer() << std::endl;
77 std::cerr <<
"points1 = " << points1.GetPointer() << std::endl;
85 template<
typename TMesh >
88 typename TMesh::CellsContainerPointer cells1 )
90 using MeshType = TMesh;
91 using CellsContainerConstIterator =
typename MeshType::CellsContainerConstIterator;
92 using CellPointIdIterator =
typename MeshType::CellType::PointIdIterator;
94 if ( cells0.IsNotNull() && cells1.IsNotNull() )
96 if( cells0->Size() != cells1->Size() )
98 std::cerr <<
"Input mesh and output mesh have different number of cells!" <<std::endl;
101 CellsContainerConstIterator ceIt0 = cells0->Begin();
102 CellsContainerConstIterator ceIt1 = cells1->Begin();
104 while ( ( ceIt0 != cells0->End() ) && ( ceIt1 != cells1->End() ) )
106 if ( ceIt0.Value()->GetType() != ceIt1.Value()->GetType() )
108 std::cerr <<
"Input mesh and output mesh are different in cell type!" << std::endl;
111 if ( ceIt0.Index() != ceIt1.Index() )
113 std::cerr <<
"Input mesh and output mesh have different cell IDs" << std::endl;
114 std::cerr <<
"Input mesh cell ID: " << ceIt0.Index() << std::endl;
115 std::cerr <<
"Output mesh cell ID: " << ceIt1.Index() << std::endl;
118 CellPointIdIterator pit0 = ceIt0.Value()->PointIdsBegin();
119 CellPointIdIterator pit1 = ceIt1.Value()->PointIdsBegin();
120 while ( pit0 != ceIt0.Value()->PointIdsEnd() )
122 if ( *pit0 != *pit1 )
124 std::cerr <<
"Input mesh and output mesh are different in cells!" << std::endl;
136 if ( cells0 != cells1.GetPointer() )
138 std::cerr <<
"Input mesh and output mesh are different in cells!" << std::endl;
139 std::cerr <<
"cells0 = " << cells0.GetPointer() << std::endl;
140 std::cerr <<
"cells1 = " << cells1.GetPointer() << std::endl;
148 template<
typename TMesh >
151 typename TMesh::PointDataContainerPointer pointData1 )
153 using MeshType = TMesh;
154 using PointDataContainerIterator =
typename MeshType::PointDataContainerIterator;
156 if ( pointData0.IsNotNull() && pointData1.IsNotNull() )
158 if( pointData0->Size() != pointData1->Size() )
160 std::cerr <<
"Input mesh and output mesh have different number of cells!" <<std::endl;
163 PointDataContainerIterator pdIt0 = pointData0->Begin();
164 PointDataContainerIterator pdIt1 = pointData1->Begin();
166 while ( ( pdIt0 != pointData0->End() ) && ( pdIt1 != pointData1->End() ) )
168 if( pdIt0->Index() != pdIt1->Index() )
170 std::cerr <<
"Input mesh and output mesh are different in point data!" << std::endl;
171 std::cerr <<
"Input point ID = " << pdIt0.Index() << std::endl;
172 std::cerr <<
"Output point ID = " << pdIt1.Index() << std::endl;
177 std::cerr <<
"Input mesh and output mesh are different in point data!" << std::endl;
178 std::cerr <<
"Input = " << pdIt0.Value() << std::endl;
179 std::cerr <<
"Output = " << pdIt1.Value() << std::endl;
188 if ( pointData0 != pointData1.GetPointer() )
190 std::cerr <<
"Input mesh and output mesh are different in point data!" << std::endl;
191 std::cerr <<
"pointData0 = " << pointData0.GetPointer() << std::endl;
192 std::cerr <<
"pointData1 = " << pointData1.GetPointer() << std::endl;
199 template<
typename TMesh >
202 typename TMesh::CellDataContainerPointer cellData1 )
204 using MeshType = TMesh;
205 using CellDataContainerIterator =
typename MeshType::CellDataContainerIterator;
207 if ( cellData0.IsNotNull() && cellData1.IsNotNull() )
209 if( cellData0->Size() != cellData1->Size() )
211 std::cerr <<
"Input mesh and output mesh have different number of cells!" <<std::endl;
215 CellDataContainerIterator cdIt0 = cellData0->Begin();
216 CellDataContainerIterator cdIt1 = cellData1->Begin();
217 while ( cdIt0 != cellData0->End() )
219 if( cdIt0->Index() != cdIt1->Index() )
221 std::cerr <<
"Input mesh and output mesh are different in cell data!" << std::endl;
222 std::cerr <<
"Input cell ID = " << cdIt0.Index() << std::endl;
223 std::cerr <<
"Output cell ID = " << cdIt1.Index() << std::endl;
228 std::cerr <<
"Input mesh and output mesh are different in cell data!" << std::endl;
229 std::cerr <<
"Input = " << cdIt0.Value() << std::endl;
230 std::cerr <<
"Output = " << cdIt1.Value() << std::endl;
239 if ( cellData0 != cellData1.GetPointer() )
241 std::cerr <<
"Input mesh and output mesh are different in cell data!" << std::endl;
242 std::cerr <<
"pointData0 = " << cellData0.GetPointer() << std::endl;
243 std::cerr <<
"pointData1 = " << cellData1.GetPointer() << std::endl;
250 template<
typename TMesh >
252 test(
char *INfilename,
char *OUTfilename,
bool IsBinary)
254 using MeshType = TMesh;
257 using MeshFileReaderPointer =
typename MeshFileReaderType::Pointer;
260 using MeshFileWriterPointer =
typename MeshFileWriterType::Pointer;
262 MeshFileReaderPointer reader = MeshFileReaderType::New();
263 reader->SetFileName(INfilename);
270 std::cerr <<
"Read file " << INfilename <<
" failed " << std::endl;
271 std::cerr << err << std::endl;
274 reader->GetMeshIO()->
Print( std::cout );
276 if( TMesh::PointDimension != reader->GetMeshIO()->GetPointDimension() )
278 std::cerr <<
"Unexpected PointDimension" << std::endl;
282 MeshFileWriterPointer writer = MeshFileWriterType::New();
283 if( itksys::SystemTools::GetFilenameLastExtension(INfilename) ==
284 itksys::SystemTools::GetFilenameLastExtension(OUTfilename) )
286 writer->SetMeshIO(reader->GetModifiableMeshIO());
288 writer->SetFileName(OUTfilename);
289 writer->SetInput( reader->GetOutput() );
294 writer->SetFileTypeAsBINARY();
303 std::cerr <<
"Write file " << OUTfilename <<
" failed " << std::endl;
304 std::cerr << err << std::endl;
308 if ( !itksys::SystemTools::FilesDiffer(INfilename, OUTfilename) )
313 typename MeshFileReaderType::Pointer reader1 = MeshFileReaderType::New();
314 reader1->SetFileName(OUTfilename);
321 std::cerr <<
"Read file " << OUTfilename <<
" failed " << std::endl;
322 std::cerr << err << std::endl;
327 if( TestPointsContainer< MeshType >( reader->GetOutput()->GetPoints(),
328 reader1->GetOutput()->GetPoints() ) == EXIT_FAILURE )
335 if( TestCellsContainer< MeshType >( reader->GetOutput()->GetCells(),
336 reader1->GetOutput()->GetCells() ) == EXIT_FAILURE )
343 if( TestPointDataContainer< MeshType >( reader->GetOutput()->GetPointData(),
344 reader1->GetOutput()->GetPointData() ) == EXIT_FAILURE )
351 if( TestCellDataContainer< MeshType >( reader->GetOutput()->GetCellData(),
352 reader1->GetOutput()->GetCellData() ) == EXIT_FAILURE )
int TestCellsContainer(typename TMesh::CellsContainerPointer cells0, typename TMesh::CellsContainerPointer cells1)
int TestPointsContainer(typename TMesh::PointsContainerPointer points0, typename TMesh::PointsContainerPointer points1)
Standard exception handling object.
virtual void Print(std::ostream &os) const
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
int TestPointDataContainer(typename TMesh::PointDataContainerPointer pointData0, typename TMesh::PointDataContainerPointer pointData1)
int TestCellDataContainer(typename TMesh::CellDataContainerPointer cellData0, typename TMesh::CellDataContainerPointer cellData1)
Writes mesh data to a single file.
static constexpr double e
The base of the natural logarithm or Euler's number
int test(char *INfilename, char *OUTfilename, bool IsBinary)
Mesh source that reads mesh data from a single file.