20 #ifndef Tulip_GLSCENE_H
21 #define Tulip_GLSCENE_H
25 #include <tulip/tulipconf.h>
26 #include <tulip/BoundingBox.h>
27 #include <tulip/GlLODCalculator.h>
28 #include <tulip/GlLayer.h>
29 #include <tulip/Color.h>
30 #include <tulip/Observable.h>
36 class GlGraphComposite;
52 enum SelectedEntityType {
56 SIMPLE_ENTITY_SELECTED = 3
60 : simpleEntity(
nullptr), complexEntityId(UINT_MAX), entityType(UNKNOW_SELECTED) {}
62 : simpleEntity(entity), complexEntityId(UINT_MAX), entityType(SIMPLE_ENTITY_SELECTED) {}
64 : complexEntityGraph(graph), complexEntityId(
id), entityType(type) {
65 assert((type == NODE_SELECTED) || (type == EDGE_SELECTED));
69 assert((entityType == SIMPLE_ENTITY_SELECTED) && (simpleEntity !=
nullptr));
73 unsigned int getComplexEntityId()
const {
74 assert((entityType != SIMPLE_ENTITY_SELECTED) && (complexEntityId != UINT_MAX));
75 return complexEntityId;
78 Graph *getComplexEntityGraph()
const {
79 assert((entityType != SIMPLE_ENTITY_SELECTED) && (complexEntityGraph !=
nullptr));
80 return complexEntityGraph;
83 SelectedEntityType getEntityType()
const {
90 assert((entityType == NODE_SELECTED) || (complexEntityId == UINT_MAX));
91 return node(complexEntityId);
98 assert((entityType == EDGE_SELECTED) || (complexEntityId == UINT_MAX));
99 return edge(complexEntityId);
105 Graph *complexEntityGraph;
107 unsigned int complexEntityId;
108 SelectedEntityType entityType;
153 GlScene(GlLODCalculator *calculator =
nullptr);
192 float *sceneRadius,
float *xWhiteFactor,
float *yWhiteFactor,
194 float *zoomFactor =
nullptr);
207 void zoomXY(
int step,
const int x,
const int y);
219 void zoom(
float factor,
const Coord &dest);
226 zoomFactor(powf(1.1f, step));
253 std::vector<SelectedEntity> &selectedEntities);
265 viewport = newViewport;
276 viewport[3] = height;
291 backgroundColor = color;
298 return backgroundColor;
305 this->viewOrtho = viewOrtho;
376 void removeLayer(
const std::string &name,
bool deleteLayer =
true);
398 for (
auto &it : layersList)
423 return lodCalculator;
430 lodCalculator = calculator;
431 calculator->setScene(*
this);
445 return glGraphComposite;
460 assert(graphLayer !=
nullptr);
461 return graphLayer->getCamera();
469 assert(graphLayer !=
nullptr);
470 graphLayer->setCamera(camera);
477 clearBufferAtDraw = clear;
484 return clearBufferAtDraw;
491 clearDepthBufferAtDraw = clear;
498 return clearDepthBufferAtDraw;
505 clearStencilBufferAtDraw = clear;
512 return clearStencilBufferAtDraw;
516 std::vector<std::pair<std::string, GlLayer *>> layersList;
517 GlLODCalculator *lodCalculator;
518 Vector<int, 4> viewport;
519 Color backgroundColor;
525 bool clearBufferAtDraw;
529 bool clearDepthBufferAtDraw;
531 bool clearStencilBufferAtDraw;
554 void notifyModifyLayer(
const std::string &name,
GlLayer *layer);
Tulip OpenGL camera object.
Class use to visualize graph in OpenGL Tulip engine.
A GlLayer is like an 2D drawing software layer system.
void setViewport(Vector< int, 4 > &newViewport)
Set the viewport of the scene with a vector The viewport must be in many case the size of the widget ...
void zoomFactor(float factor)
Zoom by factor.
GlGraphComposite * getGlGraphComposite()
Return the current GlGraphComposite used by the scene.
void addExistingLayer(GlLayer *layer)
Add an existing layer in the scene Now the scene have the ownership of this GlLayer so you don't have...
void getXML(std::string &out)
Get XML description of the scene and children and store it in out string.
bool selectEntities(RenderingEntitiesFlag type, int x, int y, int h, int w, GlLayer *layer, std::vector< SelectedEntity > &selectedEntities)
Select entities in scene.
void getXMLOnlyForCameras(std::string &out)
Get XML description of cameras of the scene and store it in out string.
void setCalculator(GlLODCalculator *calculator)
Set a new lod calculator used to render this scene.
const Vector< int, 4 > & getViewport() const
Get the viewport of the scene The viewport will be in many case the size of the widget containing the...
bool getClearStencilBufferAtDraw() const
If false, color buffer will not be cleared before drawing the scene.
BoundingBox getBoundingBox()
Return the bounding box of the scene (in 3D coordinates)
GlScene(GlLODCalculator *calculator=nullptr)
Constructor Default scene is empty.
Camera & getGraphCamera()
By default the most important layer is the layer where the graph is visualized This function return t...
void setViewOrtho(bool viewOrtho)
Set if scene is render in orthogonal mode.
void zoomXY(int step, const int x, const int y)
Zoom by step to given x,y screen coordinates.
void setWithXML(std::string &in, Graph *graph)
Set scene's data and children with a XML.
void setViewport(int x, int y, int width, int height)
Set the viewport of the scene with 4 int The viewport must be in many case the size of the widget con...
bool getClearDepthBufferAtDraw() const
If false, depth buffer will not be cleared before drawing the scene.
bool addExistingLayerAfter(GlLayer *layer, const std::string &afterLayerWithName)
Add an existing layer in the scene just after layer with given name Return false if the layer with be...
bool addExistingLayerBefore(GlLayer *layer, const std::string &beforeLayerWithName)
Add an existing layer in the scene just before layer with given name Return false if the layer with b...
GlLayer * getLayer(const std::string &name)
Return the layer with name : name Return nullptr if the layer doesn't exist in the scene.
void setBackgroundColor(const Color &color)
Set the background color of the scene.
GlLayer * getGraphLayer()
Return the layer containing the current GlGraphComposite.
void rotateCamera(const int x, const int y, const int z)
Rotate camera by (x,y,z)
void initGlParameters()
Init scene's OpenGL parameters. You don't have to call this function, it is call when you do a draw.
void setClearStencilBufferAtDraw(bool clear)
Set if OpenGL stencil buffer will be cleared at draw.
void removeLayer(const std::string &name, bool deleteLayer=true)
Remove the layer with name This GlLayer is automatically deleted If you want to keep this GlLayer you...
GlLODCalculator * getCalculator()
Return lod calculator used to render this scene.
Color getBackgroundColor() const
Get the background color of the scene.
bool isViewOrtho()
Scene is render in orthogonal mode ?
void clearLayersList()
Clear layers list Layers will not be deleted in this function.
void zoom(float factor, const Coord &dest)
Zoom to given world coordinate.
unsigned char * getImage()
Return the RGB image of GlScene.
void setClearBufferAtDraw(bool clear)
Set if OpenGL buffer will be cleared at draw.
void adjustSceneToSize(int width, int height)
void setClearDepthBufferAtDraw(bool clear)
Set if OpenGL depth buffer will be cleared at draw.
void translateCamera(const int x, const int y, const int z)
Translate camera by (x,y,z)
GlLayer * createLayer(const std::string &name)
Create a layer with the given name in the scene This layer is added to the layers list Now the scene ...
void setGraphCamera(Camera *camera)
By default the most important layer is the layer where the graph is visualized This function set the ...
bool getClearBufferAtDraw() const
If false, color buffer will not be cleared before drawing the scene.
void zoom(int step)
Zoom by step.
GlLayer * createLayerAfter(const std::string &layerName, const std::string &afterLayerWithName)
Create a layer with the given name in the scene just after layer with given name This layer is added ...
GlLayer * createLayerBefore(const std::string &layerName, const std::string &beforeLayerWithName)
Create a layer with the given name in the scene just before layer with given name This layer is added...
void removeLayer(GlLayer *layer, bool deleteLayer=true)
Remove the layer with name This GlLayer is automatically deleted If you want to keep this GlLayer you...
void draw()
Draw the scene This function is the most important function of GlScene. If you want to render a scene...
const std::vector< std::pair< std::string, GlLayer * > > & getLayersList()
Return the layer list.
void computeAdjustSceneToSize(int width, int height, Coord *center, Coord *eye, float *sceneRadius, float *xWhiteFactor, float *yWhiteFactor, BoundingBox *sceneBoundingBox=nullptr, float *zoomFactor=nullptr)
Base class for all Tulip OpenGL entities.
The Observable class is the base of Tulip's observation system.
This class represents the 3D bounding box of an object. It is mostly used to determine whether or not...
Structure to store selected entities.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.