From 9e3eb00eb7eb14ce21e89f2b09f48afe3ab48a36 Mon Sep 17 00:00:00 2001 From: Guido Ranzuglia granzuglia Date: Wed, 27 Jul 2016 11:53:42 +0000 Subject: [PATCH] - "show quoted box" moved inside MeshLab core --- src/meshlab/meshlab.pro | 1 + src/meshlab/ml_default_decorators.cpp | 243 +++++++++++++++++++++++++- src/meshlab/ml_default_decorators.h | 5 + src/meshlab/ml_render_gui.cpp | 12 ++ src/meshlab/ml_render_gui.h | 1 + src/meshlab/ml_rendering_actions.cpp | 30 ++++ src/meshlab/ml_rendering_actions.h | 11 ++ 7 files changed, 301 insertions(+), 2 deletions(-) diff --git a/src/meshlab/meshlab.pro b/src/meshlab/meshlab.pro index 1d3e21a58..77a6870fe 100644 --- a/src/meshlab/meshlab.pro +++ b/src/meshlab/meshlab.pro @@ -59,6 +59,7 @@ SOURCES = main.cpp \ ml_default_decorators.cpp \ $$VCGDIR/wrap/gui/trackball.cpp \ $$VCGDIR/wrap/gui/trackmode.cpp \ + $$VCGDIR/wrap/gui/coordinateframe.cpp \ #$$GLEWDIR/src/glew.c \ glarea_setting.cpp \ filterthread.cpp diff --git a/src/meshlab/ml_default_decorators.cpp b/src/meshlab/ml_default_decorators.cpp index 5d20ffc61..597804389 100644 --- a/src/meshlab/ml_default_decorators.cpp +++ b/src/meshlab/ml_default_decorators.cpp @@ -24,7 +24,8 @@ #include "ml_default_decorators.h" #include #include - +#include +#include bool MLDefaultMeshDecorators::updateMeshDecorationData( MeshModel& mesh,const MLRenderingData& previousdata,const MLRenderingData& currentdata ) { @@ -73,7 +74,7 @@ bool MLDefaultMeshDecorators::initMeshDecorationData( MeshModel& m,const MLRende return true; } -void MLDefaultMeshDecorators::decorateMesh( MeshModel & m,const MLRenderingData& dt, QPainter* /*painter*/, GLLogStream& log ) +void MLDefaultMeshDecorators::decorateMesh( MeshModel & m,const MLRenderingData& dt, QPainter* painter, GLLogStream& log ) { MLPerViewGLOptions opts; bool valid = dt.get(opts); @@ -196,6 +197,244 @@ void MLDefaultMeshDecorators::decorateMesh( MeshModel & m,const MLRenderingData& glPopAttrib(); } } + + if (opts._perbbox_enabled) + { + if (opts._perbbox_quoted_info_enabled) + { + QFont qf; + drawQuotedBox(m,painter,qf); + } + } +} + +void MLDefaultMeshDecorators::drawQuotedBox(MeshModel &m,QPainter *gla,QFont& qf) +{ + glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_COLOR_BUFFER_BIT ); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POINT_SMOOTH); + + // Get gl state values + double mm[16],mp[16]; + GLint vp[4]; + glGetDoublev(GL_PROJECTION_MATRIX,mp); + glGetDoublev(GL_MODELVIEW_MATRIX,mm); + glGetIntegerv(GL_VIEWPORT,vp); + + // Mesh boundingBox + Box3m b(m.cm.bbox); + + glLineWidth(1.f); + glPointSize(3.f); + + vcg::Point3d p1,p2; + + Point3m c = b.Center(); + + float s = 1.15f; + const float LabelSpacing = 30; + chooseX(b,mm,mp,vp,p1,p2); // Selects x axis candidate + glPushMatrix(); + glScalef(1,s,s); + glTranslatef(0,c[1]/s-c[1],c[2]/s-c[2]); + drawQuotedLine(p1,p2,b.min[0],b.max[0],vcg::CoordinateFrame::calcSlope(p1,p2,b.DimX(),LabelSpacing,mm,mp,vp),gla,qf); // Draws x axis + glPopMatrix(); + + chooseY(b,mm,mp,vp,p1,p2); // Selects y axis candidate + glPushMatrix(); + glScalef(s,1,s); + glTranslatef(c[0]/s-c[0],0,c[2]/s-c[2]); + drawQuotedLine(p1,p2,b.min[1],b.max[1],vcg::CoordinateFrame::calcSlope(p1,p2,b.DimY(),LabelSpacing,mm,mp,vp),gla,qf); // Draws y axis + glPopMatrix(); + + chooseZ(b,mm,mp,vp,p1,p2); // Selects z axis candidate + glPushMatrix(); + glScalef(s,s,1); + glTranslatef(c[0]/s-c[0],c[1]/s-c[1],0); + drawQuotedLine(p1,p2,b.min[2],b.max[2],vcg::CoordinateFrame::calcSlope(p1,p2,b.DimZ(),LabelSpacing,mm,mp,vp),gla,qf); // Draws z axis + glPopMatrix(); + + glPopAttrib(); + +} + +void MLDefaultMeshDecorators::drawQuotedLine(const vcg::Point3d &a,const vcg::Point3d &b, float aVal, float bVal, float tickScalarDistance, QPainter *painter, QFont& qf,float angle,bool rightAlign) +{ + glPushAttrib(GL_ALL_ATTRIB_BITS); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDisable(GL_LIGHT0); + glDisable(GL_NORMALIZE); + float labelMargin =tickScalarDistance /4.0; + float firstTick; + // fmod returns the floating-point remainder of numerator/denominator (with the sign of the dividend) + // fmod ( 104.5 , 10) returns 4.5 --> aVal - fmod(aval/tick) = 100 + // fmod ( -104.5 , 10) returns -4.5 + // So it holds that + + if(aVal > 0 ) firstTick = aVal - fmod(aVal,tickScalarDistance) + tickScalarDistance; + if(aVal ==0 ) firstTick = tickScalarDistance; + if(aVal < 0 ) firstTick = aVal + fmod(fabs(aVal),tickScalarDistance); + + // now we are sure that aVal < firstTick + // let also be sure that there is enough space + if ( (firstTick-aVal) < (labelMargin) ) + firstTick +=tickScalarDistance; + + + float tickDistTen=tickScalarDistance /10.0f; + float firstTickTen; + if(aVal > 0) firstTickTen = aVal - fmod(aVal,tickDistTen) + tickDistTen; + else firstTickTen = aVal - fmod(aVal,tickDistTen); + + int neededZeros=0; + + vcg::Point3d Zero = a-((b-a)/(bVal-aVal))*aVal; // 3D Position of Zero. + vcg::Point3d v(b-a); + //v.Normalize(); + v = v*(1.0/(bVal-aVal)); + vcg::glLabel::Mode md(qf,vcg::Color4b(vcg::Color4b::White),angle,rightAlign); + if(tickScalarDistance > 0) // Draw lines only if the two endpoint are not coincident + { + neededZeros = std::ceil(std::max(0.0,-std::log10(double(tickScalarDistance)))); + glPointSize(3); + float i; + glBegin(GL_POINTS); + for(i=firstTick;i::max(); + vcg::Point3d c; + // Project the bbox center + gluProject(box.Center()[0],box.Center()[1],box.Center()[2],mm,mp,vp,&c[0],&c[1],&c[2]); + c[2] = 0; + + vcg::Point3d out1,out2; + Point3m in1,in2; + + for (int i=0;i<8;i+=2) + { + // find the furthest axis + in1 = box.P(i); + in2 = box.P(i+1); + + gluProject((double)in1[0],(double)in1[1],(double)in1[2],mm,mp,vp,&out1[0],&out1[1],&out1[2]); + gluProject((double)in2[0],(double)in2[1],(double)in2[2],mm,mp,vp,&out2[0],&out2[1],&out2[2]); + out1[2] = out2[2] = 0; + + float currDist = Distance(c,(out1+out2)*.5f); + + if(currDist > d) + { + d = currDist; + x1.Import(in1); + x2.Import(in2); + } + } +} + + +void MLDefaultMeshDecorators::chooseY(Box3m &box,double *mm,double *mp,GLint *vp,vcg::Point3d &y1,vcg::Point3d &y2) +{ + float d = -std::numeric_limits::max(); + vcg::Point3d c; + // Project the bbox center + gluProject(box.Center()[0],box.Center()[1],box.Center()[2],mm,mp,vp,&c[0],&c[1],&c[2]); + c[2] = 0; + + vcg::Point3d out1,out2; + Point3m in1,in2; + + for (int i=0;i<6;++i) + { + if(i==2) i = 4; // skip + // find the furthest axis + in1 = box.P(i); + in2 = box.P(i+2); + + gluProject((double)in1[0],(double)in1[1],(double)in1[2],mm,mp,vp,&out1[0],&out1[1],&out1[2]); + gluProject((double)in2[0],(double)in2[1],(double)in2[2],mm,mp,vp,&out2[0],&out2[1],&out2[2]); + out1[2] = out2[2] = 0; + + float currDist = Distance(c,(out1+out2)*.5f); + + if(currDist > d) + { + d = currDist; + y1.Import(in1); + y2.Import(in2); + } + } +} + +void MLDefaultMeshDecorators::chooseZ(Box3m &box,double *mm,double *mp,GLint *vp,vcg::Point3d &z1,vcg::Point3d &z2) +{ + float d = -std::numeric_limits::max(); + vcg::Point3d c; + // Project the bbox center + gluProject(box.Center()[0],box.Center()[1],box.Center()[2],mm,mp,vp,&c[0],&c[1],&c[2]); + c[2] = 0; + + vcg::Point3d out1,out2; + Point3m in1,in2; + + vcg::Point3d m; + + for (int i=0;i<4;++i) + { + // find the furthest axis + in1 = box.P(i); + in2 = box.P(i+4); + + + gluProject((double)in1[0],(double)in1[1],(double)in1[2],mm,mp,vp,&out1[0],&out1[1],&out1[2]); + gluProject((double)in2[0],(double)in2[1],(double)in2[2],mm,mp,vp,&out2[0],&out2[1],&out2[2]); + out1[2] = out2[2] = 0; + + float currDist = Distance(c,(out1+out2)*.5f); + + if(currDist > d) + { + d = currDist; + z1.Import(in1); + z2.Import(in2); + } + } } bool MLDefaultMeshDecorators::cleanMeshDecorationData( MeshModel& mesh,const MLRenderingData& dt ) diff --git a/src/meshlab/ml_default_decorators.h b/src/meshlab/ml_default_decorators.h index 29f821bf8..a6ec9d9b2 100644 --- a/src/meshlab/ml_default_decorators.h +++ b/src/meshlab/ml_default_decorators.h @@ -64,4 +64,9 @@ private: static void drawLineVector(std::vector &EV); static void drawTriVector(std::vector &TV); static void drawDotVector(std::vector &TV, float baseSize=4.0f); + static void drawQuotedBox(MeshModel &m,QPainter *gla,QFont& qf); + static void drawQuotedLine(const vcg::Point3d &a,const vcg::Point3d &b, float aVal, float bVal, float tickScalarDistance, QPainter *painter, QFont& qf,float angle = 0,bool rightAlign = false); + static void chooseX(Box3m &box,double *mm,double *mp,GLint *vp,vcg::Point3d &x1,vcg::Point3d &x2); + static void chooseY(Box3m &box,double *mm,double *mp,GLint *vp,vcg::Point3d &y1,vcg::Point3d &y2); + static void chooseZ(Box3m &box,double *mm,double *mp,GLint *vp,vcg::Point3d &z1,vcg::Point3d &z2); }; \ No newline at end of file diff --git a/src/meshlab/ml_render_gui.cpp b/src/meshlab/ml_render_gui.cpp index c7bf9dba2..846c320dc 100644 --- a/src/meshlab/ml_render_gui.cpp +++ b/src/meshlab/ml_render_gui.cpp @@ -531,23 +531,27 @@ MLRenderingBBoxParametersFrame::MLRenderingBBoxParametersFrame( int meshid,QWidg MLRenderingBBoxParametersFrame::~MLRenderingBBoxParametersFrame() { delete _colortool; + delete _quotedinfotool; } void MLRenderingBBoxParametersFrame::getCurrentRenderingDataAccordingToGUI( MLRenderingData& dt ) const { _colortool->getCurrentRenderingDataAccordingToGUI(dt); + _quotedinfotool->getRenderingDataAccordingToGUI(dt); } void MLRenderingBBoxParametersFrame::setPrimitiveButtonStatesAccordingToRenderingData( const MLRenderingData& dt ) { _colortool->setAccordingToRenderingData(dt); + _quotedinfotool->setAccordingToRenderingData(dt); } void MLRenderingBBoxParametersFrame::setAssociatedMeshId( int meshid ) { _meshid = meshid; _colortool->setAssociatedMeshId(meshid); + _quotedinfotool->setAssociatedMeshId(meshid); } void MLRenderingBBoxParametersFrame::initGui() @@ -570,6 +574,14 @@ void MLRenderingBBoxParametersFrame::initGui() layout->addWidget(_colortool,0,1,Qt::AlignLeft); connect(_colortool,SIGNAL(updateRenderingDataAccordingToActions(int,const QList&)),this,SIGNAL(updateRenderingDataAccordingToActions(int,const QList&))); + QLabel* quotedinfolab = new QLabel("Measure Info",this); + quotedinfolab->setFont(boldfont); + layout->addWidget(quotedinfolab,1,0,Qt::AlignLeft); + _quotedinfotool = new MLRenderingOnOffToolbar(_meshid,this); + _quotedinfotool->setRenderingAction(new MLRenderingBBoxQuotedInfoAction(_meshid,this)); + layout->addWidget(_quotedinfotool,1,1,Qt::AlignLeft); + connect(_quotedinfotool,SIGNAL(updateRenderingDataAccordingToAction(int,MLRenderingAction*)),this,SIGNAL(updateRenderingDataAccordingToAction(int,MLRenderingAction*))); + setMinimumSize(layout->sizeHint()); setLayout(layout); showNormal(); diff --git a/src/meshlab/ml_render_gui.h b/src/meshlab/ml_render_gui.h index cedac68cb..d91f7e445 100644 --- a/src/meshlab/ml_render_gui.h +++ b/src/meshlab/ml_render_gui.h @@ -336,6 +336,7 @@ private: void initGui(); MLRenderingToolbar* _colortool; MLRenderingColorPicker* _userdef; + MLRenderingOnOffToolbar* _quotedinfotool; }; class MLRenderingParametersTab : public QTabWidget diff --git a/src/meshlab/ml_rendering_actions.cpp b/src/meshlab/ml_rendering_actions.cpp index 49682ac7d..c522d5572 100644 --- a/src/meshlab/ml_rendering_actions.cpp +++ b/src/meshlab/ml_rendering_actions.cpp @@ -1184,4 +1184,34 @@ MLRenderingFloatAction::MLRenderingFloatAction(int meshid, QObject* parent ) } +MLRenderingBBoxQuotedInfoAction::MLRenderingBBoxQuotedInfoAction( QObject* parent ) + :MLRenderingAction(-1,parent) +{ +} + +MLRenderingBBoxQuotedInfoAction::MLRenderingBBoxQuotedInfoAction( int meshid,QObject* parent ) + :MLRenderingAction(meshid,parent) +{ + +} + +void MLRenderingBBoxQuotedInfoAction::updateRenderingData( MLRenderingData& rd ) +{ + MLPerViewGLOptions opts; + bool valid = rd.get(opts); + if (valid) + { + opts._perbbox_quoted_info_enabled = isChecked(); + rd.set(opts); + } +} + +bool MLRenderingBBoxQuotedInfoAction::isRenderingDataEnabled( const MLRenderingData& rd ) const +{ + MLPerViewGLOptions opts; + bool valid = rd.get(opts); + if (valid) + return opts._perbbox_quoted_info_enabled; + return false; +} diff --git a/src/meshlab/ml_rendering_actions.h b/src/meshlab/ml_rendering_actions.h index c43089cdf..4fb76e6bb 100644 --- a/src/meshlab/ml_rendering_actions.h +++ b/src/meshlab/ml_rendering_actions.h @@ -445,4 +445,15 @@ public: bool isRenderingDataEnabled(const MLRenderingData& rd) const; }; +class MLRenderingBBoxQuotedInfoAction : public MLRenderingAction +{ + Q_OBJECT +public: + MLRenderingBBoxQuotedInfoAction(QObject* parent); + MLRenderingBBoxQuotedInfoAction(int meshid,QObject* parent); + + void updateRenderingData(MLRenderingData& rd); + bool isRenderingDataEnabled(const MLRenderingData& rd) const; +}; + #endif