VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkFastSplatter.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 /*---------------------------------------------------------------------------- 00016 Copyright (c) Sandia Corporation 00017 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details. 00018 ----------------------------------------------------------------------------*/ 00047 #ifndef __vtkFastSplatter_h 00048 #define __vtkFastSplatter_h 00049 00050 #include "vtkImageAlgorithm.h" 00051 00052 class VTK_IMAGING_EXPORT vtkFastSplatter : public vtkImageAlgorithm 00053 { 00054 public: 00055 vtkTypeMacro(vtkFastSplatter, vtkImageAlgorithm); 00056 static vtkFastSplatter *New(); 00057 virtual void PrintSelf(ostream &os, vtkIndent indent); 00058 00060 00064 vtkSetVector6Macro(ModelBounds,double); 00065 vtkGetVectorMacro(ModelBounds,double,6); 00067 00069 00070 vtkSetVector3Macro( OutputDimensions, int ); 00071 vtkGetVector3Macro( OutputDimensions, int ); 00073 00074 //BTX 00075 enum { NoneLimit, ClampLimit, ScaleLimit, FreezeScaleLimit }; 00076 //ETX 00077 00079 00084 vtkSetMacro(LimitMode, int); 00085 vtkGetMacro(LimitMode, int); 00086 void SetLimitModeToNone() { this->SetLimitMode(NoneLimit); } 00087 void SetLimitModeToClamp() { this->SetLimitMode(ClampLimit); } 00088 void SetLimitModeToScale() { this->SetLimitMode(ScaleLimit); } 00089 void SetLimitModeToFreezeScale() { this->SetLimitMode(FreezeScaleLimit); } 00091 00093 00094 vtkSetMacro(MinValue, double); 00095 vtkGetMacro(MinValue, double); 00096 vtkSetMacro(MaxValue, double); 00097 vtkGetMacro(MaxValue, double); 00099 00101 00103 vtkGetMacro(NumberOfPointsSplatted, int); 00105 00109 void SetSplatConnection(vtkAlgorithmOutput*); 00110 00111 protected: 00112 vtkFastSplatter(); 00113 virtual ~vtkFastSplatter(); 00114 00115 double ModelBounds[6]; 00116 int OutputDimensions[3]; 00117 00118 int LimitMode; 00119 double MinValue; 00120 double MaxValue; 00121 double FrozenScale; 00122 00123 vtkImageData *Buckets; 00124 00125 virtual int FillInputPortInformation(int port, vtkInformation *info); 00126 virtual int RequestInformation(vtkInformation *, 00127 vtkInformationVector **, 00128 vtkInformationVector *); 00129 virtual int RequestUpdateExtent(vtkInformation*, 00130 vtkInformationVector**, 00131 vtkInformationVector*); 00132 virtual int RequestData(vtkInformation *, 00133 vtkInformationVector **, 00134 vtkInformationVector *); 00135 00136 // Used internally for converting points in world space to indices in 00137 // the output image. 00138 double Origin[3]; 00139 double Spacing[3]; 00140 00141 // This is updated every time the filter executes 00142 int NumberOfPointsSplatted; 00143 00144 // Used internally to track the data range. When the limit mode is 00145 // set to FreezeScale, the data will be scaled as if this were the 00146 // range regardless of what it actually is. 00147 double LastDataMinValue; 00148 double LastDataMaxValue; 00149 00150 private: 00151 vtkFastSplatter(const vtkFastSplatter &); // Not implemented 00152 void operator=(const vtkFastSplatter &); // Not implemented 00153 }; 00154 00155 //BTX 00156 00157 //----------------------------------------------------------------------------- 00158 00159 template<class T> 00160 void vtkFastSplatterClamp(T *array, vtkIdType arraySize, 00161 T minValue, T maxValue) 00162 { 00163 for (vtkIdType i = 0; i < arraySize; i++) 00164 { 00165 if (array[i] < minValue) array[i] = minValue; 00166 if (array[i] > maxValue) array[i] = maxValue; 00167 } 00168 } 00169 00170 //----------------------------------------------------------------------------- 00171 00172 template<class T> 00173 void vtkFastSplatterScale(T *array, int numComponents, vtkIdType numTuples, 00174 T minValue, T maxValue, 00175 double *dataMinValue, double *dataMaxValue) 00176 { 00177 T *a; 00178 T min, max; 00179 *dataMinValue = 0; 00180 *dataMaxValue = 0; 00181 vtkIdType t; 00182 for (int c = 0; c < numComponents; c++) 00183 { 00184 // Find the min and max values in the array. 00185 a = array+c; 00186 min = max = *a; 00187 a += numComponents; 00188 for (t = 1; t < numTuples; t++, a += numComponents) 00189 { 00190 if (min > *a) min = *a; 00191 if (max < *a) max = *a; 00192 } 00193 00194 // Bias everything so that 0 is really the minimum. 00195 if (min != 0) 00196 { 00197 for (t = 0, a = array+c; t < numTuples; t++, a += numComponents) 00198 { 00199 *a -= min; 00200 } 00201 } 00202 00203 // Scale the values. 00204 if (max != min) 00205 { 00206 for (t = 0, a = array+c; t < numTuples; t++, a += numComponents) 00207 { 00208 *a = ((maxValue-minValue)*(*a))/(max-min); 00209 } 00210 } 00211 00212 // Bias everything again so that it lies in the correct range. 00213 if (minValue != 0) 00214 { 00215 for (t = 0, a = array+c; t < numTuples; t++, a += numComponents) 00216 { 00217 *a += minValue; 00218 } 00219 } 00220 if (c == 0) 00221 { 00222 *dataMinValue = min; 00223 *dataMaxValue = max; 00224 } 00225 } 00226 } 00227 00228 00229 //----------------------------------------------------------------------------- 00230 00231 template<class T> 00232 void vtkFastSplatterFrozenScale(T *array, 00233 int numComponents, vtkIdType numTuples, 00234 T minValue, T maxValue, 00235 double min, double max) 00236 { 00237 T *a; 00238 00239 vtkIdType t; 00240 for (int c = 0; c < numComponents; c++) 00241 { 00242 // Bias everything so that 0 is really the minimum. 00243 if (min != 0) 00244 { 00245 for (t = 0, a = array+c; t < numTuples; t++, a += numComponents) 00246 { 00247 *a -= static_cast<T>(min); 00248 } 00249 } 00250 00251 // Scale the values. 00252 if (max != min) 00253 { 00254 for (t = 0, a = array+c; t < numTuples; t++, a += numComponents) 00255 { 00256 *a = static_cast<T>(((maxValue-minValue)*(*a))/(max-min)); 00257 } 00258 } 00259 00260 // Bias everything again so that it lies in the correct range. 00261 if (minValue != 0) 00262 { 00263 for (t = 0, a = array+c; t < numTuples; t++, a += numComponents) 00264 { 00265 *a += minValue; 00266 } 00267 } 00268 } 00269 } 00270 00271 //ETX 00272 00273 #endif //__vtkFastSplatter_h