DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Data Structures | Public Member Functions | Data Fields | Protected Member Functions | Private Attributes
DGtal::Viewer3D Class Reference

#include <Viewer3D.h>

Inheritance diagram for DGtal::Viewer3D:
Inheritance graph
[legend]
Collaboration diagram for DGtal::Viewer3D:
Collaboration graph
[legend]

Data Structures

struct  compFarthestPolygonFromCamera
struct  compFarthestSurfelFromCamera
struct  compFarthestTriangleFromCamera
struct  compFarthestVoxelFromCamera

Public Member Functions

 Viewer3D ()
Viewer3Doperator<< (const DGtal::Color &aColor)
Viewer3Doperator<< (const Display3D::StreamKey &key)
void sortSurfelFromCamera ()
void sortTriangleFromCamera ()
void sortQuadFromCamera ()
void sortPolygonFromCamera ()
template<typename TDrawableWithDisplay3D >
Viewer3Doperator<< (const TDrawableWithDisplay3D &object)
void selfDisplay (std::ostream &out) const
bool isValid () const
- Public Member Functions inherited from DGtal::Display3D
virtual ~Display3D ()
 Display3D ()
virtual void setFillColor (DGtal::Color aColor)
virtual void setLineColor (DGtal::Color aColor)
virtual DGtal::Color getFillColor ()
virtual DGtal::Color getLineColor ()
virtual void addClippingPlane (double a, double b, double c, double d, bool drawPlane)
virtual void setCameraUpVector (double, double, double)
virtual void setCameraPosition (double, double, double)
virtual void setNearFar (double, double)
virtual void setCameraDirection (double, double, double)
virtual std::string getMode (const std::string &objectName) const
virtual void createNewLineList ()
virtual void createNewPointList ()
virtual void createNewVoxelList (bool depthTest=true)
virtual void addQuad (double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4, DGtal::Color aColor)
virtual void addTriangle (double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, DGtal::Color aColor)
virtual void addPolygon (std::vector< pointD3D > vectPointsPolygon, DGtal::Color aColor)
virtual void addLine (double x1, double y1, double z1, double x2, double y2, double z2, const DGtal::Color &color=DGtal::Color(20, 20, 20, 200), double width=1.5)
virtual void addVoxel (DGtal::int64_t x, DGtal::int64_t y, DGtal::int64_t z, DGtal::Color color=DGtal::Color(220, 220, 220), double width=0.5, bool withWire=false)
virtual void addPoint (double x, double y, double z, const DGtal::Color &color=DGtal::Color(200, 20, 20), double size=40)
virtual void addKSSurfel (double x, double y, double z, bool xSurfel, bool ySurfel, bool zSurfel, double sizeShiftFactor, double positionShift=0.0, double sizeFactor=1.0, bool isSigned=false, bool aSign=true, bool basicMode=false)
virtual void addKSVoxel (int x, int y, int z, double sizeFactor=0.94)
virtual void addKSPointel (double x, double y, double z, double size=0.1, bool isSigned=false, bool aSign=true)
virtual void addKSLinel (double x1, double y1, double z1, double x2, double y2, double z2, double width=0.02, bool isSigned=false, bool aSign=true)
void updateBoundingBox (double x, double y, double z)
void exportToMesh (MeshFromPoints< Display3D::pointD3D > &aMesh) const
void setScale (float sx, float sy, float sz)

Data Fields

DGtal::Color myDefaultBackgroundColor
DGtal::Color myDefaultColor
bool myIsBackgroundDefault
bool myViewWire
- Data Fields inherited from DGtal::Display3D
ModeMapping myModes
StyleMapping myStyles
bool myBoundingPtEmptyTag
double myBoundingPtUp [3]
double myBoundingPtLow [3]

Protected Member Functions

void updateList (bool needToUpdateBoundingBox=true)
void glDrawGLLinel (lineD3D aLinel)
void glDrawGLPointel (pointD3D pointel)
virtual void keyPressEvent (QKeyEvent *e)
virtual void drawWithNames ()
virtual void draw ()
virtual void init ()
virtual QString helpString () const
virtual void postSelection (const QPoint &point)

Private Attributes

GLuint myListToAff
unsigned int myNbListe
qglviewer::Vec myOrig
qglviewer::Vec myDir
qglviewer::Vec myDirSelector
qglviewer::Vec mySelectedPoint
QPoint myPosSelector

Additional Inherited Members

- Public Types inherited from DGtal::Display3D
enum  StreamKey { addNewList, updateDisplay, shiftSurfelVisu }
typedef std::map< std::string,
std::string > 
ModeMapping
typedef std::map< std::string,
CountedPtr
< DrawableWithDisplay3D > > 
StyleMapping
- Protected Attributes inherited from DGtal::Display3D
float myScaleX
float myScaleY
float myScaleZ
DGtal::Color myCurrentFillColor
DGtal::Color myCurrentLineColor
double myCurrentfShiftVisuKSSurfels
std::vector< std::vector
< voxelD3D > > 
myVoxelSetList
std::vector< std::vector
< lineD3D > > 
myLineSetList
std::vector< std::vector
< pointD3D > > 
myPointSetList
std::vector< clippingPlaneD3DmyClippingPlaneList
std::vector< quadD3DmyKSSurfelList
std::vector< pointD3DmyKSPointelList
std::vector< lineD3DmyKSLinelList
std::vector< quadD3DmyQuadList
std::vector< triangleD3DmyTriangleList
std::vector< polygonD3DmyPolygonList
std::vector< bool > myListVoxelDepthTest
float myMeshDefaultLineWidth

