1 #include <Experiments/SkeletonHausdorffDistance.h>
2 #include <cpInstances/DataObjects/Image.h>
3 #include <cpInstances/Mesh.h>
4 #include <cpInstances/DataObjects/Skeleton.h>
5 #include <cpExtensions/DataStructures/Skeleton.h>
7 #include <vtkImageData.h>
8 #include <vtkPolyData.h>
10 // -------------------------------------------------------------------------
11 fpaPluginsExperiments::SkeletonHausdorffDistance::
12 SkeletonHausdorffDistance( )
15 this->_ConfigureInput< cpInstances::DataObjects::Image >( "DistanceMap", true, false );
16 this->_ConfigureInput< cpInstances::Mesh >( "Seeds", true, false );
17 this->_ConfigureInput< cpInstances::Skeleton >( "Skeleton1", true, false );
18 this->_ConfigureInput< cpInstances::Skeleton >( "Skeleton2", true, false );
21 // -------------------------------------------------------------------------
22 fpaPluginsExperiments::SkeletonHausdorffDistance::
23 ~SkeletonHausdorffDistance( )
27 // -------------------------------------------------------------------------
28 void fpaPluginsExperiments::SkeletonHausdorffDistance::
31 typedef cpExtensions::DataStructures::Skeleton< 3 > _TSkeleton;
33 auto dmap = this->GetInputData< vtkImageData >( "DistanceMap" );
34 auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
35 auto sk1 = this->GetInputData< _TSkeleton >( "Skeleton1" );
36 auto sk2 = this->GetInputData< _TSkeleton >( "Skeleton2" );
38 double buf[ 3 ], pcoords[ 3 ];
39 seeds->GetPoint( 0, buf );
41 dmap->ComputeStructuredCoordinates( buf, ijk, pcoords );
43 dmap->GetScalarComponentAsDouble( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
45 double d1 = this->_Distance( sk1, sk2, NULL, 0 );
46 double d2 = this->_Distance( sk1, sk2, buf, radius );
50 << "-------------------------------" << std::endl
51 << "D1 : " << d1 << std::endl
52 << "D2 : " << d2 << std::endl
53 << "Radius: " << radius << std::endl
54 << "Seed : " << buf[ 0 ] << " " << buf[ 1 ] << " " << buf[ 2 ] << std::endl
55 << "-------------------------------" << std::endl;
58 // -------------------------------------------------------------------------
59 template< class _TSkeleton >
60 double fpaPluginsExperiments::SkeletonHausdorffDistance::
61 _Distance( _TSkeleton* sk1, _TSkeleton* sk2, double* center, double radius )
63 auto lst1 = this->_PointList( sk1, center, radius );
64 auto lst2 = this->_PointList( sk2, center, radius );
65 double dist = -std::numeric_limits< double >::max( );
66 typename _TSkeleton::TPath::TPoint point;
69 double ldist = std::numeric_limits< double >::max( );
70 typename _TSkeleton::TPath::TPoint lpoint;
73 double d = p1.EuclideanDistanceTo( p2 );
93 // -------------------------------------------------------------------------
94 template< class _TSkeleton >
95 std::vector< typename _TSkeleton::TPath::TPoint >
96 fpaPluginsExperiments::SkeletonHausdorffDistance::
97 _PointList( _TSkeleton* sk, double* center, double radius )
99 typename _TSkeleton::TPath::TPoint p_center;
101 for( unsigned int d = 0; d < _TSkeleton::Dimension; ++d )
102 p_center[ d ] = center[ d ];
104 std::vector< typename _TSkeleton::TPath::TPoint > lst;
105 auto mIt = sk->BeginEdgesRows( );
106 for( ; mIt != sk->EndEdgesRows( ); ++mIt )
108 auto rIt = mIt->second.begin( );
109 for( ; rIt != mIt->second.end( ); ++rIt )
111 auto eIt = rIt->second.begin( );
112 for( ; eIt != rIt->second.end( ); ++eIt )
115 for( unsigned int i = 0; i < path->GetSize( ); ++i )
117 auto p = path->GetPoint( i );
120 if( p_center.EuclideanDistanceTo( p ) > radius )