-
Notifications
You must be signed in to change notification settings - Fork 0
/
mitkVolumeRendererShearWarp.h
279 lines (234 loc) · 12.2 KB
/
mitkVolumeRendererShearWarp.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
/*=========================================================================
Program: Medical Imaging Toolkit
Date: $Date: 2008-09-01 20:13:46 +0800 $
Version: $Version: 1.00 $
Copyright: AI Lab, Institute of Automation, Chinese Academy of Sciences
Last Modified by Xiang Dehui ,2008-7-25
=========================================================================*/
#ifndef __mitkVolumeRendererShearWarp_h
#define __mitkVolumeRendererShearWarp_h
#include "mitkVolumeRenderer.h"
#include "mitkVolumeShearFunction.h"
#include "mitkRCPtr.h"
#include "mitkEncodedGradientEstimator.h"
#include "mitkEncodedGradientShader.h"
// Macro for absolute x
//#define mitkAbsMacro(x) (((x) > 0.0)?(x):(-(x)))
//#define mitkFloorMacro(x) (((x) < 0.0)?((int)((x)-1.0)):((int)(x)))
//#define mitkCeilingMacro(x) (((x) < 0.0)?((int)(x)):((int)((x)+1.0)))
//#define mitkRoundMacro(x) (((x) < 0.0)?((int)((x)-0.5)):((int)((x)+0.5)))
///////////////////////////////////////////////////////////////////////////
class mitkMatrix;
/// mitkVolumeRendererShearWarp - a concrete volume renderer for rendering a volume
///////////////////////////////////////////////////////////////////////////
/// mitkVolumeRendererShearWarp is a concrete volume renderer for rendering a volume
/// using shear-warp technique.
/// \par
/// Our implemented algorithm references to:\n
/// [1]Lacroute P, Levoy M. Fast volume rendering using a shear-warp factorization of the viewing transformation.
/// Computer Graphics Proceedings, 1994.\n
/// [2]Lacroute P. Fast volume rendering using a shear-warp factorization of the viewing transformation[R].
/// CSL-TR-95- 678,Stanford University,1995.\n
/// \par
/// However, this class just implements brute-force shear-warp algorithm, that is,
/// it does not use run-length encoding technique as Lacroute.
///
/// Its rendering speed is generally faster than mitkVolumeRendererRayCasting and
/// mitkVolumeRendererSplatting, and the rendering effect is between them.
///
/// The default perspective shearer is the object of mitkVolumeShearPerspective,
/// and the default parallel shearer is the object of mitkVolumeShearParallel.
/// Particular perspective and parallel shearers are also allowed by calling
/// SetPerspectiveShearer() and SetParallelShearer().
///
/// Two rendering modes are alternative, one is integral mode, and the other
/// is MOP mode, you can switch the mode using SetModeIntegral() and SetModeMop().
class MITK_REGISTRATION2_API mitkVolumeRendererShearWarp : public mitkVolumeRenderer
{
public:
MITK_TYPE(mitkVolumeRendererShearWarp, mitkVolumeRenderer)
virtual void PrintSelf(ostream &os);
mitkVolumeRendererShearWarp();
///////////////////////////////////////////////////////////////////////////
/// Internal method. Don't call it directly.
///////////////////////////////////////////////////////////////////////////
virtual int Render(mitkView *view, mitkVolumeModel *vol);
///////////////////////////////////////////////////////////////////////////
/// Set the gradient estimator used to estimate normals.
/// \param gradest Represent the gradient estimator used to estimate normals.
///////////////////////////////////////////////////////////////////////////
void SetGradientEstimator(mitkEncodedGradientEstimator *gradest)
{
m_GradientEstimator = gradest;
}
///////////////////////////////////////////////////////////////////////////
/// Get the gradient estimator used to estimate normals.
/// \return Return the gradient estimator used to estimate normals.
///////////////////////////////////////////////////////////////////////////
mitkEncodedGradientEstimator* GetGradientEstimator(){return m_GradientEstimator;}
///////////////////////////////////////////////////////////////////////////
/// Get the gradient shader.
/// \return Return the gradient shader.
///////////////////////////////////////////////////////////////////////////
mitkEncodedGradientShader* GetEncodedGradientShader()
{
return m_GradientShader;
}
//////////////////////////////////////////////////////////////////////////
/// Set perspective shearer to shear and composite the volume.
/// \param shearer Represent the perspective shearer.
//////////////////////////////////////////////////////////////////////////
void SetPerspectiveShearer(mitkVolumeShearFunction *shearer);
//////////////////////////////////////////////////////////////////////////
/// Set Parallel shearer to shear and composite the volume.
/// \param shearer Represent the Parallel shearer.
//////////////////////////////////////////////////////////////////////////
void SetParallelShearer(mitkVolumeShearFunction *shearer);
//////////////////////////////////////////////////////////////////////////
/// Get the perspective shearer.
/// \return Return the current perspective shearer.
//////////////////////////////////////////////////////////////////////////
mitkVolumeShearFunction* GetPerspectiveShearer();
//////////////////////////////////////////////////////////////////////////
/// Get the Parallel shearer.
/// \return Return the current Parallel shearer.
//////////////////////////////////////////////////////////////////////////
mitkVolumeShearFunction* GetParallelShearer();
///////////////////////////////////////////////////////////////////////////
/// Set the sample distance in the image plane.
/// \param val Specify the sample distance in the image plane.
///////////////////////////////////////////////////////////////////////////
void SetImageSampleDistance(float val)
{
m_ImageSampleDistance = val;
}
///////////////////////////////////////////////////////////////////////////
/// Get the sample distance in the image plane.
/// \return Return the image sample distance in the image plane.
///////////////////////////////////////////////////////////////////////////
float GetImageSampleDistance() {return m_ImageSampleDistance;}
///////////////////////////////////////////////////////////////////////////
/// Get the minimum image sample distance in the image plane.
/// \return Return the minimum sample distance in the image plane.
///////////////////////////////////////////////////////////////////////////
float GetMinimumImageSampleDistance(){return m_MinimumImageSampleDistance;}
///////////////////////////////////////////////////////////////////////////
/// Get the maximum image sample distance in the image plane.
/// \return Return the maximum sample distance in the image plane.
///////////////////////////////////////////////////////////////////////////
float GetMaximumImageSampleDistance(){return m_MaximumImageSampleDistance;}
///////////////////////////////////////////////////////////////////////////
/// Get whether to auto-adjust the image sample distances.
/// \return Return a value which indicates whether to auto-adjust
/// the sample distances (1 means true, 0 means false).
///////////////////////////////////////////////////////////////////////////
bool GetAutoAdjustImageSampleDistances(){return m_AutoAdjustImageSampleDistances;}
///////////////////////////////////////////////////////////////////////////
/// Set image sample distances auto-adjusting on.
///////////////////////////////////////////////////////////////////////////
void AutoAdjustImageSampleDistancesOn(){ m_AutoAdjustImageSampleDistances = true;}
///////////////////////////////////////////////////////////////////////////
/// Set image sample distances auto-adjusting off.
///////////////////////////////////////////////////////////////////////////
void AutoAdjustImageSampleDistancesOff(){ m_AutoAdjustImageSampleDistances = false;}
///////////////////////////////////////////////////////////////////////////
/// Get gradient magnitude scale.
/// \return Return the gradient magnitude scale.
///////////////////////////////////////////////////////////////////////////
virtual float GetGradientMagnitudeScale();
///////////////////////////////////////////////////////////////////////////
/// Get gradient magnitude bias.
/// \return Return the gradient magnitude bias.
///////////////////////////////////////////////////////////////////////////
virtual float GetGradientMagnitudeBias();
//////////////////////////////////////////////////////////////////////////
/// Set volume rendering mode to be integral projection.
//////////////////////////////////////////////////////////////////////////
void SetModeIntegral(){ m_Mode = INTEGRAL; }
//////////////////////////////////////////////////////////////////////////
/// Set volume rendering mode to be MOP(maximum opacity projection).
/// \note Each image pixel stands for maximum opacity element in the ray
/// direction, and when opacity is linear with intensity, MOP is equal to
/// MIP(maximum intensity projection).
//////////////////////////////////////////////////////////////////////////
void SetModeMop(){ m_Mode = MOP; }
//////////////////////////////////////////////////////////////////////////
/// Get the volume rendering mode.
/// \return
/// Return 0 if the volume rendering mode is integral projection.
/// Return 1 if the volume rendering mode is MOP(maximum opacity projection).
//////////////////////////////////////////////////////////////////////////
int GetMode(){ return m_Mode; }
//////////////////////////////////////////////////////////////////////////
/// Set level-of-detail display.
/// \param lod The status of level-of-detail.
/// If lod is true, it will display level-of-detail volume rendering image,
/// that is, the image sampling rate is enlarged when the view is scaled
/// so that you will get a more detailed image. however, the rendering speed
/// will be slowed accordingly.
/// If lod is false, it will display volume rendering image with the same
/// detail, that is, the image sampling rate will not be changed.
/// \note In default, it renders volume without level-of-detail.
//////////////////////////////////////////////////////////////////////////
void SetLevelOfDetail(bool lod){ m_LOD = lod; }
protected:
virtual ~mitkVolumeRendererShearWarp();
void _updateShadingTables(mitkView *view, mitkVolumeModel *vol);
void _renderTexture(mitkVolumeModel *vol, mitkView *view, unsigned char *img);
void _getTransformMatrix(mitkView *view, mitkVolumeModel *vol);
int _computeGridBounds(mitkVolumeModel *vol, mitkView *view);
void _shear(mitkView *view, mitkVolumeModel *vol);
void _getShearOrder(mitkView *view);
// bool _cullVoxel(float x, float y, float z, float *clipPlane, int pCount);
mitkRCPtr<mitkVolumeShearFunction> m_ParallelShearer;
mitkRCPtr<mitkVolumeShearFunction> m_PerspectiveShearer;
mitkRCPtr<mitkEncodedGradientEstimator> m_GradientEstimator;
mitkRCPtr<mitkEncodedGradientShader> m_GradientShader;
// Transformation information
mitkMatrix *m_GridToWorld;
mitkMatrix *m_ViewToGrid;
mitkMatrix *m_ShearMatrix;
mitkMatrix *m_InverseShearMatrix;
mitkMatrix *m_ShearOnlyMatrix;
// The distance between sample points along shear space.
float m_ImageSampleDistance;
float m_MinimumImageSampleDistance;
float m_MaximumImageSampleDistance;
bool m_AutoAdjustImageSampleDistances;
float m_AdjustDistance;
// This is the size of the intermediate image region in sheared space.
int m_GridSize[2];
// This is the location in sheared space where the intermediate image region
// is located.
int m_GridOrigin[2];
// This is the size of samples in intermediate image that we use for real display.
int m_ImageSize[2];
int m_OldImageSize[2];
// This is the size of the allocated memory for image. This may be bigger
// or smaller than Intermediate Image's full size - it will be bigger if necessary to
// ensure a power of 2, it will be smaller if the intermediate image region only covers
// a small region of the allocated memory.
int m_ImageMemorySize[2];
// This is allocated for final displayed image.
unsigned char *m_Image;
// This is allocated for compositing of sheared slices.
float *m_CompositeBuffer;
//shear related information.
mitkShear *m_Shear;
int m_Mode;
enum
{
INTEGRAL,
MOP
};
// information needed for interactive clipping.
bool m_DepthTest;
bool *m_Clips;
bool m_AutoReslice;
// information needed for level-of-detail display.
bool m_LOD;
private:
mitkVolumeRendererShearWarp(const mitkVolumeRendererShearWarp&);
void operator = (const mitkVolumeRendererShearWarp&);
};
#endif