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