]> Creatis software - creaMaracasVisu.git/commitdiff
#3514 Move selected point with normal
authorPablo Garzon <gapablo2001@gmail.com>
Tue, 13 Jun 2023 11:51:33 +0000 (13:51 +0200)
committerPablo Garzon <gapablo2001@gmail.com>
Tue, 13 Jun 2023 11:51:33 +0000 (13:51 +0200)
bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg
bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs
bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx
bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/ModelShowNPoints.h

index 11f16fc422307d9dcfe44758108c179dba9bf378..8ce9d4f59ed76e227cbb957a76150584de562f50 100644 (file)
@@ -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
index 5c2c68154060cd874b420a2d5337cb32ba35ac93..e11c59945ada8cc7a8cae179df2e7f507dbb0f14 100644 (file)
@@ -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 " "
index 3fd8695fac6a5f492758bc1965991ce73af50bd4..2d650d6c9ad149c40db7b3d57f792ac7d59c5b85 100644 (file)
@@ -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<double> 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();
index 55e1ebc21bcbe87f17c973da1ff51c890cecf1e5..fda64b0ad4b689ed7dd585652f8be4083a3b2c42 100644 (file)
@@ -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)
index baac364a80e62d4610c0b82ee387a9d15b921240..6deb8aea327a8625eed070b6c9c97eb59a89fa9f 100644 (file)
@@ -8,6 +8,7 @@
 ModelShowNPoints::ModelShowNPoints()
 {
        firsttime=true;
+       currentPoint = -1;
 }
 //----------------------------------------------------------------------
 
@@ -68,6 +69,15 @@ std::vector<std::string> ModelShowNPoints::GetLstLabels()
 void ModelShowNPoints::SetReferencePoint(std::vector<double> 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;
+}
index b809c2a602c5e91a332bd02591b104b9d6c50a2a..b4d25918330dbb6ad6ba261e789ab052759e38c5 100644 (file)
@@ -47,6 +47,7 @@ class ModelShowNPoints
          void                                                  SetFirstTime(bool value);
          bool                                                  GetFirstTime();
       void                             InversLstPoints();
+      int                                                      GetCurrentPoint();
       
        private:
          std::vector<double>           lstPointsX;
@@ -57,6 +58,7 @@ class ModelShowNPoints
          double                                mradio;
          vtkImageData                          *mimage;
          bool                                                  firsttime;
+         int                                                   currentPoint;
 
   };