Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPlanePositionManager.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 ===================================================================*/
17 #include "mitkInteractionConst.h"
18 
20 {
21 }
22 
24 {
25  for (unsigned int i = 0; i < m_PositionList.size(); ++i)
26  delete m_PositionList[i];
27 }
28 
29 unsigned int mitk::PlanePositionManagerService::AddNewPlanePosition(const PlaneGeometry *plane, unsigned int sliceIndex)
30 {
31  for (unsigned int i = 0; i < m_PositionList.size(); ++i)
32  {
33  if (m_PositionList[i] != 0)
34  {
35  bool isSameMatrix(true);
36  bool isSameOffset(true);
37  isSameOffset =
38  mitk::Equal(m_PositionList[i]->GetTransform()->GetOffset(), plane->GetIndexToWorldTransform()->GetOffset());
39  if (!isSameOffset || sliceIndex != m_PositionList[i]->GetPos())
40  continue;
41  isSameMatrix = mitk::MatrixEqualElementWise(m_PositionList[i]->GetTransform()->GetMatrix(),
42  plane->GetIndexToWorldTransform()->GetMatrix());
43  if (isSameMatrix)
44  return i;
45  }
46  }
47 
49  Matrix3D matrix;
50  matrix.GetVnlMatrix().set_column(0, plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0));
51  matrix.GetVnlMatrix().set_column(1, plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1));
52  matrix.GetVnlMatrix().set_column(2, plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2));
53  transform->SetMatrix(matrix);
54  transform->SetOffset(plane->GetIndexToWorldTransform()->GetOffset());
55 
56  mitk::Vector3D direction;
57  direction[0] = plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)[0];
58  direction[1] = plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)[1];
59  direction[2] = plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)[2];
60  direction.Normalize();
61 
63  plane->GetExtent(0),
64  plane->GetExtent(1),
65  plane->GetSpacing(),
66  sliceIndex,
67  direction,
68  transform);
69 
70  m_PositionList.push_back(newOp);
71  return GetNumberOfPlanePositions() - 1;
72 }
73 
75 {
76  if (m_PositionList.size() > ID)
77  {
78  delete m_PositionList[ID];
79  m_PositionList.erase(m_PositionList.begin() + ID);
80  return true;
81  }
82  else
83  {
84  return false;
85  }
86 }
87 
89 {
90  if (ID < m_PositionList.size())
91  {
92  return m_PositionList[ID];
93  }
94  else
95  {
96  MITK_WARN << "GetPlanePosition returned NULL!";
97  return 0;
98  }
99 }
100 
102 {
103  return m_PositionList.size();
104 }
105 
107 {
108  for (unsigned int i = 0; i < m_PositionList.size(); ++i)
109  delete m_PositionList[i];
110 
111  m_PositionList.clear();
112 }
ScalarType GetExtent(unsigned int direction) const
Set the time bounds (in ms)
itk::SmartPointer< Self > Pointer
bool MatrixEqualElementWise(const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix1, const vnl_matrix_fixed< TCoordRep, NRows, NCols > &matrix2, mitk::ScalarType epsilon=mitk::eps)
Check for element-wise matrix equality with a user defined accuracy.
Definition: mitkMatrix.h:144
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
Constants for most interaction classes, due to the generic StateMachines.
mitk::RestorePlanePositionOperation * GetPlanePosition(unsigned int ID)
Getter for a specific plane position with a given ID.
#define MITK_WARN
Definition: mitkLogMacros.h:23
bool RemovePlanePosition(unsigned int ID)
Removes the plane at the position ID from the list.
const std::string ID
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
unsigned int GetNumberOfPlanePositions()
Getting the number of all stored planes.
unsigned int AddNewPlanePosition(const mitk::PlaneGeometry *plane, unsigned int sliceIndex=0)
Adds a new plane position to the list. If this geometry is identical to one of the list nothing will ...
Describes a two-dimensional, rectangular plane.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
void RemoveAllPlanePositions()
Clears the complete positionlist.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.