00001 #ifndef _OBJECT_H_
00002 #define _OBJECT_H_
00003
00004 #include "fv_inc.h"
00005 #include "BBox3D.h"
00006 #include "RenderParams.h"
00007 #include "MathHelper.h"
00008
00009
00010 #include <map>
00011 #include <string>
00012 #include <vector>
00013
00014
00015 namespace FemViewer {
00016
00017 class PrimitiveAccumulator;
00018 class VtxAccumulator;
00019 class VtxPrimitiveAccumulator;
00020 class Vec3D;
00021 class ColorRGB;
00022
00023
00024
00025 class Object
00026 {
00027 friend class ViewManager;
00028 public:
00029 explicit Object(const char* name = "Unknown",bool usevbo = false);
00030 ~Object();
00031 void Reset();
00032 void AddMeshNode(const fvmath::Vec3f& vertex);
00033 void AddIndexOfNode(const unsigned int idx,const int dest);
00034 void AddColorOfNode(const fvmath::Vec3f& col);
00035 void AddNormalToNode(const fvmath::Vec3f& norm);
00036 void AddEdge(const unsigned int Edge[]);
00037
00038 void AddArrow(const Vec3D& p1,const Vec3D& p2,
00039 const float tipprop, const int nrpolygons);
00040
00041 void AddArrowColored(const Vec3D& p1, const ColorRGB& col1,
00042 const Vec3D& p2, const ColorRGB& col2,
00043 const float tipprop, const int nrpolygons);
00044
00045 void AddPoint(const Vec3D& pt);
00046
00047 void AddPointColored(const Vec3D& pt, const ColorRGB& col);
00048
00049 void AddLine(const Vec3D& p1, const Vec3D& p2);
00050
00051 void AddLineColored(const Vec3D& p1, const ColorRGB& col1,
00052 const Vec3D& p2, const ColorRGB& col2);
00053
00054 void AddTriangle(const Vec3D& p1, const Vec3D& p2,
00055 const Vec3D& p3);
00056
00057 void AddTriangleColored(const Vec3D& p1, const ColorRGB& col1,
00058 const Vec3D& p2, const ColorRGB& col2,
00059 const Vec3D& p3, const ColorRGB& col3);
00060
00061 void AddTriangleNormalColored(const float nv[], const float p1[], const float p2[], const float p3[],
00062 const ColorRGB& col1, const ColorRGB& col2, const ColorRGB& col3);
00063
00064 void AddQuad(const Vec3D& p1, const Vec3D& p2,
00065 const Vec3D& p3, const Vec3D& p4);
00066
00067 void AddQuadColored(const Vec3D& p1, const ColorRGB& col1,
00068 const Vec3D& p2, const ColorRGB& col2,
00069 const Vec3D& p3, const ColorRGB& col3,
00070 const Vec3D& p4, const ColorRGB& col4);
00071
00072
00073 enum eFont {
00074 fixed13,
00075 fixed15,
00076 times10,
00077 times24,
00078 helvetica10,
00079 helvetica12,
00080 helvetica18,
00081 };
00082 void AddText(const float x, const float y, const float z,
00083 eFont font, const std::string& stext);
00084
00085 Object*& AddNewObject(const std::string& sName, int* pIdx = NULL);
00086 Object* ResetSubObject(const unsigned int idx_);
00087 void ClearSubObject(const unsigned int idx_);
00088
00089 void SwitcObject(const int idx, const bool hide);
00090
00091
00092
00093 void SetDrawColor(const ColorRGB& col);
00094
00095 void SetPointSize(const float size);
00096
00097 void SetLineWidth(const float size);
00098
00099
00100
00101 void DeleteDisplayLists();
00102
00103 void DumpCharacteristics(std::ostream& pOstream,
00104 const std::string& pIndentation,
00105 const Matrix<float>& pTransformation);
00106
00107 const BBox3D& GetBBox3D() const;
00108
00109 void Render(RenderParams& pParams, bool hide=false);
00110
00111 const std::string& GetName() const { return aName; }
00112
00113
00114 private:
00115
00116 Object(const Object&);
00117 Object& operator=(const Object&);
00118
00119 typedef std::vector<std::string> Commands;
00120 typedef std::map<std::string, Object*> IndexNamedObjects;
00121 typedef std::vector<PrimitiveAccumulator*> PrimitiveAccumulators;
00122 typedef std::vector< std::pair<bool,Object*> > SubObjects;
00123 typedef std::vector<VtxAccumulator*> VtxAccumulators;
00124 typedef std::vector<VtxPrimitiveAccumulator*> VtxPrimitiveAccumulators;
00125
00126
00127 void ConstructDisplayList(RenderParams& pParams);
00128
00129 enum enum_exec_cmd {
00130 eExecPrimAccum,
00131 eExecVertexPrimAccum,
00132 };
00133
00134 void executeCommand(const std::string& pCommand, RenderParams& pParams) const;
00135
00136 PrimitiveAccumulator& GetCurrentPrimitiveAccumulator();
00137 public:
00138 VtxAccumulator& GetCurrentVtxAccumulator();
00139 private:
00140 VtxPrimitiveAccumulator& GetCurrentVtxPrimitiveAccumulator();
00141
00142 GLuint& GetGLDisplayList(const RenderParams& pParams);
00143
00144
00145 mutable BBox3D aBoundingBox;
00146 Commands aCommands;
00147 bool aFrozen;
00148 GLuint aGLDisplayListBoundingBox;
00149 GLuint aGLDisplayListFast;
00150 GLuint aGLDisplayListFull;
00151 GLuint aGLvbo[2];
00152 std::string aName;
00153 bool aNewPrimitiveAccumulatorNeeded;
00154 bool aNewVtxAccumulatorNeeded;
00155 bool aNewVtxPrimitiveAccumulatorNeeded;
00156 PrimitiveAccumulators aPrimitiveAccumulators;
00157 int aRawModeArrowTipNbPolygons;
00158 float aRawModeArrowTipProportion;
00159 SubObjects aSubObjects;
00160 VtxAccumulators aVtxAccumulators;
00161 VtxPrimitiveAccumulators aVtxPrimitiveAccumulators;
00162 int aIndex;
00163
00164
00165 };
00166
00167 }
00168 #endif
00169