OpenDAFF C++ API  v1.7
Directional Audio File Format
DAFFVizLine.cpp
Go to the documentation of this file.
1 #include <daffviz/DAFFVizLine.h>
3 
4 #include <vtkActor.h>
5 #include <vtkLineSource.h>
6 #include <vtkPolyDataMapper.h>
7 #include <vtkProperty.h>
8 #include <vtkSmartPointer.h>
9 
10 namespace DAFFViz
11 {
12 
14  : SGNode(), m_pSource( NULL )
15  , m_pMapper( NULL )
16  , m_pActor( NULL )
17  {
18  init();
19  }
20 
21  Line::Line( double x1, double y1, double z1, double x2, double y2, double z2 )
22  : SGNode(), m_pSource( NULL )
23  , m_pMapper( NULL )
24  , m_pActor( NULL )
25  {
26  init();
27  m_pSource->SetPoint1( x1, y1, z1 );
28  m_pSource->SetPoint1( x1, y1, z1 );
29  }
30 
31  Line::Line( DAFFViz::SGNode* pParentNode, double x1, double y1, double z1, double x2, double y2, double z2 )
32  : SGNode( pParentNode )
33  , m_pSource( NULL )
34  , m_pMapper( NULL )
35  , m_pActor( NULL )
36  {
37  init();
38  m_pSource->SetPoint1( x1, y1, z1 );
39  m_pSource->SetPoint2( x2, y2, z2 );
40  }
41 
43  {
44  RemoveActor( m_pActor );
45  }
46 
47  void Line::init()
48  {
49  m_pSource = vtkSmartPointer< vtkLineSource >::New();
50 
51  m_pMapper = vtkSmartPointer< vtkPolyDataMapper >::New();
52  m_pMapper->SetInputData( m_pSource->GetOutput() );
53 
54  m_pActor = vtkSmartPointer< vtkActor >::New();
55  m_pActor->SetMapper( m_pMapper );
56 
57  AddActor( m_pActor );
58  }
59 
60 
61  // --= object related methods =--
62 
63  void Line::GetPoint1(double& x, double& y, double& z) const
64  {
65  double* data = m_pSource->GetPoint1();
66  x = data[0];
67  y = data[1];
68  z = data[2];
69  }
70 
71  void Line::SetPoint1( double x, double y, double z )
72  {
73  m_pSource->SetPoint1( x, y, z );
74  }
75 
76  void Line::GetPoint2( double& x, double& y, double& z ) const
77  {
78  double* data = m_pSource->GetPoint2();
79  x = data[0];
80  y = data[1];
81  z = data[2];
82  }
83 
84  void Line::SetPoint2( double x, double y, double z )
85  {
86  m_pSource->SetPoint2( x, y, z );
87  }
88 
89 
90  // --= general methods =--
91 
92  void Line::SetColor( double r, double g, double b )
93  {
95  m_pActor->GetProperty()->SetColor( r, g, b );
97  }
98 
99  void Line::GetColor( double& r, double& g, double& b )
100  {
101  m_pActor->GetProperty()->GetColor( r, g, b );
102  }
103 
104  double Line::GetAlpha() const
105  {
106  return m_pActor->GetProperty()->GetOpacity();
107  }
108 
109  void Line::SetAlpha( double a )
110  {
112  m_pActor->GetProperty()->SetOpacity( a );
114  }
115 
116  bool Line::IsVisible() const
117  {
118  return m_pActor->GetVisibility() > 0 ? true : false;
119  }
120 
121  void Line::SetVisible( bool bVisible )
122  {
123  SGNode::SetVisible( bVisible );
124 
126  if( bVisible )
127  m_pActor->VisibilityOn();
128  else
129  m_pActor->VisibilityOff();
131  }
132 
133 } // 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.
Definition: DAFFVizLine.cpp:92
void SetPoint2(double x, double y, double z)
Definition: DAFFVizLine.cpp:84
void RemoveActor(vtkSmartPointer< vtkActor > pActor)
Remove a VTK actor from the assembly of the node.
void GetColor(double &r, double &g, double &b)
Color getter.
Definition: DAFFVizLine.cpp:99
void SetAlpha(const double a)
Alpha setter.
#define DAFFVIZ_LOCK_VTK
void GetPoint2(double &x, double &y, double &z) const
Definition: DAFFVizLine.cpp:76
void GetPoint1(double &x, double &y, double &z) const
Definition: DAFFVizLine.cpp:63
#define NULL
Definition: DAFFDefs.h:59
virtual void SetVisible(bool bVisible)
Set visibility.
void SetPoint1(double x, double y, double z)
Definition: DAFFVizLine.cpp:71
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.
bool IsVisible() const
Get visibility.
OpenDAFF is a project from the Institute of Technical Acoustics, RWTH Aachen University, Germany.