00001 /*========================================================================= 00002 00003 Copyright (c) 1998-2003 Kitware Inc. 469 Clifton Corporate Parkway, 00004 Clifton Park, NY, 12065, USA. 00005 00006 All rights reserved. No part of this software may be reproduced, distributed, 00007 or modified, in any form or by any means, without permission in writing from 00008 Kitware Inc. 00009 00010 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR 00011 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00012 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, 00013 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00014 00015 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, 00016 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 00017 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN 00018 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE 00019 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 00020 00021 =========================================================================*/ 00022 // .NAME vtkKWVolumePropertyHelper - a render widget for volumes 00023 // .SECTION Description 00024 00025 #ifndef __vtkKWVolumePropertyHelper_h 00026 #define __vtkKWVolumePropertyHelper_h 00027 00028 #include "vtkObject.h" 00029 #include "vtkKWWidgets.h" // Needed for export symbols directives 00030 00031 class vtkVolumeProperty; 00032 class vtkKWHistogramSet; 00033 class vtkImageData; 00034 00035 class KWWidgets_EXPORT vtkKWVolumePropertyHelper : public vtkObject 00036 { 00037 public: 00038 static vtkKWVolumePropertyHelper* New(); 00039 vtkTypeRevisionMacro(vtkKWVolumePropertyHelper, vtkObject); 00040 void PrintSelf(ostream& os, vtkIndent indent); 00041 00042 // Description: 00043 // Apply a normalized scalar opacity preset to a specific component 00044 // Such normalized values can later be converted to real scalar values 00045 // given an image data and/or an histogram (see ConvertNormalizedToReal). 00046 //BTX 00047 enum 00048 { 00049 // 2 points "ramp": 0% opacity at 0% to 20% opacity at 100% 00050 ScalarOpacityRamp0At0To20At100 = 0, 00051 00052 // 2 points "ramp": 0% opacity at 25% to 100% opacity at 50% 00053 ScalarOpacityRamp0At25To100At50, 00054 00055 // 2 points "ramp": 0% opacity at 50% to 100% opacity at 75% 00056 ScalarOpacityRamp0At50To100At75, 00057 00058 // 4 steps: 0% opacity until 25%, 20% opacity from 25% to 50%, 00059 // 40% opacity from 50% to 75%, and 100% opacity from 75% to 100%. 00060 ScalarOpacitySteps0To25Then20To50Then40To75Then100To100 00061 }; 00062 //ETX 00063 static void ApplyScalarOpacityPreset( 00064 vtkVolumeProperty *prop, int comp, int preset); 00065 00066 // Description: 00067 // Apply a normalized color transfer function preset to a specific component. 00068 // Such normalized values can later be converted to real scalar values 00069 // given an image data and/or an histogram (see ConvertNormalizedToReal). 00070 // Some presets will set 2, 3, 4 or more color points. You can specify 00071 // any number of colors though, the missing ones will be picked/rotated 00072 // from the one you passed (i.e. if 2 points are created and one color is 00073 // provided, the same color will be used at both locations). 00074 // Convenience methods are provided to pass one, two, three or four RGB 00075 // color(s) directly instead of an array of RGB colors (i.e. an array of 00076 // double triplets). 00077 //BTX 00078 enum 00079 { 00080 // 2 points "ramp": color at 0%, color at 100% 00081 RGBTransferFunctionRampAt0At100 = 0, 00082 00083 // 3 points "ramp": color at 0%, color at 70%, color at 100% 00084 RGBTransferFunctionRampAt0At70At100, 00085 00086 // 4 steps: color from 0% to 25%, color from 25% to 50%, 00087 // color from 50% to 75%, color from 75% to 100%. 00088 RGBTransferFunctionStepsTo25To50To75To100 00089 }; 00090 //ETX 00091 static void ApplyRGBTransferFunctionPreset( 00092 vtkVolumeProperty *prop, int comp, int preset, 00093 int nb_colors, double **rgb); 00094 static void ApplyRGBTransferFunctionPreset( 00095 vtkVolumeProperty *prop, int comp, int preset, 00096 double rgb[3]); 00097 static void ApplyRGBTransferFunctionPreset( 00098 vtkVolumeProperty *prop, int comp, int preset, 00099 double rgb1[3], double rgb2[3]); 00100 static void ApplyRGBTransferFunctionPreset( 00101 vtkVolumeProperty *prop, int comp, int preset, 00102 double rgb1[3], double rgb2[3], double rgb3[3]); 00103 static void ApplyRGBTransferFunctionPreset( 00104 vtkVolumeProperty *prop, int comp, int preset, 00105 double rgb1[3], double rgb2[3], double rgb3[3], double rgb4[3]); 00106 00107 // Description: 00108 // Apply a normalized gradient opacity preset to a specific component 00109 // Such normalized values can later be converted to real scalar values 00110 // given an image data and/or an histogram (see ConvertNormalizedToReal). 00111 //BTX 00112 enum 00113 { 00114 // No edge detection 00115 GradientOpacityNoEdge = 0, 00116 00117 // Medium edge detection 00118 GradientOpacityMediumEdge, 00119 00120 // Strong edge detection 00121 GradientOpacityStrongEdge 00122 }; 00123 //ETX 00124 static void ApplyGradientOpacityPreset( 00125 vtkVolumeProperty *prop, int comp, int preset); 00126 00127 // Description: 00128 // Apply a lighting preset to a specific component 00129 //BTX 00130 enum 00131 { 00132 // Full ambient eliminating all directional shading 00133 LightingFullAmbient = 0, 00134 00135 // Dull material properties (no specular lighting) 00136 LightingDull, 00137 00138 // Smooth material properties (moderate specular lighting) 00139 LightingSmooth, 00140 00141 // Shiny material properties (high specular lighting) 00142 LightingShiny 00143 }; 00144 //ETX 00145 static void ApplyLightingPreset( 00146 vtkVolumeProperty *prop, int comp, int preset); 00147 00148 // Description: 00149 // Apply a normalized preset, i.e. a combination of a scalar opacity 00150 // preset, a color transfer function preset, a gradient opacity preset 00151 // and a lighting preset (see ApplyScalarOpacityPreset, 00152 // ApplyRGBTransferFunctionPreset, ApplyGradientOpacityPreset and 00153 // ApplyLightingPreset). 00154 // IMPORTANT: note that the vtkVolumeProperty's IndependentComponenents 00155 // flag will be taken into account when setting the transfer functions 00156 // for each components of the property. 00157 // See ConvertNormalizedRange and/or ApplyPresetAndConvertNormalizedRange 00158 // to convert the normalized range to real scalar ranges. 00159 //BTX 00160 enum 00161 { 00162 // ScalarOpacityRamp0At0To20At100 00163 // RGBTransferFunctionRampAt0At100 00164 // => white for comp 0, then colors (red, green, blue, yellow) 00165 // GradientOpacityNoEdge 00166 // LightingDull 00167 // Shading Off 00168 Preset1 = 0, 00169 00170 // ScalarOpacityRamp0At0To20At100 00171 // RGBTransferFunctionRampAt0At100 00172 // => black to white for comp 0, then colors to white 00173 // GradientOpacityNoEdge 00174 // LightingDull 00175 // Shading Off 00176 Preset2, 00177 00178 // ScalarOpacityRamp0At0To20At100 00179 // RGBTransferFunctionRampAt0At70At100 00180 // => rainbox (blue -> green -> red) for all comps 00181 // GradientOpacityNoEdge 00182 // LightingDull 00183 // Shading Off 00184 Preset3, 00185 00186 // ScalarOpacityRamp0At25To100At50 00187 // RGBTransferFunctionRampAt0At100 00188 // => tan for comp 0, then other colors (red, green, blue, yellow) 00189 // LightingDull 00190 // Shading On 00191 Preset4, 00192 00193 // ScalarOpacityRamp0At50To100At75 00194 // RGBTransferFunctionRampAt0At100 00195 // => tan for comp 0, then other colors (red, green, blue, yellow) 00196 // GradientOpacityNoEdge 00197 // LightingDull 00198 // Shading On 00199 Preset5, 00200 00201 // ScalarOpacitySteps0To25Then20To50Then40To75Then100To100 00202 // RGBTransferFunctionStepsTo25To50To75To100 00203 // => red, green, blue, yellow steps for all comps 00204 // GradientOpacityNoEdge 00205 // LightingDull 00206 // Shading On 00207 Preset6 00208 }; 00209 //ETX 00210 static void ApplyPreset(vtkVolumeProperty *prop, int preset); 00211 00212 // Description: 00213 // Retrieve some solid color RGB presets. 00214 //BTX 00215 enum 00216 { 00217 Black = 0, 00218 White, 00219 Gray3, 00220 Red, 00221 Green, 00222 Blue, 00223 Yellow, 00224 Magenta, 00225 Cyan, 00226 Tan 00227 }; 00228 //ETX 00229 static double* GetRGBColor(int preset); 00230 00231 // Description: 00232 // Convert a normalized volume property to real scalar ranges. 00233 // The contents of normalized_prop is entirely deep-copied to 00234 // target_prop (EXCEPT the ScalarOpacityUnitDistance). 00235 // The points are all moved from normalized space to real scalar ranges 00236 // computed either from the image's data range or from its histogram (if any). 00237 static void ConvertNormalizedRange( 00238 vtkVolumeProperty *normalized_prop, 00239 vtkVolumeProperty *target_prop, 00240 vtkImageData *image, 00241 int independent_component, 00242 vtkKWHistogramSet *histogram_set 00243 ); 00244 00245 // Description: 00246 // Convenience method that will create a temporary volume property, 00247 // use ApplyPreset to convert it to a normalized preset, then convert 00248 // its normalized values to real scalar ranges by calling 00249 // ConvertNormalizedRange. 00250 // The points are all moved from normalized space to real scalar ranges 00251 // computed either from the image's data range or from its histogram (if any). 00252 static void ApplyPresetAndConvertNormalizedRange( 00253 int preset, 00254 vtkVolumeProperty *target_prop, 00255 vtkImageData *image, 00256 int independent_component, 00257 vtkKWHistogramSet *histogram_set 00258 ); 00259 00260 // Description: 00261 // Deep copy a volume property from source to target. 00262 static void DeepCopyVolumeProperty( 00263 vtkVolumeProperty *target, vtkVolumeProperty *source); 00264 00265 // Description: 00266 // Copy a volume property from source to target, optionally skipping 00267 // some fields. 00268 //BTX 00269 enum 00270 { 00271 CopySkipOpacityUnitDistance = 1, 00272 CopySkipIndependentComponents = 2 00273 }; 00274 //ETX 00275 static void CopyVolumeProperty( 00276 vtkVolumeProperty *target, vtkVolumeProperty *source, int options); 00277 00278 protected: 00279 vtkKWVolumePropertyHelper() {}; 00280 ~vtkKWVolumePropertyHelper() {}; 00281 00282 private: 00283 vtkKWVolumePropertyHelper(const vtkKWVolumePropertyHelper&); // Not implemented 00284 void operator=(const vtkKWVolumePropertyHelper&); // Not implemented 00285 }; 00286 00287 #endif