Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rita/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ license = "MIT"
anyhow = { version = "1.0", default-features = false }
geogram_predicates = "0.2.1"
log = { version = "0.4", optional = true }
nalgebra = { version = "0.33", features = ["libm", "macros", "matrixmultiply"], default-features = false }
nalgebra = { version = "0.33", features = [
"libm",
"macros",
"matrixmultiply",
], default-features = false }
rayon = "1.10"
arbitrary = { version = "1.4", optional = true, features = ["derive"] }

[dev-dependencies]
rita_test_utils = { version = "0.1", path = "../rita_test_utils" }
rita_test_utils = { path = "../rita_test_utils" }

[features]
default = ["std"]
Expand Down
1 change: 0 additions & 1 deletion rita/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! - `logging` - uses `log` to record errors and warnings, along with some extra information
//! - `log_timing` - enables logging and timing, to record timing info
#![cfg_attr(not(feature = "std"), no_std)]

#![forbid(unsafe_code)]
#![deny(unused, clippy::incompatible_msrv)]
#![warn(clippy::all, clippy::missing_const_for_fn)]
Expand Down
2 changes: 1 addition & 1 deletion rita/src/tetds/half_tri_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::VertexNode;

use super::{
hedge_iterator::HedgeIterator,
tet_data_structure::{TetDataStructure, TRIANGLE_SUBINDICES},
tet_data_structure::{TRIANGLE_SUBINDICES, TetDataStructure},
tet_iterator::TetIterator,
};

Expand Down
2 changes: 1 addition & 1 deletion rita/src/tetds/hedge_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
half_tri_iterator::HalfTriIterator,
tet_data_structure::{TetDataStructure, NEIGHBOR_HALFEDGE, TRIANGLE_SUBINDICES},
tet_data_structure::{NEIGHBOR_HALFEDGE, TRIANGLE_SUBINDICES, TetDataStructure},
};
use crate::VertexNode;

Expand Down
7 changes: 4 additions & 3 deletions rita/src/tetds/tet_data_structure.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::VertexNode;
use super::{
half_tri_iterator::HalfTriIterator, hedge_iterator::HedgeIterator, tet_iterator::TetIterator,
};
use crate::VertexNode;

use anyhow::{Ok as HowOk, Result as HowResult};
use alloc::{vec, vec::Vec};
use anyhow::{Ok as HowOk, Result as HowResult};