Detailed Description

Aim: Display 3D primitive (like PointVector, DigitalSetBySTLSet, Object ...). This class uses the libQGLViewer library (http://www.libqglviewer.com ). It inherits of the class Display3D and permits to display object using a simple stream mechanism of "<<".

Description of class 'Viewer3D'

For instance you can display objects as follows:

#include <QtGui/qapplication.h>
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/Viewer3D.h"
...
using namespace Z3i;
...
Point p1( 0, 0, 0 );
Point p2( 5, 5 ,5 );
Point p3( 2, 3, 4 );
Domain domain( p1, p2 );
Viewer3D viewer;
viewer.show();
viewer << domain;
viewer << p1 << p2 << p3;
return application.exec();
See also:
Display3D, Board3DTo2D
Examples:
geometry/surfaces/greedy-plane-segmentation-ex2.cpp, geometry/surfaces/greedy-plane-segmentation.cpp, io/digitalSetFromPointList.cpp, io/digitalSetFromVol.cpp, io/meshFromOFF.cpp, io/viewers/viewer3D-1-points.cpp, io/viewers/viewer3D-2-sets.cpp, io/viewers/viewer3D-3-objects.cpp, io/viewers/viewer3D-4-modes.cpp, io/viewers/viewer3D-4bis-illustrationMode.cpp, io/viewers/viewer3D-5-custom.cpp, io/viewers/viewer3D-6-clipping.cpp, topology/3dBorderExtraction.cpp, topology/3dBorderExtractionImg.cpp, topology/3dKSSurfaceExtraction.cpp, topology/ctopo-1-3d.cpp, topology/ctopo-1s-3d.cpp, topology/ctopo-2-3d.cpp, topology/frontierAndBoundary.cpp, topology/homotopicThinning3D.cpp, topology/volScanBoundary.cpp, and topology/volTrackBoundary.cpp.

Definition at line 112 of file Viewer3D.h.


Constructor & Destructor Documentation

DGtal::Viewer3D::Viewer3D ( )
inline

Constructor

Definition at line 121 of file Viewer3D.h.

:QGLViewer(), Display3D()
{
};

Member Function Documentation

void DGtal::Viewer3D::draw ( )
protectedvirtual

Definition at line 105 of file Viewer3D.cpp.

References DGtal::Display3D::clippingPlaneD3D::a, DGtal::Display3D::clippingPlaneD3D::b, DGtal::Display3D::clippingPlaneD3D::c, and DGtal::Display3D::clippingPlaneD3D::d.

{
glPushMatrix();
glMultMatrixd ( manipulatedFrame()->matrix() );
glPushMatrix();
glScalef(myScaleX, myScaleY, myScaleZ);
for ( unsigned int i =0; i< myClippingPlaneList.size(); i++ )
{
clippingPlaneD3D cp = myClippingPlaneList.at ( i );
double eq [4];
eq[0]=cp.a;
eq[1]=cp.b;
eq[2]=cp.c;
eq[3]=cp.d;
glEnable ( GL_CLIP_PLANE0+i );
glClipPlane ( GL_CLIP_PLANE0+i, eq );
}
Vec centerS = sceneCenter();
Vec posCam = camera()->position();
double distCam =sqrt ( ( posCam.x-centerS.x ) * ( posCam.x-centerS.x ) +
( posCam.y-centerS.y ) * ( posCam.y-centerS.y ) +
( posCam.z-centerS.z ) * ( posCam.z-centerS.z ) );
for ( unsigned int i=0; i<myPointSetList.size(); i++ )
{
if ( myPointSetList.at ( i ).size() !=0 )
{
glPointSize ( ( myPointSetList.at ( i ).at ( 0 ).size ) /distCam );
}
glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +myLineSetList.size() +i+1 ) );
}
for ( unsigned int i=0; i<myLineSetList.size(); i++ )
{
if ( myLineSetList.at ( i ).size() !=0 )
{
glLineWidth ( ( myLineSetList.at ( i ).at ( 0 ).width ) );
}
glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +1+i ) );
}
glCallList ( GLuint ( myListToAff+myVoxelSetList.size() ) );
for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
{
glCallList ( myListToAff+i );
}
// Calling lists associated to Mesh display (see. updateList)
unsigned int nbListOfPrimitives = myLineSetList.size() +myVoxelSetList.size() + myPointSetList.size();
glLineWidth ( myMeshDefaultLineWidth /distCam );
glDisable(GL_CULL_FACE);
glCallList ( GLuint ( myListToAff+nbListOfPrimitives+1 ) );
glLineWidth ( myMeshDefaultLineWidth /distCam );
glCallList ( GLuint ( myListToAff+nbListOfPrimitives+2 ) );
}
glDisable(GL_CULL_FACE);
glCallList ( GLuint ( myListToAff+nbListOfPrimitives+3 ) );
glLineWidth ( myMeshDefaultLineWidth /distCam );
glCallList ( GLuint ( myListToAff+nbListOfPrimitives+4 ) );
}
glDisable(GL_CULL_FACE);
glCallList ( GLuint ( myListToAff+nbListOfPrimitives+5 ) );
glLineWidth ( myMeshDefaultLineWidth /distCam );
glCallList ( GLuint ( myListToAff+nbListOfPrimitives+6 ) );
}
// Drawing all Khalimsky Space Cells
for ( unsigned int i=0; i< myKSPointelList.size(); i++ )
{
}
for ( unsigned int i=0; i< myKSLinelList.size(); i++ )
{
}
// Drawing all Khalimsky Space Cells
for ( unsigned int i=0; i< myKSPointelList.size(); i++ )
{
}
for ( unsigned int i=0; i< myKSLinelList.size(); i++ )
{
}
// Drawing all Khalimsky Space Cells
for ( unsigned int i=0; i< myKSPointelList.size(); i++ )
{
}
for ( unsigned int i=0; i< myKSLinelList.size(); i++ )
{
}
glPopMatrix();
glPopMatrix();
}
void DGtal::Viewer3D::drawWithNames ( )
protectedvirtual

