00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #include "SpringbackCorrection.h"
00027 #include "best_fit.h"
00028
00029
00030 #include <Mod/Mesh/App/Core/Builder.h>
00031 #include <Mod/Mesh/App/WildMagic4/Wm4MeshCurvature.h>
00032
00033 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00034 #include <Base/Builder3D.h>
00035 #include <GeomAPI_ProjectPointOnSurf.hxx>
00036 #include <BRepTools.hxx>
00037 #include <BRep_Builder.hxx>
00038 #include <Poly_PolygonOnTriangulation.hxx>
00039 #include <Poly_Triangulation.hxx>
00040 #include <BRepExtrema_DistShapeShape.hxx>
00041 #include <TopExp_Explorer.hxx>
00042 #include <TopExp.hxx>
00043 #include <TopoDS_Vertex.hxx>
00044 #include <BRep_Tool.hxx>
00045 #include <TColgp_Array1OfPnt2d.hxx>
00046 #include <BRepAdaptor_Surface.hxx>
00047 #include <BRepExtrema_DistShapeShape.hxx>
00048 #include <TopoDS.hxx>
00049 #include <TopTools_ListIteratorOfListOfShape.hxx>
00050 #include <Geom_Surface.hxx>
00051
00052
00053
00054
00056 #include <boost/numeric/bindings/traits/ublas_matrix.hpp>
00057 #include <boost/numeric/bindings/atlas/clapack.hpp>
00058
00059 using namespace boost::numeric::bindings;
00060
00061 using namespace boost::numeric;
00062
00063
00064 SpringbackCorrection::SpringbackCorrection()
00065 {
00066 }
00067
00068 SpringbackCorrection::SpringbackCorrection(const TopoDS_Shape& aShape, const MeshCore::MeshKernel& aMesh)
00069 :m_Shape(aShape),m_Mesh(aMesh)
00070 {
00071 m_EdgeStruct.clear();
00072 EdgeMap.clear();
00073 MeshMap.clear();
00074
00075 BRepTools::Clean(m_Shape);
00076 best_fit::Tesselate_Shape(m_Shape,m_CadMesh,(float) 0.1);
00077
00078 MeshCore::MeshTopoAlgorithm algo(m_CadMesh);
00079 algo.HarmonizeNormals();
00080
00081
00082 MeshCore::MeshGeomFacet facet = m_CadMesh.GetFacet(0);
00083 if (facet.GetNormal().z < 0.0)
00084 algo.FlipNormals();
00085
00086 int n = m_CadMesh.CountFacets();
00087 Base::Vector3f normal;
00088
00089 MeshCore::MeshPointArray points = m_CadMesh.GetPoints();
00090 MeshCore::MeshFacetArray facets = m_CadMesh.GetFacets();
00091
00092 for (int i=0; i<n; ++i)
00093 {
00094 MeshCore::MeshGeomFacet face = m_CadMesh.GetFacet(i);
00095 normal = face.GetNormal();
00096
00097 if (normal.z < 0.0)
00098 {
00099 facets[i].FlipNormal();
00100 }
00101 }
00102
00103 m_CadMesh.Assign(points, facets);
00104 }
00105
00106 SpringbackCorrection::~SpringbackCorrection()
00107 {
00108 }
00109 bool SpringbackCorrection::Load(const MeshCore::MeshKernel& aMesh)
00110 {
00111 m_MeshVec.push_back(aMesh);
00112
00113
00114 return true;
00115 }
00116
00117 bool SpringbackCorrection::Load(const TopoDS_Shape& aShape)
00118 {
00119 m_Shape = aShape;
00120 return true;
00121 }
00122 bool SpringbackCorrection::Load(const TopoDS_Shape& aShape, const MeshCore::MeshKernel& aMesh)
00123 {
00124 m_Shape = aShape;
00125 m_Mesh = aMesh;
00126
00127 m_EdgeStruct.clear();
00128 EdgeMap.clear();
00129 MeshMap.clear();
00130
00131
00132 BRepTools::Clean(m_Shape);
00133 best_fit::Tesselate_Shape(m_Shape,m_CadMesh,(float) 0.1);
00134
00135 MeshCore::MeshTopoAlgorithm algo(m_CadMesh);
00136 algo.HarmonizeNormals();
00137
00138 MeshCore::MeshGeomFacet facet = m_CadMesh.GetFacet(0);
00139 if (facet.GetNormal().z < 0.0)
00140 algo.FlipNormals();
00141
00142 int n = m_CadMesh.CountFacets();
00143 Base::Vector3f normal;
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 return true;
00162 }
00163
00164 bool SpringbackCorrection::CalcCurv()
00165 {
00166 Base::Builder3D logo;
00167 BRep_Builder VertexBuild;
00168 BRepExtrema_DistShapeShape pnt2edge;
00169 pnt2edge.SetDeflection(0.1);
00170
00171 TopExp_Explorer aExpFace;
00172 TopExp_Explorer aExpEdge;
00173 TopoDS_Vertex V;
00174
00175 MeshPnt aMeshStruct;
00176 MeshCore::MeshPointIterator pntIt(m_CadMesh);
00177 MeshCore::MeshKernel FaceMesh;
00178 MeshCore::MeshPointArray MeshPnts, MeshPntsCop, MeshPntsCad;
00179 MeshCore::MeshPointArray MeshPntsCopy;
00180 MeshCore::MeshFacetArray MeshFacets, MeshFacets2;
00181 MeshCore::MeshFacetIterator facetIt(m_CadMesh);
00182
00183 std::pair<Base::Vector3f, MeshPnt> inp;
00184 std::vector<int> MeanVec;
00185 std::vector<FacePnt> FacePntVector;
00186 TopLoc_Location aloc;
00187 Base::Vector3f mP;
00188 gp_Pnt e_pnt, m_pnt;
00189 double dist, distSum, revSum;;
00190 int n;
00191
00192 std::map<TopoDS_Edge, std::vector<double>, Edge_Less>::iterator edge_it;
00193 std::map<Base::Vector3f,MeshPnt,MeshPntLess >::iterator meshIt;
00194 std::vector<MeshCore::MeshPoint>::iterator pIt;
00195
00196 m_CurvPos.resize(m_CadMesh.CountPoints());
00197 m_CurvNeg.resize(m_CadMesh.CountPoints());
00198 m_MeshStruct.resize(m_CadMesh.CountPoints());
00199 MeanVec.resize(m_CadMesh.CountPoints(), 0);
00200
00201
00202 MeshPnts = m_CadMesh.GetPoints();
00203 MeshPntsCop = MeshPnts;
00204 MeshFacets2 = m_CadMesh.GetFacets();
00205
00206 for (unsigned int i=0; i<MeshPnts.size(); ++i)
00207 {
00208 aMeshStruct.pnt = MeshPnts[i];
00209 aMeshStruct.index = i;
00210 aMeshStruct.maxCurv = 1e+3;
00211 aMeshStruct.minCurv = -1e+3;
00212 inp.first = aMeshStruct.pnt;
00213 inp.second = aMeshStruct;
00214 MeshMap.insert(inp);
00215 }
00216
00217
00218 for (aExpFace.Init(m_Shape,TopAbs_FACE);aExpFace.More();aExpFace.Next())
00219 {
00220 TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
00221 TransferFaceTriangulationtoFreeCAD(aFace, FaceMesh);
00222 MeshPnts.clear();
00223 MeshPnts = FaceMesh.GetPoints();
00224 MeshPntsCopy = MeshPnts;
00225 n = MeshPnts.size();
00226 TopLoc_Location aLocation;
00227
00228 Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);
00229 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
00230
00231 TColgp_Array1OfPnt aPoints(1, aNodes.Length());
00232 for ( Standard_Integer i = 1; i <= aNodes.Length(); i++)
00233 aPoints(i) = aNodes(i).Transformed(aLocation);
00234
00235 const TColgp_Array1OfPnt2d& aUVNodes = aTr->UVNodes();
00236
00237
00238 BRepAdaptor_Surface aSurface(aFace);
00239 Base::Vector3f Pnt1, Pnt2;
00240 gp_Pnt2d par;
00241 gp_Pnt P;
00242 gp_Vec D1U, D1V;
00243
00244 for (int i=1; i<n+1; ++i)
00245 {
00246 par = aUVNodes.Value(i);
00247 aSurface.D1(par.X(),par.Y(),P,D1U,D1V);
00248 P = aPoints(i);
00249 Pnt1.x = (float) P.X();
00250 Pnt1.y = (float) P.Y();
00251 Pnt1.z = (float) P.Z();
00252 meshIt = MeshMap.find(Pnt1);
00253 if (meshIt == MeshMap.end())
00254 {
00255 cout << "error";
00256 return false;
00257 }
00258
00259 D1U.Cross(D1V);
00260 D1U.Normalize();
00261 if (aFace.Orientation() == TopAbs_FORWARD) D1U.Scale(-1.0);
00262
00263 Pnt2.Set(float(Pnt1.x+D1U.X()),float(Pnt1.y+D1U.Y()),float(Pnt1.z+D1U.Z()));
00264 logo.addSingleArrow(Pnt1, Pnt2);
00265
00266 m_MeshStruct[((*meshIt).second).index].normal.x = (float) D1U.X();
00267 m_MeshStruct[((*meshIt).second).index].normal.y = (float) D1U.Y();
00268 m_MeshStruct[((*meshIt).second).index].normal.z = (float) D1U.Z();
00269
00270 }
00271
00272 logo.saveToFile("c:/norm.iv");
00273
00274
00275
00276
00277 int innerpoints = GetBoundary(FaceMesh, MeshPnts);
00278
00279
00280
00281 FacePntVector.resize(innerpoints);
00282
00283
00284 for (aExpEdge.Init(aFace,TopAbs_EDGE);aExpEdge.More();aExpEdge.Next())
00285 {
00286 TopoDS_Edge aEdge = TopoDS::Edge(aExpEdge.Current());
00287
00288 edge_it = EdgeMap.find(aEdge);
00289 if (edge_it == EdgeMap.end())
00290 {
00291 cout << "error1";
00292 return false;
00293 }
00294
00295 pnt2edge.LoadS1(aEdge);
00296
00297 int counter = 0;
00298
00299 for (pIt = MeshPnts.begin(); pIt != MeshPnts.end(); ++pIt)
00300 {
00301
00302 if (pIt->_ulProp == 0)
00303 {
00304 m_pnt.SetCoord(pIt->x, pIt->y, pIt->z);
00305 VertexBuild.MakeVertex(V,m_pnt,0.001);
00306 pnt2edge.LoadS2(V);
00307 pnt2edge.Perform();
00308
00309 if (pnt2edge.IsDone() == false)
00310 {
00311 throw Base::Exception("couldn't perform distance calculation pnt2edge \n");
00312 }
00313
00314 dist = pnt2edge.Value();
00315
00316 FacePntVector[counter].pnt = *pIt;
00317 FacePntVector[counter].distances.push_back(dist);
00318 FacePntVector[counter].MinEdgeOff.push_back((*edge_it).second[0]);
00319 FacePntVector[counter].MaxEdgeOff.push_back((*edge_it).second[1]);
00320 ++counter;
00321 }
00322
00323 }
00324
00325
00326
00327
00328 Handle(Poly_PolygonOnTriangulation) polyg;
00329 Handle_Poly_Triangulation aTrLoc;
00330 BRep_Tool::PolygonOnTriangulation(aEdge,polyg,aTrLoc,aloc);
00331
00332 TColStd_Array1OfInteger IndArr(1,polyg->NbNodes());
00333 IndArr = polyg->Nodes();
00334
00335 const TColgp_Array1OfPnt& Nodes = aTrLoc->Nodes();
00336 TColgp_Array1OfPnt TrLocPnts(1, Nodes.Length());
00337 for ( Standard_Integer i = 1; i <= Nodes.Length(); i++)
00338 TrLocPnts(i) = Nodes(i).Transformed(aloc);
00339
00340 for (int k=0; k<polyg->Nodes().Upper(); ++k)
00341 {
00342 e_pnt = TrLocPnts(IndArr.Value(k+1));
00343
00344 mP.x = (float) e_pnt.X();
00345 mP.y = (float) e_pnt.Y();
00346 mP.z = (float) e_pnt.Z();
00347
00348 meshIt = MeshMap.find(mP);
00349 if (meshIt == MeshMap.end())
00350 {
00351 cout << "error2" << endl;
00352 return false;
00353 }
00354
00355
00356 ++MeanVec[meshIt->second.index];
00357
00358
00359 if (((*edge_it).second[0])>((*meshIt).second).minCurv)
00360 ((*meshIt).second).minCurv = (*edge_it).second[0];
00361
00362 if ((*edge_it).second[1]<((*meshIt).second).maxCurv)
00363 ((*meshIt).second).maxCurv = (*edge_it).second[1];
00364 }
00365 }
00366
00367
00368 for (unsigned int k=0; k<FacePntVector.size(); ++k)
00369 {
00370 meshIt = MeshMap.find(FacePntVector[k].pnt);
00371
00372 if (meshIt == MeshMap.end())
00373 {
00374 cout << "error3";
00375 return false;
00376 }
00377
00378 distSum = 0.0;
00379 for (unsigned int l=0; l<FacePntVector[k].distances.size(); ++l)
00380 distSum += FacePntVector[k].distances[l];
00381
00382 revSum = 0.0;
00383 for (unsigned int l=0; l<FacePntVector[k].distances.size(); ++l)
00384 {
00385 revSum += distSum/FacePntVector[k].distances[l];
00386
00387 if (((*meshIt).second).minCurv == -1e+3)
00388 ((*meshIt).second).minCurv = 0.0;
00389
00390 if (((*meshIt).second).maxCurv == 1e+3)
00391 ((*meshIt).second).maxCurv = 0.0;
00392
00393 ((*meshIt).second).minCurv += distSum*(FacePntVector[k].MinEdgeOff[l])/FacePntVector[k].distances[l];
00394 ((*meshIt).second).maxCurv += distSum*(FacePntVector[k].MaxEdgeOff[l])/FacePntVector[k].distances[l];
00395
00396 }
00397
00398 ((*meshIt).second).minCurv /= revSum;
00399 ((*meshIt).second).maxCurv /= revSum;
00400
00401 }
00402 FacePntVector.clear();
00403 }
00404
00405
00406
00407 Base::Builder3D log,log3d;
00408 Base::Vector3f pa,pb;
00409 char text[10];
00410 int w;
00411
00412
00413 for (meshIt = MeshMap.begin(); meshIt != MeshMap.end(); ++meshIt)
00414 {
00415 w = meshIt->second.index;
00416 m_MeshStruct[w].pnt = (*meshIt).first;
00417
00418 m_MeshStruct[w].minCurv = (((*meshIt).second).minCurv);
00419 m_MeshStruct[w].maxCurv = (((*meshIt).second).maxCurv);
00420
00421
00422 if (m_MeshStruct[w].maxCurv<10000000000)
00423 {
00424 snprintf(text,10,"%f",m_MeshStruct[w].minCurv);
00425
00426 log.addText(m_MeshStruct[w].pnt.x, m_MeshStruct[w].pnt.y, m_MeshStruct[w].pnt.z,text);
00427 }
00428
00429 if (MeanVec[w] == 1)
00430 log3d.addSinglePoint(m_MeshStruct[w].pnt,4,0,0,0);
00431 else if (MeanVec[w] == 2)
00432 log3d.addSinglePoint(m_MeshStruct[w].pnt,4,1,1,1);
00433 else
00434 log3d.addSinglePoint(m_MeshStruct[w].pnt,4,1,0,0);
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 }
00478
00479 log.saveToFile("c:/printCurv.iv");
00480 log3d.saveToFile("c:/triPnts.iv");
00481 logo.saveToFile("c:/NormalsCurv.iv");
00482
00483 MeshPntsCad = m_CadMesh.GetPoints();
00484
00485
00486 for (unsigned int j=0; j<m_FixFaces.size(); ++j)
00487 {
00488 TopoDS_Face aFace = TopoDS::Face(m_FixFaces[j]);
00489 TransferFaceTriangulationtoFreeCAD(aFace, FaceMesh);
00490 MeshPnts = FaceMesh.GetPoints();
00491 MeshFacets2 = m_CadMesh.GetFacets();
00492 MeshPntsCopy = MeshPnts;
00493 n = MeshPnts.size();
00494 TopLoc_Location aLocation;
00495
00496 Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);
00497 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
00498
00499 TColgp_Array1OfPnt aPoints(1, aNodes.Length());
00500 for ( Standard_Integer i = 1; i <= aNodes.Length(); i++)
00501 aPoints(i) = aNodes(i).Transformed(aLocation);
00502
00503 const TColgp_Array1OfPnt2d& aUVNodes = aTr->UVNodes();
00504
00505 BRepAdaptor_Surface aSurface(aFace);
00506 Base::Vector3f Pnt1, Pnt2;
00507 gp_Pnt2d par;
00508 gp_Pnt P;
00509 gp_Vec D1U, D1V;
00510 std::vector<bool> trans_check(m_MeshStruct.size(), false);
00511
00512 for (int i=1; i<n+1; ++i)
00513 {
00514 par = aUVNodes.Value(i);
00515 aSurface.D1(par.X(),par.Y(),P,D1U,D1V);
00516 P = aPoints(i);
00517 Pnt1.x = (float) P.X();
00518 Pnt1.y = (float) P.Y();
00519 Pnt1.z = (float) P.Z();
00520 meshIt = MeshMap.find(Pnt1);
00521 if (meshIt == MeshMap.end())
00522 {
00523 cout << "error";
00524 return false;
00525 }
00526
00527 D1U.Cross(D1V);
00528 D1U.Normalize();
00529 if (aFace.Orientation() == TopAbs_FORWARD) D1U.Scale(-1.0);
00530
00531 int g = ((*meshIt).second).index;
00532
00533 D1U.Scale(0.1);
00534 if(trans_check[g] == false)
00535 {
00536 m_dist_vec[g].x = - D1U.X();
00537 m_dist_vec[g].y = - D1U.Y();
00538 m_dist_vec[g].z = - D1U.Z();
00539
00540 MeshPntsCad[g].Set(MeshPntsCad[g].x - D1U.X(),
00541 MeshPntsCad[g].y - D1U.Y(),
00542 MeshPntsCad[g].z - D1U.Z());
00543
00544 (m_MeshStruct[g].pnt).Set(MeshPntsCad[g].x - D1U.X(),
00545 MeshPntsCad[g].y - D1U.Y(),
00546 MeshPntsCad[g].z - D1U.Z());
00547
00548 trans_check[g] = true;
00549 }
00550 }
00551 }
00552 m_CadMesh.Assign(MeshPntsCad, MeshFacets2);
00553
00554 return true;
00555 }
00556
00557
00558 bool SpringbackCorrection::Init()
00559 {
00560 m_EdgeStruct.clear();
00561 EdgeMap.clear();
00562 MeshMap.clear();
00563
00564 BRepTools::Clean(m_Shape);
00565 best_fit::Tesselate_Shape(m_Shape,m_CadMesh,(float) 0.1);
00566
00567 MeshCore::MeshTopoAlgorithm algo(m_CadMesh);
00568 algo.HarmonizeNormals();
00569
00570 MeshCore::MeshGeomFacet facet = m_CadMesh.GetFacet(0);
00571 if (facet.GetNormal().z < 0.0)
00572 algo.FlipNormals();
00573
00574 int n = m_CadMesh.CountFacets();
00575 Base::Vector3f normal;
00576
00577 MeshCore::MeshPointArray points = m_CadMesh.GetPoints();
00578 MeshCore::MeshFacetArray facets = m_CadMesh.GetFacets();
00579
00580 for (int i=0; i<n; ++i)
00581 {
00582 MeshCore::MeshGeomFacet face = m_CadMesh.GetFacet(i);
00583 normal = face.GetNormal();
00584
00585 if (normal.z < 0.0)
00586 {
00587 facets[i].FlipNormal();
00588 }
00589 }
00590
00591 m_CadMesh.Assign(points, facets);
00592
00593 double max = cMin;
00594 TopTools_IndexedDataMapOfShapeListOfShape anIndex;
00595 anIndex.Clear();
00596 TopExp aMap;
00597 aMap.MapShapesAndAncestors(m_Shape,TopAbs_EDGE,TopAbs_FACE,anIndex);
00598 TopExp_Explorer anExplorer, anExplorer2;
00599 TopoDS_Face aFace;
00600 EdgeStruct tempEdgeStruct;
00601 std::vector<EdgeStruct> EdgeVec;
00602 MeshCore::MeshKernel FaceMesh;
00603 std::vector<double> curvature(2);
00604 std::pair<TopoDS_Edge, std::vector<double> > aPair;
00605
00606 float maxOffset, minOffset;
00607
00608 for (anExplorer.Init(m_Shape,TopAbs_EDGE);anExplorer.More();anExplorer.Next())
00609 {
00610 tempEdgeStruct.aFace.clear();
00611 tempEdgeStruct.MaxOffset = 1e+10;
00612 tempEdgeStruct.MinOffset = -1e+10;
00613 tempEdgeStruct.anEdge = TopoDS::Edge(anExplorer.Current());
00614
00615 const TopTools_ListOfShape& aFaceList = anIndex.FindFromKey(tempEdgeStruct.anEdge);
00616 TopTools_ListIteratorOfListOfShape aListIterator;
00617
00618 for (aListIterator.Initialize(aFaceList);aListIterator.More(); aListIterator.Next())
00619 {
00620
00621 aFace = TopoDS::Face(aListIterator.Value());
00622 tempEdgeStruct.aFace.push_back(aFace);
00623 TransferFaceTriangulationtoFreeCAD(aFace, FaceMesh);
00624 curvature = MeshCurvature(aFace, FaceMesh);
00625
00626 if (aFace.Orientation() == TopAbs_REVERSED)
00627 {
00628 maxOffset = (float) -curvature[1];
00629 minOffset = (float) -curvature[0];
00630 }
00631 else
00632 {
00633 maxOffset = (float) curvature[0];
00634 minOffset = (float) curvature[1];
00635 }
00636
00637 if (maxOffset < tempEdgeStruct.MaxOffset)
00638 tempEdgeStruct.MaxOffset = maxOffset;
00639
00640 if (minOffset > tempEdgeStruct.MinOffset)
00641 tempEdgeStruct.MinOffset = minOffset;
00642 }
00643
00644
00645 if (tempEdgeStruct.MaxOffset > max)
00646 curvature[1] = tempEdgeStruct.MaxOffset;
00647 else
00648 curvature[1] = cMin;
00649
00650 if (-tempEdgeStruct.MinOffset > max)
00651 curvature[0] = tempEdgeStruct.MinOffset;
00652 else
00653 curvature[0] = -cMin;
00654
00655 aPair.first = tempEdgeStruct.anEdge;
00656 aPair.second = curvature;
00657 EdgeMap.insert(aPair);
00658
00659 }
00660 return true;
00661 }
00662
00663 bool SpringbackCorrection::Init_Setting(struct CuttingToolsSettings& set)
00664 {
00665 m_set = set;
00666 return true;
00667 }
00668
00669 bool SpringbackCorrection::SetFixEdges()
00670 {
00671 TopExp_Explorer anExplorer;
00672 TopoDS_Edge anEdge;
00673 std::map<TopoDS_Edge, std::vector<double>, Edge_Less>::iterator edge_it;
00674 std::vector<double> pair(2,0.0);
00675
00676 for (unsigned int i=0; i<m_FixFaces.size(); ++i)
00677 {
00678 for (anExplorer.Init(m_FixFaces[i],TopAbs_EDGE); anExplorer.More(); anExplorer.Next())
00679 {
00680 anEdge = TopoDS::Edge(anExplorer.Current());
00681 edge_it = EdgeMap.find(anEdge);
00682 edge_it->second = pair;
00683 }
00684 }
00685
00686 return true;
00687 }
00688
00689 bool SpringbackCorrection::TransferFaceTriangulationtoFreeCAD(const TopoDS_Face& aFace, MeshCore::MeshKernel& FaceMesh)
00690 {
00691 FaceMesh.Clear();
00692 MeshCore::MeshBuilder builder(FaceMesh);
00693 builder.Initialize(1000);
00694 Base::Vector3f Points[3];
00695
00696 TopLoc_Location aLocation;
00697
00698 Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);
00699 if (!aTr.IsNull())
00700 {
00701
00702 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
00703
00704 const Poly_Array1OfTriangle& triangles = aTr->Triangles();
00705
00706 TColgp_Array1OfPnt aPoints(1, aNodes.Length());
00707 for ( Standard_Integer i = 1; i <= aNodes.Length(); i++)
00708 aPoints(i) = aNodes(i).Transformed(aLocation);
00709
00710
00711 Standard_Integer nnn = aTr->NbTriangles();
00712 Standard_Integer nt,n1,n2,n3;
00713 for ( nt = 1 ; nt < nnn+1 ; nt++)
00714 {
00715
00716 triangles(nt).Get(n1,n2,n3);
00717
00718 gp_Pnt aPnt1 = aPoints(n1);
00719 Points[0].Set(float(aPnt1.X()),float(aPnt1.Y()),float(aPnt1.Z()));
00720 gp_Pnt aPnt2 = aPoints(n2);
00721 Points[1].Set((float) aPnt2.X(),(float) aPnt2.Y(),(float) aPnt2.Z());
00722 gp_Pnt aPnt3 = aPoints(n3);
00723 Points[2].Set((float) aPnt3.X(),(float) aPnt3.Y(),(float) aPnt3.Z());
00724
00725 MeshCore::MeshGeomFacet Face(Points[0],Points[1],Points[2]);
00726 builder.AddFacet(Face);
00727 }
00728
00729 }
00730
00731 else
00732 {
00733 throw Base::Exception("Empty face triangulation\n");
00734 }
00735
00736
00737 builder.Finish();
00738 return true;
00739
00740 }
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774 int SpringbackCorrection::GetBoundary(const MeshCore::MeshKernel &mesh, MeshCore::MeshPointArray &meshPnts)
00775 {
00776
00777
00778 std::list< std::vector <unsigned long> > BoundariesIndex;
00779 std::list< std::vector <unsigned long> >::iterator bInd;
00780
00781
00782 MeshCore::MeshAlgorithm algo(mesh);
00783 algo.GetMeshBorders(BoundariesIndex);
00784
00785 for (unsigned int i=0;i<meshPnts.size();++i)
00786 meshPnts[i].SetProperty(0);
00787
00788
00789 int inner_points = 0;
00790 for (bInd = BoundariesIndex.begin(); bInd != BoundariesIndex.end(); ++bInd)
00791 {
00792 for (unsigned int i=0;i< bInd->size();++i)
00793 {
00794 meshPnts[(*bInd).at(i)].SetProperty(1);
00795 }
00796
00797 }
00798 for (unsigned int i=0;i<meshPnts.size();++i)
00799 {
00800 if (meshPnts[i]._ulProp == 0)
00801 inner_points++;
00802 }
00803
00804 return (inner_points);
00805 }
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849 bool SpringbackCorrection::SmoothMesh(MeshCore::MeshKernel &Mesh, double d_max)
00850 {
00851 Base::Builder3D log;
00852 MeshCore::MeshKernel localMesh, Meshtmp;
00853 MeshCore::MeshPoint mpnt, spnt;
00854 MeshCore::MeshPointArray locPointArray, PointArray = Mesh.GetPoints();
00855 MeshCore::MeshFacetArray locFacetArray, FacetArray = Mesh.GetFacets();
00856
00857 MeshCore::MeshPointIterator v_it(Mesh);
00858 MeshCore::MeshRefPointToPoints vv_it(Mesh);
00859 std::set<unsigned long>::const_iterator pnt_it;
00860 MeshCore::MeshPointArray::_TConstIterator v_beg = Mesh.GetPoints().begin();
00861
00862 Base::Vector3f N, L, coor;
00863 int n = m_MeshStruct.size();
00864 int g;
00865
00866 for (v_it.Begin(); v_it.More(); v_it.Next())
00867 {
00868
00869 g = v_it.Position();
00870 spnt.Set(0.0, 0.0, 0.0);
00871 locPointArray.push_back(*v_it);
00872 spnt += *v_it;
00873 const std::set<unsigned long>& PntNei = vv_it[(*v_it)._ulProp];
00874
00875 if (PntNei.size() < 3)
00876 continue;
00877
00878 for (pnt_it = PntNei.begin(); pnt_it !=PntNei.end(); ++pnt_it)
00879 {
00880 locPointArray.push_back(v_beg[*pnt_it]);
00881 spnt += v_beg[*pnt_it];
00882 }
00883
00884 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)));
00885
00886 localMesh.Assign(locPointArray, locFacetArray);
00887
00888
00889
00890 MeshCore::MeshGeomFacet face;
00891 face._aclPoints[0] = locPointArray[0];
00892 face._aclPoints[1] = locPointArray[1];
00893 face._aclPoints[2] = locPointArray[2];
00894 localMesh.AddFacet(face);
00895
00896 MeshCore::MeshEigensystem pca(localMesh);
00897 pca.Evaluate();
00898 Base::Matrix4D T1 = pca.Transform();
00899
00900 N.x = (float) T1[0][0];
00901 N.y = (float) T1[0][1];
00902 N.z = (float) T1[0][2];
00903 L.Set(v_it->x - spnt.x, v_it->y - spnt.y, v_it->z - spnt.z);
00904 N.Normalize();
00905
00906
00907 if (N*L < 0.0)
00908 N.Scale(-1.0, -1.0, -1.0);
00909
00910 if ((*v_it)._ulProp == 2286)
00911 {
00912 log.addSinglePoint(spnt,4,1,0,0);
00913 log.addSinglePoint(*v_it,4,0,0,0);
00914 for (unsigned int i=0; i<locPointArray.size(); ++i)
00915 log.addSinglePoint(locPointArray[i],4);
00916
00917 for (int i=0; i<3; ++i)
00918 {
00919 coor.x = (float) T1[i][0];
00920 coor.y = (float) T1[i][1];
00921 coor.z = (float) T1[i][2];
00922
00923 coor.Normalize();
00924
00925 log.addSingleArrow(*v_it, *v_it + coor);
00926 }
00927
00928
00929
00930
00931 }
00932
00933 double d = d_max;
00934 if (fabs(N*L)< d_max) d = fabs(N*L);
00935 N.Scale((float) d,(float) d,(float) d);
00936
00937 PointArray[v_it.Position()].Set(v_it->x - N.x, v_it->y - N.y, v_it->z - N.z);
00938 locPointArray.clear();
00939 localMesh = Meshtmp;
00940 }
00941
00942 Mesh.Assign(PointArray, FacetArray);
00943 log.saveToFile("c:/checkNormals.iv");
00944
00945 return true;
00946 }
00947
00948 bool SpringbackCorrection::SmoothMesh(MeshCore::MeshKernel &Mesh, std::vector<int> ind, double d_max)
00949 {
00950 Base::Builder3D log;
00951 MeshCore::MeshKernel localMesh, Meshtmp;
00952 MeshCore::MeshPoint mpnt, spnt;
00953 MeshCore::MeshPointArray locPointArray, PointArray = Mesh.GetPoints();
00954 MeshCore::MeshFacetArray locFacetArray, FacetArray = Mesh.GetFacets();
00955
00956 MeshCore::MeshPointIterator v_it(Mesh);
00957 MeshCore::MeshRefPointToPoints vv_it(Mesh);
00958 std::set<unsigned long>::const_iterator pnt_it;
00959 MeshCore::MeshPointArray::_TConstIterator v_beg = Mesh.GetPoints().begin();
00960
00961 Base::Vector3f N, L, coor;
00962
00963 int n = ind.size();
00964
00965 for (int i=0; i<n; ++i)
00966 {
00967 v_it.Set(ind[i]);
00968 spnt.Set(0.0, 0.0, 0.0);
00969 locPointArray.push_back(*v_it);
00970 spnt += *v_it;
00971 const std::set<unsigned long>& PntNei = vv_it[(*v_it)._ulProp];
00972
00973 if (PntNei.size() < 3)
00974 continue;
00975
00976 for (pnt_it = PntNei.begin(); pnt_it !=PntNei.end(); ++pnt_it)
00977 {
00978 locPointArray.push_back(v_beg[*pnt_it]);
00979 spnt += v_beg[*pnt_it];
00980 }
00981
00982 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)));
00983
00984 localMesh.Assign(locPointArray, locFacetArray);
00985
00986
00987
00988 MeshCore::MeshGeomFacet face;
00989 face._aclPoints[0] = locPointArray[0];
00990 face._aclPoints[1] = locPointArray[1];
00991 face._aclPoints[2] = locPointArray[2];
00992 localMesh.AddFacet(face);
00993
00994 MeshCore::MeshEigensystem pca(localMesh);
00995 pca.Evaluate();
00996 Base::Matrix4D T1 = pca.Transform();
00997
00998 N.x = (float) T1[0][0];
00999 N.y = (float) T1[0][1];
01000 N.z = (float) T1[0][2];
01001 L.Set(v_it->x - spnt.x, v_it->y - spnt.y, v_it->z - spnt.z);
01002 N.Normalize();
01003
01004
01005 if (N*L < 0.0)
01006 N.Scale(-1.0, -1.0, -1.0);
01007
01008 if ((*v_it)._ulProp == 2286)
01009 {
01010 log.addSinglePoint(spnt,4,1,0,0);
01011 log.addSinglePoint(*v_it,4,0,0,0);
01012 for (unsigned int i=0; i<locPointArray.size(); ++i)
01013 log.addSinglePoint(locPointArray[i],4);
01014
01015 for (int i=0; i<3; ++i)
01016 {
01017 coor.x = (float) T1[i][0];
01018 coor.y = (float) T1[i][1];
01019 coor.z = (float) T1[i][2];
01020
01021 coor.Normalize();
01022
01023 log.addSingleArrow(*v_it, *v_it + coor);
01024 }
01025
01026
01027
01028
01029 }
01030
01031 double d = d_max;
01032 if (fabs(N*L)< d_max) d = fabs(N*L);
01033 N.Scale((float) d,(float) d,(float) d);
01034
01035 PointArray[v_it.Position()].Set(v_it->x - N.x, v_it->y - N.y, v_it->z - N.z);
01036 locPointArray.clear();
01037 localMesh = Meshtmp;
01038 }
01039
01040 Mesh.Assign(PointArray, FacetArray);
01041 log.saveToFile("c:/checkNormals.iv");
01042
01043 return true;
01044 }
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079 std::vector<int> SpringbackCorrection::InitFaceCheck(MeshCore::MeshKernel &mesh, int degree)
01080 {
01081 std::vector<int> faceInd;
01082 double tol = degree;
01083 double alpha;
01084 MeshCore::MeshFacetIterator fIt(mesh);
01085 MeshCore::MeshPointIterator mIt(mesh);
01086 MeshCore::MeshRefPointToFacets p2fIt(mesh);
01087 Base::Vector3f normal, base, gpnt;
01088 Base::Builder3D log;
01089
01090 MeshCore::MeshPointArray mPnts = mesh.GetPoints();
01091 MeshCore::MeshFacetArray mFacets = mesh.GetFacets();
01092 MeshCore::MeshFacetArray::_TConstIterator f_beg = mesh.GetFacets().begin();
01093
01094 int n = mesh.CountFacets();
01095
01096
01097 for (int i=0; i<n; ++i)
01098 {
01099 MeshCore::MeshGeomFacet face = mesh.GetFacet(i);
01100
01101 normal = face.GetNormal();
01102 normal.Normalize();
01103 base = normal;
01104 base.z = 0.0;
01105 base.Normalize();
01106
01107 gpnt = face.GetGravityPoint();
01108
01109
01110 if (normal.z < 0.0)
01111 {
01112 alpha = 90.0 + acos(normal*base)*180.0/PI;
01113
01114 }
01115 else
01116 {
01117 alpha = 90.0 - acos(normal*base)*180.0/PI;
01118
01119 }
01120
01121 if (alpha > tol)
01122 {
01123
01124 mFacets[i].SetProperty(0);
01125
01126 for (int j=0; j<3; ++j)
01127 {
01128 const std::set<unsigned long>& faceSet = p2fIt[mFacets[i]._aulPoints[j]];
01129
01130 for (std::set<unsigned long>::const_iterator it = faceSet.begin(); it != faceSet.end(); ++it)
01131 {
01132 f_beg[*it].SetProperty(5);
01133 }
01134 }
01135
01136 log.addSingleArrow(gpnt,gpnt+normal,4,1,0,0);
01137 }
01138 else
01139 {
01140 mFacets[i].SetProperty(1);
01141 faceInd.push_back(i);
01142 }
01143 }
01144
01145 log.saveToFile("c:/normalschecker.iv");
01146
01147 MeshCore::MeshFacetArray mFacets2 = mesh.GetFacets();
01148
01149 for (unsigned int i=0; i<mFacets2.size(); ++i)
01150 {
01151 if (mFacets2[i]._ulProp == 5)
01152 {
01153 mFacets[i].SetProperty(0);
01154 }
01155 }
01156
01157 mesh.Assign(mPnts, mFacets);
01158
01159 log.saveToFile("c:/angles.iv");
01160 return faceInd;
01161 }
01162
01163 std::vector<int> SpringbackCorrection::FaceCheck(MeshCore::MeshKernel &mesh, int degree)
01164 {
01165 std::vector<int> faceInd;
01166 double tol = degree;
01167 double alpha;
01168 MeshCore::MeshFacetIterator fIt(mesh);
01169 MeshCore::MeshPointIterator mIt(mesh);
01170 Base::Vector3f normal, base, gpnt;
01171 Base::Builder3D log;
01172
01173
01174 MeshCore::MeshPointArray mPnts = mesh.GetPoints();
01175 MeshCore::MeshFacetArray mFacets = mesh.GetFacets();
01176
01177 int n = mesh.CountFacets();
01178
01179 for (int i=0; i<n; ++i)
01180 {
01181 MeshCore::MeshGeomFacet face = mesh.GetFacet(i);
01182 face.CalcNormal();
01183 normal = face.GetNormal();
01184 normal.Normalize();
01185 base = normal;
01186 base.z = 0.0;
01187 base.Normalize();
01188
01189 gpnt = face.GetGravityPoint();
01190
01191 if (normal.z < 0.0)
01192 {
01193 alpha = 90.0 + acos(normal*base)*180.0/PI;
01194 log.addSingleArrow(gpnt,gpnt+normal,2,1,0,0);
01195 }
01196 else
01197 alpha = 90.0 - acos(normal*base)*180.0/PI;
01198
01199 if (alpha > tol)
01200 {
01201 faceInd.push_back(i);
01202 cout << "i: " << i << ", angle: " << alpha << endl;
01203 }
01204 }
01205
01206 log.saveToFile("c:/angles.iv");
01207 return faceInd;
01208 }
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230 bool SpringbackCorrection::Perform(int deg_Tol, bool out)
01231 {
01232 unsigned int NumRef;
01233 std::vector<double> dist_vec;
01234
01235
01236
01237
01238
01239
01240 Base::Vector3f nullvec(0.0,0.0,0.0);
01241 m_dist_vec.resize(m_CadMesh.CountPoints(), nullvec);
01242
01243 cout << "SetFixEdges" << endl;
01244
01245 SetFixEdges();
01246
01247 const MeshCore::MeshKernel RefMesh23 = m_CadMesh;
01248
01249 cout << "CalcCurv" << endl;
01250
01251 if (!CalcCurv())
01252 return false;
01253
01254
01255
01256
01257 const MeshCore::MeshKernel RefMesh = m_CadMesh;
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280 m_normals.clear();
01281 m_normals.resize(m_MeshStruct.size());
01282
01283
01284
01285 for (unsigned int i=0; i<m_normals.size(); ++i)
01286 {
01287 m_normals[i] = m_MeshStruct[i].normal;
01288
01289 }
01290
01291
01292
01293
01294 best_fit befi;
01295 befi.m_normals = m_normals;
01296 befi.m_CadMesh = m_CadMesh;
01297
01298 m_error.resize(m_CadMesh.CountPoints(), 0.0);
01299
01300 for(unsigned int i=0; i<m_MeshVec.size(); ++i)
01301 {
01302 befi.CompTotalError(m_MeshVec[i]);
01303 }
01304
01305
01306
01307 int n = m_CadMesh.CountPoints();
01308 for (int i=0; i<n; ++i)
01309 {
01310 m_MeshStruct[i].error = befi.m_error[i];
01311
01312 if (m_MeshStruct[i].error < 0)
01313 {
01314 if ((m_MeshStruct[i].maxCurv - m_set.master_radius) < 0.0)
01315 m_Offset.push_back(0.0);
01316 else if (-m_MeshStruct[i].error > (m_MeshStruct[i].maxCurv - m_set.master_radius))
01317 m_Offset.push_back(m_MeshStruct[i].maxCurv - m_set.master_radius);
01318 else
01319 m_Offset.push_back(-m_MeshStruct[i].error);
01320 }
01321 else
01322 {
01323 if ((m_MeshStruct[i].minCurv + m_set.slave_radius) > 0.0)
01324 m_Offset.push_back(0.0);
01325 else if (m_MeshStruct[i].error > -(m_MeshStruct[i].minCurv + m_set.slave_radius))
01326 m_Offset.push_back(m_MeshStruct[i].minCurv + m_set.slave_radius);
01327 else
01328 m_Offset.push_back(-m_MeshStruct[i].error);
01329 }
01330 }
01331
01332
01333
01334
01335
01336
01337 for (int i=0; i<n; ++i)
01338 {
01339 m_normals[i].Scale((float) (m_set.correction_factor*m_Offset[i]),
01340 (float) (m_set.correction_factor*m_Offset[i]),
01341 (float) (m_set.correction_factor*m_Offset[i]));
01342 }
01343
01344 for(int i=0; i<m_normals.size(); ++i)
01345 {
01346 m_dist_vec[i] = m_normals[i];
01347 }
01348
01349 if(out==true)
01350 {
01351 MeshCore::MeshPointArray mpts = RefMesh23.GetPoints();
01352
01353 Base::Builder3D loo;
01354 ofstream anOutputFile;
01355 anOutputFile.open("c:/catia_offset.txt");
01356 anOutputFile.precision(7);
01357
01358 for(int i=0; i< mpts.size(); ++i)
01359 {
01360 loo.addSingleArrow(mpts[i], mpts[i] + m_dist_vec[i]);
01361 anOutputFile << mpts[i].x << " " << mpts[i].y << " " << mpts[i].z << " " << m_dist_vec[i].x << " " << m_dist_vec[i].y << " " << m_dist_vec[i].z << endl;
01362 }
01363
01364 loo.saveToFile("c:/prpopo.iv");
01365 anOutputFile.close();
01366 return true;
01367 }
01368
01369
01370
01371 std::vector<int> tmpVec;
01372 tmpVec = FaceCheck(m_CadMesh, deg_Tol+1);
01373
01374 NumRef = (int) tmpVec.size();
01375
01376 MeshCore::MeshPointArray pntAr = m_CadMesh.GetPoints();
01377 MeshCore::MeshFacetArray facAr = m_CadMesh.GetFacets();
01378
01379
01380 Base::Builder3D log3d;
01381 for (int i=0; i<n; ++i)
01382 {
01383 log3d.addSingleArrow(pntAr[i], pntAr[i] + m_normals[i]);
01384 pntAr[i].Set(pntAr[i].x + m_normals[i].x, pntAr[i].y + m_normals[i].y, pntAr[i].z + m_normals[i].z);
01385 }
01386
01387 log3d.saveToFile("c:/project2result.iv");
01388
01389 m_CadMesh.Assign(pntAr, facAr);
01390
01391
01392 std::vector<Base::Vector3f> normalsRef = m_normals;
01393 int cc = 0;
01394
01395
01396
01397
01398 int cm = 49;
01399 InitFaceCheck(m_CadMesh, deg_Tol+1);
01400 MeshCore::MeshFacetArray facAr2 = m_CadMesh.GetFacets();
01401
01402 while (true)
01403 {
01404 tmpVec = FaceCheck(m_CadMesh, deg_Tol+1);
01405 cout << "remaining: " << tmpVec.size() << endl;
01406 if (tmpVec.size() == NumRef || cm == 0)
01407 {
01408 cout << cm << "left" << endl;
01409 break;
01410 }
01411
01412 --cm;
01413 MeshCore::MeshPointArray pntAr2 = RefMesh.GetPoints();
01414
01415 for (unsigned int i=0; i<pntAr2.size(); ++i)
01416 {
01417 m_normals[i].Normalize();
01418 m_normals[i].Scale((cm*normalsRef[i].Length())/50,(cm*normalsRef[i].Length())/50, (cm*normalsRef[i].Length())/50);
01419 pntAr2[i].Set(pntAr2[i].x + m_normals[i].x, pntAr2[i].y + m_normals[i].y, pntAr2[i].z + m_normals[i].z);
01420 }
01421
01422 m_CadMesh.Assign(pntAr2, facAr2);
01423 }
01424
01425 for(int i=0; i< m_normals.size(); ++i)
01426 {
01427 m_dist_vec[i] += m_normals[i];
01428 }
01429
01430
01431
01432
01433
01434 MeshCore::MeshFacetArray mFacets = m_CadMesh.GetFacets();
01435 MeshCore::MeshPointArray mPoints = m_CadMesh.GetPoints();
01436 int num = mFacets.size();
01437
01438 for (int i=0; i<num; ++i) mFacets[i].ResetFlag(MeshCore::MeshFacet::VISIT);
01439
01440 m_RingCurrent = 0;
01441 std::vector<unsigned long> aRegion;
01442 std::vector< std::pair<unsigned long, double> > skals;
01443 std::vector< std::vector< std::pair<unsigned long, double> > > RegionSkals;
01444
01445 MeshCore::MeshBuilder builder(m_Mesh_vis);
01446 builder.Initialize(10000);
01447 MeshCore::MeshBuilder builder2(m_Mesh_vis2);
01448 builder2.Initialize(10000);
01449
01450 for (int i=0; i<num; ++i)
01451 {
01452
01453 cout << i << " von " << num << endl;
01454 for (int m=0; m<num; ++m)
01455 {
01456 if (mFacets[m]._ulProp == 0)
01457 {
01458 mFacets[m].SetFlag(MeshCore::MeshFacet::VISIT);
01459 }
01460 }
01461
01462 if (mFacets[i]._ulProp == 0)
01463 {
01464 MeshCore::MeshGeomFacet Face(mPoints[mFacets[i]._aulPoints[0]],
01465 mPoints[mFacets[i]._aulPoints[1]],
01466 mPoints[mFacets[i]._aulPoints[2]]);
01467
01468 builder.AddFacet(Face);
01469 }
01470 else
01471 {
01472 MeshCore::MeshGeomFacet Face2(mPoints[mFacets[i]._aulPoints[0]],
01473 mPoints[mFacets[i]._aulPoints[1]],
01474 mPoints[mFacets[i]._aulPoints[2]]);
01475
01476 builder2.AddFacet(Face2);
01477 }
01478
01479
01480 m_CadMesh.Assign(mPoints, mFacets);
01481
01482 cout << "a" << endl;
01483 if (mFacets[i]._ulProp == 1 && !mFacets[i].IsFlag(MeshCore::MeshFacet::VISIT))
01484
01485 {
01486
01487 cout << "b" << endl;
01488 m_RingVector.clear();
01489 m_RingVector.push_back(i);
01490 m_RegionVector.push_back(m_RingVector);
01491 m_RingVector.clear();
01492
01493 m_RingCurrent = 0;
01494
01495 m_CadMesh.VisitNeighbourFacets(*this,i);
01496
01497 for (unsigned int j=0; j<m_RegionVector.size(); ++j)
01498 {
01499 cout << "c" << endl;
01500 for (unsigned int k=0; k<m_RegionVector[j].size(); ++k)
01501 {
01502 aRegion.push_back(m_RegionVector[j][k]);
01503
01504 }
01505 }
01506
01507
01508
01509
01510
01511
01512
01513
01514 m_Regions.push_back(aRegion);
01515
01516
01517
01518 for (int l=0; l<num; ++l) mFacets[l]._ucFlag = 0;
01519
01520 cout << "d" << endl;
01521
01522 for (unsigned int l=0; l<m_Regions.size(); ++l)
01523 for (unsigned int m=0; m<m_Regions[l].size(); ++m)
01524 mFacets[m_Regions[l][m]].SetFlag(MeshCore::MeshFacet::VISIT);
01525
01526
01527
01528 skals = RegionEvaluate(m_CadMesh, aRegion, normalsRef);
01529 RegionSkals.push_back(skals);
01530 skals.clear();
01531
01532 m_RegionVector.clear();
01533 aRegion.clear();
01534
01535 cout << "e" << endl;
01536
01537 }
01538 }
01539
01540 builder.Finish();
01541 builder2.Finish();
01542
01543 cout << "fast" << endl;
01544
01545 Base::Builder3D logg;
01546 double d;
01547
01548
01549
01550 for (unsigned int i=0; i<RegionSkals.size(); ++i)
01551 {
01552 cout << i << endl;
01553 d = double(i)/double(RegionSkals.size()-1.0);
01554 cout << d << endl;
01555 for (unsigned int j=0; j<RegionSkals[i].size(); ++j)
01556 {
01557
01558 logg.addSinglePoint((float) mPoints[RegionSkals[i][j].first].x,
01559 (float) mPoints[RegionSkals[i][j].first].y,
01560 (float) mPoints[RegionSkals[i][j].first].z,3,(float) d,(float) d,(float) d);
01561
01562
01563 }
01564 }
01565
01566 logg.saveToFile("c:/regions.iv");
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592 tmpVec = InitFaceCheck(m_CadMesh, deg_Tol+1);
01593
01594 cout << " glob: " << tmpVec.size() << endl;
01595
01596
01597 unsigned long ind;
01598
01599 MeshCore::MeshPointArray tmpPnts = m_CadMesh.GetPoints();
01600 MeshCore::MeshFacetArray tmpFact = m_CadMesh.GetFacets();
01601
01602 Base::Builder3D logic;
01603 int cm_ref = 50-cm;
01604
01605 for (unsigned int i=0; i<RegionSkals.size(); ++i)
01606 {
01607 cm = cm_ref;
01608
01609 while (true)
01610 {
01611 tmpVec = FaceCheck(m_CadMesh, deg_Tol+1);
01612 cout << "remaining: " << tmpVec.size() << endl;
01613
01614 if (tmpVec.size() > NumRef || cm == 0)
01615 {
01616 tmpPnts = m_CadMesh.GetPoints();
01617
01618 for (unsigned int k=0; k<tmpVec.size(); ++k)
01619 {
01620 for (int l=0; l<3; ++l)
01621 {
01622 logic.addSinglePoint(tmpPnts[tmpFact[tmpVec[k]]._aulPoints[l]].x,
01623 tmpPnts[tmpFact[tmpVec[k]]._aulPoints[l]].y,
01624 tmpPnts[tmpFact[tmpVec[k]]._aulPoints[l]].z,5,0,0,1);
01625 }
01626 }
01627
01628
01629 logic.saveToFile("c:/tired.iv");
01630
01631 for (unsigned int j=0; j<RegionSkals[i].size(); ++j)
01632 {
01633 ind = RegionSkals[i][j].first;
01634 m_normals[ind].Normalize();
01635 m_normals[ind].Scale(-normalsRef[ind].Length()/50,
01636 -normalsRef[ind].Length()/50,
01637 -normalsRef[ind].Length()/50);
01638
01639 tmpPnts[ind].Set(tmpPnts[ind].x + m_normals[ind].x,
01640 tmpPnts[ind].y + m_normals[ind].y,
01641 tmpPnts[ind].z + m_normals[ind].z);
01642
01643
01644 m_dist_vec[ind] += m_normals[ind];
01645
01646
01647 }
01648
01649 m_CadMesh.Assign(tmpPnts, tmpFact);
01650 break;
01651 }
01652
01653 tmpPnts = m_CadMesh.GetPoints();
01654
01655 for (unsigned int j=0; j<RegionSkals[i].size(); ++j)
01656 {
01657 ind = RegionSkals[i][j].first;
01658
01659 m_normals[ind].Normalize();
01660 m_normals[ind].Scale((normalsRef[ind].Length())/50,
01661 (normalsRef[ind].Length())/50,
01662 (normalsRef[ind].Length())/50);
01663
01664 tmpPnts[ind].Set(tmpPnts[ind].x + m_normals[ind].x,
01665 tmpPnts[ind].y + m_normals[ind].y,
01666 tmpPnts[ind].z + m_normals[ind].z);
01667
01668 m_dist_vec[ind] += m_normals[ind];
01669 }
01670
01671 m_CadMesh.Assign(tmpPnts, tmpFact);
01672 --cm;
01673 }
01674 }
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709 return true;
01710 }
01711
01712 std::vector< std::pair<unsigned long, double> > SpringbackCorrection::RegionEvaluate(const MeshCore::MeshKernel &mesh, std::vector<unsigned long> &RegionFacets, std::vector<Base::Vector3f> &normals)
01713 {
01714 std::list< std::vector <Base::Vector3f> > Borders;
01715 std::list< std::vector <Base::Vector3f> >::iterator bIt;
01716 std::map <unsigned long, Base::Vector3f> RegionMap;
01717 std::map <unsigned long, Base::Vector3f>::iterator rIt;
01718 std::map <double, unsigned long> DistMap;
01719 std::map <double, unsigned long>::iterator dIt;
01720 std::pair<unsigned long, Base::Vector3f> Ind2Pnt;
01721 std::pair<double, unsigned long> Dist2Ind;
01722
01723 std::vector< std::pair<double, unsigned long> > dists;
01724 std::vector< std::pair< unsigned long, double> > skals;
01725
01726 MeshCore::MeshAlgorithm algo(mesh);
01727 algo.GetFacetBorders(RegionFacets, Borders);
01728
01729 MeshCore::MeshFacetArray facets = mesh.GetFacets();
01730 MeshCore::MeshPointArray points = mesh.GetPoints();
01731
01732
01733 for (unsigned int i=0; i<RegionFacets.size(); ++i)
01734 {
01735 for (int j=0; j<3; ++j)
01736 {
01737 Ind2Pnt.first = facets[RegionFacets[i]]._aulPoints[j];
01738 Ind2Pnt.second = points[Ind2Pnt.first];
01739
01740 RegionMap.insert(Ind2Pnt);
01741 }
01742
01743 }
01744
01745
01746
01747 Base::Vector3f distVec;
01748 double distVal;
01749
01750 for (rIt = RegionMap.begin(); rIt != RegionMap.end(); ++rIt)
01751 {
01752 distVal = 1e+3;
01753 for (bIt = Borders.begin(); bIt != Borders.end(); ++bIt)
01754 {
01755 for (unsigned int i=0; i< bIt->size(); ++i)
01756 {
01757 distVec = (*rIt).second - (*bIt).at(i);
01758
01759 if (distVec.Length() < distVal)
01760 distVal = distVec.Length();
01761 }
01762 }
01763
01764 Dist2Ind.first = distVal;
01765 Dist2Ind.second = (*rIt).first;
01766
01767 dists.push_back(Dist2Ind);
01768 DistMap.insert(Dist2Ind);
01769 }
01770
01771 dIt = DistMap.end();
01772 --dIt;
01773 double d_max = (*dIt).first;
01774 std::pair<unsigned long, double> pair;
01775
01776 for (unsigned int i=0; i<dists.size(); ++i)
01777 {
01778 pair.first = dists[i].second;
01779
01780 if (dists[i].first != 0.0)
01781 pair.second = ( (cos( ((dists[i].first * PI) / d_max) - PI) + 1) / 2);
01782 else
01783 pair.second = 0.0;
01784
01785 skals.push_back(pair);
01786 normals[pair.first].Scale((float) pair.second, (float) pair.second, (float) pair.second);
01787 }
01788
01789 return skals;
01790 }
01791
01792
01793
01794 bool SpringbackCorrection::FacetRegionGrowing(MeshCore::MeshKernel &mesh,
01795 std::vector<MeshCore::MeshFacet> &FacetRegion,
01796 MeshCore::MeshFacetArray &mFacets)
01797 {
01798 MeshCore::MeshRefFacetToFacets ff_It(mesh);
01799
01800 MeshCore::MeshFacet facet = FacetRegion.back();
01801 const std::set<unsigned long>& FacetNei = ff_It[facet._ulProp];
01802 MeshCore::MeshFacetArray::_TConstIterator f_beg = mesh.GetFacets().begin();
01803
01804 std::set<unsigned long>::const_iterator f_it;
01805 for (f_it = FacetNei.begin(); f_it != FacetNei.end(); ++f_it)
01806 {
01807 if (f_beg[*f_it]._ucFlag == MeshCore::MeshFacet::VISIT)
01808 {
01809 FacetRegion.push_back(f_beg[*f_it]);
01810 mFacets[f_beg[*f_it]._ulProp].SetFlag(MeshCore::MeshFacet::INVALID);
01811 FacetRegionGrowing(mesh, FacetRegion, mFacets);
01812 }
01813 }
01814
01815 return true;
01816 }
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853 bool SpringbackCorrection::GetCurvature(TopoDS_Face aFace)
01854 {
01855 Base::Builder3D log;
01856 Handle_Geom_Surface geom_surface;
01857 geom_surface = BRep_Tool::Surface(aFace);
01858 gp_Pnt proPnt;
01859 double u_par,v_par,k1,k2;
01860 gp_Vec D1U,D1V,D2U,D2V,D2UV;
01861 Base::Vector3f p1,p2;
01862
01863 MeshCore::MeshPointArray PointArray = m_Mesh.GetPoints();
01864 MeshCore::MeshFacetArray FacetArray = m_Mesh.GetFacets();
01865
01866 MeshCore::MeshPointIterator p_it(m_Mesh);
01867
01868 m_CurvMax.resize(PointArray.size());
01869
01870 for (unsigned int i=0; i<PointArray.size(); ++i)
01871 {
01872
01873 proPnt.SetX(PointArray[i].x);
01874 proPnt.SetY(PointArray[i].y);
01875 proPnt.SetZ(PointArray[i].z);
01876
01877 GeomAPI_ProjectPointOnSurf aProjection(proPnt,geom_surface);
01878 aProjection.LowerDistanceParameters(u_par,v_par);
01879
01880
01881 geom_surface->D2(u_par,v_par,proPnt,D1U,D1V,D2U,D2V,D2UV);
01882
01883
01884 k1 = D1U.CrossMagnitude(D2U) / D1U.Magnitude();
01885 k2 = D1V.CrossMagnitude(D2V) / D1V.Magnitude();
01886
01887
01888
01889
01890 if (abs(k1)>abs(k2))
01891 {
01892 m_CurvMax[i] = 1/k1;
01893 }
01894 else
01895 if (k2!=0)
01896 m_CurvMax[i] = 1/k2;
01897 else
01898 m_CurvMax[i] = 100;
01899
01900
01901 D1U.Cross(D1V);
01902 D1U.Normalize();
01903 D1U.Scale(m_CurvMax[i]);
01904
01905 p1.x = (float) (proPnt.X() + D1U.X());
01906 p1.y = (float) (proPnt.Y() + D1U.Y());
01907 p1.z = (float) (proPnt.Z() + D1U.Z());
01908
01909 p2.x = (float) proPnt.X();
01910 p2.y = (float) proPnt.Y();
01911 p2.z = (float) proPnt.Z();
01912
01913 log.addSingleLine(p2, p1, 1 ,0, 0, 0 );
01914 }
01915
01916
01917 MeshCore::MeshPointIterator v_it(m_Mesh);
01918 MeshCore::MeshRefPointToPoints vv_it(m_Mesh);
01919 MeshCore::MeshPointArray::_TConstIterator v_beg = m_Mesh.GetPoints().begin();
01920 std::set<unsigned long> PntNei;
01921 std::set<unsigned long> PntNei2;
01922 std::set<unsigned long> PntNei3;
01923 std::set<unsigned long> PntNei4;
01924 std::set<unsigned long>::iterator pnt_it1;
01925 std::set<unsigned long>::iterator pnt_it2;
01926 std::set<unsigned long>::iterator pnt_it3;
01927 std::set<unsigned long>::iterator pnt_it4;
01928 std::vector<unsigned long> nei;
01929 double curv;
01930
01931 std::vector<double> CurvCop = m_CurvMax;
01932
01933 for (v_it.Begin(); v_it.More(); v_it.Next())
01934 {
01935 PntNei = vv_it[v_it.Position()];
01936 curv = m_CurvMax[v_it.Position()];
01937
01938 for (pnt_it1 = PntNei.begin(); pnt_it1 !=PntNei.end(); ++pnt_it1)
01939 {
01940 if (m_CurvMax[v_beg[*pnt_it1]._ulProp] < curv)
01941 curv = m_CurvMax[v_beg[*pnt_it1]._ulProp];
01942
01943 PntNei2 = vv_it[v_beg[*pnt_it1]._ulProp];
01944 for (pnt_it2 = PntNei2.begin(); pnt_it2 !=PntNei2.end(); ++pnt_it2)
01945 {
01946 if (m_CurvMax[v_beg[*pnt_it2]._ulProp] < curv)
01947 curv = m_CurvMax[v_beg[*pnt_it2]._ulProp];
01948
01949
01950 PntNei3 = vv_it[v_beg[*pnt_it2]._ulProp];
01951 for (pnt_it3 = PntNei3.begin(); pnt_it3 !=PntNei3.end(); ++pnt_it3)
01952 {
01953 if (m_CurvMax[v_beg[*pnt_it3]._ulProp] < curv)
01954 curv = m_CurvMax[v_beg[*pnt_it3]._ulProp];
01955
01956 PntNei4 = vv_it[v_beg[*pnt_it3]._ulProp];
01957 for (pnt_it4 = PntNei4.begin(); pnt_it4 !=PntNei4.end(); ++pnt_it4)
01958 {
01959 if (m_CurvMax[v_beg[*pnt_it4]._ulProp] < curv)
01960 curv = m_CurvMax[v_beg[*pnt_it4]._ulProp];
01961 }
01962 }
01963 }
01964 }
01965
01966 CurvCop[v_it.Position()] = curv;
01967 }
01968
01969 m_CurvMax = CurvCop;
01970
01971
01972 return true;
01973 }
01974
01975
01976
01977
01978 std::vector<double> SpringbackCorrection::MeshCurvature(const TopoDS_Face& aFace, const MeshCore::MeshKernel& mesh)
01979 {
01980
01981 TopLoc_Location aLocation;
01982 Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);
01983 const TColgp_Array1OfPnt2d& aUVNodes = aTr->UVNodes();
01984 int n = aUVNodes.Length();
01985 BRepAdaptor_Surface aSurface(aFace);
01986
01987 gp_Pnt2d par;
01988 gp_Pnt P;
01989 gp_Vec D1U, D1V, D2U, D2V, D2UV, nor, xvv, xuv, xuu;
01990 double H,K;
01991
01992 std::vector<double> aMaxCurve, aMinCurve;
01993 std::vector<double> curv(2);
01994
01995 for (int i=0; i<n; ++i)
01996 {
01997 par = aUVNodes.Value(i+1);
01998 aSurface.D2(par.X(),par.Y(),P,D1U,D1V,D2U,D2V,D2UV);
01999
02000
02001 nor = D1U;
02002 nor.Cross(D1V);
02003 nor.Normalize();
02004
02005 xvv = D2V;
02006 xuv = D2UV;
02007 xuu = D2U;
02008
02009 xvv.Multiply(D1U*D1U);
02010 xuv.Multiply(2*(D1U*D1V));
02011 xuu.Multiply(D1V*D1V);
02012
02013 H = ((xvv - xuv + xuu)*nor);
02014 H /= 2*((D1U*D1U)*(D1V*D1V) - (D1U*D1V)*(D1U*D1V));
02015 K = ((nor*D2U)*(nor*D2V) - (nor*D2UV)*(nor*D2UV))/((D1U*D1U)*(D1V*D1V) - (D1U*D1V)*(D1U*D1V));
02016
02017
02018 aMaxCurve.push_back(-(H - sqrt(H*H - K)));
02019 aMinCurve.push_back(-(H + sqrt(H*H - K)));
02020
02021 }
02022
02023
02024
02025 double maxCurv = 0.0;
02026 double avgCurv = 0.0;
02027 double tmp1 = 1e+10;
02028 double tmp2 = -1e+10;
02029
02030 double mean_curvMax = 0.0, mean_curvMin = 0.0;
02031 int c1 = 0, c2 = 0;
02032
02033 m_CurvPos.clear();
02034 m_CurvNeg.clear();
02035 m_CurvMax.clear();
02036 m_CurvPos.resize(mesh.CountPoints());
02037 m_CurvNeg.resize(mesh.CountPoints());
02038 m_CurvMax.resize(mesh.CountPoints());
02039
02040 for ( unsigned long i=0; i<n; i++ )
02041 {
02042 if (aMaxCurve[i] > 0) m_CurvPos[i] = 1 / aMaxCurve[i];
02043 else m_CurvPos[i] = 1e+10;
02044
02045 if (aMinCurve[i] < 0) m_CurvNeg[i] = 1 / aMinCurve[i];
02046 else m_CurvNeg[i] = -1e+10;
02047
02048 if (m_CurvPos[i] < tmp1)
02049 tmp1 = m_CurvPos[i];
02050
02051 if (m_CurvNeg[i] > tmp2)
02052 tmp2 = m_CurvNeg[i];
02053
02054 if (aMaxCurve[i] > 0)
02055 {
02056 ++c1;
02057 mean_curvMax += 1/aMaxCurve[i];
02058 }
02059
02060 if (aMinCurve[i] < 0)
02061 {
02062 ++c2;
02063 mean_curvMin += 1/aMinCurve[i];
02064 }
02065 }
02066
02067 if (c1==0)
02068 mean_curvMax = 1e+3;
02069 else
02070 mean_curvMax /= mesh.CountPoints();
02071
02072 if (c2==0)
02073 mean_curvMin = -1e+3;
02074 else
02075 mean_curvMin /= mesh.CountPoints();
02076
02077 curv[0] = tmp1;
02078 curv[1] = tmp2;
02079
02080
02081
02082
02083
02084
02085 for(int i=0; i<n; ++i)
02086 {
02087
02088
02089
02090
02091 std::vector< Wm4::Vector3<float> > aPnts;
02092 std::vector<Base::Vector3f> aPnts_tmp;
02093 MeshCore::MeshPointIterator cPIt( mesh );
02094 for ( cPIt.Init(); cPIt.More(); cPIt.Next() )
02095 {
02096 Wm4::Vector3<float> cP( cPIt->x, cPIt->y, cPIt->z );
02097 Base::Vector3f cP_tmp( cPIt->x, cPIt->y, cPIt->z );
02098 aPnts.push_back( cP );
02099 aPnts_tmp.push_back(cP_tmp);
02100 }
02101
02102
02103 std::vector<int> anIdx;
02104 const std::vector<MeshCore::MeshFacet>& MeshFacetArray = mesh.GetFacets();
02105 for ( std::vector<MeshCore::MeshFacet>::const_iterator jt = MeshFacetArray.begin(); jt != MeshFacetArray.end(); ++jt )
02106 {
02107 for (int i=0; i<3; i++)
02108 {
02109 anIdx.push_back( (int)jt->_aulPoints[i] );
02110 }
02111 }
02112
02113
02114 Wm4::MeshCurvature<float> meshCurv(mesh.CountPoints(), &(aPnts[0]), mesh.CountFacets(), &(anIdx[0]));
02115
02116
02117 const Wm4::Vector3<float>* aMaxCurvDir = meshCurv.GetMaxDirections();
02118 const Wm4::Vector3<float>* aMinCurvDir = meshCurv.GetMinDirections();
02119 const float* aMaxCurv = meshCurv.GetMaxCurvatures();
02120 const float* aMinCurv = meshCurv.GetMinCurvatures();
02121
02122 double maxCurv = 0.0;
02123 double avgCurv = 0.0;
02124 double tmp1 = 1e+10;
02125 double tmp2 = -1e+10;
02126
02127 double mean_curvMax = 0.0, mean_curvMin = 0.0;
02128 int c1 = 0, c2 = 0;
02129
02130 m_CurvPos.clear();
02131 m_CurvNeg.clear();
02132 m_CurvMax.clear();
02133 m_CurvPos.resize(mesh.CountPoints());
02134 m_CurvNeg.resize(mesh.CountPoints());
02135 m_CurvMax.resize(mesh.CountPoints());
02136
02137 for ( unsigned long i=0; i<mesh.CountPoints(); i++ )
02138 {
02139
02140 if (aMaxCurv[i] > 0) m_CurvPos[i] = 1 / aMaxCurv[i];
02141 else m_CurvPos[i] = 1e+10;
02142
02143 if (aMinCurv[i] < 0) m_CurvNeg[i] = 1 / aMinCurv[i];
02144 else m_CurvNeg[i] = -1e+10;
02145
02146 if (m_CurvPos[i] < tmp1)
02147 tmp1 = m_CurvPos[i];
02148
02149 if (m_CurvNeg[i] > tmp2)
02150 tmp2 = m_CurvNeg[i];
02151
02152 if (aMaxCurv[i] > 0)
02153 {
02154 ++c1;
02155 mean_curvMax += 1/aMaxCurv[i];
02156 }
02157
02158 if (aMinCurv[i] < 0)
02159 {
02160 ++c2;
02161 mean_curvMin += 1/aMinCurv[i];
02162 }
02163 }
02164
02165 if (c1==0)
02166 mean_curvMax = 1e+3;
02167 else
02168 mean_curvMax /= mesh.CountPoints();
02169
02170 if (c2==0)
02171 mean_curvMin = -1e+3;
02172 else
02173 mean_curvMin /= mesh.CountPoints();
02174
02175 curv[0] = tmp1;
02176 curv[1] = tmp2;
02177 }
02178
02179
02180 return curv;
02181 }
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02992
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008
03009
03010
03011
03012
03013
03014
03015
03016
03017
03018
03019
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029
03030
03031
03032
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050
03051
03052
03053
03054
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071 bool SpringbackCorrection::Visit(const MeshCore::MeshFacet &rclFacet, const MeshCore::MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel)
03072 {
03073 if (ulLevel != m_RingCurrent)
03074 {
03075 ++m_RingCurrent;
03076
03077 if (m_RingVector.size() == 0)
03078 {
03079 return false;
03080 }
03081
03082
03083
03084
03085
03086 else
03087 {
03088 m_RegionVector.push_back(m_RingVector);
03089 m_RingVector.clear();
03090 }
03091 }
03092
03093 if (rclFacet._ulProp == 1 && rclFrom._ulProp == 1)
03094 m_RingVector.push_back(ulFInd);
03095
03096 return true;
03097 }