]> Creatis software - creaVtk.git/commitdiff
#3268 creaVtk Feature New Normal - CreateMeshFromPoints Delaunay3D
authorEduardo DAVILA <davila@localhost.localdomain>
Tue, 25 Jun 2019 09:02:04 +0000 (11:02 +0200)
committerEduardo DAVILA <davila@localhost.localdomain>
Tue, 25 Jun 2019 09:02:04 +0000 (11:02 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx [new file with mode: 0644]
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h [new file with mode: 0644]
bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.cxx [new file with mode: 0644]
bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.h [new file with mode: 0644]

diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx
new file mode 100644 (file)
index 0000000..34c6e66
--- /dev/null
@@ -0,0 +1,155 @@
+//===== 
+// 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 "bbcreaVtkCreateMeshFromPoints.h"
+#include "bbcreaVtkPackage.h"
+
+#include "vtkPoints.h"
+#include "vtkTriangleStrip.h"
+#include "vtkCellArray.h"
+
+#include "vtkCleanPolyData.h"
+
+
+namespace bbcreaVtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,CreateMeshFromPoints)
+BBTK_BLACK_BOX_IMPLEMENTATION(CreateMeshFromPoints,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 CreateMeshFromPoints::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 CreateMeshFromPoints::Process Start\n");
+
+  
+               std::vector<double> lstX                = bbGetInputLstX();
+               std::vector<double> lstY                = bbGetInputLstY();
+               std::vector<double> lstZ                = bbGetInputLstZ();
+               std::vector<int> lstIndexs              = bbGetInputLstIndexs();
+
+
+               if ( (lstIndexs.size()<=1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
+               {
+                       printf("Warnning! CreateMeshFromPoints::Process: List of points X Y Z  and LstIndexes is not correct\n");
+               } else  {
+
+                       int ii,sizeSegment1,sizeSegment2;
+                       int endSegment;
+
+                       vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
+                       int i,sizeLstX  =       lstX.size();
+                       for (i=0;i<sizeLstX;i++)
+                       {
+                               points->InsertNextPoint(lstX[i],lstY[i],lstZ[i]);
+                       } // for i
+
+                       vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
+                       int maxElements;
+                       int maxSegment1,maxSegment2;
+                       int iSeg1,iSeg2;
+
+                       int iGeneral    =       0;
+                       int     sizeLstIdexes=lstIndexs.size();
+                       for (i=0; i<sizeLstIdexes-1;i++)
+                       {
+                               sizeSegment1=lstIndexs[i];
+                               sizeSegment2=lstIndexs[i+1];
+
+                               vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();
+                               triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2);
+
+                               maxElements=sizeSegment1;
+                               if (maxElements<sizeSegment2) maxElements=sizeSegment2;
+                               maxSegment1=iGeneral+sizeSegment1;
+                               maxSegment2=iGeneral+sizeSegment1+sizeSegment2;
+                               iSeg1=iGeneral;
+                               iSeg2=iGeneral+sizeSegment1;
+                               for (ii=0; ii<maxElements; ii++)
+                               {
+                                       triangleStrip->GetPointIds()->SetId(ii*2  ,iSeg1);
+                                       triangleStrip->GetPointIds()->SetId(ii*2+1,iSeg2);
+                                       iSeg1++;
+                                       iSeg2++;
+                                       if (iSeg1>=maxSegment1) iSeg1=maxSegment1-1;
+                                       if (iSeg2>=maxSegment2) iSeg2=maxSegment2-1;
+                               } // for ii 
+                               iGeneral=iGeneral+sizeSegment1;
+                               cells->InsertNextCell(triangleStrip);
+
+                       } //for  LstIndexs
+
+                       vtkPolyData *polydata = vtkPolyData::New();
+                       polydata->SetPoints(points);
+                       polydata->SetStrips(cells);
+
+                       vtkCleanPolyData *clean=vtkCleanPolyData::New();
+                       clean->SetInputData(polydata);
+                       clean->Update();
+
+                       bbSetOutputOut( clean->GetOutput() );
+
+               }// if listXYZ size
+
+printf("EED CreateMeshFromPoints::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 CreateMeshFromPoints::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+//   bbSetInputIn(0);
+  
+}
+//===== 
+// 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 CreateMeshFromPoints::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 CreateMeshFromPoints::bbUserFinalizeProcessing()
+{
+
+//  THE FINALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should desallocate the internal/output pointers 
+//    if any
+  
+}
+}
+// EO namespace bbcreaVtk
+
+
diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h
new file mode 100644 (file)
index 0000000..1c03523
--- /dev/null
@@ -0,0 +1,58 @@
+//===== 
+// 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)
+//===== 
+#ifndef __bbcreaVtkCreateMeshFromPoints_h_INCLUDED__
+#define __bbcreaVtkCreateMeshFromPoints_h_INCLUDED__
+
+#include "bbcreaVtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include "vtkPolyData.h"
+
+
+namespace bbcreaVtk
+{
+
+class bbcreaVtk_EXPORT CreateMeshFromPoints
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(CreateMeshFromPoints,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)
+//===== 
+  BBTK_DECLARE_INPUT(LstX,std::vector<double>);
+  BBTK_DECLARE_INPUT(LstY,std::vector<double>);
+  BBTK_DECLARE_INPUT(LstZ,std::vector<double>);
+  BBTK_DECLARE_INPUT(LstIndexs,std::vector<int>);
+  BBTK_DECLARE_OUTPUT(Out,vtkPolyData*);
+  BBTK_PROCESS(Process);
+  void Process();
+//===== 
+// 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)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(CreateMeshFromPoints,bbtk::AtomicBlackBox);
+  BBTK_NAME("CreateMeshFromPoints");
+  BBTK_AUTHOR("InfoDev");
+  BBTK_DESCRIPTION("No Description.");
+  BBTK_CATEGORY("empty");
+
+  BBTK_INPUT(CreateMeshFromPoints,LstX,"List X point",std::vector<double>,"");
+  BBTK_INPUT(CreateMeshFromPoints,LstY,"List Y point",std::vector<double>,"");
+  BBTK_INPUT(CreateMeshFromPoints,LstZ,"List Z point",std::vector<double>,"");
+  BBTK_INPUT(CreateMeshFromPoints,LstIndexs,"Number of points by segment",std::vector<int>,"");
+
+  BBTK_OUTPUT(CreateMeshFromPoints,Out,"vtkPolyData",vtkPolyData*,"");
+
+BBTK_END_DESCRIBE_BLACK_BOX(CreateMeshFromPoints);
+//===== 
+// 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)
+//===== 
+}
+// EO namespace bbcreaVtk
+
+#endif // __bbcreaVtkCreateMeshFromPoints_h_INCLUDED__
+
diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.cxx
new file mode 100644 (file)
index 0000000..02a26e7
--- /dev/null
@@ -0,0 +1,260 @@
+//===== 
+// 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
+
+
diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.h b/bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.h
new file mode 100644 (file)
index 0000000..7f8f472
--- /dev/null
@@ -0,0 +1,62 @@
+//===== 
+// 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)
+//===== 
+#ifndef __bbcreaVtkDelaunay3D_h_INCLUDED__
+#define __bbcreaVtkDelaunay3D_h_INCLUDED__
+
+#include "bbcreaVtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include "vtkPolyData.h"
+
+namespace bbcreaVtk
+{
+
+class bbcreaVtk_EXPORT Delaunay3D
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(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)
+//===== 
+
+  BBTK_DECLARE_INPUT(Tolerance,double);
+  BBTK_DECLARE_INPUT(Alpha,double);
+  BBTK_DECLARE_INPUT(ShrinkFactor,double);
+  BBTK_DECLARE_INPUT(LstPointsX,std::vector<double>);
+  BBTK_DECLARE_INPUT(LstPointsY,std::vector<double>);
+  BBTK_DECLARE_INPUT(LstPointsZ,std::vector<double>);
+  BBTK_DECLARE_OUTPUT(Out,vtkPolyData *);
+  BBTK_PROCESS(Process);
+  void Process();
+//===== 
+// 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)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(Delaunay3D,bbtk::AtomicBlackBox);
+  BBTK_NAME("Delaunay3D");
+  BBTK_AUTHOR("InfoDev");
+  BBTK_DESCRIPTION("No Description.");
+  BBTK_CATEGORY("empty");
+
+  BBTK_INPUT(Delaunay3D,Tolerance,"Delaunay Tolerance",double,"");
+  BBTK_INPUT(Delaunay3D,Alpha,"Delaunay Alpha",double,"");
+  BBTK_INPUT(Delaunay3D,ShrinkFactor,"Shrink Factor",double,"");
+  BBTK_INPUT(Delaunay3D,LstPointsX,"Vector of points X",std::vector<double>,"");
+  BBTK_INPUT(Delaunay3D,LstPointsY,"Vector of points Y",std::vector<double>,"");
+  BBTK_INPUT(Delaunay3D,LstPointsZ,"Vector of points Z",std::vector<double>,"");
+
+  BBTK_OUTPUT(Delaunay3D,Out,"vtkPolyData",vtkPolyData*,"");
+
+BBTK_END_DESCRIBE_BLACK_BOX(Delaunay3D);
+//===== 
+// 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)
+//===== 
+}
+// EO namespace bbcreaVtk
+
+#endif // __bbcreaVtkDelaunay3D_h_INCLUDED__
+