Skip to content

Commit b7f70fa

Browse files
committed
Added AssignSubsetsByVolumeAspectRatio (only for tetrahedra currently)
1 parent c021088 commit b7f70fa

File tree

9 files changed

+129
-45
lines changed

9 files changed

+129
-45
lines changed

promesh_plugin.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ static void RegisterMisc(ProMeshRegistry& reg, string baseGrp)
7575
"mesh # projection normal || value=[0,0,1]", TOOLTIP_PROJECTED_DISTANCE);
7676

7777
grp = baseGrp + string("/Info/Qualities");
78-
reg.add_function("PrintFaceAspectRatios", &PrintFaceAspectRatios, grp, "",
78+
reg.add_function("PrintFaceAspectRatios", &PrintAspectRatios<Face>, grp, "",
7979
"mesh", TOOLTIP_PRINT_FACE_ASPECT_RATIOS)
80-
.add_function("PrintFaceAspectRatioHistogram", &PrintFaceAspectRatioHistogram, grp, "",
81-
"mesh # histogram sections || min=1; value=10", TOOLTIP_PRINT_FACE_ASPECT_RATIO_HISTOGRAM);
80+
.add_function("PrintVolumeAspectRatios", &PrintAspectRatios<Volume>, grp, "",
81+
"mesh", TOOLTIP_PRINT_VOLUME_ASPECT_RATIOS)
82+
.add_function("PrintFaceAspectRatioHistogram", &PrintAspectRatioHistogram<Face>, grp, "",
83+
"mesh # histogram sections || min=1; value=10", TOOLTIP_PRINT_FACE_ASPECT_RATIO_HISTOGRAM)
84+
.add_function("PrintVolumeAspectRatioHistogram", &PrintAspectRatioHistogram<Volume>, grp, "",
85+
"mesh # histogram sections || min=1; value=10", TOOLTIP_PRINT_VOLUME_ASPECT_RATIO_HISTOGRAM);
8286

8387
grp = baseGrp + string("/Info/Measure length, area, volume");
8488
reg.add_function("MeasureGridLength", &MeasureGridLength, grp, "length",

register_selection_tools.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,26 @@ void RegisterSelectionTools(ProMeshRegistry& reg, string baseGrp)
199199

200200
.add_function("SelectInterfaceFaces", &SelectInterfaceElements<Face>, grp, "",
201201
"mesh # regard selected neighbors only", TOOLTIP_SELECT_INTERFACE_ELEMENTS)
202-
.add_function("SelectFacesByNormal", &SelectFacesByNormal, grp, "",
202+
203+
.add_function("SelectFacesByNormal",
204+
static_cast<void (*)(Mesh*, const vector3&, number)>(&SelectFacesByNormal),
205+
grp, "",
203206
"mesh #"
204207
"normal #"
205-
"max deviation angle || value=10", TOOLTIP_SELECT_FACES_BY_NORMAL)
208+
"max deviation angle || value=10",
209+
TOOLTIP_SELECT_FACES_BY_NORMAL,
210+
"", RT_NO_PROMESH)
211+
212+
.add_function("SelectFacesByNormal",
213+
static_cast<void (*)(Mesh*, const vector3&, number, number, bool)>(&SelectFacesByNormal),
214+
grp, "",
215+
"mesh #"
216+
"normal #"
217+
"min deviation angle || value=0 #"
218+
"max deviation angle || value=10 #"
219+
"ignore inner faces || value=true",
220+
TOOLTIP_SELECT_FACES_BY_NORMAL)
221+
206222
.add_function("SelectAnisotropicFaces", &SelectAnisotropicElements<Face>, grp, "",
207223
"mesh # min edge ratio || value=0.5D", TOOLTIP_SELECT_ANISOTROPIC_ELEMENTS)
208224
.add_function("SelectDegenerateFaces", &SelectDegenerateFaces, grp, "",

register_subset_tools.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ void RegisterSubsetTools(ProMeshRegistry& reg, std::string baseGrp)
113113
.add_function("AssignSubsetColors", &AssignSubsetColors, grp, "", "mesh", TOOLTIP_ASSIGN_SUBSET_COLORS)
114114
.add_function("AssignSubsetsByElementType", &AssignSubsetsByElementType, grp, "",
115115
"mesh", TOOLTIP_ASSIGN_SUBSETS_BY_ELEMENT_TYPE)
116-
.add_function("AssignSubsetsByAspectRatio", &AssignSubsetsByAspectRatio, grp, "",
116+
.add_function("AssignFaceSubsetsByAspectRatio", &AssignSubsetsByAspectRatio<Face>, grp, "",
117+
"mesh # histogram sections || min=1; value=10 # erase old subsets || value=true",
118+
TOOLTIP_ASSIGN_SUBSETS_BY_ASPECT_RATIO)
119+
.add_function("AssignVolumeSubsetsByAspectRatio", &AssignSubsetsByAspectRatio<Volume>, grp, "",
117120
"mesh # histogram sections || min=1; value=10 # erase old subsets || value=true",
118121
TOOLTIP_ASSIGN_SUBSETS_BY_ASPECT_RATIO)
119122
.add_function("AssignSubsetsFromRaster", &AssignSubsetsFromRaster, grp, "",

tools/quality_tools.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,52 @@
3737
namespace ug {
3838
namespace promesh {
3939

40-
void PrintFaceAspectRatios (Mesh* msh)
40+
template <class elem_t>
41+
void PrintAspectRatios (Mesh* msh)
4142
{
4243
Selector& sel = msh->selector();
4344
AspectRatioInfo ari;
44-
if(sel.num<Face>() > 0){
45-
UG_LOG("Face Aspect Ratios (" << sel.num<Face>() << " faces):\n\n");
46-
ari = GetFaceAspectRatioInfo (sel.faces_begin(), sel.faces_end(),
45+
if(sel.num<elem_t>() > 0){
46+
UG_LOG("Aspect Ratios (" << sel.num<elem_t>() << " "
47+
<< GRID_BASE_OBJECT_PLURAL_NAMES[elem_t::BASE_OBJECT_ID] << "):\n\n");
48+
ari = GetAspectRatioInfo (sel.begin<elem_t>(), sel.end<elem_t>(),
4749
msh->position_accessor());
4850
}
4951
else{
5052
Grid& g = msh->grid();
51-
UG_LOG("Face Aspect Ratios (" << g.num<Face>() << " faces):\n\n");
52-
ari = GetFaceAspectRatioInfo (g.faces_begin(), g.faces_end(),
53+
UG_LOG("Aspect Ratios (" << g.num<elem_t>() << " "
54+
<< GRID_BASE_OBJECT_PLURAL_NAMES[elem_t::BASE_OBJECT_ID] << "):\n\n");
55+
ari = GetAspectRatioInfo (g.begin<elem_t>(), g.end<elem_t>(),
5356
msh->position_accessor());
5457
}
5558

5659
UG_LOG(ari.to_string() << std::endl);
5760
}
5861

59-
void PrintFaceAspectRatioHistogram (Mesh* msh, int numHistoSecs)
62+
template void PrintAspectRatios <Face> (Mesh*);
63+
template void PrintAspectRatios <Volume> (Mesh*);
64+
65+
66+
template <class elem_t>
67+
void PrintAspectRatioHistogram (Mesh* msh, int numHistoSecs)
6068
{
6169
if(numHistoSecs < 1){
6270
UG_LOG("Can't create histogram with " << numHistoSecs << " sections.\n");
6371
}
6472

6573
Selector& sel = msh->selector();
6674
std::vector<int> histo;
67-
if(sel.num<Face>() > 0){
68-
UG_LOG("Face Aspect Ratio Histogram (" << sel.num<Face>() << " faces):\n\n");
69-
GetFaceAspectRatioHistogram (histo, sel.faces_begin(), sel.faces_end(),
75+
if(sel.num<elem_t>() > 0){
76+
UG_LOG("Aspect Ratio Histogram (" << sel.num<elem_t>() << " "
77+
<< GRID_BASE_OBJECT_PLURAL_NAMES[elem_t::BASE_OBJECT_ID] << "):\n\n");
78+
GetAspectRatioHistogram (histo, sel.begin<elem_t>(), sel.end<elem_t>(),
7079
numHistoSecs, msh->position_accessor());
7180
}
7281
else{
7382
Grid& g = msh->grid();
74-
UG_LOG("Face Aspect Ratio Histogram (" << g.num<Face>() << " faces):\n\n");
75-
GetFaceAspectRatioHistogram (histo, g.faces_begin(), g.faces_end(),
83+
UG_LOG("Aspect Ratio Histogram (" << g.num<elem_t>() << " "
84+
<< GRID_BASE_OBJECT_PLURAL_NAMES[elem_t::BASE_OBJECT_ID] << "):\n\n");
85+
GetAspectRatioHistogram (histo, g.begin<elem_t>(), g.end<elem_t>(),
7686
numHistoSecs, msh->position_accessor());
7787
}
7888

@@ -87,5 +97,7 @@ void PrintFaceAspectRatioHistogram (Mesh* msh, int numHistoSecs)
8797
UG_LOG(t.to_string() << std::endl);
8898
}
8999

100+
template void PrintAspectRatioHistogram <Face> (Mesh* msh, int numHistoSecs);
101+
template void PrintAspectRatioHistogram <Volume> (Mesh* msh, int numHistoSecs);
90102
}// end of namespace
91103
}// end of namespace

tools/quality_tools.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@
3535

3636
#include "../mesh.h"
3737

38-
#define TOOLTIP_PRINT_FACE_ASPECT_RATIOS "Prints information on aspect ratios of faces"
39-
#define TOOLTIP_PRINT_FACE_ASPECT_RATIO_HISTOGRAM "Prints a histogram of face aspect ratios"
38+
#define TOOLTIP_PRINT_FACE_ASPECT_RATIOS "Prints information on aspect ratios of selected faces"
39+
#define TOOLTIP_PRINT_VOLUME_ASPECT_RATIOS "Prints information on aspect ratios of selected volumes"
40+
#define TOOLTIP_PRINT_FACE_ASPECT_RATIO_HISTOGRAM "Prints a histogram of aspect ratios of selected faces"
41+
#define TOOLTIP_PRINT_VOLUME_ASPECT_RATIO_HISTOGRAM "Prints a histogram of aspect ratios of selected volumes"
4042

4143
namespace ug {
4244
namespace promesh {
4345

44-
void PrintFaceAspectRatios (Mesh* msh);
46+
template <class elem_t>
47+
void PrintAspectRatios (Mesh* msh);
4548

46-
void PrintFaceAspectRatioHistogram (Mesh* msh, int numHistoSecs);
49+
template <class elem_t>
50+
void PrintAspectRatioHistogram (Mesh* msh, int numHistoSecs);
4751

4852
}
4953
}

tools/selection_tools.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,37 @@ void SelectFacesByNormal(
819819
}
820820
}
821821

822+
823+
void SelectFacesByNormal(
824+
Mesh* obj,
825+
const vector3& refNormal,
826+
number minDeviationAngle,
827+
number maxDeviationAngle,
828+
bool noInnerFaces)
829+
{
830+
number minDot = cos(deg_to_rad(maxDeviationAngle));
831+
number maxDot = cos(deg_to_rad(minDeviationAngle));
832+
833+
Grid& grid = obj->grid();
834+
Selector& sel = obj->selector();
835+
Grid::AttachmentAccessor<Vertex, APosition> aaPos(grid, aPosition);
836+
837+
vector3 n;
838+
VecNormalize(n, refNormal);
839+
840+
for(FaceIterator iter = grid.faces_begin(); iter != grid.faces_end(); ++iter){
841+
vector3 fn;
842+
CalculateNormal(fn, *iter, aaPos);
843+
const number d = VecDot(fn, n);
844+
if((d > minDot - SMALL && d < maxDot + SMALL)
845+
&& (!noInnerFaces || (NumAssociatedVolumes(grid, *iter) < 2)))
846+
{
847+
sel.select(*iter);
848+
}
849+
}
850+
}
851+
852+
822853
void FaceSelectionFill(Mesh* obj)
823854
{
824855
Selector& sel = obj->selector();

tools/selection_tools.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ void SelectFacesByNormal(
362362
const vector3& refNormal,
363363
number maxDeviationAngle);
364364

365+
void SelectFacesByNormal(
366+
Mesh* obj,
367+
const vector3& refNormal,
368+
number minDeviationAngle,
369+
number maxDeviationAngle,
370+
bool noInnerFaces);
371+
365372
void FaceSelectionFill(Mesh* obj);
366373

367374
size_t SelectBentQuadrilaterals(Mesh* obj, number dotThreshold);

tools/subset_tools.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ void CopySubsetIndicesToSides(
434434
}
435435

436436
// NEW GROUP: Quality Util
437+
template <class elem_t>
437438
void AssignSubsetsByAspectRatio (
438439
Mesh* msh,
439440
int numHistoSecs,
@@ -451,30 +452,32 @@ void AssignSubsetsByAspectRatio (
451452
Selector& sel = msh->selector();
452453
SubsetHandler& sh = msh->subset_handler();
453454

455+
int firstSubset = sh.num_subsets();
456+
if(eraseOldSubsets){
457+
sh.clear();
458+
firstSubset = 0;
459+
}
460+
461+
454462
AInt aHistoSecs;
455-
g.attach_to_faces(aHistoSecs);
456-
Grid::FaceAttachmentAccessor<AInt> aaHistoSec (g, aHistoSecs);
463+
g.attach_to<elem_t>(aHistoSecs);
464+
Grid::AttachmentAccessor<elem_t, AInt> aaHistoSec (g, aHistoSecs);
457465

458466
std::vector<int> histo;
459467

460-
FaceIterator facesBegin = sel.faces_begin();
461-
FaceIterator facesEnd = sel.faces_end();
462-
size_t numFaces = sel.num<Face>();
463-
if(numFaces == 0){
464-
facesBegin = g.faces_begin();
465-
facesEnd = g.faces_end();
466-
numFaces = g.num<Face>();
468+
typedef typename Grid::traits<elem_t>::iterator iter_t;
469+
iter_t elemsBegin = sel.begin<elem_t>();
470+
iter_t elemsEnd = sel.end<elem_t>();
471+
size_t numElems = sel.num<elem_t>();
472+
if(numElems == 0){
473+
elemsBegin = g.begin<elem_t>();
474+
elemsEnd = g.end<elem_t>();
475+
numElems = g.num<elem_t>();
467476
}
468477

469-
GetFaceAspectRatioHistogram (histo, facesBegin, facesEnd,
470-
numHistoSecs, msh->position_accessor(),
471-
&aaHistoSec);
472-
473-
int firstSubset = sh.num_subsets();
474-
if(eraseOldSubsets){
475-
sh.clear();
476-
firstSubset = 0;
477-
}
478+
GetAspectRatioHistogram (histo, elemsBegin, elemsEnd,
479+
numHistoSecs, msh->position_accessor(),
480+
&aaHistoSec);
478481

479482
const number stepSize = 1. / (number) numHistoSecs;
480483
StringStreamTable t;
@@ -487,17 +490,20 @@ void AssignSubsetsByAspectRatio (
487490
t(1, i) << histo[i];
488491
}
489492

490-
for(FaceIterator iface = facesBegin; iface != facesEnd; ++iface)
491-
sh.assign_subset(*iface, aaHistoSec[*iface]);
493+
for(iter_t ielem = elemsBegin; ielem != elemsEnd; ++ielem)
494+
sh.assign_subset(*ielem, aaHistoSec[*ielem]);
492495

493496
AssignSubsetColorsBlueToGreen (sh, firstSubset, numHistoSecs);
494497

495-
g.detach_from_faces(aHistoSecs);
498+
g.detach_from<elem_t>(aHistoSecs);
496499

497-
UG_LOG("Face Aspect Ratio Histogram (" << numFaces << " faces):\n\n");
500+
UG_LOG("Aspect Ratio Histogram (" << numElems << " elements):\n\n");
498501
UG_LOG(t.to_string() << std::endl);
499502
}
500503

504+
template void AssignSubsetsByAspectRatio <Face> (Mesh*, int, bool);
505+
template void AssignSubsetsByAspectRatio <Volume> (Mesh*, int, bool);
506+
501507

502508
template <int dim, class elem_t>
503509
void AssignSubsetsFromRaster_IMPL (Mesh* obj, const char* rasterFileName)

tools/subset_tools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#define TOOLTIP_SEPARATE_DEGENERATED_BOUNDARY_FACE_SUBSETS "Separates degenerated boundary face subsets at sharp creases."
6363
#define TOOLTIP_COPY_SUBSET_INDICES_TO_SIDES "Copies subset indices of selected elements to sides of those elements."
6464
#define TOOLTIP_ASSIGN_SUBSETS_BY_ELEMENT_TYPE "Assigns elemets to subsets based on their concrete type."
65-
#define TOOLTIP_ASSIGN_SUBSETS_BY_ASPECT_RATIO "Assigns subsets according to a aspect ratio histogram"
65+
#define TOOLTIP_ASSIGN_SUBSETS_BY_ASPECT_RATIO "Assigns subsets according to an aspect ratio histogram"
6666
#define TOOLTIP_ASSIGN_SUBSETS_FROM_RASTER "Assigns the subset index for each element from the raster-cell in which the center of the element lies."
6767

6868
namespace ug{
@@ -139,6 +139,7 @@ void CopySubsetIndicesToSides(
139139
bool selectionOnly,
140140
bool toUnassignedOnly);
141141

142+
template <class elem_t>
142143
void AssignSubsetsByAspectRatio (
143144
Mesh* msh,
144145
int numHistoSecs,

0 commit comments

Comments
 (0)