source: trunk/packages/vizservers/vtkvis/RpVtkGraphicsObject.h @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

  • Property svn:eol-style set to native
File size: 24.9 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 __RAPPTURE_VTKVIS_VTKGRAPHICSOBJECT_H__
9#define __RAPPTURE_VTKVIS_VTKGRAPHICSOBJECT_H__
10
11#include <cmath>
12#include <string>
13
14#include <vtkSmartPointer.h>
15#include <vtkProp.h>
16#include <vtkProp3D.h>
17#include <vtkProp3DCollection.h>
18#include <vtkAssembly.h>
19#include <vtkActor.h>
20#include <vtkVolume.h>
21#include <vtkProperty.h>
22#include <vtkVolumeProperty.h>
23#include <vtkMath.h>
24#include <vtkMatrix4x4.h>
25#include <vtkPlaneCollection.h>
26
27#include "RpVtkDataSet.h"
28#include "Trace.h"
29
30namespace Rappture {
31namespace VtkVis {
32
33class Renderer;
34
35/**
36 * \brief Base class for graphics objects
37 */
38class VtkGraphicsObject {
39public:
40    enum CullFace {
41        CULL_FRONT,
42        CULL_BACK,
43        CULL_FRONT_AND_BACK
44    };
45
46    VtkGraphicsObject() :
47        _dataSet(NULL),
48        _opacity(1.0),
49        _edgeWidth(1.0f),
50        _pointSize(1.0f),
51        _lighting(true),
52        _cullFace(CULL_BACK),
53        _faceCulling(false)
54    {
55        _dataRange[0] = 0;
56        _dataRange[1] = 1;
57        _color[0] = 1.0f;
58        _color[1] = 1.0f;
59        _color[2] = 1.0f;
60        _edgeColor[0] = 0.0f;
61        _edgeColor[1] = 0.0f;
62        _edgeColor[2] = 0.0f;
63    }
64
65    virtual ~VtkGraphicsObject()
66    {}
67
68    /**
69     * \brief Return the name of the sublass of VtkGraphicsObject
70     */
71    virtual const char *getClassName() const = 0;
72
73    /**
74     * \brief Specify input DataSet and information on cumulative data ranges
75     *
76     * Default implementation calls update() and stores scalarRange to
77     * _dataRange based on cumulative range settings
78     *
79     * \param[in] dataSet DataSet to use in rendering
80     * \param[in] renderer Pointer to Renderer -- may be used to get
81     * cumulative data ranges
82     */
83    virtual void setDataSet(DataSet *dataSet,
84                            Renderer *renderer);
85
86    /**
87     * \brief Called when scalar or vector field changes (e.g. active field) or
88     * cumulative ranges or settings change
89     *
90     * \param[in] renderer Pointer to Renderer -- may be used to get
91     * cumulative data ranges
92     */
93    virtual void updateRanges(Renderer *renderer);
94
95    /**
96     * \brief Return the DataSet this object renders
97     */
98    inline DataSet *getDataSet()
99    {
100        return _dataSet;
101    }
102
103    /**
104     * \brief Return the VTK prop object to render
105     */
106    inline vtkProp *getProp()
107    {
108        return _prop;
109    }
110
111    /**
112     * \brief Cast the vktProp to a vtkProp3D
113     *
114     * \return NULL or a vtkProp3D pointer
115     */
116    inline vtkProp3D *getProp3D()
117    {
118        return vtkProp3D::SafeDownCast(_prop);
119    }
120
121    /**
122     * \brief Cast the vktProp to a vtkActor
123     *
124     * \return NULL or a vtkActor pointer
125     */
126    inline vtkActor *getActor()
127    {
128        return vtkActor::SafeDownCast(_prop);
129    }
130
131    /**
132     * \brief Cast the vktProp to a vtkVolume
133     *
134     * \return NULL or a vtkVolume pointer
135     */
136    inline vtkVolume *getVolume()
137    {
138        return vtkVolume::SafeDownCast(_prop);
139    }
140
141    /**
142     * \brief Cast the vktProp to a vtkAssembly
143     *
144     * \return NULL or a vtkAssembly pointer
145     */
146    inline vtkAssembly *getAssembly()
147    {
148        return vtkAssembly::SafeDownCast(_prop);
149    }
150
151    virtual vtkProp *getOverlayProp()
152    {
153        return NULL;
154    }
155
156    /**
157     * \brief Set an additional transform on the prop
158     *
159     * prop must be a vtkProp3D.  The transform is
160     * concatenated with the internal transform created
161     * by setting the prop position, orientation and scale
162     */
163    virtual void setTransform(vtkMatrix4x4 *matrix)
164    {
165        if (getProp3D() != NULL) {
166            getProp3D()->SetUserMatrix(matrix);
167        }
168    }
169
170    /**
171     * \brief Set the prop center of rotation
172     *
173     * \param[in] origin The point about which the object rotates
174     */
175    virtual void setOrigin(double origin[3])
176    {
177        if (getProp3D() != NULL) {
178            getProp3D()->SetOrigin(origin);
179        }
180    }
181
182    /**
183     * \brief Set the prop orientation with a quaternion
184     *
185     * \param[in] quat Quaternion with scalar part first
186     */
187    virtual void setOrientation(double quat[4])
188    {
189        if (getProp3D() != NULL) {
190            double angle = vtkMath::DegreesFromRadians(2.0 * acos(quat[0]));
191            double axis[3];
192            if (angle < 1.0e-6) {
193                axis[0] = 1;
194                axis[1] = 0;
195                axis[2] = 0;
196            } else {
197                double denom = sqrt(1. - quat[0] * quat[0]);
198                axis[0] = quat[1] / denom;
199                axis[1] = quat[2] / denom;
200                axis[2] = quat[3] / denom;
201            }
202            setOrientation(angle, axis);
203        }
204    }
205
206    /**
207     * \brief Set the prop orientation with a rotation about an axis
208     *
209     * \param[in] angle Angle in degrees
210     * \param[in] axis Axis of rotation
211     */
212    virtual void setOrientation(double angle, double axis[3])
213    {
214        if (getProp3D() != NULL) {
215            getProp3D()->SetOrientation(0, 0, 0);
216            getProp3D()->RotateWXYZ(angle, axis[0], axis[1], axis[2]);
217        }
218    }
219
220    /**
221     * \brief Set the prop position
222     *
223     * \param[in] pos Position in world coordinates
224     */
225    virtual void setPosition(double pos[3])
226    {
227        if (getProp3D() != NULL) {
228            getProp3D()->SetPosition(pos);
229        }
230    }
231
232    /**
233     * \brief Set 2D aspect ratio scaling
234     *
235     * \param aspect 0=no scaling, otherwise aspect
236     * is horiz/vertical ratio
237     */
238    virtual void setAspect(double aspect)
239    {
240        ;
241    }
242
243    /**
244     * \brief Set the prop scaling
245     *
246     * \param[in] scale Scaling in x,y,z
247     */
248    virtual void setScale(double scale[3])
249    {
250        if (getProp3D() != NULL) {
251            getProp3D()->SetScale(scale);
252        }
253    }
254
255    /**
256     * \brief Get the physical bounds of the prop
257     *
258     * If the prop is scaled, these bounds will be
259     * scaled as well
260     */
261    virtual double *getBounds()
262    {
263        if (getProp() != NULL)
264            return getProp()->GetBounds();
265        else
266            return NULL;
267    }
268
269    /**
270     * \brief Get the data bounds of the prop
271     *
272     * If the prop is scaled, these bounds will NOT
273     * be scaled, they will reflect the unscaled data
274     * bounds.
275     */
276    virtual double *getUnscaledBounds()
277    {
278        if (getProp3D() != NULL) {
279            double scale[3];
280            getProp3D()->GetScale(scale);
281            if (scale[0] == scale[1] && scale[1] == scale[2] &&
282                scale[0] == 1.0) {
283                return getBounds();
284            } else if (getBounds() != NULL) {
285                _unscaledBounds[0] = getBounds()[0] / scale[0];
286                _unscaledBounds[1] = getBounds()[1] / scale[0];
287                _unscaledBounds[2] = getBounds()[2] / scale[1];
288                _unscaledBounds[3] = getBounds()[3] / scale[1];
289                _unscaledBounds[4] = getBounds()[4] / scale[2];
290                _unscaledBounds[5] = getBounds()[5] / scale[2];
291                return _unscaledBounds;
292            }
293        }
294        return getBounds();
295    }
296
297    /**
298     * \brief Toggle visibility of the prop
299     */
300    virtual void setVisibility(bool state)
301    {
302        if (_prop != NULL)
303            _prop->SetVisibility((state ? 1 : 0));
304    }
305
306    /**
307     * \brief Get visibility state of the prop
308     */
309    virtual bool getVisibility()
310    {
311        if (_prop != NULL &&
312            _prop->GetVisibility() != 0) {
313            return true;
314        } else {
315            return false;
316        }
317    }
318
319    /**
320     * \brief Set the opacity of the object
321     *
322     * The prop must be a vtkActor or vtkAssembly
323     */
324    virtual void setOpacity(double opacity)
325    {
326        _opacity = opacity;
327        if (getActor() != NULL) {
328            getActor()->GetProperty()->SetOpacity(opacity);
329            if (_faceCulling && _opacity < 1.0) {
330                setCulling(getActor()->GetProperty(), false);
331                TRACE("Culling off");
332            } else if (_faceCulling && _opacity == 1.0) {
333                setCulling(getActor()->GetProperty(), true);
334                TRACE("Culling on");
335            }
336        } else if (getAssembly() != NULL) {
337            vtkProp3DCollection *props = getAssembly()->GetParts();
338            vtkProp3D *prop;
339            props->InitTraversal();
340            while ((prop = props->GetNextProp3D()) != NULL) {
341                if (vtkActor::SafeDownCast(prop) != NULL) {
342                    vtkActor::SafeDownCast(prop)->GetProperty()->SetOpacity(opacity);
343                    if (_faceCulling && _opacity < 1.0) {
344                        setCulling(vtkActor::SafeDownCast(prop)->GetProperty(), false);
345                        TRACE("Culling off");
346                    } else if (_faceCulling && _opacity == 1.0) {
347                        setCulling(vtkActor::SafeDownCast(prop)->GetProperty(), true);
348                        TRACE("Culling on");
349                    }
350                }
351            }
352        }
353    }
354
355    /**
356     * \brief Get the opacity of the object
357     */
358    inline double getOpacity()
359    {
360        return _opacity;
361    }
362
363    /**
364     * \brief Set the ambient material coefficient
365     */
366    virtual void setAmbient(double ambient)
367    {
368        if (getActor() != NULL) {
369            getActor()->GetProperty()->SetAmbient(ambient);
370        } else if (getVolume() != NULL) {
371            getVolume()->GetProperty()->SetAmbient(ambient);
372        } else if (getAssembly() != NULL) {
373            vtkProp3DCollection *props = getAssembly()->GetParts();
374            vtkProp3D *prop;
375            props->InitTraversal();
376            while ((prop = props->GetNextProp3D()) != NULL) {
377                if (vtkActor::SafeDownCast(prop) != NULL) {
378                    vtkActor::SafeDownCast(prop)->GetProperty()->SetAmbient(ambient);
379                } else if (vtkVolume::SafeDownCast(prop) != NULL) {
380                    vtkVolume::SafeDownCast(prop)->GetProperty()->SetAmbient(ambient);
381                }
382            }
383        }
384    }
385
386    /**
387     * \brief Set the diffuse material coefficient
388     */
389    virtual void setDiffuse(double diffuse)
390    {
391        if (getActor() != NULL) {
392            getActor()->GetProperty()->SetDiffuse(diffuse);
393        } else if (getVolume() != NULL) {
394            getVolume()->GetProperty()->SetDiffuse(diffuse);
395        } else if (getAssembly() != NULL) {
396            vtkProp3DCollection *props = getAssembly()->GetParts();
397            vtkProp3D *prop;
398            props->InitTraversal();
399            while ((prop = props->GetNextProp3D()) != NULL) {
400                if (vtkActor::SafeDownCast(prop) != NULL) {
401                    vtkActor::SafeDownCast(prop)->GetProperty()->SetDiffuse(diffuse);
402                } else if (vtkVolume::SafeDownCast(prop) != NULL) {
403                    vtkVolume::SafeDownCast(prop)->GetProperty()->SetDiffuse(diffuse);
404                }
405            }
406        }
407    }
408
409    /**
410     * \brief Set the specular material coefficient and power
411     */
412    virtual void setSpecular(double coeff, double power)
413    {
414        if (getActor() != NULL) {
415            getActor()->GetProperty()->SetSpecular(coeff);
416            getActor()->GetProperty()->SetSpecularPower(power);
417        } else if (getVolume() != NULL) {
418            getVolume()->GetProperty()->SetSpecular(coeff);
419            getVolume()->GetProperty()->SetSpecularPower(power);
420        } else if (getAssembly() != NULL) {
421            vtkProp3DCollection *props = getAssembly()->GetParts();
422            vtkProp3D *prop;
423            props->InitTraversal();
424            while ((prop = props->GetNextProp3D()) != NULL) {
425                if (vtkActor::SafeDownCast(prop) != NULL) {
426                    vtkActor::SafeDownCast(prop)->GetProperty()->SetSpecular(coeff);
427                    vtkActor::SafeDownCast(prop)->GetProperty()->SetSpecularPower(power);
428                } else if (vtkVolume::SafeDownCast(prop) != NULL) {
429                    vtkVolume::SafeDownCast(prop)->GetProperty()->SetSpecular(coeff);
430                    vtkVolume::SafeDownCast(prop)->GetProperty()->SetSpecularPower(power);
431                }
432            }
433        }
434    }
435
436    /**
437     * \brief Set material properties (coefficients and specular power) of object
438     */
439    virtual void setMaterial(double ambient, double diffuse, double specular, double specPower)
440    {
441        if (getActor() != NULL) {
442            vtkProperty *property = getActor()->GetProperty();
443            property->SetAmbient(ambient);
444            property->SetDiffuse(diffuse);
445            property->SetSpecular(specular);
446            property->SetSpecularPower(specPower);
447        } else if (getVolume() != NULL) {
448            vtkVolumeProperty *property = getVolume()->GetProperty();
449            property->SetAmbient(ambient);
450            property->SetDiffuse(diffuse);
451            property->SetSpecular(specular);
452            property->SetSpecularPower(specPower);
453        } else if (getAssembly() != NULL) {
454            vtkProp3DCollection *props = getAssembly()->GetParts();
455            vtkProp3D *prop;
456            props->InitTraversal();
457            while ((prop = props->GetNextProp3D()) != NULL) {
458                if (vtkActor::SafeDownCast(prop) != NULL) {
459                    vtkProperty *property = vtkActor::SafeDownCast(prop)->GetProperty();
460                    property->SetAmbient(ambient);
461                    property->SetDiffuse(diffuse);
462                    property->SetSpecular(specular);
463                    property->SetSpecularPower(specPower);
464                } else if (vtkVolume::SafeDownCast(prop) != NULL) {
465                    vtkVolumeProperty *property = vtkVolume::SafeDownCast(prop)->GetProperty();
466                    property->SetAmbient(ambient);
467                    property->SetDiffuse(diffuse);
468                    property->SetSpecular(specular);
469                    property->SetSpecularPower(specPower);
470                }
471            }
472        }
473    }
474
475    /**
476     * \brief Set the material color (sets ambient, diffuse, and specular)
477     */
478    virtual void setColor(float color[3])
479    {
480        for (int i = 0; i < 3; i++)
481            _color[i] = color[i];
482        if (getActor() != NULL) {
483            getActor()->GetProperty()->SetColor(color[0], color[1], color[2]);
484        } else if (getAssembly() != NULL) {
485            vtkProp3DCollection *props = getAssembly()->GetParts();
486            vtkProp3D *prop;
487            props->InitTraversal();
488            while ((prop = props->GetNextProp3D()) != NULL) {
489                if (vtkActor::SafeDownCast(prop) != NULL) {
490                    vtkActor::SafeDownCast(prop)->GetProperty()->SetColor(color[0], color[1], color[2]);
491                }
492            }
493        }
494    }
495
496    /**
497     * \brief Set the material ambient color
498     */
499    virtual void setAmbientColor(float color[3])
500    {
501        if (getActor() != NULL) {
502            getActor()->GetProperty()->SetAmbientColor(color[0], color[1], color[2]);
503        } else if (getAssembly() != NULL) {
504            vtkProp3DCollection *props = getAssembly()->GetParts();
505            vtkProp3D *prop;
506            props->InitTraversal();
507            while ((prop = props->GetNextProp3D()) != NULL) {
508                if (vtkActor::SafeDownCast(prop) != NULL) {
509                    vtkActor::SafeDownCast(prop)->GetProperty()->SetAmbientColor(color[0], color[1], color[2]);
510                }
511            }
512        }
513    }
514
515    /**
516     * \brief Set the material diffuse color
517     */
518    virtual void setDiffuseColor(float color[3])
519    {
520        if (getActor() != NULL) {
521            getActor()->GetProperty()->SetDiffuseColor(color[0], color[1], color[2]);
522        } else if (getAssembly() != NULL) {
523            vtkProp3DCollection *props = getAssembly()->GetParts();
524            vtkProp3D *prop;
525            props->InitTraversal();
526            while ((prop = props->GetNextProp3D()) != NULL) {
527                if (vtkActor::SafeDownCast(prop) != NULL) {
528                    vtkActor::SafeDownCast(prop)->GetProperty()->SetDiffuseColor(color[0], color[1], color[2]);
529                }
530            }
531        }
532    }
533
534    /**
535     * \brief Set the material specular color
536     */
537    virtual void setSpecularColor(float color[3])
538    {
539        if (getActor() != NULL) {
540            getActor()->GetProperty()->SetSpecularColor(color[0], color[1], color[2]);
541        } else if (getAssembly() != NULL) {
542            vtkProp3DCollection *props = getAssembly()->GetParts();
543            vtkProp3D *prop;
544            props->InitTraversal();
545            while ((prop = props->GetNextProp3D()) != NULL) {
546                if (vtkActor::SafeDownCast(prop) != NULL) {
547                    vtkActor::SafeDownCast(prop)->GetProperty()->SetSpecularColor(color[0], color[1], color[2]);
548                }
549            }
550        }
551    }
552
553    /**
554     * \brief Toggle lighting of the prop
555     */
556    virtual void setLighting(bool state)
557    {
558        _lighting = state;
559        if (getActor() != NULL) {
560            getActor()->GetProperty()->SetLighting((state ? 1 : 0));
561        } else if (getVolume() != NULL) {
562            getVolume()->GetProperty()->SetShade((state ? 1 : 0));
563         } else if (getAssembly() != NULL) {
564            vtkProp3DCollection *props = getAssembly()->GetParts();
565            vtkProp3D *prop;
566            props->InitTraversal();
567            while ((prop = props->GetNextProp3D()) != NULL) {
568                if (vtkActor::SafeDownCast(prop) != NULL) {
569                    vtkActor::SafeDownCast(prop)->GetProperty()->SetLighting((state ? 1 : 0));
570                } else if (vtkVolume::SafeDownCast(prop) != NULL) {
571                    vtkVolume::SafeDownCast(prop)->GetProperty()->SetShade((state ? 1 : 0));
572                }
573            }
574        }
575    }
576
577    /**
578     * \brief Toggle drawing of edges
579     */
580    virtual void setEdgeVisibility(bool state)
581    {
582        if (getActor() != NULL) {
583            getActor()->GetProperty()->SetEdgeVisibility((state ? 1 : 0));
584        } else if (getAssembly() != NULL) {
585            vtkProp3DCollection *props = getAssembly()->GetParts();
586            vtkProp3D *prop;
587            props->InitTraversal();
588            while ((prop = props->GetNextProp3D()) != NULL) {
589                if (vtkActor::SafeDownCast(prop) != NULL) {
590                    vtkActor::SafeDownCast(prop)->GetProperty()->SetEdgeVisibility((state ? 1 : 0));
591                }
592            }
593        }
594    }
595
596    /**
597     * \brief Set color of edges
598     */
599    virtual void setEdgeColor(float color[3])
600    {
601        for (int i = 0; i < 3; i++)
602            _edgeColor[i] = color[i];
603        if (getActor() != NULL) {
604            getActor()->GetProperty()->SetEdgeColor(color[0], color[1], color[2]);
605        } else if (getAssembly() != NULL) {
606            vtkProp3DCollection *props = getAssembly()->GetParts();
607            vtkProp3D *prop;
608            props->InitTraversal();
609            while ((prop = props->GetNextProp3D()) != NULL) {
610                if (vtkActor::SafeDownCast(prop) != NULL) {
611                    vtkActor::SafeDownCast(prop)->GetProperty()->SetEdgeColor(color[0], color[1], color[2]);
612                }
613            }
614        }
615    }
616
617    /**
618     * \brief Set pixel width of edges
619     *
620     * NOTE: May be a no-op if OpenGL implementation doesn't support wide lines
621     */
622    virtual void setEdgeWidth(float width)
623    {
624        _edgeWidth = width;
625        if (getActor() != NULL) {
626            getActor()->GetProperty()->SetLineWidth(width);
627        } else if (getAssembly() != NULL) {
628            vtkProp3DCollection *props = getAssembly()->GetParts();
629            vtkProp3D *prop;
630            props->InitTraversal();
631            while ((prop = props->GetNextProp3D()) != NULL) {
632                if (vtkActor::SafeDownCast(prop) != NULL) {
633                    vtkActor::SafeDownCast(prop)->GetProperty()->SetLineWidth(width);
634                }
635            }
636        }
637    }
638
639    /**
640     * \brief Set point size
641     *
642     * NOTE: May be a no-op if OpenGL implementation doesn't support wide points
643     */
644    virtual void setPointSize(float size)
645    {
646        _pointSize = size;
647        if (getActor() != NULL) {
648            getActor()->GetProperty()->SetPointSize(size);
649        } else if (getAssembly() != NULL) {
650            vtkProp3DCollection *props = getAssembly()->GetParts();
651            vtkProp3D *prop;
652            props->InitTraversal();
653            while ((prop = props->GetNextProp3D()) != NULL) {
654                if (vtkActor::SafeDownCast(prop) != NULL) {
655                    vtkActor::SafeDownCast(prop)->GetProperty()->SetPointSize(size);
656                }
657            }
658        }
659    }
660
661    /**
662     * \brief Toggle wireframe rendering of prop
663     */
664    virtual void setWireframe(bool state)
665    {
666        if (getActor() != NULL) {
667            if (state) {
668                getActor()->GetProperty()->SetRepresentationToWireframe();
669                getActor()->GetProperty()->LightingOff();
670            } else {
671                getActor()->GetProperty()->SetRepresentationToSurface();
672                setLighting(_lighting);
673            }
674        } else if (getAssembly() != NULL) {
675            vtkProp3DCollection *props = getAssembly()->GetParts();
676            vtkProp3D *prop;
677            props->InitTraversal();
678            while ((prop = props->GetNextProp3D()) != NULL) {
679                if (vtkActor::SafeDownCast(prop) != NULL) {
680                    if (state) {
681                        vtkActor::SafeDownCast(prop)->GetProperty()->SetRepresentationToWireframe();
682                        vtkActor::SafeDownCast(prop)->GetProperty()->LightingOff();
683                    } else {
684                        vtkActor::SafeDownCast(prop)->GetProperty()->SetRepresentationToSurface();
685                        vtkActor::SafeDownCast(prop)->GetProperty()->SetLighting((_lighting ? 1 : 0));
686                    }
687                }
688            }
689        }
690    }
691
692    /**
693     * \brief Toggle culling of selected CullFace
694     */
695    virtual void setCulling(bool state)
696    {
697        _faceCulling = state;
698        if (state && _opacity < 1.0)
699            return;
700        if (getActor() != NULL) {
701            setCulling(getActor()->GetProperty(), state);
702        } else if (getAssembly() != NULL) {
703            vtkProp3DCollection *props = getAssembly()->GetParts();
704            vtkProp3D *prop;
705            props->InitTraversal();
706            while ((prop = props->GetNextProp3D()) != NULL) {
707                if (vtkActor::SafeDownCast(prop) != NULL) {
708                    setCulling(vtkActor::SafeDownCast(prop)->GetProperty(), state);
709                }
710            }
711        }
712    }
713
714    /**
715     * \brief Specify which face(s) to cull when culling is enabled
716     */
717    virtual void setCullFace(CullFace cull)
718    {
719        _cullFace = cull;
720        setCulling(_faceCulling);
721    }
722
723    /**
724     * \brief Subclasses need to implement setting clipping planes in their mappers
725     */
726    virtual void setClippingPlanes(vtkPlaneCollection *planes) = 0;
727
728protected:
729    /**
730     * \brief Create and initialize a VTK Prop to render the object
731     */
732    virtual void initProp()
733    {
734        if (_prop == NULL) {
735            _prop = vtkSmartPointer<vtkActor>::New();
736            vtkProperty *property = getActor()->GetProperty();
737            property->SetColor(_color[0], _color[1], _color[2]);
738            property->SetEdgeColor(_edgeColor[0], _edgeColor[1], _edgeColor[2]);
739            property->SetLineWidth(_edgeWidth);
740            property->SetPointSize(_pointSize);
741            property->EdgeVisibilityOff();
742            if (_dataSet != NULL)
743                _opacity = _dataSet->getOpacity();
744            property->SetOpacity(_opacity);
745            property->SetAmbient(.2);
746            if (!_lighting)
747                property->LightingOff();
748            if (_faceCulling && _opacity == 1.0) {
749                setCulling(property, true);
750            }
751            if (_dataSet != NULL)
752                setVisibility(_dataSet->getVisibility());
753        }
754    }
755
756    /**
757     * \brief Subclasses implement this to create the VTK pipeline
758     * on a state change (e.g. new DataSet)
759     */
760    virtual void update() = 0;
761
762    /**
763     * \brief Convenience method to set culling state on a vtkProperty
764     *
765     * Note: Does not change the culling state flag of this VtkGraphicsObject
766     */
767    virtual void setCulling(vtkProperty *property, bool state)
768    {
769        switch (_cullFace) {
770        case CULL_FRONT:
771            property->SetFrontfaceCulling((state ? 1 : 0));
772            property->BackfaceCullingOff();
773            break;
774        case CULL_BACK:
775            property->SetBackfaceCulling((state ? 1 : 0));
776            property->FrontfaceCullingOff();
777            break;
778        case CULL_FRONT_AND_BACK:
779            property->SetBackfaceCulling((state ? 1 : 0));
780            property->SetFrontfaceCulling((state ? 1 : 0));
781            break;
782        }
783    }
784
785    DataSet *_dataSet;
786    double _dataRange[2];
787    double _unscaledBounds[6];
788    double _opacity;
789    float _color[3];
790    float _edgeColor[3];
791    float _edgeWidth;
792    float _pointSize;
793    bool _lighting;
794    CullFace _cullFace;
795    bool _faceCulling;
796
797    vtkSmartPointer<vtkProp> _prop;
798};
799
800}
801}
802
803#endif
Note: See TracBrowser for help on using the repository browser.