1 | |
---|
2 | /****************************************************************************** |
---|
3 | * SAGE - Scalable Adaptive Graphics Environment |
---|
4 | * |
---|
5 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
6 | * University of Illinois at Chicago |
---|
7 | * |
---|
8 | * All rights reserved. |
---|
9 | * |
---|
10 | * Redistribution and use in source and binary forms, with or without |
---|
11 | * modification, are permitted provided that the following conditions are met: |
---|
12 | * |
---|
13 | * * Redistributions of source code must retain the above copyright |
---|
14 | * notice, this list of conditions and the following disclaimer. |
---|
15 | * * Redistributions in binary form must reproduce the above |
---|
16 | * copyright notice, this list of conditions and the following disclaimer |
---|
17 | * in the documentation and/or other materials provided with the distribution. |
---|
18 | * * Neither the name of the University of Illinois at Chicago nor |
---|
19 | * the names of its contributors may be used to endorse or promote |
---|
20 | * products derived from this software without specific prior written permission. |
---|
21 | * |
---|
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
26 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
28 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
29 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
31 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
33 | * |
---|
34 | * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/ |
---|
35 | * |
---|
36 | *****************************************************************************/ |
---|
37 | #ifndef ANIMVIEWER_H |
---|
38 | #define ANIMVIEWER_H |
---|
39 | |
---|
40 | //#include "vtkXOpenGLOffScreenRenderWindow.h" |
---|
41 | |
---|
42 | #include <iostream> |
---|
43 | #include <sstream> |
---|
44 | #include <string> |
---|
45 | #include <vector> |
---|
46 | #include <stdlib.h> |
---|
47 | #include <stdio.h> |
---|
48 | #include <pthread.h> |
---|
49 | #include <sys/types.h> |
---|
50 | #include <sys/mman.h> |
---|
51 | #include <sys/stat.h> |
---|
52 | #include <unistd.h> |
---|
53 | #include <sys/mman.h> |
---|
54 | #include <fcntl.h> |
---|
55 | |
---|
56 | using namespace std; |
---|
57 | |
---|
58 | /************************/ |
---|
59 | |
---|
60 | #include "tile_config.h" |
---|
61 | #include "file_parsers.h" |
---|
62 | |
---|
63 | // SAGE related headers |
---|
64 | #include <sail.h> |
---|
65 | #include <misc.h> |
---|
66 | |
---|
67 | /************************/ |
---|
68 | |
---|
69 | |
---|
70 | /* MPI */ |
---|
71 | #include <mpi.h> |
---|
72 | |
---|
73 | /* VTK */ |
---|
74 | #include <vtk/vtkActor.h> |
---|
75 | #include <vtk/vtkCamera.h> |
---|
76 | #include <vtk/vtkLight.h> |
---|
77 | #include <vtk/vtkRenderWindow.h> |
---|
78 | #include <vtk/vtkRenderer.h> |
---|
79 | #include <vtk/vtkImageImport.h> |
---|
80 | #include <vtk/vtkTexture.h> |
---|
81 | #include <vtk/vtkTransformTextureCoords.h> |
---|
82 | #include <vtk/vtkTextureMapToPlane.h> |
---|
83 | #include <vtk/vtkPlaneSource.h> |
---|
84 | #include <vtk/vtkMergeFilter.h> |
---|
85 | #include <vtk/vtkPolyDataMapper.h> |
---|
86 | #include <vtk/vtkImageFlip.h> |
---|
87 | #include <vtk/vtkProperty.h> |
---|
88 | #include <vtk/vtkSphereSource.h> |
---|
89 | #include <vtk/vtkTextSource.h> |
---|
90 | #include <vtk/vtkFrustumCoverageCuller.h> |
---|
91 | #include <vtk/vtkTextActor.h> |
---|
92 | #include <vtk/vtkTextProperty.h> |
---|
93 | |
---|
94 | #include <vtk/vtkSphereSource.h> |
---|
95 | #include <vtk/vtkCubeSource.h> |
---|
96 | #include <vtk/vtkConeSource.h> |
---|
97 | #include <vtk/vtkJPEGReader.h> |
---|
98 | #include <vtk/vtkImageMapper.h> |
---|
99 | #include <vtk/vtkActor2D.h> |
---|
100 | |
---|
101 | /* QUANTA */ |
---|
102 | #include <QUANTA/QUANTAinit.hxx> |
---|
103 | #include <QUANTA/QUANTAnet_tcp_c.hxx> |
---|
104 | #include <QUANTA/QUANTAnet_datapack_c.hxx> |
---|
105 | |
---|
106 | #define PANLEFT "panleft" |
---|
107 | #define PANRIGHT "panright" |
---|
108 | #define PANUP "panup" |
---|
109 | #define PANDOWN "pandown" |
---|
110 | #define BROWSERIGHT "browseright" |
---|
111 | #define BROWSELEFT "browseleft" |
---|
112 | #define ZOOMIN "zoomin" |
---|
113 | #define ZOOMOUT "zoomout" |
---|
114 | #define SELECT "select" |
---|
115 | #define RELEASE "release" |
---|
116 | #define PRESS "press" |
---|
117 | #define SLIDER1 "slider1" |
---|
118 | #define SLIDER2 "slider2" |
---|
119 | #define SLIDER3 "slider3" |
---|
120 | #define QUIT "quit" |
---|
121 | #define CENTER "center" |
---|
122 | |
---|
123 | int PORT= 5678; |
---|
124 | #define TRANSMISSION_SIZE 16 |
---|
125 | |
---|
126 | #define ZIN 1 |
---|
127 | #define ZOUT 0 |
---|
128 | |
---|
129 | QUANTAnet_tcpServer_c* server; |
---|
130 | QUANTAnet_tcpClient_c* client; |
---|
131 | char* recmsg; |
---|
132 | |
---|
133 | double CamPosition[3]; |
---|
134 | double Fpoint[3]; |
---|
135 | double PanAmount; |
---|
136 | |
---|
137 | double Zoom = 7; |
---|
138 | double ZoomAmount; |
---|
139 | |
---|
140 | double StartingZ; |
---|
141 | |
---|
142 | //SAGE STUFF |
---|
143 | int winWidth, winHeight; |
---|
144 | sail sageInf; |
---|
145 | |
---|
146 | int rank; |
---|
147 | int size; |
---|
148 | |
---|
149 | int xWindowPos = 0; |
---|
150 | int yWindowPos = 0; |
---|
151 | |
---|
152 | vtkRenderer* renA = vtkRenderer::New(); |
---|
153 | vtkRenderer* renB = vtkRenderer::New(); |
---|
154 | vtkRenderWindow* renWin = vtkRenderWindow::New(); |
---|
155 | vtkLight* light = vtkLight::New(); |
---|
156 | vtkFrustumCoverageCuller* culler = vtkFrustumCoverageCuller::New(); |
---|
157 | vtkTextActor *text = vtkTextActor::New(); |
---|
158 | |
---|
159 | vtkConeSource *cone = vtkConeSource::New(); |
---|
160 | vtkCubeSource *cube = vtkCubeSource::New(); |
---|
161 | vtkSphereSource *sphere = vtkSphereSource::New(); |
---|
162 | vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); |
---|
163 | vtkActor *pointer = vtkActor::New(); |
---|
164 | |
---|
165 | vtkJPEGReader *splash = vtkJPEGReader::New(); |
---|
166 | vtkImageMapper *splashMapper = vtkImageMapper::New(); |
---|
167 | vtkActor2D *splashScreen = vtkActor2D::New(); |
---|
168 | |
---|
169 | #define PANSUBDIVISIONS 10 |
---|
170 | |
---|
171 | #define GRAYSCALE 1 |
---|
172 | #define RGB 3 |
---|
173 | #define RGBA 4 |
---|
174 | int MODE; |
---|
175 | |
---|
176 | int start = 0; |
---|
177 | int end = 0; |
---|
178 | |
---|
179 | #define LEFT -1 |
---|
180 | #define RIGHT 1 |
---|
181 | #define UP -2 |
---|
182 | #define DOWN 2 |
---|
183 | #define ACCEPT 0 |
---|
184 | |
---|
185 | #define X 0 |
---|
186 | #define Y 1 |
---|
187 | |
---|
188 | int CurrentLevel = 0; |
---|
189 | |
---|
190 | //#define DEBUG |
---|
191 | |
---|
192 | struct ZBound { |
---|
193 | double bound; |
---|
194 | }; |
---|
195 | |
---|
196 | struct Viewable { |
---|
197 | long level; |
---|
198 | bool virgin; |
---|
199 | unsigned char*** pixels; |
---|
200 | }; |
---|
201 | |
---|
202 | struct Point { |
---|
203 | long l; |
---|
204 | long c; |
---|
205 | long r; |
---|
206 | }; |
---|
207 | |
---|
208 | struct Geometry { |
---|
209 | vtkImageImport *importer; |
---|
210 | vtkTexture* texture; |
---|
211 | vtkPolyDataMapper *mapper; |
---|
212 | vtkActor* actor; |
---|
213 | vtkPlaneSource *plane; |
---|
214 | vtkImageFlip *flip; |
---|
215 | |
---|
216 | vtkTextSource *textSource; |
---|
217 | vtkPolyDataMapper *textMapper; |
---|
218 | vtkActor *textActor; |
---|
219 | |
---|
220 | |
---|
221 | int fd; |
---|
222 | }; |
---|
223 | |
---|
224 | struct Info { |
---|
225 | |
---|
226 | double scale[2]; |
---|
227 | double position[3]; |
---|
228 | double depth[1]; |
---|
229 | }; |
---|
230 | |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | class AnimViewer { |
---|
236 | |
---|
237 | |
---|
238 | public: |
---|
239 | |
---|
240 | AnimViewer(); |
---|
241 | ~AnimViewer(); |
---|
242 | |
---|
243 | string IntToString(long); |
---|
244 | void CopyBuffer(unsigned char*, unsigned char*); |
---|
245 | long GetNumOfCols(long, long); |
---|
246 | long GetNumOfRows(long, long); |
---|
247 | long GetLevelBlockWidth(long); |
---|
248 | long GetLevelBlockHeight(long); |
---|
249 | long GetLevelNumOfCols(long); |
---|
250 | long GetLevelNumOfRows(long); |
---|
251 | void InitViewer(char*); |
---|
252 | void GetAnimFiles(); |
---|
253 | unsigned char* GetPixelsFromFile(long, long, long); |
---|
254 | unsigned char* MMap(long, long, long); |
---|
255 | void InitRendering(); |
---|
256 | void SetUpPipeline(); |
---|
257 | void UpdateBlock(long, long, long); |
---|
258 | void ImportQueryWindowPixels(); |
---|
259 | void FindStartingQueryWindow(); |
---|
260 | void GivePixelsToVTK(); |
---|
261 | void QueryWindowPanRight(); |
---|
262 | void QueryWindowPanLeft(); |
---|
263 | void QueryWindowPanUp(); |
---|
264 | void QueryWindowPanDown(); |
---|
265 | void QueryWindowZoomIn(); |
---|
266 | void QueryWindowZoomOut(); |
---|
267 | void PositionAndScaleBlocks(); |
---|
268 | void ComputeStartingBlockSize(); |
---|
269 | double GetRowPositionAtLevel(long, long); |
---|
270 | double GetColPositionAtLevel(long, long); |
---|
271 | double GetBlockWidthAtLevel(long); |
---|
272 | double GetBlockHeightAtLevel(long); |
---|
273 | void AddBlock(long, long, long); |
---|
274 | void RemoveBlock(long, long, long); |
---|
275 | |
---|
276 | void AdjustLevelMovement(int, int); |
---|
277 | int AdjustZoomMovement(int); |
---|
278 | long GetQueryWindowLevel(); |
---|
279 | int BlockOutOfBounds(long, long, long, long); |
---|
280 | |
---|
281 | void ZoomIn(); |
---|
282 | void ZoomOut(); |
---|
283 | void PanLeft(); |
---|
284 | void PanRight(); |
---|
285 | void PanUp(); |
---|
286 | void PanDown(); |
---|
287 | void UpdateCamera(double[], double[]); |
---|
288 | double GetCenterX(); |
---|
289 | double GetCenterY(); |
---|
290 | void RepositionCamera(); |
---|
291 | |
---|
292 | void RemoveRegion(long, long, long, long, long); |
---|
293 | void AddRegion(long, long, long, long, long); |
---|
294 | |
---|
295 | void GetCamProjection(double, double); |
---|
296 | void BuildMainQueryWindow(); |
---|
297 | |
---|
298 | void BringUpStartingImage(); |
---|
299 | |
---|
300 | bool NeedToUpdateMainWindow(); |
---|
301 | |
---|
302 | void CleanUpMainWindow(); |
---|
303 | |
---|
304 | void SetTimeStep(int); |
---|
305 | |
---|
306 | void CreateZoomBounds(); |
---|
307 | |
---|
308 | void GetZProjection(double); |
---|
309 | |
---|
310 | void SetCurrentLevel(int); |
---|
311 | |
---|
312 | void SetInitialCamPosition(); |
---|
313 | |
---|
314 | |
---|
315 | private: |
---|
316 | |
---|
317 | int BlockDimensions[2]; |
---|
318 | int GlobalDimensions[2]; |
---|
319 | |
---|
320 | |
---|
321 | int Colorspace; |
---|
322 | |
---|
323 | string AnimDir; |
---|
324 | |
---|
325 | int NumOfLevels; |
---|
326 | |
---|
327 | int StartingLevel; |
---|
328 | |
---|
329 | unsigned char* pixelbuff; |
---|
330 | |
---|
331 | string*** AnimFiles; |
---|
332 | |
---|
333 | Geometry*** Block; |
---|
334 | |
---|
335 | Viewable QueryWindow; |
---|
336 | Info** BlockInfo; |
---|
337 | double BlockInitSize[2]; |
---|
338 | |
---|
339 | Point CamProjection; |
---|
340 | |
---|
341 | ZBound* ZoomBounds; |
---|
342 | int NumOfZBounds; |
---|
343 | |
---|
344 | unsigned char* Blank; |
---|
345 | |
---|
346 | |
---|
347 | int NumOfCols; |
---|
348 | int NumOfRows; |
---|
349 | }; |
---|
350 | |
---|
351 | |
---|
352 | #endif |
---|