Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 00020 #ifndef Tulip_GLLABEL_H 00021 #define Tulip_GLLABEL_H 00022 00023 #include <tulip/Coord.h> 00024 #include <tulip/Color.h> 00025 #include <tulip/Size.h> 00026 #include <tulip/Camera.h> 00027 #include <tulip/GlSimpleEntity.h> 00028 #include <tulip/TulipViewSettings.h> 00029 00030 class FTGLPolygonFont; 00031 class FTOutlineFont; 00032 00033 namespace tlp { 00034 00035 struct OcclusionTest; 00036 00037 #define MIN_LABEL_POSITION LabelPosition::Center 00038 #define MAX_LABEL_POSITION LabelPosition::Right 00039 00040 /** 00041 * @ingroup OpenGL 00042 * @brief Create a label into Tulip 3D engine 00043 * 00044 * The shortes way to create a label is : 00045 * @code 00046 * GlLabel *label=new GlLabel(Coord(0,0,0), Size (1,1,1), Color(1,1,1)); 00047 * label->setText("example"); 00048 * @endcode 00049 */ 00050 class TLP_GL_SCOPE GlLabel : public GlSimpleEntity { 00051 public : 00052 00053 /** 00054 * @brief Constructor 00055 * @warning Don't use this constructor : see other constructor 00056 */ 00057 GlLabel(); 00058 00059 /** 00060 * @brief Contructor 00061 * @param centerPosition position of the label 00062 * @param size size of the label 00063 * @param fontColor color of the label 00064 * @param leftAlign true if you want a left align label 00065 */ 00066 GlLabel(Coord centerPosition,Size size,Color fontColor,bool leftAlign=false); 00067 00068 /** 00069 * @brief Destructor 00070 */ 00071 ~GlLabel(); 00072 00073 /** 00074 * @brief Set default parameters of GlLabel 00075 * 00076 * This function is call by constructor, so you don't have to call it 00077 */ 00078 void init(); 00079 00080 /** 00081 * @brief Set the text of the label 00082 */ 00083 void setText(const std::string& text); 00084 00085 /** 00086 * @brief getText gets the text of this label. 00087 * @return The text of this label. 00088 */ 00089 const std::string& getText() const; 00090 00091 /** 00092 * @brief Set the position used to render the label 00093 */ 00094 void setPosition(const Coord &position); 00095 00096 /** 00097 * @brief Return the position of the label 00098 */ 00099 Coord getPosition(); 00100 00101 ///@cond DOXYGEN_HIDDEN 00102 00103 /** 00104 * @brief Set the translation used after rotation of the label 00105 */ 00106 virtual void setTranslationAfterRotation(Coord translation) { 00107 translationAfterRotation=translation; 00108 } 00109 00110 /** 00111 * @brief return the translation used after rotation of the label 00112 */ 00113 virtual Coord getTranslationAfterRotation() { 00114 return translationAfterRotation; 00115 } 00116 00117 ///@endcond 00118 00119 /** 00120 * @brief Set the alignment of the label : LabelPosition::Center, LabelPosition::Top, LabelPosition::Bottom, LabelPosition::Left, LabelPosition::Right 00121 * 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 00122 * @see LabelPosition 00123 * @see setSizeOfOutAlign 00124 */ 00125 virtual void setAlignment(int alignment) { 00126 this->alignment=alignment; 00127 } 00128 00129 /** 00130 * @brief Return the bounding box of the label 00131 */ 00132 virtual BoundingBox getBoundingBox(); 00133 00134 /** 00135 * @brief Return the bounding box of the text of the label after transformations 00136 */ 00137 virtual BoundingBox getTextBoundingBox(); 00138 00139 /** 00140 * @brief Set the size of the label 00141 */ 00142 virtual void setSize(const Size &size); 00143 00144 /** 00145 * @brief return the size of the text 00146 */ 00147 virtual Size getSize(); 00148 00149 /** 00150 * @brief Set the size for alignment outside (left/right/top/bottom) 00151 * 00152 * You can have a specific size when you want a label outside 00153 * @see setAlignment 00154 * 00155 * @Warning : this size is reinit when you call setSize 00156 */ 00157 virtual void setSizeForOutAlign(const Size &size); 00158 00159 /** 00160 * @brief return the size for alignment outside (left/right/top/bottom) 00161 * @see setAlignment 00162 */ 00163 virtual Size getSizeForOutAlign(); 00164 00165 /** 00166 * @brief Set color of label 00167 */ 00168 virtual void setColor(const Color &color) { 00169 this->color=color; 00170 } 00171 00172 /** 00173 * @brief Get color use to render the label 00174 */ 00175 virtual Color getColor() { 00176 return color; 00177 } 00178 00179 /** 00180 * @brief Enable/disable the OpenGL depth test for the label (default depth test is enable) 00181 */ 00182 virtual void enableDepthTest(bool state) { 00183 depthTestEnabled=state; 00184 } 00185 00186 /** 00187 * @brief Enable/disable if label is scaled to size 00188 */ 00189 virtual void setScaleToSize(bool state) { 00190 scaleToSize=state; 00191 } 00192 00193 /** 00194 * @brief Set the stencil and draw the Label, this function is usefull when we directly call draw without tulip engine 00195 */ 00196 void drawWithStencil(float lod,Camera *camera=NULL); 00197 00198 /** 00199 * @brief Return the height of the label after scaling in size box 00200 */ 00201 float getHeightAfterScale(); 00202 00203 /** 00204 * @brief Draw the Label 00205 */ 00206 virtual void draw(float, Camera *camera=NULL); 00207 00208 /** 00209 * @brief Translate entity 00210 */ 00211 virtual void translate(const Coord& mouvement); 00212 00213 /** 00214 * @brief Rotate Label 00215 */ 00216 virtual void rotate(float xRot, float yRot, float zRot); 00217 00218 /** 00219 * @brief Function to export data in outString (in XML format) 00220 */ 00221 virtual void getXML(std::string &outString); 00222 00223 /** 00224 * @brief Function to set data with inString (in XML format) 00225 */ 00226 virtual void setWithXML(const std::string &inString, unsigned int ¤tPosition); 00227 00228 /** 00229 * @brief Switch to bold font 00230 */ 00231 virtual void setBoldFont(); 00232 00233 /** 00234 * @brief Switch to plain font 00235 */ 00236 virtual void setPlainFont(); 00237 00238 /** 00239 * @brief Change font name 00240 */ 00241 virtual void setFontName(const std::string &name); 00242 00243 /** 00244 * @brief Change font name, size and color of the text 00245 */ 00246 virtual void setFontNameSizeAndColor(const std::string &name, const int &size, const Color &color); 00247 00248 ///@cond DOXYGEN_HIDDEN 00249 /** 00250 * @brief This parameters is not used 00251 */ 00252 virtual void setRenderingMode(int mode); 00253 ///@endcond 00254 00255 /** 00256 * @brief Set the occlusion tester 00257 * If occlusionTester is NULL : deactivate occlusion test 00258 */ 00259 virtual void setOcclusionTester(OcclusionTest *tester) { 00260 occlusionTester=tester; 00261 } 00262 00263 /** 00264 * @brief Set if the label is otimized with the lod 00265 */ 00266 virtual void setUseLODOptimisation(bool state,BoundingBox bb=BoundingBox()) { 00267 useLOD=state; 00268 lodBoundingBox=bb; 00269 } 00270 00271 /** 00272 * @brief Return if the label is otimized with the lod 00273 */ 00274 virtual bool getUseLODOptimisation() { 00275 return useLOD; 00276 } 00277 00278 /** 00279 * @brief Set labels density of occlusion test 00280 * This density must be in interval -100 100 00281 * 00282 * - If density is equal to -100 : we don't have occlusion test 00283 * - If density is equal to 0 : GlLabels don't overlap 00284 * - If density > 0 : GlLabels don't overlap and have space wetween us 00285 */ 00286 virtual void setLabelsDensity(int density) { 00287 if(density<-100) 00288 labelsDensity=-100; 00289 else if(density>100) 00290 labelsDensity=100; 00291 else 00292 labelsDensity=density; 00293 } 00294 00295 /** 00296 * @brief Return label density of occlusion test 00297 * This density will be in interval -100 100 00298 */ 00299 virtual int getLabelDensity() { 00300 return labelsDensity; 00301 } 00302 00303 /** 00304 * @brief Set min screen size (in pixel) of the label : this size is used in not scaled mode 00305 * @see setUseMinMaxSize 00306 */ 00307 void setMinSize(int size) { 00308 minSize=size; 00309 } 00310 00311 /** 00312 * @brief Get min screen size (in pixel) of the label : this size is used in not scaled mode 00313 * @see setUseMinMaxSize 00314 */ 00315 int getMinSize() { 00316 return minSize; 00317 } 00318 00319 /** 00320 * @brief Set max screen size (in pixel) of the label : this size is used in not scaled mode 00321 * @see setUseMinMaxSize 00322 */ 00323 void setMaxSize(int size) { 00324 maxSize=size; 00325 } 00326 00327 /** 00328 * @brief Get max screen size (in pixel) of the label : this size is used in not scaled mode 00329 * @see setUseMinMaxSize 00330 */ 00331 int getMaxSize() { 00332 return maxSize; 00333 } 00334 00335 /** 00336 * @brief Set if the label use min/max screen size in not scaled mode 00337 */ 00338 void setUseMinMaxSize(bool state) { 00339 useMinMaxSize=state; 00340 } 00341 00342 /** 00343 * @brief Return if the label using min/max screen size in not scaled mode 00344 */ 00345 bool isUsingMinMaxSize() { 00346 return useMinMaxSize; 00347 } 00348 00349 /** 00350 * @brief Return the font size 00351 */ 00352 int getFontSize() const { 00353 return fontSize; 00354 } 00355 00356 /** 00357 * @brief Sets the font size used when rendering the label. 00358 */ 00359 void setFontSize(int size) { 00360 fontSize = size; 00361 } 00362 00363 /** 00364 * @brief Return the outline color 00365 */ 00366 Color getOutlineColor() const { 00367 return outlineColor; 00368 } 00369 00370 /** 00371 * @brief Sets the outline color used when rendering the label. 00372 */ 00373 void setOutlineColor(const Color &color) { 00374 outlineColor = color; 00375 } 00376 00377 /** 00378 * @brief Return the outline size 00379 */ 00380 float getOutlineSize() const { 00381 return outlineSize; 00382 } 00383 00384 /** 00385 * @brief Sets the outline size used when rendering the label. 00386 */ 00387 void setOutlineSize(float size) { 00388 outlineSize = size; 00389 } 00390 00391 /** 00392 * @brief Return the texture name used to render the label 00393 */ 00394 std::string getTextureName() const { 00395 return textureName; 00396 } 00397 00398 /** 00399 * @brief Sets the texture name used when rendering the label. 00400 */ 00401 void setTextureName(const std::string &name) { 00402 textureName=name; 00403 } 00404 00405 /** 00406 * @brief Return if the label is billboarded 00407 */ 00408 bool isBillboarded() { 00409 return billboarded; 00410 } 00411 00412 /** 00413 * @brief Set if the label is billboarded 00414 */ 00415 void setBillboarded(bool billboarded) { 00416 this->billboarded=billboarded; 00417 } 00418 00419 private : 00420 00421 std::string text; 00422 std::string fontName; 00423 int fontSize; 00424 int renderingMode; 00425 FTGLPolygonFont *font; 00426 FTOutlineFont *borderFont; 00427 Coord centerPosition; 00428 Coord translationAfterRotation; 00429 Size size; 00430 Size sizeForOutAlign; 00431 Color color; 00432 Color outlineColor; 00433 float outlineSize; 00434 std::string textureName; 00435 int alignment; 00436 bool scaleToSize; 00437 bool useMinMaxSize; 00438 int minSize; 00439 int maxSize; 00440 bool depthTestEnabled; 00441 bool leftAlign; 00442 bool billboarded; 00443 float xRot; 00444 float yRot; 00445 float zRot; 00446 bool useLOD; 00447 BoundingBox lodBoundingBox; 00448 int labelsDensity; 00449 OcclusionTest *occlusionTester; 00450 00451 Camera oldCamera; 00452 float oldLod; 00453 Vec4i oldViewport; 00454 00455 std::vector<std::string> textVector; 00456 std::vector<float> textWidthVector; 00457 BoundingBox textBoundingBox; 00458 }; 00459 00460 } 00461 #endif 00462