\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 4.12 - Three
CGAL::Three::Viewer_interface Class Referenceabstract

#include <CGAL/Three/Viewer_interface.h>

Inherits from

QGLViewer, and QOpenGLFunctions_2_1.

Definition

Base class to interact with the viewer from the plugins, the items and the scene.

Examples:
Three/Example_plugin/Example_plugin.cpp.

Public Types

enum  OpenGL_program_IDs { ,
  PROGRAM_WITHOUT_LIGHT, PROGRAM_NO_SELECTION, PROGRAM_WITH_TEXTURE, PROGRAM_PLANE_TWO_FACES,
  PROGRAM_WITH_TEXTURED_EDGES, PROGRAM_INSTANCED, PROGRAM_INSTANCED_WIRE, PROGRAM_C3T3,
  PROGRAM_C3T3_EDGES, PROGRAM_CUTPLANE_SPHERES, PROGRAM_SPHERES, PROGRAM_FLAT,
  PROGRAM_OLD_FLAT, NB_OF_PROGRAMS
}
 The OpenGL_program_IDs enum. More...
 

Public Slots

virtual void setAntiAliasing (bool b)=0
 Sets the antialiasing to true or false. More...
 
virtual void setTwoSides (bool b)=0
 If b is true, faces will be ligted from both internal and external side. More...
 
virtual void setFastDrawing (bool b)=0
 Sets the fast drawing mode. More...
 
virtual void turnCameraBy180Degres ()=0
 Makes the camera turn around.
 
virtual QString dumpCameraCoordinates ()=0
 
virtual bool moveCameraToCoordinates (QString target, float animation_duration=0.5f)=0
 Moves the camera to the new coordinates. More...
 

Signals

void selected (int id)
 Emit this to signal that the idth item has been picked.
 
void requestContextMenu (QPoint global_pos)
 Emit this to require a contextual menu to appear at global_pos.
 
void selectedPoint (double x, double y, double z)
 Emit this to signal that the point at (x, y, z) has been picked.
 
void selectionRay (double sx, double sy, double sz, double tx, double ty, double tz)
 Emit this to request the currently selected item to perform a selection based on an AABB_Tree and a raycasting.
 

Public Member Functions

virtual QPainter * getPainter ()=0
 The viewer's QPainter. More...
 
virtual bool testDisplayId (double x, double y, double z)=0
 Tests if an id should be displayed or not. More...
 
virtual void updateIds (CGAL::Three::Scene_item *)=0
 Updates the item's displayed ids. More...
 
virtual bool hasText () const
 Specifies if the items ids are being displayed. More...
 
 Viewer_interface (QWidget *parent)
 Constructor. More...
 
virtual void setScene (CGAL::Three::Scene_draw_interface *scene)=0
 Sets the scene for the viewer.
 
virtual bool antiAliasing () const =0
 The antialiasing state. More...
 
virtual bool inFastDrawing () const =0
 The fastDrawing state. More...
 
virtual bool inDrawWithNames () const =0
 The drawWithNames state. More...
 
virtual void attribBuffers (int program_name) const =0
 Passes all the uniform data to the shaders. More...
 
virtual void enableClippingBox (QVector4D box[6])=0
 Enables the clipping box. More...
 
virtual void disableClippingBox ()=0
 Disables the clipping box. More...
 
virtual QOpenGLShaderProgram * getShaderProgram (int name) const =0
 Returns a program according to name. More...
 
virtual TextRenderertextRenderer ()=0
 TextRenderer is used to display text on the screen. More...
 
typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC)(GLenum mode
 Allows OpenGL 2.1 context to get access to glDrawArraysInstanced.
 
typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC)(GLuint index
 Allows OpenGL 2.1 context to get access to glVertexAttribDivisor.
 
typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)(GLuint target
 Allows OpenGL 2.1 context to get access to glVertexAttribDivisor.
 
virtual bool isExtensionFound ()=0
 Used by the items to avoid SEGFAULT. More...
 
virtual qglviewer::Vec offset () const =0
 Returns the scene's offset.
 
virtual void setBindingSelect ()=0
 Allows to perform picking from the keyboard and mouse. More...
 
virtual void setNoBinding ()=0
 Disable the picking from the keyboard and mouse. More...
 
virtual void set2DSelectionMode (bool)=0
 If this mode is ON, the viewer will display the content of staticImage() instead of drawing the cene. More...
 
virtual void setStaticImage (QImage image)=0
 Setter for the image to be displayed in 2D selection mode.
 
virtual const QImage & staticImage () const =0
 Returns the static image to be displayed in 2D selection mode.
 
virtual bool isOpenGL_4_3 () const =0
 Is used to know if the openGL context is 4.3 or 2.1. More...
 
virtual QOpenGLFunctions_4_3_Compatibility * openGL_4_3_functions ()=0
 Gives acces to recent openGL(4.3) features, allowing use of things like Geometry Shaders or Depth Textures. More...
 

Static Public Member Functions

static bool readFrame (QString s, qglviewer::Frame &frame)
 Sets the position and orientation of a frame using a QString. More...
 
static QString dumpFrame (const qglviewer::Frame &)
 Gives information about a frame. More...
 

Member Enumeration Documentation

◆ OpenGL_program_IDs

The OpenGL_program_IDs enum.

This enum holds the OpenGL programs IDs that are given to getShaderProgram() and attribBuffers().

See also
getShaderProgram
attribBuffers
Enumerator
PROGRAM_WITHOUT_LIGHT 

Used to render a surface or an edge affected by the light. It uses a per fragment lighting model, and renders the selected item brighter.

PROGRAM_NO_SELECTION 

Used to render a polyhedron edge or points. It renders in a uniform color and is not affected by light.

Attention
It renders the selected item in black.
PROGRAM_WITH_TEXTURE 

Used to render a polyline or a surface that is not affected by light, like a cutting plane. It renders in a uniform color that does not change with selection.

PROGRAM_PLANE_TWO_FACES 

Used to render a textured polyhedron. Affected by light.

PROGRAM_WITH_TEXTURED_EDGES 

Used to render a two-faced plane. The two faces have a different color. Not affected by light.

PROGRAM_INSTANCED 

Used to render the edges of a textured polyhedron. Not affected by light.

PROGRAM_INSTANCED_WIRE 

Used to display instanced rendered spheres.Affected by light.

PROGRAM_C3T3 

Used to display instanced rendered wired spheres. Not affected by light.

PROGRAM_C3T3_EDGES 

Used to render a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Affected by light.

PROGRAM_CUTPLANE_SPHERES 

Used to render the edges of a c3t3_item. It discards any fragment on a side of a plane, meaning that nothing is displayed on this side of the plane. Not affected by light.

PROGRAM_SPHERES 

Used to render the spheres of an item with a cut plane.

PROGRAM_FLAT 

Used to render one or several spheres.

PROGRAM_OLD_FLAT 

Used to render flat shading without pre computing normals.

NB_OF_PROGRAMS 

Used to render flat shading without pre computing normals without geometry shader.

Holds the number of different programs in this enum.

Constructor & Destructor Documentation

◆ Viewer_interface()

CGAL::Three::Viewer_interface::Viewer_interface ( QWidget *  parent)

Constructor.

Creates a valid context for OpenGL 2.1.

Parameters
parentthe parent widget. It usually is the MainWindow.

Member Function Documentation

◆ antiAliasing()

virtual bool CGAL::Three::Viewer_interface::antiAliasing ( ) const
pure virtual

The antialiasing state.

Returns
true if the antialiasing is activated.

◆ attribBuffers()

virtual void CGAL::Three::Viewer_interface::attribBuffers ( int  program_name) const
pure virtual

Passes all the uniform data to the shaders.

According to program_name, this data may change. This should be called in every Scene_item::draw() call.

See also
OpenGL_program_IDs

◆ disableClippingBox()

virtual void CGAL::Three::Viewer_interface::disableClippingBox ( )
pure virtual

Disables the clipping box.

The six clipping planes will be ignored.

See also
enableClippingBox()

◆ dumpCameraCoordinates

virtual QString CGAL::Three::Viewer_interface::dumpCameraCoordinates ( )
pure virtualslot
Returns
a QString containing the position and orientation of the camera.
See also
dumpFrame()

◆ dumpFrame()

static QString CGAL::Three::Viewer_interface::dumpFrame ( const qglviewer::Frame &  )
static

Gives information about a frame.

See also
readFrame
dumpCameraCoordinates()
Returns
a QString containing the position and orientation of a frame.

◆ enableClippingBox()

virtual void CGAL::Three::Viewer_interface::enableClippingBox ( QVector4D  box[6])
pure virtual

Enables the clipping box.

Each Vector4 of box contains the equation of a plane of the clipping box. Everything that is located on the positive side of one of those planes will not be displayed.

See also
disableCLippingBox()

◆ getPainter()

virtual QPainter* CGAL::Three::Viewer_interface::getPainter ( )
pure virtual

The viewer's QPainter.

The painter is the element that draws everything on screen, but you should only need this if you want to draw 2D things on top of the scene, like a selection rectangle. See QPainter's documentation for details.

◆ getShaderProgram()

virtual QOpenGLShaderProgram* CGAL::Three::Viewer_interface::getShaderProgram ( int  name) const
pure virtual

Returns a program according to name.

If the program does not exist yet, it is created and stored in shader_programs.

See also
OpenGL_program_IDs
Returns
a pointer to the corresponding program.

◆ hasText()

virtual bool CGAL::Three::Viewer_interface::hasText ( ) const
virtual

Specifies if the items ids are being displayed.

Returns
true if the primitive ids are currently displayed

◆ inDrawWithNames()

virtual bool CGAL::Three::Viewer_interface::inDrawWithNames ( ) const
pure virtual

The drawWithNames state.

In draw with name mode, the scene is not displayed, but a name is given to each Scene_item. It is used for picking.

Returns
true if the viewer is drawing with names.

◆ inFastDrawing()

virtual bool CGAL::Three::Viewer_interface::inFastDrawing ( ) const
pure virtual

The fastDrawing state.

In fast drawing mode, some items will be simplified while the camera is moving to gain in performance.

Returns
the fastDrawing state.

◆ isExtensionFound()

virtual bool CGAL::Three::Viewer_interface::isExtensionFound ( )
pure virtual

Used by the items to avoid SEGFAULT.

Returns
true if glVertexAttribDivisor, and glDrawArraysInstanced are found.

◆ isOpenGL_4_3()

virtual bool CGAL::Three::Viewer_interface::isOpenGL_4_3 ( ) const
pure virtual

Is used to know if the openGL context is 4.3 or 2.1.

Returns
true if the context is 4.3.
false if the context is 2.1.

◆ moveCameraToCoordinates

virtual bool CGAL::Three::Viewer_interface::moveCameraToCoordinates ( QString  target,
float  animation_duration = 0.5f 
)
pure virtualslot

Moves the camera to the new coordinates.

The movement is performed through an animation.

Parameters
targetis usually gotten by dumpCameraCoordinates() and is of the form "Px Py Pz O1 O2 O3 O4 ", with
  • Px to Py : the new position coordinates,
  • O1 to O3 : axis coordinate *sin(angle/2)
  • O4 cos(angle/2).
animation_durationis the duration of the animation of the movement.

◆ openGL_4_3_functions()

virtual QOpenGLFunctions_4_3_Compatibility* CGAL::Three::Viewer_interface::openGL_4_3_functions ( )
pure virtual

Gives acces to recent openGL(4.3) features, allowing use of things like Geometry Shaders or Depth Textures.

Returns
a pointer to an initialized QOpenGLFunctions_4_3_Compatibility if isOpenGL_4_3() is true
NULL if isOpenGL_4_3() is false

◆ readFrame()

static bool CGAL::Three::Viewer_interface::readFrame ( QString  s,
qglviewer::Frame &  frame 
)
static

Sets the position and orientation of a frame using a QString.

Parameters
sis usually gotten by dumpFrame() and is of the form "Px Py Pz O1 O2 O3 O4 ", with
  • Px to Py : the new position coordinates,
  • O1 to O3 : axis coordinate *sin(angle/2)
  • O4 cos(angle/2).
frameis the frame that will be moved
Returns
true if it worked.
See also
moveCameraToCoordinates()

◆ set2DSelectionMode()

virtual void CGAL::Three::Viewer_interface::set2DSelectionMode ( bool  )
pure virtual

If this mode is ON, the viewer will display the content of staticImage() instead of drawing the cene.

This is used when drawing 2D lines over the viewer.

See also
staticImage()
setStaticImage()

◆ setAntiAliasing

virtual void CGAL::Three::Viewer_interface::setAntiAliasing ( bool  b)
pure virtualslot

Sets the antialiasing to true or false.

See also
antiAliasing()

◆ setBindingSelect()

virtual void CGAL::Three::Viewer_interface::setBindingSelect ( )
pure virtual

Allows to perform picking from the keyboard and mouse.

Sets the combination SHIFT+LEFT CLICK to perform a selection on the screen. This is used to perform picking.

◆ setFastDrawing

virtual void CGAL::Three::Viewer_interface::setFastDrawing ( bool  b)
pure virtualslot

Sets the fast drawing mode.

See also
inFastDrawing()

◆ setNoBinding()

virtual void CGAL::Three::Viewer_interface::setNoBinding ( )
pure virtual

Disable the picking from the keyboard and mouse.

Unbinds the combination SHIFT+LEFT CLICK. It allows to avoid conflicts in the selection_tool, for example.

◆ setTwoSides

virtual void CGAL::Three::Viewer_interface::setTwoSides ( bool  b)
pure virtualslot

If b is true, faces will be ligted from both internal and external side.

If b is false, only the side that is exposed to the light source will be lighted.

◆ testDisplayId()

virtual bool CGAL::Three::Viewer_interface::testDisplayId ( double  x,
double  y,
double  z 
)
pure virtual

Tests if an id should be displayed or not.

Parameters
x,y,zthe coordinates of the id's position.
Returns
true if the ID should be displayed.

◆ textRenderer()

virtual TextRenderer* CGAL::Three::Viewer_interface::textRenderer ( )
pure virtual

TextRenderer is used to display text on the screen.

The textRenderer uses the painter to display 2D text over the 3D Scene.

Returns
the viewer's TextRender

◆ updateIds()

virtual void CGAL::Three::Viewer_interface::updateIds ( CGAL::Three::Scene_item )
pure virtual

Updates the item's displayed ids.

Call this after the mesh or its ids have changed.