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