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
//
......@@ -399,33 +399,30 @@ double GFace::curvature (const SPoint2 &param) const
}
void GFace::XYZtoUV(const double X, const double Y, const double Z,
double &U, double &V,
const double relax) const
double &U, double &V, const double relax,
bool onSurface) const
{
const double Precision = 1.e-8;
const int MaxIter = 25;
const int NumInitGuess = 11;
double Unew = 0., Vnew = 0., err, err_xyz;
int iter;
double Unew = 0., Vnew = 0.;
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};
Range<double> ru = parBounds(0);
Range<double> rv = parBounds(1);
umin = ru.low();
umax = ru.high();
vmin = rv.low();
vmax = rv.high();
double umin = ru.low();
double umax = ru.high();
double vmin = rv.low();
double vmax = rv.high();
for(int i = 0; i < NumInitGuess; i++){
for(int j = 0; j < NumInitGuess; j++){
U = init[i];
V = init[j];
err = 1.0;
iter = 1;
int err = 1.0, err_xyz = 0.;
int iter = 1;
while(err > Precision && iter < MaxIter) {
GPoint P = point(U, V);
......@@ -449,6 +446,7 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z,
jac[2][1] * (Z - P.z()));
err = DSQR(Unew - U) + DSQR(Vnew - V);
if(onSurface)
err_xyz = DSQR(X - P.x()) + DSQR(Y - P.y()) + DSQR(Z - P.z());
iter++;
U = Unew;
......@@ -458,7 +456,7 @@ void GFace::XYZtoUV(const double X, const double Y, const double Z,
if(iter < MaxIter && err <= Precision &&
Unew <= umax && Vnew <= vmax &&
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",
i, j, err, iter, err_xyz);
return;
......@@ -466,15 +464,15 @@ 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");
}
else {
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
{
double U, V;
......@@ -483,4 +481,3 @@ SPoint2 GFace::parFromPoint(const SPoint3 &p) const
return SPoint2(U, V);
}
......@@ -76,10 +76,10 @@ class GFace : public GEntity
virtual int dim() const {return 2;}
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,
double &U, double &V,
const double relax) const;
double &U, double &V, const double relax,
bool onSurface=true) const;
// The bounding box
virtual SBoundingBox3d bounds() const;
......
// $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
//
......@@ -221,9 +221,8 @@ int MeshTransfiniteSurface( GFace *gf)
double zp = TRAN_TRI(m_vertices[iP1]->z(), m_vertices[iP2]->z(),
m_vertices[iP3]->z(), m_vertices[N1]->z(),
m_vertices[N2]->z(), m_vertices[N3]->z(), u, v);
SPoint2 param = gf->parFromPoint(SPoint3(xp, yp, zp));
double Up = param.x();
double Vp = param.y();
double Up, Vp;
gf->XYZtoUV(xp, yp, zp, Up, Vp, 1.0, false);
#endif
GPoint gp = gf->point(SPoint2(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