Medical Imaging Interaction Toolkit  2018.4.99-a28b433c
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 (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 ============================================================================*/
13 #include "mitkInteractionConst.h"
14 
16 {
17 }
18 
20 {
21  for (unsigned int i = 0; i < m_PositionList.size(); ++i)
22  delete m_PositionList[i];
23 }
24 
25 unsigned int mitk::PlanePositionManagerService::AddNewPlanePosition(const PlaneGeometry *plane, unsigned int sliceIndex)
26 {
27  for (unsigned int i = 0; i < m_PositionList.size(); ++i)
28  {
29  if (m_PositionList[i] != nullptr)
30  {
31  bool isSameMatrix(true);
32  bool isSameOffset(true);
33  isSameOffset =
34  mitk::Equal(m_PositionList[i]->GetTransform()->GetOffset(), plane->GetIndexToWorldTransform()->GetOffset());
35  if (!isSameOffset || sliceIndex != m_PositionList[i]->GetPos())
36  continue;
37  isSameMatrix = mitk::MatrixEqualElementWise(m_PositionList[i]->GetTransform()->GetMatrix(),
38  plane->GetIndexToWorldTransform()->GetMatrix());
39  if (isSameMatrix)
40  return i;
41  }
42  }
43 
44  AffineTransform3D::Pointer transform = AffineTransform3D::New();
45  Matrix3D matrix;
46  matrix.GetVnlMatrix().set_column(0, plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0));
47  matrix.GetVnlMatrix().set_column(1, plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1));
48  matrix.GetVnlMatrix().set_column(2, plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2));
49  transform->SetMatrix(matrix);
50  transform->SetOffset(plane->GetIndexToWorldTransform()->GetOffset());
51 
52  mitk::Vector3D direction;
53  direction[0] = plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)[0];
54  direction[1] = plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)[1];
55  direction[2] = plane->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)[2];
56  direction.Normalize();
57 
59  plane->GetExtent(0),
60  plane->GetExtent(1),
61  plane->GetSpacing(),
62  sliceIndex,
63  direction,
64  transform);
65 
66  m_PositionList.push_back(newOp);
67  return GetNumberOfPlanePositions() - 1;
68 }
69 
71 {
72  if (m_PositionList.size() > ID)
73  {
74  delete m_PositionList[ID];
75  m_PositionList.erase(m_PositionList.begin() + ID);
76  return true;
77  }
78  else
79  {
80  return false;
81  }
82 }
83 
85 {
86  if (ID < m_PositionList.size())
87  {
88  return m_PositionList[ID];
89  }
90  else
91  {
92  MITK_WARN << "GetPlanePosition returned nullptr!";
93  return nullptr;
94  }
95 }
96 
98 {
99  return m_PositionList.size();
100 }
101 
103 {
104  for (unsigned int i = 0; i < m_PositionList.size(); ++i)
105  delete m_PositionList[i];
106 
107  m_PositionList.clear();
108 }
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:140
ScalarType GetExtent(unsigned int direction) const
Set the time bounds (in ms)
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:19
bool RemovePlanePosition(unsigned int ID)
Removes the plane at the position ID from the list.
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.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
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.