00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkOrientedImage_h
00018 #define __itkOrientedImage_h
00019
00020 #include "itkImage.h"
00021 #include "itkImageTransformHelper.h"
00022
00023 namespace itk
00024 {
00025
00030 template <class TPixel, unsigned int VImageDimension>
00031 class ITK_EXPORT OrientedImage : public Image<TPixel, VImageDimension>
00032 {
00033 public:
00035 typedef OrientedImage Self;
00036 typedef Image<TPixel, VImageDimension> Superclass;
00037 typedef SmartPointer<Self> Pointer;
00038 typedef SmartPointer<const Self> ConstPointer;
00039 typedef WeakPointer<const Self> ConstWeakPointer;
00040
00042 itkNewMacro(Self);
00043
00045 itkTypeMacro(OrientedImage, Image);
00046
00048 typedef typename Superclass::IndexType IndexType;
00049
00051 typedef typename Superclass::DirectionType DirectionType;
00052
00055 typedef typename Superclass::SpacingType SpacingType;
00056
00057 typedef typename Superclass::AccessorType AccessorType;
00058 typedef typename Superclass::AccessorFunctorType AccessorFunctorType;
00059
00062 virtual void SetSpacing (const SpacingType spacing)
00063 {
00064 Superclass::SetSpacing(spacing);
00065
00066 DirectionType scale;
00067 for (unsigned int i=0; i < VImageDimension; i++)
00068 {
00069 scale[i][i] = this->m_Spacing[i];
00070 }
00071 m_IndexToPhysicalPoint = this->m_Direction * scale;
00072 m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00073 }
00074
00075 virtual void SetSpacing (const double spacing[VImageDimension])
00076 {
00077 Superclass::SetSpacing(spacing);
00078
00079 DirectionType scale;
00080 for (unsigned int i=0; i < VImageDimension; i++)
00081 {
00082 scale[i][i] = this->m_Spacing[i];
00083 }
00084 m_IndexToPhysicalPoint = this->m_Direction * scale;
00085 m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00086 }
00087
00088 virtual void SetSpacing (const float spacing[VImageDimension])
00089 {
00090 Superclass::SetSpacing(spacing);
00091
00092 DirectionType scale;
00093 for (unsigned int i=0; i < VImageDimension; i++)
00094 {
00095 scale[i][i] = this->m_Spacing[i];
00096 }
00097 m_IndexToPhysicalPoint = this->m_Direction * scale;
00098 m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00099 }
00100
00103 virtual void SetDirection (const DirectionType direction)
00104 {
00105 Superclass::SetDirection(direction);
00106
00107 DirectionType scale;
00108 for (unsigned int i=0; i < VImageDimension; i++)
00109 {
00110 scale[i][i] = this->m_Spacing[i];
00111 }
00112 m_IndexToPhysicalPoint = this->m_Direction * scale;
00113 m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();
00114 }
00115
00120 template<class TCoordRep>
00121 bool TransformPhysicalPointToContinuousIndex(
00122 const Point<TCoordRep, VImageDimension>& point,
00123 ContinuousIndex<TCoordRep, VImageDimension>& index ) const
00124 {
00125 Vector<double, VImageDimension> cvector;
00126
00127 cvector = m_PhysicalPointToIndex * (point - this->m_Origin);
00128 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00129 {
00130 index[i] = static_cast<TCoordRep>(cvector[i]);
00131 }
00132
00133
00134 const bool isInside =
00135 this->GetLargestPossibleRegion().IsInside( index );
00136
00137 return isInside;
00138 }
00139
00144 #if 1
00145 template<class TCoordRep>
00146 bool TransformPhysicalPointToIndex(
00147 const Point<TCoordRep, VImageDimension>& point,
00148 IndexType & index ) const
00149 {
00150 ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformPhysicalPointToIndex(
00151 this->m_PhysicalPointToIndex, this->m_Origin, point, index);
00152
00153
00154 const bool isInside =
00155 this->GetLargestPossibleRegion().IsInside( index );
00156 return isInside;
00157 }
00158 #else
00159 template<class TCoordRep>
00160 bool TransformPhysicalPointToIndex(
00161 const Point<TCoordRep, VImageDimension>& point,
00162 IndexType & index ) const
00163 {
00164 typedef typename IndexType::IndexValueType IndexValueType;
00165 for (unsigned int i = 0; i < VImageDimension; i++)
00166 {
00167 index[i] = 0.0;
00168 for (unsigned int j = 0; j < VImageDimension; j++)
00169 {
00170 index[i] +=
00171 m_PhysicalPointToIndex[i][j] * (point[j] - this->m_Origin[j]);
00172 }
00173 }
00174
00175
00176 const bool isInside =
00177 this->GetLargestPossibleRegion().IsInside( index );
00178
00179 return isInside;
00180 }
00181 #endif
00182
00186 template<class TCoordRep>
00187 void TransformContinuousIndexToPhysicalPoint(
00188 const ContinuousIndex<TCoordRep, VImageDimension>& index,
00189 Point<TCoordRep, VImageDimension>& point ) const
00190 {
00191 Vector<double,VImageDimension> cvector;
00192 for (unsigned int i = 0 ; i < VImageDimension ; i++)
00193 {
00194 cvector[i] = index[i];
00195 }
00196
00197 point = this->m_Origin + m_IndexToPhysicalPoint * cvector;
00198 }
00199
00205 #if 1
00206 template<class TCoordRep>
00207 void TransformIndexToPhysicalPoint(
00208 const IndexType & index,
00209 Point<TCoordRep, VImageDimension>& point ) const
00210 {
00211 ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformIndexToPhysicalPoint(
00212 this->m_IndexToPhysicalPoint, this->m_Origin, index, point);
00213 }
00214 #else
00215 template<class TCoordRep>
00216 void TransformIndexToPhysicalPoint(
00217 const IndexType & index,
00218 Point<TCoordRep, VImageDimension>& point ) const
00219 {
00220 for (unsigned int i = 0; i < VImageDimension; i++)
00221 {
00222 point[i] = this->m_Origin[i];
00223 for (unsigned int j = 0; j < VImageDimension; j++)
00224 {
00225 point[i] += m_IndexToPhysicalPoint[i][j] * index[j];
00226 }
00227 }
00228 }
00229 #endif
00230 protected:
00231 OrientedImage();
00232 virtual ~OrientedImage() {};
00233
00234 private:
00235 OrientedImage(const Self&);
00236 void operator=(const Self&);
00237
00238 DirectionType m_IndexToPhysicalPoint;
00239 DirectionType m_PhysicalPointToIndex;
00240 };
00241 #ifdef ITK_EXPLICIT_INSTANTIATION
00242 extern template class OrientedImage<float ,2>;
00243 extern template class OrientedImage<double ,2>;
00244 extern template class OrientedImage<unsigned char ,2>;
00245 extern template class OrientedImage<unsigned short,2>;
00246 extern template class OrientedImage<unsigned int ,2>;
00247 extern template class OrientedImage<signed char ,2>;
00248 extern template class OrientedImage<signed short ,2>;
00249 extern template class OrientedImage<signed int ,2>;
00250 extern template class OrientedImage<float ,3>;
00251 extern template class OrientedImage<double ,3>;
00252 extern template class OrientedImage<unsigned char ,3>;
00253 extern template class OrientedImage<unsigned short,3>;
00254 extern template class OrientedImage<unsigned int ,3>;
00255 extern template class OrientedImage<signed char ,3>;
00256 extern template class OrientedImage<signed short ,3>;
00257 extern template class OrientedImage<signed int ,3>;
00258 #endif
00259 }
00260 #ifndef ITK_MANUAL_INSTANTIATION
00261 #include "itkOrientedImage.txx"
00262 #endif
00263
00264 #endif
00265