Skip to content

Commit 10d50c9

Browse files
authored
Run method exports convex hulls, not parts. (#1)
1 parent 22c30b4 commit 10d50c9

File tree

4 files changed

+12
-29
lines changed

4 files changed

+12
-29
lines changed

examples/main.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use std::{env, path::PathBuf, time::Instant};
33
use miniacd::{
44
Config,
55
io::{self, load_obj},
6-
mesh::Mesh,
7-
ops::{self},
86
};
9-
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
107

118
fn main() {
129
let args: Vec<String> = env::args().collect();
@@ -31,11 +28,5 @@ fn main() {
3128
let tf = Instant::now();
3229
println!("main:\t{:.2}s", (tf - t0).as_secs_f64());
3330

34-
// PARALLEL: compute the output convex hulls in parallel.
35-
let convex_meshes: Vec<Mesh> = components
36-
.par_iter()
37-
.map(|c| ops::convex_hull(&c.mesh))
38-
.collect();
39-
40-
io::write_meshes_to_obj(&output_path, &convex_meshes).unwrap();
31+
io::write_meshes_to_obj(&output_path, &components).unwrap();
4132
}

python/miniacd/cli.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def main(
8888

8989
# Run the miniacd algorithm.
9090
mesh = miniacd.Mesh(input_mesh.vertices, input_mesh.faces)
91-
parts = miniacd.run(
91+
hulls = miniacd.run(
9292
mesh,
9393
threshold=threshold,
9494
mcts_depth=mcts_depth,
@@ -98,24 +98,21 @@ def main(
9898
print=True,
9999
)
100100

101-
# Convexify the output slices.
102-
parts = [part.convex_hull() for part in parts]
103-
104101
# Build Trimesh objects from the miniacd meshes.
105-
output_parts = [
102+
output_hulls = [
106103
trimesh.Trimesh(
107-
part.vertices(), part.faces(), vertex_colors=random_rgb(), process=False
104+
hull.vertices(), hull.faces(), vertex_colors=random_rgb(), process=False
108105
)
109-
for part in parts
106+
for hull in hulls
110107
]
111108

112109
# Output a single file of multiple objects or multiple files.
113110
output_path = Path(output_path)
114111
if output_split:
115-
for i, part in enumerate(output_parts):
116-
part.export(output_path.with_stem(output_path.stem + f"_{i}"))
112+
for i, hull in enumerate(output_hulls):
113+
hull.export(output_path.with_stem(output_path.stem + f"_{i}"))
117114
else:
118-
trimesh.Scene(output_parts).export(output_path)
115+
trimesh.Scene(output_hulls).export(output_path)
119116

120117

121118
if __name__ == "__main__":

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn run_inner(input: Part, config: &Config, progress: &ProgressBar, prev_cost: f6
9999
components
100100
}
101101

102-
pub fn run(input: Mesh, config: &Config) -> Vec<Part> {
102+
pub fn run(input: Mesh, config: &Config) -> Vec<Mesh> {
103103
let progress_bar = ProgressBar::new(1)
104104
.with_message("Slicing parts...")
105105
.with_style(
@@ -127,7 +127,7 @@ pub fn run(input: Mesh, config: &Config) -> Vec<Part> {
127127
// Unapply the transform so the outputs part positions match the input.
128128
output_parts
129129
.into_iter()
130-
.map(|p| Part::from_mesh(Arc::unwrap_or_clone(p.mesh).transform(&normalization_tfm_inv)))
131-
.filter(|p| !p.mesh.is_empty())
130+
.map(|p| Arc::unwrap_or_clone(p.convex_hull).transform(&normalization_tfm_inv))
131+
.filter(|m| !m.is_empty())
132132
.collect()
133133
}

src/py.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[pyo3::pymodule(name = "miniacd")]
22
mod pyminiacd {
3-
use std::sync::Arc;
4-
53
use nalgebra::Point3;
64
use pyo3::prelude::*;
75

@@ -66,9 +64,6 @@ mod pyminiacd {
6664
};
6765

6866
let components = crate::run(mesh.0.clone(), &config);
69-
components
70-
.into_iter()
71-
.map(|c| PyMesh(Arc::unwrap_or_clone(c.mesh)))
72-
.collect()
67+
components.into_iter().map(PyMesh).collect()
7368
}
7469
}

0 commit comments

Comments
 (0)