1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19 #include "itkQuadEdgeMesh.h"
20
itkQuadEdgeMeshTest2(int,char * [])21 int itkQuadEdgeMeshTest2( int , char* [] )
22 {
23 std::cout << "Testing points and simple edges... " << std::ends;
24
25 using PixelType = double;
26 using MeshType = itk::QuadEdgeMesh< PixelType, 3 >;
27 using CellType = MeshType::CellType;
28 using LineType = itk::QuadEdgeMeshLineCell< CellType >;
29 using QuadEdgeType = LineType::QEType;
30 using CellAutoPointer = CellType::CellAutoPointer;
31
32 MeshType::Pointer mesh = MeshType::New();
33
34 MeshType::PointType p0;
35 MeshType::PointType p1;
36 MeshType::PointType p2;
37
38 p0[ 0 ] = -1.0; p0[ 1 ] = 0.0; p0[ 2 ] = 0.0;
39 p1[ 0 ] = 1.0; p1[ 1 ] = 0.0; p1[ 2 ] = 0.0;
40 p2[ 0 ] = 1.0; p2[ 1 ] = 1.0; p2[ 2 ] = 0.0;
41
42 mesh->SetPoint( 0, p0 );
43 mesh->SetPoint( 1, p1 );
44 mesh->SetPoint( 2, p2 );
45
46 CellAutoPointer line0;
47 line0.TakeOwnership( new LineType );
48 line0->SetPointId( 0, 0 );
49 line0->SetPointId( 1, 1 );
50 mesh->SetCell( 0, line0 );
51
52 CellAutoPointer line1;
53 line1.TakeOwnership( new LineType );
54 line1->SetPointId( 0, 1 );
55 line1->SetPointId( 1, 2 );
56 mesh->SetCell( 1, line1 );
57
58 CellAutoPointer line2;
59 line2.TakeOwnership( new LineType );
60 line2->SetPointId( 0, 2 );
61 line2->SetPointId( 1, 0 );
62 mesh->SetCell( 2, line2 );
63
64 if( mesh->GetNumberOfPoints() != 3 )
65 {
66 std::cout << "Not all points added." << std::endl;
67 return EXIT_FAILURE;
68 }
69
70 if( ( mesh->GetNumberOfCells( ) != 0 )
71 && ( mesh->GetNumberOfEdges( ) != 3 ) )
72 {
73 std::cout << "Not all cells added." << std::endl;
74 return EXIT_FAILURE;
75 }
76
77 using CellIterator = MeshType::CellsContainer::Iterator;
78 CellIterator cellIterator = mesh->GetCells()->Begin();
79 unsigned int ids[ ] = { 0, 1, 2, 1, 2, 0, 2, 0, 1 };
80 int itIds = 0;
81
82 while( cellIterator != mesh->GetCells()->End() )
83 {
84 MeshType::CellType* cellptr = cellIterator.Value();
85 auto * lineCell = dynamic_cast< LineType* >( cellptr );
86 lineCell->GetNameOfClass();
87 QuadEdgeType* QEGeom = lineCell->GetQEGeom( );
88 QuadEdgeType::IteratorGeom git = QEGeom->BeginGeomLnext();
89 while( git != QEGeom->EndGeomLnext() )
90 {
91 if( ids[ itIds ] != *git )
92 {
93 std::cout << "Problem with splicing edges." << std::endl;
94 return EXIT_FAILURE;
95 }
96 itIds++;
97 git++;
98 }
99 cellIterator++;
100 }
101
102 std::cout << "done!" << std::endl;
103 return EXIT_SUCCESS;
104 }
105