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 : #include <sstream>
34 : #include "marker_points.h"
35 : #include "lib_grid/algorithms/geom_obj_util/geom_obj_util.h"
36 : #include "lib_grid/file_io/file_io.h"
37 :
38 : using namespace std;
39 :
40 : namespace ug
41 : {
42 :
43 0 : MarkerPoint::MarkerPoint() :
44 : localCoord(0, 0, 0),
45 0 : associatedObj(NULL)
46 : {
47 0 : }
48 :
49 0 : MarkerPoint::MarkerPoint(const char* strName, const vector3& position,
50 0 : const vector3& normal) :
51 0 : name(strName),
52 : pos(position),
53 : norm(normal),
54 : localCoord(0, 0, 0),
55 0 : associatedObj(NULL)
56 : {
57 0 : }
58 :
59 : ////////////////////////////////////////////////////////////////////////
60 : /// Loads marker points from a file
61 0 : bool LoadMarkerPointsFromFile(MarkerPointManager& manager,
62 : const char* filename)
63 : {
64 : // load a grid and copy the points
65 0 : Grid grid;
66 0 : if(LoadGridFromFile(grid, filename)){
67 : // copy the points to the marker-file
68 : Grid::VertexAttachmentAccessor<APosition> aaPos(grid, aPosition);
69 : Grid::VertexAttachmentAccessor<ANormal> aaNorm;
70 0 : if(grid.has_vertex_attachment(aNormal))
71 : aaNorm.access(grid, aNormal);
72 :
73 : int i = 0;
74 : for(VertexIterator iter = grid.begin<Vertex>();
75 0 : iter != grid.end<Vertex>(); ++iter, ++i)
76 : {
77 0 : stringstream ss;
78 0 : ss << "marker_" << i;
79 0 : if(aaNorm.valid())
80 0 : manager.add_marker(MarkerPoint(ss.str().c_str(), aaPos[*iter],
81 : aaNorm[*iter]));
82 : else
83 0 : manager.add_marker(MarkerPoint(ss.str().c_str(), aaPos[*iter],
84 0 : vector3(0, 0, 0)));
85 0 : }
86 :
87 : return true;
88 : }
89 :
90 : return false;
91 0 : }
92 :
93 : ////////////////////////////////////////////////////////////////////////
94 0 : void SnapMarkerPointToGridVertex(MarkerPoint& markerInOut, Grid& grid,
95 : number normalOffset,
96 : Grid::VertexAttachmentAccessor<APosition>& aaPos,
97 : Grid::VertexAttachmentAccessor<ANormal>* paaNorm)
98 : {
99 : MarkerPoint& marker = markerInOut;
100 : // find the closest vertex
101 : // the specified point
102 0 : vector3& p = marker.pos;
103 :
104 : // find the closest point in the grid
105 : Vertex* vrt;
106 : {
107 : VertexIterator iter = grid.begin<Vertex>();
108 : vrt = *iter;
109 0 : number distSq = VecDistanceSq(aaPos[vrt], p);
110 : iter++;
111 0 : for(; iter != grid.end<Vertex>(); ++iter){
112 0 : number d = VecDistanceSq(aaPos[*iter], p);
113 0 : if(d < distSq){
114 : distSq = d;
115 : vrt = *iter;
116 : }
117 : }
118 : }
119 :
120 : // vrt now holds the closest vertex
121 : // get the normal offset
122 : vector3 nOff(0, 0, 0);
123 0 : if(normalOffset != 0){
124 0 : if(paaNorm)
125 : VecScale(nOff, (*paaNorm)[vrt], normalOffset);
126 : else{
127 0 : CalculateVertexNormal(nOff, grid, vrt, aaPos);
128 : VecScale(nOff, nOff, normalOffset);
129 : }
130 : }
131 :
132 : // the new position
133 : VecAdd(marker.pos, aaPos[vrt], nOff);
134 :
135 : // the new local coordinate
136 : marker.localCoord = vector3(0, 0, 0);
137 :
138 : // the new associated geometric object
139 0 : marker.associatedObj = vrt;
140 0 : }
141 :
142 : }// end of namespace
|