Skip to content

Commit

Permalink
Merge pull request #4856 from N-Dekker/VectorContainer-default-index
Browse files Browse the repository at this point in the history
Make the index type of VectorContainer `itk::SizeValueType` by default
  • Loading branch information
thewtex authored Oct 7, 2024
2 parents 89bb76b + edae0bc commit ed46040
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkSTLConstContainerAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace itk
* Here's a usage example of STLContainerAdaptor
*
\code
itk::STLConstContainerAdaptor<itk::VectorContainer<SizeValueType, ElementType>> vecAdaptor(aContainer);
itk::STLConstContainerAdaptor<itk::VectorContainer<ElementType>> vecAdaptor(aContainer);
const std::vector<ElementType> & vec = vecAdaptor.GetSTLContainerRef();
// do things with vec ...
\endcode
Expand Down
21 changes: 20 additions & 1 deletion Modules/Core/Common/include/itkVectorContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
#include "itkObject.h"
#include "itkObjectFactory.h"

#include <type_traits> // For is_void_v.
#include <utility>
#include <vector>

namespace itk
{
namespace detail
{
/** \class VectorContainer
* \brief Define a front-end to the STL "vector" container that conforms to the
* IndexedContainerInterface.
Expand Down Expand Up @@ -561,14 +564,30 @@ class ITK_TEMPLATE_EXPORT VectorContainer
, VectorType(first, last)
{}
};
} // namespace detail


/** Alias template, allowing to use `itk::VectorContainer<TElement>` without having to explicitly specify its
* `ElementIdentifier` type.
*
* The template parameters `T1` and `T2` allow specifying the index type and the element type, as follows:
*
* \tparam T1 The index type OR (when `T2` is `void`) the element type.
*
* \tparam T2 The element type OR `void`. When `T2` is `void`, the element type is specified by the first template
* argument (T1), and the index type will be `SizeValueType`.
*/
template <typename T1, typename T2 = void>
using VectorContainer = detail::VectorContainer<std::conditional_t<std::is_void_v<T2>, SizeValueType, T1>,
std::conditional_t<std::is_void_v<T2>, T1, T2>>;


/** Makes a VectorContainer that has a copy of the specified `std::vector`. */
template <typename TElement>
auto
MakeVectorContainer(std::vector<TElement> stdVector)
{
auto vectorContainer = VectorContainer<SizeValueType, TElement>::New();
auto vectorContainer = VectorContainer<TElement>::New();
vectorContainer->CastToSTLContainer() = std::move(stdVector);
return vectorContainer;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkVectorContainer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "itkNumericTraits.h"

namespace itk
namespace itk::detail
{

template <typename TElementIdentifier, typename TElement>
Expand Down Expand Up @@ -183,6 +183,6 @@ template <typename TElementIdentifier, typename TElement>
void
VectorContainer<TElementIdentifier, TElement>::Squeeze()
{}
} // end namespace itk
} // namespace itk::detail

#endif
6 changes: 3 additions & 3 deletions Modules/Core/Common/test/itkVectorContainerGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
using TestedElementIdentifierType = size_t;

// Test template instantiations for various TElement template arguments:
template class itk::VectorContainer<TestedElementIdentifierType, int>;
template class itk::VectorContainer<TestedElementIdentifierType, bool>;
template class itk::VectorContainer<TestedElementIdentifierType, std::string>;
template class itk::detail::VectorContainer<TestedElementIdentifierType, int>;
template class itk::detail::VectorContainer<TestedElementIdentifierType, bool>;
template class itk::detail::VectorContainer<TestedElementIdentifierType, std::string>;


namespace
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Mesh/include/itkMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ITK_TEMPLATE_EXPORT Mesh : public PointSet<TPixelType, VDimension, TMeshTr
using CellDataContainer = typename MeshTraits::CellDataContainer;

/** For improving Python support for Triangle Meshes **/
using CellsVectorContainer = typename itk::VectorContainer<IdentifierType, IdentifierType>;
using CellsVectorContainer = typename itk::VectorContainer<IdentifierType>;
using CellsVectorContainerPointer = typename CellsVectorContainer::Pointer;

/** Used to support geometric operations on the toolkit. */
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/SpatialObjects/include/itkBlobSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ITK_TEMPLATE_EXPORT BlobSpatialObject : public PointBasedSpatialObject<TDi
using typename Superclass::SpatialObjectPointType;
using typename Superclass::TransformType;
using typename Superclass::BoundingBoxType;
using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;

/** Method for creation through the object factory. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ITK_TEMPLATE_EXPORT ContourSpatialObject
using typename Superclass::PointType;
using typename Superclass::TransformType;
using typename Superclass::BoundingBoxType;
using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;

using InterpolationMethodEnum = ContourSpatialObjectEnums::InterpolationMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ITK_TEMPLATE_EXPORT DTITubeSpatialObject
using typename Superclass::PointType;
using typename Superclass::TransformType;
using typename Superclass::SpatialObjectPointType;
using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;
using typename Superclass::VectorType;
using typename Superclass::CovariantVectorType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ITK_TEMPLATE_EXPORT EllipseSpatialObject : public SpatialObject<TDimension
using typename Superclass::PointType;
using typename Superclass::TransformType;
using typename Superclass::BoundingBoxType;
using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;

using ArrayType = FixedArray<double, TDimension>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ITK_TEMPLATE_EXPORT LandmarkSpatialObject : public PointBasedSpatialObject
using typename Superclass::PointType;
using typename Superclass::TransformType;
using typename Superclass::BoundingBoxType;
using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;

/** Method for creation through the object factory. */
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/SpatialObjects/include/itkLineSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ITK_TEMPLATE_EXPORT LineSpatialObject
using typename Superclass::PointType;
using typename Superclass::TransformType;
using typename Superclass::BoundingBoxType;
using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;

/** Method for creation through the object factory. */
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/SpatialObjects/include/itkMeshSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ITK_TEMPLATE_EXPORT MeshSpatialObject : public SpatialObject<TMesh::PointD
using typename Superclass::PointType;
using typename Superclass::BoundingBoxType;

using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = typename PointContainerType::Pointer;

/** Method for creation through the object factory. */
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/SpatialObjects/include/itkSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ITK_TEMPLATE_EXPORT SpatialObject : public DataObject
using TransformPointer = typename TransformType::Pointer;
using TransformConstPointer = const TransformType *;

using VectorContainerType = VectorContainer<IdentifierType, PointType>;
using VectorContainerType = VectorContainer<PointType>;

using BoundingBoxType = BoundingBox<IdentifierType, VDimension, ScalarType, VectorContainerType>;
using BoundingBoxPointer = typename BoundingBoxType::Pointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ITK_TEMPLATE_EXPORT SurfaceSpatialObject
using typename Superclass::BoundingBoxType;
using typename Superclass::CovariantVectorType;

using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;

/** Method for creation through the object factory. */
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/SpatialObjects/include/itkTubeSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ITK_TEMPLATE_EXPORT TubeSpatialObject : public PointBasedSpatialObject<TDi
using typename Superclass::PointType;
using typename Superclass::TransformType;
using typename Superclass::SpatialObjectPointType;
using PointContainerType = VectorContainer<IdentifierType, PointType>;
using PointContainerType = VectorContainer<PointType>;
using PointContainerPointer = SmartPointer<PointContainerType>;
using typename Superclass::VectorType;
using typename Superclass::CovariantVectorType;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Transform/include/itkKernelTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ITK_TEMPLATE_EXPORT KernelTransform : public Transform<TParametersValueTyp
using PointIdentifier = typename PointSetType::PointIdentifier;

/** VectorSet type alias. */
using VectorSetType = itk::VectorContainer<SizeValueType, InputVectorType>;
using VectorSetType = itk::VectorContainer<InputVectorType>;
using VectorSetPointer = typename VectorSetType::Pointer;

/** Get/Set the source landmarks list, which we will denote \f$ p \f$. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ITK_TEMPLATE_EXPORT FastMarchingExtensionImageFilterBase : public FastMarc
/** AuxVarType type alias support */
using AuxValueType = TAuxValue;
using AuxValueVectorType = Vector<AuxValueType, AuxDimension>;
using AuxValueContainerType = VectorContainer<IdentifierType, AuxValueVectorType>;
using AuxValueContainerType = VectorContainer<AuxValueVectorType>;

using AuxValueContainerPointer = typename AuxValueContainerType::Pointer;
using AuxValueContainerConstIterator = typename AuxValueContainerType::ConstIterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FastMarchingTraitsBase
using OutputPixelType = typename OutputDomainType::PixelType;

using NodePairType = NodePair<NodeType, OutputPixelType>;
using NodePairContainerType = VectorContainer<IdentifierType, NodePairType>;
using NodePairContainerType = VectorContainer<NodePairType>;
using NodePairContainerPointer = typename NodePairContainerType::Pointer;
using NodePairContainerIterator = typename NodePairContainerType::Iterator;
using NodePairContainerConstIterator = typename NodePairContainerType::ConstIterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ITK_TEMPLATE_EXPORT GridImageSource : public GenerateImageSource<TOutputIm
using ArrayType = FixedArray<RealType, Self::ImageDimension>;
using BoolArrayType = FixedArray<bool, Self::ImageDimension>;
using PixelArrayType = vnl_vector<RealType>;
using PixelArrayContainerType = VectorContainer<SizeValueType, PixelArrayType>;
using PixelArrayContainerType = VectorContainer<PixelArrayType>;

/** Set/Get kernel function used to create the grid. */
itkSetObjectMacro(KernelFunction, KernelFunctionType);
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/MeshVTK/include/itkVTKPolyDataMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ITKIOMeshVTK_EXPORT VTKPolyDataMeshIO : public MeshIOBase
using StringVectorType = std::vector<StringType>;
using StringStreamType = std::stringstream;
using PointIdVector = std::vector<SizeValueType>;
using PolylinesContainerType = VectorContainer<SizeValueType, PointIdVector>;
using PolylinesContainerType = VectorContainer<PointIdVector>;
using PolylinesContainerPointer = PolylinesContainerType::Pointer;

/** Method for creation through the object factory. */
Expand Down
2 changes: 1 addition & 1 deletion Modules/Registration/Common/include/itkPointsLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace itk
*
* \ingroup ITKRegistrationCommon
*/
template <typename TPointsContainer = VectorContainer<IdentifierType, Point<float, 3>>>
template <typename TPointsContainer = VectorContainer<Point<float, 3>>>
class ITK_TEMPLATE_EXPORT PointsLocator : public Object
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ itkEuclideanDistancePointSetMetricTest3Run(double distanceThreshold)
{
using PointSetType = itk::PointSet<float, Dimension>;
using PointType = typename PointSetType::PointType;
using IdentifierType = itk::IdentifierType;
using PointsContainerType = itk::VectorContainer<IdentifierType, PointType>;
using PointsContainerType = itk::VectorContainer<PointType>;
using PointsLocatorType = itk::PointsLocator<PointsContainerType>;
auto pointsLocator = PointsLocatorType::New();

Expand Down

0 comments on commit ed46040

Please sign in to comment.