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