Segment.h

00001 // This file may be redistributed and modified only under the terms of
00002 // the GNU General Public License (See COPYING for details).
00003 // Copyright (C) 2003 Alistair Riddoch, Damien McGinnes
00004 
00005 #ifndef MERCATOR_SEGMENT_H
00006 #define MERCATOR_SEGMENT_H
00007 
00008 #include <Mercator/Mercator.h>
00009 #include <Mercator/Matrix.h>
00010 #include <Mercator/BasePoint.h>
00011 
00012 #include <wfmath/vector.h>
00013 #include <wfmath/axisbox.h>
00014 
00015 #include <list>
00016 #include <map>
00017 
00018 namespace Mercator {
00019 
00020 class Terrain;
00021 class Surface;
00022 class TerrainMod;
00023 typedef std::list<TerrainMod *> ModList;
00024 class Area;
00025 
00026 // This class will need to be reference counted if we want the code to
00027 // be able to hold onto it, as currently they get deleted internally
00028 // whenever height points are asserted.
00029 
00032 class Segment {
00033   public:
00035     typedef std::map<int, Surface *> Surfacestore;
00036     
00037     typedef std::multimap<int, Area *> Areastore;
00038   private:
00040     const int m_res;
00042     const int m_size;
00044     const int m_xRef;
00046     const int m_yRef;
00048     Matrix<2, 2, BasePoint> m_controlPoints;
00050     float * m_points;
00052     float * m_normals;
00054     float m_max;
00056     float m_min;
00057 
00059     Surfacestore m_surfaces;
00060     
00062     Areastore m_areas;
00063   public:
00064     explicit Segment(int x, int y, unsigned int resolution);
00065     ~Segment();
00066 
00068     const int getResolution() const {
00069         return m_res;
00070     }
00071 
00073     const int getSize() const {
00074         return m_size;
00075     }
00076 
00078     const int getXRef() const {
00079         return m_xRef;
00080     }
00081 
00083     const int getYRef() const {
00084         return m_yRef;
00085     }
00086 
00090     const bool isValid() const {
00091         return (m_points != 0);
00092     }
00093 
00098     void setMinMax(float min, float max) {
00099         m_min = min;
00100         m_max = max;
00101     }
00102 
00103     void invalidate(bool points = true);
00104 
00111     void setCornerPoint(unsigned int x, unsigned int y, const BasePoint & bp) {
00112         m_controlPoints(x, y) = bp;
00113         invalidate();
00114     }
00115     
00117     const Matrix<2, 2, BasePoint> & getControlPoints() const {
00118         return m_controlPoints;
00119     }
00120 
00122     Matrix<2, 2, BasePoint> & getControlPoints() {
00123         return m_controlPoints;
00124     }
00125 
00127     const Surfacestore & getSurfaces() const {
00128         return m_surfaces;
00129     }
00130 
00132     Surfacestore & getSurfaces() {
00133         return m_surfaces;
00134     }
00135 
00137     const float * getPoints() const {
00138         return m_points;
00139     }
00140 
00142     float * getPoints() {
00143         return m_points;
00144     }
00145 
00147     const float * getNormals() const {
00148         return m_normals;
00149     }
00150 
00152     float * getNormals() {
00153         return m_normals;
00154     }
00155 
00157     float get(int x, int y) const {
00158         return m_points[y * (m_res + 1) + x];
00159     }
00160 
00161     void getHeightAndNormal(float x, float y, float &h, 
00162                     WFMath::Vector<3> &normal) const;
00163 
00164     void populate();
00165     void populateNormals();
00166     void populateSurfaces();
00167 
00169     float getMax() const { return m_max; }
00171     float getMin() const { return m_min; }
00172 
00174     WFMath::AxisBox<2> getRect() const;
00175 
00177     WFMath::AxisBox<3> getBox() const;
00178 
00179     void addMod(TerrainMod *t);
00180     void clearMods();
00181     
00182     const Areastore& getAreas() const
00183     { return m_areas; }
00184     
00185     void addArea(Area* a);
00186     void clearAreas();
00187   private:
00192     void checkMaxMin(float h) { 
00193         if (h<m_min) {
00194             m_min=h;
00195         }
00196         if (h>m_max) {
00197             m_max=h;
00198         }
00199     } 
00200 
00201     void fill1d(const BasePoint& l, const BasePoint &h, float *array) const;
00202 
00203     void fill2d(const BasePoint& p1, const BasePoint& p2, 
00204                 const BasePoint& p3, const BasePoint& p4);
00205 
00206     float qRMD(float nn, float fn, float ff, float nf, 
00207                float roughness, float falloff, int depth) const;
00208 
00209     bool clipToSegment(const WFMath::AxisBox<2> &bbox, int &lx, int &hx, int &ly, int &hy);
00210 
00211     void applyMod(TerrainMod *t);
00212 
00213     void invalidateSurfaces();
00214 
00216     ModList m_modList;
00217 
00218 };
00219 
00220 } // namespace Mercator
00221 
00222 #endif // MERCATOR_SEGMENT_H

Generated on Wed Sep 12 22:21:35 2007 for Mercator by  doxygen 1.5.2