pub struct Model<F: Face> {
pub faces: Vec<F>,
pub curves: Vec<CurveGroup>,
}Fields§
§faces: Vec<F>§curves: Vec<CurveGroup>Implementations§
Source§impl<F: Face> Model<F>
impl<F: Face> Model<F>
Sourcepub fn new() -> Model<F>
pub fn new() -> Model<F>
Examples found in repository?
examples/bezier.rs (line 17)
6fn load_teapot(
7 division: (usize, usize),
8) -> std::io::Result<Model<SurfacePatch<BezierSurface<Point3>>>> {
9 use std::fs::File;
10 use std::io::{BufRead, BufReader};
11 use std::path::Path;
12 use std::str::FromStr;
13
14 let file = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("assets/teapot.bpt");
15 let reader = BufReader::new(File::open(file)?);
16
17 let mut model = Model::new();
18 let mut points = Vec::new();
19 let mut current_cols = 0;
20
21 for line in reader.lines() {
22 let numbers = line?;
23 let items = numbers.split_whitespace().collect::<Vec<_>>();
24 if items.len() == 1 {
25 model
26 .faces
27 .reserve_exact(usize::from_str(items[0]).unwrap());
28 } else if items.len() == 2 {
29 if points.len() > 0 {
30 let surface = SurfacePatch {
31 surface: BezierSurface::new(Grid::from_vec(points, current_cols)),
32 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
33 parameter_division: division,
34 };
35 model.add_face(surface);
36 }
37 let m = usize::from_str(items[0]).unwrap();
38 let n = usize::from_str(items[1]).unwrap();
39 points = Vec::with_capacity((m + 1) * (n + 1));
40 current_cols = n + 1;
41 } else if items.len() == 3 {
42 let point = Point3::new(
43 Float::from_str(items[0]).unwrap(),
44 Float::from_str(items[1]).unwrap(),
45 Float::from_str(items[2]).unwrap(),
46 );
47 points.push(point);
48 }
49 }
50 // add last surface
51 let surface = SurfacePatch {
52 surface: BezierSurface::new(Grid::from_vec(points, current_cols)),
53 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
54 parameter_division: division,
55 };
56 model.add_face(surface);
57 Ok(model)
58}More examples
examples/bspline.rs (line 18)
6fn load_teapot(
7 degree: (usize, usize),
8 division: (usize, usize),
9) -> std::io::Result<Model<SurfacePatch<BSplineSurface<Point3>>>> {
10 use std::fs::File;
11 use std::io::{BufRead, BufReader};
12 use std::path::Path;
13 use std::str::FromStr;
14
15 let file = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("assets/teapot.bpt");
16 let reader = BufReader::new(File::open(file)?);
17
18 let mut model = Model::new();
19 let mut points = Vec::new();
20 let mut current_cols = 0;
21
22 for line in reader.lines() {
23 let numbers = line?;
24 let items = numbers.split_whitespace().collect::<Vec<_>>();
25 if items.len() == 1 {
26 model
27 .faces
28 .reserve_exact(usize::from_str(items[0]).unwrap());
29 } else if items.len() == 2 {
30 if points.len() > 0 {
31 let surface = SurfacePatch {
32 surface: BSplineSurface::uniform_clamped(
33 Grid::from_vec(points, current_cols),
34 degree,
35 ),
36 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
37 parameter_division: division,
38 };
39 model.add_face(surface);
40 }
41 let m = usize::from_str(items[0]).unwrap();
42 let n = usize::from_str(items[1]).unwrap();
43 points = Vec::with_capacity((m + 1) * (n + 1));
44 current_cols = n + 1;
45 } else if items.len() == 3 {
46 let point = Point3::new(
47 Float::from_str(items[0]).unwrap(),
48 Float::from_str(items[1]).unwrap(),
49 Float::from_str(items[2]).unwrap(),
50 );
51 points.push(point);
52 }
53 }
54 // add last surface
55 let surface = SurfacePatch {
56 surface: BSplineSurface::uniform_clamped(Grid::from_vec(points, current_cols), degree),
57 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
58 parameter_division: division,
59 };
60 model.add_face(surface);
61 Ok(model)
62}Sourcepub fn add_face(&mut self, face: F)
pub fn add_face(&mut self, face: F)
Examples found in repository?
examples/bezier.rs (line 35)
6fn load_teapot(
7 division: (usize, usize),
8) -> std::io::Result<Model<SurfacePatch<BezierSurface<Point3>>>> {
9 use std::fs::File;
10 use std::io::{BufRead, BufReader};
11 use std::path::Path;
12 use std::str::FromStr;
13
14 let file = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("assets/teapot.bpt");
15 let reader = BufReader::new(File::open(file)?);
16
17 let mut model = Model::new();
18 let mut points = Vec::new();
19 let mut current_cols = 0;
20
21 for line in reader.lines() {
22 let numbers = line?;
23 let items = numbers.split_whitespace().collect::<Vec<_>>();
24 if items.len() == 1 {
25 model
26 .faces
27 .reserve_exact(usize::from_str(items[0]).unwrap());
28 } else if items.len() == 2 {
29 if points.len() > 0 {
30 let surface = SurfacePatch {
31 surface: BezierSurface::new(Grid::from_vec(points, current_cols)),
32 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
33 parameter_division: division,
34 };
35 model.add_face(surface);
36 }
37 let m = usize::from_str(items[0]).unwrap();
38 let n = usize::from_str(items[1]).unwrap();
39 points = Vec::with_capacity((m + 1) * (n + 1));
40 current_cols = n + 1;
41 } else if items.len() == 3 {
42 let point = Point3::new(
43 Float::from_str(items[0]).unwrap(),
44 Float::from_str(items[1]).unwrap(),
45 Float::from_str(items[2]).unwrap(),
46 );
47 points.push(point);
48 }
49 }
50 // add last surface
51 let surface = SurfacePatch {
52 surface: BezierSurface::new(Grid::from_vec(points, current_cols)),
53 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
54 parameter_division: division,
55 };
56 model.add_face(surface);
57 Ok(model)
58}More examples
examples/bspline.rs (line 39)
6fn load_teapot(
7 degree: (usize, usize),
8 division: (usize, usize),
9) -> std::io::Result<Model<SurfacePatch<BSplineSurface<Point3>>>> {
10 use std::fs::File;
11 use std::io::{BufRead, BufReader};
12 use std::path::Path;
13 use std::str::FromStr;
14
15 let file = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("assets/teapot.bpt");
16 let reader = BufReader::new(File::open(file)?);
17
18 let mut model = Model::new();
19 let mut points = Vec::new();
20 let mut current_cols = 0;
21
22 for line in reader.lines() {
23 let numbers = line?;
24 let items = numbers.split_whitespace().collect::<Vec<_>>();
25 if items.len() == 1 {
26 model
27 .faces
28 .reserve_exact(usize::from_str(items[0]).unwrap());
29 } else if items.len() == 2 {
30 if points.len() > 0 {
31 let surface = SurfacePatch {
32 surface: BSplineSurface::uniform_clamped(
33 Grid::from_vec(points, current_cols),
34 degree,
35 ),
36 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
37 parameter_division: division,
38 };
39 model.add_face(surface);
40 }
41 let m = usize::from_str(items[0]).unwrap();
42 let n = usize::from_str(items[1]).unwrap();
43 points = Vec::with_capacity((m + 1) * (n + 1));
44 current_cols = n + 1;
45 } else if items.len() == 3 {
46 let point = Point3::new(
47 Float::from_str(items[0]).unwrap(),
48 Float::from_str(items[1]).unwrap(),
49 Float::from_str(items[2]).unwrap(),
50 );
51 points.push(point);
52 }
53 }
54 // add last surface
55 let surface = SurfacePatch {
56 surface: BSplineSurface::uniform_clamped(Grid::from_vec(points, current_cols), degree),
57 parameter_range: ((0.0, 1.0), (0.0, 1.0)),
58 parameter_division: division,
59 };
60 model.add_face(surface);
61 Ok(model)
62}pub fn add_curve(&mut self, curve: CurveGroup)
Sourcepub fn save_as_stl<P: AsRef<Path>>(&self, filename: P) -> Result<()>
pub fn save_as_stl<P: AsRef<Path>>(&self, filename: P) -> Result<()>
Examples found in repository?
More examples
Sourcepub fn save_as_obj<P: AsRef<Path>>(&self, filename: P) -> Result<()>
pub fn save_as_obj<P: AsRef<Path>>(&self, filename: P) -> Result<()>
Examples found in repository?
More examples
examples/nurbs.rs (line 8)
3fn main() {
4 let file = std::env::args().nth(1).expect("stp file name");
5 let file = std::path::Path::new(&file);
6 let model = StepReader::read_model(&file).unwrap();
7 if model.faces.len() > 0 {
8 model.save_as_obj(file.with_extension("obj")).unwrap();
9 }
10 if model.curves.len() > 0 {
11 model
12 .save_as_svg(file.with_extension("svg"), (350.0, 245.0))
13 .unwrap();
14 }
15}Sourcepub fn save_as_svg<P: AsRef<Path>>(
&self,
filename: P,
(width, height): (f64, f64),
) -> Result<()>
pub fn save_as_svg<P: AsRef<Path>>( &self, filename: P, (width, height): (f64, f64), ) -> Result<()>
Examples found in repository?
examples/nurbs.rs (line 12)
3fn main() {
4 let file = std::env::args().nth(1).expect("stp file name");
5 let file = std::path::Path::new(&file);
6 let model = StepReader::read_model(&file).unwrap();
7 if model.faces.len() > 0 {
8 model.save_as_obj(file.with_extension("obj")).unwrap();
9 }
10 if model.curves.len() > 0 {
11 model
12 .save_as_svg(file.with_extension("svg"), (350.0, 245.0))
13 .unwrap();
14 }
15}Auto Trait Implementations§
impl<F> Freeze for Model<F>
impl<F> !RefUnwindSafe for Model<F>
impl<F> !Send for Model<F>
impl<F> !Sync for Model<F>
impl<F> Unpin for Model<F>where
F: Unpin,
impl<F> !UnwindSafe for Model<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.