1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2004-2012 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Author: Leif Delgass <ldelgass@purdue.edu> |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef __RAPPTURE_VTKVIS_RENDERER_GRAPHICS_OBJS_H__ |
---|
9 | #define __RAPPTURE_VTKVIS_RENDERER_GRAPHICS_OBJS_H__ |
---|
10 | |
---|
11 | #include <tr1/unordered_map> |
---|
12 | #include <typeinfo> |
---|
13 | |
---|
14 | // Use GCC/G++ specific name demangling |
---|
15 | #define DEMANGLE |
---|
16 | |
---|
17 | #ifdef DEMANGLE |
---|
18 | #include <cstdlib> |
---|
19 | #include <cxxabi.h> |
---|
20 | #define GO_TRACE(go, format, ...) \ |
---|
21 | do { \ |
---|
22 | int status; \ |
---|
23 | char * typeName = abi::__cxa_demangle(typeid(go).name(), 0, 0, &status); \ |
---|
24 | TRACE("%s " format, typeName, __VA_ARGS__); \ |
---|
25 | free(typeName); \ |
---|
26 | } while (0) |
---|
27 | |
---|
28 | #define GO_ERROR(go, format, ...) \ |
---|
29 | do { \ |
---|
30 | int status; \ |
---|
31 | char * typeName = abi::__cxa_demangle(typeid(go).name(), 0, 0, &status); \ |
---|
32 | ERROR("%s " format, typeName, __VA_ARGS__); \ |
---|
33 | free(typeName); \ |
---|
34 | } while (0) |
---|
35 | #else |
---|
36 | #define GO_TRACE(go, format, ...) TRACE("%s " format, typeid(go).name(), __VA_ARGS__); |
---|
37 | #define GO_ERROR(go, format, ...) ERROR("%s " format, typeid(go).name(), __VA_ARGS__); |
---|
38 | #endif |
---|
39 | |
---|
40 | #include "RpVtkRenderer.h" |
---|
41 | |
---|
42 | namespace Rappture { |
---|
43 | namespace VtkVis { |
---|
44 | |
---|
45 | /** |
---|
46 | * \brief Look up graphics object by name |
---|
47 | */ |
---|
48 | template<class GraphicsObject> |
---|
49 | GraphicsObject *Renderer::getGraphicsObject(const DataSetId& id) |
---|
50 | { |
---|
51 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
52 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
53 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator |
---|
54 | itr = hashmap.find(id); |
---|
55 | |
---|
56 | if (itr == hashmap.end()) { |
---|
57 | #ifdef DEBUG |
---|
58 | GO_TRACE(GraphicsObject, "not found: %s", id.c_str()); |
---|
59 | #endif |
---|
60 | return NULL; |
---|
61 | } else |
---|
62 | return itr->second; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * \brief Delete graphics object by name |
---|
67 | */ |
---|
68 | template<class GraphicsObject> |
---|
69 | void Renderer::deleteGraphicsObject(const DataSetId& id) |
---|
70 | { |
---|
71 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
72 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
73 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
74 | |
---|
75 | bool doAll = false; |
---|
76 | |
---|
77 | if (id.compare("all") == 0) { |
---|
78 | itr = hashmap.begin(); |
---|
79 | doAll = true; |
---|
80 | } else { |
---|
81 | itr = hashmap.find(id); |
---|
82 | } |
---|
83 | if (itr == hashmap.end()) { |
---|
84 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
85 | return; |
---|
86 | } |
---|
87 | |
---|
88 | TRACE("Deleting %s for %s", itr->second->getClassName(), id.c_str()); |
---|
89 | |
---|
90 | do { |
---|
91 | GraphicsObject *gobj = itr->second; |
---|
92 | if (gobj->getProp()) |
---|
93 | _renderer->RemoveViewProp(gobj->getProp()); |
---|
94 | if (gobj->getOverlayProp()) |
---|
95 | _renderer->RemoveViewProp(gobj->getOverlayProp()); |
---|
96 | delete gobj; |
---|
97 | |
---|
98 | itr = hashmap.erase(itr); |
---|
99 | } while (doAll && itr != hashmap.end()); |
---|
100 | |
---|
101 | sceneBoundsChanged(); |
---|
102 | _needsRedraw = true; |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * \brief Delete all graphics objects from renderer |
---|
107 | */ |
---|
108 | template<class GraphicsObject> |
---|
109 | void Renderer::deleteAllGraphicsObjects() |
---|
110 | { |
---|
111 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
112 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
113 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
114 | |
---|
115 | itr = hashmap.begin(); |
---|
116 | if (itr == hashmap.end()) |
---|
117 | return; |
---|
118 | |
---|
119 | TRACE("Deleting all %s objects", itr->second->getClassName()); |
---|
120 | |
---|
121 | for (; itr != hashmap.end(); ++itr) { |
---|
122 | delete itr->second; |
---|
123 | } |
---|
124 | hashmap.clear(); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * \brief Add a graphics objects to the renderer's scene |
---|
129 | */ |
---|
130 | template<class GraphicsObject> |
---|
131 | bool Renderer::addGraphicsObject(const DataSetId& id) |
---|
132 | { |
---|
133 | DataSetHashmap::iterator itr; |
---|
134 | |
---|
135 | bool doAll = false; |
---|
136 | |
---|
137 | if (id.compare("all") == 0) { |
---|
138 | itr = _dataSets.begin(); |
---|
139 | } else { |
---|
140 | itr = _dataSets.find(id); |
---|
141 | } |
---|
142 | if (itr == _dataSets.end()) { |
---|
143 | ERROR("Unknown dataset %s", id.c_str()); |
---|
144 | return false; |
---|
145 | } |
---|
146 | |
---|
147 | do { |
---|
148 | DataSet *ds = itr->second; |
---|
149 | const DataSetId& dsID = ds->getName(); |
---|
150 | |
---|
151 | GraphicsObject *gobj; |
---|
152 | if ((gobj = getGraphicsObject<GraphicsObject>(dsID)) != NULL) { |
---|
153 | WARN("Replacing existing %s %s", gobj->getClassName(), dsID.c_str()); |
---|
154 | deleteGraphicsObject<GraphicsObject>(dsID); |
---|
155 | } |
---|
156 | |
---|
157 | gobj = new GraphicsObject(); |
---|
158 | |
---|
159 | gobj->setDataSet(ds, this); |
---|
160 | |
---|
161 | if (gobj->getProp() == NULL && |
---|
162 | gobj->getOverlayProp() == NULL) { |
---|
163 | delete gobj; |
---|
164 | return false; |
---|
165 | } else { |
---|
166 | if (gobj->getProp()) |
---|
167 | _renderer->AddViewProp(gobj->getProp()); |
---|
168 | if (gobj->getOverlayProp()) |
---|
169 | _renderer->AddViewProp(gobj->getOverlayProp()); |
---|
170 | } |
---|
171 | |
---|
172 | getGraphicsObjectHashmap<GraphicsObject>()[dsID] = gobj; |
---|
173 | } while (doAll && ++itr != _dataSets.end()); |
---|
174 | |
---|
175 | sceneBoundsChanged(); |
---|
176 | _needsRedraw = true; |
---|
177 | return true; |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * \brief Set the prop orientation with a quaternion |
---|
182 | */ |
---|
183 | template<class GraphicsObject> |
---|
184 | void Renderer::setGraphicsObjectTransform(const DataSetId& id, vtkMatrix4x4 *trans) |
---|
185 | { |
---|
186 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
187 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
188 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
189 | |
---|
190 | bool doAll = false; |
---|
191 | |
---|
192 | if (id.compare("all") == 0) { |
---|
193 | itr = hashmap.begin(); |
---|
194 | if (itr == hashmap.end()) |
---|
195 | return; |
---|
196 | doAll = true; |
---|
197 | } else { |
---|
198 | itr = hashmap.find(id); |
---|
199 | } |
---|
200 | if (itr == hashmap.end()) { |
---|
201 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
202 | return; |
---|
203 | } |
---|
204 | |
---|
205 | do { |
---|
206 | itr->second->setTransform(trans); |
---|
207 | } while (doAll && ++itr != hashmap.end()); |
---|
208 | |
---|
209 | sceneBoundsChanged(); |
---|
210 | _needsRedraw = true; |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * \brief Set the prop orientation with a quaternion |
---|
215 | */ |
---|
216 | template<class GraphicsObject> |
---|
217 | void Renderer::setGraphicsObjectOrientation(const DataSetId& id, double quat[4]) |
---|
218 | { |
---|
219 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
220 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
221 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
222 | |
---|
223 | bool doAll = false; |
---|
224 | |
---|
225 | if (id.compare("all") == 0) { |
---|
226 | itr = hashmap.begin(); |
---|
227 | if (itr == hashmap.end()) |
---|
228 | return; |
---|
229 | doAll = true; |
---|
230 | } else { |
---|
231 | itr = hashmap.find(id); |
---|
232 | } |
---|
233 | if (itr == hashmap.end()) { |
---|
234 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
235 | return; |
---|
236 | } |
---|
237 | |
---|
238 | do { |
---|
239 | itr->second->setOrientation(quat); |
---|
240 | } while (doAll && ++itr != hashmap.end()); |
---|
241 | |
---|
242 | sceneBoundsChanged(); |
---|
243 | _needsRedraw = true; |
---|
244 | } |
---|
245 | |
---|
246 | /** |
---|
247 | * \brief Set the prop orientation with a rotation about an axis |
---|
248 | */ |
---|
249 | template<class GraphicsObject> |
---|
250 | void Renderer::setGraphicsObjectOrientation(const DataSetId& id, double angle, double axis[3]) |
---|
251 | { |
---|
252 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
253 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
254 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
255 | |
---|
256 | bool doAll = false; |
---|
257 | |
---|
258 | if (id.compare("all") == 0) { |
---|
259 | itr = hashmap.begin(); |
---|
260 | if (itr == hashmap.end()) |
---|
261 | return; |
---|
262 | doAll = true; |
---|
263 | } else { |
---|
264 | itr = hashmap.find(id); |
---|
265 | } |
---|
266 | if (itr == hashmap.end()) { |
---|
267 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
268 | return; |
---|
269 | } |
---|
270 | |
---|
271 | do { |
---|
272 | itr->second->setOrientation(angle, axis); |
---|
273 | } while (doAll && ++itr != hashmap.end()); |
---|
274 | |
---|
275 | sceneBoundsChanged(); |
---|
276 | _needsRedraw = true; |
---|
277 | } |
---|
278 | |
---|
279 | /** |
---|
280 | * \brief Set the prop position in world coords |
---|
281 | */ |
---|
282 | template<class GraphicsObject> |
---|
283 | void Renderer::setGraphicsObjectPosition(const DataSetId& id, double pos[3]) |
---|
284 | { |
---|
285 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
286 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
287 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
288 | |
---|
289 | bool doAll = false; |
---|
290 | |
---|
291 | if (id.compare("all") == 0) { |
---|
292 | itr = hashmap.begin(); |
---|
293 | if (itr == hashmap.end()) |
---|
294 | return; |
---|
295 | doAll = true; |
---|
296 | } else { |
---|
297 | itr = hashmap.find(id); |
---|
298 | } |
---|
299 | if (itr == hashmap.end()) { |
---|
300 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
301 | return; |
---|
302 | } |
---|
303 | |
---|
304 | do { |
---|
305 | itr->second->setPosition(pos); |
---|
306 | } while (doAll && ++itr != hashmap.end()); |
---|
307 | |
---|
308 | sceneBoundsChanged(); |
---|
309 | _needsRedraw = true; |
---|
310 | } |
---|
311 | |
---|
312 | /** |
---|
313 | * \brief Set the prop scaling based on a 2D aspect ratio |
---|
314 | * |
---|
315 | * \param id The name of the DataSet |
---|
316 | * \param aspect The aspect ratio (width/height), zero means native aspect |
---|
317 | */ |
---|
318 | template<class GraphicsObject> |
---|
319 | void Renderer::setGraphicsObjectAspect(const DataSetId& id, double aspect) |
---|
320 | { |
---|
321 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
322 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
323 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
324 | |
---|
325 | bool doAll = false; |
---|
326 | |
---|
327 | if (id.compare("all") == 0) { |
---|
328 | itr = hashmap.begin(); |
---|
329 | if (itr == hashmap.end()) |
---|
330 | return; |
---|
331 | doAll = true; |
---|
332 | } else { |
---|
333 | itr = hashmap.find(id); |
---|
334 | } |
---|
335 | if (itr == hashmap.end()) { |
---|
336 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
337 | return; |
---|
338 | } |
---|
339 | |
---|
340 | do { |
---|
341 | itr->second->setAspect(aspect); |
---|
342 | } while (doAll && ++itr != hashmap.end()); |
---|
343 | |
---|
344 | sceneBoundsChanged(); |
---|
345 | _needsRedraw = true; |
---|
346 | } |
---|
347 | |
---|
348 | /** |
---|
349 | * \brief Set the prop scaling |
---|
350 | */ |
---|
351 | template<class GraphicsObject> |
---|
352 | void Renderer::setGraphicsObjectScale(const DataSetId& id, double scale[3]) |
---|
353 | { |
---|
354 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
355 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
356 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
357 | |
---|
358 | bool doAll = false; |
---|
359 | |
---|
360 | if (id.compare("all") == 0) { |
---|
361 | itr = hashmap.begin(); |
---|
362 | if (itr == hashmap.end()) |
---|
363 | return; |
---|
364 | doAll = true; |
---|
365 | } else { |
---|
366 | itr = hashmap.find(id); |
---|
367 | } |
---|
368 | if (itr == hashmap.end()) { |
---|
369 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
370 | return; |
---|
371 | } |
---|
372 | |
---|
373 | do { |
---|
374 | itr->second->setScale(scale); |
---|
375 | } while (doAll && ++itr != hashmap.end()); |
---|
376 | |
---|
377 | sceneBoundsChanged(); |
---|
378 | _needsRedraw = true; |
---|
379 | } |
---|
380 | |
---|
381 | /** |
---|
382 | * \brief Set visibility of VtkGraphicsObject for the given DataSet |
---|
383 | */ |
---|
384 | template<class GraphicsObject> |
---|
385 | void Renderer::setGraphicsObjectVisibility(const DataSetId& id, bool state) |
---|
386 | { |
---|
387 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
388 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
389 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
390 | |
---|
391 | bool doAll = false; |
---|
392 | |
---|
393 | if (id.compare("all") == 0) { |
---|
394 | itr = hashmap.begin(); |
---|
395 | if (itr == hashmap.end()) |
---|
396 | return; |
---|
397 | doAll = true; |
---|
398 | } else { |
---|
399 | itr = hashmap.find(id); |
---|
400 | } |
---|
401 | if (itr == hashmap.end()) { |
---|
402 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
403 | return; |
---|
404 | } |
---|
405 | |
---|
406 | do { |
---|
407 | itr->second->setVisibility(state); |
---|
408 | } while (doAll && ++itr != hashmap.end()); |
---|
409 | |
---|
410 | sceneBoundsChanged(); |
---|
411 | _needsRedraw = true; |
---|
412 | } |
---|
413 | |
---|
414 | /** |
---|
415 | * \brief Set the volume slice |
---|
416 | */ |
---|
417 | template<class GraphicsObject> |
---|
418 | void Renderer::setGraphicsObjectVolumeSlice(const DataSetId& id, Axis axis, double ratio) |
---|
419 | { |
---|
420 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
421 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
422 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
423 | |
---|
424 | bool doAll = false; |
---|
425 | |
---|
426 | if (id.compare("all") == 0) { |
---|
427 | itr = hashmap.begin(); |
---|
428 | if (itr == hashmap.end()) |
---|
429 | return; |
---|
430 | doAll = true; |
---|
431 | } else { |
---|
432 | itr = hashmap.find(id); |
---|
433 | } |
---|
434 | |
---|
435 | if (itr == hashmap.end()) { |
---|
436 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
437 | return; |
---|
438 | } |
---|
439 | |
---|
440 | do { |
---|
441 | itr->second->selectVolumeSlice(axis, ratio); |
---|
442 | } while (doAll && ++itr != hashmap.end()); |
---|
443 | |
---|
444 | sceneBoundsChanged(); |
---|
445 | _needsRedraw = true; |
---|
446 | } |
---|
447 | |
---|
448 | |
---|
449 | /** |
---|
450 | * \brief Set the RGB actor color for the specified DataSet |
---|
451 | */ |
---|
452 | template<class GraphicsObject> |
---|
453 | void Renderer::setGraphicsObjectColor(const DataSetId& id, float color[3]) |
---|
454 | { |
---|
455 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
456 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
457 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
458 | |
---|
459 | bool doAll = false; |
---|
460 | |
---|
461 | if (id.compare("all") == 0) { |
---|
462 | itr = hashmap.begin(); |
---|
463 | if (itr == hashmap.end()) |
---|
464 | return; |
---|
465 | doAll = true; |
---|
466 | } else { |
---|
467 | itr = hashmap.find(id); |
---|
468 | } |
---|
469 | if (itr == hashmap.end()) { |
---|
470 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
471 | return; |
---|
472 | } |
---|
473 | |
---|
474 | do { |
---|
475 | itr->second->setColor(color); |
---|
476 | } while (doAll && ++itr != hashmap.end()); |
---|
477 | |
---|
478 | _needsRedraw = true; |
---|
479 | } |
---|
480 | |
---|
481 | /** |
---|
482 | * \brief Turn on/off edges for the given DataSet |
---|
483 | */ |
---|
484 | template<class GraphicsObject> |
---|
485 | void Renderer::setGraphicsObjectEdgeVisibility(const DataSetId& id, bool state) |
---|
486 | { |
---|
487 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
488 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
489 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
490 | |
---|
491 | bool doAll = false; |
---|
492 | |
---|
493 | if (id.compare("all") == 0) { |
---|
494 | itr = hashmap.begin(); |
---|
495 | if (itr == hashmap.end()) |
---|
496 | return; |
---|
497 | doAll = true; |
---|
498 | } else { |
---|
499 | itr = hashmap.find(id); |
---|
500 | } |
---|
501 | if (itr == hashmap.end()) { |
---|
502 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
503 | return; |
---|
504 | } |
---|
505 | |
---|
506 | do { |
---|
507 | itr->second->setEdgeVisibility(state); |
---|
508 | } while (doAll && ++itr != hashmap.end()); |
---|
509 | |
---|
510 | sceneBoundsChanged(); |
---|
511 | _needsRedraw = true; |
---|
512 | } |
---|
513 | |
---|
514 | /** |
---|
515 | * \brief Set the RGB isosurface edge color for the specified DataSet |
---|
516 | */ |
---|
517 | template<class GraphicsObject> |
---|
518 | void Renderer::setGraphicsObjectEdgeColor(const DataSetId& id, float color[3]) |
---|
519 | { |
---|
520 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
521 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
522 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
523 | |
---|
524 | bool doAll = false; |
---|
525 | |
---|
526 | if (id.compare("all") == 0) { |
---|
527 | itr = hashmap.begin(); |
---|
528 | if (itr == hashmap.end()) |
---|
529 | return; |
---|
530 | doAll = true; |
---|
531 | } else { |
---|
532 | itr = hashmap.find(id); |
---|
533 | } |
---|
534 | if (itr == hashmap.end()) { |
---|
535 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
536 | return; |
---|
537 | } |
---|
538 | |
---|
539 | do { |
---|
540 | itr->second->setEdgeColor(color); |
---|
541 | } while (doAll && ++itr != hashmap.end()); |
---|
542 | |
---|
543 | _needsRedraw = true; |
---|
544 | } |
---|
545 | |
---|
546 | /** |
---|
547 | * \brief Set the isosurface edge width for the specified DataSet (may be a no-op) |
---|
548 | * |
---|
549 | * If the OpenGL implementation/hardware does not support wide lines, |
---|
550 | * this function may not have an effect. |
---|
551 | */ |
---|
552 | template<class GraphicsObject> |
---|
553 | void Renderer::setGraphicsObjectEdgeWidth(const DataSetId& id, float edgeWidth) |
---|
554 | { |
---|
555 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
556 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
557 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
558 | |
---|
559 | bool doAll = false; |
---|
560 | |
---|
561 | if (id.compare("all") == 0) { |
---|
562 | itr = hashmap.begin(); |
---|
563 | if (itr == hashmap.end()) |
---|
564 | return; |
---|
565 | doAll = true; |
---|
566 | } else { |
---|
567 | itr = hashmap.find(id); |
---|
568 | } |
---|
569 | if (itr == hashmap.end()) { |
---|
570 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
571 | return; |
---|
572 | } |
---|
573 | |
---|
574 | do { |
---|
575 | itr->second->setEdgeWidth(edgeWidth); |
---|
576 | } while (doAll && ++itr != hashmap.end()); |
---|
577 | |
---|
578 | sceneBoundsChanged(); |
---|
579 | _needsRedraw = true; |
---|
580 | } |
---|
581 | |
---|
582 | /** |
---|
583 | * \brief Set ambient lighting/shading coefficient for the specified DataSet |
---|
584 | */ |
---|
585 | template<class GraphicsObject> |
---|
586 | void Renderer::setGraphicsObjectAmbient(const DataSetId& id, double coeff) |
---|
587 | { |
---|
588 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
589 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
590 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
591 | |
---|
592 | bool doAll = false; |
---|
593 | |
---|
594 | if (id.compare("all") == 0) { |
---|
595 | itr = hashmap.begin(); |
---|
596 | if (itr == hashmap.end()) |
---|
597 | return; |
---|
598 | doAll = true; |
---|
599 | } else { |
---|
600 | itr = hashmap.find(id); |
---|
601 | } |
---|
602 | if (itr == hashmap.end()) { |
---|
603 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
604 | return; |
---|
605 | } |
---|
606 | |
---|
607 | do { |
---|
608 | itr->second->setAmbient(coeff); |
---|
609 | } while (doAll && ++itr != hashmap.end()); |
---|
610 | |
---|
611 | _needsRedraw = true; |
---|
612 | } |
---|
613 | |
---|
614 | /** |
---|
615 | * \brief Set diffuse lighting/shading coefficient for the specified DataSet |
---|
616 | */ |
---|
617 | template<class GraphicsObject> |
---|
618 | void Renderer::setGraphicsObjectDiffuse(const DataSetId& id, double coeff) |
---|
619 | { |
---|
620 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
621 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
622 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
623 | |
---|
624 | bool doAll = false; |
---|
625 | |
---|
626 | if (id.compare("all") == 0) { |
---|
627 | itr = hashmap.begin(); |
---|
628 | if (itr == hashmap.end()) |
---|
629 | return; |
---|
630 | doAll = true; |
---|
631 | } else { |
---|
632 | itr = hashmap.find(id); |
---|
633 | } |
---|
634 | if (itr == hashmap.end()) { |
---|
635 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
636 | return; |
---|
637 | } |
---|
638 | |
---|
639 | do { |
---|
640 | itr->second->setDiffuse(coeff); |
---|
641 | } while (doAll && ++itr != hashmap.end()); |
---|
642 | |
---|
643 | _needsRedraw = true; |
---|
644 | } |
---|
645 | |
---|
646 | /** |
---|
647 | * \brief Set specular lighting/shading coefficient and power for the specified DataSet |
---|
648 | */ |
---|
649 | template<class GraphicsObject> |
---|
650 | void Renderer::setGraphicsObjectSpecular(const DataSetId& id, double coeff, double power) |
---|
651 | { |
---|
652 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
653 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
654 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
655 | |
---|
656 | bool doAll = false; |
---|
657 | |
---|
658 | if (id.compare("all") == 0) { |
---|
659 | itr = hashmap.begin(); |
---|
660 | if (itr == hashmap.end()) |
---|
661 | return; |
---|
662 | doAll = true; |
---|
663 | } else { |
---|
664 | itr = hashmap.find(id); |
---|
665 | } |
---|
666 | if (itr == hashmap.end()) { |
---|
667 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
668 | return; |
---|
669 | } |
---|
670 | |
---|
671 | do { |
---|
672 | itr->second->setSpecular(coeff, power); |
---|
673 | } while (doAll && ++itr != hashmap.end()); |
---|
674 | |
---|
675 | _needsRedraw = true; |
---|
676 | } |
---|
677 | |
---|
678 | /** |
---|
679 | * \brief Turn actor lighting on/off for the specified DataSet |
---|
680 | */ |
---|
681 | template<class GraphicsObject> |
---|
682 | void Renderer::setGraphicsObjectLighting(const DataSetId& id, bool state) |
---|
683 | { |
---|
684 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
685 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
686 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
687 | |
---|
688 | bool doAll = false; |
---|
689 | |
---|
690 | if (id.compare("all") == 0) { |
---|
691 | itr = hashmap.begin(); |
---|
692 | if (itr == hashmap.end()) |
---|
693 | return; |
---|
694 | doAll = true; |
---|
695 | } else { |
---|
696 | itr = hashmap.find(id); |
---|
697 | } |
---|
698 | if (itr == hashmap.end()) { |
---|
699 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
700 | return; |
---|
701 | } |
---|
702 | |
---|
703 | do { |
---|
704 | itr->second->setLighting(state); |
---|
705 | } while (doAll && ++itr != hashmap.end()); |
---|
706 | |
---|
707 | _needsRedraw = true; |
---|
708 | } |
---|
709 | |
---|
710 | /** |
---|
711 | * \brief Set opacity of VtkGraphicsObject for the given DataSet |
---|
712 | */ |
---|
713 | template<class GraphicsObject> |
---|
714 | void Renderer::setGraphicsObjectOpacity(const DataSetId& id, double opacity) |
---|
715 | { |
---|
716 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
717 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
718 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
719 | |
---|
720 | bool doAll = false; |
---|
721 | |
---|
722 | if (id.compare("all") == 0) { |
---|
723 | itr = hashmap.begin(); |
---|
724 | if (itr == hashmap.end()) |
---|
725 | return; |
---|
726 | doAll = true; |
---|
727 | } else { |
---|
728 | itr = hashmap.find(id); |
---|
729 | } |
---|
730 | if (itr == hashmap.end()) { |
---|
731 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
732 | return; |
---|
733 | } |
---|
734 | |
---|
735 | do { |
---|
736 | itr->second->setOpacity(opacity); |
---|
737 | } while (doAll && ++itr != hashmap.end()); |
---|
738 | |
---|
739 | _needsRedraw = true; |
---|
740 | } |
---|
741 | |
---|
742 | /** |
---|
743 | * \brief Set the point size for the specified DataSet (may be a no-op) |
---|
744 | * |
---|
745 | * If the OpenGL implementation/hardware does not support wide points, |
---|
746 | * this function may not have an effect. |
---|
747 | */ |
---|
748 | template<class GraphicsObject> |
---|
749 | void Renderer::setGraphicsObjectPointSize(const DataSetId& id, float size) |
---|
750 | { |
---|
751 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
752 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
753 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
754 | |
---|
755 | bool doAll = false; |
---|
756 | |
---|
757 | if (id.compare("all") == 0) { |
---|
758 | itr = hashmap.begin(); |
---|
759 | if (itr == hashmap.end()) |
---|
760 | return; |
---|
761 | doAll = true; |
---|
762 | } else { |
---|
763 | itr = hashmap.find(id); |
---|
764 | } |
---|
765 | if (itr == hashmap.end()) { |
---|
766 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
767 | return; |
---|
768 | } |
---|
769 | |
---|
770 | do { |
---|
771 | itr->second->setPointSize(size); |
---|
772 | } while (doAll && ++itr != hashmap.end()); |
---|
773 | |
---|
774 | sceneBoundsChanged(); |
---|
775 | _needsRedraw = true; |
---|
776 | } |
---|
777 | |
---|
778 | /** |
---|
779 | * \brief Set wireframe actor rendering for the specified DataSet |
---|
780 | */ |
---|
781 | template<class GraphicsObject> |
---|
782 | void Renderer::setGraphicsObjectWireframe(const DataSetId& id, bool state) |
---|
783 | { |
---|
784 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
785 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
786 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
787 | |
---|
788 | bool doAll = false; |
---|
789 | |
---|
790 | if (id.compare("all") == 0) { |
---|
791 | itr = hashmap.begin(); |
---|
792 | if (itr == hashmap.end()) |
---|
793 | return; |
---|
794 | doAll = true; |
---|
795 | } else { |
---|
796 | itr = hashmap.find(id); |
---|
797 | } |
---|
798 | if (itr == hashmap.end()) { |
---|
799 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
800 | return; |
---|
801 | } |
---|
802 | |
---|
803 | do { |
---|
804 | itr->second->setWireframe(state); |
---|
805 | } while (doAll && ++itr != hashmap.end()); |
---|
806 | |
---|
807 | _needsRedraw = true; |
---|
808 | } |
---|
809 | |
---|
810 | /** |
---|
811 | * \brief Associate an existing named color map with a graphics object for the given DataSet |
---|
812 | */ |
---|
813 | template<class GraphicsObject> |
---|
814 | void Renderer::setGraphicsObjectColorMap(const DataSetId& id, const ColorMapId& colorMapId) |
---|
815 | { |
---|
816 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
817 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
818 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
819 | |
---|
820 | bool doAll = false; |
---|
821 | |
---|
822 | if (id.compare("all") == 0) { |
---|
823 | itr = hashmap.begin(); |
---|
824 | if (itr == hashmap.end()) |
---|
825 | return; |
---|
826 | doAll = true; |
---|
827 | } else { |
---|
828 | itr = hashmap.find(id); |
---|
829 | } |
---|
830 | |
---|
831 | if (itr == hashmap.end()) { |
---|
832 | GO_ERROR(GraphicsObject, "not found: %s", id.c_str()); |
---|
833 | return; |
---|
834 | } |
---|
835 | |
---|
836 | ColorMap *cmap = getColorMap(colorMapId); |
---|
837 | if (cmap == NULL) { |
---|
838 | ERROR("Unknown colormap: %s", colorMapId.c_str()); |
---|
839 | return; |
---|
840 | } |
---|
841 | |
---|
842 | do { |
---|
843 | GO_TRACE(GraphicsObject, "Set color map: %s for dataset %s", |
---|
844 | colorMapId.c_str(), |
---|
845 | itr->second->getDataSet()->getName().c_str()); |
---|
846 | |
---|
847 | itr->second->setColorMap(cmap); |
---|
848 | } while (doAll && ++itr != hashmap.end()); |
---|
849 | |
---|
850 | _needsRedraw = true; |
---|
851 | } |
---|
852 | |
---|
853 | /** |
---|
854 | * \brief Notify graphics object that color map has changed |
---|
855 | */ |
---|
856 | template<class GraphicsObject> |
---|
857 | void Renderer::updateGraphicsObjectColorMap(ColorMap *cmap) |
---|
858 | { |
---|
859 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
860 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
861 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
862 | |
---|
863 | for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) { |
---|
864 | if (itr->second->getColorMap() == cmap) { |
---|
865 | itr->second->updateColorMap(); |
---|
866 | _needsRedraw = true; |
---|
867 | } |
---|
868 | } |
---|
869 | } |
---|
870 | |
---|
871 | /** |
---|
872 | * \brief Check if a color map is in use by a graphics object |
---|
873 | */ |
---|
874 | template<class GraphicsObject> |
---|
875 | bool Renderer::graphicsObjectColorMapUsed(ColorMap *cmap) |
---|
876 | { |
---|
877 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
878 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
879 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
880 | |
---|
881 | for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) { |
---|
882 | if (itr->second->getColorMap() == cmap) |
---|
883 | return true; |
---|
884 | } |
---|
885 | return false; |
---|
886 | } |
---|
887 | |
---|
888 | /** |
---|
889 | * \brief Compute union of bounds and GO's bounds |
---|
890 | */ |
---|
891 | template<class GraphicsObject> |
---|
892 | void Renderer::mergeGraphicsObjectBounds(double *bounds, bool onlyVisible) |
---|
893 | { |
---|
894 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
895 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
896 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
897 | |
---|
898 | for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) { |
---|
899 | if ((!onlyVisible || itr->second->getVisibility()) && |
---|
900 | itr->second->getProp() != NULL) |
---|
901 | mergeBounds(bounds, bounds, itr->second->getBounds()); |
---|
902 | #ifdef DEBUG |
---|
903 | double *bPtr = itr->second->getBounds(); |
---|
904 | assert(bPtr != NULL); |
---|
905 | GO_TRACE(GraphicsObject, |
---|
906 | "%s bounds: %g %g %g %g %g %g", |
---|
907 | itr->first.c_str(), |
---|
908 | bPtr[0], bPtr[1], bPtr[2], bPtr[3], bPtr[4], bPtr[5]); |
---|
909 | #endif |
---|
910 | } |
---|
911 | } |
---|
912 | |
---|
913 | /** |
---|
914 | * \brief Compute union of bounds and GO's unscaled bounds |
---|
915 | * |
---|
916 | * Unscaled bounds are the bounds of the object before any actor scaling is |
---|
917 | * applied |
---|
918 | */ |
---|
919 | template<class GraphicsObject> |
---|
920 | void Renderer::mergeGraphicsObjectUnscaledBounds(double *bounds, bool onlyVisible) |
---|
921 | { |
---|
922 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
923 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
924 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
925 | |
---|
926 | for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) { |
---|
927 | if ((!onlyVisible || itr->second->getVisibility()) && |
---|
928 | itr->second->getProp() != NULL) |
---|
929 | mergeBounds(bounds, bounds, itr->second->getUnscaledBounds()); |
---|
930 | #ifdef DEBUG |
---|
931 | double *bPtr = itr->second->getUnscaledBounds(); |
---|
932 | assert(bPtr != NULL); |
---|
933 | GO_TRACE(GraphicsObject, |
---|
934 | "%s bounds: %g %g %g %g %g %g", |
---|
935 | itr->first.c_str(), |
---|
936 | bPtr[0], bPtr[1], bPtr[2], bPtr[3], bPtr[4], bPtr[5]); |
---|
937 | #endif |
---|
938 | } |
---|
939 | } |
---|
940 | |
---|
941 | /** |
---|
942 | * \brief Notify object that field value ranges have changed |
---|
943 | */ |
---|
944 | template<class GraphicsObject> |
---|
945 | void Renderer::updateGraphicsObjectFieldRanges() |
---|
946 | { |
---|
947 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
948 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
949 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
950 | |
---|
951 | for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) { |
---|
952 | itr->second->updateRanges(this); |
---|
953 | } |
---|
954 | } |
---|
955 | |
---|
956 | /** |
---|
957 | * \brief Pass global clip planes to graphics object |
---|
958 | */ |
---|
959 | template<class GraphicsObject> |
---|
960 | void Renderer::setGraphicsObjectClippingPlanes(vtkPlaneCollection *planes) |
---|
961 | { |
---|
962 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
963 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
964 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
965 | |
---|
966 | for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) { |
---|
967 | itr->second->setClippingPlanes(planes); |
---|
968 | } |
---|
969 | } |
---|
970 | |
---|
971 | /** |
---|
972 | * \brief Set the prop scaling based on a 2D aspect ratio |
---|
973 | * |
---|
974 | * This method sets the aspect on all graphics objects of a given type |
---|
975 | * |
---|
976 | * \param aspectRatio The aspect ratio (width/height), zero means native aspect |
---|
977 | */ |
---|
978 | template<class GraphicsObject> |
---|
979 | void Renderer::setGraphicsObjectAspect(double aspectRatio) |
---|
980 | { |
---|
981 | std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = |
---|
982 | getGraphicsObjectHashmap<GraphicsObject>(); |
---|
983 | typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; |
---|
984 | |
---|
985 | for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) { |
---|
986 | itr->second->setAspect(aspectRatio); |
---|
987 | } |
---|
988 | |
---|
989 | sceneBoundsChanged(); |
---|
990 | _needsRedraw = true; |
---|
991 | } |
---|
992 | |
---|
993 | } |
---|
994 | } |
---|
995 | |
---|
996 | #endif |
---|