// 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
// & Aurelien ALLEAUME (DISTENE)
// Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
// ---
-//
+
#include "BLSURFPlugin_BLSURF.hxx"
#include "BLSURFPlugin_Hypothesis.hxx"
#include "BLSURFPlugin_Attractor.hxx"
#include <Basics_Utils.hxx>
+#include <Basics_OCCTVersion.hxx>
#include <SMESH_Gen.hxx>
#include <SMESH_Mesh.hxx>
attractorFunctionStream << "def f(u,v): return ";
attractorFunctionStream << _smp_phy_size << "-(" << _smp_phy_size <<"-" << a << ")";
//attractorFunctionStream << "*exp(-((u-("<<u0<<"))*(u-("<<u0<<"))+(v-("<<v0<<"))*(v-("<<v0<<")))/(" << b << "*" << b <<"))";
- // rnc: make possible to keep the size constant until
- // a defined distance. Distance is expressed as the positiv part
+ // rnc: make possible to keep the size constant until
+ // a defined distance. Distance is expressed as the positiv part
// of r-d where r is the distance to (u0,v0)
- attractorFunctionStream << "*exp(-(0.5*(sqrt((u-"<<u0<<")**2+(v-"<<v0<<")**2)-"<<d<<"+abs(sqrt((u-"<<u0<<")**2+(v-"<<v0<<")**2)-"<<d<<"))/(" << b << "))**2)";
+ attractorFunctionStream << "*exp(-(0.5*(sqrt((u-"<<u0<<")**2+(v-"<<v0<<")**2)-"<<d<<"+abs(sqrt((u-"<<u0<<")**2+(v-"<<v0<<")**2)-"<<d<<"))/(" << b << "))**2)";
MESSAGE("Python function for attractor:" << std::endl << attractorFunctionStream.str());
// }
// else
// MESSAGE("face OK");
-//
+//
// if (FaceId2ClassAttractor[key].GetAttractorShape().IsNull()){
// MESSAGE("pas de point");
// }
_precadDiscardInput = hyp->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;
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");
}
}
}
-
+
if (GeomType == TopAbs_FACE){
HasSizeMapOnFace = true;
createAttractorOnFace(GeomShape, atIt->second);
*/
}
}
-
+
// 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)
// - 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();
// 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) );
}
key = FacesWithSizeMap.FindIndex(TopoDS::Face(GeomShape));
// MESSAGE("Face with key " << key << " already in map");
}
-
+
FaceId2ClassAttractor[key] = AtIt->second;
}
else{
}
}
-
//
// Enforced Vertices
}
}
}
-
+
if (GeomType == TopAbs_FACE){
HasSizeMapOnFace = true;
createEnforcedVertexOnFace(GeomShape, enfIt->second);
/* 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
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<Handle(Geom2d_Curve)> curves;
vector<Handle(Geom_Surface)> surfaces;
surfaces.resize(0);
curves.resize(0);
-
+
TopTools_IndexedMapOfShape fmap;
TopTools_IndexedMapOfShape emap;
TopTools_IndexedMapOfShape pmap;
-
+
fmap.Clear();
FaceId2PythonSmp.clear();
emap.Clear();
gstate = PyGILState_Ensure();
string theSizeMapStr;
-
+
/****************************************************************************************
FACES
*****************************************************************************************/
// 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
* 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 :"<<faceKey)
theSizeMapStr = FaceId2SizeMap[faceKey];
FaceId2PythonSmp[iface]=func;
FaceId2SizeMap.erase(faceKey);
}
-
+
// Specific size map = Attractor
std::map<int,std::vector<double> >::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);
FaceIndex2ClassAttractor[iface]=clAttractor_iter->second;
FaceId2ClassAttractor.erase(clAttractor_iter);
}
- }
-
+ }
+
// Enforced Vertices
faceKey = FacesWithEnforcedVertices.FindIndex(f);
std::map<int,BLSURFPlugin_Hypothesis::TEnfVertexCoordsList >::const_iterator evmIt = FaceId2EnforcedVertexCoords.find(faceKey);
// else
// std::cout << "No enforced vertex defined" << std::endl;
// }
-
-
+
+
/****************************************************************************************
EDGES
now create the edges associated to this face
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()) {
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);
gp_Pnt2d e0 = curves.back()->Value(tmin);
gp_Pnt ee0 = surfaces.back()->Value(e0.X(), e0.Y());
Standard_Real d1=0,d2=0;
-
-
+
+
/****************************************************************************************
VERTICES
*****************************************************************************************/
*ip = pmap.FindIndex(v);
if(*ip <= 0)
*ip = pmap.Add(v);
-
+
if (HasSizeMapOnVertex){
vertexKey = VerticesWithSizeMap.FindIndex(v);
if (VertexId2SizeMap.find(vertexKey)!=VertexId2SizeMap.end()){
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);
return error(_comment);
//return false;
}
-
+
std::string GMFFileName = _hypothesis->GetGMFFile();
if (GMFFileName != "") {
// bool GMFFileMode = _hypothesis->GetGMFFileMode();
*/
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];
feclearexcept( FE_ALL_EXCEPT );
#endif
- /*
+ /*
std::cout << "FacesWithSizeMap" << std::endl;
FacesWithSizeMap.Statistics(std::cout);
std::cout << "EdgesWithSizeMap" << std::endl;
std::cout << "FacesWithEnforcedVertices" << std::endl;
FacesWithEnforcedVertices.Statistics(std::cout);
*/
-
+
MESSAGE("END OF BLSURFPlugin_BLSURF::Compute()");
return true;
}
{
/* 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;
/* 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,
{
/* 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;
//=============================================================================
/*!
- *
+ *
*/
//=============================================================================
bool BLSURFPlugin_BLSURF::Evaluate(SMESH_Mesh& aMesh,
bool IsQuadratic = false;
// ----------------
- // evaluate 1D
+ // evaluate 1D
// ----------------
TopTools_DataMapOfShapeInteger EdgesMap;
double fullLen = 0.0;
}
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()) {
*/
//=============================================================================
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);
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;
}
}
-