xc
DqPtrsEntities.h
1 //----------------------------------------------------------------------------
2 // XC program; finite element analysis code
3 // for structural analysis and design.
4 //
5 // Copyright (C) Luis Claudio Pérez Tato
6 //
7 // This program derives from OpenSees <http://opensees.berkeley.edu>
8 // developed by the «Pacific earthquake engineering research center».
9 //
10 // Except for the restrictions that may arise from the copyright
11 // of the original program (see copyright_opensees.txt)
12 // XC is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program.
25 // If not, see <http://www.gnu.org/licenses/>.
26 //----------------------------------------------------------------------------
27 //DqPtrsEntities.h
28 //deque de pointers (se emplear en la clase Set).
29 
30 
31 #ifndef DQPTRSENTITIES_H
32 #define DQPTRSENTITIES_H
33 
34 #include "DqPtrs.h"
35 #include "xc_utils/src/geom/pos_vec/Pos3d.h"
36 #include "xc_utils/src/geom/d3/BND3d.h"
37 
38 class GeomObj3d;
39 class BND3d;
40 
41 namespace XC {
42 
44 template <class T>
45 class DqPtrsEntities: public DqPtrs<T>
46  {
47  public:
48  typedef DqPtrs<T> dq_ptr;
49  typedef typename dq_ptr::const_iterator const_iterator;
50  typedef typename dq_ptr::iterator iterator;
51 
52  DqPtrsEntities(CommandEntity *owr= nullptr)
53  : DqPtrs<T>(owr) {}
54  DqPtrsEntities(const DqPtrs<T> &other)
55  : DqPtrs<T>(other) {}
56  explicit DqPtrsEntities(const std::deque<T *> &ts)
57  : DqPtrs<T>(ts) {}
58  explicit DqPtrsEntities(const std::set<const T *> &ts)
59  : DqPtrs<T>(ts) {}
60 
63 
64  void remove(const DqPtrsEntities<T> &other);
65  void intersect(const DqPtrsEntities<T> &other);
66 
67  T *searchName(const std::string &nmb);
68  T *getNearest(const Pos3d &p);
69  const T *getNearest(const Pos3d &p) const;
70  DqPtrsEntities<T> pickEntitiesInside(const GeomObj3d &, const double &tol= 0.0) const;
71  BND3d Bnd(void) const;
72  };
73 
74 
76 template <class T>
77 T *DqPtrsEntities<T>::searchName(const std::string &nmb)
78  {
79  for(const_iterator i= this->begin();i!=this->end();i++)
80  if((*i)->getName()==nmb) return *i;
81  return nullptr;
82  }
83 
85 template <class T>
87  {
88  T *retval= nullptr;
89  if(!this->empty())
90  {
91  const_iterator i= this->begin();
92  double d2= (*i)->getSquaredDistanceTo(p);
93  retval= *i; i++;
94  double tmp;
95  for(;i!=this->end();i++)
96  {
97  tmp= (*i)->getSquaredDistanceTo(p);
98  if(tmp<d2)
99  {
100  d2= tmp;
101  retval= *i;
102  }
103  }
104  }
105  return retval;
106  }
107 
109 template <class T>
110 const T *DqPtrsEntities<T>::getNearest(const Pos3d &p) const
111  {
112  const T *retval= nullptr;
113  if(!this->empty())
114  {
115  const_iterator i= this->begin();
116  double d2= (*i)->getSquaredDistanceTo(p);
117  retval= *i; i++;
118  double tmp;
119  for(;i!=this->end();i++)
120  {
121  tmp= (*i)->getSquaredDistanceTo(p);
122  if(tmp<d2)
123  {
124  d2= tmp;
125  retval= *i;
126  }
127  }
128  }
129  return retval;
130  }
131 
137 template <class T>
138 DqPtrsEntities<T> DqPtrsEntities<T>::pickEntitiesInside(const GeomObj3d &geomObj, const double &tol) const
139  {
140  DqPtrsEntities<T> retval;
141  for(const_iterator i= this->begin();i!= this->end();i++)
142  {
143  T *t= (*i);
144  assert(t);
145  if(t->In(geomObj,tol))
146  retval.push_back(t);
147  }
148  return retval;
149  }
150 
153 template <class T>
154 BND3d DqPtrsEntities<T>::Bnd(void) const
155  {
156  BND3d retval;
157  if(!this->empty())
158  {
159  const_iterator i= this->begin();
160  const T *t= (*i);
161  assert(t);
162  retval= t->Bnd();
163  i++;
164  for(;i!= this->end();i++)
165  {
166  const T *t= (*i);
167  assert(t);
168  retval+= t->Bnd();
169  }
170  }
171  return retval;
172  }
173 
175 template <class T>
177  {
178  for(const_iterator i= other.begin();i!= other.end();i++)
179  {
180  const T *t= (*i);
181  iterator j= find(this->begin(),this->end(),t);
182  if(j!=this->end()) //Found.
183  this->erase(j);
184  }
185  }
186 
188 template <class T>
190  {
191  for(const_iterator i= other.begin();i!= other.end();i++)
192  {
193  const T *t= (*i);
194  iterator j= find(this->begin(),this->end(),t);
195  if(j==this->end()) //Not found
196  this->erase(j);
197  }
198  }
199 
201 template <class T>
203  {
204  remove(other);
205  return *this;
206  }
207 
209 template <class T>
211  {
212  intersect(other);
213  return *this;
214  }
215 
216 
218 template <class T>
220  {
221  DqPtrsEntities<T> retval(a);
222  retval+=b;
223  return retval;
224  }
225 
227 template <class T>
229  {
230  DqPtrsEntities<T> retval;
231  for(typename DqPtrsEntities<T>::const_iterator i= a.begin();i!= a.end();i++)
232  {
233  const T *t= (*i);
234  const typename DqPtrsEntities<T>::const_iterator j= find(b.begin(),b.end(),t);
235  if(j==b.end()) //Not found in b.
236  retval.push_back(t);
237  }
238  return retval;
239  }
240 
242 template <class T>
244  {
245  DqPtrsEntities<T> retval;
246  for(typename DqPtrsEntities<T>::const_iterator i= a.begin();i!= a.end();i++)
247  {
248  const T *t= (*i);
249  const typename DqPtrsEntities<T>::const_iterator j= find(b.begin(),b.end(),t);
250  if(j!=b.end()) //Found also in b.
251  retval.push_back(t);
252  }
253  return retval;
254  }
255 
256 } //end of XC namespace
257 
258 #endif
259 
FiberSet operator*(const FiberSet &, const FiberSet &)
Return the fibers in a that are also in b.
Definition: FiberSet.cc:87
void intersect(const DqPtrsEntities< T > &other)
Removes the objects that belongs also to the parameter.
Definition: DqPtrsEntities.h:189
BND3d Bnd(void) const
Return the entities boundary.
Definition: DqPtrsEntities.h:154
FiberSet operator+(const FiberSet &, const FiberSet &)
Return the union of both containers.
Definition: FiberSet.cc:65
T * getNearest(const Pos3d &p)
Returns the object closest to the position being passed as parameter.
Definition: DqPtrsEntities.h:86
Container for preprocessor entities (points, lines, surfaces,...)
Definition: DqPtrsEntities.h:45
void remove(const DqPtrsEntities< T > &other)
Removes the objects that belongs also to the parameter.
Definition: DqPtrsEntities.h:176
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
FiberSet operator-(const FiberSet &, const FiberSet &)
Return the fibers in a that are not in b.
Definition: FiberSet.cc:73
DqPtrsEntities & operator*=(const DqPtrsEntities &)
*= (intersection) operator.
Definition: DqPtrsEntities.h:210
T * searchName(const std::string &nmb)
Returns a pointer to the objet identified by the name.
Definition: DqPtrsEntities.h:77
DqPtrsEntities & operator-=(const DqPtrsEntities &)
-= (difference) operator.
Definition: DqPtrsEntities.h:202
DqPtrsEntities< T > pickEntitiesInside(const GeomObj3d &, const double &tol=0.0) const
Return a container with the entities that lie inside the geometric object.
Definition: DqPtrsEntities.h:138
Pointer to (nodes, elements, points, lines,...) container.
Definition: DqPtrs.h:56