]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 2 Dec 2016 22:49:41 +0000 (17:49 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 2 Dec 2016 22:49:41 +0000 (17:49 -0500)
plugins/Experiments/InsertNoiseIntoPoints.cxx

index d81b6f17f017dc70fa8d1ca9181440fe23e28dbb..fef1f0db154ee2f52aefe9321e5c5812de39055c 100644 (file)
@@ -1,22 +1,32 @@
 #include <Experiments/InsertNoiseIntoPoints.h>
 #include <cpInstances/Image.h>
+#include <cpInstances/Mesh.h>
 
 #include <random>
 #include <vtkImageData.h>
 #include <vtkPolyData.h>
-#error http://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
+
 // -------------------------------------------------------------------------
 fpaPluginsExperiments::InsertNoiseIntoPoints::
 InsertNoiseIntoPoints( )
   : Superclass( )
 {
   typedef cpInstances::Image _TImage;
-  typedef cpPlugins::BaseObjects::DataObject _TData;
+  typedef cpInstances::Mesh  _TMesh;
 
-  this->_ConfigureInput< _TData >( "Seeds", true, false );
+  this->_ConfigureInput< _TMesh >( "Seeds", true, false );
   this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
-  this->_ConfigureOutput< _TData >( "Output" );
-  this->m_Parameters.ConfigureAsUint( "NumberOfSamples", 0 );
+  this->_ConfigureOutput< _TMesh >( "Output" );
+  this->m_Parameters.ConfigureAsBool( "InsertNoise", false );
+
+  // Create output data
+  auto out = this->_CreateVTK< vtkPolyData >( );
+  out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
+  out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
+  out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
+  out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
+  out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
+  this->GetOutput( "Output" )->SetVTK( out );
 }
 
 // -------------------------------------------------------------------------
@@ -31,59 +41,36 @@ _GenerateData( )
 {
   auto dmap = this->GetInputData< vtkImageData >( "DistanceMap" );
   auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
+  auto out = this->GetOutputData< vtkPolyData >( "Output" );
+
+  typedef std::uniform_real_distribution< double > _TDist;
+  std::random_device rd;
+  std::mt19937 gen( rd( ) );
   for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
   {
     double buf[ 3 ], pcoords[ 3 ];
     seeds->GetPoint( i, buf );
-    int ijk[ 3 ];
-    dmap->ComputeStructuredCoordinates( buf, ijk, pcoords );
-    double radius =
-      dmap->GetScalarComponentAsDouble( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
-
-  } // rof
-
-  /* TODO
-     cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 )
-     this->_Error( "Invalid input image." );
-  */
-}
 
-// -------------------------------------------------------------------------
-/* TODO
-   template< class _TImage >
-   void fpaPluginsExperiments::InsertNoiseIntoPoints::
-   _GD0( _TImage* image )
-   {
-   typedef fpa::Image::InsertNoiseIntoPoints< _TImage > _TFilter;
-   auto filter = this->_CreateITK< _TFilter >( );
-   filter->SetInput( image );
-
-   if( seeds != NULL )
-   {
-   typename _TImage::PointType pnt;
-   typename _TImage::IndexType idx;
-   unsigned int dim =
-   ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
-
-   for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
-   {
-   double buf[ 3 ];
-   seeds->GetPoint( i, buf );
-   pnt.Fill( 0 );
-   for( unsigned int d = 0; d < dim; ++d )
-   pnt[ d ] = buf[ d ];
-
-   if( image->TransformPhysicalPointToIndex( pnt, idx ) )
-   filter->AddSeed( idx, 0 );
+    if( this->m_Parameters.GetBool( "InsertNoise" ) )
+    {
+      int ijk[ 3 ];
+      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 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 );
+      buf[ 1 ] += rad_dis * std::sin( the_dis ) * std::sin( phi_dis );
+      buf[ 2 ] += rad_dis * std::cos( the_dis );
 
-   } // rof
+    } // fi
+    out->GetPoints( )->InsertNextPoint( buf );
+    out->GetVerts( )->InsertNextCell( 1 );
+    out->GetVerts( )->InsertCellPoint( i );
+    out->Modified( );
 
-   } // fi
-
-   filter->Update( );
-   this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) );
-   this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) );
-   }
-*/
+  } // rof
+}
 
 // eof - $RCSfile$