Merge branch 'fix_parsing_stl_params' into 'master'

fix parsing of stl parameters from python

See merge request jschoeberl/netgen!271
This commit is contained in:
Matthias Hochsteger 2019-10-07 11:52:49 +00:00
commit 86342534c1
6 changed files with 15815 additions and 81 deletions

View File

@ -52,7 +52,7 @@ void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)
stlparam.outerchartangle = py::cast<double>(kwargs.attr("pop")("outerchartangle"));
if(kwargs.contains("usesearchtree"))
stlparam.usesearchtree = py::cast<int>(kwargs.attr("pop")("usesearchtree"));
if(kwargs.contains("resthatlasfac"))
if(kwargs.contains("atlasfac"))
{
auto val = kwargs.attr("pop")("resthatlasfac");
if(val.is_none())
@ -65,9 +65,9 @@ void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)
}
if(kwargs.contains("atlasminh"))
stlparam.atlasminh = py::cast<double>(kwargs.attr("pop")("atlasminh"));
if(kwargs.contains("resthsurfcurvfac"))
if(kwargs.contains("surfcurvfac"))
{
auto val = kwargs.attr("pop")("resthsurfcurvfac");
auto val = kwargs.attr("pop")("surfcurvfac");
if(val.is_none())
stlparam.resthsurfcurvenable = false;
else
@ -76,9 +76,9 @@ void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)
stlparam.resthsurfcurvfac = py::cast<double>(val);
}
}
if(kwargs.contains("resthchartdistfac"))
if(kwargs.contains("chartdistfac"))
{
auto val = kwargs.attr("pop")("resthchartdistfac");
auto val = kwargs.attr("pop")("chartdistfac");
if(val.is_none())
stlparam.resthchartdistenable = false;
else
@ -87,9 +87,9 @@ void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)
stlparam.resthchartdistfac = py::cast<double>(val);
}
}
if(kwargs.contains("resthcloseedgefac"))
if(kwargs.contains("closeedgefac"))
{
auto val = kwargs.attr("pop")("resthcloseedgefac");
auto val = kwargs.attr("pop")("closeedgefac");
if(val.is_none())
stlparam.resthcloseedgeenable = false;
else
@ -98,9 +98,9 @@ void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)
stlparam.resthcloseedgefac = py::cast<double>(val);
}
}
if(kwargs.contains("resthedgeanglefac"))
if(kwargs.contains("edgeanglefac"))
{
auto val = kwargs.attr("pop")("resthedgeanglefac");
auto val = kwargs.attr("pop")("edgeanglefac");
if(val.is_none())
stlparam.resthedgeangleenable = false;
else
@ -109,9 +109,9 @@ void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)
stlparam.resthedgeanglefac = py::cast<double>(val);
}
}
if(kwargs.contains("resthsurfmeshcurvfac"))
if(kwargs.contains("surfmeshcurvfac"))
{
auto val = kwargs.attr("pop")("resthsurfmeshcurvfac");
auto val = kwargs.attr("pop")("surfmeshcurvfac");
if(val.is_none())
stlparam.resthsurfmeshcurvenable = false;
else
@ -120,9 +120,9 @@ void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)
stlparam.resthsurfmeshcurvfac = py::cast<double>(val);
}
}
if(kwargs.contains("resthlinelengthfac"))
if(kwargs.contains("linelengthfac"))
{
auto val = kwargs.attr("pop")("resthlinelengthfac");
auto val = kwargs.attr("pop")("linelengthfac");
if(val.is_none())
stlparam.resthlinelengthenable = false;
else

View File

@ -302,6 +302,13 @@ public:
void Print (ostream & ost) const;
};
inline ostream & operator<< (ostream & ost, const STLParameters & stlparam)
{
stlparam.Print (ost);
return ost;
}
void STLMeshing (STLGeometry & geom,
Mesh & mesh,

View File

@ -6,12 +6,10 @@ class _MeshsizeObject:
return MeshingParameters(curvaturesafety=1,
segmentsperedge=0.3,
grading=0.7,
surfcurvfac=0.25,
chartdistfac=0.8,
linelengthfac=0.2,
closeedgefac=0.5,
minedgelen=0.002,
edgeanglefac=0.25,
surfmeshcurvfac=1.,
optsteps3d=5)
@property
@ -19,12 +17,10 @@ class _MeshsizeObject:
return MeshingParameters(curvaturesafety=1.5,
segmentsperedge=0.5,
grading=0.5,
surfcurvfac=0.5,
chartdistfac=1,
linelengthfac=0.35,
closeedgefac=1,
minedgelen=0.02,
edgeanglefac=0.5,
surfmeshcurvfac=1.5,
optsteps3d=5)
@property
@ -32,12 +28,10 @@ class _MeshsizeObject:
return MeshingParameters(curvaturesafety=2,
segmentsperedge=1,
grading=0.3,
surfcurvfac=1.,
chartdistfac=1.5,
linelengthfac=0.5,
closeedgefac=2,
minedgelen=0.2,
edgeanglefac=1,
surfmeshcurvfac=2.,
optsteps3d=5)
@property
@ -45,12 +39,10 @@ class _MeshsizeObject:
return MeshingParameters(curvaturesafety=3,
segmentsperedge=2,
grading=0.2,
surfcurvfac=1.5,
chartdistfac=2,
linelengthfac=1.5,
closeedgefac=3.5,
minedgelen=1.,
edgeanglefac=1.5,
surfmeshcurvfac=3.,
optsteps3d=5)
@ -59,12 +51,10 @@ class _MeshsizeObject:
return MeshingParameters(curvaturesafety=5,
segmentsperedge=3,
grading=0.1,
surfcurvfac=3,
chartdistfac=5,
linelengthfac=3,
closeedgefac=5,
minedgelen=2.,
edgeanglefac=3.,
surfmeshcurvfac=5.,
optsteps3d=5)

File diff suppressed because it is too large Load Diff

View File

@ -691,39 +691,39 @@
"total_badness": 2772.6154636
},
{
"ne1d": 398,
"ne2d": 1030,
"ne3d": 1389,
"quality_histogram": "[0, 0, 0, 0, 2, 5, 18, 35, 47, 74, 111, 126, 131, 179, 189, 185, 134, 93, 46, 14]",
"total_badness": 2178.5663259
"ne1d": 298,
"ne2d": 608,
"ne3d": 770,
"quality_histogram": "[0, 0, 0, 1, 10, 9, 19, 15, 35, 46, 62, 87, 79, 89, 83, 87, 64, 45, 30, 9]",
"total_badness": 1284.6220542
},
{
"ne1d": 422,
"ne2d": 1094,
"ne3d": 1530,
"quality_histogram": "[0, 0, 0, 0, 0, 7, 14, 43, 46, 79, 94, 164, 155, 163, 212, 180, 180, 118, 61, 14]",
"total_badness": 2364.3186941
"ne1d": 370,
"ne2d": 854,
"ne3d": 1130,
"quality_histogram": "[0, 0, 0, 0, 2, 4, 17, 25, 26, 34, 64, 107, 137, 161, 156, 181, 93, 73, 42, 8]",
"total_badness": 1739.2621504
},
{
"ne1d": 456,
"ne2d": 1230,
"ne3d": 1988,
"quality_histogram": "[0, 0, 0, 0, 0, 2, 2, 5, 19, 39, 62, 112, 177, 236, 314, 304, 295, 236, 140, 45]",
"total_badness": 2747.770553
"ne1d": 516,
"ne2d": 1584,
"ne3d": 2549,
"quality_histogram": "[0, 0, 0, 0, 2, 1, 7, 19, 30, 53, 121, 174, 224, 296, 384, 362, 331, 304, 201, 40]",
"total_badness": 3600.6650263
},
{
"ne1d": 498,
"ne2d": 1396,
"ne3d": 2903,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 3, 4, 13, 31, 64, 136, 221, 397, 484, 533, 504, 399, 114]",
"total_badness": 3701.6633824
"ne1d": 722,
"ne2d": 2888,
"ne3d": 6818,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 1, 3, 12, 29, 67, 167, 379, 655, 877, 1099, 1146, 1177, 948, 258]",
"total_badness": 8742.2896959
},
{
"ne1d": 538,
"ne2d": 1670,
"ne3d": 4609,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 14, 45, 103, 220, 448, 693, 963, 1055, 803, 257]",
"total_badness": 5628.2514122
"ne1d": 1862,
"ne2d": 19516,
"ne3d": 135482,
"quality_histogram": "[0, 0, 0, 0, 0, 1, 0, 6, 30, 145, 444, 1158, 3034, 7025, 13447, 21335, 28448, 30344, 22953, 7112]",
"total_badness": 165806.81509
}
],
"lshape3d.geo": [
@ -899,39 +899,39 @@
"total_badness": 1672.6379358
},
{
"ne1d": 146,
"ne2d": 378,
"ne3d": 629,
"quality_histogram": "[0, 0, 0, 0, 1, 4, 13, 14, 23, 44, 56, 74, 86, 82, 70, 72, 36, 38, 10, 6]",
"total_badness": 1030.3136745
"ne1d": 112,
"ne2d": 212,
"ne3d": 346,
"quality_histogram": "[0, 0, 0, 3, 8, 8, 8, 9, 19, 25, 40, 40, 35, 39, 38, 37, 17, 14, 5, 1]",
"total_badness": 629.86936176
},
{
"ne1d": 156,
"ne2d": 394,
"ne3d": 758,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 3, 10, 24, 33, 62, 90, 103, 138, 113, 90, 60, 22, 10]",
"total_badness": 1097.0227588
"ne1d": 134,
"ne2d": 288,
"ne3d": 523,
"quality_histogram": "[0, 0, 0, 0, 0, 5, 5, 4, 14, 15, 32, 48, 68, 67, 66, 76, 44, 43, 29, 7]",
"total_badness": 790.86141744
},
{
"ne1d": 170,
"ne2d": 454,
"ne3d": 1180,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 3, 4, 12, 16, 43, 89, 116, 178, 208, 222, 153, 99, 37]",
"total_badness": 1563.8386897
"ne1d": 194,
"ne2d": 594,
"ne3d": 1742,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 2, 5, 9, 40, 88, 126, 192, 280, 281, 279, 241, 165, 34]",
"total_badness": 2325.4945287
},
{
"ne1d": 190,
"ne2d": 504,
"ne3d": 1516,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 20, 50, 73, 141, 210, 280, 272, 238, 170, 55]",
"total_badness": 1957.4591373
"ne1d": 266,
"ne2d": 990,
"ne3d": 4103,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 1, 2, 13, 28, 69, 162, 317, 534, 761, 831, 732, 513, 140]",
"total_badness": 5196.8765579
},
{
"ne1d": 230,
"ne2d": 698,
"ne3d": 3545,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 2, 6, 12, 20, 44, 109, 246, 424, 580, 665, 742, 515, 180]",
"total_badness": 4425.483014
"ne1d": 674,
"ne2d": 6870,
"ne3d": 82768,
"quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 0, 14, 59, 188, 513, 1613, 4088, 7976, 12954, 17553, 18871, 14413, 4526]",
"total_badness": 100797.22838
}
],
"period.geo": [
@ -978,6 +978,50 @@
"total_badness": 84181.20294
}
],
"plane.stl": [
{
"ne1d": 890,
"ne2d": 2646,
"ne3d": 8528,
"quality_histogram": "[4, 14, 27, 37, 43, 46, 41, 91, 102, 180, 331, 464, 679, 978, 1233, 1340, 1240, 987, 555, 136]",
"total_badness": 12856.87891
},
{
"ne1d": 572,
"ne2d": 1228,
"ne3d": 1901,
"quality_histogram": "[2, 18, 45, 48, 51, 66, 60, 92, 128, 133, 165, 191, 187, 197, 168, 128, 114, 65, 39, 4]",
"total_badness": 4320.0075948
},
{
"ne1d": 724,
"ne2d": 1754,
"ne3d": 3285,
"quality_histogram": "[4, 20, 30, 41, 36, 43, 44, 68, 96, 154, 170, 280, 339, 436, 436, 406, 340, 206, 107, 29]",
"total_badness": 5959.5331564
},
{
"ne1d": 956,
"ne2d": 2886,
"ne3d": 8682,
"quality_histogram": "[3, 11, 23, 48, 51, 47, 53, 55, 92, 133, 207, 340, 555, 905, 1236, 1446, 1418, 1197, 665, 197]",
"total_badness": 12703.577343
},
{
"ne1d": 1554,
"ne2d": 6466,
"ne3d": 31866,
"quality_histogram": "[4, 7, 10, 5, 21, 54, 53, 79, 111, 204, 328, 684, 1327, 2460, 3983, 5375, 6122, 5827, 4106, 1106]",
"total_badness": 41304.661508
},
{
"ne1d": 2992,
"ne2d": 23396,
"ne3d": 276949,
"quality_histogram": "[5, 10, 11, 13, 8, 23, 34, 93, 171, 459, 1121, 2702, 6581, 15040, 28425, 44154, 58179, 60855, 45197, 13868]",
"total_badness": 341180.22628
}
],
"revolution.geo": [
{
"ne1d": 320,

View File

@ -31,11 +31,16 @@ def checkData(mesh, mp, ref):
assert ref['quality_histogram'] == data['quality_histogram']
assert ref['total_badness'] == pytest.approx(data['total_badness'], rel=1e-5)
# get tutorials
def getFiles(fileEnding):
r, d, files = next(os.walk(os.path.join("..","..","tutorials")))
return (f for f in files if f.endswith(fileEnding))
# get additional tests
def getAdditionalFiles(fileEnding):
r, d, files = next(os.walk("geofiles"))
return (f for f in files if f.endswith(fileEnding))
@pytest.fixture
def refdata():
return json.load(open('results.json','r'))
@ -59,25 +64,30 @@ _geofiles = [f for f in getFiles(".geo")] + [f for f in getFiles(".stl")]
if has_occ:
_geofiles += [f for f in getFiles(".step")]
_geofiles.sort()
_additional_testfiles = [f for f in getAdditionalFiles(".stl")]
if has_occ:
_additional_testfiles += [f for f in getAdditionalFiles(".step")]
_additional_testfiles.sort()
def generateMesh(filename, mp):
folder = os.path.join("..","..","tutorials") if filename in _geofiles else "geofiles"
if filename.endswith(".geo"):
geo = csg.CSGeometry(os.path.join("..","..","tutorials", filename))
geo = csg.CSGeometry(os.path.join(folder, filename))
elif filename.endswith(".stl"):
geo = stl.STLGeometry(os.path.join("..","..","tutorials", filename))
geo = stl.STLGeometry(os.path.join(folder, filename))
elif filename.endswith(".step"):
geo = occ.OCCGeometry(os.path.join("..","..","tutorials", filename))
geo = occ.OCCGeometry(os.path.join(folder, filename))
return geo.GenerateMesh(mp)
def isSlowTest(filename):
return filename in ["cubemcyl.geo", "frame.step", "revolution.geo", "manyholes.geo", "torus.geo",
"cubemsphere.geo", "manyholes2.geo", "matrix.geo", "trafo.geo", "ellipticcone.geo",
"period.geo", "shaft.geo", "cubeandring.geo", "ellipticcyl.geo",
"ellipsoid.geo", "cone.geo"]
"ellipsoid.geo", "cone.geo", "plane.stl"]
def getParameters():
res = []
for f in _geofiles:
for f in _geofiles + _additional_testfiles:
for i,mp in enumerate(getMeshingparameters(f)):
if isSlowTest(f):
res.append( pytest.param(f, mp, i, marks=pytest.mark.slow ) )
@ -105,7 +115,7 @@ def generateResultFile():
import re, time
data = {}
with TaskManager():
for _file in _geofiles:
for _file in _geofiles + _additional_testfiles:
print("generate "+_file)
start = time.time()
mps = getMeshingparameters(_file)
@ -116,10 +126,11 @@ def generateResultFile():
mesh = generateMesh(_file, mp)
meshdata.append( getData(mesh, mp) )
data[_file] = meshdata
print("needed", time.time() - start, "seconds")
s = json.dumps(data, sort_keys=True, indent=4)
open("results.json", "w").write(s)
print("done")
if __name__ == "__main__":
generateResultFile()