00001 #ifndef _ModelCtrl_H_
00002 #define _ModelCtrl_H_
00003
00004
00005 #include "Geometry.h"
00006 #include "defs.h"
00007 #include "ocl.h"
00008
00009 #include "Mesh.h"
00010 #include "Field.h"
00011 #include "GraphicsSettings.h"
00012 #include "GraphicMesh.hpp"
00013 #include "RContext.h"
00014
00015 #include "CutPlane.h"
00016 #include "BBox3D.h"
00017 #include "../utils/fv_exception.h"
00018
00019
00020 #include<string>
00021
00022 #include<cassert>
00023 #include<memory>
00024 #include<map>
00025 #include<vector>
00026 #include<bitset>
00027
00028
00029
00030 namespace FemViewer
00031 {
00032
00033
00034 class Object;
00035 class VtxAccumulator;
00036 class ViewManager;
00037 class BBox3D;
00038 struct SolutionData;
00039
00040
00041 class ModelCtrl
00042 {
00043
00044 friend ModelCtrl & ModelCtrlInst(void);
00045
00046 public:
00047
00048 enum eCommnad {
00049 INIT = 0,
00050 CLEAR = 1,
00051 UPDATE = 2,
00052 INIT_MESH = (UPDATE << 1),
00053 INIT_FIELD = (UPDATE << 2),
00054 INIT_ACCEL = (UPDATE << 3),
00055 INIT_GL = (UPDATE << 4),
00056 INIT_LEGEND = (UPDATE << 5),
00057 INIT_SOL = (UPDATE << 6),
00058 INIT_PLANE = (UPDATE << 7),
00059 INIT_DISPLAY = (UPDATE << 8),
00060 };
00061
00062 enum eItem {
00063 enumAll = 0,
00064 enumMesh = 0,
00065 enumField,
00066 enumLegend,
00067 enumAccelerator,
00068 enumGL,
00069 enumGLParams,
00070 enumCutPlane,
00071 enumSolution,
00072 enumDrawMethod,
00073 enumNumItems
00074 };
00075
00076 typedef enum {
00077 MESH_STATE =0,
00078 FIELD_STATE,
00079 COLORMAP_STATE,
00080 CUT_PLANE_STATE,
00081 ACCELERATOR_STATE,
00082 GLPARAMS_STATE,
00083 DISPLAY_STATE,
00084 ALL_ITEM_STATES,
00085 NUM_STATES = ALL_ITEM_STATES,
00086 } notify_status_t;
00087
00088 public:
00089
00090
00091 ~ModelCtrl();
00092
00093 bool Do(const int oper = INIT, const char* path_ = NULL);
00094 void Reset(bool eraseall = false);
00095 void Clear();
00096 void Destroy();
00097 void Draw(RenderParams& pParams);
00098 void SetMeshChange() { m_meshChange = true; }
00099 void SetFieldChange() { m_fieldChange = true; }
00100 void SetLegendChange() { m_legendChange = true; }
00101 void SetCutPlaneChange() { m_cutPlaneChange = true; }
00102 void SetCutPlaneDisplay() { m_displayChange = true; }
00103 void SetRenderParamsChange() { m_glParamsChange = true; }
00104
00105 void NotifyChange(notify_status_t item);
00106 std::shared_ptr<Legend> LoadColorMap(const char* path);
00107
00108 int InitData();
00109 int InitData2();
00110 public:
00111 std::vector<prism_info<mfvFloat_t> > elData;
00112 std::vector<coeffs_info<mfvFloat_t> > coeffsData;
00113 grid_t gridData;
00114 int* C_ptr;
00115 int* L_ptr;
00116 protected:
00117
00118 ModelCtrl();
00119
00120 GraphicsSettings* m_psettings;
00121 SolutionData CurrentSolution;
00122 Mesh m_mesh;
00123 Field m_field;
00124 RContext* m_pRC;
00125
00126 bool m_meshChange;
00127 bool m_fieldChange;
00128 bool m_legendChange;
00129 bool m_solutionChange;
00130 bool m_accelChange;
00131 bool m_glChange;
00132 bool m_glParamsChange;
00133 bool m_cutPlaneChange;
00134 bool m_displayChange;
00135
00136
00137 std::vector<CutPlane> m_currPlanes;
00138 host_info_id _hosts;
00139 RenderManager<GLCore>* m_pgm;
00140 #ifdef PARALLEL
00141 int _procId;
00142 int _nrProcesses;
00143 #endif
00144 std::map<std::string,Legend> m_colorMaps;
00145 std::bitset<NUM_STATES> m_status;
00146 public:
00147 SolutionData& GetCurrentSolution() { return CurrentSolution; }
00148 Field* GetCurrentField() { return &m_field; }
00149 Mesh* GetCurrentMesh() { return &m_mesh; }
00150 std::vector<CutPlane>& GetCutPlanes() { return m_currPlanes; }
00151 const std::vector<CutPlane>& GetCutPlanes() const { return m_currPlanes; }
00152 RContext* RenderingContext() { return m_pRC; }
00153 const RContext* RenderingContext() const { return m_pRC; }
00154
00155 inline int GetMeshModuleType() const { return Mesh::GetMeshModuleType(); }
00156 inline int GetApproximationType() const { return Field::GetApproximationType(); }
00157
00158 const BBox3D& Boundary() const { return m_mesh.GetMeshBBox3D(); }
00159
00160 private:
00161
00162 ModelCtrl(const ModelCtrl&);
00163 ModelCtrl& operator=(const ModelCtrl&);
00164
00165
00166 bool InitMesh(const char* file_name_ = NULL);
00167 bool InitField(const char* file_name_= NULL,
00168 const HandleType type_= Unknown);
00169 bool InitVertexAccumulator();
00170 bool InitAccelStruct();
00171
00172 void EraseMesh(const int& idx_);
00173 void EraseField(const int& idx_);
00174
00175 template<class TEntity>
00176 TEntity* GetEntity(const int idx_,const char* name_);
00177
00178 template<class TMap, class T>
00179 inline T* GetTPtr(TMap& map_, const int & id_);
00180 template<class T>
00181 int RenderColoredLines();
00182
00183 void BeforeRender();
00184 void AfterRender();
00185 bool SetBoundaryElems();
00186 int TestConnection() const;
00187 int InitHosts(int numHosts);
00188
00189 };
00190
00191
00192 extern ModelCtrl& ModelCtrlInst(void);
00193
00194 extern int init_data();
00195
00196
00197
00198 }
00199 #endif
00200