From: Pablo Garzon Date: Tue, 4 Apr 2023 14:10:10 +0000 (+0200) Subject: #3502 Bug close surface in CreateMeshFromPoints X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=474a0f3cd44a108f172a412545fbd7b2d716ed8f;p=creaVtk.git #3502 Bug close surface in CreateMeshFromPoints --- diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx index bfe74d4..194c378 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx @@ -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 lstIndexs, bool uP bool normalOrder = isPointingCorrectly(firstIndex, firstIndex+increment, centroid, contraryId); centroidId = points->InsertNextPoint(centroid[0], centroid[1], centroid[2]); vtkSmartPointer triangleStrip1 = vtkSmartPointer::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 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; diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h index 5d5ed25..2dd7615 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h @@ -40,6 +40,7 @@ class bbcreaVtk_EXPORT CreateMeshFromPoints vtkPolyData *polydata; vtkCleanPolyData *clean; vtkTriangleFilter *triangle; + bool isClosedCont; bool CalcValidCentroid(double(¢roid)[3], int start, int end, int increment, int numPoints); bool CheckLinePointOrder();