]> Creatis software - creaMaracasVisu.git/commitdiff
#3528 Contour ordering around axis
authorPablo Garzon <gapablo2001@gmail.com>
Mon, 24 Jul 2023 10:41:34 +0000 (12:41 +0200)
committerPablo Garzon <gapablo2001@gmail.com>
Mon, 24 Jul 2023 10:41:34 +0000 (12:41 +0200)
bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbg
bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbs
bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg
bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs
bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx
bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h

index c8ab33b7c347f09f2bb659960a185c6890dfc183..7079b3a7a44077f22383477bfc96ad36f01382dc 100644 (file)
@@ -17,7 +17,7 @@ widget
 FIN_COMPLEX_PORT
 COMPLEX_PORT
 ExportIsActive_concatstring_tool
--495.718682:-76.702206:-900.000000
+-550.600502:-76.318417:-900.000000
 FIN_COMPLEX_PORT
 COMPLEXINPUTS:9
 COMPLEX_PORT
@@ -56,7 +56,7 @@ COMPLEX_PORT
 meshmanagermodel
 -131.800179:136.578564:-900.000000
 FIN_COMPLEX_PORT
-BOXES:90
+BOXES:98
 BOX
 wx:LayoutLine:Box08
 ISEXEC:FALSE
@@ -214,8 +214,8 @@ FIN_BOX
 BOX
 creaMaracasVisu:wxVtkBaseView_Info:Box96
 ISEXEC:FALSE
--287.507139:74.319532:-900.000000
--260.227139:71.819532:-900.000000
+-282.583529:75.895087:-900.000000
+-255.303529:73.395087:-900.000000
 FIN_BOX
 BOX
 creaVtk:MeshManager_tool:Box48
@@ -416,8 +416,8 @@ FIN_BOX
 BOX
 creaMaracasVisu:wxVtkBaseView_info_tool:Box91
 ISEXEC:FALSE
--295.971226:67.391116:-900.000000
--272.891226:64.891116:-900.000000
+-301.387197:67.588060:-900.000000
+-278.307197:65.088060:-900.000000
 PORT
 Type:"0"
 FIN_BOX
@@ -757,7 +757,63 @@ BoxProcessMode:"Manual"
 PORT
 Tool:"20"
 FIN_BOX
-CONNECTIONS:171
+BOX
+creaMaracasVisu:SetPosition:Box142
+ISEXEC:FALSE
+-486.165273:-86.007669:-900.000000
+-464.395273:-88.507669:-900.000000
+FIN_BOX
+BOX
+creaMaracasVisu:SetPosition:Box143
+ISEXEC:FALSE
+-458.925237:-86.103993:-900.000000
+-437.155237:-88.603993:-900.000000
+FIN_BOX
+BOX
+std:MathOperationVector:Box144
+ISEXEC:FALSE
+-453.769576:-74.337147:-900.000000
+-429.249576:-76.837147:-900.000000
+PORT
+Type:"3"
+FIN_BOX
+BOX
+std:MathOperationVector:Box145
+ISEXEC:FALSE
+-482.408042:-69.518814:-900.000000
+-457.888042:-72.018814:-900.000000
+PORT
+Type:"3"
+FIN_BOX
+BOX
+creaVtk:PointPickerNearest:Box148
+ISEXEC:FALSE
+-516.890064:-75.470080:-900.000000
+-494.330064:-77.970080:-900.000000
+FIN_BOX
+BOX
+creaVtk:PlaneWidget_Base:Box154
+ISEXEC:FALSE
+-534.858110:-91.209728:-900.000000
+-512.338110:-93.709728:-900.000000
+PORT
+Type:"2"
+FIN_BOX
+BOX
+std:MultipleInputs:Box150
+ISEXEC:FALSE
+-513.551344:-104.677172:-900.000000
+-491.471344:-107.177172:-900.000000
+FIN_BOX
+BOX
+creaVtk:PlaneWidget_Base:Box151
+ISEXEC:FALSE
+-512.258536:-92.741365:-900.000000
+-489.738536:-95.241365:-900.000000
+PORT
+Type:"3"
+FIN_BOX
+CONNECTIONS:185
 CONNECTION
 Box08:Widget:widget:widget
 NumberOfControlPoints:0
