18 #ifndef __itkPoint_txx
19 #define __itkPoint_txx
21 #include <vnl/vnl_math.h>
32 template<
class T,
unsigned int TPo
intDimension>
33 Point<T, TPointDimension>&
37 BaseArray::operator=(r);
45 template<
class T,
unsigned int TPo
intDimension>
50 BaseArray::operator=(r);
58 template<
class T,
unsigned int TPo
intDimension>
63 for(
unsigned int i=0; i<TPointDimension; i++)
74 template<
class T,
unsigned int TPo
intDimension>
79 for(
unsigned int i=0; i<TPointDimension; i++)
91 template<
class T,
unsigned int TPo
intDimension>
97 for(
unsigned int i=0; i<TPointDimension; i++)
99 result[i] = (*this)[i] + vec[i];
107 template<
class T,
unsigned int TPo
intDimension>
113 for(
unsigned int i=0; i<TPointDimension; i++)
115 result[i] = (*this)[i] - vec[i];
123 template<
class T,
unsigned int TPo
intDimension>
129 for(
unsigned int i=0; i<TPointDimension; i++)
131 result[i] = (*this)[i] - pnt[i];
139 template<
class T,
unsigned int TPo
intDimension >
144 return vnl_vector_ref< T >( TPointDimension, this->GetDataPointer());
150 template<
class T,
unsigned int TPo
intDimension>
159 return vnl_vector_ref<T>( TPointDimension,
160 const_cast<T*
>(this->GetDataPointer()));
166 template<
class T,
unsigned int TPo
intDimension >
171 return vnl_vector_ref< T >( TPointDimension, this->GetDataPointer());
177 template<
class T,
unsigned int TPo
intDimension>
186 return vnl_vector_ref<T>( TPointDimension,
187 const_cast<T*
>(this->GetDataPointer()));
190 template<
class T,
unsigned int TPo
intDimension >
202 template<
class T,
unsigned int TPo
intDimension>
207 for(
unsigned int i=0; i<TPointDimension; i++)
209 (*this)[i] = ( A[i] + B[i] ) /2.0;
216 template<
class T,
unsigned int TPo
intDimension>
223 const double wa = alpha;
224 const double wb = 1.0 - alpha;
225 for(
unsigned int i=0; i<TPointDimension; i++)
227 (*this)[i] = wa * A[i] + wb * B[i];
234 template<
class T,
unsigned int TPo
intDimension>
243 const double weightForC = 1.0 - weightForA - weightForB;
244 for(
unsigned int i=0; i<TPointDimension; i++)
246 (*this)[i] = weightForA * A[i] + weightForB * B[i] + weightForC * C[i];
253 template<
class T,
unsigned int TPo
intDimension>
257 const double * weights,
unsigned int N )
259 this->Fill( NumericTraits<T>::Zero );
260 double weightSum = 0.0;
261 for(
unsigned int j=0; j<N-1; j++)
263 const double weight = weights[j];
265 for(
unsigned int i=0; i<TPointDimension; i++)
267 (*this)[i] += weight * P[j][i];
270 const double weight = ( 1.0 - weightSum );
271 for(
unsigned int i=0; i<TPointDimension; i++)
273 (*this)[i] += weight * P[N-1][i];
281 template<
class TPo
intContainer,
class TWeightContainer >
290 typedef typename TPointContainer::Element
PointType;
291 typedef typename PointType::ValueType ValueType;
292 PointType barycentre;
293 barycentre.Fill( NumericTraits< ValueType >::Zero );
295 typename TPointContainer::Iterator point = points->Begin();
296 typename TPointContainer::Iterator
final = points->End();
297 typename TPointContainer::Iterator last =
final;
300 double weightSum = 0.0;
302 const unsigned int PointDimension = PointType::PointDimension;
305 while( point != last )
307 const double weight = weights[j++];
309 for(
unsigned int i=0; i<PointDimension; i++)
311 barycentre[i] += weight * (point->Value())[i];
318 const double weight = ( 1.0 - weightSum );
319 for(
unsigned int i=0; i<PointDimension; i++)
321 barycentre[i] += weight * (last->Value())[i];
331 template<
class T,
unsigned int TPo
intDimension>
333 operator<<(std::ostream& os,const Point<T,TPointDimension> & vct )
336 if ( TPointDimension == 1)
342 for(
unsigned int i=0; i+1<TPointDimension; i++)
344 os << vct[i] <<
", ";
346 os << vct[TPointDimension-1];
355 template<
class T,
unsigned int TPo
intDimension>
359 for(
unsigned int i=0; i<TPointDimension; i++)