From 18925a120aeb6bda1e90b1a9a2e8d81e63551151 Mon Sep 17 00:00:00 2001 From: Pablo Garzon Date: Thu, 30 Mar 2023 14:41:36 +0200 Subject: [PATCH] #3502 Modify middle point in patch --- bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbg | 112 ++++++++++++++++-- bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbs | 36 +++++- .../bbcreaMaracasVisuShowNPoints_Tools.cxx | 48 +++++++- bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h | 8 +- .../wxWindows/widgets/ModelShowNPoints.cxx | 13 +- .../wxWindows/widgets/ModelShowNPoints.h | 2 + .../wxWindows/widgets/WidgetShowNPoints.cxx | 10 +- .../wxWindows/widgets/WidgetShowNPoints.h | 2 + 8 files changed, 215 insertions(+), 16 deletions(-) diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbg b/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbg index 04ed010..112a484 100644 --- a/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbg +++ b/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbg @@ -1,6 +1,6 @@ # ---------------------------------- # - BBTKGEditor v 1.5 BBG BlackBox Diagram file -# - /Users/davila/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbg +# - /home/garzon/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbg # ---------------------------------- APP_START @@ -72,7 +72,7 @@ COMPLEX_PORT meshmanagermodel -150.374274:130.740991:-900.000000 FIN_COMPLEX_PORT -BOXES:75 +BOXES:81 BOX creaMaracasVisu:ShowNPoints:showNpoints ISEXEC:FALSE @@ -94,8 +94,8 @@ FIN_BOX BOX creaMaracasVisu:ManualContourModel_Box:Box06 ISEXEC:FALSE -29.075845:30.364799:-900.000000 -53.595845:27.864799:-900.000000 +35.216468:30.364799:-900.000000 +59.736468:27.864799:-900.000000 PORT DoubleContour:"1" PORT @@ -132,8 +132,8 @@ FIN_BOX BOX std:MultipleInputs:Box31 ISEXEC:FALSE -21.957727:-67.075176:-900.000000 -43.927727:-69.575176:-900.000000 +18.992085:-64.219001:-900.000000 +40.962085:-66.719001:-900.000000 FIN_BOX BOX creaMaracasVisu:ManualContourModel_Box:Box29 @@ -516,8 +516,8 @@ FIN_BOX BOX creaVtk:LinearExtrusionFilter:Box96 ISEXEC:FALSE -126.330445:-29.439611:-900.000000 -148.840445:-31.939611:-900.000000 +126.138551:-32.318028:-900.000000 +148.648551:-34.818028:-900.000000 FIN_BOX BOX creaMaracasVisu:PolyDataToActor_Widget:Box98 @@ -691,7 +691,59 @@ ISEXEC:FALSE PORT In0:"Auto Add Points (Start/Stop)" FIN_BOX -CONNECTIONS:154 +BOX +creaMaracasVisu:ShowNPoints_Tools:Box120 +ISEXEC:FALSE +-380.000207:-26.721711:-900.000000 +-357.455207:-29.221711:-900.000000 +PORT +BoxProcessMode:"Manual" +PORT +Type:"220" +FIN_BOX +BOX +wx:CommandButton:Box121 +ISEXEC:FALSE +-390.668472:-8.967632:-900.000000 +-368.283472:-11.467632:-900.000000 +PORT +Label:"+" +FIN_BOX +BOX +wx:CommandButton:Box127 +ISEXEC:FALSE +-322.149651:-11.922729:-900.000000 +-299.764651:-14.422729:-900.000000 +PORT +Label:"-" +FIN_BOX +BOX +creaMaracasVisu:ShowNPoints_Tools:Box128 +ISEXEC:FALSE +-328.813882:-27.476919:-900.000000 +-306.268882:-29.976919:-900.000000 +PORT +BoxProcessMode:"Manual" +PORT +Type:"220" +FIN_BOX +BOX +std:ConcatStrings:Box130 +ISEXEC:FALSE +-378.800018:37.000233:-900.000000 +-356.040018:34.500233:-900.000000 +PORT +In2:" 1" +FIN_BOX +BOX +std:ConcatStrings:Box131 +ISEXEC:FALSE +-344.138161:36.747302:-900.000000 +-321.378161:34.247302:-900.000000 +PORT +In2:" -1" +FIN_BOX +CONNECTIONS:168 CONNECTION Box06:LstContourPointsX:Box04:LstX NumberOfControlPoints:0 @@ -1154,4 +1206,46 @@ NumberOfControlPoints:0 CONNECTION Box119:Out:Box58:StringVector NumberOfControlPoints:0 +CONNECTION +Box68:Spacing:Box120:Spacing +NumberOfControlPoints:0 +CONNECTION +showNpoints:WidgetShowNPoints:Box120:WidgetShowNPoints +NumberOfControlPoints:0 +CONNECTION +Box121:BoxChange:Box120:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box121:Widget:Box101:Widget5 +NumberOfControlPoints:0 +CONNECTION +Box127:BoxChange:Box128:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box127:Widget:Box101:Widget6 +NumberOfControlPoints:0 +CONNECTION +Box68:Spacing:Box128:Spacing +NumberOfControlPoints:0 +CONNECTION +showNpoints:WidgetShowNPoints:Box128:WidgetShowNPoints +NumberOfControlPoints:0 +CONNECTION +Box60:Out:Box130:In1 +NumberOfControlPoints:0 +CONNECTION +Box60:Out:Box131:In1 +NumberOfControlPoints:0 +CONNECTION +Box130:Out:Box120:Params +NumberOfControlPoints:0 +CONNECTION +Box131:Out:Box128:Params +NumberOfControlPoints:0 +CONNECTION +Box120:BoxChange:Box31:In3 +NumberOfControlPoints:0 +CONNECTION +Box128:BoxChange:Box31:In5 +NumberOfControlPoints:0 APP_END diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbs b/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbs index 8bad5a3..0317830 100644 --- a/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbs +++ b/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbs @@ -1,6 +1,6 @@ # ---------------------------------- # - BBTKGEditor v 1.5 BBS BlackBox Script (Complex Box) -# - /Users/davila/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbs +# - /home/garzon/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/Mesh_tool_ApplyPatch.bbs # ---------------------------------- include std @@ -252,6 +252,26 @@ new wx:Slider Box118 new std:AddStringToVector Box119 set Box119.In0 "Auto Add Points (Start/Stop)" +new creaMaracasVisu:ShowNPoints_Tools Box120 + set Box120.BoxProcessMode "Manual" + set Box120.Type "220" + +new wx:CommandButton Box121 + set Box121.Label "+" + +new wx:CommandButton Box127 + set Box127.Label "-" + +new creaMaracasVisu:ShowNPoints_Tools Box128 + set Box128.BoxProcessMode "Manual" + set Box128.Type "220" + +new std:ConcatStrings Box130 + set Box130.In2 " 1" + +new std:ConcatStrings Box131 + set Box131.In2 " -1" + connect Box06.LstContourPointsX Box04.LstX connect showNpoints.lstIndexs Box06.LstIndexsIn @@ -392,6 +412,20 @@ connect Box118.Widget Box101.Widget1 connect Box118.Out Box96.ScalarFactor connect Box118.BoxChange Box103.In3 connect Box119.Out Box58.StringVector +connect Box68.Spacing Box120.Spacing +connect showNpoints.WidgetShowNPoints Box120.WidgetShowNPoints +connect Box121.BoxChange Box120.BoxExecute +connect Box121.Widget Box101.Widget5 +connect Box127.BoxChange Box128.BoxExecute +connect Box127.Widget Box101.Widget6 +connect Box68.Spacing Box128.Spacing +connect showNpoints.WidgetShowNPoints Box128.WidgetShowNPoints +connect Box60.Out Box130.In1 +connect Box60.Out Box131.In1 +connect Box130.Out Box120.Params +connect Box131.Out Box128.Params +connect Box120.BoxChange Box31.In3 +connect Box128.BoxChange Box31.In5 # Complex input ports input point showNpoints.In " " diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx index c258512..275a66d 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx @@ -30,7 +30,7 @@ void ShowNPoints_Tools::NearestPointToMesh( vtkPoints *points,vtkStaticPointLoca void ShowNPoints_Tools::CreatePatch_3points() { - printf("PG ShowNPoints_Tools::CreatePatch_3points Entered patch 3 points !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + //printf("PG ShowNPoints_Tools::CreatePatch_3points Entered patch 3 points !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints(); wsp->StopAutoAddPoints(); wsp->StopTrackPoint(); @@ -106,11 +106,11 @@ void ShowNPoints_Tools::CreatePatch_3points() resListX.push_back(pointSub[0]); resListY.push_back(pointSub[1]); resListZ.push_back(pointSub[2]); - printf("PG ShowNPoints_Tools::CreatePatch_3points Calls CreatePatch_Points !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + //printf("PG ShowNPoints_Tools::CreatePatch_3points Calls CreatePatch_Points !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); //Create patch given the previously calculated points (4 points) CreatePatch_Points(resListX, resListY, resListZ); }else{ - printf("PG ShowNPoints_Tools::CreatePatch_3points Warning patch not apply. Need only one group of 3 points\n"); + //printf("PG ShowNPoints_Tools::CreatePatch_3points Warning patch not apply. Need only one group of 3 points\n"); } } @@ -305,15 +305,53 @@ void ShowNPoints_Tools::CreatePatch_Points(std::vector lstX, std::vectorInvertLstPoints_(); } // if angle + std::vector normalOut(n2, n2 + 3); + double norm = vtkMath::Norm(n2); + normalOut[0] = normalOut[0]/norm; + normalOut[1] = normalOut[1]/norm; + normalOut[2] = normalOut[2]/norm; + bbSetOutputOut(normalOut); // --- Finish --- wsp->SetOutputBox(); wsp->UndoRedo_SaveCollection(); } +void ShowNPoints_Tools::MovePatchCenter() +{ + std::vector params = bbGetInputParams(); + if(params.size() == 4) + { + if(params[3] != 1 && params[3] != -1) + { + printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. direction of movement should be 1 or -1\n"); + return; + } + + double centerPoint[3]; + std::vector normal, modPoint; + + normal.push_back(params[0]); + normal.push_back(params[1]); + normal.push_back(params[2]); + int direction = -params[3]; + + WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints(); + wsp->GetCollectionPoint(1,1, centerPoint); + modPoint.push_back(centerPoint[0] + direction*normal[0]); + modPoint.push_back(centerPoint[1] + direction*normal[1]); + modPoint.push_back(centerPoint[2] + direction*normal[2]); + + wsp->SetCollectionPoint(1, 1, modPoint); + wsp->GetViewShowNPoints()->RefreshPoints(); + }else{ + printf("PG ShowNPoints_Tools::MovePatchCenter() Warning params are wrong. Need 4: normal x y z and direction of movement (1 or -1)\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) @@ -391,6 +429,10 @@ void ShowNPoints_Tools::Process() { bbGetInputWidgetShowNPoints()->OnInvertLstPoints_(); } // if Type + if(bbGetInputType()==220) + { + MovePatchCenter(); + } // if Type } // if bbGetInputWidgetShowNPoints } //===== diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h index 28b8e65..d0abad8 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h @@ -29,6 +29,8 @@ class bbcreaMaracasVisu_EXPORT ShowNPoints_Tools BBTK_DECLARE_INPUT(Spacing,std::vector); BBTK_DECLARE_INPUT(Mesh,vtkPolyData*); BBTK_DECLARE_INPUT(Type,int); + BBTK_DECLARE_INPUT(Params, std::vector); + BBTK_DECLARE_OUTPUT(Out, std::vector); // BBTK_DECLARE_OUTPUT(Out,double); BBTK_PROCESS(Process); void Process(); @@ -37,6 +39,7 @@ class bbcreaMaracasVisu_EXPORT ShowNPoints_Tools void CreatePatch_4points(); void CreatePatch_Points(std::vector lstX, std::vector lstY, std::vector lstZ); void NearestPointToMesh( vtkPoints *points, vtkStaticPointLocator *pointLocator, double *spc , double *p , double *pM ); + void MovePatchCenter(); //===== // 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) @@ -51,7 +54,10 @@ BBTK_CATEGORY("empty"); BBTK_INPUT(ShowNPoints_Tools,WidgetShowNPoints,"WidgetShowNPoints",WidgetShowNPoints*,""); BBTK_INPUT(ShowNPoints_Tools,Spacing,"(default [1,1,1] )Spacing",std::vector,""); BBTK_INPUT(ShowNPoints_Tools,Mesh,"Mesh en format vtkPolyData ",vtkPolyData*,""); - BBTK_INPUT(ShowNPoints_Tools,Type,"(default 0) 0:Nothing 1:Auto add poits 5:Add Point 10:Insert Point 20:TrackPoint 30:Set nearest point 40:Erase point 50:Deleta all points 100:Insert group after 110:Delete group 120:Reset colletion 190:Tool 3 points to surface - Create Mesh (based with one group and 3 points) 200:Tool 4 points to surface - Create Mesh (based with one group and 4 points)",int,""); + BBTK_INPUT(ShowNPoints_Tools,Type,"(default 0) 0:Nothing 1:Auto add poits 5:Add Point 10:Insert Point 20:TrackPoint 30:Set nearest point 40:Erase point 50:Deleta all points 100:Insert group after 110:Delete group 120:Reset colletion 190:Tool 3 points to surface - Create Mesh (based with one group and 3 points) 200:Tool 4 points to surface - Create Mesh (based with one group and 4 points) 210: Invert points 220: Move patch center",int,""); + BBTK_INPUT(ShowNPoints_Tools, Params,"Optional params for the tools, required for 200: Normal and direction", std::vector,""); + + BBTK_OUTPUT(ShowNPoints_Tools, Out, "Output", std::vector, ""); // BBTK_OUTPUT(ShowNPoints_Tools,Out,"First output",double,""); BBTK_END_DESCRIBE_BLACK_BOX(ShowNPoints_Tools); //===== diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx index 95d6e9e..ea3616a 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx @@ -366,7 +366,18 @@ int ModelShowNPoints::IdInsidePoint() return id; } // if } - +//------------------------------------------------------------------------ +void ModelShowNPoints::SetPointById(int id, std::vector point) +{ + if(id >= 0 && id < lstPointsX.size()){ + lstPointsX[id] = point[0]; + lstPointsY[id] = point[1]; + lstPointsZ[id] = point[2]; + } + else{ + printf("WidgetShowNPoints::SetPointById Invalid pointid, id is outside range\n"); + } +} //------------------------------------------------------------------------ int ModelShowNPoints::RenamePoint(std::string label) { diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h index 7fbbad7..fce6107 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h @@ -33,6 +33,8 @@ class ModelShowNPoints void SetPointId_mReferencePoint(int id); int IdInsidePoint(); + void SetPointById(int id, std::vector point); + void SetReferencePoint(std::vector ppoint); std::vector GetReferencePoint(); void SetImage(vtkImageData *image); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx index 5574c86..7aba88a 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx @@ -1369,7 +1369,15 @@ void WidgetShowNPoints::GetCollectionPoint(int idCol,int idPoint, double *pPoint pPoint[1] = y; pPoint[2] = z; } - +//------------------------------------------------------------------------ +void WidgetShowNPoints::SetCollectionPoint(int idCol, int idPoint, std::vector modPoint) +{ + if(idCol >= 0 && idCol < lstModelShowNPoints.size()) + lstModelShowNPoints[idCol]->SetPointById(idPoint, modPoint); + else{ + printf("WidgetShowNPoints::SetCollectionPoint ...Error... Invalid collection, out of range"); + } +} //------------------------------------------------------------------------ std::vector WidgetShowNPoints::GetLstPointsX() { diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h index 7e41319..54d77e0 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h @@ -69,6 +69,8 @@ class WidgetShowNPoints : public wxPanel void OnResetCollections_(); void OnResetCollections(wxCommandEvent &event); void GetCollectionPoint(int idCol,int idPoint, double *pPoint); + + void SetCollectionPoint(int idCol, int idPoint, std::vector modPoint); void OnUndo(wxCommandEvent &event); void OnRedo(wxCommandEvent &event); -- 2.47.1