]> Creatis software - creaVtk.git/commitdiff
#3502 Bug close surface in CreateMeshFromPoints
authorPablo Garzon <garzon@ei-pfe-706.creatis.insa-lyon.fr>
Tue, 4 Apr 2023 14:10:10 +0000 (16:10 +0200)
committerPablo Garzon <garzon@ei-pfe-706.creatis.insa-lyon.fr>
Tue, 4 Apr 2023 14:10:10 +0000 (16:10 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h

index bfe74d4182d5d7abb6b93a90010012312ab2de9c..194c3780f0940395ea86a8af42385f6282240920 100644 (file)
@@ -91,14 +91,28 @@ void CreateMeshFromPoints::Process()
                        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 closedLineOrd = !altFace1open && !altFace2open;
+                       
+                       //isClosedCont = !face1open && !face2open;
+                       isClosedCont = false;
                        if(bbGetInputCloseSurface())
                        {                       
                                //false = Open Contour
                                //true = Closed Contour
                                if(!face1open && !face2open)
-                               {               
+                               {
+                                       isClosedCont = true;
                                        CloseContourSides(lstIndexs, true);
-                               }else{
+                               }
+                               else if(!altFace1open && !altFace2open)
+                               {
+                                       isClosedCont = true;
+                                       CloseContourSides(lstIndexs, false);
+                               }
+                               else{
                                        CloseOpenContourSurface(lstIndexs);
                                }
                        }
@@ -160,20 +174,20 @@ 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+1);
+                               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);
-                                               if(index+increment >= end){
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+1,initial);//2
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+2,centroidId);//3
-                                               }
-                                               else{                                           
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);//1
+                                               triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);//1
+                                               if(index+increment >= end && !isClosedCont){
+                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+2,initial);//2
+                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+3,centroidId);//3
                                                }
+                                               //else{
+                                               //}
                                                triangleIndex+=2;
                                        }
                                        cells->InsertNextCell(triangleStrip1);
@@ -183,12 +197,13 @@ void CreateMeshFromPoints::CloseContourSides(std::vector<int> lstIndexs, bool uP
                                        int triangleStripStart = end-1;
                                        for(int index = triangleStripStart; index > initial; index-=increment){
                                                triangleStrip1->GetPointIds()->SetId(triangleIndex,index);
-                                               if(index-increment <= initial){
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+1,triangleStripStart);
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+2,centroidId);
-                                               }else{                                          
-                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);
+                                               triangleStrip1->GetPointIds()->SetId(triangleIndex+1,centroidId);
+                                               if(index-increment <= initial && !isClosedCont){
+                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+2,triangleStripStart);
+                                                       triangleStrip1->GetPointIds()->SetId(triangleIndex+3,centroidId);
                                                }
+                                               //else{
+                                               //}
                                                triangleIndex+=2;
                                        }
                                        cells->InsertNextCell(triangleStrip1);
@@ -252,8 +267,7 @@ bool CreateMeshFromPoints::CheckLinePointOrder(){
                        secondRadiusSum += vtkMath::Solve3PointCircle(point1, point2, point3, center);
                }
        }
-       //cout << firstRadiusSum << endl;
-       //cout << secondRadiusSum << endl;
+
        return firstRadiusSum > secondRadiusSum;
 }
 
@@ -346,6 +360,7 @@ void CreateMeshFromPoints::bbUserSetDefaultValues()
 //    Here we initialize the input 'In' to 0
 //   bbSetInputIn(0);
        bbSetInputCloseSurface(false);
+       isClosedCont = NULL;
        points          = NULL;
        cells           = NULL;
        polydata        = NULL;
index 5d5ed25508c813bfbd71533b219cfec2237b781c..2dd7615f35a30327205f191ce79ab4d0e1e4ba6c 100644 (file)
@@ -40,6 +40,7 @@ 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();