]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Fri, 24 Mar 2017 00:19:18 +0000 (19:19 -0500)
committerLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Fri, 24 Mar 2017 00:19:18 +0000 (19:19 -0500)
examples/Dijkstra_Maurer.cxx
libs/fpa/Base/Dijkstra.hxx
libs/fpa/Base/MinimumSpanningTree.hxx
libs/fpa/Image/MinimumSpanningTreeToImageFilter.h [new file with mode: 0644]
libs/fpa/Image/MinimumSpanningTreeToImageFilter.hxx [new file with mode: 0644]

index 88759597496bc98a149697f11bb4c2ff11d663a8..c67024a12fc0215b15f4e628c1e50ecdc44ca48c 100644 (file)
@@ -7,6 +7,7 @@
 #include <fpa/Image/Dijkstra.h>
 #include <fpa/Image/Functors/VertexIdentity.h>
 #include <fpa/Base/Functors/InvertValue.h>
+#include <fpa/Image/MinimumSpanningTreeToImageFilter.h>
 
 // -------------------------------------------------------------------------
 static const unsigned int VDim = 2;
@@ -20,12 +21,19 @@ typedef fpa::Image::Dijkstra< TScalarImage, TScalarImage > TFilter;
 typedef itk::MinimumMaximumImageCalculator< TImage >       TMinMax;
 typedef itk::SignedMaurerDistanceMapImageFilter< TImage, TScalarImage > TDMap;
 
+typedef TImage::IndexType TIndex;
+
 typedef fpa::Image::Functors::VertexIdentity< TScalarImage, TScalar > TVertexFunc;
 typedef fpa::Base::Functors::InvertValue< TScalar, TScalar > TValueFunc;
 
 typedef TFilter::TMST                TMST;
 typedef itk::ImageFileWriter< TMST > TMSTWriter;
 
+typedef unsigned char TColorValue;
+typedef fpa::Image::MinimumSpanningTreeToImageFilter< TMST, TColorValue > TMSTToImage;
+typedef TMSTToImage::TOutputImage TColorImage;
+typedef itk::ImageFileWriter< TColorImage > TColorImageWriter;
+
 // -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
@@ -34,7 +42,7 @@ int main( int argc, char* argv[] )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
-      << " input_image output_image output_mst stop_at_one_front";
+      << " input_image output_image output_paths stop_at_one_front";
     for( unsigned int i = 0; i < VDim; ++i )
       std::cerr << " s_" << i;
     std::cerr << " ..." << std::endl;
@@ -43,7 +51,7 @@ int main( int argc, char* argv[] )
   } // fi
   std::string input_image_filename = argv[ 1 ];
   std::string output_image_filename = argv[ 2 ];
-  std::string output_mst_filename = argv[ 3 ];
+  std::string output_paths_filename = argv[ 3 ];
   bool stop_at_one_front = ( std::atoi( argv[ 4 ] ) == 1 );
 
   TReader::Pointer reader = TReader::New( );
@@ -99,14 +107,20 @@ int main( int argc, char* argv[] )
   writer->SetInput( filter->GetOutput( ) );
   writer->SetFileName( output_image_filename );
 
-  TMSTWriter::Pointer mst_writer = TMSTWriter::New( );
-  mst_writer->SetInput( filter->GetMinimumSpanningTree( ) );
-  mst_writer->SetFileName( output_mst_filename );
+  TMSTToImage::Pointer mst_image = TMSTToImage::New( );
+  mst_image->SetInput( filter->GetMinimumSpanningTree( ) );
+  for( TIndex iseed: filter->GetSeeds( ) )
+    for( TIndex jseed: filter->GetSeeds( ) )
+      mst_image->AddPath( iseed, jseed, 255, 0, 0 );
+
+  TColorImageWriter::Pointer paths_writer = TColorImageWriter::New( );
+  paths_writer->SetInput( mst_image->GetOutput( ) );
+  paths_writer->SetFileName( output_paths_filename );
 
   try
   {
     writer->Update( );
-    mst_writer->Update( );
+    paths_writer->Update( );
   }
   catch( std::exception& err )
   {
index c5563c92d29702a7738a7e9ebd46483b1da95156..149363d64128543dd1bfa29de9edd04cf2b8cac3 100644 (file)
@@ -173,6 +173,12 @@ GenerateData( )
 
   } // elihw
   this->_FreeMarks( );
+
+  // Complete data into minimum spanning tree
+  mst->ClearSeeds( );
+  mst->SetCollisions( this->m_Collisions );
+  for( TVertex seed: this->GetSeeds( ) )
+    mst->AddSeed( seed );
 }
 
 #endif // __fpa__Base__Dijkstra__hxx__
