]> Creatis software - creaVtk.git/commitdiff
#3502 Bug close surface in CreateMeshFromPoints
authorPablo Garzon <gapablo2001@gmail.com>
Tue, 18 Apr 2023 11:42:22 +0000 (13:42 +0200)
committerPablo Garzon <gapablo2001@gmail.com>
Tue, 18 Apr 2023 11:42:22 +0000 (13:42 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h

index c794d404e66043e165af0fd6449a069061ad4448..79b999135824b68eafc2a10a76d7e737a2ccad67 100644 (file)
@@ -5,6 +5,7 @@
 #include "bbcreaVtkPackage.h"
 
 #include "vtkTriangleStrip.h"
+#include "vtkTriangle.h"
 #include <vtkMath.h>
 
 namespace bbcreaVtk
@@ -86,28 +87,27 @@ void CreateMeshFromPoints::Process()
                        } //for  LstIndexs
 
                        if(bbGetInputCloseSurface())
-                       {                       
+                       {
                                int lastId1 = lstIndexs[0]-1;
                                int lastId2 = sizeLstX - 1;
                                int firstId2 = sizeLstX - lstIndexs[sizeLstIdexes - 1];
-                               bool face1open = lstX[0] != lstX[lastId1] && lstY[0] != lstY[lastId1] && lstZ[0] != lstZ[lastId1];
-                               bool face2open = lstX[firstId2] != lstX[lastId2] && lstY[firstId2] != lstY[lastId2] && lstZ[firstId2] != lstZ[lastId2];
-                               
-                               bool altFace1open = lstX[0] != lstX[firstId2] && lstY[0] != lstY[firstId2] && lstZ[0] != lstZ[firstId2];
-                               bool altFace2open = lstX[lastId1] != lstX[lastId2] && lstY[lastId1] != lstY[lastId2] && lstZ[lastId1] != lstZ[lastId2];
+                               bool face1open = std::fabs(lstX[0] - lstX[lastId1]) > 0.0001 && std::fabs(lstY[0] - lstY[lastId1]) > 0.0001 && std::fabs(lstZ[0] - lstZ[lastId1]) > 0.0001;
+                               bool face2open = std::fabs(lstX[firstId2] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[firstId2] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[firstId2] - lstZ[lastId2]) > 0.0001;
                                
-                               isClosedCont = false;
+                               bool altFace1open = std::fabs(lstX[0] - lstX[firstId2]) > 0.0001 && std::fabs(lstY[0] - lstY[firstId2]) > 0.0001 && std::fabs(lstZ[0] - lstZ[firstId2]) > 0.0001;
+                               bool altFace2open = std::fabs(lstX[lastId1] - lstX[lastId2]) > 0.0001 && std::fabs(lstY[lastId1] - lstY[lastId2]) > 0.0001 && std::fabs(lstZ[lastId1] - lstZ[lastId2]) > 0.0001;
+
                                //false = Open Contour
                                //true = Closed Contour
                                if(!face1open && !face2open)
                                {
-                                       isClosedCont = true;
-                                       CloseContourSides(lstIndexs, true);
+//                                     isClosedCont = true;
+                                       CloseContourSides(lstIndexs, true, true);
                                }
                                else if(!altFace1open && !altFace2open)
                                {
-                                       isClosedCont = true;
-                                       CloseContourSides(lstIndexs, false);
+//                                     isClosedCont = true;
+                                       CloseContourSides(lstIndexs, false, true);
                                }
                                else{
                                        CloseOpenContourSurface(lstIndexs);
@@ -140,7 +140,7 @@ void CreateMeshFromPoints::Process()
 * uPointOrder: Points are order in a U shape
 * lstIndexs: number of points on each spline
 */
-void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder){
+void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder, bool isClosedCont){
        int     sizeLstIdexes = lstIndexs.size();
        int sizePoints = bbGetInputLstX().size();
 
@@ -169,36 +169,42 @@ void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uP
                        {
                                bool normalOrder    = isPointingCorrectly(firstIndex, firstIndex+increment, centroid, contraryId);
                                centroidId          = points->InsertNextPoint(centroid[0], centroid[1], centroid[2]);
-                               vtkSmartPointer<vtkTriangleStrip> triangleStrip1 = vtkSmartPointer<vtkTriangleStrip>::New();
-                               triangleStrip1->GetPointIds()->SetNumberOfIds(numPointsFace*2 + (!isClosedCont?2:0));
                                if( normalOrder )
                 {
-                                       int initial = firstIndex;
-                                       int triangleIndex = 0;
-                                       for(int index = initial; index < end; index+=increment){
-                                               triangleStrip1->GetPointIds()->SetId(triangleIndex,index);
-                                               triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);//1
+                       int initial = firstIndex;
+                       for(int index = initial; index < end; index+=increment){
                                                if(index+increment >= end && !isClosedCont){
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+2,initial);//2
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+3,centroidId);//3
+                                                       vtkNew<vtkTriangle> triangle;
+                                                       triangle->GetPointIds()->SetId(0, index);
+                                                       triangle->GetPointIds()->SetId(1, initial);
+                                                       triangle->GetPointIds()->SetId(2, centroidId);
+                                                       cells->InsertNextCell(triangle);
+                                               }else if(index+increment < end){
+                                                       vtkNew<vtkTriangle> triangle;
+                                                       triangle->GetPointIds()->SetId(0, index);
+                                                       triangle->GetPointIds()->SetId(1, index+increment);
+                                                       triangle->GetPointIds()->SetId(2, centroidId);
+                                                       cells->InsertNextCell(triangle);
                                                }
-                                               triangleIndex+=2;
                                        }
-                                       cells->InsertNextCell(triangleStrip1);
                                } else {
                                        int initial = firstIndex-1;
-                                       int triangleIndex = 0;
                                        int triangleStripStart = end-1;
                                        for(int index = triangleStripStart; index > initial; index-=increment){
-                                               triangleStrip1->GetPointIds()->SetId(triangleIndex,index);
-                                               triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);
                                                if(index-increment <= initial && !isClosedCont){
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+2,triangleStripStart);
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+3,centroidId);
+                                                       vtkNew<vtkTriangle> triangle;
+                                                       triangle->GetPointIds()->SetId(0, index);
+                                                       triangle->GetPointIds()->SetId(1, triangleStripStart);
+                                                       triangle->GetPointIds()->SetId(2, centroidId);
+                                                       cells->InsertNextCell(triangle);
+                                               }else if(index-increment > initial){
+                                                       vtkNew<vtkTriangle> triangle;
+                                                       triangle->GetPointIds()->SetId(0, index);
+                                                       triangle->GetPointIds()->SetId(1, index-increment);
+                                                       triangle->GetPointIds()->SetId(2, centroidId);
+                                                       cells->InsertNextCell(triangle);
                                                }
-                                               triangleIndex+=2;
                                        }
