]> Creatis software - cpMesh.git/blob - lib/cpm/Algorithms/Base/FindClosestPointInMesh.h
First commit
[cpMesh.git] / lib / cpm / Algorithms / Base / FindClosestPointInMesh.h
1 #ifndef __CPM__ALGORITHMS__BASE__FINDCLOSESTPOINTINMESH__H__
2 #define __CPM__ALGORITHMS__BASE__FINDCLOSESTPOINTINMESH__H__
3
4 #include <itkObject.h>
5 #include <itkWeightedCentroidKdTreeGenerator.h>
6 #include <itkListSample.h>
7
8 #include <cpm/DataStructures/KDVector.h>
9
10 namespace cpm
11 {
12   namespace Algorithms
13   {
14     namespace Base
15     {
16       /**
17        */
18       template< class M, class S = float >
19       class FindClosestPointInMesh
20         : public itk::Object
21       {
22       public:
23         typedef FindClosestPointInMesh          Self;
24         typedef itk::Object                     Superclass;
25         typedef itk::SmartPointer< Self >       Pointer;
26         typedef itk::SmartPointer< const Self > ConstPointer;
27
28         itkStaticConstMacro( Dimension, unsigned int, M::PointDimension );
29         typedef S                                             TKDScalar;
30         typedef cpm::DataStructures::KDVector< S, Dimension > TKDVector;
31         typedef itk::Statistics::ListSample< TKDVector >      TKDSample;
32
33         typedef
34         itk::Statistics::WeightedCentroidKdTreeGenerator< TKDSample >
35         TKDGenerator;
36         typedef typename TKDGenerator::KdTreeType TKDTree;
37         typedef typename TKDTree::KdTreeNodeType  TKDNode;
38
39       public:
40         itkNewMacro( Self );
41         itkTypeMacro( FindClosestPointInMesh, itkObject );
42
43         itkGetConstMacro( BucketSize, unsigned int );
44         itkSetMacro( BucketSize, unsigned int );
45
46         itkGetConstObjectMacro( Mesh, M );
47
48       public:
49         void SetMesh( const M* m );
50
51         void Build( );
52
53         template< class P >
54         typename M::PointIdentifier FindClosestPoint( const P& p ) const;
55
56         template< class P, class C >
57         typename M::PointIdentifier FindClosestPoint(
58           const P& p, const C& c
59           ) const;
60
61         template< class V, class N >
62         void _Dummy( TKDNode* root, const V& d, const V& n, const N& nd ) const;
63
64       protected:
65         FindClosestPointInMesh( );
66         virtual ~FindClosestPointInMesh( );
67
68         template< class V, class N, class P >
69         static S _LinePointDistance( const P& p0, const V& d, const V& n, const N& nd );
70
71       private:
72         // Purposely not implemented
73         FindClosestPointInMesh( Self& );
74         Self& operator=( Self& );
75
76       protected:
77         unsigned int                   m_BucketSize;
78         typename M::ConstPointer       m_Mesh;
79         typename TKDSample::Pointer    m_KDSample;
80         typename TKDGenerator::Pointer m_KDGenerator;
81         typename TKDTree::Pointer      m_KDTree;
82       };
83
84     } // ecapseman
85
86   } // ecapseman
87
88 } // ecapseman
89
90 #include <cpm/Algorithms/Base/FindClosestPointInMesh.hxx>
91
92 #endif // __CPM__ALGORITHMS__BASE__FINDCLOSESTPOINTINMESH__H__
93
94 // eof - $RCSfile$