Tulip  4.1.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 getText gets the text of this label.
88  * @return The text of this label.
89  */
90  const std::string& getText() const;
91 
92  /**
93  * @brief Set the position used to render the label
94  */
95  void setPosition(const Coord &position);
96 
97  /**
98  * @brief Return the position of the label
99  */
100  Coord getPosition();
101 
102  ///@cond DOXYGEN_HIDDEN
103 
104  /**
105  * @brief Set the translation used after rotation of the label
106  */
107  virtual void setTranslationAfterRotation(Coord translation) {
108  translationAfterRotation=translation;
109  }
110 
111  /**
112  * @brief return the translation used after rotation of the label
113  */
114  virtual Coord getTranslationAfterRotation() {
115  return translationAfterRotation;
116  }
117 
118  ///@endcond
119 
120  /**
121  * @brief Set the alignment of the label : ON_CENTER, ON_TOP, ON_BOTTOM, ON_LEFT, ON_RIGHT
122  * 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
123  * @see LabelPosition
124  * @see setSizeOfOutAlign
125  */
126  virtual void setAlignment(int alignment) {
127  this->alignment=alignment;
128  }
129 
130  /**
131  * @brief Return the bounding box of the label
132  */
133  virtual BoundingBox getBoundingBox();
134 
135  /**
136  * @brief Return the bounding box of the text of the label after transformations
137  */
138  virtual BoundingBox getTextBoundingBox();
139 
140  /**
141  * @brief Set the size of the label
142  */
143  virtual void setSize(const Size &size);
144 
145  /**
146  * @brief return the size of the text
147  */
148  virtual Size getSize();
149 
150  /**
151  * @brief Set the size for alignment outside (left/right/top/bottom)
152  *
153  * You can have a specific size when you want a label outside
154  * @see setAlignment
155  *
156  * @Warning : this size is reinit when you call setSize
157  */
158  virtual void setSizeForOutAlign(const Size &size);
159 
160  /**
161  * @brief return the size for alignment outside (left/right/top/bottom)
162  * @see setAlignment
163  */
164  virtual Size getSizeForOutAlign();
165 
166  /**
167  * @brief Set color of label
168  */
169  virtual void setColor(const Color &color) {
170  this->color=color;
171  }
172 
173  /**
174  * @brief Get color use to render the label
175  */
176  virtual Color getColor() {
177  return color;
178  }
179 
180  /**
181  * @brief Enable/disable the OpenGL depth test for the label (default depth test is enable)
182  */
183  virtual void enableDepthTest(bool state) {
184  depthTestEnabled=state;
185  }
186 
187  /**
188  * @brief Enable/disable if label is scaled to size
189  */
190  virtual void setScaleToSize(bool state) {
191  scaleToSize=state;
192  }
193 
194  /**
195  * @brief Set the stencil and draw the Label, this function is usefull when we directly call draw without tulip engine
196  */
197  void drawWithStencil(float lod,Camera *camera=NULL);
198 
199  /**
200  * @brief Return the height of the label after scaling in size box
201  */
202  float getHeightAfterScale();
203 
204  /**
205  * @brief Draw the Label
206  */
207  virtual void draw(float, Camera *camera=NULL);
208 
209  /**
210  * @brief Translate entity
211  */
212  virtual void translate(const Coord& mouvement);
213 
214  /**
215  * @brief Rotate Label
216  */
217  virtual void rotate(float xRot, float yRot, float zRot);
218 
219  /**
220  * @brief Function to export data in outString (in XML format)
221  */
222  virtual void getXML(std::string &outString);
223 
224  /**
225  * @brief Function to set data with inString (in XML format)
226  */
227  virtual void setWithXML(const std::string &inString, unsigned int &currentPosition);
228 
229  /**
230  * @brief Switch to bold font
231  */
232  virtual void setBoldFont();
233 
234  /**
235  * @brief Switch to plain font
236  */
237  virtual void setPlainFont();
238 
239  /**
240  * @brief Change font name
241  */
242  virtual void setFontName(const std::string &name);
243 
244  /**
245  * @brief Change font name, size and color of the text
246  */
247  virtual void setFontNameSizeAndColor(const std::string &name, const int &size, const Color &color);
248 
249  ///@cond DOXYGEN_HIDDEN
250  /**
251  * @brief This parameters is not used
252  */
253  virtual void setRenderingMode(int mode);
254  ///@endcond
255 
256  /**
257  * @brief Set the occlusion tester
258  * If occlusionTester is NULL : deactivate occlusion test
259  */
260  virtual void setOcclusionTester(OcclusionTest *tester) {
261  occlusionTester=tester;
262  }
263 
264  /**
265  * @brief Set if the label is otimized with the lod
266  */
267  virtual void setUseLODOptimisation(bool state,BoundingBox bb=BoundingBox()) {
268  useLOD=state;
269  lodBoundingBox=bb;
270  }
271 
272  /**
273  * @brief Return if the label is otimized with the lod
274  */
275  virtual bool getUseLODOptimisation() {
276  return useLOD;
277  }
278 
279  /**
280  * @brief Set labels density of occlusion test
281  * This density must be in interval -100 100
282  *
283  * - If density is equal to -100 : we don't have occlusion test
284  * - If density is equal to 0 : GlLabels don't overlap
285  * - If density > 0 : GlLabels don't overlap and have space wetween us
286  */
287  virtual void setLabelsDensity(int density) {
288  if(density<-100)
289  labelsDensity=-100;
290  else if(density>100)
291  labelsDensity=100;
292  else
293  labelsDensity=density;
294  }
295 
296  /**
297  * @brief Return label density of occlusion test
298  * This density will be in interval -100 100
299  */
300  virtual int getLabelDensity() {
301  return labelsDensity;
302  }
303 
304  /**
305  * @brief Set min screen size (in pixel) of the label : this size is used in not scaled mode
306  * @see setUseMinMaxSize
307  */
308  void setMinSize(int size) {
309  minSize=size;
310  }
311 
312  /**
313  * @brief Get min screen size (in pixel) of the label : this size is used in not scaled mode
314  * @see setUseMinMaxSize
315  */
316  int getMinSize() {
317  return minSize;
318  }
319 
320  /**
321  * @brief Set max screen size (in pixel) of the label : this size is used in not scaled mode
322  * @see setUseMinMaxSize
323  */
324  void setMaxSize(int size) {
325  maxSize=size;
326  }
327 
328  /**
329  * @brief Get max screen size (in pixel) of the label : this size is used in not scaled mode
330  * @see setUseMinMaxSize
331  */
332  int getMaxSize() {
333  return maxSize;
334  }
335 
336  /**
337  * @brief Set if the label use min/max screen size in not scaled mode
338  */
339  void setUseMinMaxSize(bool state) {
340  useMinMaxSize=state;
341  }
342 
343  /**
344  * @brief Return if the label using min/max screen size in not scaled mode
345  */
347  return useMinMaxSize;
348  }
349 
350  /**
351  * @brief Return the font size
352  */
353  int getFontSize() const {
354  return fontSize;
355  }
356 
357  /**
358  * @brief Sets the font size used when rendering the label.
359  */
360  void setFontSize(int size) {
361  fontSize = size;
362  }
363 
364  /**
365  * @brief Return the outline color
366  */
367  Color getOutlineColor() const {
368  return outlineColor;
369  }
370 
371  /**
372  * @brief Sets the outline color used when rendering the label.
373  */
374  void setOutlineColor(const Color &color) {
375  outlineColor = color;
376  }
377 
378  /**
379  * @brief Return the outline size
380  */
381  float getOutlineSize() const {
382  return outlineSize;
383  }
384 
385  /**
386  * @brief Sets the outline size used when rendering the label.
387  */
388  void setOutlineSize(float size) {
389  outlineSize = size;
390  }
391 
392  /**
393  * @brief Return the texture name used to render the label
394  */
395  std::string getTextureName() const {
396  return textureName;
397  }
398 
399  /**
400  * @brief Sets the texture name used when rendering the label.
401  */
402  void setTextureName(const std::string &name) {
403  textureName=name;
404  }
405 
406  /**
407  * @brief Return if the label is billboarded
408  */
409  bool isBillboarded() {
410  return billboarded;
411  }
412 
413  /**
414  * @brief Set if the label is billboarded
415  */
416  void setBillboarded(bool billboarded) {
417  this->billboarded=billboarded;
418  }
419 
420 private :
421 
422  std::string text;
423  std::string fontName;
424  int fontSize;
425  int renderingMode;
426  FTGLPolygonFont *font;
427  FTOutlineFont *borderFont;
428  Coord centerPosition;
429  Coord translationAfterRotation;
430  Size size;
431  Size sizeForOutAlign;
432  Color color;
433  Color outlineColor;
434  float outlineSize;
435  std::string textureName;
436  int alignment;
437  bool scaleToSize;
438  bool useMinMaxSize;
439  int minSize;
440  int maxSize;
441  bool depthTestEnabled;
442  bool leftAlign;
443  bool billboarded;
444  float xRot;
445  float yRot;
446  float zRot;
447  bool useLOD;
448  BoundingBox lodBoundingBox;
449  int labelsDensity;
450  OcclusionTest *occlusionTester;
451 
452  Camera oldCamera;
453  float oldLod;
454 
455  std::vector<std::string> textVector;
456  std::vector<float> textWidthVector;
457  BoundingBox textBoundingBox;
458 };
459 
460 }
461 #endif
462