MeVisLab Toolbox Reference
WEMTriangle.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 "WEMFace.h"
16 #include "WEMNode.h"
17 #include "WEMEdge.h"
18 
19 #include <array>
20 
21 ML_START_NAMESPACE
22 
24 
27 {
28 public:
34  WEMTriangle(WEMTriangle &&t) noexcept;
37 
39  ~WEMTriangle() override;
40 
42  void reset();
43 
45  void clone(WEMTriangle* triangle);
46 
48  void computeNormal() override;
50  inline unsigned int getNumNodes() const override { return 3; }
52  int getIndex(WEMNode* node) const override;
54  inline WEMNode* getNodeAt(unsigned int index) override { return _nodes[index]; }
56  inline const WEMNode* getNodeAt(unsigned int index) const override { return const_cast<WEMTriangle*>(this)->getNodeAt(index); }
58  inline void setNode(unsigned int index, WEMNode* node) override { _nodes[index] = node; invalidateBoundingBox(); }
60  virtual inline void setNodes(WEMNode* node1, WEMNode* node2, WEMNode* node3) {
61  _nodes[0] = node1; _nodes[1] = node2; _nodes[2] = node3;
63  }
65  void replace(WEMNode* orig, WEMNode* replacement) override;
67  bool contains(WEMNode* node) const override;
69  Vector3 getNodePositionAt(unsigned int index) const override { return _nodes[index]->getPosition(); }
70 
72  int getIndex(WEMEdge* edge) const override;
74  inline WEMEdge* getEdgeAt(unsigned int index) override { return _edges[index]; }
76  inline const WEMEdge* getEdgeAt(unsigned int index) const override { return const_cast<WEMTriangle*>(this)->getEdgeAt(index); }
78  inline void setEdge(unsigned int index, WEMEdge* edge) override { _edges[index] = edge; invalidateBoundingBox(); }
80  virtual inline void setEdges(WEMEdge* edge1, WEMEdge* edge2, WEMEdge* edge3)
81  {
82  _edges[0] = edge1; _edges[1] = edge2; _edges[2] = edge3;
84  }
86  void replace(WEMEdge* orig, WEMEdge* replacement) override;
88  bool contains(WEMEdge* edge) const override;
90  void removeEdges() override;
91 
92 
94  Vector3 getCentroid() const override;
95  void getCentroid(Vector3& centroid) const override;
97  double getPerimeter() const override;
99  double getArea() const override;
101  WEMNode* getOther(WEMNode* n1, WEMNode* n2) override;
103  inline const WEMNode* getOther(WEMNode* n1, WEMNode* n2) const override { return const_cast<WEMTriangle*>(this)->getOther(n1, n2); }
105  WEMEdge* getOther(WEMEdge* e1, WEMEdge* e2) override;
107  inline const WEMEdge* getOther(WEMEdge* e1, WEMEdge* e2) const override { return const_cast<WEMTriangle*>(this)->getOther(e1, e2); }
111  inline const WEMEdge* getEdgeNotContaining(WEMNode* n) const override { return const_cast<WEMTriangle*>(this)->getEdgeNotContaining(n); }
118  double getQuality() const override;
120  int isConcave() const override { return 0; }
122  virtual bool isFolding(WEMNode *node, const Vector3& position) const;
124  virtual bool pointInTriangle(const Vector3& position) const;
126  virtual bool rayIntersect(const Vector3& origin, const Vector3& direction) const;
128  void mirror() override;
129 
131  friend bool MLWEM_EXPORT operator==(const WEMTriangle &x, const WEMTriangle &y);
133  friend bool MLWEM_EXPORT operator!=(const WEMTriangle &x, const WEMTriangle &y);
134 
135  // for performance reasons, direct access to the nodes and edges is allowed:
136 public:
137 
139  std::array<WEMNode*, 3> _nodes;
141  std::array<WEMEdge*, 3> _edges;
142 
143 private:
144  void resetTriangle();
145 };
146 
147 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
void invalidateBoundingBox()
Definition: WEMFace.h:98
Defines the mesh component: node.
Definition: WEMNode.h:33
Defines the mesh component: triangle.
Definition: WEMTriangle.h:27
WEMEdge * getEdgeAt(unsigned int index) override
Returns the edge at the given index in this face.
Definition: WEMTriangle.h:74
void getCentroid(Vector3 &centroid) const override
void setEdge(unsigned int index, WEMEdge *edge) override
Sets the given edge to the given index in this face.
Definition: WEMTriangle.h:78
double getArea() const override
Calculates the area of this face.
const WEMEdge * getOther(WEMEdge *e1, WEMEdge *e2) const override
Returns the edge incident to this face that is not given as a parameter.
Definition: WEMTriangle.h:107
~WEMTriangle() override
Standard destructor.
int getIndex(WEMEdge *edge) const override
Returns the index of the given edge.
virtual void setNodes(WEMNode *node1, WEMNode *node2, WEMNode *node3)
Sets the given nodes.
Definition: WEMTriangle.h:60
void setNode(unsigned int index, WEMNode *node) override
Sets the given node to the given index in this face.
Definition: WEMTriangle.h:58
int isConcave() const override
Checks whether this face a concave polygon. Return the number of concavities.
Definition: WEMTriangle.h:120
WEMTriangle()
Standard constructor.
WEMNode * getNodeAt(unsigned int index) override
Returns the node at the given index in this face.
Definition: WEMTriangle.h:54
virtual bool rayIntersect(const Vector3 &origin, const Vector3 &direction) const
Returns whether the given ray intersects this triangle?
double getPerimeter() const override
Calculates the perimeter of this face.
void removeEdges() override
Removes all edge pointers of this face.
int getIndex(WEMNode *node) const override
Returns the index of the given node.
const WEMNode * getOther(WEMNode *n1, WEMNode *n2) const override
Returns the node incident to this face that is not given as a parameter.
Definition: WEMTriangle.h:103
WEMTriangle & operator=(WEMTriangle &&t) noexcept
Move assignment operator.
friend bool MLWEM_EXPORT operator==(const WEMTriangle &x, const WEMTriangle &y)
Operator for equality. Currently only the node positions of the triangles and their orientation are c...
const WEMEdge * getEdgeNotContaining(WEMNode *n) const override
Returns the edge not containing given node.
Definition: WEMTriangle.h:111
virtual void setEdges(WEMEdge *edge1, WEMEdge *edge2, WEMEdge *edge3)
Sets the given edges.
Definition: WEMTriangle.h:80
unsigned int getNumNodes() const override
Returns the number of nodes.
Definition: WEMTriangle.h:50
void reset()
Resets the object to default constructed state.
double getQuality() const override
Calculates the quality of the face.
WEMTriangle(const WEMTriangle &t)
Standard copy constructor.
const WEMNode * getNodeAt(unsigned int index) const override
Returns the node at the given index in this face.
Definition: WEMTriangle.h:56
virtual bool isFolding(WEMNode *node, const Vector3 &position) const
Returns whether this face is folding?
void mirror() override
Mirrors this face. Note that the edge information gets corrupted! Use WEM::buildEdgeConnectivity afte...
Vector3 getCentroid() const override
Returns the geometric centroid of this face.
Vector3 getNodePositionAt(unsigned int index) const override
Returns the position of a node at the given index.
Definition: WEMTriangle.h:69
bool contains(WEMNode *node) const override
Returns whether this face contains the given node.
void computeNormal() override
Computes the normal.
void clone(WEMTriangle *triangle)
Clones given triangle.
bool contains(WEMEdge *edge) const override
Returns whether this face contains the given edge.
WEMEdge * getOther(WEMEdge *e1, WEMEdge *e2) override
Returns the edge incident to this face that is not given as a parameter.
const WEMEdge * getEdgeAt(unsigned int index) const override
Returns the edge at the given index in this face.
Definition: WEMTriangle.h:76
std::array< WEMNode *, 3 > _nodes
Node pointers.
Definition: WEMTriangle.h:139
void replace(WEMNode *orig, WEMNode *replacement) override
Replaces the given orig node by the given replace node.
std::array< WEMEdge *, 3 > _edges
Edge pointers.
Definition: WEMTriangle.h:141
void replace(WEMEdge *orig, WEMEdge *replacement) override
Replaces the given orig node by the given replace edge.
virtual bool pointInTriangle(const Vector3 &position) const
Returns whether the given point is in this triangle.
WEMTriangle(WEMTriangle &&t) noexcept
Move constructor.
WEMNode * getOther(WEMNode *n1, WEMNode *n2) override
Returns the node incident to this face that is not given as a parameter.
friend bool MLWEM_EXPORT operator!=(const WEMTriangle &x, const WEMTriangle &y)
Operator for not equality.
WEMEdge * getEdgeNotContaining(WEMNode *n) override
Returns the edge not containing given node.