Definition at line 86 of file Viewer3D.cpp.

{
for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
{
glCallList ( myListToAff+i );
}
for ( unsigned int i=0; i<myLineSetList.size(); i++ )
{
glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +i ) );
}
for ( unsigned int i=0; i<myPointSetList.size(); i++ )
{
glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +myLineSetList.size() +i ) );
}
}
void DGtal::Viewer3D::glDrawGLLinel ( lineD3D  aLinel)
protected

Draw a linel by using the [gluCylinder] primitive.

Definition at line 703 of file Viewer3D.cpp.

References DGtal::Display3D::lineD3D::B, DGtal::Display3D::lineD3D::G, DGtal::Display3D::lineD3D::isSigned, DGtal::Display3D::lineD3D::R, DGtal::Display3D::lineD3D::signPos, DGtal::Display3D::lineD3D::T, DGtal::Display3D::lineD3D::width, DGtal::Display3D::lineD3D::x1, DGtal::Display3D::lineD3D::x2, DGtal::Display3D::lineD3D::y1, DGtal::Display3D::lineD3D::y2, DGtal::Display3D::lineD3D::z1, and DGtal::Display3D::lineD3D::z2.

{
glPushMatrix();
glTranslatef ( aLinel.x1, aLinel.y1, aLinel.z1 );
Vec dir ( aLinel.x2-aLinel.x1, aLinel.y2-aLinel.y1, aLinel.z2-aLinel.z1 );
glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
GLUquadric* quadric = gluNewQuadric();
glColor4ub ( aLinel.R, aLinel.G, aLinel.B, aLinel.T );
gluCylinder ( quadric, ( aLinel.signPos || !aLinel.isSigned ) ? aLinel.width :0 ,
( aLinel.signPos && aLinel.isSigned ) ? 0 :aLinel.width ,
dir.norm(),10, 4 );
glPopMatrix();
}
void DGtal::Viewer3D::glDrawGLPointel ( pointD3D  pointel)
protected

Draw a linel by using the [gluCSphere] primitive.

Definition at line 723 of file Viewer3D.cpp.

References DGtal::Display3D::pointD3D::B, DGtal::Display3D::pointD3D::G, DGtal::Display3D::pointD3D::isSigned, DGtal::Display3D::pointD3D::R, DGtal::Display3D::pointD3D::signPos, DGtal::Display3D::pointD3D::size, DGtal::Display3D::pointD3D::T, DGtal::Display3D::pointD3D::x, DGtal::Display3D::pointD3D::y, and DGtal::Display3D::pointD3D::z.

{
if ( !pointel.isSigned )
{
glPushMatrix();
glTranslatef ( pointel.x, pointel.y, pointel.z );
GLUquadric* quadric = gluNewQuadric();
glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
gluSphere ( quadric, pointel.size, 10, 10 );
glPopMatrix();
}
else
{
// a small "+" is drawn with cylinder
if ( pointel.signPos )
{
glPushMatrix();
glTranslatef ( pointel.x-0.07, pointel.y-0.07, pointel.z );
Vec dir ( 0.14, 0.14, 0 );
glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
GLUquadric* quadric = gluNewQuadric();
glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
gluCylinder ( quadric, pointel.size/3.0 , pointel.size/3.0,
dir.norm(),10, 4 );
glPopMatrix();
glPushMatrix();
glTranslatef ( pointel.x-0.07, pointel.y+0.07, pointel.z );
dir=Vec ( 0.14, -0.14, 0 );
glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
quadric = gluNewQuadric();
glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
gluCylinder ( quadric, pointel.size/3.0 , pointel.size/3.0,
dir.norm(),10, 4 );
glPopMatrix();
}
else
{
glPushMatrix();
glTranslatef ( pointel.x, pointel.y+0.07, pointel.z-0.07 );
Vec dir ( 0.0, -0.14, 0.14 );
glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
GLUquadric* quadric = gluNewQuadric();
glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
gluCylinder ( quadric, pointel.size/4.0 , pointel.size/4.0,
dir.norm(),10, 4 );
glPopMatrix();
}
}
}
QString DGtal::Viewer3D::helpString ( ) const
protectedvirtual

