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