MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
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{
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);
71 WEMPatch(WEMPatch&& other) noexcept;
75 virtual ~WEMPatch();
77 virtual WEMPatch* copy() = 0;
79 void dispose();
82
84 inline unsigned int getBlocksize() const
85 {
86 return _blocksize;
87 }
89 virtual PatchTypes getPatchType() const = 0;
91 virtual inline unsigned int getNumFaces() const
92 {
93 return 0;
94 }
95
97 inline bool isTrianglePatch() const
98 {
99 return getPatchType() == WEM_PATCH_TRIANGLES;
100 }
102 inline bool isQuadPatch() const
103 {
104 return getPatchType() == WEM_PATCH_QUADS;
105 }
106
108
110 inline unsigned int getNumNodes() const
111 {
112 return _nodes.num();
113 }
116 {
117 return &_nodes;
118 }
120 inline const WEMIndexVector<WEMNode>* getNodes() const
121 {
122 return const_cast<WEMPatch*>(this)->getNodes();
123 }
127 inline WEMNode* getNodeAt(unsigned int index)
128 {
129 return _nodes.at(index);
130 }
132 inline const WEMNode* getNodeAt(unsigned int index) const
133 {
134 return const_cast<WEMPatch*>(this)->getNodeAt(index);
135 }
142 void createNodes(unsigned int numNodes);
147 void delNode(WEMNode* node);
150 void addNodeValues(WEMNode* target, WEMNode* source, double modifier);
154 void extendNodeValueLists(unsigned int number, double value);
155
157
159 inline unsigned int getNumEdges() const
160 {
161 return _edges.num();
162 }
165 {
166 return &_edges;
167 }
169 inline const WEMIndexVector<WEMEdge>* getEdges() const
170 {
171 return const_cast<WEMPatch*>(this)->getEdges();
172 }
176 inline WEMEdge* getEdgeAt(unsigned int index)
177 {
178 return _edges.at(index);
179 }
181 inline const WEMEdge* getEdgeAt(unsigned int index) const
182 {
183 return const_cast<WEMPatch*>(this)->getEdgeAt(index);
184 }
187 inline WEMEdge* addEdge()
188 {
189 return _edges.append();
190 }
192 inline void delEdge(WEMEdge* edge)
193 {
194 _edges.remove(edge);
195 }
197 inline bool hasEdges() const
198 {
199 return (_edges.num() > 0);
200 }
203 void addEdgeValues(WEMEdge* target, WEMEdge* source, double modifier);
205 void extendEdgeValueLists(unsigned int number, double value);
206
208
210 virtual WEMFace* getFaceAt(unsigned int index) = 0;
212 virtual const WEMFace* getFaceAt(unsigned int index) const = 0;
213
216 virtual WEMFace* addFace() = 0;
219 void addFaceValues(WEMFace* target, WEMFace* source, double modifier);
221 void extendFaceValueLists(unsigned int number, double value);
222
224
226 void setNodeTraversalState(bool state);
228 void setEdgeTraversalState(bool state);
230 void setFaceTraversalState(bool state);
238
240
242 double getArea() const;
244 double getVolume() const;
246 bool pointsOutwards() const;
247
249
252 {
253 return &_boundingBox;
254 }
256 inline const WEMBoundingBox* getBoundingBox() const
257 {
258 return const_cast<WEMPatch*>(this)->getBoundingBox();
259 }
264
266 void translate(const Vector3& offset);
267
269
272 inline double getLUTMin() const
273 {
274 const WEMPrimitiveValueList* pvl = getPrimitiveValueList("LUT");
275 if (pvl) {
276 return pvl->getMinValue();
277 }
278 else {
279 return 0;
280 }
281 }
284 inline double getLUTMax() const
285 {
286 const WEMPrimitiveValueList* pvl = getPrimitiveValueList("LUT");
287 if (pvl) {
288 return pvl->getMaxValue();
289 }
290 else {
291 return 0;
292 }
293 }
294
296
298 void setType(std::string type)
299 {
300 _type = type;
301 }
303 std::string getType() const
304 {
305 return _type;
306 }
308 void setCreatorId(int id)
309 {
310 _creatorId = id;
311 }
313 int getCreatorId() const
314 {
315 return _creatorId;
316 }
317
319
321 inline void setWEM(WEM* wem)
322 {
323 _wem = wem;
324 }
326 inline WEM* getWEM()
327 {
328 return _wem;
329 }
331 inline const WEM* getWEM() const
332 {
333 return const_cast<WEMPatch*>(this)->getWEM();
334 }
335
337
339 inline void setLabel(std::string label)
340 {
341 _attributes.label = label;
342 }
344 inline std::string getLabel() const
345 {
346 return _attributes.label;
347 }
348
350 inline void setDescription(std::string desc)
351 {
352 _attributes.description = desc;
353 }
355 inline std::string getDescription() const
356 {
357 return _attributes.description;
358 }
359
361
363 inline unsigned int getId() const
364 {
365 return _uniqueId;
366 }
367
369 inline void setId(unsigned int newId)
370 {
371 _uniqueId = newId;
372 }
373
375
378
380
383
385 void mirror();
386
388 virtual void sortFacesByZPosition() = 0;
389
392
394
397 virtual void buildEdgeConnectivity();
398
402
405
407
411
415
417
421
425
428 const WEMPrimitiveValueList* getPrimitiveValueList(const std::string& name) const;
429
432 std::vector<std::string> getRegisteredPrimitiveValueLists() const;
433
435 const std::vector<WEMPrimitiveValueList*>& getPrimitiveValueLists() const
436 {
437 return _primitiveValueLists;
438 }
439
441 bool removePrimitiveValueList(const std::string& name);
442
455
458 {
459 return _irregularSurfaceDetected;
460 };
461
462protected:
465
468
469 void _getReorderedIndicesForFaces(std::vector<unsigned int>& reorderedIndices);
470
472 unsigned int _blocksize;
478 WEM* _wem{};
480 unsigned int _uniqueId{};
482 std::string _type;
485
490
492 std::vector<WEMPrimitiveValueList*> _primitiveValueLists;
493
494private:
497 void _storePrimitiveValueListValue(unsigned int i, unsigned int index, double value);
499 void _handlePVLs(WEMPatch* wemPatch, const WEMPrimitiveCount& targetPC, const WEMPrimitiveCount& sourcePC);
500 bool _irregularSurfaceDetected{};
502};
503
505
#define MLWEM_EXPORT
Definition MLWEMSystem.h:18
Wraps a FileMap so we can handle errors and exceptions more easily.
This class comprises some attributes that are common for a WEM and a WEMPatch.
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
Class to save/load a WEMPatch.
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.
void delEdge(WEMEdge *edge)
Deletes an edge and erases it from the internal edges vector.
Definition WEMPatch.h:192
WEMIndexVector< WEMNode > * getNodes()
Returns the pointer to the internal nodes structure.
Definition WEMPatch.h:115
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:313
const WEMBoundingBox * getBoundingBox() const
Returns the bounding box.
Definition WEMPatch.h:256
WEMNode * getNodeAt(unsigned int index)
Returns the node at the given index.
Definition WEMPatch.h:127
WEMIndexVector< WEMEdge > * getEdges()
Returns the pointer to the internal edges structure.
Definition WEMPatch.h:164
const WEMPrimitiveValueList * getPrimitiveValueList(const std::string &name) const
Returns a pointer to the PVL with the given name.
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:251
virtual WEMFace * addFace()=0
Instantiates a new face and adds it to the internal faces vector.
virtual void buildEdgeConnectivity()
Builds edge connectivity for the whole WEM.
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:484
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:369
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:476
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:110
WEMPrimitiveValueList * getPrimitiveValueList(const std::string &name)
Returns a pointer to the PVL with the given name.
WEMEdge * getEdgeAt(unsigned int index)
Returns the edge at the given index.
Definition WEMPatch.h:176
bool isSingleColored(WEMFace *face)
Returns whether the given face is single colored.
std::vector< std::string > getRegisteredPrimitiveValueLists() const
Returns all available primitive value lists as a vector filled with the registered names of the PVLs.
const WEM * getWEM() const
Returns the internal pointer to the embracing WEM.
Definition WEMPatch.h:331
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:97
WEMNode * addNode()
Instantiates a new WEMNode and adds it to the internal nodes vector.
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)
Builds local edge connectivity, only provided face is rebuild.
virtual unsigned int getNumFaces() const
Returns the number of faces in the patch.
Definition WEMPatch.h:91
bool isQuadPatch() const
Helper method to check if the patch is a quad patch.
Definition WEMPatch.h:102
WEMEdge * addEdge()
Instantiates a new WEMEdge and adds it to the internal edges vector.
Definition WEMPatch.h:187
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 _blocksize
Initial blocksize for the WEMVector, WEMObjectVector variables used.
Definition WEMPatch.h:472
void centerByBoundingBox()
Centers the patch by its bounding box.
void addNodeValues(WEMNode *target, WEMNode *source, double modifier)
Adds node values from node source to given target node.
WEM * getWEM()
Returns the internal pointer to the embracing WEM.
Definition WEMPatch.h:326
const std::vector< WEMPrimitiveValueList * > & getPrimitiveValueLists() const
Returns an array of the primitive value lists.
Definition WEMPatch.h:435
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)
Adds the edge values from edge source to given target edge.
void setWEM(WEM *wem)
Sets the internal pointer to the embracing WEM.
Definition WEMPatch.h:321
void mirror()
Mirrors the faces in this patch.
WEMAttributes _attributes
The attributes of this WEMPatch.
Definition WEMPatch.h:487
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)
Constructor which takes a pointer to the WEM this WEM is in.
void addFaceValues(WEMFace *target, WEMFace *source, double modifier)
Adds the face values from face source to given target face.
const WEMIndexVector< WEMEdge > * getEdges() const
Returns the pointer to the internal edges structure.
Definition WEMPatch.h:169
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
Returns the minimum value of the LUT PVL for range determination.
Definition WEMPatch.h:272
std::string _type
Type of this WEMPatch.
Definition WEMPatch.h:482
void applyMatrix(const Matrix4 &transformationMatrix)
Applies the given matrix on all nodes, applies the inverse transposed matrix on all node normals,...
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:308
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:457
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:303
bool hasEdges() const
Returns whether this patch has any edges.
Definition WEMPatch.h:197
bool isSingleColored(WEMEdge *edge)
Returns whether an adjacent face to the given edge is single colored.
WEMPrimitiveValueList * createOrGetPrimitiveValueList(const std::string &name)
Creates a PVL under the given name and returns a pointer to it.
WEMPatch & operator=(WEMPatch &&other) noexcept
Move assignment operator.
virtual void _addFaceUpdatePrimitiveValueLists()
Updates primitive value lists on addFace.
void createNodes(unsigned int numNodes)
Instantiates the given number of new WEMNodes and adds them to the internal nodes vector.
WEMBoundingBox _boundingBox
The bounding box of this WEMPatch.
Definition WEMPatch.h:489
const WEMNode * getNodeAt(unsigned int index) const
Returns the node at the given index.
Definition WEMPatch.h:132
unsigned int getNumEdges() const
Returns the number of edges in the patch.
Definition WEMPatch.h:159
double getLUTMax() const
Returns the maximum value of the LUT PVL for range determination.
Definition WEMPatch.h:284
void setLabel(std::string label)
Sets the 'label' attribute of this WEMPatch.
Definition WEMPatch.h:339
const WEMEdge * getEdgeAt(unsigned int index) const
Returns the edge at the given index.
Definition WEMPatch.h:181
void dispose()
Disposes of internal data structures.
void setDescription(std::string desc)
Sets the 'description' attribute of this WEMPatch.
Definition WEMPatch.h:350
void delNode(WEMNode *node)
Deletes the given node and erases it from the internal nodes vector.
const WEMIndexVector< WEMNode > * getNodes() const
Returns the pointer to internal nodes structure.
Definition WEMPatch.h:120
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:355
WEMIndexVector< WEMNode > _nodes
The vector that holds all the nodes of the wem.
Definition WEMPatch.h:474
std::vector< WEMPrimitiveValueList * > _primitiveValueLists
The registered primitive value lists vector.
Definition WEMPatch.h:492
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:298
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:363
std::string getLabel() const
Returns the 'label' attribute of this WEMPatch.
Definition WEMPatch.h:344
Stores a value list where the values are associated to primitives (WEMNode, WEMEdge,...
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
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
PrimitiveValueListTypes
Enumeration of primitive value list types.
TriangulationModes
Enumeration of the triangulation modes. Note that these are 'mirrored' in the SoWEM part.
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
bool operator<(const CentroidIndex &c) const
Definition WEMPatch.h:39
unsigned int index
Definition WEMPatch.h:36
Structure to gather persistence parameters.
WEMPrimitiveCount(WEMPatch *patch)
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.