Shapeworks Studio  2.1
Shape analysis software suite
itkPSMSurfaceNeighborhood.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 __itkPSMSurfaceNeighborhood_hxx
19 #define __itkPSMSurfaceNeighborhood_hxx
20 #include "itkPSMSurfaceNeighborhood.h"
21 
22 namespace itk
23 {
24 template <class TImage>
25 typename PSMSurfaceNeighborhood<TImage>::PointVectorType
28  std::vector<double> &weights, double radius) const
29 {
30  const DomainType *domain = dynamic_cast<const DomainType *>(this->GetDomain());
31  GradientVectorType posnormal = domain->SampleNormalVnl(center, 1.0e-10);
32  // double posnormalmag = posnormal.magnitude();
33  weights.clear();
34 
35  // Compute bounding box of the given hypersphere.
36  PointType l, u;
37  for (unsigned int i = 0; i < Dimension; i++)
38  {
39  l[i] = center[i] - radius;
40  u[i] = center[i] + radius;
41  }
42 
43  // Grab the list of points in this bounding box.
44  typename PointTreeType::PointIteratorListType pointlist
45  = Superclass::m_Tree->FindPointsInRegion(l, u);
46 
47  // Allocate return vector. Reserve ensures no extra copies occur.
48  PointVectorType ret;
49  ret.reserve(pointlist.size());
50  weights.reserve(pointlist.size());
51 
52  std::vector<double> vec_dist;
53  std::vector<double> vec_cos;
54 
55  // Add any point whose distance from center is less than radius to the return
56  // list.
57  // double vmax = radius;
58  for (typename PointTreeType::PointIteratorListType::const_iterator it = pointlist.begin();
59  it != pointlist.end(); it++)
60  {
61  // double dist = this->GetDomain()->Distance(center, (*it)->Point);
62  double sum = 0.0;
63  for (unsigned int i = 0; i < Dimension; i++)
64  {
65  double q = center[i] - (*it)->Point[i];
66  sum += q*q;
67  }
68  sum = sqrt(sum);
69 
70  if ( sum < radius && sum > 0.0 )
71  {
72  GradientVectorType pn = domain->SampleNormalVnl((*it)->Point, 1.0e-10);
73  double cosine = dot_product(posnormal,pn); // normals already normalized
74  // double cosine = proj / (posnormalmag * pn.magnitude() + 1.0e-6);
75 
76  // double dist =
77 
78 
79  if ( cosine >= m_FlatCutoff)
80  {
81  // Determine distance to tangent plane by projecting the point onto the
82  // normal.
83  weights.push_back(1.0);
84 
85  }
86  else
87  {
88  // Drop to zero influence over 90 degrees.
89  weights.push_back(cos((m_FlatCutoff - cosine) / (1.0+m_FlatCutoff) * 1.5708));
90 
91  // More quickly drop to zero influence
92  // weights.push_back( exp((cosine - m_FlatCutoff) / (1.0 + m_FlatCutoff) * 4.0) );
93 
94  // vmax = dist;
95  }
96 
97  ret.push_back( **it );
98  }
99 
100  }
101 
102  return ret;
103 }
104 
105 }
106 
107 #endif
virtual PointVectorType FindNeighborhoodPointsWithWeights(const PointType &, std::vector< double > &, double) const
Base class for defining the domain in which a particle system exists.
Definition: itkPSMDomain.h:48
std::vector< PSMPointIndexPair< VDimension > > PointVectorType