Plugins
remeshing_tools.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2017: 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__UG__remeshing_tools__
34 #define __H__UG__remeshing_tools__
35 
36 #include <vector>
37 #include "../mesh.h"
38 #include "topology_tools.h"
56 
57 #define TOOLTIP_SIMPLIFY_POLYLINES "Removes vertices from the selected polyline which have a smaller curvature than the specified angle."
58 #define TOOLTIP_SIMPLIFY_SMOOTHED_POLYLINES "Removes vertices from the selected polyline which have a smaller smoothed curvature than the specified angle."
59 #define TOOLTIP_CONVERT_TO_TRIANGLES "Converts selected quadrilaterals to triangles."
60 #define TOOLTIP_CONVERT_TO_QUADRILATERALS "Converts selected triangles or triangles connected by selected edges to quadrilaterals."
61 #define TOOLTIP_TRIANGLE_FILL "Performs triangle fill using the sweep-line algorithm followed by an optional Constrained Delaunay retriangulation."
62 #define TOOLTIP_RETRIANGULATE "Inserts vertices as required and performs Constrained Delaunay triangulation."
63 #define TOOLTIP_ADJUST_EDGE_LENGTH "Remeshes the active grid so that all edges approximatly have a certain length."
64 #define TOOLTIP_ADAPT_SURFACE_TO_CYLINDER "Introduces edges in a grid around a selected vertex which roughly correspond to the intersection of a cylinder with the surface."
65 #define TOOLTIP_REPLACE_VALENCE_3_VERTICES "Replaces selected valence-3 vertices by triangles, if the curvature of associated triangles is low"
66 #define TOOLTIP_REPLACE_LOW_VALENCE_VERTICES "Replaces selected valence-3 and valence-4 vertices by triangles, if the curvature of associated triangles is low"
67 #define TOOLTIP_CONVERT_TO_TETRAHEDRA "Converts selected volume elements to tetrahedra."
68 #define TOOLTIP_TETRAHEDRALIZE "Fills a closed surface with tetrahedra using TetGen."
69 #define TOOLTIP_ASSIGN_VOLUME_CONSTRAINTS "Assigns volume constraints to selected tetrahedra."
70 #define TOOLTIP_CLEAR_VOLUME_CONSTRAINTS "Clears all assigned volume constraints."
71 #define TOOLTIP_RETETRAHEDRALIZE "Given a tetrahedralization and volume constraints, this method adapts the tetrahedra using TetGen."
72 #define TOOLTIP_DUPLICATE "Duplicates the selected geometry."
73 #define TOOLTIP_EXTRUDE_AND_MOVE "Extrudes selected geometry (vertices, edges, faces) and moves new vertices by the specified offset."
74 #define TOOLTIP_EXTRUDE_AND_SCALE "Extrudes selected geometry (vertices, edges, faces) and scales new vertices by the specified scale."
75 #define TOOLTIP_EXTRUDE_ALONG_NORMAL "Extrudes selected geometry (vertices, edges, faces) and moves new vertices along their normal."
76 #define TOOLTIP_EXTRUDE_TO_TICKNESS "Extrudes selected geometry (vertices, edges, faces) and moves new vertices so that created elements have the specified thickness."
77 #define TOOLTIP_EXTRUDE_CYLINDERS "Extrudes cylinders around selected points of a 2d manifold."
78 #define TOOLTIP_CREATE_SHRINK_GEOMETRY "Creates new elements from existing ones, providing each with a unique set of corner vertices. Those corners are scaled towards the center using the given scale-parameter."
79 #define TOOLTIP_EXTRUDE_FACES_WITH_TETS "Experimental function to create 'plaque'-like geometry based on extruding faces with tetrahedra."
80 
81 #define TOOLTIP_MESH_LAYERS "Creates triangle/quadrilateral grids for the given raster-layers"
82 #define TOOLTIP_MESH_LAYER_BOUNDARIES "Creates boundary grids for the given raster-layers"
83 #define TOOLTIP_PROJECT_TO_LAYER "Projects a (surface-)mesh to the specified raster-layer. Only height values in valid regions are adjusted."
84 #define TOOLTIP_PROJECT_TO_TOP_LAYER "Projects a (surface-)mesh to the top-layer of the specified raster-stack. Only height values in valid regions are adjusted."
85 #define TOOLTIP_EXTRUDE_LAYERS "Creates volumes for a given stack of raster-layers and an initial triangulation of the surface."
86 #define TOOLTIP_EXTRUDE_LAYERS_AND_ADD_PROJECTOR "Creates volumes for a given stack of raster-layers and an initial triangulation of the surface. It also generates a raster-based refinement-projector for the whole geometry."
87 #define TOOLTIP_SNAP_TO_HORIZONTAL_RASTER "Snaps all vertices of the given (surface) grid horizontally to the closest raster-node."
88 
89 #define TOOLTIP_CSG_FACE_UNION "Performs a union operation on the geometry of the two specifed subsets. IMPORTANT: Both subsets have to be closed manifolds, i.e., homeomorphic to the sphere."
90 #define TOOLTIP_CSG_FACE_INTERSECTION "Performs an intersection operation on the geometry of the two specifed subsets. IMPORTANT: Both subsets have to be closed manifolds, i.e., homeomorphic to the sphere."
91 #define TOOLTIP_CSG_FACE_DIFFERENCE "Performs a difference operation on the geometry of the two specifed subsets. IMPORTANT: Both subsets have to be closed manifolds, i.e., homeomorphic to the sphere."
92 
93 namespace ug{
94 namespace promesh{
95 
98 
99 void SimplifyPolylines(Mesh* m, number curvatureThreshold);
100 
102  Mesh* m,
103  number curvatureThreshold,
104  number smoothingAlpha,
105  int smoothingIterations);
106 
107 void ConvertToTriangles(Mesh* obj);
108 
109 void ConvertToQuadrilaterals(Mesh* obj);
110 
111 void ExtrudeFacesWithTets(Mesh* obj, int fromSi, int toSi, const number factor);
112 
113 void TriangleFill(Mesh* obj, bool qualityGeneration, number minAngle, int si);
114 
115 void Retriangulate(Mesh* obj, number minAngle);
116 
117 void AdjustEdgeLength(
118  Mesh* obj,
119  number minEdgeLen,
120  number maxEdgeLen,
121  int numIterations,
122  bool adaptive,
123  bool automarkBoundaries);
124 
126  Mesh* obj,
127  number minEdgeLen,
128  number maxEdgeLen,
129  number approximation,
130  number triQuality,
131  int numIterations,
132  bool automarkBoundaries);
133 
134 void AdaptSurfaceToCylinder(Mesh* obj, number radius, number threshold);
135 
136 void ConvertToTetrahedra(Mesh* obj);
137 
138 void Tetrahedralize(
139  Mesh* obj,
140  number quality,
141  bool preserveOuter,
142  bool preserveAll,
143  bool separateVolumes,
144  bool appendSubsetsAtEnd,
145  int verbosity);
146 
147 void AssignVolumeConstraints(Mesh* obj, number volConstraint);
148 
149 void ClearVolumeConstraints(Mesh* obj);
150 
151 void Retetrahedralize(
152  Mesh* obj,
153  number quality,
154  bool preserveOuter,
155  bool preserveAll,
156  bool applyVolumeConstraint,
157  int verbosity);
158 
159 void Duplicate(Mesh* obj, const vector3& offset, bool deselectOld, bool selectNew);
160 
161 void ExtrudeAndMove(
162  Mesh* obj,
163  const vector3& totalDir,
164  int numSteps,
165  bool createFaces,
166  bool createVolumes);
167 
168 void ExtrudeAndScale(
169  Mesh* obj,
170  number totalScale,
171  bool scaleAroundPivot,
172  int numSteps,
173  bool createFaces,
174  bool createVolumes);
175 
176 void ExtrudeAlongNormal(
177  Mesh* obj,
178  number totalLength,
179  int numSteps,
180  bool createFaces,
181  bool createVolumes);
182 
183 void ExtrudeToThickness(Mesh* obj,
184  number thickness,
185  int numSteps,
186  bool createFaces,
187  bool createVolumes);
188 
189 void ExtrudeCylinders(Mesh* obj, number height, number radius, number snapThreshold);
190 
196 template <class TElemIter>
198  Mesh* obj,
199  number scale,
200  TElemIter elemsBegin,
201  TElemIter elemsEnd)
202 {
203  using namespace std;
204  typedef typename TElemIter::value_type elem_ptr_t;
205  Grid& g = obj->grid();
207 
208  vector<elem_ptr_t> elems(elemsBegin, elemsEnd);
209 
210  CustomVertexGroup vrts;
211  for(size_t i_elem = 0; i_elem < elems.size(); ++i_elem){
212  elem_ptr_t e = elems[i_elem];
213  vector3 c = CalculateCenter(e, aaPos);
214 
215  // create new corner-vertices first
216  vrts.clear();
217  for(size_t i = 0; i < e->num_vertices(); ++i){
218  vrts.push_back(*g.create_by_cloning(e->vertex(i), e->vertex(i)));
219  VecScaleAdd(aaPos[vrts[i]], scale, aaPos[e->vertex(i)], 1. - scale, c);
220  }
221 
222  // now clone the element
223  g.create_by_cloning(e, vrts, e);
224 
225  // finally delete the old element
226  g.erase(e);
227  }
228 }
229 
233 void CreateShrinkGeometry(Mesh* obj, number scale);
234 
235 void ReplaceLowValenceVertices(Mesh* obj, number maxSquaredHeightToBaseAreaRatio);
236 
237 void ReplaceValence3Vertices(Mesh* obj, number maxSquaredHeightToBaseAreaRatio);
238 
239 void MeshLayers(Mesh* m, const RasterLayers& layers);
240 
241 void MeshLayerBoundaries(Mesh* m, const RasterLayers& layers);
242 
243 void ProjectToLayer(Mesh* obj, RasterLayers& layers, int layerIndex);
244 
245 void ProjectToTopLayer(Mesh* obj, RasterLayers& layers);
246 
247 void ExtrudeLayers(Mesh* obj, RasterLayers& layers, bool allowForTetsAndPyras);
248 
250  Mesh* obj,
251  SPRasterLayers layers,
252  bool allowForTetsAndPyras);
253 
254 void SnapToHorizontalRaster(Mesh* obj, SPRasterLayers layers);
255 
260 };
261 
262 void CSGFaceOperation(
263  Mesh* obj,
264  CSGOperation op,
265  int subsetIndex0,
266  int subsetIndex1,
267  number snapThreshold);
268 
269 
270 void CSGFaceUnion(
271  Mesh* obj,
272  int subsetIndex0,
273  int subsetIndex1,
274  number snapThreshold);
275 
277  Mesh* obj,
278  int subsetIndex0,
279  int subsetIndex1,
280  number snapThreshold);
281 
282 void CSGFaceDifference(
283  Mesh* obj,
284  int subsetIndex0,
285  int subsetIndex1,
286  number snapThreshold);
287 
288 
289 // }
291 
292 }}// end of namespace
293 
294 #endif
void push_back(Vertex *vrt)
void erase(const GeomObjIter &iterBegin, const GeomObjIter &iterEnd)
EdgeIterator create_by_cloning(Edge *pCloneMe, const IVertexGroup &ev, GridObject *pParent=NULL)
Definition: mesh.h:73
position_accessor_t & position_accessor()
returns accessor to vertex positions
Definition: mesh.h:113
Grid & grid()
Definition: mesh.h:99
UG_API TVertexPositionAttachmentAccessor::ValueType CalculateCenter(const Edge *e, TVertexPositionAttachmentAccessor &aaPosVRT)
T value_type
void Tetrahedralize(Mesh *obj, number quality, bool preserveOuter, bool preserveAll, bool separateVolumes, bool appendSubsetsAtEnd, int verbosity)
Definition: remeshing_tools.cpp:356
void ExtrudeToThickness(Mesh *obj, number thickness, int numSteps, bool createFaces, bool createVolumes)
Definition: remeshing_tools.cpp:686
void ClearVolumeConstraints(Mesh *obj)
Definition: remeshing_tools.cpp:404
void CSGFaceOperation(Mesh *obj, CSGOperation op, int subsetIndex0, int subsetIndex1, number snapThreshold)
Definition: remeshing_tools.cpp:976
void ProjectToTopLayer(Mesh *obj, RasterLayers &layers)
Definition: remeshing_tools.cpp:945
void TriangleFill(Mesh *obj, bool qualityGeneration, number minAngle, int si)
Definition: remeshing_tools.cpp:149
void ReplaceLowValenceVertices(Mesh *obj, number maxSquaredHeightToBaseAreaRatio)
Definition: remeshing_tools.cpp:916
void MeshLayerBoundaries(Mesh *m, const RasterLayers &layers)
Definition: remeshing_tools.cpp:935
void ReplaceValence3Vertices(Mesh *obj, number maxSquaredHeightToBaseAreaRatio)
Definition: remeshing_tools.cpp:923
void Duplicate(Mesh *obj, const vector3 &offset, bool deselectOld, bool selectNew)
Definition: remeshing_tools.cpp:432
void ExtrudeFacesWithTets(Mesh *obj, int fromSi, int toSi, const number factor)
Definition: remeshing_tools.cpp:95
void ConvertToTetrahedra(Mesh *obj)
Definition: remeshing_tools.cpp:347
void ExtrudeAndMove(Mesh *obj, const vector3 &totalDir, int numSteps, bool createFaces, bool createVolumes)
Definition: remeshing_tools.cpp:439
void ProjectToLayer(Mesh *obj, RasterLayers &layers, int layerIndex)
Definition: remeshing_tools.cpp:941
void Retriangulate(Mesh *obj, number minAngle)
Definition: remeshing_tools.cpp:249
void Retetrahedralize(Mesh *obj, number quality, bool preserveOuter, bool preserveAll, bool applyVolumeConstraint, int verbosity)
Definition: remeshing_tools.cpp:409
void CSGFaceDifference(Mesh *obj, int subsetIndex0, int subsetIndex1, number snapThreshold)
Definition: remeshing_tools.cpp:1120
void CSGFaceIntersection(Mesh *obj, int subsetIndex0, int subsetIndex1, number snapThreshold)
Definition: remeshing_tools.cpp:1111
void ExtrudeAndScale(Mesh *obj, number totalScale, bool scaleAroundPivot, int numSteps, bool createFaces, bool createVolumes)
Definition: remeshing_tools.cpp:494
void AdjustEdgeLength(Mesh *obj, number minEdgeLen, number maxEdgeLen, int numIterations, bool adaptive, bool automarkBoundaries)
Definition: remeshing_tools.cpp:264
void MeshLayers(Mesh *m, const RasterLayers &layers)
Definition: remeshing_tools.cpp:930
void CreateShrinkElements(Mesh *obj, number scale, TElemIter elemsBegin, TElemIter elemsEnd)
Definition: remeshing_tools.h:197
void SnapToHorizontalRaster(Mesh *obj, SPRasterLayers layers)
Definition: remeshing_tools.cpp:971
void SimplifySmoothedPolylines(Mesh *m, number curvatureThreshold, number smoothingAlpha, int smoothingIterations)
Definition: remeshing_tools.cpp:48
void SimplifyPolylines(Mesh *m, number curvatureThreshold)
Definition: remeshing_tools.cpp:40
void AdjustEdgeLengthExtended(Mesh *obj, number minEdgeLen, number maxEdgeLen, number approximation, number triQuality, int numIterations, bool automarkBoundaries)
Definition: remeshing_tools.cpp:290
void ExtrudeLayersAndAddProjector(Mesh *obj, SPRasterLayers layers, bool allowForTetsAndPyras)
Definition: remeshing_tools.cpp:955
void ConvertToQuadrilaterals(Mesh *obj)
Definition: remeshing_tools.cpp:73
void AdaptSurfaceToCylinder(Mesh *obj, number radius, number threshold)
Definition: remeshing_tools.cpp:321
void AssignVolumeConstraints(Mesh *obj, number volConstraint)
Definition: remeshing_tools.cpp:392
void ExtrudeCylinders(Mesh *obj, number height, number radius, number snapThreshold)
Definition: remeshing_tools.cpp:873
void CSGFaceUnion(Mesh *obj, int subsetIndex0, int subsetIndex1, number snapThreshold)
Definition: remeshing_tools.cpp:1102
CSGOperation
Definition: remeshing_tools.h:256
void CreateShrinkGeometry(Mesh *obj, number scale)
Definition: remeshing_tools.cpp:902
void ExtrudeLayers(Mesh *obj, RasterLayers &layers, bool allowForTetsAndPyras)
Definition: remeshing_tools.cpp:950
void ConvertToTriangles(Mesh *obj)
Definition: remeshing_tools.cpp:63
void ExtrudeAlongNormal(Mesh *obj, number totalLength, int numSteps, bool createFaces, bool createVolumes)
Definition: remeshing_tools.cpp:575
@ CSG_UNION
Definition: remeshing_tools.h:257
@ CSG_INTERSECTION
Definition: remeshing_tools.h:258
@ CSG_DIFFERENCE
Definition: remeshing_tools.h:259
double number
void VecScaleAdd(double &dest, double alpha1, const double &v1, double alpha2, const double &v2)