+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+#include "bbcreaVtkDelaunay3D.h"
+#include "bbcreaVtkPackage.h"
+
+#include "vtkPoints.h"
+#include "vtkDelaunay2D.h"
+#include "vtkDelaunay3D.h"
+#include "vtkShrinkFilter.h"
+#include "vtkGeometryFilter.h"
+#include <vtkUnstructuredGrid.h>
+#include <vtkCleanPolyData.h>
+
+#include <vtkPCANormalEstimation.h>
+#include <vtkSignedDistance.h>
+#include <vtkExtractSurface.h>
+#include <vtkPointData.h>
+
+#include <vtkSurfaceReconstructionFilter.h>
+#include <vtkContourFilter.h>
+#include <vtkReverseSense.h>
+
+
+
+namespace bbcreaVtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,Delaunay3D)
+BBTK_BLACK_BOX_IMPLEMENTATION(Delaunay3D,bbtk::AtomicBlackBox);
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Delaunay3D::Process()
+{
+
+// THE MAIN PROCESSING METHOD BODY
+// Here we simply set the input 'In' value to the output 'Out'
+// And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+// void bbSet{Input|Output}NAME(const TYPE&)
+// const TYPE& bbGet{Input|Output}NAME() const
+// Where :
+// * NAME is the name of the input/output
+// (the one provided in the attribute 'name' of the tag 'input')
+// * TYPE is the C++ type of the input/output
+// (the one provided in the attribute 'type' of the tag 'input')
+// bbSetOutputOut( bbGetInputIn() );
+// std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
+
+
+printf("EED Delaunay3D::Process Start\n");
+ std::vector<double> lstX=bbGetInputLstPointsX();
+ std::vector<double> lstY=bbGetInputLstPointsY();
+ std::vector<double> lstZ=bbGetInputLstPointsZ();
+ if (lstX.size()!=0)
+ {
+ vtkPoints *points = vtkPoints::New();
+ int i,size=lstX.size();
+ for (i=0;i<size;i++)
+ {
+ points->InsertNextPoint( lstX[i], lstY[i], lstZ[i] );
+ } // for i
+
+ vtkPolyData *inputpolydata = vtkPolyData::New();
+ inputpolydata->SetPoints( points );
+
+/* Delaunay */
+ vtkDelaunay3D* delaunay = vtkDelaunay3D::New();
+ delaunay->SetInputData( inputpolydata );
+ delaunay->SetTolerance( bbGetInputTolerance() ); //0.01
+ delaunay->SetAlpha( bbGetInputAlpha() ); //0.2
+ delaunay->BoundingTriangulationOff();
+ delaunay->Update();
+
+ vtkGeometryFilter *geometry = vtkGeometryFilter::New();
+ geometry->SetInputData( delaunay->GetOutput() );
+ geometry->Update();
+
+ bbSetOutputOut( geometry->GetOutput() );
+
+
+/* vtkExtractSurface
+ double bounds[6];
+ inputpolydata->GetBounds(bounds);
+ double range[3];
+ for (int i = 0; i < 3; ++i)
+ {
+ range[i] = bounds[2*i + 1] - bounds[2*i];
+ }
+
+ int sampleSize = inputpolydata->GetNumberOfPoints() * .00005;
+ if (sampleSize < 10)
+ {
+ sampleSize = 10;
+ }
+ std::cout << "Sample size is: " << sampleSize << std::endl;
+ // Do we need to estimate normals?
+ vtkSmartPointer<vtkSignedDistance> distance =
+ vtkSmartPointer<vtkSignedDistance>::New();
+ if (inputpolydata->GetPointData()->GetNormals())
+ {
+ std::cout << "Using normals from input file" << std::endl;
+ distance->SetInputData (inputpolydata);
+ } else{
+ std::cout << "Estimating normals using PCANormalEstimation" << std::endl;
+ vtkSmartPointer<vtkPCANormalEstimation> normals =
+ vtkSmartPointer<vtkPCANormalEstimation>::New();
+ normals->SetInputData (inputpolydata);
+ normals->SetSampleSize(sampleSize);
+ normals->SetNormalOrientationToGraphTraversal();
+ normals->FlipNormalsOn();
+ distance->SetInputConnection (normals->GetOutputPort());
+ }
+ std::cout << "Range: "
+ << range[0] << ", "
+ << range[1] << ", "
+ << range[2] << std::endl;
+ int dimension = 256;
+ double radius;
+
+ radius = std::max(std::max(range[0], range[1]), range[2])
+ / static_cast<double>(dimension) * 4; // ~4 voxels
+
+//EED
+ radius = bbGetInputTolerance();
+
+
+ std::cout << "Radius: " << radius << std::endl;
+
+ distance->SetRadius(radius);
+ distance->SetDimensions(dimension, dimension, dimension);
+ distance->SetBounds(
+ bounds[0] - range[0] * .1,
+ bounds[1] + range[0] * .1,
+ bounds[2] - range[1] * .1,
+ bounds[3] + range[1] * .1,
+ bounds[4] - range[2] * .1,
+ bounds[5] + range[2] * .1);
+
+
+ vtkExtractSurface *surface = vtkExtractSurface::New();
+ surface->SetInputConnection (distance->GetOutputPort());
+ surface->SetRadius(radius * .99 ); //
+ surface->Update();
+ bbSetOutputOut( surface->GetOutput() );
+*/
+
+/*vtkPoissonReconstruction
+ vtkPolyData *polyData=inputpolydata;
+
+ vtkSmartPointer<vtkPoissonReconstruction> surface =
+ vtkSmartPointer<vtkPoissonReconstruction>::New();
+ surface->SetDepth(12);
+
+ int sampleSize = polyData->GetNumberOfPoints() * .00005;
+ if (sampleSize < 10)
+ {
+ sampleSize = 10;
+ }
+ if (polyData->GetPointData()->GetNormals())
+ {
+ std::cout << "Using normals from input file" << std::endl;
+ surface->SetInputData (polyData);
+ }
+ else
+ {
+ std::cout << "Estimating normals using PCANormalEstimation" << std::endl;
+ vtkSmartPointer<vtkPCANormalEstimation> normals =
+ vtkSmartPointer<vtkPCANormalEstimation>::New();
+ normals->SetInputData (polyData);
+ normals->SetSampleSize(sampleSize);
+ normals->SetNormalOrientationToGraphTraversal();
+ normals->FlipNormalsOff();
+ surface->SetInputConnection(normals->GetOutputPort());
+ }
+
+ surface->Update();
+ bbSetOutputOut( surface->GetOutput() );
+
+*/
+
+
+
+/*SurfaceReconstructionFilter
+
+ vtkPolyData *polydata=inputpolydata;
+
+ // Construct the surface and create isosurface.
+ vtkSmartPointer<vtkSurfaceReconstructionFilter> surf =
+ vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
+ surf->SetInputData(polydata);
+
+ vtkSmartPointer<vtkContourFilter> cf =
+ vtkSmartPointer<vtkContourFilter>::New();
+ cf->SetInputConnection(surf->GetOutputPort());
+ cf->SetValue(0, 0.0);
+
+ // Sometimes the contouring algorithm can create a volume whose gradient
+ // vector and ordering of polygon (using the right hand rule) are
+ // inconsistent. vtkReverseSense cures this problem.
+ vtkSmartPointer<vtkReverseSense> reverse =
+ vtkSmartPointer<vtkReverseSense>::New();
+ reverse->SetInputConnection(cf->GetOutputPort());
+ reverse->ReverseCellsOn();
+ reverse->ReverseNormalsOn();
+
+ bbSetOutputOut( reverse->GetOutput() );
+
+*/
+
+ } else {
+ printf("Warnning! Delaunay3D::Process: list of points empty. \n");
+ } // if lstX.size
+
+printf("EED Delaunay3D::Process End\n");
+
+}
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Delaunay3D::bbUserSetDefaultValues()
+{
+
+// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+// Here we initialize the input 'In' to 0
+ bbSetInputTolerance( 0.01 );
+ bbSetInputAlpha( 0.2 );
+ bbSetInputShrinkFactor( 0.9 );
+
+}
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Delaunay3D::bbUserInitializeProcessing()
+{
+
+// THE INITIALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should allocate the internal/output pointers
+// if any
+
+
+}
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Delaunay3D::bbUserFinalizeProcessing()
+{
+
+// THE FINALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should desallocate the internal/output pointers
+// if any
+
+}
+}
+// EO namespace bbcreaVtk
+
+