netgen/libsrc/visualization/vsmesh.cpp

3567 lines
87 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#include <mystdlib.h>
2009-01-25 17:14:08 +05:00
2009-01-13 04:40:13 +05:00
#include <myadt.hpp>
#include <meshing.hpp>
2011-01-11 01:18:01 +05:00
// #include <csg.hpp>
#ifdef STLGEOM
2009-01-13 04:40:13 +05:00
#include <stlgeom.hpp>
2011-01-11 01:18:01 +05:00
#endif
2009-01-13 04:40:13 +05:00
2009-01-25 17:20:07 +05:00
// #include <parallel.hpp>
2009-01-13 04:40:13 +05:00
#include <visual.hpp>
2009-01-13 04:40:13 +05:00
namespace netgen
{
2014-10-06 15:57:44 +06:00
// extern shared_ptr<Mesh> mesh;
2011-01-11 01:18:01 +05:00
extern NetgenGeometry * ng_geometry;
VisualSceneMesh vsmesh;
VisualSceneMesh :: VisualSceneMesh ()
: VisualScene()
{
selface = -1;
selelement = -1;
2023-03-29 23:30:21 +05:00
locpi = -2;
2019-08-07 21:34:43 +05:00
selpoint = PointIndex::INVALID;
selpoint2 = PointIndex::INVALID;
2011-01-11 01:18:01 +05:00
seledge = -1;
minh = 0.0;
maxh = 0.0;
2012-08-30 19:40:17 +06:00
user_me_handler = NULL;
2011-01-11 01:18:01 +05:00
}
VisualSceneMesh :: ~VisualSceneMesh ()
{
;
}
void VisualSceneMesh :: DrawScene ()
{
2014-10-06 15:57:44 +06:00
try
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
if (!mesh)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
VisualScene::DrawScene();
return;
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
lock = NULL;
2011-01-15 01:50:12 +05:00
static int timer = NgProfiler::CreateTimer ("VSMesh::DrawScene");
NgProfiler::RegionTimer reg (timer);
2011-01-11 01:18:01 +05:00
BuildScene();
2015-01-09 02:18:33 +05:00
glEnable(GL_DEPTH_TEST);
2011-01-11 01:18:01 +05:00
glClearColor(backcolor, backcolor, backcolor, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2011-01-11 01:18:01 +05:00
glEnable (GL_COLOR_MATERIAL);
glColor3f (1.0f, 1.0f, 1.0f);
glLineWidth (1.0f);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
SetLight();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glPushMatrix();
glMultMatrixd (transformationmat);
2009-01-13 04:40:13 +05:00
GLdouble projmat[16]; // brauchen wir das ?
2011-01-11 01:18:01 +05:00
glGetDoublev (GL_PROJECTION_MATRIX, projmat);
2009-01-13 04:40:13 +05:00
#ifdef PARALLEL
2011-01-11 01:18:01 +05:00
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2009-01-13 04:40:13 +05:00
#endif
2011-01-11 01:18:01 +05:00
glInitNames ();
glPushName (0);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
// glEnable (GL_LINE_SMOOTH);
// glEnable (GL_BLEND);
// glEnable (GL_POLYGON_SMOOTH);
// glDisable (GL_DEPTH_TEST);
// glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
2011-01-11 01:18:01 +05:00
glDisable (GL_COLOR_MATERIAL);
2011-01-11 01:18:01 +05:00
GLfloat matcol0[] = { 0, 0, 0, 1 };
GLfloat matcol1[] = { 1, 1, 1, 1 };
GLfloat matcolf[] = { 0, 1, 0, 1 };
GLfloat matcolb[] = { 0.5, 0, 0, 1 };
// GLfloat matcolblue[] = { 0, 0, 1, 1 };
2011-01-11 01:18:01 +05:00
glMatrixMode (GL_MODELVIEW);
2011-01-11 01:18:01 +05:00
glMaterialfv(GL_FRONT, GL_EMISSION, matcol0);
glMaterialfv(GL_BACK, GL_EMISSION, matcol0);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matcol1);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, matcolf);
glMaterialfv(GL_BACK, GL_AMBIENT_AND_DIFFUSE, matcolb);
2011-01-11 01:18:01 +05:00
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
// glPolygonOffset (1,10);
glPolygonOffset (2,2);
glEnable (GL_POLYGON_OFFSET_FILL);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
SetClippingPlane ();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.drawfilledtrigs)
2009-01-13 04:40:13 +05:00
{
2023-03-29 23:30:21 +05:00
BuildFilledList (false);
2009-01-13 04:40:13 +05:00
2009-08-24 08:56:22 +06:00
2009-01-13 04:40:13 +05:00
#ifdef PARALLELGL
2011-01-11 01:18:01 +05:00
if (ntasks > 1 && vispar.drawtetsdomain > 0 && vispar.drawtetsdomain < ntasks)
glCallList (par_filledlists[vispar.drawtetsdomain]);
else
2009-01-13 04:40:13 +05:00
#endif
2011-01-11 01:18:01 +05:00
glCallList (filledlist);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (vispar.drawbadels)
glCallList (badellist);
2009-01-13 04:40:13 +05:00
BitArray shownode(mesh->GetNP()+1);
if (vispar.clipping.enable)
{
shownode.Clear();
for (PointIndex pi : mesh->Points().Range())
{
Point<3> p = (*mesh)[pi];
double val =
p[0] * clipplane[0] +
p[1] * clipplane[1] +
p[2] * clipplane[2] +
clipplane[3];
if (val > 0) shownode.SetBit (pi);
}
}
else
shownode.Set();
2011-01-11 01:18:01 +05:00
if (vispar.drawprisms)
2009-01-13 04:40:13 +05:00
{
BuildPrismList (shownode);
2011-01-11 01:18:01 +05:00
glCallList (prismlist);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (vispar.drawpyramids)
2009-01-13 04:40:13 +05:00
{
BuildPyramidList (shownode);
2011-01-11 01:18:01 +05:00
glCallList (pyramidlist);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (vispar.drawhexes)
2009-01-13 04:40:13 +05:00
{
BuildHexList (shownode);
2011-01-11 01:18:01 +05:00
glCallList (hexlist);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (vispar.drawtets)
2009-01-13 04:40:13 +05:00
{
BuildTetList (shownode);
2011-01-11 01:18:01 +05:00
glCallList (tetlist);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (vispar.drawdomainsurf)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
BuildDomainSurfList();
glCallList (domainsurflist);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glDisable (GL_POLYGON_OFFSET_FILL);
2011-01-11 01:18:01 +05:00
// draw lines
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glMatrixMode (GL_MODELVIEW);
2011-01-11 01:18:01 +05:00
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, matcol0);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, matcol0);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matcol0);
2011-01-11 01:18:01 +05:00
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
glLineWidth (1.0f);
glColor3f (0.0f, 0.0f, 0.0f);
glDisable (GL_LINE_SMOOTH);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.drawoutline)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
glPolygonOffset (1, 1);
glEnable (GL_POLYGON_OFFSET_LINE);
2009-01-13 04:40:13 +05:00
BuildLineList ();
2009-01-13 04:40:13 +05:00
#ifdef PARALLELGL
2011-01-11 01:18:01 +05:00
if (ntasks > 1 && vispar.drawtetsdomain > 0 && vispar.drawtetsdomain < ntasks)
glCallList (par_linelists[vispar.drawtetsdomain]);
else
2009-01-13 04:40:13 +05:00
#endif
2011-01-11 01:18:01 +05:00
glCallList (linelist);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glDisable (GL_POLYGON_OFFSET_LINE);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (vispar.drawidentified)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
glPolygonOffset (1, -1);
glEnable (GL_POLYGON_OFFSET_LINE);
glCallList (identifiedlist);
glDisable (GL_POLYGON_OFFSET_LINE);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (vispar.drawpointnumbers ||
vispar.drawedgenumbers ||
vispar.drawfacenumbers ||
vispar.drawsegmentnumbers ||
vispar.drawsurfaceelementnumbers ||
2011-01-11 01:18:01 +05:00
vispar.drawelementnumbers)
glCallList (pointnumberlist);
2011-01-11 01:18:01 +05:00
glPopName();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.drawedges)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
BuildEdgeList();
glCallList (edgelist);
2009-01-13 04:40:13 +05:00
}
DrawMarker();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glDisable(GL_CLIP_PLANE0);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glPopMatrix();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.colormeshsize)
DrawColorBar (minh, maxh, 1);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
DrawCoordinateCross ();
DrawNetgenLogo ();
2009-01-13 04:40:13 +05:00
2011-01-15 01:50:12 +05:00
2011-01-11 01:18:01 +05:00
if (lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock -> UnLock();
delete lock;
lock = NULL;
2009-01-13 04:40:13 +05:00
}
2011-01-15 01:50:12 +05:00
2011-01-11 01:18:01 +05:00
glFinish();
2014-10-06 15:57:44 +06:00
}
catch (bad_weak_ptr e)
{
2017-01-01 19:34:38 +05:00
// cout << "don't have a mesh to visualize" << endl;
2014-10-06 15:57:44 +06:00
VisualScene::DrawScene();
}
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
2023-03-31 18:46:45 +05:00
void VisualSceneMesh :: SelectCenter (int zoomall)
{
shared_ptr<Mesh> mesh = GetMesh();
Point3d pmin, pmax;
mesh->GetBox (pmin, pmax, -1);
// works in NGSolve, mesh view
if (mesh->GetDimension() == 2)
mesh->GetBox (pmin, pmax);
else // otherwise strange zooms during mesh generation
mesh->GetBox (pmin, pmax, SURFACEPOINT);
if (vispar.use_center_coords && zoomall==2)
{
center.X() = vispar.centerx;
center.Y() = vispar.centery;
center.Z() = vispar.centerz;
}
else if (selpoint >= 1 && zoomall==2)
center = mesh->Point (selpoint);
else if (marker && zoomall==2)
center = *marker;
else if (vispar.centerpoint >= 1 && zoomall==2)
center = mesh->Point (vispar.centerpoint);
else
center = Center (pmin, pmax);
double oldrad = rad;
rad = 0.5 * Dist (pmin, pmax);
if(rad == 0) rad = 1e-6;
if (rad > 1.2 * oldrad ||
mesh->GetMajorTimeStamp() > vstimestamp ||
zoomall)
{
CalcTransformationMatrices();
}
glEnable (GL_NORMALIZE);
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: BuildScene (int zoomall)
{
2014-10-06 15:57:44 +06:00
try
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
if (!mesh)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
VisualScene::BuildScene (zoomall);
return;
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (!lock)
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
}
2011-01-15 01:50:12 +05:00
static int timer = NgProfiler::CreateTimer ("VSMesh::BuildScene");
NgProfiler::RegionTimer reg (timer);
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<Element2d> faces;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
int meshtimestamp = mesh->GetTimeStamp();
if (meshtimestamp > vstimestamp || zoomall)
2023-03-31 18:46:45 +05:00
SelectCenter(zoomall);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (pointnumberlist)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
glDeleteLists (pointnumberlist, 1);
pointnumberlist = 0;
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (badellist)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
glDeleteLists (badellist, 1);
badellist = 0;
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
/*
2009-01-13 04:40:13 +05:00
if (prismlist)
{
glDeleteLists (prismlist, 1);
prismlist = 0;
}
if (pyramidlist)
{
glDeleteLists (pyramidlist, 1);
pyramidlist = 0;
}
if (hexlist)
{
glDeleteLists (hexlist, 1);
hexlist = 0;
}
2011-01-11 01:18:01 +05:00
*/
if (identifiedlist)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
glDeleteLists (identifiedlist, 1);
identifiedlist = 0;
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
pointnumberlist = glGenLists (1);
glNewList (pointnumberlist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.drawpointnumbers ||
vispar.drawedgenumbers ||
vispar.drawfacenumbers ||
vispar.drawsegmentnumbers ||
vispar.drawsurfaceelementnumbers ||
2011-01-11 01:18:01 +05:00
vispar.drawelementnumbers)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
// glEnable (GL_COLOR_MATERIAL);
2014-08-15 20:46:26 +06:00
GLfloat textcol[3] = { float(1-backcolor),
float(1-backcolor),
float(1-backcolor) };
2011-01-11 01:18:01 +05:00
glColor3fv (textcol);
glNormal3d (0, 0, 1);
glPushAttrib (GL_LIST_BIT);
// glListBase (fontbase);
char buf[30];
if (vispar.drawpointnumbers)
2016-12-12 00:17:07 +05:00
for (PointIndex pi : mesh->Points().Range())
{
2016-12-12 00:17:07 +05:00
const Point3d & p = mesh->Point(pi);
2011-01-11 01:18:01 +05:00
glRasterPos3d (p.X(), p.Y(), p.Z());
2022-12-08 19:26:27 +05:00
snprintf (buf, size(buf), "%d", int(pi));
2011-01-11 01:18:01 +05:00
// glCallLists (strlen (buf), GL_UNSIGNED_BYTE, buf);
MyOpenGLText (buf);
}
2011-01-11 01:18:01 +05:00
if (vispar.drawedgenumbers)
{
/*
for (SegmentIndex i = 0; i < mesh->GetNSeg(); i++)
{
const Segment & seg = (*mesh)[i];
const Point3d & p1 = mesh->Point(seg[0]);
const Point3d & p2 = mesh->Point(seg[1]);
const Point3d p = Center (p1, p2);
glRasterPos3d (p.X(), p.Y(), p.Z());
2022-12-08 19:26:27 +05:00
snprintf (buf, size(buf), "%d", seg.edgenr);
2011-01-11 01:18:01 +05:00
glCallLists (strlen (buf), GL_UNSIGNED_BYTE, buf);
}
*/
const MeshTopology & top = mesh->GetTopology();
2011-01-15 01:50:12 +05:00
for (int i = 1; i <= top.GetNEdges(); i++)
2011-01-11 01:18:01 +05:00
{
2023-07-31 01:29:54 +05:00
// int v1, v2;
// top.GetEdgeVertices (i, v1, v2);
auto [v1,v2] = top.GetEdgeVertices(i-1);
2011-01-11 01:18:01 +05:00
const Point3d & p1 = mesh->Point(v1);
const Point3d & p2 = mesh->Point(v2);
const Point3d p = Center (p1, p2);
glRasterPos3d (p.X(), p.Y(), p.Z());
2022-12-08 19:26:27 +05:00
snprintf (buf, size(buf), "%d", i);
2011-01-11 01:18:01 +05:00
// glCallLists (strlen (buf), GL_UNSIGNED_BYTE, buf);
MyOpenGLText (buf);
}
}
if (vispar.drawsegmentnumbers)
{
for (auto si : Range(mesh->LineSegments())) {
const auto& seg = (*mesh)[si];
Point<3> c = Center((*mesh)[seg[0]], (*mesh)[seg[1]]);
glRasterPos3d (c[0], c[1], c[2]);
snprintf (buf, size(buf), "%d", int(si));
MyOpenGLText (buf);
}
}
2011-01-11 01:18:01 +05:00
if (vispar.drawfacenumbers)
2011-01-11 01:18:01 +05:00
{
const MeshTopology & top = mesh->GetTopology();
2019-07-09 13:39:16 +05:00
NgArray<int> v;
2011-01-15 01:50:12 +05:00
for (int i = 1; i <= top.GetNFaces(); i++)
2011-01-11 01:18:01 +05:00
{
top.GetFaceVertices (i, v);
const Point3d & p1 = mesh->Point(v.Elem(1));
const Point3d & p2 = mesh->Point(v.Elem(2));
const Point3d & p3 = mesh->Point(v.Elem(3));
Point3d p;
if (v.Elem(4) == 0)
{
2011-01-11 01:18:01 +05:00
p = Center (p1, p2, p3);
}
2011-01-11 01:18:01 +05:00
else
{
2011-01-11 01:18:01 +05:00
const Point3d & p4 = mesh->Point(v.Elem(4));
Point3d hp1 = Center (p1, p2);
Point3d hp2 = Center (p3, p4);
p = Center (hp1, hp2);
}
2011-01-11 01:18:01 +05:00
glRasterPos3d (p.X(), p.Y(), p.Z());
2022-12-08 19:26:27 +05:00
snprintf (buf, size(buf), "%d", i);
2011-01-11 01:18:01 +05:00
// glCallLists (strlen (buf), GL_UNSIGNED_BYTE, buf);
MyOpenGLText (buf);
}
}
if (vispar.drawsurfaceelementnumbers)
{
for (auto sei : Range(mesh->SurfaceElements()))
{
const auto & sel = (*mesh)[sei];
Point<3> c;
if(sel.GetNV() == 3)
c = Center((*mesh)[sel[0]],
(*mesh)[sel[1]],
(*mesh)[sel[2]]);
else
c = Center((*mesh)[sel[0]],
(*mesh)[sel[1]],
(*mesh)[sel[2]],
(*mesh)[sel[3]]);
glRasterPos3d (c[0], c[1], c[2]);
snprintf (buf, size(buf), "%d", int(sei));
MyOpenGLText (buf);
}
}
if (vispar.drawelementnumbers)
2011-01-11 01:18:01 +05:00
{
2019-07-09 13:39:16 +05:00
NgArray<int> v;
2011-01-15 01:50:12 +05:00
for (int i = 1; i <= mesh->GetNE(); i++)
2011-01-11 01:18:01 +05:00
{
// const ELEMENTTYPE & eltype = mesh->ElementType(i);
2019-07-09 13:39:16 +05:00
NgArray<int> pnums;
2011-01-11 01:18:01 +05:00
Point3d p;
const Element & el = mesh->VolumeElement (i);
2011-01-11 01:18:01 +05:00
if ( ! el.PNum(5)) // eltype == TET )
{
2011-01-11 01:18:01 +05:00
pnums.SetSize(4);
for( int j = 0; j < pnums.Size(); j++)
pnums[j] = mesh->VolumeElement(i).PNum(j+1);
2011-01-11 01:18:01 +05:00
const Point3d & p1 = mesh->Point(pnums[0]);
const Point3d & p2 = mesh->Point(pnums[1]);
const Point3d & p3 = mesh->Point(pnums[2]);
const Point3d & p4 = mesh->Point(pnums[3]);
p = Center (p1, p2, p3, p4);
}
2011-01-11 01:18:01 +05:00
else if ( ! el.PNum(6)) // eltype == PYRAMID
{
2011-01-11 01:18:01 +05:00
pnums.SetSize(5);
for( int j = 0; j < pnums.Size(); j++)
pnums[j] = mesh->VolumeElement(i).PNum(j+1);
2011-01-11 01:18:01 +05:00
const Point3d & p1 = mesh->Point(pnums[0]);
const Point3d & p2 = mesh->Point(pnums[1]);
const Point3d & p3 = mesh->Point(pnums[2]);
const Point3d & p4 = mesh->Point(pnums[3]);
const Point3d & p5 = mesh->Point(pnums[4]);
2011-01-11 01:18:01 +05:00
p.X() = 0.3 * p5.X() + 0.7 * Center ( Center(p1, p3) , Center(p2, p4) ) . X();
p.Y() = 0.3 * p5.Y() + 0.7 * Center ( Center(p1, p3) , Center(p2, p4) ) . Y();
p.Z() = 0.3 * p5.Z() + 0.7 * Center ( Center(p1, p3) , Center(p2, p4) ) . Z();
}
2011-01-11 01:18:01 +05:00
else if ( ! el.PNum(7) ) // eltype == PRISM
{
2011-01-11 01:18:01 +05:00
pnums.SetSize(6);
for( int j = 0; j < pnums.Size(); j++)
pnums[j] = mesh->VolumeElement(i).PNum(j+1);
const Point3d & p1 = mesh->Point(pnums[0]);
const Point3d & p2 = mesh->Point(pnums[1]);
const Point3d & p3 = mesh->Point(pnums[2]);
const Point3d & p11 = mesh->Point(pnums[3]);
const Point3d & p12 = mesh->Point(pnums[4]);
const Point3d & p13 = mesh->Point(pnums[5]);
p = Center ( Center (p1, p2, p3) , Center(p11, p12, p13) ) ;
}
2011-01-11 01:18:01 +05:00
else if (! el.PNum(9) ) // eltype == HEX
{
2011-01-11 01:18:01 +05:00
pnums.SetSize(8);
for( int j = 0; j < pnums.Size(); j++)
pnums[j] = mesh->VolumeElement(i).PNum(j+1);
const Point3d & p1 = mesh->Point(pnums[0]);
const Point3d & p2 = mesh->Point(pnums[1]);
const Point3d & p3 = mesh->Point(pnums[2]);
const Point3d & p4 = mesh->Point(pnums[3]);
const Point3d & p5 = mesh->Point(pnums[4]);
const Point3d & p6 = mesh->Point(pnums[5]);
const Point3d & p7 = mesh->Point(pnums[6]);
const Point3d & p8 = mesh->Point(pnums[7]);
p = Center ( Center ( Center(p1, p3), Center(p2, p4) ) , Center( Center(p5, p7) , Center(p6, p8 ) ) );
}
2011-01-11 01:18:01 +05:00
glRasterPos3d (p.X(), p.Y(), p.Z());
2022-12-08 19:26:27 +05:00
snprintf (buf, size(buf), "%d", i);
2011-01-11 01:18:01 +05:00
// glCallLists (strlen (buf), GL_UNSIGNED_BYTE, buf);
MyOpenGLText (buf);
2011-01-11 01:18:01 +05:00
}
}
2011-01-11 01:18:01 +05:00
glPopAttrib ();
// glDisable (GL_COLOR_MATERIAL);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glEndList ();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
badellist = glGenLists (1);
glNewList (badellist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.drawbadels)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
// SetClippingPlane ();
2011-01-11 01:18:01 +05:00
static float badelcol[] = { 1.0f, 0.0f, 1.0f, 1.0f };
glLineWidth (1.0f);
2011-01-15 01:50:12 +05:00
for (int i = 1; i <= mesh->GetNE(); i++)
2011-01-11 01:18:01 +05:00
{
if (mesh->VolumeElement(i).Flags().badel ||
mesh->VolumeElement(i).Flags().illegal ||
2011-01-11 01:18:01 +05:00
(i == vispar.drawelement))
{
// copy to be thread-safe
Element el = mesh->VolumeElement (i);
el.GetSurfaceTriangles (faces);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, badelcol);
// if ( (el.GetNP() == 4) || (el.GetNP() == 10))
if (el.PNum(1))
{
glBegin (GL_TRIANGLES);
2011-01-15 01:50:12 +05:00
for (int j = 1; j <= faces.Size(); j++)
2011-01-11 01:18:01 +05:00
{
Element2d & face = faces.Elem(j);
const Point3d & lp1 = mesh->Point (el.PNum(face.PNum(1)));
const Point3d & lp2 = mesh->Point (el.PNum(face.PNum(2)));
const Point3d & lp3 = mesh->Point (el.PNum(face.PNum(3)));
Vec3d n = Cross (Vec3d (lp1, lp2), Vec3d (lp1, lp3));
n /= (n.Length()+1e-12);
glNormal3d (n.X(), n.Y(), n.Z());
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
}
glEnd();
}
}
}
2016-12-12 00:17:07 +05:00
for (ElementIndex ei : mesh->VolumeElements().Range())
2011-01-11 01:18:01 +05:00
{
if ((*mesh)[ei].Flags().badel)
2011-01-11 01:18:01 +05:00
{
// copy to be thread-safe
2019-08-09 03:23:12 +05:00
Element el = (*mesh)[ei];
2011-01-11 01:18:01 +05:00
if ( (el.GetNP() == 4) || (el.GetNP() == 10))
{
glBegin (GL_LINES);
glVertex3d (0,0,0);
const Point3d & p = mesh->Point(el.PNum(1));
glVertex3d (p.X(), p.Y(), p.Z());
glEnd();
}
}
}
2011-01-15 01:50:12 +05:00
for (int i = 1; i <= mesh->GetNE(); i++)
2011-01-11 01:18:01 +05:00
{
Element el = mesh->VolumeElement (i);
int hascp = 0;
2011-01-15 01:50:12 +05:00
for (int j = 1; j <= el.GetNP(); j++)
2011-01-11 01:18:01 +05:00
if (el.PNum(j) == vispar.centerpoint)
hascp = 1;
if (hascp)
2011-01-11 01:18:01 +05:00
{
(*testout) << "draw el " << i << " : ";
2011-01-15 01:50:12 +05:00
for (int j = 1; j <= el.GetNP(); j++)
(*testout) << el.PNum(j) << " ";
2011-01-11 01:18:01 +05:00
(*testout) << endl;
if (el.GetNP() == 4)
{
int et[6][2] =
{ { 1, 2 },
{ 1, 3 },
{ 1, 4 },
{ 2, 3 },
{ 2, 4 },
{ 3, 4 } } ;
2011-01-15 01:50:12 +05:00
for (int j = 0; j < 6; j++)
2011-01-11 01:18:01 +05:00
{
glBegin (GL_LINES);
const Point3d & p1 = mesh->Point (el.PNum(et[j][0]));
const Point3d & p2 = mesh->Point (el.PNum(et[j][1]));
glVertex3d (p1.X(), p1.Y(), p1.Z());
glVertex3d (p2.X(), p2.Y(), p2.Z());
glEnd ();
}
}
if (el.GetNP() == 10)
{
int et[12][2] =
{ { 1, 5 },
{ 2, 5 },
{ 1, 6 },
{ 3, 6 },
{ 1, 7 },
{ 4, 7 },
{ 2, 8 },
{ 3, 8 },
{ 2, 9 },
{ 4, 9 },
{ 3, 10 },
{ 4, 10 } };
2011-01-15 01:50:12 +05:00
for (int j = 0; j < 12; j++)
2011-01-11 01:18:01 +05:00
{
glBegin (GL_LINES);
const Point3d & p1 = mesh->Point (el.PNum(et[j][0]));
const Point3d & p2 = mesh->Point (el.PNum(et[j][1]));
glVertex3d (p1.X(), p1.Y(), p1.Z());
glVertex3d (p2.X(), p2.Y(), p2.Z());
glEnd ();
}
}
}
}
2016-12-12 00:17:07 +05:00
for (SurfaceElementIndex sei : mesh->SurfaceElements().Range())
2011-01-11 01:18:01 +05:00
{
2019-08-09 03:23:12 +05:00
Element2d el = (*mesh)[sei]; // copy to be thread-safe
if (!el.BadElement())
2011-01-11 01:18:01 +05:00
continue;
2019-08-09 03:23:12 +05:00
if (el.IsDeleted()) continue;
2016-12-12 00:17:07 +05:00
bool drawel = true;
2011-01-15 01:50:12 +05:00
for (int j = 1; j <= el.GetNP(); j++)
2016-12-12 00:17:07 +05:00
if (!el.PNum(j).IsValid())
drawel = false;
if (!drawel)
2011-01-11 01:18:01 +05:00
continue;
2011-10-13 02:57:49 +06:00
// cout << int (el.GetType()) << " " << flush;
switch (el.GetType())
2011-01-11 01:18:01 +05:00
{
case TRIG:
{
glBegin (GL_TRIANGLES);
Point3d lp1 = mesh->Point (el.PNum(1));
Point3d lp2 = mesh->Point (el.PNum(2));
Point3d lp3 = mesh->Point (el.PNum(3));
Vec3d n = Cross (Vec3d (lp1, lp2), Vec3d (lp1, lp3));
n /= (n.Length() + 1e-12);
glNormal3dv (&n.X());
glVertex3dv (&lp1.X());
glVertex3dv (&lp2.X());
glVertex3dv (&lp3.X());
glEnd();
break;
2011-01-11 01:18:01 +05:00
}
case QUAD:
{
glBegin (GL_QUADS);
const Point3d & lp1 = mesh->Point (el.PNum(1));
const Point3d & lp2 = mesh->Point (el.PNum(2));
const Point3d & lp3 = mesh->Point (el.PNum(4));
const Point3d & lp4 = mesh->Point (el.PNum(3));
Vec3d n = Cross (Vec3d (lp1, lp2),
2011-01-11 01:18:01 +05:00
Vec3d (lp1, Center (lp3, lp4)));
n /= (n.Length() + 1e-12);
glNormal3d (n.X(), n.Y(), n.Z());
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp4.X(), lp4.Y(), lp4.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
glEnd();
break;
2011-01-11 01:18:01 +05:00
}
case TRIG6:
{
int lines[6][2] = {
2011-01-11 01:18:01 +05:00
{ 1, 6 }, { 2, 6 },
{ 1, 5 }, { 3, 5 },
{ 2, 4 }, { 3, 4 } };
glBegin (GL_LINES);
2011-01-15 01:50:12 +05:00
for (int j = 0; j < 6; j++)
2011-01-11 01:18:01 +05:00
{
glVertex3dv ( mesh->Point (el.PNum(lines[j][0])) );
glVertex3dv ( mesh->Point (el.PNum(lines[j][0])) );
}
glEnd();
break;
}
case QUAD6:
{
int lines[6][2] = {
2011-01-11 01:18:01 +05:00
{ 1, 5 }, { 2, 5 },
{ 3, 6 }, { 4, 6 },
{ 1, 4 }, { 2, 3 } };
glBegin (GL_LINES);
2011-01-15 01:50:12 +05:00
for (int j = 0; j < 6; j++)
2011-01-11 01:18:01 +05:00
{
const Point3d & lp1 = mesh->Point (el.PNum(lines[j][0]));
const Point3d & lp2 = mesh->Point (el.PNum(lines[j][1]));
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
}
glEnd ();
break;
}
default:
PrintSysError ("Cannot draw surface element of type ",
int(el.GetType()));
}
}
glLoadName (0);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glEndList ();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (1)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
identifiedlist = glGenLists (1);
glNewList (identifiedlist, GL_COMPILE);
2011-01-11 01:18:01 +05:00
GLfloat identifiedcol[] = { 1, 0, 1, 1 };
2011-01-11 01:18:01 +05:00
glLineWidth (3);
2011-01-11 01:18:01 +05:00
// for (i = 1; i <= mesh->GetNSeg(); i++)
2009-01-13 04:40:13 +05:00
2016-02-23 22:22:00 +05:00
if (mesh -> HasIdentifications() )
2011-01-11 01:18:01 +05:00
{
2018-04-28 06:42:04 +05:00
// if (mesh->GetIdentifications().HasIdentifiedPoints())
2011-01-11 01:18:01 +05:00
{
auto & idpts =
2016-02-23 22:22:00 +05:00
mesh->GetIdentifications().GetIdentifiedPoints();
2011-01-15 01:50:12 +05:00
for (int i = 1; i <= idpts.GetNBags(); i++)
for (int j = 1; j <= idpts.GetBagSize(i); j++)
2011-01-11 01:18:01 +05:00
{
INDEX_3 pts;
int dummy, val;
idpts.GetData (i, j, pts, dummy);
val = pts[2];
2011-01-11 01:18:01 +05:00
const Point3d & p1 = mesh->Point(pts.I1());
const Point3d & p2 = mesh->Point(pts.I2());
2011-01-11 01:18:01 +05:00
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
identifiedcol);
2011-01-11 01:18:01 +05:00
glBegin (GL_LINES);
glVertex3f (p1.X(), p1.Y(), p1.Z());
glVertex3f (p2.X(), p2.Y(), p2.Z());
glEnd();
}
}
}
2011-01-11 01:18:01 +05:00
glEndList ();
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
if (lock)
{
2011-01-11 01:18:01 +05:00
lock -> UnLock();
delete lock;
lock = NULL;
}
2011-01-11 01:18:01 +05:00
vstimestamp = meshtimestamp;
2014-10-06 15:57:44 +06:00
}
catch (bad_weak_ptr e)
{
2017-01-01 19:34:38 +05:00
PrintMessage (3, "vsmesh::buildscene: don't have a mesh to visualize");
2014-10-06 15:57:44 +06:00
VisualScene::BuildScene (zoomall);
}
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
void VisualSceneMesh :: BuildColorTexture ()
{
shared_ptr<Mesh> mesh = GetMesh();
if(colors.texture == -1)
glGenTextures(1, &colors.texture);
// build color texture
glBindTexture(GL_TEXTURE_2D, colors.texture);
Array<float> data;
for(auto fdi : Range(1, mesh->GetNFD()+1))
{
auto c = mesh->GetFaceDescriptor(fdi).SurfColour();
ArrayMem<float, 4> cf{float(c[0]), float(c[1]), float(c[2]), float(c[3])};
if(fdi==selface)
cf = {1.0f, 0.0f, 0.0f, 1.0f};
data.Append(cf);
}
int n = data.Size()/4;
colors.width = max2(1,min2(n, 1024));
colors.height = (n+colors.width-1)/colors.width;
2023-08-05 15:01:01 +05:00
for([[maybe_unused]] auto i: Range(n, colors.width*colors.height))
data.Append({0.0f, 0.0f, 0.0f, 0.0f});
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, colors.width, colors.height, 0, GL_RGBA, GL_FLOAT, data.Data());
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
2009-01-13 04:40:13 +05:00
2023-03-29 23:30:21 +05:00
void VisualSceneMesh :: BuildFilledList (bool build_select)
2011-01-11 01:18:01 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
static int timer = NgProfiler::CreateTimer ("Mesh::BuildFilledList");
NgProfiler::RegionTimer reg (timer);
2023-03-29 23:30:21 +05:00
auto & list = build_select ? select.list : filledlist;
auto & timestamp = build_select ? select.list_timestamp : filledtimestamp;
if (list && timestamp > max(mesh->GetTimeStamp(), subdivision_timestamp))
return;
2009-01-13 04:40:13 +05:00
#ifdef PARALLELGL
2011-01-11 01:18:01 +05:00
if (id == 0 && ntasks > 1)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
InitParallelGL();
par_filledlists.SetSize (ntasks);
2009-01-13 04:40:13 +05:00
2011-07-15 03:36:19 +06:00
MyMPI_SendCmd ("redraw");
MyMPI_SendCmd ("filledlist");
2011-01-11 01:18:01 +05:00
for ( int dest = 1; dest < ntasks; dest++ )
2011-11-15 00:16:40 +06:00
MyMPI_Recv (par_filledlists[dest], dest, MPI_TAG_VIS);
2009-01-13 04:40:13 +05:00
2023-03-29 23:30:21 +05:00
if (list)
glDeleteLists (list, 1);
2009-01-13 04:40:13 +05:00
2023-03-29 23:30:21 +05:00
list = glGenLists (1);
glNewList (list, GL_COMPILE);
2011-01-11 01:18:01 +05:00
for ( int dest = 1; dest < ntasks; dest++ )
glCallList (par_filledlists[dest]);
2011-01-11 01:18:01 +05:00
glEndList();
2009-01-13 04:40:13 +05:00
2023-03-29 23:30:21 +05:00
timestamp = NextTimeStamp();
2011-01-11 01:18:01 +05:00
return;
2009-01-13 04:40:13 +05:00
}
#endif
2011-01-11 01:18:01 +05:00
if (!lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
2009-01-13 04:40:13 +05:00
}
2023-03-29 23:30:21 +05:00
timestamp = NextTimeStamp();
2009-01-13 04:40:13 +05:00
if(!build_select && !vispar.colormeshsize)
BuildColorTexture();
2023-03-29 23:30:21 +05:00
if (list)
glDeleteLists (list, 1);
2023-03-29 23:30:21 +05:00
list = glGenLists (1);
glNewList (list, GL_COMPILE);
2009-01-13 04:40:13 +05:00
glBindTexture(GL_TEXTURE_2D, colors.texture);
2011-01-11 01:18:01 +05:00
#ifdef STLGEOM
STLGeometry * stlgeometry = dynamic_cast<STLGeometry*> (ng_geometry);
bool checkvicinity = (stlgeometry != NULL) && stldoctor.showvicinity;
#endif
glEnable (GL_NORMALIZE);
2011-01-11 01:18:01 +05:00
glLineWidth (1.0f);
2011-01-11 01:18:01 +05:00
Vector locms;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.colormeshsize)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
glEnable (GL_COLOR_MATERIAL);
glShadeModel (GL_SMOOTH);
locms.SetSize (mesh->GetNP());
maxh = -1;
minh = 1e99;
for (int i = 1; i <= locms.Size(); i++)
{
Point3d p = mesh->Point(i);
locms(i-1) = mesh->GetH (p);
if (locms(i-1) > maxh) maxh = locms(i-1);
if (locms(i-1) < minh) minh = locms(i-1);
2011-01-11 01:18:01 +05:00
}
if (!locms.Size())
{
minh = 1;
maxh = 10;
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
}
else if (build_select)
2023-03-29 23:30:21 +05:00
{
glDisable(GL_TEXTURE_1D);
2023-03-29 23:30:21 +05:00
glDisable(GL_TEXTURE_2D);
glDisable(GL_FOG);
glDisable(GL_LIGHTING);
glDisable (GL_COLOR_MATERIAL);
}
else
{
glDisable(GL_TEXTURE_1D);
glEnable(GL_TEXTURE_2D);
glEnable (GL_COLOR_MATERIAL);
glBindTexture(GL_TEXTURE_2D, colors.texture);
}
2009-01-13 04:40:13 +05:00
2023-08-05 15:01:01 +05:00
// GLfloat matcol[] = { 0, 1, 0, 1 };
// GLfloat matcolsel[] = { 1, 0, 0, 1 };
2009-01-13 04:40:13 +05:00
2011-01-15 01:50:12 +05:00
GLint rendermode;
glGetIntegerv (GL_RENDER_MODE, &rendermode);
2011-01-11 01:18:01 +05:00
CurvedElements & curv = mesh->GetCurvedElements();
2011-01-15 01:50:12 +05:00
2023-03-29 23:30:21 +05:00
int hoplotn = 1 << subdivisions;
2011-01-15 01:50:12 +05:00
Array<SurfaceElementIndex> seia;
2009-01-13 04:40:13 +05:00
2011-01-15 01:50:12 +05:00
for (int faceindex = 1; faceindex <= mesh->GetNFD(); faceindex++)
2009-01-13 04:40:13 +05:00
{
2011-01-15 01:50:12 +05:00
mesh->GetSurfaceElementsOfFace (faceindex, seia);
if(!build_select && !vispar.colormeshsize)
2023-03-29 23:30:21 +05:00
{
int i = faceindex-1;
float x = (0.5+i%colors.width)/colors.width;
float y = (0.5+i/colors.width)/colors.height;
glTexCoord2f(x,y);
2023-03-29 23:30:21 +05:00
}
2011-01-15 01:50:12 +05:00
2019-10-10 10:38:10 +05:00
static Point<3> xa[129];
static Vec<3> na[129];
2009-01-13 04:40:13 +05:00
2019-10-10 10:38:10 +05:00
2011-01-15 01:50:12 +05:00
for (int hi = 0; hi < seia.Size(); hi++)
{
SurfaceElementIndex sei = seia[hi];
const Element2d & el = (*mesh)[sei];
2009-01-13 04:40:13 +05:00
2023-08-05 15:01:01 +05:00
bool drawel = (!el.IsDeleted() && el.IsVisible());
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
#ifdef STLGEOM
if (checkvicinity)
2011-01-11 01:18:01 +05:00
for (int j = 0; j < el.GetNP(); j++)
if (!stlgeometry->Vicinity(el.GeomInfoPi(j+1).trignum))
drawel = 0;
#endif
2009-01-13 04:40:13 +05:00
if (!drawel)
2011-01-11 01:18:01 +05:00
continue;
2011-01-15 01:50:12 +05:00
2023-03-29 23:30:21 +05:00
if (build_select)
{
GLushort r,g,b;
r = (sei+1) % (1<<16);
g = (sei+1) >> 16;
b = 0;
glColor3us(r,g,b);
}
2009-01-13 04:40:13 +05:00
switch (el.GetType())
2011-01-11 01:18:01 +05:00
{
case TRIG:
{
if (curv.IsHighOrder()) // && curv.IsSurfaceElementCurved(sei))
2011-01-11 01:18:01 +05:00
{
if (hoplotn > 128) hoplotn = 128;
for (int i = 0; i < hoplotn; i++)
{
glBegin (GL_TRIANGLE_STRIP);
for (int j = 0; j <= hoplotn-i; j++)
for (int k = 0; k < 2; k++)
{
if (j == hoplotn-i && k == 1) continue;
if (i > 0 && k == 0)
{
glNormal3dv (na[j]);
glVertex3dv (xa[j]);
continue;
}
Point<2> xref (double(j) / hoplotn, double(i+k) / hoplotn);
Point<3> xglob;
Mat<3,2> dxdxi;
Vec<3> dx, dy, n;
curv.CalcSurfaceTransformation (xref, sei, xglob, dxdxi);
for (int i = 0; i < 3; i++)
{
dx(i) = dxdxi(i,0);
dy(i) = dxdxi(i,1);
}
n = Cross (dx, dy);
glNormal3dv (n);
glVertex3dv (xglob);
if (k == 1)
{
na[j] = n;
xa[j] = xglob;
}
}
glEnd();
}
}
else // not high order
{
2011-11-15 00:16:40 +06:00
glBegin (GL_TRIANGLES);
const Point<3> & lp0 = (*mesh) [el[0]];
const Point<3> & lp1 = (*mesh) [el[1]];
const Point<3> & lp2 = (*mesh) [el[2]];
2011-11-15 00:16:40 +06:00
Vec<3> n = Cross (lp1-lp0, lp2-lp0).Normalize();
glNormal3dv (n);
2011-11-15 00:16:40 +06:00
for (int j = 0; j < 3; j++)
{
2011-11-15 00:16:40 +06:00
if (vispar.colormeshsize)
SetOpenGlColor (locms(el[0]-1), minh, maxh, 0);
glVertex3dv ( (*mesh)[el[j]] );
}
2011-11-15 00:16:40 +06:00
glEnd();
}
break;
2011-01-11 01:18:01 +05:00
}
case QUAD:
{
if (curv.IsHighOrder()) // && curv.IsSurfaceElementCurved(sei))
2011-01-11 01:18:01 +05:00
{
Point<2> xr[4];
Point<3> xg;
Vec<3> dx, dy, n;
2011-01-11 01:18:01 +05:00
glBegin (GL_QUADS);
2011-01-11 01:18:01 +05:00
for (int i = 0; i < hoplotn; i++)
for (int j = 0; j < hoplotn; j++)
2011-01-11 01:18:01 +05:00
{
xr[0](0) = (double) i/hoplotn; xr[0](1) = (double) j/hoplotn;
xr[1](0) = (double)(i+1)/hoplotn; xr[1](1) = (double) j/hoplotn;
xr[2](0) = (double)(i+1)/hoplotn; xr[2](1) = (double)(j+1)/hoplotn;
xr[3](0) = (double) i/hoplotn; xr[3](1) = (double)(j+1)/hoplotn;
for (int l=0; l<4; l++)
{
Mat<3,2> dxdxi;
curv.CalcSurfaceTransformation (xr[l], sei, xg, dxdxi);
for (int i = 0; i < 3; i++)
{
dx(i) = dxdxi(i,0);
dy(i) = dxdxi(i,1);
}
n = Cross (dx, dy);
n.Normalize();
glNormal3d (n(0), n(1), n(2));
glVertex3d (xg(0), xg(1), xg(2));
}
}
glEnd();
}
else // not high order
2011-01-11 01:18:01 +05:00
{
glBegin (GL_QUADS);
2011-01-11 01:18:01 +05:00
const Point<3> & lp1 = mesh->Point (el.PNum(1));
const Point<3> & lp2 = mesh->Point (el.PNum(2));
const Point<3> & lp3 = mesh->Point (el.PNum(4));
const Point<3> & lp4 = mesh->Point (el.PNum(3));
2011-01-11 01:18:01 +05:00
Vec<3> n = Cross (lp2-lp1, Center (lp3, lp4)-lp1);
n.Normalize();
glNormal3dv (n);
2011-01-11 01:18:01 +05:00
glVertex3dv (lp1);
glVertex3dv (lp2);
glVertex3dv (lp4);
glVertex3dv (lp3);
2011-01-11 01:18:01 +05:00
glEnd ();
}
break;
2011-01-11 01:18:01 +05:00
}
2011-01-11 01:18:01 +05:00
case TRIG6:
{
glBegin (GL_TRIANGLES);
static int trigs[4][3] = {
2011-01-11 01:18:01 +05:00
{ 1, 6, 5 },
{ 2, 4, 6 },
{ 3, 5, 4 },
{ 4, 5, 6 } };
for (int j = 0; j < 4; j++)
{
const Point<3> & lp1 = mesh->Point (el.PNum(trigs[j][0]));
const Point<3> & lp2 = mesh->Point (el.PNum(trigs[j][1]));
const Point<3> & lp3 = mesh->Point (el.PNum(trigs[j][2]));
// Vec3d n = Cross (Vec3d (lp1, lp2), Vec3d (lp1, lp3));
Vec<3> n = Cross (lp2-lp1, lp3-lp1);
glNormal3dv (n);
glVertex3dv (lp1);
glVertex3dv (lp2);
glVertex3dv (lp3);
}
glEnd();
break;
}
case QUAD6:
{
glBegin (GL_QUADS);
static int quads[2][4] = {
2011-01-11 01:18:01 +05:00
{ 1, 5, 6, 4 },
{ 5, 2, 3, 6 } };
for (int j = 0; j < 2; j++)
{
Point3d lp1 = mesh->Point (el.PNum(quads[j][0]));
Point3d lp2 = mesh->Point (el.PNum(quads[j][1]));
Point3d lp3 = mesh->Point (el.PNum(quads[j][2]));
Point3d lp4 = mesh->Point (el.PNum(quads[j][3]));
Vec3d n = Cross (Vec3d (lp1, lp2), Vec3d (lp1, lp3));
n /= (n.Length() + 1e-12);
glNormal3dv (&n.X());
glVertex3dv (&lp1.X());
glVertex3dv (&lp2.X());
glVertex3dv (&lp3.X());
glVertex3dv (&lp4.X());
}
glEnd();
break;
}
case QUAD8:
{
glBegin (GL_TRIANGLES);
static int boundary[] =
2011-01-11 01:18:01 +05:00
{ 1, 5, 2, 8, 3, 6, 4, 7, 1 };
Point3d c(0,0,0);
for (int j = 0; j < 4; j++)
2011-01-11 01:18:01 +05:00
{
const Point3d & hp = mesh->Point (el[j]);
c.X() -= 0.25 * hp.X();
c.Y() -= 0.25 * hp.Y();
c.Z() -= 0.25 * hp.Z();
}
for (int j = 4; j < 8; j++)
2011-01-11 01:18:01 +05:00
{
const Point3d & hp = mesh->Point (el[j]);
c.X() += 0.5 * hp.X();
c.Y() += 0.5 * hp.Y();
c.Z() += 0.5 * hp.Z();
}
for (int j = 0; j < 8; j++)
2011-01-11 01:18:01 +05:00
{
Point3d lp1 = mesh->Point (el.PNum(boundary[j]));
Point3d lp2 = mesh->Point (el.PNum(boundary[j+1]));
Vec3d n = Cross (Vec3d (c, lp1), Vec3d (c, lp2));
n /= (n.Length() + 1e-12);
glNormal3dv (&n.X());
glVertex3dv (&lp1.X());
glVertex3dv (&lp2.X());
glVertex3dv (&c.X());
}
glEnd();
break;
2011-01-11 01:18:01 +05:00
}
2011-01-11 01:18:01 +05:00
default:
PrintSysError ("Cannot draw (2) surface element of type ",
int(el.GetType()));
}
2011-01-15 01:50:12 +05:00
2011-01-15 01:50:12 +05:00
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
}
2011-01-15 01:50:12 +05:00
2011-01-11 01:18:01 +05:00
glLoadName (0);
glBindTexture(GL_TEXTURE_2D, 0);
2011-01-11 01:18:01 +05:00
glEndList ();
2009-01-13 04:40:13 +05:00
#ifdef PARALLELGL
2011-01-11 01:18:01 +05:00
glFinish();
if (id > 0)
2023-03-29 23:30:21 +05:00
MyMPI_Send (list, 0, MPI_TAG_VIS);
2009-01-13 04:40:13 +05:00
#endif
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: BuildLineList()
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
if (linetimestamp > max(mesh->GetTimeStamp (), subdivision_timestamp))
return;
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
static int timer = NgProfiler::CreateTimer ("Mesh::BuildLineList");
NgProfiler::RegionTimer reg (timer);
2009-01-13 04:40:13 +05:00
#ifdef PARALLELGL
2011-01-11 01:18:01 +05:00
if (id == 0 && ntasks > 1)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
InitParallelGL();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
par_linelists.SetSize (ntasks);
2009-01-13 04:40:13 +05:00
2011-07-15 03:36:19 +06:00
MyMPI_SendCmd ("redraw");
MyMPI_SendCmd ("linelist");
2011-01-11 01:18:01 +05:00
for ( int dest = 1; dest < ntasks; dest++ )
2011-07-07 03:08:58 +06:00
MyMPI_Recv (par_linelists[dest], dest, MPI_TAG_VIS);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (linelist)
glDeleteLists (linelist, 1);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
linelist = glGenLists (1);
glNewList (linelist, GL_COMPILE);
2011-01-11 01:18:01 +05:00
for ( int dest = 1; dest < ntasks; dest++ )
glCallList (par_linelists[dest]);
2011-01-11 01:18:01 +05:00
glEndList();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
linetimestamp = NextTimeStamp();
return;
2009-01-13 04:40:13 +05:00
}
#endif
2011-01-11 01:18:01 +05:00
if (!lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
linetimestamp = NextTimeStamp();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
#ifdef STLGEOM
STLGeometry * stlgeometry = dynamic_cast<STLGeometry*> (ng_geometry);
bool checkvicinity = (stlgeometry != NULL) && stldoctor.showvicinity;
#endif
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (linelist)
glDeleteLists (linelist, 1);
2011-01-11 01:18:01 +05:00
linelist = glGenLists (1);
glNewList (linelist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
// cout << "linelist = " << linelist << endl;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glLineWidth (1.0f);
2009-01-13 04:40:13 +05:00
2023-03-29 23:30:21 +05:00
int hoplotn = 1 << subdivisions;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
// PrintMessage (3, "nse = ", mesh->GetNSE());
for (SurfaceElementIndex sei = 0; sei < mesh->GetNSE(); sei++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
const Element2d & el = (*mesh)[sei];
2023-08-05 15:01:01 +05:00
bool drawel = (!el.IsDeleted() && el.IsVisible());
2011-01-11 01:18:01 +05:00
#ifdef STLGEOM
if (checkvicinity)
for (int j = 0; j < el.GetNP(); j++)
if (!stlgeometry->Vicinity(el.GeomInfoPi(j+1).trignum))
drawel = 0;
#endif
2011-01-11 01:18:01 +05:00
if (!drawel)
continue;
2011-01-11 01:18:01 +05:00
switch (el.GetType())
{
case TRIG:
{
2011-01-11 01:18:01 +05:00
CurvedElements & curv = mesh->GetCurvedElements();
if (curv.IsHighOrder()) // && curv.IsSurfaceElementCurved(sei))
{
Point<3> xg;
glBegin (GL_LINE_LOOP);
for (int i = 0; i < hoplotn; i++)
2011-01-11 01:18:01 +05:00
{
Point<2> xr (double(i) / hoplotn, 0);
curv.CalcSurfaceTransformation (xr, sei, xg);
glVertex3dv (xg);
}
for (int i = 0; i < hoplotn; i++)
2011-01-11 01:18:01 +05:00
{
Point<2> xr (double(hoplotn-i) / hoplotn, double(i)/hoplotn);
curv.CalcSurfaceTransformation (xr, sei, xg);
glVertex3dv (xg);
}
for (int i = 0; i < hoplotn; i++)
2011-01-11 01:18:01 +05:00
{
Point<2> xr (0, double(hoplotn-i) / hoplotn);
curv.CalcSurfaceTransformation (xr, sei, xg);
glVertex3dv (xg);
}
glEnd();
2011-01-11 01:18:01 +05:00
}
else
{
glBegin (GL_TRIANGLES);
2011-11-15 00:16:40 +06:00
for (int j = 0; j < 3; j++)
glVertex3dv ( (*mesh) [el[j]] );
/*
const Point<3> & lp0 = (*mesh) [el[0]];
const Point<3> & lp1 = (*mesh) [el[1]];
const Point<3> & lp2 = (*mesh) [el[2]];
glVertex3dv (lp0);
glVertex3dv (lp1);
glVertex3dv (lp2);
2011-11-15 00:16:40 +06:00
*/
glEnd();
2011-01-11 01:18:01 +05:00
}
2011-01-11 01:18:01 +05:00
break;
}
2011-01-11 01:18:01 +05:00
case QUAD:
{
2011-01-11 01:18:01 +05:00
CurvedElements & curv = mesh->GetCurvedElements();
if (curv.IsHighOrder()) // && curv.IsSurfaceElementCurved(sei))
{
Point<2> xr;
Point<3> xg;
glBegin (GL_LINE_STRIP);
for (int side = 0; side < 4; side++)
2011-01-11 01:18:01 +05:00
{
for (int i = 0; i <= hoplotn; i++)
{
switch (side)
{
case 0:
xr(0) = (double) i/hoplotn;
xr(1) = 0.;
break;
case 1:
xr(0) = 1.;
xr(1) = (double) i/hoplotn;
break;
case 2:
xr(0) = (double) (hoplotn-i)/hoplotn;
xr(1) = 1.;
break;
case 3:
xr(0) = 0.;
xr(1) = (double) (hoplotn-i)/hoplotn;
break;
}
curv.CalcSurfaceTransformation (xr, sei, xg);
glVertex3d (xg(0), xg(1), xg(2));
2011-01-11 01:18:01 +05:00
}
}
glEnd();
2011-01-11 01:18:01 +05:00
} else {
2011-01-11 01:18:01 +05:00
glBegin (GL_QUADS);
2011-01-11 01:18:01 +05:00
const Point3d & lp1 = mesh->Point (el.PNum(1));
const Point3d & lp2 = mesh->Point (el.PNum(2));
const Point3d & lp3 = mesh->Point (el.PNum(4));
const Point3d & lp4 = mesh->Point (el.PNum(3));
Vec3d n = Cross (Vec3d (lp1, lp2),
Vec3d (lp1, Center (lp3, lp4)));
glNormal3d (n.X(), n.Y(), n.Z());
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp4.X(), lp4.Y(), lp4.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
glEnd();
2011-01-11 01:18:01 +05:00
}
2011-01-11 01:18:01 +05:00
break;
}
2011-01-11 01:18:01 +05:00
case TRIG6:
{
2011-01-11 01:18:01 +05:00
int lines[6][2] = {
{ 1, 6 }, { 2, 6 },
{ 1, 5 }, { 3, 5 },
{ 2, 4 }, { 3, 4 } };
glBegin (GL_LINES);
for (int j = 0; j < 6; j++)
{
const Point3d & lp1 = mesh->Point (el.PNum(lines[j][0]));
const Point3d & lp2 = mesh->Point (el.PNum(lines[j][1]));
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
}
glEnd();
break;
}
2011-01-11 01:18:01 +05:00
case QUAD6:
{
2011-01-11 01:18:01 +05:00
int lines[6][2] = {
{ 1, 5 }, { 2, 5 },
{ 3, 6 }, { 4, 6 },
{ 1, 4 }, { 2, 3 } };
glBegin (GL_LINES);
for (int j = 0; j < 6; j++)
{
const Point3d & lp1 = mesh->Point (el.PNum(lines[j][0]));
const Point3d & lp2 = mesh->Point (el.PNum(lines[j][1]));
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
}
glEnd ();
break;
}
2011-01-11 01:18:01 +05:00
case QUAD8:
{
2011-01-11 01:18:01 +05:00
int lines[8][2] = {
{ 1, 5 }, { 2, 5 }, { 3, 6 }, { 4, 6 },
{ 1, 7 }, { 4, 7 }, { 2, 8 }, { 3, 8 }
};
2011-01-11 01:18:01 +05:00
glBegin (GL_LINES);
2011-01-11 01:18:01 +05:00
for (int j = 0; j < 8; j++)
{
const Point3d & lp1 = mesh->Point (el.PNum(lines[j][0]));
const Point3d & lp2 = mesh->Point (el.PNum(lines[j][1]));
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
2011-01-11 01:18:01 +05:00
}
glEnd ();
break;
}
2011-01-11 01:18:01 +05:00
default:
PrintSysError ("Cannot draw (4) surface element of type ",
2011-01-11 01:18:01 +05:00
int(el.GetType()));
}
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glEndList ();
2009-01-13 04:40:13 +05:00
2009-01-13 04:40:13 +05:00
#ifdef PARALLELGL
2011-01-11 01:18:01 +05:00
glFinish();
if (id > 0)
2011-07-07 03:08:58 +06:00
MyMPI_Send (linelist, 0, MPI_TAG_VIS);
2009-01-13 04:40:13 +05:00
#endif
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: BuildEdgeList()
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
if (!lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
2009-01-13 04:40:13 +05:00
}
if (edgetimestamp > max(mesh->GetTimeStamp(), subdivision_timestamp) && vispar.drawtetsdomain == 0
2014-04-28 12:53:37 +06:00
&& vispar.shrink == 1)
2011-01-11 01:18:01 +05:00
return;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
edgetimestamp = NextTimeStamp();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (edgelist)
glDeleteLists (edgelist, 1);
2011-01-11 01:18:01 +05:00
edgelist = glGenLists (1);
glNewList (edgelist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
GLfloat matcoledge[] = { 0, 0, 1, 1 };
GLfloat matcolsingedge[] = { 1, 0, 1, 1 };
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glEnable (GL_POLYGON_OFFSET_LINE);
glPolygonOffset (1, -1);
2011-01-11 01:18:01 +05:00
glEnable (GL_COLOR_MATERIAL);
glDisable (GL_LIGHTING);
2011-01-11 01:18:01 +05:00
for (int i = 1; i <= mesh->GetNSeg(); i++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
const Segment & seg = mesh->LineSegment(i);
2014-04-28 12:53:37 +06:00
/*
2014-04-28 12:53:37 +06:00
#ifdef PARALLEL
if (ntasks > 1 &&
vispar.drawtetsdomain &&
// (vispar.drawtetsdomain != seg.GetPartition())) continue;
(vispar.drawtetsdomain != mesh->seg_partition[i-1]) continue;
2014-04-28 12:53:37 +06:00
#endif
*/
2011-01-11 01:18:01 +05:00
const Point3d & p1 = (*mesh)[seg[0]];
const Point3d & p2 = (*mesh)[seg[1]];
if (seg.singedge_left || seg.singedge_right)
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
matcolsingedge);
else
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
matcoledge);
if (seg.singedge_left || seg.singedge_right)
glColor3fv (matcolsingedge);
else
glColor3fv (matcoledge);
if (seg.edgenr == seledge)
glLineWidth(5);
else
glLineWidth(2);
if (mesh->GetCurvedElements().IsHighOrder())
{
2023-03-29 23:30:21 +05:00
int hoplotn = 1 << subdivisions;
// mesh->GetCurvedElements().GetNVisualSubsecs();
Point<3> x;
glBegin (GL_LINE_STRIP);
for (int j = 0; j <= hoplotn; j++)
2011-01-11 01:18:01 +05:00
{
mesh->GetCurvedElements().CalcSegmentTransformation ((double) j/hoplotn, i-1, x);
glVertex3d (x(0), x(1), x(2));
/*
cout << "x = " << x(0) << ", " << x(1) << ", " << x(2)
<< ", norm = 1+" << sqrt(x(0)*x(0)+x(1)*x(1))-1
<< ", phi = " << atan2(x(1), x(0))/M_PI << endl;
*/
}
glEnd();
2011-01-11 01:18:01 +05:00
}
else
{
glBegin (GL_LINES);
Point<3> hp1 = p1;
Point<3> hp2 = p2;
Point<3> c = Center(p1, p2);
if (vispar.shrink < 1)
2011-01-11 01:18:01 +05:00
{
hp1 = c + vispar.shrink * (hp1 - c);
hp2 = c + vispar.shrink * (hp2 - c);
}
glVertex3dv (hp1);
glVertex3dv (hp2); // p2.X(), p2.Y(), p2.Z());
glEnd();
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glLineWidth (2);
glDisable (GL_POLYGON_OFFSET_LINE);
2011-01-11 01:18:01 +05:00
glDisable (GL_COLOR_MATERIAL);
glEnable (GL_LIGHTING);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glEndList();
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: BuildPointNumberList()
{
;
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
// Bernstein Pol B_{n,i}(x) = n! / i! / (n-i)! (1-x)^{n-i} x^i
static inline double Bernstein (int n, int i, double x)
{
double val = 1;
for (int j = 1; j <= i; j++)
val *= x;
for (int j = 1; j <= n-i; j++)
val *= (1-x) * (j+i) / j;
return val;
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void ToBernstein (int order, Point<3> * pts, int stride)
{
static DenseMatrix mat, inv;
static Vector vec1, vec2;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (mat.Height () != order+1)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
mat.SetSize (order+1);
inv.SetSize (order+1);
vec1.SetSize (order+1);
vec2.SetSize (order+1);
for (int i = 0; i <= order; i++)
{
double x = double(i) / order;
for (int j = 0; j <= order; j++)
2011-01-11 01:18:01 +05:00
mat(i,j) = Bernstein (order, j, x);
}
2011-01-11 01:18:01 +05:00
CalcInverse (mat, inv);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
for (int i = 0; i < 3; i++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
for (int j = 0; j <= order; j++)
vec1(j) = pts[j*stride](i);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
inv.Mult (vec1, vec2);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int j = 0; j <= order; j++)
pts[j*stride](i) = vec2(j);
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
void VisualSceneMesh :: BuildTetList(const BitArray & shownode)
2011-01-11 01:18:01 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
if (tettimestamp > mesh->GetTimeStamp () &&
2012-11-05 17:28:36 +06:00
tettimestamp > vispar.clipping.timestamp )
2011-01-11 01:18:01 +05:00
return;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (!lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
tettimestamp = NextTimeStamp();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (tetlist)
glDeleteLists (tetlist, 1);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
tetlist = glGenLists (1);
glNewList (tetlist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
Vector locms;
2011-01-11 01:18:01 +05:00
// Philippose - 16/02/2010
// Add Mesh size based coloring of
// meshes also for the volume elements
if (vispar.colormeshsize)
{
2011-01-11 01:18:01 +05:00
glEnable (GL_COLOR_MATERIAL);
locms.SetSize (mesh->GetNP());
maxh = -1;
minh = 1e99;
for (int i = 1; i <= locms.Size(); i++)
{
Point3d p = mesh->Point(i);
locms(i-1) = mesh->GetH (p);
if (locms(i-1) > maxh) maxh = locms(i-1);
if (locms(i-1) < minh) minh = locms(i-1);
2011-01-11 01:18:01 +05:00
}
if (!locms.Size())
{
minh = 1;
maxh = 10;
2011-01-11 01:18:01 +05:00
}
}
2011-01-11 01:18:01 +05:00
else
glDisable (GL_COLOR_MATERIAL);
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<Element2d> faces;
2011-05-13 17:36:50 +06:00
static float tetcols[][4] =
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
{ 1.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f },
2011-05-13 17:36:50 +06:00
{ 0.0f, 0.0f, 1.0f, 1.0f }
/*
2011-01-11 01:18:01 +05:00
{ 1.0f, 1.0f, 0.0f, 0.3f },
{ 1.0f, 0.0f, 0.0f, 0.3f },
{ 0.0f, 1.0f, 0.0f, 0.3f },
{ 0.0f, 0.0f, 1.0f, 0.3f }
2011-05-13 17:36:50 +06:00
*/
2009-01-13 04:40:13 +05:00
};
2011-01-11 01:18:01 +05:00
CurvedElements & curv = mesh->GetCurvedElements();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (!curv.IsHighOrder())
glShadeModel (GL_FLAT);
else
glShadeModel (GL_SMOOTH);
2009-01-13 04:40:13 +05:00
2023-03-29 23:30:21 +05:00
int hoplotn = max (2, 1 << subdivisions);
2009-01-13 04:40:13 +05:00
2011-05-13 17:36:50 +06:00
2011-01-11 01:18:01 +05:00
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
2009-01-13 04:40:13 +05:00
{
2011-02-14 17:27:18 +05:00
if (vispar.drawtetsdomain > 0)
{
/*
2011-05-13 17:36:50 +06:00
int tetid = vispar.drawmetispartition ?
(*mesh)[ei].GetPartition() : (*mesh)[ei].GetIndex();
*/
int tetid = (*mesh)[ei].GetIndex();
2011-05-13 17:36:50 +06:00
if (vispar.drawtetsdomain != tetid) continue;
2011-02-14 17:27:18 +05:00
}
2011-01-11 01:18:01 +05:00
const Element & el = (*mesh)[ei];
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if ((el.GetType() == TET || el.GetType() == TET10) && !el.IsDeleted())
{
bool visible = true;
for (auto pi: el.PNums())
if (!shownode[pi])
visible = false;
if(!visible) continue;
int ind = el.GetIndex() % 4;
2009-01-13 04:40:13 +05:00
// if (vispar.drawmetispartition && el.GetPartition()!=-1)
// ind = el.GetPartition() % 4;
2009-01-13 04:40:13 +05:00
2012-06-21 20:19:25 +06:00
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, tetcols[ind]);
2009-01-13 04:40:13 +05:00
if (curv.IsHighOrder()) // && curv.IsElementCurved(ei))
2011-01-11 01:18:01 +05:00
{
const ELEMENT_FACE * faces = MeshTopology :: GetFaces1 (TET);
const Point3d * vertices = MeshTopology :: GetVertices (TET);
/*
Point<3> grid[11][11];
Point<3> fpts[3];
int order = vispar.subdivisions+1;
for (int trig = 0; trig < 4; trig++)
{
for (int j = 0; j < 3; j++)
fpts[j] = vertices[faces[trig][j]-1];
static Point<3> c(0.25, 0.25, 0.25);
if (vispar.shrink < 1)
for (int j = 0; j < 3; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
for (int ix = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++)
{
double lami[3] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
double(iy)/order };
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) = lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l);
curv.CalcElementTransformation (xl, i-1, grid[ix][iy]);
}
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(8, 0.0, 0.999, 8, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 8, 0, 8);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
*/
int order = curv.GetOrder();
2019-07-09 13:39:16 +05:00
NgArray<Point<3> > ploc ( (order+1)*(order+1) );
NgArray<Point<3> > pglob ( (order+1)*(order+1) );
2011-01-11 01:18:01 +05:00
Point<3> fpts[3];
for (int trig = 0; trig < 4; trig++)
{
for (int j = 0; j < 3; j++)
fpts[j] = vertices[faces[trig][j]-1];
static Point<3> c(0.25, 0.25, 0.25);
if (vispar.shrink < 1)
for (int j = 0; j < 3; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
2011-01-11 01:18:01 +05:00
for (int ix = 0, ii = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++, ii++)
{
double lami[3] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
double(iy)/order };
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) = lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l);
ploc[ii] = xl;
}
curv.CalcMultiPointElementTransformation (&ploc, ei, &pglob, 0);
Point<3> grid[11][11];
for (int ix = 0, ii = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++, ii++)
grid[ix][iy] = pglob[ii];
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(hoplotn, 0.0, 0.9999f, hoplotn, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, hoplotn, 0, hoplotn);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
}
else // Not High Order
2011-01-11 01:18:01 +05:00
{
Point<3> pts[4];
for (int j = 0; j < 4; j++)
2009-01-13 04:40:13 +05:00
pts[j] = (*mesh)[el[j]];
2011-01-11 01:18:01 +05:00
if (vispar.shrink < 1)
{
Point<3> c = Center (pts[0], pts[1], pts[2], pts[3]);
for (int j = 0; j < 4; j++)
pts[j] = c + vispar.shrink * (pts[j]-c);
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
Vec<3> n;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
// Philippose - 16/02/2010
// Add Mesh size based coloring of
// meshes also for the volume elements
if(vispar.colormeshsize)
{
2012-06-08 00:49:41 +06:00
glBegin (GL_TRIANGLE_STRIP);
2011-01-11 01:18:01 +05:00
n = Cross (pts[1]-pts[0], pts[2]-pts[0]);
glNormal3dv (n);
2011-05-13 17:36:50 +06:00
SetOpenGlColor (locms(el[0]-1), minh, maxh, 0);
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[0]);
2011-05-13 17:36:50 +06:00
SetOpenGlColor (locms(el[1]-1), minh, maxh, 0);
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[1]);
2011-05-13 17:36:50 +06:00
SetOpenGlColor (locms(el[2]-1), minh, maxh, 0);
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[2]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
n = Cross (pts[3]-pts[1], pts[2]-pts[1]);
glNormal3dv (n);
2009-01-13 04:40:13 +05:00
2011-05-13 17:36:50 +06:00
SetOpenGlColor (locms(el[3]-1), minh, maxh, 0);
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[3]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
n = Cross (pts[3]-pts[2], pts[0]-pts[2]);
glNormal3dv (n);
2011-05-13 17:36:50 +06:00
SetOpenGlColor (locms(el[0]-1), minh, maxh, 0);
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[0]);
2011-01-11 01:18:01 +05:00
n = Cross (pts[1]-pts[3], pts[0]-pts[3]);
glNormal3dv (n);
2011-05-13 17:36:50 +06:00
SetOpenGlColor (locms(el[1]-1), minh, maxh, 0);
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[1]);
2012-06-08 00:49:41 +06:00
glEnd();
2011-01-11 01:18:01 +05:00
}
else // Do not color mesh based on mesh size
{
2012-06-08 00:49:41 +06:00
GLubyte ind[4][3] = { { 0,1,2 }, { 3,1,0 },
{ 1,3,2 }, { 2,3,0 } };
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_DOUBLE, 0, &pts[0](0));
for (int j = 0; j < 4; j++)
{
glNormal3dv (Cross (pts[ind[j][1]]-pts[ind[j][0]],
pts[ind[j][2]]-pts[ind[j][0]]));
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, &ind[j][0]);
}
glDisableClientState(GL_VERTEX_ARRAY);
/*
glBegin (GL_TRIANGLE_STRIP);
2011-05-13 17:36:50 +06:00
glNormal3dv (Cross (pts[1]-pts[0], pts[2]-pts[0]));
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[0]);
glVertex3dv (pts[1]);
glVertex3dv (pts[2]);
2011-05-13 17:36:50 +06:00
glNormal3dv (Cross (pts[3]-pts[1], pts[2]-pts[1]));
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[3]);
2011-05-13 17:36:50 +06:00
glNormal3dv (Cross (pts[3]-pts[2], pts[0]-pts[2]));
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[0]);
2011-05-13 17:36:50 +06:00
glNormal3dv (Cross (pts[1]-pts[3], pts[0]-pts[3]));
2011-01-11 01:18:01 +05:00
glVertex3dv (pts[1]);
2012-06-08 00:49:41 +06:00
glEnd();
*/
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
}
}
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glEndList ();
}
2009-01-13 04:40:13 +05:00
void VisualSceneMesh :: BuildPrismList(const BitArray & shownode)
2011-01-11 01:18:01 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
if (prismtimestamp > mesh->GetTimeStamp () &&
2012-11-05 17:28:36 +06:00
prismtimestamp > vispar.clipping.timestamp )
2011-01-11 01:18:01 +05:00
return;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (!lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
prismtimestamp = NextTimeStamp();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (prismlist)
glDeleteLists (prismlist, 1);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
prismlist = glGenLists (1);
glNewList (prismlist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
static float prismcol[] = { 0.0f, 1.0f, 1.0f, 1.0f };
glLineWidth (1.0f);
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<Element2d> faces;
2009-01-13 04:40:13 +05:00
2023-04-12 19:43:33 +05:00
glDisable (GL_COLOR_MATERIAL);
2011-01-11 01:18:01 +05:00
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, prismcol);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
const Element & el = (*mesh)[ei];
if (el.GetType() == PRISM && !el.IsDeleted())
{
bool visible = true;
for (auto pi: el.PNums())
if (!shownode[pi])
visible = false;
if(!visible) continue;
int j;
int i = ei + 1;
CurvedElements & curv = mesh->GetCurvedElements();
if (curv.IsHighOrder()) // && curv.IsElementCurved(ei))
2011-01-11 01:18:01 +05:00
{
const ELEMENT_FACE * faces = MeshTopology :: GetFaces1 (PRISM);
const Point3d * vertices = MeshTopology :: GetVertices (PRISM);
Point<3> grid[11][11];
Point<3> fpts[4];
2023-03-29 23:30:21 +05:00
int order = subdivisions+1;
2011-01-11 01:18:01 +05:00
for (int trig = 0; trig < 2; trig++)
{
for (int j = 0; j < 3; j++)
fpts[j] = vertices[faces[trig][j]-1];
static Point<3> c(1.0/3.0, 1.0/3.0, 0.5);
if (vispar.shrink < 1)
for (int j = 0; j < 3; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++)
{
double lami[3] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
double(iy)/order };
2011-01-11 01:18:01 +05:00
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) = lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l);
2011-01-11 01:18:01 +05:00
curv.CalcElementTransformation (xl, i-1, grid[ix][iy]);
}
2011-01-11 01:18:01 +05:00
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(8, 0.0, 0.999f, 8, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 8, 0, 8);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
for (int quad = 2; quad < 5; quad++)
{
for (int j = 0; j < 4; j++)
fpts[j] = vertices[faces[quad][j]-1];
static Point<3> c(1.0/3.0, 1.0/3.0, 0.5);
if (vispar.shrink < 1)
for (int j = 0; j < 4; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++)
{
double lami[4] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * ( double(iy)/order),
(1-double(ix)/order) * ( double(iy)/order) };
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) =
lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l) + lami[3] * fpts[3](l);
curv.CalcElementTransformation (xl, ei, grid[ix][iy]);
}
2011-01-11 01:18:01 +05:00
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(8, 0.0, 1.0, 8, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 8, 0, 8);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
/*
2023-03-29 23:30:21 +05:00
int hoplotn = 1 << subdivisions;
2011-01-11 01:18:01 +05:00
// int hoplotn = curv.GetNVisualSubsecs();
const Point3d * facepoint = MeshTopology :: GetVertices (TRIG);
const ELEMENT_FACE * elface = MeshTopology :: GetFaces(TRIG);
glBegin (GL_TRIANGLES);
for (int trig = 0; trig<2; trig++)
{
Vec<3> x0,x1,d0,d1;
x0 = facepoint[1] - facepoint[2];
x1 = facepoint[0] - facepoint[2];
x0.Normalize();
x1.Normalize();
if (trig == 1) swap (x0,x1);
Point<3> xr[3];
Point<3> xg;
Vec<3> dx, dy, dz, n;
for (int i1 = 0; i1 < hoplotn; i1++)
for (int j1 = 0; j1 < hoplotn-i1; j1++)
for (int k = 0; k < 2; k++)
{
if (k == 0)
{
xr[0](0) = (double) i1/hoplotn; xr[0](1) = (double) j1/hoplotn;
xr[1](0) = (double)(i1+1)/hoplotn; xr[1](1) = (double) j1/hoplotn;
xr[2](0) = (double) i1/hoplotn; xr[2](1) = (double)(j1+1)/hoplotn;
} else
{
if (j1 == hoplotn-i1-1) continue;
xr[0](0) = (double)(i1+1)/hoplotn; xr[0](1) = (double) j1/hoplotn;
xr[1](0) = (double)(i1+1)/hoplotn; xr[1](1) = (double)(j1+1)/hoplotn;
xr[2](0) = (double) i1/hoplotn; xr[2](1) = (double)(j1+1)/hoplotn;
};
for (int l=0; l<3; l++)
{
Mat<3,3> dxdxi;
xr[l](2) = (double) trig;
curv.CalcElementTransformation (xr[l], i-1, xg, dxdxi);
for (int i = 0; i < 3; i++)
{
dx(i) = dxdxi(i,0);
dy(i) = dxdxi(i,1);
dz(i) = dxdxi(i,2);
}
Vec<3> d0 = x0(0)*dx + x0(1)*dy + x0(2)*dz;
Vec<3> d1 = x1(0)*dx + x1(1)*dy + x1(2)*dz;
n = Cross (d1, d0);
glNormal3d (n(0), n(1), n(2));
glVertex3d (xg(0), xg(1), xg(2));
}
}
}
glEnd ();
glBegin (GL_QUADS);
for (int quad = 0; quad<3; quad++)
{
const Point3d * facepoint = MeshTopology :: GetVertices (PRISM);
Vec<3> x0,x1;
int xyz;
switch (quad)
{
case 0:
x0 = facepoint[5] - facepoint[2];
x1 = facepoint[0] - facepoint[2];
xyz = 0;
break;
case 1:
x0 = facepoint[4] - facepoint[0];
x1 = facepoint[1] - facepoint[0];
xyz = 0;
break;
case 2:
x0 = facepoint[1] - facepoint[2];
x1 = facepoint[5] - facepoint[2];
xyz = 1;
break;
}
x0.Normalize();
x1.Normalize();
swap (x0,x1);
Point<3> xr[4];
Point<3> xg;
Vec<3> dx, dy, dz, n;
for (int i1 = 0; i1 < hoplotn; i1++)
for (int j1 = 0; j1 < hoplotn; j1++)
{
xr[0](xyz) = (double) i1/hoplotn; xr[0](2) = (double) j1/hoplotn;
xr[1](xyz) = (double)(i1+1)/hoplotn; xr[1](2) = (double) j1/hoplotn;
xr[2](xyz) = (double)(i1+1)/hoplotn; xr[2](2) = (double)(j1+1)/hoplotn;
xr[3](xyz) = (double) i1/hoplotn; xr[3](2) = (double)(j1+1)/hoplotn;
for (int l=0; l<4; l++)
{
switch (quad)
{
case 0: xr[l](1) = 0; break;
case 1: xr[l](1) = 1-xr[l](0); break;
case 2: xr[l](0) = 0; break;
}
Mat<3,3> dxdxi;
curv.CalcElementTransformation (xr[l], i-1, xg, dxdxi);
for (int i = 0; i < 3; i++)
{
dx(i) = dxdxi(i,0);
dy(i) = dxdxi(i,1);
dz(i) = dxdxi(i,2);
}
Vec<3> d0 = x0(0)*dx + x0(1)*dy + x0(2)*dz;
Vec<3> d1 = x1(0)*dx + x1(1)*dy + x1(2)*dz;
n = Cross (d1, d0);
glNormal3d (n(0), n(1), n(2));
glVertex3d (xg(0), xg(1), xg(2));
}
}
}
glEnd ();
*/
}
else
{
Point3d c(0,0,0);
if (vispar.shrink < 1)
{
for (j = 1; j <= 6; j++)
{
Point3d p = mesh->Point(el.PNum(j));
c.X() += p.X() / 6;
c.Y() += p.Y() / 6;
c.Z() += p.Z() / 6;
}
}
el.GetSurfaceTriangles (faces);
glBegin (GL_TRIANGLES);
for (j = 1; j <= faces.Size(); j++)
{
Element2d & face = faces.Elem(j);
Point3d lp1 = mesh->Point (el.PNum(face.PNum(1)));
Point3d lp2 = mesh->Point (el.PNum(face.PNum(2)));
Point3d lp3 = mesh->Point (el.PNum(face.PNum(3)));
Vec3d n = Cross (Vec3d (lp1, lp3), Vec3d (lp1, lp2));
n /= (n.Length()+1e-12);
glNormal3d (n.X(), n.Y(), n.Z());
if (vispar.shrink < 1)
{
lp1 = c + vispar.shrink * (lp1 - c);
lp2 = c + vispar.shrink * (lp2 - c);
lp3 = c + vispar.shrink * (lp3 - c);
}
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
}
glEnd();
}
}
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glEndList ();
}
2009-01-13 04:40:13 +05:00
void VisualSceneMesh :: BuildHexList(const BitArray & shownode)
2011-01-11 01:18:01 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
if (hextimestamp > mesh->GetTimeStamp () &&
2012-11-05 17:28:36 +06:00
hextimestamp > vispar.clipping.timestamp )
2011-01-11 01:18:01 +05:00
return;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (!lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
hextimestamp = NextTimeStamp();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (hexlist) glDeleteLists (hexlist, 1);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
hexlist = glGenLists (1);
glNewList (hexlist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
static float hexcol[] = { 1.0f, 1.0f, 0.0f, 1.0f };
glLineWidth (1.0f);
2023-04-12 19:43:33 +05:00
glDisable (GL_COLOR_MATERIAL);
2011-01-11 01:18:01 +05:00
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, hexcol);
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<Element2d> faces;
2011-01-11 01:18:01 +05:00
// int hoplotn = 1 << vispar.subdivisions;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
const Element & el = (*mesh)[ei];
if (el.GetType() == HEX && !el.IsDeleted())
{
bool visible = true;
for (auto pi: el.PNums())
if (!shownode[pi])
visible = false;
if(!visible) continue;
CurvedElements & curv = mesh->GetCurvedElements();
if (curv.IsHighOrder()) // && curv.IsElementCurved(ei))
2011-01-11 01:18:01 +05:00
{
/* // classical
glBegin (GL_QUADS);
const ELEMENT_FACE * faces = MeshTopology :: GetFaces (HEX);
const Point3d * vertices = MeshTopology :: GetVertices (HEX);
Point<3> grid[33][33];
Vec<3> gridn[33][33];
Point<3> fpts[4];
for (int quad = 0; quad<6; quad++)
{
for (int j = 0; j < 4; j++)
fpts[j] = vertices[faces[quad][j]-1];
static Point<3> c(0.5, 0.5, 0.5);
if (vispar.shrink < 1)
for (int j = 0; j < 4; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
Vec<3> taux = fpts[1]-fpts[0];
Vec<3> tauy = fpts[3]-fpts[0];
for (int ix = 0; ix <= hoplotn; ix++)
for (int iy = 0; iy <= hoplotn; iy++)
{
Point<3> xl;
Mat<3,3> dxdxi;
double lami[4] =
{ (1-double(ix)/hoplotn) * (1-double(iy)/hoplotn),
( double(ix)/hoplotn) * (1-double(iy)/hoplotn),
( double(ix)/hoplotn) * ( double(iy)/hoplotn),
(1-double(ix)/hoplotn) * ( double(iy)/hoplotn) };
for (int l = 0; l < 3; l++)
xl(l) = lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l) + lami[3] * fpts[3](l);
curv.CalcElementTransformation (xl, ei, grid[ix][iy], dxdxi);
Vec<3> gtaux = dxdxi * taux;
Vec<3> gtauy = dxdxi * tauy;
gridn[ix][iy] = Cross (gtauy, gtaux).Normalize();
}
for (int ix = 0; ix < hoplotn; ix++)
for (int iy = 0; iy < hoplotn; iy++)
{
glNormal3dv (gridn[ix][iy]);
glVertex3dv (grid[ix][iy]);
glNormal3dv (gridn[ix+1][iy]);
glVertex3dv (grid[ix+1][iy]);
glNormal3dv (gridn[ix+1][iy+1]);
glVertex3dv (grid[ix+1][iy+1]);
glNormal3dv (gridn[ix][iy+1]);
glVertex3dv (grid[ix][iy+1]);
}
}
glEnd ();
*/
const ELEMENT_FACE * faces = MeshTopology :: GetFaces1 (HEX);
const Point3d * vertices = MeshTopology :: GetVertices (HEX);
Point<3> grid[11][11];
Point<3> fpts[4];
2023-03-29 23:30:21 +05:00
int order = subdivisions+1;
2011-01-11 01:18:01 +05:00
for (int quad = 0; quad<6; quad++)
{
for (int j = 0; j < 4; j++)
fpts[j] = vertices[faces[quad][j]-1];
static Point<3> c(0.5, 0.5, 0.5);
if (vispar.shrink < 1)
for (int j = 0; j < 4; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++)
{
double lami[4] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * ( double(iy)/order),
(1-double(ix)/order) * ( double(iy)/order) };
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) = lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l) + lami[3] * fpts[3](l);
curv.CalcElementTransformation (xl, ei, grid[ix][iy]);
}
2011-01-11 01:18:01 +05:00
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(8, 0.0, 1.0, 8, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 8, 0, 8);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
}
else
{
Point3d c(0,0,0);
if (vispar.shrink < 1)
{
for (int j = 1; j <= 8; j++)
{
Point3d p = mesh->Point(el.PNum(j));
c.X() += p.X();
c.Y() += p.Y();
c.Z() += p.Z();
}
c.X() /= 8;
c.Y() /= 8;
c.Z() /= 8;
}
glBegin (GL_TRIANGLES);
el.GetSurfaceTriangles (faces);
for (int j = 1; j <= faces.Size(); j++)
{
Element2d & face = faces.Elem(j);
Point<3> lp1 = mesh->Point (el.PNum(face.PNum(1)));
Point<3> lp2 = mesh->Point (el.PNum(face.PNum(2)));
Point<3> lp3 = mesh->Point (el.PNum(face.PNum(3)));
Vec<3> n = Cross (lp3-lp1, lp2-lp1);
n.Normalize();
glNormal3dv (n);
if (vispar.shrink < 1)
{
lp1 = c + vispar.shrink * (lp1 - c);
lp2 = c + vispar.shrink * (lp2 - c);
lp3 = c + vispar.shrink * (lp3 - c);
}
glVertex3dv (lp1);
glVertex3dv (lp2);
glVertex3dv (lp3);
}
glEnd();
}
}
2009-01-13 04:40:13 +05:00
}
2023-09-21 01:21:24 +05:00
2023-09-29 12:30:19 +05:00
static float hex7col[] = { 1.0f, 0.65f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, hex7col);
2023-09-21 01:21:24 +05:00
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
{
const Element & el = (*mesh)[ei];
if (el.GetType() == HEX7 && !el.IsDeleted())
{
/*
CurvedElements & curv = mesh->GetCurvedElements();
if (curv.IsHighOrder())
{
const ELEMENT_FACE * faces = MeshTopology :: GetFaces1 (HEX);
const Point3d * vertices = MeshTopology :: GetVertices (HEX);
Point<3> grid[11][11];
Point<3> fpts[4];
int order = subdivisions+1;
for (int quad = 0; quad<6; quad++)
{
for (int j = 0; j < 4; j++)
fpts[j] = vertices[faces[quad][j]-1];
static Point<3> c(0.5, 0.5, 0.5);
if (vispar.shrink < 1)
for (int j = 0; j < 4; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
for (int ix = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++)
{
double lami[4] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * ( double(iy)/order),
(1-double(ix)/order) * ( double(iy)/order) };
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) = lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l) + lami[3] * fpts[3](l);
curv.CalcElementTransformation (xl, ei, grid[ix][iy]);
}
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(8, 0.0, 1.0, 8, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 8, 0, 8);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
}
else
*/
{
Point3d c(0,0,0);
if (vispar.shrink < 1)
{
for (int j = 1; j <= 7; j++)
{
Point3d p = mesh->Point(el.PNum(j));
c.X() += p.X();
c.Y() += p.Y();
c.Z() += p.Z();
}
c.X() /= 7;
c.Y() /= 7;
c.Z() /= 7;
}
glBegin (GL_TRIANGLES);
el.GetSurfaceTriangles (faces);
for (int j = 1; j <= faces.Size(); j++)
{
Element2d & face = faces.Elem(j);
Point<3> lp1 = mesh->Point (el.PNum(face.PNum(1)));
Point<3> lp2 = mesh->Point (el.PNum(face.PNum(2)));
Point<3> lp3 = mesh->Point (el.PNum(face.PNum(3)));
Vec<3> n = Cross (lp3-lp1, lp2-lp1);
n.Normalize();
glNormal3dv (n);
if (vispar.shrink < 1)
{
lp1 = c + vispar.shrink * (lp1 - c);
lp2 = c + vispar.shrink * (lp2 - c);
lp3 = c + vispar.shrink * (lp3 - c);
}
glVertex3dv (lp1);
glVertex3dv (lp2);
glVertex3dv (lp3);
}
glEnd();
}
}
}
2011-01-11 01:18:01 +05:00
glEndList ();
}
2009-01-13 04:40:13 +05:00
void VisualSceneMesh :: BuildPyramidList(const BitArray & shownode)
2011-01-11 01:18:01 +05:00
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
if (pyramidtimestamp > mesh->GetTimeStamp () &&
2012-11-05 17:28:36 +06:00
pyramidtimestamp > vispar.clipping.timestamp )
2011-01-11 01:18:01 +05:00
return;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (!lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock = new NgLock (mesh->Mutex());
lock -> Lock();
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
pyramidtimestamp = NextTimeStamp();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (pyramidlist)
glDeleteLists (pyramidlist, 1);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
pyramidlist = glGenLists (1);
glNewList (pyramidlist, GL_COMPILE);
2011-01-11 01:18:01 +05:00
static float pyramidcol[] = { 1.0f, 0.0f, 1.0f, 1.0f };
2023-04-12 19:43:33 +05:00
glDisable (GL_COLOR_MATERIAL);
2011-01-11 01:18:01 +05:00
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, pyramidcol);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glLineWidth (1.0f);
2019-07-09 13:39:16 +05:00
NgArray<Element2d> faces;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
const Element & el = (*mesh)[ei];
if ((el.GetType() == PYRAMID || el.GetType() == PYRAMID13) && !el.IsDeleted())
2011-01-11 01:18:01 +05:00
{
bool visible = true;
for (auto pi: el.PNums())
if (!shownode[pi])
visible = false;
if(!visible) continue;
int i = ei + 1;
CurvedElements & curv = mesh->GetCurvedElements();
if (curv.IsHighOrder()) // && curv.IsElementCurved(ei))
2011-01-11 01:18:01 +05:00
{
2011-01-11 01:18:01 +05:00
const ELEMENT_FACE * faces = MeshTopology :: GetFaces1 (PYRAMID);
const Point3d * vertices = MeshTopology :: GetVertices (PYRAMID);
2011-01-11 01:18:01 +05:00
Point<3> grid[11][11];
Point<3> fpts[4];
2023-03-29 23:30:21 +05:00
int order = subdivisions+1;
2011-01-11 01:18:01 +05:00
for (int trig = 0; trig < 4; trig++)
{
for (int j = 0; j < 3; j++)
fpts[j] = vertices[faces[trig][j]-1];
2011-01-11 01:18:01 +05:00
static Point<3> c(0.375, 0.375, 0.25);
if (vispar.shrink < 1)
for (int j = 0; j < 3; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++)
{
double lami[3] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
double(iy)/order };
2011-01-11 01:18:01 +05:00
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) = lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l);
2011-01-11 01:18:01 +05:00
curv.CalcElementTransformation (xl, i-1, grid[ix][iy]);
}
2011-01-11 01:18:01 +05:00
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
glMapGrid2f(8, 0.0, 0.999f, 8, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 8, 0, 8);
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
for (int quad = 4; quad < 5; quad++)
{
for (int j = 0; j < 4; j++)
fpts[j] = vertices[faces[quad][j]-1];
static Point<3> c(0.375, 0.375, 0.25);
if (vispar.shrink < 1)
for (int j = 0; j < 4; j++)
fpts[j] += (1-vispar.shrink) * (c-fpts[j]);
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix <= order; ix++)
for (int iy = 0; iy <= order; iy++)
{
double lami[4] =
{ (1-double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * (1-double(iy)/order),
( double(ix)/order) * ( double(iy)/order),
(1-double(ix)/order) * ( double(iy)/order) };
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) =
lami[0] * fpts[0](l) + lami[1] * fpts[1](l) +
lami[2] * fpts[2](l) + lami[3] * fpts[3](l);
curv.CalcElementTransformation (xl, ei, grid[ix][iy]);
}
2011-01-11 01:18:01 +05:00
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[j][0], &grid[0][1]-&grid[0][0]);
for (int j = 0; j <= order; j++)
ToBernstein (order, &grid[0][j], &grid[1][0]-&grid[0][0]);
2011-01-11 01:18:01 +05:00
glMap2d(GL_MAP2_VERTEX_3,
0.0, 1.0, &grid[0][1](0)-&grid[0][0](0), order+1,
0.0, 1.0, &grid[1][0](0)-&grid[0][0](0), order+1,
&grid[0][0](0));
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);
2011-01-11 01:18:01 +05:00
glMapGrid2f(8, 0.0, 1.0, 8, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 8, 0, 8);
2011-01-11 01:18:01 +05:00
glDisable (GL_AUTO_NORMAL);
glDisable (GL_MAP2_VERTEX_3);
}
2011-01-11 01:18:01 +05:00
/*
int hoplotn = 1 << vispar.subdivisions;
2011-01-11 01:18:01 +05:00
const ELEMENT_FACE * faces = MeshTopology :: GetFaces (PYRAMID);
const Point3d * vertices = MeshTopology :: GetVertices (PYRAMID);
2011-01-11 01:18:01 +05:00
Point<3> grid[33][33];
Vec<3> gridn[33][33];
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glBegin (GL_TRIANGLES);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int trig = 0; trig < 4; trig++)
{
Point<3> p0 = vertices[faces[trig][0]-1];
Point<3> p1 = vertices[faces[trig][1]-1];
Point<3> p2 = vertices[faces[trig][2]-1];
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.shrink < 1)
{
static Point<3> c(0.375, 0.375, 0.25);
p0 = c + vispar.shrink * (p0 - c);
p1 = c + vispar.shrink * (p1 - c);
p2 = c + vispar.shrink * (p2 - c);
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
Vec<3> taux = p0-p2;
Vec<3> tauy = p1-p2;
Vec<3> gtaux, gtauy;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
Point<3> xl;
Mat<3,3> dxdxi;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix <= hoplotn; ix++)
for (int iy = 0; iy <= hoplotn-ix; iy++)
{
for (int l = 0; l < 3; l++)
xl(l) =
(1-double(ix+iy)/hoplotn) * p2(l) +
(double(ix)/hoplotn) * p0(l) +
(double(iy)/hoplotn) * p1(l);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
curv.CalcElementTransformation (xl, i-1, grid[ix][iy], dxdxi);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
gtaux = dxdxi * taux;
gtauy = dxdxi * tauy;
gridn[ix][iy] = Cross (gtauy, gtaux).Normalize();
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix < hoplotn; ix++)
for (int iy = 0; iy < hoplotn-ix; iy++)
{
glNormal3dv (gridn[ix][iy]);
glVertex3dv (grid[ix][iy]);
2011-01-11 01:18:01 +05:00
glNormal3dv (gridn[ix+1][iy]);
glVertex3dv (grid[ix+1][iy]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glNormal3dv (gridn[ix][iy+1]);
glVertex3dv (grid[ix][iy+1]);
2011-01-11 01:18:01 +05:00
if (iy < hoplotn-ix-1)
{
glNormal3dv (gridn[ix][iy+1]);
glVertex3dv (grid[ix][iy+1]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glNormal3dv (gridn[ix+1][iy]);
glVertex3dv (grid[ix+1][iy]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glNormal3dv (gridn[ix+1][iy+1]);
glVertex3dv (grid[ix+1][iy+1]);
}
}
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glEnd ();
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glBegin (GL_QUADS);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int quad = 4; quad < 5; quad++)
{
Point<3> p0 = vertices[faces[quad][0]-1];
Point<3> p1 = vertices[faces[quad][1]-1];
Point<3> p2 = vertices[faces[quad][2]-1];
Point<3> p3 = vertices[faces[quad][3]-1];
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
if (vispar.shrink < 1)
{
static Point<3> c(0.375, 0.375, 0.25);
p0 = c + vispar.shrink * (p0 - c);
p1 = c + vispar.shrink * (p1 - c);
p2 = c + vispar.shrink * (p2 - c);
p3 = c + vispar.shrink * (p3 - c);
}
2011-01-11 01:18:01 +05:00
Vec<3> taux = p1-p0;
Vec<3> tauy = p3-p0;
Vec<3> gtaux, gtauy;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
Point<3> xl, xg;
Mat<3,3> dxdxi;
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix <= hoplotn; ix++)
for (int iy = 0; iy <= hoplotn; iy++)
{
Point<3> xl;
for (int l = 0; l < 3; l++)
xl(l) =
(1-double(ix)/hoplotn)*(1-double(iy)/hoplotn) * p0(l) +
( double(ix)/hoplotn)*(1-double(iy)/hoplotn) * p1(l) +
( double(ix)/hoplotn)*( double(iy)/hoplotn) * p2(l) +
(1-double(ix)/hoplotn)*( double(iy)/hoplotn) * p3(l);
2011-01-11 01:18:01 +05:00
curv.CalcElementTransformation (xl, i-1, grid[ix][iy], dxdxi);
gtaux = dxdxi * taux;
gtauy = dxdxi * tauy;
gridn[ix][iy] = Cross (gtauy, gtaux).Normalize();
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
for (int ix = 0; ix < hoplotn; ix++)
for (int iy = 0; iy < hoplotn; iy++)
{
glNormal3dv (gridn[ix][iy]);
glVertex3dv (grid[ix][iy]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glNormal3dv (gridn[ix+1][iy]);
glVertex3dv (grid[ix+1][iy]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glNormal3dv (gridn[ix+1][iy+1]);
glVertex3dv (grid[ix+1][iy+1]);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
glNormal3dv (gridn[ix][iy+1]);
glVertex3dv (grid[ix][iy+1]);
}
}
2011-01-11 01:18:01 +05:00
glEnd ();
*/
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
}
else
2011-01-11 01:18:01 +05:00
{
Point3d c(0,0,0);
if (vispar.shrink < 1)
{
for (int j = 1; j <= 5; j++)
{
Point3d p = mesh->Point(el.PNum(j));
c.X() += p.X() / 5;
c.Y() += p.Y() / 5;
c.Z() += p.Z() / 5;
}
}
el.GetSurfaceTriangles (faces);
if (el.PNum(1))
{
glBegin (GL_TRIANGLES);
for (int j = 1; j <= faces.Size(); j++)
{
Element2d & face = faces.Elem(j);
Point3d lp1 = mesh->Point (el.PNum(face.PNum(1)));
Point3d lp2 = mesh->Point (el.PNum(face.PNum(2)));
Point3d lp3 = mesh->Point (el.PNum(face.PNum(3)));
Vec3d n = Cross (Vec3d (lp1, lp2), Vec3d (lp1, lp3));
n /= (n.Length()+1e-12);
n *= -1;
glNormal3d (n.X(), n.Y(), n.Z());
if (vispar.shrink < 1)
{
lp1 = c + vispar.shrink * (lp1 - c);
lp2 = c + vispar.shrink * (lp2 - c);
lp3 = c + vispar.shrink * (lp3 - c);
}
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
}
glEnd();
}
}
}
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glEndList ();
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: BuildBadelList()
{
;
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: BuildIdentifiedList()
{
;
}
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: BuildDomainSurfList()
{
2015-01-09 02:18:33 +05:00
shared_ptr<Mesh> mesh = GetMesh();
2014-10-06 15:57:44 +06:00
2011-01-11 01:18:01 +05:00
if (domainsurflist)
glDeleteLists (domainsurflist, 1);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
domainsurflist = glGenLists (1);
glNewList (domainsurflist, GL_COMPILE);
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
int i, j;
glLineWidth (1.0f);
2011-01-11 01:18:01 +05:00
glDisable (GL_COLOR_MATERIAL);
2011-01-11 01:18:01 +05:00
for (i = 1; i <= mesh->GetNSE(); i++)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
Element2d el = mesh->SurfaceElement (i);
2011-01-11 01:18:01 +05:00
int drawel = 1;
for (j = 1; j <= el.GetNP(); j++)
{
if (!el.PNum(j))
2011-01-11 01:18:01 +05:00
drawel = 0;
}
2011-01-11 01:18:01 +05:00
if (!drawel)
continue;
2011-01-11 01:18:01 +05:00
if (el.GetIndex() < 1 || el.GetIndex() > mesh->GetNFD())
continue;
int domin = mesh->GetFaceDescriptor(el.GetIndex()).DomainIn();
int domout = mesh->GetFaceDescriptor(el.GetIndex()).DomainOut();
2011-01-11 01:18:01 +05:00
int fac;
if (domin == vispar.drawdomainsurf)
fac = 1;
else if (domout == vispar.drawdomainsurf)
fac = -1;
else
continue;
2011-01-11 01:18:01 +05:00
GLfloat matcol[] = { 1, 0, 0, 1 };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, matcol);
2011-01-11 01:18:01 +05:00
if (el.GetNP() == 3)
{
glBegin (GL_TRIANGLES);
const Point3d & lp1 = mesh->Point (el.PNum(1));
const Point3d & lp2 = mesh->Point (el.PNum(2));
const Point3d & lp3 = mesh->Point (el.PNum(3));
Vec3d n = Cross (Vec3d (lp1, lp2), Vec3d (lp1, lp3));
n /= ( fac * (n.Length()+1e-12));
glNormal3d (n.X(), n.Y(), n.Z());
if (!vispar.colormeshsize)
2011-01-11 01:18:01 +05:00
{
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
}
glEnd();
2011-01-11 01:18:01 +05:00
}
else if (el.GetNP() == 4)
{
glBegin (GL_QUADS);
const Point3d & lp1 = mesh->Point (el.PNum(1));
const Point3d & lp2 = mesh->Point (el.PNum(2));
const Point3d & lp3 = mesh->Point (el.PNum(4));
const Point3d & lp4 = mesh->Point (el.PNum(3));
Vec3d n = Cross (Vec3d (lp1, lp2),
2011-01-11 01:18:01 +05:00
Vec3d (lp1, Center (lp3, lp4)));
n /= (fac * (n.Length()+1e-12));
glNormal3d (n.X(), n.Y(), n.Z());
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp4.X(), lp4.Y(), lp4.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
glEnd();
2011-01-11 01:18:01 +05:00
}
else if (el.GetNP() == 6)
{
glBegin (GL_TRIANGLES);
static int trigs[4][3] = {
2011-01-11 01:18:01 +05:00
{ 1, 6, 5 },
{ 2, 4, 6 },
{ 3, 5, 4 },
{ 4, 5, 6 } };
for (j = 0; j < 4; j++)
{
const Point3d & lp1 = mesh->Point (el.PNum(trigs[j][0]));
const Point3d & lp2 = mesh->Point (el.PNum(trigs[j][1]));
const Point3d & lp3 = mesh->Point (el.PNum(trigs[j][2]));
Vec3d n = Cross (Vec3d (lp1, lp2), Vec3d (lp1, lp3));
n /= (fac * (n.Length() + 1e-12));
glNormal3d (n.X(), n.Y(), n.Z());
glVertex3d (lp1.X(), lp1.Y(), lp1.Z());
glVertex3d (lp2.X(), lp2.Y(), lp2.Z());
glVertex3d (lp3.X(), lp3.Y(), lp3.Z());
}
glEnd();
}
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
glEndList ();
}
2009-01-13 04:40:13 +05:00
2023-03-29 23:30:21 +05:00
bool VisualSceneMesh :: SelectSurfaceElement (int px, int py, Point<3> &p, bool select_on_clipping_plane)
2011-01-11 01:18:01 +05:00
{
2023-03-29 23:30:21 +05:00
selelement = -1;
marker = nullopt;
2023-03-29 23:30:21 +05:00
shared_ptr<Mesh> mesh = GetMesh();
if(px != select.x || py != select.y)
{
select.x = px;
select.y = py;
locpi = -2;
}
glGetIntegerv (GL_VIEWPORT, select.viewport);
2023-08-05 15:01:01 +05:00
// GLenum err;
2023-03-29 23:30:21 +05:00
if(select.framebuffer == 0 || select.viewport[2] != select.width || select.viewport[3] != select.height)
{
select.width = select.viewport[2];
select.height = select.viewport[3];
if(select.framebuffer != 0)
{
glDeleteRenderbuffers(2, select.render_buffers);
glDeleteFramebuffers(1, &select.framebuffer);
}
glGenFramebuffers(1, &select.framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, select.framebuffer);
// create, reserve and attach color and depth renderbuffer
glGenRenderbuffers(2, select.render_buffers);
glBindRenderbuffer(GL_RENDERBUFFER, select.render_buffers[0]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB16, select.width, select.height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, select.render_buffers[0]);
glBindRenderbuffer(GL_RENDERBUFFER, select.render_buffers[1]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, select.width, select.height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, select.render_buffers[1]);
// check if framebuffer status is complete
if(int fbstatus; (fbstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE)
cerr << "no frame buffer " << fbstatus << endl;
}
glFlush();
2023-03-29 23:30:21 +05:00
glBindFramebuffer(GL_FRAMEBUFFER, select.framebuffer);
BuildFilledList (true);
2014-02-06 20:13:32 +06:00
2023-03-29 23:30:21 +05:00
glEnable(GL_DEPTH_TEST);
glClearColor(0, 0, 0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2014-02-06 20:13:32 +06:00
2023-03-29 23:30:21 +05:00
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMultMatrixd (transformationmat);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
auto hy = select.viewport[3] - py;
SetClippingPlane();
if (vispar.clipping.enable)
{
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;
if(select_on_clipping_plane)
{
glColor3us(0,0,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 (select.list);
glFinish();
glGetDoublev (GL_PROJECTION_MATRIX, select.projmat);
auto found = Unproject(px, py, p);
if(found)
{
marker = p;
GLushort numbers[3];
glReadPixels (px, hy, 1, 1, GL_RGB, GL_UNSIGNED_SHORT, numbers);
selelement = numbers[0] + numbers[1]*(1<<16);
locpi++;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glPopMatrix();
2021-01-08 12:30:47 +05:00
if(lock)
{
lock->UnLock();
delete lock;
lock = NULL;
}
2023-03-29 23:30:21 +05:00
return found;
}
2023-03-29 23:30:21 +05:00
bool VisualSceneMesh :: Unproject(int px, int py, Point<3> &p)
{
auto hy = select.viewport[3] - py;
float pz;
glReadPixels (px, hy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pz);
if(pz<1 && pz>0)
gluUnProject(px, hy, pz, transformationmat, select.projmat, select.viewport,
&p[0], &p[1], &p[2]);
return pz<1 && pz>0;
}
ngcore::IVec<2> VisualSceneMesh :: Project(Point<3> p)
2023-03-29 23:30:21 +05:00
{
Point<3> pwin;
gluProject(p[0], p[1], p[2], transformationmat, select.projmat, select.viewport,
&pwin[0], &pwin[1], &pwin[2]);
return ngcore::IVec<2>(pwin[0]+0.5, select.viewport[3]-pwin[1]+0.5);
2021-01-08 12:30:47 +05:00
}
void VisualSceneMesh :: MouseDblClick (int px, int py)
{
Point<3> p;
2023-03-29 23:30:21 +05:00
bool found_point = SelectSurfaceElement(px, py, p, false);
2021-01-08 12:30:47 +05:00
2023-03-29 23:30:21 +05:00
if(selelement>0)
2021-01-08 12:30:47 +05:00
{
const Element2d & sel = GetMesh()->SurfaceElement(selelement);
SetSelectedFace(sel.GetIndex());
2014-02-06 20:13:32 +06:00
2023-03-29 23:30:21 +05:00
auto pi_nearest = sel[0];
double min_dist = 1e99;
for(auto pi : sel.PNums())
if(Dist2(GetMesh()->Point(pi), p) < min_dist)
{
min_dist = Dist2(GetMesh()->Point(pi), p);
pi_nearest = pi;
}
auto p_win = Project(GetMesh()->Point(pi_nearest));
if(abs(p_win[0]-px) < 5 && abs(p_win[1]-py) < 5)
{
marker = GetMesh()->Point(pi_nearest);
selpoint = pi_nearest;
cout << "select point " << pi_nearest << " at " << *marker << endl;
2023-03-29 23:30:21 +05:00
locpi = -2;
}
else
{
if(locpi < 0)
{
cout << endl << "select element " << selelement
2023-04-12 19:43:46 +05:00
<< " on face " << sel.GetIndex();
// output face name
auto mesh = GetMesh();
string name;
if(mesh->GetDimension() == 3)
name = mesh->GetFaceDescriptor(sel.GetIndex()).GetBCName();
else
name = mesh->GetMaterial(sel.GetIndex());
2023-04-12 19:43:46 +05:00
if(name != "")
cout << " with name " << name;
cout << endl;
if(mesh->GetDimension() == 3) {
auto & fd = mesh->GetFaceDescriptor(sel.GetIndex());
auto domin = fd.DomainIn();
auto domout = fd.DomainOut();
string name_in = domin >0 ? mesh->GetMaterial(domin) : "";
string name_out = domout >0 ? mesh->GetMaterial(domout) : "";
cout << "\tadjacent domains " << domin << ": " << name_in << ", " << domout << ": " << name_out << endl;
}
cout << "\tpoint: " << p << endl;;
cout << "\tnodes: ";
2023-03-29 23:30:21 +05:00
for (int i = 1; i <= sel.GetNP(); i++)
cout << sel.PNum(i) << " ";
cout << endl;
}
else {
auto pi = sel[locpi%sel.GetNP()];
marker = GetMesh()->Points()[pi];
cout << "select point " << pi << " at " << *marker << endl;
2023-03-29 23:30:21 +05:00
}
}
2021-01-08 12:30:47 +05:00
}
if(found_point && user_me_handler)
{
if (selelement != -1)
user_me_handler -> DblClick (selelement-1, p[0], p[1], p[2]);
}
2011-01-15 01:50:12 +05:00
2011-01-11 01:18:01 +05:00
if(lock)
2009-01-13 04:40:13 +05:00
{
2011-01-11 01:18:01 +05:00
lock->UnLock();
delete lock;
lock = NULL;
2009-01-13 04:40:13 +05:00
}
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
2011-01-11 01:18:01 +05:00
void VisualSceneMesh :: SetSelectedFace (int asf)
{
2023-03-29 23:30:21 +05:00
if(selface != asf)
{
selface = asf;
BuildColorTexture();
}
2011-01-11 01:18:01 +05:00
}
2009-01-13 04:40:13 +05:00
}
2014-10-09 23:17:11 +06:00
#ifdef NG_PYTHON
#include <../general/ngpython.hpp>
#include "../include/nginterface.h"
2014-10-09 23:17:11 +06:00
NGGUI_API void ExportMeshVis(py::module &m)
2014-10-09 23:17:11 +06:00
{
using namespace netgen;
vispar.drawcolorbar = true;
vispar.drawnetgenlogo = true;
vispar.drawcoordinatecross = true;
vispar.drawfilledtrigs = true;
vispar.drawdomainsurf = true;
vispar.drawhexes = true;
vispar.drawtets = true;
vispar.drawprisms = true;
vispar.drawoutline = true;
2016-11-04 16:14:52 +05:00
py::class_<VisualSceneMesh, shared_ptr<VisualSceneMesh>>
(m, "VisualSceneMesh")
2014-10-09 23:17:11 +06:00
.def("Draw", &VisualSceneMesh::DrawScene)
;
2016-11-04 16:14:52 +05:00
m.def("VS", FunctionPointer
2014-10-09 23:17:11 +06:00
([](shared_ptr<Mesh> mesh)
{
auto vs = make_shared<VisualSceneMesh>();
2015-01-09 02:18:33 +05:00
// vs->SetMesh(mesh);
SetGlobalMesh (mesh);
2014-10-09 23:17:11 +06:00
return vs;
}));
2016-11-04 16:14:52 +05:00
m.def("MouseMove", FunctionPointer
2014-10-09 23:17:11 +06:00
([](VisualSceneMesh &vsmesh, int oldx, int oldy, int newx, int
newy, char mode)
{
vsmesh.MouseMove(oldx, oldy, newx, newy, mode);
}));
2016-11-04 16:14:52 +05:00
m.def("SelectFace", FunctionPointer
([] (int facenr) {
vsmesh.SetSelectedFace(facenr);
}));
2016-11-04 16:14:52 +05:00
m.def("GetGlobalMesh", FunctionPointer
([] () {
return vsmesh.GetMesh();
}));
2014-10-09 23:17:11 +06:00
}
2016-11-04 16:14:52 +05:00
// BOOST_PYTHON_MODULE(libvisual)
// {
// ExportMeshVis();
// }
2014-10-09 23:17:11 +06:00
#endif