Skip to content

Commit

Permalink
BUG: TubeSpatialObject missing CopyInformation
Browse files Browse the repository at this point in the history
Calling CopyInformation on a TubeSpatialObject did not copy
member variables - defaulted to CopyInformation of a Superclass
instead.
  • Loading branch information
aylward authored and thewtex committed Aug 3, 2021
1 parent 1755e0f commit 3060a6d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Modules/Core/SpatialObjects/include/itkTubeSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class ITK_TEMPLATE_EXPORT TubeSpatialObject : public PointBasedSpatialObject<TDi
/* Avoid hiding the overload that supports depth and name arguments */
using Superclass::IsInsideInObjectSpace;

void
CopyInformation(const DataObject * data) override;

protected:
/** Compute the boundaries of the tube. */
void
Expand All @@ -129,7 +132,7 @@ class ITK_TEMPLATE_EXPORT TubeSpatialObject : public PointBasedSpatialObject<TDi
void
PrintSelf(std::ostream & os, Indent indent) const override;

typename LightObject::Pointer
virtual typename LightObject::Pointer
InternalClone() const override;

private:
Expand Down
38 changes: 36 additions & 2 deletions Modules/Core/SpatialObjects/include/itkTubeSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,54 @@ TubeSpatialObject<TDimension, TTubePointType>::Clear()
this->Modified();
}

/** Copy the information from another spatial object */
template <unsigned int TDimension, typename TTubePointType>
void
TubeSpatialObject<TDimension, TTubePointType>::CopyInformation(const DataObject * data)
{
// Standard call to the superclass' method
Superclass::CopyInformation(data);

// Attempt to cast data to an ImageBase
const TubeSpatialObject<TDimension> * soData;
soData = dynamic_cast<const TubeSpatialObject<TDimension> *>(data);

if (soData == nullptr)
{
// pointer could not be cast back down
itkExceptionMacro(<< "itk::TubeSpatialObject::CopyInformation() cannot cast " << typeid(data).name() << " to "
<< typeid(TubeSpatialObject<TDimension> *).name());
}

// check if we are the same type
const auto * source = dynamic_cast<const Self *>(data);
if (!source)
{
std::cerr << "CopyInformation: objects are not of the same type" << std::endl;
return;
}

// copy the ivars
this->SetRoot(source->GetRoot());
this->SetEndRounded(source->GetEndRounded());

// Don't copy parent info
// this->SetParentPoint(source->GetParentPoint());
}

/** InternalClone */
template <unsigned int TDimension, typename TTubePointType>
typename LightObject::Pointer
TubeSpatialObject<TDimension, TTubePointType>::InternalClone() const
{
// Default implementation just copies the parameters from
// this to new transform.
typename LightObject::Pointer loPtr = Superclass::InternalClone();

typename Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer());
if (rval.IsNull())
{
itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass() << " failed.");
}

rval->SetEndRounded(this->GetEndRounded());
rval->SetParentPoint(this->GetParentPoint());
rval->SetRoot(this->GetRoot());
Expand Down

0 comments on commit 3060a6d

Please sign in to comment.