source: vtkvis/branches/1.7/RendererGraphicsObjs.h @ 4778

Last change on this file since 4778 was 4607, checked in by ldelgass, 10 years ago

Merge trivial fix from r4174

  • Property svn:eol-style set to native
File size: 30.2 KB
Line 
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 VTKVIS_RENDERER_GRAPHICS_OBJS_H
9#define 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, ...)                                            \
21do {                                                                         \
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, ...)                                            \
29do {                                                                         \
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 "Renderer.h"
41
42namespace VtkVis {
43
44/**
45 * \brief Look up graphics object by name
46 */
47template<class T>
48T *Renderer::getGraphicsObject(const DataSetId& id)
49{
50    std::tr1::unordered_map<DataSetId, T *>& hashmap =
51        getGraphicsObjectHashmap<T>();
52    typename std::tr1::unordered_map<DataSetId, T *>::iterator
53        itr = hashmap.find(id);
54
55    if (itr == hashmap.end()) {
56#ifdef DEBUG
57        GO_TRACE(T, "not found: %s", id.c_str());
58#endif
59        return NULL;
60    } else
61        return itr->second;
62}
63
64/**
65 * \brief Delete graphics object by name
66 */
67template<class T>
68void Renderer::deleteGraphicsObject(const DataSetId& id)
69{
70    std::tr1::unordered_map<DataSetId, T *>& hashmap =
71        getGraphicsObjectHashmap<T>();
72    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
73
74    bool doAll = false;
75
76    if (id.compare("all") == 0) {
77        itr = hashmap.begin();
78        doAll = true;
79    } else {
80        itr = hashmap.find(id);
81    }
82    if (itr == hashmap.end()) {
83        GO_ERROR(T, "not found: %s", id.c_str());
84        return;
85    }
86
87    TRACE("Deleting %s for %s", itr->second->getClassName(), id.c_str());
88
89    do {
90        T *gobj = itr->second;
91        if (gobj->getProp())
92            _renderer->RemoveViewProp(gobj->getProp());
93        if (gobj->getOverlayProp())
94            _renderer->RemoveViewProp(gobj->getOverlayProp());
95        delete gobj;
96
97        itr = hashmap.erase(itr);
98    } while (doAll && itr != hashmap.end());
99
100    sceneBoundsChanged();
101    _needsRedraw = true;
102}
103
104/**
105 * \brief Delete all graphics objects from renderer
106 */
107template<class T>
108void Renderer::deleteAllGraphicsObjects()
109{
110    std::tr1::unordered_map<DataSetId, T *>& hashmap =
111        getGraphicsObjectHashmap<T>();
112    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
113
114    itr = hashmap.begin();
115    if (itr == hashmap.end())
116        return;
117
118    TRACE("Deleting all %s objects", itr->second->getClassName());
119
120    for (; itr != hashmap.end(); ++itr) {
121        delete itr->second;
122    }
123    hashmap.clear();
124}
125
126/**
127 * \brief Add a graphics objects to the renderer's scene
128 */
129template<class T>
130bool Renderer::addGraphicsObject(const DataSetId& id)
131{
132    DataSetHashmap::iterator itr;
133
134    bool doAll = false;
135
136    if (id.compare("all") == 0) {
137        itr = _dataSets.begin();
138    } else {
139        itr = _dataSets.find(id);
140    }
141    if (itr == _dataSets.end()) {
142        ERROR("Unknown dataset %s", id.c_str());
143        return false;
144    }
145
146    do {
147        DataSet *ds = itr->second;
148        const DataSetId& dsID = ds->getName();
149
150        T *gobj;
151        if ((gobj = getGraphicsObject<T>(dsID)) != NULL) {
152            WARN("Replacing existing %s %s", gobj->getClassName(), dsID.c_str());
153            deleteGraphicsObject<T>(dsID);
154        }
155
156        gobj = new T();
157 
158        gobj->setDataSet(ds, this);
159
160        if (gobj->getProp() == NULL &&
161            gobj->getOverlayProp() == NULL) {
162            delete gobj;
163            return false;
164        } else {
165            if (gobj->getProp())
166                _renderer->AddViewProp(gobj->getProp());
167            if (gobj->getOverlayProp())
168                _renderer->AddViewProp(gobj->getOverlayProp());
169        }
170
171        getGraphicsObjectHashmap<T>()[dsID] = gobj;
172    } while (doAll && ++itr != _dataSets.end());
173
174    sceneBoundsChanged();
175    _needsRedraw = true;
176    return true;
177}
178
179/**
180 * \brief Set the prop orientation with a quaternion
181 */
182template<class T>
183void Renderer::setGraphicsObjectTransform(const DataSetId& id, vtkMatrix4x4 *trans)
184{
185    std::tr1::unordered_map<DataSetId, T *>& hashmap =
186        getGraphicsObjectHashmap<T>();
187    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
188
189    bool doAll = false;
190
191    if (id.compare("all") == 0) {
192        itr = hashmap.begin();
193        if (itr == hashmap.end())
194            return;
195        doAll = true;
196    } else {
197        itr = hashmap.find(id);
198    }
199    if (itr == hashmap.end()) {
200        GO_ERROR(T, "not found: %s", id.c_str());
201        return;
202    }
203
204    do {
205        itr->second->setTransform(trans);
206    } while (doAll && ++itr != hashmap.end());
207
208    sceneBoundsChanged();
209    _needsRedraw = true;
210}
211
212/**
213 * \brief Set the prop orientation with a quaternion
214 */
215template<class T>
216void Renderer::setGraphicsObjectOrientation(const DataSetId& id, double quat[4])
217{
218    std::tr1::unordered_map<DataSetId, T *>& hashmap =
219        getGraphicsObjectHashmap<T>();
220    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
221
222    bool doAll = false;
223
224    if (id.compare("all") == 0) {
225        itr = hashmap.begin();
226        if (itr == hashmap.end())
227            return;
228        doAll = true;
229    } else {
230        itr = hashmap.find(id);
231    }
232    if (itr == hashmap.end()) {
233        GO_ERROR(T, "not found: %s", id.c_str());
234        return;
235    }
236
237    do {
238        itr->second->setOrientation(quat);
239    } while (doAll && ++itr != hashmap.end());
240
241    sceneBoundsChanged();
242    _needsRedraw = true;
243}
244
245/**
246 * \brief Set the prop orientation with a rotation about an axis
247 */
248template<class T>
249void Renderer::setGraphicsObjectOrientation(const DataSetId& id, double angle, double axis[3])
250{
251    std::tr1::unordered_map<DataSetId, T *>& hashmap =
252        getGraphicsObjectHashmap<T>();
253    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
254
255    bool doAll = false;
256
257    if (id.compare("all") == 0) {
258        itr = hashmap.begin();
259        if (itr == hashmap.end())
260            return;
261        doAll = true;
262    } else {
263        itr = hashmap.find(id);
264    }
265    if (itr == hashmap.end()) {
266        GO_ERROR(T, "not found: %s", id.c_str());
267        return;
268    }
269
270    do {
271        itr->second->setOrientation(angle, axis);
272    } while (doAll && ++itr != hashmap.end());
273
274    sceneBoundsChanged();
275    _needsRedraw = true;
276}
277
278/**
279 * \brief Set the prop origin (center of rotation)
280 */
281template<class T>
282void Renderer::setGraphicsObjectOrigin(const DataSetId& id, double origin[3])
283{
284    std::tr1::unordered_map<DataSetId, T *>& hashmap =
285        getGraphicsObjectHashmap<T>();
286    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
287
288    bool doAll = false;
289
290    if (id.compare("all") == 0) {
291        itr = hashmap.begin();
292        if (itr == hashmap.end())
293            return;
294        doAll = true;
295    } else {
296        itr = hashmap.find(id);
297    }
298    if (itr == hashmap.end()) {
299        GO_ERROR(T, "not found: %s", id.c_str());
300        return;
301    }
302
303    do {
304        itr->second->setOrigin(origin);
305    } while (doAll && ++itr != hashmap.end());
306
307    sceneBoundsChanged();
308    _needsRedraw = true;
309}
310
311/**
312 * \brief Set the prop position in world coords
313 */
314template<class T>
315void Renderer::setGraphicsObjectPosition(const DataSetId& id, double pos[3])
316{
317    std::tr1::unordered_map<DataSetId, T *>& hashmap =
318        getGraphicsObjectHashmap<T>();
319    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
320
321    bool doAll = false;
322
323    if (id.compare("all") == 0) {
324        itr = hashmap.begin();
325        if (itr == hashmap.end())
326            return;
327        doAll = true;
328    } else {
329        itr = hashmap.find(id);
330    }
331    if (itr == hashmap.end()) {
332        GO_ERROR(T, "not found: %s", id.c_str());
333        return;
334    }
335
336    do {
337        itr->second->setPosition(pos);
338    } while (doAll && ++itr != hashmap.end());
339
340    sceneBoundsChanged();
341    _needsRedraw = true;
342}
343
344/**
345 * \brief Set the prop scaling based on a 2D aspect ratio
346 *
347 * \param id The name of the DataSet
348 * \param aspect The aspect ratio (width/height), zero means native aspect
349 */
350template<class T>
351void Renderer::setGraphicsObjectAspect(const DataSetId& id, double aspect)
352{
353    std::tr1::unordered_map<DataSetId, T *>& hashmap =
354        getGraphicsObjectHashmap<T>();
355    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
356
357    bool doAll = false;
358
359    if (id.compare("all") == 0) {
360        itr = hashmap.begin();
361        if (itr == hashmap.end())
362            return;
363        doAll = true;
364    } else {
365        itr = hashmap.find(id);
366    }
367    if (itr == hashmap.end()) {
368        GO_ERROR(T, "not found: %s", id.c_str());
369        return;
370    }
371
372    do {
373        itr->second->setAspect(aspect);
374    } while (doAll && ++itr != hashmap.end());
375
376    sceneBoundsChanged();
377    _needsRedraw = true;
378}
379
380/**
381 * \brief Set the prop scaling
382 */
383template<class T>
384void Renderer::setGraphicsObjectScale(const DataSetId& id, double scale[3])
385{
386    std::tr1::unordered_map<DataSetId, T *>& hashmap =
387        getGraphicsObjectHashmap<T>();
388    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
389
390    bool doAll = false;
391
392    if (id.compare("all") == 0) {
393        itr = hashmap.begin();
394        if (itr == hashmap.end())
395            return;
396        doAll = true;
397    } else {
398        itr = hashmap.find(id);
399    }
400    if (itr == hashmap.end()) {
401        GO_ERROR(T, "not found: %s", id.c_str());
402        return;
403    }
404
405    do {
406        itr->second->setScale(scale);
407    } while (doAll && ++itr != hashmap.end());
408
409    sceneBoundsChanged();
410    _needsRedraw = true;
411}
412
413/**
414 * \brief Set visibility of GraphicsObject for the given DataSet
415 */
416template<class T>
417void Renderer::setGraphicsObjectVisibility(const DataSetId& id, bool state)
418{
419    std::tr1::unordered_map<DataSetId, T *>& hashmap =
420        getGraphicsObjectHashmap<T>();
421    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
422
423    bool doAll = false;
424
425    if (id.compare("all") == 0) {
426        itr = hashmap.begin();
427        if (itr == hashmap.end())
428            return;
429        doAll = true;
430    } else {
431        itr = hashmap.find(id);
432    }
433    if (itr == hashmap.end()) {
434        GO_ERROR(T, "not found: %s", id.c_str());
435        return;
436    }
437
438    do {
439        itr->second->setVisibility(state);
440    } while (doAll && ++itr != hashmap.end());
441
442    sceneBoundsChanged();
443    _needsRedraw = true;
444}
445
446/**
447 * \brief Set the volume slice
448 */
449template<class T>
450void Renderer::setGraphicsObjectVolumeSlice(const DataSetId& id, Axis axis, double ratio)
451{
452    std::tr1::unordered_map<DataSetId, T *>& hashmap =
453        getGraphicsObjectHashmap<T>();
454    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
455
456    bool doAll = false;
457
458    if (id.compare("all") == 0) {
459        itr = hashmap.begin();
460        if (itr == hashmap.end())
461            return;
462        doAll = true;
463    } else {
464        itr = hashmap.find(id);
465    }
466
467    if (itr == hashmap.end()) {
468        GO_ERROR(T, "not found: %s", id.c_str());
469        return;
470    }
471
472    do {
473        itr->second->selectVolumeSlice(axis, ratio);
474     } while (doAll && ++itr != hashmap.end());
475
476    sceneBoundsChanged();
477    _needsRedraw = true;
478}
479
480
481/**
482 * \brief Set the RGB actor color for the specified DataSet
483 */
484template<class T>
485void Renderer::setGraphicsObjectColor(const DataSetId& id, float color[3])
486{
487    std::tr1::unordered_map<DataSetId, T *>& hashmap =
488        getGraphicsObjectHashmap<T>();
489    typename std::tr1::unordered_map<DataSetId, T *>::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(T, "not found: %s", id.c_str());
503        return;
504    }
505
506    do {
507        itr->second->setColor(color);
508    } while (doAll && ++itr != hashmap.end());
509
510    _needsRedraw = true;
511}
512
513/**
514 * \brief Set cull face for graphics object
515 */
516template<class T>
517void Renderer::setGraphicsObjectCullFace(const DataSetId& id,
518                                         GraphicsObject::CullFace state)
519{
520    std::tr1::unordered_map<DataSetId, T *>& hashmap =
521        getGraphicsObjectHashmap<T>();
522    typename std::tr1::unordered_map<DataSetId, T *>::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
535    if (itr == hashmap.end()) {
536        GO_ERROR(T, "not found: %s", id.c_str());
537        return;
538    }
539
540    do {
541        itr->second->setCullFace(state);
542    } while (doAll && ++itr != hashmap.end());
543
544    _needsRedraw = true;
545}
546
547/**
548 * \brief Set face culling for graphics object
549 */
550template<class T>
551void Renderer::setGraphicsObjectCulling(const DataSetId& id, bool state)
552{
553    std::tr1::unordered_map<DataSetId, T *>& hashmap =
554        getGraphicsObjectHashmap<T>();
555    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
556
557    bool doAll = false;
558
559    if (id.compare("all") == 0) {
560        itr = hashmap.begin();
561        if (itr == hashmap.end())
562            return;
563        doAll = true;
564    } else {
565        itr = hashmap.find(id);
566    }
567
568    if (itr == hashmap.end()) {
569        GO_ERROR(T, "not found: %s", id.c_str());
570        return;
571    }
572
573    do {
574        itr->second->setCulling(state);
575    } while (doAll && ++itr != hashmap.end());
576
577    _needsRedraw = true;
578}
579
580/**
581 * \brief Turn on/off edges for the given DataSet
582 */
583template<class T>
584void Renderer::setGraphicsObjectEdgeVisibility(const DataSetId& id, bool state)
585{
586    std::tr1::unordered_map<DataSetId, T *>& hashmap =
587        getGraphicsObjectHashmap<T>();
588    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
589
590    bool doAll = false;
591
592    if (id.compare("all") == 0) {
593        itr = hashmap.begin();
594        if (itr == hashmap.end())
595            return;
596        doAll = true;
597    } else {
598        itr = hashmap.find(id);
599    }
600    if (itr == hashmap.end()) {
601        GO_ERROR(T, "not found: %s", id.c_str());
602        return;
603    }
604
605    do {
606        itr->second->setEdgeVisibility(state);
607    } while (doAll && ++itr != hashmap.end());
608
609    sceneBoundsChanged();
610    _needsRedraw = true;
611}
612
613/**
614 * \brief Set the RGB isosurface edge color for the specified DataSet
615 */
616template<class T>
617void Renderer::setGraphicsObjectEdgeColor(const DataSetId& id, float color[3])
618{
619    std::tr1::unordered_map<DataSetId, T *>& hashmap =
620        getGraphicsObjectHashmap<T>();
621    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
622
623    bool doAll = false;
624
625    if (id.compare("all") == 0) {
626        itr = hashmap.begin();
627        if (itr == hashmap.end())
628            return;
629        doAll = true;
630    } else {
631        itr = hashmap.find(id);
632    }
633    if (itr == hashmap.end()) {
634        GO_ERROR(T, "not found: %s", id.c_str());
635        return;
636    }
637
638    do {
639        itr->second->setEdgeColor(color);
640    } while (doAll && ++itr != hashmap.end());
641
642    _needsRedraw = true;
643}
644
645/**
646 * \brief Set the isosurface edge width for the specified DataSet (may be a no-op)
647 *
648 * If the OpenGL implementation/hardware does not support wide lines,
649 * this function may not have an effect.
650 */
651template<class T>
652void Renderer::setGraphicsObjectEdgeWidth(const DataSetId& id, float edgeWidth)
653{
654    std::tr1::unordered_map<DataSetId, T *>& hashmap =
655        getGraphicsObjectHashmap<T>();
656    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
657
658    bool doAll = false;
659
660    if (id.compare("all") == 0) {
661        itr = hashmap.begin();
662        if (itr == hashmap.end())
663            return;
664        doAll = true;
665    } else {
666        itr = hashmap.find(id);
667    }
668    if (itr == hashmap.end()) {
669        GO_ERROR(T, "not found: %s", id.c_str());
670        return;
671    }
672
673    do {
674        itr->second->setEdgeWidth(edgeWidth);
675    } while (doAll && ++itr != hashmap.end());
676
677    sceneBoundsChanged();
678    _needsRedraw = true;
679}
680
681/**
682 * \brief Flip normals and front/back faces of the shape geometry
683 */
684template<class T>
685void Renderer::setGraphicsObjectFlipNormals(const DataSetId& id, bool state)
686{
687    std::tr1::unordered_map<DataSetId, T *>& hashmap =
688        getGraphicsObjectHashmap<T>();
689    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
690
691    bool doAll = false;
692
693    if (id.compare("all") == 0) {
694        itr = hashmap.begin();
695        if (itr == hashmap.end())
696            return;
697        doAll = true;
698    } else {
699        itr = hashmap.find(id);
700    }
701    if (itr == hashmap.end()) {
702        GO_ERROR(T, "not found: %s", id.c_str());
703        return;
704    }
705
706    do {
707        itr->second->flipNormals(state);
708    } while (doAll && ++itr != hashmap.end());
709
710    _needsRedraw = true;
711}
712
713/**
714 * \brief Set ambient lighting/shading coefficient for the specified DataSet
715 */
716template<class T>
717void Renderer::setGraphicsObjectAmbient(const DataSetId& id, double coeff)
718{
719    std::tr1::unordered_map<DataSetId, T *>& hashmap =
720        getGraphicsObjectHashmap<T>();
721    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
722
723    bool doAll = false;
724
725    if (id.compare("all") == 0) {
726        itr = hashmap.begin();
727        if (itr == hashmap.end())
728            return;
729        doAll = true;
730    } else {
731        itr = hashmap.find(id);
732    }
733    if (itr == hashmap.end()) {
734        GO_ERROR(T, "not found: %s", id.c_str());
735        return;
736    }
737
738    do {
739        itr->second->setAmbient(coeff);
740    } while (doAll && ++itr != hashmap.end());
741
742    _needsRedraw = true;
743}
744
745/**
746 * \brief Set diffuse lighting/shading coefficient for the specified DataSet
747 */
748template<class T>
749void Renderer::setGraphicsObjectDiffuse(const DataSetId& id, double coeff)
750{
751    std::tr1::unordered_map<DataSetId, T *>& hashmap =
752        getGraphicsObjectHashmap<T>();
753    typename std::tr1::unordered_map<DataSetId, T *>::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(T, "not found: %s", id.c_str());
767        return;
768    }
769
770    do {
771        itr->second->setDiffuse(coeff);
772    } while (doAll && ++itr != hashmap.end());
773
774    _needsRedraw = true;
775}
776
777/**
778 * \brief Set the shading of the object (flat or smooth)
779 *
780 * Currently Phong shading is not implemented
781 */
782template<class T>
783void Renderer::setGraphicsObjectShadingModel(const DataSetId& id,
784                                             GraphicsObject::ShadingModel state)
785{
786    std::tr1::unordered_map<DataSetId, T *>& hashmap =
787        getGraphicsObjectHashmap<T>();
788    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
789
790    bool doAll = false;
791
792    if (id.compare("all") == 0) {
793        itr = hashmap.begin();
794        if (itr == hashmap.end())
795            return;
796        doAll = true;
797    } else {
798        itr = hashmap.find(id);
799    }
800    if (itr == hashmap.end()) {
801        GO_ERROR(T, "not found: %s", id.c_str());
802        return;
803    }
804
805    do {
806        itr->second->setShadingModel(state);
807    } while (doAll && ++itr != hashmap.end());
808
809    _needsRedraw = true;
810}
811
812/**
813 * \brief Set specular lighting/shading coefficient and power for the specified DataSet
814 */
815template<class T>
816void Renderer::setGraphicsObjectSpecular(const DataSetId& id, double coeff, double power)
817{
818    std::tr1::unordered_map<DataSetId, T *>& hashmap =
819        getGraphicsObjectHashmap<T>();
820    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
821
822    bool doAll = false;
823
824    if (id.compare("all") == 0) {
825        itr = hashmap.begin();
826        if (itr == hashmap.end())
827            return;
828        doAll = true;
829    } else {
830        itr = hashmap.find(id);
831    }
832    if (itr == hashmap.end()) {
833        GO_ERROR(T, "not found: %s", id.c_str());
834        return;
835    }
836
837    do {
838        itr->second->setSpecular(coeff, power);
839    } while (doAll && ++itr != hashmap.end());
840
841    _needsRedraw = true;
842}
843
844/**
845 * \brief Turn actor lighting on/off for the specified DataSet
846 */
847template<class T>
848void Renderer::setGraphicsObjectLighting(const DataSetId& id, bool state)
849{
850    std::tr1::unordered_map<DataSetId, T *>& hashmap =
851        getGraphicsObjectHashmap<T>();
852    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
853
854    bool doAll = false;
855
856    if (id.compare("all") == 0) {
857        itr = hashmap.begin();
858        if (itr == hashmap.end())
859            return;
860        doAll = true;
861    } else {
862        itr = hashmap.find(id);
863    }
864    if (itr == hashmap.end()) {
865        GO_ERROR(T, "not found: %s", id.c_str());
866        return;
867    }
868
869    do {
870        itr->second->setLighting(state);
871    } while (doAll && ++itr != hashmap.end());
872
873    _needsRedraw = true;
874}
875
876/**
877 * \brief Set opacity of GraphicsObject for the given DataSet
878 */
879template<class T>
880void Renderer::setGraphicsObjectOpacity(const DataSetId& id, double opacity)
881{
882    std::tr1::unordered_map<DataSetId, T *>& hashmap =
883        getGraphicsObjectHashmap<T>();
884    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
885
886    bool doAll = false;
887
888    if (id.compare("all") == 0) {
889        itr = hashmap.begin();
890        if (itr == hashmap.end())
891            return;
892        doAll = true;
893    } else {
894        itr = hashmap.find(id);
895    }
896    if (itr == hashmap.end()) {
897        GO_ERROR(T, "not found: %s", id.c_str());
898        return;
899    }
900
901    do {
902        itr->second->setOpacity(opacity);
903    } while (doAll && ++itr != hashmap.end());
904
905    _needsRedraw = true;
906}
907
908/**
909 * \brief Set the point size for the specified DataSet (may be a no-op)
910 *
911 * If the OpenGL implementation/hardware does not support wide points,
912 * this function may not have an effect.
913 */
914template<class T>
915void Renderer::setGraphicsObjectPointSize(const DataSetId& id, float size)
916{
917    std::tr1::unordered_map<DataSetId, T *>& hashmap =
918        getGraphicsObjectHashmap<T>();
919    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
920
921    bool doAll = false;
922
923    if (id.compare("all") == 0) {
924        itr = hashmap.begin();
925        if (itr == hashmap.end())
926            return;
927        doAll = true;
928    } else {
929        itr = hashmap.find(id);
930    }
931    if (itr == hashmap.end()) {
932        GO_ERROR(T, "not found: %s", id.c_str());
933        return;
934    }
935
936    do {
937        itr->second->setPointSize(size);
938    } while (doAll && ++itr != hashmap.end());
939
940    sceneBoundsChanged();
941    _needsRedraw = true;
942}
943
944/**
945 * \brief Set wireframe actor rendering for the specified DataSet
946 */
947template<class T>
948void Renderer::setGraphicsObjectWireframe(const DataSetId& id, bool state)
949{
950    std::tr1::unordered_map<DataSetId, T *>& hashmap =
951        getGraphicsObjectHashmap<T>();
952    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
953
954    bool doAll = false;
955
956    if (id.compare("all") == 0) {
957        itr = hashmap.begin();
958        if (itr == hashmap.end())
959            return;
960        doAll = true;
961    } else {
962        itr = hashmap.find(id);
963    }
964    if (itr == hashmap.end()) {
965        GO_ERROR(T, "not found: %s", id.c_str());
966        return;
967    }
968
969    do {
970        itr->second->setWireframe(state);
971    } while (doAll && ++itr != hashmap.end());
972
973    _needsRedraw = true;
974}
975
976/**
977 * \brief Associate an existing named color map with a graphics object for the given DataSet
978 */
979template<class T>
980void Renderer::setGraphicsObjectInterpolateBeforeMapping(const DataSetId& id, bool state)
981{
982    std::tr1::unordered_map<DataSetId, T *>& hashmap =
983        getGraphicsObjectHashmap<T>();
984    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
985
986    bool doAll = false;
987
988    if (id.compare("all") == 0) {
989        itr = hashmap.begin();
990        if (itr == hashmap.end())
991            return;
992        doAll = true;
993    } else {
994        itr = hashmap.find(id);
995    }
996
997    if (itr == hashmap.end()) {
998        GO_ERROR(T, "not found: %s", id.c_str());
999        return;
1000    }
1001
1002    do {
1003        itr->second->setInterpolateBeforeMapping(state);
1004    } while (doAll && ++itr != hashmap.end());
1005
1006    _needsRedraw = true;
1007}
1008
1009/**
1010 * \brief Associate an existing named color map with a graphics object for the given DataSet
1011 */
1012template<class T>
1013void Renderer::setGraphicsObjectColorMap(const DataSetId& id, const ColorMapId& colorMapId)
1014{
1015    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1016        getGraphicsObjectHashmap<T>();
1017    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1018
1019    bool doAll = false;
1020
1021    if (id.compare("all") == 0) {
1022        itr = hashmap.begin();
1023        if (itr == hashmap.end())
1024            return;
1025        doAll = true;
1026    } else {
1027        itr = hashmap.find(id);
1028    }
1029
1030    if (itr == hashmap.end()) {
1031        GO_ERROR(T, "not found: %s", id.c_str());
1032        return;
1033    }
1034
1035    ColorMap *cmap = getColorMap(colorMapId);
1036    if (cmap == NULL && colorMapId.compare("none") != 0) {
1037        ERROR("Unknown colormap: %s", colorMapId.c_str());
1038        return;
1039    }
1040
1041    do {
1042        GO_TRACE(T, "Set color map: %s for dataset %s",
1043                 colorMapId.c_str(),
1044                 itr->second->getDataSet()->getName().c_str());
1045
1046        itr->second->setColorMap(cmap);
1047    } while (doAll && ++itr != hashmap.end());
1048
1049    _needsRedraw = true;
1050}
1051
1052/**
1053 * \brief Notify graphics object that color map has changed
1054 */
1055template<class T>
1056void Renderer::updateGraphicsObjectColorMap(ColorMap *cmap)
1057{
1058    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1059        getGraphicsObjectHashmap<T>();
1060    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1061
1062    for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) {
1063        if (itr->second->getColorMap() == cmap) {
1064            itr->second->updateColorMap();
1065            _needsRedraw = true;
1066        }
1067    }
1068}
1069
1070/**
1071 * \brief Check if a color map is in use by a graphics object
1072 */
1073template<class T>
1074bool Renderer::graphicsObjectColorMapUsed(ColorMap *cmap)
1075{
1076    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1077        getGraphicsObjectHashmap<T>();
1078    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1079
1080    for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) {
1081        if (itr->second->getColorMap() == cmap)
1082            return true;
1083    }
1084    return false;
1085}
1086
1087/**
1088 * \brief Compute union of bounds and GO's bounds
1089 */
1090template<class T>
1091void Renderer::mergeGraphicsObjectBounds(double *bounds, bool onlyVisible)
1092{
1093    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1094        getGraphicsObjectHashmap<T>();
1095    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1096
1097    for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) {
1098        if ((!onlyVisible || itr->second->getVisibility()) &&
1099            itr->second->getProp() != NULL) {
1100            mergeBounds(bounds, bounds, itr->second->getBounds());
1101#ifdef DEBUG
1102            double *bPtr = itr->second->getBounds();
1103            assert(bPtr != NULL);
1104            GO_TRACE(T,
1105                     "%s bounds: %g %g %g %g %g %g",
1106                     itr->first.c_str(),
1107                     bPtr[0], bPtr[1], bPtr[2], bPtr[3], bPtr[4], bPtr[5]);
1108#endif
1109        }
1110    }
1111}
1112
1113/**
1114 * \brief Compute union of bounds and GO's unscaled bounds
1115 *
1116 * Unscaled bounds are the bounds of the object before any actor scaling is
1117 * applied
1118 */
1119template<class T>
1120void Renderer::mergeGraphicsObjectUnscaledBounds(double *bounds, bool onlyVisible)
1121{
1122    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1123        getGraphicsObjectHashmap<T>();
1124    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1125
1126    for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) {
1127        if ((!onlyVisible || itr->second->getVisibility()) &&
1128            itr->second->getProp() != NULL) {
1129            mergeBounds(bounds, bounds, itr->second->getUnscaledBounds());
1130#ifdef DEBUG
1131            double *bPtr = itr->second->getUnscaledBounds();
1132            assert(bPtr != NULL);
1133            GO_TRACE(T,
1134                     "%s bounds: %g %g %g %g %g %g",
1135                     itr->first.c_str(),
1136                     bPtr[0], bPtr[1], bPtr[2], bPtr[3], bPtr[4], bPtr[5]);
1137#endif
1138        }
1139    }
1140}
1141
1142/**
1143 * \brief Notify object that field value ranges have changed
1144 */
1145template<class T>
1146void Renderer::updateGraphicsObjectFieldRanges()
1147{
1148    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1149        getGraphicsObjectHashmap<T>();
1150    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1151
1152    for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) {
1153        itr->second->updateRanges(this);
1154    }
1155}
1156
1157/**
1158 * \brief Pass global clip planes to graphics object
1159 */
1160template<class T>
1161void Renderer::setGraphicsObjectClippingPlanes(vtkPlaneCollection *planes)
1162{
1163    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1164        getGraphicsObjectHashmap<T>();
1165    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1166
1167    for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) {
1168        itr->second->setClippingPlanes(planes);
1169    }
1170}
1171
1172/**
1173 * \brief Set the prop scaling based on a 2D aspect ratio
1174 *
1175 * This method sets the aspect on all graphics objects of a given type
1176 *
1177 * \param aspectRatio The aspect ratio (width/height), zero means native aspect
1178 */
1179template<class T>
1180void Renderer::setGraphicsObjectAspect(double aspectRatio)
1181{
1182    std::tr1::unordered_map<DataSetId, T *>& hashmap =
1183        getGraphicsObjectHashmap<T>();
1184    typename std::tr1::unordered_map<DataSetId, T *>::iterator itr;
1185
1186    for (itr = hashmap.begin(); itr != hashmap.end(); ++itr) {
1187        itr->second->setAspect(aspectRatio);
1188    }
1189
1190    sceneBoundsChanged();
1191    _needsRedraw = true;
1192}
1193
1194}
1195
1196#endif
Note: See TracBrowser for help on using the repository browser.