G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsPlanarDomain.h
Go to the documentation of this file.
1 
17 #pragma once
18 
19 #include <iostream>
20 #include <deque>
21 
22 #include <gsModeling/gsCurveLoop.h>
23 #include <gsModeling/gsTemplate.h>
24 
25 // #include <gsUtils/gsSortedVector.h>
26 
27 
28 namespace gismo
29 {
30 template <class T>
31 class gsBemSolution;
32 
41 // TODO Add gsWriteParaview using PolygonalData....
42 template<class T>
44 {
45 public:
46 
47  typedef memory::shared_ptr<gsPlanarDomain> Ptr;
48  typedef memory::unique_ptr<gsPlanarDomain> uPtr;
49 
52 
55  {
56  if ( boundary->is_ccw() )
57  {
58  m_loops.push_back(boundary);
59  }
60  else
61  {
62  boundary->reverse();
63  m_loops.push_back(boundary);
64  }
65 
67  }
68 
70  gsPlanarDomain( std::vector< gsCurveLoop<T> *> const & loops);
71 
74  {
75  m_loops.push_back( new gsCurveLoop<T>(boundary) );
77  }
78 
80  {
81  freeAll( m_loops );
82  }
83 
86  : m_loops( other.m_loops.size() )
87  {
88  m_bbox = other.m_bbox;
89  cloneAll( other.m_loops.begin(), other.m_loops.end(),
90  this->m_loops.begin() );
91  }
92 
93 
96  {
97  freeAll( m_loops );
98  m_loops.resize( other.m_loops.size() );
99  m_bbox = other.m_bbox;
100  cloneAll( other.m_loops.begin(), other.m_loops.end(),
101  this->m_loops.begin() );
102  return *this;
103  }
104 
106  //GISMO_CLONE_FUNCTION(gsPlanarDomain)
107  uPtr clone() const
108  {
109  return uPtr(new gsPlanarDomain(*this));
110  }
111 
112 public:
113 
114  void check()
115  {
116  if ( !m_loops[0]->is_ccw() )
117  gsWarn<< "Wrong orientation in outer loop of planar domain.";
118  for(size_t i=1; i< m_loops.size(); i++)
119  {
120  if( m_loops[i]->is_ccw())
121  gsWarn<< "Wrong orientation in loop["<< i <<"] of planar domain.";
122  }
123  }
124 
125  void insertHole( gsCurveLoop<T> * hole )
126  {
127  if ( hole->is_ccw() )
128  {
129  hole->reverse();
130  }
131  m_loops.push_back( hole );
132  }
133 
134  int numLoops() const { return m_loops.size(); }
135  int numHoles() const { return m_loops.size() -1; }
136 
137  gsCurveLoop<T> & outer() { return loop(0); }
138  const gsCurveLoop<T> & outer() const { return loop(0); }
139 
140  gsCurveLoop<T> & loop(unsigned loopNumber)
141  {
142  GISMO_ASSERT( loopNumber<m_loops.size(), "Loop does not exist" );
143  return *m_loops[loopNumber];
144  }
145  const gsCurveLoop<T> & loop(unsigned loopNumber) const
146  {
147  GISMO_ASSERT( loopNumber<m_loops.size(), "Loop does not exist" );
148  return *m_loops[loopNumber];
149  }
150 
151  gsCurve<T> & curve(unsigned loopNumber, unsigned curveNumber)
152  {
153  GISMO_ASSERT( loopNumber<m_loops.size(), "Loop does not exist" );
154  return m_loops[loopNumber]->curve(curveNumber);
155  }
156  const gsCurve<T> & curve(unsigned loopNumber, unsigned curveNumber) const
157  {
158  GISMO_ASSERT( loopNumber<m_loops.size(), "Loop does not exist" );
159  return m_loops[loopNumber]->curve(curveNumber);
160  }
161 
162  bool contains( gsVector<T> const &, T)
163  {
165  }
166 
167  gsMatrix<T> boundingBox() const
168  {
169  gsMatrix<T> res(2,2);
170 
171  res = m_loops[0]->getBoundingBox();
172  return res;
173  }
174 
175  void translate(gsVector<T> const & v)
176  {
177  for ( typename std::vector< gsCurveLoop<T> *>::iterator it =
178  m_loops.begin(); it != m_loops.end(); ++it)
179  (*it)->translate(v);
180  }
181 
182  //gsMatrix<T> averageValue( std::vector<gsFunction<T>*> const &f, std::vector<T> const & breaks);
183 
187  bool inDomain( gsMatrix<T> const & u, int direction = 0);
188 
191  bool onBoundary(gsMatrix<T> const & u);
192 
194  std::ostream &print(std::ostream &os) const;
195 
196  friend std::ostream& operator<<(std::ostream& os, const gsPlanarDomain& pd) { return pd.print(os); }
197 
199  void sampleLoop_into( int loopID, int npoints, int numEndPoints, gsMatrix<T> & u );
200 
201  gsMatrix<T> sampleLoop( int loopID, int npoints=50, int numEndPoints=2)
202  {
203  gsMatrix<T> u;
204  sampleLoop_into( loopID, npoints, numEndPoints, u );
205  return u;
206  }
207 
208  void sampleCurve_into( int loopID, int curveID, int npoints, gsMatrix<T> & u );
209 
210  gsMatrix<T> sampleCurve(int loopID, int curveID, int npoints = 50)
211  {
212  gsMatrix<T> u;
213  sampleCurve_into( loopID, curveID, npoints, u );
214  return u;
215  }
216 
218  memory::unique_ptr<gsMesh<T> > toMesh(int npoints = 50) const; // FOR NOW ONLY ONE LOOP
219 
222  uPtr split(int startIndex, int endIndex,
223  gsCurve<T> * newCurveThisFace, gsCurve<T> * newCurveNewFace)
224  {
225  typename gsCurveLoop<T>::uPtr newCurveLoop = this->m_loops[0]->split(startIndex, endIndex, newCurveThisFace, newCurveNewFace);
227 
228  return uPtr(new gsPlanarDomain<T>(newCurveLoop.release()));
229  }
230 
233  // TODO: make this function private or protected. In order to do this we
234  // would need to replace the functions "outer", "loop" and "curve" with
235  // new public functions for modifying the loops that call this function
236  // when they are done.
238  {
239  assert(!m_loops.empty()); // outer loop does not exist
240  m_bbox = m_loops[0]->getBoundingBox();
241  }
242 
247  gsMatrix<T> splitCurve(size_t loopId, size_t curveId, T lengthRatio=.5)
248  {
249  return m_loops[loopId]->splitCurve(curveId,lengthRatio);
250  }
251 
252 
253 
254  // Data members
255 private:
256 
257  // m_loops[0] is CCW, all others CW holes
258  std::vector< gsCurveLoop<T> *> m_loops;
259 
260  // The lower left and upper right corner of a square bounding the
261  // domain
262  gsMatrix<T,2,2> m_bbox;
263 
264 public:
265 # define Eigen gsEigen
266  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
267 # undef Eigen
268 
269 }; // class gsPlanarDomain
270 
271 } // namespace gismo
272 
273 
274 #ifndef GISMO_BUILD_LIB
275 #include GISMO_HPP_HEADER(gsPlanarDomain.hpp)
276 #endif
Provides definition of gsTemplate class.
void sampleLoop_into(int loopID, int npoints, int numEndPoints, gsMatrix< T > &u)
linearly discriti
Definition: gsPlanarDomain.hpp:169
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
Abstract base class representing a curve.
Definition: gsCurve.h:30
memory::unique_ptr< gsMesh< T > > toMesh(int npoints=50) const
Return a triangulation of the planar domain.
Definition: gsPlanarDomain.hpp:248
void updateBoundingBox()
Definition: gsPlanarDomain.h:237
gsPlanarDomain(gsCurve< T > *boundary)
Construct planar domain by an outer boundary given by a curve.
Definition: gsPlanarDomain.h:73
Struct that defines the boundary sides and corners and types of a geometric object.
Definition: gsBoundary.h:55
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void cloneAll(It start, It end, ItOut out)
Clones all pointers in the range [start end) and stores new raw pointers in iterator out...
Definition: gsMemory.h:295
uPtr clone() const
Clone function. Used to make a copy of the (derived) geometry.
Definition: gsPlanarDomain.h:107
gsMatrix< T > splitCurve(size_t loopId, size_t curveId, T lengthRatio=.5)
Definition: gsPlanarDomain.h:247
#define gsWarn
Definition: gsDebug.h:50
memory::unique_ptr< gsCurveLoop > uPtr
Unique pointer for gsCurveLoop.
Definition: gsCurveLoop.h:47
GISMO_DEPRECATED index_t direction(index_t s)
Returns the parametric direction that corresponds to side s.
Definition: gsBoundary.h:1048
gsPlanarDomain()
Default empty constructor.
Definition: gsPlanarDomain.h:51
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition: gsMemory.h:312
gsPlanarDomain(const gsPlanarDomain &other)
Copy constructor.
Definition: gsPlanarDomain.h:85
Class representing a Planar domain with an outer boundary and a number of holes.
Definition: gsPlanarDomain.h:43
gsPlanarDomain(gsCurveLoop< T > *boundary)
Construct planar domain by giving the outer boundary.
Definition: gsPlanarDomain.h:54
gsPlanarDomain & operator=(const gsPlanarDomain &other)
Assignment operator.
Definition: gsPlanarDomain.h:95
A closed loop given by a collection of curves.
Definition: gsCurveLoop.h:36
Interface for gsCurveLoop class, representing a loop of curves, in anticlockwise order.
uPtr split(int startIndex, int endIndex, gsCurve< T > *newCurveThisFace, gsCurve< T > *newCurveNewFace)
Definition: gsPlanarDomain.h:222
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsPlanarDomain.hpp:151