From 2b221681ec9be0b3ee8a57d78010a52b71f7d7a5 Mon Sep 17 00:00:00 2001 From: enk Date: Mon, 22 Jan 2007 11:16:20 +0000 Subject: [PATCH] Fix for Bug IPAL14023: Incorrect presentation of a polyhedral mesh volume --- src/VTKViewer/VTKViewer_ConvexTool.cxx | 160 ++++++++++++++++++++----- 1 file changed, 132 insertions(+), 28 deletions(-) diff --git a/src/VTKViewer/VTKViewer_ConvexTool.cxx b/src/VTKViewer/VTKViewer_ConvexTool.cxx index b89fd4d99..0754b777f 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.cxx +++ b/src/VTKViewer/VTKViewer_ConvexTool.cxx @@ -44,6 +44,12 @@ #include #include +#ifdef _DEBUG_ +static int DEBUG_TRIA_EXECUTE = 0; +#else +static int DEBUG_TRIA_EXECUTE = 0; +#endif + namespace { typedef std::vector TConnectivities; @@ -118,7 +124,7 @@ VTKViewer_Triangulator vtkPoints *aPoints = InitPoints(); vtkIdType aNumPts = GetNbOfPoints(); - //cout<<"Triangulator - aNumPts = "<GetPoint(GetPointId(aPntId),aPntCoord); - //cout<<"\taPntId = "< TPointIds; @@ -197,8 +203,10 @@ VTKViewer_Triangulator // To get know, if the points of the trinagle were already observed bool anIsObserved = aFace2PointIds.find(aPointIds) == aFace2PointIds.end(); - //cout<<"\taFaceId = "<GetPoint(aPntId,aPntCoord); + + vtkFloatingPointType aVector0Pnt[3] = { aPntCoord[0] - aCoord[0][0], + aPntCoord[1] - aCoord[0][1], + aPntCoord[2] - aCoord[0][2] }; + + + vtkMath::Normalize(aVector0Pnt); + + vtkFloatingPointType aNormalPnt[3]; + // calculate aNormalPnt + { + vtkFloatingPointType aCosPnt01 = vtkMath::Dot(aVector0Pnt,aVector01); + vtkFloatingPointType aCosPnt02 = vtkMath::Dot(aVector0Pnt,aVector02); + if(aCosPnt01<-1) + aCosPnt01 = -1; + if(aCosPnt01>1) + aCosPnt01 = 1; + if(aCosPnt02<-1) + aCosPnt02 = -1; + if(aCosPnt02>1) + aCosPnt02 = 1; + + vtkFloatingPointType aDist01,aDist02;// deflection from Pi/3 angle (equilateral triangle) + vtkFloatingPointType aAngPnt01 = fabs(acos(aCosPnt01)); + vtkFloatingPointType aAngPnt02 = fabs(acos(aCosPnt02)); + + aDist01 = fabs(aAngPnt01-(vtkMath::Pi())/3.0); + aDist02 = fabs(aAngPnt02-(vtkMath::Pi())/3.0); + + // if((aAngPnt01 > aEps) && (aAngPnt01 < vtkMath::Pi()-aEps)) + if(aDist01 <= aDist02) + vtkMath::Cross(aVector0Pnt,aVector01,aNormalPnt); + else + vtkMath::Cross(aVector0Pnt,aVector02,aNormalPnt); + + } + + vtkMath::Normalize(aNormalPnt); + + vtkFloatingPointType aCos = vtkMath::Dot(aNormalPnt,aNormal); + if(aCos<-1) + aCos = -1; + if(aCos>1) + aCos = 1; + + vtkFloatingPointType aSignAng = acos(aCos); + vtkFloatingPointType aAng = fabs(aSignAng); + + if(DEBUG_TRIA_EXECUTE) + cout<<"\t\taPntId = "< 0){ aNormal[0] = -aNormal[0]; aNormal[1] = -aNormal[1]; @@ -269,8 +341,10 @@ VTKViewer_Triangulator aCoord[0][2] - aCenter[2] }; vtkMath::Normalize(aVector0); - //cout<<"\t\taCenter = {"< 1.0) + vtkFloatingPointType anAngle = 0.0; + if(aCosinus >= 1.0){ aCosinus = 1.0; - if(aCosinus < -1.0) + } else if (aCosinus <= -1.0){ aCosinus = -1.0; - static vtkFloatingPointType a2Pi = 2.0 * vtkMath::Pi(); - vtkFloatingPointType anAngle = acos(aCosinus); - //cout<<"\t\t\taPntId = "<second; aConnectivities[anId] = GetConnectivity(aPntId); + if(DEBUG_TRIA_EXECUTE) cout << aPntId << ","; } + if(DEBUG_TRIA_EXECUTE) cout << endl; aPolygons.push_back(::TPolygon(aConnectivities,aCenter,aNormal)); } } } } - if(aPolygons.empty()) return true; @@ -360,15 +455,17 @@ VTKViewer_Triangulator ::TPolygon& aPolygon = aPolygons[aPolygonId]; vtkFloatingPointType* aNormal = aPolygon.myNormal; vtkFloatingPointType* anOrigin = aPolygon.myOrigin; - //cout<<"\taPolygonId = "<GetPoint(anId,aPntCoord); vtkFloatingPointType aDist = vtkPlane::Evaluate(aNormal,anOrigin,aPntCoord); - //cout<<"\t\taPntId = "<InsertNextCell(VTK_POLYGON,aNbPoints,&aConnectivities[0]); if(theStoreMapping) @@ -390,7 +493,8 @@ VTKViewer_Triangulator } } - //cout<<"\tTriangulator - Ok\n"; + if(DEBUG_TRIA_EXECUTE) cout<<"\tTriangulator - Ok\n"; + return true; } -- 2.39.2