[][src]Enum density_mesh_core::generator::DensityMeshGenerator

pub enum DensityMeshGenerator {
    Uninitialized,
    FindingPoints {
        settings: GenerateDensityMeshSettings,
        map: DensityMap,
        tries: usize,
        remaining: Vec<(Coord, Scalar, Scalar, Scalar)>,
        points: Vec<Coord>,
        progress_current: usize,
        progress_limit: usize,
    },
    Triangulate {
        settings: GenerateDensityMeshSettings,
        map: DensityMap,
        points: Vec<Coord>,
        progress_limit: usize,
    },
    Extrude {
        points: Vec<Coord>,
        triangles: Vec<Triangle>,
        size: Scalar,
        progress_limit: usize,
    },
    BakeFinalMesh {
        points: Vec<Coord>,
        triangles: Vec<Triangle>,
        progress_limit: usize,
    },
    Completed {
        mesh: DensityMesh,
        progress_limit: usize,
    },
}

Density mesh generator state object. It allows you to process mesh generation in steps and track progress or cancel generation in the middle of the process.

Variants

Uninitialized
FindingPoints

Fields of FindingPoints

settings: GenerateDensityMeshSettingsmap: DensityMaptries: usizeremaining: Vec<(Coord, Scalar, Scalar, Scalar)>

[(coordinate, value, steepness, local point separation squared)]

points: Vec<Coord>progress_current: usizeprogress_limit: usize
Triangulate

Fields of Triangulate

settings: GenerateDensityMeshSettingsmap: DensityMappoints: Vec<Coord>progress_limit: usize
Extrude

Fields of Extrude

points: Vec<Coord>triangles: Vec<Triangle>size: Scalarprogress_limit: usize
BakeFinalMesh

Fields of BakeFinalMesh

points: Vec<Coord>triangles: Vec<Triangle>progress_limit: usize
Completed

Fields of Completed

mesh: DensityMeshprogress_limit: usize

Implementations

impl DensityMeshGenerator[src]

pub fn new(
    points: Vec<Coord>,
    map: DensityMap,
    settings: GenerateDensityMeshSettings
) -> Self
[src]

Creates new generator instance. Check struct documentation for examples.

Arguments

  • points - List of initial points.
  • map - Density map.
  • settings - Density mesh generation settings.

Returns

New generator instance.

pub fn progress(&self) -> (usize, usize, Scalar)[src]

Get processing progress.

Returns

(current, limit, percentage)

pub fn is_done(&self) -> bool[src]

Check if mesh generation is done.

Returns

True if process is completed.

pub fn get_mesh_or_self(self) -> Result<DensityMesh, Self>[src]

Tries to get inner generated mesh when ready, otherwise gets itself. This function consumes generator!

Returns

Result with mesh (Ok) when completed, or self (Err) when still processing.

Examples

use density_mesh_core::prelude::*;

let map = DensityMap::new(2, 2, 1, vec![1, 2, 3, 1]).unwrap();
let settings = GenerateDensityMeshSettings {
    points_separation: 0.5.into(),
    visibility_threshold: 0.0,
    steepness_threshold: 0.0,
    ..Default::default()
};
let mut generator = DensityMeshGenerator::new(vec![], map, settings);
match generator.get_mesh_or_self() {
    Ok(mesh) => println!("{:#?}", mesh),
    Err(gen) => generator = gen,
}

pub fn process(self) -> Result<Self, GenerateDensityMeshError>[src]

Process mesh generation. This function consumes generator!

Returns

Self if ok or mesh generation error.

Examples

use density_mesh_core::prelude::*;

let map = DensityMap::new(2, 2, 1, vec![1, 2, 3, 1]).unwrap();
let settings = GenerateDensityMeshSettings {
    points_separation: 0.5.into(),
    visibility_threshold: 0.0,
    steepness_threshold: 0.0,
    ..Default::default()
};
let mut generator = DensityMeshGenerator::new(vec![], map, settings);
loop {
    match generator.process().unwrap().get_mesh_or_self() {
        Ok(mesh) => {
            println!("{:#?}", mesh);
            return;
        },
        Err(gen) => generator = gen,
    }
}

pub fn process_wait(self) -> Result<DensityMesh, GenerateDensityMeshError>[src]

Process mesh generation until it returns either mesh or error. This function consumes generator!

Returns

Density mesh or mesh generation error.

Examples

use density_mesh_core::prelude::*;

let map = DensityMap::new(2, 2, 1, vec![1, 2, 3, 1]).unwrap();
let settings = GenerateDensityMeshSettings {
    points_separation: 0.5.into(),
    visibility_threshold: 0.0,
    steepness_threshold: 0.0,
    ..Default::default()
};
assert_eq!(
    DensityMeshGenerator::new(vec![], map, settings).process_wait(),
    Ok(DensityMesh {
        points: vec![
            Coord { x: 0.0, y: 1.0 },
            Coord { x: 0.0, y: 0.0 },
            Coord { x: 1.0, y: 1.0 },
            Coord { x: 1.0, y: 0.0 },
        ],
        triangles: vec![
            Triangle { a: 0, b: 2, c: 1 },
            Triangle { a: 2, b: 3, c: 1 },
        ],
    }),
);

pub fn process_wait_tracked<F>(
    self,
    f: F
) -> Result<DensityMesh, GenerateDensityMeshError> where
    F: FnMut(usize, usize, Scalar), 
[src]

Process mesh generation with callback that gets called on progress update until it returns either mesh or error. This function consumes generator!

Arguments

  • f - Callback with progress arguments: (current, limit, percentage).

Returns

Density mesh or mesh generation error.

Examples

use density_mesh_core::prelude::*;

let map = DensityMap::new(2, 2, 1, vec![1, 2, 3, 1]).unwrap();
let settings = GenerateDensityMeshSettings {
    points_separation: 0.5.into(),
    visibility_threshold: 0.0,
    steepness_threshold: 0.0,
    ..Default::default()
};
assert_eq!(
    DensityMeshGenerator::new(vec![], map, settings)
        .process_wait_tracked(|c, l, p| println!("Progress: {}% ({} / {})", p * 100.0, c, l)),
    Ok(DensityMesh {
        points: vec![
            Coord { x: 0.0, y: 1.0 },
            Coord { x: 0.0, y: 0.0 },
            Coord { x: 1.0, y: 1.0 },
            Coord { x: 1.0, y: 0.0 },
        ],
        triangles: vec![
            Triangle { a: 0, b: 2, c: 1 },
            Triangle { a: 2, b: 3, c: 1 },
        ],
    }),
);

Trait Implementations

impl Clone for DensityMeshGenerator[src]

impl Debug for DensityMeshGenerator[src]

impl Default for DensityMeshGenerator[src]

impl<'de> Deserialize<'de> for DensityMeshGenerator[src]

impl PartialEq<DensityMeshGenerator> for DensityMeshGenerator[src]

impl Serialize for DensityMeshGenerator[src]

impl StructuralPartialEq for DensityMeshGenerator[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.