Shapeworks Studio  2.1
Shape analysis software suite
itkPSMImageDomain.h
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 __itkPSMImageDomain_h
19 #define __itkPSMImageDomain_h
20 
21 #include "itkImage.h"
22 #include "itkPSMRegionDomain.h"
23 #include "itkLinearInterpolateImageFunction.h"
24 
25 namespace itk
26 {
37 template <class T, unsigned int VDimension>
38 class ITK_EXPORT PSMImageDomain : public PSMRegionDomain<VDimension>
39 {
40 public:
43  typedef PSMRegionDomain<VDimension> Superclass;
44  typedef SmartPointer<Self> Pointer;
45  typedef SmartPointer<const Self> ConstPointer;
46  typedef WeakPointer<const Self> ConstWeakPointer;
47 
49  typedef Image<T, VDimension> ImageType;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(PSMImageDomain, PSMRegionDomain);
56 
58  typedef typename Superclass::PointType PointType;
59 
60  typedef LinearInterpolateImageFunction<ImageType, typename PointType::CoordRepType>
61  ScalarInterpolatorType;
62 
63 
64 
66  itkStaticConstMacro(Dimension, unsigned int, VDimension);
67 
70  void SetImage(ImageType *I)
71  {
72  this->Modified();
73  m_Image= I;
74 
75  // Set up the scalar image and interpolation.
76  m_ScalarInterpolator->SetInputImage(m_Image);
77 
78  // Grab the upper-left and lower-right corners of the bounding box. Points
79  // are always in physical coordinates, not image index coordinates.
80  typename ImageType::RegionType::IndexType idx
81  = m_Image->GetRequestedRegion().GetIndex(); // upper lh corner
82  typename ImageType::RegionType::SizeType sz
83  = m_Image->GetRequestedRegion().GetSize(); // upper lh corner
84 
85  typename ImageType::PointType l0;
86  m_Image->TransformIndexToPhysicalPoint(idx, l0);
87  typename ImageType::PointType u0;
88  m_Image->TransformIndexToPhysicalPoint(idx + sz, u0);
89 
90  // Cast points to higher precision if needed. Parent class uses doubles
91  // because they are compared directly with points in the particle system,
92  // which are always double precision.
93  typename Superclass::PointType l;
94  typename Superclass::PointType u;
95 
96  for (unsigned int i = 0; i < VDimension; i++)
97  {
98  l[i] = static_cast<double>(l0[i]);
99  u[i] = static_cast<double>(u0[i]);
100  }
101 
102  this->SetLowerBound(l);
103  this->SetUpperBound(u);
104  }
105  itkGetObjectMacro(Image, ImageType);
106  itkGetConstObjectMacro(Image, ImageType);
107 
110  inline T Sample(const PointType &p) const
111  { return m_ScalarInterpolator->Evaluate(p); }
112 
114  inline bool IsInsideBuffer(const PointType &p) const
115  { return m_ScalarInterpolator->IsInsideBuffer(p); }
116 
118  itkGetObjectMacro(ScalarInterpolator, ScalarInterpolatorType);
119 
120 protected:
122  {
123  m_ScalarInterpolator = ScalarInterpolatorType::New();
124  }
125 
126  void PrintSelf(std::ostream& os, Indent indent) const
127  {
128  Superclass::PrintSelf(os, indent);
129 
130  os << indent << "m_Image = " << m_Image << std::endl;
131  os << indent << "m_ScalarInterpolator = " << m_ScalarInterpolator << std::endl;
132  }
133  virtual ~PSMImageDomain() {};
134 
135 private:
136  PSMImageDomain(const Self&); //purposely not implemented
137  void operator=(const Self&); //purposely not implemented
138 
139  typename ImageType::Pointer m_Image;
140  typename ScalarInterpolatorType::Pointer m_ScalarInterpolator;
141 };
142 
143 } // end namespace itk
144 
145 #endif
Image< T, VDimension > ImageType
bool IsInsideBuffer(const PointType &p) const
T Sample(const PointType &p) const
void SetImage(ImageType *I)
Superclass::PointType PointType