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

add extra arg to XYZtoUV so we can use it also for point that are not on
the surface
parent d4c68c17
No related branches found
No related tags found
No related merge requests found
// $Id: GFace.cpp,v 1.24 2006-12-03 00:04:31 geuzaine Exp $ // $Id: GFace.cpp,v 1.25 2006-12-03 00:35:56 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
...@@ -399,37 +399,34 @@ double GFace::curvature (const SPoint2 &param) const ...@@ -399,37 +399,34 @@ double GFace::curvature (const SPoint2 &param) const
} }
void GFace::XYZtoUV(const double X, const double Y, const double Z, void GFace::XYZtoUV(const double X, const double Y, const double Z,
double &U, double &V, double &U, double &V, const double relax,
const double relax) const bool onSurface) const
{ {
const double Precision = 1.e-8; const double Precision = 1.e-8;
const int MaxIter = 25; const int MaxIter = 25;
const int NumInitGuess = 11; const int NumInitGuess = 11;
double Unew = 0., Vnew = 0., err, err_xyz; double Unew = 0., Vnew = 0.;
int iter;
double mat[3][3], jac[3][3]; double mat[3][3], jac[3][3];
double umin, umax, vmin, vmax; double init[NumInitGuess] = {0.487, 0.6, 0.4, 0.7, 0.3, 0.8, 0.2, 0.9, 0.1, 0, 1};
double init[NumInitGuess] = {0.487, 0.6, 0.4, 0.7, 0.3, 0.8, 0.2, 0.9, 0.1,0,1};
Range<double> ru = parBounds(0); Range<double> ru = parBounds(0);
Range<double> rv = parBounds(1); Range<double> rv = parBounds(1);
umin = ru.low(); double umin = ru.low();
umax = ru.high(); double umax = ru.high();
vmin = rv.low(); double vmin = rv.low();
vmax = rv.high(); double vmax = rv.high();
for(int i = 0; i < NumInitGuess; i++){ for(int i = 0; i < NumInitGuess; i++){
for(int j = 0; j < NumInitGuess; j++){ for(int j = 0; j < NumInitGuess; j++){
U = init[i]; U = init[i];
V = init[j]; V = init[j];
err = 1.0; int err = 1.0, err_xyz = 0.;
iter = 1; int iter = 1;
while(err > Precision && iter < MaxIter) { while(err > Precision && iter < MaxIter) {
GPoint P = point(U,V); GPoint P = point(U, V);
Pair<SVector3,SVector3> der = firstDer(SPoint2(U,V)); Pair<SVector3, SVector3> der = firstDer(SPoint2(U, V));
mat[0][0] = der.left().x(); mat[0][0] = der.left().x();
mat[0][1] = der.left().y(); mat[0][1] = der.left().y();
mat[0][2] = der.left().z(); mat[0][2] = der.left().z();
...@@ -449,7 +446,8 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z, ...@@ -449,7 +446,8 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z,
jac[2][1] * (Z - P.z())); jac[2][1] * (Z - P.z()));
err = DSQR(Unew - U) + DSQR(Vnew - V); err = DSQR(Unew - U) + DSQR(Vnew - V);
err_xyz = DSQR(X - P.x()) + DSQR(Y - P.y()) + DSQR(Z - P.z()); if(onSurface)
err_xyz = DSQR(X - P.x()) + DSQR(Y - P.y()) + DSQR(Z - P.z());
iter++; iter++;
U = Unew; U = Unew;
V = Vnew; V = Vnew;
...@@ -458,7 +456,7 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z, ...@@ -458,7 +456,7 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z,
if(iter < MaxIter && err <= Precision && if(iter < MaxIter && err <= Precision &&
Unew <= umax && Vnew <= vmax && Unew <= umax && Vnew <= vmax &&
Unew >= umin && Vnew >= vmin){ Unew >= umin && Vnew >= vmin){
if(err_xyz > 1.e-5) if(onSurface && err_xyz > Precision * CTX.lc)
Msg(WARNING,"converged for i=%d j=%d (err=%g iter=%d), but err_xyz = %g", Msg(WARNING,"converged for i=%d j=%d (err=%g iter=%d), but err_xyz = %g",
i, j, err, iter, err_xyz); i, j, err, iter, err_xyz);
return; return;
...@@ -466,21 +464,20 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z, ...@@ -466,21 +464,20 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z,
} }
} }
if(relax < 1.e-6) if(relax < 1.e-6){
Msg(GERROR, "Could not converge: surface mesh will be wrong"); Msg(GERROR, "Could not converge: surface mesh will be wrong");
}
else { else {
Msg(INFO, "Relaxation factor = %g", 0.75 * relax); Msg(INFO, "Relaxation factor = %g", 0.75 * relax);
XYZtoUV(X, Y, Z, U, V, 0.75 * relax); XYZtoUV(X, Y, Z, U, V, 0.75 * relax, onSurface);
} }
} }
SPoint2 GFace::parFromPoint(const SPoint3 &p) const SPoint2 GFace::parFromPoint(const SPoint3 &p) const
{ {
double U,V; double U, V;
XYZtoUV(p.x(),p.y(),p.z(),U,V,1.0); XYZtoUV(p.x(), p.y(), p.z(), U, V, 1.0);
return SPoint2(U,V); return SPoint2(U, V);
} }
...@@ -76,10 +76,10 @@ class GFace : public GEntity ...@@ -76,10 +76,10 @@ class GFace : public GEntity
virtual int dim() const {return 2;} virtual int dim() const {return 2;}
virtual void setVisibility(char val, bool recursive=false); virtual void setVisibility(char val, bool recursive=false);
// compute XYZ from parametric UV // compute the parameters UV from a point XYZ
void XYZtoUV(const double X, const double Y, const double Z, void XYZtoUV(const double X, const double Y, const double Z,
double &U, double &V, double &U, double &V, const double relax,
const double relax) const; bool onSurface=true) const;
// The bounding box // The bounding box
virtual SBoundingBox3d bounds() const; virtual SBoundingBox3d bounds() const;
...@@ -94,7 +94,7 @@ class GFace : public GEntity ...@@ -94,7 +94,7 @@ class GFace : public GEntity
// Return the parmater location on the face given a point in space // Return the parmater location on the face given a point in space
// that is on the face. // that is on the face.
virtual SPoint2 parFromPoint(const SPoint3 &) const; virtual SPoint2 parFromPoint(const SPoint3 &) const;
// True if the parameter value is interior to the face. // True if the parameter value is interior to the face.
virtual int containsParam(const SPoint2 &pt) const = 0; virtual int containsParam(const SPoint2 &pt) const = 0;
......
// $Id: meshGFaceTransfinite.cpp,v 1.10 2006-12-02 22:48:25 geuzaine Exp $ // $Id: meshGFaceTransfinite.cpp,v 1.11 2006-12-03 00:35:56 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
...@@ -221,9 +221,8 @@ int MeshTransfiniteSurface( GFace *gf) ...@@ -221,9 +221,8 @@ int MeshTransfiniteSurface( GFace *gf)
double zp = TRAN_TRI(m_vertices[iP1]->z(), m_vertices[iP2]->z(), double zp = TRAN_TRI(m_vertices[iP1]->z(), m_vertices[iP2]->z(),
m_vertices[iP3]->z(), m_vertices[N1]->z(), m_vertices[iP3]->z(), m_vertices[N1]->z(),
m_vertices[N2]->z(), m_vertices[N3]->z(), u, v); m_vertices[N2]->z(), m_vertices[N3]->z(), u, v);
SPoint2 param = gf->parFromPoint(SPoint3(xp, yp, zp)); double Up, Vp;
double Up = param.x(); gf->XYZtoUV(xp, yp, zp, Up, Vp, 1.0, false);
double Vp = param.y();
#endif #endif
GPoint gp = gf->point(SPoint2(Up, Vp)); GPoint gp = gf->point(SPoint2(Up, Vp));
MFaceVertex *newv = new MFaceVertex(gp.x(), gp.y(), gp.z(), gf, Up, Vp); MFaceVertex *newv = new MFaceVertex(gp.x(), gp.y(), gp.z(), gf, Up, Vp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment