G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsVertex.h
Go to the documentation of this file.
1 
14 #pragma once
15 
17 #include <gsCore/gsLinearAlgebra.h>
18 
19 namespace gismo
20 {
21 
25 template <class T>
26 class gsVertex : public gsMeshElement<T>, public gsVector3d<T>
27 {
28 public:
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 
40 public:
42  gsVertex() : MeshElement(), gsVector3d<T>() { }
43 
44  template<typename OtherDerived>
45  gsVertex(const gsEigen::MatrixBase<OtherDerived>& other) :
46  MeshElement(), gsVector3d<T>(other) { }
47 
50  gsVertex(scalar_t x, scalar_t y, scalar_t z = 0) :
51  MeshElement(), gsVector3d<T>(x,y,z),sharp(0), numEdges(0), data()
52  { }
53 
56  gsVertex( gsVector3d<T> const & u) :
57  MeshElement(), gsVector3d<T>(u),sharp(0), numEdges(0), data()
58  { }
59 
62  gsVertex( gsVector<T> const & u) :
63  MeshElement(), gsVector3d<T>(),sharp(0),numEdges(0), data()
64  {
65  // vertex is always a 3-cooordinate vector.
66  const index_t r = u.rows();
67  GISMO_ASSERT(r<=3, "Invalid input in gsVertex constructor");
68 
69  if ( r < 3 )
70  this->tail(3-r).setZero();
71 
72  this->head(r) = u;
73  }
74 
75  virtual ~gsVertex() { };
76 
77 
78  void setCoords(gsVector<T> const & coord)
79  {
80  this->gsVector3d<T>::operator=(coord);
81  }
82 
83  gsVertex & operator=(const gsVertex & other)
84  {
85  this->gsVector3d<T>::operator=(other);
86  return *this;
87  }
88 
89  //GISMO_CLONE_FUNCTION(gsVertex)
91  uPtr clone() const { return uPtr(new gsVertex(*this)); }
92 
95  void move(scalar_t dx, scalar_t dy, scalar_t dz)
96  {
97  this->x() += dx;
98  this->y() += dy;
99  this->z() += dz;
100  }
101 
104  inline void addFace(gsFaceHandle const& f)
105  { faces.push_back( f ); }
106 
108  inline T x () const { return (*this)(0); }
110  inline T y () const { return (*this)(1); }
112  inline T z () const { return (*this)(2); }
114  inline T & x () { return (*this)(0); }
116  inline T & y () { return (*this)(1); }
118  inline T & z () { return (*this)(2); }
119 
120  std::ostream &print(std::ostream &os) const
121  {
122  os << "Vertex( " << this->x() << " " << this->y() << " " << this->z() << " )\n";
123  return os;
124  }
125 
126 public:
127 
128  std::vector<gsVertexHandle> nVertices;
129  //gsVector3d<T> coords;
130  bool sharp;
131 
133  std::vector<gsFaceHandle> faces;
134  int numEdges;
135 
136  T data;
137 };
138 
139  template<class T>
140  static bool Xless( typename gsVertex<T>::gsVertexHandle const & a,
141  typename gsVertex<T>::gsVertexHandle const & b )
142  {return a->x()< b->x() || ( a->x()==b->x() && a->y()<b->y() )
143  || ( a->x()==b->x() && a->y()==b->y() && a->z()<b->z()); }
144 
145  template<class T>
146  static bool Yless( typename gsVertex<T>::gsVertexHandle const & a,
147  typename gsVertex<T>::gsVertexHandle const & b )
148  {return a->y()< b->y() || ( a->y()==b->y() && a->x()<b->x() ); }
149  template<class T>
150  static bool Zless( typename gsVertex<T>::gsVertexHandle const & a,
151  typename gsVertex<T>::gsVertexHandle const & b )
152  {return a->z()< b->z(); }
153 
154 // Lexicographic comparison for vertex handles
155 
156 template<class T>
157 struct lexCompareVHandle
158 {
159  bool operator() (typename gsVertex<T>::gsVertexHandle const & lhs,
160  typename gsVertex<T>::gsVertexHandle const & rhs) const
161  {return lhs->x()< rhs->x() || ( lhs->x()==rhs->x() && lhs->y()<rhs->y() )
162  || ( lhs->x()==rhs->x() && lhs->y()==rhs->y() && lhs->z()<rhs->z()); }
163 };
164 
165 template<class T>
166 T length(gsVertex<T> const & vert)
167 {
168  //return (sqrt(vert.x()*vert.x()+vert.y()*vert.y()+vert.z()*vert.z()));
169  return vert.norm();
170 }
171 
172 template<class T>
173 bool operator < (typename gsVertex<T>::gsVertexHandle const & lhs,
174  typename gsVertex<T>::gsVertexHandle const & rhs)
175 {
176  return !(lhs->x() < rhs->x() || (lhs->x() == rhs->x() && lhs->y() < rhs->y())
177  || (lhs->x() == rhs->x() && lhs->y() == rhs->y() && lhs->z() < rhs->z()));
178 }
179 template<class T>
180 bool operator > (typename gsVertex<T>::gsVertexHandle const & lhs,
181  typename gsVertex<T>::gsVertexHandle const & rhs)
182 {
183  return !(lhs->x() > rhs->x() || (lhs->x() == rhs->x() && lhs->y() > rhs->y())
184  || (lhs->x() == rhs->x() && lhs->y() == rhs->y() && lhs->z() > rhs->z()));
185 }
186 //template<class T>
187 //bool operator == (typename gsVertex<T> const & lhs,
188 // typename gsVertex<T> const & rhs)
189 //{
190 // return (lhs->x()== rhs->x()&& lhs->y()==rhs->y()&& lhs->z()==rhs->z())
191 // ;}
192 
200 template<class T>
201 bool operator == (gsVertex<T> const & lhs,gsVertex<T> const & rhs)
202 {
203  return (lhs.x()==rhs.x())&&
204  (lhs.y()==rhs.y())&&
205  (lhs.z()==rhs.z());
206 // return lhs.gsEigen::template Matrix<T,3,1>::operator==(rhs); /slower
207 }
208 
209 template<class T>
210 bool operator < (gsVertex<T> const & lhs,gsVertex<T> const & rhs)
211 {
212  return (lhs.x()> rhs.x() || ( lhs.x()==rhs.x() && lhs.y()>rhs.y() )
213  || ( lhs.x()==rhs.x() && lhs.y()==rhs.y() && lhs.z()>rhs.z()));
214 }
215 
225 template<class T>
226 bool operator > (gsVertex<T> const & lhs,gsVertex<T> const & rhs)
227 {
228  return (lhs.x() < rhs.x() ||
229  (lhs.x() == rhs.x() && lhs.y() < rhs.y()) ||
230  (lhs.x() == rhs.x() && lhs.y() == rhs.y() && lhs.z() < rhs.z()));
231 }
232 
239 template<class T>
240 bool operator != (gsVertex<T> const & lhs, gsVertex<T> const & rhs)
241 {
242  //return lhs.gsEigen::template Matrix<T,3,1>::operator!=(rhs);
243  return !(lhs.x()== rhs.x()&& lhs.y()==rhs.y()&& lhs.z()==rhs.z());
244 }
245 
246 } // namespace gismo
A fixed-size, statically allocated 3D vector.
Definition: gsVector.h:218
void addFace(gsFaceHandle const &f)
Adds a gsFaceHandle f to the list of faces adjaent to this vertex.
Definition: gsVertex.h:104
Provides gsMeshElement class - a vertex, edge, face or cell of a gsMesh.
memory::shared_ptr< gsVertex > Ptr
Shared pointer for gsVertex.
Definition: gsVertex.h:30
#define index_t
Definition: gsConfig.h:32
T & x()
Definition: gsVertex.h:114
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
T & y()
Definition: gsVertex.h:116
std::vector< gsFaceHandle > faces
List of faces adjacent to this vertex.
Definition: gsVertex.h:133
uPtr clone() const
Clone Function (deep copy)
Definition: gsVertex.h:91
gsVertex()
Constructor.
Definition: gsVertex.h:42
bool operator!=(gsVertex< T > const &lhs, gsVertex< T > const &rhs)
Definition: gsVertex.h:240
gsVertex(gsVector< T > const &u)
Constructor, takes a gsVector.
Definition: gsVertex.h:62
void move(scalar_t dx, scalar_t dy, scalar_t dz)
Moves a gsVertex relatively.
Definition: gsVertex.h:95
T x() const
Definition: gsVertex.h:108
gsVertex(gsVector3d< T > const &u)
Constructor, takes a gsVector3d.
Definition: gsVertex.h:56
T y() const
Definition: gsVertex.h:110
This is the main header file that collects wrappers of Eigen for linear algebra.
gsVertex(scalar_t x, scalar_t y, scalar_t z=0)
Constructor, take 3 scalars.
Definition: gsVertex.h:50
T & z()
Definition: gsVertex.h:118
memory::unique_ptr< gsVertex > uPtr
Unique pointer for gsVertex.
Definition: gsVertex.h:33
T z() const
Definition: gsVertex.h:112
gsVertex class that represents a 3D vertex for a gsMesh.
Definition: gsVertex.h:26