Definition at line 905 of file Viewer3D.cpp.

{
QString text ( "<h2> Viewer3D</h2>" );
text += "Use the mouse to move the camera around the object. ";
text += "You can respectively revolve around, zoom and translate with the three mouse buttons. ";
text += "Left and middle buttons pressed together rotate around the camera view direction axis<br><br>";
text += "Pressing <b>Alt</b> and one of the function keys (<b>F1</b>..<b>F12</b>) defines a camera keyFrame. ";
text += "Simply press the function key again to restore it. Several keyFrames define a ";
text += "camera path. Paths are saved when you quit the application and restored at next start.<br><br>";
text += "Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, ";
text += "<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save a snapshot. ";
text += "See the <b>Keyboard</b> tab in this window for a complete shortcut list.<br><br>";
text += "Double clicks automates single click actions: A left button double click aligns the closer axis with the camera (if close enough). ";
text += "A middle button double click fits the zoom of the camera and the right button re-centers the scene.<br><br>";
text += "A left button double click while holding right button pressed defines the camera <i>Revolve Around Point</i>. ";
text += "See the <b>Mouse</b> tab and the documentation web pages for details.<br><br>";
text += "Press <b>Escape</b> to exit the viewer.";
return text;
}
void DGtal::Viewer3D::init ( )
protectedvirtual

Definition at line 248 of file Viewer3D.cpp.

{
myViewWire=true;
vector<lineD3D> listeLine;
myLineSetList.push_back ( listeLine );
vector<pointD3D> listePoint;
myPointSetList.push_back ( listePoint );
myCurrentFillColor = Color ( 220, 220, 220 );
myCurrentLineColor = Color ( 22, 22, 222, 50 );
myDefaultBackgroundColor = Color ( backgroundColor().red(), backgroundColor().green(),
backgroundColor().blue() );
myBoundingPtLow[0]=numeric_limits<double>::max( );
myBoundingPtLow[1]=numeric_limits<double>::max( );
myBoundingPtLow[2]=numeric_limits<double>::max( );
myBoundingPtUp[0]=numeric_limits<double>::min( );
myBoundingPtUp[1]=numeric_limits<double>::min( );
myBoundingPtUp[2]=numeric_limits<double>::min( );
std::vector<voxelD3D> aKSVoxelList;
myDefaultColor= Color ( 255, 255, 255 );
camera()->showEntireScene();
setKeyDescription ( Qt::Key_E, "Export the current display into OFF file (just Voxel, surfel and KSSurfel for now)." );
setKeyDescription ( Qt::Key_W, "Switch display with and without wired view of triangle and quad faces." );
setKeyDescription ( Qt::Key_T, "Sort elements for display improvements." );
setKeyDescription ( Qt::Key_L, "Load last visualisation settings." );
setKeyDescription ( Qt::Key_B, "Switch background color with White/Black colors." );
setKeyDescription ( Qt::Key_C, "Show camera informations." );
setKeyDescription ( Qt::Key_R, "Reset default scale for 3 axes to 1.0f." );
setMouseBindingDescription ( Qt::ShiftModifier+Qt::RightButton, "Delete the mouse selected list." );
setManipulatedFrame ( new ManipulatedFrame() );
}
bool DGtal::Viewer3D::isValid ( ) const

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Reimplemented from DGtal::Display3D.

Definition at line 75 of file Viewer3D.cpp.

{
return true;
}
void DGtal::Viewer3D::keyPressEvent ( QKeyEvent *  e)
protectedvirtual

Used to manage new key event (wich are added from the default QGLviewer keys).

Note that when a new key event is taken into account it could be added in the QGLviewer init() method to update automatically the key description in the help QGLviewer window. For instance when a new key is processed in this method you simply should add the following code in the init() method:

setKeyDescription(Qt::Key_NEW, "Description of the new Key.");
Parameters:
e,:the QKeyEvent

Definition at line 779 of file Viewer3D.cpp.

References DGtal::Trace::info(), and DGtal::trace.