@@ -1269,6 +1325,48 @@ CONNECTION
 Box58:BoxChange:Box89:BoxExecute
 NumberOfControlPoints:0
 CONNECTION
-Box122:Out:Box134:StringParam
+Box122:Out:Box134:DoubleParams
+NumberOfControlPoints:0
+CONNECTION
+Box138:BoxChange:Box143:BoxExecute
+NumberOfControlPoints:0
+CONNECTION
+Box96:wxVtkBaseView:Box143:wxVtkBaseView
+NumberOfControlPoints:0
+CONNECTION
+Box96:wxVtkBaseView:Box142:wxVtkBaseView
+NumberOfControlPoints:0
+CONNECTION
+Box138:Out:Box144:In0
+NumberOfControlPoints:0
+CONNECTION
+Box83:Spacing:Box144:In1
+NumberOfControlPoints:0
+CONNECTION
+Box144:Out:Box143:Point
+NumberOfControlPoints:0
+CONNECTION
+Box137:Out:Box145:In0
+NumberOfControlPoints:0
+CONNECTION
+Box83:Spacing:Box145:In1
+NumberOfControlPoints:0
+CONNECTION
+Box145:Out:Box142:Point
+NumberOfControlPoints:0
+CONNECTION
+Box154:BoxChange:Box150:In1
+NumberOfControlPoints:0
+CONNECTION
+Box148:Normal:Box154:ParamVector
+NumberOfControlPoints:0
+CONNECTION
+Box151:BoxChange:Box150:In3
+NumberOfControlPoints:0
+CONNECTION
+Box148:PointOut:Box151:ParamVector
+NumberOfControlPoints:0
+CONNECTION
+Box137:BoxChange:Box142:BoxExecute
 NumberOfControlPoints:0
 APP_END
index 1d13c1781b32636af4b132a347e75e92e527b48a..da33e193ac65795b690429941dbb1fd01d4f016d 100644 (file)
@@ -279,6 +279,26 @@ new creaVtk:MeshManager_tool Box138
   set Box138.BoxProcessMode "Manual"
   set Box138.Tool "20"
 
+new creaMaracasVisu:SetPosition Box142
+
+new creaMaracasVisu:SetPosition Box143
+
+new std:MathOperationVector Box144
+  set Box144.Type "3"
+
+new std:MathOperationVector Box145
+  set Box145.Type "3"
+
+new creaVtk:PointPickerNearest Box148
+
+new creaVtk:PlaneWidget_Base Box154
+  set Box154.Type "2"
+
+new std:MultipleInputs Box150
+
+new creaVtk:PlaneWidget_Base Box151
+  set Box151.Type "3"
+
 
 connect Box66.Out Box11.Renderer
 connect Box66.Out Box37.render
@@ -439,7 +459,21 @@ connect Box50.Out Box89.Active
 connect Box95.Out Box58.Origin
 connect Box58.BoxChange Box61.In2
 connect Box58.BoxChange Box89.BoxExecute
-connect Box122.Out Box134.StringParam
+connect Box122.Out Box134.DoubleParams
+connect Box138.BoxChange Box143.BoxExecute
+connect Box96.wxVtkBaseView Box143.wxVtkBaseView
+connect Box96.wxVtkBaseView Box142.wxVtkBaseView
+connect Box138.Out Box144.In0
+connect Box83.Spacing Box144.In1
+connect Box144.Out Box143.Point
+connect Box137.Out Box145.In0
+connect Box83.Spacing Box145.In1
+connect Box145.Out Box142.Point
+connect Box154.BoxChange Box150.In1
+connect Box148.Normal Box154.ParamVector
+connect Box151.BoxChange Box150.In3
+connect Box148.PointOut Box151.ParamVector
+connect Box137.BoxChange Box142.BoxExecute
 
 # Complex input ports
 input mesh Box67.In " "
