Model

Struct Model 

Source
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>

Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

pub fn add_curve(&mut self, curve: CurveGroup)

Source

pub fn save_as_stl<P: AsRef<Path>>(&self, filename: P) -> Result<()>

Examples found in repository?
examples/bezier.rs (line 62)
60fn main() {
61    let teapot = load_teapot((16, 16)).unwrap();
62    teapot.save_as_stl("teapot.stl").unwrap();
63    teapot.save_as_obj("teapot.obj").unwrap();
64}
More examples
Hide additional examples
examples/bspline.rs (line 66)
64fn main() {
65    let teapot = load_teapot((2, 2), (16, 16)).unwrap();
66    teapot.save_as_stl("teapot.stl").unwrap();
67    let teapot = load_teapot((3, 1), (16, 16)).unwrap();
68    teapot.save_as_obj("teapot.obj").unwrap();
69}
Source

pub fn save_as_obj<P: AsRef<Path>>(&self, filename: P) -> Result<()>

Examples found in repository?
examples/bezier.rs (line 63)
60fn main() {
61    let teapot = load_teapot((16, 16)).unwrap();
62    teapot.save_as_stl("teapot.stl").unwrap();
63    teapot.save_as_obj("teapot.obj").unwrap();
64}
More examples
Hide additional examples
examples/bspline.rs (line 68)
64fn main() {
65    let teapot = load_teapot((2, 2), (16, 16)).unwrap();
66    teapot.save_as_stl("teapot.stl").unwrap();
67    let teapot = load_teapot((3, 1), (16, 16)).unwrap();
68    teapot.save_as_obj("teapot.obj").unwrap();
69}
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}
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.