Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

physics/HeightField

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: HeightField 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
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   // fast, unchecked and unmapped access
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 } // physics
00089 
00090 #endif

Generated on Thu Jul 29 15:56:23 2004 for OpenSim by doxygen 1.3.6