OpenDAFF C++ API  v1.7
Directional Audio File Format
DAFFVizLabel.cpp
Go to the documentation of this file.
1 #include <daffviz/DAFFVizLabel.h>
2 
4 
5 #include <vtkCamera.h>
6 #include <vtkFollower.h>
7 #include <vtkPolyDataMapper.h>
8 #include <vtkProperty.h>
9 #include <vtkVectorText.h>
10 
11 namespace DAFFViz
12 {
13 
15  : SGNode()
16  {
17  m_sText = "No label text set";
18  init();
19  }
20 
22  : SGNode(pNode)
23  {
24  m_sText = "No label text set";
25  init();
26  }
27 
28  Label::Label( SGNode* pNode, std::string sText )
29  : SGNode(pNode)
30  {
31  m_sText = sText;
32  init();
33  }
34 
35 
37  {
38  RemoveActor( m_pFollower );
39  }
40 
41  void Label::init()
42  {
43  m_pLabelText = vtkSmartPointer< vtkVectorText >::New();
44  m_pLabelText->SetText( m_sText.c_str() );
45 
46  m_pMapper = vtkSmartPointer< vtkPolyDataMapper >::New();
47  m_pMapper->SetInputConnection( m_pLabelText->GetOutputPort() );
48 
49  m_pFollower = vtkSmartPointer< vtkFollower >::New();
50  m_pFollower->SetMapper( m_pMapper );
51 
52  m_pFollower->SetScale( 0.1, 0.1, 0.1 );
53 
54  AddActor( m_pFollower );
55  }
56 
57  // --= general methods =--
58 
59  void Label::GetColor(double& r, double& g, double& b) const
60  {
61  m_pFollower->GetProperty()->GetColor( r, g, b );
62  }
63 
64  void Label::SetColor( double r, double g, double b )
65  {
67  m_pFollower->GetProperty()->SetColor( r, g, b );
69  }
70 
71  double Label::GetAlpha() const
72  {
73  return m_pFollower->GetProperty()->GetOpacity();
74  }
75 
76  void Label::SetAlpha( double a )
77  {
79  m_pFollower->GetProperty()->SetOpacity(a);
81  }
82 
83  void Label::SetVisible( bool bVisible )
84  {
85  // keep visibility traversal
86  SGNode::SetVisible( bVisible );
88  if( bVisible )
89  m_pFollower->VisibilityOn();
90  else
91  m_pFollower->VisibilityOff();
93  }
94 
95  bool Label::IsVisible() const
96  {
97  return m_pFollower->GetVisibility() > 0 ? true : false;
98  }
99 
100 
101  // --= object related methods =--
102 
103  void Label::SetText( const std::string& s )
104  {
106  m_pLabelText->SetText( s.c_str() );
108  }
109 
110  void Label::OnSetFollowerCamera( vtkSmartPointer< vtkCamera > pCamera )
111  {
112  //DAFFVIZ_LOCK_VTK;
113  m_pFollower->SetCamera( pCamera );
114  //DAFFVIZ_UNLOCK_VTK;
115 
116  // Delegate
118  }
119 
120 } // End of namespace "DAFFViz"
void AddActor(vtkSmartPointer< vtkActor > pActor)
Add a VTK actor to the node.
void SetColor(double r, double g, double b)
Color setter.
void RemoveActor(vtkSmartPointer< vtkActor > pActor)
Remove a VTK actor from the assembly of the node.
#define DAFFVIZ_LOCK_VTK
virtual void OnSetFollowerCamera(vtkSmartPointer< vtkCamera > pCamera)
Set active camera for followers.
void GetColor(double &r, double &g, double &b) const
Color getter.
bool IsVisible() const
Get visibility.
void SetAlpha(double a)
Alpha setter.
virtual void SetVisible(bool bVisible)
Set visibility.
void SetText(const std::string &sText)
Label text setter.
Base class for scene graph nodes.
Definition: DAFFVizSGNode.h:67
double GetAlpha() const
Alpha getter.
#define DAFFVIZ_UNLOCK_VTK
void SetVisible(bool bVisible)
Set visibility.
OpenDAFF is a project from the Institute of Technical Acoustics, RWTH Aachen University, Germany.