From cd78f0e4408f23169d4230aabbfe7dc27c3257cc Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Sat, 21 Sep 2019 22:08:35 +0200 Subject: [PATCH 1/4] draw stl meshing 2d local coordinates --- libsrc/meshing/meshing2.cpp | 51 ++++++++++++++++++++------------- libsrc/visualization/mvdraw.hpp | 4 +++ ng/ngpkg.cpp | 2 +- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index a696e608..76aa6e60 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -1,9 +1,12 @@ #include #include "meshing.hpp" +#include namespace netgen { + extern DLL_HEADER void Render(bool blocking = false); static void glrender (int wait); + VisualSceneSurfaceMeshing vssurfacemeshing; // global variable for visualization @@ -15,7 +18,7 @@ namespace netgen // // static int geomtrig; // //static const char * rname; // static int cntelem, trials, nfaces; -// static int oldnl; + static int oldnl; // static int qualclass; @@ -241,14 +244,20 @@ namespace netgen bool debugflag; // double h; - - NgArray locpoints; + + auto locpointsptr = make_shared>(); + vssurfacemeshing.locpointsptr = locpointsptr; + auto& locpoints = *locpointsptr; NgArray legalpoints; - NgArray plainpoints; + auto plainpointsptr = make_shared>(); + auto& plainpoints = *plainpointsptr; + vssurfacemeshing.plainpointsptr = plainpointsptr; NgArray plainzones; - NgArray loclines; + auto loclinesptr = make_shared>(); + auto &loclines = *loclinesptr; + vssurfacemeshing.loclinesptr = loclinesptr; int cntelem = 0, trials = 0, nfaces = 0; - int oldnl = 0; + oldnl = 0; int qualclass; @@ -1579,14 +1588,11 @@ namespace netgen - -// #define OPENGL -#ifdef OPENGLxx +#ifdef OPENGL /* *********************** Draw Surface Meshing **************** */ -#include #include namespace netgen @@ -1594,7 +1600,6 @@ namespace netgen extern STLGeometry * stlgeometry; extern Mesh * mesh; - VisualSceneSurfaceMeshing vssurfacemeshing; @@ -1604,8 +1609,9 @@ namespace netgen if (multithread.drawing) { - // vssurfacemeshing.Render(); - Render (); + // vssurfacemeshing.Render(); + // Render (); + Render(); if (wait || multithread.testmode) { @@ -1630,7 +1636,12 @@ namespace netgen void VisualSceneSurfaceMeshing :: DrawScene () { - int i, j, k; + // int i, j, k; + if(!locpointsptr) + return; + auto& locpoints = *locpointsptr; + auto& loclines = *loclinesptr; + auto& plainpoints = *plainpointsptr; if (loclines.Size() != changeval) { @@ -1657,7 +1668,7 @@ namespace netgen // SetLight(); glPushMatrix(); - glMultMatrixf (transformationmat); + glMultMatrixd (transformationmat); glShadeModel (GL_SMOOTH); // glDisable (GL_COLOR_MATERIAL); @@ -1694,7 +1705,7 @@ namespace netgen glPolygonOffset (1, -1); glLineWidth (3); - for (i = 1; i <= loclines.Size(); i++) + for (int i = 1; i <= loclines.Size(); i++) { if (i == 1) { @@ -1731,7 +1742,7 @@ namespace netgen float mat_colp[] = { 1, 0, 0, 1 }; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp); glBegin (GL_POINTS); - for (i = 1; i <= locpoints.Size(); i++) + for (int i = 1; i <= locpoints.Size(); i++) { Point3d p = locpoints.Get(i); glVertex3f (p.X(), p.Y(), p.Z()); @@ -1751,7 +1762,7 @@ namespace netgen double scalex = 0.1, scaley = 0.1; glBegin (GL_LINES); - for (i = 1; i <= loclines.Size(); i++) + for (int i = 1; i <= loclines.Size(); i++) { glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d); if (i == 1) @@ -1776,7 +1787,7 @@ namespace netgen glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp); glBegin (GL_POINTS); - for (i = 1; i <= plainpoints.Size(); i++) + for (int i = 1; i <= plainpoints.Size(); i++) { Point2d p = plainpoints.Get(i); glVertex3f (scalex * p.X(), scaley * p.Y(), -5); @@ -1971,7 +1982,7 @@ namespace netgen void VisualSceneSurfaceMeshing :: BuildScene (int zoomall) { - int i, j, k; + // int i, j, k; /* center = stlgeometry -> GetBoundingBox().Center(); rad = stlgeometry -> GetBoundingBox().Diam() / 2; diff --git a/libsrc/visualization/mvdraw.hpp b/libsrc/visualization/mvdraw.hpp index 9df510a7..94f4c7a5 100644 --- a/libsrc/visualization/mvdraw.hpp +++ b/libsrc/visualization/mvdraw.hpp @@ -96,6 +96,10 @@ namespace netgen class VisualSceneSurfaceMeshing : public VisualScene { public: + shared_ptr> locpointsptr; + shared_ptr> loclinesptr; + shared_ptr> plainpointsptr; + bool clearptr; VisualSceneSurfaceMeshing (); virtual ~VisualSceneSurfaceMeshing (); diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index c4866ab7..a0226cf3 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -1940,7 +1940,7 @@ namespace netgen vs = &vsmeshdoc; } - // if (strcmp (vismode, "surfmeshing") == 0) vs = &vssurfacemeshing; + if (strcmp (vismode, "surfmeshing") == 0) vs = &vssurfacemeshing; if (strcmp (vismode, "specpoints") == 0) vs = &vsspecpoints; if (strcmp (vismode, "solution") == 0) vs = &netgen::GetVSSolution(); } From d080f516cce0128c9b14b7ea4a5ff10f468bb45f Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Sat, 21 Sep 2019 22:41:01 +0200 Subject: [PATCH 2/4] draw 3d and 2d local coordinates --- libsrc/meshing/meshing2.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index 76aa6e60..381c22c5 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -1609,9 +1609,8 @@ namespace netgen if (multithread.drawing) { - // vssurfacemeshing.Render(); - // Render (); - Render(); + // vssurfacemeshing.DrawScene(); + Render (); if (wait || multithread.testmode) { @@ -1648,7 +1647,7 @@ namespace netgen center = Point<3>(0,0,-5); rad = 0.1; - CalcTransformationMatrices(); + // CalcTransformationMatrices(); changeval = loclines.Size(); } @@ -1688,7 +1687,7 @@ namespace netgen - /* + float mat_col[] = { 0.2, 0.2, 0.8, 1 }; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col); @@ -1751,9 +1750,9 @@ namespace netgen glPopMatrix(); - */ + - float mat_colp[] = { 1, 0, 0, 1 }; + // float mat_colp[] = { 1, 0, 0, 1 }; float mat_col2d1[] = { 1, 0.5, 0.5, 1 }; float mat_col2d[] = { 1, 1, 1, 1 }; From 4eb7c1860c3767e975a375ff7cb6f57503258334 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Sun, 22 Sep 2019 14:37:14 +0200 Subject: [PATCH 3/4] allow 2d plainview to be moved using meta key --- libsrc/meshing/meshing2.cpp | 15 ++++++++------- libsrc/visualization/mvdraw.cpp | 23 ++++++++++++++++++++--- libsrc/visualization/mvdraw.hpp | 14 +++++++++----- ng/drawing.tcl | 12 ++++++++++++ ng/drawing_togl17.tcl | 12 ++++++++++++ ng/onetcl.cpp | 10 ++++++++++ 6 files changed, 71 insertions(+), 15 deletions(-) diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index 381c22c5..e19406d1 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -18,7 +18,7 @@ namespace netgen // // static int geomtrig; // //static const char * rname; // static int cntelem, trials, nfaces; - static int oldnl; +// static int oldnl; // static int qualclass; @@ -257,7 +257,8 @@ namespace netgen auto &loclines = *loclinesptr; vssurfacemeshing.loclinesptr = loclinesptr; int cntelem = 0, trials = 0, nfaces = 0; - oldnl = 0; + int oldnl = 0; + vssurfacemeshing.oldnl = oldnl; int qualclass; @@ -523,6 +524,7 @@ namespace netgen { oldnp = locpoints.Size(); oldnl = loclines.Size(); + vssurfacemeshing.oldnl = oldnl; if (debugflag) (*testout) << "define new transformation" << endl; @@ -1461,6 +1463,7 @@ namespace netgen (*testout) << adfront.GetGlobalIndex (pindex.Get(i)) << endl; (*testout) << "old number of lines = " << oldnl << endl; + vssurfacemeshing.oldnl = oldnl; for (int i = 1; i <= loclines.Size(); i++) { (*testout) << "line "; @@ -1758,8 +1761,6 @@ namespace netgen float mat_col2d[] = { 1, 1, 1, 1 }; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d); - double scalex = 0.1, scaley = 0.1; - glBegin (GL_LINES); for (int i = 1; i <= loclines.Size(); i++) { @@ -1776,8 +1777,8 @@ namespace netgen Point2d p2 = plainpoints.Get(pi2); glBegin (GL_LINES); - glVertex3f (scalex * p1.X(), scaley * p1.Y(), -5); - glVertex3f (scalex * p2.X(), scaley * p2.Y(), -5); + glVertex3f (scalex * p1.X() + shiftx, scaley * p1.Y() + shifty, -5); + glVertex3f (scalex * p2.X() + shiftx, scaley * p2.Y() + shifty, -5); glEnd(); } } @@ -1789,7 +1790,7 @@ namespace netgen for (int i = 1; i <= plainpoints.Size(); i++) { Point2d p = plainpoints.Get(i); - glVertex3f (scalex * p.X(), scaley * p.Y(), -5); + glVertex3f (scalex * p.X() + shiftx, scaley * p.Y() + shifty, -5); } glEnd(); diff --git a/libsrc/visualization/mvdraw.cpp b/libsrc/visualization/mvdraw.cpp index 3a71da01..07d9aec4 100644 --- a/libsrc/visualization/mvdraw.cpp +++ b/libsrc/visualization/mvdraw.cpp @@ -758,9 +758,26 @@ namespace netgen } - - - + void VisualSceneSurfaceMeshing::MouseMove(int oldx, int oldy, + int newx, int newy, + char mode) + { + double fac = 0.001; + if(mode == 'M') + { + shiftx += fac * (newx - oldx); + shifty += fac * (oldy - newy); + return; + } + else if(mode == 'Z') + { + scalex *= (1 - fac * (newy - oldy)); + scaley *= (1 - fac * (newy - oldy)); + return; + } + + VisualScene::MouseMove(oldx, oldy, newx, newy, mode); + } #ifdef PARALLELGL diff --git a/libsrc/visualization/mvdraw.hpp b/libsrc/visualization/mvdraw.hpp index 94f4c7a5..2f0fa643 100644 --- a/libsrc/visualization/mvdraw.hpp +++ b/libsrc/visualization/mvdraw.hpp @@ -52,9 +52,9 @@ namespace netgen DLL_HEADER void ArbitraryRotation (const NgArray & alpha, const NgArray & vec); DLL_HEADER void ArbitraryRotation (const double alpha, const Vec3d & vec); - DLL_HEADER void MouseMove(int oldx, int oldy, - int newx, int newy, - char mode); + DLL_HEADER virtual void MouseMove(int oldx, int oldy, + int newx, int newy, + char mode); DLL_HEADER void LookAt (const Point<3> & cam, const Point<3> & obj, const Point<3> & camup); @@ -95,16 +95,20 @@ namespace netgen class VisualSceneSurfaceMeshing : public VisualScene { + double scalex = 1., scaley = 1., shiftx = 0., shifty = 0.; public: shared_ptr> locpointsptr; shared_ptr> loclinesptr; shared_ptr> plainpointsptr; + int oldnl; bool clearptr; VisualSceneSurfaceMeshing (); virtual ~VisualSceneSurfaceMeshing (); - virtual void BuildScene (int zoomall = 0); - virtual void DrawScene (); + void BuildScene (int zoomall = 0) override; + void DrawScene () override; + void MouseMove(int oldx, int oldy, int newx, int newy, + char mode) override; }; diff --git a/ng/drawing.tcl b/ng/drawing.tcl index b7e99b9d..3bc7c652 100644 --- a/ng/drawing.tcl +++ b/ng/drawing.tcl @@ -81,6 +81,18 @@ if { $toglok == 1} { .ndraw render set oldmousex %x; set oldmousey %y; } + + bind .ndraw { + Ng_MouseMove $oldmousex $oldmousey %x %y Move2d + .ndraw render + set oldmousex %x; set oldmousey %y; + } + + bind .ndraw { + Ng_MouseMove $oldmousex $oldmousey %x %y Zoom2d + .ndraw render + set oldmousex %x; set oldmousey %y; + } } diff --git a/ng/drawing_togl17.tcl b/ng/drawing_togl17.tcl index be52dfab..36dfe6d2 100644 --- a/ng/drawing_togl17.tcl +++ b/ng/drawing_togl17.tcl @@ -54,6 +54,18 @@ if {[catch {togl .ndraw -width 400 -height 300 -rgba true -double true -depth t .ndraw render set oldmousex %x; set oldmousey %y; } + + bind .ndraw { + Ng_MouseMove $oldmousex $oldmousey %x %y Move2d + .ndraw render + set oldmousex %x; set oldmousey %y; + } + + bind .ndraw { + Ng_MouseMove $oldmousex $oldmousey %x %y Zoom2d + .ndraw render + set oldmousex %x; set oldmousey %y; + } } diff --git a/ng/onetcl.cpp b/ng/onetcl.cpp index 9841677b..a61b1e5a 100644 --- a/ng/onetcl.cpp +++ b/ng/onetcl.cpp @@ -3373,6 +3373,16 @@ const char * ngscript[] = {"" ,".ndraw render\n" ,"set oldmousex %x; set oldmousey %y;\n" ,"}\n" +,"bind .ndraw {\n" +,"Ng_MouseMove $oldmousex $oldmousey %x %y Move2d\n" +,".ndraw render\n" +,"set oldmousex %x; set oldmousey %y;\n" +,"}\n" +,"bind .ndraw {\n" +,"Ng_MouseMove $oldmousex $oldmousey %x %y Zoom2d\n" +,".ndraw render\n" +,"set oldmousex %x; set oldmousey %y;\n" +,"}\n" ,"}\n" ,"proc popupcheckredraw { vari { x 0 } } {\n" ,"upvar $vari varname\n" From f64c736c2bbb3b078d0fe2c3bd9bb8af108b9e05 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Sun, 22 Sep 2019 17:55:43 +0200 Subject: [PATCH 4/4] dll header vssurfacemeshing --- libsrc/meshing/meshing2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index e19406d1..bc292a1b 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -6,6 +6,7 @@ namespace netgen { extern DLL_HEADER void Render(bool blocking = false); static void glrender (int wait); + DLL_HEADER extern VisualSceneSurfaceMeshing vssurfacemeshing; VisualSceneSurfaceMeshing vssurfacemeshing;