00001
00002
00003
00004 #ifndef TE_PATCH_H
00005 #define TE_PATCH_H
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00041 #include <Inventor/SbLinear.h>
00042 #include <Inventor/SbBox2f.h>
00043
00044 class SoSeparator;
00045 class TeHeightMap;
00046 class TeEngine;
00047
00067 class TePatch {
00068
00069 friend class TeEngine;
00070
00071 public:
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00085 enum Direction { SOUTH_WEST = 0,
00086 SOUTH_EAST = 1,
00087 NORTH_WEST = 2,
00088 NORTH_EAST = 3,
00089 SOUTH = 4,
00090 WEST = 5,
00091 EAST = 6,
00092 NORTH = 7
00093 };
00094
00096 enum PatchMissedPolicy { DONT_CREATE,
00097 CREATE,
00098 LOWER_DETAIL
00099 };
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00111 enum WhichHMap { HMAP_PATCH = 4,
00112 HMAP_SOUTH_WEST = 0,
00113 HMAP_SOUTH_EAST = 1,
00114 HMAP_NORTH_WEST = 2,
00115 HMAP_NORTH_EAST = 3
00116 };
00117
00118 static inline int getOppositeDirection(const int d);
00119 static inline Direction getDirectionXFromVec(const SbVec2f &vec);
00120
00121 private:
00122
00124 SbBox2f area;
00125
00127 TeHeightMap *hmap;
00128
00130 TeHeightMap* seamMap[8];
00131
00133 TeHeightMap* buildMap[4];
00134
00136 TeEngine *engine;
00137
00139 TePatch *parent;
00140
00142 TePatch* detail[4];
00143
00145 TePatch* neighbour[8];
00146
00148 SoSeparator *graph;
00149
00151 SoSeparator* seamGraph[8];
00152
00153 TePatch* getPatchHierarch(const SbVec2f &pos, const int level,
00154 PatchMissedPolicy policy = CREATE);
00155 TePatch* getPatchHierarchRelative(const SbVec2f &pos, const int relativeLevel,
00156 PatchMissedPolicy policy = CREATE);
00157 void updateNeighbours();
00158 static SbVec3f calculateNormal(const TeHeightMap *map, const int x,
00159 const int y, const float sx, const float sy);
00160 static unsigned short selectMaterial(float value);
00161 static SoSeparator* generateGraphFromSubMap(const TeHeightMap *map,
00162 const SbVec2s &min, const SbVec2s &max,
00163 const SbBox2f &area);
00164
00165 SoSeparator* generateGraph();
00166 SoSeparator* generatePatchGraph();
00167 SoSeparator* generateSeamGraph(const Direction which);
00168
00169 TePatch();
00170
00171 public:
00172
00173 TePatch(TeEngine *engine);
00174 ~TePatch();
00175
00176 const TeHeightMap* getHMap() const;
00177 TeHeightMap* getHMap();
00178 void setHMap(TeHeightMap *hmap);
00179
00180 const TeHeightMap* getSeamMap(const Direction which) const;
00181 TeHeightMap* getSeamMap(const Direction which);
00182 void setSeamMap(const Direction which, TeHeightMap *map);
00183 SbBool generateSeamMap(const Direction which);
00184
00185 TeEngine* getEngine() const;
00186 void setEngine();
00187
00188
00189 const SbBox2f& getArea() const;
00190 int getLevel() const;
00191 TePatch* getParent() const;
00192
00193 TePatch* getPatch(const SbVec2f &pos, const int level, PatchMissedPolicy policy = CREATE);
00194 TePatch* getPatchRelative(const SbVec2f &pos, const int relativeLevel,
00195 PatchMissedPolicy policy = CREATE);
00196
00197 TePatch* getDetail(const Direction which);
00198 void setDetail(const Direction which, TePatch *patch);
00199 void removeDetail(TePatch *patch);
00200
00201 Direction getDirectionWithinParent() const;
00202 Direction getDetailDirection(const SbVec2f &point) const;
00203
00204 const TeHeightMap* getBuildMap(const int i) const;
00205 TeHeightMap* getBuildMap(const int i);
00206 void setBuildMap(const int i, TeHeightMap *hmap);
00207 void setBuildMaps(TeHeightMap *nw, TeHeightMap *ne, TeHeightMap *sw, TeHeightMap *se);
00208 void findBuildMap(const int i);
00209 void prepareBuildMaps();
00210 void buildHMapFromBuildMaps();
00211
00212 void generateHMapFF(WhichHMap which,
00213 const unsigned int seed, const int num_faults,
00214 const float min_delta, const float max_delta);
00215
00216
00217 void makeRoot(const SbBox2f &area, TeEngine *engine);
00218
00219
00220 SoSeparator *getGraph();
00221 SoSeparator *getPatchGraph();
00222 SoSeparator *getSeamGraph(const Direction which);
00223 };
00224
00225
00236 inline int TePatch::getOppositeDirection(const int d)
00237 {
00238 if (d<4) return 3-d;
00239 else return 11-d;
00240 }
00241
00242
00249 inline TePatch::Direction TePatch::getDirectionXFromVec(const SbVec2f &vec)
00250 {
00251 if (vec[1] < 0.f)
00252 if (vec[0] < 0.f) return SOUTH_WEST;
00253 else return SOUTH_EAST;
00254 else
00255 if (vec[0] < 0.f) return NORTH_WEST;
00256 else return NORTH_EAST;
00257 }
00258
00259
00260 #endif