Skip to content

Commit

Permalink
ENH: Add C++17 [[nodiscard]] to Image "Transform" member functions
Browse files Browse the repository at this point in the history
It would usually be a mistake when a user would unintentionally ignore the
return value of those member functions. Specifically, the overloads of
`TransformPhysicalPointToIndex` and `TransformPhysicalPointToContinuousIndex`
that have two parameters both return a `bool` value. If this return value can be
ignored, it is preferable (for performance reasons) to call the corresponding
overload that has one parameter instead.

The compiler may now produce a warning when the return value of any of those
member functions is unintentionally ignored.
  • Loading branch information
N-Dekker authored and hjmjohnson committed Apr 5, 2023
1 parent 1d03697 commit 63d4354
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
16 changes: 8 additions & 8 deletions Modules/Core/Common/include/itkImageBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
\endcode
* \sa Transform */
template <typename TCoordRep>
IndexType
[[nodiscard]] IndexType
TransformPhysicalPointToIndex(const Point<TCoordRep, VImageDimension> & point) const
{
IndexType index;
Expand All @@ -465,7 +465,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
*
* \sa Transform */
template <typename TCoordRep>
bool
[[nodiscard]] bool
TransformPhysicalPointToIndex(const Point<TCoordRep, VImageDimension> & point, IndexType & index) const
{
index = TransformPhysicalPointToIndex(point);
Expand All @@ -491,7 +491,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
\endcode
* \sa Transform */
template <typename TIndexRep, typename TCoordRep>
ContinuousIndex<TIndexRep, VImageDimension>
[[nodiscard]] ContinuousIndex<TIndexRep, VImageDimension>
TransformPhysicalPointToContinuousIndex(const Point<TCoordRep, VImageDimension> & point) const
{
ContinuousIndex<TIndexRep, VImageDimension> index;
Expand All @@ -518,7 +518,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
*
* \sa Transform */
template <typename TCoordRep, typename TIndexRep>
bool
[[nodiscard]] bool
TransformPhysicalPointToContinuousIndex(const Point<TCoordRep, VImageDimension> & point,
ContinuousIndex<TIndexRep, VImageDimension> & index) const
{
Expand Down Expand Up @@ -554,7 +554,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
* from a continuous index (in the index space)
* \sa Transform */
template <typename TCoordRep, typename TIndexRep>
Point<TCoordRep, VImageDimension>
[[nodiscard]] Point<TCoordRep, VImageDimension>
TransformContinuousIndexToPhysicalPoint(const ContinuousIndex<TIndexRep, VImageDimension> & index) const
{
Point<TCoordRep, VImageDimension> point;
Expand Down Expand Up @@ -587,7 +587,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
*
* \sa Transform */
template <typename TCoordRep>
Point<TCoordRep, VImageDimension>
[[nodiscard]] Point<TCoordRep, VImageDimension>
TransformIndexToPhysicalPoint(const IndexType & index) const
{
Point<TCoordRep, VImageDimension> point;
Expand Down Expand Up @@ -637,7 +637,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
* \sa Image
*/
template <typename TVector>
TVector
[[nodiscard]] TVector
TransformLocalVectorToPhysicalVector(const TVector & inputGradient) const
{
TVector outputGradient;
Expand Down Expand Up @@ -686,7 +686,7 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
*
*/
template <typename TVector>
TVector
[[nodiscard]] TVector
TransformPhysicalVectorToLocalVector(const TVector & inputGradient) const
{
TVector outputGradient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage : public SpecialC

/** Returns the continuous index from a physical point */
template <typename TIndexRep, typename TCoordRep>
ContinuousIndex<TIndexRep, 3>
[[nodiscard]] ContinuousIndex<TIndexRep, 3>
TransformPhysicalPointToContinuousIndex(const Point<TCoordRep, 3> & point) const
{
const RegionType region = this->GetLargestPossibleRegion();
Expand Down Expand Up @@ -217,7 +217,7 @@ class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage : public SpecialC
*
* \sa Transform */
template <typename TCoordRep, typename TIndexRep>
bool
[[nodiscard]] bool
TransformPhysicalPointToContinuousIndex(const Point<TCoordRep, 3> & point,
ContinuousIndex<TIndexRep, 3> & index) const
{
Expand All @@ -233,7 +233,7 @@ class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage : public SpecialC
* Floating point index results are truncated to integers.
*/
template <typename TCoordRep>
IndexType
[[nodiscard]] IndexType
TransformPhysicalPointToIndex(const Point<TCoordRep, 3> & point) const
{
const RegionType region = this->GetLargestPossibleRegion();
Expand Down Expand Up @@ -267,7 +267,7 @@ class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage : public SpecialC
*
* \sa Transform */
template <typename TCoordRep>
bool
[[nodiscard]] bool
TransformPhysicalPointToIndex(const Point<TCoordRep, 3> & point, IndexType & index) const
{
index = this->TransformPhysicalPointToIndex(point);
Expand Down Expand Up @@ -308,7 +308,7 @@ class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage : public SpecialC

/** Returns a physical point from a continuous index. */
template <typename TCoordRep, typename TIndexRep>
Point<TCoordRep, 3>
[[nodiscard]] Point<TCoordRep, 3>
TransformContinuousIndexToPhysicalPoint(const ContinuousIndex<TIndexRep, 3> & index) const
{
Point<TCoordRep, 3> point;
Expand Down Expand Up @@ -346,7 +346,7 @@ class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage : public SpecialC

/** Returns a physical point from a discrete index. */
template <typename TCoordRep>
Point<TCoordRep, 3>
[[nodiscard]] Point<TCoordRep, 3>
TransformIndexToPhysicalPoint(const IndexType & index) const
{
Point<TCoordRep, 3> point;
Expand Down
16 changes: 8 additions & 8 deletions Modules/Core/ImageAdaptors/include/itkImageAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension

/** Returns the continuous index from a physical point. */
template <typename TIndexRep, typename TCoordRep>
ContinuousIndex<TIndexRep, TImage::ImageDimension>
[[nodiscard]] ContinuousIndex<TIndexRep, TImage::ImageDimension>
TransformPhysicalPointToContinuousIndex(const Point<TCoordRep, TImage::ImageDimension> & point) const
{
return m_Image->template TransformPhysicalPointToContinuousIndex<TIndexRep>(point);
Expand All @@ -398,7 +398,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension
*
* \sa Transform */
template <typename TCoordRep>
bool
[[nodiscard]] bool
TransformPhysicalPointToContinuousIndex(const Point<TCoordRep, Self::ImageDimension> & point,
ContinuousIndex<TCoordRep, Self::ImageDimension> & index) const
{
Expand All @@ -407,7 +407,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension

/** Returns the index (discrete) of a voxel from a physical point. */
template <typename TCoordRep>
IndexType
[[nodiscard]] IndexType
TransformPhysicalPointToIndex(const Point<TCoordRep, Self::ImageDimension> & point) const
{
return m_Image->TransformPhysicalPointToIndex(point);
Expand All @@ -422,7 +422,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension
*
* \sa Transform */
template <typename TCoordRep>
bool
[[nodiscard]] bool
TransformPhysicalPointToIndex(const Point<TCoordRep, Self::ImageDimension> & point, IndexType & index) const
{
return m_Image->TransformPhysicalPointToIndex(point, index);
Expand All @@ -442,7 +442,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension

/** Returns a physical point from a continuous index (in the index space) */
template <typename TCoordRep, typename TIndexRep>
Point<TCoordRep, TImage::ImageDimension>
[[nodiscard]] Point<TCoordRep, TImage::ImageDimension>
TransformContinuousIndexToPhysicalPoint(const ContinuousIndex<TIndexRep, Self::ImageDimension> & index) const
{
return m_Image->template TransformContinuousIndexToPhysicalPoint<TIndexRep>(index);
Expand All @@ -462,7 +462,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension

/** Returns a physical point from a discrete index (in the index space) */
template <typename TCoordRep>
Point<TCoordRep, Self::ImageDimension>
[[nodiscard]] Point<TCoordRep, Self::ImageDimension>
TransformIndexToPhysicalPoint(const IndexType & index) const
{
return m_Image->template TransformIndexToPhysicalPoint<TCoordRep>(index);
Expand All @@ -477,7 +477,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension
}

template <typename TVector>
TVector
[[nodiscard]] TVector
TransformLocalVectorToPhysicalVector(const TVector & inputGradient) const
{
TVector outputGradient;
Expand All @@ -494,7 +494,7 @@ class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension
}

template <typename TVector>
TVector
[[nodiscard]] TVector
TransformPhysicalVectorToLocalVector(const TVector & inputGradient) const
{
TVector outputGradient;
Expand Down

0 comments on commit 63d4354

Please sign in to comment.