| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkOrientedImage.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:43 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkOrientedImage_h |
| 18 |
|
#define __itkOrientedImage_h |
| 19 |
|
|
| 20 |
|
#include "itkImage.h" |
| 21 |
|
#include "itkImageTransformHelper.h" |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
/** \class OrientedImage |
| 27 |
|
* \brief Templated n-dimensional oriented image class. |
| 28 |
|
* |
| 29 |
|
* \note |
| 30 |
|
* This work is part of the National Alliance for Medical Image Computing |
| 31 |
|
* (NAMIC), funded by the National Institutes of Health through the NIH Roadmap |
| 32 |
|
* for Medical Research, Grant U54 EB005149. |
| 33 |
|
* |
| 34 |
|
* \ingroup ImageObjects */ |
| 35 |
|
template <class TPixel, unsigned int VImageDimension> |
| 36 |
|
class ITK_EXPORT OrientedImage : public Image<TPixel, VImageDimension> |
| 37 |
|
{ |
| 38 |
|
public: |
| 39 |
|
/** Standard class typedefs */ |
| 40 |
|
typedef OrientedImage Self; |
| 41 |
TDA |
typedef Image<TPixel, VImageDimension> Superclass; |
| 42 |
TDA |
typedef SmartPointer<Self> Pointer; |
| 43 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 44 |
TDA |
typedef WeakPointer<const Self> ConstWeakPointer; |
| 45 |
|
|
| 46 |
|
/** Method for creation through the object factory. */ |
| 47 |
|
itkNewMacro(Self); |
| 48 |
|
|
| 49 |
|
/** Run-time type information (and related methods). */ |
| 50 |
|
itkTypeMacro(OrientedImage, Image); |
| 51 |
|
|
| 52 |
|
/** Index typedef support. An index is used to access pixel values. */ |
| 53 |
|
typedef typename Superclass::IndexType IndexType; |
| 54 |
|
|
| 55 |
|
/** Direction typedef support. The direction cosines of the image. */ |
| 56 |
|
typedef typename Superclass::DirectionType DirectionType; |
| 57 |
|
|
| 58 |
|
/** Spacing typedef support. Spacing holds the size of a pixel. The |
| 59 |
|
* spacing is the geometric distance between image samples. */ |
| 60 |
|
typedef typename Superclass::SpacingType SpacingType; |
| 61 |
|
|
| 62 |
|
typedef typename Superclass::AccessorType AccessorType; |
| 63 |
|
typedef typename Superclass::AccessorFunctorType AccessorFunctorType; |
| 64 |
|
typedef typename Superclass::IOPixelType IOPixelType; |
| 65 |
|
|
| 66 |
|
/** Tyepdef for the functor used to access a neighborhood of pixel pointers.*/ |
| 67 |
|
typedef NeighborhoodAccessorFunctor< Self > |
| 68 |
IND |
********************************************NeighborhoodAccessorFunctorType; |
| 69 |
|
|
| 70 |
|
/** Return the NeighborhoodAccessor functor. This method is called by the |
| 71 |
|
* neighborhood iterators. */ |
| 72 |
|
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() |
| 73 |
|
{ return NeighborhoodAccessorFunctorType(); } |
| 74 |
|
|
| 75 |
|
/** Return the NeighborhoodAccessor functor. This method is called by the |
| 76 |
|
* neighborhood iterators. */ |
| 77 |
|
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const |
| 78 |
|
{ return NeighborhoodAccessorFunctorType(); } |
| 79 |
|
|
| 80 |
IND |
***/** Set the spacing of the image and precompute the transforms for |
| 81 |
|
* the image. */ |
| 82 |
|
virtual void SetSpacing (const SpacingType spacing) |
| 83 |
|
{ |
| 84 |
|
Superclass::SetSpacing(spacing); |
| 85 |
|
|
| 86 |
|
DirectionType scale; |
| 87 |
|
for (unsigned int i=0; i < VImageDimension; i++) |
| 88 |
|
{ |
| 89 |
|
scale[i][i] = this->m_Spacing[i]; |
| 90 |
|
} |
| 91 |
|
m_IndexToPhysicalPoint = this->m_Direction * scale; |
| 92 |
|
m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse(); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
virtual void SetSpacing (const double spacing[VImageDimension]) |
| 96 |
|
{ |
| 97 |
|
Superclass::SetSpacing(spacing); |
| 98 |
|
|
| 99 |
|
DirectionType scale; |
| 100 |
|
for (unsigned int i=0; i < VImageDimension; i++) |
| 101 |
|
{ |
| 102 |
|
scale[i][i] = this->m_Spacing[i]; |
| 103 |
|
} |
| 104 |
|
m_IndexToPhysicalPoint = this->m_Direction * scale; |
| 105 |
|
m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse(); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
virtual void SetSpacing (const float spacing[VImageDimension]) |
| 109 |
|
{ |
| 110 |
|
Superclass::SetSpacing(spacing); |
| 111 |
|
|
| 112 |
|
DirectionType scale; |
| 113 |
|
for (unsigned int i=0; i < VImageDimension; i++) |
| 114 |
|
{ |
| 115 |
|
scale[i][i] = this->m_Spacing[i]; |
| 116 |
|
} |
| 117 |
|
m_IndexToPhysicalPoint = this->m_Direction * scale; |
| 118 |
|
m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse(); |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
/** Set the direction of the image and precompute the transforms for |
| 122 |
|
* the image. */ |
| 123 |
|
virtual void SetDirection (const DirectionType direction) |
| 124 |
|
{ |
| 125 |
|
Superclass::SetDirection(direction); |
| 126 |
|
|
| 127 |
|
DirectionType scale; |
| 128 |
|
for (unsigned int i=0; i < VImageDimension; i++) |
| 129 |
|
{ |
| 130 |
|
scale[i][i] = this->m_Spacing[i]; |
| 131 |
|
} |
| 132 |
|
m_IndexToPhysicalPoint = this->m_Direction * scale; |
| 133 |
|
m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse(); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
/** \brief Get the continuous index from a physical point |
| 137 |
|
* |
| 138 |
|
* Returns true if the resulting index is within the image, false otherwise. |
| 139 |
|
* \sa Transform */ |
| 140 |
|
template<class TCoordRep> |
| 141 |
|
bool TransformPhysicalPointToContinuousIndex( |
| 142 |
|
const Point<TCoordRep, VImageDimension>& point, |
| 143 |
|
ContinuousIndex<TCoordRep, VImageDimension>& index ) const |
| 144 |
|
{ |
| 145 |
|
Vector<double, VImageDimension> cvector; |
| 146 |
|
|
| 147 |
|
cvector = m_PhysicalPointToIndex * (point - this->m_Origin); |
| 148 |
SEM,SEM |
for (unsigned int i = 0 ; i < VImageDimension ; i++) |
| 149 |
|
{ |
| 150 |
|
index[i] = static_cast<TCoordRep>(cvector[i]); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
// Now, check to see if the index is within allowed bounds |
| 154 |
|
const bool isInside = |
| 155 |
IND |
******this->GetLargestPossibleRegion().IsInside( index ); |
| 156 |
|
|
| 157 |
|
return isInside; |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
/** Get the index (discrete) from a physical point. |
| 161 |
|
* Floating point index results are truncated to integers. |
| 162 |
|
* Returns true if the resulting index is within the image, false otherwise |
| 163 |
|
* \sa Transform */ |
| 164 |
|
#if 1 |
| 165 |
|
template<class TCoordRep> |
| 166 |
|
bool TransformPhysicalPointToIndex( |
| 167 |
|
const Point<TCoordRep, VImageDimension>& point, |
| 168 |
|
IndexType & index ) const |
| 169 |
|
{ |
| 170 |
LEN,IND |
******ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformPhysicalPointToIndex( |
| 171 |
|
this->m_PhysicalPointToIndex, this->m_Origin, point, index); |
| 172 |
|
|
| 173 |
|
// Now, check to see if the index is within allowed bounds |
| 174 |
|
const bool isInside = |
| 175 |
IND |
******this->GetLargestPossibleRegion().IsInside( index ); |
| 176 |
|
return isInside; |
| 177 |
|
} |
| 178 |
IND |
#else |
| 179 |
|
template<class TCoordRep> |
| 180 |
|
bool TransformPhysicalPointToIndex( |
| 181 |
|
const Point<TCoordRep, VImageDimension>& point, |
| 182 |
|
IndexType & index ) const |
| 183 |
|
{ |
| 184 |
|
typedef typename IndexType::IndexValueType IndexValueType; |
| 185 |
|
for (unsigned int i = 0; i < VImageDimension; i++) |
| 186 |
|
{ |
| 187 |
|
index[i] = 0.0; |
| 188 |
|
for (unsigned int j = 0; j < VImageDimension; j++) |
| 189 |
|
{ |
| 190 |
|
index[i] += |
| 191 |
|
m_PhysicalPointToIndex[i][j] * (point[j] - this->m_Origin[j]); |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
// Now, check to see if the index is within allowed bounds |
| 196 |
|
const bool isInside = |
| 197 |
IND |
******this->GetLargestPossibleRegion().IsInside( index ); |
| 198 |
|
|
| 199 |
|
return isInside; |
| 200 |
|
} |
| 201 |
|
#endif |
| 202 |
|
/** Get a physical point (in the space which |
| 203 |
|
* the origin and spacing infomation comes from) |
| 204 |
|
* from a continuous index (in the index space) |
| 205 |
|
* \sa Transform */ |
| 206 |
|
template<class TCoordRep> |
| 207 |
|
void TransformContinuousIndexToPhysicalPoint( |
| 208 |
|
const ContinuousIndex<TCoordRep, VImageDimension>& index, |
| 209 |
|
Point<TCoordRep, VImageDimension>& point ) const |
| 210 |
|
{ |
| 211 |
|
Vector<double,VImageDimension> cvector; |
| 212 |
SEM,SEM |
for (unsigned int i = 0 ; i < VImageDimension ; i++) |
| 213 |
|
{ |
| 214 |
|
cvector[i] = index[i]; |
| 215 |
|
} |
| 216 |
|
|
| 217 |
|
point = this->m_Origin + m_IndexToPhysicalPoint * cvector; |
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
/** Get a physical point (in the space which |
| 221 |
|
* the origin and spacing infomation comes from) |
| 222 |
|
* from a discrete index (in the index space) |
| 223 |
|
* |
| 224 |
|
* \sa Transform */ |
| 225 |
|
#if 1 |
| 226 |
|
template<class TCoordRep> |
| 227 |
|
void TransformIndexToPhysicalPoint( |
| 228 |
|
const IndexType & index, |
| 229 |
|
Point<TCoordRep, VImageDimension>& point ) const |
| 230 |
|
{ |
| 231 |
LEN,IND |
******ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformIndexToPhysicalPoint( |
| 232 |
|
this->m_IndexToPhysicalPoint, this->m_Origin, index, point); |
| 233 |
|
} |
| 234 |
IND |
#else |
| 235 |
|
template<class TCoordRep> |
| 236 |
|
void TransformIndexToPhysicalPoint( |
| 237 |
|
const IndexType & index, |
| 238 |
|
Point<TCoordRep, VImageDimension>& point ) const |
| 239 |
|
{ |
| 240 |
|
for (unsigned int i = 0; i < VImageDimension; i++) |
| 241 |
|
{ |
| 242 |
|
point[i] = this->m_Origin[i]; |
| 243 |
|
for (unsigned int j = 0; j < VImageDimension; j++) |
| 244 |
|
{ |
| 245 |
|
point[i] += m_IndexToPhysicalPoint[i][j] * index[j]; |
| 246 |
|
} |
| 247 |
|
} |
| 248 |
|
} |
| 249 |
|
#endif |
| 250 |
|
protected: |
| 251 |
|
OrientedImage(); |
| 252 |
|
virtual ~OrientedImage() {}; |
| 253 |
|
|
| 254 |
|
private: |
| 255 |
|
OrientedImage(const Self&); //purposely not implemented |
| 256 |
|
void operator=(const Self&); //purposely not implemented |
| 257 |
|
|
| 258 |
|
DirectionType m_IndexToPhysicalPoint; |
| 259 |
|
DirectionType m_PhysicalPointToIndex; |
| 260 |
|
}; |
| 261 |
|
#ifdef ITK_EXPLICIT_INSTANTIATION |
| 262 |
|
extern template class OrientedImage<float ,2>; |
| 263 |
IND |
***extern template class OrientedImage<double ,2>; |
| 264 |
IND |
***extern template class OrientedImage<unsigned char ,2>; |
| 265 |
IND |
***extern template class OrientedImage<unsigned short,2>; |
| 266 |
IND |
***extern template class OrientedImage<unsigned int ,2>; |
| 267 |
IND |
***extern template class OrientedImage<signed char ,2>; |
| 268 |
IND |
***extern template class OrientedImage<signed short ,2>; |
| 269 |
IND |
***extern template class OrientedImage<signed int ,2>; |
| 270 |
IND |
***extern template class OrientedImage<float ,3>; |
| 271 |
IND |
***extern template class OrientedImage<double ,3>; |
| 272 |
IND |
***extern template class OrientedImage<unsigned char ,3>; |
| 273 |
IND |
***extern template class OrientedImage<unsigned short,3>; |
| 274 |
IND |
***extern template class OrientedImage<unsigned int ,3>; |
| 275 |
IND |
***extern template class OrientedImage<signed char ,3>; |
| 276 |
IND |
***extern template class OrientedImage<signed short ,3>; |
| 277 |
IND |
***extern template class OrientedImage<signed int ,3>; |
| 278 |
|
#endif |
| 279 |
|
} // end namespace itk |
| 280 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 281 |
|
#include "itkOrientedImage.txx" |
| 282 |
|
#endif |
| 283 |
|
|
| 284 |
|
#endif |
| 285 |
|
|
| 286 |
EOF |
|