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 <vector>
34 : #include "extrude.h"
35 : #include "cylinder_extrusion.h"
36 : #include "lib_grid/algorithms/remeshing/grid_adaption.h"
37 : #include "lib_grid/algorithms/selection_util.h"
38 :
39 : using namespace std;
40 :
41 : namespace ug
42 : {
43 :
44 : // this method actually performs the extrusion. It is only callable from
45 : // inside this file.
46 0 : static bool ExtrudeCylinder(Grid& grid, SubsetHandler* sh, Vertex* vrt,
47 : const vector3& direction, number height, number radius,
48 : number rimSnapThreshold,
49 : Grid::VertexAttachmentAccessor<APosition>& aaPos,
50 : int bottomSubInd, int cylSubInd,
51 : Selector* pSel)
52 : {
53 : // we'll use this selector if no selector was specified
54 0 : Selector locSel;
55 0 : if(!pSel){
56 0 : locSel.assign_grid(grid);
57 : pSel = &locSel;
58 : }
59 : Selector& sel = *pSel;
60 :
61 0 : if(!AdaptSurfaceGridToCylinder(sel, grid, vrt, direction, radius, rimSnapThreshold)){
62 : LOG(" WARNING: AdaptSurfaceGridToCylinder failed during ExtrudeCylinder.\n");
63 : return false;
64 : }
65 :
66 : // select boundary edges
67 0 : sel.clear<Edge>();
68 0 : SelectAreaBoundary(sel, sel.begin<Face>(), sel.end<Face>());
69 :
70 : // gather faces and edges for extrusion
71 : vector<Edge*> vEdges;
72 : vector<Face*> vFaces;
73 :
74 : for(EdgeIterator iter = sel.begin<Edge>();
75 0 : iter != sel.end<Edge>(); ++iter)
76 0 : vEdges.push_back(*iter);
77 :
78 : for(FaceIterator iter = sel.begin<Face>();
79 0 : iter != sel.end<Face>(); ++iter)
80 0 : vFaces.push_back(*iter);
81 :
82 : // everything that is extruded shall go into a separate subset
83 : bool bSInh = false;
84 : int defSubInd = -1;
85 0 : if(sh){
86 : // assign faces that will be extruded into a separate subset
87 0 : sh->assign_subset(vFaces.begin(), vFaces.end(), bottomSubInd);
88 : // the rest gets into the next subset
89 : bSInh = sh->subset_inheritance_enabled();
90 : defSubInd = sh->get_default_subset_index();
91 0 : sh->enable_subset_inheritance(false);
92 0 : sh->set_default_subset_index(cylSubInd);
93 : }
94 :
95 : vector3 scaledDir;
96 : VecScale(scaledDir, direction, height);
97 :
98 0 : Extrude(grid, NULL, &vEdges, &vFaces, scaledDir, EO_CREATE_FACES, aPosition);
99 :
100 0 : if(sh){
101 : // restore subset handler
102 0 : sh->enable_subset_inheritance(bSInh);
103 0 : sh->set_default_subset_index(defSubInd);
104 : }
105 :
106 : return true;
107 0 : }
108 :
109 0 : bool ExtrudeCylinder(Grid& grid, SubsetHandler& sh, Vertex* vrt,
110 : const vector3& direction, number height, number radius,
111 : number rimSnapThreshold,
112 : Grid::VertexAttachmentAccessor<APosition>& aaPos,
113 : int bottomSubInd, int cylSubInd,
114 : Selector* pSel)
115 : {
116 0 : return ExtrudeCylinder(grid, &sh, vrt, direction, height, radius,
117 0 : rimSnapThreshold, aaPos, bottomSubInd, cylSubInd, pSel);
118 :
119 : }
120 :
121 0 : bool ExtrudeCylinder(Grid& grid, Vertex* vrt,
122 : const vector3& direction, number height, number radius,
123 : number rimSnapThreshold,
124 : Grid::VertexAttachmentAccessor<APosition>& aaPos,
125 : Selector* pSel)
126 : {
127 0 : return ExtrudeCylinder(grid, NULL, vrt, direction, height, radius,
128 0 : rimSnapThreshold, aaPos, -1, -1, pSel);
129 : }
130 :
131 : }// end of namespace
|