--- /dev/null
+//=====
+// 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 "bbcreaVtkCleanMeshWithPatch.h"
+#include "bbcreaVtkPackage.h"
+
+#include <vtkAppendPolyData.h>
+#include <vtkStaticPointLocator.h>
+#include <vtkDijkstraGraphGeodesicPath.h>
+#include <vtkImprintFilter.h>
+
+namespace bbcreaVtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,CleanMeshWithPatch)
+BBTK_BLACK_BOX_IMPLEMENTATION(CleanMeshWithPatch,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 CleanMeshWithPatch::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 CleanMeshWithPatch::Process Start \n");
+ std::vector<int> lstIndexs = bbGetInputLstIndexs();
+ if (( lstIndexs.size()>=3 ) && (bbGetInputMesh()!=NULL) ) {
+
+ // Step 1. ----Get perimeter CtrlPoints-----
+ std::vector<double> lstX = bbGetInputLstX();
+ std::vector<double> lstY = bbGetInputLstY();
+ std::vector<double> lstZ = bbGetInputLstZ();
+ std::vector<double> perimeterX;
+ std::vector<double> perimeterY;
+ std::vector<double> perimeterZ;
+ std::vector<double> tmpX;
+ std::vector<double> tmpY;
+ std::vector<double> tmpZ;
+ int iGroup,sizeGroups = lstIndexs.size();
+ int i,iGeneral=0,size;
+ for (iGroup=0 ; iGroup<sizeGroups ; iGroup++)
+ {
+ if (iGroup==0)
+ {
+ for (i=iGeneral ; i<iGeneral+lstIndexs[iGroup] ; i++)
+ {
+ perimeterX.push_back( lstX[i] );
+ perimeterY.push_back( lstY[i] );
+ perimeterZ.push_back( lstZ[i] );
+ } // for first group
+ } // if iGroup == 0
+ if ((iGroup!=0) && (iGroup!=sizeGroups-1))
+ {
+ i=iGeneral+(lstIndexs[iGroup]-1);
+ perimeterX.push_back( lstX[i] );
+ perimeterY.push_back( lstY[i] );
+ perimeterZ.push_back( lstZ[i] );
+ tmpX.insert( tmpX.begin() , lstX[iGeneral] );
+ tmpY.insert( tmpY.begin() , lstY[iGeneral] );
+ tmpZ.insert( tmpZ.begin() , lstZ[iGeneral] );
+ }
+ if (iGroup==sizeGroups-1)
+ {
+ for (i=iGeneral+lstIndexs[iGroup]-1 ; i>=iGeneral ; i--)
+ {
+ perimeterX.push_back( lstX[i] );
+ perimeterY.push_back( lstY[i] );
+ perimeterZ.push_back( lstZ[i] );
+ } // for i last group
+ } // if iGroup == 0
+ iGeneral=iGeneral+lstIndexs[iGroup];
+ } // for
+ size=tmpX.size();
+ for (i=0; i<size ; i++)
+ {
+ perimeterX.push_back( tmpX[i] );
+ perimeterY.push_back( tmpY[i] );
+ perimeterZ.push_back( tmpZ[i] );
+ } // for i tmpX
+ // Step 2. ----Get Ids in Mesh of perimeter CtrlPoints-----
+ std::vector<double> spc;
+ if (bbGetInputSpacing().size()<3)
+ {
+ spc.push_back(1);
+ spc.push_back(1);
+ spc.push_back(1);
+ } else {
+ spc = bbGetInputSpacing();
+ }//
+ vtkStaticPointLocator *pointLocator;
+ pointLocator = vtkStaticPointLocator::New();
+ pointLocator->SetDataSet( bbGetInputMesh() );
+ pointLocator->BuildLocator();
+ long int id;
+ size=perimeterX.size();
+ std::vector<long int> lstIds;
+ for (i=0;i<size;i++)
+ {
+ id = pointLocator->FindClosestPoint( perimeterX[i]*spc[0] ,perimeterY[i]*spc[1] , perimeterZ[i]*spc[2] ) ;
+ lstIds.push_back( id );
+ printf("EED id=%ld spc=%f %f %f point=%f %f %f \n",id, spc[0],spc[1],spc[2], perimeterX[i], perimeterY[i], perimeterZ[i] );
+ } // for i perimeter
+ // Step 3 Get geodesic path from segments
+ long int id1,id2;
+ vtkAppendPolyData* append = vtkAppendPolyData::New();
+ vtkPoints *points ;
+ for (i=0;i<size;i++)
+ {
+ id1=lstIds[i];
+ if (i<size-1)
+ {
+ id2 = lstIds[i+1];
+ } else {
+ id2 = lstIds[0];
+ }// if
+ vtkDijkstraGraphGeodesicPath *pathFilter = vtkDijkstraGraphGeodesicPath::New();
+ pathFilter->SetInputData( bbGetInputMesh() );
+ pathFilter->SetStartVertex( id1 );
+ pathFilter->SetEndVertex( id2 );
+ pathFilter->Update();
+ append->AddInputData( pathFilter->GetOutput() );
+ append->Update();
+
+ points = pathFilter->GetOutput()->GetPoints();
+ printf("EED nrP=%d \n", points->GetNumberOfPoints() );
+ pathFilter->Delete();
+// if (i==0) bbSetOutputOut( pathFilter->GetOutput() );
+ } // for i perimeter
+ append->Update();
+
+ // Step 4. -- vtkImprintFilter ---
+ vtkImprintFilter *imp = vtkImprintFilter::New();
+// imp->SetTargetData( append->GetOutput() );
+// imp->SetImprintData( bbGetInputMesh() );
+
+// imp->SetTargetData( bbGetInputMesh() );
+// imp->SetImprintData( append->GetOutput() );
+
+// imp->SetTargetData( bbGetInputMesh() );
+// imp->SetImprintData( bbGetInputPatch() );
+
+ imp->SetTargetData( bbGetInputMesh() );
+ imp->SetImprintData( bbGetInputPatch() );
+
+ // imp->SetOutputTypeToProjectedImprint();
+ imp->SetOutputTypeToTargetCells();
+ // imp->SetOutputTypeToImprintedCells();
+ // imp->SetOutputTypeToImprintedRegion();
+ // imp->SetOutputTypeToMergedImprint();
+
+ imp->SetTolerance(500);
+ imp->Update();
+
+ bbSetOutputOut( imp->GetOutput() );
+ printf("EED CleanMeshWithPatch::Process size=%d \n", perimeterX.size());
+ } // if LstIndexs size >=3
+ printf("EED CleanMeshWithPatch::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 CleanMeshWithPatch::bbUserSetDefaultValues()
+{
+// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+// Here we initialize the input 'In' to 0
+ bbSetInputMesh(NULL);
+ bbSetInputPatch(NULL);
+ bbSetOutputOut(NULL);
+}
+
+//=====
+// 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 CleanMeshWithPatch::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 CleanMeshWithPatch::bbUserFinalizeProcessing()
+{
+// THE FINALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should desallocate the internal/output pointers
+// if any
+}
+
+} // EO namespace bbcreaVtk
+
+
--- /dev/null
+//=====
+// 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 __bbcreaVtkCleanMeshWithPatch_h_INCLUDED__
+#define __bbcreaVtkCleanMeshWithPatch_h_INCLUDED__
+
+#include "bbcreaVtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include <vtkPolyData.h>
+
+namespace bbcreaVtk
+{
+
+class bbcreaVtk_EXPORT CleanMeshWithPatch
+ :
+ public bbtk::AtomicBlackBox
+{
+ BBTK_BLACK_BOX_INTERFACE(CleanMeshWithPatch,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(Mesh,vtkPolyData*);
+ BBTK_DECLARE_INPUT(Patch,vtkPolyData*);
+ 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_INPUT(Spacing,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(CleanMeshWithPatch,bbtk::AtomicBlackBox);
+ BBTK_NAME("CleanMeshWithPatch");
+ BBTK_AUTHOR("InfoDev");
+ BBTK_DESCRIPTION("No Description.");
+ BBTK_CATEGORY("empty");
+ BBTK_INPUT(CleanMeshWithPatch,Mesh,"Mesh to be clean",vtkPolyData*,"");
+ BBTK_INPUT(CleanMeshWithPatch,Patch,"Patch reference",vtkPolyData*,"");
+ BBTK_INPUT(CleanMeshWithPatch,LstX,"List of points X",std::vector<double>,"");
+ BBTK_INPUT(CleanMeshWithPatch,LstY,"List of points Y",std::vector<double>,"");
+ BBTK_INPUT(CleanMeshWithPatch,LstZ,"List of points Z",std::vector<double>,"");
+ BBTK_INPUT(CleanMeshWithPatch,LstIndexs,"List of indexs",std::vector<int>,"");
+ BBTK_INPUT(CleanMeshWithPatch,Spacing,"Spacing [spcX,spcY,spcZ]",std::vector<double>,"");
+ BBTK_OUTPUT(CleanMeshWithPatch,Out,"Output result",vtkPolyData*,"");
+BBTK_END_DESCRIBE_BLACK_BOX(CleanMeshWithPatch);
+//=====
+// 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 // __bbcreaVtkCleanMeshWithPatch_h_INCLUDED__
+