index 79ddebe4b8cf673aab43a7a778bb78bb7f38f966..c5838f319be7784e4d949796aee058ac1d442a75 100644 (file)
@@ -86,8 +86,7 @@ void fpa::Base::MinimumSpanningTree< _TVertex, _Superclass >::
 ClearSeeds( )
 {
   this->m_Seeds.clear( );
-  if( this->m_DataObject != NULL )
-    this->m_DataObject->Modified( );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
@@ -96,8 +95,7 @@ void fpa::Base::MinimumSpanningTree< _TVertex, _Superclass >::
 AddSeed( const _TVertex& seed )
 {
   this->m_Seeds.push_back( seed );
-  if( this->m_DataObject != NULL )
-    this->m_DataObject->Modified( );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
diff --git a/libs/fpa/Image/MinimumSpanningTreeToImageFilter.h b/libs/fpa/Image/MinimumSpanningTreeToImageFilter.h
new file mode 100644 (file)
index 0000000..a119702
--- /dev/null
@@ -0,0 +1,84 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Image__MinimumSpanningTreeToImageFilter__h__
+#define __fpa__Image__MinimumSpanningTreeToImageFilter__h__
+
+#include <itkRGBAPixel.h>
+#include <itkImageToImageFilter.h>
+#include <vector>
+
+namespace fpa
+{
+  namespace Image
+  {
+    /**
+     */
+    template< class _TMST, class _TOutputPixelValue >
+    class MinimumSpanningTreeToImageFilter
+      : public itk::ImageToImageFilter< _TMST, itk::Image< itk::RGBAPixel< _TOutputPixelValue >, _TMST::ImageDimension > >
+    {
+    public:
+      typedef _TMST TMST;
+      typedef _TOutputPixelValue TOutputPixelValue;
+      typedef itk::RGBAPixel< TOutputPixelValue > TOutputPixel;
+      typedef itk::Image< TOutputPixel, TMST::ImageDimension > TOutputImage;
+
+      typedef MinimumSpanningTreeToImageFilter              Self;
+      typedef itk::SmartPointer< Self >                     Pointer;
+      typedef itk::SmartPointer< const Self >               ConstPointer;
+      typedef itk::ImageToImageFilter< TMST, TOutputImage > Superclass;
+
+      typedef typename TMST::IndexType TIndex;
+      struct TPathData
+      {
+        TIndex Start;
+        TIndex End;
+        TOutputPixelValue Red;
+        TOutputPixelValue Green;
+        TOutputPixelValue Blue;
+      };
+      typedef std::vector< TPathData > TPaths;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro(
+        fpa::Image::MinimumSpanningTreeToImageFilter,
+        itk::ImageToImageFilter
+        );
+
+    public:
+      void AddPath(
+        const TIndex& start, const TIndex& end,
+        const TOutputPixelValue& r = TOutputPixelValue( 1 ),
+        const TOutputPixelValue& g = TOutputPixelValue( 0 ),
+        const TOutputPixelValue& b = TOutputPixelValue( 0 )
+        );
+
+    protected:
+      MinimumSpanningTreeToImageFilter( );
+      virtual ~MinimumSpanningTreeToImageFilter( );
+
+      virtual void GenerateData( ) override;
+
+    private:
+      MinimumSpanningTreeToImageFilter( const Self& other );
+      Self& operator=( const Self& other );
+
+    protected:
+      TPaths m_Paths;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <fpa/Image/MinimumSpanningTreeToImageFilter.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __fpa__Image__MinimumSpanningTreeToImageFilter__h__
+
+// eof - $RCSfile$
diff --git a/libs/fpa/Image/MinimumSpanningTreeToImageFilter.hxx b/libs/fpa/Image/MinimumSpanningTreeToImageFilter.hxx
new file mode 100644 (file)
index 0000000..1ef0039
--- /dev/null
@@ -0,0 +1,77 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Image__MinimumSpanningTreeToImageFilter__hxx__
+#define __fpa__Image__MinimumSpanningTreeToImageFilter__hxx__
+
+// -------------------------------------------------------------------------
+template< class _TMST, class _TOutputPixelValue >
+void fpa::Image::MinimumSpanningTreeToImageFilter< _TMST, _TOutputPixelValue >::
+AddPath(
+  const TIndex& start, const TIndex& end,
+  const TOutputPixelValue& r,
+  const TOutputPixelValue& g,
+  const TOutputPixelValue& b
+  )
+{
+  if( start != end )
+  {
+    TPathData d;
+    d.Start = start;
+    d.End = end;
+    d.Red = r;
+    d.Green = g;
+    d.Blue = b;
+    this->m_Paths.push_back( d );
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TMST, class _TOutputPixelValue >
+fpa::Image::MinimumSpanningTreeToImageFilter< _TMST, _TOutputPixelValue >::
+MinimumSpanningTreeToImageFilter( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TMST, class _TOutputPixelValue >
+fpa::Image::MinimumSpanningTreeToImageFilter< _TMST, _TOutputPixelValue >::
+~MinimumSpanningTreeToImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TMST, class _TOutputPixelValue >
+void fpa::Image::MinimumSpanningTreeToImageFilter< _TMST, _TOutputPixelValue >::
+GenerateData( )
+{
+  TOutputPixel color;
+  color.Fill( 0 );
+
+  const TMST* mst = this->GetInput( );
+  TOutputImage* output = this->GetOutput( );
+  output->SetBufferedRegion( mst->GetBufferedRegion( ) );
+  output->Allocate( );
+  output->FillBuffer( color );
+
+  for( TPathData d: this->m_Paths )
+  {
+    typename TMST::TVertices path = mst->GetPath( d.Start, d.End );
+    color[ 0 ] = d.Red;
+    color[ 1 ] = d.Green;
+    color[ 2 ] = d.Blue;
+    color[ 3 ] = std::numeric_limits< TOutputPixelValue >::max( );
+    for( TIndex i: path )
+      output->SetPixel( i, color );
+
+  } // rof
+}
+
+#endif // __fpa__Image__MinimumSpanningTreeToImageFilter__hxx__
+
+// eof - $RCSfile$