1 #include <Experiments/InsertNoiseIntoPoints.h>
2 #include <cpInstances/DataObjects/Image.h>
3 #include <cpInstances/Mesh.h>
6 #include <vtkImageData.h>
7 #include <vtkPolyData.h>
9 // -------------------------------------------------------------------------
10 fpaPluginsExperiments::InsertNoiseIntoPoints::
11 InsertNoiseIntoPoints( )
14 typedef cpInstances::DataObjects::Image _TImage;
15 typedef cpInstances::Mesh _TMesh;
17 this->_ConfigureInput< _TMesh >( "Seeds", true, false );
18 this->_ConfigureInput< _TImage >( "DistanceMap", true, false );
19 this->_ConfigureOutput< _TMesh >( "Output" );
20 this->m_Parameters.ConfigureAsBool( "InsertNoise", false );
23 auto out = this->_CreateVTK< vtkPolyData >( );
24 out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
25 out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
26 out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
27 out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
28 out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
29 this->GetOutput( "Output" )->SetVTK( out );
32 // -------------------------------------------------------------------------
33 fpaPluginsExperiments::InsertNoiseIntoPoints::
34 ~InsertNoiseIntoPoints( )
38 // -------------------------------------------------------------------------
39 void fpaPluginsExperiments::InsertNoiseIntoPoints::
42 auto dmap = this->GetInputData< vtkImageData >( "DistanceMap" );
43 auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
44 auto out = this->GetOutputData< vtkPolyData >( "Output" );
46 typedef std::uniform_real_distribution< double > _TDist;
47 std::random_device rd;
48 std::mt19937 gen( rd( ) );
49 for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
51 double buf[ 3 ], pcoords[ 3 ];
52 seeds->GetPoint( i, buf );
54 if( this->m_Parameters.GetBool( "InsertNoise" ) )
57 dmap->ComputeStructuredCoordinates( buf, ijk, pcoords );
59 dmap->GetScalarComponentAsDouble( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
60 double rad_dis = _TDist( 1e-2, radius * 0.9 )( gen );
61 double the_dis = _TDist( 0, 3.14159265359 )( gen );
62 double phi_dis = _TDist( 0, 6.28318530718 )( gen );
63 buf[ 0 ] += rad_dis * std::sin( the_dis ) * std::cos( phi_dis );
64 buf[ 1 ] += rad_dis * std::sin( the_dis ) * std::sin( phi_dis );
65 buf[ 2 ] += rad_dis * std::cos( the_dis );
68 out->GetPoints( )->InsertNextPoint( buf );
69 out->GetVerts( )->InsertNextCell( 1 );
70 out->GetVerts( )->InsertCellPoint( i );