MeVisLab Toolbox Reference
WEM.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #pragma once
14 
15 #include "MLWEMIncludes.h"
16 #include "WEMAttributes.h"
17 #include "WEMPatch.h"
18 #include "WEMTrianglePatch.h"
19 #include "WEMQuadPatch.h"
20 #include "WEMPolygonPatch.h"
21 
22 #ifdef WIN32
23 typedef void* HANDLE;
24 #endif
25 
26 
27 ML_START_NAMESPACE
28 
30 
33 {
35  {
36  notificationType = WEM_NOTIFICATION_NONE;
37  patchId = WEM_PATCH_ID_ALL;
38 
39  repaintFaces =
40  repaintEdges =
41  repaintNodes =
42  repaintBoundingBoxes = false;
43 
44  selectionWasClicked = false;
45  selectionFaceHit = 0;
46  selectionHitPoint.assign(0,0,0);
47  }
48 
52  int patchId;
53 
55 
56  bool repaintFaces;
57  bool repaintEdges;
58  bool repaintNodes;
60 
62 
66 };
67 
69 
71 typedef void wemNotificationCB(void* data, std::vector<WEMEventContainer> ecList);
72 
74 
75 // A define that can be used to detect if the WEM is ref counted:
76 #define ML_WEM_REFCOUNTED 1
77 
78 // Declare WEMPtr smart pointer
80 
81 class MLWEM_EXPORT WEM : public RefCountedBase
88 {
89  ML_CLASS_HEADER(WEM)
90 
91 public:
92 
94  WEM();
96  WEM(const WEM& wem);
97 
98 protected:
104  ~WEM() override;
105 
106 public:
107 
111  {
114  std::vector<WEMEventContainer> ecList;
115  };
116 
118 
120  void clone(const WEM& wem);
122  WEM* deepCopy() const override;
123 
125 
128  bool isValid() const;
129 
131 
133  void addNotificationObserver(wemNotificationCB* callback, void* userData);
135  void removeNotificationObserver(wemNotificationCB* callback, void* userData);
137  void notifyObservers(std::vector<WEMEventContainer> ecList);
139  void notifyObservers(const ml::WEMNotificationType& notificationType);
141  static void removeNotificationObserverFromAllWEMs(wemNotificationCB* callback, void* userData);
142 
144 
148  unsigned int getCurrentWEMPatchId();
150  inline void setCurrentWEMPatchId(unsigned int id) { _currentLastWEMPatchId = id; }
151 
153 
158  void addWEMPatch(WEMPatch* wemPatch, bool mergeAllPatches=false);
160  WEMTrianglePatch* addWEMPatchCopy(WEMTrianglePatch* wemPatch, bool assignNewId=false);
162  WEMQuadPatch* addWEMPatchCopy(WEMQuadPatch* wemPatch, bool assignNewId=false);
164  WEMPolygonPatch* addWEMPatchCopy(WEMPolygonPatch* wemPatch, bool assignNewId=false);
165 
168  bool removeWEMPatch(WEMPatch* wemPatch);
171  bool removeWEMPatch(unsigned int id);
174  bool removeAll();
177 
179 
181  WEMPatch* getWEMPatchAt(unsigned int index);
183  inline const WEMPatch* getWEMPatchAt(unsigned int index) const { return const_cast<WEM*>(this)->getWEMPatchAt(index); }
186  WEMPatch* getWEMPatchById(unsigned int id);
189  inline const WEMPatch* getWEMPatchById(unsigned int id) const { return const_cast<WEM*>(this)->getWEMPatchById(id); }
191  unsigned int getWEMPatchIndex(WEMPatch* wemPatch) const;
193  unsigned int getWEMPatchIndex(unsigned int id) const;
195  bool hasWEMPatch(WEMPatch* wemPatch) const;
196 
198 
200  inline unsigned int getNumWEMPatches() const { return static_cast<unsigned int>(_wemPatchList.size()); }
201 
203 
205  inline void enableRepaintObserver() { _enableRepaintObserver = true; }
207  inline void disableRepaintObserver() { _enableRepaintObserver = false; }
208 
210  inline void enableFinishedObserver() { _enableFinishedObserver = true; }
212  inline void disableFinishedObserver() { _enableFinishedObserver = false; }
213 
215  inline void enableInteractionObserver() { _enableInteractionObserver = true; }
217  inline void disableInteractionObserver() { _enableInteractionObserver = false; }
218 
220  inline void enableSelectionObserver() { _enableSelectionObserver = true; }
222  inline void disableSelectionObserver() { _enableSelectionObserver = false; }
223 
225 
227  inline bool isRepaintNotificationEnabled() const { return _enableRepaintObserver; }
229  inline bool isFinishedNotificationEnabled() const { return _enableFinishedObserver; }
231  inline bool isInteractionInitNotificationEnabled() const { return _enableInteractionObserver; }
233  inline bool isSelectionNotificationEnabled() const { return _enableSelectionObserver; }
234 
236 
238  inline int getId() const { return _uniqueId; }
240  inline std::string getName() const { return _name; }
242  inline void setName(std::string name) { _name = name; }
243 
245 
247  void saveWEMSurface(const std::string& filename, const WEMPersistenceParameters& persistenceParameters, ProgressField *progressFld = nullptr);
249  void saveWEMSurface(std::ostream& outstream, const WEMPersistenceParameters& persistenceParameters, ProgressField *progressFld = nullptr);
250 
253  bool loadWEMSurface(const std::string& filename, bool generateEdges=true, ProgressField *progressFld=nullptr);
256  bool loadWEMSurface(const std::string& filename, MLuint64 filesize, bool generateEdges = true, ProgressField *progressFld = nullptr);
257 
259 
261  bool hasPrimitiveValueListForAllPatches(std::string description) const;
263  std::vector<std::string> getRegisteredPrimitiveValueLists() const;
264 
266 
268  void flatten(WEMTrianglePatch *triPatch, WEMRequirements* requirements, TriangulationModes triangulationMode);
269 
273 
274 private:
275 
277  void _setIdAndName();
278 
280  static int _getUniqueId();
281 
282 #ifdef WIN32
283  void _closeFileHandles(void* hMap, HANDLE hFile, HANDLE dFile);
284 #else
285  void _closeFileHandles(void* hMap, int dFile, MLuint64 filesize);
286 #endif
287 
289  int _uniqueId;
290 
292  std::string _name;
293 
295  std::vector<WEMPatch*>_wemPatchList;
296 
299  unsigned int _currentLastWEMPatchId;
300 
302  std::vector<WEMNotificationCBData>_notificationObservers;
303 
305  bool _enableRepaintObserver;
307  bool _enableFinishedObserver;
309  bool _enableInteractionObserver;
311  bool _enableSelectionObserver;
312 
313 
315  static int _currentLastId;
316 
318  static std::vector<WEM*> _registeredWEMs;
319 
321  static void registerWEM(WEM* wem);
323  static void deregisterWEM(WEM* wem);
324 };
325 
327 
328 
329 ML_END_NAMESPACE
#define MLWEM_EXPORT
Definition: MLWEMSystem.h:18
void * HANDLE
Definition: WEM.h:23
Field to encapsulate an increasing float value from range [0,1].
Definition: mlFields.h:744
Base class for triangle and quad patches.
Definition: WEMPatch.h:48
This represents a WEMPatch consisting of polygons only.
This represents a WEMPatch consisting of quads only.
Definition: WEMQuadPatch.h:24
This class represents WEMPatch requirements to be used by WEMProcessor.
This represents a WEMPatch consisting of triangles only.
A WEM comprises a number of WEMPatches.
Definition: WEM.h:88
unsigned int getNumWEMPatches() const
Returns the number of WEMs in the list.
Definition: WEM.h:200
void enableRepaintObserver()
Enables the repaint observer mechanism.
Definition: WEM.h:205
bool removeAll()
Removes all WEMPatches from the list.
void enableFinishedObserver()
Enables the finished observer mechanism.
Definition: WEM.h:210
unsigned int getWEMPatchIndex(WEMPatch *wemPatch) const
Returns the index of the given WEMPatch in its list.
void setName(std::string name)
Sets name of the WEM to the given string.
Definition: WEM.h:242
bool isRepaintNotificationEnabled() const
Returns whether the repaint notification is enabled.
Definition: WEM.h:227
void flatten(WEMTrianglePatch *triPatch, WEMRequirements *requirements, TriangulationModes triangulationMode)
Flatten: joins and converts all patches to triangle patches with same normal orientation.
WEM * deepCopy() const override
Returns a deep copy of this WEM.
bool isValid() const
Returns whether this WEM is valid.
const WEMPatch * getWEMPatchAt(unsigned int index) const
Returns a pointer to the WEMPatch at the given position in the internal list.
Definition: WEM.h:183
bool isSelectionNotificationEnabled() const
Returns whether the selection notification is enabled.
Definition: WEM.h:233
bool removeWEMPatch(WEMPatch *wemPatch)
Removes a given WEMPatch from the list.
void enableSelectionObserver()
Enables the selection observer mechanism.
Definition: WEM.h:220
WEMPolygonPatch * addWEMPatchCopy(WEMPolygonPatch *wemPatch, bool assignNewId=false)
Adds a copy of the given WEMPatch (WEMPolygonPatch) to the list. Assigns optionally a new id to the p...
void enableInteractionObserver()
Enables the interaction observer mechanism.
Definition: WEM.h:215
~WEM() override
The WEM destructor is protected since the WEM ownership is managed by the WEMPtr intrusive smart poin...
WEMQuadPatch * addWEMPatchCopy(WEMQuadPatch *wemPatch, bool assignNewId=false)
Adds a copy of the given WEMPatch (WEMQuadPatch) to the list. Assigns optionally a new id to the patc...
WEM()
Standard constructor.
void addNotificationObserver(wemNotificationCB *callback, void *userData)
Adds a notification observer to this WEM.
bool loadWEMSurface(const std::string &filename, bool generateEdges=true, ProgressField *progressFld=nullptr)
Loads the geometry from a file given by its file name.
static void removeNotificationObserverFromAllWEMs(wemNotificationCB *callback, void *userData)
Removes a certain notification observer from all WEM.
bool removeWEMPatch(unsigned int id)
Removes a WEMPatch by its id .
int getId() const
Returns the id of the WEM.
Definition: WEM.h:238
void addWEMPatch(WEMPatch *wemPatch, bool mergeAllPatches=false)
Adds the given WEMPatch as a pointer to the list.
void disableRepaintObserver()
Disables the repaint observer mechanism.
Definition: WEM.h:207
WEMTrianglePatch * addWEMPatchCopy(WEMTrianglePatch *wemPatch, bool assignNewId=false)
Adds a copy of the given WEMPatch (WEMTrianglePatch) to the list. Assigns optionally a new id to the ...
void notifyObservers(std::vector< WEMEventContainer > ecList)
Notifies all observers with the events stored in the event container list.
WEMPatch * getWEMPatchAt(unsigned int index)
Returns a pointer to the WEMPatch at the given position in the internal list.
void removeNotificationObserver(wemNotificationCB *callback, void *userData)
Removes a notification observer from this WEM.
bool isFinishedNotificationEnabled() const
Returns whether the finished notification is enabled.
Definition: WEM.h:229
void disableSelectionObserver()
Disables the selection observer mechanism.
Definition: WEM.h:222
bool hasWEMPatch(WEMPatch *wemPatch) const
Returns whether there is the given WEMPatch in the list.
std::vector< std::string > getRegisteredPrimitiveValueLists() const
Returns unique list of registered primitive value lists for all patches as a vector.
void mergeAllPatchesIntoSinglePatch()
Merges all internal WEMPatches into a single WEMPatch.
void notifyObservers(const ml::WEMNotificationType &notificationType)
Notifies all observers with the given event.
WEMPatch * getWEMPatchById(unsigned int id)
Returns a pointer to the WEMPatch with the given unique id.
bool hasPrimitiveValueListForAllPatches(std::string description) const
Returns whether all patches have a PVL with the given description.
unsigned int getWEMPatchIndex(unsigned int id) const
Returns the index of the WEMPatch with the given id in its list.
bool isInteractionInitNotificationEnabled() const
Returns whether the interaction init notification is enabled.
Definition: WEM.h:231
void removeAllNoDelete()
Clear internal vector (DOES NOT DELETE WEMPatches!!!)
std::string getName() const
Returns name of the WEM.
Definition: WEM.h:240
void saveWEMSurface(std::ostream &outstream, const WEMPersistenceParameters &persistenceParameters, ProgressField *progressFld=nullptr)
Saves the geometry to a given stream.
void setCurrentWEMPatchId(unsigned int id)
Sets the current last id for WEMPatches. Do not mess with it.
Definition: WEM.h:150
void disableInteractionObserver()
Disables the interaction observer mechanism.
Definition: WEM.h:217
unsigned int getCurrentWEMPatchId()
Returns the current last id (incremented each call) for WEMPatches.
WEM(const WEM &wem)
Copy constructor.
const WEMPatch * getWEMPatchById(unsigned int id) const
Returns a pointer to the WEMPatch with the given unique id.
Definition: WEM.h:189
void saveWEMSurface(const std::string &filename, const WEMPersistenceParameters &persistenceParameters, ProgressField *progressFld=nullptr)
Saves the geometry to the given file name.
void disableFinishedObserver()
Disables the finished observer mechanism.
Definition: WEM.h:212
bool loadWEMSurface(const std::string &filename, MLuint64 filesize, bool generateEdges=true, ProgressField *progressFld=nullptr)
Loads the geometry from a file given by its file name.
void clone(const WEM &wem)
Clones the internal WEMs of the given WEM to this one.
#define ML_REFCOUNTED_PTR(CLASSNAME)
Macro that defines convenience Ptr/ConstPtr typedefs to be used instead of intrusive_ptr templates.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
const int WEM_PATCH_ID_ALL
Patch Id meaning: all patches.
TriangulationModes
Enumeration of the triangulation modes. Note that these are 'mirrored' in the SoWEM part.
void wemNotificationCB(void *data, std::vector< WEMEventContainer > ecList)
Defines the function signature for the callback methods that is to be touched by a WEM notification.
Definition: WEM.h:71
WEMNotificationType
Defines the available WEM notifications.
Definition: MLWEMIncludes.h:98
@ WEM_NOTIFICATION_NONE
Notification flag: no notification at all (for initializing).
Definition: MLWEMIncludes.h:99
This struct holds all necessary data for the different notifications.
Definition: WEM.h:33
int notificationType
The type of the event (None, Repaint, Selection, Finished or InteractionInit). Default: None.
Definition: WEM.h:50
bool repaintFaces
Flag: repaint the faces.
Definition: WEM.h:56
bool repaintEdges
Flag: repaint the edges.
Definition: WEM.h:57
bool selectionWasClicked
Flag: was the WEM part selected by clicking?
Definition: WEM.h:63
Vector3 selectionHitPoint
The hit point.
Definition: WEM.h:65
int patchId
The id of the WEM part for which the event is to be evaluated. Default: -1 for all parts.
Definition: WEM.h:52
bool repaintBoundingBoxes
Flag: repaint the bounding boxes.
Definition: WEM.h:59
bool repaintNodes
Flag: repaint the nodes.
Definition: WEM.h:58
int selectionFaceHit
The entryNum of the hit face.
Definition: WEM.h:64
Structure to gather persistence parameters.
This struct combines a function pointer, a user data pointer and a flag for the notification observer...
Definition: WEM.h:111
wemNotificationCB * notificationCB
The callback function that is triggered by the notification.
Definition: WEM.h:112
void * notificationCBData
The callback data that is a pointer to the observer object.
Definition: WEM.h:113
std::vector< WEMEventContainer > ecList
Each eventContainer contains all information on the type and content of the notification.
Definition: WEM.h:114