1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkPlaybackRepresentation.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkPlaybackRepresentation.h"
16 #include "vtkActor2D.h"
17 #include "vtkCallbackCommand.h"
18 #include "vtkCamera.h"
19 #include "vtkCameraInterpolator.h"
20 #include "vtkCellArray.h"
21 #include "vtkObjectFactory.h"
22 #include "vtkPoints.h"
23 #include "vtkPolyData.h"
24 #include "vtkPolyDataMapper2D.h"
25 #include "vtkProperty2D.h"
26 #include "vtkRenderWindow.h"
27 #include "vtkRenderWindowInteractor.h"
28 #include "vtkRenderer.h"
29 #include "vtkTransform.h"
30 #include "vtkTransformPolyDataFilter.h"
31 
32 vtkStandardNewMacro(vtkPlaybackRepresentation);
33 
vtkPlaybackRepresentation()34 vtkPlaybackRepresentation::vtkPlaybackRepresentation()
35 {
36   // Set up the geometry
37   double size[2];
38   this->GetSize(size);
39   this->Position2Coordinate->SetValue(0.04 * size[0], 0.04 * size[1]);
40   this->ProportionalResize = 1;
41   this->Moving = 1;
42   this->SetShowBorder(vtkBorderRepresentation::BORDER_ON);
43 
44   // Create the geometry in canonical coordinates
45   this->Points = vtkPoints::New();
46   this->Points->SetDataTypeToDouble();
47   this->Points->SetNumberOfPoints(43);
48   this->Points->SetPoint(0, 0.3, 0.2, 0.0);
49   this->Points->SetPoint(1, 0.3, 1.8, 0.0);
50   this->Points->SetPoint(2, 0.3, 1.0, 0.0);
51   this->Points->SetPoint(3, 1.0, 0.2, 0.0);
52   this->Points->SetPoint(4, 1.0, 1.8, 0.0);
53   this->Points->SetPoint(5, 1.0, 1.0, 0.0);
54   this->Points->SetPoint(6, 1.7, 0.2, 0.0);
55   this->Points->SetPoint(7, 1.7, 1.8, 0.0);
56   this->Points->SetPoint(8, 2.3, 0.3, 0.0);
57   this->Points->SetPoint(9, 2.5, 0.3, 0.0);
58   this->Points->SetPoint(10, 2.5, 0.5, 0.0);
59   this->Points->SetPoint(11, 2.3, 0.5, 0.0);
60   this->Points->SetPoint(12, 2.2, 1.0, 0.0);
61   this->Points->SetPoint(13, 3.0, 0.2, 0.0);
62   this->Points->SetPoint(14, 3.0, 1.8, 0.0);
63   this->Points->SetPoint(15, 3.0, 1.0, 0.0);
64   this->Points->SetPoint(16, 3.8, 0.2, 0.0);
65   this->Points->SetPoint(17, 3.8, 1.8, 0.0);
66   this->Points->SetPoint(18, 4.5, 0.3, 0.0);
67   this->Points->SetPoint(19, 5.7, 0.3, 0.0);
68   this->Points->SetPoint(20, 5.7, 1.7, 0.0);
69   this->Points->SetPoint(21, 4.5, 1.7, 0.0);
70   this->Points->SetPoint(22, 6.5, 0.3, 0.0);
71   this->Points->SetPoint(23, 7.7, 1.0, 0.0);
72   this->Points->SetPoint(24, 6.5, 1.7, 0.0);
73   this->Points->SetPoint(25, 8.2, 0.2, 0.0);
74   this->Points->SetPoint(26, 9.0, 1.0, 0.0);
75   this->Points->SetPoint(27, 8.2, 1.8, 0.0);
76   this->Points->SetPoint(28, 9.0, 0.2, 0.0);
77   this->Points->SetPoint(29, 9.8, 1.0, 0.0);
78   this->Points->SetPoint(30, 9.0, 1.8, 0.0);
79   this->Points->SetPoint(31, 9.7, 0.3, 0.0);
80   this->Points->SetPoint(32, 9.9, 0.3, 0.0);
81   this->Points->SetPoint(33, 9.9, 0.5, 0.0);
82   this->Points->SetPoint(34, 9.7, 0.5, 0.0);
83   this->Points->SetPoint(35, 10.3, 0.2, 0.0);
84   this->Points->SetPoint(36, 11.0, 1.0, 0.0);
85   this->Points->SetPoint(37, 10.3, 1.8, 0.0);
86   this->Points->SetPoint(38, 11.0, 0.2, 0.0);
87   this->Points->SetPoint(39, 11.7, 1.0, 0.0);
88   this->Points->SetPoint(40, 11.0, 1.8, 0.0);
89   this->Points->SetPoint(41, 11.7, 0.2, 0.0);
90   this->Points->SetPoint(42, 11.7, 1.8, 0.0);
91 
92   vtkCellArray* lines = vtkCellArray::New();
93   lines->InsertNextCell(2); // left jump
94   lines->InsertCellPoint(0);
95   lines->InsertCellPoint(1);
96   lines->InsertNextCell(5); // left frame
97   lines->InsertCellPoint(8);
98   lines->InsertCellPoint(9);
99   lines->InsertCellPoint(10);
100   lines->InsertCellPoint(11);
101   lines->InsertCellPoint(8);
102   lines->InsertNextCell(5); // right frame
103   lines->InsertCellPoint(31);
104   lines->InsertCellPoint(32);
105   lines->InsertCellPoint(33);
106   lines->InsertCellPoint(34);
107   lines->InsertCellPoint(31);
108   lines->InsertNextCell(2); // right jump
109   lines->InsertCellPoint(41);
110   lines->InsertCellPoint(42);
111 
112   vtkCellArray* polys = vtkCellArray::New();
113   polys->InsertNextCell(3); // left jump
114   polys->InsertCellPoint(2);
115   polys->InsertCellPoint(3);
116   polys->InsertCellPoint(4);
117   polys->InsertNextCell(3);
118   polys->InsertCellPoint(5);
119   polys->InsertCellPoint(6);
120   polys->InsertCellPoint(7);
121   polys->InsertNextCell(3); // left frame
122   polys->InsertCellPoint(12);
123   polys->InsertCellPoint(13);
124   polys->InsertCellPoint(14);
125   polys->InsertNextCell(3);
126   polys->InsertCellPoint(15);
127   polys->InsertCellPoint(16);
128   polys->InsertCellPoint(17);
129   polys->InsertNextCell(4); // stop
130   polys->InsertCellPoint(18);
131   polys->InsertCellPoint(19);
132   polys->InsertCellPoint(20);
133   polys->InsertCellPoint(21);
134   polys->InsertNextCell(3); // play
135   polys->InsertCellPoint(22);
136   polys->InsertCellPoint(23);
137   polys->InsertCellPoint(24);
138   polys->InsertNextCell(3); // right frame
139   polys->InsertCellPoint(25);
140   polys->InsertCellPoint(26);
141   polys->InsertCellPoint(27);
142   polys->InsertNextCell(3);
143   polys->InsertCellPoint(28);
144   polys->InsertCellPoint(29);
145   polys->InsertCellPoint(30);
146   polys->InsertNextCell(3); // right jump
147   polys->InsertCellPoint(35);
148   polys->InsertCellPoint(36);
149   polys->InsertCellPoint(37);
150   polys->InsertNextCell(3);
151   polys->InsertCellPoint(38);
152   polys->InsertCellPoint(39);
153   polys->InsertCellPoint(40);
154 
155   this->PolyData = vtkPolyData::New();
156   this->PolyData->SetPoints(this->Points);
157   this->PolyData->SetLines(lines);
158   this->PolyData->SetPolys(polys);
159   lines->Delete();
160   polys->Delete();
161 
162   this->TransformFilter = vtkTransformPolyDataFilter::New();
163   this->TransformFilter->SetTransform(this->BWTransform);
164   this->TransformFilter->SetInputData(this->PolyData);
165 
166   this->Mapper = vtkPolyDataMapper2D::New();
167   this->Mapper->SetInputConnection(this->TransformFilter->GetOutputPort());
168   this->Property = vtkProperty2D::New();
169   this->Actor = vtkActor2D::New();
170   this->Actor->SetMapper(this->Mapper);
171   this->Actor->SetProperty(this->Property);
172 }
173 
174 //------------------------------------------------------------------------------
~vtkPlaybackRepresentation()175 vtkPlaybackRepresentation::~vtkPlaybackRepresentation()
176 {
177   this->Points->Delete();
178   this->TransformFilter->Delete();
179   this->PolyData->Delete();
180   this->Mapper->Delete();
181   this->Property->Delete();
182   this->Actor->Delete();
183 }
184 
185 //------------------------------------------------------------------------------
BuildRepresentation()186 void vtkPlaybackRepresentation::BuildRepresentation()
187 {
188   // Note that the transform is updated by the superclass
189   this->Superclass::BuildRepresentation();
190 }
191 
192 //------------------------------------------------------------------------------
GetActors2D(vtkPropCollection * pc)193 void vtkPlaybackRepresentation::GetActors2D(vtkPropCollection* pc)
194 {
195   pc->AddItem(this->Actor);
196   this->Superclass::GetActors2D(pc);
197 }
198 
199 //------------------------------------------------------------------------------
ReleaseGraphicsResources(vtkWindow * w)200 void vtkPlaybackRepresentation::ReleaseGraphicsResources(vtkWindow* w)
201 {
202   this->Actor->ReleaseGraphicsResources(w);
203   this->Superclass::ReleaseGraphicsResources(w);
204 }
205 
206 //------------------------------------------------------------------------------
RenderOverlay(vtkViewport * w)207 int vtkPlaybackRepresentation::RenderOverlay(vtkViewport* w)
208 {
209   int count = this->Superclass::RenderOverlay(w);
210   count += this->Actor->RenderOverlay(w);
211   return count;
212 }
213 
214 //------------------------------------------------------------------------------
RenderOpaqueGeometry(vtkViewport * w)215 int vtkPlaybackRepresentation::RenderOpaqueGeometry(vtkViewport* w)
216 {
217   int count = this->Superclass::RenderOpaqueGeometry(w);
218   count += this->Actor->RenderOpaqueGeometry(w);
219   return count;
220 }
221 
222 //------------------------------------------------------------------------------
RenderTranslucentPolygonalGeometry(vtkViewport * w)223 int vtkPlaybackRepresentation::RenderTranslucentPolygonalGeometry(vtkViewport* w)
224 {
225   int count = this->Superclass::RenderTranslucentPolygonalGeometry(w);
226   count += this->Actor->RenderTranslucentPolygonalGeometry(w);
227   return count;
228 }
229 
230 //------------------------------------------------------------------------------
231 // Description:
232 // Does this prop have some translucent polygonal geometry?
HasTranslucentPolygonalGeometry()233 vtkTypeBool vtkPlaybackRepresentation::HasTranslucentPolygonalGeometry()
234 {
235   int result = this->Superclass::HasTranslucentPolygonalGeometry();
236   result |= this->Actor->HasTranslucentPolygonalGeometry();
237   return result;
238 }
239 
240 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)241 void vtkPlaybackRepresentation::PrintSelf(ostream& os, vtkIndent indent)
242 {
243   this->Superclass::PrintSelf(os, indent);
244 
245   if (this->Property)
246   {
247     os << indent << "Property:\n";
248     this->Property->PrintSelf(os, indent.GetNextIndent());
249   }
250   else
251   {
252     os << indent << "Property: (none)\n";
253   }
254 }
255