Density.H

Go to the documentation of this file.
00001 // $Revision: 1.21 $  $Author: schwehr $  $Date: 2004/11/03 00:29:22 $
00002 /*
00003     Copyright (C) 2004  Kurt Schwehr
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 */
00020 
00021 #ifndef _DENSITY_H_
00022 #define _DENSITY_H_
00023 
00024 #include <vector>
00025 #include <string>
00026 
00030 
00031 
00032 
00039 
00040 enum PackType {PACK_SCALE, PACK_CLIP, PACK_WRAP};
00041 
00042 
00047 
00053 class Density {
00054 public:
00058   Density();
00059 
00067   Density(const size_t width, const size_t height, const size_t depth,
00068           const float minX, const float maxX,
00069           const float minY, const float maxY,
00070           const float minZ, const float maxZ
00071           );
00072 
00078   Density(const std::string &filename, bool &ok);
00079 
00087   void resize(const size_t width, const size_t height, const size_t depth,
00088               const float minX, const float maxX,
00089               const float minY, const float maxY,
00090               const float minZ, const float maxZ
00091               );
00092 
00093 
00094 
00099   void rescale(const float minX, const float maxX,
00100                const float minY, const float maxY,
00101                const float minZ, const float maxZ
00102               );
00103 
00104 
00107   bool addPoint(const float x, const float y, const float z);
00109   void addPoints(const size_t index,const size_t count) {assert(isValidCell(index)); counts[index]+=count; totalPointsInside+=count;}
00111   void printCellCounts() const;
00112   size_t getWidth()  const {return (width);} 
00113   size_t getHeight() const {return (height);} 
00114   size_t getDepth()  const {return (depth);} 
00115   size_t getSize() const {return (counts.size());} 
00116 
00118   size_t getCountInside() const {return(totalPointsInside);}
00122   size_t getCountOutside() const {return(totalPointsOutside);}
00123 
00126   size_t getCell(const float x, const float y, const float z) const;
00127   bool   isValidCell(const size_t i) const {return(i<counts.size()?true:false);}
00128   size_t getCellX(const float x) const {return(size_t((x-xR[0])/dx));}
00129   size_t getCellY(const float y) const {return(size_t((y-yR[0])/dy));}
00130   size_t getCellZ(const float z) const {return(size_t((z-zR[0])/dz));}
00131   void   getCellXYZ(const size_t index, size_t &cx, size_t &cy, size_t &cz) const;
00132   size_t getCellFromWHD(const size_t xIndex, const size_t yIndex, const size_t zIndex) const;
00133 
00134 
00137   enum NeighborEnum {LEFT,RIGHT,FRONT,BACK,BELOW,ABOVE,NUM_NEIGHBORS=6};
00139   size_t getCellNeighbor(const size_t i, NeighborEnum which) const; 
00140 
00142   void getCellCenter(const size_t cellNum, float &x, float &y, float &z) const;
00143 
00145   size_t getCellCount(size_t i) const{assert(isValidCell(i));return(counts[i]);}
00146 
00147 
00148   float getDX() const {return(dx);}  
00149   float getDY() const {return(dy);}  
00150   float getDZ() const {return(dz);}  
00151 
00155   bool writeVolScale(const std::string &filename) const;
00156 
00158   size_t scaleValue(const size_t value, const PackType p, const size_t bitsPerVoxel) const;
00159 
00164   bool writeVol(const std::string &filename,const size_t bitsPerPixel,const PackType p) const;
00165 
00179   bool writeVol(const std::string &filename,
00180                        const size_t bitsPerVoxel,const PackType p,
00181                        const float scaleX, const float scaleY, const float scaleZ,
00182                        const float rotX=0.f, const float rotY=0.f,const float rotZ=0.f
00183                 ) const;
00184 
00185 
00187   static size_t badValue() {return(std::numeric_limits<size_t>::max());}
00188 
00190   unsigned char scaleCount(const size_t i, const size_t min, const size_t max) const;
00191 
00195   bool buildCDF(std::vector<float> &cdfpercent) const;
00196 
00197 private:
00198   // Computing min/max doesn't change the object, so mutable
00199   mutable bool stale; 
00200   mutable size_t maxCache, minCache;
00203   void invalidateCache() {stale=true; maxCache=minCache=badValue();}
00204   void computeMinMax() const;
00205 
00206 public:
00207 
00208   size_t getMaxCount() const; 
00209   size_t getMinCount() const; 
00210 
00211 
00212 #ifndef REGRESSION_TEST
00213 private:
00214 #endif
00215   //size_t cellSize[3]; 
00216   size_t width;  
00217   size_t height; 
00218   size_t depth;  
00219 
00220   float dx; 
00221   float dy; 
00222   float dz; 
00223 
00224   float xR[2]; 
00225   float yR[2]; 
00226   float zR[2]; 
00227 
00228   std::vector<size_t> counts; 
00229   size_t totalPointsInside; 
00230   size_t totalPointsOutside; 
00231 };
00232 #endif // _DENSITY_H_

Generated on Thu Mar 2 17:55:25 2006 for density by  doxygen 1.4.6