1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkAMRVolumeMapper.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 vtkAMRVolumeMapper - AMR class for a volume mapper
16 
17 // .SECTION Description
18 // vtkAMRVolumeMapper is the  definition of a volume mapper.
19 // for AMR Structured Data
20 
21 // .SECTION see also
22 //
23 
24 #ifndef vtkAMRVolumeMapper_h
25 #define vtkAMRVolumeMapper_h
26 
27 #include "vtkRenderingVolumeAMRModule.h" // For export macro
28 #include "vtkVolumeMapper.h"
29 #include "vtkImageReslice.h" // for VTK_RESLICE_NEAREST, VTK_RESLICE_CUBIC
30 
31 class vtkAMRResampleFilter;
32 class vtkCamera;
33 class vtkImageData;
34 class vtkOverlappingAMR;
35 class vtkSmartVolumeMapper;
36 class vtkUniformGrid;
37 
38 class VTKRENDERINGVOLUMEAMR_EXPORT vtkAMRVolumeMapper : public vtkVolumeMapper
39 {
40 public:
41   static vtkAMRVolumeMapper *New();
42   vtkTypeMacro(vtkAMRVolumeMapper,vtkVolumeMapper);
43   void PrintSelf( ostream& os, vtkIndent indent );
44 
45   // Description:
46   // Set the input data
47   virtual void SetInputData( vtkImageData* );
48   virtual void SetInputData( vtkDataSet* );
49   virtual void SetInputData( vtkOverlappingAMR* );
50   virtual void SetInputConnection (int port, vtkAlgorithmOutput *input);
SetInputConnection(vtkAlgorithmOutput * input)51   virtual void SetInputConnection (vtkAlgorithmOutput *input)
52   {this->SetInputConnection(0, input);}
53 
54   // Description:
55   // Return bounding box (array of six doubles) of data expressed as
56   // (xmin,xmax, ymin,ymax, zmin,zmax).
57   virtual double *GetBounds();
GetBounds(double bounds[6])58   virtual void GetBounds(double bounds[6])
59     {this->vtkVolumeMapper::GetBounds(bounds); };
60 
61   // Description:
62   // Control how the mapper works with scalar point data and cell attribute
63   // data.  By default (ScalarModeToDefault), the mapper will use point data,
64   // and if no point data is available, then cell data is used. Alternatively
65   // you can explicitly set the mapper to use point data
66   // (ScalarModeToUsePointData) or cell data (ScalarModeToUseCellData).
67   // You can also choose to get the scalars from an array in point field
68   // data (ScalarModeToUsePointFieldData) or cell field data
69   // (ScalarModeToUseCellFieldData).  If scalars are coming from a field
70   // data array, you must call SelectScalarArray.
71   virtual void SetScalarMode(int mode);
72 
73   // Description:
74   // Set/Get the blend mode. Currently this is only supported
75   // by the vtkFixedPointVolumeRayCastMapper - other mappers
76   // have different ways to set this (supplying a function
77   // to a vtkVolumeRayCastMapper) or don't have any options
78   // (vtkVolumeTextureMapper2D supports only compositing).
79   // Additive blend mode adds scalars along the ray and multiply them by
80   // their opacity mapping value.
81   virtual void SetBlendMode(int mode);
82   virtual int GetBlendMode();
83 
84   // Description:
85   // When ScalarMode is set to UsePointFieldData or UseCellFieldData,
86   // you can specify which scalar array to use during rendering.
87   // The transfer function in the vtkVolumeProperty (attached to the calling
88   // vtkVolume) will decide how to convert vectors to colors.
89   virtual void SelectScalarArray(int arrayNum);
90   virtual void SelectScalarArray(const char* arrayName);
91 
92   // Description:
93   // Get the array name or number and component to use for rendering.
94   virtual char* GetArrayName();
95   virtual int GetArrayId();
96   virtual int GetArrayAccessMode();
97 
98   // Description:
99   // Return the method for obtaining scalar data.
100   const char *GetScalarModeAsString();
101   // Description:
102   // Turn On/Off orthogonal cropping. (Clipping planes are
103   // perpendicular to the coordinate axes.)
104   virtual void SetCropping(int mode);
105   virtual int GetCropping();
106 
107   // Description:
108   // Set/Get the Cropping Region Planes ( xmin, xmax, ymin, ymax, zmin, zmax )
109   // These planes are defined in volume coordinates - spacing and origin are
110   // considered.
111   virtual void SetCroppingRegionPlanes(double arg1, double arg2, double arg3,
112                                        double arg4, double arg5, double arg6);
SetCroppingRegionPlanes(double * planes)113   virtual void SetCroppingRegionPlanes(double *planes)
114     {this->SetCroppingRegionPlanes(
115         planes[0],planes[1],planes[2],
116         planes[3],planes[4],planes[5]);}
117   virtual void GetCroppingRegionPlanes(double *planes);
118   virtual double *GetCroppingRegionPlanes();
119   // Description:
120   // Set the flags for the cropping regions. The clipping planes divide the
121   // volume into 27 regions - there is one bit for each region. The regions
122   // start from the one containing voxel (0,0,0), moving along the x axis
123   // fastest, the y axis next, and the z axis slowest. These are represented
124   // from the lowest bit to bit number 27 in the integer containing the
125   // flags. There are several convenience functions to set some common
126   // configurations - subvolume (the default), fence (between any of the
127   // clip plane pairs), inverted fence, cross (between any two of the
128   // clip plane pairs) and inverted cross.
129   virtual void SetCroppingRegionFlags(int mode);
130   virtual int GetCroppingRegionFlags();
131 
132 //BTX
133 // The possible values for the default and current render mode ivars
134   enum
135   {
136     DefaultRenderMode=0,
137     RayCastAndTextureRenderMode,
138     RayCastRenderMode,
139     TextureRenderMode,
140     GPURenderMode,
141     UndefinedRenderMode,
142     InvalidRenderMode
143   };
144 //ETX
145 
146   // Description:
147   // Set the requested render mode. The default is
148   // vtkSmartVolumeMapper::DefaultRenderMode.
149   void SetRequestedRenderMode(int mode);
150   int GetRequestedRenderMode();
151 
152   // Description:
153   // Set the requested render mode to vtkAMRVolumeMapper::DefaultRenderMode.
154   // This is the best option for an application that must adapt to different
155   // data types, hardware, and rendering parameters.
SetRequestedRenderModeToDefault()156   void SetRequestedRenderModeToDefault()
157   {this->SetRequestedRenderMode(vtkAMRVolumeMapper::DefaultRenderMode);}
158 
159   // Description:
160   // Set the requested render mode to
161   // vtkAMRVolumeMapper::RayCastAndTextureRenderMode.
162   // This is a good option if you want to avoid using advanced OpenGL
163   // functionality, but would still like to used 3D texture mapping, if
164   // available, for interactive rendering.
SetRequestedRenderModeToRayCastAndTexture()165   void SetRequestedRenderModeToRayCastAndTexture()
166   {this->SetRequestedRenderMode(vtkAMRVolumeMapper::RayCastAndTextureRenderMode);}
167 
168   // Description:
169   // Set the requested render mode to vtkAMRVolumeMapper::RayCastRenderMode.
170   // This option will use software rendering exclusively. This is a good option
171   // if you know there is no hardware acceleration.
SetRequestedRenderModeToRayCast()172   void SetRequestedRenderModeToRayCast()
173   {this->SetRequestedRenderMode(vtkAMRVolumeMapper::RayCastRenderMode);}
174 
175   // Description:
176   // Set the requested render mode to
177   // vtkAMRVolumeMapper::TextureRenderMode.
178   // This is a good option if you want to use 3D texture mapping, if
179   // available, for interactive rendering.
SetRequestedRenderModeToTexture()180   void SetRequestedRenderModeToTexture()
181   {this->SetRequestedRenderMode(vtkAMRVolumeMapper::TextureRenderMode);}
182 
183   // Description:
184   // Set the requested render mode to
185   // vtkAMRVolumeMapper::GPURenderMode.
186   // This will do the volume rendering on the GPU
SetRequestedRenderModeToGPU()187   void SetRequestedRenderModeToGPU()
188   {this->SetRequestedRenderMode(vtkAMRVolumeMapper::GPURenderMode);}
189 
190   // Description:
191   // Set interpolation mode for downsampling (lowres GPU)
192   // (initial value: cubic).
193   void SetInterpolationMode(int mode);
194   int GetInterpolationMode();
195 
SetInterpolationModeToNearestNeighbor()196   void SetInterpolationModeToNearestNeighbor()
197   {this->SetInterpolationMode(VTK_RESLICE_NEAREST);}
198 
SetInterpolationModeToLinear()199   void SetInterpolationModeToLinear()
200   {this->SetInterpolationMode(VTK_RESLICE_LINEAR);}
201 
SetInterpolationModeToCubic()202   void SetInterpolationModeToCubic()
203   {this->SetInterpolationMode(VTK_RESLICE_CUBIC);}
204 
205   // Description:
206   // Set/Get the number of samples/cells along the i/j/k directions.
207   // The default is 128x128x128
208   vtkSetVector3Macro(NumberOfSamples,int);
209   vtkGetVector3Macro(NumberOfSamples,int);
210 
211   // Description:
212   // Set the rate at or above this render will be considered interactive.
213   // If the DesiredUpdateRate of the vtkRenderWindow that caused the Render
214   // falls at or above this rate, the render is considered interactive and
215   // the mapper may be adjusted (depending on the render mode).
216   // Initial value is 1.0.
217   virtual void SetInteractiveUpdateRate(double rate);
218 
219   // Description:
220   // Get the update rate at or above which this is considered an
221   // interactive render.
222   // Initial value is 1.0.
223   virtual double GetInteractiveUpdateRate();
224 
225 //BTX
226   // Description:
227   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
228   // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS
229   // Render the volume
230   virtual void Render(vtkRenderer *ren, vtkVolume *vol);
231 
232   // Description:
233   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
234   // Release any graphics resources that are being consumed by this mapper.
235   // The parameter window could be used to determine which graphic
236   // resources to release.
237   virtual void ReleaseGraphicsResources(vtkWindow *);
238 
239   void ProcessUpdateExtentRequest(vtkRenderer *renderer, vtkInformation*info,
240                                   vtkInformationVector **inputVector,
241                                   vtkInformationVector *outputVector);
242   void ProcessInformationRequest(vtkRenderer *renderer, vtkInformation*info,
243                                  vtkInformationVector **inputVector,
244                                  vtkInformationVector *outputVector);
245   void UpdateResampler(vtkRenderer *ren, vtkOverlappingAMR *amr);
246   void UpdateResamplerFrustrumMethod(vtkRenderer *ren, vtkOverlappingAMR *amr);
247 //ETX
248 
249   // Description:
250   //Select the type of resampling techinque approach to use.
251   vtkSetMacro(RequestedResamplingMode, int);
252   vtkGetMacro(RequestedResamplingMode, int);
253   vtkSetMacro(FreezeFocalPoint, bool);
254   vtkGetMacro(FreezeFocalPoint, bool);
255 
256   // Description:
257   //Sets/Gets the tolerance used to determine if the resampler needs
258   // to be updated. Default is 10e-8
259   vtkSetMacro(ResamplerUpdateTolerance, double);
260   vtkGetMacro(ResamplerUpdateTolerance, double);
261 
262   // Description:
263   //Sets/Gets a flag that indicates the internal volume mapper
264   // should use the  default number of threads.  This is useful in applications
265   // such as ParaView that will turn off multiple threads by default. Default is false
266   vtkSetMacro(UseDefaultThreading, bool);
267   vtkGetMacro(UseDefaultThreading, bool);
268 
269   // Description:
270   // Utility method used by UpdateResamplerFrustrumMethod() to compute the
271   // bounds.
272   static bool ComputeResamplerBoundsFrustumMethod(
273     vtkCamera* camera, vtkRenderer* renderer,
274     const double data_bounds[6], double out_bounds[6]);
275 protected:
276   vtkAMRVolumeMapper();
277   ~vtkAMRVolumeMapper();
278 
279   // see algorithm for more info
280   virtual int FillInputPortInformation(int port, vtkInformation* info);
281   void UpdateGrid();
282 
283   vtkSmartVolumeMapper *InternalMapper;
284   vtkAMRResampleFilter *Resampler;
285   vtkUniformGrid *Grid;
286   int NumberOfSamples[3];
287   double Bounds[6];
288   // This indicates that the input has meta data for
289   // doing demand driven operations.
290   bool HasMetaData;
291   int RequestedResamplingMode;
292   bool FreezeFocalPoint;
293   // Cached values for camera focal point and
294   // the distance between the camera position and
295   // focal point
296   double LastFocalPointPosition[3];
297   double LastPostionFPDistance;
298   // This is used when determing if
299   // either the camera or focal point has
300   // move enough to cause the resampler to update
301   double ResamplerUpdateTolerance;
302   bool GridNeedsToBeUpdated;
303   bool UseDefaultThreading;
304 
305 private:
306   vtkAMRVolumeMapper(const vtkAMRVolumeMapper&);  // Not implemented.
307   void operator=(const vtkAMRVolumeMapper&);  // Not implemented.
308 };
309 
310 
311 #endif
312