// For each tri idx within a tet, associate list of vertex idx triples, i.e. the face indices
/// For each triangle index within tetrahedron, associate list of vertices within tetrahedron
Expand Down Expand Up @@ -363,7 +363,8 @@ impl TetDataStructure {
if !he_cur.tri().tet().should_del() {
let ind_tri2 = he_cur.tri().idx();
let j2 = he_cur.idx();
let ind_cur2 = if let Some((i2, _)) = vec_tri.iter()
let ind_cur2 = if let Some((i2, _)) = vec_tri
.iter()
.enumerate()
.find(|&(_, &ind)| ind == ind_tri2)
{
Expand Down
2 changes: 1 addition & 1 deletion rita/src/tetds/tet_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{utils::types::TetIteratorIdx, VertexNode};
use super::{half_tri_iterator::HalfTriIterator, tet_data_structure::TetDataStructure};
use crate::{VertexNode, utils::types::TetIteratorIdx};

pub struct TetIterator<'a> {
pub tds: &'a TetDataStructure,
Expand Down
650 changes: 592 additions & 58 deletions rita/src/tetrahedralization.rs

Large diffs are not rendered by default.

94 changes: 73 additions & 21 deletions rita/src/triangulation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use core::panic;
use alloc::{vec, vec::Vec};
use core::cmp;
use alloc::{vec::Vec, vec};
use core::panic;

// TODO: we could allow the epsilon filter on insertion also allow to happen, when the inserted vertex is in a casual triangle, i.e. outside the c-hull
// TODO: we could also incorporate that in the 3->1 flip, as to remove points in a later stage of the algo (not just at insertion)

use crate::{
VertexNode,
trids::{
hedge_iterator::HedgeIterator, tri_data_structure::TriDataStructure,
tri_iterator::TriIterator,
Expand All @@ -15,7 +16,6 @@ use crate::{
point_order::sort_along_hilbert_curve_2d,
types::{Edge2, Triangle2, Vertex2, VertexIdx},
},
VertexNode,
};
use anyhow::{Ok as HowOk, Result as HowResult};
use geogram_predicates as gp;
Expand Down Expand Up @@ -117,23 +117,27 @@ impl Default for Triangulation {
#[macro_export]
macro_rules! triangulation {
($vertices:expr) => {{
let mut triangulation = $crate::Triangulation::new_with_vert_capacity(None, $vertices.len());
let mut triangulation =
$crate::Triangulation::new_with_vert_capacity(None, $vertices.len());
let _ = triangulation.insert_vertices($vertices, None, true);
triangulation
}};
($vertices:expr, epsilon = $epsilon:expr) => {{
let mut triangulation = $crate::Triangulation::new_with_vert_capacity(Some($epsilon), $vertices.len());
let mut triangulation =
$crate::Triangulation::new_with_vert_capacity(Some($epsilon), $vertices.len());
let _ = triangulation.insert_vertices($vertices, None, true);
triangulation
}};
// with weights
($vertices:expr, $weights:expr) => {{
let mut triangulation = $crate::Triangulation::new_with_vert_capacity(None, $vertices.len());
let mut triangulation =
$crate::Triangulation::new_with_vert_capacity(None, $vertices.len());
let _ = triangulation.insert_vertices($vertices, Some($weights), true);
triangulation
}};
($vertices:expr, $weights:expr, epsilon = $epsilon:expr) => {{
let mut triangulation = $crate::Triangulation::new_with_vert_capacity(Some($epsilon), $vertices.len());
let mut triangulation =
$crate::Triangulation::new_with_vert_capacity(Some($epsilon), $vertices.len());
let _ = triangulation.insert_vertices($vertices, Some($weights), true);
triangulation
}};
Expand Down Expand Up @@ -412,7 +416,9 @@ impl Triangulation {
let containing_tri_idx = self.locate_vis_walk(v_idx, near_to)?; // the possibly invalid triangle

#[cfg(feature = "timing")]
{ self.time_walking += now.elapsed().as_micros(); }
{
self.time_walking += now.elapsed().as_micros();
}

// Skip vertices that are not in power circle by epsilon (i.e. above the hyperplane)
// but only if the containing triangle is casual (for now), i.e. the vertex is inside the current convex hull
Expand Down Expand Up @@ -446,7 +452,9 @@ impl Triangulation {
self.last_inserted_triangle = Some(t0.idx);

#[cfg(feature = "timing")]
{ self.time_inserting += now.elapsed().as_micros() };
{
self.time_inserting += now.elapsed().as_micros();
};

// Perform flips and measure time
#[cfg(feature = "timing")]
Expand Down Expand Up @@ -500,7 +508,9 @@ impl Triangulation {
}
}
#[cfg(feature = "timing")]
{ self.time_flipping += now.elapsed().as_micros(); }
{
self.time_flipping += now.elapsed().as_micros();
}
HowOk(())
}

Expand Down Expand Up @@ -1229,7 +1239,9 @@ mod pre_test {
#[cfg(not(feature = "logging"))]
#[test]
fn logging_enabled() {
panic!("\x1b[1;31;7m tests must be run with logging enabled, try `--features logging` \x1b[0m")
panic!(
"\x1b[1;31;7m tests must be run with logging enabled, try `--features logging` \x1b[0m"
)
}
}

Expand Down Expand Up @@ -1460,16 +1472,56 @@ mod tests {
assert_eq!(
triangulation!(vertices).tris(),
vec![
[[-0.4931480236200205, -0.16592024114317144], [-0.3855198542371303, -0.44705493099901394], [0.3504827256051506, -0.19027659995331642]],
[[-0.37122939978339264, 0.3190369464265699], [-0.4931480236200205, -0.16592024114317144], [0.24723377358550735, 0.2100464123915723]],
[[-0.28683831662024745, 0.4111240123491553], [0.24723377358550735, 0.2100464123915723], [0.37042241707160173, 0.18423333136526698]],
[[0.24723377358550735, 0.2100464123915723], [-0.28683831662024745, 0.4111240123491553], [-0.37122939978339264, 0.3190369464265699]],
[[0.3504827256051506, -0.19027659995331642], [0.24723377358550735, 0.2100464123915723], [-0.4931480236200205, -0.16592024114317144]],
[[0.24723377358550735, 0.2100464123915723], [0.36490258549176935, 0.1365021615193457], [0.37042241707160173, 0.18423333136526698]],
[[0.37042241707160173, 0.18423333136526698], [0.36490258549176935, 0.1365021615193457], [0.44217013845102393, -0.055915696282054284]],
[[0.36490258549176935, 0.1365021615193457], [0.24723377358550735, 0.2100464123915723], [0.3504827256051506, -0.19027659995331642]],
[[0.44217013845102393, -0.055915696282054284], [0.36490258549176935, 0.1365021615193457], [0.3504827256051506, -0.19027659995331642]],
[[0.3504827256051506, -0.19027659995331642], [0.4250889854947786, -0.11789966697253218], [0.44217013845102393, -0.055915696282054284]],
[
[-0.4931480236200205, -0.16592024114317144],
[-0.3855198542371303, -0.44705493099901394],
[0.3504827256051506, -0.19027659995331642]
],
[
[-0.37122939978339264, 0.3190369464265699],
[-0.4931480236200205, -0.16592024114317144],
[0.24723377358550735, 0.2100464123915723]
],
[
[-0.28683831662024745, 0.4111240123491553],
[0.24723377358550735, 0.2100464123915723],
[0.37042241707160173, 0.18423333136526698]
],
[
[0.24723377358550735, 0.2100464123915723],
[-0.28683831662024745, 0.4111240123491553],
[-0.37122939978339264, 0.3190369464265699]
],
[
[0.3504827256051506, -0.19027659995331642],
[0.24723377358550735, 0.2100464123915723],
[-0.4931480236200205, -0.16592024114317144]
],
[
[0.24723377358550735, 0.2100464123915723],
[0.36490258549176935, 0.1365021615193457],
[0.37042241707160173, 0.18423333136526698]
],
[
[0.37042241707160173, 0.18423333136526698],
[0.36490258549176935, 0.1365021615193457],
[0.44217013845102393, -0.055915696282054284]
],
[
[0.36490258549176935, 0.1365021615193457],
[0.24723377358550735, 0.2100464123915723],
[0.3504827256051506, -0.19027659995331642]
],
[
[0.44217013845102393, -0.055915696282054284],
[0.36490258549176935, 0.1365021615193457],
[0.3504827256051506, -0.19027659995331642]
],
[
[0.3504827256051506, -0.19027659995331642],
[0.4250889854947786, -0.11789966697253218],
[0.44217013845102393, -0.055915696282054284]
],
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions rita/src/trids/hedge_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use core::cmp::Ordering;
use core::fmt;
#[cfg(feature = "logging")]
use log::error;
use core::cmp::Ordering;

use crate::{utils::types::HedgeIteratorIdx, VertexNode};
use super::{tri_data_structure::TriDataStructure, tri_iterator::TriIterator};
use crate::{VertexNode, utils::types::HedgeIteratorIdx};

/// An iterator over the half-edges of a triangulation data structure.
#[derive(Clone)]
Expand Down
10 changes: 7 additions & 3 deletions rita/src/trids/tri_data_structure.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{utils::types::HedgeIteratorIdx, VertexNode};
use super::{hedge_iterator::HedgeIterator, tri_iterator::TriIterator};
use crate::{VertexNode, utils::types::HedgeIteratorIdx};

use alloc::vec::Vec;
use anyhow::{Ok as HowOk, Result as HowResult};
use geogram_predicates as gp;
use alloc::vec::Vec;

const INACTIVE: usize = usize::MAX;

Expand Down Expand Up @@ -114,7 +114,11 @@ impl TriDataStructure {
}

/// Insert a vertex `d` into an existing triangle `abc`; called the `1 -> 3 flip`, as it deletes the triangle and creates three new ones.
pub fn flip_1_to_3(&mut self, idx_to_remove: usize, v_idx: usize) -> HowResult<[TriIterator; 3]> {
pub fn flip_1_to_3(
&mut self,
idx_to_remove: usize,
v_idx: usize,
) -> HowResult<[TriIterator; 3]> {
if idx_to_remove > self.num_tris() + self.num_deleted_tris {
return Err(anyhow::Error::msg("Triangle index out of bounds!"));
}
Expand Down
2 changes: 1 addition & 1 deletion rita/src/trids/tri_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt;

use crate::{utils::types::TriIteratorIdx, VertexNode};
use super::{hedge_iterator::HedgeIterator, tri_data_structure::TriDataStructure};
use crate::{VertexNode, utils::types::TriIteratorIdx};

pub struct TriIterator<'a> {
pub tds: &'a TriDataStructure,
Expand Down
2 changes: 1 addition & 1 deletion rita/src/utils/convexity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::types::Vertex2;
use geogram_predicates as gp;
use core::cmp;
use geogram_predicates as gp;

/// Checks if ang(v1--v0, v1--v2) is convex, flat, or concave
pub(crate) fn is_convex(v0: Vertex2, v1: Vertex2, v2: Vertex2) -> bool {
Expand Down
7 changes: 6 additions & 1 deletion rita_lab/src/panels/tabs/debug/central_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ pub fn show(
}

fn draw_triangles(plot_ui: &mut PlotUi, triangulation_data: &mut TriangulationData) {
for (i, [a, b, c]) in triangulation_data.triangulation.tris().into_iter().enumerate() {
for (i, [a, b, c]) in triangulation_data
.triangulation
.tris()
.into_iter()
.enumerate()
{
plot_ui.polygon(
// todo use borrowed series
Polygon::new(format!("Triangle {i}"), vec![a, b, c])
Expand Down
7 changes: 5 additions & 2 deletions rita_lab/src/panels/tabs/lab/central_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use egui::{Color32, Context, Stroke};
use egui_plot::{Legend, Plot, PlotResponse, PlotUi, Points, Polygon};
use vertex_clustering::VertexClusterer2;

use crate::types::{PlotSettings, TriangulationData, Vertex2, ORANGE, TRI_GREEN};
use crate::types::{ORANGE, PlotSettings, TRI_GREEN, TriangulationData, Vertex2};

pub fn show(
ctx: &Context,
Expand Down Expand Up @@ -89,7 +89,10 @@ fn vertex_markers<'p>(plot_settings: &mut PlotSettings, vertices: &'p [Vertex2])
}

/// Create the plot markers for the input vertices of the triangulation
fn scaled_vertex_markers<'p>(plot_settings: &mut PlotSettings, vertices: &'p [Vertex2]) -> Points<'p> {
fn scaled_vertex_markers<'p>(
plot_settings: &mut PlotSettings,
vertices: &'p [Vertex2],
) -> Points<'p> {
let plot_points: Vec<[f64; 2]> = vertices.iter().map(|&v| [v[0], v[1]]).collect();

Points::new("Scaled Vertices", plot_points)
Expand Down
2 changes: 1 addition & 1 deletion rita_lab/src/types/file_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::mpsc::{Receiver, Sender, channel};

/// Contains the text of the file and a channel to communicate with the file panel.
pub struct FileHandler {
Expand Down
Loading