Skip to content
Snippets Groups Projects
Commit ea74526f authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

fix out of bound access

parent 030e50f4
No related branches found
No related tags found
No related merge requests found
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include "GenericFace.h" #include "GenericFace.h"
#include "Context.h" #include "Context.h"
//------------------------------------------------------------------------
GenericEdge::ptrfunction_int_double_refvector GenericEdge::EdgeEvalXYZFromT = NULL; GenericEdge::ptrfunction_int_double_refvector GenericEdge::EdgeEvalXYZFromT = NULL;
GenericEdge::ptrfunction_int_refdouble_refdouble GenericEdge::EdgeEvalParBounds = NULL; GenericEdge::ptrfunction_int_refdouble_refdouble GenericEdge::EdgeEvalParBounds = NULL;
GenericEdge::ptrfunction_int_refstring GenericEdge::EdgeGeomType = NULL; GenericEdge::ptrfunction_int_refstring GenericEdge::EdgeGeomType = NULL;
...@@ -23,28 +21,25 @@ GenericEdge::ptrfunction_int_refvector_refdouble_refvector_refbool GenericEdge:: ...@@ -23,28 +21,25 @@ GenericEdge::ptrfunction_int_refvector_refdouble_refvector_refbool GenericEdge::
GenericEdge::ptrfunction_int_refbool GenericEdge::EdgeIs3D = NULL; GenericEdge::ptrfunction_int_refbool GenericEdge::EdgeIs3D = NULL;
GenericEdge::ptrfunction_int_int_double_int_refvector GenericEdge::EdgeReparamOnFace = NULL; GenericEdge::ptrfunction_int_int_double_int_refvector GenericEdge::EdgeReparamOnFace = NULL;
//------------------------------------------------------------------------ GenericEdge::GenericEdge(GModel *m, int num, int _native_id, GVertex *v1, GVertex *v2)
: GEdge(m, num, v1, v2), id(_native_id)
GenericEdge::GenericEdge(GModel *m, int num, int _native_id, GVertex *v1, GVertex *v2):GEdge(m, num, v1, v2), id(_native_id){ {
if ((!EdgeEvalParBounds)||(!EdgeEvalXYZFromT)) Msg::Error("GenericEdge::ERROR: Callback not set"); if ((!EdgeEvalParBounds)||(!EdgeEvalXYZFromT)) Msg::Error("GenericEdge::ERROR: Callback not set");
bool ok = EdgeEvalParBounds(id,s0,s1); bool ok = EdgeEvalParBounds(id,s0,s1);
if (!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalParBounds ! " ); if (!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalParBounds ! " );
} }
//------------------------------------------------------------------------ GenericEdge::~GenericEdge()
{
GenericEdge::~GenericEdge(){
} }
//------------------------------------------------------------------------ Range<double> GenericEdge::parBounds(int i) const
{
Range<double> GenericEdge::parBounds(int i) const{
return Range<double>(s0, s1); return Range<double>(s0, s1);
} }
//------------------------------------------------------------------------ SPoint2 GenericEdge::reparamOnFace(const GFace *face, double par, int dir) const
{
SPoint2 GenericEdge::reparamOnFace(const GFace *face, double par, int dir) const{
vector<double> res(2,0.); vector<double> res(2,0.);
if (!EdgeReparamOnFace) Msg::Error("GenericEdge::ERROR: Callback EdgeReparamOnFace not set"); if (!EdgeReparamOnFace) Msg::Error("GenericEdge::ERROR: Callback EdgeReparamOnFace not set");
bool ok = EdgeReparamOnFace(id,face->getNativeInt(),par, dir,res); bool ok = EdgeReparamOnFace(id,face->getNativeInt(),par, dir,res);
...@@ -52,9 +47,8 @@ SPoint2 GenericEdge::reparamOnFace(const GFace *face, double par, int dir) const ...@@ -52,9 +47,8 @@ SPoint2 GenericEdge::reparamOnFace(const GFace *face, double par, int dir) const
return SPoint2(res[0],res[1]);; return SPoint2(res[0],res[1]);;
} }
//------------------------------------------------------------------------ GPoint GenericEdge::closestPoint(const SPoint3 &qp, double &param) const
{
GPoint GenericEdge::closestPoint(const SPoint3 &qp, double &param) const{
vector<double> queryPoint(3,0.); vector<double> queryPoint(3,0.);
for (int i=0;i<3;i++) queryPoint[i] = qp[i]; for (int i=0;i<3;i++) queryPoint[i] = qp[i];
vector<double> res(3,0.); vector<double> res(3,0.);
...@@ -66,17 +60,15 @@ GPoint GenericEdge::closestPoint(const SPoint3 &qp, double &param) const{ ...@@ -66,17 +60,15 @@ GPoint GenericEdge::closestPoint(const SPoint3 &qp, double &param) const{
return GPoint(res[0], res[1], res[2], this, param); return GPoint(res[0], res[1], res[2], this, param);
} }
//------------------------------------------------------------------------
// True if the edge is a seam for the given face // True if the edge is a seam for the given face
bool GenericEdge::isSeam(const GFace *face) const{ bool GenericEdge::isSeam(const GFace *face) const
{
Msg::Error("GenericEdge::isSeam: not implemented yet ! "); Msg::Error("GenericEdge::isSeam: not implemented yet ! ");
return false; return false;
} }
//------------------------------------------------------------------------ GPoint GenericEdge::point(double par) const
{
GPoint GenericEdge::point(double par) const{
vector<double> res(3,0.); vector<double> res(3,0.);
if (!EdgeEvalXYZFromT) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalXYZFromT not set"); if (!EdgeEvalXYZFromT) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalXYZFromT not set");
bool ok = EdgeEvalXYZFromT(id,par,res); bool ok = EdgeEvalXYZFromT(id,par,res);
...@@ -84,9 +76,8 @@ GPoint GenericEdge::point(double par) const{ ...@@ -84,9 +76,8 @@ GPoint GenericEdge::point(double par) const{
return GPoint(res[0], res[1], res[2], this, par); return GPoint(res[0], res[1], res[2], this, par);
} }
//------------------------------------------------------------------------ SVector3 GenericEdge::firstDer(double par) const
{
SVector3 GenericEdge::firstDer(double par) const{
vector<double> res(3,0.); vector<double> res(3,0.);
if (!EdgeEvalFirstDer) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalFirstDer not set"); if (!EdgeEvalFirstDer) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalFirstDer not set");
bool ok = EdgeEvalFirstDer(id,par,res); bool ok = EdgeEvalFirstDer(id,par,res);
...@@ -94,9 +85,8 @@ SVector3 GenericEdge::firstDer(double par) const{ ...@@ -94,9 +85,8 @@ SVector3 GenericEdge::firstDer(double par) const{
return SVector3(res[0],res[1],res[2]); return SVector3(res[0],res[1],res[2]);
} }
//------------------------------------------------------------------------ GEntity::GeomType GenericEdge::geomType() const
{
GEntity::GeomType GenericEdge::geomType() const{
string s; string s;
if (!EdgeGeomType) Msg::Error("GenericEdge::ERROR: Callback EdgeGeomType not set"); if (!EdgeGeomType) Msg::Error("GenericEdge::ERROR: Callback EdgeGeomType not set");
bool ok = EdgeGeomType(id,s); bool ok = EdgeGeomType(id,s);
...@@ -127,9 +117,8 @@ GEntity::GeomType GenericEdge::geomType() const{ ...@@ -127,9 +117,8 @@ GEntity::GeomType GenericEdge::geomType() const{
return Unknown; return Unknown;
} }
//------------------------------------------------------------------------ double GenericEdge::curvature(double par) const
{
double GenericEdge::curvature(double par) const{
double res; double res;
if (!EdgeEvalCurvature) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalCurvature not set"); if (!EdgeEvalCurvature) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalCurvature not set");
bool ok = EdgeEvalCurvature(id,par,res); bool ok = EdgeEvalCurvature(id,par,res);
...@@ -137,9 +126,8 @@ double GenericEdge::curvature(double par) const{ ...@@ -137,9 +126,8 @@ double GenericEdge::curvature(double par) const{
return res; return res;
} }
//------------------------------------------------------------------------ bool GenericEdge::is3D() const
{
bool GenericEdge::is3D() const{
bool res; bool res;
if (!EdgeIs3D) Msg::Error("GenericEdge::ERROR: Callback EdgeIs3D not set"); if (!EdgeIs3D) Msg::Error("GenericEdge::ERROR: Callback EdgeIs3D not set");
bool ok = EdgeIs3D(id,res); bool ok = EdgeIs3D(id,res);
...@@ -147,16 +135,11 @@ bool GenericEdge::is3D() const{ ...@@ -147,16 +135,11 @@ bool GenericEdge::is3D() const{
return res; return res;
} }
//------------------------------------------------------------------------ bool GenericEdge::degenerate(int) const
{
bool GenericEdge::degenerate(int) const{
bool res; bool res;
if (!EdgeDegenerated) Msg::Error("GenericEdge::ERROR: Callback EdgeDegenerated not set"); if (!EdgeDegenerated) Msg::Error("GenericEdge::ERROR: Callback EdgeDegenerated not set");
bool ok = EdgeDegenerated(id,res); bool ok = EdgeDegenerated(id,res);
if (!ok) Msg::Error("GenericEdge::ERROR from EdgeDegenerated ! " ); if (!ok) Msg::Error("GenericEdge::ERROR from EdgeDegenerated ! " );
return res; return res;
} }
//------------------------------------------------------------------------
...@@ -18,68 +18,67 @@ using namespace std; ...@@ -18,68 +18,67 @@ using namespace std;
class GenericFace; class GenericFace;
/*The set of Generic Entities is a generic interface to any other modeler. /*The set of Generic Entities is a generic interface to any other modeler.
Callbacks (function pointers) are given, sending requests, enquiries, to the native modeler. */ Callbacks (function pointers) are given, sending requests, enquiries, to the
native modeler. */
class GenericEdge : public GEdge { class GenericEdge : public GEdge {
protected: protected:
double s0, s1; double s0, s1;
int id; int id;
public: public:
// callbacks typedef // callbacks typedef
typedef bool (*ptrfunction_int_double_refvector)(int, double, vector<double>&); typedef bool (*ptrfunction_int_double_refvector)(int, double, vector<double>&);
typedef bool (*ptrfunction_int_refdouble_refdouble)(int, double&, double&); typedef bool (*ptrfunction_int_refdouble_refdouble)(int, double&, double&);
typedef bool (*ptrfunction_int_double_refdouble)(int, double, double&); typedef bool (*ptrfunction_int_double_refdouble)(int, double, double&);
typedef bool (*ptrfunction_int_refstring)(int, string&); typedef bool (*ptrfunction_int_refstring)(int, string&);
typedef bool (*ptrfunction_int_refbool)(int, bool&); typedef bool (*ptrfunction_int_refbool)(int, bool&);
typedef bool (*ptrfunction_int_refvector_refdouble_refvector_refbool)(int, const vector<double> &, double &, vector<double>&, bool &); typedef bool (*ptrfunction_int_refvector_refdouble_refvector_refbool)
typedef bool (*ptrfunction_int_int_double_int_refvector)(int, int, double, int, vector<double> &); (int, const vector<double> &, double &, vector<double>&, bool &);
typedef bool (*ptrfunction_int_int_double_int_refvector)(int, int, double, int, vector<double> &);
GenericEdge(GModel *model, int num,int _native_id, GVertex *v1, GVertex *v2);
virtual ~GenericEdge(); GenericEdge(GModel *model, int num,int _native_id, GVertex *v1, GVertex *v2);
virtual ~GenericEdge();
virtual Range<double> parBounds(int i) const;
virtual GeomType geomType() const; virtual Range<double> parBounds(int i) const;
virtual bool degenerate(int) const; virtual GeomType geomType() const;
virtual GPoint point(double p) const; virtual bool degenerate(int) const;
virtual SVector3 firstDer(double par) const; virtual GPoint point(double p) const;
virtual double curvature (double par) const; virtual SVector3 firstDer(double par) const;
virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const; virtual double curvature (double par) const;
virtual GPoint closestPoint(const SPoint3 &queryPoint, double &param) const; virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const;
virtual GPoint closestPoint(const SPoint3 &queryPoint, double &param) const;
ModelType getNativeType() const { return GenericModel; }
virtual int getNativeInt()const{return id;}; ModelType getNativeType() const { return GenericModel; }
virtual int getNativeInt()const{return id;};
bool is3D() const;
bool isSeam(const GFace *) const; bool is3D() const;
bool isSeam(const GFace *) const;
// sets the callbacks, to be given by the user
static void setEdgeEvalXYZFromT(ptrfunction_int_double_refvector fct){EdgeEvalXYZFromT = fct;}; // sets the callbacks, to be given by the user
static void setEdgeEvalParBounds(ptrfunction_int_refdouble_refdouble fct){EdgeEvalParBounds = fct;}; static void setEdgeEvalXYZFromT(ptrfunction_int_double_refvector fct){EdgeEvalXYZFromT = fct;};
static void setEdgeGeomType(ptrfunction_int_refstring fct){EdgeGeomType = fct;}; static void setEdgeEvalParBounds(ptrfunction_int_refdouble_refdouble fct){EdgeEvalParBounds = fct;};
static void setEdgeDegenerated(ptrfunction_int_refbool fct){EdgeDegenerated = fct;}; static void setEdgeGeomType(ptrfunction_int_refstring fct){EdgeGeomType = fct;};
static void setEdgeEvalFirstDer(ptrfunction_int_double_refvector fct){EdgeEvalFirstDer = fct;}; static void setEdgeDegenerated(ptrfunction_int_refbool fct){EdgeDegenerated = fct;};
static void setEdgeEvalCurvature(ptrfunction_int_double_refdouble fct){EdgeEvalCurvature = fct;}; static void setEdgeEvalFirstDer(ptrfunction_int_double_refvector fct){EdgeEvalFirstDer = fct;};
static void setEdgeClosestPoint(ptrfunction_int_refvector_refdouble_refvector_refbool fct){EdgeClosestPoint = fct;}; static void setEdgeEvalCurvature(ptrfunction_int_double_refdouble fct){EdgeEvalCurvature = fct;};
static void setEdgeIs3D(ptrfunction_int_refbool fct){EdgeIs3D = fct;}; static void setEdgeClosestPoint(ptrfunction_int_refvector_refdouble_refvector_refbool fct){EdgeClosestPoint = fct;};
static void setEdgeReparamOnFace(ptrfunction_int_int_double_int_refvector fct){EdgeReparamOnFace = fct;}; static void setEdgeIs3D(ptrfunction_int_refbool fct){EdgeIs3D = fct;};
static void setEdgeReparamOnFace(ptrfunction_int_int_double_int_refvector fct){EdgeReparamOnFace = fct;};
private:
// the callbacks: private:
// -------------- // the callbacks:
static ptrfunction_int_double_refvector EdgeEvalXYZFromT; static ptrfunction_int_double_refvector EdgeEvalXYZFromT;
static ptrfunction_int_refdouble_refdouble EdgeEvalParBounds; static ptrfunction_int_refdouble_refdouble EdgeEvalParBounds;
static ptrfunction_int_refstring EdgeGeomType; static ptrfunction_int_refstring EdgeGeomType;
static ptrfunction_int_refbool EdgeDegenerated; static ptrfunction_int_refbool EdgeDegenerated;
static ptrfunction_int_double_refvector EdgeEvalFirstDer; static ptrfunction_int_double_refvector EdgeEvalFirstDer;
static ptrfunction_int_double_refdouble EdgeEvalCurvature; static ptrfunction_int_double_refdouble EdgeEvalCurvature;
// the first vector is a query point xyz, fills the second vector with closest point // the first vector is a query point xyz, fills the second vector with closest
// on edge using orthogonal projection. Fills double param with parametric coordinate of end point projection. // point on edge using orthogonal projection. Fills double param with
static ptrfunction_int_refvector_refdouble_refvector_refbool EdgeClosestPoint; // parametric coordinate of end point projection.
static ptrfunction_int_refbool EdgeIs3D; static ptrfunction_int_refvector_refdouble_refvector_refbool EdgeClosestPoint;
static ptrfunction_int_int_double_int_refvector EdgeReparamOnFace; static ptrfunction_int_refbool EdgeIs3D;
static ptrfunction_int_int_double_int_refvector EdgeReparamOnFace;
}; };
#endif #endif
...@@ -14,9 +14,6 @@ ...@@ -14,9 +14,6 @@
#include "Context.h" #include "Context.h"
#include <math.h> #include <math.h>
//------------------------------------------------------------------------
GenericFace::ptrfunction_int_refstring GenericFace::FaceGeomType = NULL; GenericFace::ptrfunction_int_refstring GenericFace::FaceGeomType = NULL;
GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceUVFromXYZ = NULL; GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceUVFromXYZ = NULL;
GenericFace::ptrfunction_int_refvector_refvector_refvector GenericFace::FaceClosestPoint = NULL; GenericFace::ptrfunction_int_refvector_refvector_refvector GenericFace::FaceClosestPoint = NULL;
...@@ -29,9 +26,8 @@ GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceEvalNormal = N ...@@ -29,9 +26,8 @@ GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceEvalNormal = N
GenericFace::ptrfunction_int_refvector_refvector_refvector GenericFace::FaceFirstDer = NULL; GenericFace::ptrfunction_int_refvector_refvector_refvector GenericFace::FaceFirstDer = NULL;
GenericFace::ptrfunction_int_refvector_refvector_refvector_refvector GenericFace::FaceSecondDer = NULL; GenericFace::ptrfunction_int_refvector_refvector_refvector_refvector GenericFace::FaceSecondDer = NULL;
//------------------------------------------------------------------------ GenericFace::GenericFace(GModel *m, int num, int _native_id):GFace(m, num), id(_native_id)
{
GenericFace::GenericFace(GModel *m, int num, int _native_id):GFace(m, num), id(_native_id){
if (!FaceParBounds) Msg::Fatal("Genericface::ERROR: Callback FaceParBounds not set"); if (!FaceParBounds) Msg::Fatal("Genericface::ERROR: Callback FaceParBounds not set");
Range<double> rangeu = parBounds(0); Range<double> rangeu = parBounds(0);
Range<double> rangev = parBounds(1); Range<double> rangev = parBounds(1);
...@@ -39,58 +35,53 @@ GenericFace::GenericFace(GModel *m, int num, int _native_id):GFace(m, num), id(_ ...@@ -39,58 +35,53 @@ GenericFace::GenericFace(GModel *m, int num, int _native_id):GFace(m, num), id(_
umax = rangeu.high(); umax = rangeu.high();
vmin = rangev.low(); vmin = rangev.low();
vmax = rangev.high(); vmax = rangev.high();
// TODO: set periodic or not !!! // TODO: set periodic or not !!!
//bool _periodic[2];// is periodic in u, v //bool _periodic[2];// is periodic in u, v
// throw; // throw;
} }
//------------------------------------------------------------------------ GenericFace::~GenericFace()
{
GenericFace::~GenericFace(){
} }
//------------------------------------------------------------------------ Range<double> GenericFace::parBounds(int i) const
{
Range<double> GenericFace::parBounds(int i) const{
if(i == 0) return Range<double>(umin, umax); if(i == 0) return Range<double>(umin, umax);
return Range<double>(vmin, vmax); return Range<double>(vmin, vmax);
} }
//------------------------------------------------------------------------ SVector3 GenericFace::normal(const SPoint2 &param) const
{
SVector3 GenericFace::normal(const SPoint2 &param) const{
vector<double> res(3,0.); vector<double> res(3,0.);
vector<double> par(2,0.); vector<double> par(2,0.);
for (int i=0;i<3;i++) par[i] = param[i]; for (int i=0;i<2;i++) par[i] = param[i];
if (!FaceEvalNormal) Msg::Fatal("Genericface::ERROR: Callback FaceEvalNormal not set"); if (!FaceEvalNormal) Msg::Fatal("Genericface::ERROR: Callback FaceEvalNormal not set");
bool ok = FaceEvalNormal(id,par,res); bool ok = FaceEvalNormal(id,par,res);
if (!ok) Msg::Error("GenericFace::ERROR from FaceEvalNormal ! " ); if (!ok) Msg::Error("GenericFace::ERROR from FaceEvalNormal ! " );
return SVector3(res[0],res[1],res[2]); return SVector3(res[0],res[1],res[2]);
} }
//------------------------------------------------------------------------ Pair<SVector3,SVector3> GenericFace::firstDer(const SPoint2 &param) const
{
Pair<SVector3,SVector3> GenericFace::firstDer(const SPoint2 &param) const{
if (!FaceFirstDer) Msg::Fatal("Genericface::ERROR: Callback FaceFirstDer not set"); if (!FaceFirstDer) Msg::Fatal("Genericface::ERROR: Callback FaceFirstDer not set");
vector<double> deru(3,0.); vector<double> deru(3,0.);
vector<double> derv(3,0.); vector<double> derv(3,0.);
vector<double> par(2,0.); vector<double> par(2,0.);
for (int i=0;i<3;i++) par[i] = param[i]; for (int i=0;i<2;i++) par[i] = param[i];
bool ok = FaceFirstDer(id,par,deru,derv); bool ok = FaceFirstDer(id,par,deru,derv);
if (!ok) Msg::Error("GenericFace::ERROR from FaceFirstDer ! " ); if (!ok) Msg::Error("GenericFace::ERROR from FaceFirstDer ! " );
return Pair<SVector3,SVector3>(SVector3(deru[0],deru[1],deru[2]), return Pair<SVector3,SVector3>(SVector3(deru[0],deru[1],deru[2]),
SVector3(derv[0],derv[1],derv[2])); SVector3(derv[0],derv[1],derv[2]));
} }
//------------------------------------------------------------------------ void GenericFace::secondDer(const SPoint2 &param,SVector3 *dudu, SVector3 *dvdv, SVector3 *dudv) const
{
void GenericFace::secondDer(const SPoint2 &param,SVector3 *dudu, SVector3 *dvdv, SVector3 *dudv) const{
vector<double> deruu(3,0.); vector<double> deruu(3,0.);
vector<double> dervv(3,0.); vector<double> dervv(3,0.);
vector<double> deruv(3,0.); vector<double> deruv(3,0.);
vector<double> par(2,0.); vector<double> par(2,0.);
for (int i=0;i<3;i++) par[i] = param[i]; for (int i=0;i<2;i++) par[i] = param[i];
if (!FaceSecondDer) Msg::Fatal("Genericface::ERROR: Callback FaceSecondDer not set"); if (!FaceSecondDer) Msg::Fatal("Genericface::ERROR: Callback FaceSecondDer not set");
bool ok = FaceSecondDer(id,par,deruu,dervv,deruv); bool ok = FaceSecondDer(id,par,deruu,dervv,deruv);
if (!ok) Msg::Error("GenericFace::ERROR from FaceSecondDer ! " ); if (!ok) Msg::Error("GenericFace::ERROR from FaceSecondDer ! " );
...@@ -100,9 +91,8 @@ void GenericFace::secondDer(const SPoint2 &param,SVector3 *dudu, SVector3 *dvdv, ...@@ -100,9 +91,8 @@ void GenericFace::secondDer(const SPoint2 &param,SVector3 *dudu, SVector3 *dvdv,
return; return;
} }
//------------------------------------------------------------------------ GPoint GenericFace::point(double par1, double par2) const
{
GPoint GenericFace::point(double par1, double par2) const{
vector<double> uv(2,0.); vector<double> uv(2,0.);
uv[0] = par1; uv[0] = par1;
uv[1] = par2; uv[1] = par2;
...@@ -114,9 +104,8 @@ GPoint GenericFace::point(double par1, double par2) const{ ...@@ -114,9 +104,8 @@ GPoint GenericFace::point(double par1, double par2) const{
return GPoint(xyz[0], xyz[1], xyz[2], this, pp); return GPoint(xyz[0], xyz[1], xyz[2], this, pp);
} }
//------------------------------------------------------------------------ GPoint GenericFace::closestPoint(const SPoint3 &qp, const double initialGuess[2]) const
{
GPoint GenericFace::closestPoint(const SPoint3 &qp, const double initialGuess[2]) const{
vector<double> uvres(2,0.); vector<double> uvres(2,0.);
vector<double> xyzres(3,0.); vector<double> xyzres(3,0.);
vector<double> queryPoint(3,0.); vector<double> queryPoint(3,0.);
...@@ -140,9 +129,8 @@ GPoint GenericFace::closestPoint(const SPoint3 &qp, const double initialGuess[2] ...@@ -140,9 +129,8 @@ GPoint GenericFace::closestPoint(const SPoint3 &qp, const double initialGuess[2]
return GPoint(xyzres[0], xyzres[1], xyzres[2], this, pp); return GPoint(xyzres[0], xyzres[1], xyzres[2], this, pp);
} }
//------------------------------------------------------------------------ SPoint2 GenericFace::parFromPoint(const SPoint3 &qp, bool onSurface) const
{
SPoint2 GenericFace::parFromPoint(const SPoint3 &qp, bool onSurface) const{
vector<double> uvres(2,0.); vector<double> uvres(2,0.);
vector<double> xyzres(3,0.); vector<double> xyzres(3,0.);
vector<double> queryPoint(3,0.); vector<double> queryPoint(3,0.);
...@@ -150,7 +138,7 @@ SPoint2 GenericFace::parFromPoint(const SPoint3 &qp, bool onSurface) const{ ...@@ -150,7 +138,7 @@ SPoint2 GenericFace::parFromPoint(const SPoint3 &qp, bool onSurface) const{
bool ok=true; bool ok=true;
if (onSurface){ if (onSurface){
if (!FaceUVFromXYZ) Msg::Fatal("Genericface::ERROR: Callback FaceUVFromXYZ not set"); if (!FaceUVFromXYZ) Msg::Fatal("Genericface::ERROR: Callback FaceUVFromXYZ not set");
ok = FaceUVFromXYZ(id,queryPoint,uvres);// assuming point is on surface ok = FaceUVFromXYZ(id,queryPoint,uvres);// assuming point is on surface
if (!ok) Msg::Error("GenericFace::ERROR from FaceUVFromXYZ ! " ); if (!ok) Msg::Error("GenericFace::ERROR from FaceUVFromXYZ ! " );
} }
if ((!onSurface)||(!ok)){// if not on surface if ((!onSurface)||(!ok)){// if not on surface
...@@ -166,9 +154,8 @@ SPoint2 GenericFace::parFromPoint(const SPoint3 &qp, bool onSurface) const{ ...@@ -166,9 +154,8 @@ SPoint2 GenericFace::parFromPoint(const SPoint3 &qp, bool onSurface) const{
return SPoint2(uvres[0],uvres[1]); return SPoint2(uvres[0],uvres[1]);
} }
//------------------------------------------------------------------------ GEntity::GeomType GenericFace::geomType() const
{
GEntity::GeomType GenericFace::geomType() const{
string s; string s;
if (!FaceGeomType) Msg::Fatal("Genericface::ERROR: Callback FaceGeomType not set"); if (!FaceGeomType) Msg::Fatal("Genericface::ERROR: Callback FaceGeomType not set");
bool ok = FaceGeomType(id,s); bool ok = FaceGeomType(id,s);
...@@ -197,40 +184,38 @@ GEntity::GeomType GenericFace::geomType() const{ ...@@ -197,40 +184,38 @@ GEntity::GeomType GenericFace::geomType() const{
return Unknown; return Unknown;
} }
//------------------------------------------------------------------------ double GenericFace::curvatureMax(const SPoint2 &param) const
{
double GenericFace::curvatureMax(const SPoint2 &param) const{
vector<double> dirMax(3,0.); vector<double> dirMax(3,0.);
vector<double> dirMin(3,0.); vector<double> dirMin(3,0.);
double curvMax,curvMin; double curvMax,curvMin;
vector<double> par(2,0.); vector<double> par(2,0.);
for (int i=0;i<3;i++) par[i] = param[i]; for (int i=0;i<2;i++) par[i] = param[i];
if (!FaceCurvatures) Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set"); if (!FaceCurvatures) Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set");
bool ok = FaceCurvatures(id,par,dirMax,dirMin,curvMax,curvMin); bool ok = FaceCurvatures(id,par,dirMax,dirMin,curvMax,curvMin);
if (!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! " ); if (!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! " );
return std::max(fabs(curvMax), fabs(curvMin)); return std::max(fabs(curvMax), fabs(curvMin));
} }
//------------------------------------------------------------------------ double GenericFace::curvatures(const SPoint2 &_param,SVector3 *_dirMax,SVector3 *_dirMin,
double *curvMax,double *curvMin) const
double GenericFace::curvatures(const SPoint2 &_param,SVector3 *_dirMax,SVector3 *_dirMin,double *curvMax,double *curvMin) const{ {
vector<double> param(2,0.); vector<double> param(2,0.);
for (int i=0;i<3;i++) param[i] = _param[i]; for (int i=0;i<2;i++) param[i] = _param[i];
vector<double> dirMax(3,0.); vector<double> dirMax(3,0.);
vector<double> dirMin(3,0.); vector<double> dirMin(3,0.);
if (!FaceCurvatures) Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set"); if (!FaceCurvatures) Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set");
bool ok = FaceCurvatures(id,param,dirMax,dirMin,*curvMax,*curvMin); bool ok = FaceCurvatures(id,param,dirMax,dirMin,*curvMax,*curvMin);
if (!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! " ); if (!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! " );
*_dirMax = SVector3(dirMax[0],dirMax[1],dirMax[2]); *_dirMax = SVector3(dirMax[0],dirMax[1],dirMax[2]);
*_dirMin = SVector3(dirMin[0],dirMin[1],dirMin[2]); *_dirMin = SVector3(dirMin[0],dirMin[1],dirMin[2]);
return *curvMax; return *curvMax;
} }
//------------------------------------------------------------------------ bool GenericFace::containsPoint(const SPoint3 &pt) const
{
bool GenericFace::containsPoint(const SPoint3 &pt) const{
bool res; bool res;
vector<double> queryPoint(3,0.); vector<double> queryPoint(3,0.);
for (int i=0;i<3;i++) queryPoint[i] = pt[i]; for (int i=0;i<3;i++) queryPoint[i] = pt[i];
...@@ -240,5 +225,3 @@ bool GenericFace::containsPoint(const SPoint3 &pt) const{ ...@@ -240,5 +225,3 @@ bool GenericFace::containsPoint(const SPoint3 &pt) const{
return res; return res;
} }
//------------------------------------------------------------------------
...@@ -16,77 +16,80 @@ ...@@ -16,77 +16,80 @@
using namespace std; using namespace std;
/*The set of Generic Entities is a generic interface to any other modeler. /* The set of Generic Entities is a generic interface to any other modeler.
Callbacks (function pointers) are given, sending requests, enquiries, to the native modeler. */ Callbacks (function pointers) are given, sending requests, enquiries, to the
native modeler. */
class GenericFace : public GFace { class GenericFace : public GFace {
protected: protected:
int id; int id;
double umin, umax, vmin, vmax;// face uv bounds double umin, umax, vmin, vmax;// face uv bounds
bool _periodic[2];// is periodic in u, v bool _periodic[2];// is periodic in u, v
public: public:
// callbacks typedef // callbacks typedef
typedef bool (*ptrfunction_int_refstring)(int, string&); typedef bool (*ptrfunction_int_refstring)(int, string&);
typedef bool (*ptrfunction_int_refvector_refvector)(const int , const vector<double> &, vector<double> &); typedef bool (*ptrfunction_int_refvector_refvector)(const int , const vector<double> &, vector<double> &);
typedef bool (*ptrfunction_int_refvector_refvector_refvector)(const int , const vector<double> &, vector<double> &, vector<double> &); typedef bool (*ptrfunction_int_refvector_refvector_refvector)
typedef bool (*ptrfunction_int_refvector_refbool)(const int , const vector<double> &, bool &); (const int , const vector<double> &, vector<double> &, vector<double> &);
typedef bool (*ptrfunction_int_int_refdouble_refdouble)(const int, const int, double &, double &); typedef bool (*ptrfunction_int_refvector_refbool)(const int , const vector<double> &, bool &);
typedef bool (*ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble)(const int, const vector<double> &, vector<double> &, vector<double> &, double &, double &); typedef bool (*ptrfunction_int_int_refdouble_refdouble)(const int, const int, double &, double &);
typedef bool (*ptrfunction_int_refvector_refvector_refvector_refvector)(const int , const vector<double> &, vector<double> &, vector<double> &, vector<double> &); typedef bool (*ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble)
(const int, const vector<double> &, vector<double> &, vector<double> &, double &, double &);
typedef bool (*ptrfunction_int_refvector_refvector_refvector_refvector)
(const int , const vector<double> &, vector<double> &, vector<double> &, vector<double> &);
GenericFace(GModel *m, int num, int _native_id); GenericFace(GModel *m, int num, int _native_id);
virtual ~GenericFace(); virtual ~GenericFace();
Range<double> parBounds(int i) const; Range<double> parBounds(int i) const;
virtual GPoint point(double par1, double par2) const; virtual GPoint point(double par1, double par2) const;
virtual GPoint closestPoint(const SPoint3 & queryPoint, virtual GPoint closestPoint(const SPoint3 & queryPoint,
const double initialGuess[2]) const; const double initialGuess[2]) const;
virtual bool containsPoint(const SPoint3 &pt) const; virtual bool containsPoint(const SPoint3 &pt) const;
virtual SVector3 normal(const SPoint2 &param) const; virtual SVector3 normal(const SPoint2 &param) const;
virtual Pair<SVector3,SVector3> firstDer(const SPoint2 &param) const; virtual Pair<SVector3,SVector3> firstDer(const SPoint2 &param) const;
virtual void secondDer(const SPoint2 &, SVector3 *, SVector3 *, SVector3 *) const; virtual void secondDer(const SPoint2 &, SVector3 *, SVector3 *, SVector3 *) const;
virtual GEntity::GeomType geomType() const; virtual GEntity::GeomType geomType() const;
virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const;
virtual double curvatureMax(const SPoint2 &param) const; virtual double curvatureMax(const SPoint2 &param) const;
virtual double curvatures(const SPoint2 &param, SVector3 *dirMax, SVector3 *dirMin, virtual double curvatures(const SPoint2 &param, SVector3 *dirMax, SVector3 *dirMin,
double *curvMax, double *curvMin) const; double *curvMax, double *curvMin) const;
ModelType getNativeType() const { return GenericModel; } ModelType getNativeType() const { return GenericModel; }
virtual int getNativeInt()const{return id;}; virtual int getNativeInt()const{return id;};
void addBndInfo(int loop, GEdge *ptr, int sign){
bnd.insert(make_pair(loop, make_pair(ptr,sign)));
l_dirs.push_back(sign);
l_edges.push_back(ptr);
ptr->addFace(this);
};
// sets callbacks
static void setFaceGeomType(ptrfunction_int_refstring fct){FaceGeomType = fct;};
static void setFaceUVFromXYZ(ptrfunction_int_refvector_refvector fct){FaceUVFromXYZ = fct;};
static void setFaceClosestPoint(ptrfunction_int_refvector_refvector_refvector fct){FaceClosestPoint = fct;};
static void setFaceContainsPointFromXYZ(ptrfunction_int_refvector_refbool fct){FaceContainsPointFromXYZ = fct;};
static void setFaceContainsPointFromUV(ptrfunction_int_refvector_refbool fct){FaceContainsPointFromUV = fct;};
static void setFaceXYZFromUV(ptrfunction_int_refvector_refvector fct){FaceXYZFromUV = fct;};
static void setFaceParBounds(ptrfunction_int_int_refdouble_refdouble fct){FaceParBounds = fct;};
static void setFaceCurvatures(ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble fct){FaceCurvatures = fct;};
static void setFaceEvalNormal(ptrfunction_int_refvector_refvector fct){FaceEvalNormal = fct;};
static void setFaceFirstDer(ptrfunction_int_refvector_refvector_refvector fct){FaceFirstDer = fct;};
static void setFaceSecondDer(ptrfunction_int_refvector_refvector_refvector_refvector fct){FaceSecondDer = fct;};
private:
multimap<int, pair<GEdge*,int> > bnd;
// the callbacks: void addBndInfo(int loop, GEdge *ptr, int sign){
static ptrfunction_int_refstring FaceGeomType; bnd.insert(make_pair(loop, make_pair(ptr,sign)));
static ptrfunction_int_refvector_refvector FaceUVFromXYZ,FaceXYZFromUV,FaceEvalNormal; l_dirs.push_back(sign);
static ptrfunction_int_refvector_refvector_refvector FaceClosestPoint,FaceFirstDer; l_edges.push_back(ptr);
static ptrfunction_int_refvector_refbool FaceContainsPointFromXYZ,FaceContainsPointFromUV; ptr->addFace(this);
static ptrfunction_int_int_refdouble_refdouble FaceParBounds; };
static ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble FaceCurvatures;
static ptrfunction_int_refvector_refvector_refvector_refvector FaceSecondDer;
// sets callbacks
static void setFaceGeomType(ptrfunction_int_refstring fct){FaceGeomType = fct;};
static void setFaceUVFromXYZ(ptrfunction_int_refvector_refvector fct){FaceUVFromXYZ = fct;};
static void setFaceClosestPoint(ptrfunction_int_refvector_refvector_refvector fct){FaceClosestPoint = fct;};
static void setFaceContainsPointFromXYZ(ptrfunction_int_refvector_refbool fct){FaceContainsPointFromXYZ = fct;};
static void setFaceContainsPointFromUV(ptrfunction_int_refvector_refbool fct){FaceContainsPointFromUV = fct;};
static void setFaceXYZFromUV(ptrfunction_int_refvector_refvector fct){FaceXYZFromUV = fct;};
static void setFaceParBounds(ptrfunction_int_int_refdouble_refdouble fct){FaceParBounds = fct;};
static void setFaceCurvatures(ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble fct){FaceCurvatures = fct;};
static void setFaceEvalNormal(ptrfunction_int_refvector_refvector fct){FaceEvalNormal = fct;};
static void setFaceFirstDer(ptrfunction_int_refvector_refvector_refvector fct){FaceFirstDer = fct;};
static void setFaceSecondDer(ptrfunction_int_refvector_refvector_refvector_refvector fct){FaceSecondDer = fct;};
private:
multimap<int, pair<GEdge*,int> > bnd;
// the callbacks:
static ptrfunction_int_refstring FaceGeomType;
static ptrfunction_int_refvector_refvector FaceUVFromXYZ,FaceXYZFromUV,FaceEvalNormal;
static ptrfunction_int_refvector_refvector_refvector FaceClosestPoint,FaceFirstDer;
static ptrfunction_int_refvector_refbool FaceContainsPointFromXYZ,FaceContainsPointFromUV;
static ptrfunction_int_int_refdouble_refdouble FaceParBounds;
static ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble FaceCurvatures;
static ptrfunction_int_refvector_refvector_refvector_refvector FaceSecondDer;
}; };
#endif #endif
...@@ -11,24 +11,15 @@ ...@@ -11,24 +11,15 @@
#include "GenericFace.h" #include "GenericFace.h"
#include "GenericRegion.h" #include "GenericRegion.h"
//------------------------------------------------------------------------
GenericRegion::GenericRegion(GModel *m, int num, int _native_id):GRegion(m, num), id(_native_id) GenericRegion::GenericRegion(GModel *m, int num, int _native_id):GRegion(m, num), id(_native_id)
{ {
} }
//------------------------------------------------------------------------
GenericRegion::~GenericRegion() GenericRegion::~GenericRegion()
{ {
} }
//------------------------------------------------------------------------
GEntity::GeomType GenericRegion::geomType() const GEntity::GeomType GenericRegion::geomType() const
{ {
return Unknown; return Unknown;
} }
//------------------------------------------------------------------------
...@@ -10,28 +10,30 @@ ...@@ -10,28 +10,30 @@
#include "GRegion.h" #include "GRegion.h"
/*The set of Generic Entities is a generic interface to any other modeler. /*The set of Generic Entities is a generic interface to any other modeler.
Callbacks (function pointers) are given, sending requests, enquiries, to the native modeler. */ Callbacks (function pointers) are given, sending requests, enquiries, to the
native modeler. */
class GenericRegion : public GRegion { class GenericRegion : public GRegion {
public: public:
GenericRegion(GModel *m, int num, int _native_id); GenericRegion(GModel *m, int num, int _native_id);
virtual ~GenericRegion(); virtual ~GenericRegion();
virtual GeomType geomType() const; virtual GeomType geomType() const;
ModelType getNativeType() const { return GenericModel; } ModelType getNativeType() const { return GenericModel; }
virtual int getNativeInt()const{return id;}; virtual int getNativeInt()const{return id;};
// TODO: When using GRegion->l_dirs and l_faces, what is the convention for l_dirs ? For now, assuming positive value for normals pointing inside the region. // TODO: When using GRegion->l_dirs and l_faces, what is the convention for
void addFace(GenericFace *ptr, int sign){ // l_dirs ? For now, assuming positive value for normals pointing inside the
l_dirs.push_back(sign); // region.
l_faces.push_back(ptr); void addFace(GenericFace *ptr, int sign){
ptr->addRegion(this); l_dirs.push_back(sign);
}; l_faces.push_back(ptr);
ptr->addRegion(this);
};
private:
int id; private:
int id;
}; };
#endif #endif
...@@ -12,13 +12,10 @@ ...@@ -12,13 +12,10 @@
#include "GenericFace.h" #include "GenericFace.h"
#include<algorithm> #include<algorithm>
//------------------------------------------------------------------------
GenericVertex::ptrfunction_int_vector GenericVertex::VertexXYZ = NULL; GenericVertex::ptrfunction_int_vector GenericVertex::VertexXYZ = NULL;
//------------------------------------------------------------------------ GenericVertex::GenericVertex(GModel *m, int num, int _native_id):GVertex(m, num), id(_native_id)
{
GenericVertex::GenericVertex(GModel *m, int num, int _native_id):GVertex(m, num), id(_native_id){
if (!VertexXYZ) if (!VertexXYZ)
Msg::Fatal("GenericVertex::ERROR: Callback not set"); Msg::Fatal("GenericVertex::ERROR: Callback not set");
...@@ -30,13 +27,10 @@ GenericVertex::GenericVertex(GModel *m, int num, int _native_id):GVertex(m, num) ...@@ -30,13 +27,10 @@ GenericVertex::GenericVertex(GModel *m, int num, int _native_id):GVertex(m, num)
_z=vec[2]; _z=vec[2];
} }
//------------------------------------------------------------------------ GenericVertex::~GenericVertex()
{
GenericVertex::~GenericVertex(){
} }
//------------------------------------------------------------------------
SPoint2 GenericVertex::reparamOnFace(const GFace *gf, int dir) const SPoint2 GenericVertex::reparamOnFace(const GFace *gf, int dir) const
{ {
std::list<GEdge*>::const_iterator it = l_edges.begin(); std::list<GEdge*>::const_iterator it = l_edges.begin();
...@@ -75,8 +69,6 @@ SPoint2 GenericVertex::reparamOnFace(const GFace *gf, int dir) const ...@@ -75,8 +69,6 @@ SPoint2 GenericVertex::reparamOnFace(const GFace *gf, int dir) const
return GVertex::reparamOnFace(gf, dir); return GVertex::reparamOnFace(gf, dir);
} }
//------------------------------------------------------------------------
void GenericVertex::setPosition(GPoint &p) void GenericVertex::setPosition(GPoint &p)
{ {
_x = p.x(); _x = p.x();
...@@ -88,5 +80,3 @@ void GenericVertex::setPosition(GPoint &p) ...@@ -88,5 +80,3 @@ void GenericVertex::setPosition(GPoint &p)
mesh_vertices[0]->z() = p.z(); mesh_vertices[0]->z() = p.z();
} }
} }
//------------------------------------------------------------------------
...@@ -13,39 +13,39 @@ ...@@ -13,39 +13,39 @@
using namespace std; using namespace std;
/*The set of Generic Entities is a generic interface to any other modeler. /* The set of Generic Entities is a generic interface to any other modeler.
Callbacks (function pointers) are given, sending requests, enquiries, to the native modeler. */ Callbacks (function pointers) are given, sending requests, enquiries, to the
native modeler. */
class GenericVertex : public GVertex { class GenericVertex : public GVertex {
protected: protected:
int id; int id;
double _x, _y, _z; double _x, _y, _z;
public: public:
// callbacks typedef // callbacks typedef
typedef bool (*ptrfunction_int_vector)(int, vector<double>&); typedef bool (*ptrfunction_int_vector)(int, vector<double>&);
GenericVertex(GModel *m, int num, int _native_id); GenericVertex(GModel *m, int num, int _native_id);
virtual ~GenericVertex(); virtual ~GenericVertex();
virtual GPoint point() const { return GPoint(x(), y(), z()); } virtual GPoint point() const { return GPoint(x(), y(), z()); }
virtual double x() const { return _x; } virtual double x() const { return _x; }
virtual double y() const { return _y; } virtual double y() const { return _y; }
virtual double z() const { return _z; } virtual double z() const { return _z; }
virtual void setPosition(GPoint &p); virtual void setPosition(GPoint &p);
virtual SPoint2 reparamOnFace(const GFace *gf, int) const; virtual SPoint2 reparamOnFace(const GFace *gf, int) const;
ModelType getNativeType() const { return GenericModel; } ModelType getNativeType() const { return GenericModel; }
virtual int getNativeInt()const{return id;}; virtual int getNativeInt()const{return id;};
// sets the callbacks // sets the callbacks
static void setVertexXYZ(ptrfunction_int_vector fct){VertexXYZ = fct;}; static void setVertexXYZ(ptrfunction_int_vector fct){VertexXYZ = fct;};
private: private:
// the callbacks: // the callbacks:
// -------------- // fills vector xyz for vertex of int id
// fills vector xyz for vertex of int id static ptrfunction_int_vector VertexXYZ;
static ptrfunction_int_vector VertexXYZ;
}; };
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment