Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkRotatedSlice4DTest.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 "mitkExtractSliceFilter.h"
14 #include "mitkIOUtil.h"
16 #include "mitkImageTimeSelector.h"
17 #include "mitkInteractionConst.h"
18 #include "mitkRotationOperation.h"
19 #include "mitkTestingMacros.h"
20 #include <ctime>
21 
22 /*
23 * The mitkRotatedSlice4DTest loads a 4D image and extracts a specifically rotated slice in each time step's volume.
24 */
25 int mitkRotatedSlice4DTest(int, char *argv[])
26 {
27  MITK_TEST_BEGIN("mitkRotatedSlice4DTest");
28 
29  std::string filename = argv[1];
30 
31  // load 4D image
32  mitk::Image::Pointer image4D = mitk::IOUtil::Load<mitk::Image>(filename);
33  // check inputs
34  if (image4D.IsNull())
35  {
36  MITK_INFO << "Could not load the file";
37  return false;
38  }
39 
40  // for each time step...
41  for (unsigned int ts = 0; ts < image4D->GetTimeSteps(); ts++)
42  {
44  timeSelector->SetInput(image4D);
45  timeSelector->SetTimeNr(ts);
46  timeSelector->Update();
47  mitk::Image::Pointer image3D = timeSelector->GetOutput();
48 
49  int sliceNumber = 5;
50 
52  plane->InitializeStandardPlane(image3D->GetGeometry(), mitk::PlaneGeometry::Frontal, sliceNumber, true, false);
53 
54  // rotate about an arbitrary point and axis...
55  float angle = 30;
56  mitk::Point3D point;
57  point.Fill(sliceNumber);
58  mitk::Vector3D rotationAxis;
59  rotationAxis[0] = 1;
60  rotationAxis[1] = 2;
61  rotationAxis[2] = 3;
62  rotationAxis.Normalize();
63 
64  // Create Rotation Operation
65  auto *op = new mitk::RotationOperation(mitk::OpROTATE, point, rotationAxis, angle);
66  plane->ExecuteOperation(op);
67  delete op;
68 
69  // Now extract
71  extractor->SetInput(image3D);
72  extractor->SetWorldGeometry(plane);
73  extractor->Update();
74  mitk::Image::Pointer extractedPlane;
75  extractedPlane = extractor->GetOutput();
76 
77  std::stringstream ss;
78  ss << " : Valid slice in timestep " << ts;
79 
80  MITK_TEST_CONDITION_REQUIRED(extractedPlane.IsNotNull(), ss.str().c_str());
81  }
82  MITK_TEST_END();
83 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
static Pointer New()
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
Constants for most interaction classes, due to the generic StateMachines.
int mitkRotatedSlice4DTest(int, char *argv[])
static Pointer New()
and MITK_TEST_END()
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
static Pointer New()