]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 9 Dec 2016 22:38:50 +0000 (17:38 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 9 Dec 2016 22:38:50 +0000 (17:38 -0500)
plugins/Experiments/InsertNoiseIntoPoints.cxx
plugins/Experiments/SkeletonHausdorffDistance.cxx [new file with mode: 0644]
plugins/Experiments/SkeletonHausdorffDistance.h [new file with mode: 0644]

index fef1f0db154ee2f52aefe9321e5c5812de39055c..403231662307a9aa06c194ce1a724f57441f918b 100644 (file)
@@ -57,7 +57,7 @@ _GenerateData( )
       dmap->ComputeStructuredCoordinates( buf, ijk, pcoords );
       double radius =
         dmap->GetScalarComponentAsDouble( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
-      double rad_dis = _TDist( 1e-5, radius * 0.9 )( gen );
+      double rad_dis = _TDist( 1e-2, radius * 0.9 )( gen );
       double the_dis = _TDist( 0, 3.14159265359 )( gen );
       double phi_dis = _TDist( 0, 6.28318530718 )( gen );
       buf[ 0 ] += rad_dis * std::sin( the_dis ) * std::cos( phi_dis );
diff --git a/plugins/Experiments/SkeletonHausdorffDistance.cxx b/plugins/Experiments/SkeletonHausdorffDistance.cxx
new file mode 100644 (file)
index 0000000..9f5a4dc
--- /dev/null
@@ -0,0 +1,136 @@
+#include <Experiments/SkeletonHausdorffDistance.h>
+#include <cpInstances/Image.h>
+#include <cpInstances/Mesh.h>
+#include <cpInstances/Skeleton.h>
+#include <cpExtensions/DataStructures/Skeleton.h>
+
+#include <vtkImageData.h>
+#include <vtkPolyData.h>
+
+// -------------------------------------------------------------------------
+fpaPluginsExperiments::SkeletonHausdorffDistance::
+SkeletonHausdorffDistance( )
+  : Superclass( )
+{
+  this->_ConfigureInput< cpInstances::Image >( "DistanceMap", true, false );
+  this->_ConfigureInput< cpInstances::Mesh >( "Seeds", true, false );
+  this->_ConfigureInput< cpInstances::Skeleton >( "Skeleton1", true, false );
+  this->_ConfigureInput< cpInstances::Skeleton >( "Skeleton2", true, false );
+}
+
+// -------------------------------------------------------------------------
+fpaPluginsExperiments::SkeletonHausdorffDistance::
+~SkeletonHausdorffDistance( )
+{
+}
+
+// -------------------------------------------------------------------------
+void fpaPluginsExperiments::SkeletonHausdorffDistance::
+_GenerateData( )
+{
+  typedef cpExtensions::DataStructures::Skeleton< 3 > _TSkeleton;
+
+  auto dmap = this->GetInputData< vtkImageData >( "DistanceMap" );
+  auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
+  auto sk1 = this->GetInputData< _TSkeleton >( "Skeleton1" );
+  auto sk2 = this->GetInputData< _TSkeleton >( "Skeleton2" );
+
+  double buf[ 3 ], pcoords[ 3 ];
+  seeds->GetPoint( 0, buf );
+  int ijk[ 3 ];
+  dmap->ComputeStructuredCoordinates( buf, ijk, pcoords );
+  double radius =
+    dmap->GetScalarComponentAsDouble( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
+
+  double d1 = this->_Distance( sk1, sk2, NULL, 0 );
+  double d2 = this->_Distance( sk1, sk2, buf, radius );
+
+  std::cout
+    << std::endl
+    << "-------------------------------" << std::endl
+    << "D1    : " << d1 << std::endl
+    << "D2    : " << d2 << std::endl
+    << "Radius: " << radius << std::endl
+    << "Seed  : " << buf[ 0 ] << " " << buf[ 1 ] << " " << buf[ 2 ] << std::endl
+    << "-------------------------------" << std::endl;
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+double fpaPluginsExperiments::SkeletonHausdorffDistance::
+_Distance( _TSkeleton* sk1, _TSkeleton* sk2, double* center, double radius )
+{
+  auto lst1 = this->_PointList( sk1, center, radius );
+  auto lst2 = this->_PointList( sk2, center, radius );
+  double dist = -std::numeric_limits< double >::max( );
+  typename _TSkeleton::TPath::TPoint point;
+  for( auto p1 : lst1 )
+  {
+    double ldist = std::numeric_limits< double >::max( );
+    typename _TSkeleton::TPath::TPoint lpoint;
+    for( auto p2 : lst2 )
+    {
+      double d = p1.EuclideanDistanceTo( p2 );
+      if( d < ldist )
+      {
+        ldist = d;
+        lpoint = p2;
+
+      } // fi
+
+    } // rof
+    if( ldist > dist )
+    {
+      dist = ldist;
+      point = lpoint;
+
+    } // fi
+
+  } // rof
+  return( dist );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+std::vector< typename _TSkeleton::TPath::TPoint >
+fpaPluginsExperiments::SkeletonHausdorffDistance::
+_PointList( _TSkeleton* sk, double* center, double radius )
+{
+  typename _TSkeleton::TPath::TPoint p_center;
+  if( center != NULL )
+    for( unsigned int d = 0; d < _TSkeleton::Dimension; ++d )
+      p_center[ d ] = center[ d ];
+
+  std::vector< typename _TSkeleton::TPath::TPoint > lst;
+  auto mIt = sk->BeginEdgesRows( );
+  for( ; mIt != sk->EndEdgesRows( ); ++mIt )
+  {
+    auto rIt = mIt->second.begin( );
+    for( ; rIt != mIt->second.end( ); ++rIt )
+    {
+      auto eIt = rIt->second.begin( );
+      for( ; eIt != rIt->second.end( ); ++eIt )
+      {
+        auto path = *eIt;
+        for( unsigned int i = 0; i < path->GetSize( ); ++i )
+        {
+          auto p = path->GetPoint( i );
+          if( center != NULL )
+          {
+            if( p_center.EuclideanDistanceTo( p ) > radius )
+              lst.push_back( p );
+          }
+          else
+            lst.push_back( p );
+
+        } // rof
+
+      } // rof
+
+    } // rof
+
+  } // rof
+  return( lst );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/Experiments/SkeletonHausdorffDistance.h b/plugins/Experiments/SkeletonHausdorffDistance.h
new file mode 100644 (file)
index 0000000..ae4ef80
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef __fpaPluginsExperiments__SkeletonHausdorffDistance__h__
+#define __fpaPluginsExperiments__SkeletonHausdorffDistance__h__
+
+#include <fpaPluginsExperiments_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace fpaPluginsExperiments
+{
+  /**
+   */
+  class fpaPluginsExperiments_EXPORT SkeletonHausdorffDistance
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      SkeletonHausdorffDistance,
+      cpPlugins::BaseObjects::ProcessObject,
+      fpaExperiments
+      );
+
+  protected:
+    template< class _TSkeleton >
+    inline double _Distance(
+      _TSkeleton* sk1, _TSkeleton* sk2,
+      double* center,
+      double radius
+      );
+
+    template< class _TSkeleton >
+    inline std::vector< typename _TSkeleton::TPath::TPoint > _PointList(
+      _TSkeleton* sk,
+      double* center,
+      double radius
+      );
+  };
+
+} // ecapseman
+
+#endif // __fpaPluginsExperiments__SkeletonHausdorffDistance__h__
+
+// eof - $RCSfile$