Skip to main content

engeom/
lib.rs

1extern crate core;
2
3use std::error::Error;
4
5pub mod airfoil2;
6pub mod common;
7pub mod errors;
8pub mod func1;
9pub mod geom2;
10pub mod geom3;
11pub mod io;
12pub mod metrology;
13pub mod raster2;
14pub mod raster3;
15pub mod sensors;
16pub mod stats;
17pub mod utility;
18
19pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
20pub type ResultCode<T> = std::result::Result<T, usize>;
21
22// Re-export some commonly used crates for convenience
23pub use alum;
24pub use colorgrad;
25pub use imageproc;
26pub use imageproc::image;
27pub use levenberg_marquardt;
28pub use parry2d_f64 as parry2d;
29pub use parry3d_f64 as parry3d;
30pub use parry3d_f64::na;
31pub use rayon;
32pub use serde;
33pub use serde_json;
34// Re-exported so a caller can reach `tol_compress::reorder` without taking the dependency and
35// matching versions themselves. Writing a tcmesh renumbers vertices, and that is the module which
36// says how, so anyone holding per-vertex data outside the file needs it.
37pub use tol_compress;
38
39// Common one-dimensional functions
40pub use func1::{Func1, Gaussian1, Line1, Polynomial, Series1};
41
42// Extremely common angle tools
43pub use common::{AngleDir, AngleInterval, IndexMask, IntervalOps};
44
45// Nalgebra exports
46pub type DVector = na::DVector<f64>;
47pub type DMatrix = na::DMatrix<f64>;
48
49// Extremely common 2D types
50pub use geom2::{
51    Arc2, Circle2, Curve2, CurveGroup2, CurveStation2, Iso2, KdTree2, Line2, Point2, SurfacePoint2,
52    SvdBasis2, UnitVec2, Vector2,
53};
54
55// Extremely common 3D types
56pub use geom3::{
57    Aabb3, CloudIndex3, Curve3, CurveGroup3, CurveStation3, FaceAttrSet3, FlatDomain,
58    HalfEdgeMesh3, Iso3, KdTree3, Line3, Manifold1Pos3, Mesh3, MeshData3, MeshView3, PlanarMap,
59    PlanarSection, Plane3, PlaneFrame, Point3, PointAttrSet3, PointCloud3, PointCloudOverlap,
60    Sphere3, SurfacePoint3, SvdBasis3, UnitVec3, VOXEL_COHERENCE_ATTR, VOXEL_COUNT_ATTR, Vector3,
61};
62
63// Extremely common conversion tools
64pub use common::{To2D, To3D};
65
66/// General purpose option for how to handle the result of a dot product between directional
67/// vectors.
68#[derive(Debug, Copy, Clone, PartialEq, Eq)]
69pub enum VecDot {
70    /// Use the dot product as is, allowing it to range from any negative to any positive number
71    AsIs,
72
73    /// Use the absolute value of the dot product
74    Abs,
75
76    /// Clamp the dot product to a positive value. Values below 0 are raised to zero.
77    ClampPos,
78}
79
80/// General purpose option for starting the selection of a set of items, either from everything,
81/// nothing, a specific set of indices, or a bitmask.
82#[derive(Debug, Clone)]
83pub enum Selection {
84    /// Start with no items selected. This is used to indicate that the selection should start with
85    /// nothing selected, and then items can be selected or modified.
86    None,
87
88    /// Select all items in the set. This is used to indicate that the selection should start with
89    /// everything selected, and then items can be deselected or modified.
90    All,
91
92    /// A specific set of indices to select. This is passed as a vector of indices and not as
93    /// a reference to a slice because the selection will need to be able to own and modify
94    /// the indices.
95    Indices(Vec<usize>),
96
97    /// A bitmask which indicates which items are selected. This is passed not as a reference
98    /// because the selection will need to be able to own and modify the mask.
99    Mask(IndexMask),
100}
101
102/// General purpose option for selecting or deselecting items from a set
103#[derive(Debug, Clone, Copy)]
104pub enum SelectOp {
105    /// The items identified by the operation should be added to the existing selection
106    Add,
107
108    /// The items identified by the operation should be removed from the existing selection
109    Remove,
110
111    /// The items identified by the operation should be retained in the selection, while
112    /// the rest of the selection is cleared
113    KeepOnly,
114}
115
116/// General purpose options for resampling data over a discrete domain.
117pub enum Resample {
118    /// Resample by a given number of points, evenly spaced over the domain
119    ByCount(usize),
120
121    /// Resample with a specific spacing between points, understanding that if the spacing does not
122    /// divide evenly into the domain the end points may not be centered in the original domain
123    BySpacing(f64),
124
125    /// Resample with a maximum spacing between points. The number of points will be chosen
126    /// automatically such that the entire domain is covered (as if `BySpacing` was used) but the
127    /// spacing between points will not exceed the given value.
128    ByMaxSpacing(f64),
129}
130
131/// General purpose options for smoothing data over a discrete domain.
132pub enum Smoothing {
133    /// A Gaussian filter with the given standard deviation, where the filter size is truncated to
134    /// 3 standard deviations
135    Gaussian(f64),
136
137    /// A quadratic fit filter with the given window size. A quadratic polynomial is fit to items
138    /// within the window, and the item is replaced with the value of the polynomial at the same
139    /// position
140    Quadratic(f64),
141
142    /// A cubic fit filter with the given window size. A cubic polynomial is fit to items within
143    /// the window, and the item is replaced with the value of the polynomial at the same position
144    Cubic(f64),
145}
146
147#[cfg(test)]
148pub mod tests {
149    use crate::io::{read_tc_curve2_from, read_tc_mesh_from};
150
151    use crate::{Curve2, Mesh3};
152
153    /// Load a mesh with the stanford bunny reconstruction at resolution 4. The vertices are within
154    /// 0.00000189 of the original ply file.
155    pub fn stanford_bun_4() -> Mesh3 {
156        embedded_mesh(include_bytes!("../tests/data/stanford_bun_4.tcmesh"))
157    }
158
159    /// Load a mesh with the stanford bunny reconstruction at resolution 2. The vertices are within
160    /// 0.00000189 of the original ply file.
161    pub fn stanford_bun_2() -> Mesh3 {
162        embedded_mesh(include_bytes!("../tests/data/stanford_bun_2.tcmesh"))
163    }
164
165    /// Load a mesh with the stanford bunny reconstruction at resolution 3. The vertices are within
166    /// 0.00000189 of the original ply file.
167    pub fn stanford_bun_3() -> Mesh3 {
168        embedded_mesh(include_bytes!("../tests/data/stanford_bun_3.tcmesh"))
169    }
170
171    /// Load a mesh of a small engine blade. The mesh has 21795 vertices and 43586 faces. Dimensions
172    /// are in millimeters. The mesh has been processed externally to remove mesh errors and should
173    /// be watertight. Stored at a 1 micron tolerance.
174    pub fn engine_blade() -> Mesh3 {
175        embedded_mesh(include_bytes!("../tests/data/engine-blade.tcmesh"))
176    }
177
178    fn embedded_mesh(bytes: &[u8]) -> Mesh3 {
179        let data = read_tc_mesh_from(&mut { bytes }).unwrap();
180        Mesh3::from_data(data, false).unwrap()
181    }
182
183    pub fn airfoil_curve() -> Curve2 {
184        let bytes = include_bytes!("../tests/data/airfoil-0.tccurve2");
185        let mut working = bytes.as_slice();
186        read_tc_curve2_from(&mut working).unwrap()
187    }
188
189    /// Get the path to the test data directory.
190    pub fn get_test_data_path() -> std::path::PathBuf {
191        let mut path = std::env::current_dir().unwrap();
192        path.push("tests");
193        path.push("data");
194        path
195    }
196
197    /// Get the path to a test file in the test data directory. This does not check if the file
198    /// exists.
199    pub fn get_test_file_path(str: &str) -> std::path::PathBuf {
200        let mut path = get_test_data_path();
201        path.push(str);
202        path
203    }
204}