-                                       cells->InsertNextCell(triangleStrip1);
                                }
                        }//if validCentroid
                }//if numPointsFace
@@ -269,7 +275,7 @@ bool CreateMeshFromPoints::CheckLinePointOrder(){
 */
 void CreateMeshFromPoints::CloseOpenContourSurface(std::vector<int> lstIndexs){
        bool linePointOrder = CheckLinePointOrder();
-       CloseContourSides(lstIndexs, !linePointOrder);
+       CloseContourSides(lstIndexs, !linePointOrder, false);
        CloseContourBottom(!linePointOrder);
 }
 
@@ -352,7 +358,6 @@ void CreateMeshFromPoints::bbUserSetDefaultValues()
 //    Here we initialize the input 'In' to 0
 //   bbSetInputIn(0);
        bbSetInputCloseSurface(false);
-       isClosedCont = NULL;
        points          = NULL;
        cells           = NULL;
        polydata        = NULL;
index 2dd7615f35a30327205f191ce79ab4d0e1e4ba6c..f92f3428c5a8affa6d31268d41d79025bb7e9c98 100644 (file)
@@ -40,13 +40,12 @@ class bbcreaVtk_EXPORT CreateMeshFromPoints
        vtkPolyData             *polydata;
        vtkCleanPolyData        *clean;
        vtkTriangleFilter       *triangle;
-       bool                            isClosedCont;
        
        bool CalcValidCentroid(double(&centroid)[3], int start, int end, int increment, int numPoints);
        bool CheckLinePointOrder();
        bool isPointingCorrectly( int firstPointId, int secPointId, double(&centroid)[3], int contrPointId);
        void CloseContourBottom(bool uPointOrder);
-       void CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder);
+       void CloseContourSides(std::vector<int> lstIndexs, bool uPointOrder, bool isClosedCont);
        void CloseOpenContourSurface(std::vector<int> lstIndexs);
 
 //=====