From 51f20c2ae79090ebe8c95ed7194daeee2fe9c215 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Mon, 6 Dec 2021 14:44:21 +0100 Subject: [PATCH] #3472 MeshDeformation --- .../src/bbcreaVtkMeshDeformation.cxx | 127 +++++++++++------- .../src/bbcreaVtkMeshDeformation.h | 10 +- 2 files changed, 87 insertions(+), 50 deletions(-) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx index 3fac0f9..9223d52 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.cxx @@ -27,17 +27,26 @@ void MeshDeformation::Process() // (the one provided in the attribute 'type' of the tag 'input') // bbSetOutputOut( bbGetInputIn() ); // std::cout << "Output value = " < lstCenter = bbGetInputCenter(); + double s = bbGetInputS(); - bool ok=true; - if (bbGetInputDirection().size()==3) + bool ok=false; + if (bbGetInputTypeIn()==0) // direction { - ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) ); - } - if ( (bbGetInputIn()!=NULL) && (ok==true) && (bbGetInputEdgeId()>=0)) + if (bbGetInputDirection().size()==3) + { + ok = !( (bbGetInputDirection()[0]==0) && (bbGetInputDirection()[1]==0) && (bbGetInputDirection()[2]==0) ); + } + } // if TypeIn 0 + + if (bbGetInputTypeIn()==1) // center { + ok = ( lstCenter.size()==3 ); + } // if TypeIn 1 + if ( (bbGetInputIn()!=NULL) && (ok==true) && (bbGetInputEdgeId()>=0) && (bbGetInputActive()==true) ) + { vtkPoints* points=bbGetInputIn()->GetPoints(); long i,size=points->GetNumberOfPoints(); double p[3]; // point @@ -48,58 +57,74 @@ void MeshDeformation::Process() sy = sx; sz = sy; - points->GetPoint( bbGetInputEdgeId() , pb ); - - if (EdgeIdBack!=bbGetInputEdgeId() ) - { - voiIdPoints.clear(); - EdgeIdBack = bbGetInputEdgeId(); - for ( i=0 ; iGetPoint(i,p); - - if ( (p[0]>(pb[0]-sx)) && (p[0]<(pb[0]+sx)) && - (p[1]>(pb[1]-sy)) && (p[1]<(pb[1]+sy)) && - (p[2]>(pb[2]-sz)) && (p[2]<(pb[2]+sz)) ) - { - voiIdPoints.push_back( i ); - } // if - } // for i - } // back double displcement_x = 0; double displcement_y = 0; double displcement_z = 0; - if (bbGetInputDirection().size()==3) + if (bbGetInputTypeIn()==0) // Direction { displcement_x = bbGetInputDirection()[0]; displcement_y = bbGetInputDirection()[1]; displcement_z = bbGetInputDirection()[2]; - } + } // if TypeIn 0 Direction - size=voiIdPoints.size(); - for (i=0;iGetPoint( voiIdPoints[i] , p ); - double x = p[0] - pb[0]; //distance between a point and seed point - double y = p[1] - pb[1]; - double z = p[2] - pb[2]; - double distance = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2)); + if (EdgeIdBack==bbGetInputEdgeId() ) + { + displcement_x = (lstCenter[0]-backLstCenter[0])/1.0; + displcement_y = (lstCenter[1]-backLstCenter[1])/1.0; + displcement_z = (lstCenter[2]-backLstCenter[2])/1.0; + } // if EdgeIdBack!=bbGetInputEdgeId() + backLstCenter[0]= lstCenter[0]; + backLstCenter[1]= lstCenter[1]; + backLstCenter[2]= lstCenter[2]; + } // if TypeIn 1 Center -// https://en.wikipedia.org/wiki/Generalized_normal_distribution -// with Gama function - - double weight = exp(-distance * 1. / s); - if (weight > 0.0001) + + points->GetPoint( bbGetInputEdgeId() , pb ); + if (EdgeIdBack!=bbGetInputEdgeId() ) { - np[0] = p[0] + weight*displcement_x; - np[1] = p[1] + weight*displcement_y; - np[2] = p[2] + weight*displcement_z; - points->SetPoint( voiIdPoints[i] , np ); - } // if - } // for - points->Modified(); - bbGetInputIn()->Modified(); + EdgeIdBack = bbGetInputEdgeId(); + voiIdPoints.clear(); + for ( i=0 ; iGetPoint(i,p); + if ( (p[0]>(pb[0]-sx)) && (p[0]<(pb[0]+sx)) && + (p[1]>(pb[1]-sy)) && (p[1]<(pb[1]+sy)) && + (p[2]>(pb[2]-sz)) && (p[2]<(pb[2]+sz)) ) + { + voiIdPoints.push_back( i ); + } // if + } // for i + } // back + + if ( !((displcement_x==0) &&(displcement_y==0) && (displcement_z==0)) ) + { + size=voiIdPoints.size(); + for (i=0;iGetPoint( voiIdPoints[i] , p ); + double x = p[0] - pb[0]; //distance between a point and seed point + double y = p[1] - pb[1]; + double z = p[2] - pb[2]; + double distance = std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2)); + + // https://en.wikipedia.org/wiki/Generalized_normal_distribution + // with Gama function + + double weight = exp(-distance * 1. / s); + if (weight > 0.0001) + { + np[0] = p[0] + weight*displcement_x; + np[1] = p[1] + weight*displcement_y; + np[2] = p[2] + weight*displcement_z; + points->SetPoint( voiIdPoints[i] , np ); + } // if + } // for + points->Modified(); + bbGetInputIn()->Modified(); + } // if distance_x y z != 0 } // In != NULL } //===== @@ -110,7 +135,9 @@ void MeshDeformation::bbUserSetDefaultValues() // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 - bbSetInputIn(NULL); + bbSetInputActive(true); + bbSetInputTypeIn(0); + bbSetInputIn(NULL); std::vector direction; direction.push_back(1); direction.push_back(0); @@ -119,6 +146,10 @@ void MeshDeformation::bbUserSetDefaultValues() EdgeIdBack=-1; bbSetInputEdgeId(EdgeIdBack); bbSetInputS(10); + + backLstCenter.push_back(0); + backLstCenter.push_back(0); + backLstCenter.push_back(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) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.h b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.h index 22bb17c..c2ce1a8 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshDeformation.h @@ -21,17 +21,20 @@ class bbcreaVtk_EXPORT MeshDeformation //===== // 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(Active, bool); + BBTK_DECLARE_INPUT(TypeIn, int); BBTK_DECLARE_INPUT(In,vtkPolyData*); BBTK_DECLARE_INPUT(EdgeId, long); BBTK_DECLARE_INPUT(S, double); + BBTK_DECLARE_INPUT(Center, std::vector); BBTK_DECLARE_INPUT(Direction, std::vector); // BBTK_DECLARE_OUTPUT(Out,double); BBTK_PROCESS(Process); void Process(); long EdgeIdBack; - std::vector voiIdPoints; - + std::vector voiIdPoints; + std::vector backLstCenter; //===== // 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) //===== @@ -42,9 +45,12 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(MeshDeformation,bbtk::AtomicBlackBox); BBTK_AUTHOR("Info-Dev"); BBTK_DESCRIPTION("No Description."); BBTK_CATEGORY("empty"); + BBTK_INPUT(MeshDeformation,Active,"(default true) true/false",bool,""); + BBTK_INPUT(MeshDeformation,TypeIn,"(default 0) 0:Direction 1:Center",int,""); BBTK_INPUT(MeshDeformation,In,"vtk PolyData",vtkPolyData*,""); BBTK_INPUT(MeshDeformation,EdgeId,"Edge Id",long,""); BBTK_INPUT(MeshDeformation,S,"Deformation",double,""); + BBTK_INPUT(MeshDeformation,Center,"[X,Y,Z]",std::vector,""); BBTK_INPUT(MeshDeformation,Direction,"(default [1,0,0]) [X,Y,Z]",std::vector,""); // BBTK_OUTPUT(MeshDeformation,Out,"First output",double,""); BBTK_END_DESCRIBE_BLACK_BOX(MeshDeformation); -- 2.45.1