1 #include "vtkLineRepresentation.h"
2
3 #include <cstdlib>
4 #include <iostream>
5
6 #include "WidgetTestingMacros.h"
7
8 #include "vtkPointHandleRepresentation3D.h"
9 #include "vtkPolyData.h"
10 #include "vtkProperty.h"
11 #include "vtkFollower.h"
12
vtkLineRepresentationTest1(int,char * [])13 int vtkLineRepresentationTest1(int , char * [] )
14 {
15 vtkSmartPointer< vtkLineRepresentation > node1 = vtkSmartPointer< vtkLineRepresentation >::New();
16
17 vtkSmartPointer<vtkPointHandleRepresentation3D> handleRep = vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
18 node1->SetHandleRepresentation(handleRep);
19 node1->InstantiateHandleRepresentation();
20
21 EXERCISE_BASIC_REPRESENTATION_METHODS(vtkLineRepresentation, node1);
22
23
24 double pos[3] = {-100.0, 0.0, 99.9};
25 double pos2[3];
26 double *posptr = nullptr;
27
28 // point 1 world
29 node1->SetPoint1WorldPosition(pos);
30 posptr = node1->GetPoint1WorldPosition();
31 if (!posptr)
32 {
33 std::cerr << "Error in get double * for Point1WorldPosition, null pointer returned." << std::endl;
34 return EXIT_FAILURE;
35 }
36 else if (posptr[0] != pos[0] ||
37 posptr[1] != pos[1] ||
38 posptr[2] != pos[2])
39 {
40 std::cerr << "Error in double * Set/Get Point1WorldPosition, expected " << pos[0] << ", " << pos[1] << ", " << pos[2] << " but got " << posptr[0] << ", " << posptr[1] << ", " << posptr[2] << std::endl;
41 return EXIT_FAILURE;
42 }
43 else
44 {
45 std::cout << "GetPoint1WorldPosition double * = " << posptr[0] << ", " << posptr[1] << ", " << posptr[2] << std::endl;
46 }
47 node1->GetPoint1WorldPosition(pos2);
48 if (pos2[0] != pos[0] ||
49 pos2[1] != pos[1] ||
50 pos2[2] != pos[2])
51 {
52 std::cerr << "Error in Set/Get Point1WorldPosition, expected " << pos[0] << ", " << pos[1] << ", " << pos[2] << " but got " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << std::endl;
53 return EXIT_FAILURE;
54 }
55 else
56 {
57 std::cout << "GetPoint1WorldPosition = " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << std::endl;
58 }
59
60 // point 1 display
61 /// causes seg faults, don't test yet
62 /*
63 pos[1] = -99.9;
64 //node1->SetPoint1DisplayPosition(pos);
65 posptr = node1->GetPoint1DisplayPosition();
66 if (!posptr)
67 {
68 std::cerr << "Error in get double * for Point1DisplayPosition, null pointer returned." << std::endl;
69 return EXIT_FAILURE;
70 }
71 else if (posptr[0] != pos[0] ||
72 posptr[1] != pos[1] ||
73 posptr[2] != pos[2])
74 {
75 std::cerr << "Error in double * Set/Get Point1DisplayPosition, expected " << pos[0] << ", " << pos[1] << ", " << pos[2] << " but got " << posptr[0] << ", " << posptr[1] << ", " << posptr[2] << std::endl;
76 return EXIT_FAILURE;
77 }
78 else
79 {
80 std::cout << "GetPoint1DisplayPosition double * = " << posptr[0] << ", " << posptr[1] << ", " << posptr[2] << std::endl;
81 }
82 node1->GetPoint1DisplayPosition(pos2);
83 if (pos2[0] != pos[0] ||
84 pos2[1] != pos[1] ||
85 pos2[2] != pos[2])
86 {
87 std::cerr << "Error in Set/Get Point1DisplayPosition, expected " << pos[0] << ", " << pos[1] << ", " << pos[2] << " but got " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << std::endl;
88 return EXIT_FAILURE;
89 }
90 else
91 {
92 std::cout << "GetPoint1DisplayPosition = " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << std::endl;
93 }
94 */
95
96 // point 2 world
97
98 pos[1] = 77.0;
99 node1->SetPoint2WorldPosition(pos);
100 posptr = node1->GetPoint2WorldPosition();
101 if (!posptr)
102 {
103 std::cerr << "Error in get double * for Point2WorldPosition, null pointer returned." << std::endl;
104 return EXIT_FAILURE;
105 }
106 else if (posptr[0] != pos[0] ||
107 posptr[1] != pos[1] ||
108 posptr[2] != pos[2])
109 {
110 std::cerr << "Error in double * Set/Get Point2WorldPosition, expected " << pos[0] << ", " << pos[1] << ", " << pos[2] << " but got " << posptr[0] << ", " << posptr[1] << ", " << posptr[2] << std::endl;
111 return EXIT_FAILURE;
112 }
113 else
114 {
115 std::cout << "GetPoint2WorldPosition double * = " << posptr[0] << ", " << posptr[1] << ", " << posptr[2] << std::endl;
116 }
117 node1->GetPoint2WorldPosition(pos2);
118 if (pos2[0] != pos[0] ||
119 pos2[1] != pos[1] ||
120 pos2[2] != pos[2])
121 {
122 std::cerr << "Error in Set/Get Point2WorldPosition, expected " << pos[0] << ", " << pos[1] << ", " << pos[2] << " but got " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << std::endl;
123 return EXIT_FAILURE;
124 }
125 else
126 {
127 std::cout << "GetPoint2WorldPosition = " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << std::endl;
128 }
129
130 vtkSmartPointer<vtkPointHandleRepresentation3D> subHandleRep;
131 subHandleRep = node1->GetPoint1Representation();
132 subHandleRep = node1->GetPoint2Representation();
133 subHandleRep = node1->GetLineHandleRepresentation();
134
135 vtkSmartPointer<vtkProperty> prop = node1->GetEndPointProperty();
136 if (prop == nullptr)
137 {
138 std::cout << "End Point Property is nullptr." << std::endl;
139 }
140 prop = node1->GetSelectedEndPointProperty();
141 if (prop == nullptr)
142 {
143 std::cout << "Selected End Point Property is nullptr." << std::endl;
144 }
145
146 prop = node1->GetEndPoint2Property();
147 if (prop == nullptr)
148 {
149 std::cout << "End Point2 Property is nullptr." << std::endl;
150 }
151 prop = node1->GetSelectedEndPoint2Property();
152 if (prop == nullptr)
153 {
154 std::cout << "Selected End Point2 Property is nullptr." << std::endl;
155 }
156
157 prop = node1->GetLineProperty();
158 if (prop == nullptr)
159 {
160 std::cout << "Line Property is nullptr." << std::endl;
161 }
162 prop = node1->GetSelectedLineProperty();
163 if (prop == nullptr)
164 {
165 std::cout << "Selected Line Property is nullptr." << std::endl;
166 }
167
168 TEST_SET_GET_INT_RANGE(node1, Tolerance, 2, 99);
169 // 0 is invalid
170 TEST_SET_GET_INT_RANGE(node1, Resolution, 2, 100);
171
172 vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();
173 node1->GetPolyData(pd);
174 if (pd == nullptr)
175 {
176 std::cout << "Polydata is null" << std::endl;
177 }
178
179 // clamped 0-6
180 TEST_SET_GET_INT_RANGE(node1, InteractionState, 1, 5);
181 // fails on 0
182 TEST_SET_GET_INT_RANGE(node1, RepresentationState, 2, 5);
183
184 std::cout << "MTime = " << node1->GetMTime() << std::endl;
185
186 TEST_SET_GET_BOOLEAN(node1, DistanceAnnotationVisibility);
187 TEST_SET_GET_STRING(node1, DistanceAnnotationFormat);
188
189 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node1, DistanceAnnotationScale, 0.0, 100.0);
190
191 std::cout << "Distance = " << node1->GetDistance() << std::endl;
192
193 node1->SetLineColor(1.0, 0.5, 0.75);
194
195 prop = node1->GetDistanceAnnotationProperty();
196
197 vtkSmartPointer<vtkFollower> follower = node1->GetTextActor();
198
199 return EXIT_SUCCESS;
200 }
201