1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 #ifndef itkContinuousIndex_h 19 #define itkContinuousIndex_h 20 21 #include "itkPoint.h" 22 #include "itkIndex.h" 23 24 #include <type_traits> // For is_floating_point. 25 26 namespace itk 27 { 28 /** \class ContinuousIndex 29 * \brief A templated class holding a point in n-Dimensional image space. 30 * 31 * ContinuousIndex is a templated class that holds a set of coordinates 32 * (components). 33 * The template parameter TCoordRep can be any floating point type (float, double). 34 * The VIndexDimension defines the number of components in the continuous 35 * index array. 36 * 37 * \sa Point 38 * \sa Index 39 * 40 * \ingroup ImageAccess 41 * \ingroup ImageObjects 42 * 43 * \ingroup ITKCommon 44 */ 45 template< typename TCoordRep = double, unsigned int VIndexDimension = 2 > 46 class ContinuousIndex:public Point< TCoordRep, VIndexDimension > 47 { 48 static_assert(std::is_floating_point<TCoordRep>::value, 49 "The coordinates of a continuous index must be represented by floating point numbers."); 50 51 public: 52 /** Standard class type aliases. */ 53 using Self = ContinuousIndex; 54 using Superclass = Point< TCoordRep, VIndexDimension >; 55 56 /** ValueType can be used to declare a variable that is the same type 57 * as a data element held in an Point. */ 58 using ValueType = TCoordRep; 59 using CoordRepType = TCoordRep; 60 61 /** Dimension of the Space */ 62 static constexpr unsigned int IndexDimension = VIndexDimension; 63 64 /** Corresponding discrete index type */ 65 using IndexType = Index< VIndexDimension >; 66 67 /** The Array type from which this Vector is derived. */ 68 using BaseArray = typename Superclass::BaseArray; 69 using Iterator = typename BaseArray::Iterator; 70 using ConstIterator = typename BaseArray::ConstIterator; 71 72 /** Constructors */ 73 ContinuousIndex() = default; 74 ContinuousIndex(const ContinuousIndex &) = default; 75 ContinuousIndex(ContinuousIndex &&) = default; 76 ContinuousIndex & operator=(const ContinuousIndex &) = default; 77 ContinuousIndex & operator=(ContinuousIndex &&) = default; 78 ~ContinuousIndex() = default; 79 80 /** Pass-through constructor to the Point base class. */ ContinuousIndex(const ValueType r[IndexDimension])81 ContinuousIndex(const ValueType r[IndexDimension]):Superclass(r) {} 82 83 /** Construct from discrete index type */ ContinuousIndex(const IndexType & index)84 ContinuousIndex(const IndexType & index) 85 { 86 for ( unsigned int i = 0; i < VIndexDimension; i++ ) 87 { 88 ( *this )[i] = static_cast<TCoordRep>(index[i]); 89 } 90 } 91 }; 92 } // namespace itk 93 94 #endif 95