fshake3d  0.0.1
FreeformDensity3DSurfaceEditor
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
scene_ElevationGrid.hpp
Go to the documentation of this file.
00001 #ifndef SCENE_ELEVATION_GRID_HPP
00002 #define SCENE_ELEVATION_GRID_HPP
00003 
00004 #include "math.hpp"
00005 #include "scene.hpp"
00006 
00007 class ElevationGrid
00008 {
00009 public:
00010   ElevationGrid(int xsteps=20, int ysteps=20
00011     , const Vec2d& xlimits=Vec2d(-1,1)
00012     , const Vec2d& ylimits=Vec2d(-1,1) 
00013   )
00014     : mXLimits(xlimits)
00015     , mYLimits(ylimits)
00016     , mXSteps(xsteps)
00017     , mYSteps(ysteps)
00018   {    
00019     mSize = Vec2d( mXLimits[1] - mXLimits[0], mYLimits[1] - mYLimits[0] );
00020     size_t n = xsteps*ysteps;
00021     mPositions.resize(n);
00022     initGrid();
00023     mNormals.resize(n);
00024     computeNormals();
00025   }  
00026 
00027   // draw methods
00028 
00029   void drawPoints();
00030   void drawPointLists(int listid);
00031   void drawQuadStrips();
00032   void drawQuadStripNormals();
00033   void drawQuadStripNormalT1D();
00034   void drawGrid();
00035   void drawNormalLines(double s);
00036   void initGrid();
00037 
00038   // intersection
00039 
00040   bool intersect(const Rayd& pickRay, int& hitindex_x, int& hitindex_y, double hitRadius);
00041   bool intersectNearest(const Rayd& pickRay, int& hitindex_x, int& hitindex_y, double hitRadius);
00042 
00043   // get grid point by index
00044 
00045   inline const Point3d& getPoint (int ix, int iy) const
00046   {
00047     return mPositions[ ix+iy*mXSteps ];
00048   }
00049   inline const Vec3d& getNormal(int ix, int iy) const
00050   {
00051     return mNormals[ ix+iy*mXSteps ];
00052   }
00053 
00054   // modification
00055 
00056   virtual void updatePositionZ(int ix, int iy, double pos_Z) { mPositions[ iy*mXSteps+ix ][2] = pos_Z; }
00057 
00058   // compute normals
00059 
00060   void computeNormals();
00061 
00062   // attributes
00063 
00064   Vec2d getSize()    const { return mSize; }
00065   int   getXSteps()  const { return mXSteps; }
00066   int   getYSteps()  const { return mYSteps; }
00067   Vec2d getXLimits() const { return mXLimits; }
00068   Vec2d getYLimits() const { return mYLimits; }
00069 
00070 protected:
00071   Vec2d mXLimits;
00072   Vec2d mYLimits;
00073   Vec2d mSize;
00074   int   mXSteps;
00075   int   mYSteps;
00076   std::vector<Point3d> mPositions;
00077   std::vector<Vec3d>   mNormals;
00078 };
00079 
00080 #endif // SCENE_ELEVATION_GRID_HPP
00081