Merge branch 'occ_colors' into 'master'

occ colors also in netgen gui, also allow transparency

See merge request jschoeberl/netgen!427
This commit is contained in:
Joachim Schöberl 2021-10-04 07:51:00 +00:00
commit 3ecca3e86e
12 changed files with 99 additions and 826 deletions

View File

@ -32,13 +32,13 @@ namespace netgen
colours match is defined as "eps" and is currently
2.5e-5 (for square of distance)
*/
bool ColourMatch(Vec3d col1, Vec3d col2, double eps)
bool ColourMatch(Vec<4> col1, Vec<4> col2, double eps)
{
if(eps <= 0.0) eps = DEFAULT_EPS;
bool colmatch = false;
if(Dist2(col1,col2) < eps) colmatch = true;
if((col1-col2).Length2() < eps) colmatch = true;
return colmatch;
}
@ -51,14 +51,14 @@ namespace netgen
Function to create a list of all the unique colours
available in a given mesh
*/
void GetFaceColours(Mesh & mesh, NgArray<Vec3d> & face_colours)
void GetFaceColours(Mesh & mesh, NgArray<Vec<4>> & face_colours)
{
face_colours.SetSize(1);
face_colours.Elem(1) = mesh.GetFaceDescriptor(1).SurfColour();
for(int i = 1; i <= mesh.GetNFD(); i++)
{
Vec3d face_colour = mesh.GetFaceDescriptor(i).SurfColour();
auto face_colour = mesh.GetFaceDescriptor(i).SurfColour();
bool col_found = false;
for(int j = 1; j <= face_colours.Size(); j++)
@ -143,7 +143,7 @@ namespace netgen
// Arrays to hold the specified RGB colour triplets as well
// as the associated boundary condition number
NgArray<Vec3d> bc_colours(numentries);
NgArray<Vec<4>> bc_colours(numentries);
NgArray<int> bc_num(numentries);
NgArray<bool> bc_used(numentries);
@ -162,9 +162,9 @@ namespace netgen
bc_num.Elem(i) = bcnum;
bc_used.Elem(i) = false;
ocf >> bc_colours.Elem(i).X()
>> bc_colours.Elem(i).Y()
>> bc_colours.Elem(i).Z();
ocf >> bc_colours.Elem(i)[0]
>> bc_colours.Elem(i)[1]
>> bc_colours.Elem(i)[2];
if(!ocf.good())
{
@ -175,12 +175,8 @@ namespace netgen
// Bound checking of the values
// The RGB values should be between 0.0 and 1.0
if(bc_colours.Elem(bcnum).X() < 0.0) bc_colours.Elem(bcnum).X() = 0.0;
if(bc_colours.Elem(bcnum).X() > 1.0) bc_colours.Elem(bcnum).X() = 1.0;
if(bc_colours.Elem(bcnum).Y() < 0.0) bc_colours.Elem(bcnum).X() = 0.0;
if(bc_colours.Elem(bcnum).Y() > 1.0) bc_colours.Elem(bcnum).X() = 1.0;
if(bc_colours.Elem(bcnum).Z() < 0.0) bc_colours.Elem(bcnum).X() = 0.0;
if(bc_colours.Elem(bcnum).Z() > 1.0) bc_colours.Elem(bcnum).X() = 1.0;
for(auto i : Range(3))
bc_colours.Elem(bcnum)[i] = max2(min2(bc_colours.Elem(bcnum)[i], 1.), 0.);
}
PrintMessage(3, "Successfully loaded Boundary Colour Profile file....");
@ -198,7 +194,7 @@ namespace netgen
PrintMessage(3, "Highest boundary number in list = ",max_bcnum);
NgArray<Vec3d> all_colours;
NgArray<Vec<4>> all_colours;
// Extract all the colours to see how many there are
GetFaceColours(mesh,all_colours);
@ -214,12 +210,9 @@ namespace netgen
for(int face_index = 1; face_index <= nfd; face_index++)
{
// Temporary container for individual face colours
Vec3d face_colour;
// Get the colour of the face being currently processed
face_colour = mesh.GetFaceDescriptor(face_index).SurfColour();
if(!ColourMatch(face_colour,Vec3d(DEFAULT_R,DEFAULT_G,DEFAULT_B)))
auto face_colour = mesh.GetFaceDescriptor(face_index).SurfColour();
if(!ColourMatch(face_colour,Vec<4>(DEFAULT_R,DEFAULT_G,DEFAULT_B, 1.0)))
{
// Boolean variable to check if the boundary condition was applied
// or not... not applied would imply that the colour of the face
@ -257,7 +250,7 @@ namespace netgen
}
// User Information of the results of the operation
Vec3d ref_colour(0.0,1.0,0.0);
Vec<4> ref_colour(0.0,1.0,0.0,1.0);
PrintMessage(3,"Colour based Boundary Condition Property details:");
for(int bc_index = 0; bc_index <= bc_num.Size(); bc_index++)
{
@ -266,12 +259,12 @@ namespace netgen
if(bc_index == 0)
{
PrintMessage(3, "BC Property: ",DEFAULT_BCNUM);
PrintMessage(3, " RGB Face Colour = ",ref_colour,"","\n");
PrintMessage(3, " RGB Face Colour = ",Vec3d{ref_colour[0], ref_colour[1], ref_colour[2]},"","\n");
}
else if(bc_used.Elem(bc_index))
{
PrintMessage(3, "BC Property: ",bc_num.Elem(bc_index));
PrintMessage(3, " RGB Face Colour = ",ref_colour,"","\n");
PrintMessage(3, " RGB Face Colour = ",Vec3d{ref_colour[0], ref_colour[1], ref_colour[2]},"","\n");
}
}
}
@ -290,7 +283,7 @@ namespace netgen
*/
void AutoColourAlg_Sorted(Mesh & mesh)
{
NgArray<Vec3d> all_colours;
NgArray<Vec<4>> all_colours;
NgArray<int> faces_sorted;
NgArray<int> colours_sorted;
@ -301,7 +294,7 @@ namespace netgen
// for automatically
for(int i = 1; i <= all_colours.Size(); i++)
{
if(ColourMatch(all_colours.Elem(i),Vec3d(DEFAULT_R,DEFAULT_G,DEFAULT_B)))
if(ColourMatch(all_colours.Elem(i),Vec<4>(DEFAULT_R,DEFAULT_G,DEFAULT_B,1.0)))
{
all_colours.DeleteElement(i);
break;
@ -346,10 +339,8 @@ namespace netgen
mesh.GetSurfaceElementsOfFace(face_index, se_face);
Vec3d face_colour;
face_colour = mesh.GetFaceDescriptor(face_index).SurfColour();
if(!ColourMatch(face_colour,Vec3d(DEFAULT_R,DEFAULT_G,DEFAULT_B)))
auto face_colour = mesh.GetFaceDescriptor(face_index).SurfColour();
if(!ColourMatch(face_colour,Vec<4>(DEFAULT_R,DEFAULT_G,DEFAULT_B,1.0)))
{
for(int i = 1; i <= all_colours.Size(); i++)
{
@ -378,14 +369,12 @@ namespace netgen
// Now actually assign the BC Property to the respective faces
for(int face_index = 1; face_index <= nfd; face_index++)
{
Vec3d face_colour;
face_colour = mesh.GetFaceDescriptor(face_index).SurfColour();
if(!ColourMatch(face_colour,Vec3d(DEFAULT_R,DEFAULT_G,DEFAULT_B)))
auto face_colour = mesh.GetFaceDescriptor(face_index).SurfColour();
if(!ColourMatch(face_colour,Vec<4>(DEFAULT_R,DEFAULT_G,DEFAULT_B, 1.0)))
{
for(int i = 0; i < colours_sorted.Size(); i++)
{
Vec3d ref_colour;
Vec<4> ref_colour;
if(i != no_colour_index) ref_colour = all_colours.Elem(colours_sorted[i]);
if(ColourMatch(face_colour, ref_colour))
@ -403,7 +392,7 @@ namespace netgen
}
// User Information of the results of the operation
Vec3d ref_colour(0.0,1.0,0.0);
Vec<4> ref_colour(0.0,1.0,0.0,1.0);
PrintMessage(3,"Colour based Boundary Condition Property details:");
for(int i = 0; i < faces_sorted.Size(); i++)
{
@ -412,7 +401,7 @@ namespace netgen
PrintMessage(3, "BC Property: ",i + DEFAULT_BCNUM);
PrintMessage(3, " Nr. of Surface Elements = ", faces_sorted[i]);
PrintMessage(3, " Colour Index = ", colours_sorted[i]);
PrintMessage(3, " RGB Face Colour = ",ref_colour,"","\n");
PrintMessage(3, " RGB Face Colour = ",Vec3d{ref_colour[0], ref_colour[1], ref_colour[2]},"","\n");
}
}

View File

@ -45,9 +45,9 @@ namespace netgen
//extern void OCCAutoColourBcProps(Mesh & mesh, OCCGeometry & occgeometry, const char *occcolourfile);
extern DLL_HEADER void AutoColourBcProps(Mesh & mesh, const char *bccolourfile);
extern DLL_HEADER void GetFaceColours(Mesh & mesh, NgArray<Vec3d> & face_colours);
extern DLL_HEADER void GetFaceColours(Mesh & mesh, NgArray<Vec<4>> & face_colours);
extern DLL_HEADER bool ColourMatch(Vec3d col1, Vec3d col2, double eps = 2.5e-05);
extern DLL_HEADER bool ColourMatch(Vec<4> col1, Vec<4> col2, double eps = 2.5e-05);
}
#endif

View File

@ -1080,6 +1080,15 @@ namespace netgen
outfile << GetFaceDescriptor(i).SurfColour()[2];
outfile << endl;
}
outfile << "face_transparencies" << endl << cnt_facedesc << endl;
for(i = 1; i <= cnt_facedesc; i++)
{
outfile.width(8);
outfile << GetFaceDescriptor(i).SurfNr()+1 << " ";
outfile.width(12);
outfile << GetFaceDescriptor(i).SurfColour()[3] << endl;
}
}
outfile << endl << endl << "endmesh" << endl << endl;
@ -1547,12 +1556,12 @@ namespace netgen
for(i = 1; i <= n; i++)
{
int surfnr = 0;
Vec3d surfcolour(0.0,1.0,0.0);
Vec<4> surfcolour(0.0,1.0,0.0,1.0);
infile >> surfnr
>> surfcolour.X()
>> surfcolour.Y()
>> surfcolour.Z();
>> surfcolour[0]
>> surfcolour[1]
>> surfcolour[2];
surfnr--;
@ -1570,6 +1579,36 @@ namespace netgen
}
}
if (strcmp (str, "face_transparencies") == 0)
{
int cnt_facedesc = GetNFD();
infile >> n;
int index = 1;
if(n == cnt_facedesc)
{
for(int index = 1; index <= n; index++)
{
int surfnr;
double transp;
infile >> surfnr >> transp;
surfnr--;
if(surfnr > 0)
{
for(int facedesc = 1; facedesc <= cnt_facedesc; facedesc++)
{
if(surfnr == GetFaceDescriptor(facedesc).SurfNr())
{
auto& fd = GetFaceDescriptor(facedesc);
auto scol = fd.SurfColour();
scol[3] = transp;
fd.SetSurfColour(scol);
}
}
}
}
}
}
if (strcmp (str, "endmesh") == 0)
endmesh = true;

View File

@ -2525,7 +2525,7 @@ namespace netgen
domin_singular = domout_singular = 0.;
// Philippose - 06/07/2009
// Initialise surface colour
surfcolour = Vec3d(0.0,1.0,0.0);
surfcolour = Vec<4>(0.0,1.0,0.0,1.0);
tlosurf = -1;
// bcname = 0;
firstelement = -1;
@ -2548,7 +2548,7 @@ namespace netgen
domout = domouti;
// Philippose - 06/07/2009
// Initialise surface colour
surfcolour = Vec3d(0.0,1.0,0.0);
surfcolour = Vec<4>(0.0,1.0,0.0,1.0);
tlosurf = tlosurfi;
bcprop = surfnri;
domin_singular = domout_singular = 0.;
@ -2563,7 +2563,7 @@ namespace netgen
domout = seg.domout+1;
// Philippose - 06/07/2009
// Initialise surface colour
surfcolour = Vec3d(0.0,1.0,0.0);
surfcolour = Vec<4>(0.0,1.0,0.0,1.0);
tlosurf = seg.tlosurf+1;
bcprop = 0;
domin_singular = domout_singular = 0.;

View File

@ -1171,7 +1171,7 @@ namespace netgen
// Add capability to store surface colours along with
// other face data
/// surface colour (Default: R=0.0 ; G=1.0 ; B=0.0)
Vec<3> surfcolour;
Vec<4> surfcolour;
///
static string default_bcname;
@ -1203,7 +1203,7 @@ namespace netgen
// Philippose - 06/07/2009
// Get Surface colour
Vec<3> SurfColour () const { return surfcolour; }
Vec<4> SurfColour () const { return surfcolour; }
DLL_HEADER const string & GetBCName () const { return *bcname; }
// string * BCNamePtr () { return bcname; }
// const string * BCNamePtr () const { return bcname; }
@ -1214,7 +1214,7 @@ namespace netgen
void SetBCName (string * bcn); // { bcname = bcn; }
// Philippose - 06/07/2009
// Set the surface colour
void SetSurfColour (Vec<3> colour) { surfcolour = colour; }
void SetSurfColour (Vec<4> colour) { surfcolour = colour; }
void SetDomainInSingular (double v) { domin_singular = v; }
void SetDomainOutSingular (double v) { domout_singular = v; }

View File

@ -418,7 +418,7 @@ namespace netgen
auto it = OCCGeometry::global_shape_properties.find(face.TShape());
if (it != OCCGeometry::global_shape_properties.end() && it->second.col)
{
Vec<3> col = it->second.col.value_or(Vec<3>(0,1,0));
Vec<4> col = it->second.col.value_or(Vec<4>(0,1,0,1));
mesh.GetFaceDescriptor(facenr).SetSurfColour(col);
}
else

View File

@ -218,7 +218,7 @@ namespace netgen
{
public:
optional<string> name;
optional<Vec<3>> col;
optional<Vec<4>> col;
double maxh = 1e99;
void Merge(const ShapeProperties & prop2)
{

View File

@ -687,14 +687,14 @@ namespace netgen
if(strcmp(argv[1], "getcolours") == 0)
{
stringstream outVar;
NgArray<Vec3d> face_colours;
NgArray<Vec<4>> face_colours;
GetFaceColours(*mesh, face_colours);
for(int i = 0; i < face_colours.Size();i++)
{
outVar << "{ " << face_colours[i].X(1)
<< " " << face_colours[i].X(2)
<< " " << face_colours[i].X(3)
outVar << "{ " << face_colours[i][0]
<< " " << face_colours[i][1]
<< " " << face_colours[i][2]
<< " } ";
}
@ -704,7 +704,7 @@ namespace netgen
if(strcmp(argv[1], "showalso") == 0)
{
NgArray<Vec3d> face_colours;
NgArray<Vec<4>> face_colours;
GetFaceColours(*mesh,face_colours);
int colourind = atoi (argv[2]);
@ -728,7 +728,7 @@ namespace netgen
if(strcmp(argv[1], "hidealso") == 0)
{
NgArray<Vec3d> face_colours;
NgArray<Vec<4>> face_colours;
GetFaceColours(*mesh,face_colours);
int colourind = atoi (argv[2]);
@ -752,7 +752,7 @@ namespace netgen
if(strcmp(argv[1], "showonly") == 0)
{
NgArray<Vec3d> face_colours;
NgArray<Vec<4>> face_colours;
GetFaceColours(*mesh,face_colours);
int colourind = atoi (argv[2]);
@ -783,7 +783,7 @@ namespace netgen
if(strcmp(argv[1], "hideonly") == 0)
{
NgArray<Vec3d> face_colours;
NgArray<Vec<4>> face_colours;
GetFaceColours(*mesh,face_colours);
int colourind = atoi (argv[2]);

View File

@ -883,12 +883,14 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
.def_property("col", [](const TopoDS_Shape & self) {
auto it = OCCGeometry::global_shape_properties.find(self.TShape());
Vec<3> col(0.2, 0.2, 0.2);
Vec<4> col(0.2, 0.2, 0.2);
if (it != OCCGeometry::global_shape_properties.end() && it->second.col)
col = *it->second.col;
col = *it->second.col;
return std::vector<double> ( { col(0), col(1), col(2) } );
}, [](const TopoDS_Shape & self, std::vector<double> c) {
Vec<3> col(c[0], c[1], c[2]);
Vec<4> col(c[0], c[1], c[2], 1.0);
if(c.size() == 4)
col[3] = c[3];
OCCGeometry::global_shape_properties[self.TShape()].col = col;
}, "color of shape as RGB - tuple")
.def("UnifySameDomain", [](const TopoDS_Shape& shape,
@ -1627,7 +1629,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
.def_property("col", [](ListOfShapes& shapes) {
throw Exception("Cannot get property of ListOfShapes, get the property from individual shapes!");
}, [](ListOfShapes& shapes, std::vector<double> c) {
Vec<3> col(c[0], c[1], c[2]);
Vec<4> col(c[0], c[1], c[2], 1.0);
if(c.size() == 4)
col[3] = c[3];
for(auto& shape : shapes)
OCCGeometry::global_shape_properties[shape.TShape()].col = col;
}, "set col for all elements of list")

View File

@ -568,6 +568,10 @@ namespace netgen
mat_col[1] = 1.0;
mat_col[2] = 0.0;
}
if(auto c = OCCGeometry::global_shape_properties[face.TShape()].col)
for(auto j : Range(4))
mat_col[j] = (*c)[j];
}
else
{

View File

@ -1019,9 +1019,8 @@ namespace netgen
// the mesh data structure, rather than limit it to the OCC geometry
// structure... allows other geometry types to use face colours too
for (auto i : Range(3))
for (auto i : Range(4))
matcol[i] = mesh->GetFaceDescriptor(faceindex).SurfColour()[i];
matcol[3] = 1.0;
if (faceindex == selface)
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matcolsel);

View File

@ -1,762 +0,0 @@
#ifndef NOTCL
#ifdef OCCGEOMETRY
#include <mystdlib.h>
#include <myadt.hpp>
#include <meshing.hpp>
#include <occgeom.hpp>
#include "TopoDS_Shape.hxx"
#include "TopoDS_Vertex.hxx"
#include "TopExp_Explorer.hxx"
#include "BRep_Tool.hxx"
#include "TopoDS.hxx"
#include "gp_Pnt.hxx"
#include "Geom_Curve.hxx"
#include "Poly_Triangulation.hxx"
#include "Poly_Array1OfTriangle.hxx"
#include "TColgp_Array1OfPnt2d.hxx"
#include "Poly_Triangle.hxx"
#include "Poly_Polygon3D.hxx"
#include "Poly_PolygonOnTriangulation.hxx"
#include <visual.hpp>
namespace netgen
{
extern OCCGeometry * occgeometry;
/* *********************** Draw OCC Geometry **************** */
VisualSceneOCCGeometry :: VisualSceneOCCGeometry ()
: VisualScene()
{
trilists.SetSize(0);
linelists.SetSize(1);
}
VisualSceneOCCGeometry :: ~VisualSceneOCCGeometry ()
{
;
}
void VisualSceneOCCGeometry :: DrawScene ()
{
if ( occgeometry->changed )
{
BuildScene();
occgeometry -> changed = 0;
}
glClearColor(backcolor, backcolor, backcolor, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SetLight();
glPushMatrix();
glMultMatrixf (transformationmat);
glShadeModel (GL_SMOOTH);
glDisable (GL_COLOR_MATERIAL);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glEnable (GL_LIGHTING);
double shine = vispar.shininess;
// double transp = vispar.transp;
glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shine);
glLogicOp (GL_COPY);
glEnable (GL_NORMALIZE);
float mat_col[] = { 0.2f, 0.2f, 0.8f, 1.0f};
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);
glPolygonOffset (1, 1);
glEnable (GL_POLYGON_OFFSET_FILL);
// Philippose - 30/01/2009
// Added clipping planes to Geometry view
SetClippingPlane();
GLfloat matcoledge[] = { 0, 0, 1, 1};
GLfloat matcolhiedge[] = { 1, 0, 0, 1};
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matcoledge);
glLineWidth (1.0f);
if (vispar.occshowedges) glCallList (linelists.Get(1));
if (vispar.occshowsurfaces) glCallList (trilists.Get(1));
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matcolhiedge);
glLineWidth (5.0f);
if (vispar.occshowedges) glCallList (linelists.Get(2));
for (int i = 1; i <= occgeometry->vmap.Extent(); i++)
if (occgeometry->vvispar[i-1].IsHighlighted())
{
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matcolhiedge);
glLineWidth (5.0f);
glBegin (GL_LINES);
gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(occgeometry->vmap(i)));
double d = rad/100;
glVertex3f (p.X()-d, p.Y(), p.Z());
glVertex3f (p.X()+d, p.Y(), p.Z());
glVertex3f (p.X(), p.Y()-d, p.Z());
glVertex3f (p.X(), p.Y()+d, p.Z());
glVertex3f (p.X(), p.Y(), p.Z()-d);
glVertex3f (p.X(), p.Y(), p.Z()+d);
glEnd();
}
glDisable (GL_POLYGON_OFFSET_FILL);
glPopMatrix();
// DrawCoordinateCross ();
// DrawNetgenLogo ();
glFinish();
glDisable (GL_POLYGON_OFFSET_FILL);
}
/*
void VisualSceneOCCGeometry :: BuildScene (int zoomall)
{
int i = 0, j, k;
TopExp_Explorer ex, ex_edge;
if (vispar.occvisproblemfaces || (occgeometry -> changed != 2))
{
Box<3> bb = occgeometry -> GetBoundingBox();
center = bb.Center();
rad = bb.Diam() / 2;
if (vispar.occvisproblemfaces)
{
for (i = 1; i <= occgeometry->fmap.Extent(); i++)
if (occgeometry->facemeshstatus[i-1] == -1)
{
GProp_GProps system;
BRepGProp::LinearProperties(occgeometry->fmap(i), system);
gp_Pnt pnt = system.CentreOfMass();
center = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
cout << "Setting center to mid of face " << i << " = " << center << endl;
}
}
CalcTransformationMatrices();
}
for (i = 1; i <= linelists.Size(); i++)
glDeleteLists (linelists.Elem(i), 1);
linelists.SetSize(0);
linelists.Append (glGenLists (1));
glNewList (linelists.Last(), GL_COMPILE);
i = 0;
for (ex_edge.Init(occgeometry -> shape, TopAbs_EDGE);
ex_edge.More(); ex_edge.Next())
{
if (BRep_Tool::Degenerated(TopoDS::Edge(ex_edge.Current()))) continue;
i++;
TopoDS_Edge edge = TopoDS::Edge(ex_edge.Current());
Handle(Poly_PolygonOnTriangulation) aEdgePoly;
Handle(Poly_Triangulation) T;
TopLoc_Location aEdgeLoc;
BRep_Tool::PolygonOnTriangulation(edge, aEdgePoly, T, aEdgeLoc);
if(aEdgePoly.IsNull())
{
cout << "cannot visualize edge " << i << endl;
continue;
}
glBegin (GL_LINE_STRIP);
int nbnodes = aEdgePoly -> NbNodes();
for (j = 1; j <= nbnodes; j++)
{
gp_Pnt p = (T -> Nodes())(aEdgePoly->Nodes()(j)).Transformed(aEdgeLoc);
glVertex3f (p.X(), p.Y(), p.Z());
}
glEnd ();
}
glEndList ();
for (i = 1; i <= trilists.Size(); i++)
glDeleteLists (trilists.Elem(i), 1);
trilists.SetSize(0);
trilists.Append (glGenLists (1));
glNewList (trilists.Last(), GL_COMPILE);
i = 0;
TopExp_Explorer exp0, exp1, exp2, exp3;
int shapenr = 0;
for (exp0.Init(occgeometry -> shape, TopAbs_SOLID); exp0.More(); exp0.Next())
{
shapenr++;
if (vispar.occshowvolumenr != 0 &&
vispar.occshowvolumenr != shapenr) continue;
float mat_col[4];
mat_col[3] = 1;
switch (shapenr)
{
case 1:
mat_col[0] = 0.2;
mat_col[1] = 0.2;
mat_col[2] = 0.8;
break;
case 2:
mat_col[0] = 0.8;
mat_col[1] = 0.2;
mat_col[2] = 0.8;
break;
case 3:
mat_col[0] = 0.2;
mat_col[1] = 0.8;
mat_col[2] = 0.8;
break;
case 4:
mat_col[0] = 0.8;
mat_col[1] = 0.2;
mat_col[2] = 0.2;
break;
case 5:
mat_col[0] = 0.8;
mat_col[1] = 0.8;
mat_col[2] = 0.8;
break;
case 6:
mat_col[0] = 0.6;
mat_col[1] = 0.6;
mat_col[2] = 0.6;
break;
case 7:
mat_col[0] = 0.2;
mat_col[1] = 0.8;
mat_col[2] = 0.2;
break;
case 8:
mat_col[0] = 0.8;
mat_col[1] = 0.8;
mat_col[2] = 0.2;
break;
default:
// mat_col[0] = 1-(1.0/double(shapenr));
// mat_col[1] = 0.5;
mat_col[0] = 0.5+double((shapenr*shapenr*shapenr*shapenr) % 10)/20.0;
mat_col[1] = 0.5+double(int(shapenr*shapenr*shapenr*shapenr*sin(double(shapenr))) % 10)/20.0;
mat_col[2] = 0.5+double((shapenr*shapenr*shapenr) % 10)/20.0;
}
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);
for (exp1.Init(exp0.Current(), TopAbs_SHELL); exp1.More(); exp1.Next())
for (exp2.Init(exp1.Current().Composed(exp0.Current().Orientation()), TopAbs_FACE); exp2.More(); exp2.Next())
{
TopoDS_Face face = TopoDS::Face (exp2.Current().Composed(exp1.Current().Orientation()));
i = occgeometry->fmap.FindIndex(face);
TopLoc_Location loc;
Handle(Geom_Surface) surf = BRep_Tool::Surface (face);
BRepAdaptor_Surface sf(face, Standard_False);
BRepLProp_SLProps prop(sf, 1, 1e-5);
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc);
if (triangulation.IsNull())
{
cout << "cannot visualize face " << i << endl;
continue;
}
if (vispar.occvisproblemfaces)
{
switch (occgeometry->facemeshstatus[i-1])
{
case 0:
mat_col[0] = 0.2;
mat_col[1] = 0.2;
mat_col[2] = 0.8;
break;
case 1:
mat_col[0] = 0.2;
mat_col[1] = 0.8;
mat_col[2] = 0.2;
break;
case -1:
mat_col[0] = 0.8;
mat_col[1] = 0.2;
mat_col[2] = 0.2;
break;
}
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);
}
glBegin (GL_TRIANGLES);
int ntriangles = triangulation -> NbTriangles();
for (j = 1; j <= ntriangles; j++)
{
Poly_Triangle triangle = (triangulation -> Triangles())(j);
for (k = 1; k <= 3; k++)
{
gp_Pnt2d uv = (triangulation -> UVNodes())(triangle(k));
gp_Pnt pnt;
gp_Vec du, dv;
prop.SetParameters (uv.X(), uv.Y());
surf->D0 (uv.X(), uv.Y(), pnt);
gp_Vec n;
if (prop.IsNormalDefined())
n = prop.Normal();
else
n = gp_Vec (0,0,0);
if (face.Orientation() == TopAbs_REVERSED) n *= -1;
glNormal3f (n.X(), n.Y(), n.Z());
glVertex3f (pnt.X(), pnt.Y(), pnt.Z());
}
}
glEnd ();
}
}
glEndList ();
}
*/
void VisualSceneOCCGeometry :: BuildScene (int zoomall)
{
if (occgeometry -> changed == OCCGEOMETRYVISUALIZATIONFULLCHANGE)
{
occgeometry -> BuildVisualizationMesh (vispar.occdeflection);
center = occgeometry -> Center();
rad = occgeometry -> GetBoundingBox().Diam() / 2;
if (vispar.occzoomtohighlightedentity)
{
bool hilite = false;
bool hiliteonepoint = false;
Bnd_Box bb;
for (int i = 1; i <= occgeometry->fmap.Extent(); i++)
if (occgeometry->fvispar[i-1].IsHighlighted())
{
hilite = true;
BRepBndLib::Add (occgeometry->fmap(i), bb);
}
for (int i = 1; i <= occgeometry->emap.Extent(); i++)
if (occgeometry->evispar[i-1].IsHighlighted())
{
hilite = true;
BRepBndLib::Add (occgeometry->emap(i), bb);
}
for (int i = 1; i <= occgeometry->vmap.Extent(); i++)
if (occgeometry->vvispar[i-1].IsHighlighted())
{
hiliteonepoint = true;
BRepBndLib::Add (occgeometry->vmap(i), bb);
}
if (hilite || hiliteonepoint)
{
double x1,y1,z1,x2,y2,z2;
bb.Get (x1,y1,z1,x2,y2,z2);
Point<3> p1 = Point<3> (x1,y1,z1);
Point<3> p2 = Point<3> (x2,y2,z2);
Box<3> boundingbox(p1,p2);
center = boundingbox.Center();
if (hiliteonepoint)
rad = occgeometry -> GetBoundingBox().Diam() / 100;
else
rad = boundingbox.Diam() / 2;
}
}
CalcTransformationMatrices();
}
// Clear lists
for (int i = 1; i <= linelists.Size(); i++)
glDeleteLists (linelists.Elem(i), 1);
linelists.SetSize(0);
for (int i = 1; i <= trilists.Size(); i++)
glDeleteLists (trilists.Elem(i), 1);
trilists.SetSize(0);
// Total wireframe
linelists.Append (glGenLists (1));
glNewList (linelists.Last(), GL_COMPILE);
for (int i = 1; i <= occgeometry->emap.Extent(); i++)
{
TopoDS_Edge edge = TopoDS::Edge(occgeometry->emap(i));
if (BRep_Tool::Degenerated(edge)) continue;
if (occgeometry->evispar[i-1].IsHighlighted()) continue;
Handle(Poly_PolygonOnTriangulation) aEdgePoly;
Handle(Poly_Triangulation) T;
TopLoc_Location aEdgeLoc;
BRep_Tool::PolygonOnTriangulation(edge, aEdgePoly, T, aEdgeLoc);
if(aEdgePoly.IsNull())
{
(*testout) << "visualizing edge " << occgeometry->emap.FindIndex (edge)
<< " without using the occ visualization triangulation" << endl;
double s0, s1;
Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
glBegin (GL_LINE_STRIP);
for (int i = 0; i<=50; i++)
{
gp_Pnt p = c->Value (s0 + i*(s1-s0)/50.0);
glVertex3f (p.X(),p.Y(),p.Z());
}
glEnd ();
continue;
}
int nbnodes = aEdgePoly -> NbNodes();
glBegin (GL_LINE_STRIP);
for (int j = 1; j <= nbnodes; j++)
{
gp_Pnt p = (T -> Nodes())(aEdgePoly->Nodes()(j)).Transformed(aEdgeLoc);
glVertex3f (p.X(), p.Y(), p.Z());
}
glEnd ();
}
glEndList ();
// Highlighted edge list
linelists.Append (glGenLists (1));
glNewList (linelists.Last(), GL_COMPILE);
for (int i = 1; i <= occgeometry->emap.Extent(); i++)
if (occgeometry->evispar[i-1].IsHighlighted())
{
TopoDS_Edge edge = TopoDS::Edge(occgeometry->emap(i));
if (BRep_Tool::Degenerated(edge)) continue;
Handle(Poly_PolygonOnTriangulation) aEdgePoly;
Handle(Poly_Triangulation) T;
TopLoc_Location aEdgeLoc;
BRep_Tool::PolygonOnTriangulation(edge, aEdgePoly, T, aEdgeLoc);
if(aEdgePoly.IsNull())
{
(*testout) << "visualizing edge " << occgeometry->emap.FindIndex (edge)
<< " without using the occ visualization triangulation" << endl;
double s0, s1;
Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
glBegin (GL_LINE_STRIP);
for (int i = 0; i<=50; i++)
{
gp_Pnt p = c->Value (s0 + i*(s1-s0)/50.0);
glVertex3f (p.X(),p.Y(),p.Z());
}
glEnd ();
continue;
}
int nbnodes = aEdgePoly -> NbNodes();
glBegin (GL_LINE_STRIP);
for (int j = 1; j <= nbnodes; j++)
{
gp_Pnt p = (T -> Nodes())(aEdgePoly->Nodes()(j)).Transformed(aEdgeLoc);
glVertex3f (p.X(), p.Y(), p.Z());
}
glEnd ();
}
glEndList ();
// display faces
trilists.Append (glGenLists (1));
glNewList (trilists.Last(), GL_COMPILE);
for (int i = 1; i <= occgeometry->fmap.Extent(); i++)
{
if (!occgeometry->fvispar[i-1].IsVisible()) continue;
glLoadName (i);
float mat_col[4];
mat_col[3] = 1;
TopoDS_Face face = TopoDS::Face(occgeometry->fmap(i));
if (!occgeometry->fvispar[i-1].IsHighlighted())
{
// Philippose - 30/01/2009
// OpenCascade XDE Support
Quantity_Color 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] = 0.0;
mat_col[1] = 1.0;
mat_col[2] = 0.0;
}
}
else
{
mat_col[0] = 0.8;
mat_col[1] = 0.2;
mat_col[2] = 0.2;
}
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);
TopLoc_Location loc;
Handle(Geom_Surface) surf = BRep_Tool::Surface (face);
BRepAdaptor_Surface sf(face, Standard_False);
BRepLProp_SLProps prop(sf, 1, 1e-5);
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc);
if (triangulation.IsNull())
{
cout << "cannot visualize face " << i << endl;
occgeometry->fvispar[i-1].SetNotDrawable();
continue;
}
gp_Pnt2d uv;
gp_Pnt pnt;
gp_Vec n;
glBegin (GL_TRIANGLES);
int ntriangles = triangulation -> NbTriangles();
for (int j = 1; j <= ntriangles; j++)
{
Poly_Triangle triangle = (triangulation -> Triangles())(j);
gp_Pnt p[3];
for (int k = 1; k <= 3; k++)
p[k-1] = (triangulation -> Nodes())(triangle(k)).Transformed(loc);
for (int k = 1; k <= 3; k++)
{
uv = (triangulation -> UVNodes())(triangle(k));
prop.SetParameters (uv.X(), uv.Y());
// surf->D0 (uv.X(), uv.Y(), pnt);
if (prop.IsNormalDefined())
n = prop.Normal();
else
{
(*testout) << "Visualization of face " << i
<< ": Normal vector not defined" << endl;
// n = gp_Vec (0,0,0);
gp_Vec a(p[0],p[1]);
gp_Vec b(p[0],p[2]);
n = b^a;
}
if (face.Orientation() == TopAbs_REVERSED) n *= -1;
glNormal3f (n.X(), n.Y(), n.Z());
glVertex3f (p[k-1].X(), p[k-1].Y(), p[k-1].Z());
}
}
glEnd ();
}
glEndList ();
}
void SelectFaceInOCCDialogTree (int facenr);
void VisualSceneOCCGeometry :: MouseDblClick (int px, int py)
{
int hits;
// select surface triangle by mouse click
GLuint selbuf[10000];
glSelectBuffer (10000, selbuf);
glRenderMode (GL_SELECT);
GLint viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
GLdouble projmat[16];
glGetDoublev (GL_PROJECTION_MATRIX, projmat);
glLoadIdentity();
gluPickMatrix (px, viewport[3] - py, 1, 1, viewport);
glMultMatrixd (projmat);
glClearColor(backcolor, backcolor, backcolor, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glMultMatrixf (transformationmat);
glInitNames();
glPushName (1);
glPolygonOffset (1, 1);
glEnable (GL_POLYGON_OFFSET_FILL);
glDisable(GL_CLIP_PLANE0);
// Philippose - 30/01/2009
// Enable clipping planes for Selection mode in OCC Geometry
if (vispar.clipenable)
{
Vec<3> n(clipplane[0], clipplane[1], clipplane[2]);
double len = Abs(n);
double mu = -clipplane[3] / (len*len);
Point<3> p (mu * n);
n /= len;
Vec<3> t1 = n.GetNormal ();
Vec<3> t2 = Cross (n, t1);
double xi1mid = (center - p) * t1;
double xi2mid = (center - p) * t2;
glLoadName (0);
glBegin (GL_QUADS);
glVertex3dv (p + (xi1mid-rad) * t1 + (xi2mid-rad) * t2);
glVertex3dv (p + (xi1mid+rad) * t1 + (xi2mid-rad) * t2);
glVertex3dv (p + (xi1mid+rad) * t1 + (xi2mid+rad) * t2);
glVertex3dv (p + (xi1mid-rad) * t1 + (xi2mid+rad) * t2);
glEnd ();
}
glCallList (trilists.Get(1));
glDisable (GL_POLYGON_OFFSET_FILL);
glPopName();
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glMatrixMode (GL_MODELVIEW);
glPopMatrix();
glFlush();
hits = glRenderMode (GL_RENDER);
int minname = 0;
GLuint mindepth = 0;
// find clippingplane
GLuint clipdepth = 0; // GLuint(-1);
for (int i = 0; i < hits; i++)
{
int curname = selbuf[4*i+3];
if (!curname) clipdepth = selbuf[4*i+1];
}
for (int i = 0; i < hits; i++)
{
int curname = selbuf[4*i+3];
GLuint curdepth = selbuf[4*i+1];
if (curname && (curdepth> clipdepth) &&
(curdepth < mindepth || !minname))
{
mindepth = curdepth;
minname = curname;
}
}
occgeometry->LowLightAll();
if (minname)
{
occgeometry->fvispar[minname-1].Highlight();
if (vispar.occzoomtohighlightedentity)
occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
else
occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
cout << "Selected face: " << minname << endl;
}
else
{
occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
}
glDisable(GL_CLIP_PLANE0);
SelectFaceInOCCDialogTree (minname);
// Philippose - 30/01/2009
// Set the currently selected face in the array
// for local face mesh size definition
occgeometry->SetSelectedFace(minname);
// selecttimestamp = NextTimeStamp();
}
}
#endif
#endif // NOTCL