![]() |
MechSys
1.0
Computing library for simulations in continuum and discrete mechanics
|
00001 /************************************************************************ 00002 * MechSys - Open Library for Mechanical Systems * 00003 * Copyright (C) 2005 Dorival M. Pedroso, Raúl D. D. Farfan * 00004 * * 00005 * This program is free software: you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation, either version 3 of the License, or * 00008 * any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00017 ************************************************************************/ 00018 00019 #ifndef MECHSYS_TEXT_H 00020 #define MECHSYS_TEXT_H 00021 00022 // VTK 00023 #include <vtkTextActor3D.h> 00024 #include <vtkTextProperty.h> 00025 00026 // MechSys 00027 #include <mechsys/vtk/win.h> 00028 #include <mechsys/util/colors.h> 00029 00030 namespace VTK 00031 { 00032 00033 class Text 00034 { 00035 public: 00036 // Constructor & Destructor 00037 Text () { _create(); } 00038 ~Text (); 00039 00040 // Alternative constructor 00041 Text (Vec3_t const & X, char const * Txt) { _create(); SetPos(X); SetText(Txt); } 00042 00043 // Set methods 00044 Text & SetText (char const * Txt) { _text_actor->SetInput (Txt); return (*this); } 00045 Text & SetPos (Vec3_t const & X) { _text_actor->SetPosition (X(0),X(1),X(2)); return (*this); } 00046 Text & SetOri (double AlpX=90.0, double AlpY=90.0, double AlpZ=45.0) { _text_actor->SetOrientation(AlpX,AlpY,AlpZ); return (*this); } 00047 Text & SetProps (double Scale=0.003, int SizePt=14, bool Shadow=true); 00048 Text & SetColor (char const * Name="blue"); 00049 00050 // Methods 00051 void AddTo (VTK::Win & win) { win.AddActor(reinterpret_cast<vtkActor*>(_text_actor)); } 00052 00053 private: 00054 vtkTextActor3D * _text_actor; 00055 vtkTextProperty * _text_prop; 00056 void _create (); 00057 }; 00058 00059 00061 00062 00063 inline Text::~Text () 00064 { 00065 _text_actor -> Delete(); 00066 _text_prop -> Delete(); 00067 } 00068 00069 inline Text & Text::SetProps (double Scale, int SizePt, bool Shadow) 00070 { 00071 _text_actor -> SetScale (Scale); 00072 _text_prop -> SetFontSize (SizePt); 00073 _text_prop -> SetShadow (Shadow); 00074 return (*this); 00075 } 00076 00077 inline Text & Text::SetColor (char const * Name) 00078 { 00079 Vec3_t c(Colors::Get(Name)); 00080 _text_prop->SetColor (c.data()); 00081 return (*this); 00082 } 00083 00084 inline void Text::_create () 00085 { 00086 _text_prop = vtkTextProperty ::New(); 00087 _text_actor = vtkTextActor3D ::New(); 00088 _text_actor -> SetTextProperty (_text_prop); 00089 SetOri (); 00090 SetProps (); 00091 SetColor (); 00092 } 00093 00094 }; // namespace VTK 00095 00096 #endif // MECHSYS_TEXT_H