00001 #ifndef _SpatialIndex_h
00002 #define _SpatialIndex_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <math.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <time.h>
00024 #include <SpatialGeneral.h>
00025 #include <SpatialVector.h>
00026 #include <SpatialEdge.h>
00027 #include <SpatialException.h>
00028
00029 #include <vector>
00030 #include <string>
00031 #include <algorithm>
00032
00033
00034
00035
00036
00037
00038
00039
00063 class LINKAGE SpatialIndex {
00064 public:
00065 size_t getMaxlevel(){return maxlevel_;};
00066 size_t getBildLevel(){return buildlevel_;};
00067
00073 SpatialIndex() {};
00074 SpatialIndex(size_t maxlevel, size_t buildlevel =5);
00075
00077 static uint64 idByName(const char *);
00078
00088 static char * nameById(uint64 ID, char * name = 0);
00089
00093 uint32 leafNumberById(uint64 ID) const;
00094
00097 uint64 idByLeafNumber(uint32 n) const ;
00098
00102 char * nameByLeafNumber(uint32 n, char * name = 0) const;
00103
00106 void pointById(SpatialVector & vector, uint64 ID) const;
00107
00110 uint64 idByPoint(SpatialVector & vector) const;
00111
00113 uint64 idByPoint(const float64 & ra, const float64 & dec) const;
00114
00116
00117 char* nameByPoint(SpatialVector & vector, char* s=NULL) const;
00118
00120 char* nameByPoint(const float64 & ra, const float64 & dec,
00121 char* s=NULL) const;
00122
00124 uint64 leafCount() const;
00125
00127 size_t nVertices() const;
00128
00130 float64 area(uint64 ID) const;
00131
00133 float64 area(const SpatialVector & v1,
00134 const SpatialVector & v2,
00135 const SpatialVector & v3) const;
00136
00138 void nodeVertex(const uint64 id,
00139 SpatialVector & v1,
00140 SpatialVector & v2,
00141 SpatialVector & v3) const;
00142
00144 void nodeVertex(const size_t idx,
00145 size_t & v1, size_t & v2, size_t & v3) const;
00146
00148 void showVertices(ostream & out) const;
00149
00151 void setMaxlevel(int level);
00152
00153 private:
00154
00155
00156
00157 struct Layer {
00158 size_t level_;
00159 size_t nVert_;
00160 size_t nNode_;
00161 size_t nEdge_;
00162 uint64 firstIndex_;
00163 size_t firstVertex_;
00164 };
00165
00166 struct QuadNode {
00167 uint64 index_;
00168 size_t v_[3];
00169 size_t w_[3];
00170 uint64 childID_[4];
00171 uint64 parent_;
00172 uint64 id_;
00173 };
00174
00175
00176 typedef std::vector<QuadNode> ValueVectorQuad;
00177
00178
00179
00180
00181
00182 uint64 newNode(size_t v1, size_t v2,size_t v3,uint64 id,uint64 parent);
00183
00184
00185 void makeNewLayer(size_t oldlayer);
00186
00187
00188 void vMax(size_t *nodes, size_t *vertices);
00189
00190
00191 void sortIndex();
00192
00193
00194
00195 bool isInside(const SpatialVector & v, const SpatialVector & v0,
00196 const SpatialVector & v1, const SpatialVector & v2) const;
00197
00198
00199
00200 size_t maxlevel_;
00201 size_t buildlevel_;
00202 uint64 leaves_;
00203 uint64 storedleaves_;
00204 ValueVectorQuad nodes_;
00205 std::vector<Layer> layers_;
00206
00207 typedef std::vector<SpatialVector> ValueVectorSpvec;
00208 ValueVectorSpvec vertices_;
00209 uint64 index_;
00210
00211 friend class SpatialEdge;
00212 friend class SpatialConvex;
00213 friend class RangeConvex;
00214 friend class SpatialDomain;
00215 friend class htmInterface;
00216 };
00217
00218
00219 #include "SpatialIndex.hxx"
00220 #endif