From: Eduardo DAVILA Date: Tue, 27 Jun 2023 10:46:00 +0000 (+0200) Subject: #3513 CleanMeshWithPatch X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=444964b786ba62c7715c061d116a2baddcf81f23;p=creaVtk.git #3513 CleanMeshWithPatch --- diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCleanMeshWithPatch.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCleanMeshWithPatch.cxx new file mode 100644 index 0000000..2cdb49b --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCleanMeshWithPatch.cxx @@ -0,0 +1,207 @@ +//===== +// 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 +#include +#include +#include + +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 = " < lstIndexs = bbGetInputLstIndexs(); + if (( lstIndexs.size()>=3 ) && (bbGetInputMesh()!=NULL) ) { + + // Step 1. ----Get perimeter CtrlPoints----- + std::vector lstX = bbGetInputLstX(); + std::vector lstY = bbGetInputLstY(); + std::vector lstZ = bbGetInputLstZ(); + std::vector perimeterX; + std::vector perimeterY; + std::vector perimeterZ; + std::vector tmpX; + std::vector tmpY; + std::vector tmpZ; + int iGroup,sizeGroups = lstIndexs.size(); + int i,iGeneral=0,size; + for (iGroup=0 ; iGroup=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 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 lstIds; + for (i=0;iFindClosestPoint( 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;iSetInputData( 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 + + diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCleanMeshWithPatch.h b/bbtk_creaVtk_PKG/src/bbcreaVtkCleanMeshWithPatch.h new file mode 100644 index 0000000..e56ce6f --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCleanMeshWithPatch.h @@ -0,0 +1,60 @@ +//===== +// 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 + +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); + BBTK_DECLARE_INPUT(LstY,std::vector); + BBTK_DECLARE_INPUT(LstZ,std::vector); + BBTK_DECLARE_INPUT(LstIndexs,std::vector); + BBTK_DECLARE_INPUT(Spacing,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(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,""); + BBTK_INPUT(CleanMeshWithPatch,LstY,"List of points Y",std::vector,""); + BBTK_INPUT(CleanMeshWithPatch,LstZ,"List of points Z",std::vector,""); + BBTK_INPUT(CleanMeshWithPatch,LstIndexs,"List of indexs",std::vector,""); + BBTK_INPUT(CleanMeshWithPatch,Spacing,"Spacing [spcX,spcY,spcZ]",std::vector,""); + 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__ +