MeVisLab Toolbox Reference
WEMPatch.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 "WEMNode.h"
16#include "WEMEdge.h"
17#include "WEMBoundingBox.h"
18#include "WEMAttributes.h"
19#include "WEMRequirements.h"
24
25ML_START_NAMESPACE
26
28
29class WEM;
30class WEMPatch;
31class WEMPatchPersistence;
32
35{
36 unsigned int index;
37 double centroidZ;
38
39 bool operator < (const CentroidIndex& c) const
40 {
41 return centroidZ < c.centroidZ;
42 }
43};
44
45
47{
49 unsigned int getNumPrimitives(PrimitiveValueListTypes pvlType) const;
50
51 unsigned int numNodes{};
52 unsigned int numEdges{};
53 unsigned int numFaces{};
54};
55
56
58
61{
62public:
64 WEMPatch(unsigned int bs = 8192);
67 WEMPatch(WEM* wem, unsigned int bs = 8192);
69 WEMPatch(const WEMPatch& wemPatch);
71 WEMPatch(WEMPatch &&other) noexcept;
73 WEMPatch &operator=(WEMPatch &&other) noexcept;
75 virtual ~WEMPatch();
77 virtual WEMPatch* copy() = 0;
79 void dispose();
81 void addPatch(WEMPatch* wemPatch);
82
84 inline unsigned int getBlocksize() const { return _blocksize; }
86 virtual PatchTypes getPatchType() const = 0;
88 virtual inline unsigned int getNumFaces() const { return 0; }
89
91 inline bool isTrianglePatch() const { return getPatchType() == WEM_PATCH_TRIANGLES; }
93 inline bool isQuadPatch() const { return getPatchType() == WEM_PATCH_QUADS; }
94
96
98 inline unsigned int getNumNodes() const { return _nodes.num(); }
102 inline const WEMIndexVector<WEMNode>* getNodes() const { return const_cast<WEMPatch*>(this)->getNodes(); }
104 inline WEMNode* getNodeAt(unsigned int index) { return _nodes.at(index); }
106 inline const WEMNode* getNodeAt(unsigned int index) const { return const_cast<WEMPatch*>(this)->getNodeAt(index); }
115 void delNode(WEMNode* node);
118 void addNodeValues(WEMNode* target, WEMNode* source, double modifier);
120 void averageNodeValues(WEMNode* target, WEMNode* source1, WEMNode* source2);
122 void extendNodeValueLists(unsigned int number, double value);
123
125
127 inline unsigned int getNumEdges() const { return _edges.num(); }
131 inline const WEMIndexVector<WEMEdge>* getEdges() const { return const_cast<WEMPatch*>(this)->getEdges(); }
133 inline WEMEdge* getEdgeAt(unsigned int index) { return _edges.at(index); }
135 inline const WEMEdge* getEdgeAt(unsigned int index) const { return const_cast<WEMPatch*>(this)->getEdgeAt(index); }
138 inline WEMEdge* addEdge() { return _edges.append(); }
140 inline void delEdge(WEMEdge* edge) { _edges.remove(edge); }
142 inline bool hasEdges() const { return (_edges.num() > 0); }
145 void addEdgeValues(WEMEdge* target, WEMEdge* source, double modifier);
147 void extendEdgeValueLists(unsigned int number, double value);
148
150
152 virtual WEMFace* getFaceAt(unsigned int index) = 0;
154 virtual const WEMFace* getFaceAt(unsigned int index) const = 0;
155
158 virtual WEMFace* addFace() = 0;
161 void addFaceValues(WEMFace* target, WEMFace* source, double modifier);
163 void extendFaceValueLists(unsigned int number, double value);
164
166
168 void setNodeTraversalState(bool state);
170 void setEdgeTraversalState(bool state);
172 void setFaceTraversalState(bool state);
179 void applyMatrix(const Matrix4& transformationMatrix);
180
182
184 double getArea() const;
186 double getVolume() const;
188 bool pointsOutwards() const;
189
191
195 inline const WEMBoundingBox* getBoundingBox() const { return const_cast<WEMPatch*>(this)->getBoundingBox(); }
200
202 void translate(const Vector3& offset);
203
205
208 inline double getLUTMin() const
209 {
211 if (pvl) { return pvl->getMinValue(); }
212 else { return 0; }
213 }
214
216 inline double getLUTMax() const
217 {
219 if (pvl) { return pvl->getMaxValue(); }
220 else { return 0; }
221 }
222
224
226 void setType(std::string type) { _type = type; }
228 std::string getType() const { return _type; }
230 void setCreatorId(int id) { _creatorId = id; }
232 int getCreatorId() const { return _creatorId; }
233
235
237 inline void setWEM(WEM* wem) { _wem = wem; }
239 inline WEM* getWEM() { return _wem; }
241 inline const WEM* getWEM() const { return const_cast<WEMPatch*>(this)->getWEM(); }
242
244
246 inline void setLabel(std::string label) { _attributes.label = label; }
248 inline std::string getLabel() const { return _attributes.label; }
249
251 inline void setDescription(std::string desc) { _attributes.description = desc; }
253 inline std::string getDescription() const { return _attributes.description; }
254
256
258 inline unsigned int getId() const { return _uniqueId; }
259
261 inline void setId(unsigned int newId) { _uniqueId = newId; }
262
264
267
269
271 void triangulate(WEMTrianglePatch* wemPatch, TriangulationModes triangulationMode);
272
274 void mirror();
275
277 virtual void sortFacesByZPosition() = 0;
278
280 WEMPatch* makeCompatible(WEMRequirements* requirements, TriangulationModes triangulationMode);
281
283
286 virtual void buildEdgeConnectivity();
287
291
294
296
298 void saveTo(OutStreamWrapper& ostreamWrapper, const WEMPersistenceParameters& writeParameters, WEMProgressUpdater& progressUpdater);
299
301 unsigned int loadFrom(FileMapWrapper& mapper, const WEMPersistenceParameters& persistenceParameters, const WEMReadParameters& parameters, WEMProgressUpdater& progressUpdater);
302
304
308
312
315 const WEMPrimitiveValueList* getPrimitiveValueList(const std::string& name) const;
316
319 std::vector<std::string> getRegisteredPrimitiveValueLists() const;
320
322 const std::vector<WEMPrimitiveValueList*>& getPrimitiveValueLists() const { return _primitiveValueLists; }
323
325 bool removePrimitiveValueList(const std::string& name);
326
339
341 bool irregularSurfaceDetected() const { return _irregularSurfaceDetected; };
342
343protected:
344
347
350
351 void _getReorderedIndicesForFaces(std::vector<unsigned int>& reorderedIndices);
352
354 unsigned int _blocksize;
362 unsigned int _uniqueId{};
364 std::string _type;
367
372
374 std::vector<WEMPrimitiveValueList*> _primitiveValueLists;
375
376private:
377
380 void _storePrimitiveValueListValue(unsigned int i, unsigned int index, double value);
382 void _handlePVLs(WEMPatch* wemPatch, const WEMPrimitiveCount& targetPC, const WEMPrimitiveCount& sourcePC);
383 bool _irregularSurfaceDetected{};
385};
386
388
389ML_END_NAMESPACE
#define MLWEM_EXPORT
Definition MLWEMSystem.h:18
Wraps a FileMap so we can handle errors and exceptions more easily.
This class represents an axis aligned bounding box for a WEMPatch.
Defines the mesh component: edge.
Definition WEMEdge.h:30
Defines the mesh component: face.
Definition WEMFace.h:30
Dynamic vector, based on a memory pool. Keeps track on entry numbers of stored primitives.
Defines the mesh component: node.
Definition WEMNode.h:33
Base class for triangle and quad patches.
Definition WEMPatch.h:61
bool removePrimitiveValueList(const std::string &name)
Removes the PVL with the given name. Returns whether the operation was successful.
friend class WEMPatchPersistence
Definition WEMPatch.h:384
void delEdge(WEMEdge *edge)
Deletes an edge and erases it from the internal edges vector.
Definition WEMPatch.h:140
WEMIndexVector< WEMNode > * getNodes()
Returns the pointer to the internal nodes structure.
Definition WEMPatch.h:100
void removeAllEdges()
Removes all edges.
void deleteOrphanNodes()
Deletes orphan nodes (number of edges == number of faces == 0).
unsigned int loadFrom(FileMapWrapper &mapper, const WEMPersistenceParameters &persistenceParameters, const WEMReadParameters &parameters, WEMProgressUpdater &progressUpdater)
Loads this patch from given memory map.
int getCreatorId() const
Returns the creator ID of the WEMPatch.
Definition WEMPatch.h:232
const WEMBoundingBox * getBoundingBox() const
Returns the bounding box.
Definition WEMPatch.h:195
WEMNode * getNodeAt(unsigned int index)
Returns the node at the given index.
Definition WEMPatch.h:104
WEMIndexVector< WEMEdge > * getEdges()
Returns the pointer to the internal edges structure.
Definition WEMPatch.h:129
const WEMPrimitiveValueList * getPrimitiveValueList(const std::string &name) const
void translate(const Vector3 &offset)
Translates all nodes by the given offset.
virtual void _delFaceUpdatePrimitiveValueLists(WEMFace *face)
Updates primitive value lists on delFace.
WEMBoundingBox * getBoundingBox()
Returns the bounding box.
Definition WEMPatch.h:193
virtual WEMFace * addFace()=0
virtual void buildEdgeConnectivity()
virtual WEMFace * getFaceAt(unsigned int index)=0
Returns the face at the given index.
double getArea() const
Returns the area of this patch in square mm.
int _creatorId
ID of the creator of this WEMPatch.
Definition WEMPatch.h:366
void setEdgeTraversalState(bool state)
Sets the specified traversal state to all edges.
void setId(unsigned int newId)
Sets the unique ID of this WEMPatch. Beware: do not set this ID unless you really know what you do!
Definition WEMPatch.h:261
WEMPatch(const WEMPatch &wemPatch)
Copy constructor.
void setNodeTraversalState(bool state)
Sets the specified traversal state to all nodes.
virtual WEMPatch * copy()=0
Create a (deep) copy of the patch.
WEMIndexVector< WEMEdge > _edges
The vector that holds all the edges of the wem.
Definition WEMPatch.h:358
void computeNormals()
Computes all normals.
WEMPatch(unsigned int bs=8192)
Standard constructor.
double getVolume() const
Returns the volume of this patch in cubic mm.
unsigned int getBlocksize() const
Returns the block size for the patch.
Definition WEMPatch.h:84
unsigned int getNumNodes() const
Returns the number of nodes in the patch.
Definition WEMPatch.h:98
WEMPrimitiveValueList * getPrimitiveValueList(const std::string &name)
WEMEdge * getEdgeAt(unsigned int index)
Returns the edge at the given index.
Definition WEMPatch.h:133
WEM * _wem
A pointer to the WEM this WEMPart is in.
Definition WEMPatch.h:360
bool isSingleColored(WEMFace *face)
Returns whether the given face is single colored.
std::vector< std::string > getRegisteredPrimitiveValueLists() const
const WEM * getWEM() const
Returns the internal pointer to the embracing WEM.
Definition WEMPatch.h:241
virtual const WEMFace * getFaceAt(unsigned int index) const =0
Returns the face at the given index.
unsigned int getNumSingleColoredFaces()
Return the number of single-colored faces.
bool isTrianglePatch() const
Helper method to check if the patch is a triangle patch.
Definition WEMPatch.h:91
WEMNode * addNode()
bool isSingleColored(WEMNode *node)
Returns whether an adjacent face to the given node is single colored.
void averageNodeValues(WEMNode *target, WEMNode *source1, WEMNode *source2)
Averages the given source node values and stores values in the given target node.
void buildLocalEdgeConnectivity(WEMFace *face)
virtual unsigned int getNumFaces() const
Returns the number of faces in the patch.
Definition WEMPatch.h:88
bool isQuadPatch() const
Helper method to check if the patch is a quad patch.
Definition WEMPatch.h:93
WEMEdge * addEdge()
Definition WEMPatch.h:138
virtual ~WEMPatch()
Standard destructor.
void setFaceTraversalState(bool state)
Sets the specified traversal state to all faces.
void addPatch(WEMPatch *wemPatch)
Adds the primitives of the given patch to this patch.
unsigned int _uniqueId
Unique ID of this WEM.
Definition WEMPatch.h:362
unsigned int _blocksize
Initial blocksize for the WEMVector, WEMObjectVector variables used.
Definition WEMPatch.h:354
void centerByBoundingBox()
Centers the patch by its bounding box.
void addNodeValues(WEMNode *target, WEMNode *source, double modifier)
WEM * getWEM()
Returns the internal pointer to the embracing WEM.
Definition WEMPatch.h:239
const std::vector< WEMPrimitiveValueList * > & getPrimitiveValueLists() const
Returns an array of the primitive value lists.
Definition WEMPatch.h:322
void extendNodeValueLists(unsigned int number, double value)
Extends all node value lists with the given value.
bool hasSingleColoredPVL()
Returns whether the patch has a PVL set for single colored faces.
virtual void sortFacesByZPosition()=0
Sorts the faces by the z-position of their centroids.
void addEdgeValues(WEMEdge *target, WEMEdge *source, double modifier)
void setWEM(WEM *wem)
Sets the internal pointer to the embracing WEM.
Definition WEMPatch.h:237
void mirror()
Mirrors the faces in this patch.
WEMAttributes _attributes
The attributes of this WEMPatch.
Definition WEMPatch.h:369
bool hasAllFacesSingleColored()
Returns whether all faces are single colored.
void triangulate(WEMTrianglePatch *wemPatch, TriangulationModes triangulationMode)
Triangulates the patch and adds triangles to the given triangle patch.
WEMPatch(WEM *wem, unsigned int bs=8192)
void addFaceValues(WEMFace *target, WEMFace *source, double modifier)
const WEMIndexVector< WEMEdge > * getEdges() const
Returns the pointer to the internal edges structure.
Definition WEMPatch.h:131
void extendEdgeValueLists(unsigned int number, double value)
Extends all edge value lists with given value.
WEMPatch * makeCompatible(WEMRequirements *requirements, TriangulationModes triangulationMode)
Makes WEMPatch compatible with the given requirements.
double getLUTMin() const
Definition WEMPatch.h:208
std::string _type
Type of this WEMPatch.
Definition WEMPatch.h:364
void applyMatrix(const Matrix4 &transformationMatrix)
void extendFaceValueLists(unsigned int number, double value)
Extends all face value lists with the given value.
void setCreatorId(int id)
Sets the creator ID of the WEMPatch.
Definition WEMPatch.h:230
WEMNode * addNodeNoUpdatePrimitiveValueLists()
Creates and returns a new node without changing the nodes PVL.
void flipNormals()
Flip all normals.
WEMPatch(WEMPatch &&other) noexcept
Move c'tor.
bool irregularSurfaceDetected() const
Returns whether an irregular face reference was detected during last buildEdgeConnectivity.
Definition WEMPatch.h:341
void saveTo(OutStreamWrapper &ostreamWrapper, const WEMPersistenceParameters &writeParameters, WEMProgressUpdater &progressUpdater)
Saves this patch to given output stream.
std::string getType() const
Returns the type of the WEMPatch.
Definition WEMPatch.h:228
bool hasEdges() const
Returns whether this patch has any edges.
Definition WEMPatch.h:142
bool isSingleColored(WEMEdge *edge)
Returns whether an adjacent face to the given edge is single colored.
WEMPrimitiveValueList * createOrGetPrimitiveValueList(const std::string &name)
WEMPatch & operator=(WEMPatch &&other) noexcept
Move assignment operator.
virtual void _addFaceUpdatePrimitiveValueLists()
Updates primitive value lists on addFace.
WEMBoundingBox _boundingBox
The bounding box of this WEMPatch.
Definition WEMPatch.h:371
const WEMNode * getNodeAt(unsigned int index) const
Returns the node at the given index.
Definition WEMPatch.h:106
unsigned int getNumEdges() const
Returns the number of edges in the patch.
Definition WEMPatch.h:127
double getLUTMax() const
Definition WEMPatch.h:216
void setLabel(std::string label)
Sets the 'label' attribute of this WEMPatch.
Definition WEMPatch.h:246
const WEMEdge * getEdgeAt(unsigned int index) const
Returns the edge at the given index.
Definition WEMPatch.h:135
void dispose()
Disposes of internal data structures.
void setDescription(std::string desc)
Sets the 'description' attribute of this WEMPatch.
Definition WEMPatch.h:251
void delNode(WEMNode *node)
const WEMIndexVector< WEMNode > * getNodes() const
Returns the pointer to internal nodes structure.
Definition WEMPatch.h:102
bool pointsOutwards() const
Checks and returns whether this patch has most normals pointing outwards.
std::string getDescription() const
Returns the 'description' attribute of this WEMPatch.
Definition WEMPatch.h:253
WEMIndexVector< WEMNode > _nodes
The vector that holds all the nodes of the wem.
Definition WEMPatch.h:356
std::vector< WEMPrimitiveValueList * > _primitiveValueLists
The registered primitive value lists vector.
Definition WEMPatch.h:374
virtual PatchTypes getPatchType() const =0
Returns the mesh type of this patch.
void setType(std::string type)
Sets the type of the WEMPatch.
Definition WEMPatch.h:226
void computeBoundingBox()
Computes the bounding box.
void _getReorderedIndicesForFaces(std::vector< unsigned int > &reorderedIndices)
unsigned int getId() const
Returns the unique ID of this WEMPatch.
Definition WEMPatch.h:258
std::string getLabel() const
Returns the 'label' attribute of this WEMPatch.
Definition WEMPatch.h:248
double getMaxValue() const
Returns the maximum value.
double getMinValue() const
Returns the minimum value.
This class represents WEMPatch requirements to be used by WEMProcessor.
This represents a WEMPatch consisting of triangles only.
Definition WEM.h:89
PrimitiveValueListTypes
Enumeration of primitive value list types.
Tmat4< MLdouble > Matrix4
The standard 4x4 matrix of type double.
Definition mlMatrix4.h:713
TriangulationModes
Enumeration of the triangulation modes. Note that these are 'mirrored' in the SoWEM part.
Tvec3< MLdouble > Vector3
A vector with three components of type double.
Definition mlVector3.h:286
PatchTypes
Enumeration of mesh types.
@ WEM_PATCH_TRIANGLES
Patch type: all faces are triangles.
@ WEM_PATCH_QUADS
Patch type: all faces are quads.
Structure used to sort faces in z-direction.
Definition WEMPatch.h:35
unsigned int index
Definition WEMPatch.h:36
Structure to gather persistence parameters.
WEMPrimitiveCount(WEMPatch *patch)
unsigned int numEdges
Definition WEMPatch.h:52
unsigned int numFaces
Definition WEMPatch.h:53
unsigned int numNodes
Definition WEMPatch.h:51
unsigned int getNumPrimitives(PrimitiveValueListTypes pvlType) const
Helper struct for updating the progress bar while loading/saving.
Helper struct for bundling parameters to keep method interfaces small.