00001
00010 #ifndef CUBOIDGRIDOBJECTPOPULATION_H_
00011 #define CUBOIDGRIDOBJECTPOPULATION_H_
00012
00013 #include "SpatialSimObjectPopulation.h"
00014
00016
00019 class CuboidGridObjectPopulation : public SpatialSimObjectPopulation {
00020 public:
00021
00022 typedef enum { X = 0, Y = 1, Z = 2 } CoordinateIndex;
00023
00024 CuboidGridObjectPopulation(SimNetwork &net, GridPoint3D origin, Volume3DSize dims, SimObjectFactory &objFactory);
00025
00026 CuboidGridObjectPopulation(SimNetwork &net, GridPoint3D origin, Volume3DSize dims, SimObject::ID::Vector vec);
00027
00028 GridPoint3D & getOrigin() {
00029 return origin;
00030 };
00031
00032
00034 virtual Point3D<double> getLocation( size_t index ) const {
00035 GridPoint3D p = origin + getRelativeLocation(index);
00036 return Point3D<double>( p.x(), p.y(), p.z() );
00037 };
00038
00039 GridPoint3D getRelativeLocation(size_t idx) const {
00040 div_t xy = div(idx, dim[Y] * dim[Z]);
00041 div_t yz = div(xy.rem, dim[Z]);
00042 return GridPoint3D(xy.quot, yz.quot, yz.rem);
00043 };
00044
00045 SimObject::ID operator() (int x, int y, int z) const {
00046 return (SimObject::ID)(*id_vec)[dim[Y]*dim[Z]*x + dim[Z]*y + z];
00047 };
00048
00049 SimObject::ID operator() (const GridPoint3D &loc) const {
00050 return (SimObject::ID)(*id_vec)[dim[Y]*dim[Z]*loc.x() + dim[Z]*loc.y() + loc.z()];
00051 };
00052
00053 int getIndex(int x, int y, int z) const {
00054 return dim[Y]*dim[Z]*x + dim[Z]*y + z;
00055 };
00056
00057 int getIndex(const GridPoint3D &loc) const {
00058 return dim[Y]*dim[Z]*loc.x() + dim[Z]*loc.y() + loc.z();
00059 }
00060
00061 SimObject::ID operator() (int idx) const {
00062 return (SimObject::ID)((*id_vec)[idx]);
00063 };
00064
00065 SimObject::ID atRelative(int x, int y, int z) const {
00066 return (SimObject::ID)(*id_vec)[dim[Y]*dim[Z]*x + dim[Z]*y + z];
00067 };
00068
00069 SimObject::ID at(int x, int y, int z) const {
00070 return at(x - origin.x(), y - origin.y(), z - origin.z());
00071 };
00072
00073 CuboidGridObjectPopulation subVolume(int origX, int origY, int origZ,
00074 int Xdim, int Ydim, int Zdim) const;
00075
00076 CuboidGridObjectPopulation subVolume(const GridPoint3D &origin, const Volume3DSize & size) const;
00077
00078 const Volume3DSize & getDimensions() const {
00079 return dim;
00080 }
00081
00082
00083 protected:
00084 GridPoint3D origin;
00085 Volume3DSize dim;
00086
00087 };
00088
00089
00090 #endif