File: itkQuadEdgeMeshPointTest1.cxx

package info (click to toggle)
insighttoolkit5 5.4.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704,384 kB
  • sloc: cpp: 783,592; ansic: 628,724; xml: 44,704; fortran: 34,250; python: 22,874; sh: 4,078; pascal: 2,636; lisp: 2,158; makefile: 464; yacc: 328; asm: 205; perl: 203; lex: 146; tcl: 132; javascript: 98; csh: 81
file content (213 lines) | stat: -rw-r--r-- 5,069 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*=========================================================================
 *
 *  Copyright NumFOCUS
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         https://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include "itkQuadEdgeMeshPoint.h"
#include "itkMesh.h"

int
itkQuadEdgeMeshPointTest1(int, char *[])
{
  std::cout << "Testing points..." << std::endl;

  //
  // These type alias are taken from a traditional itk mesh just
  // to get definitions that are consistent with the derived class.
  //
  using NonQuadEdgeMeshType = itk::Mesh<float, 3>;
  using PointIdentifier = NonQuadEdgeMeshType::PointIdentifier;
  using FaceIdentifier = NonQuadEdgeMeshType::CellIdentifier;

  using PrimalDataType = bool;
  using DualDataType = bool;

  const bool ThisIsDual = true;

  using QuadEdgeType =
    itk::GeometricalQuadEdge<PointIdentifier, FaceIdentifier, PrimalDataType, DualDataType, ThisIsDual>;

  using PointType = itk::QuadEdgeMeshPoint<float, 3, QuadEdgeType>;

  using SuperclassPointType = PointType::Superclass;


  PointType p0; // Test default constructor

  PointType p1;

  p1[0] = 17.7;
  p1[1] = 39.7;
  p1[2] = -49.7;

  PointType p2(p1); // Test copy constructor

  if (p1.EuclideanDistanceTo(p2) > 1e-6)
  {
    std::cerr << "Error in the copy constructor" << std::endl;
    return EXIT_FAILURE;
  }

  //
  // Test assignment from an itk::Point
  //
  SuperclassPointType ps;

  ps[0] = 29;
  ps[1] = 31;
  ps[2] = 37;

  PointType pp = ps;

  if (pp.EuclideanDistanceTo(ps) > 1e-6)
  {
    std::cerr << "Error in the array constructor" << std::endl;
    return EXIT_FAILURE;
  }

  PointType pp2;
  pp2.SetPoint(ps);

  if (pp2.EuclideanDistanceTo(ps) > 1e-6)
  {
    std::cerr << "Error in the array constructor" << std::endl;
    return EXIT_FAILURE;
  }

  PointType::ValueArrayType cc;
  cc[0] = 17.7;
  cc[1] = 39.7;
  cc[2] = -49.7;

  PointType p3(cc); // Test Array based constructor

  if (p2.EuclideanDistanceTo(p1) > 1e-6)
  {
    std::cerr << "Error in the array constructor" << std::endl;
    return EXIT_FAILURE;
  }

  PointType p4;
  PointType p4b;
  p4b = p4 = p1; // Test assignment operator to Self

  if (p4.EuclideanDistanceTo(p1) > 1e-6)
  {
    std::cerr << "Error in the assignment operator to Self" << std::endl;
    return EXIT_FAILURE;
  }

  if (p4b.EuclideanDistanceTo(p4) > 1e-6)
  {
    std::cerr << "Error in the assignment operator to Self" << std::endl;
    return EXIT_FAILURE;
  }

  PointType::Superclass pp1;
  pp1[0] = 17.7;
  pp1[1] = 39.7;
  pp1[2] = -49.7;

  PointType p5;
  PointType p5b;
  p5b = p5 = pp1; // Test assignment operator from Superclass

  if (p5.EuclideanDistanceTo(pp1) > 1e-6)
  {
    std::cerr << "Error assignment operator from Superclass" << std::endl;
    return EXIT_FAILURE;
  }

  if (p5b.EuclideanDistanceTo(p5) > 1e-6)
  {
    std::cerr << "Error assignment operator from Superclass" << std::endl;
    return EXIT_FAILURE;
  }

  PointType p6;
  PointType p6b;
  p6b = p6 = cc; // Test assignment operator from array

  if (p6.EuclideanDistanceTo(p3) > 1e-6)
  {
    std::cerr << "Error in the assignment operator from Array " << std::endl;
    return EXIT_FAILURE;
  }

  if (p6b.EuclideanDistanceTo(p6) > 1e-6)
  {
    std::cerr << "Error in the assignment operator from Array " << std::endl;
    return EXIT_FAILURE;
  }

  auto * edge1 = new QuadEdgeType;

  p6.SetEdge(edge1);

  if (p6.GetEdge() != edge1)
  {
    std::cerr << "Error in SetEdge()/GetEdge() " << std::endl;
    delete edge1;
    return EXIT_FAILURE;
  }

  auto * edge2 = new QuadEdgeType;

  p6.SetEdge(edge2);

  if (p6.GetEdge() != edge2)
  {
    std::cerr << "Error in SetEdge()/GetEdge() " << std::endl;
    delete edge1;
    delete edge2;
    return EXIT_FAILURE;
  }

  // The following tests are commented out
  // because the point code is not safe yet.
#if defined(POINTMAKESAFE)
  bool internal = p6.IsInternal();

  if (internal != true) // FIXME: verify with a realistic case
  {
    std::cerr << "Error in IsInternal() " << std::endl;
    delete edge1;
    delete edge2;
    return EXIT_FAILURE;
  }

  PointType p7;
  if (p7.IsInternal())
  {
    std::cerr << "Error in IsInternal() " << std::endl;
    return EXIT_FAILURE;
  }

  int valence = p6.GetValence();
  if (valence != 1)
  {
    std::cerr << "Error in GetValence() " << std::endl;
    std::cerr << "valence = " << valence << std::endl;
    return EXIT_FAILURE;
  }
#endif

  delete edge1;
  delete edge2;

  std::cout << "Test passed" << std::endl;
  return EXIT_SUCCESS;
}