Plugins
Loading...
Searching...
No Matches
boxunions.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Gesellschaft fuer Anlagen- und Reaktorsicherheit gGmbH
3 * SPDX-License-Identifier: EUPL-1.2
4 * SPDX-FileContributor: Dmitry Logashenko
5 * SPDX-FileContributor: Goethe Universität Frankfurt
6 * SPDX-FileType: SOURCE
7 *
8 * This file is part of d3f++.
9 * d3f++ is an extension for UG4. Licensing information and citation requirements of UG4 are provided in LICENSES/UG4-LGPL_2.1
10 */
11
12
13
14/*
15 * Definition of surface functions by unions of boxes
16 */
17#ifndef __H__UG__PLUGINS__D3F__BOXUNIONS__
18#define __H__UG__PLUGINS__D3F__BOXUNIONS__
19
20#include <vector>
21
22// ug4 headers
23#include "common/common.h"
24#include "common/math/ugmath.h"
25
26namespace ug {
27namespace d3f {
28
35{
36// Description of the union of boxes
38 {
39 public:
41 int ident;
42 size_t dir;
45 std::vector<MathVector<2> > beg_corner;
46 std::vector<MathVector<2> > end_corner;
47
50 (
51 int the_id,
52 size_t the_dir,
53 number the_dx, number the_dy,
54 number x, number y,
55 t_box_union_item * the_tl = NULL)
56 : tl (the_tl), ident (the_id), dir (the_dir), dx_half (the_dx/2), dy_half (the_dy/2),
57 beg_corner (1), end_corner (1)
58 {
59 beg_corner[0][0] = x; beg_corner[0][1] = y;
60 end_corner[0] = beg_corner[0];
61 }
62
64 void append (number x, number y);
65
67 bool pnt_inside (number x, number y) const;
68 };
69
70public:
71
74 : m_dir (2), m_dx (1), m_dy (1), m_box_unions (NULL)
75 {};
76
79 {
81 while (t != NULL)
82 {
83 t_box_union_item * s = t->tl;
84 delete t;
85 t = s;
86 }
87 }
88
91 (
92 size_t dir,
93 number dx,
94 number dy
95 )
96 {
97 m_dir = dir;
98 m_dx = dx; m_dy = dy;
99 }
100
102 void append_point (number x, number y, int ident)
103 {
104 t_box_union_item * t = union_by_id (ident);
105 if (t != NULL)
106 t->append (x, y);
107 else
109 }
110
112 bool get_id_by_pnt (number x, number y, int & ident) const
113 {
114 for (t_box_union_item * t = m_box_unions; t != NULL; t = t->tl)
115 if (t->pnt_inside (x, y))
116 {
117 ident = t->ident;
118 return true;
119 }
120 return false;
121 }
122
124 int get_id_by_pnt_dv (number x, number y, int dv) const
125 {
126 int ident;
127 return (get_id_by_pnt (x, y, ident))? ident : dv;
128 }
129
131 void load_points_from (const char * file_name);
132
133private:
134
136 t_box_union_item * union_by_id (int ident) const
137 {
139 for (t = m_box_unions; t != NULL; t = t->tl)
140 if (t->ident == ident)
141 break;
142 return t;
143 }
144
146 void load_points_from (std::istream & input);
147
148private:
149 size_t m_dir;
153};
154
155} // namespace d3f
156} // end namespace ug
157
158#endif // __H__UG__PLUGINS__D3F__BOXUNIONS__
159
160/* End of File */
parameterString s
Definition Biogas.lua:2
number dy_half
y-size of the boxes / 2
Definition boxunions.h:44
void append(number x, number y)
appends a point at the end of the list
Definition boxunions.cpp:26
std::vector< MathVector< 2 > > end_corner
right corners of the boxes
Definition boxunions.h:46
int ident
identifier of the union
Definition boxunions.h:41
size_t dir
direction (0 = x, 1 = y, otherwise none)
Definition boxunions.h:42
t_box_union_item(int the_id, size_t the_dir, number the_dx, number the_dy, number x, number y, t_box_union_item *the_tl=NULL)
constructor: we need at least one point
Definition boxunions.h:50
bool pnt_inside(number x, number y) const
checks whether a point is in the union
Definition boxunions.cpp:49
number dx_half
x-size of the boxes / 2
Definition boxunions.h:43
std::vector< MathVector< 2 > > beg_corner
left corners of the boxes
Definition boxunions.h:45
t_box_union_item * tl
next union
Definition boxunions.h:40
Definition boxunions.h:35
number m_dy
y-size of the boxes
Definition boxunions.h:151
t_box_union_item * union_by_id(int ident) const
gets a union by id
Definition boxunions.h:136
void set_grid_sizes(size_t dir, number dx, number dy)
sets the grid sizes and the agglomeration direction
Definition boxunions.h:91
bool get_id_by_pnt(number x, number y, int &ident) const
checks, in which union (x, y) is (if in any)
Definition boxunions.h:112
void load_points_from(const char *file_name)
loads point and union descriptsions from a file
Definition boxunions.cpp:98
size_t m_dir
direction of the agglomeration (0 = x, 1 = y, otherwise none)
Definition boxunions.h:149
number m_dx
x-size of the boxes
Definition boxunions.h:150
UnionsOfBoxes()
class constructor
Definition boxunions.h:73
~UnionsOfBoxes()
class destructor
Definition boxunions.h:78
void append_point(number x, number y, int ident)
appends a point to an existing union, or creates a new union
Definition boxunions.h:102
t_box_union_item * m_box_unions
unions
Definition boxunions.h:152
int get_id_by_pnt_dv(number x, number y, int dv) const
returns the union id, where (x, y) is, or a given default value
Definition boxunions.h:124
double number