MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00006 00013 #ifndef __WEM_H 00014 #define __WEM_H 00015 00016 #include "MLWEMIncludes.h" 00017 #include "WEMAttributes.h" 00018 #include "WEMPatch.h" 00019 #include "WEMTrianglePatch.h" 00020 #include "WEMQuadPatch.h" 00021 #include "WEMPolygonPatch.h" 00022 00023 00024 ML_START_NAMESPACE 00025 00027 00029 struct WEMEventContainer 00030 { 00031 WEMEventContainer() 00032 { 00033 notificationType = WEM_NOTIFICATION_NONE; 00034 patchId = WEM_PATCH_ID_ALL; 00035 00036 repaintFaces = 00037 repaintEdges = 00038 repaintNodes = 00039 repaintBoundingBoxes = false; 00040 00041 selectionWasClicked = false; 00042 selectionFaceHit = 0; 00043 selectionHitPoint.assign(0,0,0); 00044 } 00045 00047 int notificationType; 00049 int patchId; 00050 00052 00053 bool repaintFaces; 00054 bool repaintEdges; 00055 bool repaintNodes; 00056 bool repaintBoundingBoxes; 00057 00059 00060 bool selectionWasClicked; 00061 int selectionFaceHit; 00062 Vector3 selectionHitPoint; 00063 }; 00064 00066 00068 typedef void wemNotificationCB(void* data, std::vector<WEMEventContainer> ecList); 00069 00071 00072 // A define that can be used to detect if the WEM is ref counted: 00073 #define ML_WEM_REFCOUNTED 1 00074 00075 // Declare WEMPtr smart pointer 00076 ML_REFCOUNTED_PTR(WEM) 00077 00078 00079 00080 00081 00082 00083 00084 class MLWEM_EXPORT WEM : public RefCountedBase 00085 { 00086 ML_CLASS_HEADER(WEM) 00087 00088 public: 00089 00091 WEM(); 00093 WEM(const WEM& wem); 00094 00095 protected: 00101 virtual ~WEM(); 00102 00103 public: 00104 00107 struct WEMNotificationCBData 00108 { 00109 wemNotificationCB* notificationCB; 00110 void* notificationCBData; 00111 std::vector<WEMEventContainer> ecList; 00112 }; 00113 00115 00117 void clone(const WEM& wem); 00119 virtual WEM* deepCopy() const; 00120 00122 00124 void addNotificationObserver(wemNotificationCB* callback, void* userData); 00126 void removeNotificationObserver(wemNotificationCB* callback, void* userData); 00128 void notifyObservers(std::vector<WEMEventContainer> ecList); 00130 static void removeNotificationObserverFromAllWEMs(wemNotificationCB* callback, void* userData); 00131 00133 00137 unsigned int getCurrentWEMPatchId(); 00139 inline void setCurrentWEMPatchId(unsigned int id) { _currentLastWEMPatchId = id; } 00140 00142 00145 void addWEMPatch(WEMPatch* wemPatch); 00147 WEMTrianglePatch* addWEMPatchCopy(WEMTrianglePatch* wemPatch, bool assignNewId=false); 00149 WEMQuadPatch* addWEMPatchCopy(WEMQuadPatch* wemPatch, bool assignNewId=false); 00151 WEMPolygonPatch* addWEMPatchCopy(WEMPolygonPatch* wemPatch, bool assignNewId=false); 00152 00155 bool removeWEMPatch(WEMPatch* wemPatch); 00158 bool removeWEMPatch(unsigned int id); 00161 bool removeAll(); 00163 void clear(); 00164 00166 00168 WEMPatch* getWEMPatchAt(unsigned int index); 00170 inline const WEMPatch* getWEMPatchAt(unsigned int index) const { return const_cast<WEM*>(this)->getWEMPatchAt(index); } 00173 WEMPatch* getWEMPatchById(unsigned int id); 00176 inline const WEMPatch* getWEMPatchById(unsigned int id) const { return const_cast<WEM*>(this)->getWEMPatchById(id); } 00178 unsigned int getWEMPatchIndex(WEMPatch* wemPatch) const; 00180 unsigned int getWEMPatchIndex(unsigned int id) const; 00182 bool hasWEMPatch(WEMPatch* wemPatch) const; 00183 00185 00187 inline unsigned int getNumWEMPatches() const { return static_cast<unsigned int>(_wemPatchList.size()); } 00188 00190 00192 inline void enableRepaintObserver() { _enableRepaintObserver = true; } 00194 inline void disableRepaintObserver() { _enableRepaintObserver = false; } 00195 00197 inline void enableFinishedObserver() { _enableFinishedObserver = true; } 00199 inline void disableFinishedObserver() { _enableFinishedObserver = false; } 00200 00202 inline void enableInteractionObserver() { _enableInteractionObserver = true; } 00204 inline void disableInteractionObserver() { _enableInteractionObserver = false; } 00205 00207 inline void enableSelectionObserver() { _enableSelectionObserver = true; } 00209 inline void disableSelectionObserver() { _enableSelectionObserver = false; } 00210 00212 00214 inline bool isRepaintNotificationEnabled() const { return _enableRepaintObserver; } 00216 inline bool isFinishedNotificationEnabled() const { return _enableFinishedObserver; } 00218 inline bool isInteractionInitNotificationEnabled() const { return _enableInteractionObserver; } 00220 inline bool isSelectionNotificationEnabled() const { return _enableSelectionObserver; } 00221 00223 00225 inline int getId() const { return _uniqueId; } 00227 inline std::string getName() const { return _name; } 00229 inline void setName(std::string name) { _name = name; } 00230 00232 00235 bool loadWEMSurface(const std::string& filename, bool generateEdges=true, ProgressField *progressFld=NULL); 00238 bool loadWEMSurface(const std::string& filename, int filesize, bool generateEdges=true, ProgressField *progressFld=NULL); 00241 bool loadWEMSurface(std::istream& instream, int filesize, bool generateEdges=true, ProgressField *progressFld=NULL); 00243 void saveWEMSurface(const std::string& filename, ProgressField *progressFld=NULL); 00245 void saveWEMSurface(std::ostream& outstream, ProgressField *progressFld=NULL); 00246 00248 00250 bool hasPrimitiveValueListForAllPatches(std::string description) const; 00252 std::vector<std::string> getRegisteredPrimitiveValueLists() const; 00253 00255 00257 void flatten(WEMTrianglePatch *triPatch, WEMRequirements* requirements, TriangulationModes triangulationMode); 00258 00259 private: 00260 00262 void _setIdAndName(); 00263 00265 static int _getUniqueId(); 00266 00268 int _uniqueId; 00269 00271 std::string _name; 00272 00274 std::vector<WEMPatch*>_wemPatchList; 00275 00278 unsigned int _currentLastWEMPatchId; 00279 00281 std::vector<WEMNotificationCBData>_notificationObservers; 00282 00284 bool _enableRepaintObserver; 00286 bool _enableFinishedObserver; 00288 bool _enableInteractionObserver; 00290 bool _enableSelectionObserver; 00291 00292 00294 static int _currentLastId; 00295 00297 static std::vector<WEM*> _registeredWEMs; 00298 00300 static void registerWEM(WEM* wem); 00302 static void deregisterWEM(WEM* wem); 00303 }; 00304 00306 00307 00308 ML_END_NAMESPACE 00309 00310 00311 #endif // __WEM_H