Skip to content
Snippets Groups Projects
Commit 8acb8f52 authored by Jean-François Remacle's avatar Jean-François Remacle
Browse files

*** empty log message ***

parent bb105e29
No related branches found
No related tags found
No related merge requests found
......@@ -168,7 +168,7 @@ BDS_Triangle * BDS_Mesh :: add_triangle (int p1, int p2, int p3 )
BDS_Edge *e2 = find_edge (p2,p3);
BDS_Edge *e3 = find_edge (p3,p1);
try {
BDS_Triangle *t = new BDS_Triangle ( e1, e2, e3 ,find_point(p1));
BDS_Triangle *t = new BDS_Triangle ( e1, e2, e3 );
triangles.push_back ( t );
return t;
}
......@@ -261,6 +261,8 @@ BDS_Vector BDS_Triangle :: N () const
void BDS_Mesh :: classify ( double angle )
{
printf(" classifying \n");
static BDS_GeomEntity EDGE_CLAS (0,1);
{
std::set<BDS_Edge*, EdgeLessThan>::iterator it = edges.begin();
......@@ -269,6 +271,11 @@ void BDS_Mesh :: classify ( double angle )
{
BDS_Edge &e = *((BDS_Edge *) *it);
if ( e.numfaces() == 1) e.g = &EDGE_CLAS;
else if (e.numfaces() == 2 &&
e.faces[0]->g != e.faces[1]->g )
{
e.g = &EDGE_CLAS;
}
else if (e.numfaces() == 2)
{
BDS_Vector N0 = e.faces[0]->N();
......@@ -289,6 +296,18 @@ void BDS_Mesh :: classify ( double angle )
++it;
}
}
{
std::list<BDS_Triangle*>::iterator it = triangles.begin();
std::list<BDS_Triangle*>::iterator ite = triangles.end();
while (it!=ite)
{
(*it)->g = 0;
++it;
}
geom.clear();
}
{
int tag = 1;
while (1)
......@@ -368,6 +387,7 @@ void BDS_Mesh :: classify ( double angle )
++it;
}
}
printf(" end classifying \n");
}
double PointLessThanLexicographic::t = 0;
......@@ -648,6 +668,89 @@ bool BDS_Mesh :: read_stl ( const char *filename , const double tolerance)
fclose (f);
}
// INRIA FORMAT
bool BDS_Mesh :: read_mesh ( const char *filename )
{
FILE *f = fopen ( filename, "r");
if (!f)return false;
char buffer [256], name[256];
fgets (buffer,255,f);
int format;
sscanf (buffer,"%s %d",name,&format);
// ASCII MESH
if (format == 1)
{
printf("format = 1\n");
while (!feof(f))
{
fgets (buffer,255,f);
printf("%s\n",buffer);
if (buffer[0] != '#') // skip comments
{
sscanf(buffer,"%s",name);
if (!strcmp (name,"Dimension"))
fgets (buffer,255,f);
else if (!strcmp (name,"Vertices"))
{
Min[0] = Min[1] = Min[2] = 1.e12;
Max[0] = Max[1] = Max[2] = -1.e12;
int nbv,cl;
double x,y,z;
fgets (buffer,255,f);
sscanf (buffer,"%d",&nbv);
printf("%d Vertices\n",nbv);
for (int i=0;i<nbv;i++)
{
fgets (buffer,255,f);
sscanf (buffer,"%lf %lf %lf %d",&x,&y,&z,&cl);
Min[0] = (Min[0] < x)?Min[0]:x;
Min[1] = (Min[1] < y)?Min[1]:y;
Min[2] = (Min[2] < z)?Min[2]:z;
Max[0] = (Max[0] > x)?Max[0]:x;
Max[1] = (Max[1] > y)?Max[1]:y;
Max[2] = (Max[2] > z)?Max[2]:z;
add_point (i+1 , x,y,z );
}
MAXPOINTNUMBER = nbv+1;
}
else if (!strcmp (name,"Triangles"))
{
int nbt,cl,n1,n2,n3;
fgets (buffer,255,f);
sscanf (buffer,"%d",&nbt);
printf("%d Triangles\n",nbt);
for (int i=0;i<nbt;i++)
{
fgets (buffer,255,f);
sscanf (buffer,"%d %d %d %d",&n1,&n2,&n3,&cl);
BDS_Triangle *t = add_triangle(n1,n2,n3);
t->g = get_geom (cl,2);
if (!t->g)
{
add_geom (cl,2);
t->g = get_geom (cl,2);
}
}
}
}
}
LC = sqrt ((Min[0]-Max[0])*(Min[0]-Max[0])+
(Min[1]-Max[1])*(Min[1]-Max[1])+
(Min[2]-Max[2])*(Min[2]-Max[2]));
}
else
{
throw;
}
}
void BDS_Mesh :: save_gmsh_format ( const char *filename )
{
cleanup();
......@@ -826,10 +929,10 @@ bool BDS_Mesh ::split_edge ( BDS_Edge *e, double coord)
edges.insert ( mid_op2 );
// printf("split ends 1 %d (%d %d) %d %d \n",p1_op1->numfaces(), p1->iD, op[0]->iD, op1_mid->numfaces(),p1_mid->numfaces());
BDS_Triangle*t1 = new BDS_Triangle ( p1_op1, op1_mid, p1_mid ,op[0] );
BDS_Triangle*t2 = new BDS_Triangle ( op2_p2, mid_op2, mid_p2 ,op[1] );
BDS_Triangle*t3 = new BDS_Triangle ( op1_p2, op1_mid, mid_p2 ,p2);
BDS_Triangle*t4 = new BDS_Triangle ( p1_op2, mid_op2, p1_mid ,p1);
BDS_Triangle*t1 = new BDS_Triangle ( p1_op1, op1_mid, p1_mid );
BDS_Triangle*t2 = new BDS_Triangle ( op2_p2, mid_op2, mid_p2 );
BDS_Triangle*t3 = new BDS_Triangle ( op1_p2, op1_mid, mid_p2 );
BDS_Triangle*t4 = new BDS_Triangle ( p1_op2, mid_op2, p1_mid );
t1->g = g1;
t2->g = g2;
......@@ -889,23 +992,8 @@ bool BDS_Mesh ::swap_edge ( BDS_Edge *e)
BDS_Edge *op1_op2 = new BDS_Edge ( op[0], op[1] );
edges.insert ( op1_op2 );
BDS_Point *first_in_0 = 0;
for (int k=0;k<3;k++)
if (pts1[k] == p1)
{
if (pts1[(k+1)%3] == op[0])first_in_0 = p1;
else first_in_0 = op[0];
}
BDS_Point *first_in_1 = 0;
for (int k=0;k<3;k++)
if (pts2[k] == p2)
{
if (pts2[(k+1)%3] == op[1])first_in_1 = p2;
else first_in_1 = op[1];
}
BDS_Triangle*t1 = new BDS_Triangle ( p1_op1, p1_op2, op1_op2 , first_in_0 );
BDS_Triangle*t2 = new BDS_Triangle ( op2_p2, op1_op2, op1_p2 , first_in_1 );
BDS_Triangle*t1 = new BDS_Triangle ( p1_op1, p1_op2, op1_op2 );
BDS_Triangle*t2 = new BDS_Triangle ( op2_p2, op1_op2, op1_p2 );
t1->g = g1;
t2->g = g2;
......
......@@ -30,6 +30,7 @@ public:
class BDS_Edge;
class BDS_Triangle;
class BDS_Mesh;
void print_face (BDS_Triangle *t);
class BDS_Vector
{
......@@ -113,11 +114,23 @@ public:
if (faces[0]) return 1;
return 0;
}
inline BDS_Point * commonvertex ( const BDS_Edge *other ) const
{
if (p1 == other->p1 || p1 == other->p2) return p1;
if (p2 == other->p1 || p2 == other->p2) return p2;
return 0;
}
inline void addface ( BDS_Triangle *f)
{
if (faces[1])
{
printf("Non Manifold model not done yet\n");
print_face (f);
print_face (faces[0]);
print_face (faces[1]);
throw 1;
}
if(faces [0])faces[1] = f;
......@@ -130,7 +143,7 @@ public:
if (*other.p2 < *p2) return true;
return false;
}
inline BDS_Triangle * otherFace ( BDS_Triangle *f)
inline BDS_Triangle * otherFace ( const BDS_Triangle *f) const
{
if (f == faces[0]) return faces[1];
if (f == faces[1]) return faces[0];
......@@ -175,34 +188,18 @@ class BDS_Triangle
{
public:
bool deleted;
int ori_first_edge;
BDS_Edge *e1,*e2,*e3;
BDS_Vector N() const ;
BDS_GeomEntity *g;
inline void getNodes (BDS_Point *n[3]) const
{
if (ori_first_edge == 1)
{
n[0] = e1->p1;
n[1] = e1->p2;
n[0] = e1->commonvertex (e3);
n[1] = e1->commonvertex (e2);
n[2] = e2->commonvertex (e3);
}
else
{
n[0] = e1->p2;
n[1] = e1->p1;
}
if (e2->p1 != n[0] && e2->p1 != n[1])n[2] = e2->p1;
else n[2] = e2->p2;
}
BDS_Triangle ( BDS_Edge *A, BDS_Edge *B, BDS_Edge *C, BDS_Point *first_vertex)
BDS_Triangle ( BDS_Edge *A, BDS_Edge *B, BDS_Edge *C)
: deleted (false) , e1(A),e2(B),e3(C),g(0)
{
if (first_vertex == A->p1)
ori_first_edge = 1;
else if (first_vertex == A->p2)
ori_first_edge = -1;
else
throw;
e1->addface(this);
e2->addface(this);
e3->addface(this);
......@@ -278,8 +275,10 @@ class BDS_Mesh
int adapt_mesh(double);
void cleanup();
// io's
// STL
bool read_stl ( const char *filename, const double tolerance);
bool read_tri ( const char *filename);
// INRIA MESH
bool read_mesh ( const char *filename);
bool read_vrml ( const char *filename);
void save_gmsh_format (const char *filename);
};
......
// $Id: OpenFile.cpp,v 1.75 2005-04-19 16:03:15 remacle Exp $
// $Id: OpenFile.cpp,v 1.76 2005-04-21 09:26:11 remacle Exp $
//
// Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
//
......@@ -278,12 +278,19 @@ int MergeProblem(char *name, int warn_if_missing)
#endif
status = 0;
}
else if(!strcmp(ext, ".stl")|| !strcmp(ext, ".STL"))
else if(!strcmp(ext, ".stl")|| !strcmp(ext, ".STL")|| !strcmp(ext, ".mesh"))
{
// STEREO LITOGRAPHY (STL) FILE
if (THEM->bds)delete THEM->bds;
THEM->bds = new BDS_Mesh;
if(!strcmp(ext, ".mesh"))
{
THEM->bds->read_mesh ( name );
}
else
{
// STEREO LITOGRAPHY (STL) FILE
THEM->bds->read_stl ( name , 1.e-6 );
}
THEM->bds->save_gmsh_format ( "1.msh" );
THEM->bds->classify ( M_PI / 6 );
THEM->bds->save_gmsh_format ( "2.msh" );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment