OpenDAFF C++ API  v1.7
Directional Audio File Format
DAFFVizArrow.cpp
Go to the documentation of this file.
1 #include <daffviz/DAFFVizArrow.h>
3 
4 #include <vtkActor.h>
5 #include <vtkArrowSource.h>
6 #include <vtkPolyDataMapper.h>
7 #include <vtkPolyDataNormals.h>
8 #include <vtkProperty.h>
9 
10 namespace DAFFViz
11 {
12  Arrow::Arrow( DAFFViz::SGNode* pParentNode, double dTipLength, double dTipRadius, int iTipResolution, double dShaftRadius, int iShaftResolution )
13  : SGNode( pParentNode )
14  , m_pSource( NULL )
15  , m_pMapper( NULL )
16  , m_pActor( NULL )
17  {
18  init();
19  m_pSource->SetTipLength( dTipLength );
20  m_pSource->SetTipRadius( dTipRadius );
21  m_pSource->SetTipResolution( iTipResolution );
22  m_pSource->SetShaftRadius( dShaftRadius );
23  m_pSource->SetShaftResolution( iShaftResolution );
24  m_pSource->Update();
25  }
26 
28  {
29  RemoveActor( m_pActor );
30  }
31 
32  void Arrow::init()
33  {
34  m_pSource = vtkSmartPointer<vtkArrowSource>::New();
35 
36  m_pMapper = vtkSmartPointer< vtkPolyDataMapper >::New();
37  m_pMapper->SetInputConnection( m_pSource->GetOutputPort() );
38 
39  m_pActor = vtkSmartPointer< vtkActor >::New();
40  m_pActor->SetMapper( m_pMapper );
41 
42  m_pActor->GetProperty()->SetInterpolationToGouraud();
43  m_pActor->GetProperty()->SetDiffuse( 0.9 );
44  m_pActor->GetProperty()->SetAmbient( 0.4 );
45 
46  AddActor( m_pActor );
47  }
48 
49  // --= object related methods =--
50 
51  double Arrow::GetTipLength() const
52  {
53  return m_pSource->GetTipLength();
54  }
55 
56  void Arrow::SetTipLength( double dLength ) {
57  m_pSource->SetTipLength( dLength );
58  }
59 
60  double Arrow::GetTipRadius() const {
61  return m_pSource->GetTipLength();
62  }
63 
64  void Arrow::SetTipRadius( double dRadius ) {
65  m_pSource->SetTipLength( dRadius );
66  }
67 
68  void Arrow::SetTipResolution( int iResolution ) {
69  m_pSource->SetTipResolution( iResolution );
70  }
71 
73  return m_pSource->GetTipResolution();
74  }
75 
76  double Arrow::GetShaftRadius() const {
77  return m_pSource->GetShaftRadius();
78  }
79 
80  void Arrow::SetShaftRadius( double dRadius ) {
81  m_pSource->SetShaftRadius( dRadius );
82  }
83 
85  return m_pSource->GetShaftResolution();
86  }
87 
88  void Arrow::SetShaftResolution( int iResolution ) {
89  m_pSource->SetShaftResolution( iResolution );
90  }
91 
92 
93  // --= general methods =--
94 
95  void Arrow::SetColor( const double r, const double g, const double b ) {
97  m_pActor->GetProperty()->SetColor( r, g, b );
99  }
100 
101  void Arrow::GetColor( double& r, double& g, double& b ) {
102  m_pActor->GetProperty()->GetColor( r, g, b );
103  }
104 
105  double Arrow::GetAlpha() const {
106  return m_pActor->GetProperty()->GetOpacity();
107  }
108 
109  void Arrow::SetAlpha( const double a ) {
111  m_pActor->GetProperty()->SetOpacity( a );
113  }
114 
115  void Arrow::SetVisible( bool bVisible ) {
116  // keep visibility traversal
117  SGNode::SetVisible( bVisible );
118 
120  if( bVisible )
121  m_pActor->VisibilityOn();
122  else
123  m_pActor->VisibilityOff();
125  }
126 
127  bool Arrow::IsVisible() const {
128  return m_pActor->GetVisibility() > 0 ? true : false;
129  }
130 
131 } // End of namespace "DAFFViz"
void SetAlpha(double a)
Alpha setter.
bool IsVisible() const
Get visibility.
void AddActor(vtkSmartPointer< vtkActor > pActor)
Add a VTK actor to the node.
Arrow(DAFFViz::SGNode *pParentNode=NULL, double dTipLength=.15f, double dTipRadius=.06f, int iTipResolution=36, double dShaftRadius=.02f, int iShaftResolution=36)
Constructor.
double GetAlpha() const
Alpha getter.
void SetTipLength(double dLength)
Tip length setter.
void RemoveActor(vtkSmartPointer< vtkActor > pActor)
Remove a VTK actor from the assembly of the node.
virtual ~Arrow()
double GetTipRadius() const
Tip radius getter.
int GetShaftResolution() const
Shaft resolution getter.
#define DAFFVIZ_LOCK_VTK
#define NULL
Definition: DAFFDefs.h:59
void SetVisible(bool bVisible)
Set visibility.
double GetShaftRadius() const
Shaft radius getter.
int GetTipResolution() const
Tip resolution getter.
virtual void SetVisible(bool bVisible)
Set visibility.
double GetTipLength() const
Tip length getter.
void SetColor(double r, double g, double b)
Color setter.
Base class for scene graph nodes.
Definition: DAFFVizSGNode.h:67
void SetTipRadius(double dRadius)
Tip radius setter.
void GetColor(double &r, double &g, double &b)
Color getter.
void SetShaftRadius(double dRadius)
Shaft radius setter.
void SetShaftResolution(int iResolution)
Shaft resolution setter.
#define DAFFVIZ_UNLOCK_VTK
void SetTipResolution(int iResolution)
Tip resolution setter.
OpenDAFF is a project from the Institute of Technical Acoustics, RWTH Aachen University, Germany.