メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ | 関連ページ

CDPolyhedron.h

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     /// QuickHullにとっての頂点.この面を双対変換してできる頂点
00021     Vec3f GetPos() const { return normal / dist; }
00022     ///
00023     /** QuickHullアルゴリズム用ワークエリア.
00024         一番遠い頂点から見える面を削除したあと残った形状のエッジ部分
00025         を一周接続しておくためのポインタ.
00026         頂点→面の接続.    面→頂点は頂点の並び順から分かる.  */
00027     CDQHPlane<CDFace>* horizon;
00028 
00029     /** 双対変換を行う.baseに渡す頂点バッファは,双対変換が可能なように
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 /** 3角形だけから構成される凸多面体 */
00056 class CDPolyhedron:public CDConvex{
00057 public:
00058     SGOBJECTDEF(CDPolyhedron);
00059     /// 探索開始頂点番号
00060     mutable int curPos;
00061     /// GeomtryID
00062     virtual int GeometryID(){ return CONVEX; }
00063     /// 頂点の座標(ローカル座標系)
00064     Vec3f* base;
00065     /// 作業領域:頂点の座標(変換後の座標系)
00066     Vec3f* tvtxs;
00067 
00068     /// この凸多面体を構成する頂点たち.posはこの配列内の位置を表す.
00069     CDVertexIDs vtxIDs;
00070     /// 頂点の隣の頂点の位置が入った配列
00071     std::vector< std::vector<int> > neighbor;
00072     /// 面(3角形 0..nPlanes-1 が独立な面,それ以降はMargeFaceで削除される同一平面上の面)
00073     CDFaces faces;
00074     /// 面(3角形のうち,MergeFace()で残った数)
00075     int nPlanes;
00076 
00077     /// 頂点の座標を返す.
00078     Vec3f Vertex(int pos) const { return base[vtxIDs[pos]]; }
00079 
00080     /// 頂点から面や接続情報を生成する.
00081     void CalcFace();
00082     /// 同一平面上で接続されている3角形をマージする
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

Springheadに対してSun Apr 16 01:57:49 2006に生成されました。  doxygen 1.4.1