Skip to content

Commit e765507

Browse files
authored
Update EBGeometry file parser and support more file types (#83)
1 parent f74c319 commit e765507

57 files changed

Lines changed: 5775299 additions & 942 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CheckDocs.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
import subprocess
3+
import re
4+
from pathlib import Path
5+
6+
def get_changed_files(base_branch="main"):
7+
"""Get list of changed .cpp, .hpp, .options, and .inputs files compared to base branch."""
8+
result = subprocess.run(
9+
["git", "diff", "--name-only", base_branch],
10+
capture_output=True,
11+
text=True,
12+
check=True
13+
)
14+
files = [line.strip() for line in result.stdout.splitlines() if line.strip()]
15+
exts = (".cpp", ".hpp", ".options", ".inputs", ".md")
16+
return [str(Path(f).resolve()) for f in files if f.endswith(exts)]
17+
18+
def find_literalincludes(rst_dir, changed_files):
19+
"""Search .rst files for literalinclude directives referencing changed files."""
20+
includes_found = []
21+
22+
for rst_path in Path(rst_dir).rglob("*.rst"):
23+
with open(rst_path, encoding="utf-8") as f:
24+
for lineno, line in enumerate(f, start=1):
25+
match = re.match(r"\s*\.\.\s+literalinclude::\s+(.*)", line)
26+
if match:
27+
included_file = match.group(1).strip()
28+
# Resolve relative path from rst file location
29+
included_path = (rst_path.parent / included_file).resolve()
30+
if str(included_path) in changed_files:
31+
includes_found.append(
32+
(rst_path, lineno, included_file, included_path)
33+
)
34+
return includes_found
35+
36+
if __name__ == "__main__":
37+
base_branch = "main"
38+
rst_dir = "Docs/Sphinx/source"
39+
40+
changed_files = get_changed_files(base_branch)
41+
if not changed_files:
42+
print(f"No changed .cpp, .hpp, .options, .inputs, or .md files compared to {base_branch}")
43+
exit(0)
44+
45+
includes = find_literalincludes(rst_dir, changed_files)
46+
47+
if includes:
48+
print("Found literalincludes referencing changed files:\n")
49+
for rst_file, line, included, resolved in includes:
50+
print(f"{rst_file}:{line} -> includes '{included}' (resolved: {resolved})")
51+
else:
52+
print("No literalinclude directives reference changed files.")

Docs/Sphinx/source/Parsers.rst

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ Reading data
66
Routines for parsing surface grid from files into ``EBGeometry``'s DCEL grids are given in the namespace ``EBGeometry::Parser``.
77
The source code is implemented in :file:`Source/EBGeometry_Parser.hpp`.
88

9-
.. warning::
9+
.. important::
1010

11-
``EBGeometry`` is currently limited to reading binary and ASCII STL files and reconstructing DCEL grids from those.
12-
However, it is also possible to build DCEL grids from polygon soups read using third-party codes (see :ref:`Chap:ThirdPartyParser`).
11+
``EBGeometry`` is currently limited to reading STL, PLY, and VTK files, and then reconstructing DCEL grids from those.
12+
PLY and and VTK files can contain associated data on the nodes and faces, but this is not automatically populated when constructing the DCEL grids.
13+
It is also possible to build DCEL grids from polygon soups read using third-party codes (see :ref:`Chap:ThirdPartyParser`).
1314

1415
Quickstart
1516
----------
1617

17-
If you have one or multiple STL files, you can quickly turn them into signed distance fields using
18+
If you have one or multiple files, you can quickly turn them into signed distance fields using
1819

1920
.. code-block:: c++
2021

@@ -37,46 +38,52 @@ See :ref:`Chap:LinearSTL` for further details.
3738

3839
This version will convert all DCEL polygons to triangles, and usually provides a nice code speedup.
3940

40-
Reading STL files
41-
-----------------
41+
Reading mesh files
42+
------------------
4243

43-
``EBGeometry`` supports a native parser for binary and ASCII STL files, which can be read into a few different representations:
44+
``EBGeometry`` supports a native parser for binary and ASCII files, which can be read into a few different representations:
4445

4546
#. Into a DCEL mesh, see :ref:`Chap:ImplemDCEL`.
4647
#. Into a signed distance function representation of a DCEL mesh, see :ref:`Chap:ImplemCSG`.
4748
#. Into a signed distance function representation of a DCEL mesh, but using a BVH accelerator in full representation.
48-
#. Into a signed distance function representation of a DCEL mesh, but using a BVH accelerator in compact representation.
49+
#. Into a signed distance function representation of a DCEL mesh, but using a BVH accelerator in compact representation.
50+
51+
.. important::
52+
53+
The ``EBGeometry`` parser will read input files into internal objects that represent each file type.
54+
Conversion of these objects into DCEL meshes is not required, and it is possible to creating bounding volume hierarchies directly from the facets.
55+
This is useful when only an acceleration structure is needed for looking up facets or triangles, but no signed distance function is otherwise required.
4956

5057
DCEL representation
5158
___________________
5259

53-
To read one or multiple STL files and turn it into DCEL meshes, use
60+
To read one or multiple files and turn it into DCEL meshes, use
5461

5562
.. literalinclude:: ../../../Source/EBGeometry_Parser.hpp
5663
:language: c++
57-
:lines: 54-68
64+
:lines: 124-138
5865
:dedent: 2
5966

6067
Note that this will only expose the DCEL mesh, but not include any signed distance functionality.
6168

6269
DCEL mesh SDF
6370
_____________
6471

65-
To read one or multiple STL files and also turn it into signed distance representations, use
72+
To read one or multiple files and also turn it into signed distance representations, use
6673

6774
.. literalinclude:: ../../../Source/EBGeometry_Parser.hpp
6875
:language: c++
69-
:lines: 70-84
76+
:lines: 140-154
7077
:dedent: 2
7178

7279
DCEL mesh SDF with full BVH
7380
___________________________
7481

75-
To read one or multiple STL files and turn it into signed distance representations using a full BVH representation, use
82+
To read one or multiple files and turn it into signed distance representations using a full BVH representation, use
7683

7784
.. literalinclude:: ../../../Source/EBGeometry_Parser.hpp
7885
:language: c++
79-
:lines: 86-106
86+
:lines: 156-176
8087
:dedent: 2
8188

8289
.. _Chap:LinearSTL:
@@ -88,18 +95,18 @@ To read one or multiple STL files and turn it into signed distance representatio
8895

8996
.. literalinclude:: ../../../Source/EBGeometry_Parser.hpp
9097
:language: c++
91-
:lines: 107-128
98+
:lines: 178-198
9299
:dedent: 2
93100

94101

95102
Triangle meshes with BVH
96103
________________________
97104

98-
To read one or multiple STL files and turn it into signed distance representations using a compact BVH representation, use
105+
To read one or multiple files and turn it into signed distance representations using a compact BVH representation, use
99106

100107
.. literalinclude:: ../../../Source/EBGeometry_Parser.hpp
101108
:language: c++
102-
:lines: 130-147
109+
:lines: 200-217
103110
:dedent: 2
104111

105112
This version differs from the DCEL meshes in that each DCEL polygon is converted into triangles after parsing.
@@ -122,9 +129,9 @@ Here, ``vertices`` contains the :math:`x,y,z` coordinates of each vertex, while
122129

123130
To turn this into a DCEL mesh, one should compress the triangle soup (get rid of duplicate vertices) and then construct the DCEL mesh:
124131

125-
.. literalinclude:: ../../../Source/EBGeometry_Parser.hpp
132+
.. literalinclude:: ../../../Source/EBGeometry_Soup.hpp
126133
:language: c++
127-
:lines: 182-201
134+
:lines: 37-56
128135
:dedent: 2
129136

130137
The ``compress`` function will discard duplicate vertices from the soup, while the ``soupToDCEL`` will tie the remaining polygons into a DCEL mesh.

EBGeometry.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Source/EBGeometry_SFC.hpp"
1414
#include "Source/EBGeometry_SignedDistanceFunction.hpp"
1515
#include "Source/EBGeometry_SimpleTimer.hpp"
16+
#include "Source/EBGeometry_Soup.hpp"
1617
#include "Source/EBGeometry_Transform.hpp"
1718
#include "Source/EBGeometry_Triangle.hpp"
1819

Examples/AMReX_DCEL/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,36 @@ main(int argc, char* argv[])
103103

104104
if (which_geom == 0) { // Airfoil case
105105
rb = RealBox({-100, -100, -75}, {400, 100, 125});
106-
filename = "../Resources/airfoil.stl";
106+
filename = "../Resources/airfoil_binary.stl";
107107
}
108108
else if (which_geom == 1) { // Sphere case
109109
rb = RealBox({-400, -400, -400}, {400, 400, 400});
110-
filename = "../Resources/sphere.stl";
110+
filename = "../Resources/sphere_binary.stl";
111111
}
112112
else if (which_geom == 2) { // Dodecahedron
113113
rb = RealBox({-2., -2., -2.}, {2., 2., 2.});
114-
filename = "../Resources/dodecahedron.stl";
114+
filename = "../Resources/dodecahedron_binary.stl";
115115
}
116116
else if (which_geom == 3) { // Horse
117117
rb = RealBox({-0.12, -0.12, -0.12}, {0.12, 0.12, 0.12});
118-
filename = "../Resources/horse.stl";
118+
filename = "../Resources/horse_binary.stl";
119119
}
120120
else if (which_geom == 4) { // Car
121121
// rb = RealBox({-20,-20,-20}, {20,20,20}); // Doesn't work.
122122
rb = RealBox({-10, -5, -5}, {10, 5, 5}); // Works.
123-
filename = "../Resources/porsche.stl";
123+
filename = "../Resources/porsche_binary.stl";
124124
}
125125
else if (which_geom == 5) { // Orion
126126
rb = RealBox({-10, -5, -10}, {10, 10, 10});
127-
filename = "../Resources/orion.stl";
127+
filename = "../Resources/orion_binary.stl";
128128
}
129129
else if (which_geom == 6) { // Armadillo
130130
rb = RealBox({-100, -75, -100}, {100, 125, 100});
131-
filename = "../Resources/armadillo.stl";
131+
filename = "../Resources/armadillo_binary.stl";
132132
}
133133
else if (which_geom == 7) { // Adirondacks
134134
rb = RealBox({0, 0, 0}, {200, 200, 50});
135-
filename = "../Resources/adirondack.stl";
135+
filename = "../Resources/adirondack_binary.stl";
136136
}
137137

138138
Array<int, AMREX_SPACEDIM> is_periodic{false, false, false};

Examples/AMReX_PaintEB/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,36 @@ main(int argc, char* argv[])
114114

115115
if (which_geom == 0) { // Airfoil case
116116
rb = RealBox({-100, -100, -75}, {400, 100, 125});
117-
filename = "../Resources/airfoil.stl";
117+
filename = "../Resources/airfoil_binary.stl";
118118
}
119119
else if (which_geom == 1) { // Sphere case
120120
rb = RealBox({-400, -400, -400}, {400, 400, 400});
121-
filename = "../Resources/sphere.stl";
121+
filename = "../Resources/sphere_binary.stl";
122122
}
123123
else if (which_geom == 2) { // Dodecahedron
124124
rb = RealBox({-2., -2., -2.}, {2., 2., 2.});
125-
filename = "../Resources/dodecahedron.stl";
125+
filename = "../Resources/dodecahedron_binary.stl";
126126
}
127127
else if (which_geom == 3) { // Horse
128128
rb = RealBox({-0.12, -0.12, -0.12}, {0.12, 0.12, 0.12});
129-
filename = "../Resources/horse.stl";
129+
filename = "../Resources/horse_binary.stl";
130130
}
131131
else if (which_geom == 4) { // Car
132132
// rb = RealBox({-20,-20,-20}, {20,20,20}); // Doesn't work.
133133
rb = RealBox({-10, -5, -5}, {10, 5, 5}); // Works.
134-
filename = "../Resources/porsche.stl";
134+
filename = "../Resources/porsche_binary.stl";
135135
}
136136
else if (which_geom == 5) { // Orion
137137
rb = RealBox({-10, -5, -10}, {10, 10, 10});
138-
filename = "../Resources/orion.stl";
138+
filename = "../Resources/orion_binary.stl";
139139
}
140140
else if (which_geom == 6) { // Armadillo
141141
rb = RealBox({-100, -75, -100}, {100, 125, 100});
142-
filename = "../Resources/armadillo.stl";
142+
filename = "../Resources/armadillo_binary.stl";
143143
}
144144
else if (which_geom == 7) { // Adirondacks
145145
rb = RealBox({0, 0, 0}, {200, 200, 50});
146-
filename = "../Resources/adirondack.stl";
146+
filename = "../Resources/adirondack_binary.stl";
147147
}
148148

149149
Array<int, AMREX_SPACEDIM> is_periodic{false, false, false};

Examples/Chombo3_DCEL/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,48 +91,48 @@ main(int argc, char* argv[])
9191
loCorner = -50 * RealVect::Unit;
9292
hiCorner = 250 * RealVect::Unit;
9393

94-
filename = "../Resources/airfoil.stl";
94+
filename = "../Resources/airfoil_binary.stl";
9595
}
9696
else if (whichGeom == 1) { // Sphere
9797
loCorner = -400 * RealVect::Unit;
9898
hiCorner = 400 * RealVect::Unit;
9999

100-
filename = "../Resources/sphere.stl";
100+
filename = "../Resources/sphere_binary.stl";
101101
}
102102
else if (whichGeom == 2) { // Dodecahedron
103103
loCorner = -2 * RealVect::Unit;
104104
hiCorner = 2 * RealVect::Unit;
105105

106-
filename = "../Resources/dodecahedron.stl";
106+
filename = "../Resources/dodecahedron_binary.stl";
107107
}
108108
else if (whichGeom == 3) { // Horse
109109
loCorner = -0.12 * RealVect::Unit;
110110
hiCorner = 0.12 * RealVect::Unit;
111111

112-
filename = "../Resources/horse.stl";
112+
filename = "../Resources/horse_binary.stl";
113113
}
114114
else if (whichGeom == 4) { // Porsche
115115
loCorner = -10 * RealVect::Unit;
116116
hiCorner = 10 * RealVect::Unit;
117117

118-
filename = "../Resources/porsche.stl";
118+
filename = "../Resources/porsche_binary.stl";
119119
}
120120
else if (whichGeom == 5) { // Orion
121121
loCorner = -10 * RealVect::Unit;
122122
hiCorner = 10 * RealVect::Unit;
123123

124-
filename = "../Resources/orion.stl";
124+
filename = "../Resources/orion_binary.stl";
125125
}
126126
else if (whichGeom == 6) { // Armadillo
127127
loCorner = -125 * RealVect::Unit;
128128
hiCorner = 125 * RealVect::Unit;
129129

130-
filename = "../Resources/armadillo.stl";
130+
filename = "../Resources/armadillo_binary.stl";
131131
}
132132
else if (whichGeom == 7) { // Adirondacks
133133
loCorner = RealVect::Zero;
134134
hiCorner = 250 * RealVect::Unit;
135-
filename = "../Resources/adirondack.stl";
135+
filename = "../Resources/adirondack_binary.stl";
136136
}
137137

