00001 #ifndef CDPOLYHEDRON_H
00002 #define CDPOLYHEDRON_H
00003 #include "CDGeometry.h"
00004 #include "CDConvex.h"
00005 #include "CDQuickHull3D.h"
00006
00007 namespace Spr {;
00008
00009 class CDPolyhedron;
00010 class CDFace{
00011 public:
00012 class DualPlanes: public std::vector<CDQHPlane<CDFace>*>{
00013 public:
00014 };
00015 int vtxs[3];
00016
00017
00018 Vec3f normal;
00019 float dist;
00020
00021 Vec3f GetPos() const { return normal / dist; }
00022
00023
00024
00025
00026
00027 CDQHPlane<CDFace>* horizon;
00028
00029
00030
00031 bool CalcDualVtx(Vec3f* base);
00032
00033
00034
00035
00036 DualPlanes dualPlanes;
00037
00038 size_t NCommonVtx(){ return dualPlanes.size(); }
00039
00040 Vec3f CommonVtx(int i);
00041
00042 void Print(std::ostream& os) const;
00043 };
00044 inline std::ostream& operator << (std::ostream& os, const CDFace& f){
00045 f.Print(os);
00046 return os;
00047 }
00048 class CDFaces:public std::vector<CDFace>{
00049 };
00050 class CDVertexIDs:public std::vector<int>{
00051 public:
00052 int FindPos(int id) const;
00053 };
00054
00055
00056 class CDPolyhedron:public CDConvex{
00057 public:
00058 SGOBJECTDEF(CDPolyhedron);
00059
00060 mutable int curPos;
00061
00062 virtual int GeometryID(){ return CONVEX; }
00063
00064 Vec3f* base;
00065
00066 Vec3f* tvtxs;
00067
00068
00069 CDVertexIDs vtxIDs;
00070
00071 std::vector< std::vector<int> > neighbor;
00072
00073 CDFaces faces;
00074
00075 int nPlanes;
00076
00077
00078 Vec3f Vertex(int pos) const { return base[vtxIDs[pos]]; }
00079
00080
00081 void CalcFace();
00082
00083 void MergeFace();
00084
00085
00086 bool HasFace(CDFace* face){
00087 return &*faces.begin() <= face && face <= &*faces.end();
00088 }
00089
00090 virtual Vec3f Support(const Vec3f& p) const;
00091 private:
00092 bool VertexNear(int v1, int v2) const;
00093 };
00094
00095 }
00096 #endif