index 335e4b26028c74417a40e2c6bc209e684deba53a..fa4c0a6e5520861c31d372dec5197ce0545b2859 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
@@ -176,6 +176,8 @@ creaMaracasVisu:ShowNPoints_Tools:Box60
 ISEXEC:FALSE
 -271.434991:53.686536:-900.000000
 -248.999991:51.186536:-900.000000
+PORT
+Params:"156 276 97"
 FIN_BOX
 BOX
 vtk:ImageVtkProperties:Box68
@@ -523,9 +525,9 @@ ISEXEC:FALSE
 -265.790737:67.872984:-900.000000
 -237.750737:65.372984:-900.000000
 PORT
-In0:"0  1  2   3   4   5   6   7   8      9       10   11   12"
+In0:"0  1  2   3   4   5   6   7   8      9       10   11   12   13"
 PORT
-In1:"1  5 10 20 30 40 50 0  100   110   205  210  240"
+In1:"1  5 10 20 30 40 50 0  100   110   205  210  240  400"
 PORT
 Type:"2"
 FIN_BOX
@@ -648,6 +650,8 @@ PORT
 In0:"Tool - Inverse Normals"
 PORT
 In1:"Tool - Join start and end points to current spline"
+PORT
+In2:"Tool - Separate and order contours around axis"
 FIN_BOX
 BOX
 wx:LayoutLine:Box121
index a6b1664e7ae555439488ae0c1b0ced1df874025d..4f95771dbe7103d43aaaaaf45cb41a0f8a854872 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
@@ -58,6 +58,7 @@ new std:AddStringToVector Box58
   set Box58.In9 "Tool - Create Volume Surface from 3 or 4 points (use Close Spline 2 - Close Surface Off)"
 
 new creaMaracasVisu:ShowNPoints_Tools Box60
+  set Box60.Params "156 276 97"
 
 new vtk:ImageVtkProperties Box68
 
@@ -185,8 +186,8 @@ new std:AddStringToVector Box99
   set Box99.In0 "Auto Add Points (Start/Stop)"
 
 new std:VectorFilterString Box100
-  set Box100.In0 "0  1  2   3   4   5   6   7   8      9       10   11   12"
-  set Box100.In1 "1  5 10 20 30 40 50 0  100   110   205  210  240"
+  set Box100.In0 "0  1  2   3   4   5   6   7   8      9       10   11   12   13"
+  set Box100.In1 "1  5 10 20 30 40 50 0  100   110   205  210  240  400"
   set Box100.Type "2"
 
 new std:ConcatStrings Box101
@@ -235,6 +236,7 @@ new wx:LayoutLine Box114
 new std:AddStringToVector Box115
   set Box115.In0 "Tool - Inverse Normals"
   set Box115.In1 "Tool - Join start and end points to current spline"
+  set Box115.In2 "Tool - Separate and order contours around axis"
 
 new wx:LayoutLine Box121
   set Box121.Orientation "V"
index 0d76ac3ddf54633515715ab69a6ca05dbf0129b3..fa719af0edf67ec31544ecf0b35a200b8c61422c 100644 (file)
@@ -862,6 +862,112 @@ void ShowNPoints_Tools::SetMesh()
     wsp->SetAuxMesh(bbGetInputMesh(), bbGetInputSpacing(), bbGetInputParams() );
 }
 
