Tulip  4.0.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
GlLabel.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 <string>
24 
25 #include <tulip/Coord.h>
26 #include <tulip/Color.h>
27 #include <tulip/Size.h>
28 
29 #include <tulip/GlSimpleEntity.h>
30 
31 class FTGLPolygonFont;
32 class FTOutlineFont;
33 
34 namespace tlp {
35 
36 class Camera;
37 struct OcclusionTest;
38 
39 enum LabelPosition {ON_CENTER = 0, ON_TOP = 1, ON_BOTTOM = 2, ON_LEFT = 3, ON_RIGHT = 4};
40 
41 /**
42  * @ingroup OpenGL
43  * @brief Create a label into Tulip 3D engine
44  *
45  * The shortes way to create a label is :
46  * @code
47  * GlLabel *label=new GlLabel(Coord(0,0,0), Size (1,1,1), Color(1,1,1));
48  * label->setText("example");
49  * @endcode
50  */
51 class TLP_GL_SCOPE GlLabel : public GlSimpleEntity {
52 public :
53 
54  /**
55  * @brief Constructor
56  * @warning Don't use this constructor : see other constructor
57  */
58  GlLabel();
59 
60  /**
61  * @brief Contructor
62  * @param centerPosition position of the label
63  * @param size size of the label
64  * @param fontColor color of the label
65  * @param leftAlign true if you want a left align label
66  */
67  GlLabel(Coord centerPosition,Size size,Color fontColor,bool leftAlign=false);
68 
69  /**
70  * @brief Destructor
71  */
72  ~GlLabel();
73 
74  /**
75  * @brief Set default parameters of GlLabel
76  *
77  * This function is call by constructor, so you don't have to call it
78  */
79  void init();
80 
81  /**
82  * @brief Set the text of the label
83  */
84  void setText(const std::string& text);
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 : ON_CENTER, ON_TOP, ON_BOTTOM, ON_LEFT, ON_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 lod,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  std::vector<std::string> textVector;
447  std::vector<float> textWidthVector;
448  BoundingBox textBoundingBox;
449 };
450 
451 }
452 #endif
453