From: Pablo Garzon Date: Mon, 24 Jul 2023 10:41:34 +0000 (+0200) Subject: #3528 Contour ordering around axis X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=77998421b003659ad81e05fed83e66a8041ab7e8;p=creaMaracasVisu.git #3528 Contour ordering around axis --- diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbg b/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbg index c8ab33b..7079b3a 100644 --- a/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbg +++ b/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbg @@ -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 diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbs b/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbs index 1d13c17..da33e19 100644 --- a/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbs +++ b/bbtk/bbs/boxes/Mesh_tool_ApplyDeformation.bbs @@ -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 " " diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg b/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbg index 335e4b2..fa4c0a6 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 @@ -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 diff --git a/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs b/bbtk/bbs/boxes/Mesh_tool_ApplySurface.bbs index a6b1664..4f95771 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 @@ -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" diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx index 0d76ac3..fa719af 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx @@ -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 refPoint = bbGetInputParams(); + std::vector pointsX, pointsY, pointsZ; + std::vector>> newGroups; + std::vector> 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> pointsOver, pointsUnder, pointsOn; + std::vector 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 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 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> group = newGroups[indexVect[i]]; + for(int j = 0; j < group.size(); j++){ + std::vector 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 } //===== diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h index 932cc8e..3b85d44 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h @@ -7,6 +7,7 @@ #include "bbcreaMaracasVisu_EXPORT.h" #include "bbtkAtomicBlackBox.h" #include "iostream" +#include #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,""); 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,""); + 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,""); BBTK_OUTPUT(ShowNPoints_Tools, Out, "Output", std::vector, ""); // BBTK_OUTPUT(ShowNPoints_Tools,Out,"First output",double,"");