* Fixed the OCC XDE Interface for BREP and IGES Files

* Added stricter error checking for face colour extraction
* Improved consistency of OCC geometry and mesh colours across file formats
This commit is contained in:
Philippose Rajan 2009-02-23 23:10:00 +00:00
parent 3271c2f5ae
commit 78736845ca
3 changed files with 378 additions and 272 deletions

View File

@ -1092,43 +1092,55 @@ namespace netgen
}
// Philippose - 23/02/2009
/* Special IGES File load function including the ability
to extract individual surface colours via the extended
OpenCascade XDE and XCAF Feature set.
*/
OCCGeometry *LoadOCC_IGES(const char *filename)
{
OCCGeometry *occgeo;
occgeo = new OCCGeometry;
IGESControl_Reader reader;
// Initiate a dummy XCAF Application to handle the IGES XCAF Document
static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();
// Create an XCAF Document to contain the IGES file itself
Handle_TDocStd_Document iges_doc;
// Check if a IGES File is already open under this handle, if so, close it to prevent
// Segmentation Faults when trying to create a new document
if(dummy_app->NbDocuments() > 0)
{
dummy_app->GetDocument(1,iges_doc);
dummy_app->Close(iges_doc);
}
dummy_app->NewDocument ("IGES-XCAF",iges_doc);
IGESCAFControl_Reader reader;
Standard_Integer stat = reader.ReadFile((char*)filename);
// pre OCC52-times:
// Standard_Integer stat = reader.LoadFile((char*)filename);
// reader.Clear();
// Enable transfer of colours
reader.SetColorMode(Standard_True);
reader.Transfer(iges_doc);
reader.TransferRoots(); // Tranlate IGES -> OCC
// Read in the shape(s) and the colours present in the IGES File
Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main());
Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main());
// pre OCC52-times:
// reader.TransferRoots(Standard_False); // Tranlate IGES -> OCC
//reader.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ListByItem);
TDF_LabelSequence iges_shapes;
iges_shape_contents->GetShapes(iges_shapes);
// For the IGES Reader, all the shapes can be exported as one compund shape
// using the "OneShape" member
occgeo->shape = reader.OneShape();
occgeo->face_colours = iges_colour_contents;
occgeo->changed = 1;
occgeo->BuildFMap();
//
// Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
// sfs->Init(occgeo->shape);
// sfs->Perform();
// Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe(occgeo->shape);
// //sfwf->DropSmallEdgesMode() = Standard_True;
// sfwf->FixSmallEdges();
// sfwf->FixWireGaps();
//
// occgeo->BuildVisualizationMesh();
occgeo->CalcBoundingBox();
PrintContents (occgeo);
@ -1138,6 +1150,58 @@ namespace netgen
// Philippose - 23/02/2009
// The LOADOCC_IGES Function has been replaced by the one
// above, which also includes support for the OpenCascade
// XDE Features.
//
//OCCGeometry * LoadOCC_IGES (const char * filename)
//{
// OCCGeometry * occgeo;
// occgeo = new OCCGeometry;
// IGESControl_Reader reader;
// Standard_Integer stat = reader.ReadFile((char*)filename);
// // pre OCC52-times:
// // Standard_Integer stat = reader.LoadFile((char*)filename);
// // reader.Clear();
// reader.TransferRoots(); // Tranlate IGES -> OCC
// // pre OCC52-times:
// // reader.TransferRoots(Standard_False); // Tranlate IGES -> OCC
// //reader.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ListByItem);
// occgeo->shape = reader.OneShape();
// occgeo->changed = 1;
// occgeo->BuildFMap();
// //
// // Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
// // sfs->Init(occgeo->shape);
// // sfs->Perform();
// // Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe(occgeo->shape);
// // //sfwf->DropSmallEdgesMode() = Standard_True;
// // sfwf->FixSmallEdges();
// // sfwf->FixWireGaps();
// //
// // occgeo->BuildVisualizationMesh();
// occgeo->CalcBoundingBox();
// PrintContents (occgeo);
// return occgeo;
//}
// Philippose - 29/01/2009
/* Special STEP File load function including the ability
to extract individual surface colours via the extended
@ -1192,6 +1256,8 @@ OCCGeometry * LoadOCC_STEP (const char * filename)
}
*/
// For the STEP File Reader in OCC, the 1st Shape contains the entire
// compound geometry as one shape
occgeo->shape = step_shape_contents->GetShape(step_shapes.Value(1));
occgeo->face_colours = step_colour_contents;
occgeo->changed = 1;
@ -1281,7 +1347,12 @@ OCCGeometry * LoadOCC_STEP (const char * filename)
// cout << "Writing STL" << endl;
// StlAPI::Write(occgeo->shape,"test.stl");
// Philippose - 23/02/2009
// Fixed a bug in the OpenCascade XDE Colour handling when
// opening BREP Files, since BREP Files have no colour data.
// Hence, the face_colours Handle needs to be created as a NULL handle.
occgeo->face_colours = Handle_XCAFDoc_ColorTool::Handle_XCAFDoc_ColorTool();
occgeo->face_colours.Nullify();
occgeo->changed = 1;
occgeo->BuildFMap();
// occgeo->BuildVisualizationMesh();
@ -1291,6 +1362,9 @@ OCCGeometry * LoadOCC_STEP (const char * filename)
return occgeo;
}
char * shapesname[] =
{" ", "CompSolids", "Solids", "Shells",
@ -1303,6 +1377,9 @@ OCCGeometry * LoadOCC_STEP (const char * filename)
char * orientationstring[] =
{"+", "-"};
void OCCGeometry :: RecursiveTopologyTree (const TopoDS_Shape & sh,
stringstream & str,
TopAbs_ShapeEnum l,
@ -1371,6 +1448,9 @@ OCCGeometry * LoadOCC_STEP (const char * filename)
}
}
void OCCGeometry :: GetTopologyTree (stringstream & str)
{
cout << "Building topology tree ... " << flush;

View File

@ -994,10 +994,10 @@ namespace netgen
glDisable (GL_COLOR_MATERIAL);
GLfloat matcol[] = { 0, 1, 0, 1 };
GLfloat matcol[] = { 1, 1, 0, 1 };
GLfloat matcolsel[] = { 1, 0, 0, 1 };
#ifdef PARALLEL
GLfloat mat_coll_transp[] = { 0, 1, 0, 0.3 };
GLfloat mat_coll_transp[] = { 1, 1, 0, 0.3 };
GLfloat mat_coll_transp_sel[] = { 1, 0, 0, 0.3 };
#endif
@ -1041,10 +1041,24 @@ namespace netgen
{
TopoDS_Face face = TopoDS::Face(occgeometry->fmap(el.GetIndex()));
Quantity_Color face_colour;
occgeometry->face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour);
// Philippose - 23/02/2009
// Check to see if colours have been extracted first!!
// Forum bug-fox (Jean-Yves - 23/02/2009)
if(!(occgeometry->face_colours.IsNull())
&&(occgeometry->face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour)))
{
matcol[0] = face_colour.Red();
matcol[1] = face_colour.Green();
matcol[2] = face_colour.Blue();
}
else
{
matcol[0] = 1.0;
matcol[1] = 1.0;
matcol[2] = 0.0;
}
matcol[3] = 1.0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, matcol);
}

View File

@ -541,12 +541,24 @@ namespace netgen
// Philippose - 30/01/2009
// OpenCascade XDE Support
Quantity_Color face_colour;
occgeometry->face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour);
// Philippose - 23/02/2009
// Check to see if colours have been extracted first!!
// Forum bug-fox (Jean-Yves - 23/02/2009)
if(!(occgeometry->face_colours.IsNull())
&& (occgeometry->face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour)))
{
mat_col[0] = face_colour.Red();
mat_col[1] = face_colour.Green();
mat_col[2] = face_colour.Blue();
}
else
{
mat_col[0] = 1.0;
mat_col[1] = 1.0;
mat_col[2] = 0.0;
}
}
else
{
mat_col[0] = 0.8;
mat_col[1] = 0.2;