From: Pablo Garzon Date: Tue, 13 Jun 2023 11:51:33 +0000 (+0200) Subject: #3514 Move selected point with normal X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=42289f3058ddc721b21e04869b365b2e8c1378fa;p=creaMaracasVisu.git #3514 Move selected point with normal --- diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg b/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg index 11f16fc..8ce9d4f 100644 --- a/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg +++ b/bbtk/bbs/boxes/Mesh_tool_ApplySurface.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_ApplySurface.bbg +# - /home/garzon/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg # ---------------------------------- APP_START @@ -72,7 +72,7 @@ COMPLEX_PORT meshmanagermodel -150.374274:130.740991:-900.000000 FIN_COMPLEX_PORT -BOXES:70 +BOXES:75 BOX creaMaracasVisu:ShowNPoints:showNpoints ISEXEC:FALSE @@ -649,7 +649,55 @@ ISEXEC:FALSE PORT In0:"Tool - Inverse Normals" FIN_BOX -CONNECTIONS:147 +BOX +creaMaracasVisu:ShowNPoints_Tools:Box116 +ISEXEC:FALSE +83.181891:-37.997829:-900.000000 +105.726891:-40.497829:-900.000000 +PORT +BoxProcessMode:"Manual" +PORT +Params:" -1" +PORT +Type:"230" +FIN_BOX +BOX +wx:CommandButton:Box117 +ISEXEC:FALSE +100.839007:-14.508839:-900.000000 +123.224007:-17.008839:-900.000000 +PORT +Label:"-" +FIN_BOX +BOX +wx:LayoutLine:Box118 +ISEXEC:FALSE +105.323248:-27.231844:-900.000000 +138.643248:-29.731844:-900.000000 +PORT +Orientation:"H" +FIN_BOX +BOX +wx:CommandButton:Box119 +ISEXEC:FALSE +131.048147:-14.696561:-900.000000 +153.433147:-17.196561:-900.000000 +PORT +Label:"+" +FIN_BOX +BOX +creaMaracasVisu:ShowNPoints_Tools:Box120 +ISEXEC:FALSE +118.818739:-37.869439:-900.000000 +141.363739:-40.369439:-900.000000 +PORT +BoxProcessMode:"Manual" +PORT +Params:" 1" +PORT +Type:"230" +FIN_BOX +CONNECTIONS:158 CONNECTION Box06:LstContourPointsX:Box04:LstX NumberOfControlPoints:0 @@ -1091,4 +1139,37 @@ NumberOfControlPoints:0 CONNECTION Box49:OutString:Box29:NbPoints NumberOfControlPoints:0 +CONNECTION +showNpoints:WidgetShowNPoints:Box116:WidgetShowNPoints +NumberOfControlPoints:0 +CONNECTION +Box68:Spacing:Box116:Spacing +NumberOfControlPoints:0 +CONNECTION +Box117:BoxChange:Box116:BoxExecute +NumberOfControlPoints:0 +CONNECTION +Box117:Widget:Box118:Widget2 +NumberOfControlPoints:0 +CONNECTION +Box118:Widget:Box50:Widget9 +NumberOfControlPoints:0 +CONNECTION +Box119:Widget:Box118:Widget3 +NumberOfControlPoints:0 +CONNECTION +Box119:BoxChange:Box120:BoxExecute +NumberOfControlPoints:0 +CONNECTION +showNpoints:WidgetShowNPoints:Box120:WidgetShowNPoints +NumberOfControlPoints:0 +CONNECTION +Box68:Spacing:Box120:Spacing +NumberOfControlPoints:0 +CONNECTION +Box105:Out:Box116:Mesh +NumberOfControlPoints:0 +CONNECTION +Box105:Out:Box120:Mesh +NumberOfControlPoints:0 APP_END diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs b/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs index 5c2c681..e11c599 100644 --- a/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs +++ b/bbtk/bbs/boxes/Mesh_tool_ApplySurface.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_ApplySurface.bbs +# - /home/garzon/Creatis/C23/creatools_source/creaMaracasVisu/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs # ---------------------------------- include std @@ -236,6 +236,25 @@ new wx:LayoutLine Box114 new std:AddStringToVector Box115 set Box115.In0 "Tool - Inverse Normals" +new creaMaracasVisu:ShowNPoints_Tools Box116 + set Box116.BoxProcessMode "Manual" + set Box116.Params " -1" + set Box116.Type "230" + +new wx:CommandButton Box117 + set Box117.Label "-" + +new wx:LayoutLine Box118 + set Box118.Orientation "H" + +new wx:CommandButton Box119 + set Box119.Label "+" + +new creaMaracasVisu:ShowNPoints_Tools Box120 + set Box120.BoxProcessMode "Manual" + set Box120.Params " 1" + set Box120.Type "230" + connect Box06.LstContourPointsX Box04.LstX connect showNpoints.lstIndexs Box06.LstIndexsIn @@ -369,6 +388,17 @@ connect Box58.Out Box115.StringVector connect Box115.Out Box57.In connect Box67.Out Box60.Mesh connect Box49.OutString Box29.NbPoints +connect showNpoints.WidgetShowNPoints Box116.WidgetShowNPoints +connect Box68.Spacing Box116.Spacing +connect Box117.BoxChange Box116.BoxExecute +connect Box117.Widget Box118.Widget2 +connect Box118.Widget Box50.Widget9 +connect Box119.Widget Box118.Widget3 +connect Box119.BoxChange Box120.BoxExecute +connect showNpoints.WidgetShowNPoints Box120.WidgetShowNPoints +connect Box68.Spacing Box120.Spacing +connect Box105.Out Box116.Mesh +connect Box105.Out Box120.Mesh # Complex input ports input point showNpoints.In " " diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx index 3fd8695..2d650d6 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx @@ -632,7 +632,6 @@ void ShowNPoints_Tools::ExpandPatch() double currentPoint[3], dV[3], mdfdPoint[3]; for(int group = 0; group < 3; group++){ if(group == 1){ - cout << "collection: " << group << " i: " << "0" << endl; wsp->GetCollectionPoint(group, 0, currentPoint); dV[0] = currentPoint[0] - centroid[0]; dV[1] = currentPoint[1] - centroid[1]; @@ -642,7 +641,6 @@ void ShowNPoints_Tools::ExpandPatch() vtkMath::Add(currentPoint, dV, mdfdPoint); modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint)); wsp->SetCollectionPoint(group, 0, modPoint); - cout << "collection: " << group << " i: " << "2" << endl; wsp->GetCollectionPoint(group, 2, currentPoint); dV[0] = currentPoint[0] - centroid[0]; dV[1] = currentPoint[1] - centroid[1]; @@ -662,7 +660,6 @@ void ShowNPoints_Tools::ExpandPatch() vtkMath::MultiplyScalar(dV, direction); vtkMath::Add(currentPoint, dV, mdfdPoint); modPoint.insert(modPoint.begin(), std::begin(mdfdPoint), std::end(mdfdPoint)); - cout << "collection: " << group << " i: " << i << endl; wsp->SetCollectionPoint(group, i, modPoint); } } @@ -713,6 +710,59 @@ void ShowNPoints_Tools::WidenSurface() wsp->SetOutputBox(); wsp->UndoRedo_SaveCollection(); } + +void ShowNPoints_Tools::MovePointInNormal() +{ + //move the currently selected control point in the direction or opposite of the normal vector of the closest point in the input mesh + + WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints(); + wsp->StopAutoAddPoints(); + wsp->StopTrackPoint(); + if((wsp->GetLstModelShowNPointsSize()>=2) //Check condition + && (wsp->GetModelShowNPoints()->GetLstPointsSize()>0) + && (bbGetInputParams().size() == 1) + && (bbGetInputMesh() != NULL) + && (bbGetInputSpacing().size() == 3)) + { + if(bbGetInputParams()[0] != -1 && bbGetInputParams()[0] != 1){ + printf("PG ShowNPoints_Tools::MovePointInNormal No direction provided, must be 1 or -1"); + return; + } + double spc[3]; + double x,y,z; + double p[3], normal[3];; // point to modify and normal + std::vector pN(3); // new point + + spc[0] = bbGetInputSpacing()[0]; + spc[1] = bbGetInputSpacing()[1]; + spc[2] = bbGetInputSpacing()[2]; + + vtkPoints *points = bbGetInputMesh()->GetPoints(); + vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New(); + pointLocator->SetDataSet( bbGetInputMesh() ); + pointLocator->BuildLocator(); + + int idControlPoint = wsp->GetModelShowNPoints()->GetNearestPoint(); + if(idControlPoint >= 0){ + wsp->GetModelShowNPoints()->GetIdPoint(idControlPoint, &x, &y, &z); + p[0] = x; + p[1] = y; + p[2] = z; + int idMeshPoint = pointLocator->FindClosestPoint(p); + bbGetInputMesh()->GetPointData()->GetNormals()->GetTuple(idMeshPoint, normal); + int direction = bbGetInputParams()[0]; + pN[0] = p[0] + direction*normal[0]; + pN[1] = p[1] + direction*normal[1]; + pN[2] = p[2] + direction*normal[2]; + + wsp->GetModelShowNPoints()->SetPointById(idControlPoint, pN); + wsp->GetViewShowNPoints()->RefreshPoint(idControlPoint); + wsp->SetOutputBox(); + wsp->UndoRedo_SaveCollection(); + } + + } +} //===== // 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) //===== @@ -793,6 +843,10 @@ void ShowNPoints_Tools::Process() { MovePatchCenter(); } // if Type + if(bbGetInputType()==230) + { + MovePointInNormal(); + } // if Type if(bbGetInputType()==300) { CreateExpandedSurface(); diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h index 55e1ebc..fda64b0 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h @@ -47,6 +47,7 @@ class bbcreaMaracasVisu_EXPORT ShowNPoints_Tools void ExpandSurfaceArea(); void WidenSurface(); void ExpandPatch(); + void MovePointInNormal(); //===== // 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/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx index baac364..6deb8ae 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx @@ -8,6 +8,7 @@ ModelShowNPoints::ModelShowNPoints() { firsttime=true; + currentPoint = -1; } //---------------------------------------------------------------------- @@ -68,6 +69,15 @@ std::vector ModelShowNPoints::GetLstLabels() void ModelShowNPoints::SetReferencePoint(std::vector ppoint) { mReferencePoint = ppoint; + if(lstPointsX.size() > 0){ + int idPoint = IdInsidePoint(); + if(idPoint == -1 && currentPoint >= 0 && currentPoint < lstPointsX.size()){ + currentPoint = currentPoint; + } + else{ + currentPoint = idPoint; + } + } } //------------------------------------------------------------------------ @@ -428,4 +438,8 @@ void ModelShowNPoints::InversLstPoints() } // for i } - +//---------------------------------------------------------------------- +int ModelShowNPoints::GetCurrentPoint() +{ + return currentPoint; +} diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h index b809c2a..b4d2591 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h @@ -47,6 +47,7 @@ class ModelShowNPoints void SetFirstTime(bool value); bool GetFirstTime(); void InversLstPoints(); + int GetCurrentPoint(); private: std::vector lstPointsX; @@ -57,6 +58,7 @@ class ModelShowNPoints double mradio; vtkImageData *mimage; bool firsttime; + int currentPoint; };