18 #include <vtkPolyData.h> 20 static vtkSmartPointer<vtkPolyData>
DeepCopy(vtkPolyData *other)
25 vtkSmartPointer<vtkPolyData> copy = vtkSmartPointer<vtkPolyData>::New();
26 copy->DeepCopy(other);
44 m_LargestPossibleRegion(other.m_LargestPossibleRegion),
45 m_RequestedRegion(other.m_RequestedRegion),
46 m_CalculateBoundingBox(other.m_CalculateBoundingBox)
48 if (!other.m_PolyDatas.empty())
50 m_PolyDatas.resize(other.m_PolyDatas.size());
51 std::transform(other.m_PolyDatas.cbegin(), other.m_PolyDatas.cend(), m_PolyDatas.begin(),
DeepCopy);
61 std::swap(m_PolyDatas, other.m_PolyDatas);
62 std::swap(m_LargestPossibleRegion, other.m_LargestPossibleRegion);
63 std::swap(m_RequestedRegion, other.m_RequestedRegion);
64 std::swap(m_CalculateBoundingBox, other.m_CalculateBoundingBox);
87 m_LargestPossibleRegion.SetIndex(3, 0);
88 m_LargestPossibleRegion.SetSize(3,
GetTimeGeometry()->CountTimeSteps());
90 return m_LargestPossibleRegion;
95 return m_RequestedRegion;
100 if (!m_PolyDatas.empty())
105 m_PolyDatas.push_back(
nullptr);
113 if (m_PolyDatas[t] !=
nullptr)
115 if (m_PolyDatas[t].GetPointer() == polyData)
119 m_PolyDatas[t].TakeReference(polyData);
121 if (polyData !=
nullptr)
122 polyData->Register(
nullptr);
124 m_CalculateBoundingBox =
true;
137 return polyData ==
nullptr || (polyData->GetNumberOfLines() == 0 && polyData->GetNumberOfPolys() == 0 &&
138 polyData->GetNumberOfStrips() == 0 && polyData->GetNumberOfVerts() == 0);
143 if (t < m_PolyDatas.size())
145 if (m_PolyDatas[t] ==
nullptr && this->
GetSource().IsNotNull())
148 requestedRegion.SetIndex(3, t);
149 requestedRegion.SetSize(3, 1);
150 this->m_RequestedRegion = requestedRegion;
154 return m_PolyDatas[t].GetPointer();
163 this->
GetSource()->UpdateOutputInformation();
165 if (m_CalculateBoundingBox ==
true && !m_PolyDatas.empty())
176 mitkThrow() <<
"Number of geometry time steps is inconsistent with number of poly data pointers.";
178 for (
unsigned int i = 0; i < m_PolyDatas.size(); ++i)
180 vtkPolyData *polyData = m_PolyDatas[i].GetPointer();
181 double bounds[6] = {0};
183 if (polyData !=
nullptr && polyData->GetNumberOfPoints() > 0)
186 polyData->ComputeBounds();
187 polyData->GetBounds(bounds);
192 if (geometry.IsNull())
193 mitkThrow() <<
"Time-sliced geometry is invalid (equals nullptr).";
195 geometry->SetFloatBounds(bounds);
199 m_CalculateBoundingBox =
false;
209 RegionType::IndexValueType end = m_RequestedRegion.GetIndex(3) + m_RequestedRegion.GetSize(3);
211 if (static_cast<RegionType::IndexValueType>(m_PolyDatas.size()) < end)
214 for (RegionType::IndexValueType t = m_RequestedRegion.GetIndex(3); t < end; ++t)
216 if (m_PolyDatas[t] ==
nullptr)
225 if (m_RequestedRegion.GetIndex(3) >= 0 &&
226 m_RequestedRegion.GetIndex(3) + m_RequestedRegion.GetSize(3) <= m_PolyDatas.size())
234 const auto *surface =
dynamic_cast<const mitk::Surface *
>(data);
236 if (surface !=
nullptr)
237 m_RequestedRegion = surface->GetRequestedRegion();
239 mitkThrow() <<
"Data object used to get requested region is not a mitk::Surface.";
244 if (region ==
nullptr)
245 mitkThrow() <<
"Requested region is invalid (equals nullptr)";
247 m_RequestedRegion = *region;
254 const auto *surface =
dynamic_cast<const mitk::Surface *
>(data);
256 if (surface ==
nullptr)
257 mitkThrow() <<
"Data object used to get largest possible region is not a mitk::Surface.";
259 m_LargestPossibleRegion = surface->GetLargestPossibleRegion();
267 std::for_each(m_PolyDatas.begin(), m_PolyDatas.end(),
Update);
274 if (timeSteps > m_PolyDatas.size())
278 m_PolyDatas.resize(timeSteps);
279 m_CalculateBoundingBox =
true;
291 if (surfaceOperation ==
nullptr)
294 unsigned int timeStep = surfaceOperation->
GetTimeStep();
296 if (m_PolyDatas[timeStep] !=
nullptr)
298 vtkPolyData *updatedPolyData = surfaceOperation->GetVtkPolyData();
300 if (updatedPolyData !=
nullptr)
318 return m_PolyDatas.size();
323 const auto *surface =
dynamic_cast<const Surface *
>(data);
325 if (surface ==
nullptr)
326 mitkThrow() <<
"Data object used to graft surface is not a mitk::Surface.";
331 for (
unsigned int i = 0; i < surface->GetSizeOfPolyDataSeries(); ++i)
333 m_PolyDatas.push_back(vtkSmartPointer<vtkPolyData>::New());
334 m_PolyDatas.back()->DeepCopy(surface->GetVtkPolyData(i));
342 os << indent <<
"\nNumber PolyDatas: " << m_PolyDatas.size() <<
"\n";
344 unsigned int count = 0;
346 for (
auto it = m_PolyDatas.begin(); it != m_PolyDatas.end(); ++it)
352 os << indent <<
"PolyData at time step " << count <<
":\n";
353 os << indent <<
"Number of cells: " << (*it)->GetNumberOfCells() <<
"\n";
354 os << indent <<
"Number of points: " << (*it)->GetNumberOfPoints() <<
"\n\n";
355 os << indent <<
"VTKPolyData:\n";
361 os << indent <<
"Empty PolyData at time step " << count <<
"\n";
370 if ((leftHandSide ==
nullptr) || (rightHandSide ==
nullptr))
372 MITK_ERROR <<
"mitk::Equal( vtkPolyData* leftHandSide, vtkPolyData* rightHandSide, mitk::ScalarType eps, bool " 373 "verbose ) does not work for nullptr pointer input.";
376 return Equal(*leftHandSide, *rightHandSide, eps, verbose);
381 bool noDifferenceFound =
true;
386 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of cells not equal";
387 noDifferenceFound =
false;
393 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of vertices not equal";
394 noDifferenceFound =
false;
400 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of lines not equal";
401 noDifferenceFound =
false;
407 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of polys not equal";
408 noDifferenceFound =
false;
414 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of strips not equal";
415 noDifferenceFound =
false;
419 unsigned int numberOfPointsRight = rightHandSide.GetPoints()->GetNumberOfPoints();
420 unsigned int numberOfPointsLeft = leftHandSide.GetPoints()->GetNumberOfPoints();
421 if (!
mitk::Equal(numberOfPointsLeft, numberOfPointsRight, eps, verbose))
424 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Number of points not equal";
425 noDifferenceFound =
false;
429 for (
unsigned int i(0); i < numberOfPointsRight; i++)
431 bool pointFound =
false;
433 rightHandSide.GetPoints()->GetPoint(i, pointOne);
435 for (
unsigned int j(0); j < numberOfPointsLeft; j++)
438 leftHandSide.GetPoints()->GetPoint(j, pointTwo);
440 double x = pointOne[0] - pointTwo[0];
441 double y = pointOne[1] - pointTwo[1];
442 double z = pointOne[2] - pointTwo[2];
443 double distance = x * x + y * y + z * z;
455 MITK_INFO <<
"[Equal( vtkPolyData*, vtkPolyData* )] Right hand side point with id " << i
456 <<
" and coordinates ( " << std::setprecision(12) << pointOne[0] <<
" ; " << pointOne[1] <<
" ; " 457 << pointOne[2] <<
" ) could not be found in left hand side with epsilon " << eps <<
".";
459 noDifferenceFound =
false;
465 return noDifferenceFound;
470 if ((leftHandSide ==
nullptr) || (rightHandSide ==
nullptr))
472 MITK_ERROR <<
"mitk::Equal( mitk::Surface* leftHandSide, mitk::Surface* rightHandSide, mitk::ScalarType eps, bool " 473 "verbose ) does not work with nullptr pointer input.";
476 return Equal(*leftHandSide, *rightHandSide, eps, verbose);
481 bool noDifferenceFound =
true;
486 MITK_INFO <<
"[Equal( mitk::surface&, mitk::surface& )] Size of PolyData series not equal.";
503 MITK_INFO <<
"[Equal( mitk::surface&, mitk::surface& )] Poly datas not equal.";
504 noDifferenceFound =
false;
508 return noDifferenceFound;
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
Class for storing surfaces (vtkPolyData).
itk::SmartPointer< mitk::BaseDataSource > GetSource() const
Get the process object that generated this data object.
virtual void ClearData()
reset to non-initialized state, release memory
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...
void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual TimeStepType CountTimeSteps() const =0
Returns the number of time steps.
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
Base of all data objects.
Base class of all Operation-classes.
void CalculateBoundingBox()
static vtkSmartPointer< vtkPolyData > DeepCopy(vtkPolyData *other)
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
static void Update(vtkPolyData *)
void UpdateOutputInformation() override
Constants for most interaction classes, due to the generic StateMachines.
void InitializeEmpty() override
Pure virtual; Must be used in subclasses to get a data object to a valid state. Should at least creat...
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
virtual void Swap(Surface &other)
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
virtual const RegionType & GetRequestedRegion() const
unsigned int GetSizeOfPolyDataSeries() const
virtual void SetVtkPolyData(vtkPolyData *polydata, unsigned int t=0)
const RegionType & GetLargestPossibleRegion() const
void ClearData() override
reset to non-initialized state, release memory
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.
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
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
void Graft(const DataObject *data) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
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 Expand(unsigned int timeSteps)
Expands the TimeGeometry to a number of TimeSteps.
void CopyInformation(const itk::DataObject *data) override
void ExecuteOperation(Operation *operation) override
overwrite if the Data can be called by an Interactor (StateMachine).
virtual void InitializeTimeGeometry(unsigned int timeSteps=1)
Initialize the TimeGeometry for a number of time steps. The TimeGeometry is initialized empty and eve...
Surface & operator=(Surface other)
void Expand(unsigned int timeSteps=1) override
Expands the TimeGeometry to a number of TimeSteps.
void CopyInformation(const itk::DataObject *data) override
Copy information from the specified data set.