+void ShowNPoints_Tools::SeparateSplines()
+{
+       WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints();
+       if((wsp->GetLstModelShowNPointsSize() > 0) && (bbGetInputParams().size() == 3))
+       {
+               std::vector<double> refPoint = bbGetInputParams();
+               std::vector<double> pointsX, pointsY, pointsZ;
+               std::vector<std::vector<std::vector<double>>> newGroups;
+               std::vector<std::vector<double>> planesNorm;
+               
+               double rotAxis[3] = {0,0,1};
+               
+               double vector1[3], vector2[3], planeNormal[3], rotatedNormal[3], axisPoint[3], refPlaneNorm[3];
+               int idPoint2, idPoint3;
+               
+               int numGroups = wsp->GetLstModelShowNPointsSize();
+               for(int i = 0; i < numGroups; i++){
+                       pointsX = wsp->GetModelShowNPoints(i)->GetLstPointsX();
+                       pointsY = wsp->GetModelShowNPoints(i)->GetLstPointsY();
+                       pointsZ = wsp->GetModelShowNPoints(i)->GetLstPointsZ();
+                       
+                       idPoint2 = ((int)pointsX.size()/3)-1;
+                       idPoint3 = idPoint2*2;
+                       
+                       vector1[0] = pointsX[idPoint2]-refPoint[0];
+                       vector1[1] = pointsY[idPoint2]-refPoint[1];
+                       vector1[2] = pointsZ[idPoint2]-refPoint[2];
+                       
+                       vector2[0] = pointsX[idPoint3]-refPoint[0];
+                       vector2[1] = pointsY[idPoint3]-refPoint[1];
+                       vector2[2] = pointsZ[idPoint3]-refPoint[2];
+                       
+                       vtkMath::Cross(vector1, vector2, planeNormal);
+                       vtkMath::Normalize(planeNormal);
+                       vtkMath::Cross(planeNormal, rotAxis, rotatedNormal);
+                       vtkMath::Normalize(rotatedNormal);
+                       
+                       if(i == 0){
+                               std::copy(std::begin(planeNormal), std::end(planeNormal), std::begin(refPlaneNorm));
+                       }
+                       
+                       std::vector<std::vector<double>> pointsOver, pointsUnder, pointsOn;
+                       std::vector<double> point(3);
+                       for(int j = 0; j < pointsX.size(); j++){
+                               point[0] = pointsX[j];
+                               point[1] = pointsY[j];
+                               point[2] = pointsZ[j];
+                               vtkMath::Subtract(point.data(), refPoint.data(), vector1);
+                               if(vtkMath::Dot(vector1, rotatedNormal) > 0){
+                                       pointsOver.push_back(point);
+                               }
+                               else if (vtkMath::Dot(vector1, rotatedNormal) < 0){
+                                       pointsUnder.push_back(point);
+                               }
+                               //else{
+                               //      pointsOn.push_back(j);
+                               //}
+                       }
+                       
+                       std::vector<double> normalToSave(std::begin(planeNormal), std::end(planeNormal));
+                       if(!pointsOver.empty()){                        
+                               newGroups.push_back(pointsOver);
+                               planesNorm.push_back(normalToSave);
+                       }
+                       if(!pointsUnder.empty()){       
+                               std::reverse(pointsUnder.begin(), pointsUnder.end());
+                               newGroups.push_back(pointsUnder);
+                               vtkMath::MultiplyScalar(planeNormal, -1);
+                               normalToSave[0] = planeNormal[0]; normalToSave[1] = planeNormal[1]; normalToSave[2] = planeNormal[2];
+                               planesNorm.push_back(normalToSave);
+                       }
+                       
+
+               }
+               
+               auto comp = [&](int id1,int id2)-> bool {
+                       //double dot = vtkMath::Dot(planesNorm[id1].data(), refPlaneNorm);
+                       //double det = vtkMath::Determinant3x3(planesNorm[id1].data(), refPlaneNorm, rotAxis);
+                       //double angle1 = atan2(det, dot);
+                       double angle1 = vtkMath::SignedAngleBetweenVectors(planesNorm[id1].data(), refPlaneNorm, rotAxis);
+                       if(angle1 < 0) angle1 += 2*vtkMath::Pi();
+                       double angle2 = vtkMath::SignedAngleBetweenVectors(planesNorm[id2].data(), refPlaneNorm, rotAxis);
+                       if(angle2 < 0) angle2 += 2*vtkMath::Pi();
+                       return angle1 < angle2;
+       };
+               
+               std::vector<int> indexVect((int)newGroups.size());
+               std::iota(std::begin(indexVect), std::end(indexVect), 0);
+               std::sort(indexVect.begin(), indexVect.end(), comp);
+               
+               wsp->ResetCollections_();
+               for(int i = 0; i < newGroups.size(); i++){
+                       std::vector<std::vector<double>> group = newGroups[indexVect[i]];
+                       for(int j = 0; j < group.size(); j++){
+                               std::vector<double> point = group[j];
+                               wsp->AddPoint(point[0] ,point[1], point[2],"");
+                       }
+                       if(i < newGroups.size()-1){
+                               wsp->InsertCollectionAfter_();
+                       }
+               }
+               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)
 //===== 
@@ -978,6 +1084,10 @@ void ShowNPoints_Tools::Process()
         {
                ExpandPatch();
         } // if Type
+        if(bbGetInputType()==400)
+        {
+               SeparateSplines();
+        } // if Type
     } // if bbGetInputWidgetShowNPoints
 }
 //===== 
