* Code cleanup and formatting

* Included error checking when opening OCC geometry files
* Attempt to retain face colours even after geometry healing
* Fixed a bug which did not clear face mesh size array when a new geometry was loaded
* More consistent code between STEP and IGES geometry load functions
This commit is contained in:
Philippose Rajan 2009-10-04 15:12:43 +00:00
parent 5701d9f094
commit df79bea6bd

View File

@ -15,15 +15,10 @@
#include "ShapeFix.hxx"
#include "ShapeFix_FixSmallFace.hxx"
#include "Partition_Spliter.hxx"
//#include "VrmlAPI.hxx"
//#include "StlAPI.hxx"
namespace netgen
{
// #include "../visualization/vispar.hpp"
void OCCGeometry :: PrintNrShapes ()
{
TopExp_Explorer e;
@ -39,6 +34,8 @@ namespace netgen
}
void PrintContents (OCCGeometry * geom)
{
ShapeAnalysis_ShapeContents cont;
@ -195,13 +192,10 @@ namespace netgen
// Set the original colour of the face to the newly created
// face (after the healing process)
face = TopoDS::Face (exp0.Current());
face_colours->SetColor(face,face_colour,XCAFDoc_ColorSurf);
//delete sff; sff = NULL;
}
shape = rebuild->Apply(shape);
//delete rebuild; rebuild = NULL;
}
@ -582,18 +576,6 @@ namespace netgen
cout << endl;
cout << "Totol surface area : " << newsurfacecont << " (" << surfacecont << ")" << endl;
cout << endl;
// cout << "Write: " << flush;
// char answer;
// cin >> answer;
// if(answer == 'y')
// {
// cout << "Writing VRML" << endl;
// VrmlAPI::Write(shape,"test2.vrml");
// cout << "Writing STL" << endl;
// StlAPI::Write(shape,"test2.stl");
// }
}
@ -635,7 +617,6 @@ namespace netgen
for (exp1.Init(solid, TopAbs_SHELL);
exp1.More(); exp1.Next())
{
// TopoDS_Shell shell = TopoDS::Shell (exp1.Current().Composed (exp0.Current().Orientation()));
TopoDS_Shell shell = TopoDS::Shell (exp1.Current());
if (shmap.FindIndex(shell) < 1)
{
@ -644,7 +625,6 @@ namespace netgen
for (exp2.Init(shell, TopAbs_FACE);
exp2.More(); exp2.Next())
{
// TopoDS_Face face = TopoDS::Face(exp2.Current().Composed(shell.Orientation()));
TopoDS_Face face = TopoDS::Face(exp2.Current());
if (fmap.FindIndex(face) < 1)
{
@ -655,7 +635,6 @@ namespace netgen
for (exp3.Init(exp2.Current(), TopAbs_WIRE);
exp3.More(); exp3.Next())
{
// TopoDS_Wire wire = TopoDS::Wire (exp3.Current().Composed(face.Orientation()));
TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
if (wmap.FindIndex(wire) < 1)
{
@ -664,7 +643,6 @@ namespace netgen
for (exp4.Init(exp3.Current(), TopAbs_EDGE);
exp4.More(); exp4.Next())
{
// TopoDS_Edge edge = TopoDS::Edge(exp4.Current().Composed(wire.Orientation()));
TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
if (emap.FindIndex(edge) < 1)
{
@ -688,11 +666,8 @@ namespace netgen
}
// Free Shells
for (exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID);
// for (exp1.Init(exp0.Current(), TopAbs_SHELL, TopAbs_SOLID);
exp1.More(); exp1.Next())
for (exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID); exp1.More(); exp1.Next())
{
// TopoDS_Shape shell = exp1.Current().Composed (exp0.Current().Orientation());
TopoDS_Shell shell = TopoDS::Shell(exp1.Current());
if (shmap.FindIndex(shell) < 1)
{
@ -702,36 +677,28 @@ namespace netgen
(*testout) << ((shell.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", ";
(*testout) << ((exp1.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << endl;
for (exp2.Init(shell, TopAbs_FACE);
exp2.More(); exp2.Next())
for (exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next())
{
TopoDS_Face face = TopoDS::Face(exp2.Current());
// TopoDS_Face face = TopoDS::Face(exp2.Current().Composed(shell.Orientation()));
if (fmap.FindIndex(face) < 1)
{
fmap.Add (face);
for (exp3.Init(face, TopAbs_WIRE);
exp3.More(); exp3.Next())
for (exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next())
{
// TopoDS_Wire wire = TopoDS::Wire (exp3.Current().Composed(face.Orientation()));
TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
if (wmap.FindIndex(wire) < 1)
{
wmap.Add (wire);
for (exp4.Init(wire, TopAbs_EDGE);
exp4.More(); exp4.Next())
for (exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next())
{
// TopoDS_Edge edge = TopoDS::Edge(exp4.Current().Composed(wire.Orientation()));
TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
if (emap.FindIndex(edge) < 1)
{
emap.Add (edge);
for (exp5.Init(edge, TopAbs_VERTEX);
exp5.More(); exp5.Next())
for (exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next())
{
// TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current().Composed(edge.Orientation()));
TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
if (vmap.FindIndex(vertex) < 1)
vmap.Add (vertex);
@ -748,36 +715,28 @@ namespace netgen
// Free Faces
for (exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL);
exp2.More(); exp2.Next())
for (exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next())
{
// TopoDS_Face face = TopoDS::Face(exp2.Current().Composed(shape.Orientation()));
TopoDS_Face face = TopoDS::Face(exp2.Current());
if (fmap.FindIndex(face) < 1)
{
fmap.Add (face);
for (exp3.Init(exp2.Current(), TopAbs_WIRE);
exp3.More(); exp3.Next())
for (exp3.Init(exp2.Current(), TopAbs_WIRE); exp3.More(); exp3.Next())
{
// TopoDS_Wire wire = TopoDS::Wire (exp3.Current().Composed(face.Orientation()));
TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
if (wmap.FindIndex(wire) < 1)
{
wmap.Add (wire);
for (exp4.Init(exp3.Current(), TopAbs_EDGE);
exp4.More(); exp4.Next())
for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next())
{
// TopoDS_Edge edge = TopoDS::Edge(exp4.Current().Composed(wire.Orientation()));
TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
if (emap.FindIndex(edge) < 1)
{
emap.Add (edge);
for (exp5.Init(exp4.Current(), TopAbs_VERTEX);
exp5.More(); exp5.Next())
for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
{
// TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current().Composed(edge.Orientation()));
TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
if (vmap.FindIndex(vertex) < 1)
vmap.Add (vertex);
@ -792,23 +751,20 @@ namespace netgen
// Free Wires
for (exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE);
exp3.More(); exp3.Next())
for (exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE); exp3.More(); exp3.Next())
{
TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
if (wmap.FindIndex(wire) < 1)
{
wmap.Add (wire);
for (exp4.Init(exp3.Current(), TopAbs_EDGE);
exp4.More(); exp4.Next())
for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next())
{
TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
if (emap.FindIndex(edge) < 1)
{
emap.Add (edge);
for (exp5.Init(exp4.Current(), TopAbs_VERTEX);
exp5.More(); exp5.Next())
for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
{
TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
if (vmap.FindIndex(vertex) < 1)
@ -822,15 +778,13 @@ namespace netgen
// Free Edges
for (exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE);
exp4.More(); exp4.Next())
for (exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE); exp4.More(); exp4.Next())
{
TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
if (emap.FindIndex(edge) < 1)
{
emap.Add (edge);
for (exp5.Init(exp4.Current(), TopAbs_VERTEX);
exp5.More(); exp5.Next())
for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
{
TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
if (vmap.FindIndex(vertex) < 1)
@ -842,8 +796,7 @@ namespace netgen
// Free Vertices
for (exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE);
exp5.More(); exp5.Next())
for (exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE); exp5.More(); exp5.Next())
{
TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
if (vmap.FindIndex(vertex) < 1)
@ -886,7 +839,6 @@ namespace netgen
cout << "Trying to sew faces ..." << flush;
BRepOffsetAPI_Sewing sewedObj(1);
// BRepOffsetAPI_Sewing sewedObj(healingtolerance);
for (int i = 1; i <= fmap.Extent(); i++)
{
@ -903,12 +855,6 @@ namespace netgen
}
else
cout << " not possible";
/*
ShapeUpgrade_ShellSewing sewing;
TopoDS_Shape sh = sewing.ApplySewing (shape);
shape = sh;
*/
}
@ -955,16 +901,12 @@ namespace netgen
TopoDS_Solid newsolid = solid;
BRepLib::OrientClosedSolid (newsolid);
Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
// rebuild->Apply(shape);
rebuild->Replace(solid, newsolid, Standard_False);
// TopoDS_Shape newshape = rebuild->Apply(shape);
TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_SHAPE, 1);
shape = newshape;
}
//delete sfs; sfs = NULL;
cout << " done" << endl;
}
else
@ -972,17 +914,20 @@ namespace netgen
}
void OCCGeometry :: BuildVisualizationMesh (double deflection)
{
cout << "Preparing visualization (deflection = " << deflection << ") ... " << flush;
BRepTools::Clean (shape);
//WriteOCC_STL("test.stl");
BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh (shape, deflection, true);
cout << "done" << endl;
}
void OCCGeometry :: CalcBoundingBox ()
{
Bnd_Box bb;
@ -999,6 +944,8 @@ namespace netgen
}
void OCCGeometry :: Project (int surfi, Point<3> & p) const
{
static int cnt = 0;
@ -1006,25 +953,6 @@ namespace netgen
gp_Pnt pnt(p(0), p(1), p(2));
//(*testout) << "before " << pnt.X() << " "<< pnt.Y() << " "<< pnt.Z() << " " << endl;
/*
GeomAPI_ProjectPointOnSurf proj(pnt, BRep_Tool::Surface(TopoDS::Face(fmap(surfi))));
if (proj.NbPoints() == 0)
{
cout << "Projection fails" << endl;
}
else
{
pnt = proj.NearestPoint();
//(*testout) << "after " << pnt.X() << " "<< pnt.Y() << " "<< pnt.Z() << " " << endl;
p = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
}
*/
double u,v;
Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
@ -1038,6 +966,8 @@ namespace netgen
}
bool OCCGeometry :: FastProject (int surfi, Point<3> & ap, double& u, double& v) const
{
gp_Pnt p(ap(0), ap(1), ap(2));
@ -1095,6 +1025,8 @@ namespace netgen
}
void OCCGeometry :: WriteOCC_STL(char * filename)
{
cout << "writing stl..."; cout.flush();
@ -1138,6 +1070,12 @@ namespace netgen
Standard_Integer stat = reader.ReadFile((char*)filename);
if(stat != IFSelect_RetDone)
{
delete occgeo;
return NULL;
}
// Enable transfer of colours
reader.SetColorMode(Standard_True);
@ -1150,6 +1088,20 @@ namespace netgen
TDF_LabelSequence iges_shapes;
iges_shape_contents->GetShapes(iges_shapes);
// List out the available colours in the IGES File as Colour Names
TDF_LabelSequence all_colours;
iges_colour_contents->GetColors(all_colours);
PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length());
for(int i = 1; i <= all_colours.Length(); i++)
{
Quantity_Color col;
stringstream col_rgb;
iges_colour_contents->GetColor(all_colours.Value(i),col);
col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
}
// For the IGES Reader, all the shapes can be exported as one compund shape
// using the "OneShape" member
occgeo->shape = reader.OneShape();
@ -1157,7 +1109,6 @@ namespace netgen
occgeo->changed = 1;
occgeo->BuildFMap();
// occgeo->BuildVisualizationMesh();
occgeo->CalcBoundingBox();
PrintContents (occgeo);
@ -1195,11 +1146,17 @@ namespace netgen
STEPCAFControl_Reader reader;
Standard_Integer stat = reader.ReadFile((char*)filename);
// Enable transfer of colours
reader.SetColorMode(Standard_True);
Standard_Integer stat = reader.ReadFile((char*)filename);
if(stat != IFSelect_RetDone)
{
delete occgeo;
return NULL;
}
reader.Transfer(step_doc);
// Read in the shape(s) and the colours present in the STEP File
@ -1209,16 +1166,17 @@ namespace netgen
TDF_LabelSequence step_shapes;
step_shape_contents->GetShapes(step_shapes);
// List out the available colours in the STEP File as Colour Names
TDF_LabelSequence all_colours;
step_colour_contents->GetColors(all_colours);
PrintMessage(4,"Number of colours in STEP File: ",all_colours.Length());
PrintMessage(1,"Number of colours in STEP File: ",all_colours.Length());
for(int i = 1; i <= all_colours.Length(); i++)
{
Quantity_Color col;
stringstream col_rgb;
step_colour_contents->GetColor(all_colours.Value(i),col);
PrintMessage(4, "Colour [", i, "] = ",col.StringName(col.Name()));
col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
}
@ -1229,7 +1187,6 @@ namespace netgen
occgeo->changed = 1;
occgeo->BuildFMap();
// occgeo->BuildVisualizationMesh();
occgeo->CalcBoundingBox();
PrintContents (occgeo);
@ -1239,8 +1196,6 @@ namespace netgen
OCCGeometry *LoadOCC_BREP (const char *filename)
{
OCCGeometry * occgeo;
@ -1249,11 +1204,11 @@ namespace netgen
BRep_Builder aBuilder;
Standard_Boolean result = BRepTools::Read(occgeo->shape, const_cast<char*> (filename),aBuilder);
// cout << "Writing VRML" << endl;
// VrmlAPI::Write(occgeo->shape,"test.vrml");
// cout << "Writing STL" << endl;
// StlAPI::Write(occgeo->shape,"test.stl");
if(!result)
{
delete occgeo;
return NULL;
}
// Philippose - 23/02/2009
// Fixed a bug in the OpenCascade XDE Colour handling when
@ -1263,7 +1218,7 @@ namespace netgen
occgeo->face_colours.Nullify();
occgeo->changed = 1;
occgeo->BuildFMap();
// occgeo->BuildVisualizationMesh();
occgeo->CalcBoundingBox();
PrintContents (occgeo);
@ -1373,6 +1328,9 @@ namespace netgen
// cout << "done" << endl;
}
void OCCGeometry :: CheckIrregularEntities(stringstream & str)
{
ShapeAnalysis_CheckSmallFace csm;
@ -1508,25 +1466,6 @@ namespace netgen
GProp_GProps system;
BRepGProp::LinearProperties(edge1, system);
edgeLengths[i-1] = system.Mass();
/*
int j;
for (j = i+1; j <= emap.Extent(); j++)
{
TopoDS_Edge edge2 = TopoDS::Edge (emap(j));
if (csm.CheckStripEdges(edge1, edge2, csm.Tolerance(), dmax))
{
if (!edgessamebutnotidentified++)
str << "EdgesSameButNotIdentified {Edges same but not identified} ";
cnt++;
(*testout) << "Edge " << i << " and edge " << j
<< " are on one strip (same but not identified)" << endl;
str << "EdgesSameButNotIdentified/Edge" << cnt << " ";
str << "{Edge " << i << " and Edge " << j << "} ";
}
}
*/
}
Sort (edgeLengths, order);
@ -1541,37 +1480,9 @@ namespace netgen
str << flush;
cout << "done" << endl;
/*
for (i = 1; i <= shmap.Extent(); i++)
{
TopoDS_Shell shell = TopoDS::Shell (shmap(i));
if (!shell.Closed())
cout << "Shell " << i << " is not closed" << endl;
if (shell.Infinite())
cout << "Shell " << i << " is infinite" << endl;
BRepCheck_Analyzer ba(shell);
if (!ba.IsValid ())
cout << "Shell " << i << " is not valid" << endl;
}
for (i = 1; i <= somap.Extent(); i++)
{
TopoDS_Solid solid = TopoDS::Solid (somap(i));
if (!solid.Closed())
cout << "Solid " << i << " is not closed" << endl;
if (solid.Infinite())
cout << "Solid " << i << " is infinite" << endl;
BRepCheck_Analyzer ba(solid);
if (!ba.IsValid ())
cout << "Solid " << i << " is not valid" << endl;
}
*/
}
void OCCGeometry :: GetUnmeshedFaceInfo (stringstream & str)
@ -1584,6 +1495,9 @@ namespace netgen
str << flush;
}
void OCCGeometry :: GetNotDrawableFaces (stringstream & str)
{
for (int i = 1; i <= fmap.Extent(); i++)
@ -1594,6 +1508,9 @@ namespace netgen
str << flush;
}
bool OCCGeometry :: ErrorInSurfaceMeshing ()
{
for (int i = 1; i <= fmap.Extent(); i++)
@ -1604,12 +1521,17 @@ namespace netgen
}
int OCCGeometry :: GenerateMesh (Mesh*& mesh,
int perfstepsstart, int perfstepsend, char* optstring)
{
return OCCGenerateMesh (*this, mesh, perfstepsstart, perfstepsend, optstring);
}
const Refinement & OCCGeometry :: GetRefinement () const
{
return * new OCCRefinementSurfaces (*this);