KWWidgets
vtkKWVolumePropertyHelper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Copyright (c) 1998-2003 Kitware Inc. 469 Clifton Corporate Parkway,
4 Clifton Park, NY, 12065, USA.
5 
6 All rights reserved. No part of this software may be reproduced, distributed,
7 or modified, in any form or by any means, without permission in writing from
8 Kitware Inc.
9 
10 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
11 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
12 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
13 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 
15 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
18 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
19 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
20 
21 =========================================================================*/
22 // .NAME vtkKWVolumePropertyHelper - a render widget for volumes
23 // .SECTION Description
24 
25 #ifndef __vtkKWVolumePropertyHelper_h
26 #define __vtkKWVolumePropertyHelper_h
27 
28 #include "vtkObject.h"
29 #include "vtkKWWidgets.h" // Needed for export symbols directives
30 
31 class vtkVolumeProperty;
32 class vtkKWHistogramSet;
33 class vtkImageData;
34 
35 class KWWidgets_EXPORT vtkKWVolumePropertyHelper : public vtkObject
36 {
37 public:
38  static vtkKWVolumePropertyHelper* New();
39  vtkTypeRevisionMacro(vtkKWVolumePropertyHelper, vtkObject);
40  void PrintSelf(ostream& os, vtkIndent indent);
41 
42  // Description:
43  // Apply a normalized scalar opacity preset to a specific component
44  // Such normalized values can later be converted to real scalar values
45  // given an image data and/or an histogram (see ConvertNormalizedToReal).
46  //BTX
47  enum
48  {
49  // 2 points "ramp": 0% opacity at 0% to 20% opacity at 100%
50  ScalarOpacityRamp0At0To20At100 = 0,
51 
52  // 2 points "ramp": 0% opacity at 25% to 100% opacity at 50%
53  ScalarOpacityRamp0At25To100At50,
54 
55  // 2 points "ramp": 0% opacity at 50% to 100% opacity at 75%
56  ScalarOpacityRamp0At50To100At75,
57 
58  // 4 steps: 0% opacity until 25%, 20% opacity from 25% to 50%,
59  // 40% opacity from 50% to 75%, and 100% opacity from 75% to 100%.
60  ScalarOpacitySteps0To25Then20To50Then40To75Then100To100
61  };
62  //ETX
63  static void ApplyScalarOpacityPreset(
64  vtkVolumeProperty *prop, int comp, int preset);
65 
66  // Description:
67  // Apply a normalized color transfer function preset to a specific component.
68  // Such normalized values can later be converted to real scalar values
69  // given an image data and/or an histogram (see ConvertNormalizedToReal).
70  // Some presets will set 2, 3, 4 or more color points. You can specify
71  // any number of colors though, the missing ones will be picked/rotated
72  // from the one you passed (i.e. if 2 points are created and one color is
73  // provided, the same color will be used at both locations).
74  // Convenience methods are provided to pass one, two, three or four RGB
75  // color(s) directly instead of an array of RGB colors (i.e. an array of
76  // double triplets).
77  //BTX
78  enum
79  {
80  // 2 points "ramp": color at 0%, color at 100%
81  RGBTransferFunctionRampAt0At100 = 0,
82 
83  // 3 points "ramp": color at 0%, color at 70%, color at 100%
84  RGBTransferFunctionRampAt0At70At100,
85 
86  // 4 steps: color from 0% to 25%, color from 25% to 50%,
87  // color from 50% to 75%, color from 75% to 100%.
88  RGBTransferFunctionStepsTo25To50To75To100
89  };
90  //ETX
91  static void ApplyRGBTransferFunctionPreset(
92  vtkVolumeProperty *prop, int comp, int preset,
93  int nb_colors, double **rgb);
94  static void ApplyRGBTransferFunctionPreset(
95  vtkVolumeProperty *prop, int comp, int preset,
96  double rgb[3]);
97  static void ApplyRGBTransferFunctionPreset(
98  vtkVolumeProperty *prop, int comp, int preset,
99  double rgb1[3], double rgb2[3]);
100  static void ApplyRGBTransferFunctionPreset(
101  vtkVolumeProperty *prop, int comp, int preset,
102  double rgb1[3], double rgb2[3], double rgb3[3]);
103  static void ApplyRGBTransferFunctionPreset(
104  vtkVolumeProperty *prop, int comp, int preset,
105  double rgb1[3], double rgb2[3], double rgb3[3], double rgb4[3]);
106 
107  // Description:
108  // Apply a normalized gradient opacity preset to a specific component
109  // Such normalized values can later be converted to real scalar values
110  // given an image data and/or an histogram (see ConvertNormalizedToReal).
111  //BTX
112  enum
113  {
114  // No edge detection
115  GradientOpacityNoEdge = 0,
116 
117  // Medium edge detection
118  GradientOpacityMediumEdge,
119 
120  // Strong edge detection
121  GradientOpacityStrongEdge
122  };
123  //ETX
124  static void ApplyGradientOpacityPreset(
125  vtkVolumeProperty *prop, int comp, int preset);
126 
127  // Description:
128  // Apply a lighting preset to a specific component
129  //BTX
130  enum
131  {
132  // Full ambient eliminating all directional shading
133  LightingFullAmbient = 0,
134 
135  // Dull material properties (no specular lighting)
136  LightingDull,
137 
138  // Smooth material properties (moderate specular lighting)
139  LightingSmooth,
140 
141  // Shiny material properties (high specular lighting)
142  LightingShiny
143  };
144  //ETX
145  static void ApplyLightingPreset(
146  vtkVolumeProperty *prop, int comp, int preset);
147 
148  // Description:
149  // Apply a normalized preset, i.e. a combination of a scalar opacity
150  // preset, a color transfer function preset, a gradient opacity preset
151  // and a lighting preset (see ApplyScalarOpacityPreset,
152  // ApplyRGBTransferFunctionPreset, ApplyGradientOpacityPreset and
153  // ApplyLightingPreset).
154  // IMPORTANT: note that the vtkVolumeProperty's IndependentComponenents
155  // flag will be taken into account when setting the transfer functions
156  // for each components of the property.
157  // See ConvertNormalizedRange and/or ApplyPresetAndConvertNormalizedRange
158  // to convert the normalized range to real scalar ranges.
159  //BTX
160  enum
161  {
162  // ScalarOpacityRamp0At0To20At100
163  // RGBTransferFunctionRampAt0At100
164  // => white for comp 0, then colors (red, green, blue, yellow)
165  // GradientOpacityNoEdge
166  // LightingDull
167  // Shading Off
168  Preset1 = 0,
169 
170  // ScalarOpacityRamp0At0To20At100
171  // RGBTransferFunctionRampAt0At100
172  // => black to white for comp 0, then colors to white
173  // GradientOpacityNoEdge
174  // LightingDull
175  // Shading Off
176  Preset2,
177 
178  // ScalarOpacityRamp0At0To20At100
179  // RGBTransferFunctionRampAt0At70At100
180  // => rainbox (blue -> green -> red) for all comps
181  // GradientOpacityNoEdge
182  // LightingDull
183  // Shading Off
184  Preset3,
185 
186  // ScalarOpacityRamp0At25To100At50
187  // RGBTransferFunctionRampAt0At100
188  // => tan for comp 0, then other colors (red, green, blue, yellow)
189  // LightingDull
190  // Shading On
191  Preset4,
192 
193  // ScalarOpacityRamp0At50To100At75
194  // RGBTransferFunctionRampAt0At100
195  // => tan for comp 0, then other colors (red, green, blue, yellow)
196  // GradientOpacityNoEdge
197  // LightingDull
198  // Shading On
199  Preset5,
200 
201  // ScalarOpacitySteps0To25Then20To50Then40To75Then100To100
202  // RGBTransferFunctionStepsTo25To50To75To100
203  // => red, green, blue, yellow steps for all comps
204  // GradientOpacityNoEdge
205  // LightingDull
206  // Shading On
207  Preset6
208  };
209  //ETX
210  static void ApplyPreset(vtkVolumeProperty *prop, int preset);
211 
212  // Description:
213  // Retrieve some solid color RGB presets.
214  //BTX
215  enum
216  {
217  Black = 0,
218  White,
219  Gray3,
220  Red,
221  Green,
222  Blue,
223  Yellow,
224  Magenta,
225  Cyan,
226  Tan
227  };
228  //ETX
229  static double* GetRGBColor(int preset);
230 
231  // Description:
232  // Convert a normalized volume property to real scalar ranges.
233  // The contents of normalized_prop is entirely deep-copied to
234  // target_prop (EXCEPT the ScalarOpacityUnitDistance).
235  // The points are all moved from normalized space to real scalar ranges
236  // computed either from the image's data range or from its histogram (if any).
237  static void ConvertNormalizedRange(
238  vtkVolumeProperty *normalized_prop,
239  vtkVolumeProperty *target_prop,
240  vtkImageData *image,
241  int independent_component,
242  vtkKWHistogramSet *histogram_set
243  );
244 
245  // Description:
246  // Convenience method that will create a temporary volume property,
247  // use ApplyPreset to convert it to a normalized preset, then convert
248  // its normalized values to real scalar ranges by calling
249  // ConvertNormalizedRange.
250  // The points are all moved from normalized space to real scalar ranges
251  // computed either from the image's data range or from its histogram (if any).
252  static void ApplyPresetAndConvertNormalizedRange(
253  int preset,
254  vtkVolumeProperty *target_prop,
255  vtkImageData *image,
256  int independent_component,
257  vtkKWHistogramSet *histogram_set
258  );
259 
260  // Description:
261  // Deep copy a volume property from source to target.
262  static void DeepCopyVolumeProperty(
263  vtkVolumeProperty *target, vtkVolumeProperty *source);
264 
265  // Description:
266  // Copy a volume property from source to target, optionally skipping
267  // some fields.
268  //BTX
269  enum
270  {
271  CopySkipOpacityUnitDistance = 1,
272  CopySkipIndependentComponents = 2
273  };
274  //ETX
275  static void CopyVolumeProperty(
276  vtkVolumeProperty *target, vtkVolumeProperty *source, int options);
277 
278 protected:
281 
282 private:
283  vtkKWVolumePropertyHelper(const vtkKWVolumePropertyHelper&); // Not implemented
284  void operator=(const vtkKWVolumePropertyHelper&); // Not implemented
285 };
286 
287 #endif