Line data Source code
1 : /*
2 : * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Sebastian Reiter
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #ifndef __H__LIBGRID__MARKER_POINTS__
34 : #define __H__LIBGRID__MARKER_POINTS__
35 :
36 : #include <vector>
37 : #include <string>
38 : #include "common/common.h"
39 : #include "lib_grid/grid/grid.h"
40 : #include "lib_grid/common_attachments.h"
41 :
42 : namespace ug
43 : {
44 : ////////////////////////////////////////////////////////////////////////
45 : /**
46 : * Marker points help when it comes to associating something with a
47 : * free point.
48 : *
49 : * Used in Tetrahedralize to define units.
50 : */
51 0 : struct MarkerPoint
52 : {
53 : MarkerPoint();
54 : MarkerPoint(const char* name, const vector3& position, const vector3& normal);
55 :
56 : std::string name;
57 :
58 : vector3 pos;
59 : vector3 norm;
60 : vector3 localCoord;
61 : GridObject* associatedObj;
62 : };
63 :
64 : ////////////////////////////////////////////////////////////////////////
65 : /**
66 : * the marker point manager handles a group of marker points.
67 : */
68 : class MarkerPointManager
69 : {
70 : public:
71 : void clear() {m_markers.clear();}
72 : inline void add_marker() {m_markers.resize(m_markers.size() + 1);}
73 : inline void add_markers(size_t num = 1) {m_markers.resize(m_markers.size() + num);}
74 0 : void add_marker(const MarkerPoint& marker) {m_markers.push_back(marker);}
75 :
76 : inline size_t num_markers() const {return m_markers.size();}
77 :
78 : inline MarkerPoint& get_marker(size_t index) {return m_markers[index];}
79 : inline const MarkerPoint& get_marker(size_t index) const {return m_markers[index];}
80 :
81 : inline void set_marker(size_t index,
82 : const MarkerPoint& marker) {m_markers[index] = marker;}
83 :
84 : inline MarkerPoint const *get_array() {return &m_markers.front();}
85 :
86 : protected:
87 : std::vector<MarkerPoint> m_markers;
88 : };
89 :
90 :
91 : ////////////////////////////////////////////////////////////////////////
92 : /// Loads marker points from a file
93 : bool LoadMarkerPointsFromFile(MarkerPointManager& manager,
94 : const char* filename);
95 :
96 : ////////////////////////////////////////////////////////////////////////
97 : /// Snaps a marker point to a grid vertex
98 : /**
99 : * Uses the initial position of the marker-point to determine the
100 : * closest vertex in the grid. The new position is then calculated
101 : * by an offset of the vertex-normal to the original vertex-position.
102 : *
103 : * If a normal-accessor is supplied, the normal of the target vertex
104 : * will be taken from it. If not, it will be calculated on the fly.
105 : *
106 : * Both aaPos and paaNorm (if supplied) have to access valid vertex
107 : * attachments of the given grid.
108 : *
109 : * Please note that marker.norm and marker.name will remain unchanged.
110 : * However the other entries will be changed.
111 : *
112 : * Note that this method checks each vertex of the grid and is thus a
113 : * little slow. Alternate implementations should use a kd-tree or similar.
114 : */
115 : void SnapMarkerPointToGridVertex(MarkerPoint& markerInOut, Grid& grid,
116 : number normalOffset,
117 : Grid::VertexAttachmentAccessor<APosition>& aaPos,
118 : Grid::VertexAttachmentAccessor<ANormal>* paaNorm = NULL);
119 :
120 : }// end of namespace
121 :
122 : #endif
|