MCPcopy Create free account
hub / github.com/MITK/MITK / mitkRotatedSlice4DTest

Function mitkRotatedSlice4DTest

Modules/Core/test/mitkRotatedSlice4DTest.cpp:25–84  ·  view source on GitHub ↗

* The mitkRotatedSlice4DTest loads a 4D image and extracts a specifically rotated slice in each time step's volume. */

Source from the content-addressed store, hash-verified

23* The mitkRotatedSlice4DTest loads a 4D image and extracts a specifically rotated slice in each time step's volume.
24*/
25int 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 auto numTimeSteps = std::min(2, static_cast<int>(image4D->GetTimeSteps()));
41
42 for (int ts = 0; ts < numTimeSteps; ++ts)
43 {
44 mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New();
45 timeSelector->SetInput(image4D);
46 timeSelector->SetTimeNr(ts);
47 timeSelector->Update();
48 mitk::Image::Pointer image3D = timeSelector->GetOutput();
49
50 int sliceNumber = std::min(5, static_cast<int>(image3D->GetSlicedGeometry()->GetSlices()));
51
52 mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
53 plane->InitializeStandardPlane(image3D->GetGeometry(), mitk::AnatomicalPlane::Coronal, sliceNumber, true, false);
54
55 // rotate about an arbitrary point and axis...
56 float angle = 30;
57 mitk::Point3D point;
58 point.Fill(sliceNumber);
59 mitk::Vector3D rotationAxis;
60 rotationAxis[0] = 1;
61 rotationAxis[1] = 2;
62 rotationAxis[2] = 3;
63 rotationAxis.Normalize();
64
65 // Create Rotation Operation
66 auto *op = new mitk::RotationOperation(mitk::OpROTATE, point, rotationAxis, angle);
67 plane->ExecuteOperation(op);
68 delete op;
69
70 // Now extract
71 mitk::ExtractSliceFilter::Pointer extractor = mitk::ExtractSliceFilter::New();
72 extractor->SetInput(image3D);
73 extractor->SetWorldGeometry(plane);
74 extractor->Update();
75 mitk::Image::Pointer extractedPlane;
76 extractedPlane = extractor->GetOutput();
77
78 std::stringstream ss;
79 ss << " : Valid slice in timestep " << ts;
80
81 MITK_TEST_CONDITION_REQUIRED(extractedPlane.IsNotNull(), ss.str().c_str());
82 }

Callers

nothing calls this directly

Calls 13

GetTimeStepsMethod · 0.80
GetSlicedGeometryMethod · 0.80
GetGeometryMethod · 0.80
NormalizeMethod · 0.80
IsNotNullMethod · 0.80
NewFunction · 0.50
IsNullMethod · 0.45
SetInputMethod · 0.45
UpdateMethod · 0.45
GetOutputMethod · 0.45
FillMethod · 0.45

Tested by

no test coverage detected