OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
geotoolbox.h
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
35 #ifndef geotoolbox_h
36 #define geotoolbox_h
37 
38 #include <list>
39 #include <cstdlib>
40 
41 #include "oofemcfg.h"
42 #include "floatarray.h"
43 
44 #ifdef __OOFEG
45  #include "oofeggraphiccontext.h"
46 #endif
47 
48 namespace oofem {
49 
50 #define GT_EPS 1.e-12
51 // zero for parallel lines test
52 #define GT_TEPS 1.e-16
53 
54 
60 class OOFEM_EXPORT Vertex
61 {
62 public:
64  Vertex(double x = 0, double y = 0) : coords(2) {
65  coords(0) = x;
66  coords(1) = y;
67  }
68  Vertex(double c [ 2 ]) : coords(2) {
69  coords(0) = c [ 0 ];
70  coords(1) = c [ 1 ];
71  }
72  Vertex(const Vertex & src) : coords(src.coords) { }
73  Vertex &operator = ( const Vertex & src ) {
74  coords = src.coords;
75  return * this;
76  }
77  void setCoords(double x, double y) {
78  coords(0) = x;
79  coords(1) = y;
80  }
81  const FloatArray *getCoords() const { return & coords; }
82 };
83 
84 
91 class OOFEM_EXPORT Polygon
92 {
93  std :: list< Vertex >vertices;
94 public:
95  Polygon() { }
96  void addVertex(Vertex v) { vertices.push_back(v); }
97  double computeVolume() const;
98  int testPoint(double x, double y) const;
99  double pointDistance(double x, double y) const;
100  void clear() { vertices.clear(); }
101 #ifdef __OOFEG
102  GraphicObj *draw(oofegGraphicContext &, bool filled, int layer = OOFEG_DEBUG_LAYER);
103 #endif
104 public:
106  {
107  bool last;
108  const Polygon *ptr;
110  std :: list< Vertex > :: const_iterator iter;
111 public:
112  PolygonEdgeIterator(const Polygon * p) : iter() {
113  iter = p->vertices.begin();
114  if ( iter == p->vertices.end() ) {
115  last = true;
116  } else {
117  curr = ( * iter );
118  ptr = p;
119  last = false;
120  }
121  }
122  int giveNext(Vertex &p1, Vertex &p2) {
123  Vertex next;
124  if ( last ) {
125  return 0;
126  } else {
127  //next=*(++iter);
128  ++iter;
129  if ( iter == ptr->vertices.end() ) {
130  next = * ( ptr->vertices.begin() );
131  last = true;
132  } else {
133  next = * iter;
134  }
135 
136  p1 = curr;
137  p2 = next;
138  curr = next;
139  return 1;
140  }
141  }
142  };
143 
145  {
146  const Polygon *ptr;
147  std :: list< Vertex > :: const_iterator iter;
148 public:
149  PolygonVertexIterator(const Polygon * p) : iter() {
150  iter = p->vertices.begin();
151  ptr = p;
152  }
153  void init(const Polygon *p) {
154  iter = p->vertices.begin();
155  ptr = p;
156  }
157  int giveNext(Vertex &p1) {
158  if ( iter == ptr->vertices.end() ) {
159  return 0;
160  } else {
161  p1 = ( * iter );
162  }
163 
164  ++iter;
165  return 1;
166  }
167  int giveNext(const Vertex **p1) {
168  if ( iter == ptr->vertices.end() ) {
169  return 0;
170  } else {
171  * p1 = iter.operator->( );
172  }
173 
174  ++iter;
175  return 1;
176  }
177  };
178 };
179 
191 class OOFEM_EXPORT Graph
192 {
193 protected:
194  enum nodeStatus { NS_Vertex, NS_IntersectionVertex, NS_Intersection };
195  struct node
196  {
197  double x, y;
198  struct node *next;
199  struct node *prev;
200  struct node *nextPoly; /* pointer to the next polygon */
201  struct node *neighbor; /* the corresponding intersection point */
202  //int intersect; /* 1 if an intersection point, 0 otherwise */
204  int entry; /* 1 if entry point (edge starting at this node is inside), -1 boundary edge, 0 otherwise */
205  int visited; /* 1 if the node has been visited, 0 otherwise */
206  double alpha; /* intersection point placement */
207  };
208 
209  node *s, *c;
210 public:
211  Graph() : s(NULL), c(NULL) { }
212  ~Graph();
213 
214  void clip(Polygon &result, const Polygon &a, const Polygon &b);
215 protected:
216  void insert(node *ins, node *first, node *last); // insert node in graph
218  node *createNode(double x, double y, node *next, node *prev, node *nextPoly,
219  node *neighbor, nodeStatus st, int entry, int visited, double alpha);
220  node *next_node(node *p); // return next node in graph
221  node *prev_node(node *p); // return prev node in graph
222  node *last_node(node *p); // returns last node in graph
223  node *first(node *p);
224  void remove(node *n);
225  double dist(double x1, double y1, double x2, double y2);
226 
227  int testIfIntersect(node *p1, node *p2, node *q1, node *q2,
228  double *alpha_p, double *alpha_q, double *xint, double *yint);
229 
230  int testIfCoincident(node *p1, node *p2, node *q1, node *q2, double *alpha_1, double *alpha_2);
231  int testPoint(node *poly, double x, double y) const;
232 
233  bool belongs(node *n, node *v1, node *v2);
234  bool intersectionExist(node *p1, node *p2, node *q1, node *q2);
235  void removeIntersectionIfExist(node *p1, node *p2, node *q1, node *q2);
236  int vertex2IntersectionVertex(node *v, node *l1, node *l2);
237  void testNewIntersectionVertexEdgeCollapse(node *v, node *l1, node *l2);
238  bool testCollapsedEdge(node *p1, node *p2);
239  void merge2vertex(node *v1, node *v2);
240 
241  void printYourself();
242 
243  void clear();
244 };
245 
246 class OOFEM_EXPORT GT_Exception
247 {
248  const char *msg, *file;
249  int line;
250 
251 public:
252  GT_Exception(const char *file, int line) : msg(NULL), file(file), line(line) { }
253  GT_Exception(const char *msg, const char *file, int line) : msg(msg), file(file), line(line) { }
255 
256  void print();
257 };
258 
259 #define THROW_GT_EXCEPTION() throw GT_Exception(__FILE__, __LINE__);
260 #define THROW_GT_EXCEPTIONM(m) throw GT_Exception(m, __FILE__, __LINE__);
261 } // end namespace oofem
262 #endif // geotoolbox_h
std::list< Vertex >::const_iterator iter
Definition: geotoolbox.h:110
std::list< Vertex >::const_iterator iter
Definition: geotoolbox.h:147
int giveNext(const Vertex **p1)
Definition: geotoolbox.h:167
Vertex(const Vertex &src)
Definition: geotoolbox.h:72
struct node * neighbor
Definition: geotoolbox.h:201
nodeStatus status
Definition: geotoolbox.h:203
const FloatArray * getCoords() const
Definition: geotoolbox.h:81
GT_Exception(const char *file, int line)
Definition: geotoolbox.h:252
FloatArray coords
Definition: geotoolbox.h:63
struct node * next
Definition: geotoolbox.h:198
GT_Exception(const char *msg, const char *file, int line)
Definition: geotoolbox.h:253
Vertex(double x=0, double y=0)
Definition: geotoolbox.h:64
Class representing the special graph constructed from two polygons that is used to perform boolean op...
Definition: geotoolbox.h:191
PolygonEdgeIterator(const Polygon *p)
Definition: geotoolbox.h:112
Class representing vector of real numbers.
Definition: floatarray.h:82
PolygonVertexIterator(const Polygon *p)
Definition: geotoolbox.h:149
Class representing 2D polygon.
Definition: geotoolbox.h:91
void setCoords(double x, double y)
Definition: geotoolbox.h:77
Vertex(double c[2])
Definition: geotoolbox.h:68
struct node * nextPoly
Definition: geotoolbox.h:200
Class representing vertex.
Definition: geotoolbox.h:60
std::list< Vertex > vertices
Definition: geotoolbox.h:93
#define OOFEG_DEBUG_LAYER
the oofem namespace is to define a context or scope in which all oofem names are defined.
void addVertex(Vertex v)
Definition: geotoolbox.h:96
const char * msg
Definition: geotoolbox.h:248
struct node * prev
Definition: geotoolbox.h:199
int giveNext(Vertex &p1, Vertex &p2)
Definition: geotoolbox.h:122

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011