Shapeworks Studio  2.1
Shape analysis software suite
itkPSMImplicitSurfaceDomain.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 __itkPSMImplicitSurfaceDomain_h
19 #define __itkPSMImplicitSurfaceDomain_h
20 
21 #include "itkPSMImageDomainWithCurvature.h"
22 #include <ctime>
23 
24 namespace itk
25 {
34 template <class T, unsigned int VDimension>
35 class ITK_EXPORT PSMImplicitSurfaceDomain
36  : public PSMImageDomainWithCurvature<T, VDimension>
37 {
38 public:
42  typedef SmartPointer<Self> Pointer;
43  typedef SmartPointer<const Self> ConstPointer;
44  typedef WeakPointer<const Self> ConstWeakPointer;
45  typedef typename Superclass::ImageType ImageType;
46  typedef typename Superclass::PointType PointType;
47  typedef T PixelType;
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(PSMImplicitSurfaceDomain, ParticleClipByRegionDomain);
54 
56  itkStaticConstMacro(Dimension, unsigned int, VDimension);
57 
60  itkSetMacro(Tolerance, T);
61  itkGetMacro(Tolerance, T);
62 
73  virtual bool ApplyConstraints(PointType &p) const;
74 
77  virtual bool ApplyVectorConstraints(vnl_vector_fixed<double, VDimension> &gradE,
78  const PointType &pos,
79  double maxtimestep) const;
80 
87  virtual double Distance(const PointType &, const PointType &) const;
88 
89  void SetCuttingPlane(const vnl_vector<double> &a, const vnl_vector<double> &b,
90  const vnl_vector<double> &c);
91 
92  void RemoveCuttingPlane() { m_UseCuttingPlane = false; }
93 
94  bool IsCuttingPlaneDefined() const {return m_UseCuttingPlane;}
95 
96  const vnl_vector_fixed<double, VDimension> &GetCuttingPlanePoint() const
97  { return m_CuttingPlanePoint; }
98  const vnl_vector_fixed<double, VDimension> &GetCuttingPlaneNormal() const
99  { return m_CuttingPlaneNormal; }
100 
101 
104  void AddSphere(const vnl_vector_fixed<double,VDimension> &v, double r)
105  {
106  if (r > 0)
107  {
108  m_SphereCenterList.push_back(v);
109  m_SphereRadiusList.push_back(r);
110  }
111  }
112 
114  double GetSphereRadius(unsigned int i) const
115  {
116  if (m_SphereRadiusList.size() > i) return m_SphereRadiusList[i];
117  else return 0.0;
118  }
119 
122  vnl_vector_fixed<double, VDimension> GetSphereCenter(unsigned int i) const
123  {
124  if (m_SphereRadiusList.size() > i) return m_SphereCenterList[i];
125  else
126  { return vnl_vector_fixed<double, VDimension>(0.0,0.0,0.0); }
127  }
128 
129  unsigned int GetNumberOfSpheres() const
130  {
131  return m_SphereCenterList.size();
132  }
133 
134 
135 protected:
136  PSMImplicitSurfaceDomain() : m_Tolerance(1.0e-4), m_UseCuttingPlane(false)
137  {
138  srand(time(0));
139  }
140  void PrintSelf(std::ostream& os, Indent indent) const
141  {
142  Superclass::PrintSelf(os, indent);
143  os << indent << "m_Tolerance = " << m_Tolerance << std::endl;
144  }
145  virtual ~PSMImplicitSurfaceDomain() {};
146 
147 private:
148  PixelType m_Tolerance;
149  bool m_UseCuttingPlane;
150  vnl_vector_fixed<double, VDimension> m_CuttingPlanePoint;
151  vnl_vector_fixed<double, VDimension> m_CuttingPlaneNormal;
152 
153  std::vector< vnl_vector_fixed<double, VDimension> > m_SphereCenterList;
154  std::vector< double > m_SphereRadiusList;
155 
156  PSMImplicitSurfaceDomain(const Self&); //purposely not implemented
157  void operator=(const Self&); //purposely not implemented
158 };
159 
160 } // end namespace itk
161 
162 #ifndef ITK_MANUAL_INSTANTIATION
163 #include "itkPSMImplicitSurfaceDomain.hxx"
164 #endif
165 
166 #endif
Image< T, VDimension > ImageType
vnl_vector_fixed< double, VDimension > GetSphereCenter(unsigned int i) const
double GetSphereRadius(unsigned int i) const
void AddSphere(const vnl_vector_fixed< double, VDimension > &v, double r)