MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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#include "WEMBoundingBox.h"
22
23#ifdef WIN32
24typedef void* HANDLE;
25#endif
26
27
29
31
34{
36 {
37 notificationType = WEM_NOTIFICATION_NONE;
38 patchId = WEM_PATCH_ID_ALL;
39
40 repaintFaces = repaintEdges = repaintNodes = repaintBoundingBoxes = false;
41
42 selectionWasClicked = false;
43 selectionFaceHit = 0;
44 selectionHitPoint.assign(0, 0, 0);
45 }
46
51
53
58
60
64};
65
67
69typedef void wemNotificationCB(void* data, std::vector<WEMEventContainer> ecList);
70
72
73// A define that can be used to detect if the WEM is ref counted:
74#define ML_WEM_REFCOUNTED 1
75
76// Declare WEMPtr smart pointer
78
79
86{
88
89public:
91 WEM();
93 WEM(const WEM& wem);
94
95protected:
101 ~WEM() override;
102
103public:
107 {
110 std::vector<WEMEventContainer>
112 };
113
115
117 void clone(const WEM& wem);
119 WEM* deepCopy() const override;
120
122
125 bool isValid() const;
126
128
130 void addNotificationObserver(wemNotificationCB* callback, void* userData);
132 void removeNotificationObserver(wemNotificationCB* callback, void* userData);
134 void notifyObservers(std::vector<WEMEventContainer> ecList);
136 void notifyObservers(const ml::WEMNotificationType& notificationType);
138 static void removeNotificationObserverFromAllWEMs(wemNotificationCB* callback, void* userData);
139
141
145 unsigned int getCurrentWEMPatchId();
147 inline void setCurrentWEMPatchId(unsigned int id)
148 {
149 _currentLastWEMPatchId = id;
150 }
151
153
165
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
184 {
185 return const_cast<WEM*>(this)->getWEMPatchAt(index);
186 }
189 WEMPatch* getWEMPatchById(unsigned int id);
192 inline const WEMPatch* getWEMPatchById(unsigned int id) const
193 {
194 return const_cast<WEM*>(this)->getWEMPatchById(id);
195 }
197 unsigned int getWEMPatchIndex(WEMPatch* wemPatch) const;
199 unsigned int getWEMPatchIndex(unsigned int id) const;
202
204
206 inline unsigned int getNumWEMPatches() const
207 {
208 return static_cast<unsigned int>(_wemPatchList.size());
209 }
210
212
215 {
216 _enableRepaintObserver = true;
217 }
220 {
221 _enableRepaintObserver = false;
222 }
223
226 {
227 _enableFinishedObserver = true;
228 }
231 {
232 _enableFinishedObserver = false;
233 }
234
237 {
238 _enableInteractionObserver = true;
239 }
242 {
243 _enableInteractionObserver = false;
244 }
245
248 {
249 _enableSelectionObserver = true;
250 }
253 {
254 _enableSelectionObserver = false;
255 }
256
258
261 {
262 return _enableRepaintObserver;
263 }
266 {
267 return _enableFinishedObserver;
268 }
271 {
272 return _enableInteractionObserver;
273 }
276 {
277 return _enableSelectionObserver;
278 }
279
281
283 inline int getId() const
284 {
285 return _uniqueId;
286 }
288 inline std::string getName() const
289 {
290 return _name;
291 }
293 inline void setName(std::string name)
294 {
295 _name = name;
296 }
297
299
301 void saveWEMSurface(const std::string& filename, const WEMPersistenceParameters& persistenceParameters,
302 ProgressField* progressFld = nullptr);
305 ProgressField* progressFld = nullptr);
306
309 bool loadWEMSurface(const std::string& filename, bool generateEdges = true, ProgressField* progressFld = nullptr,
310 bool* irregularSurfaceDetected = nullptr);
313 bool loadWEMSurface(const std::string& filename, MLuint64 filesize, bool generateEdges = true,
314 ProgressField* progressFld = nullptr, bool* irregularSurfaceDetected = nullptr);
315
317
319 bool hasPrimitiveValueListForAllPatches(std::string description) const;
321 std::vector<std::string> getRegisteredPrimitiveValueLists() const;
322
324
327
331
335
339
340private:
342 void _setIdAndName();
343
345 static int _getUniqueId();
346
347#ifdef WIN32
348 void _closeFileHandles(void* hMap, HANDLE hFile, HANDLE dFile);
349#else
350 void _closeFileHandles(void* hMap, int dFile, MLuint64 filesize);
351#endif
352
354 int _uniqueId;
355
357 std::string _name;
358
360 std::vector<WEMPatch*> _wemPatchList;
361
364 WEMBoundingBox _boundingBox;
365
368 unsigned int _currentLastWEMPatchId;
369
371 std::vector<WEMNotificationCBData> _notificationObservers;
372
374 bool _enableRepaintObserver;
376 bool _enableFinishedObserver;
378 bool _enableInteractionObserver;
380 bool _enableSelectionObserver;
381
382
384 static int _currentLastId;
385
387 static std::vector<WEM*> _registeredWEMs;
388
390 static void registerWEM(WEM* wem);
392 static void deregisterWEM(WEM* wem);
393};
394
396
397
#define MLWEM_EXPORT
Definition MLWEMSystem.h:18
void * HANDLE
Definition WEM.h:24
Field to encapsulate an increasing float value from range [0,1].
Definition mlFields.h:519
RefCountedBase class adds intrusive reference counting support to the Base class.
This class represents an axis aligned bounding box for a WEMPatch.
Base class for triangle and quad patches.
Definition WEMPatch.h:61
This represents a WEMPatch consisting of polygons only.
This represents a WEMPatch consisting of quads only.
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:86
unsigned int getNumWEMPatches() const
Returns the number of WEMs in the list.
Definition WEM.h:206
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
void enableRepaintObserver()
Enables the repaint observer mechanism.
Definition WEM.h:214
bool removeAll()
Removes all WEMPatches from the list.
void enableFinishedObserver()
Enables the finished observer mechanism.
Definition WEM.h:225
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:293
bool isRepaintNotificationEnabled() const
Returns whether the repaint notification is enabled.
Definition WEM.h:260
void flatten(WEMTrianglePatch *triPatch, WEMRequirements *requirements, TriangulationModes triangulationMode)
Flatten: joins and converts all patches to triangle patches with same normal orientation.
WEMPatch * getWEMPatchById(unsigned int id)
Returns a pointer to the WEMPatch with the given unique id.
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 * deepCopy() const override
Returns a deep copy of this WEM.
bool isValid() const
Returns whether this WEM is valid.
bool isSelectionNotificationEnabled() const
Returns whether the selection notification is enabled.
Definition WEM.h:275
bool removeWEMPatch(WEMPatch *wemPatch)
Removes a given WEMPatch from the list.
void enableSelectionObserver()
Enables the selection observer mechanism.
Definition WEM.h:247
void enableInteractionObserver()
Enables the interaction observer mechanism.
Definition WEM.h:236
~WEM() override
The WEM destructor is protected since the WEM ownership is managed by the WEMPtr intrusive smart poin...
WEM()
Standard constructor.
void addNotificationObserver(wemNotificationCB *callback, void *userData)
Adds a notification observer to this WEM.
WEMPatch * getWEMPatchAt(unsigned int index)
Returns a pointer to the WEMPatch at the given position in the internal list.
std::vector< std::string > getRegisteredPrimitiveValueLists() const
Returns unique list of registered primitive value lists for all patches as a vector.
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 ...
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:283
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:219
void notifyObservers(std::vector< WEMEventContainer > ecList)
Notifies all observers with the events stored in the event container 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:265
bool loadWEMSurface(const std::string &filename, MLuint64 filesize, bool generateEdges=true, ProgressField *progressFld=nullptr, bool *irregularSurfaceDetected=nullptr)
Loads the geometry from a file given by its file name.
void disableSelectionObserver()
Disables the selection observer mechanism.
Definition WEM.h:252
bool hasWEMPatch(WEMPatch *wemPatch) const
Returns whether there is the given WEMPatch in the list.
void computeBoundingBox()
(Re)Computes the bounding boxes of all patches.
void mergeAllPatchesIntoSinglePatch()
Merges all internal WEMPatches into a single WEMPatch.
WEMBoundingBox * getBoundingBox()
Returns the bounding box of all patches.
void notifyObservers(const ml::WEMNotificationType &notificationType)
Notifies all observers with the given event.
const WEMPatch * getWEMPatchById(unsigned int id) const
Returns a pointer to the WEMPatch with the given unique id.
Definition WEM.h:192
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:270
void removeAllNoDelete()
Clear internal vector (DOES NOT DELETE WEMPatches!!!)
std::string getName() const
Returns name of the WEM.
Definition WEM.h:288
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:147
void disableInteractionObserver()
Disables the interaction observer mechanism.
Definition WEM.h:241
unsigned int getCurrentWEMPatchId()
Returns the current last id (incremented each call) for WEMPatches.
WEM(const WEM &wem)
Copy constructor.
void saveWEMSurface(const std::string &filename, const WEMPersistenceParameters &persistenceParameters, ProgressField *progressFld=nullptr)
Saves the geometry to the given file name.
bool loadWEMSurface(const std::string &filename, bool generateEdges=true, ProgressField *progressFld=nullptr, bool *irregularSurfaceDetected=nullptr)
Loads the geometry from a file given by its file name.
void disableFinishedObserver()
Disables the finished observer mechanism.
Definition WEM.h:230
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 clone(const WEM &wem)
Clones the internal WEMs of the given WEM to this one.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#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:424
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:69
WEMNotificationType
Defines the available WEM notifications.
@ WEM_NOTIFICATION_NONE
Notification flag: no notification at all (for initializing).
This struct holds all necessary data for the different notifications.
Definition WEM.h:34
int notificationType
The type of the event (None, Repaint, Selection, Finished or InteractionInit). Default: None.
Definition WEM.h:48
bool repaintFaces
Flag: repaint the faces.
Definition WEM.h:54
bool repaintEdges
Flag: repaint the edges.
Definition WEM.h:55
bool selectionWasClicked
Flag: was the WEM part selected by clicking?
Definition WEM.h:61
Vector3 selectionHitPoint
The hit point.
Definition WEM.h:63
int patchId
The id of the WEM part for which the event is to be evaluated. Default: -1 for all parts.
Definition WEM.h:50
bool repaintBoundingBoxes
Flag: repaint the bounding boxes.
Definition WEM.h:57
bool repaintNodes
Flag: repaint the nodes.
Definition WEM.h:56
int selectionFaceHit
The entryNum of the hit face.
Definition WEM.h:62
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:107
wemNotificationCB * notificationCB
The callback function that is triggered by the notification.
Definition WEM.h:108
void * notificationCBData
The callback data that is a pointer to the observer object.
Definition WEM.h:109
std::vector< WEMEventContainer > ecList
Each eventContainer contains all information on the type and content of the notification.
Definition WEM.h:111