From fc4f16fa8a3bc738f4acb116a8600b5f5b33a8cc Mon Sep 17 00:00:00 2001 From: jfa Date: Mon, 15 Aug 2011 11:37:22 +0000 Subject: [PATCH] Porting to OCCT6.5.1 --- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 165 ++++++++++++----------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index 17ddf40..a2ac186 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -15,7 +15,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// // --- // File : BLSURFPlugin_BLSURF.cxx @@ -23,7 +22,7 @@ // & Aurelien ALLEAUME (DISTENE) // Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE) // --- -// + #include "BLSURFPlugin_BLSURF.hxx" #include "BLSURFPlugin_Hypothesis.hxx" #include "BLSURFPlugin_Attractor.hxx" @@ -38,6 +37,7 @@ extern "C"{ #include +#include #include #include @@ -623,10 +623,10 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction attractorFunctionStream << "def f(u,v): return "; attractorFunctionStream << _smp_phy_size << "-(" << _smp_phy_size <<"-" << a << ")"; //attractorFunctionStream << "*exp(-((u-("<GetPreCADDiscardInput(); _precadManifoldGeom = hyp->GetPreCADManifoldGeom(); _precadClosedGeom = hyp->GetPreCADClosedGeom(); - + } else { //0020968: EDF1545 SMESH: Problem in the creation of a mesh group on geometry // GetDefaultPhySize() sometimes leads to computation failure _phySize = mesh.GetShapeDiagonalSize() / _gen->GetBoundaryBoxSegmentation(); MESSAGE("BLSURFPlugin_BLSURF::SetParameters using defaults"); } - + // PreCAD if (_topology == BLSURFPlugin_Hypothesis::PreCAD) { *use_precad = true; @@ -742,7 +742,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, precad_set_param(pcs, "manifold_geometry", _precadManifoldGeom ? "1" : "0"); precad_set_param(pcs, "closed_geometry", _precadClosedGeom ? "1" : "0"); } - + _smp_phy_size = _phySize; blsurf_set_param(bls, "topo_points", _topology == BLSURFPlugin_Hypothesis::Process || _topology == BLSURFPlugin_Hypothesis::Process2 ? "1" : "0"); blsurf_set_param(bls, "topo_curves", _topology == BLSURFPlugin_Hypothesis::Process || _topology == BLSURFPlugin_Hypothesis::Process2 ? "1" : "0"); @@ -877,7 +877,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, } } } - + if (GeomType == TopAbs_FACE){ HasSizeMapOnFace = true; createAttractorOnFace(GeomShape, atIt->second); @@ -897,10 +897,10 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, */ } } - + // Class Attractors // temporary commented out for testing - // TODO + // TODO // - Fill in the BLSURFPlugin_Hypothesis::TAttractorMap map in the hypothesis // - Uncomment and complete this part to construct the attractors from the attractor shape and the passed parameters on each face of the map // - To do this use the public methodss: SetParameters(several double parameters) and SetType(int type) @@ -908,7 +908,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, // - Construct the attractors with an empty dist. map in the hypothesis // - build the map here for each face with an attractor set and only if the attractor shape as changed since the last call to _buildmap() // -> define a bool _mapbuilt in the class that is set to false by default and set to true when calling _buildmap() OK - + const BLSURFPlugin_Hypothesis::TAttractorMap class_attractors = BLSURFPlugin_Hypothesis::GetClassAttractorEntries(hyp); int key=-1; BLSURFPlugin_Hypothesis::TAttractorMap::const_iterator AtIt = class_attractors.begin(); @@ -923,18 +923,18 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, // for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ // if (it.Value().ShapeType() == TopAbs_FACE){ // HasAttractorOnFace = true; -// myAttractor = BLSURFPluginAttractor(GeomShape, AttShape); +// myAttractor = BLSURFPluginAttractor(GeomShape, AttShape); // } // } // } - - if (GeomType == TopAbs_FACE - && (AttShape.ShapeType() == TopAbs_VERTEX - || AttShape.ShapeType() == TopAbs_EDGE - || AttShape.ShapeType() == TopAbs_WIRE + + if (GeomType == TopAbs_FACE + && (AttShape.ShapeType() == TopAbs_VERTEX + || AttShape.ShapeType() == TopAbs_EDGE + || AttShape.ShapeType() == TopAbs_WIRE || AttShape.ShapeType() == TopAbs_COMPOUND) ){ HasSizeMapOnFace = true; - + if (! FacesWithSizeMap.Contains(TopoDS::Face(GeomShape)) ) { key = FacesWithSizeMap.Add(TopoDS::Face(GeomShape) ); } @@ -942,7 +942,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, key = FacesWithSizeMap.FindIndex(TopoDS::Face(GeomShape)); // MESSAGE("Face with key " << key << " already in map"); } - + FaceId2ClassAttractor[key] = AtIt->second; } else{ @@ -952,7 +952,6 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, } } - // // Enforced Vertices @@ -973,7 +972,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, } } } - + if (GeomType == TopAbs_FACE){ HasSizeMapOnFace = true; createEnforcedVertexOnFace(GeomShape, enfIt->second); @@ -1038,9 +1037,9 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) /* create a distene context (generic object) */ status_t status = STATUS_ERROR; - + context_t *ctx = context_new(); - + /* Set the message callback in the working context */ context_set_message_callback(ctx, message_cb, &_comment); #ifdef WITH_SMESH_CANCEL_COMPUTE @@ -1073,26 +1072,25 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) cad_t *cleanc = NULL; precad_session_t *pcs = precad_session_new(ctx); precad_data_set_cad(pcs, c); - + blsurf_session_t *bls = blsurf_session_new(ctx); MESSAGE("BEGIN SetParameters"); bool use_precad = false; SetParameters(_hypothesis, bls, pcs, aMesh, &use_precad); MESSAGE("END SetParameters"); - - + // needed to prevent the opencascade memory managmement from freeing things vector curves; vector surfaces; surfaces.resize(0); curves.resize(0); - + TopTools_IndexedMapOfShape fmap; TopTools_IndexedMapOfShape emap; TopTools_IndexedMapOfShape pmap; - + fmap.Clear(); FaceId2PythonSmp.clear(); emap.Clear(); @@ -1105,7 +1103,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) gstate = PyGILState_Ensure(); string theSizeMapStr; - + /**************************************************************************************** FACES *****************************************************************************************/ @@ -1122,14 +1120,14 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) // make INTERNAL face oriented FORWARD (issue 0020993) if (f.Orientation() != TopAbs_FORWARD && f.Orientation() != TopAbs_REVERSED ) f.Orientation(TopAbs_FORWARD); - + if (fmap.FindIndex(f) > 0) continue; fmap.Add(f); iface++; surfaces.push_back(BRep_Tool::Surface(f)); - + /* create an object representing the face for blsurf */ /* where face_id is an integer identifying the face. * surf_function is the function that defines the surface @@ -1137,24 +1135,24 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) * as last parameter. */ cad_face_t *fce = cad_face_new(c, iface, surf_fun, surfaces.back()); - + /* by default a face has no tag (color). The following call sets it to the same value as the face_id : */ cad_face_set_tag(fce, iface); - + /* Set face orientation (optional if you want a well oriented output mesh)*/ if(f.Orientation() != TopAbs_FORWARD){ cad_face_set_orientation(fce, CAD_ORIENTATION_REVERSED); } else { cad_face_set_orientation(fce, CAD_ORIENTATION_FORWARD); } - + if (HasSizeMapOnFace && !use_precad){ // MESSAGE("A size map is defined on a face") // std::cout << "A size map is defined on a face" << std::endl; // Classic size map faceKey = FacesWithSizeMap.FindIndex(f); - - + + if (FaceId2SizeMap.find(faceKey)!=FaceId2SizeMap.end()){ MESSAGE("A size map is defined on face :"< >::iterator attractor_iter = FaceId2AttractorCoords.begin(); - + for (; attractor_iter != FaceId2AttractorCoords.end(); ++attractor_iter) { if (attractor_iter->first == faceKey) { MESSAGE("Face indice: " << iface); MESSAGE("Adding attractor"); - + double xyzCoords[3] = {attractor_iter->second[2], attractor_iter->second[3], attractor_iter->second[4]}; - + MESSAGE("Check position of vertex =(" << xyzCoords[0] << "," << xyzCoords[1] << "," << xyzCoords[2] << ")"); gp_Pnt P(xyzCoords[0],xyzCoords[1],xyzCoords[2]); BRepClass_FaceClassifier scl(f,P,1e-7); @@ -1219,8 +1217,8 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) FaceIndex2ClassAttractor[iface]=clAttractor_iter->second; FaceId2ClassAttractor.erase(clAttractor_iter); } - } - + } + // Enforced Vertices faceKey = FacesWithEnforcedVertices.FindIndex(f); std::map::const_iterator evmIt = FaceId2EnforcedVertexCoords.find(faceKey); @@ -1282,8 +1280,8 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) // else // std::cout << "No enforced vertex defined" << std::endl; // } - - + + /**************************************************************************************** EDGES now create the edges associated to this face @@ -1297,7 +1295,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) double tmin,tmax; curves.push_back(BRep_Tool::CurveOnSurface(e, f, tmin, tmax)); - + if (HasSizeMapOnEdge){ edgeKey = EdgesWithSizeMap.FindIndex(e); if (EdgeId2SizeMap.find(edgeKey)!=EdgeId2SizeMap.end()) { @@ -1315,18 +1313,18 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) EdgeId2SizeMap.erase(edgeKey); } } - + /* attach the edge to the current blsurf face */ cad_edge_t *edg = cad_edge_new(fce, ic, tmin, tmax, curv_fun, curves.back()); - + /* by default an edge has no tag (color). The following call sets it to the same value as the edge_id : */ cad_edge_set_tag(edg, ic); - + /* by default, an edge does not necessalry appear in the resulting mesh, unless the following property is set : */ cad_edge_set_property(edg, EDGE_PROPERTY_SOFT_REQUIRED); - + /* by default an edge is a boundary edge */ if (e.Orientation() == TopAbs_INTERNAL) cad_edge_set_property(edg, EDGE_PROPERTY_INTERNAL); @@ -1336,8 +1334,8 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) gp_Pnt2d e0 = curves.back()->Value(tmin); gp_Pnt ee0 = surfaces.back()->Value(e0.X(), e0.Y()); Standard_Real d1=0,d2=0; - - + + /**************************************************************************************** VERTICES *****************************************************************************************/ @@ -1355,7 +1353,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) *ip = pmap.FindIndex(v); if(*ip <= 0) *ip = pmap.Add(v); - + if (HasSizeMapOnVertex){ vertexKey = VerticesWithSizeMap.FindIndex(v); if (VertexId2SizeMap.find(vertexKey)!=VertexId2SizeMap.end()){ @@ -1394,27 +1392,27 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) PyGILState_Release(gstate); - + if (use_precad){ /* Now launch the PreCAD process */ status = precad_process(pcs); if(status != STATUS_OK){ cout << "PreCAD processing failed with error code " << status << "\n"; - // Now we can delete the PreCAD session + // Now we can delete the PreCAD session precad_session_delete(pcs); } else { - // retrieve the pre-processed CAD object + // retrieve the pre-processed CAD object cleanc = precad_new_cad(pcs); if(!cleanc){ cout << "Unable to retrieve PreCAD result \n"; } cout << "PreCAD processing successfull \n"; - // Now we can delete the PreCAD session + // Now we can delete the PreCAD session precad_session_delete(pcs); } } - + if (cleanc) { // Give the pre-processed CAD object to the current BLSurf session blsurf_data_set_cad(bls, cleanc); @@ -1480,7 +1478,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) return error(_comment); //return false; } - + std::string GMFFileName = _hypothesis->GetGMFFile(); if (GMFFileName != "") { // bool GMFFileMode = _hypothesis->GetGMFFileMode(); @@ -1504,7 +1502,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) */ mesh_write_mesh(msh, GMFFileName.c_str()); } - + /* retrieve mesh data (see distene/mesh.h) */ integer nv, ne, nt, nq, vtx[4], tag; real xyz[3]; @@ -1688,7 +1686,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) feclearexcept( FE_ALL_EXCEPT ); #endif - /* + /* std::cout << "FacesWithSizeMap" << std::endl; FacesWithSizeMap.Statistics(std::cout); std::cout << "EdgesWithSizeMap" << std::endl; @@ -1698,7 +1696,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape) std::cout << "FacesWithEnforcedVertices" << std::endl; FacesWithEnforcedVertices.Statistics(std::cout); */ - + MESSAGE("END OF BLSURFPlugin_BLSURF::Compute()"); return true; } @@ -1805,7 +1803,7 @@ status_t curv_fun(real t, real *uv, real *dt, real *dtt, void *user_data) { /* t is given. It contains the t (time) 1D parametric coordintaes of the point PreCAD/BLSurf is querying on the curve */ - + /* user_data identifies the edge PreCAD/BLSurf is querying * (see cad_edge_new later in this example) */ const Geom2d_Curve*pargeo = (const Geom2d_Curve*) user_data; @@ -1837,8 +1835,8 @@ status_t curv_fun(real t, real *uv, real *dt, real *dtt, void *user_data) /* Surface definition function. * See cad_surf_t in file distene/cad.h for more information. * NOTE : if when your CAD systems evaluates second order derivatives it also - * computes first order derivatives and function evaluation, you can optimize - * this example by making only one CAD call and filling the necessary xyz, du, dv, etc.. + * computes first order derivatives and function evaluation, you can optimize + * this example by making only one CAD call and filling the necessary xyz, du, dv, etc.. * arrays. */ status_t surf_fun(real *uv, real *xyz, real*du, real *dv, @@ -1846,7 +1844,7 @@ status_t surf_fun(real *uv, real *xyz, real*du, real *dv, { /* uv[2] is given. It contains the u,v coordinates of the point * PreCAD/BLSurf is querying on the surface */ - + /* user_data identifies the face PreCAD/BLSurf is querying (see * cad_face_new later in this example)*/ const Geom_Surface* geometry = (const Geom_Surface*) user_data; @@ -2062,7 +2060,7 @@ status_t interrupt_cb(integer *interrupt_status, void *user_data) //============================================================================= /*! - * + * */ //============================================================================= bool BLSURFPlugin_BLSURF::Evaluate(SMESH_Mesh& aMesh, @@ -2087,7 +2085,7 @@ bool BLSURFPlugin_BLSURF::Evaluate(SMESH_Mesh& aMesh, bool IsQuadratic = false; // ---------------- - // evaluate 1D + // evaluate 1D // ---------------- TopTools_DataMapOfShapeInteger EdgesMap; double fullLen = 0.0; @@ -2138,7 +2136,7 @@ bool BLSURFPlugin_BLSURF::Evaluate(SMESH_Mesh& aMesh, } double ELen = fullLen/fullNbSeg; // ---------------- - // evaluate 2D + // evaluate 2D // ---------------- // try to evaluate as in MEFISTO for (TopExp_Explorer exp(aShape, TopAbs_FACE); exp.More(); exp.Next()) { @@ -2219,11 +2217,11 @@ bool BLSURFPlugin_BLSURF::Evaluate(SMESH_Mesh& aMesh, */ //============================================================================= void BLSURFPlugin_BLSURF::BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, - const TopoDS_Face& face, - const gp_Pnt& P, + const TopoDS_Face& face, + const gp_Pnt& P, const Standard_Real Tol) { - //-- Voir BRepExtrema_ExtPF.cxx + //-- Voir BRepExtrema_ExtPF.cxx BRepAdaptor_Surface Surf(face); Standard_Real U1, U2, V1, V2; BRepTools::UVBounds(face, U1, U2, V1, V2); @@ -2231,32 +2229,35 @@ void BLSURFPlugin_BLSURF::BRepClass_FaceClassifierPerform(BRepClass_FaceClassif myExtrem.Initialize(Surf, U1, U2, V1, V2, Tol, Tol); myExtrem.Perform(P); //---------------------------------------------------------- - //-- On cherche le point le plus proche , PUIS - //-- On le classifie. + //-- On cherche le point le plus proche , PUIS + //-- On le classifie. Standard_Integer nbv = 0; // xpu Standard_Real MaxDist = RealLast(); Standard_Integer indice = 0; - if(myExtrem.IsDone()) { + if (myExtrem.IsDone()) { nbv = myExtrem.NbExt(); for (Standard_Integer i = 1; i <= nbv; i++) { +#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 + Standard_Real d = myExtrem.SquareDistance(i); +#else Standard_Real d = myExtrem.Value(i); d = Abs(d); - if(d <= MaxDist) { - MaxDist = d; - indice = i; +#endif + if (d <= MaxDist) { + MaxDist = d; + indice = i; } } } - if(indice) { + if (indice) { gp_Pnt2d Puv; Standard_Real U1,U2; myExtrem.Point(indice).Parameter(U1, U2); Puv.SetCoord(U1, U2); fc->Perform(face, Puv, Tol); } - else { + else { fc->Perform(face, gp_Pnt2d(U1-1.0,V1 - 1.0), Tol); //-- NYI etc BUG PAS BEAU En attendant l acces a rejected //-- le resultat est TopAbs_OUT; } } - -- 2.39.2