From 27cd1709e7cd62aa62f02df8abecdd8bea1d8767 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Tue, 25 Jun 2019 11:02:04 +0200 Subject: [PATCH] #3268 creaVtk Feature New Normal - CreateMeshFromPoints Delaunay3D --- .../src/bbcreaVtkCreateMeshFromPoints.cxx | 155 +++++++++++ .../src/bbcreaVtkCreateMeshFromPoints.h | 58 ++++ bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.cxx | 260 ++++++++++++++++++ bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.h | 62 +++++ 4 files changed, 535 insertions(+) create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.cxx create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.h diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx new file mode 100644 index 0000000..34c6e66 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx @@ -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 = " < lstX = bbGetInputLstX(); + std::vector lstY = bbGetInputLstY(); + std::vector lstZ = bbGetInputLstZ(); + std::vector 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 points = vtkSmartPointer::New(); + int i,sizeLstX = lstX.size(); + for (i=0;iInsertNextPoint(lstX[i],lstY[i],lstZ[i]); + } // for i + + vtkSmartPointer cells = vtkSmartPointer::New(); + int maxElements; + int maxSegment1,maxSegment2; + int iSeg1,iSeg2; + + int iGeneral = 0; + int sizeLstIdexes=lstIndexs.size(); + for (i=0; i triangleStrip = vtkSmartPointer::New(); + triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2); + + maxElements=sizeSegment1; + if (maxElementsGetPointIds()->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 index 0000000..1c03523 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h @@ -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); + BBTK_DECLARE_INPUT(LstY,std::vector); + BBTK_DECLARE_INPUT(LstZ,std::vector); + BBTK_DECLARE_INPUT(LstIndexs,std::vector); + 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,""); + BBTK_INPUT(CreateMeshFromPoints,LstY,"List Y point",std::vector,""); + BBTK_INPUT(CreateMeshFromPoints,LstZ,"List Z point",std::vector,""); + BBTK_INPUT(CreateMeshFromPoints,LstIndexs,"Number of points by segment",std::vector,""); + + 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 index 0000000..02a26e7 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.cxx @@ -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 +#include + +#include +#include +#include +#include + +#include +#include +#include + + + +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 = " < lstX=bbGetInputLstPointsX(); + std::vector lstY=bbGetInputLstPointsY(); + std::vector lstZ=bbGetInputLstPointsZ(); + if (lstX.size()!=0) + { + vtkPoints *points = vtkPoints::New(); + int i,size=lstX.size(); + for (i=0;iInsertNextPoint( 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 distance = + vtkSmartPointer::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 normals = + vtkSmartPointer::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(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 surface = + vtkSmartPointer::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 normals = + vtkSmartPointer::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 surf = + vtkSmartPointer::New(); + surf->SetInputData(polydata); + + vtkSmartPointer cf = + vtkSmartPointer::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 reverse = + vtkSmartPointer::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 index 0000000..7f8f472 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkDelaunay3D.h @@ -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); + BBTK_DECLARE_INPUT(LstPointsY,std::vector); + BBTK_DECLARE_INPUT(LstPointsZ,std::vector); + 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,""); + BBTK_INPUT(Delaunay3D,LstPointsY,"Vector of points Y",std::vector,""); + BBTK_INPUT(Delaunay3D,LstPointsZ,"Vector of points Z",std::vector,""); + + 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__ + -- 2.47.1