138138
using Meta = EBGeometry::DCEL::DefaultMetaData;

Examples/EBGeometry_DCEL/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ main(int argc, char* argv[])
4040
else {
4141
std::cout << "Missing file name. Use ./a.out 'filename' where 'filename' "
4242
"is one of the files in ../Resources. Setting this equal to the armadillo file\n";
43-
file = "../Resources/armadillo.stl";
43+
file = "../Resources/armadillo_binary.stl";
4444
}
4545

46-
// Three representations of the same object. Note that this reads the mesh three
47-
// times and builds the BVH twice (there are converters that avoid this, users will
48-
// only use one of these representations).
46+
// Representations of the same object. Note that this reads the mesh and builds the BVH
47+
// tree multiple times.
48+
//
49+
// There are converters that avoid this, but users will almost always only use one of
50+
// these representations.
4951
const auto dcelSDF = EBGeometry::Parser::readIntoMesh<T, Meta>(file);
5052
const auto bvhSDF = EBGeometry::Parser::readIntoFullBVH<T, Meta, BV, K>(file);
5153
const auto linSDF = EBGeometry::Parser::readIntoLinearBVH<T, Meta, BV, K>(file);

Examples/EBGeometry_F18/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ main(int argc, char* argv[])
135135

136136
// Debug -- make sure all functions produce the same result!.
137137
if (std::abs(sumSlowSlow) - std::abs(sumFastFast) > std::numeric_limits<T>::min()) {
138-
std::cerr << "Got wrong distance! Diff = " << std::abs(sumSlowFast) - std::abs(sumFastFast) << "\n";
138+
std::cerr << "Got wrong slowslow-fastfast distance with diff = " << std::abs(sumSlowFast) - std::abs(sumFastFast)
139+
<< "\n";
139140
}
140141
if (std::abs(sumSlowSlow) - std::abs(sumFastSlow) > std::numeric_limits<T>::min()) {
141-
std::cerr << "Got wrong distance! Diff = " << std::abs(sumSlowFast) - std::abs(sumFastSlow) << "\n";
142+
std::cerr << "Got wrong slowslow-fastslow distance with diff = " << std::abs(sumSlowFast) - std::abs(sumFastSlow)
143+
<< "\n";
142144
}
143145