{
bool handled = false;
if( e->key() == Qt::Key_E){
trace.info() << "Exporting mesh..." ;
(*this) >> "exportedMesh.off";
trace.info() << "[done]"<< endl ;
}
if ( ( e->key() ==Qt::Key_W ) )
{
updateList(false);
updateGL();
}
if ( ( e->key() ==Qt::Key_R ) )
{
myScaleX=1.0f;
myScaleY=1.0f;
myScaleZ=1.0f;
updateGL();
}
if ( ( e->key() ==Qt::Key_T ) )
{
handled=true;
DGtal::trace.info() << "sorting surfel according camera position....";
DGtal::trace.info() << " [done]"<< std::endl;
updateList(false);
updateGL();
}
if ( ( e->key() ==Qt::Key_B ) )
{
handled=true;
{
setBackgroundColor ( QColor ( 255, 255,255 ) );
}
else
{
setBackgroundColor ( QColor ( 51, 51, 51 ) );
}
updateGL();
}
if ( ( e->key() ==Qt::Key_L ) )
{
restoreStateFromFile();
updateGL();
}
if ( ( e->key() ==Qt::Key_C ) ) // MT
{
handled=true;
GLint Viewport[4];
GLdouble Projection[16], Modelview[16];
//Unused matrix so I remove it (DC)
//GLdouble matrix[16];
// Precomputation begin
glGetIntegerv ( GL_VIEWPORT , Viewport );
glGetDoublev ( GL_MODELVIEW_MATRIX , Modelview );
glGetDoublev ( GL_PROJECTION_MATRIX, Projection );
for ( unsigned short m=0; m<4; ++m )
{
for ( unsigned short l=0; l<4; ++l )
{
double sum = 0.0;
for ( unsigned short k=0; k<4; ++k )
sum += Projection[l+4*k]*Modelview[k+4*m];
//matrix[l+4*m] = sum;
}
}
// Precomputation end
// print
DGtal::trace.info() << "Viewport: ";
for ( unsigned short l=0; l<4; ++l )
DGtal::trace.info() << Viewport[l] << ", ";
DGtal::trace.info() << std::endl;
Vec cp = camera()->position();
Vec cd = camera()->viewDirection();
Vec cup = camera()->upVector();
DGtal::trace.info() << "camera.position: " ;
for ( unsigned short l=0; l<3; ++l )
DGtal::trace.info() << cp[l] << ", ";
DGtal::trace.info() << std::endl;
DGtal::trace.info() << "camera.direction: ";
for ( unsigned short l=0; l<3; ++l )
DGtal::trace.info() << cd[l] << ", ";
DGtal::trace.info() << std::endl;
DGtal::trace.info() << "camera.upVector: ";
for ( unsigned short l=0; l<3; ++l )
DGtal::trace.info() << cup[l] << ", ";
DGtal::trace.info() << std::endl;
DGtal::trace.info() << "zNear: " << camera()->zNear() << " - zFar: " << camera()->zFar() << std::endl;
// print
}
if ( !handled )
}
DGtal::Viewer3D & DGtal::Viewer3D::operator<< ( const DGtal::Color aColor)
inline

Set the default color for future drawing.

Parameters:
aColor,:a DGtal::Color (allow to set a trasnparency value).

Definition at line 48 of file Viewer3D.ih.

References myDefaultColor.

{
return *this;
}
DGtal::Viewer3D & DGtal::Viewer3D::operator<< ( const Display3D::StreamKey key)
inline

Set the default color for future drawing.

Parameters:
aColor,:a DGtal::Color (allow to set a trasnparency value).

Set the default color for future drawing.

Parameters:
aColor,:a DGtal::Color (allow to set a transparency value).

Definition at line 65 of file Viewer3D.ih.

References DGtal::Display3D::addNewList, DGtal::Display3D::shiftSurfelVisu, and DGtal::Display3D::updateDisplay.

{
switch (key){
break;
break;
break;
}
return *this;
}
template<typename TDrawableWithDisplay3D >
DGtal::Viewer3D & DGtal::Viewer3D::operator<< ( const TDrawableWithDisplay3D &  object)
inline

Draws the drawable [object] in this board. It should satisfy the concept CDrawableWithViewer3D, which requires for instance a method setStyle( Viewer3D & ).

Parameters:
objectany drawable object.
Returns:
a reference on 'this'.

Reimplemented from DGtal::Display3D.

Definition at line 88 of file Viewer3D.ih.

References DGtal::Display3DFactory::draw().

{
return *this;
}
void DGtal::Viewer3D::postSelection ( const QPoint &  point)
protectedvirtual

Definition at line 357 of file Viewer3D.cpp.

References DGtal::abs(), DGtal::Trace::info(), and DGtal::trace.

{
camera()->convertClickToLine ( point, myOrig, myDir );
bool found;
this->myPosSelector= point;
mySelectedPoint = camera()->pointUnderPixel ( point, found );
if ( found )
{
DGtal::trace.info() << "Element of liste= " << selectedName() << "selected" << endl;
if ( selectedName() !=-1 )
{
unsigned int id = abs ( selectedName()-1 );
if ( id< myVoxelSetList.size() )
{
DGtal::trace.info() << "deleting list="<< id<<endl;
myVoxelSetList.erase ( myVoxelSetList.begin() +id );
updateList ( false );
}
else if ( id< myVoxelSetList.size() +myLineSetList.size() )
{
myLineSetList.erase ( myLineSetList.begin() + ( id-myVoxelSetList.size() ) );
updateList ( false );
}
else if ( id< myPointSetList.size() +myLineSetList.size() +myVoxelSetList.size() )
{
myPointSetList.erase ( myPointSetList.begin() + ( id-myVoxelSetList.size()-myLineSetList.size() ) );
updateList ( false );
}
}
}
}
void DGtal::Viewer3D::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Reimplemented from DGtal::Display3D.

Definition at line 65 of file Viewer3D.cpp.

{
out << "[Viewer3D]";
}
void DGtal::Viewer3D::sortPolygonFromCamera ( )

Sort all polygons from the camera.

Definition at line 342 of file Viewer3D.cpp.

References DGtal::Trace::info(), DGtal::Viewer3D::compFarthestPolygonFromCamera::posCam, and DGtal::trace.

