MeVisLab Toolbox Reference
WEMNode.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 "WEMPrimitive.h"
16 #include "WEMFace.h"
17 #include "WEMEdge.h"
18 #include "WEMPrimitiveValueList.h"
20 
21 ML_START_NAMESPACE
22 
24 
25 class WEMTriangle;
26 class WEMQuad;
27 class WEMPolygon;
28 
30 
33 {
34 public:
35 
39  WEMNode(const WEMNode& n);
40  WEMNode(WEMNode&&n) noexcept;
41  WEMNode& operator=(WEMNode &&n) noexcept;
43  ~WEMNode() override;
45  void reset();
47  void clone(WEMNode* n);
48 
50  inline const Vector3& getPosition() const { return _position; }
52  inline void getPosition(double& x, double& y, double& z) const { x=_position.x; y=_position.y; z=_position.z;}
53 
54 #if ML_DEPRECATED_SINCE(3,5,0)
60  inline void getPosition(float& x, float& y, float& z)
61  {
62  x=static_cast<float>(_position.x);
63  y=static_cast<float>(_position.y);
64  z=static_cast<float>(_position.z);
65  }
67 #endif
68 
70  inline void setPosition(const Vector3& position) { _position = position; invalidateBoundingBoxesOfAdjacentFaces(); }
72  inline void setPosition(double x, double y, double z) { _position.assign(x,y,z); invalidateBoundingBoxesOfAdjacentFaces(); }
74  inline void translate(const Vector3& offset) { _position += offset; invalidateBoundingBoxesOfAdjacentFaces(); }
77  void applyMatrix(const Matrix4& transformMatrix);
79  inline void scale(const Vector3& scaleFactor) { _position *= scaleFactor; invalidateBoundingBoxesOfAdjacentFaces(); }
81  inline unsigned int getFaceValence() const { return _faces.num(); }
83  inline unsigned int getEdgeValence() const { return _edges.num(); }
85  inline unsigned int getNumFaces() const { return getFaceValence(); }
87  inline unsigned int getNumEdges() const { return getEdgeValence(); }
89  inline Vector4 getColor() const { return _color; }
91  inline void setColor(const Vector4& color) { _color = color; }
93  inline void setColor(float r, float g, float b) { _color[0] = r; _color[1] = g; _color[2] = b; }
95  inline void setColor(float a) { _color[3] = a; }
97  inline Vector3 getNormal() const { return _normal; }
99  inline void setNormal(const Vector3& normal) { _normal = normal; }
101  inline void setNormal(float x, float y, float z) { _normal.assign(x,y,z); }
105  inline WEMFace* getFaceAt(unsigned int index) { return _faces.at(index); }
107  inline const WEMFace* getFaceAt(unsigned int index) const { return const_cast<WEMNode*>(this)->getFaceAt(index); }
109  inline WEMTriangle* getTriangleAt(unsigned int index) { return (_faces.at(index)) ? reinterpret_cast<WEMTriangle*>(_faces.at(index)) : nullptr; }
111  inline const WEMTriangle* getTriangleAt(unsigned int index) const { return const_cast<WEMNode*>(this)->getTriangleAt(index); }
113  inline WEMQuad* getQuadAt(unsigned int index) { return (_faces.at(index)) ? reinterpret_cast<WEMQuad*>(_faces.at(index)) : nullptr; }
115  inline const WEMQuad* getQuadAt(unsigned int index) const { return const_cast<WEMNode*>(this)->getQuadAt(index); }
117  inline WEMPolygon* getPolygonAt(unsigned int index) { return (_faces.at(index)) ? reinterpret_cast<WEMPolygon*>(_faces.at(index)) : nullptr; }
119  inline const WEMPolygon* getPolygonAt(unsigned int index) const { return const_cast<WEMNode*>(this)->getPolygonAt(index); }
121  inline void addFace(WEMFace* face) { _faces.append(face); }
123  void remove(WEMFace* face);
125  inline WEMEdge* getEdgeAt(unsigned int index) { return _edges.at(index); }
127  inline const WEMEdge* getEdgeAt(unsigned int index) const { return const_cast<WEMNode*>(this)->getEdgeAt(index); }
129  inline void addEdge(WEMEdge* edge) { _edges.append(edge); }
131  void remove(WEMEdge* edge);
135  inline const WEMEdge* getEdgeWith(WEMNode* node) const { return const_cast<WEMNode*>(this)->getEdgeWith(node); }
137  inline bool isBoundary() const { return (_edges.num() && (_edges.num() != _faces.num())); }
139  void replace(WEMEdge* orig, WEMEdge* replacement);
141  void replace(WEMFace* orig, WEMFace* replacement);
143  inline void removeEdges() { _edges.clear(); }
145  inline void removeFaces() { _faces.clear(); }
147  double getLargestDihedralAngle() const;
150  double getPrimitiveValue(const WEMPrimitiveValueList* valueList) const;
151 
152 private:
153 
154  void invalidateBoundingBoxesOfAdjacentFaces();
155 
156  void resetNode();
157 
159  Vector3 _position;
161  Vector4 _color;
163  Vector3 _normal;
168 };
169 
171 
173 
175 
176 ML_END_NAMESPACE
#define MLWEM_EXPORT
Definition: MLWEMSystem.h:18
Defines the mesh component: edge.
Definition: WEMEdge.h:30
Defines the mesh component: face.
Definition: WEMFace.h:30
Defines the mesh component: node.
Definition: WEMNode.h:33
void removeFaces()
Removes all faces attached to this node.
Definition: WEMNode.h:145
const WEMQuad * getQuadAt(unsigned int index) const
Returns the face at the given index and casts it to WEMQuad.
Definition: WEMNode.h:115
double getLargestDihedralAngle() const
Returns the largest angle between the node normal and any incident face's normal.
const Vector3 & getPosition() const
Returns the world position.
Definition: WEMNode.h:50
const WEMPolygon * getPolygonAt(unsigned int index) const
Returns the face at the given index and casts it to WEMPolygon.
Definition: WEMNode.h:119
const WEMTriangle * getTriangleAt(unsigned int index) const
Returns the face at the given index and casts it to WEMTriangle.
Definition: WEMNode.h:111
WEMNode & operator=(WEMNode &&n) noexcept
void replace(WEMEdge *orig, WEMEdge *replacement)
Replaces an edge orig in the internal edge's vector by another edge replace.
void clone(WEMNode *n)
Clones given node.
WEMTriangle * getTriangleAt(unsigned int index)
Returns the face at the given index and casts it to WEMTriangle.
Definition: WEMNode.h:109
void setPosition(const Vector3 &position)
Sets the position in world coordinates.
Definition: WEMNode.h:70
WEMQuad * getQuadAt(unsigned int index)
Returns the face at the given index and casts it to WEMQuad.
Definition: WEMNode.h:113
unsigned int getFaceValence() const
Returns the face valence of node. The valence denotes the number of attached faces.
Definition: WEMNode.h:81
void setColor(float a)
Sets the alpha color of the node.
Definition: WEMNode.h:95
unsigned int getEdgeValence() const
Returns the edge valence of node. The valence denotes the number of attached edges.
Definition: WEMNode.h:83
void setNormal(const Vector3 &normal)
Sets the normal of the node.
Definition: WEMNode.h:99
void setColor(const Vector4 &color)
Sets the color of the node.
Definition: WEMNode.h:91
void setNormal(float x, float y, float z)
Sets the normal of the node.
Definition: WEMNode.h:101
~WEMNode() override
Standard destructor.
void translate(const Vector3 &offset)
Translates the position by the given vector.
Definition: WEMNode.h:74
void getPosition(double &x, double &y, double &z) const
Returns the world position.
Definition: WEMNode.h:52
Vector4 getColor() const
Returns the color of the node.
Definition: WEMNode.h:89
WEMEdge * getEdgeWith(WEMNode *node)
Returns the edge shared with the given node.
unsigned int getNumFaces() const
Returns the number of faces attached to this node.
Definition: WEMNode.h:85
void applyMatrix(const Matrix4 &transformMatrix)
Multiplies the node's position with the given transformation matrix.
void addEdge(WEMEdge *edge)
Adds the edge.
Definition: WEMNode.h:129
WEMPolygon * getPolygonAt(unsigned int index)
Returns the face at the given index and casts it to WEMPolygon.
Definition: WEMNode.h:117
void setPosition(double x, double y, double z)
Sets the position in world coordinates.
Definition: WEMNode.h:72
WEMEdge * getEdgeAt(unsigned int index)
Returns the edge at the given index.
Definition: WEMNode.h:125
void remove(WEMEdge *edge)
Removes the given edge.
WEMNode(const WEMNode &n)
Copy constructor.
void replace(WEMFace *orig, WEMFace *replacement)
Replaces a face orig in the internal face's vector by another face replace.
void removeEdges()
Removes all edges attached to this node.
Definition: WEMNode.h:143
const WEMEdge * getEdgeAt(unsigned int index) const
Returns the edge at the given index.
Definition: WEMNode.h:127
Vector3 getNormal() const
Returns the normal of the node.
Definition: WEMNode.h:97
WEMNode(WEMNode &&n) noexcept
void remove(WEMFace *face)
Removes the given face.
const WEMFace * getFaceAt(unsigned int index) const
Returns the face at the given index.
Definition: WEMNode.h:107
WEMFace * getFaceAt(unsigned int index)
Returns the face at the given index.
Definition: WEMNode.h:105
void reset()
Resets the object to default constructed state.
void setColor(float r, float g, float b)
Sets the RGB color of the node.
Definition: WEMNode.h:93
bool isBoundary() const
Returns whether the node has any edge which is a boundary edge.
Definition: WEMNode.h:137
unsigned int getNumEdges() const
Returns the number of edges attached to this node.
Definition: WEMNode.h:87
void scale(const Vector3 &scaleFactor)
Scales the position by given vector.
Definition: WEMNode.h:79
double getPrimitiveValue(const WEMPrimitiveValueList *valueList) const
Returns the node value from the given primitive value list.
const WEMEdge * getEdgeWith(WEMNode *node) const
Returns the edge shared with the given node.
Definition: WEMNode.h:135
void computeNormal()
Computes the normal of the node.
void addFace(WEMFace *face)
Adds the given face.
Definition: WEMNode.h:121
WEMNode()
Standard constructor.
Defines the mesh component: polygon.
Definition: WEMPolygon.h:22
Stores a value list where the values are associated to primitives (WEMNode, WEMEdge,...
This is the base class for the WEM elements nodes, edges, and faces.
Definition: WEMPrimitive.h:28
Defines the mesh component: quad.
Definition: WEMQuad.h:25
Defines the mesh component: triangle.
Definition: WEMTriangle.h:27
Dynamic templated vector.
Definition: WEMVector.h:28
bool MLWEM_EXPORT nodesAtAlmostIdenticalPositions(const WEMNode &x, const WEMNode &y)