/usr/include/InsightToolkit/Common/itkPoint.h is in libinsighttoolkit3-dev 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | /*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkPoint.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkPoint_h
#define __itkPoint_h
#include "itkFixedArray.h"
#include "itkNumericTraits.h"
#include "itkVector.h"
#include <vnl/vnl_vector_ref.h>
namespace itk
{
/** \class Point
* \brief A templated class holding a geometric point in n-Dimensional space.
*
* Point is a templated class that holds a set of coordinates (components).
* Point can be used as the data type held at each pixel in
* an Image or at each vertex of an Mesh. The template parameter T can
* be any data type that behaves like a primitive (or atomic) data type (int,
* short, float, complex). The NPointDimension defines the number of
* components in the point array.
*
* \ingroup Geometry
* \ingroup DataRepresentation
*
* \sa Image \sa Mesh \sa Vector \sa CovariantVector \sa Matrix
*/
template<class TCoordRep, unsigned int NPointDimension=3>
class Point : public FixedArray< TCoordRep, NPointDimension >
{
public:
/** Standard class typedefs. */
typedef Point Self;
typedef FixedArray<TCoordRep,NPointDimension> Superclass;
/** ValueType can be used to declare a variable that is the same type
* as a data element held in an Point. */
typedef TCoordRep ValueType;
typedef TCoordRep CoordRepType;
typedef typename NumericTraits< ValueType >::RealType RealType;
/** Dimension of the Space */
itkStaticConstMacro(PointDimension, unsigned int, NPointDimension);
/** The Array type from which this Vector is derived. */
typedef FixedArray<TCoordRep, NPointDimension> BaseArray;
typedef typename BaseArray::Iterator Iterator;
typedef typename BaseArray::ConstIterator ConstIterator;
/** Get the dimension (size) of the point. */
static unsigned int GetPointDimension()
{ return NPointDimension; }
/** VectorType define the difference between two Points */
typedef Vector< ValueType, NPointDimension > VectorType;
/** Default constructor has nothing to do. */
Point() {}
/** Pass-through constructors for the Array base class. */
template< class TPointValueType >
Point(const Point< TPointValueType, NPointDimension>& r): BaseArray(r) {}
Point(const ValueType r[PointDimension]): BaseArray(r) {}
/** Pass-through assignment operator for the Array base class. */
Point& operator= (const Self& r);
Point& operator= (const ValueType r[NPointDimension]);
/** Compare two points for equality. */
bool
operator==(const Self &pt) const
{
bool same=true;
for (unsigned int i=0; i < PointDimension && same; i++)
{ same = ((*this)[i] == pt[i]); }
return same;
}
/** Compare two points for inequality. */
bool
operator!=(const Self &pt) const
{
bool same=true;
for (unsigned int i=0; i < PointDimension && same; i++)
{ same = ((*this)[i] == pt[i]); }
return !same;
}
/** Point operator+=. Adds a vector to the current point. */
const Self& operator+=(const VectorType &vec);
/** Point operator-=. Subtracts a vector from a current point. */
const Self& operator-=(const VectorType &vec);
/** Computes the Vector difference between two points */
VectorType operator-(const Self &pnt) const;
/** Add a vector to a point. Return a new point. */
Self operator+(const VectorType &vec) const;
/** Subtract a vector from a point. Return a new point. */
Self operator-(const VectorType &vec) const;
/** Access an element of a point. */
VectorType GetVectorFromOrigin() const;
/** Get a vnl_vector_ref referencing the same memory block */
vnl_vector_ref<TCoordRep> GetVnlVector( void );
/** Get a vnl_vector with a copy of the internal memory block. */
vnl_vector<TCoordRep> GetVnlVector( void ) const;
/** Get a vnl_vector_ref referencing the same memory block
* \deprecated Use GetVnlVector() instead. */
vnl_vector_ref<TCoordRep> Get_vnl_vector( void );
/** Get a vnl_vector with a copy of the internal memory block.
* \deprecated Use GetVnlVector() instead. */
vnl_vector<TCoordRep> Get_vnl_vector( void ) const;
/** Set to median point between the two points
* given as arguments
*
* This method computes:
*
* \f[
* \overrightarrow{P}=\frac{(\overrightarrow{A}+\overrightarrow{B})}{2}
* \f]
*
* using the two Points given as arguments, and store the result in
* the Point on which the method is invoked. */
void SetToMidPoint( const Self &, const Self & );
/** Set the current point to a barycentric combination of the two points
* given as arguments.
*
* \param A First point
* \param B Second point
* \param alpha Weight for the first point
*
* The first point is multiplied by \f$ \alpha \f$, the second is multiplied
* by * \f$ (1-\alpha) \f$, and the sum is stored in the Point on which the
* method is invoked.
*
* \f[
* \overrightarrow{P}=\alpha * \overrightarrow{A}+ (1-\alpha)*\overrightarrow{B}
* \f]
*
* If the value of \f$ \alpha \in [0,1] \f$, the resulting point will be placed
* in the line segment \f$ \overline{AB} \f$ joining \f$ \overrightarrow{A} \f$
* and \f$ \overrightarrow{A} \f$
*
* If the value of \f$ \alpha < 0 \f$ the resulting point will be placed outside
* the line segment \f$ \overline{AB} \f$ on the side of \f$ \overrightarrow{A} \f$.
*
* If the value of \f$ \alpha > 1 \f$ the resulting point will be placed outside
* the line segment \f$ \overline{AB} \f$ on the side of \f$ \overrightarrow{B} \f$.
*
* \sa SetToMedian */
void SetToBarycentricCombination( const Self & A, const Self & B, double alpha );
/** Set the current point to a barycentric combination of three points
* Two values are expected to weight the contribution of the first two points,
* the weight of for the third point is computed to ensure that the three weights
* sum 1.
*
* This method computes:
*
* \f[
* \overrightarrow{P}= w_1 * \overrightarrow{P}_1
+ w_2 * \overrightarrow{P}_2
+ (1-w_1-w_2 ) * \overrightarrow{P}_3
* \f]
*
* If the two weight are \f$ \in [0,1] \f$ , The resulting point will alway be placed
* inside the triangle formed by the three points given as arguments. */
void SetToBarycentricCombination( const Self & A, const Self & B, const Self & C,
double weightA, double weightB );
/** Set the current point to a barycentric combination of an array of N points
* An array of (N-1) values is expected to weight the contribution of the
* first (N-1) points, the weight of the Nth point is computed to ensure that
* the N weights sum 1.
*
* This method computes:
*
* \f[
* \overrightarrow{P}= \sum_{i=1}^{N-1} w_i * \overrightarrow{P}_i
+ \left(1- \sum_{i=1}^{N-1} w_i\right) * \overrightarrow{P}_N
* \f]
*/
void SetToBarycentricCombination( const Self * P, const double * weights, unsigned int N);
/** Copy from another Point with a different representation type.
* Casting is done with C-Like rules */
template < typename TCoordRepB >
void CastFrom( const Point<TCoordRepB,NPointDimension> & pa )
{
for(unsigned int i=0; i<NPointDimension; i++ )
{
(*this)[i] = static_cast<TCoordRep>( pa[i] );
}
}
/** Compute the Squared Euclidean Distance from this point to another point
* with a different representation type. Casting is done with
* C-Like rules */
template < typename TCoordRepB >
RealType SquaredEuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
{
RealType sum = NumericTraits< RealType >::Zero;
for(unsigned int i=0; i<NPointDimension; i++ )
{
const RealType component = static_cast< RealType >( pa[i] );
const RealType difference = static_cast< RealType >( (*this)[i] ) - component;
sum += difference * difference;
}
return sum;
}
/** Compute the Euclidean Distance from this point to another point
* with a different representation type. Casting is done with
* C-Like rules */
template < typename TCoordRepB >
RealType EuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
{
const double distance = vcl_sqrt(
static_cast<double>( this->SquaredEuclideanDistanceTo( pa ) ) );
return static_cast<RealType>( distance );
}
};
template< class T, unsigned int NPointDimension >
ITK_EXPORT std::ostream& operator<<(std::ostream& os,
const Point<T,NPointDimension> & v);
template< class T, unsigned int NPointDimension >
ITK_EXPORT std::istream& operator>>(std::istream& is,
Point<T,NPointDimension> & v);
/** \class BarycentricCombination
* Class that computes the barycentric combination of an array of N points
*
* An array of (N-1) values is expected to weight the contribution of the
* first (N-1) points, the weight of the Nth point is computed to ensure that
* the N weights sum 1.
*
* This method computes:
*
* \f[
* \overrightarrow{P}= \sum_{i=1}^{N-1} w_i * \overrightarrow{P}_i
* + \left(1- \sum_{i=1}^{N-1} w_i\right) * \overrightarrow{P}_N
* \f]
*
* The points are expected to be stored in an itkContainer class like
* itk::VectorContainer, responding to the Begin(), End(), Value() API.
*
* The weights are expected to be stored in any array-like container
* having a operator[i].
*
* \ingroup Geometry
*/
template< class TPointContainer, class TWeightContainer >
ITK_EXPORT class BarycentricCombination
{
public:
/** Convenient typedefs. */
typedef TPointContainer PointContainerType;
typedef typename PointContainerType::Pointer PointContainerPointer;
typedef typename PointContainerType::Element PointType;
typedef TWeightContainer WeightContainerType;
BarycentricCombination() {};
~BarycentricCombination() {};
static PointType Evaluate(
const PointContainerPointer & points,
const WeightContainerType & weights );
};
} // end namespace itk
// Define instantiation macro for this template.
#define ITK_TEMPLATE_Point(_, EXPORT, x, y) namespace itk { \
_(2(class EXPORT Point< ITK_TEMPLATE_2 x >)) \
_(1(EXPORT std::ostream& operator<<(std::ostream&, \
const Point< ITK_TEMPLATE_2 x >&))) \
_(1(EXPORT std::istream& operator>>(std::istream&, \
Point< ITK_TEMPLATE_2 x >&))) \
namespace Templates { typedef Point< ITK_TEMPLATE_2 x > Point##y; } \
}
#if ITK_TEMPLATE_EXPLICIT
# include "Templates/itkPoint+-.h"
#endif
#if ITK_TEMPLATE_TXX
# include "itkPoint.txx"
#endif
#endif
|