Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkTestingMacros.h"
18 #define _USE_MATH_DEFINES
19 #include <iostream>
20 
22 #include "mitkGeometry3D.h"
23 #include "mitkNumericTypes.h"
24 #include "mitkPlaneGeometry.h"
25 
26 #include <cmath>
27 
29 {
30  // Check planes which are inside the bounding box
31 
34  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
35 
36  // Check planes which are only on one slice:
37 
38  // Slice 0
39  mitk::Point3D origin;
40  origin[0] = 511;
41  origin[1] = 0;
42  origin[2] = 0;
43 
44  mitk::Vector3D normal;
45  mitk::FillVector3D(normal, 0, 0, 1);
46 
48  planeOnSliceZero->InitializePlane(origin, normal);
49 
50  calculator->SetInput(planeOnSliceZero, image);
51  calculator->Update();
52 
54 
55  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
56  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 0, "Check if plane is on slice 0");
57 
58  // Slice 3
59  origin[2] = 3;
60 
62  planeOnSliceThree->InitializePlane(origin, normal);
63  planeOnSliceThree->SetImageGeometry(false);
64 
65  calculator->SetInput(planeOnSliceThree, image);
66  calculator->Update();
67 
68  minMax = calculator->GetMinMaxSpatialDirectionZ();
69 
70  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
71  MITK_TEST_CONDITION(minMax.first == 3 && minMax.second == 3, "Check if plane is on slice 3");
72 
73  // Slice 17
74  origin[2] = 17;
75 
77  planeOnSliceSeventeen->InitializePlane(origin, normal);
78 
79  calculator->SetInput(planeOnSliceSeventeen, image);
80  calculator->Update();
81 
82  minMax = calculator->GetMinMaxSpatialDirectionZ();
83 
84  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
85  MITK_TEST_CONDITION(minMax.first == 17 && minMax.second == 17, "Check if plane is on slice 17");
86 
87  // Slice 20
88  origin[2] = 19;
89 
91  planeOnSliceTwenty->InitializePlane(origin, normal);
92 
93  calculator->SetInput(planeOnSliceTwenty, image);
94  calculator->Update();
95 
96  minMax = calculator->GetMinMaxSpatialDirectionZ();
97 
98  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
99  MITK_TEST_CONDITION(minMax.first == 19 && minMax.second == 19, "Check if plane is on slice 19");
100 
101  delete calculator;
102 }
103 
105 {
106  // Check planes which are inside the bounding box
107 
110  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
111 
112  // Check planes which are only on one slice:
113  // Slice 0
114  mitk::Point3D origin;
115  origin[0] = 510; // Set to 511.9 so that the intersection point is inside the bounding box
116  origin[1] = 0;
117  origin[2] = 0;
118 
119  mitk::Vector3D normal;
120  mitk::FillVector3D(normal, 1, 0, 0);
121 
123  planeSagittalOne->InitializePlane(origin, normal);
124 
125  calculator->SetInput(planeSagittalOne, image);
126  calculator->Update();
127 
129  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
130 
131  // Slice 3
132  origin[0] = 256;
133 
134  MITK_INFO << "Case1 origin: " << origin;
135 
137  planeSagittalTwo->InitializePlane(origin, normal);
138 
139  MITK_INFO << "PlaneNormal: " << planeSagittalTwo->GetNormal();
140  MITK_INFO << "PlaneOrigin: " << planeSagittalTwo->GetOrigin();
141 
142  calculator->SetInput(planeSagittalTwo, image);
143  calculator->Update();
144 
145  minMax = calculator->GetMinMaxSpatialDirectionZ();
146  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
147 
148  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
149 
150  // Slice 17
151  origin[0] = 0; // Set to 0.1 so that the intersection point is inside the bounding box
152 
153  mitk::PlaneGeometry::Pointer planeOnSliceSeventeen = mitk::PlaneGeometry::New();
154  planeOnSliceSeventeen->InitializePlane(origin, normal);
155 
156  calculator->SetInput(planeOnSliceSeventeen, image);
157  calculator->Update();
158 
159  minMax = calculator->GetMinMaxSpatialDirectionZ();
160  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
161 
162  // Crooked planes:
163  origin[0] = 0;
164  origin[1] = 507;
165  origin[2] = 0;
166 
167  normal[0] = 1;
168  normal[1] = -1;
169  normal[2] = 1;
170 
172  planeCrookedOne->InitializePlane(origin, normal);
173 
174  calculator->SetInput(planeCrookedOne, image);
175  calculator->Update();
176 
177  minMax = calculator->GetMinMaxSpatialDirectionZ();
178  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
179 
180  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 5,
181  "Check if plane is from slice 0 to slice 5 with inclined plane");
182 
183  origin[0] = 512;
184  origin[1] = 0;
185  origin[2] = 16;
186 
188  planeCrookedTwo->InitializePlane(origin, normal);
189 
190  calculator->SetInput(planeCrookedTwo, image);
191  calculator->Update();
192 
193  minMax = calculator->GetMinMaxSpatialDirectionZ();
194  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
195 
196  MITK_TEST_CONDITION(minMax.first == 16 && minMax.second == 19,
197  "Check if plane is from slice 16 to slice 19 with inclined plane");
198 
199  origin[0] = 510;
200  origin[1] = 0;
201  origin[2] = 0;
202 
203  normal[1] = 0;
204  normal[2] = 0.04;
205 
207  planeCrookedThree->InitializePlane(origin, normal);
208 
209  calculator->SetInput(planeCrookedThree, image);
210  calculator->Update();
211 
212  minMax = calculator->GetMinMaxSpatialDirectionZ();
213  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
214 
215  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19,
216  "Check if plane is from slice 0 to slice 19 with inclined plane");
217 
218  delete calculator;
219 }
220 
222 {
223  // Check planes which are outside of the bounding box
224 
227  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
228 
229  // In front of the bounding box
230  mitk::Point3D origin;
231  origin[0] = 510;
232  origin[1] = 0;
233  origin[2] = -5;
234 
235  mitk::Vector3D normal;
236  mitk::FillVector3D(normal, 0, 0, 1);
237 
239  planeInFront->InitializePlane(origin, normal);
240 
241  calculator->SetInput(planeInFront, image);
242  calculator->Update();
243 
245 
246  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
247  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
248 
249  // Behind the bounding box
250  origin[2] = 515;
251 
253  planeBehind->InitializePlane(origin, normal);
254 
255  calculator->SetInput(planeBehind, image);
256  calculator->Update();
257 
258  minMax = calculator->GetMinMaxSpatialDirectionZ();
259 
260  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
261  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
262 
263  // Above
264  origin[1] = 515;
265 
266  mitk::FillVector3D(normal, 0, 1, 0);
267 
269  planeAbove->InitializePlane(origin, normal);
270 
271  calculator->SetInput(planeAbove, image);
272  calculator->Update();
273 
274  minMax = calculator->GetMinMaxSpatialDirectionZ();
275 
276  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
277  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
278 
279  // Below
280  origin[1] = -5;
281 
283  planeBelow->InitializePlane(origin, normal);
284 
285  calculator->SetInput(planeBelow, image);
286  calculator->Update();
287 
288  minMax = calculator->GetMinMaxSpatialDirectionZ();
289 
290  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
291  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
292 
293  // Left side
294  origin[0] = -5;
295 
296  mitk::FillVector3D(normal, 1, 0, 0);
297 
299  planeLeftSide->InitializePlane(origin, normal);
300 
301  calculator->SetInput(planeLeftSide, image);
302  calculator->Update();
303 
304  minMax = calculator->GetMinMaxSpatialDirectionZ();
305 
306  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
307  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
308 
309  // Right side
310  origin[1] = 515;
311 
313  planeRightSide->InitializePlane(origin, normal);
314 
315  calculator->SetInput(planeRightSide, image);
316  calculator->Update();
317 
318  minMax = calculator->GetMinMaxSpatialDirectionZ();
319 
320  MITK_TEST_CONDITION(minMax.first == std::numeric_limits<int>::max(), "Check if min value hasn't been set");
321  MITK_TEST_CONDITION(minMax.second == std::numeric_limits<int>::min(), "Check if max value hasn't been set");
322 
323  delete calculator;
324 }
325 
327  mitk::BaseGeometry::Pointer secondGeometry3D)
328 {
330  mitk::Image::Pointer firstImage = mitk::Image::New();
331  firstImage->Initialize(mitk::MakePixelType<int, int, 1>(), *(firstGeometry3D.GetPointer()));
332 
333  calculator->SetInput(secondGeometry3D, firstImage);
334  calculator->Update();
335 
336  auto minMax = calculator->GetMinMaxSpatialDirectionZ();
337  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
338 
339  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 19, "Check if plane is from slice 0 to slice 19");
340  delete calculator;
341 }
342 
344 {
345  // Check planes which are inside the bounding box
346 
348  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(geometry3D.GetPointer()));
349 
350  {
351  mitk::Point3D pnt1, pnt2;
352  pnt1[0] = 3;
353  pnt1[1] = 5;
354  pnt1[2] = 3;
355  pnt2[0] = 8;
356  pnt2[1] = 3;
357  pnt2[2] = 8;
358 
360  pointlist.push_back(pnt1);
361  pointlist.push_back(pnt2);
362 
364  calculator.SetInput(pointlist, image);
365  calculator.Update();
366 
368  MITK_TEST_CONDITION(minMaxZ.first == 3 && minMaxZ.second == 8,
369  "Check if points span from slice 3 to slice 8 in axial");
370 
372  MITK_TEST_CONDITION(minMaxX.first == 3 && minMaxX.second == 5,
373  "Check if points span from slice 3 to slice 5 in sagittal");
374  }
375 
376  {
377  mitk::Point3D pnt1, pnt2;
378  pnt1.Fill(-3);
379  pnt2.Fill(600);
380 
382  pointlist.push_back(pnt1);
383  pointlist.push_back(pnt2);
384 
386  calculator.SetInput(pointlist, image);
387  calculator.Update();
388 
390  MITK_TEST_CONDITION(minMaxZ.first == 0 && minMaxZ.second == 19,
391  "Check if points are correctly clipped to slice 0 and slice 19 in axial");
392 
394  MITK_TEST_CONDITION(minMaxX.first == 0 && minMaxX.second == 511,
395  "Check if points are correctly clipped to slice 0 and slice 511 in sagittal");
396  }
397 }
398 
400 {
401  // Define origin for second Geometry3D;
402  mitk::Point3D origin3;
403  origin3[0] = -45.25;
404  origin3[1] = -113.22;
405  origin3[2] = 0.62;
406 
407  // Define normal:
408  mitk::Vector3D normal3;
409  normal3[0] = -0.02;
410  normal3[1] = -0.18;
411  normal3[2] = 2.99;
412 
413  mitk::Vector3D spacing;
414  spacing[0] = 1.43;
415  spacing[1] = 1.43;
416  spacing[2] = 3.0;
417 
418  // Initialize PlaneGeometry:
420  planeGeometry3->InitializePlane(origin3, normal3);
421  planeGeometry3->SetSpacing(spacing);
422 
423  mitk::BoundingBox::BoundsArrayType moreBounds = planeGeometry3->GetBounds();
424  moreBounds[0] = 0;
425  moreBounds[1] = 64;
426  moreBounds[2] = 0;
427  moreBounds[3] = 140;
428  moreBounds[4] = 0;
429  moreBounds[5] = 1;
430  planeGeometry3->SetBounds(moreBounds);
431 
432  // Initialize SlicedGeometry3D:
434  rotatedSlicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry3.GetPointer()), 25);
435  rotatedSlicedGeometry3D->SetImageGeometry(true);
436  mitk::AffineTransform3D *geom = rotatedSlicedGeometry3D->GetIndexToWorldTransform();
437 
438  mitk::AffineTransform3D::MatrixType matrix;
439  matrix[0][0] = 1.43;
440  matrix[0][1] = -0.01;
441  matrix[0][2] = -0.02;
442 
443  matrix[0][0] = 0.01;
444  matrix[1][1] = 1.43;
445  matrix[2][2] = -0.18;
446 
447  matrix[0][0] = 0.01;
448  matrix[1][1] = 0.08;
449  matrix[2][2] = 2.99;
450  geom->SetMatrix(matrix);
451 
454  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(rotatedSlicedGeometry3D.GetPointer()));
455 
456  // Check planes which are only on one slice:
457 
458  {
459  // last Slice
460  mitk::Point3D origin;
461  origin[0] = -47.79;
462  origin[1] = 81.41;
463  origin[2] = 84.34;
464 
465  mitk::Vector3D normal;
466  mitk::FillVector3D(normal, 0.02, 0.18, -2.99);
467 
468  mitk::Vector3D spacing;
469  spacing[0] = 1.43;
470  spacing[1] = 1.43;
471  spacing[2] = 3.0;
472 
474  planeOnSliceZero->InitializePlane(origin, normal);
475  planeOnSliceZero->SetSpacing(spacing);
476 
477  calculator->SetInput(planeOnSliceZero, image);
478  calculator->Update();
479 
481 
482  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
483  MITK_TEST_CONDITION(minMax.first == 24 && minMax.second == 24, "Check if plane is on slice 24");
484  }
485 
486  {
487  // Slice 0-24
488  mitk::Point3D origin;
489  origin[0] = -45;
490  origin[1] = -105;
491  origin[2] = 35;
492 
493  mitk::Vector3D normal;
494  mitk::FillVector3D(normal, 1.43, 0.01, 0.01);
495 
496  mitk::Vector3D spacing;
497  spacing[0] = 1.43;
498  spacing[1] = 3.0;
499  spacing[2] = 1.43;
500 
502  planeOnSliceZero->InitializePlane(origin, normal);
503  planeOnSliceZero->SetSpacing(spacing);
504 
505  calculator->SetInput(planeOnSliceZero, image);
506  calculator->Update();
507 
509 
510  MITK_TEST_CONDITION(minMax.first != minMax.second, "Check if plane is only on one slice");
511  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 24, "Check if plane is on slices 0-24");
512  }
513 
514  delete calculator;
515 }
516 
518 {
519  // Define origin for second Geometry3D;
520  mitk::Point3D origin3;
521  origin3[0] = 0.0;
522  origin3[1] = 0.0;
523  origin3[2] = 0.0;
524 
525  // Define normal:
526  mitk::Vector3D normal3;
527  normal3[0] = 0;
528  normal3[1] = 0;
529  normal3[2] = 1;
530 
531  mitk::Vector3D spacing;
532  spacing[0] = 1.0;
533  spacing[1] = 2.0;
534  spacing[2] = 1.0;
535 
536  // Initialize PlaneGeometry:
538  planeGeometry3->InitializePlane(origin3, normal3);
539  planeGeometry3->SetSpacing(spacing);
540 
541  mitk::BoundingBox::BoundsArrayType moreBounds = planeGeometry3->GetBounds();
542  moreBounds[0] = 0;
543  moreBounds[1] = 50;
544  moreBounds[2] = 0;
545  moreBounds[3] = 50;
546  moreBounds[4] = 0;
547  moreBounds[5] = 1;
548  planeGeometry3->SetBounds(moreBounds);
549 
550  // Initialize SlicedGeometry3D:
552  rotatedSlicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry3.GetPointer()), 50);
553  rotatedSlicedGeometry3D->SetImageGeometry(true);
554 
555  // Set the rotation to zero (identity times spacing matrix) because the default makes a rotation
556  mitk::AffineTransform3D *geom = rotatedSlicedGeometry3D->GetIndexToWorldTransform();
557 
558  mitk::AffineTransform3D::MatrixType matrix;
559  matrix[0][0] = spacing[0];
560  matrix[0][1] = 0.0;
561  matrix[0][2] = 0.0;
562 
563  matrix[1][0] = 0.0;
564  matrix[1][1] = spacing[1];
565  matrix[1][2] = 0.0;
566 
567  matrix[2][0] = 0.0;
568  matrix[2][1] = 0.0;
569  matrix[2][2] = spacing[2];
570  geom->SetMatrix(matrix);
571 
574  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(rotatedSlicedGeometry3D.GetPointer()));
575 
576  // construct the planes in y direction
577  {
578  // first Slice in Y direction
579  mitk::Point3D originFirstSlice;
580  originFirstSlice[0] = 0.0;
581  originFirstSlice[1] = -1.0;
582  originFirstSlice[2] = 0.0;
583 
584  mitk::Vector3D normalFitrstSlice;
585  mitk::FillVector3D(normalFitrstSlice, 0.0, 1.0, 0.0);
586 
587  mitk::Vector3D spacingFirstSlice;
588  spacingFirstSlice[0] = 1.0;
589  spacingFirstSlice[1] = 1.0;
590  spacingFirstSlice[2] = 1.0;
591 
593  planeOnFirstSlice->InitializePlane(originFirstSlice, normalFitrstSlice);
594  planeOnFirstSlice->SetSpacing(spacingFirstSlice);
595 
596  // last Slice in Y Direction
597  mitk::Point3D originLastSlice;
598  originLastSlice[0] = 0.0;
599  originLastSlice[1] = 99.0;
600  originLastSlice[2] = 0.0;
601 
602  mitk::Vector3D normalLastSlice;
603  mitk::FillVector3D(normalLastSlice, 0.0, 1.0, 0.0);
604 
605  mitk::Vector3D spacingLastSlice;
606  spacingLastSlice[0] = 1.0;
607  spacingLastSlice[1] = 1.0;
608  spacingLastSlice[2] = 1.0;
609 
611  planeOnLastSlice->InitializePlane(originLastSlice, normalLastSlice);
612  planeOnLastSlice->SetSpacing(spacingLastSlice);
613 
614  // calculate the intersection on the last slice
615  calculator->SetInput(planeOnLastSlice, image);
616  calculator->Update();
617 
619 
620  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
621  MITK_TEST_CONDITION(minMax.first == 49 && minMax.second == 49, "Check if plane is on slice 49");
622  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
623 
624  // calculate the intersection on the first slice
625  calculator->SetInput(planeOnFirstSlice, image);
626  calculator->Update();
627 
628  minMax = calculator->GetMinMaxSpatialDirectionY();
629 
630  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
631  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 0, "Check if plane is on slice 0");
632  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
633  }
634 
635  // now we make a rotation of the Image about 270 degrees around Z Axis to get an aligment on the positiv x axis
636  double angleInDegrees = 270 * M_PI / 180;
637 
638  mitk::AffineTransform3D::MatrixType matrix2;
639  matrix2[0][0] = cos(angleInDegrees);
640  matrix2[0][1] = -sin(angleInDegrees);
641  matrix2[0][2] = 0.0;
642 
643  matrix2[1][0] = sin(angleInDegrees);
644  matrix2[1][1] = cos(angleInDegrees);
645  matrix2[1][2] = 0.0;
646 
647  matrix2[2][0] = 0.0;
648  matrix2[2][1] = 0.0;
649  matrix2[2][2] = 1.0;
650 
651  // multiplie the identity with the transformation matrix
652  mitk::AffineTransform3D::MatrixType TransformationMatrix = matrix2 * matrix;
653 
654  // initialize the image with the new rotation Matrix
655  geom->SetMatrix(TransformationMatrix);
656  image->Initialize(mitk::MakePixelType<int, int, 1>(), *(rotatedSlicedGeometry3D.GetPointer()));
657 
658  {
659  // first Slice in X Diection
660  mitk::Point3D originFirstSlice;
661  originFirstSlice[0] = -1.0;
662  originFirstSlice[1] = 0.0;
663  originFirstSlice[2] = 0.0;
664 
665  mitk::Vector3D normalFitrstSlice;
666  mitk::FillVector3D(normalFitrstSlice, 1.0, 0.0, 0.0);
667 
668  mitk::Vector3D spacingFirstSlice;
669  spacingFirstSlice[0] = 1.0;
670  spacingFirstSlice[1] = 1.0;
671  spacingFirstSlice[2] = 1.0;
672 
674  planeOnFirstSlice->InitializePlane(originFirstSlice, normalFitrstSlice);
675  planeOnFirstSlice->SetSpacing(spacingFirstSlice);
676 
677  // last Slice in X Direction
678  mitk::Point3D originLastSlice;
679  originLastSlice[0] = 99.0;
680  originLastSlice[1] = 0.0;
681  originLastSlice[2] = 0.0;
682 
683  mitk::Vector3D normalLastSlice;
684  mitk::FillVector3D(normalLastSlice, 1.0, 0.0, 0.0);
685 
686  mitk::Vector3D spacingLastSlice;
687  spacingLastSlice[0] = 1.0;
688  spacingLastSlice[1] = 1.0;
689  spacingLastSlice[2] = 1.0;
690 
692  planeOnLastSlice->InitializePlane(originLastSlice, normalLastSlice);
693  planeOnLastSlice->SetSpacing(spacingLastSlice);
694 
695  calculator->SetInput(planeOnLastSlice, image);
696  calculator->Update();
697 
699 
700  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
701  MITK_TEST_CONDITION(minMax.first == 49 && minMax.second == 49, "Check if plane is on slice 49");
702  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
703 
704  calculator->SetInput(planeOnFirstSlice, image);
705  calculator->Update();
706 
707  minMax = calculator->GetMinMaxSpatialDirectionY();
708 
709  MITK_TEST_CONDITION(minMax.first == minMax.second, "Check if plane is only on one slice");
710  MITK_TEST_CONDITION(minMax.first == 0 && minMax.second == 0, "Check if plane is on slice 0");
711  MITK_INFO << "min: " << minMax.first << " max: " << minMax.second;
712  }
713 
714  delete calculator;
715 }
716 
718 {
719  // always start with this!
720  MITK_TEST_BEGIN("ClippedSurfaceBoundsCalculator");
721 
735  /********************* Define Geometry3D ***********************/
736  // Define origin:
737  mitk::Point3D origin;
738  origin[0] = 511;
739  origin[1] = 0;
740  origin[2] = 0;
741 
742  // Define normal:
743  mitk::Vector3D normal;
744  mitk::FillVector3D(normal, 0, 0, 1);
745 
746  // Initialize PlaneGeometry:
748  planeGeometry->InitializePlane(origin, normal);
749 
750  // Set Bounds:
751  mitk::BoundingBox::BoundsArrayType bounds = planeGeometry->GetBounds();
752  bounds[0] = 0;
753  bounds[1] = 512;
754  bounds[2] = 0;
755  bounds[3] = 512;
756  bounds[4] = 0;
757  bounds[5] = 1;
758  planeGeometry->SetBounds(bounds);
759 
760  // Initialize SlicedGeometry3D:
762  slicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry.GetPointer()), 20);
763  mitk::BaseGeometry::Pointer geometry3D = dynamic_cast<mitk::BaseGeometry *>(slicedGeometry3D.GetPointer());
764  geometry3D->SetImageGeometry(true);
765 
766  // Define origin for second Geometry3D;
767  mitk::Point3D origin2;
768  origin2[0] = 511;
769  origin2[1] = 60;
770  origin2[2] = 0;
771 
772  // Define normal:
773  mitk::Vector3D normal2;
774  mitk::FillVector3D(normal2, 0, 1, 0);
775 
776  // Initialize PlaneGeometry:
778  planeGeometry2->InitializePlane(origin2, normal2);
779 
780  // Initialize SlicedGeometry3D:
782  secondSlicedGeometry3D->InitializeEvenlySpaced(dynamic_cast<mitk::PlaneGeometry *>(planeGeometry2.GetPointer()), 20);
783  mitk::BaseGeometry::Pointer secondGeometry3D =
784  dynamic_cast<mitk::BaseGeometry *>(secondSlicedGeometry3D.GetPointer());
785  secondGeometry3D->SetImageGeometry(true);
786 
787  /***************************************************************/
788 
791  CheckPlanesInsideBoundingBox(geometry3D);
792  CheckIntersectionPointsOfTwoGeometry3D(geometry3D, secondGeometry3D);
796 
801  MITK_TEST_END();
802 }
OutputType GetMinMaxSpatialDirectionZ()
What Z coordinates (slice indices) are cut/visible in given plane.
static void CheckIntersectionWithRotatedGeometry()
#define MITK_INFO
Definition: mitkLogMacros.h:22
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:110
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:70
static Pointer New()
static void CheckIntersectionWithRotatedGeometry90()
static T min(T x, T y)
Definition: svm.cpp:67
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)