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

- bug fix: need to create temporary bounding box and compute CTX.lc
*during* parsing step until we fill the new db on the fly

(Some geo transforms in the parser use CTX.lc for tolerences. But
CTX.lc was always equal to 1 since we only do a SetBoundingBox on
GModel after parsing!)

- cleanup spline interpol (remove duplicate code)
parent ebbb4a5f
No related branches found
No related tags found
No related merge requests found
// $Id: GeoInterpolation.cpp,v 1.12 2007-01-07 10:52:46 geuzaine Exp $ // $Id: GeoInterpolation.cpp,v 1.13 2007-01-10 13:48:46 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
...@@ -55,7 +55,7 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee) ...@@ -55,7 +55,7 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee)
int N, i, j; int N, i, j;
Vertex *v[5]; Vertex *v[5];
double T[4], W, theta, t1, t2, t; double theta, t1, t2, t;
double vec[4]; double vec[4];
Vertex temp1, temp2; Vertex temp1, temp2;
...@@ -122,40 +122,16 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee) ...@@ -122,40 +122,16 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee)
case MSH_SEGM_SPLN: case MSH_SEGM_SPLN:
N = List_Nbr(c->Control_Points); N = List_Nbr(c->Control_Points);
/*
0 i P i+1 N-1
vfirst*---------*---------*----X-----*----------*----------* vlast
0 t1 absc t2 1
0 t 1
Splines uniformes -> Le point se trouve entre v[1] et v[2]
-> Calcul de l'abcisse curviligne locale t ( entre 0 et 1 )
0 -> t1
1 -> t2
u -> t
Splines Lineiques -> Multilines
*/
i = (int)((double)(N - 1) * u); i = (int)((double)(N - 1) * u);
if(i < 0) if(i < 0)
i = 0; i = 0;
if(i >= N - 1) if(i >= N - 1)
i = N - 2; i = N - 2;
t1 = (double)(i) / (double)(N - 1); t1 = (double)(i) / (double)(N - 1);
t2 = (double)(i + 1) / (double)(N - 1); t2 = (double)(i + 1) / (double)(N - 1);
t = (u - t1) / (t2 - t1); t = (u - t1) / (t2 - t1);
List_Read(c->Control_Points, i, &v[1]); List_Read(c->Control_Points, i, &v[1]);
List_Read(c->Control_Points, i + 1, &v[2]); List_Read(c->Control_Points, i + 1, &v[2]);
V.lc = (1. - t) * v[1]->lc + t * v[2]->lc;
V.w = (1. - t) * v[1]->w + t * v[2]->w;
if(!i) { if(!i) {
v[0] = &temp1; v[0] = &temp1;
v[0]->Pos.X = 2. * v[1]->Pos.X - v[2]->Pos.X; v[0]->Pos.X = 2. * v[1]->Pos.X - v[2]->Pos.X;
...@@ -165,7 +141,6 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee) ...@@ -165,7 +141,6 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee)
else { else {
List_Read(c->Control_Points, i - 1, &v[0]); List_Read(c->Control_Points, i - 1, &v[0]);
} }
if(i == N - 2) { if(i == N - 2) {
v[3] = &temp2; v[3] = &temp2;
v[3]->Pos.X = 2. * v[2]->Pos.X - v[1]->Pos.X; v[3]->Pos.X = 2. * v[2]->Pos.X - v[1]->Pos.X;
...@@ -175,62 +150,7 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee) ...@@ -175,62 +150,7 @@ Vertex InterpolateCurve(Curve * c, double u, int derivee)
else { else {
List_Read(c->Control_Points, i + 2, &v[3]); List_Read(c->Control_Points, i + 2, &v[3]);
} }
return InterpolateCubicSpline(v, t, c->mat, 0, t1, t2);
T[3] = 1.;
T[2] = t;
T[1] = t * t;
T[0] = t * t * t;
V.Pos.X = V.Pos.Y = V.Pos.Z = W = 0.0;
for(i = 0; i < 4; i++) {
vec[i] = 0.0;
}
/* X */
for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
vec[i] += c->mat[i][j] * v[j]->Pos.X;
}
}
for(j = 0; j < 4; j++) {
V.Pos.X += T[j] * vec[j];
vec[j] = 0.0;
}
/* Y */
for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
vec[i] += c->mat[i][j] * v[j]->Pos.Y;
}
}
for(j = 0; j < 4; j++) {
V.Pos.Y += T[j] * vec[j];
vec[j] = 0.0;
}
/* Z */
for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
vec[i] += c->mat[i][j] * v[j]->Pos.Z;
}
}
for(j = 0; j < 4; j++) {
V.Pos.Z += T[j] * vec[j];
vec[j] = 0.0;
}
/* W */
for(i = 0; i < 4; i++) {
for(j = 0; j < 4; j++) {
vec[i] += c->mat[i][j] * v[j]->lc;
}
}
for(j = 0; j < 4; j++) {
W += T[j] * vec[j];
}
return V;
default: default:
Msg(GERROR, "Unknown curve type in interpolation"); Msg(GERROR, "Unknown curve type in interpolation");
......
// $Id: SBoundingBox3d.cpp,v 1.4 2006-11-27 22:22:14 geuzaine Exp $ // $Id: SBoundingBox3d.cpp,v 1.5 2007-01-10 13:48:46 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
...@@ -30,6 +30,12 @@ SBoundingBox3d::SBoundingBox3d(const SPoint3 & pt) ...@@ -30,6 +30,12 @@ SBoundingBox3d::SBoundingBox3d(const SPoint3 & pt)
: MinPt(pt), MaxPt(pt) : MinPt(pt), MaxPt(pt)
{} {}
void SBoundingBox3d::reset()
{
MinPt = SPoint3(DBL_MAX,DBL_MAX,DBL_MAX);
MaxPt = SPoint3(-DBL_MAX,-DBL_MAX,-DBL_MAX);
}
bool SBoundingBox3d::empty() bool SBoundingBox3d::empty()
{ {
if(MinPt.x() == DBL_MAX || MinPt.y() == DBL_MAX || MinPt.z() == DBL_MAX || if(MinPt.x() == DBL_MAX || MinPt.y() == DBL_MAX || MinPt.z() == DBL_MAX ||
......
...@@ -29,6 +29,7 @@ class SBoundingBox3d { ...@@ -29,6 +29,7 @@ class SBoundingBox3d {
SBoundingBox3d(); SBoundingBox3d();
SBoundingBox3d(const SPoint3 &); SBoundingBox3d(const SPoint3 &);
bool empty(); bool empty();
void reset();
void operator+=(const SPoint3 &pt); void operator+=(const SPoint3 &pt);
void operator+=(const SBoundingBox3d &pt); void operator+=(const SBoundingBox3d &pt);
void operator*=(double scale); void operator*=(double scale);
......
This diff is collapsed.
%{ %{
// $Id: Gmsh.y,v 1.252 2006-12-16 15:44:30 geuzaine Exp $ // $Id: Gmsh.y,v 1.253 2007-01-10 13:48:49 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
...@@ -1029,11 +1029,13 @@ Shape : ...@@ -1029,11 +1029,13 @@ Shape :
yymsg(GERROR, "Point %d already exists", num); yymsg(GERROR, "Point %d already exists", num);
} }
else{ else{
Vertex *v = Create_Vertex(num, CTX.geom.scaling_factor * $6[0], double x = CTX.geom.scaling_factor * $6[0];
CTX.geom.scaling_factor * $6[1], double y = CTX.geom.scaling_factor * $6[1];
CTX.geom.scaling_factor * $6[2], double z = CTX.geom.scaling_factor * $6[2];
CTX.geom.scaling_factor * $6[3], 1.0); double lc = CTX.geom.scaling_factor * $6[3];
Vertex *v = Create_Vertex(num, x, y, z, lc, 1.0);
Tree_Add(THEM->Points, &v); Tree_Add(THEM->Points, &v);
AddToTemporaryBoundingBox(x, y, z);
} }
$$.Type = MSH_POINT; $$.Type = MSH_POINT;
$$.Num = num; $$.Num = num;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* A lexical scanner generated by flex */ /* A lexical scanner generated by flex */
/* Scanner skeleton version: /* Scanner skeleton version:
* $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.293 2006-12-16 15:44:30 geuzaine Exp $ * $Header: /cvsroot/gmsh/Parser/Gmsh.yy.cpp,v 1.294 2007-01-10 13:48:49 geuzaine Exp $
*/ */
#define FLEX_SCANNER #define FLEX_SCANNER
...@@ -727,7 +727,7 @@ char *yytext; ...@@ -727,7 +727,7 @@ char *yytext;
#line 1 "Gmsh.l" #line 1 "Gmsh.l"
#define INITIAL 0 #define INITIAL 0
#line 2 "Gmsh.l" #line 2 "Gmsh.l"
// $Id: Gmsh.yy.cpp,v 1.293 2006-12-16 15:44:30 geuzaine Exp $ // $Id: Gmsh.yy.cpp,v 1.294 2007-01-10 13:48:49 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
......
// $Id: OpenFile.cpp,v 1.136 2006-12-21 17:10:15 geuzaine Exp $ // $Id: OpenFile.cpp,v 1.137 2007-01-10 13:48:50 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
...@@ -165,6 +165,27 @@ void SetBoundingBox(void) ...@@ -165,6 +165,27 @@ void SetBoundingBox(void)
FinishUpBoundingBox(); FinishUpBoundingBox();
} }
// FIXME: this is necessary for now to have an approximate CTX.lc
// *while* parsing input files (it's important since some of the
// geometrical operations use a tolerance that depends on
// CTX.lc). This will be removed once the new database is filled
// directly during the parsing step
static SBoundingBox3d temp_bb;
void ResetTemporaryBoundingBox()
{
temp_bb.reset();
}
void AddToTemporaryBoundingBox(double x, double y, double z)
{
temp_bb += SPoint3(x, y, z);
CTX.min[0] = temp_bb.min().x(); CTX.max[0] = temp_bb.max().x();
CTX.min[1] = temp_bb.min().y(); CTX.max[1] = temp_bb.max().y();
CTX.min[2] = temp_bb.min().z(); CTX.max[2] = temp_bb.max().z();
FinishUpBoundingBox();
}
int ParseFile(char *f, int close, int warn_if_missing) int ParseFile(char *f, int close, int warn_if_missing)
{ {
char yyname_old[256], tmp[256]; char yyname_old[256], tmp[256];
...@@ -389,6 +410,9 @@ void OpenProject(char *name) ...@@ -389,6 +410,9 @@ void OpenProject(char *name)
// Initialize pseudo random mesh generator to the same seed // Initialize pseudo random mesh generator to the same seed
srand(1); srand(1);
// temporary hack until we fill GMODEL on the fly during parsing
ResetTemporaryBoundingBox();
SetProjectName(name); SetProjectName(name);
MergeFile(name); MergeFile(name);
......
...@@ -31,5 +31,6 @@ void SetBoundingBox(double xmin, double xmax, ...@@ -31,5 +31,6 @@ void SetBoundingBox(double xmin, double xmax,
double ymin, double ymax, double ymin, double ymax,
double zmin, double zmax); double zmin, double zmax);
void SetBoundingBox(void); void SetBoundingBox(void);
void AddToTemporaryBoundingBox(double x, double y, double z);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment