UniformGrid3D.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005-2006 Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved  @@
00005 //
00006 #ifndef _UNIFORMGRID3D_H_20050124_1703
00007 #define _UNIFORMGRID3D_H_20050124_1703
00008 
00009 #include "point.h"
00010 #include <DataStructs/DiscreteValueVect.h>
00011 #include "Grid3D.h"
00012 #include <iostream>
00013 namespace RDGeom {
00014   class UniformGrid3D : public Grid3D {
00015   
00016   public:
00017        
00018     //! \brief ctor
00019     /*
00020         \param dimX:    the x dimension of the grid, in Angstroms
00021         \param dimY:    the y dimension of the grid, in Angstroms
00022         \param dimZ:    the z dimension of the grid, in Angstroms
00023         \param spacing: the grid spacing, in Angstroms
00024         \param valType: the data type of the grid (determines the number of bits
00025                         per point)
00026         \param offset:  OPTIONAL: the offset of the grid from (0,0,0), in Angstroms.
00027 
00028         \b Note: the values of arguments such as \c dimX and \c spacing
00029         don't actually need to be in Angstroms, but they should be internally
00030         consistent.
00031         
00032     */
00033     UniformGrid3D(double dimX, double dimY, double dimZ, double spacing=0.5,
00034                   RDKit::DiscreteValueVect::DiscreteValueType valType=RDKit::DiscreteValueVect::TWOBITVALUE,
00035                   const RDGeom::Point3D *offset=0){
00036       if (offset == 0) {
00037         initGrid(dimX, dimY, dimZ, spacing, valType,
00038                  Point3D(-0.5*dimX, -0.5*dimY, -0.5*dimZ));
00039       } else {
00040         initGrid(dimX, dimY, dimZ, spacing, valType, *offset);
00041       }
00042     }
00043     //! copy ctor
00044     UniformGrid3D(const UniformGrid3D &other);
00045     //! construct from a string pickle
00046     UniformGrid3D(const std::string pkl);
00047     //! construct from a text pickle
00048     UniformGrid3D(const char *pkl,unsigned int);
00049 
00050     ~UniformGrid3D();
00051 
00052     //! \brief Get the index of the grid point closest to point
00053     //!
00054     //! \return the integer index, -1 if the specified point is outside the grid
00055     int getGridPointIndex(const Point3D &point) const;
00056 
00057     //! \brief Get the value at the grid point closest to the specified point
00058     //!
00059     //! \return the integer value, -1 if the specified index is outside the grid
00060     int getVal(const Point3D &point) const;
00061 
00062     //! \brief Get the value at a specified grid point
00063     //!
00064     //! \return the unsigned integer value
00065     unsigned int getVal(unsigned int pointId) const;
00066 
00067     //! \brief Set the value at the grid point closest to the specified point
00068     //!
00069     //! doesn't do anything if the point is outside the grid 
00070     void setVal(const Point3D &point, unsigned int val);
00071 
00072     //! \brief get the location of the specified grid point
00073     Point3D getGridPointLoc(unsigned int pointId) const;
00074 
00075     //! \brief Set the value at the specified grid point 
00076     void setVal(unsigned int pointId, unsigned int val);
00077 
00078     //! \brief get the size of the grid (number of grid points)
00079     unsigned int getSize() const { return d_numX*d_numY*d_numZ; };
00080 
00081     //! \brief set the occupancy for a multi-layered sphere
00082     /*!
00083       This function encodes the occupancy for a sphere and multiple layers around it
00084       \param center              location of the sphere center
00085       \param radius              Radius of the base sphere
00086       \param stepSize            thickness of each layer on top of the base sphere
00087       \param maxNumLayers        maximum number of layers, if -1 this is determined by
00088                                  the number of bits used per grid points in the storage
00089       \param ignoreOutOfBound    if true, ignore if center is outside the grid, otherwise throw
00090                                  an exception
00091       
00092     */
00093     void setSphereOccupancy(const Point3D & center, double radius, 
00094                             double stepSize, int maxNumLayers=-1, 
00095                             bool ignoreOutOfBound=true);
00096 
00097     //! \brief get the index of the grid point given the x, y, z indices
00098     //!
00099     //! \return the integer value, -1 if the indices are outside the grid
00100     int getGridIndex(unsigned int xi, unsigned int yi, unsigned int zi) const;
00101 
00102     //! \brief get the number of grid points along x-axis
00103     unsigned int getNumX() const { return d_numX; };
00104 
00105     //! \brief get the number of grid points along y-axis
00106     unsigned int getNumY() const { return d_numY; };
00107 
00108     //! \brief get the number of grid points along z-axis
00109     unsigned int getNumZ() const { return d_numZ; };
00110 
00111     //! \brief get the grid's offset
00112     const Point3D &getOffset() const { return d_offSet; };
00113 
00114     //! \brief get the grid's spacing
00115     double getSpacing() const { return d_spacing; };
00116 
00117     //! \brief return a \b const pointer to our occupancy vector
00118     const RDKit::DiscreteValueVect *getOccupancyVect() const { return dp_storage;} ;
00119 
00120     //! \brief returns true if the grid \c other has parameters
00121     //!        compatible with ours.
00122     virtual bool compareParams(const UniformGrid3D &other) const;
00123     //! \brief calculates the union between the data on this grid and
00124     //!  that on \c other.
00125     //!  This grid is modified.
00126     //!  NOTE that the grids must have the same parameters.   
00127     UniformGrid3D &operator|=(const UniformGrid3D &other);
00128     //! \brief calculates the intersection between the data on this grid and
00129     //!  that on \c other.
00130     //!  This grid is modified.
00131     //!  NOTE that the grids must have the same parameters.   
00132     UniformGrid3D &operator&=(const UniformGrid3D &other);
00133     //! \brief calculates the sum of the data on this grid and
00134     //!  that on \c other.
00135     //!  This grid is modified.
00136     //!  NOTE that the grids must have the same parameters.   
00137     UniformGrid3D &operator+=(const UniformGrid3D &other);
00138     //! \brief calculates the difference between the data on this grid and
00139     //!  that on \c other.
00140     //!  This grid is modified.
00141     //!  NOTE that the grids must have the same parameters.   
00142     UniformGrid3D &operator-=(const UniformGrid3D &other);
00143 
00144     //! \brief create and return a pickle
00145     std::string toString() const;
00146 
00147     UniformGrid3D operator& (const UniformGrid3D &other) const{
00148       PRECONDITION(dp_storage,"bad storage");
00149       PRECONDITION(compareParams(other),"mismatched params");
00150       UniformGrid3D res(d_numX*d_spacing,d_numY*d_spacing,d_numZ*d_spacing,
00151                         d_spacing,dp_storage->getValueType(),&d_offSet);
00152       
00153     };
00154     
00155   private:
00156     //! \brief internal initialization code
00157     /*
00158         \param dimX:    the x dimension of the grid, in Angstroms
00159         \param dimY:    the y dimension of the grid, in Angstroms
00160         \param dimZ:    the z dimension of the grid, in Angstroms
00161         \param spacing: the grid spacing, in Angstroms
00162         \param valType: the data type of the grid (determines the number of bits
00163                         per point)
00164         \param offset:  the offset of the grid from (0,0,0), in Angstroms.
00165         \param data:    (optional) a pointer to a DiscreteValueVect to use, we take 
00166                         ownership of the pointer.
00167     */
00168     void initGrid(double dimX, double dimY, double dimZ, double spacing,
00169                   RDKit::DiscreteValueVect::DiscreteValueType valType,
00170                   const RDGeom::Point3D &offSet,RDKit::DiscreteValueVect *data=0);
00171     unsigned int d_numX, d_numY, d_numZ; //! number of grid points along x, y, z axes
00172     double d_spacing; //! grid spacing
00173     Point3D d_offSet; //! the grid offset (from the origin)
00174     RDKit::DiscreteValueVect *dp_storage; //! storage for values at each grid point
00175 
00176     //! \brief construct from a pickle
00177     void initFromText(const char *pkl,const unsigned int length);
00178 
00179   };
00180 
00181   //! \brief writes the contents of the grid to a stream
00182   /*
00183     The grid is written in GRD format
00184   */
00185   void writeGridToStream(const UniformGrid3D &grid, std::ostream &outStrm);
00186 
00187   //! \brief writes the contents of the grid to a named file
00188   /*
00189     The grid is written in GRD format
00190   */
00191   void writeGridToFile(const UniformGrid3D &grid, std::string filename);
00192 
00193 }
00194 
00195 #endif
00196 

Generated on Sat May 24 08:36:32 2008 for RDCode by  doxygen 1.5.3