00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _PHYSICS_HEIGHTFIELD_
00026 #define _PHYSICS_HEIGHTFIELD_
00027
00028 #include <base/base>
00029 #include <base/VFile>
00030 #include <base/path_not_found>
00031 #include <base/io_error>
00032
00033 #include <valarray>
00034
00035
00036 namespace physics {
00037
00038
00039 class HeightField : public base::ReferencedObject
00040 {
00041 public:
00042 HeightField();
00043 HeightField(const HeightField& heightfield);
00044 HeightField(Int nx, Int ny, Real dx, Real dy) throw(std::invalid_argument);
00045 HeightField(ref<base::VFile> file) throw(std::invalid_argument, base::io_error);
00046 virtual ~HeightField();
00047
00048 virtual String className() const { return String("HeightField"); }
00049 virtual base::Object& clone() const { return *NewNamedObj(className()) HeightField(*this); }
00050
00051 Real& height(Real x, Real y) throw(std::out_of_range);
00052 const Real& height(Real x, Real y) const throw(std::out_of_range);
00053 Real& at(Real x, Real y) throw(std::out_of_range) { return height(x,y); }
00054 const Real& at(Real x, Real y) const throw(std::out_of_range) { return height(x,y); }
00055
00056
00057 Real& height(Int xi, Int yi) throw() { return (*hf)[yi*_nx+xi]; }
00058 const Real& height(Int xi, Int yi) const throw() { return (*hf)[yi*_nx+xi]; }
00059 Real operator[](Int i) const throw() { return (*hf)[i]; }
00060 Real& operator[](Int i) throw() { return (*hf)[i]; }
00061
00062 Real dx() const throw() { return _dx; }
00063 Real dy() const throw() { return _dy; }
00064 Int nx() const throw() { return _nx; }
00065 Int ny() const throw() { return _ny; }
00066 Real xsize() const throw() { return (_nx-1)*_dx; }
00067 Real ysize() const throw() { return (_ny-1)*_dy; }
00068
00069 void setResolution(Real dx, Real dy) throw(std::invalid_argument);
00070
00071 void load(ref<base::VFile> file) throw(std::invalid_argument, base::io_error);
00072 void save(ref<base::VFile> file) throw(std::invalid_argument, base::io_error);
00073
00074 void scale(Real s);
00075 void scaleHeights(Real s);
00076 Real maxHeight();
00077 Real minHeight();
00078
00079 protected:
00080 Int _nx, _ny;
00081 Real _dx, _dy;
00082 std::valarray<Real>* hf;
00083
00084 void loadDATFile(std::istream& in) throw(base::io_error);
00085 void loadTHFFile(std::istream& in) throw(base::io_error);
00086 };
00087
00088 }
00089
00090 #endif