Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkContourSet.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 "mitkContourSet.h"
19 
20 mitk::ContourSet::ContourSet() : m_ContourVector(ContourVectorType()), m_NumberOfContours(0)
21 {
23  timeGeometry->Initialize(1);
24  SetTimeGeometry(timeGeometry);
25 }
26 
28 {
29 }
30 
31 void mitk::ContourSet::AddContour(unsigned int index, mitk::Contour::Pointer contour)
32 {
33  m_ContourVector.insert(std::make_pair(index, contour));
34 }
35 
36 void mitk::ContourSet::RemoveContour(unsigned long index)
37 {
38  m_ContourVector.erase(index);
39 }
40 
42 {
43  mitk::ContourSet::ContourVectorType contourVec = GetContours();
44  auto contoursIterator = contourVec.begin();
45  auto contoursIteratorEnd = contourVec.end();
46 
47  // initialize container
49 
50  mitk::BoundingBox::PointIdentifier pointid = 0;
51  mitk::Point3D point;
52 
53  mitk::AffineTransform3D *transform = GetGeometry(0)->GetIndexToWorldTransform();
55  transform->GetInverse(inverse);
56 
57  // calculate a bounding box that includes all contours
58  // \todo probably we should do this additionally for each time-step
59  while (contoursIterator != contoursIteratorEnd)
60  {
61  const TimeGeometry *geometry = (*contoursIterator).second->GetUpdatedTimeGeometry();
62  unsigned char i;
63  for (i = 0; i < 8; ++i)
64  {
65  point = inverse->TransformPoint(geometry->GetCornerPointInWorld(i));
66  if (point[0] * point[0] + point[1] * point[1] + point[2] * point[2] < mitk::large)
67  pointscontainer->InsertElement(pointid++, point);
68  else
69  {
70  itkGenericOutputMacro(<< "Unrealistically distant corner point encountered. Ignored. BoundingObject: "
71  << (*contoursIterator).second);
72  }
73  }
74  ++contoursIterator;
75  }
76 
78  boundingBox->SetPoints(pointscontainer);
79  boundingBox->ComputeBoundingBox();
80 
81  BaseGeometry *geometry3d = GetGeometry(0);
82  geometry3d->SetIndexToWorldTransform(transform);
83  geometry3d->SetBounds(boundingBox->GetBounds());
84 
86  timeGeometry->Initialize(geometry3d, GetTimeGeometry()->CountTimeSteps());
87  SetTimeGeometry(timeGeometry);
88 }
89 
91 {
92 }
93 
95 {
96  return true;
97 }
98 
100 {
101  return true;
102 }
103 
104 void mitk::ContourSet::SetRequestedRegion(const itk::DataObject *)
105 {
106 }
107 
109 {
110  m_ContourVector = ContourVectorType();
112  timeGeometry->Initialize(1);
113  SetTimeGeometry(timeGeometry);
114 }
115 
117 {
118  return m_ContourVector.size();
119 }
120 
122 {
123  return m_ContourVector;
124 }
itk::SmartPointer< Self > Pointer
void SetIndexToWorldTransform(mitk::AffineTransform3D *transform)
virtual bool VerifyRequestedRegion() override
virtual void SetTimeGeometry(TimeGeometry *geometry)
Set the TimeGeometry of the data, which will be referenced (not copied!).
Point3D GetCornerPointInWorld(int id) const
Get the position of the corner number id (in world coordinates)
virtual void UpdateOutputInformation() override
virtual void SetRequestedRegionToLargestPossibleRegion() override
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override
void Initialize() override
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
std::map< unsigned long, Contour::Pointer > ContourVectorType
MITKCORE_EXPORT const double large
ContourVectorType GetContours()
void SetBounds(const BoundsArrayType &bounds)
Set the bounding box (in index/unit coordinates)
virtual void SetRequestedRegion(const itk::DataObject *data) override
void AddContour(unsigned int index, mitk::Contour::Pointer contour)
BaseGeometry Describes the geometry of a data object.
void RemoveContour(unsigned long index)
unsigned int GetNumberOfContours()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.