From ee3f02c29b54082a4f7e24aca0296f44d0ab75c5 Mon Sep 17 00:00:00 2001 From: Kerautret Date: Tue, 18 Apr 2017 14:43:57 +0200 Subject: [PATCH 1/3] add option for ambient light in meshViewer --- ChangeLog.md | 4 ++-- visualisation/meshViewer.cpp | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index e2a0d894..c0da4afb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,8 +4,8 @@ - Improve visualisation tools (vol2heightfield, vol2obj, vol2raw, vol2sdp, vol2slice, volBoundary2obj, 3dImageViewer, 3dVolViewer, sliceViewer, Viewer3DImage) allowing to read longvol including rescaling. (Bertrand Kerautret, [#296](https://github.com/DGtal-team/DGtalTools/pull/296)) - - + - meshViewer: add an option to set the ambient light source. + (Bertrand Kerautret, [#301](https://github.com/DGtal-team/DGtalTools/pull/301)) # DGtalTools 0.9.3 diff --git a/visualisation/meshViewer.cpp b/visualisation/meshViewer.cpp index b40993c1..4c64d830 100644 --- a/visualisation/meshViewer.cpp +++ b/visualisation/meshViewer.cpp @@ -87,6 +87,9 @@ using namespace DGtal; discrete points (used with displaySDP option) -n [ --invertNormal ] threshold min to define binary shape + -A [ --addAmbientLight ] arg(=0) add an ambient light for better display + (between 0 and 1). + -v [ --drawVertex ] draw the vertex of the mesh -d [ --doSnapShotAndExit] arg, save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting. @@ -175,9 +178,10 @@ int main( int argc, char** argv ) ("displayVectorField,f",po::value(), "display a vector field from a simple sdp file (two points per line)" ) ("vectorFieldIndex",po::value >()->multitoken(), "specify special indices for the two point coordinates (instead usinf the default indices: 0 1, 2, 3, 4, 5)" ) ("customLineColor",po::value >()->multitoken(), "set the R, G, B components of the colors of the lines displayed from the --displayVectorField option (red by default). " ) - ("displaySDP,s", po::value(), "Add the display of a set of discrete points as ball of radius 0.5.") + ("displaySDP,s", po::value(), "add the display of a set of discrete points as ball of radius 0.5.") ("SDPradius", po::value()->default_value(0.5), "change the ball radius to display a set of discrete points (used with displaySDP option)") ("invertNormal,n", "invert face normal vectors." ) + ("addAmbientLight,A",po:: value()->default_value(0.0), "add an ambient light for better display (between 0 and 1)." ) ("drawVertex,v", "draw the vertex of the mesh" ) ("doSnapShotAndExit,d", po::value(), "save display snapshot into file. Notes that the camera setting is set by default according the last saved configuration (use SHIFT+Key_M to save current camera setting in the Viewer3D). If the camera setting was not saved it will use the default camera setting." ); @@ -289,16 +293,21 @@ int main( int argc, char** argv ) if(vm.count("doSnapShotAndExit")){ viewer.setSnapshotFileName(QString(vm["doSnapShotAndExit"].as().c_str())); } + std::stringstream title; title << "Simple Mesh Viewer: " << inputFilenameVect[0]; viewer.setWindowTitle(title.str().c_str()); viewer.show(); viewer.myGLLineMinWidth = lineWidth; viewer.setGLScale(sx, sy, sz); - bool invertNormal= vm.count("invertNormal"); - - + bool invertNormal= vm.count("invertNormal"); double ballRadius = vm["SDPradius"].as(); + if(vm.count("addAmbientLight")) + { + float val = vm["addAmbientLight"].as(); + GLfloat lightAmbientCoeffs [4] = {val,val, val, 1.0f}; + viewer.setGLLightAmbientCoefficients(lightAmbientCoeffs); + } trace.info() << "Importing mesh... "; From eecb8d6d2362898dffdceec3451e1ac00d644dc4 Mon Sep 17 00:00:00 2001 From: Kerautret Date: Sat, 22 Apr 2017 14:27:08 +0200 Subject: [PATCH 2/3] add display distance mesh from camera --- visualisation/meshViewer.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/visualisation/meshViewer.cpp b/visualisation/meshViewer.cpp index 4c64d830..91ea8c95 100644 --- a/visualisation/meshViewer.cpp +++ b/visualisation/meshViewer.cpp @@ -138,9 +138,13 @@ class CustomViewer3D: public Viewer3D<> { handled=true; myIsDisplayingInfoMode = !myIsDisplayingInfoMode; - std::stringstream sstring; + stringstream ss; + qglviewer::Vec camPos = camera()->position(); + DGtal::Z3i::RealPoint c (camPos[0], camPos[1], camPos[2]); + ss << myInfoDisplay << "distance to camera: " << (c-centerMesh).norm(); Viewer3D<>::displayMessage(QString(myIsDisplayingInfoMode ? - myInfoDisplay.c_str() : " "), 1000000); + ss.str().c_str() : " "), 1000000); + Viewer3D<>::updateGL(); } if(!handled) @@ -153,6 +157,7 @@ class CustomViewer3D: public Viewer3D<> std::string myInfoDisplay = "No information loaded..."; bool myIsDisplayingInfoMode = false; bool mySaveSnap = false; + DGtal::Z3i::RealPoint centerMesh; }; @@ -317,8 +322,16 @@ int main( int argc, char** argv ) aMesh << inputFilenameVect[i]; vectMesh.push_back(aMesh); } - - + DGtal::Z3i::RealPoint centerMeshes; + unsigned int tot=0; + for(const auto & m: vectMesh) + { + for( auto p = m.vertexBegin(); p!=m.vertexEnd(); ++p) + centerMeshes += *p; + tot+=m.nbVertex(); + } + centerMeshes /= tot; + viewer.centerMesh = centerMeshes; bool import = vectMesh.size()==inputFilenameVect.size(); if(!import){ trace.info() << "File import failed. " << std::endl; @@ -381,7 +394,7 @@ int main( int argc, char** argv ) nbFaces +=m.nbFaces(); } stringstream ss; - ss << "# faces: " << std::fixed << nbFaces << " #vertex: " << nbVertex; + ss << "# faces: " << std::fixed << nbFaces << " #vertex: " << nbVertex ; viewer.myInfoDisplay = ss.str(); viewer << CustomViewer3D::updateDisplay; if(vm.count("doSnapShotAndExit")){ From cbd7368f62381123689178bff6e4ed73bbe0b26a Mon Sep 17 00:00:00 2001 From: Kerautret Date: Sat, 22 Apr 2017 14:31:08 +0200 Subject: [PATCH 3/3] add display distance mesh from camera (space) --- visualisation/meshViewer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visualisation/meshViewer.cpp b/visualisation/meshViewer.cpp index 91ea8c95..aa411af0 100644 --- a/visualisation/meshViewer.cpp +++ b/visualisation/meshViewer.cpp @@ -141,7 +141,7 @@ class CustomViewer3D: public Viewer3D<> stringstream ss; qglviewer::Vec camPos = camera()->position(); DGtal::Z3i::RealPoint c (camPos[0], camPos[1], camPos[2]); - ss << myInfoDisplay << "distance to camera: " << (c-centerMesh).norm(); + ss << myInfoDisplay << " distance to camera: " << (c-centerMesh).norm(); Viewer3D<>::displayMessage(QString(myIsDisplayingInfoMode ? ss.str().c_str() : " "), 1000000);