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