144146
const std::chrono::duration<T, std::micro> slowSlowTime = (t1 - t0);

Examples/Resources/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
This folder contains various surface grids, remarks on where the data was obtained, and what was done with it.
1+
This folder contains various surface grids. The files that are listed below were obtained externally. See provided references.
22

3-
| Model Name | Image | PLY file | Source | Note |
3+
| Model Name | Image | Base file | Source | Note |
44
|------------|-------|---------------|------------|------|
5-
| Adirondack | <img src="img/adirondack.png" width="200"/> | [.stl](adirondack.stl) | [GrabCAD](https://grabcad.com/library/adirondack-park-elevation-model-1) | |
6-
| Airfoil | <img src="img/airfoil.png" width="200"/> | [.stl](airfoil.stl) | [AMReX](http://git@github.com/AMReX-Codes/amrex-tutorials.git) | |
7-
| Armadillo | <img src="img/armadillo.png" width="200"/> | [.stl](armadillo.stl) | [Stanford](http://graphics.stanford.edu/data/3Dscanrep/) | |
8-
| Dodecahedron | <img src="img/dodecahedron.png" width="200"/> | [.stl](dodecahedron.stl) | [John Burkardt](https://people.sc.fsu.edu/~jburkardt/data/ply/ply.html) | |
9-
| Horse | <img src="img/horse.png" width="200"/> | [.stl](horse.stl) | [Alec Jacobson](https://github.com/alecjacobson/common-3d-test-models) | Repaired using MeshLab |
10-
| Orion | <img src="img/orion.png" width="200"/> | [.stl](orion.stl) | [NASA](https://nasa3d.arc.nasa.gov/detail/orion-capsule) | |
11-
| Sphere | <img src="img/sphere.png" width="200"/> | [.stl](sphere.stl) | [John Burkardt](https://people.sc.fsu.edu/~jburkardt/data/ply/ply.html) | |
5+
| Adirondack | <img src="img/adirondack.png" width="200"/> | [.stl](adirondack_binary.stl) | [GrabCAD](https://grabcad.com/library/adirondack-park-elevation-model-1) | |
6+
| Airfoil | <img src="img/airfoil.png" width="200"/> | [.stl](airfoil_binary.stl) | [AMReX](http://git@github.com/AMReX-Codes/amrex-tutorials.git) | |
7+
| Armadillo | <img src="img/armadillo.png" width="200"/> | [.stl](armadillo_binary.stl) | [Stanford](http://graphics.stanford.edu/data/3Dscanrep/) | |
8+
| Dodecahedron | <img src="img/dodecahedron.png" width="200"/> | [.stl](dodecahedron_binary.stl) | [John Burkardt](https://people.sc.fsu.edu/~jburkardt/data/ply/ply.html) | |
9+
| Horse | <img src="img/horse.png" width="200"/> | [.stl](horse_binary.stl) | [Alec Jacobson](https://github.com/alecjacobson/common-3d-test-models) | Repaired using MeshLab |
10+
| Orion | <img src="img/orion.png" width="200"/> | [.stl](orion_binary.stl) | [NASA](https://nasa3d.arc.nasa.gov/detail/orion-capsule) | |
11+
| Sphere | <img src="img/sphere.png" width="200"/> | [.stl](sphere_binary.stl) | [John Burkardt](https://people.sc.fsu.edu/~jburkardt/data/ply/ply.html) | |
12+

0 commit comments

Comments
 (0)