/*************************************************************************** * Copyright (c) 2007 * * Joachim Zettler * * Human Rezai * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #include "SpringbackCorrection.h" #include "best_fit.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include ///*********BINDINGS********/ #include #include using namespace boost::numeric::bindings; using namespace boost::numeric; SpringbackCorrection::SpringbackCorrection() { } SpringbackCorrection::SpringbackCorrection(const TopoDS_Shape& aShape, const MeshCore::MeshKernel& aMesh) :m_Shape(aShape),m_Mesh(aMesh) { m_EdgeStruct.clear(); EdgeMap.clear(); MeshMap.clear(); //Remove any existing Triangulation on the Shape BRepTools::Clean(m_Shape); best_fit::Tesselate_Shape(m_Shape,m_CadMesh,(float) 0.1); // Basistriangulierung des ganzen Shapes MeshCore::MeshTopoAlgorithm algo(m_CadMesh); algo.HarmonizeNormals(); // flip all normals so that they are oriented in positive z-direction MeshCore::MeshGeomFacet facet = m_CadMesh.GetFacet(0); if (facet.GetNormal().z < 0.0) algo.FlipNormals(); int n = m_CadMesh.CountFacets(); Base::Vector3f normal; MeshCore::MeshPointArray points = m_CadMesh.GetPoints(); MeshCore::MeshFacetArray facets = m_CadMesh.GetFacets(); for (int i=0; i inp; std::vector MeanVec; std::vector FacePntVector; TopLoc_Location aloc; Base::Vector3f mP; gp_Pnt e_pnt, m_pnt; double dist, distSum, revSum;; int n; std::map, Edge_Less>::iterator edge_it; std::map::iterator meshIt; std::vector::iterator pIt; m_CurvPos.resize(m_CadMesh.CountPoints()); m_CurvNeg.resize(m_CadMesh.CountPoints()); m_MeshStruct.resize(m_CadMesh.CountPoints()); MeanVec.resize(m_CadMesh.CountPoints(), 0); // Fülle Map mit Punkten (Key) und deren, zur Basistriangulierung korrespondierenden, Indizes MeshPnts = m_CadMesh.GetPoints(); MeshPntsCop = MeshPnts; MeshFacets2 = m_CadMesh.GetFacets(); for (unsigned int i=0; i m_MeshStruct Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation); const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); // create array of node points in absolute coordinate system TColgp_Array1OfPnt aPoints(1, aNodes.Length()); for ( Standard_Integer i = 1; i <= aNodes.Length(); i++) aPoints(i) = aNodes(i).Transformed(aLocation); const TColgp_Array1OfPnt2d& aUVNodes = aTr->UVNodes(); BRepAdaptor_Surface aSurface(aFace); Base::Vector3f Pnt1, Pnt2; gp_Pnt2d par; gp_Pnt P; gp_Vec D1U, D1V; for (int i=1; i_ulProp == 0) { m_pnt.SetCoord(pIt->x, pIt->y, pIt->z); VertexBuild.MakeVertex(V,m_pnt,0.001); pnt2edge.LoadS2(V); pnt2edge.Perform(); if (pnt2edge.IsDone() == false) { throw Base::Exception("couldn't perform distance calculation pnt2edge \n"); } dist = pnt2edge.Value(); FacePntVector[counter].pnt = *pIt; FacePntVector[counter].distances.push_back(dist); FacePntVector[counter].MinEdgeOff.push_back((*edge_it).second[0]); FacePntVector[counter].MaxEdgeOff.push_back((*edge_it).second[1]); ++counter; } } // Knoten auf der EDGE die EdgeOffset-Werte zuweisen // Edge -> Polygon -> Nodes Handle(Poly_PolygonOnTriangulation) polyg; Handle_Poly_Triangulation aTrLoc; BRep_Tool::PolygonOnTriangulation(aEdge,polyg,aTrLoc,aloc); TColStd_Array1OfInteger IndArr(1,polyg->NbNodes()); IndArr = polyg->Nodes(); const TColgp_Array1OfPnt& Nodes = aTrLoc->Nodes(); TColgp_Array1OfPnt TrLocPnts(1, Nodes.Length()); for ( Standard_Integer i = 1; i <= Nodes.Length(); i++) TrLocPnts(i) = Nodes(i).Transformed(aloc); for (int k=0; kNodes().Upper(); ++k) { e_pnt = TrLocPnts(IndArr.Value(k+1)); mP.x = (float) e_pnt.X(); mP.y = (float) e_pnt.Y(); mP.z = (float) e_pnt.Z(); meshIt = MeshMap.find(mP); if (meshIt == MeshMap.end()) { cout << "error2" << endl; return false; } ++MeanVec[meshIt->second.index]; // nehme stets den minimalen wert if (((*edge_it).second[0])>((*meshIt).second).minCurv) ((*meshIt).second).minCurv = (*edge_it).second[0]; if ((*edge_it).second[1]<((*meshIt).second).maxCurv) ((*meshIt).second).maxCurv = (*edge_it).second[1]; } } // Knoten INNERHALB eines Faces die Offset-Werte zuweisen for (unsigned int k=0; ksecond.index; m_MeshStruct[w].pnt = (*meshIt).first; m_MeshStruct[w].minCurv = (((*meshIt).second).minCurv); m_MeshStruct[w].maxCurv = (((*meshIt).second).maxCurv); // Ausgabe if (m_MeshStruct[w].maxCurv<10000000000) { snprintf(text,10,"%f",m_MeshStruct[w].minCurv); //snprintf(text,10,"%i",w); log.addText(m_MeshStruct[w].pnt.x, m_MeshStruct[w].pnt.y, m_MeshStruct[w].pnt.z,text); } if (MeanVec[w] == 1) log3d.addSinglePoint(m_MeshStruct[w].pnt,4,0,0,0); // innere punkte - > schwarz else if (MeanVec[w] == 2) log3d.addSinglePoint(m_MeshStruct[w].pnt,4,1,1,1); // edge-punkte - > weiß else log3d.addSinglePoint(m_MeshStruct[w].pnt,4,1,0,0); // eck-punkte - > rot //m_MeshStruct[w].minCurv = (((*meshIt).second).minCurv)/MeanVec[w]; //m_MeshStruct[w].maxCurv = (((*meshIt).second).maxCurv)/MeanVec[w]; //if(m_MeshStruct[w].maxCurv < 100 || fabs(m_MeshStruct[w].minCurv) < 100) //{ // if(m_MeshStruct[w].maxCurv > fabs(m_MeshStruct[w].minCurv)) // { // snprintf(text,10,"%f",m_MeshStruct[w].minCurv); // //m_MeshStruct[w].normal.Scale(m_MeshStruct[w].minCurv,m_MeshStruct[w].minCurv,m_MeshStruct[w].minCurv); // logo.addSingleArrow(m_MeshStruct[w].pnt, m_MeshStruct[w].pnt+m_MeshStruct[w].normal); // } // else // { // //snprintf(text,4,"%f",m_MeshStruct[w].maxCurv); // m_MeshStruct[w].normal.Scale(m_MeshStruct[w].maxCurv,m_MeshStruct[w].maxCurv,m_MeshStruct[w].maxCurv); // logo.addSingleArrow(m_MeshStruct[w].pnt, m_MeshStruct[w].pnt+m_MeshStruct[w].normal); // } //} //if(m_MeshStruct[w].maxCurv < 100) //{ // m_MeshStruct[w].normal.Scale(0.5*m_MeshStruct[w].maxCurv,0.5*m_MeshStruct[w].maxCurv,0.5*m_MeshStruct[w].maxCurv); // logo.addSingleArrow(m_MeshStruct[w].pnt, m_MeshStruct[w].pnt+m_MeshStruct[w].normal); //}*/ //snprintf(text,10,"%f",m_MeshStruct[w].maxCurv); //snprintf(text,10,"%i",w); /*if(m_MeshStruct[w].maxCurv > fabs(m_MeshStruct[w].minCurv)) { snprintf(text,10,"%f",m_MeshStruct[w].minCurv); } else { snprintf(text,10,"%f",m_MeshStruct[w].maxCurv); }*/ } log.saveToFile("c:/printCurv.iv"); log3d.saveToFile("c:/triPnts.iv"); logo.saveToFile("c:/NormalsCurv.iv"); MeshPntsCad = m_CadMesh.GetPoints(); for (unsigned int j=0; j m_MeshStruct Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation); const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); // create array of node points in absolute coordinate system TColgp_Array1OfPnt aPoints(1, aNodes.Length()); for ( Standard_Integer i = 1; i <= aNodes.Length(); i++) aPoints(i) = aNodes(i).Transformed(aLocation); const TColgp_Array1OfPnt2d& aUVNodes = aTr->UVNodes(); BRepAdaptor_Surface aSurface(aFace); Base::Vector3f Pnt1, Pnt2; gp_Pnt2d par; gp_Pnt P; gp_Vec D1U, D1V; std::vector trans_check(m_MeshStruct.size(), false); for (int i=1; i EdgeVec; MeshCore::MeshKernel FaceMesh; std::vector curvature(2); std::pair > aPair; float maxOffset, minOffset; for (anExplorer.Init(m_Shape,TopAbs_EDGE);anExplorer.More();anExplorer.Next()) { tempEdgeStruct.aFace.clear(); tempEdgeStruct.MaxOffset = 1e+10; tempEdgeStruct.MinOffset = -1e+10; tempEdgeStruct.anEdge = TopoDS::Edge(anExplorer.Current()); // store current edge const TopTools_ListOfShape& aFaceList = anIndex.FindFromKey(tempEdgeStruct.anEdge); TopTools_ListIteratorOfListOfShape aListIterator; for (aListIterator.Initialize(aFaceList);aListIterator.More(); aListIterator.Next()) { // store corresponding faces aFace = TopoDS::Face(aListIterator.Value()); tempEdgeStruct.aFace.push_back(aFace); TransferFaceTriangulationtoFreeCAD(aFace, FaceMesh); curvature = MeshCurvature(aFace, FaceMesh); if (aFace.Orientation() == TopAbs_REVERSED) { maxOffset = (float) -curvature[1]; minOffset = (float) -curvature[0]; } else { maxOffset = (float) curvature[0]; minOffset = (float) curvature[1]; } if (maxOffset < tempEdgeStruct.MaxOffset) tempEdgeStruct.MaxOffset = maxOffset; if (minOffset > tempEdgeStruct.MinOffset) tempEdgeStruct.MinOffset = minOffset; } if (tempEdgeStruct.MaxOffset > max) curvature[1] = tempEdgeStruct.MaxOffset; else curvature[1] = cMin; if (-tempEdgeStruct.MinOffset > max) curvature[0] = tempEdgeStruct.MinOffset; else curvature[0] = -cMin; aPair.first = tempEdgeStruct.anEdge; aPair.second = curvature; EdgeMap.insert(aPair); } return true; } bool SpringbackCorrection::Init_Setting(struct CuttingToolsSettings& set) { m_set = set; return true; } bool SpringbackCorrection::SetFixEdges() { TopExp_Explorer anExplorer; TopoDS_Edge anEdge; std::map, Edge_Less>::iterator edge_it; std::vector pair(2,0.0); for (unsigned int i=0; isecond = pair; } } return true; } bool SpringbackCorrection::TransferFaceTriangulationtoFreeCAD(const TopoDS_Face& aFace, MeshCore::MeshKernel& FaceMesh) { FaceMesh.Clear(); MeshCore::MeshBuilder builder(FaceMesh); builder.Initialize(1000); Base::Vector3f Points[3]; TopLoc_Location aLocation; // takes the triangulation of the face aFace: Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation); if (!aTr.IsNull()) // if this triangulation is not NULL { // takes the array of nodes for this triangulation: const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); // takes the array of triangles for this triangulation: const Poly_Array1OfTriangle& triangles = aTr->Triangles(); // create array of node points in absolute coordinate system TColgp_Array1OfPnt aPoints(1, aNodes.Length()); for ( Standard_Integer i = 1; i <= aNodes.Length(); i++) aPoints(i) = aNodes(i).Transformed(aLocation); // Takes the node points of each triangle of this triangulation. // takes a number of triangles: Standard_Integer nnn = aTr->NbTriangles(); Standard_Integer nt,n1,n2,n3; for ( nt = 1 ; nt < nnn+1 ; nt++) { // takes the node indices of each triangle in n1,n2,n3: triangles(nt).Get(n1,n2,n3); // takes the node points: gp_Pnt aPnt1 = aPoints(n1); Points[0].Set(float(aPnt1.X()),float(aPnt1.Y()),float(aPnt1.Z())); gp_Pnt aPnt2 = aPoints(n2); Points[1].Set((float) aPnt2.X(),(float) aPnt2.Y(),(float) aPnt2.Z()); gp_Pnt aPnt3 = aPoints(n3); Points[2].Set((float) aPnt3.X(),(float) aPnt3.Y(),(float) aPnt3.Z()); // give the occ faces to the internal mesh structure of freecad MeshCore::MeshGeomFacet Face(Points[0],Points[1],Points[2]); builder.AddFacet(Face); } } // if the triangulation of only one face is not possible to get else { throw Base::Exception("Empty face triangulation\n"); } // finish FreeCAD Mesh Builder and exit with new mesh builder.Finish(); return true; } /* MeshCore::MeshKernel SpringbackCorrection::BuildMesh(Handle_Poly_Triangulation aTri, std::vector TrPoints) { MeshCore::MeshKernel FaceMesh; MeshCore::MeshBuilder builder(FaceMesh); builder.Initialize(1000); Base::Vector3f Points[3]; const Poly_Array1OfTriangle& triangles = aTri->Triangles(); Standard_Integer nnn = aTri->NbTriangles(); Standard_Integer nt,n1,n2,n3; for ( nt = 1 ; nt < nnn+1 ; nt++) { // takes the node indices of each triangle in n1,n2,n3: triangles(nt).Get(n1,n2,n3); // takes the node points: Points[0] = TrPoints[n1]; Points[1] = TrPoints[n2]; Points[2] = TrPoints[n3]; // give the occ faces to the internal mesh structure of freecad MeshCore::MeshGeomFacet Face(Points[0],Points[1],Points[2]); builder.AddFacet(Face); } // finish FreeCAD Mesh Builder and exit with new mesh builder.Finish(); return FaceMesh; } */ int SpringbackCorrection::GetBoundary(const MeshCore::MeshKernel &mesh, MeshCore::MeshPointArray &meshPnts) { // get mesh-boundary // zweck: nur für die inneren punkte wird der curvature wert über die edge abstände berechnet std::list< std::vector > BoundariesIndex; std::list< std::vector >::iterator bInd; MeshCore::MeshAlgorithm algo(mesh); algo.GetMeshBorders(BoundariesIndex); //Set all MeshPoints to Property 0 for (unsigned int i=0;isize();++i) { meshPnts[(*bInd).at(i)].SetProperty(1); } } for (unsigned int i=0;i PntNei; std::set::iterator pnt_it; int n = m_MeshStruct.size(); std::vector SCMax(n); std::vector SCMin(n); double maxCurv = 0.0, minCurv = 0.0; for (v_it.Begin(); v_it.More(); v_it.Next()) { PntNei = vv_it[v_it.Position()]; maxCurv += m_MeshStruct[v_it.Position()].maxCurv; minCurv += m_MeshStruct[v_it.Position()].minCurv; for (pnt_it = PntNei.begin(); pnt_it !=PntNei.end(); ++pnt_it) { maxCurv += m_MeshStruct[(*pnt_it)[0]._ulProp].maxCurv; minCurv += m_MeshStruct[(*pnt_it)[0]._ulProp].minCurv; } SCMax[v_it.Position()] = maxCurv/(PntNei.size()+1); SCMin[v_it.Position()] = minCurv/(PntNei.size()+1); maxCurv = 0.0; minCurv = 0.0; } for (int i=0; i::const_iterator pnt_it; MeshCore::MeshPointArray::_TConstIterator v_beg = Mesh.GetPoints().begin(); Base::Vector3f N, L, coor; int n = m_MeshStruct.size(); int g; for (v_it.Begin(); v_it.More(); v_it.Next()) { g = v_it.Position(); spnt.Set(0.0, 0.0, 0.0); locPointArray.push_back(*v_it); spnt += *v_it; const std::set& PntNei = vv_it[(*v_it)._ulProp]; if (PntNei.size() < 3) continue; for (pnt_it = PntNei.begin(); pnt_it !=PntNei.end(); ++pnt_it) { locPointArray.push_back(v_beg[*pnt_it]); spnt += v_beg[*pnt_it]; } spnt.Scale((float) (1.0/(double(PntNei.size()) + 1.0)),(float) (1.0/(double(PntNei.size()) + 1.0)),(float) (1.0/(double(PntNei.size()) + 1.0))); localMesh.Assign(locPointArray, locFacetArray); // need at least one facet to perform the PCA MeshCore::MeshGeomFacet face; face._aclPoints[0] = locPointArray[0]; face._aclPoints[1] = locPointArray[1]; face._aclPoints[2] = locPointArray[2]; localMesh.AddFacet(face); MeshCore::MeshEigensystem pca(localMesh); pca.Evaluate(); Base::Matrix4D T1 = pca.Transform(); N.x = (float) T1[0][0]; N.y = (float) T1[0][1]; N.z = (float) T1[0][2]; L.Set(v_it->x - spnt.x, v_it->y - spnt.y, v_it->z - spnt.z); N.Normalize(); if (N*L < 0.0) N.Scale(-1.0, -1.0, -1.0); if ((*v_it)._ulProp == 2286) { log.addSinglePoint(spnt,4,1,0,0); log.addSinglePoint(*v_it,4,0,0,0); for (unsigned int i=0; ix, v_it->y, v_it->z,text);*/ } double d = d_max; if (fabs(N*L)< d_max) d = fabs(N*L); N.Scale((float) d,(float) d,(float) d); PointArray[v_it.Position()].Set(v_it->x - N.x, v_it->y - N.y, v_it->z - N.z); locPointArray.clear(); localMesh = Meshtmp; } Mesh.Assign(PointArray, FacetArray); log.saveToFile("c:/checkNormals.iv"); return true; } bool SpringbackCorrection::SmoothMesh(MeshCore::MeshKernel &Mesh, std::vector ind, double d_max) { Base::Builder3D log; MeshCore::MeshKernel localMesh, Meshtmp; MeshCore::MeshPoint mpnt, spnt; MeshCore::MeshPointArray locPointArray, PointArray = Mesh.GetPoints(); MeshCore::MeshFacetArray locFacetArray, FacetArray = Mesh.GetFacets(); MeshCore::MeshPointIterator v_it(Mesh); MeshCore::MeshRefPointToPoints vv_it(Mesh); std::set::const_iterator pnt_it; MeshCore::MeshPointArray::_TConstIterator v_beg = Mesh.GetPoints().begin(); Base::Vector3f N, L, coor; int n = ind.size(); for (int i=0; i& PntNei = vv_it[(*v_it)._ulProp]; if (PntNei.size() < 3) continue; for (pnt_it = PntNei.begin(); pnt_it !=PntNei.end(); ++pnt_it) { locPointArray.push_back(v_beg[*pnt_it]); spnt += v_beg[*pnt_it]; } spnt.Scale((float) (1.0/(double(PntNei.size()) + 1.0)),(float) (1.0/(double(PntNei.size()) + 1.0)),(float) (1.0/(double(PntNei.size()) + 1.0))); localMesh.Assign(locPointArray, locFacetArray); // need at least one facet to perform the PCA MeshCore::MeshGeomFacet face; face._aclPoints[0] = locPointArray[0]; face._aclPoints[1] = locPointArray[1]; face._aclPoints[2] = locPointArray[2]; localMesh.AddFacet(face); MeshCore::MeshEigensystem pca(localMesh); pca.Evaluate(); Base::Matrix4D T1 = pca.Transform(); N.x = (float) T1[0][0]; N.y = (float) T1[0][1]; N.z = (float) T1[0][2]; L.Set(v_it->x - spnt.x, v_it->y - spnt.y, v_it->z - spnt.z); N.Normalize(); if (N*L < 0.0) N.Scale(-1.0, -1.0, -1.0); if ((*v_it)._ulProp == 2286) { log.addSinglePoint(spnt,4,1,0,0); log.addSinglePoint(*v_it,4,0,0,0); for (unsigned int i=0; ix, v_it->y, v_it->z,text);*/ } double d = d_max; if (fabs(N*L)< d_max) d = fabs(N*L); N.Scale((float) d,(float) d,(float) d); PointArray[v_it.Position()].Set(v_it->x - N.x, v_it->y - N.y, v_it->z - N.z); locPointArray.clear(); localMesh = Meshtmp; } Mesh.Assign(PointArray, FacetArray); log.saveToFile("c:/checkNormals.iv"); return true; } /* bool SpringbackCorrection::GetFaceAng(MeshCore::MeshKernel &mesh, int deg_tol) { Base::Vector3f normal, base; double deg; int n = mesh.CountFacets(); bool b = true; for (int i=0; i deg_tol) b = false; m_FaceAng.push_back(deg); } return b; } */ std::vector SpringbackCorrection::InitFaceCheck(MeshCore::MeshKernel &mesh, int degree) { std::vector faceInd; double tol = degree; double alpha; MeshCore::MeshFacetIterator fIt(mesh); MeshCore::MeshPointIterator mIt(mesh); MeshCore::MeshRefPointToFacets p2fIt(mesh); Base::Vector3f normal, base, gpnt; Base::Builder3D log; MeshCore::MeshPointArray mPnts = mesh.GetPoints(); MeshCore::MeshFacetArray mFacets = mesh.GetFacets(); MeshCore::MeshFacetArray::_TConstIterator f_beg = mesh.GetFacets().begin(); int n = mesh.CountFacets(); for (int i=0; i tol) { // markiere kritisches face mFacets[i].SetProperty(0); for (int j=0; j<3; ++j) { const std::set& faceSet = p2fIt[mFacets[i]._aulPoints[j]]; for (std::set::const_iterator it = faceSet.begin(); it != faceSet.end(); ++it) { f_beg[*it].SetProperty(5); } } log.addSingleArrow(gpnt,gpnt+normal,4,1,0,0); } else { mFacets[i].SetProperty(1); faceInd.push_back(i); } } log.saveToFile("c:/normalschecker.iv"); MeshCore::MeshFacetArray mFacets2 = mesh.GetFacets(); for (unsigned int i=0; i SpringbackCorrection::FaceCheck(MeshCore::MeshKernel &mesh, int degree) { std::vector faceInd; double tol = degree; double alpha; MeshCore::MeshFacetIterator fIt(mesh); MeshCore::MeshPointIterator mIt(mesh); Base::Vector3f normal, base, gpnt; Base::Builder3D log; MeshCore::MeshPointArray mPnts = mesh.GetPoints(); MeshCore::MeshFacetArray mFacets = mesh.GetFacets(); int n = mesh.CountFacets(); for (int i=0; i tol) { faceInd.push_back(i); cout << "i: " << i << ", angle: " << alpha << endl; } } log.saveToFile("c:/angles.iv"); return faceInd; } /* bool SpringbackCorrection::CorrectScale(double zLim) { // VERSCHIEBUNGSVEKTOREN ... // berechnung der skalierungsfaktoren bzgl. der Cad-Normalen int n = m_CadMesh.CountPoints(); double zLev; for (int i=0; izLim) m_Offset[i] = (zLim - m_MeshStruct[i].pnt.z)/m_MeshStruct[i].normal.z; } return true; } */ bool SpringbackCorrection::Perform(int deg_Tol, bool out) { unsigned int NumRef; std::vector dist_vec; //GetFaceAng(m_CadMesh, deg_Tol+1); //cout << "Init" << endl; //Init(); // tesseliere shape -> Basistriangulierung CAD-Mesh // EdgeMap wird hier gefüllt Base::Vector3f nullvec(0.0,0.0,0.0); m_dist_vec.resize(m_CadMesh.CountPoints(), nullvec); // fülle mit Nullvektoren cout << "SetFixEdges" << endl; SetFixEdges(); const MeshCore::MeshKernel RefMesh23 = m_CadMesh; cout << "CalcCurv" << endl; if (!CalcCurv()) return false; // berechne Krümmungswerte über Edgekrümmungen // MeshMap wird hier gefüllt const MeshCore::MeshKernel RefMesh = m_CadMesh; // übegebe CAD-Mesh vor der Verformung /*Base::Builder3D log; Base::Vector3f gpnt, normal; int numb = m_CadMesh.CountFacets(); for (int i=0; i (m_MeshStruct[i].maxCurv - m_set.master_radius)) m_Offset.push_back(m_MeshStruct[i].maxCurv - m_set.master_radius); else m_Offset.push_back(-m_MeshStruct[i].error); } else { if ((m_MeshStruct[i].minCurv + m_set.slave_radius) > 0.0) m_Offset.push_back(0.0); else if (m_MeshStruct[i].error > -(m_MeshStruct[i].minCurv + m_set.slave_radius)) m_Offset.push_back(m_MeshStruct[i].minCurv + m_set.slave_radius); else m_Offset.push_back(-m_MeshStruct[i].error); } } //Base::BoundBox3f bbox = m_CadMesh.GetBoundBox(); // hole bounding-box //CorrectScale(bbox.MaxZ); // korrigiere verschiebungsvektoren... //m_set.correction_factor = -0.1; // skalierung der Cad-Normalen for (int i=0; i tmpVec; tmpVec = FaceCheck(m_CadMesh, deg_Tol+1); NumRef = (int) tmpVec.size(); MeshCore::MeshPointArray pntAr = m_CadMesh.GetPoints(); MeshCore::MeshFacetArray facAr = m_CadMesh.GetFacets(); // Spiegelung Base::Builder3D log3d; for (int i=0; i tmpVec; std::vector normalsRef = m_normals; int cc = 0; // ********************************** GLOBALE KORREKTUR **************************************** int cm = 49; InitFaceCheck(m_CadMesh, deg_Tol+1); // kritische dreiecke -> _ulProp = 0 MeshCore::MeshFacetArray facAr2 = m_CadMesh.GetFacets(); while (true) { tmpVec = FaceCheck(m_CadMesh, deg_Tol+1); cout << "remaining: " << tmpVec.size() << endl; if (tmpVec.size() == NumRef || cm == 0) { cout << cm << "left" << endl; break; } --cm; MeshCore::MeshPointArray pntAr2 = RefMesh.GetPoints(); for (unsigned int i=0; i aRegion; std::vector< std::pair > skals; std::vector< std::vector< std::pair > > RegionSkals; MeshCore::MeshBuilder builder(m_Mesh_vis); builder.Initialize(10000); MeshCore::MeshBuilder builder2(m_Mesh_vis2); builder2.Initialize(10000); for (int i=0; i& faceSet = p2fIt[m_Regions[0][i]._aulPoints[j]]; for (std::set::const_iterator it = faceSet.begin(); it != faceSet.end(); ++it) { if((*it)[0]._ulProp == 0) m_RegionBounds.push_back((*it)[0]); } } }*/ tmpVec = InitFaceCheck(m_CadMesh, deg_Tol+1); cout << " glob: " << tmpVec.size() << endl; // ********************************** LOKALE KORREKTUR **************************************** unsigned long ind; MeshCore::MeshPointArray tmpPnts = m_CadMesh.GetPoints(); MeshCore::MeshFacetArray tmpFact = m_CadMesh.GetFacets(); Base::Builder3D logic; int cm_ref = 50-cm; for (unsigned int i=0; i NumRef || cm == 0) { tmpPnts = m_CadMesh.GetPoints(); for (unsigned int k=0; k > SpringbackCorrection::RegionEvaluate(const MeshCore::MeshKernel &mesh, std::vector &RegionFacets, std::vector &normals) { std::list< std::vector > Borders; std::list< std::vector >::iterator bIt; std::map RegionMap; std::map ::iterator rIt; std::map DistMap; std::map ::iterator dIt; std::pair Ind2Pnt; std::pair Dist2Ind; std::vector< std::pair > dists; std::vector< std::pair< unsigned long, double> > skals; MeshCore::MeshAlgorithm algo(mesh); // übergebe mesh algo.GetFacetBorders(RegionFacets, Borders); // speichert ränder der region in Borders MeshCore::MeshFacetArray facets = mesh.GetFacets(); MeshCore::MeshPointArray points = mesh.GetPoints(); // um doppelte indizes zu vermeiden push die punkte der region in eine map for (unsigned int i=0; isize(); ++i) { distVec = (*rIt).second - (*bIt).at(i); if (distVec.Length() < distVal) distVal = distVec.Length(); } } Dist2Ind.first = distVal; Dist2Ind.second = (*rIt).first; dists.push_back(Dist2Ind); DistMap.insert(Dist2Ind); } dIt = DistMap.end(); --dIt; double d_max = (*dIt).first; std::pair pair; for (unsigned int i=0; i &FacetRegion, MeshCore::MeshFacetArray &mFacets) { MeshCore::MeshRefFacetToFacets ff_It(mesh); MeshCore::MeshFacet facet = FacetRegion.back(); const std::set& FacetNei = ff_It[facet._ulProp]; MeshCore::MeshFacetArray::_TConstIterator f_beg = mesh.GetFacets().begin(); std::set::const_iterator f_it; for (f_it = FacetNei.begin(); f_it != FacetNei.end(); ++f_it) { if (f_beg[*f_it]._ucFlag == MeshCore::MeshFacet::VISIT) { FacetRegion.push_back(f_beg[*f_it]); mFacets[f_beg[*f_it]._ulProp].SetFlag(MeshCore::MeshFacet::INVALID); // markiere als schon zugewiesen FacetRegionGrowing(mesh, FacetRegion, mFacets); } } return true; } // //bool SpringbackCorrection::Init() //{ // Base::Builder3D log; // Base::Vector3f p1,p2; // double curv; // // Triangulate Shape (vorläufig) // best_fit::Tesselate_Shape(m_Shape, m_Mesh, 1); // // MeshCurvature(m_Mesh); // // std::vector normals = best_fit::Comp_Normals(m_Mesh); // MeshCore::MeshPointIterator p_it(m_Mesh); // int i = 0; // // for(p_it.Begin(); p_it.More(); p_it.Next()){ // normals[i].Scale(m_CurvMax[i], m_CurvMax[i], m_CurvMax[i]); // //p1.Set(PointArray[i].x, PointArray[i].y, PointArray[i].z); // p2.Set(p_it->x + normals[i].x, p_it->y + normals[i].y, p_it->z + normals[i].z); // // // if(m_CurvMax[i] < 100) // log.addSingleLine(*p_it, p2, 1 ,0, 0, 0 ); // // //cout << p_it->x << ", " << p_it->y << ", " << p_it->z << endl; // //cout <D2(u_par,v_par,proPnt,D1U,D1V,D2U,D2V,D2UV); // erste & zweite Hauptkrümmung k1 = D1U.CrossMagnitude(D2U) / D1U.Magnitude(); k2 = D1V.CrossMagnitude(D2V) / D1V.Magnitude(); /*if(k1>k2) PointArray[i].SetProperty(1/k1); else PointArray[i].SetProperty(1/k2);*/ if (abs(k1)>abs(k2)) { m_CurvMax[i] = 1/k1; } else if (k2!=0) m_CurvMax[i] = 1/k2; else m_CurvMax[i] = 100; D1U.Cross(D1V); D1U.Normalize(); D1U.Scale(m_CurvMax[i]); p1.x = (float) (proPnt.X() + D1U.X()); p1.y = (float) (proPnt.Y() + D1U.Y()); p1.z = (float) (proPnt.Z() + D1U.Z()); p2.x = (float) proPnt.X(); p2.y = (float) proPnt.Y(); p2.z = (float) proPnt.Z(); log.addSingleLine(p2, p1, 1 ,0, 0, 0 ); } MeshCore::MeshPointIterator v_it(m_Mesh); MeshCore::MeshRefPointToPoints vv_it(m_Mesh); MeshCore::MeshPointArray::_TConstIterator v_beg = m_Mesh.GetPoints().begin(); std::set PntNei; std::set PntNei2; std::set PntNei3; std::set PntNei4; std::set::iterator pnt_it1; std::set::iterator pnt_it2; std::set::iterator pnt_it3; std::set::iterator pnt_it4; std::vector nei; double curv; std::vector CurvCop = m_CurvMax; for (v_it.Begin(); v_it.More(); v_it.Next()) { PntNei = vv_it[v_it.Position()]; curv = m_CurvMax[v_it.Position()]; for (pnt_it1 = PntNei.begin(); pnt_it1 !=PntNei.end(); ++pnt_it1) { if (m_CurvMax[v_beg[*pnt_it1]._ulProp] < curv) curv = m_CurvMax[v_beg[*pnt_it1]._ulProp]; PntNei2 = vv_it[v_beg[*pnt_it1]._ulProp]; for (pnt_it2 = PntNei2.begin(); pnt_it2 !=PntNei2.end(); ++pnt_it2) { if (m_CurvMax[v_beg[*pnt_it2]._ulProp] < curv) curv = m_CurvMax[v_beg[*pnt_it2]._ulProp]; PntNei3 = vv_it[v_beg[*pnt_it2]._ulProp]; for (pnt_it3 = PntNei3.begin(); pnt_it3 !=PntNei3.end(); ++pnt_it3) { if (m_CurvMax[v_beg[*pnt_it3]._ulProp] < curv) curv = m_CurvMax[v_beg[*pnt_it3]._ulProp]; PntNei4 = vv_it[v_beg[*pnt_it3]._ulProp]; for (pnt_it4 = PntNei4.begin(); pnt_it4 !=PntNei4.end(); ++pnt_it4) { if (m_CurvMax[v_beg[*pnt_it4]._ulProp] < curv) curv = m_CurvMax[v_beg[*pnt_it4]._ulProp]; } } } } CurvCop[v_it.Position()] = curv; } m_CurvMax = CurvCop; return true; } // 1. Computes the curvature of the mesh at the verticies // 2. Stores the minimum curvatures along the neighbours for all verticies in a vector std::vector SpringbackCorrection::MeshCurvature(const TopoDS_Face& aFace, const MeshCore::MeshKernel& mesh) { TopLoc_Location aLocation; Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation); const TColgp_Array1OfPnt2d& aUVNodes = aTr->UVNodes(); int n = aUVNodes.Length(); BRepAdaptor_Surface aSurface(aFace); gp_Pnt2d par; gp_Pnt P; gp_Vec D1U, D1V, D2U, D2V, D2UV, nor, xvv, xuv, xuu; double H,K; // Gaußsche- und mittlere Krümmung std::vector aMaxCurve, aMinCurve; std::vector curv(2); for (int i=0; i 0) m_CurvPos[i] = 1 / aMaxCurve[i]; else m_CurvPos[i] = 1e+10; if (aMinCurve[i] < 0) m_CurvNeg[i] = 1 / aMinCurve[i]; else m_CurvNeg[i] = -1e+10; if (m_CurvPos[i] < tmp1) tmp1 = m_CurvPos[i]; if (m_CurvNeg[i] > tmp2) tmp2 = m_CurvNeg[i]; if (aMaxCurve[i] > 0) { ++c1; mean_curvMax += 1/aMaxCurve[i]; } if (aMinCurve[i] < 0) { ++c2; mean_curvMin += 1/aMinCurve[i]; } } if (c1==0) mean_curvMax = 1e+3; else mean_curvMax /= mesh.CountPoints(); if (c2==0) mean_curvMin = -1e+3; else mean_curvMin /= mesh.CountPoints(); curv[0] = tmp1; curv[1] = tmp2; //Krümmung auf Netzbasis for(int i=0; i > aPnts; std::vector aPnts_tmp; MeshCore::MeshPointIterator cPIt( mesh ); for ( cPIt.Init(); cPIt.More(); cPIt.Next() ) { Wm4::Vector3 cP( cPIt->x, cPIt->y, cPIt->z ); Base::Vector3f cP_tmp( cPIt->x, cPIt->y, cPIt->z ); aPnts.push_back( cP ); aPnts_tmp.push_back(cP_tmp); } // get all point connections std::vector anIdx; const std::vector& MeshFacetArray = mesh.GetFacets(); for ( std::vector::const_iterator jt = MeshFacetArray.begin(); jt != MeshFacetArray.end(); ++jt ) { for (int i=0; i<3; i++) { anIdx.push_back( (int)jt->_aulPoints[i] ); } } // compute vertex based curvatures Wm4::MeshCurvature meshCurv(mesh.CountPoints(), &(aPnts[0]), mesh.CountFacets(), &(anIdx[0])); // get curvature information now const Wm4::Vector3* aMaxCurvDir = meshCurv.GetMaxDirections(); const Wm4::Vector3* aMinCurvDir = meshCurv.GetMinDirections(); const float* aMaxCurv = meshCurv.GetMaxCurvatures(); const float* aMinCurv = meshCurv.GetMinCurvatures(); double maxCurv = 0.0; double avgCurv = 0.0; double tmp1 = 1e+10; double tmp2 = -1e+10; double mean_curvMax = 0.0, mean_curvMin = 0.0; int c1 = 0, c2 = 0; m_CurvPos.clear(); m_CurvNeg.clear(); m_CurvMax.clear(); m_CurvPos.resize(mesh.CountPoints()); m_CurvNeg.resize(mesh.CountPoints()); m_CurvMax.resize(mesh.CountPoints()); for ( unsigned long i=0; i 0) m_CurvPos[i] = 1 / aMaxCurv[i]; else m_CurvPos[i] = 1e+10; if (aMinCurv[i] < 0) m_CurvNeg[i] = 1 / aMinCurv[i]; else m_CurvNeg[i] = -1e+10; if (m_CurvPos[i] < tmp1) tmp1 = m_CurvPos[i]; if (m_CurvNeg[i] > tmp2) tmp2 = m_CurvNeg[i]; if (aMaxCurv[i] > 0) { ++c1; mean_curvMax += 1/aMaxCurv[i]; } if (aMinCurv[i] < 0) { ++c2; mean_curvMin += 1/aMinCurv[i]; } } if (c1==0) mean_curvMax = 1e+3; else mean_curvMax /= mesh.CountPoints(); if (c2==0) mean_curvMin = -1e+3; else mean_curvMin /= mesh.CountPoints(); curv[0] = tmp1; curv[1] = tmp2; } return curv; } /* bool SpringbackCorrection::MirrorMesh(std::vector error) { // Flags: 0 - not yet checked // 1 - no correction applied, but necessary // 2 - first correction applied and still necessary // 3 - done successfully // 4 - done without success // 5 - boundary point int n = error.size(); m_error = error; std::vector InterPnts; std::vector InterFace; std::vector IFCopy; bool boo = true; std::vector ind; std::vector copy; MeshRef = m_Mesh; std::vector NormalsRef = m_normals; std::vector NormalOrig = m_normals; PointArray = MeshRef.GetPoints(); MeshCore::MeshPointArray PntArray = m_Mesh.GetPoints(); MeshCore::MeshFacetArray FctArray = m_Mesh.GetFacets(); MeshCore::MeshFacetArray FacetArray = MeshRef.GetFacets(); MeshCore::MeshFacetIterator f_it(MeshRef); MeshCore::MeshPointIterator v_it(MeshRef); MeshCore::MeshRefPointToPoints vv_it(MeshRef); MeshCore::MeshRefPointToFacets vf_it(MeshRef); std::set PntNei; std::set FacetNei; // Iterates in facets in form of MeshGeomFacets std::set::iterator face_it; std::set::iterator pnt_it; std::vector NeiLoc; std::vector NorLoc; std::vector TmpPntVec; std::vector TmpIndVec; std::vector nei; bool k=true; int count = 0; while (k==true) { // ------ Self-Intersection Check + Correction ------------------------------------------------------ if (count ==2) break; count++; Base::Builder3D log3d; Base::Builder3D loga; Base::Vector3f Pnt, NeiPnt, NeiPntNext, NeiPntPrev, TmpPnt, TmpNor; std::vector Neis; double minScale, tmp; bool sign; ublas::matrix A(3, 3); ublas::matrix b(1, 3); ind.clear(); for (unsigned int i=0; i 0); // (+) -> true , (-) -> false MeshRef.Assign(PointArray, FacetArray); v_it.Set(ind[j]); Pnt = *v_it; PntNei = vv_it[ind[j]]; FacetNei = vf_it[ind[j]]; nei.clear(); // falls boundary-point tue nichts bzw. gehe zum nächsten punkt if (FacetNei.size() != PntNei.size()) { PointArray[ind[j]]._ucFlag = 5; m_CurvMax[ind[j]] = abs(error[ind[j]]); // vorübergehend continue; } // ordne nachbarn ReorderNeighbourList(PntNei,FacetNei,nei,ind[j]); NeiLoc.clear(); NorLoc.clear(); NeiLoc.push_back(Pnt); NorLoc.push_back(NormalsRef[ind[j]]); for (unsigned int r=0; r 0) { PointArray[ind[j]]._ucFlag = 3; m_CurvMax[ind[j]] = abs(minScale); //cout << "t, "; continue; } else { PointArray[ind[j]]._ucFlag = 4; m_CurvMax[ind[j]] = abs(minScale); cout << "f, "; continue; } } if (sign ==true) minScale = -(1e+10); else minScale = 1e+10; minScale = LocalCorrection(NeiLoc,NorLoc,sign,minScale); if ((abs(0.8*minScale) - abs(error[ind[j]])) > 0) { PointArray[ind[j]]._ucFlag = 3; m_CurvMax[ind[j]] = abs(minScale); continue; } //---------------------------- 1. Korrektur ------------------------- tmp = 0; std::vector ConvComb = FillConvex(NeiLoc,NorLoc,20); for (unsigned int l=0; l abs(tmp)) { tmp = minScale; TmpPnt = NeiLoc[0]; } } NeiLoc[0] = PointArray[ind[j]]; cout << "new minScale: " << tmp << endl; if ((abs(0.8*tmp) - abs(error[ind[j]])) > 0) { PointArray[ind[j]].Set(TmpPnt.x, TmpPnt.y, TmpPnt.z); PointArray[ind[j]]._ucFlag = 3; m_CurvMax[ind[j]] = abs(tmp); continue; } else { PointArray[ind[j]]._ucFlag = 2; m_CurvMax[ind[j]] = abs(tmp); } //------------------------------- END ------------------------------- // update for (unsigned int r=0; r 0) { PointArray[ind[j]].Set(NeiLoc[0].x, NeiLoc[0].y, NeiLoc[0].z); NormalsRef[ind[j]].Set(NorLoc[0].x, NorLoc[0].y, NorLoc[0].z); PointArray[ind[j]]._ucFlag = 3; m_CurvMax[ind[j]] = abs(tmp); continue; } else { if (m_CurvMax[ind[j]] < abs(tmp)) { m_CurvMax[ind[j]] = abs(tmp); PointArray[ind[j]].Set(NeiLoc[0].x, NeiLoc[0].y, NeiLoc[0].z); NormalsRef[ind[j]].Set(NorLoc[0].x, NorLoc[0].y, NorLoc[0].z); } // flag bleibt 2 } //------------------------------- END ------------------------------- } // end for cout << "Replace Mesh..." << endl; PntArray = PointArray; m_normals = NormalsRef; m_Mesh = MeshRef; } // end while double ver, mx=100; for (unsigned int i=0; i IndexVec,NumVec, NumVecCopy; int c, lastNum, lastInd; // kritische punkte plus anzahl seiner kritischen nachbarn speichern //ind.clear(); for (unsigned int j=0; j_ulProp]._ucFlag == 4) c++; } IndexVec.push_back(ind[j]); NumVec.push_back(c); } } // normalenskalierung for (unsigned int j=0; j SortNumVec(NumVec.size(), -1); std::vector SortIndVec(NumVec.size(), -1); cout << NumVec.size() << endl; //cout << "vor dem sortieren: "; //for(int j=0; j v(3); v[0].x = (float) T1[0][0]; v[0].y = (float) T1[0][1]; v[0].z = (float) T1[0][2]; v[1].x = (float) T1[1][0]; v[1].y = (float) T1[1][1]; v[1].z = (float) T1[1][2]; v[2].x = (float) T1[2][0]; v[2].y = (float) T1[2][1]; v[2].z = (float) T1[2][2]; v[0].Normalize(); v[1].Normalize(); v[2].Normalize(); double deg,temp=0; int s; for (int i=0; i<3; ++i) { deg = v[i]*NormalOrig[SortIndVec[j]]; if (abs(deg)>temp) { temp = abs(deg); s=i; } } if (v[s].z < 0.0) v[s] *= -1; for (unsigned int i=0; i Convs = FillConvex(NeiLoc, NorLoc, 20); for (unsigned int i=0; i Neib , std::vector Normal, bool sign, double minScale) { Base::Vector3f Pnt, NeiPnt, NeiPntNext, NeiPntPrev; ublas::matrix A(3, 3); ublas::matrix b(1, 3); // 2. Spalte bleibt unverändert A(0,2) = -Normal[0].x; A(1,2) = -Normal[0].y; A(2,2) = -Normal[0].z; // forward for (unsigned int k=1; k=0) && (b(0,1)<=1)) { if (minScale < b(0,2)) minScale = b(0,2); } else if (b(0,2)>=0 && sign == false && (b(0,1)>=0) && (b(0,1)<=1)) { if (minScale > b(0,2)) minScale = b(0,2); } } // backward for (unsigned int k=1; k=0) && (b(0,1)<=1)) { if (minScale < b(0,2)) minScale = b(0,2); } else if (b(0,2)>0 && sign == false && (b(0,1)>=0) && (b(0,1)<=1)) { if (minScale > b(0,2)) minScale = b(0,2); } } return minScale; } */ /* std::vector SpringbackCorrection::FillConvex(std::vector Neib, std::vector Normals, int n) { std::vector ConvComb; Base::Vector3f tmp; for (unsigned int i=1; i Neib) { Base::Vector3f Pnt, NeiPnt, NeiPntNext, Cross; ublas::matrix A(3, 3); ublas::matrix b(1, 3); bool b1 = true, b2; for (unsigned int k=1; k0) { b1 = false; b2 = false; } } if (b1==false) { if ((b2 == true) && (b(0,2) > 0)) return false; if ((b2 == false) && (b(0,2) < 0)) return false; } } return true; } */ /* double SpringbackCorrection::GlobalCorrection(std::vector NeiLoc, std::vector NorLoc, bool sign, int ind) { double minScale,mScRef,tmp = 0; Base::Vector3f TmpPnt, TmpNor; if (sign ==true) mScRef = -(1e+10); else mScRef = 1e+10; minScale = mScRef; minScale = LocalCorrection(NeiLoc,NorLoc,sign,minScale); if ((abs(0.8*minScale) - abs(m_error[ind])) > 0) { PointArray[ind]._ucFlag = 3; m_CurvMax[ind] = abs(minScale); return minScale; } std::vector ConvComb = FillConvex(NeiLoc,NorLoc,20); // füge schwerpunkte der umgebenden faces hinzu std::set FacetNei; std::set::iterator face_it; MeshCore::MeshFacetIterator f_it (MeshRef); MeshCore::MeshRefPointToFacets vf_it(MeshRef); FacetNei = vf_it[ind]; for (face_it = FacetNei.begin(); face_it != FacetNei.end(); ++face_it) { TmpPnt.Set(0.0, 0.0, 0.0); TmpPnt += PointArray[(*face_it)->_aulPoints[0]]; TmpPnt += PointArray[(*face_it)->_aulPoints[1]]; TmpPnt += PointArray[(*face_it)->_aulPoints[2]]; TmpPnt.Scale((float) (1.0/3.0),(float) (1.0/3.0),(float) (1.0/3.0)); ConvComb.push_back(TmpPnt); } //Base::Builder3D logg; //for(int i=0; i tmp) { tmp = minScale; TmpPnt = NeiLoc[0]; TmpNor = NorLoc[0]; } } } NeiLoc[0] = TmpPnt; NorLoc[0] = TmpNor; if ((abs(0.8*tmp) - abs(m_error[ind])) > 0) { PointArray[ind]._ucFlag = 3; m_CurvMax[ind] = abs(tmp); } else { PointArray[ind]._ucFlag = 4; m_CurvMax[ind] = abs(tmp); } return tmp; } /* /*! \brief Reorder the neighbour list This function will reorder the list in one-direction. Clockwise or counter clockwise is depending on the facet list and will not be checked by this function. (i.e the third vertex i.e vertex in first facet that is not the CurIndex or the first neighbour in pnt[Ok, I am also lost with this..., just debug and step to see what I mean...]) */ /* void SpringbackCorrection::ReorderNeighbourList(std::set &pnt, std::set &face, std::vector &nei, unsigned long CurInd) { std::set::iterator pnt_it; std::set::iterator face_it; std::vector::iterator vec_it; std::vector::iterator ulong_it; unsigned long PrevIndex; if (face.size() != pnt.size()) //this means boundary point { for (pnt_it = pnt.begin(); pnt_it != pnt.end(); ++pnt_it) { int c = 0; for (face_it = face.begin(); face_it != face.end(); ++face_it) { if ((*pnt_it)[0]._ulProp == (*face_it)[0]._aulPoints[0]) ++c; if ((*pnt_it)[0]._ulProp == (*face_it)[0]._aulPoints[1]) ++c; if ((*pnt_it)[0]._ulProp == (*face_it)[0]._aulPoints[2]) ++c; } if (c==1) break; } } else pnt_it = pnt.begin(); face_it = face.begin(); nei.push_back((*pnt_it)->_ulProp); //push back first neighbour vec_it = nei.begin(); PrevIndex = nei[0]; //Initialize PrevIndex for (unsigned int i = 1; i < pnt.size(); i++) //Start { while (true) { std::vector facetpnt; facetpnt.push_back((*face_it)->_aulPoints[0]); //push back into a vector for easier iteration facetpnt.push_back((*face_it)->_aulPoints[1]); facetpnt.push_back((*face_it)->_aulPoints[2]); if ((ulong_it = find(facetpnt.begin(), facetpnt.end(), PrevIndex)) == facetpnt.end()) //if PrevIndex not found { //in current facet if (face_it != face.end()) ++face_it; //next face please else break; continue; } else { for (unsigned int k = 0 ; k < 3; k++) { //If current facetpnt[k] is not yet in nei_list AND it is not the CurIndex if (((vec_it = find(nei.begin(), nei.end(), facetpnt[k])) == nei.end()) && facetpnt[k] != CurInd) { face.erase(face_it); //erase this face nei.push_back(facetpnt[k]); //push back the index PrevIndex = facetpnt[k]; //this index is now PrevIndex face_it = face.begin(); //reassign the iterator break; //end this for-loop } } break; //end this while loop } } } } */ bool SpringbackCorrection::Visit(const MeshCore::MeshFacet &rclFacet, const MeshCore::MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel) { if (ulLevel != m_RingCurrent) { ++m_RingCurrent; if (m_RingVector.size() == 0) { return false; } //else if(m_RingVector.size() < 2 && m_RingCurrent > 2) //{ // m_RingVector.clear(); // return false; //} else { m_RegionVector.push_back(m_RingVector); m_RingVector.clear(); } } if (rclFacet._ulProp == 1 && rclFrom._ulProp == 1) m_RingVector.push_back(ulFInd); return true; }