22 #include <vtkPolyData.h>
24 static vtkSmartPointer<vtkPolyData>
DeepCopy(vtkPolyData *other)
30 copy->DeepCopy(other);
48 m_LargestPossibleRegion(other.m_LargestPossibleRegion),
49 m_RequestedRegion(other.m_RequestedRegion),
50 m_CalculateBoundingBox(other.m_CalculateBoundingBox)
52 if (!other.m_PolyDatas.empty())
54 m_PolyDatas.resize(other.m_PolyDatas.size());
55 std::transform(other.m_PolyDatas.cbegin(), other.m_PolyDatas.cend(), m_PolyDatas.begin(),
DeepCopy);
65 std::swap(m_PolyDatas, other.m_PolyDatas);
66 std::swap(m_LargestPossibleRegion, other.m_LargestPossibleRegion);
67 std::swap(m_RequestedRegion, other.m_RequestedRegion);
68 std::swap(m_CalculateBoundingBox, other.m_CalculateBoundingBox);
86 Superclass::ClearData();
91 m_LargestPossibleRegion.SetIndex(3, 0);
92 m_LargestPossibleRegion.SetSize(3, GetTimeGeometry()->CountTimeSteps());
94 return m_LargestPossibleRegion;
99 return m_RequestedRegion;
104 if (!m_PolyDatas.empty())
107 Superclass::InitializeTimeGeometry();
109 m_PolyDatas.push_back(
nullptr);
110 m_Initialized =
true;
117 if (m_PolyDatas[t] !=
nullptr)
119 if (m_PolyDatas[t].GetPointer() == polyData)
123 m_PolyDatas[t].TakeReference(polyData);
125 if (polyData !=
nullptr)
126 polyData->Register(
nullptr);
128 m_CalculateBoundingBox =
true;
131 this->UpdateOutputInformation();
136 if (!IsInitialized())
139 vtkPolyData *polyData =
const_cast<Surface *
>(
this)->GetVtkPolyData(t);
141 return polyData ==
nullptr || (polyData->GetNumberOfLines() == 0 && polyData->GetNumberOfPolys() == 0 &&
142 polyData->GetNumberOfStrips() == 0 && polyData->GetNumberOfVerts() == 0);
147 if (t < m_PolyDatas.size())
149 if (m_PolyDatas[t] ==
nullptr && this->GetSource().IsNotNull())
152 requestedRegion.SetIndex(3, t);
153 requestedRegion.SetSize(3, 1);
154 this->m_RequestedRegion = requestedRegion;
155 this->GetSource()->Update();
158 return m_PolyDatas[t].GetPointer();
166 if (this->GetSource().IsNotNull())
167 this->GetSource()->UpdateOutputInformation();
169 if (m_CalculateBoundingBox ==
true && !m_PolyDatas.empty())
170 this->CalculateBoundingBox();
172 this->GetTimeGeometry()->Update();
179 if (timeGeometry->CountTimeSteps() != m_PolyDatas.size())
180 mitkThrow() <<
"Number of geometry time steps is inconsistent with number of poly data pointers.";
182 for (
unsigned int i = 0; i < m_PolyDatas.size(); ++i)
184 vtkPolyData *polyData = m_PolyDatas[i].GetPointer();
185 double bounds[6] = {0};
187 if (polyData !=
nullptr && polyData->GetNumberOfPoints() > 0)
190 polyData->ComputeBounds();
191 polyData->GetBounds(bounds);
196 if (geometry.IsNull())
197 mitkThrow() <<
"Time-sliced geometry is invalid (equals NULL).";
199 geometry->SetFloatBounds(bounds);
203 m_CalculateBoundingBox =
false;
208 m_RequestedRegion = GetLargestPossibleRegion();
213 RegionType::IndexValueType end = m_RequestedRegion.GetIndex(3) + m_RequestedRegion.GetSize(3);
215 if (static_cast<RegionType::IndexValueType>(m_PolyDatas.size()) < end)
218 for (RegionType::IndexValueType t = m_RequestedRegion.GetIndex(3); t < end; ++t)
220 if (m_PolyDatas[t] ==
nullptr)
229 if (m_RequestedRegion.GetIndex(3) >= 0 &&
230 m_RequestedRegion.GetIndex(3) + m_RequestedRegion.GetSize(3) <= m_PolyDatas.size())
240 if (surface !=
nullptr)
243 mitkThrow() <<
"Data object used to get requested region is not a mitk::Surface.";
248 if (region ==
nullptr)
249 mitkThrow() <<
"Requested region is invalid (equals NULL)";
251 m_RequestedRegion = *region;
256 Superclass::CopyInformation(data);
260 if (surface ==
nullptr)
261 mitkThrow() <<
"Data object used to get largest possible region is not a mitk::Surface.";
270 if (this->GetSource().IsNull())
271 std::for_each(m_PolyDatas.begin(), m_PolyDatas.end(),
Update);
278 if (timeSteps > m_PolyDatas.size())
280 Superclass::Expand(timeSteps);
282 m_PolyDatas.resize(timeSteps);
283 m_CalculateBoundingBox =
true;
295 if (surfaceOperation ==
nullptr)
298 unsigned int timeStep = surfaceOperation->
GetTimeStep();
300 if (m_PolyDatas[timeStep] !=
nullptr)
302 vtkPolyData *updatedPolyData = surfaceOperation->
GetVtkPolyData();
304 if (updatedPolyData !=
nullptr)
306 this->SetVtkPolyData(updatedPolyData, timeStep);
307 this->CalculateBoundingBox();
322 return m_PolyDatas.size();
329 if (surface ==
nullptr)
330 mitkThrow() <<
"Data object used to graft surface is not a mitk::Surface.";
332 this->CopyInformation(data);
338 m_PolyDatas.back()->DeepCopy(const_cast<mitk::Surface *>(surface)->GetVtkPolyData(i));
344 Superclass::PrintSelf(os, indent);
346 os << indent <<
"\nNumber PolyDatas: " << m_PolyDatas.size() <<
"\n";
348 unsigned int count = 0;
350 for (
auto it = m_PolyDatas.begin(); it != m_PolyDatas.end(); ++it)
356 os << indent <<
"PolyData at time step " << count <<
":\n";
357 os << indent <<
"Number of cells: " << (*it)->GetNumberOfCells() <<
"\n";
358 os << indent <<
"Number of points: " << (*it)->GetNumberOfPoints() <<
"\n\n";
359 os << indent <<
"VTKPolyData:\n";
365 os << indent <<
"Empty PolyData at time step " << count <<
"\n";
374 if ((leftHandSide ==
nullptr) || (rightHandSide ==
nullptr))
376 MITK_ERROR <<
"mitk::Equal( vtkPolyData* leftHandSide, vtkPolyData* rightHandSide, mitk::ScalarType eps, bool "
377 "verbose ) does not work for NULL pointer input.";
380 return Equal(*leftHandSide, *rightHandSide, eps, verbose);
385 bool noDifferenceFound =
true;
387 if (!
mitk::Equal(leftHandSide.GetNumberOfCells(), rightHandSide.GetNumberOfCells(),
eps, verbose))
390 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of cells not equal";
391 noDifferenceFound =
false;
394 if (!
mitk::Equal(leftHandSide.GetNumberOfVerts(), rightHandSide.GetNumberOfVerts(),
eps, verbose))
397 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of vertices not equal";
398 noDifferenceFound =
false;
401 if (!
mitk::Equal(leftHandSide.GetNumberOfLines(), rightHandSide.GetNumberOfLines(),
eps, verbose))
404 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of lines not equal";
405 noDifferenceFound =
false;
408 if (!
mitk::Equal(leftHandSide.GetNumberOfPolys(), rightHandSide.GetNumberOfPolys(),
eps, verbose))
411 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of polys not equal";
412 noDifferenceFound =
false;
415 if (!
mitk::Equal(leftHandSide.GetNumberOfStrips(), rightHandSide.GetNumberOfStrips(),
eps, verbose))
418 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of strips not equal";
419 noDifferenceFound =
false;
423 unsigned int numberOfPointsRight = rightHandSide.GetPoints()->GetNumberOfPoints();
424 unsigned int numberOfPointsLeft = leftHandSide.GetPoints()->GetNumberOfPoints();
425 if (!
mitk::Equal(numberOfPointsLeft, numberOfPointsRight, eps, verbose))
428 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of points not equal";
429 noDifferenceFound =
false;
433 for (
unsigned int i(0); i < numberOfPointsRight; i++)
435 bool pointFound =
false;
437 rightHandSide.GetPoints()->GetPoint(i, pointOne);
439 for (
unsigned int j(0); j < numberOfPointsLeft; j++)
442 leftHandSide.GetPoints()->GetPoint(j, pointTwo);
444 double x = pointOne[0] - pointTwo[0];
445 double y = pointOne[1] - pointTwo[1];
446 double z = pointOne[2] - pointTwo[2];
447 double distance = x * x + y * y + z * z;
459 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Right hand side point with id " << i
460 <<
" and coordinates ( " << std::setprecision(12) << pointOne[0] <<
" ; " << pointOne[1] <<
" ; "
461 << pointOne[2] <<
" ) could not be found in left hand side with epsilon " << eps <<
".";
463 noDifferenceFound =
false;
469 return noDifferenceFound;
474 if ((leftHandSide ==
nullptr) || (rightHandSide ==
nullptr))
476 MITK_ERROR <<
"mitk::Equal( mitk::Surface* leftHandSide, mitk::Surface* rightHandSide, mitk::ScalarType eps, bool "
477 "verbose ) does not work with NULL pointer input.";
480 return Equal(*leftHandSide, *rightHandSide, eps, verbose);
485 bool noDifferenceFound =
true;
490 MITK_INFO <<
"[Equal( mitk::surface&, mitk::surface& )] Size of PolyData series not equal.";
507 MITK_INFO <<
"[Equal( mitk::surface&, mitk::surface& )] Poly datas not equal.";
508 noDifferenceFound =
false;
512 return noDifferenceFound;
virtual bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
Class for storing surfaces (vtkPolyData).
unsigned int GetSizeOfPolyDataSeries() const
virtual void SetRequestedRegion(const itk::DataObject *data) override
Set the requested region from this data object to match the requested region of the data object passe...
Base of all data objects.
Base class of all Operation-classes.
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
void CalculateBoundingBox()
static vtkSmartPointer< vtkPolyData > DeepCopy(vtkPolyData *other)
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
static void Update(vtkPolyData *)
virtual void UpdateOutputInformation() override
const RegionType & GetLargestPossibleRegion() const
Constants for most interaction classes, due to the generic StateMachines.
virtual void InitializeEmpty() override
Pure virtual; Must be used in subclasses to get a data object to a valid state. Should at least creat...
virtual void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
virtual void Swap(Surface &other)
virtual void SetVtkPolyData(vtkPolyData *polydata, unsigned int t=0)
virtual void ClearData() override
reset to non-initialized state, release memory
vtkPolyData * GetVtkPolyData()
unsigned int GetTimeStep()
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.
static void swap(T &x, T &y)
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const =0
Returns the geometry which corresponds to the given time step.
MITKCORE_EXPORT const ScalarType eps
virtual void Update() override
virtual void Graft(const DataObject *data) override
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual bool IsEmptyTimeStep(unsigned int t) const override
Check whether object contains data (at a specified time), e.g., a set of points may be empty...
OperationType GetOperationType()
itk::ImageRegion< 5 > RegionType
void Update()
Updates the geometry.
virtual void CopyInformation(const itk::DataObject *data) override
virtual void ExecuteOperation(Operation *operation) override
overwrite if the Data can be called by an Interactor (StateMachine).
Surface & operator=(Surface other)
virtual void Expand(unsigned int timeSteps=1) override
Expands the TimeGeometry to a number of TimeSteps.
virtual const RegionType & GetRequestedRegion() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.