{
compFarthestPolygonFromCamera comp;
comp.posCam= camera()->position();
DGtal::trace.info() << "sort polygon size" << myPolygonList.size() << std::endl;
sort ( myPolygonList.begin(), myPolygonList.end(), comp );
}
void DGtal::Viewer3D::sortQuadFromCamera ( )

Sort all triangle from the camera.

Definition at line 329 of file Viewer3D.cpp.

References DGtal::Trace::info(), DGtal::Viewer3D::compFarthestSurfelFromCamera::posCam, and DGtal::trace.

{
compFarthestSurfelFromCamera comp;
comp.posCam= camera()->position();
DGtal::trace.info() << "sort quad size" << myTriangleList.size() << std::endl;
sort ( myQuadList.begin(), myQuadList.end(), comp );
}
void DGtal::Viewer3D::sortSurfelFromCamera ( )

Sort all surfels from the camera.

Definition at line 299 of file Viewer3D.cpp.

References DGtal::Trace::info(), DGtal::Viewer3D::compFarthestVoxelFromCamera::posCam, and DGtal::trace.

{
compFarthestVoxelFromCamera comp;
comp.posCam= camera()->position();
for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
{
sort ( myVoxelSetList.at ( i ).begin(), myVoxelSetList.at ( i ).end(), comp );
}
compFarthestSurfelFromCamera compSurf;
DGtal::trace.info() << "sort surfel size" << myKSSurfelList.size() << std::endl;
sort ( myKSSurfelList.begin(), myKSSurfelList.end(), compSurf );
}
void DGtal::Viewer3D::sortTriangleFromCamera ( )

Sort all triangle from the camera.

Definition at line 315 of file Viewer3D.cpp.

References DGtal::Trace::info(), DGtal::Viewer3D::compFarthestTriangleFromCamera::posCam, and DGtal::trace.

{
compFarthestTriangleFromCamera comp;
comp.posCam= camera()->position();
DGtal::trace.info() << "sort triangle size" << myTriangleList.size() << std::endl;
sort ( myTriangleList.begin(), myTriangleList.end(), comp );
}
void DGtal::Viewer3D::updateList ( bool  needToUpdateBoundingBox = true)
protected

Permit to update the OpenGL list to be displayed. Need to called after a number of addVoxel or after a sortSurfelFromCamera().

Creation of new lists to display 3D mesh First list: quad faces. Second list: Wired version of quad face. Third list: Triangle faces. Fourth list: Wired version of triangle face. Fifth list: Polygonal faces. Sixth list: Wired version of polygonal face.

Definition at line 395 of file Viewer3D.cpp.

