1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkProp.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkProp - abstract superclass for all actors, volumes and annotations
16 // .SECTION Description
17 // vtkProp is an abstract superclass for any objects that can exist in a
18 // rendered scene (either 2D or 3D). Instances of vtkProp may respond to
19 // various render methods (e.g., RenderOpaqueGeometry()). vtkProp also
20 // defines the API for picking, LOD manipulation, and common instance
21 // variables that control visibility, picking, and dragging.
22 // .SECTION See Also
23 // vtkActor2D vtkActor vtkVolume vtkProp3D
24 
25 #ifndef vtkProp_h
26 #define vtkProp_h
27 
28 #include "vtkRenderingCoreModule.h" // For export macro
29 #include "vtkObject.h"
30 
31 class vtkAssemblyPath;
32 class vtkAssemblyPaths;
33 class vtkMatrix4x4;
34 class vtkPropCollection;
35 class vtkViewport;
36 class vtkWindow;
37 class vtkInformation;
38 class vtkInformationIntegerKey;
39 class vtkInformationDoubleVectorKey;
40 
41 class VTKRENDERINGCORE_EXPORT vtkProp : public vtkObject
42 {
43 public:
44   vtkTypeMacro(vtkProp, vtkObject);
45   void PrintSelf(ostream& os, vtkIndent indent);
46 
47   // Description:
48   // For some exporters and other other operations we must be
49   // able to collect all the actors or volumes. These methods
50   // are used in that process.
GetActors(vtkPropCollection *)51   virtual void GetActors(vtkPropCollection *) {}
GetActors2D(vtkPropCollection *)52   virtual void GetActors2D(vtkPropCollection *) {}
GetVolumes(vtkPropCollection *)53   virtual void GetVolumes(vtkPropCollection *) {}
54 
55   // Description:
56   // Set/Get visibility of this vtkProp. Initial value is true.
57   vtkSetMacro(Visibility, int);
58   vtkGetMacro(Visibility, int);
59   vtkBooleanMacro(Visibility, int);
60 
61   // Description:
62   // Set/Get the pickable instance variable.  This determines if the vtkProp
63   // can be picked (typically using the mouse). Also see dragable.
64   // Initial value is true.
65   vtkSetMacro(Pickable, int);
66   vtkGetMacro(Pickable, int);
67   vtkBooleanMacro(Pickable, int);
68 
69   // Description:
70   // Method fires PickEvent if the prop is picked.
71   virtual void Pick();
72 
73   // Description:
74   // Set/Get the value of the dragable instance variable. This determines if
75   // an Prop, once picked, can be dragged (translated) through space.
76   // This is typically done through an interactive mouse interface.
77   // This does not affect methods such as SetPosition, which will continue
78   // to work.  It is just intended to prevent some vtkProp'ss from being
79   // dragged from within a user interface.
80   // Initial value is true.
81   vtkSetMacro(Dragable, int);
82   vtkGetMacro(Dragable, int);
83   vtkBooleanMacro(Dragable, int);
84 
85   // Description:
86   // Return the mtime of anything that would cause the rendered image to
87   // appear differently. Usually this involves checking the mtime of the
88   // prop plus anything else it depends on such as properties, textures
89   // etc.
GetRedrawMTime()90   virtual unsigned long GetRedrawMTime()
91     { return this->GetMTime(); }
92 
93   // Description:
94   // In case the Visibility flag is true, tell if the bounds of this prop
95   // should be taken into account or ignored during the computation of other
96   // bounding boxes, like in vtkRenderer::ResetCamera().
97   // Initial value is true.
98   vtkSetMacro(UseBounds, bool);
99   vtkGetMacro(UseBounds, bool);
100   vtkBooleanMacro(UseBounds, bool);
101 
102   // Description:
103   // Get the bounds for this Prop as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
104   // in world coordinates. NULL means that the bounds are not defined.
GetBounds()105   virtual double *GetBounds()
106     { return NULL; }
107 
108   // Description:
109   // Shallow copy of this vtkProp.
110   virtual void ShallowCopy(vtkProp *prop);
111 
112   // Description:
113   // vtkProp and its subclasses can be picked by subclasses of
114   // vtkAbstractPicker (e.g., vtkPropPicker). The following methods interface
115   // with the picking classes and return "pick paths". A pick path is a
116   // hierarchical, ordered list of props that form an assembly.  Most often,
117   // when a vtkProp is picked, its path consists of a single node (i.e., the
118   // prop). However, classes like vtkAssembly and vtkPropAssembly can return
119   // more than one path, each path being several layers deep. (See
120   // vtkAssemblyPath for more information.)  To use these methods - first
121   // invoke InitPathTraversal() followed by repeated calls to GetNextPath().
122   // GetNextPath() returns a NULL pointer when the list is exhausted.
123   virtual void InitPathTraversal();
124   virtual vtkAssemblyPath *GetNextPath();
GetNumberOfPaths()125   virtual int GetNumberOfPaths()
126     { return 1; }
127 
128   // Description:
129   // These methods are used by subclasses to place a matrix (if any) in the
130   // prop prior to rendering. Generally used only for picking. See vtkProp3D
131   // for more information.
PokeMatrix(vtkMatrix4x4 * vtkNotUsed (matrix))132   virtual void PokeMatrix(vtkMatrix4x4 *vtkNotUsed(matrix)) {}
GetMatrix()133   virtual vtkMatrix4x4 *GetMatrix()
134     { return NULL; }
135 
136   // Description:
137   // Set/Get property keys. Property keys can be digest by some rendering
138   // passes.
139   // For instance, the user may mark a prop as a shadow caster for a
140   // shadow mapping render pass. Keys are documented in render pass classes.
141   // Initial value is NULL.
142   vtkGetObjectMacro(PropertyKeys,vtkInformation);
143   virtual void SetPropertyKeys(vtkInformation *keys);
144 
145   // Description:
146   // Tells if the prop has all the required keys.
147   // \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
148   virtual bool HasKeys(vtkInformation *requiredKeys);
149 
150   // Description:
151   // Props may provide a mapping from picked value to actual value
152   // This is useful for hardware based pickers where
153   // there is a mapping between the color in the buffer
154   // and the actual pick value
GetConvertedPickValue(vtkIdType idIn,int vtkNotUsed (fieldassociation))155   virtual vtkIdType GetConvertedPickValue(vtkIdType idIn,
156       int vtkNotUsed(fieldassociation)) { return idIn; }
157 
158   // Description:
159   // Optional Key Indicating the texture unit for general texture mapping
160   // Old OpenGL was a state machine where you would push or pop
161   // items. The new OpenGL design is more mapper centric. Some
162   // classes push a texture and then assume a mapper will use it.
163   // The new design wants explicit comunication of when a texture
164   // is being used.  This key can be used to pass that information
165   // down to a mapper.
166   static vtkInformationIntegerKey *GeneralTextureUnit();
167 
168   // Description:
169   // Optional Key Indicating the texture transform for general texture mapping
170   // Old OpenGL was a state machine where you would push or pop
171   // items. The new OpenGL design is more mapper centric. Some
172   // classes push a texture and then assume a mapper will use it.
173   // The new design wants explicit comunication of when a texture
174   // is being used.  This key can be used to pass that information
175   // down to a mapper.
176   static vtkInformationDoubleVectorKey *GeneralTextureTransform();
177 
178 //BTX
179   // Description:
180   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
181   // DO NOT USE THESE METHODS OUTSIDE OF THE RENDERING PROCESS
182   // All concrete subclasses must be able to render themselves.
183   // There are four key render methods in vtk and they correspond
184   // to four different points in the rendering cycle. Any given
185   // prop may implement one or more of these methods.
186   // The first method is intended for rendering all opaque geometry. The
187   // second method is intended for rendering all translucent polygonal
188   // geometry. The third one is intended for rendering all translucent
189   // volumetric geometry. Most of the volume rendering mappers draw their
190   // results during this third method.
191   // The last method is to render any 2D annotation or overlays.
192   // Each of these methods return an integer value indicating
193   // whether or not this render method was applied to this data.
RenderOpaqueGeometry(vtkViewport *)194   virtual int RenderOpaqueGeometry(vtkViewport *)
195     { return 0; }
RenderTranslucentPolygonalGeometry(vtkViewport *)196   virtual int RenderTranslucentPolygonalGeometry(vtkViewport *)
197     { return 0; }
RenderVolumetricGeometry(vtkViewport *)198   virtual int RenderVolumetricGeometry(vtkViewport *)
199     { return 0; }
RenderOverlay(vtkViewport *)200   virtual int RenderOverlay(vtkViewport *)
201     { return 0; }
202 
203   // Description:
204   // Render the opaque geometry only if the prop has all the requiredKeys.
205   // This is recursive for composite props like vtkAssembly.
206   // An implementation is provided in vtkProp but each composite prop
207   // must override it.
208   // It returns if the rendering was performed.
209   // \pre v_exists: v!=0
210   // \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
211   virtual bool RenderFilteredOpaqueGeometry(vtkViewport *v,
212                                             vtkInformation *requiredKeys);
213 
214   // Description:
215   // Render the translucent polygonal geometry only if the prop has all the
216   // requiredKeys.
217   // This is recursive for composite props like vtkAssembly.
218   // An implementation is provided in vtkProp but each composite prop
219   // must override it.
220   // It returns if the rendering was performed.
221   // \pre v_exists: v!=0
222   // \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
223   virtual bool RenderFilteredTranslucentPolygonalGeometry(
224     vtkViewport *v,
225     vtkInformation *requiredKeys);
226 
227   // Description:
228   // Render the volumetric geometry only if the prop has all the
229   // requiredKeys.
230   // This is recursive for composite props like vtkAssembly.
231   // An implementation is provided in vtkProp but each composite prop
232   // must override it.
233   // It returns if the rendering was performed.
234   // \pre v_exists: v!=0
235   // \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
236   virtual bool RenderFilteredVolumetricGeometry(vtkViewport *v,
237                                                 vtkInformation *requiredKeys);
238 
239   // Description:
240   // Render in the overlay of the viewport only if the prop has all the
241   // requiredKeys.
242   // This is recursive for composite props like vtkAssembly.
243   // An implementation is provided in vtkProp but each composite prop
244   // must override it.
245   // It returns if the rendering was performed.
246   // \pre v_exists: v!=0
247   // \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
248   virtual bool RenderFilteredOverlay(vtkViewport *v,
249                                      vtkInformation *requiredKeys);
250 
251   // Description:
252   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
253   // DO NOT USE THESE METHODS OUTSIDE OF THE RENDERING PROCESS
254   // Does this prop have some translucent polygonal geometry?
255   // This method is called during the rendering process to know if there is
256   // some translucent polygonal geometry. A simple prop that has some
257   // translucent polygonal geometry will return true. A composite prop (like
258   // vtkAssembly) that has at least one sub-prop that has some translucent
259   // polygonal geometry will return true.
260   // Default implementation return false.
HasTranslucentPolygonalGeometry()261   virtual int HasTranslucentPolygonalGeometry()
262     { return 0; }
263 
264   // Description:
265   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
266   // Release any graphics resources that are being consumed by this actor.
267   // The parameter window could be used to determine which graphic
268   // resources to release.
ReleaseGraphicsResources(vtkWindow *)269   virtual void ReleaseGraphicsResources(vtkWindow *) {}
270 
271   // Description:
272   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
273   // DO NOT USE THESE METHODS OUTSIDE OF THE RENDERING PROCESS
274   // The EstimatedRenderTime may be used to select between different props,
275   // for example in LODProp it is used to select the level-of-detail.
276   // The value is returned in seconds. For simple geometry the accuracy may
277   // not be great due to buffering. For ray casting, which is already
278   // multi-resolution, the current resolution of the image is factored into
279   // the time. We need the viewport for viewing parameters that affect timing.
280   // The no-arguments version simply returns the value of the variable with
281   // no estimation.
GetEstimatedRenderTime(vtkViewport *)282   virtual double GetEstimatedRenderTime( vtkViewport * )
283     { return this->EstimatedRenderTime; }
GetEstimatedRenderTime()284   virtual double GetEstimatedRenderTime()
285     { return this->EstimatedRenderTime; }
286 
287   // Description:
288   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
289   // DO NOT USE THESE METHODS OUTSIDE OF THE RENDERING PROCESS
290   // This method is used by, for example, the vtkLODProp3D in order to
291   // initialize the estimated render time at start-up to some user defined
292   // value.
SetEstimatedRenderTime(double t)293   virtual void SetEstimatedRenderTime(double t)
294     { this->EstimatedRenderTime = t; this->SavedEstimatedRenderTime = t; }
295 
296   // Description:
297   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
298   // DO NOT USE THESE METHODS OUTSIDE OF THE RENDERING PROCESS
299   // When the EstimatedRenderTime is first set to 0.0 (in the
300   // SetAllocatedRenderTime method) the old value is saved. This
301   // method is used to restore that old value should the render be
302   // aborted.
RestoreEstimatedRenderTime()303   virtual void RestoreEstimatedRenderTime()
304     { this->EstimatedRenderTime = this->SavedEstimatedRenderTime; }
305 
306 
307   // Description:
308   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
309   // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
310   // This method is intended to allow the renderer to add to the
311   // EstimatedRenderTime in props that require information that
312   // the renderer has in order to do this. For example, props
313   // that are rendered with a ray casting method do not know
314   // themselves how long it took for them to render. We don't want to
315   // cause a this->Modified() when we set this value since it is not
316   // really a modification to the object. (For example, we don't want
317   // to rebuild matrices at every render because the estimated render time
318   // is changing)
AddEstimatedRenderTime(double t,vtkViewport * vtkNotUsed (vp))319   virtual void AddEstimatedRenderTime(double t, vtkViewport *vtkNotUsed(vp))
320     { this->EstimatedRenderTime += t; }
321 
322   // Description:
323   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
324   // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
325   // The renderer may use the allocated rendering time to determine
326   // how to render this actor. Therefore it might need the information
327   // provided in the viewport.
328   // A side effect of this method is to reset the EstimatedRenderTime to
329   // 0.0. This way, each of the ways that this prop may be rendered can
330   // be timed and added together into this value.
SetAllocatedRenderTime(double t,vtkViewport * vtkNotUsed (v))331   virtual void SetAllocatedRenderTime(double t, vtkViewport *vtkNotUsed(v))
332     {
333     this->AllocatedRenderTime = t;
334     this->SavedEstimatedRenderTime = this->EstimatedRenderTime;
335     this->EstimatedRenderTime = 0.0;
336     }
337 
338   // Description:
339   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
340   // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
341   vtkGetMacro(AllocatedRenderTime, double);
342 
343   // Description:
344   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
345   // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
346   // Get/Set the multiplier for the render time. This is used
347   // for culling and is a number between 0 and 1. It is used
348   // to create the allocated render time value.
SetRenderTimeMultiplier(double t)349   void SetRenderTimeMultiplier( double t )
350     { this->RenderTimeMultiplier = t; }
351   vtkGetMacro(RenderTimeMultiplier, double);
352 
353   // Description:
354   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
355   // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
356   // Used to construct assembly paths and perform part traversal.
357   virtual void BuildPaths(vtkAssemblyPaths *paths, vtkAssemblyPath *path);
358 
359   // Description:
360   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
361   // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
362   // Used by vtkHardwareSelector to determine if the prop supports hardware
363   // selection.
GetSupportsSelection()364   virtual bool GetSupportsSelection()
365     { return false; }
366 
367   // Description:
368   // Get the number of consumers
369   vtkGetMacro(NumberOfConsumers,int);
370 
371   // Description:
372   // Add or remove or get or check a consumer,
373   void AddConsumer(vtkObject *c);
374   void RemoveConsumer(vtkObject *c);
375   vtkObject *GetConsumer(int i);
376   int IsConsumer(vtkObject *c);
377 
378 //ETX
379 
380 protected:
381   vtkProp();
382   ~vtkProp();
383 
384   int Visibility;
385   int Pickable;
386   int Dragable;
387   bool UseBounds;
388 
389   double AllocatedRenderTime;
390   double EstimatedRenderTime;
391   double SavedEstimatedRenderTime;
392   double RenderTimeMultiplier;
393 
394   // how many consumers does this object have
395   int NumberOfConsumers;
396   vtkObject **Consumers;
397 
398   // support multi-part props and access to paths of prop
399   // stuff that follows is used to build the assembly hierarchy
400   vtkAssemblyPaths *Paths;
401 
402   vtkInformation *PropertyKeys;
403 
404 private:
405   vtkProp(const vtkProp&);  // Not implemented.
406   void operator=(const vtkProp&);  // Not implemented.
407 };
408 
409 #endif
410