forked from karlkrissian/vtkMultiVolRen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkGPUMultiVolumeRayCastMapper.h
executable file
·348 lines (284 loc) · 12.6 KB
/
vtkGPUMultiVolumeRayCastMapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGPUMultiVolumeRayCastMapper.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Modified by: Carlos Falcón [email protected]
Karl Krissian [email protected]
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkGPUMultiVolumeRayCastMapper - Ray casting performed on the GPU.
// .SECTION Description
// vtkGPUMultiVolumeRayCastMapper is a volume mapper that performs ray casting on
// the GPU using fragment programs, using two input datasets.
#ifndef __vtkGPUMultiVolumeRayCastMapper_h
#define __vtkGPUMultiVolumeRayCastMapper_h
#include "vtkVolumeMapper.h"
class vtkVolumeProperty;
class vtkRenderWindow;
class vtkImageData;
class vtkTransform;
//class vtkKWAMRVolumeMapper; // friend class.
class VTK_VOLUMERENDERING_EXPORT vtkGPUMultiVolumeRayCastMapper : public vtkVolumeMapper
{
public:
static vtkGPUMultiVolumeRayCastMapper *New();
vtkTypeMacro(vtkGPUMultiVolumeRayCastMapper,vtkVolumeMapper);
void PrintSelf( ostream& os, vtkIndent indent );
// Define the Input for both datasets
using vtkVolumeMapper::SetInput;
void SetInput( int port, vtkImageData *input );
void SetInput( int port, vtkDataSet *genericInput );
vtkImageData * GetInput( int port=0);
// set/get the properties of the second volume
void SetProperty2(vtkVolumeProperty *property);
vtkVolumeProperty *GetProperty2();
// set/get a user transformation for 2nd input user transform
void SetSecondInputUserTransform(vtkTransform *t);
vtkTransform *GetSecondInputUserTransform();
// Description:
// If AutoAdjustSampleDistances is on, the the ImageSampleDistance
// will be varied to achieve the allocated render time of this
// prop (controlled by the desired update rate and any culling in
// use).
vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
vtkGetMacro( AutoAdjustSampleDistances, int );
vtkBooleanMacro( AutoAdjustSampleDistances, int );
// Description:
// Set/Get the distance between samples used for rendering
// when AutoAdjustSampleDistances is off, or when this mapper
// has more than 1 second allocated to it for rendering.
// Initial value is 1.0.
vtkSetMacro( SampleDistance, float );
vtkGetMacro( SampleDistance, float );
// Description:
// Sampling distance in the XY image dimensions. Default value of 1 meaning
// 1 ray cast per pixel. If set to 0.5, 4 rays will be cast per pixel. If
// set to 2.0, 1 ray will be cast for every 4 (2 by 2) pixels. This value
// will be adjusted to meet a desired frame rate when AutoAdjustSampleDistances
// is on.
vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f );
vtkGetMacro( ImageSampleDistance, float );
// Description:
// This is the minimum image sample distance allow when the image
// sample distance is being automatically adjusted.
vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f );
vtkGetMacro( MinimumImageSampleDistance, float );
// Description:
// This is the maximum image sample distance allow when the image
// sample distance is being automatically adjusted.
vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f );
vtkGetMacro( MaximumImageSampleDistance, float );
// Description:
// Set/Get the window / level applied to the final color.
// This allows brightness / contrast adjustments on the
// final image.
// window is the width of the window.
// level is the center of the window.
// Initial window value is 1.0
// Initial level value is 0.5
// window cannot be null but can be negative, this way
// values will be reversed.
// |window| can be larger than 1.0
// level can be any real value.
vtkSetMacro( FinalColorWindow, float );
vtkGetMacro( FinalColorWindow, float );
vtkSetMacro( FinalColorLevel, float );
vtkGetMacro( FinalColorLevel, float );
// Description:
// Maximum size of the 3D texture in GPU memory.
// Will default to the size computed from the graphics
// card. Can be adjusted by the user.
vtkSetMacro( MaxMemoryInBytes, vtkIdType );
vtkGetMacro( MaxMemoryInBytes, vtkIdType );
// Description:
// Maximum fraction of the MaxMemoryInBytes that should
// be used to hold the texture. Valid values are 0.1 to
// 1.0.
vtkSetClampMacro( MaxMemoryFraction, float, 0.1f, 1.0f );
vtkGetMacro( MaxMemoryFraction, float );
// Description:
// Tells if the mapper will report intermediate progress.
// Initial value is true. As the progress works with a GL blocking
// call (glFinish()), this can be useful for huge dataset but can
// slow down rendering of small dataset. It should be set to true
// for big dataset or complex shading and streaming but to false for
// small datasets.
vtkSetMacro(ReportProgress,bool);
vtkGetMacro(ReportProgress,bool);
// Description:
// Based on hardware and properties, we may or may not be able to
// render using 3D texture mapping. This indicates if 3D texture
// mapping is supported by the hardware, and if the other extensions
// necessary to support the specific properties are available.
virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window),
vtkVolumeProperty *vtkNotUsed(property))
{
return 0;
}
void CreateCanonicalView( vtkRenderer *ren,
vtkVolume *volume,
vtkImageData *image,
int blend_mode,
double viewDirection[3],
double viewUp[3] );
// Description:
// Optionally, set a mask input. This mask may be a binary mask or a label
// map. This must be specified via SetMaskType.
//
// If the mask is a binary mask, the volume rendering is confined to regions
// within the binary mask. The binary mask is assumed to have a datatype of
// UCHAR and values of 255 (inside) and 0 (outside).
//
// The mask may also be a label map. The label map is allowed to contain only
// 3 labels (values of 0, 1 and 2) and must have a datatype of UCHAR. In voxels
// with label value of 0, the color transfer function supplied by component
// 0 is used.
// In voxels with label value of 1, the color transfer function supplied by
// component 1 is used and blended with the transfer function supplied by
// component 0, with the blending weight being determined by
// MaskBlendFactor.
// In voxels with a label value of 2, the color transfer function supplied
// by component 2 is used and blended with the transfer function supplied by
// component 0, with the blending weight being determined by
// MaskBlendFactor.
void SetMaskInput(vtkImageData *mask);
vtkGetObjectMacro(MaskInput, vtkImageData);
//BTX
enum { BinaryMaskType = 0, LabelMapMaskType };
//ETX
// Description:
// Set the mask type, if mask is to be used. See documentation for
// SetMaskInput(). The default is a LabelMapMaskType.
vtkSetMacro( MaskType, int );
vtkGetMacro( MaskType, int );
void SetMaskTypeToBinary();
void SetMaskTypeToLabelMap();
// Description:
// Tells how much mask color transfer function is used compared to the
// standard color transfer function when the mask is true. This is relevant
// only for the label map mask.
// 0.0 means only standard color transfer function.
// 1.0 means only mask color tranfer function.
// The default value is 1.0.
vtkSetClampMacro(MaskBlendFactor,float,0.0f,1.0f);
vtkGetMacro(MaskBlendFactor,float);
//BTX
// Description:
// WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
// Initialize rendering for this volume.
void Render( vtkRenderer *, vtkVolume * );
// Description:
// Handled in the subclass - the actual render method
// \pre input is up-to-date.
virtual void GPURender( vtkRenderer *, vtkVolume *) {}
// Description:
// WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
// Release any graphics resources that are being consumed by this mapper.
// The parameter window could be used to determine which graphic
// resources to release.
void ReleaseGraphicsResources(vtkWindow *) {};
// Description:
// Return how much the dataset has to be reduced in each dimension to
// fit on the GPU. If the value is 1.0, there is no need to reduce the
// dataset.
// \pre the calling thread has a current OpenGL context.
// \pre mapper_supported: IsRenderSupported(renderer->GetRenderWindow(),0)
// The computation is based on hardware limits (3D texture indexable size)
// and MaxMemoryInBytes.
// \post valid_i_ratio: ratio[0]>0 && ratio[0]<=1.0
// \post valid_j_ratio: ratio[1]>0 && ratio[1]<=1.0
// \post valid_k_ratio: ratio[2]>0 && ratio[2]<=1.0
virtual void GetReductionRatio(double ratio[3])=0;
//ETX
protected:
vtkGPUMultiVolumeRayCastMapper();
~vtkGPUMultiVolumeRayCastMapper();
// Check to see that the render will be OK
int ValidateRender( vtkRenderer *, vtkVolume * );
// Special version of render called during the creation
// of a canonical view.
void CanonicalViewRender( vtkRenderer *, vtkVolume * );
// Methods called by the AMR Volume Mapper.
virtual void PreRender(vtkRenderer *ren,
vtkVolume *vol,
double datasetBounds[6],
double scalarRange[2],
int numberOfScalarComponents,
unsigned int numberOfLevels)=0;
// \pre input is up-to-date
virtual void RenderBlock(vtkRenderer *ren,
vtkVolume *vol,
unsigned int level)=0;
virtual void PostRender(vtkRenderer *ren,
int numberOfScalarComponents)=0;
// Description:
// Called by the AMR Volume Mapper.
// Set the flag that tells if the scalars are on point data (0) or
// cell data (1).
void SetCellFlag(int cellFlag);
// The distance between sample points along the ray
float SampleDistance;
float ImageSampleDistance;
float MinimumImageSampleDistance;
float MaximumImageSampleDistance;
int AutoAdjustSampleDistances;
int SmallVolumeRender;
double BigTimeToDraw;
double SmallTimeToDraw;
float FinalColorWindow;
float FinalColorLevel;
vtkIdType MaxMemoryInBytes;
float MaxMemoryFraction;
//Property of the second volume
vtkVolumeProperty *Property2;
// 1 if we are generating the canonical image, 0 otherwise
int GeneratingCanonicalView;
vtkImageData *CanonicalViewImageData;
// Description:
// Set the mapper in AMR Mode or not. Initial value is false.
// Called only by the vtkKWAMRVolumeMapper
vtkSetClampMacro(AMRMode,int,0,1);
vtkGetMacro(AMRMode,int);
vtkBooleanMacro(AMRMode,int);
int AMRMode;
int CellFlag; // point data or cell data (or field data, not handled) ?
// Description:
// Compute the cropping planes clipped by the bounds of the volume.
// The result is put into this->ClippedCroppingRegionPlanes.
// NOTE: IT WILL BE MOVED UP TO vtkVolumeMapper after bullet proof usage
// in this mapper. Other subclasses will use the ClippedCroppingRegionsPlanes
// members instead of CroppingRegionPlanes.
// \pre volume_exists: this->GetInput()!=0
// \pre valid_cropping: this->Cropping &&
// this->CroppingRegionPlanes[0]<this->CroppingRegionPlanes[1] &&
// this->CroppingRegionPlanes[2]<this->CroppingRegionPlanes[3] &&
// this->CroppingRegionPlanes[4]<this->CroppingRegionPlanes[5])
virtual void ClipCroppingRegionPlanes();
double ClippedCroppingRegionPlanes[6];
bool ReportProgress;
vtkImageData * MaskInput;
float MaskBlendFactor;
int MaskType;
vtkImageData * TransformedInput;
// need to duplicate the TransformedInput
vtkImageData * TransformedInput2;
vtkGetObjectMacro(TransformedInput, vtkImageData);
void SetTransformedInput(vtkImageData*);
vtkGetObjectMacro(TransformedInput2, vtkImageData);
void SetTransformedInput2(vtkImageData*);
// Description:
// This is needed only to check if the input data has been changed since the last
// Render() call.
vtkImageData* LastInput;
vtkImageData* LastInput2;
//
vtkTransform* SecondInputUserTransform;
private:
vtkGPUMultiVolumeRayCastMapper(const vtkGPUMultiVolumeRayCastMapper&); // Not implemented.
void operator=(const vtkGPUMultiVolumeRayCastMapper&); // Not implemented.
};
#endif