Correct layer configs

This commit is contained in:
Connor Slade
2024-06-19 15:56:44 -04:00
parent b55f2f8ac1
commit f65f4638c3
5 changed files with 73 additions and 13 deletions

3
Cargo.lock generated
View File

@@ -1095,12 +1095,9 @@ dependencies = [
"anyhow", "anyhow",
"common", "common",
"goo_format", "goo_format",
"image",
"imageproc", "imageproc",
"nalgebra", "nalgebra",
"ordered-float", "ordered-float",
"rand",
"rayon",
"stl_io", "stl_io",
] ]

View File

@@ -111,3 +111,9 @@ impl Serializer for DynamicSerializer {
self.buffer.extend_from_slice(&data.data); self.buffer.extend_from_slice(&data.data);
} }
} }
impl Default for DynamicSerializer {
fn default() -> Self {
Self::new()
}
}

View File

@@ -7,12 +7,9 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.86" anyhow = "1.0.86"
image = "0.25.1"
imageproc = "0.25.0" imageproc = "0.25.0"
nalgebra = "0.32.6" nalgebra = "0.32.6"
ordered-float = "4.2.0" ordered-float = "4.2.0"
rand = "0.8.5"
rayon = "1.10.0"
stl_io = "0.7.0" stl_io = "0.7.0"
common = { path = "../common" } common = { path = "../common" }

View File

@@ -6,11 +6,9 @@ use std::{
use anyhow::Result; use anyhow::Result;
use common::serde::DynamicSerializer; use common::serde::DynamicSerializer;
use goo_format::{File as GooFile, HeaderInfo, LayerContent, LayerEncoder}; use goo_format::{File as GooFile, HeaderInfo, LayerContent, LayerEncoder};
use image::{Rgb, RgbImage};
use mesh::load_mesh; use mesh::load_mesh;
use nalgebra::{Vector2, Vector3}; use nalgebra::{Vector2, Vector3};
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
use rayon::iter::{ParallelBridge, ParallelIterator};
type Pos = Vector3<f32>; type Pos = Vector3<f32>;
@@ -20,6 +18,18 @@ struct SliceConfig {
platform_resolution: Vector2<u32>, platform_resolution: Vector2<u32>,
platform_size: Vector3<f32>, platform_size: Vector3<f32>,
slice_height: f32, slice_height: f32,
exposure_config: ExposureConfig,
first_exposure_config: ExposureConfig,
first_layers: u32,
}
struct ExposureConfig {
exposure_time: f32,
lift_distance: f32,
lift_speed: f32,
retract_distance: f32,
retract_speed: f32,
} }
fn main() -> Result<()> { fn main() -> Result<()> {
@@ -31,6 +41,16 @@ fn main() -> Result<()> {
platform_resolution: Vector2::new(11520, 5121), platform_resolution: Vector2::new(11520, 5121),
platform_size: Vector3::new(218.88, 122.904, 260.0), platform_size: Vector3::new(218.88, 122.904, 260.0),
slice_height: 0.05, slice_height: 0.05,
exposure_config: ExposureConfig {
exposure_time: 3.0,
..Default::default()
},
first_exposure_config: ExposureConfig {
exposure_time: 50.0,
..Default::default()
},
first_layers: 10,
}; };
let mut file = File::open(FILE_PATH)?; let mut file = File::open(FILE_PATH)?;
@@ -64,7 +84,7 @@ fn main() -> Result<()> {
let layers = (max.z / slice_config.slice_height).ceil() as u32; let layers = (max.z / slice_config.slice_height).ceil() as u32;
let layers = (0..layers) let layers = (0..layers)
.par_bridge() // .par_bridge()
.map(|layer| { .map(|layer| {
let height = layer as f32 * slice_config.slice_height; let height = layer as f32 * slice_config.slice_height;
@@ -100,7 +120,8 @@ fn main() -> Result<()> {
intersections.dedup(); intersections.dedup();
for span in intersections.chunks_exact(2) { for span in intersections.chunks_exact(2) {
out.push((span[0] as u64, span[1] as u64)); let y_offset = (slice_config.platform_resolution.x * y) as u64;
out.push((y_offset + span[0] as u64, y_offset + span[1] as u64));
} }
} }
@@ -117,10 +138,22 @@ fn main() -> Result<()> {
} }
let (data, checksum) = encoder.finish(); let (data, checksum) = encoder.finish();
println!("#{layer} Data Size: {}", data.len()); let layer_exposure = if layer < slice_config.first_layers {
&slice_config.first_exposure_config
} else {
&slice_config.exposure_config
};
LayerContent { LayerContent {
data, data,
checksum, checksum,
layer_position_z: slice_config.slice_height * layer as f32,
layer_exposure_time: layer_exposure.exposure_time,
lift_distance: layer_exposure.lift_distance,
lift_speed: layer_exposure.lift_speed,
retract_distance: layer_exposure.retract_distance,
retract_speed: layer_exposure.retract_speed,
..Default::default() ..Default::default()
} }
}) })
@@ -129,6 +162,22 @@ fn main() -> Result<()> {
let goo = GooFile::new( let goo = GooFile::new(
HeaderInfo { HeaderInfo {
layer_count: layers.len() as u32, layer_count: layers.len() as u32,
layer_thickness: slice_config.slice_height,
bottom_layers: slice_config.first_layers,
exposure_time: slice_config.exposure_config.exposure_time,
lift_distance: slice_config.exposure_config.lift_distance,
lift_speed: slice_config.exposure_config.lift_speed,
retract_distance: slice_config.exposure_config.retract_distance,
retract_speed: slice_config.exposure_config.retract_speed,
bottom_exposure_time: slice_config.first_exposure_config.exposure_time,
bottom_lift_distance: slice_config.first_exposure_config.lift_distance,
bottom_lift_speed: slice_config.first_exposure_config.lift_speed,
bottom_retract_distance: slice_config.first_exposure_config.retract_distance,
bottom_retract_speed: slice_config.first_exposure_config.retract_speed,
..Default::default() ..Default::default()
}, },
layers, layers,
@@ -142,3 +191,15 @@ fn main() -> Result<()> {
Ok(()) Ok(())
} }
impl Default for ExposureConfig {
fn default() -> Self {
Self {
exposure_time: 3.0,
lift_distance: 5.0,
lift_speed: 65.0,
retract_distance: 5.0,
retract_speed: 0.0,
}
}
}

View File

@@ -1,7 +1,6 @@
use std::io::{Read, Seek}; use std::io::{Read, Seek};
use anyhow::Result; use anyhow::Result;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use crate::Pos; use crate::Pos;
@@ -44,7 +43,7 @@ impl Mesh {
pub fn intersect_plane(&self, height: f32) -> Vec<Pos> { pub fn intersect_plane(&self, height: f32) -> Vec<Pos> {
self.faces self.faces
.par_iter() .iter()
.flat_map(|face| { .flat_map(|face| {
let v0 = self.transform(&self.vertices[face[0]]); let v0 = self.transform(&self.vertices[face[0]]);
let v1 = self.transform(&self.vertices[face[1]]); let v1 = self.transform(&self.vertices[face[1]]);