Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
triangle_fill_sweep_line_impl.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-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__UG4__LIB_GRID__TRIANGLE_FILL_SWEEP_LINE_IMPL__
34#define __H__UG4__LIB_GRID__TRIANGLE_FILL_SWEEP_LINE_IMPL__
35
36namespace ug
37{
38template <class TIterator>
39bool TriangleFill_SweepLine(Grid& grid, TIterator edgesBegin,
40 TIterator edgesEnd, APosition& aPosVRT,
41 AInt& aIntVRT,
42 SubsetHandler* pSH,
43 int newSubsetIndex)
44{
45 if(!grid.has_vertex_attachment(aPosVRT)){
46 UG_LOG("position attachment missing in TriangleFill_SweepLine");
47 return false;
48 }
49
50 if(!grid.has_vertex_attachment(aIntVRT)){
51 UG_LOG("int attachment missing in TriangleFill_SweepLine");
52 return false;
53 }
54
56 Grid::VertexAttachmentAccessor<AInt> aaInt(grid, aIntVRT);
57
58// set up the vertex and edge arrays and build some additional
59// information that is required when it comes to building the triangles.
60 std::vector<Vertex*> vrtPtrs;
61 std::vector<vector3> vrts;
62 std::vector<int> edges;
63
64 grid.begin_marking();
65 for(TIterator iter = edgesBegin; iter != edgesEnd; ++iter)
66 {
67 Edge* e = *iter;
68
69 for(size_t i = 0; i < 2; ++i){
70 Vertex* vrt = e->vertex(i);
71 if(!grid.is_marked(vrt)){
72 aaInt[vrt] = (int)vrts.size();
73 vrts.push_back(aaPos[vrt]);
74 //vrts.push_back(vector2(aaPos[vrt].x(), aaPos[vrt].y()));
75 vrtPtrs.push_back(vrt);
76 grid.mark(vrt);
77 }
78
79 edges.push_back(aaInt[vrt]);
80 }
81 }
82 grid.end_marking();
83
84// now call the original implementation
85 size_t numInitialEdges = edges.size();
86 std::vector<int> faces;
87 if(TriangleFill_SweepLine(faces, vrts, edges)){
88
89 // now create the triangles
90 for(size_t i = 0; i < faces.size(); i+=3){
91 Triangle* tri = *grid.create<Triangle>(TriangleDescriptor(vrtPtrs[faces[i]],
92 vrtPtrs[faces[i + 1]],
93 vrtPtrs[faces[i + 2]]));
94 if(pSH){
95 pSH->assign_subset(tri, newSubsetIndex);
96 }
97 }
98
99 return true;
100 }
101
102 else{
103 //DEBUG ONLY
104 // create edges
105 for(size_t i = numInitialEdges; i < edges.size(); i+=2){
106 Edge* e = *grid.create<RegularEdge>(EdgeDescriptor(vrtPtrs[edges[i]], vrtPtrs[edges[i+1]]));
107 if(pSH){
108 pSH->assign_subset(e, newSubsetIndex);
109 }
110 }
111 }
112
113 return false;
114}
115
116}// namespace ug
117
118#endif
A generic specialization of IAttachment.
Definition attachment_pipe.h:263
Can be used to store information about an edge and to construct an edge.
Definition grid_base_objects.h:464
Base-class for edges.
Definition grid_base_objects.h:397
virtual Vertex * vertex(size_t index) const
Definition grid_base_objects.h:366
Manages the elements of a grid and their interconnection.
Definition grid.h:132
void end_marking()
ends a marking sequence. Call this method when you're done with marking.
Definition grid.cpp:1285
bool is_marked(GridObject *obj) const
returns true if the object is marked, false if not.
Definition grid_impl.hpp:843
void mark(GridObject *obj)
marks the object. Calls are only valid between calls to Grid::begin_marking and Grid::end_marking.
Definition grid_impl.hpp:773
void begin_marking()
begin marking.
Definition grid.cpp:1262
bool has_vertex_attachment(IAttachment &attachment)
Definition grid.h:798
geometry_traits< TGeomObj >::iterator create(GridObject *pParent=NULL)
create a custom element.
Definition grid_impl.hpp:69
Partitions elements of a grid into several subsets.
Definition subset_handler_grid.h:53
void assign_subset(Vertex *elem, int subsetIndex)
assigns a vertex to a subset.
Definition subset_handler_grid.cpp:204
Edges connect two vertices.
Definition grid_objects_1d.h:66
only used to initialize a triangle. for all other tasks you should use FaceDescriptor.
Definition grid_objects_2d.h:78
the most simple form of a face
Definition grid_objects_2d.h:174
Base-class for all vertex-types.
Definition grid_base_objects.h:231
#define UG_LOG(msg)
Definition log.h:367
the ug namespace
bool TriangleFill_SweepLine(vector< int > &facesOut, const vector< vector2 > &srcVrtsOrig, vector< int > &srcEdges)
Performs triangulation of a polygon and resoves additional inner edges.
Definition triangle_fill_sweep_line.cpp:942