VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Imaging/Hybrid/vtkFastSplatter.h
Go to the documentation of this file.
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 "vtkImagingHybridModule.h" // For export macro
00051 #include "vtkImageAlgorithm.h"
00052 
00053 class VTKIMAGINGHYBRID_EXPORT vtkFastSplatter : public vtkImageAlgorithm
00054 {
00055 public:
00056   vtkTypeMacro(vtkFastSplatter, vtkImageAlgorithm);
00057   static vtkFastSplatter *New();
00058   virtual void PrintSelf(ostream &os, vtkIndent indent);
00059 
00061 
00065   vtkSetVector6Macro(ModelBounds,double);
00066   vtkGetVectorMacro(ModelBounds,double,6);
00068 
00070 
00071   vtkSetVector3Macro( OutputDimensions, int );
00072   vtkGetVector3Macro( OutputDimensions, int );
00074 
00075 //BTX
00076   enum { NoneLimit, ClampLimit, ScaleLimit, FreezeScaleLimit };
00077 //ETX
00078 
00080 
00085   vtkSetMacro(LimitMode, int);
00086   vtkGetMacro(LimitMode, int);
00087   void SetLimitModeToNone() { this->SetLimitMode(NoneLimit); }
00088   void SetLimitModeToClamp() { this->SetLimitMode(ClampLimit); }
00089   void SetLimitModeToScale() { this->SetLimitMode(ScaleLimit); }
00090   void SetLimitModeToFreezeScale() { this->SetLimitMode(FreezeScaleLimit); }
00092 
00094 
00095   vtkSetMacro(MinValue, double);
00096   vtkGetMacro(MinValue, double);
00097   vtkSetMacro(MaxValue, double);
00098   vtkGetMacro(MaxValue, double);
00100 
00102 
00104   vtkGetMacro(NumberOfPointsSplatted, int);
00106 
00110   void SetSplatConnection(vtkAlgorithmOutput*);
00111 
00112 protected:
00113   vtkFastSplatter();
00114   virtual ~vtkFastSplatter();
00115 
00116   double ModelBounds[6];
00117   int OutputDimensions[3];
00118 
00119   int LimitMode;
00120   double MinValue;
00121   double MaxValue;
00122   double FrozenScale;
00123 
00124   vtkImageData *Buckets;
00125 
00126   virtual int FillInputPortInformation(int port, vtkInformation *info);
00127   virtual int RequestInformation(vtkInformation *,
00128                                  vtkInformationVector **,
00129                                  vtkInformationVector *);
00130   virtual int RequestUpdateExtent(vtkInformation*,
00131                                   vtkInformationVector**,
00132                                   vtkInformationVector*);
00133   virtual int RequestData(vtkInformation *,
00134                           vtkInformationVector **,
00135                           vtkInformationVector *);
00136 
00137   // Used internally for converting points in world space to indices in
00138   // the output image.
00139   double Origin[3];
00140   double Spacing[3];
00141 
00142   // This is updated every time the filter executes
00143   int NumberOfPointsSplatted;
00144 
00145   // Used internally to track the data range.  When the limit mode is
00146   // set to FreezeScale, the data will be scaled as if this were the
00147   // range regardless of what it actually is.
00148   double LastDataMinValue;
00149   double LastDataMaxValue;
00150 
00151 private:
00152   vtkFastSplatter(const vtkFastSplatter &); // Not implemented
00153   void operator=(const vtkFastSplatter &); // Not implemented
00154 };
00155 
00156 //BTX
00157 
00158 //-----------------------------------------------------------------------------
00159 
00160 template<class T>
00161 void vtkFastSplatterClamp(T *array, vtkIdType arraySize,
00162                           T minValue, T maxValue)
00163 {
00164   for (vtkIdType i = 0; i < arraySize; i++)
00165     {
00166     if (array[i] < minValue) array[i] = minValue;
00167     if (array[i] > maxValue) array[i] = maxValue;
00168     }
00169 }
00170 
00171 //-----------------------------------------------------------------------------
00172 
00173 template<class T>
00174 void vtkFastSplatterScale(T *array, int numComponents, vtkIdType numTuples,
00175                           T minValue, T maxValue,
00176                           double *dataMinValue, double *dataMaxValue)
00177 {
00178   T *a;
00179   T min, max;
00180   *dataMinValue = 0;
00181   *dataMaxValue = 0;
00182   vtkIdType t;
00183   for (int c = 0; c < numComponents; c++)
00184     {
00185     // Find the min and max values in the array.
00186     a = array+c;
00187     min = max = *a;
00188     a += numComponents;
00189     for (t = 1; t < numTuples; t++, a += numComponents)
00190       {
00191       if (min > *a) min = *a;
00192       if (max < *a) max = *a;
00193       }
00194 
00195     // Bias everything so that 0 is really the minimum.
00196     if (min != 0)
00197       {
00198       for (t = 0, a = array+c; t < numTuples; t++, a += numComponents)
00199         {
00200         *a -= min;
00201         }
00202       }
00203 
00204     // Scale the values.
00205     if (max != min)
00206       {
00207       for (t = 0, a = array+c; t < numTuples; t++, a += numComponents)
00208         {
00209         *a = ((maxValue-minValue)*(*a))/(max-min);
00210         }
00211       }
00212 
00213     // Bias everything again so that it lies in the correct range.
00214     if (minValue != 0)
00215       {
00216       for (t = 0, a = array+c; t < numTuples; t++, a += numComponents)
00217         {
00218         *a += minValue;
00219         }
00220       }
00221     if (c == 0)
00222       {
00223       *dataMinValue = min;
00224       *dataMaxValue = max;
00225       }
00226     }
00227 }
00228 
00229 
00230 //-----------------------------------------------------------------------------
00231 
00232 template<class T>
00233 void vtkFastSplatterFrozenScale(T *array,
00234                                 int numComponents, vtkIdType numTuples,
00235                                 T minValue, T maxValue,
00236                                 double min, double max)
00237 {
00238   T *a;
00239 
00240   vtkIdType t;
00241   for (int c = 0; c < numComponents; c++)
00242     {
00243     // Bias everything so that 0 is really the minimum.
00244     if (min != 0)
00245       {
00246       for (t = 0, a = array+c; t < numTuples; t++, a += numComponents)
00247         {
00248         *a -= static_cast<T>(min);
00249         }
00250       }
00251 
00252     // Scale the values.
00253     if (max != min)
00254       {
00255       for (t = 0, a = array+c; t < numTuples; t++, a += numComponents)
00256         {
00257         *a = static_cast<T>(((maxValue-minValue)*(*a))/(max-min));
00258         }
00259       }
00260 
00261     // Bias everything again so that it lies in the correct range.
00262     if (minValue != 0)
00263       {
00264       for (t = 0, a = array+c; t < numTuples; t++, a += numComponents)
00265         {
00266         *a += minValue;
00267         }
00268       }
00269     }
00270 }
00271 
00272 //ETX
00273 
00274 #endif //vtkFastSplatter_h