index 932cc8ed90a5e568bf3c5bb93d9121f1526057f1..3b85d44c471f42298893490f2e533111603eee2d 100644 (file)
@@ -7,6 +7,7 @@
 #include "bbcreaMaracasVisu_EXPORT.h"
 #include "bbtkAtomicBlackBox.h"
 #include "iostream"
+#include <numeric>
 
 #include "WidgetShowNPoints.h"
 
@@ -51,6 +52,7 @@ class bbcreaMaracasVisu_EXPORT ShowNPoints_Tools
     void MovePointInNormal();
     void JoinPoints();
     void SetMesh();
+    void SeparateSplines();
 
 //===== 
 // 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)
@@ -65,8 +67,8 @@ BBTK_CATEGORY("empty");
   BBTK_INPUT(ShowNPoints_Tools,WidgetShowNPoints,"WidgetShowNPoints",WidgetShowNPoints*,"");
   BBTK_INPUT(ShowNPoints_Tools,Spacing,"(default [1,1,1] )Spacing",std::vector<double>,"");
   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  200:Tool 3 or 4 points to patch surface - Create Mesh (based on 1 group and 3 or 4 points)   205:Tool 3 or 4 points to volume surface - Create Mesh (based on 1 group and 3 or 4 points)   210: Invert points   220: Move patch center (param is the step ex [-1] or [1])      230: Move point in normal of surface (Params [-1] or [1])       235: ChangeCurrentPoint (Params [-1] or [1])  240: Join all start-end points to the start-end points on selected spline  250: Set Mesh SPC (Params: [0]:Patch [1]:CloseSpline1 [2]:CloseSpline2)   300: Create expanded surface   310: Create wide expanded surface     320: Expand Surface,   330: Widen surface,   340: Expand patch",int,"");
-  BBTK_INPUT(ShowNPoints_Tools, Params,"Optional params for the tools, required for 200: normal and direction, 320: centroid and direction, 330: normal and direction, 340: centroid and direction", std::vector<double>,"");
+  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  200:Tool 3 or 4 points to patch surface - Create Mesh (based on 1 group and 3 or 4 points)   205:Tool 3 or 4 points to volume surface - Create Mesh (based on 1 group and 3 or 4 points)   210: Invert points   220: Move patch center (param is the step ex [-1] or [1])      230: Move point in normal of surface (Params [-1] or [1])       235: ChangeCurrentPoint (Params [-1] or [1])  240: Join all start-end points to the start-end points on selected spline  250: Set Mesh SPC (Params: [0]:Patch [1]:CloseSpline1 [2]:CloseSpline2)   300: Create expanded surface   310: Create wide expanded surface     320: Expand Surface,   330: Widen surface,   340: Expand patch,   400: Separate and Order Splines given a rotation origin",int,"");
+  BBTK_INPUT(ShowNPoints_Tools, Params,"Optional params for the tools, required for 200: normal and direction, 320: centroid and direction, 330: normal and direction, 340: centroid and direction,    400: reference point", std::vector<double>,"");
   
   BBTK_OUTPUT(ShowNPoints_Tools, Out, "Output", std::vector<double>, "");
 //  BBTK_OUTPUT(ShowNPoints_Tools,Out,"First output",double,"");