Medical Imaging Interaction Toolkit  2018.4.99-b7f3afaa
Medical Imaging Interaction Toolkit
mitkClippedSurfaceBoundsCalculatorTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkTestingMacros.h"
14 #include <iostream>
15 
17 #include "mitkGeometry3D.h"
18 #include "mitkNumericTypes.h"
19 #include "mitkPlaneGeometry.h"
20 
22 {
23  // Check planes which are inside the bounding box
24 
27  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
28 
29  // Check planes which are only on one slice:
30 
31  // Slice 0
32  mitk::Point3D origin;
33  origin[0] = 511;
34  origin[1] = 0;
35  origin[2] = 0;
36 
37  mitk::Vector3D normal;
38  mitk::FillVector3D(normal, 0, 0, 1);
39 
41  planeOnSliceZero->InitializePlane(origin, normal);
42 
43  calculator->SetInput(planeOnSliceZero, image);
44  calculator->Update();
45 
47 
48  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
49  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 0, "Check if plane is on slice 0");
50 
51  // Slice 3
52  origin[2] = 3;
53 
55  planeOnSliceThree->InitializePlane(origin, normal);
56  planeOnSliceThree->SetImageGeometry(false);
57 
58  calculator->SetInput(planeOnSliceThree, image);
59  calculator->Update();
60 
61  minMax = calculator->GetMinMaxSpatialDirectionZ();
62 
63  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
64  MITK_TEST_CONDITION(minMax.first == 3 && minMax.second == 3, "Check if plane is on slice 3");
65 
66  // Slice 17
67  origin[2] = 17;
68 
70  planeOnSliceSeventeen->InitializePlane(origin, normal);
71 
72  calculator->SetInput(planeOnSliceSeventeen, image);
73  calculator->Update();
74 
75  minMax = calculator->GetMinMaxSpatialDirectionZ();
76 
77  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
78  MITK_TEST_CONDITION(minMax.first == 17 && minMax.second == 17, "Check if plane is on slice 17");
79 
80  // Slice 20
81  origin[2] = 19;
82 
84  planeOnSliceTwenty->InitializePlane(origin, normal);
85 
86  calculator->SetInput(planeOnSliceTwenty, image);
87  calculator->Update();
88 
89  minMax = calculator->GetMinMaxSpatialDirectionZ();
90 
91  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
92  MITK_TEST_CONDITION(minMax.first == 19 && minMax.second == 19, "Check if plane is on slice 19");
93 
94  delete calculator;
95 }
96 
98 {
99  // Check planes which are inside the bounding box
100 
103  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
104 
105  // Check planes which are only on one slice:
106  // Slice 0
107  mitk::Point3D origin;
108  origin[0] = 510; // Set to 511.9 so that the intersection point is inside the bounding box
109  origin[1] = 0;
110  origin[2] = 0;
111 
112  mitk::Vector3D normal;
113  mitk::FillVector3D(normal, 1, 0, 0);
114 
116  planeSagittalOne->InitializePlane(origin, normal);
117 
118  calculator->SetInput(planeSagittalOne, image);
119  calculator->Update();
120 
122  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
123 
124  // Slice 3
125  origin[0] = 256;
126 
127  MITK_INFO << "Case1 origin: " << origin;
128 
130  planeSagittalTwo->InitializePlane(origin, normal);
131 
132  MITK_INFO << "PlaneNormal: " << planeSagittalTwo->GetNormal();
133  MITK_INFO << "PlaneOrigin: " << planeSagittalTwo->GetOrigin();
134 
135  calculator->SetInput(planeSagittalTwo, image);
136  calculator->Update();
137 
138  minMax = calculator->GetMinMaxSpatialDirectionZ();
139  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
140 
141  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
142 
143  // Slice 17
144  origin[0] = 0; // Set to 0.1 so that the intersection point is inside the bounding box
145 
146  mitk::PlaneGeometry::Pointer planeOnSliceSeventeen = mitk::PlaneGeometry::New();
147  planeOnSliceSeventeen->InitializePlane(origin, normal);
148 
149  calculator->SetInput(planeOnSliceSeventeen, image);
150  calculator->Update();
151 
152  minMax = calculator->GetMinMaxSpatialDirectionZ();
153  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
154 
155  // Crooked planes:
156  origin[0] = 0;
157  origin[1] = 507;
158  origin[2] = 0;
159 
160  normal[0] = 1;
161  normal[1] = -1;
162  normal[2] = 1;
163 
165  planeCrookedOne->InitializePlane(origin, normal);
166 
167  calculator->SetInput(planeCrookedOne, image);
168  calculator->Update();
169 
170  minMax = calculator->GetMinMaxSpatialDirectionZ();
171  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
172 
173  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 5,
174  "Check if plane is from slice 0 to slice 5 with inclined plane");
175 
176  origin[0] = 512;
177  origin[1] = 0;
178  origin[2] = 16;
179 
181  planeCrookedTwo->InitializePlane(origin, normal);
182 
183  calculator->SetInput(planeCrookedTwo, image);
184  calculator->Update();
185 
186  minMax = calculator->GetMinMaxSpatialDirectionZ();
187  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
188 
189  MITK_TEST_CONDITION(minMax.first == 16 && minMax.second == 19,
190  "Check if plane is from slice 16 to slice 19 with inclined plane");
191 
192  origin[0] = 510;
193  origin[1] = 0;
194  origin[2] = 0;
195 
196  normal[1] = 0;
197  normal[2] = 0.04;
198 
200  planeCrookedThree->InitializePlane(origin, normal);
201 
202  calculator->SetInput(planeCrookedThree, image);
203  calculator->Update();
204 
205  minMax = calculator->GetMinMaxSpatialDirectionZ();
206  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
207 
208  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19,
209  "Check if plane is from slice 0 to slice 19 with inclined plane");
210 
211  delete calculator;
212 }
213 
215 {
216  // Check planes which are outside of the bounding box
217 
220  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
221 
222  // In front of the bounding box
223  mitk::Point3D origin;
224  origin[0] = 510;
225  origin[1] = 0;
226  origin[2] = -5;
227 
228  mitk::Vector3D normal;
229  mitk::FillVector3D(normal, 0, 0, 1);
230 
232  planeInFront->InitializePlane(origin, normal);
233 
234  calculator->SetInput(planeInFront, image);
235  calculator->Update();
236 
238 
239  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
240  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
241 
242  // Behind the bounding box
243  origin[2] = 515;
244 
246  planeBehind->InitializePlane(origin, normal);
247 
248  calculator->SetInput(planeBehind, image);
249  calculator->Update();
250 
251  minMax = calculator->GetMinMaxSpatialDirectionZ();
252 
253  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
254  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
255 
256  // Above
257  origin[1] = 515;
258 
259  mitk::FillVector3D(normal, 0, 1, 0);
260 
262  planeAbove->InitializePlane(origin, normal);
263 
264  calculator->SetInput(planeAbove, image);
265  calculator->Update();
266 
267  minMax = calculator->GetMinMaxSpatialDirectionZ();
268 
269  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
270  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
271 
272  // Below
273  origin[1] = -5;
274 
276  planeBelow->InitializePlane(origin, normal);
277 
278  calculator->SetInput(planeBelow, image);
279  calculator->Update();
280 
281  minMax = calculator->GetMinMaxSpatialDirectionZ();
282 
283  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
284  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
285 
286  // Left side
287  origin[0] = -5;
288 
289  mitk::FillVector3D(normal, 1, 0, 0);
290 
292  planeLeftSide->InitializePlane(origin, normal);
293 
294  calculator->SetInput(planeLeftSide, image);
295  calculator->Update();
296 
297  minMax = calculator->GetMinMaxSpatialDirectionZ();
298 
299  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
300  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
301 
302  // Right side
303  origin[1] = 515;
304 
306  planeRightSide->InitializePlane(origin, normal);
307 
308  calculator->SetInput(planeRightSide, image);
309  calculator->Update();
310 
311  minMax = calculator->GetMinMaxSpatialDirectionZ();
312 
313  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
314  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
315 
316  delete calculator;
317 }
318 
320  mitk::BaseGeometry::Pointer secondGeometry3D)
321 {
323  mitk::Image::Pointer firstImage = mitk::Image::New();
324  firstImage->Initialize(mitk::MakePixelType<int, int, 1>(), *(firstGeometry3D.GetPointer()));
325 
326  calculator->SetInput(secondGeometry3D, firstImage);
327  calculator->Update();
328 
329  auto minMax = calculator->GetMinMaxSpatialDirectionZ();
330  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
331 
332  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
333  delete calculator;
334 }
335 
337 {
338  // Check planes which are inside the bounding box
339 
341  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
342 
343  {
344  mitk::Point3D pnt1, pnt2;
345  pnt1[0] = 3;
346  pnt1[1] = 5;
347  pnt1[2] = 3;
348  pnt2[0] = 8;
349  pnt2[1] = 3;
350  pnt2[2] = 8;
351 
353  pointlist.push_back(pnt1);
354  pointlist.push_back(pnt2);
355 
357  calculator.SetInput(pointlist, image);
358  calculator.Update();
359 
361  MITK_TEST_CONDITION(minMaxZ.first == 3 && minMaxZ.second == 8,
362  "Check if points span from slice 3 to slice 8 in axial");
363 
365  MITK_TEST_CONDITION(minMaxX.first == 3 && minMaxX.second == 5,
366  "Check if points span from slice 3 to slice 5 in sagittal");
367  }
368 
369  {
370  mitk::Point3D pnt1, pnt2;
371  pnt1.Fill(-3);
372  pnt2.Fill(600);
373 
375  pointlist.push_back(pnt1);
376  pointlist.push_back(pnt2);
377 
379  calculator.SetInput(pointlist, image);
380  calculator.Update();
381 
383  MITK_TEST_CONDITION(minMaxZ.first == 0 && minMaxZ.second == 19,
384  "Check if points are correctly clipped to slice 0 and slice 19 in axial");
385 
387  MITK_TEST_CONDITION(minMaxX.first == 0 && minMaxX.second == 511,
388  "Check if points are correctly clipped to slice 0 and slice 511 in sagittal");
389  }
390 }
391 
393 {
394  // Define origin for second Geometry3D;
395  mitk::Point3D origin3;
396  origin3[0] = -45.25;
397  origin3[1] = -113.22;
398  origin3[2] = 0.62;
399 
400  // Define normal:
401  mitk::Vector3D normal3;
402  normal3[0] = -0.02;
403  normal3[1] = -0.18;
404  normal3[2] = 2.99;
405 
406  mitk::Vector3D spacing;
407  spacing[0] = 1.43;
408  spacing[1] = 1.43;
409  spacing[2] = 3.0;
410 
411  // Initialize PlaneGeometry:
413  planeGeometry3->InitializePlane(origin3, normal3);
414  planeGeometry3->SetSpacing(spacing);
415 
416  mitk::BoundingBox::BoundsArrayType moreBounds = planeGeometry3->GetBounds();
417  moreBounds[0] = 0;
418  moreBounds[1] = 64;
419  moreBounds[2] = 0;
420  moreBounds[3] = 140;
421  moreBounds[4] = 0;
422  moreBounds[5] = 1;
423  planeGeometry3->SetBounds(moreBounds);
424 
425  // Initialize SlicedGeometry3D:
427  rotatedSlicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry3.GetPointer()), 25);
428  rotatedSlicedGeometry3D->SetImageGeometry(true);
429  mitk::AffineTransform3D *geom = rotatedSlicedGeometry3D->GetIndexToWorldTransform();
430 
431  mitk::AffineTransform3D::MatrixType matrix;
432  matrix[0][0] = 1.43;
433  matrix[0][1] = -0.01;
434  matrix[0][2] = -0.02;
435 
436  matrix[0][0] = 0.01;
437  matrix[1][1] = 1.43;
438  matrix[2][2] = -0.18;
439 
440  matrix[0][0] = 0.01;
441  matrix[1][1] = 0.08;
442  matrix[2][2] = 2.99;
443  geom->SetMatrix(matrix);
444 
447  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(rotatedSlicedGeometry3D.GetPointer()));
448 
449  // Check planes which are only on one slice:
450 
451  {
452  // last Slice
453  mitk::Point3D origin;
454  origin[0] = -47.79;
455  origin[1] = 81.41;
456  origin[2] = 84.34;
457 
458  mitk::Vector3D normal;
459  mitk::FillVector3D(normal, 0.02, 0.18, -2.99);
460 
461  mitk::Vector3D spacing;
462  spacing[0] = 1.43;
463  spacing[1] = 1.43;
464  spacing[2] = 3.0;
465 
467  planeOnSliceZero->InitializePlane(origin, normal);
468  planeOnSliceZero->SetSpacing(spacing);
469 
470  calculator->SetInput(planeOnSliceZero, image);
471  calculator->Update();
472 
474 
475  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
476  MITK_TEST_CONDITION(minMax.first == 24 && minMax.second == 24, "Check if plane is on slice 24");
477  }
478 
479  {
480  // Slice 0-24
481  mitk::Point3D origin;
482  origin[0] = -45;
483  origin[1] = -105;
484  origin[2] = 35;
485 
486  mitk::Vector3D normal;
487  mitk::FillVector3D(normal, 1.43, 0.01, 0.01);
488 
489  mitk::Vector3D spacing;
490  spacing[0] = 1.43;
491  spacing[1] = 3.0;
492  spacing[2] = 1.43;
493 
495  planeOnSliceZero->InitializePlane(origin, normal);
496  planeOnSliceZero->SetSpacing(spacing);
497 
498  calculator->SetInput(planeOnSliceZero, image);
499  calculator->Update();
500 
502 
503  MITK_TEST_CONDITION(minMax.first != minMax.second, "Check if plane is only on one slice");
504  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 24, "Check if plane is on slices 0-24");
505  }
506 
507  delete calculator;
508 }
509 
511 {
512  // Define origin for second Geometry3D;
513  mitk::Point3D origin3;
514  origin3[0] = 0.0;
515  origin3[1] = 0.0;
516  origin3[2] = 0.0;
517 
518  // Define normal:
519  mitk::Vector3D normal3;
520  normal3[0] = 0;
521  normal3[1] = 0;
522  normal3[2] = 1;
523 
524  mitk::Vector3D spacing;
525  spacing[0] = 1.0;
526  spacing[1] = 2.0;
527  spacing[2] = 1.0;
528 
529  // Initialize PlaneGeometry:
531  planeGeometry3->InitializePlane(origin3, normal3);
532  planeGeometry3->SetSpacing(spacing);
533 
534  mitk::BoundingBox::BoundsArrayType moreBounds = planeGeometry3->GetBounds();
535  moreBounds[0] = 0;
536  moreBounds[1] = 50;
537  moreBounds[2] = 0;
538  moreBounds[3] = 50;
539  moreBounds[4] = 0;
540  moreBounds[5] = 1;
541  planeGeometry3->SetBounds(moreBounds);
542 
543  // Initialize SlicedGeometry3D:
545  rotatedSlicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry3.GetPointer()), 50);
546  rotatedSlicedGeometry3D->SetImageGeometry(true);
547 
548  // Set the rotation to zero (identity times spacing matrix) because the default makes a rotation
549  mitk::AffineTransform3D *geom = rotatedSlicedGeometry3D->GetIndexToWorldTransform();
550 
551  mitk::AffineTransform3D::MatrixType matrix;
552  matrix[0][0] = spacing[0];
553  matrix[0][1] = 0.0;
554  matrix[0][2] = 0.0;
555 
556  matrix[1][0] = 0.0;
557  matrix[1][1] = spacing[1];
558  matrix[1][2] = 0.0;
559 
560  matrix[2][0] = 0.0;
561  matrix[2][1] = 0.0;
562  matrix[2][2] = spacing[2];
563  geom->SetMatrix(matrix);
564 
567  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(rotatedSlicedGeometry3D.GetPointer()));
568 
569  // construct the planes in y direction
570  {
571  // first Slice in Y direction
572  mitk::Point3D originFirstSlice;
573  originFirstSlice[0] = 0.0;
574  originFirstSlice[1] = -1.0;
575  originFirstSlice[2] = 0.0;
576 
577  mitk::Vector3D normalFitrstSlice;
578  mitk::FillVector3D(normalFitrstSlice, 0.0, 1.0, 0.0);
579 
580  mitk::Vector3D spacingFirstSlice;
581  spacingFirstSlice[0] = 1.0;
582  spacingFirstSlice[1] = 1.0;
583  spacingFirstSlice[2] = 1.0;
584 
586  planeOnFirstSlice->InitializePlane(originFirstSlice, normalFitrstSlice);
587  planeOnFirstSlice->SetSpacing(spacingFirstSlice);
588 
589  // last Slice in Y Direction
590  mitk::Point3D originLastSlice;
591  originLastSlice[0] = 0.0;
592  originLastSlice[1] = 99.0;
593  originLastSlice[2] = 0.0;
594 
595  mitk::Vector3D normalLastSlice;
596  mitk::FillVector3D(normalLastSlice, 0.0, 1.0, 0.0);
597 
598  mitk::Vector3D spacingLastSlice;
599  spacingLastSlice[0] = 1.0;
600  spacingLastSlice[1] = 1.0;
601  spacingLastSlice[2] = 1.0;
602 
604  planeOnLastSlice->InitializePlane(originLastSlice, normalLastSlice);
605  planeOnLastSlice->SetSpacing(spacingLastSlice);
606 
607  // calculate the intersection on the last slice
608  calculator->SetInput(planeOnLastSlice, image);
609  calculator->Update();
610 
612 
613  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
614  MITK_TEST_CONDITION(minMax.first == 49 && minMax.second == 49, "Check if plane is on slice 49");
615  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
616 
617  // calculate the intersection on the first slice
618  calculator->SetInput(planeOnFirstSlice, image);
619  calculator->Update();
620 
621  minMax = calculator->GetMinMaxSpatialDirectionY();
622 
623  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
624  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 0, "Check if plane is on slice 0");
625  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
626  }
627 
628  // now we make a rotation of the Image about 270 degrees around Z Axis to get an aligment on the positiv x axis
629  double angleInDegrees = 270 * itk::Math::pi / 180;
630 
631  mitk::AffineTransform3D::MatrixType matrix2;
632  matrix2[0][0] = cos(angleInDegrees);
633  matrix2[0][1] = -sin(angleInDegrees);
634  matrix2[0][2] = 0.0;
635 
636  matrix2[1][0] = sin(angleInDegrees);
637  matrix2[1][1] = cos(angleInDegrees);
638  matrix2[1][2] = 0.0;
639 
640  matrix2[2][0] = 0.0;
641  matrix2[2][1] = 0.0;
642  matrix2[2][2] = 1.0;
643 
644  // multiplie the identity with the transformation matrix
645  mitk::AffineTransform3D::MatrixType TransformationMatrix = matrix2 * matrix;
646 
647  // initialize the image with the new rotation Matrix
648  geom->SetMatrix(TransformationMatrix);
649  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(rotatedSlicedGeometry3D.GetPointer()));
650 
651  {
652  // first Slice in X Diection
653  mitk::Point3D originFirstSlice;
654  originFirstSlice[0] = -1.0;
655  originFirstSlice[1] = 0.0;
656  originFirstSlice[2] = 0.0;
657 
658  mitk::Vector3D normalFitrstSlice;
659  mitk::FillVector3D(normalFitrstSlice, 1.0, 0.0, 0.0);
660 
661  mitk::Vector3D spacingFirstSlice;
662  spacingFirstSlice[0] = 1.0;
663  spacingFirstSlice[1] = 1.0;
664  spacingFirstSlice[2] = 1.0;
665 
667  planeOnFirstSlice->InitializePlane(originFirstSlice, normalFitrstSlice);
668  planeOnFirstSlice->SetSpacing(spacingFirstSlice);
669 
670  // last Slice in X Direction
671  mitk::Point3D originLastSlice;
672  originLastSlice[0] = 99.0;
673  originLastSlice[1] = 0.0;
674  originLastSlice[2] = 0.0;
675 
676  mitk::Vector3D normalLastSlice;
677  mitk::FillVector3D(normalLastSlice, 1.0, 0.0, 0.0);
678 
679  mitk::Vector3D spacingLastSlice;
680  spacingLastSlice[0] = 1.0;
681  spacingLastSlice[1] = 1.0;
682  spacingLastSlice[2] = 1.0;
683 
685  planeOnLastSlice->InitializePlane(originLastSlice, normalLastSlice);
686  planeOnLastSlice->SetSpacing(spacingLastSlice);
687 
688  calculator->SetInput(planeOnLastSlice, image);
689  calculator->Update();
690 
692 
693  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
694  MITK_TEST_CONDITION(minMax.first == 49 && minMax.second == 49, "Check if plane is on slice 49");
695  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
696 
697  calculator->SetInput(planeOnFirstSlice, image);
698  calculator->Update();
699 
700  minMax = calculator->GetMinMaxSpatialDirectionY();
701 
702  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
703  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 0, "Check if plane is on slice 0");
704  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
705  }
706 
707  delete calculator;
708 }
709 
711 {
712  // always start with this!
713  MITK_TEST_BEGIN("ClippedSurfaceBoundsCalculator");
714 
728  /********************* Define Geometry3D ***********************/
729  // Define origin:
730  mitk::Point3D origin;
731  origin[0] = 511;
732  origin[1] = 0;
733  origin[2] = 0;
734 
735  // Define normal:
736  mitk::Vector3D normal;
737  mitk::FillVector3D(normal, 0, 0, 1);
738 
739  // Initialize PlaneGeometry:
741  planeGeometry->InitializePlane(origin, normal);
742 
743  // Set Bounds:
744  mitk::BoundingBox::BoundsArrayType bounds = planeGeometry->GetBounds();
745  bounds[0] = 0;
746  bounds[1] = 512;
747  bounds[2] = 0;
748  bounds[3] = 512;
749  bounds[4] = 0;
750  bounds[5] = 1;
751  planeGeometry->SetBounds(bounds);
752 
753  // Initialize SlicedGeometry3D:
755  slicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry.GetPointer()), 20);
756  mitk::BaseGeometry::Pointer geometry3D = dynamic_cast<mitk::BaseGeometry *>(slicedGeometry3D.GetPointer());
757  geometry3D->SetImageGeometry(true);
758 
759  // Define origin for second Geometry3D;
760  mitk::Point3D origin2;
761  origin2[0] = 511;
762  origin2[1] = 60;
763  origin2[2] = 0;
764 
765  // Define normal:
766  mitk::Vector3D normal2;
767  mitk::FillVector3D(normal2, 0, 1, 0);
768 
769  // Initialize PlaneGeometry:
771  planeGeometry2->InitializePlane(origin2, normal2);
772 
773  // Initialize SlicedGeometry3D:
775  secondSlicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry2.GetPointer()), 20);
776  mitk::BaseGeometry::Pointer secondGeometry3D =
777  dynamic_cast<mitk::BaseGeometry *>(secondSlicedGeometry3D.GetPointer());
778  secondGeometry3D->SetImageGeometry(true);
779 
780  /***************************************************************/
781 
784  CheckPlanesInsideBoundingBox(geometry3D);
785  CheckIntersectionPointsOfTwoGeometry3D(geometry3D, secondGeometry3D);
789 
794  MITK_TEST_END();
795 }
OutputType GetMinMaxSpatialDirectionZ()
What Z coordinates (slice indices) are cut/visible in given plane.
static void CheckIntersectionWithRotatedGeometry()
#define MITK_INFO
Definition: mitkLogMacros.h:18
void SetInput(const mitk::PlaneGeometry *geometry, mitk::Image *image)
static Pointer New()
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static void CheckPlanesInsideBoundingBox(mitk::BaseGeometry::Pointer geometry3D)
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:106
static void CheckIntersectionWithPointCloud(mitk::BaseGeometry::Pointer geometry3D)
#define MITK_TEST_CONDITION(COND, MSG)
static void CheckPlanesOutsideOfBoundingBox(mitk::BaseGeometry::Pointer geometry3D)
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
static T max(T x, T y)
Definition: svm.cpp:56
mitk::Image::Pointer image
static Pointer New()
static void CheckIntersectionWithRotatedGeometry90()
static T min(T x, T y)
Definition: svm.cpp:53
int mitkClippedSurfaceBoundsCalculatorTest(int, char *[])
static Pointer New()
OutputType GetMinMaxSpatialDirectionY()
What Y coordinates (slice indices) are cut/visible in given plane.
static void CheckPlanesInsideBoundingBoxOnlyOnOneSlice(mitk::BaseGeometry::Pointer geometry3D)
OutputType GetMinMaxSpatialDirectionX()
What X coordinates (slice indices) are cut/visible in given plane.
and MITK_TEST_END()
BaseGeometry Describes the geometry of a data object.
std::pair< int, int > OutputType
Minimum (first) and maximum (second) slice index.
BoundingBoxType::BoundsArrayType BoundsArrayType
static void CheckIntersectionPointsOfTwoGeometry3D(mitk::BaseGeometry::Pointer firstGeometry3D, mitk::BaseGeometry::Pointer secondGeometry3D)