Line data Source code
1 : /*
2 : * Copyright (c) 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 <algorithm>
34 : #include "ray_element_intersection_util.h"
35 : #include "common/math/misc/math_util.h"
36 : #include "lib_grid/iterators/lg_for_each.h"
37 :
38 : using namespace std;
39 :
40 : namespace ug{
41 :
42 : /// utility method for the full-dimensional RayElementIntersection implementation
43 : template <class TElem, class vector_t>
44 : static bool
45 0 : RayElementIntersectionImpl(
46 : number& sminOut,
47 : number& smaxOut,
48 : const vector_t& from,
49 : const vector_t& dir,
50 : TElem* e,
51 : Grid& g,
52 : Grid::VertexAttachmentAccessor<Attachment<vector_t> > aaPos,
53 : number sml)
54 : {
55 : typedef typename TElem::side side_t;
56 :
57 : int numIntersections = 0;
58 0 : number smin = 0, smax = 0;
59 :
60 : typename Grid::traits<side_t>::secure_container sides;
61 : g.associated_elements(sides, e);
62 :
63 0 : for_each_in_vec(side_t* s, sides){
64 : number tsmin, tsmax;
65 0 : if(RayElementIntersection(tsmin, tsmax, from, dir, s, g, aaPos, sml)){
66 0 : if(numIntersections == 0)
67 0 : smin = smax = tsmin;
68 : else{
69 0 : smin = min(smin, tsmin);
70 0 : smax = max(smax, tsmax);
71 : }
72 0 : ++numIntersections;
73 : }
74 : }end_for;
75 :
76 0 : sminOut = smin;
77 0 : smaxOut = smax;
78 0 : return numIntersections > 0;
79 : }
80 :
81 :
82 : // 2d edge intersection
83 0 : bool RayElementIntersection(
84 : number& sminOut,
85 : number& smaxOut,
86 : const vector2& from,
87 : const vector2& dir,
88 : Edge* e,
89 : Grid&,
90 : Grid::VertexAttachmentAccessor<AVector2> aaPos,
91 : number sml)
92 : {
93 : vector2 v;
94 : number t;
95 0 : bool ret = RayLineIntersection2d(v, t, sminOut, aaPos[e->vertex(0)],
96 0 : aaPos[e->vertex(1)], from, dir, sml);
97 0 : smaxOut = sminOut;
98 0 : return ret;
99 : }
100 :
101 : // 2d face intersection
102 0 : bool RayElementIntersection(
103 : number& sminOut,
104 : number& smaxOut,
105 : const vector2& from,
106 : const vector2& dir,
107 : Face* f,
108 : Grid& g,
109 : Grid::VertexAttachmentAccessor<AVector2> aaPos,
110 : number sml)
111 : {
112 0 : return RayElementIntersectionImpl(sminOut, smaxOut, from, dir, f, g, aaPos, sml);
113 : }
114 :
115 :
116 : // 3d face intersection
117 0 : bool RayElementIntersection(
118 : number& sminOut,
119 : number& smaxOut,
120 : const vector3& from,
121 : const vector3& dir,
122 : Face* f,
123 : Grid&,
124 : Grid::VertexAttachmentAccessor<AVector3> aaPos,
125 : number sml)
126 : {
127 : vector3 v;
128 : number t0, t1;
129 : bool ret = false;
130 : size_t i = 0;
131 :
132 : do{
133 0 : ret = RayTriangleIntersection(
134 : v, t0, t1, sminOut,
135 0 : aaPos[f->vertex(0)],
136 0 : aaPos[f->vertex(i + 1)],
137 0 : aaPos[f->vertex(i + 2)],
138 : from, dir, sml);
139 : ++i;
140 0 : }while(!ret && (i + 2 < f->num_vertices()));
141 :
142 0 : smaxOut = sminOut;
143 0 : return ret;
144 : }
145 :
146 : // 3d volume intersection
147 0 : bool RayElementIntersection(
148 : number& sminOut,
149 : number& smaxOut,
150 : const vector3& from,
151 : const vector3& dir,
152 : Volume* v,
153 : Grid& g,
154 : Grid::VertexAttachmentAccessor<AVector3> aaPos,
155 : number sml)
156 : {
157 0 : return RayElementIntersectionImpl(sminOut, smaxOut, from, dir, v, g, aaPos, sml);
158 : }
159 :
160 : // 3d edge intersection
161 0 : bool RayElementIntersection(
162 : number& sminOut,
163 : number& smaxOut,
164 : const vector3& from,
165 : const vector3& dir,
166 : Edge* e,
167 : Grid& g,
168 : Grid::VertexAttachmentAccessor<AVector3> aaPos,
169 : number sml)
170 : {
171 0 : return false;
172 : }
173 :
174 : }// end of namespace
|