Tulip  5.1.0
Large graphs analysis and drawing
GlLabel.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef Tulip_GLLABEL_H
21 #define Tulip_GLLABEL_H
22 
23 #include <tulip/Coord.h>
24 #include <tulip/Color.h>
25 #include <tulip/Size.h>
26 #include <tulip/Camera.h>
27 #include <tulip/GlSimpleEntity.h>
28 
29 class FTGLPolygonFont;
30 class FTOutlineFont;
31 
32 namespace tlp {
33 
34 struct OcclusionTest;
35 
36 /**
37  * @ingroup OpenGL
38  * @brief Create a label into Tulip 3D engine
39  *
40  * The shortes way to create a label is :
41  * @code
42  * GlLabel *label=new GlLabel(Coord(0,0,0), Size (1,1,1), Color(1,1,1));
43  * label->setText("example");
44  * @endcode
45  */
46 class TLP_GL_SCOPE GlLabel : public GlSimpleEntity {
47  /**
48  * @brief Set default parameters of GlLabel
49  *
50  */
51  void init();
52 
53 public :
54 
55  /**
56  * @brief Constructor
57  * @warning Don't use this constructor : see other constructor
58  */
59  GlLabel();
60 
61  /**
62  * @brief Contructor
63  * @param centerPosition position of the label
64  * @param size size of the label
65  * @param fontColor color of the label
66  * @param leftAlign true if you want a left align label
67  */
68  GlLabel(Coord centerPosition,Size size,Color fontColor,bool leftAlign=false);
69 
70  /**
71  * @brief Destructor
72  */
73  ~GlLabel();
74 
75  /**
76  * @brief Set the text of the label
77  */
78  void setText(const std::string& text);
79 
80  /**
81  * @brief getText gets the text of this label.
82  * @return The text of this label.
83  */
84  const std::string& getText() const;
85 
86  /**
87  * @brief Set the position used to render the label
88  */
89  void setPosition(const Coord &position);
90 
91  /**
92  * @brief Return the position of the label
93  */
94  Coord getPosition();
95 
96  ///@cond DOXYGEN_HIDDEN
97 
98  /**
99  * @brief Set the translation used after rotation of the label
100  */
101  virtual void setTranslationAfterRotation(Coord translation) {
102  translationAfterRotation=translation;
103  }
104 
105  /**
106  * @brief return the translation used after rotation of the label
107  */
108  virtual Coord getTranslationAfterRotation() {
109  return translationAfterRotation;
110  }
111 
112  ///@endcond
113 
114  /**
115  * @brief Set the alignment of the label : LabelPosition::Center, LabelPosition::Top, LabelPosition::Bottom, LabelPosition::Left, LabelPosition::Right
116  * This function is usefull when you have an entity : you spesify the size of the position of this entity and you tell that you want a label outside this entity
117  * @see LabelPosition
118  * @see setSizeOfOutAlign
119  */
120  virtual void setAlignment(int alignment) {
121  this->alignment=alignment;
122  }
123 
124  /**
125  * @brief Return the bounding box of the label
126  */
127  virtual BoundingBox getBoundingBox();
128 
129  /**
130  * @brief Return the bounding box of the text of the label after transformations
131  */
132  virtual BoundingBox getTextBoundingBox();
133 
134  /**
135  * @brief Set the size of the label
136  */
137  virtual void setSize(const Size &size);
138 
139  /**
140  * @brief return the size of the text
141  */
142  virtual Size getSize();
143 
144  /**
145  * @brief Set the size for alignment outside (left/right/top/bottom)
146  *
147  * You can have a specific size when you want a label outside
148  * @see setAlignment
149  *
150  * @Warning : this size is reinit when you call setSize
151  */
152  virtual void setSizeForOutAlign(const Size &size);
153 
154  /**
155  * @brief return the size for alignment outside (left/right/top/bottom)
156  * @see setAlignment
157  */
158  virtual Size getSizeForOutAlign();
159 
160  /**
161  * @brief Set color of label
162  */
163  virtual void setColor(const Color &color) {
164  this->color=color;
165  }
166 
167  /**
168  * @brief Get color use to render the label
169  */
170  virtual Color getColor() {
171  return color;
172  }
173 
174  /**
175  * @brief Enable/disable the OpenGL depth test for the label (default depth test is enable)
176  */
177  virtual void enableDepthTest(bool state) {
178  depthTestEnabled=state;
179  }
180 
181  /**
182  * @brief Enable/disable if label is scaled to size
183  */
184  virtual void setScaleToSize(bool state) {
185  scaleToSize=state;
186  }
187 
188  /**
189  * @brief Set the stencil and draw the Label, this function is usefull when we directly call draw without tulip engine
190  */
191  void drawWithStencil(float lod,Camera *camera=NULL);
192 
193  /**
194  * @brief Return the height of the label after scaling in size box
195  */
196  float getHeightAfterScale();
197 
198  /**
199  * @brief Draw the Label
200  */
201  virtual void draw(float, Camera *camera=NULL);
202 
203  /**
204  * @brief Translate entity
205  */
206  virtual void translate(const Coord& mouvement);
207 
208  /**
209  * @brief Rotate Label
210  */
211  virtual void rotate(float xRot, float yRot, float zRot);
212 
213  /**
214  * @brief Function to export data in outString (in XML format)
215  */
216  virtual void getXML(std::string &outString);
217 
218  /**
219  * @brief Function to set data with inString (in XML format)
220  */
221  virtual void setWithXML(const std::string &inString, unsigned int &currentPosition);
222 
223  /**
224  * @brief Switch to bold font
225  */
226  virtual void setBoldFont();
227 
228  /**
229  * @brief Switch to plain font
230  */
231  virtual void setPlainFont();
232 
233  /**
234  * @brief Change font name
235  */
236  virtual void setFontName(const std::string &name);
237 
238  /**
239  * @brief Change font name, size and color of the text
240  */
241  virtual void setFontNameSizeAndColor(const std::string &name, const int &size, const Color &color);
242 
243  ///@cond DOXYGEN_HIDDEN
244  /**
245  * @brief This parameters is not used
246  */
247  virtual void setRenderingMode(int mode);
248  ///@endcond
249 
250  /**
251  * @brief Set the occlusion tester
252  * If occlusionTester is NULL : deactivate occlusion test
253  */
254  virtual void setOcclusionTester(OcclusionTest *tester) {
255  occlusionTester=tester;
256  }
257 
258  /**
259  * @brief Set if the label is otimized with the lod
260  */
261  virtual void setUseLODOptimisation(bool state,BoundingBox bb=BoundingBox()) {
262  useLOD=state;
263  lodBoundingBox=bb;
264  }
265 
266  /**
267  * @brief Return if the label is otimized with the lod
268  */
269  virtual bool getUseLODOptimisation() {
270  return useLOD;
271  }
272 
273  /**
274  * @brief Set labels density of occlusion test
275  * This density must be in interval -100 100
276  *
277  * - If density is equal to -100 : we don't have occlusion test
278  * - If density is equal to 0 : GlLabels don't overlap
279  * - If density > 0 : GlLabels don't overlap and have space wetween us
280  */
281  virtual void setLabelsDensity(int density) {
282  if(density<-100)
283  labelsDensity=-100;
284  else if(density>100)
285  labelsDensity=100;
286  else
287  labelsDensity=density;
288  }
289 
290  /**
291  * @brief Return label density of occlusion test
292  * This density will be in interval -100 100
293  */
294  virtual int getLabelDensity() {
295  return labelsDensity;
296  }
297 
298  /**
299  * @brief Set min screen size (in pixel) of the label : this size is used in not scaled mode
300  * @see setUseMinMaxSize
301  */
302  void setMinSize(int size) {
303  minSize=size;
304  }
305 
306  /**
307  * @brief Get min screen size (in pixel) of the label : this size is used in not scaled mode
308  * @see setUseMinMaxSize
309  */
310  int getMinSize() {
311  return minSize;
312  }
313 
314  /**
315  * @brief Set max screen size (in pixel) of the label : this size is used in not scaled mode
316  * @see setUseMinMaxSize
317  */
318  void setMaxSize(int size) {
319  maxSize=size;
320  }
321 
322  /**
323  * @brief Get max screen size (in pixel) of the label : this size is used in not scaled mode
324  * @see setUseMinMaxSize
325  */
326  int getMaxSize() {
327  return maxSize;
328  }
329 
330  /**
331  * @brief Set if the label use min/max screen size in not scaled mode
332  */
333  void setUseMinMaxSize(bool state) {
334  useMinMaxSize=state;
335  }
336 
337  /**
338  * @brief Return if the label using min/max screen size in not scaled mode
339  */
341  return useMinMaxSize;
342  }
343 
344  /**
345  * @brief Return the font size
346  */
347  int getFontSize() const {
348  return fontSize;
349  }
350 
351  /**
352  * @brief Sets the font size used when rendering the label.
353  */
354  void setFontSize(int size) {
355  fontSize = size;
356  }
357 
358  /**
359  * @brief Return the outline color
360  */
361  Color getOutlineColor() const {
362  return outlineColor;
363  }
364 
365  /**
366  * @brief Sets the outline color used when rendering the label.
367  */
368  void setOutlineColor(const Color &color) {
369  outlineColor = color;
370  }
371 
372  /**
373  * @brief Return the outline size
374  */
375  float getOutlineSize() const {
376  return outlineSize;
377  }
378 
379  /**
380  * @brief Sets the outline size used when rendering the label.
381  */
382  void setOutlineSize(float size) {
383  outlineSize = size;
384  }
385 
386  /**
387  * @brief Return the texture name used to render the label
388  */
389  std::string getTextureName() const {
390  return textureName;
391  }
392 
393  /**
394  * @brief Sets the texture name used when rendering the label.
395  */
396  void setTextureName(const std::string &name) {
397  textureName=name;
398  }
399 
400  /**
401  * @brief Return if the label is billboarded
402  */
403  bool isBillboarded() {
404  return billboarded;
405  }
406 
407  /**
408  * @brief Set if the label is billboarded
409  */
410  void setBillboarded(bool billboarded) {
411  this->billboarded=billboarded;
412  }
413 
414 private :
415 
416  std::string text;
417  std::string fontName;
418  int fontSize;
419  int renderingMode;
420  FTGLPolygonFont *font;
421  FTOutlineFont *borderFont;
422  Coord centerPosition;
423  Coord translationAfterRotation;
424  Size size;
425  Size sizeForOutAlign;
426  Color color;
427  Color outlineColor;
428  float outlineSize;
429  std::string textureName;
430  int alignment;
431  bool scaleToSize;
432  bool useMinMaxSize;
433  int minSize;
434  int maxSize;
435  bool depthTestEnabled;
436  bool leftAlign;
437  bool billboarded;
438  float xRot;
439  float yRot;
440  float zRot;
441  bool useLOD;
442  BoundingBox lodBoundingBox;
443  int labelsDensity;
444  OcclusionTest *occlusionTester;
445 
446  Camera oldCamera;
447  float oldLod;
448  Vec4i oldViewport;
449 
450  std::vector<std::string> textVector;
451  std::vector<float> textWidthVector;
452  BoundingBox textBoundingBox;
453 };
454 
455 }
456 #endif
457 
int getFontSize() const
Return the font size.
Definition: GlLabel.h:347
virtual int getLabelDensity()
Return label density of occlusion test This density will be in interval -100 100. ...
Definition: GlLabel.h:294
Base class for all Tulip OpenGL entities.
virtual void setLabelsDensity(int density)
Set labels density of occlusion test This density must be in interval -100 100.
Definition: GlLabel.h:281
void setUseMinMaxSize(bool state)
Set if the label use min/max screen size in not scaled mode.
Definition: GlLabel.h:333
virtual Color getColor()
Get color use to render the label.
Definition: GlLabel.h:170
virtual void setColor(const Color &color)
Set color of label.
Definition: GlLabel.h:163
int getMaxSize()
Get max screen size (in pixel) of the label : this size is used in not scaled mode.
Definition: GlLabel.h:326
void setBillboarded(bool billboarded)
Set if the label is billboarded.
Definition: GlLabel.h:410
virtual bool getUseLODOptimisation()
Return if the label is otimized with the lod.
Definition: GlLabel.h:269
Create a label into Tulip 3D engine.
Definition: GlLabel.h:46
float getOutlineSize() const
Return the outline size.
Definition: GlLabel.h:375
bool isUsingMinMaxSize()
Return if the label using min/max screen size in not scaled mode.
Definition: GlLabel.h:340
std::string getTextureName() const
Return the texture name used to render the label.
Definition: GlLabel.h:389
void setMaxSize(int size)
Set max screen size (in pixel) of the label : this size is used in not scaled mode.
Definition: GlLabel.h:318
virtual void setOcclusionTester(OcclusionTest *tester)
Set the occlusion tester If occlusionTester is NULL : deactivate occlusion test.
Definition: GlLabel.h:254
void setOutlineColor(const Color &color)
Sets the outline color used when rendering the label.
Definition: GlLabel.h:368
This class represents the 3D bounding box of an object. It is mostly used to determine whether or not...
Definition: BoundingBox.h:63
Tulip OpenGL camera object.
Definition: Camera.h:45
void setFontSize(int size)
Sets the font size used when rendering the label.
Definition: GlLabel.h:354
bool isBillboarded()
Return if the label is billboarded.
Definition: GlLabel.h:403
Color getOutlineColor() const
Return the outline color.
Definition: GlLabel.h:361
int getMinSize()
Get min screen size (in pixel) of the label : this size is used in not scaled mode.
Definition: GlLabel.h:310
virtual void setAlignment(int alignment)
Set the alignment of the label : LabelPosition::Center, LabelPosition::Top, LabelPosition::Bottom, LabelPosition::Left, LabelPosition::Right This function is usefull when you have an entity : you spesify the size of the position of this entity and you tell that you want a label outside this entity.
Definition: GlLabel.h:120
void setMinSize(int size)
Set min screen size (in pixel) of the label : this size is used in not scaled mode.
Definition: GlLabel.h:302
virtual void setScaleToSize(bool state)
Enable/disable if label is scaled to size.
Definition: GlLabel.h:184
void setTextureName(const std::string &name)
Sets the texture name used when rendering the label.
Definition: GlLabel.h:396
virtual void enableDepthTest(bool state)
Enable/disable the OpenGL depth test for the label (default depth test is enable) ...
Definition: GlLabel.h:177
virtual void setUseLODOptimisation(bool state, BoundingBox bb=BoundingBox())
Set if the label is otimized with the lod.
Definition: GlLabel.h:261
void setOutlineSize(float size)
Sets the outline size used when rendering the label.
Definition: GlLabel.h:382