G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsVertex.h
Go to the documentation of this file.
1
14#pragma once
15
18
19namespace gismo
20{
21
25template <class T>
26class gsVertex : public gsMeshElement<T>, public gsVector3d<T>
27{
28public:
30 typedef memory::shared_ptr< gsVertex > Ptr;
31
33 typedef memory::unique_ptr< gsVertex > uPtr;
34
35 typedef typename gsVector3d<T>::Scalar scalar_t;
36 typedef gsMeshElement<T> MeshElement;
37 typedef typename MeshElement::gsFaceHandle gsFaceHandle;
39
40public:
42 gsVertex() : MeshElement(), gsVector3d<T>() { }
43
44 template<typename OtherDerived>
45 gsVertex(const gsEigen::MatrixBase<OtherDerived>& other) :
46 MeshElement(), gsVector3d<T>(other),sharp(0), numEdges(0), data()
47 { }
48
51 gsVertex(scalar_t x, scalar_t y, scalar_t z = 0) :
52 MeshElement(), gsVector3d<T>(x,y,z),sharp(0), numEdges(0), data()
53 { }
54
57 gsVertex( gsVector3d<T> const & u) :
58 MeshElement(), gsVector3d<T>(u),sharp(0), numEdges(0), data()
59 { }
60
63 gsVertex( gsVector<T> const & u) :
64 MeshElement(), gsVector3d<T>(),sharp(0),numEdges(0), data()
65 {
66 // vertex is always a 3-cooordinate vector.
67 const index_t r = u.rows();
68 GISMO_ASSERT(r<=3, "Invalid input in gsVertex constructor");
69
70 if ( r < 3 )
71 this->tail(3-r).setZero();
72
73 this->head(r) = u;
74 }
75
76 // Copy costructor
77 gsVertex(const gsVertex & other) :
78 MeshElement(other), gsVector3d<T>(other), sharp(other.sharp), numEdges(other.numEdges), data(other.data)
79 { }
80
81 // Copy assignment operator
82 gsVertex & operator=(const gsVertex & other)
83 {
84 MeshElement::operator=(other);
85 gsVector3d<T>::operator=(other);
86 sharp = other.sharp;
87 numEdges = other.numEdges;
88 data = other.data;
89 return *this;
90 }
91
92 // Destructor
93 virtual ~gsVertex() { };
94
95
96 void setCoords(gsVector<T> const & coord)
97 {
98 this->gsVector3d<T>::operator=(coord);
99 }
100
101 //GISMO_CLONE_FUNCTION(gsVertex)
103 uPtr clone() const { return uPtr(new gsVertex(*this)); }
104
107 void move(scalar_t dx, scalar_t dy, scalar_t dz)
108 {
109 this->x() += dx;
110 this->y() += dy;
111 this->z() += dz;
112 }
113
116 inline void addFace(gsFaceHandle const& f)
117 { faces.push_back( f ); }
118
120 inline T x () const { return (*this)(0); }
122 inline T y () const { return (*this)(1); }
124 inline T z () const { return (*this)(2); }
126 inline T & x () { return (*this)(0); }
128 inline T & y () { return (*this)(1); }
130 inline T & z () { return (*this)(2); }
131
132 std::ostream &print(std::ostream &os) const
133 {
134 os << "Vertex( " << this->x() << " " << this->y() << " " << this->z() << " )\n";
135 return os;
136 }
137
138public:
139
140 std::vector<gsVertexHandle> nVertices;
141 //gsVector3d<T> coords;
142 bool sharp;
143
145 std::vector<gsFaceHandle> faces;
146 int numEdges;
147
148 T data;
149};
150
151 template<class T>
152 static bool Xless( typename gsVertex<T>::gsVertexHandle const & a,
153 typename gsVertex<T>::gsVertexHandle const & b )
154 {return a->x()< b->x() || ( a->x()==b->x() && a->y()<b->y() )
155 || ( a->x()==b->x() && a->y()==b->y() && a->z()<b->z()); }
156
157 template<class T>
158 static bool Yless( typename gsVertex<T>::gsVertexHandle const & a,
159 typename gsVertex<T>::gsVertexHandle const & b )
160 {return a->y()< b->y() || ( a->y()==b->y() && a->x()<b->x() ); }
161 template<class T>
162 static bool Zless( typename gsVertex<T>::gsVertexHandle const & a,
163 typename gsVertex<T>::gsVertexHandle const & b )
164 {return a->z()< b->z(); }
165
166// Lexicographic comparison for vertex handles
167
168template<class T>
169struct lexCompareVHandle
170{
171 bool operator() (typename gsVertex<T>::gsVertexHandle const & lhs,
172 typename gsVertex<T>::gsVertexHandle const & rhs) const
173 {return lhs->x()< rhs->x() || ( lhs->x()==rhs->x() && lhs->y()<rhs->y() )
174 || ( lhs->x()==rhs->x() && lhs->y()==rhs->y() && lhs->z()<rhs->z()); }
175};
176
177template<class T>
178T length(gsVertex<T> const & vert)
179{
180 //return (sqrt(vert.x()*vert.x()+vert.y()*vert.y()+vert.z()*vert.z()));
181 return vert.norm();
182}
183
184template<class T>
185bool operator < (typename gsVertex<T>::gsVertexHandle const & lhs,
186 typename gsVertex<T>::gsVertexHandle const & rhs)
187{
188 return !(lhs->x() < rhs->x() || (lhs->x() == rhs->x() && lhs->y() < rhs->y())
189 || (lhs->x() == rhs->x() && lhs->y() == rhs->y() && lhs->z() < rhs->z()));
190}
191template<class T>
192bool operator > (typename gsVertex<T>::gsVertexHandle const & lhs,
193 typename gsVertex<T>::gsVertexHandle const & rhs)
194{
195 return !(lhs->x() > rhs->x() || (lhs->x() == rhs->x() && lhs->y() > rhs->y())
196 || (lhs->x() == rhs->x() && lhs->y() == rhs->y() && lhs->z() > rhs->z()));
197}
198//template<class T>
199//bool operator == (typename gsVertex<T> const & lhs,
200// typename gsVertex<T> const & rhs)
201//{
202// return (lhs->x()== rhs->x()&& lhs->y()==rhs->y()&& lhs->z()==rhs->z())
203// ;}
204
212template<class T>
213bool operator == (gsVertex<T> const & lhs,gsVertex<T> const & rhs)
214{
215 return (lhs.x()==rhs.x())&&
216 (lhs.y()==rhs.y())&&
217 (lhs.z()==rhs.z());
218// return lhs.gsEigen::template Matrix<T,3,1>::operator==(rhs); /slower
219}
220
221template<class T>
222bool operator < (gsVertex<T> const & lhs,gsVertex<T> const & rhs)
223{
224 return (lhs.x()> rhs.x() || ( lhs.x()==rhs.x() && lhs.y()>rhs.y() )
225 || ( lhs.x()==rhs.x() && lhs.y()==rhs.y() && lhs.z()>rhs.z()));
226}
227
237template<class T>
238bool operator > (gsVertex<T> const & lhs,gsVertex<T> const & rhs)
239{
240 return (lhs.x() < rhs.x() ||
241 (lhs.x() == rhs.x() && lhs.y() < rhs.y()) ||
242 (lhs.x() == rhs.x() && lhs.y() == rhs.y() && lhs.z() < rhs.z()));
243}
244
251template<class T>
252bool operator != (gsVertex<T> const & lhs, gsVertex<T> const & rhs)
253{
254 //return lhs.gsEigen::template Matrix<T,3,1>::operator!=(rhs);
255 return !(lhs.x()== rhs.x()&& lhs.y()==rhs.y()&& lhs.z()==rhs.z());
256}
257
258} // namespace gismo
A fixed-size, statically allocated 3D vector.
Definition gsVector.h:219
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
gsVertex class that represents a 3D vertex for a gsMesh.
Definition gsVertex.h:27
T & x()
Definition gsVertex.h:126
std::vector< gsFaceHandle > faces
List of faces adjacent to this vertex.
Definition gsVertex.h:145
gsVertex(scalar_t x, scalar_t y, scalar_t z=0)
Constructor, take 3 scalars.
Definition gsVertex.h:51
T & y()
Definition gsVertex.h:128
T & z()
Definition gsVertex.h:130
void move(scalar_t dx, scalar_t dy, scalar_t dz)
Moves a gsVertex relatively.
Definition gsVertex.h:107
memory::shared_ptr< gsVertex > Ptr
Shared pointer for gsVertex.
Definition gsVertex.h:30
memory::unique_ptr< gsVertex > uPtr
Unique pointer for gsVertex.
Definition gsVertex.h:33
gsVertex(gsVector< T > const &u)
Constructor, takes a gsVector.
Definition gsVertex.h:63
T x() const
Definition gsVertex.h:120
T z() const
Definition gsVertex.h:124
T y() const
Definition gsVertex.h:122
gsVertex()
Constructor.
Definition gsVertex.h:42
void addFace(gsFaceHandle const &f)
Adds a gsFaceHandle f to the list of faces adjaent to this vertex.
Definition gsVertex.h:116
gsVertex(gsVector3d< T > const &u)
Constructor, takes a gsVector3d.
Definition gsVertex.h:57
uPtr clone() const
Clone Function (deep copy)
Definition gsVertex.h:103
#define index_t
Definition gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
This is the main header file that collects wrappers of Eigen for linear algebra.
Provides gsMeshElement class - a vertex, edge, face or cell of a gsMesh.
The G+Smo namespace, containing all definitions for the library.
bool operator!=(gsVertex< T > const &lhs, gsVertex< T > const &rhs)
Definition gsVertex.h:252