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 "itkContourSpatialObjectPoint.h"
20 #include "itkTestingMacros.h"
21
22
itkContourSpatialObjectPointTest(int,char * [])23 int itkContourSpatialObjectPointTest( int, char* [] )
24 {
25 // Test for 2D
26 //
27 using ContourSpatialObjectPoint2DType = itk::ContourSpatialObjectPoint< 2 >;
28
29 ContourSpatialObjectPoint2DType contourSpatialObjectPoint2D;
30
31 constexpr double pickedPointX = 4.35;
32 constexpr double pickedPointY = 7.56;
33 ContourSpatialObjectPoint2DType::PointType pickedPoint2D;
34 pickedPoint2D[0] = pickedPointX;
35 pickedPoint2D[1] = pickedPointY;
36
37 contourSpatialObjectPoint2D.SetPickedPointInObjectSpace( pickedPoint2D );
38 TEST_SET_GET_VALUE( pickedPoint2D,
39 contourSpatialObjectPoint2D.GetPickedPointInObjectSpace() );
40
41 constexpr double normalX = 1.0;
42 constexpr double normalY = 1.0;
43 ContourSpatialObjectPoint2DType::CovariantVectorType normal2D;
44 normal2D[0] = normalX;
45 normal2D[1] = normalY;
46
47 contourSpatialObjectPoint2D.SetNormalInObjectSpace( normal2D );
48 TEST_SET_GET_VALUE( normal2D,
49 contourSpatialObjectPoint2D.GetNormalInObjectSpace() );
50
51 // Create another ContourSpatialObjectPoint
52
53 ContourSpatialObjectPoint2DType contourSpatialObjectPoint2DAlt;
54
55 constexpr double pickedPointXAlt = 25.89;
56 constexpr double pickedPointYAlt = 57.26;
57 ContourSpatialObjectPoint2DType::PointType pickedPoint2DAlt;
58 pickedPoint2DAlt[0] = pickedPointXAlt;
59 pickedPoint2DAlt[1] = pickedPointYAlt;
60
61 contourSpatialObjectPoint2DAlt.SetPickedPointInObjectSpace(
62 pickedPoint2DAlt );
63 TEST_SET_GET_VALUE( pickedPoint2DAlt,
64 contourSpatialObjectPoint2DAlt.GetPickedPointInObjectSpace() );
65
66 constexpr double normalXAlt = 7.28;
67 constexpr double normalYAlt = 14.03;
68 ContourSpatialObjectPoint2DType::CovariantVectorType normal2DAlt;
69 normal2DAlt[0] = normalXAlt;
70 normal2DAlt[1] = normalYAlt;
71
72 contourSpatialObjectPoint2DAlt.SetNormalInObjectSpace( normal2DAlt );
73 TEST_SET_GET_VALUE( normal2DAlt,
74 contourSpatialObjectPoint2DAlt.GetNormalInObjectSpace() );
75
76 // Assign the old ContourSpatialObjectPoint object to the alternative one
77 contourSpatialObjectPoint2DAlt = contourSpatialObjectPoint2D;
78
79 TEST_SET_GET_VALUE( pickedPoint2D,
80 contourSpatialObjectPoint2DAlt.GetPickedPointInObjectSpace() );
81 TEST_SET_GET_VALUE( normal2D,
82 contourSpatialObjectPoint2DAlt.GetNormalInObjectSpace() );
83
84
85 // Test for 3D
86 //
87 using ContourSpatialObjectPoint3DType = itk::ContourSpatialObjectPoint< 3 >;
88
89 ContourSpatialObjectPoint3DType contourSpatialObjectPoint3D;
90
91 constexpr double pickedPointZ = 23.78;
92 ContourSpatialObjectPoint3DType::PointType pickedPoint3D;
93 pickedPoint3D[0] = pickedPointX;
94 pickedPoint3D[1] = pickedPointY;
95 pickedPoint3D[2] = pickedPointZ;
96
97 contourSpatialObjectPoint3D.SetPickedPointInObjectSpace( pickedPoint3D );
98 TEST_SET_GET_VALUE( pickedPoint3D,
99 contourSpatialObjectPoint3D.GetPickedPointInObjectSpace() );
100
101 constexpr double normalZ = 1.0;
102 ContourSpatialObjectPoint3DType::CovariantVectorType normal3D;
103 normal3D[0] = normalX;
104 normal3D[1] = normalY;
105 normal3D[2] = normalZ;
106
107 contourSpatialObjectPoint3D.SetNormalInObjectSpace( normal3D );
108 TEST_SET_GET_VALUE( normal3D,
109 contourSpatialObjectPoint3D.GetNormalInObjectSpace() );
110
111 // Create another ContourSpatialObjectPoint
112
113 ContourSpatialObjectPoint3DType contourSpatialObjectPoint3DAlt;
114
115 constexpr double pickedPointZAlt = 19.6;
116 ContourSpatialObjectPoint3DType::PointType pickedPoint3DAlt;
117 pickedPoint3DAlt[0] = pickedPointXAlt;
118 pickedPoint3DAlt[1] = pickedPointYAlt;
119 pickedPoint3DAlt[2] = pickedPointZAlt;
120
121 contourSpatialObjectPoint3DAlt.SetPickedPointInObjectSpace( pickedPoint3DAlt );
122 TEST_SET_GET_VALUE( pickedPoint3DAlt,
123 contourSpatialObjectPoint3DAlt.GetPickedPointInObjectSpace() );
124
125 constexpr double normalZAlt = 1.4;
126 ContourSpatialObjectPoint3DType::CovariantVectorType normal3DAlt;
127 normal3DAlt[0] = normalXAlt;
128 normal3DAlt[1] = normalYAlt;
129 normal3DAlt[2] = normalZAlt;
130
131 contourSpatialObjectPoint3DAlt.SetNormalInObjectSpace( normal3DAlt );
132 TEST_SET_GET_VALUE( normal3DAlt,
133 contourSpatialObjectPoint3DAlt.GetNormalInObjectSpace() );
134
135 // Assign the old ContourSpatialObjectPoint object to the alternative one
136 contourSpatialObjectPoint3DAlt = contourSpatialObjectPoint3D;
137
138 TEST_SET_GET_VALUE( pickedPoint3D,
139 contourSpatialObjectPoint3DAlt.GetPickedPointInObjectSpace() );
140 TEST_SET_GET_VALUE( normal3D,
141 contourSpatialObjectPoint3DAlt.GetNormalInObjectSpace() );
142
143 // Test for 4D
144 //
145 using ContourSpatialObjectPoint4DType = itk::ContourSpatialObjectPoint< 4 >;
146
147 ContourSpatialObjectPoint4DType contourSpatialObjectPoint4D;
148
149 constexpr double pickedPointW = 4.63;
150 ContourSpatialObjectPoint4DType::PointType pickedPoint4D;
151 pickedPoint4D[0] = pickedPointX;
152 pickedPoint4D[1] = pickedPointY;
153 pickedPoint4D[2] = pickedPointZ;
154 pickedPoint4D[3] = pickedPointW;
155
156 contourSpatialObjectPoint4D.SetPickedPointInObjectSpace( pickedPoint4D );
157 TEST_SET_GET_VALUE( pickedPoint4D,
158 contourSpatialObjectPoint4D.GetPickedPointInObjectSpace() );
159
160 constexpr double normalW = 3.1;
161 ContourSpatialObjectPoint4DType::CovariantVectorType normal4D;
162 normal4D[0] = normalX;
163 normal4D[1] = normalY;
164 normal4D[2] = normalZ;
165 normal4D[3] = normalW;
166
167 contourSpatialObjectPoint4D.SetNormalInObjectSpace( normal4D );
168 TEST_SET_GET_VALUE( normal4D,
169 contourSpatialObjectPoint4D.GetNormalInObjectSpace() );
170
171 // Create another ContourSpatialObjectPoint
172
173 ContourSpatialObjectPoint4DType contourSpatialObjectPoint4DAlt;
174
175 constexpr double pickedPointWAlt = 8.71;
176 ContourSpatialObjectPoint4DType::PointType pickedPoint4DAlt;
177 pickedPoint4DAlt[0] = pickedPointXAlt;
178 pickedPoint4DAlt[1] = pickedPointYAlt;
179 pickedPoint4DAlt[2] = pickedPointZAlt;
180 pickedPoint4DAlt[3] = pickedPointWAlt;
181
182 contourSpatialObjectPoint4DAlt.SetPickedPointInObjectSpace(
183 pickedPoint4DAlt );
184 TEST_SET_GET_VALUE( pickedPoint4DAlt,
185 contourSpatialObjectPoint4DAlt.GetPickedPointInObjectSpace() );
186
187 constexpr double normalWAlt = 4.23;
188 ContourSpatialObjectPoint4DType::CovariantVectorType normal4DAlt;
189 normal4DAlt[0] = normalXAlt;
190 normal4DAlt[1] = normalYAlt;
191 normal4DAlt[2] = normalZAlt;
192 normal4DAlt[3] = normalWAlt;
193
194 contourSpatialObjectPoint4DAlt.SetNormalInObjectSpace( normal4DAlt );
195 TEST_SET_GET_VALUE( normal4DAlt,
196 contourSpatialObjectPoint4DAlt.GetNormalInObjectSpace() );
197
198 // Assign the old ContourSpatialObjectPoint object to the alternative one
199 contourSpatialObjectPoint4DAlt = contourSpatialObjectPoint4D;
200
201 TEST_SET_GET_VALUE( pickedPoint4D,
202 contourSpatialObjectPoint4DAlt.GetPickedPointInObjectSpace() );
203 TEST_SET_GET_VALUE( normal4D,
204 contourSpatialObjectPoint4DAlt.GetNormalInObjectSpace() );
205
206 std::cout << "Test finished" << std::endl;
207 return EXIT_SUCCESS;
208 }
209