-BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor, int MapGrid){
+#include "BLSURFPlugin_Attractor.hxx"
+
+BLSURFPlugin_Attractor::BLSURFPlugin_Attractor ()
+ : _face(),
+ _attractorShape(),
+ _vectU(),
+ _vectV(),
+ _DMap(),
+ _known(),
+ _trial(),
+ _mapGrid(-1),
+ _i0(-1),
+ _j0(-1),
+ _u1 (0.),
+ _u2 (0.),
+ _v1 (0.),
+ _v2 (0.){}
+
+BLSURFPlugin_Attractor::BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor)
+ : _face(),
+ _attractorShape(),
+ _vectU(),
+ _vectV(),
+ _DMap(),
+ _known(),
+ _trial(),
+ _mapGrid(-1),
+ _i0(-1),
+ _j0(-1),
+ _u1 (0.),
+ _u2 (0.),
+ _v1 (0.),
+ _v2 (0.)
+{
_face = Face;
_attractorShape = Attractor;
- _mapGrid = MapGrid;
+ _mapGrid = 50;
init();
}
bool BLSURFPlugin_Attractor::init(){
+ Standard_Real u0,v0;
+ int i,j ;
_known.clear();
_trial.clear();
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face);
- TPnt Trial_Pnt(0,0,0);
+ Trial_Pnt TPnt(0,0,0);
// Discretization of the parameters
aSurf->Bounds(_u1, _u2, _v1, _v2); // unusable in the generic case because the surface may be infinite (ok for prototype on a Sphere)
}
// Determination of the starting point
+ GeomAPI_ProjectPointOnSurf projector( point, surface );
+ projector.LowerDistanceParameters(u0,v0);
+ //gp_Pnt2d P = BRep_Tool::Parameters(TopoDS::Vertex(_attractorShape),_face);
+ //u0 = P.X();
+ //v0 = P.Y();
int i0 = floor ( (u0 - _u1) * _mapGrid / (_u2 - _u1) + 0.5 );
int j0 = floor ( (v0 - _v1) * _mapGrid / (_v2 - _v1) + 0.5 );
TPnt.dist=0.; // Set distance to 0.
_trial.insert(TPnt); // Move starting point to _trial
// Initialization of _DMap
- std:vector<double> temp(_mapGrid+1,numeric_limits<double>::infinity()); // Set distance of all "far" points to Infinity
+ std::vector<double> temp(_mapGrid+1,std::numeric_limits<double>::infinity()); // Set distance of all "far" points to Infinity
for (i=0; i<=_mapGrid; i++){
- DMap.push_back(temp);
+ _DMap.push_back(temp);
}
_DMap[i0][j0] = 0.; // Set distance of starting point to 0.
_buildMap(); // Computes the distance for all points of the discrete surface
}
-double BLSURFPlugin_BLSURF::GetSize(double u, double v){
+double BLSURFPlugin_Attractor::GetSize(double u, double v){
int i = floor ( (u - _u1) * _mapGrid / (_u2 - _u1) + 0.5 );
int j = floor ( (v - _v1) * _mapGrid / (_v2 - _v1) + 0.5 );
return _DMap[i][j]; // more generally: function of _DMap
double D_Ref = 0.;
double Dist = 0.;
bool Dist_changed = false;
- Current_Pnt = IJ_Pnt(0,0);
- TPnt Trial_Pnt(0,0,0);
+ IJ_Pnt Current_Pnt(0,0);
+ Trial_Pnt TPnt(0,0,0);
TTrialSet::iterator min;
+ Handle(Geom_Surface) aSurf = BRep_Tool::Surface(_face);
while (_trial.size() > 0){
min = _trial.begin(); // Get trial point with min distance from start
- i0 = min->Ti;
- j0 = min->Tj;
+ int i0 = min->Ti;
+ int j0 = min->Tj;
Current_Pnt.Pi = i0; // Define it as the current point
Current_Pnt.Pj = j0;
_known.insert(Current_Pnt); // Move it to _known and remove it from _trial
aSurf->D1(_vectU[i],_vectV[j],P,D1U,D1V); // Calculate the metric at (i,j)
Guu = D1U.X()*D1U.X() + D1U.Y()*D1U.Y() + D1U.Z()*D1U.Z(); // Guu = ||dS/du||**2 G(i,j)= | ||dS/du||**2 0 | assuming that the isolines are orthogonal in 3D space
Gvv = D1V.X()*D1V.X() + D1V.Y()*D1V.Y() + D1V.Z()*D1V.Z(); // Gvv = ||dS/dv||**2 | 0 ||dS/dv||**2 |
- D_Ref = DMap[ip][jp]; // Set a ref. distance to the value in DMap (may be infinite or uncertain)
+ D_Ref = _DMap[ip][jp]; // Set a ref. distance to the value in DMap (may be infinite or uncertain)
TPnt.dist = D_Ref; // Store the point as a trial point
TPnt.Ti = ip;
TPnt.Tj = jp;
Current_Pnt.Pj = np;
if (_known.find( Current_Pnt ) != _known.end()){ // If distance of the neighbour is known
// Calculate the distance from (k,n)
- du = (k-i) * Ustep;
- dv = (n-j) * Vstep;
+ du = (k-i) * (_u2 - _u1) / _mapGrid;
+ dv = (n-j) * (_v2 - _v1) / _mapGrid;
Dist = _DMap[kp][np] + Guu * du*du + Gvv * dv*dv; // ds**2 = du'Gdu + dv'Gdv (we assume Guv=Gvu=0)
if (Dist < D_Ref) { // If smaller than ref. distance -> update ref. distance
D_Ref = Dist;
#include <set>
#include <stdexcept>
#include <string>
+#include <limits>
+
+// OPENCASCADE includes
+#include <BRep_Tool.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <NCollection_Map.hxx>
+
+#include <Geom_Surface.hxx>
+#include <Handle_Geom_Surface.hxx>
+#include <Geom2d_Curve.hxx>
+#include <Handle_Geom2d_Curve.hxx>
+#include <Geom_Curve.hxx>
+#include <Handle_Geom_Curve.hxx>
+#include <Handle_AIS_InteractiveObject.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
+
+#include <gp_Pnt2d.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepTools.hxx>
+
+#include <TopTools_DataMapOfShapeInteger.hxx>
+#include <GProp_GProps.hxx>
+#include <BRepGProp.hxx>
+
+#ifndef WNT
+#include <fenv.h>
+#endif
+#include <Standard_ErrorHandler.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
+#include <GeomAPI_ProjectPointOnSurf.hxx>
+#include <gp_XY.hxx>
+#include <gp_XYZ.hxx>
+#include <TopTools_MapOfShape.hxx>
+class IJ_Pnt{
+ public:
+ IJ_Pnt(int i,int j){
+ Pi=i;
+ Pj=j;
+ }
+ int Pi;
+ int Pj;
+};
+
+class IJ_comp{
+ public:
+ bool operator() (const IJ_Pnt p1, const IJ_Pnt p2) {
+ if (&p1 && &p2)
+ return ((p1.Pi < p2.Pi) && (p1.Pj < p2.Pj));
+ else
+ return (&p1 < &p2);
+ }
+};
+
+class Trial_Pnt{
+ public:
+ Trial_Pnt(int i,int j,double d){
+ Ti=i;
+ Tj=j;
+ dist=d;
+ }
+ int Ti;
+ int Tj;
+ double dist;
+};
+
+class Trial_comp {
+ public:
+ bool operator() (const Trial_Pnt me, const Trial_Pnt other) const {
+ return (&me && &other) ? (me.dist < other.dist) : (&me < &other);
+ }
+};
+
class BLSURFPlugin_Attractor {
public:
- BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor, int MapGrid);
+ BLSURFPlugin_Attractor ();
+ // TODO ~BLSURFPlugin_Attractor ();
+ BLSURFPlugin_Attractor (TopoDS_Face Face, TopoDS_Shape Attractor);
bool init(); // Calculates the discrete points correponding to attractor, initialises the map and calls _buildMap
double GetSize (double u, double v);
TopoDS_Face GetFace(){ return _face;}
- TopoDS_Shape GetAttractor(){ return _attractorShape;}
- bool SetAttractor(TopoDS_Shape Attractor){ _attractorShape = Attractor; }
+ TopoDS_Shape GetAttractorShape(){ return _attractorShape;}
+ bool SetAttractorShape(TopoDS_Shape Attractor){ _attractorShape = Attractor; }
typedef std::vector<double> TDiscreteParam;
typedef std::vector< std::vector<double> > TDistMap;
bool _buildMap(); // Builds the map of distances between source point and any point (u,v)
};
-class IJ_Pnt{
- public:
- IJ_Pnt(int i,int j){
- Pi=i;
- Pj=j;
- }
- int Pi;
- int Pj;
-};
-
-class IJ_comp{
- bool operator() (const IJ_Pnt p1, const IJ_Pnt p2) {
- if (&p1 && &p2)
- return ((p1.Pi < p2.Pi) && (p1.Pj < p2.Pj));
- else
- return (&p1 < &p2);
- }
-};
-
-class Trial_Pnt{
- public:
- Trial_Pnt(int i,int j,double d){
- Ti=i;
- Tj=j;
- dist=d;
- }
- int Ti;
- int Tj;
- double dist;
-};
-class Trial_comp {
- bool operator() (const Trial_Pnt me, const Trial_Pnt other) const {
- return (&me && &other) ? (me.dist < other.dist) : (&me < &other);
- }
-};
//
#include "BLSURFPlugin_BLSURF.hxx"
#include "BLSURFPlugin_Hypothesis.hxx"
+#include "BLSURFPlugin_Attractor.hxx"
extern "C"{
#include <distene/api.h>
#include <TopoDS_Face.hxx>
#include <gp_Pnt2d.hxx>
+#include <gp_Pnt.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopoDS_Shape.hxx>
#include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepTools.hxx>
#include <TopTools_DataMapOfShapeInteger.hxx>
std::map<int,PyObject*> VertexId2PythonSmp;
std::map<int,std::vector<double> > FaceId2AttractorCoords;
+std::map<int,BLSURFPlugin_Attractor> FaceId2ClassAttractor;
TopTools_IndexedMapOfShape FacesWithEnforcedVertices;
std::map< int, std::set< std::vector<double> > > FaceId2EnforcedVertexCoords;
bool HasSizeMapOnFace=false;
bool HasSizeMapOnEdge=false;
bool HasSizeMapOnVertex=false;
+bool HasAttractorOnFace=false;
//=============================================================================
/*!
MESSAGE("Creating node on ("<<x0<<","<<y0<<","<<z0<<")");
FaceId2AttractorCoords[key] = coords;
}
+ // Test for new attractors
+ gp_Pnt myP(xyzPoint);
+ TopoDS_Vertex myV = BRepBuilderAPI_MakeVertex(myP);
+ BLSURFPlugin_Attractor myAttractor(TopoDS::Face(GeomShape),myV);
+ FaceId2ClassAttractor[key] = myAttractor;
}
/////////////////////////////////////////////////////////
// blsurf_set_param(bls, "hphy_flag", "2");
if ((to_string(_physicalMesh))=="2"){
TopoDS_Shape GeomShape;
+ TopoDS_Shape AttShape;
TopAbs_ShapeEnum GeomType;
//
// Standard Size Maps
*/
}
}
-
+
+ // Class Attractors
+ // TODO temporary commented out for testing
+
+// BLSURFPlugin_Attractor myAttractor;
+// const BLSURFPlugin_Hypothesis::TAttractorMap class_attractors = BLSURFPlugin_Hypothesis::GetClassAttractorEntries(hyp);
+// BLSURFPlugin_Hypothesis::TSizeMap::const_iterator AtIt = class_attractors.begin();
+// for ( ; AtIt != class_attractors.end(); ++atIt ) {
+// if ( !AtIt->second.empty() ) {
+// // MESSAGE("blsurf_set_attractor(): " << AtIt->first << " = " << AtIt->second);
+// GeomShape = entryToShape(AtIt->first);
+// AttShape = entryToShape(AtIt->second);
+// GeomType = GeomShape.ShapeType();
+// // Group Management
+// // if (GeomType == TopAbs_COMPOUND){
+// // for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){
+// // if (it.Value().ShapeType() == TopAbs_FACE){
+// // HasAttractorOnFace = true;
+// // myAttractor = BLSURFPluginAttractor(GeomShape, AttShape);
+// // }
+// // }
+// // }
+//
+// if (GeomType == TopAbs_FACE){
+// HasAttractorOnFace = true;
+// myAttractor = BLSURFPlugin_Attractor(TopoDS::Face(GeomShape), AttShape);
+// }
+//
+// }
+// }
+
//
// Enforced Vertices
}
if (FaceId2PythonSmp.count(face_id) != 0){
- PyObject * pyresult = NULL;
- PyObject* new_stderr = NULL;
- assert(Py_IsInitialized());
- PyGILState_STATE gstate;
- gstate = PyGILState_Ensure();
- pyresult = PyObject_CallFunction(FaceId2PythonSmp[face_id],"(f,f)",uv[0],uv[1]);
- double result;
- if ( pyresult == NULL){
- fflush(stderr);
- string err_description="";
- new_stderr = newPyStdOut(err_description);
- PySys_SetObject("stderr", new_stderr);
- PyErr_Print();
- PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
- Py_DECREF(new_stderr);
- MESSAGE("Can't evaluate f(" << uv[0] << "," << uv[1] << ")" << " error is " << err_description);
- result = *((double*)user_data);
- }
- else {
- result = PyFloat_AsDouble(pyresult);
- Py_DECREF(pyresult);
- }
+// PyObject * pyresult = NULL;
+// PyObject* new_stderr = NULL;
+// assert(Py_IsInitialized());
+// PyGILState_STATE gstate;
+// gstate = PyGILState_Ensure();
+// pyresult = PyObject_CallFunction(FaceId2PythonSmp[face_id],"(f,f)",uv[0],uv[1]);
+// double result;
+// if ( pyresult == NULL){
+// fflush(stderr);
+// string err_description="";
+// new_stderr = newPyStdOut(err_description);
+// PySys_SetObject("stderr", new_stderr);
+// PyErr_Print();
+// PySys_SetObject("stderr", PySys_GetObject("__stderr__"));
+// Py_DECREF(new_stderr);
+// MESSAGE("Can't evaluate f(" << uv[0] << "," << uv[1] << ")" << " error is " << err_description);
+// result = *((double*)user_data);
+// }
+// else {
+// result = PyFloat_AsDouble(pyresult);
+// Py_DECREF(pyresult);
+// }
+ double result = FaceId2ClassAttractor[face_id].GetSize(uv[0],uv[1]);
*size = result;
//MESSAGE("f(" << uv[0] << "," << uv[1] << ")" << " = " << result);
- PyGILState_Release(gstate);
+ //PyGILState_Release(gstate);
}
else {
*size = *((double*)user_data);
// ---
//
#include "BLSURFPlugin_Hypothesis.hxx"
+#include "BLSURFPlugin_Attractor.hxx"
#include <utilities.h>
#include <cstring>
#include <iostream>
_verb( GetDefaultVerbosity() ),
_sizeMap(GetDefaultSizeMap()),
_attractors(GetDefaultSizeMap()),
+ _classAttractors(GetDefaultAttractorMap()),
_enfVertexList(GetDefaultEnfVertexList()),
_entryEnfVertexListMap(GetDefaultEntryEnfVertexListMap())
/* TODO GROUPS
return hyp ? hyp->_GetAttractorEntries():GetDefaultSizeMap();
}
+//=======================================================================
+//function : SetClassAttractorEntry
+//=======================================================================
+void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry,const std::string& att_entry) // TODO finir
+{
+ if (!_classAttractors[entry].compare(att_entry)){
+ _classAttractors[entry] = att_entry;
+ NotifySubMeshesHypothesisModification();
+ }
+}
+
+//=======================================================================
+//function : GetClassAttractorEntry
+//=======================================================================
+std::string BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
+{
+ TAttractorMap::iterator it = _classAttractors.find( entry );
+ if ( it != _classAttractors.end() )
+ return it->second;
+ else
+ return "No_Such_Entry";
+}
+
+ /*!
+ * \brief Return the attractor instances
+ */
+BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
+{
+ return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
+}
+
+
//=======================================================================
//function : ClearEntry
//=======================================================================
void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
{
TSizeMap::iterator it = _sizeMap.find( entry );
+
if ( it != _sizeMap.end() ) {
_sizeMap.erase(it);
NotifySubMeshesHypothesisModification();
_attractors.erase(itAt);
NotifySubMeshesHypothesisModification();
}
- else
- std::cout<<"No_Such_Entry"<<std::endl;
+ else {
+ TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
+ if ( it_clAt != _classAttractors.end() ) {
+ _classAttractors.erase(it_clAt);
+ NotifySubMeshesHypothesisModification();
+ }
+ else
+ std::cout<<"No_Such_Entry"<<std::endl;
+ }
}
}
{
_sizeMap.clear();
_attractors.clear();
+ _classAttractors.clear();
}
void UnsetCustomSizeMap(const std::string& entry);
const TSizeMap& GetCustomSizeMapEntries() const { return _customSizeMap; }
*/
+
+ typedef std::map<std::string, std::string> TAttractorMap;
+
+ void SetClassAttractorEntry(const std::string& entry,const std::string& att_entry);
+ std::string GetClassAttractorEntry(const std::string& entry);
+ const TAttractorMap& _GetClassAttractorEntries() const { return _classAttractors; }
+ /*!
+ * \brief Return the attractors entries
+ */
+ static TAttractorMap GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
+
/*!
* To set/get/unset an enforced vertex
static bool GetDefaultQuadAllowed();
static bool GetDefaultDecimesh();
static int GetDefaultVerbosity() { return 10; }
- static TSizeMap GetDefaultSizeMap() { return TSizeMap();}
+ static TSizeMap GetDefaultSizeMap() { return TSizeMap(); }
+ static TAttractorMap GetDefaultAttractorMap() { return TAttractorMap(); }
static TEnfVertexList GetDefaultEnfVertexList() { return TEnfVertexList(); }
static TEntryEnfVertexListMap GetDefaultEntryEnfVertexListMap() { return TEntryEnfVertexListMap(); }
/* TODO GROUPS
TOptionNames _doubleOptions, _charOptions;
TSizeMap _sizeMap;
TSizeMap _attractors;
+ TAttractorMap _classAttractors;
TEnfVertexList _enfVertexList;
TEntryEnfVertexListMap _entryEnfVertexListMap;
/* TODO GROUPS
BLSURFPlugin_BLSURF.hxx \
BLSURFPlugin_BLSURF_i.hxx \
BLSURFPlugin_Hypothesis.hxx \
- BLSURFPlugin_Hypothesis_i.hxx
+ BLSURFPlugin_Hypothesis_i.hxx \
+ BLSURFPlugin_Attractor.hxx
# Libraries targets
lib_LTLIBRARIES = libBLSURFEngine.la
BLSURFPlugin_BLSURF_i.cxx \
BLSURFPlugin_Hypothesis.cxx \
BLSURFPlugin_Hypothesis_i.cxx \
- BLSURFPlugin_i.cxx
+ BLSURFPlugin_i.cxx \
+ BLSURFPlugin_Attractor.cxx
libBLSURFEngine_la_CPPFLAGS = \
$(QT_INCLUDES) \