Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkPlane.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 "mitkPlane.h"
14 #include "mitkNumericTypes.h"
15 
16 #include <vtkDoubleArray.h>
17 #include <vtkLinearTransform.h>
18 #include <vtkPlaneSource.h>
19 #include <vtkPointData.h>
20 
21 namespace mitk
22 {
24  {
25  // Set up Plane Surface.
26  m_PlaneSource = vtkPlaneSource::New();
27  m_PlaneSource->SetOrigin(-32.0, -32.0, 0.0);
28  m_PlaneSource->SetPoint1(32.0, -32.0, 0.0);
29  m_PlaneSource->SetPoint2(-32.0, 32.0, 0.0);
30  m_PlaneSource->SetResolution(128, 128);
31  m_PlaneSource->Update();
32 
33  m_PlaneNormal = vtkDoubleArray::New();
34  m_PlaneNormal->SetNumberOfComponents(3);
35  m_PlaneNormal->SetNumberOfTuples(m_PlaneSource->GetOutput()->GetNumberOfPoints());
36  m_PlaneNormal->SetTuple3(0, 0.0, 0.0, 1.0);
37  m_PlaneNormal->SetName("planeNormal");
38 
39  m_Plane = vtkPolyData::New();
40  m_Plane->DeepCopy(m_PlaneSource->GetOutput());
41  m_Plane->GetPointData()->SetVectors(m_PlaneNormal);
42 
43  this->SetVtkPolyData(m_Plane);
44  }
45 
47  {
48  m_PlaneSource->Delete();
49  m_Plane->Delete();
50  m_PlaneNormal->Delete();
51  }
52 
53  void Plane::SetExtent(const double x, const double y)
54  {
55  m_PlaneSource->SetOrigin(-x / 2.0, -y / 2.0, 0.0);
56  m_PlaneSource->SetPoint1(x / 2.0, -y / 2.0, 0.0);
57  m_PlaneSource->SetPoint2(-x / 2.0, y / 2.0, 0.0);
58  m_PlaneSource->Update();
59 
60  m_Plane->DeepCopy(m_PlaneSource->GetOutput());
61  m_Plane->GetPointData()->SetVectors(m_PlaneNormal);
62 
63  this->Modified();
64  }
65 
66  void Plane::GetExtent(double &x, double &y) const
67  {
68  x = m_PlaneSource->GetPoint1()[0] - m_PlaneSource->GetOrigin()[0];
69  y = m_PlaneSource->GetPoint2()[1] - m_PlaneSource->GetOrigin()[1];
70  }
71 
72  void Plane::SetResolution(const int xR, const int yR)
73  {
74  m_PlaneSource->SetResolution(xR, yR);
75  m_PlaneSource->Update();
76 
77  m_Plane->DeepCopy(m_PlaneSource->GetOutput());
78  m_Plane->GetPointData()->SetVectors(m_PlaneNormal);
79 
80  this->Modified();
81  }
82 
83  void Plane::GetResolution(int &xR, int &yR) const { m_PlaneSource->GetResolution(xR, yR); }
84  bool Plane::IsInside(const Point3D & /*worldPoint*/) const
85  {
86  // Plane does not have a volume
87  return false;
88  }
89 
91  {
92  // Plane does not have a volume
93  return 0.0;
94  }
95 }
double ScalarType
mitk::ScalarType GetVolume() override
Definition: mitkPlane.cpp:90
DataCollection - Class to facilitate loading/accessing structured data.
void GetExtent(double &x, double &y) const
Definition: mitkPlane.cpp:66
vtkPlaneSource * m_PlaneSource
Definition: mitkPlane.h:50
vtkDoubleArray * m_PlaneNormal
Definition: mitkPlane.h:54
superclass of all bounding objects (cylinder, cuboid,...)
virtual void SetVtkPolyData(vtkPolyData *polydata, unsigned int t=0)
bool IsInside(const Point3D &p) const override
Definition: mitkPlane.cpp:84
void SetExtent(const double x, const double y)
Definition: mitkPlane.cpp:53
vtkPolyData * m_Plane
Definition: mitkPlane.h:52
~Plane() override
Definition: mitkPlane.cpp:46
void SetResolution(const int xR, const int yR)
Definition: mitkPlane.cpp:72
void GetResolution(int &xR, int &yR) const
Definition: mitkPlane.cpp:83