OpenDAFF C++ API  v1.7
Directional Audio File Format
DAFFVizGrid.cpp
Go to the documentation of this file.
1 #include <daffviz/DAFFVizGrid.h>
3 
4 #include <vtkActor.h>
5 #include <vtkCellArray.h>
6 #include <vtkDataSetMapper.h>
7 #include <vtkLine.h>
8 #include <vtkPoints.h>
9 #include <vtkPolyData.h>
10 #include <vtkPolyDataMapper.h>
11 #include <vtkProperty.h>
12 #include <vtkPolygon.h>
13 #include <vtkUnstructuredGrid.h>
14 
15 namespace DAFFViz
16 {
17 
18  Grid::Grid(unsigned int iCellsX, unsigned int iCellsZ)
19  : SGNode(), m_iCellsX(iCellsX), m_iCellsZ(iCellsZ)
20  {
21  if (m_iCellsX == 0)
22  m_iCellsX = 10;
23 
24  if (m_iCellsZ == 0)
25  m_iCellsZ = 10;
26 
27  init();
28  }
29 
30  Grid::Grid(DAFFViz::SGNode* pParentNode, unsigned int iCellsX, unsigned int iCellsZ)
31  : SGNode(pParentNode), m_iCellsX(iCellsX), m_iCellsZ(iCellsZ)
32  {
33  if (m_iCellsX == 0)
34  m_iCellsX = 10;
35 
36  if (m_iCellsZ == 0)
37  m_iCellsZ = 10;
38 
39  init();
40  }
41 
43  {
44  RemoveActor( m_pActorGrid );
45  }
46 
47  void Grid::init()
48  {
49  // Points
50  vtkSmartPointer< vtkPoints > pGridPoints = vtkSmartPointer< vtkPoints >::New();
51 
52  // Grids
53  vtkSmartPointer< vtkUnstructuredGrid > pGrid = vtkSmartPointer< vtkUnstructuredGrid >::New();
54 
55  pGrid->SetPoints( pGridPoints );
56  pGrid->Allocate( m_iCellsX + m_iCellsZ + 2, 1 );
57 
58  // Helper
59  vtkSmartPointer< vtkLine > pLine = vtkSmartPointer< vtkLine >::New();
60 
61  // Create grid
62  int k = 0;
63  int subk = 0;
64 
65  // X direction lines
66  for( int i = 0; i <= m_iCellsX; i++ )
67  {
68  pGridPoints->InsertPoint(k++, i/(double) m_iCellsX, 0, 0);
69  pGridPoints->InsertPoint(k++, i/(double) m_iCellsX, 0, 1);
70  pLine->GetPointIds()->SetId(0, k-2);
71  pLine->GetPointIds()->SetId(1, k-1);
72  pGrid->InsertNextCell( pLine->GetCellType(), pLine->GetPointIds() );
73  }
74 
75  // Z direction lines
76  for( int i = 0; i <= m_iCellsZ; i++ )
77  {
78  pGridPoints->InsertPoint(k++, 0, 0, i/(double) m_iCellsZ);
79  pGridPoints->InsertPoint(k++, 1, 0, i/(double) m_iCellsZ);
80  pLine->GetPointIds()->SetId(0, k-2);
81  pLine->GetPointIds()->SetId(1, k-1);
82  pGrid->InsertNextCell( pLine->GetCellType(), pLine->GetPointIds() );
83  }
84 
85  // Grid actor
86  vtkSmartPointer< vtkDataSetMapper > pGridMapper = vtkSmartPointer< vtkDataSetMapper >::New();
87  pGridMapper->SetInputData( pGrid );
88 
89  m_pActorGrid = vtkSmartPointer< vtkActor >::New();
90  m_pActorGrid->SetMapper( pGridMapper );
91 
93  m_pActorGrid->GetProperty()->SetAmbient(1);
94  m_pActorGrid->GetProperty()->SetDiffuse(0);
95  m_pActorGrid->GetProperty()->SetSpecular(0);
96  double dGridColor = 0.4;
97  m_pActorGrid->GetProperty()->SetColor( dGridColor, dGridColor, dGridColor );
98  m_pActorGrid->GetProperty()->SetOpacity( 0.8 );
100 
101  AddActor( m_pActorGrid );
102  }
103 
104  bool Grid::IsVisible() const
105  {
106  return m_pActorGrid->GetVisibility() ? true : false;
107  }
108 
109  void Grid::SetVisible( bool bVisible )
110  {
111  SGNode::SetVisible(bVisible);
112 
114  bVisible ? m_pActorGrid->VisibilityOn() : m_pActorGrid->VisibilityOff();
116  }
117 
118 } // End of namespace "DAFFViz"
void AddActor(vtkSmartPointer< vtkActor > pActor)
Add a VTK actor to the node.
void SetVisible(bool bVisible)
Set visibility.
void RemoveActor(vtkSmartPointer< vtkActor > pActor)
Remove a VTK actor from the assembly of the node.
#define DAFFVIZ_LOCK_VTK
virtual void SetVisible(bool bVisible)
Set visibility.
Base class for scene graph nodes.
Definition: DAFFVizSGNode.h:67
#define DAFFVIZ_UNLOCK_VTK
Grid(DAFFViz::SGNode *pParentNode, unsigned int iCellsX=10, unsigned int iCellsZ=10)
Definition: DAFFVizGrid.cpp:30
bool IsVisible() const
Get visibility.
OpenDAFF is a project from the Institute of Technical Acoustics, RWTH Aachen University, Germany.