* Added a separate source and header file for OpenCascade Auxiliary functions which cannot be directly categorised under either geometry or mesh operations.

This commit is contained in:
Philippose Rajan 2009-03-15 12:17:27 +00:00
parent 87404f51c9
commit e266a0115d
2 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,138 @@
#ifdef OCCGEOMETRY
#include <mystdlib.h>
#include <meshing.hpp>
#include <occgeom.hpp>
namespace netgen
{
void OCCAutoColourBcProps(Mesh & mesh, OCCGeometry & occgeometry)
{
TDF_LabelSequence all_colours;
Array<int> faces_sorted;
Array<int> colours_sorted;
// Extract all the colours to see how many there are
occgeometry.face_colours->GetColors(all_colours);
PrintMessage(3,"\nNumber of colours defined in OCC Mesh: ", all_colours.Length());
if(all_colours.Length() == 0)
{
PrintMessage(3,"No colour data detected in OCC Mesh... no changes made!");
return;
}
// One more slot than the number of colours are required, to
// account for individual faces which have no colour data
// assigned to them in the CAD software
faces_sorted.SetSize(all_colours.Length()+1);
colours_sorted.SetSize(all_colours.Length()+1);
faces_sorted = 0;
// Slave Array to identify the colours the faces were assigned to,
// after the bubble sort routine to sort the automatic boundary
// identifiers according to the number of surface mesh elements
// of a given colour
for(int i = 0; i <= all_colours.Length(); i++) colours_sorted[i] = i;
// Used to hold the number of surface elements without any OCC
// colour definition
int no_colour_faces = 0;
// Index in the faces array assigned to faces without an
// OCC Colour definition
int no_colour_index = 0;
int nfd = mesh.GetNFD();
// Extract the number of surface elements having a given OCC colour
// And save this number into an array for later sorting
for(int face_index = 1; face_index <= nfd; face_index++)
{
Array<SurfaceElementIndex> se_face;
mesh.GetSurfaceElementsOfFace(face_index, se_face);
// Note: From the logic in file "occgenmesh.cpp", function "FindEdges"
// the Face Descriptor Number of an OCC face has a one-to-one mapping
// to the face number in the OCC face map (fmap)
TopoDS_Face face = TopoDS::Face(occgeometry.fmap(face_index));
Quantity_Color face_colour;
if(occgeometry.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))
{
for(int i = 1; i <= all_colours.Length(); i++)
{
Quantity_Color ref_colour;
occgeometry.face_colours->GetColor(all_colours.Value(i),ref_colour);
if(face_colour == ref_colour)
{
faces_sorted[i] = faces_sorted[i] + se_face.Size();
}
}
}
else
{
// Add the number of surface elements without any colour
// definition separately
no_colour_faces = no_colour_faces + se_face.Size();
}
}
// Sort the face colour indices according to the number of surface
// mesh elements which have a specific colour
BubbleSort(faces_sorted,colours_sorted);
// Now update the array position assigned for surface elements
// without any colour definition with the number of elements
faces_sorted[no_colour_index] = no_colour_faces;
// Now actually assign the BC Property to the respective faces
for(int face_index = 1; face_index <= nfd; face_index++)
{
TopoDS_Face face = TopoDS::Face(occgeometry.fmap(face_index));
Quantity_Color face_colour;
if(occgeometry.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))
{
for(int i = 0; i < colours_sorted.Size(); i++)
{
Quantity_Color ref_colour;
if(i != no_colour_index)
occgeometry.face_colours->GetColor(all_colours.Value(colours_sorted[i]),ref_colour);
if(face_colour == ref_colour)
{
mesh.GetFaceDescriptor(face_index).SetBCProperty(i);
}
}
}
else
{
mesh.GetFaceDescriptor(face_index).SetBCProperty(no_colour_index);
}
PrintMessage(4,"Face number: ",face_index," ; BC Property = ",mesh.GetFaceDescriptor(face_index).BCProperty());
}
// User Information of the results of the operation
PrintMessage(3,"OCC Colour based Boundary Condition Property details:");
for(int i = 0; i < faces_sorted.Size(); i++)
{
Quantity_Color ref_colour;
ref_colour.SetValues(1.0,1.0,0.0,Quantity_TOC_RGB);
if(colours_sorted[i] > 0) occgeometry.face_colours->GetColor(all_colours.Value(colours_sorted[i]),ref_colour);
PrintMessage(3, "BC Property: ",i);
PrintMessage(3, " Nr. of Surface Elements = ", faces_sorted[i]);
PrintMessage(3, " OCC Colour Index = ", colours_sorted[i]);
PrintMessage(3, " RGB Face Colour = (",ref_colour.Red(),","
,ref_colour.Green(),","
,ref_colour.Blue(),")","\n");
}
}
}
#endif // #ifdef OCCGEOMETRY

View File

@ -0,0 +1,46 @@
#ifndef FILE_OCCAUXFUNCTIONS
#define FILE_OCCAUXFUNCTIONS
// Philippose - 14/03/2009
// Auxiliary functions for OCC Geometry
// Use this file and the corresponding ".cpp"
// file to add miscellaneous functionality
// to the OpenCascade Geometry support in Netgen
namespace netgen
{
/*! \brief Automatically assign boundary conditions for OCC meshes
This function allows the boundary condition numbers of a
mesh created using an OpenCascade (STEP / IGES) geometry
to be assigned automatically.
The boundary conditions are assigned based on the face
colour information (if any) contained in the geometry.
Currently the following process is used to assign the BC Properties:
- Extract all the colours present in the OCC Geometry
- Use colour index 0 (zero) for all faces with no colour defined
- Calculate the number of faces of the surface mesh for each colour
- Sort the number of surface elements in ascending order, with the
colour indices as a slave
- Use the indices of the sorted array as the BC property number
Example: If there are 3 colours, present in the file and the number
of surface elements for each colour are:
- Colour 0: 8500
- Colour 1: 120
- Colour 2: 2200
- Colour 3: 575
The above is sorted in ascending order and assigned as BC Properties:
- BC Prop 0: 120 : Colour 1
- BC Prop 1: 575 : Colour 3
- BC Prop 2: 2200 : Colour 2
- BC Prop 3: 8500 : Colour 0 (no colour defined)
*/
extern void OCCAutoColourBcProps(Mesh & mesh, OCCGeometry & occgeometry);
}
#endif