Shapeworks Studio  2.1
Shape analysis software suite
itkPSMMeanCurvatureAttribute.hxx
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 __itkPSMMeanCurvatureAttribute_hxx
19 #define __itkPSMMeanCurvatureAttribute_hxx
20 #include "itkPSMMeanCurvatureAttribute.h"
21 
22 #include "itkZeroCrossingImageFilter.h"
23 #include "itkImageRegionConstIteratorWithIndex.h"
24 
25 namespace itk
26 {
27 
28 template <class TNumericType, unsigned int VDimension>
29 void
31 ComputeCurvatureStatistics(const ParticleSystemType *system, unsigned int d)
32 {
34  typedef typename DomainType::ImageType ImageType;
35 
36  // Loop through a zero crossing image, project all the zero crossing points
37  // to the surface, and use those points to comput curvature stats.
38  typedef itk::ZeroCrossingImageFilter<ImageType, ImageType> ZeroCrossingImageFilterType;
39  typename ZeroCrossingImageFilterType::Pointer zc = ZeroCrossingImageFilterType::New() ;
40  zc->SetInput( dynamic_cast<const DomainType *>(system->GetDomain(d))->GetImage() );
41  zc->Update();
42 
43  itk::ImageRegionConstIteratorWithIndex<ImageType> it(zc->GetOutput(),
44  zc->GetOutput()->GetRequestedRegion());
45  std::vector<double> datalist;
46  m_MeanCurvatureList[d] = 0.0;
47  m_CurvatureStandardDeviationList[d] = 0.0;
48  const DomainType *domain = static_cast<const DomainType *>(system->GetDomain(d));
49 
50  for (; ! it.IsAtEnd(); ++it)
51  {
52  if (it.Get() == 1.0)
53  {
54  // Find closest pixel location to surface.
55  PointType pos;
56  domain->GetImage()->TransformIndexToPhysicalPoint(it.GetIndex(), pos);
57 
58  // Project point to surface.
59  // Make sure constraints are enabled
60  // bool c = domain->GetConstraintsEnabled();
61  // domain->EnableConstraints();
62  domain->ApplyConstraints(pos);
63  // domain->SetConstraintsEnabled(c);
64 
65  // Compute curvature at point.
66  double mc = domain->GetCurvature(pos);
67  m_MeanCurvatureList[d] += mc;
68  datalist.push_back(mc);
69  }
70  }
71  double n = static_cast<double>(datalist.size());
72  m_MeanCurvatureList[d] /= n;
73 
74  // Compute std deviation using point list
75  for (unsigned int i = 0; i < datalist.size(); i++)
76  {
77  m_CurvatureStandardDeviationList[d] += (datalist[i] - m_MeanCurvatureList[d]) * (datalist[i] - m_MeanCurvatureList[d]);
78  }
79  m_CurvatureStandardDeviationList[d] = sqrt(m_CurvatureStandardDeviationList[d] / (n-1));
80 }
81 
82 } // end namespace itk
83 
84 #endif
virtual void ComputeCurvatureStatistics(const ParticleSystemType *, unsigned int d)
A facade class that manages interactions with a particle system.
DomainType * GetDomain(unsigned int i)
Definition: Shape.h:14