00001
00002
00003
00004
00005 #ifndef synaps_topology_inter_points_h
00006 #define synaps_topology_inter_points_h
00007
00008 #include <synaps/init.h>
00009 #include <synaps/topology/point_graph.h>
00010
00011
00012 __BEGIN_NAMESPACE_SYNAPS
00013
00014 struct XMAJOR
00015 {
00016 template<class T>
00017 static bool less(const T& a, const T& b)
00018 {
00019 return (a->pnt[0]<b->pnt[0]);
00020 }
00021 template<class T>
00022 bool operator()(const T& a, const T& b)
00023 {
00024 return less(a,b);
00025 }
00026 };
00027 struct YMAJOR
00028 {
00029 template<class T>
00030 static bool less(const T& a, const T& b)
00031 {
00032 return (a->pnt[1]<b->pnt[1]);
00033 }
00034 template<class T>
00035 bool operator()(const T& a, const T& b)
00036 {
00037 return less(a,b);
00038 }
00039 };
00040 struct ZMAJOR
00041 {
00042 template<class T>
00043 static bool less(const T& a, const T& b)
00044 {
00045 return (a->pnt[2]<b->pnt[2]);
00046 }
00047 template<class T>
00048 bool operator()(const T& a, const T& b)
00049 {
00050 return less(a,b);
00051 }
00052 };
00053
00054
00055 struct XPT
00056 {
00057 template<class T>
00058 static bool less(const T& a, const T& b)
00059 {
00060 return (a[0]<b[0]);
00061 }
00062 template<class T>
00063 bool operator()(const T& a, const T& b)
00064 {
00065 return less(a,b);
00066 }
00067 };
00068 struct YPT
00069 {
00070 template<class T>
00071 static bool less(const T& a, const T& b)
00072 {
00073 return (a[1]<b[1]);
00074 }
00075 template<class T>
00076 bool operator()(const T& a, const T& b)
00077 {
00078 return less(a,b);
00079 }
00080 };
00081 struct ZPT
00082 {
00083 template<class T>
00084 static bool less(const T& a, const T& b)
00085 {
00086 return (a[2]<b[2]);
00087 }
00088 template<class T>
00089 bool operator()(const T& a, const T& b)
00090 {
00091 return less(a,b);
00092 }
00093 };
00094
00095 template<class point_t>
00096 struct XYPLANE
00097 {
00098 point_t center;
00099
00100 XYPLANE(const point_t& pt): center(pt){};
00101
00102 template<class T>
00103 bool less(const T& a, const T& b)
00104 {
00105 return ((a[0]-center[0]) * (b[1]-center[1]) <= (b[0]-center[0]) * (a[1]-center[1]));
00106 }
00107 template<class T>
00108 bool operator()(const T& a, const T& b)
00109 {
00110 return less(a,b);
00111 }
00112 };
00113
00114
00115 template<class point_t>
00116 struct XZPLANE
00117 {
00118 point_t center;
00119
00120 XZPLANE(const point_t& pt): center(pt){};
00121
00122 template<class T>
00123 bool less(const T& a, const T& b)
00124 {
00125 return ((a[0]-center[0]) * (b[2]-center[2]) <= (b[0]-center[0]) * (a[2]-center[2]));
00126 }
00127 template<class T>
00128 bool operator()(const T& a, const T& b)
00129 {
00130 return less(a,b);
00131 }
00132 };
00133
00134 template<class point_t>
00135 struct YZPLANE
00136 {
00137 point_t center;
00138
00139 YZPLANE(const point_t& pt): center(pt){};
00140
00141 template<class T>
00142 bool less(const T& a, const T& b)
00143 {
00144 return ((a[1]-center[1]) * (b[2]-center[2]) <= (b[1]-center[1]) * (a[2]-center[2]));
00145 }
00146 template<class T>
00147 bool operator()(const T& a, const T& b)
00148 {
00149 return less(a,b);
00150 }
00151 };
00152
00153 #define _is_singular(x) ((x) < 1e-6 && (x) > -1e-6)
00154 #define _is_verysmall(x) (std::abs(x)<1e-3)
00155 template<class POINT>
00156 bool same_point(const POINT & a, const POINT & b)
00157 {
00158 return (_is_singular(a[0]-b[0]) && _is_singular(a[1]-b[1]) && _is_singular(a[2]-b[2]));
00159 }
00160
00161
00162 #define MAX_FACEIDX 3
00163
00164 static int _cellidx[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3,
00165 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7};
00166
00167
00168
00169 static int _faceidx[] = { 1, 3, 5, 3, 5,-1, 1, 5,-1, 5,-1,-1,
00170 1, 3,-1, 3,-1,-1, 1,-1,-1, -1,-1,-1};
00171
00172 static int _shareidx[] = { 1, 2, 4, 3, 5,-1, 3, 6,-1, 7,-1,-1,
00173 5, 6,-1, 7,-1,-1, 7,-1,-1, -1,-1,-1};
00174
00175 static int _inheritidx[]={ 0, 2, 4, 1, 2, 4, 0, 3, 4, 1, 3, 4,
00176 0, 2, 5, 1, 2, 5, 0, 3, 5, 1, 3, 5};
00177
00178
00179 static int plane_axisidx[] = {1, 2,
00180 0, 2,
00181 0, 1};
00182
00183 static int subcellidx[] = {0, 1, 4, 5, 2, 3, 6, 7,
00184 0, 2, 4, 6, 1, 3, 5, 7,
00185 0, 4, 2, 6, 1, 5, 3, 7};
00186
00187
00188
00189 enum PLANES
00190 {
00191 PLANEYZ = 0,
00192 PLANEXZ = 1,
00193 PLANEXY = 2
00194 };
00195
00196
00197
00198
00199
00200
00201 template < class C = double >
00202 struct intersection3d
00203 {
00204
00205
00206 typedef topology::point_graph<C> pointgraph_t;
00207 typedef topology::point<C> point_t;
00208
00209
00210
00211
00212 intersection3d() : nMulti(1), nPlane(-1), nCount(0) {}
00213 intersection3d(const point_t& p, int plane = -1, int nMul = 1) : nMulti(nMul), nPlane(plane), nCount(0) {pnt = p;}
00214 intersection3d(const intersection3d& i) : nCount(0) {assign(i);}
00215
00216
00217
00218
00219 point_t pnt;
00220 point_t der;
00221 int nMulti;
00222 int nPlane;
00223
00224
00225 int nFlag;
00226 int nCount;
00227 int nDepth;
00228
00229
00230
00231 void assign(const intersection3d& i)
00232 {
00233 pnt = i.pnt;
00234 der = i.der;
00235 nMulti = i.nMulti;
00236 nPlane = i.nPlane;
00237 }
00238
00239 intersection3d& operator = (const intersection3d& i)
00240 {
00241 assign(i);
00242 return *this;
00243 }
00244 C operator[](unsigned i) {return pnt[i];}
00245
00246
00247 };
00248
00249
00250 int ptcmp(const shared_object<intersection3d<double>*>& p1,
00251 const shared_object<intersection3d<double>*>& p2)
00252 {
00253 return ptcmp(rep(p1)->pnt,rep(p2)->pnt);
00254 }
00255
00256
00257 __END_NAMESPACE_SYNAPS
00258 #endif //synaps_topology_inter_points_h