1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkPointBasedSpatialObject_h
#define itkPointBasedSpatialObject_h
#include "itkSpatialObject.h"
#include "itkSpatialObjectPoint.h"
namespace itk
{
/**
* \class PointBasedSpatialObject
* \brief This class serves as the base class for point-based spatial objects
*
* A PointBasedSpatialObject is an abstract class to support
* PointBasedSpatialObject filters and algorithms.
*
* \ingroup ITKSpatialObjects
*/
template <unsigned int TDimension = 3, class TSpatialObjectPointType = SpatialObjectPoint<TDimension>>
class ITK_TEMPLATE_EXPORT PointBasedSpatialObject : public SpatialObject<TDimension>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(PointBasedSpatialObject);
using Self = PointBasedSpatialObject;
using Superclass = SpatialObject<TDimension>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
using ScalarType = double;
using SpatialObjectPointType = TSpatialObjectPointType;
using SpatialObjectPointListType = std::vector<SpatialObjectPointType>;
using typename Superclass::PointType;
using typename Superclass::TransformType;
using typename Superclass::VectorType;
using typename Superclass::CovariantVectorType;
using typename Superclass::BoundingBoxType;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** \see LightObject::GetNameOfClass() */
itkOverrideGetNameOfClassMacro(PointBasedSpatialObject);
/** Reset the spatial object to its initial condition, yet preserves
* Id, Parent, and Child information */
void
Clear() override;
/** Assign points to this object, and assigned this object to
* each point (for computing world coordinates) */
virtual void
AddPoint(const SpatialObjectPointType & newPoint);
/** Removes the indicated point from this object. */
virtual void
RemovePoint(IdentifierType id);
/** Assign points to this object, and assigned this object to
* each point (for computing world coordinates). */
virtual void
SetPoints(const SpatialObjectPointListType & newPoints);
/** Get the list of points assigned to this object. */
virtual SpatialObjectPointListType &
GetPoints()
{
return m_Points;
}
/** Get a const list of the points assigned to this object */
virtual const SpatialObjectPointListType &
GetPoints() const
{
return m_Points;
}
/** Return a SpatialObjectPoint given its position in the list */
virtual const SpatialObjectPointType *
GetPoint(IdentifierType id) const
{
return &(m_Points[id]);
}
virtual SpatialObjectPointType *
GetPoint(IdentifierType id)
{
return &(m_Points[id]);
}
/** Return the number of points in the list */
virtual SizeValueType
GetNumberOfPoints() const
{
return static_cast<SizeValueType>(m_Points.size());
}
/** Get the closest point in world space. */
TSpatialObjectPointType
ClosestPointInWorldSpace(const PointType & point) const;
/** Get the closest point in object space. */
TSpatialObjectPointType
ClosestPointInObjectSpace(const PointType & point) const;
/** Test if a world-coordinate point is inside of this object or its children.
*
* Returns true if the point is inside the blob, false otherwise.
*/
bool
IsInsideInObjectSpace(const PointType & point) const override;
/* Avoid hiding the overload that supports depth and name arguments */
using Superclass::IsInsideInObjectSpace;
protected:
/** Compute the boundaries of the Blob. */
void
ComputeMyBoundingBox() override;
PointBasedSpatialObject();
~PointBasedSpatialObject() override = default;
SpatialObjectPointListType m_Points{};
/** Method to print the object.*/
void
PrintSelf(std::ostream & os, Indent indent) const override;
typename LightObject::Pointer
InternalClone() const override;
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkPointBasedSpatialObject.hxx"
#endif
#endif // itkPointBasedSpatialObject_h
|