{
// Additionnaly to the primitive list (of myVoxelSetList myLineSetList.size() myPointSetList.size()) we add
// 6 new lists associated to the mesh Display.
unsigned int nbList= ( unsigned int ) ( myVoxelSetList.size() + myLineSetList.size() + myPointSetList.size() +6 );
glDeleteLists ( myListToAff, myNbListe );
myListToAff = glGenLists ( nbList );
unsigned int listeID=0;
glEnable ( GL_BLEND );
glEnable ( GL_MULTISAMPLE_ARB );
glEnable ( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
{
glNewList ( myListToAff+i, GL_COMPILE );
if ( myListVoxelDepthTest.at ( i ) )
{
glEnable ( GL_DEPTH_TEST );
}
else
{
glDisable ( GL_DEPTH_TEST );
}
glPushName ( myNbListe );
glBegin ( GL_QUADS );
for ( std::vector<voxelD3D>::iterator s_it = myVoxelSetList.at ( i ).begin();
s_it != myVoxelSetList.at ( i ).end();
++s_it )
{
glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
double _width= ( *s_it ).width;
//z+
glNormal3f ( 0.0, 0.0, 1.0 );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
//z-
glNormal3f ( 0.0, 0.0, -1.0 );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
//x+
glNormal3f ( 1.0, 0.0, 0.0 );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
//x-
glNormal3f ( -1.0, 0.0, 0.0 );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
//y+
glNormal3f ( 0.0, 1.0, 0.0 );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
//y-
glNormal3f ( 0.0, -1.0, 0.0 );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
}
glEnd();
glEndList();
}
glNewList ( GLuint ( myListToAff+myVoxelSetList.size() ), GL_COMPILE );
glPushName ( myNbListe );
glEnable ( GL_DEPTH_TEST );
glEnable ( GL_BLEND );
glEnable ( GL_MULTISAMPLE_ARB );
glEnable ( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glBegin ( GL_QUADS );
glEnable ( GL_DEPTH_TEST );
for ( std::vector<quadD3D>::iterator s_it = myKSSurfelList.begin();
s_it != myKSSurfelList.end();
++s_it )
{
glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
glNormal3f ( ( *s_it ).nx, ( *s_it ).ny, ( *s_it ).nz );
glVertex3f ( ( *s_it ).x1, ( *s_it ).y1 , ( *s_it ).z1 );
glVertex3f ( ( *s_it ).x2, ( *s_it ).y2 , ( *s_it ).z2 );
glVertex3f ( ( *s_it ).x3, ( *s_it ).y3 , ( *s_it ).z3 );
glVertex3f ( ( *s_it ).x4, ( *s_it ).y4 , ( *s_it ).z4 );
}
glEnd();
glEndList();
for ( unsigned int i=0; i<myLineSetList.size(); i++ )
{
listeID++;
glNewList ( GLuint ( myListToAff+myVoxelSetList.size() +i+1 ), GL_COMPILE );
glDisable ( GL_LIGHTING );
glPushName ( myNbListe );
glBegin ( GL_LINES );
for ( std::vector<lineD3D>::iterator s_it = myLineSetList.at ( i ).begin();
s_it != myLineSetList.at ( i ).end();
++s_it )
{
glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
glVertex3f ( ( *s_it ).x1, ( *s_it ).y1, ( *s_it ).z1 );
glVertex3f ( ( *s_it ).x2, ( *s_it ).y2, ( *s_it ).z2 );
}
glEnd();
glEnable ( GL_LIGHTING );
glEndList();
}
for ( unsigned int i=0; i<myPointSetList.size(); i++ )
{
glNewList ( GLuint ( myListToAff+myLineSetList.size() +myVoxelSetList.size() +i+1 ), GL_COMPILE );
glDepthMask ( GL_TRUE );
glDisable ( GL_TEXTURE_2D );
glDisable ( GL_POINT_SMOOTH );
glDisable ( GL_LIGHTING );
glPushName ( myNbListe );
glBegin ( GL_POINTS );
for ( std::vector<pointD3D>::iterator s_it = myPointSetList.at ( i ).begin();
s_it != myPointSetList.at ( i ).end();
++s_it )
{
glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
glVertex3f ( ( *s_it ).x, ( *s_it ).y, ( *s_it ).z );
}
glEnd();
glEnable ( GL_LIGHTING );
glEndList();
}
unsigned int nbListOfPrimitives = myLineSetList.size() +myVoxelSetList.size() + myPointSetList.size();
// First List (quad faces)
glNewList ( GLuint ( myListToAff +nbListOfPrimitives + 1 ), GL_COMPILE );
glPushName ( myNbListe );
glEnable ( GL_LIGHTING );
glBegin ( GL_QUADS );
for ( unsigned int i=0; i<myQuadList.size(); i++ )
{
glColor4ub ( myQuadList.at ( i ).R, myQuadList.at ( i ).G, myQuadList.at ( i ).B, myQuadList.at ( i ).T );
glNormal3f ( -myQuadList.at ( i ).nx, -myQuadList.at ( i ).ny ,-myQuadList.at ( i ).nz );
glVertex3f ( myQuadList.at ( i ).x1, myQuadList.at ( i ).y1, myQuadList.at ( i ).z1 );
glVertex3f ( myQuadList.at ( i ).x2, myQuadList.at ( i ).y2, myQuadList.at ( i ).z2 );
glVertex3f ( myQuadList.at ( i ).x3, myQuadList.at ( i ).y3, myQuadList.at ( i ).z3 );
glVertex3f ( myQuadList.at ( i ).x4, myQuadList.at ( i ).y4, myQuadList.at ( i ).z4 );
}
glEnd();
glEndList();
// Second list: Wired version of quad face.
glNewList ( GLuint ( myListToAff +nbListOfPrimitives + 2 ), GL_COMPILE );
glPushName ( myNbListe );
glDisable ( GL_LIGHTING );
glBegin ( GL_LINES );
for ( unsigned int i=0; i<myQuadList.size(); i++ )
{
glColor4ub ( 150.0,150.0,150.0,255.0 );
glVertex3f ( myQuadList.at ( i ).x1, myQuadList.at ( i ).y1, myQuadList.at ( i ).z1 );
glVertex3f ( myQuadList.at ( i ).x2, myQuadList.at ( i ).y2, myQuadList.at ( i ).z2 );
glVertex3f ( myQuadList.at ( i ).x2, myQuadList.at ( i ).y2, myQuadList.at ( i ).z2 );
glVertex3f ( myQuadList.at ( i ).x3, myQuadList.at ( i ).y3, myQuadList.at ( i ).z3 );
glVertex3f ( myQuadList.at ( i ).x3, myQuadList.at ( i ).y3, myQuadList.at ( i ).z3 );
glVertex3f ( myQuadList.at ( i ).x4, myQuadList.at ( i ).y4, myQuadList.at ( i ).z4 );
glVertex3f ( myQuadList.at ( i ).x4, myQuadList.at ( i ).y4, myQuadList.at ( i ).z4 );
glVertex3f ( myQuadList.at ( i ).x1, myQuadList.at ( i ).y1, myQuadList.at ( i ).z1 );
}
glEnable ( GL_LIGHTING );
glEnd();
glEndList();
// Third list: Triangle faces.
glNewList ( GLuint (myListToAff +nbListOfPrimitives + 3 ), GL_COMPILE );
glPushName ( myNbListe );
glEnable ( GL_LIGHTING );
glBegin ( GL_TRIANGLES );
for ( unsigned int i=0; i<myTriangleList.size(); i++ )
{
glColor4ub ( myTriangleList.at ( i ).R, myTriangleList.at ( i ).G, myTriangleList.at ( i ).B, myTriangleList.at ( i ).T );
glNormal3f ( -myTriangleList.at ( i ).nx, -myTriangleList.at ( i ).ny ,-myTriangleList.at ( i ).nz );
glVertex3f ( myTriangleList.at ( i ).x1, myTriangleList.at ( i ).y1, myTriangleList.at ( i ).z1 );
glVertex3f ( myTriangleList.at ( i ).x2, myTriangleList.at ( i ).y2, myTriangleList.at ( i ).z2 );
glVertex3f ( myTriangleList.at ( i ).x3, myTriangleList.at ( i ).y3, myTriangleList.at ( i ).z3 );
}
glEnd();
glEndList();
// Fourth list: Wired version of triangle face.
glNewList ( GLuint ( myListToAff + nbListOfPrimitives +4), GL_COMPILE );
glPushName ( myNbListe );
glDisable ( GL_LIGHTING );
glBegin ( GL_LINES );
for ( unsigned int i=0; i<myTriangleList.size(); i++ )
{
glVertex3f ( myTriangleList.at ( i ).x1, myTriangleList.at ( i ).y1, myTriangleList.at ( i ).z1 );
glVertex3f ( myTriangleList.at ( i ).x2, myTriangleList.at ( i ).y2, myTriangleList.at ( i ).z2 );
glVertex3f ( myTriangleList.at ( i ).x2, myTriangleList.at ( i ).y2, myTriangleList.at ( i ).z2 );
glVertex3f ( myTriangleList.at ( i ).x3, myTriangleList.at ( i ).y3, myTriangleList.at ( i ).z3 );
glVertex3f ( myTriangleList.at ( i ).x3, myTriangleList.at ( i ).y3, myTriangleList.at ( i ).z3 );
glVertex3f ( myTriangleList.at ( i ).x1, myTriangleList.at ( i ).y1, myTriangleList.at ( i ).z1 );
}
glEnd();
glEnable ( GL_LIGHTING );
glEndList();
// Fifth list: Polygonal faces.
glNewList ( GLuint (myListToAff + nbListOfPrimitives +5 ), GL_COMPILE );
glPushName ( myNbListe );
glEnable ( GL_LIGHTING );
for ( unsigned int i=0; i<myPolygonList.size(); i++ )
{
glBegin ( GL_POLYGON );
glColor4ub ( myPolygonList.at ( i ).R, myPolygonList.at ( i ).G, myPolygonList.at ( i ).B, myPolygonList.at ( i ).T );
glNormal3f ( -myPolygonList.at ( i ).nx, -myPolygonList.at ( i ).ny ,-myPolygonList.at ( i ).nz );
vector<pointD3D> vectVertex = myPolygonList.at ( i ).vectPoints;
for(unsigned int j=0;j < vectVertex.size();j++){
glVertex3f ( vectVertex.at(j).x, vectVertex.at(j).y, vectVertex.at ( j ).z );
}
glEnd();
}
glEndList();
// Sixth list: Wired version of polygonal face.
glNewList ( GLuint (myListToAff + nbListOfPrimitives +6 ), GL_COMPILE );
glPushName ( myNbListe );
glDisable ( GL_LIGHTING );
glBegin ( GL_LINES );
for ( unsigned int i=0; i<myPolygonList.size(); i++ )
{
vector<pointD3D> vectVertex = myPolygonList.at ( i ).vectPoints;
for(unsigned int j=0;j < vectVertex.size();j++){
glVertex3f ( vectVertex.at(j).x, vectVertex.at(j).y, vectVertex.at ( j ).z );
glVertex3f ( vectVertex.at((j+1)%vectVertex.size()).x, vectVertex.at((j+1)%vectVertex.size()).y, vectVertex.at ( (j+1)%vectVertex.size() ).z );
}
}
glEnd();
glEndList();
if ( needToUpdateBoundingBox )
{
setSceneBoundingBox ( qglviewer::Vec ( myBoundingPtLow[0],myBoundingPtLow[1],myBoundingPtLow[2] ),
qglviewer::Vec ( myBoundingPtUp[0], myBoundingPtUp[1], myBoundingPtUp[2] ) );
showEntireScene();
}
glPopMatrix();
}

Field Documentation

DGtal::Color DGtal::Viewer3D::myDefaultBackgroundColor

Definition at line 124 of file Viewer3D.h.

DGtal::Color DGtal::Viewer3D::myDefaultColor

Definition at line 130 of file Viewer3D.h.

Referenced by operator<<().

qglviewer::Vec DGtal::Viewer3D::myDir
private

Definition at line 237 of file Viewer3D.h.

qglviewer::Vec DGtal::Viewer3D::myDirSelector
private

Definition at line 237 of file Viewer3D.h.

bool DGtal::Viewer3D::myIsBackgroundDefault

Definition at line 131 of file Viewer3D.h.

GLuint DGtal::Viewer3D::myListToAff
private

Definition at line 235 of file Viewer3D.h.

unsigned int DGtal::Viewer3D::myNbListe
private

Definition at line 236 of file Viewer3D.h.

qglviewer::Vec DGtal::Viewer3D::myOrig
private

Definition at line 237 of file Viewer3D.h.

QPoint DGtal::Viewer3D::myPosSelector
private

Definition at line 238 of file Viewer3D.h.

qglviewer::Vec DGtal::Viewer3D::mySelectedPoint
private

Definition at line 237 of file Viewer3D.h.

bool DGtal::Viewer3D::myViewWire

Definition at line 132 of file Viewer3D.h.


The documentation for this class was generated from the following files: