OpenDAFF C++ API  v1.7
Directional Audio File Format
DAFFVizSphere.cpp
Go to the documentation of this file.
3 
4 #include <vtkActor.h>
5 #include <vtkSphereSource.h>
6 #include <vtkPolyDataMapper.h>
7 #include <vtkProperty.h>
8 #include "vtkPolyDataNormals.h"
9 
10 namespace DAFFViz
11 {
12 
14  : SGNode(), m_pSource(NULL), m_pMapper(NULL), m_pActor(NULL)
15  {
16  init();
17  }
18 
19  Sphere::Sphere(double dRadius, int iPhiResolution, int iThetaResolution)
20  : SGNode(), m_pSource(NULL), m_pMapper(NULL), m_pActor(NULL)
21  {
22  init();
23  m_pSource->SetRadius(dRadius);
24  m_pSource->SetPhiResolution(iPhiResolution);
25  m_pSource->SetThetaResolution( iThetaResolution );
26  m_pSource->Update();
27  }
28 
29  Sphere::Sphere( DAFFViz::SGNode* pParentNode, double dRadius, int iPhiResolution, int iThetaResolution )
30  : SGNode(pParentNode)
31  , m_pSource(NULL)
32  , m_pMapper(NULL)
33  , m_pActor(NULL)
34  {
35  init();
36  m_pSource->SetRadius(dRadius);
37  m_pSource->SetPhiResolution(iPhiResolution);
38  m_pSource->SetThetaResolution(iThetaResolution);
39  m_pSource->Update();
40  }
41 
43  {
44  RemoveActor( m_pActor );
45  }
46 
47  void Sphere::init()
48  {
49  m_pSource = vtkSmartPointer< vtkSphereSource >::New();
50 
51  m_pMapper = vtkSmartPointer< vtkPolyDataMapper >::New();
52  m_pMapper->SetInputConnection( m_pSource->GetOutputPort() );
53 
54  m_pActor = vtkSmartPointer< vtkActor >::New();
55  m_pActor->SetMapper( m_pMapper );
56 
57  m_pActor->GetProperty()->SetDiffuse( 0.9 );
58  m_pActor->GetProperty()->SetAmbient( 0.4 );
59 
60  AddActor( m_pActor );
61  }
62 
63 
64  // --= object related methods =--
65 
66  double Sphere::GetRadius() const {
67  return m_pSource->GetRadius();
68  }
69 
70  void Sphere::SetRadius(double dRadius) {
71  m_pSource->SetRadius(dRadius);
72  }
73 
74  void Sphere::SetPhiResolution(int iResolution) {
75  m_pSource->SetPhiResolution(iResolution);
76  }
77 
78  void Sphere::SetThetaResolution(int iResolution) {
79  m_pSource->SetThetaResolution(iResolution);
80  }
81 
83  return m_pSource->GetPhiResolution();
84  }
85 
87  return m_pSource->GetThetaResolution();
88  }
89 
90 
91  // --= general methods =--
92 
93  void Sphere::SetColor(const double r, const double g, const double b) {
95  m_pActor->GetProperty()->SetColor(r, g, b);
97  }
98 
99  void Sphere::GetColor(double& r, double& g, double& b) {
100  m_pActor->GetProperty()->GetColor(r, g, b);
101  }
102 
103  double Sphere::GetAlpha() const {
104  return m_pActor->GetProperty()->GetOpacity();
105  }
106 
107  void Sphere::SetAlpha(const double a) {
109  m_pActor->GetProperty()->SetOpacity(a);
111  }
112 
113  bool Sphere::IsVisible() const {
114  return m_pActor->GetVisibility() > 0 ? true : false;
115  }
116 
117  void Sphere::SetVisible(bool bVisible) {
118  SGNode::SetVisible(bVisible);
119 
121  if (bVisible)
122  m_pActor->VisibilityOn();
123  else
124  m_pActor->VisibilityOff();
126  }
127 
128 } // End of namespace "DAFFViz"
void AddActor(vtkSmartPointer< vtkActor > pActor)
Add a VTK actor to the node.
int GetThetaResolution() const
void SetThetaResolution(int iResolution)
void RemoveActor(vtkSmartPointer< vtkActor > pActor)
Remove a VTK actor from the assembly of the node.
#define DAFFVIZ_LOCK_VTK
#define NULL
Definition: DAFFDefs.h:59
void GetColor(double &r, double &g, double &b)
Color getter.
void SetPhiResolution(int iResolution)
virtual void SetVisible(bool bVisible)
Set visibility.
void SetAlpha(const double a)
Alpha setter.
Base class for scene graph nodes.
Definition: DAFFVizSGNode.h:67
bool IsVisible() const
Get visibility.
void SetColor(const double r, const double g, const double b)
Color setter.
#define DAFFVIZ_UNLOCK_VTK
void SetRadius(double dRadius)
double GetAlpha() const
Alpha getter.
void SetVisible(bool bVisible)
Set visibility.
double GetRadius() const
int GetPhiResolution() const
OpenDAFF is a project from the Institute of Technical Acoustics, RWTH Aachen University, Germany.