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