Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!(core): delete the io feature from the core crate #255

Merged
merged 3 commits into from
Dec 12, 2024
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
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ publish = false
autoexamples = false

[dev-dependencies]
honeycomb-core = { workspace = true, features = ["io"] }
honeycomb-core = { workspace = true }
honeycomb-render = { workspace = true }
honeycomb-kernels = { workspace = true }
rand = { workspace = true, features = ["small_rng"] }
Expand Down
5 changes: 2 additions & 3 deletions honeycomb-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ keywords.workspace = true
authors.workspace = true
publish = true

[features]
io = ["dep:vtkio"]
# [features]

# deps

Expand All @@ -24,7 +23,7 @@ loom.workspace= true
num-traits.workspace = true
stm.workspace = true
thiserror.workspace = true
vtkio = { workspace = true, optional = true }
vtkio.workspace = true

[build-dependencies]
rustversion.workspace = true
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
//! Input/Output features implementation
//!
//! The support for I/O is currently very restricted since this is not the focus of this project.
//! Maps can be built from and serialized to VTK legacy files (both binary and ASCII). The
//! `DATASET` of the VTK file should be `UNSTRUCTURED_GRID`, and only a given set of `CELL_TYPES`
//! are supported, because of orientation and dimension restriction.

// ------ IMPORTS
use crate::prelude::{BuilderError, CMap2, CMapBuilder, DartIdType, Vertex2, VertexIdType};
use crate::{attributes::AttrStorageManager, geometry::CoordsFloat};
use num_traits::Zero;

use std::collections::BTreeMap;

use num_traits::Zero;
use vtkio::model::{CellType, DataSet, VertexNumbers};
use vtkio::{IOBuffer, Vtk};

// ------ CONTENT
// --- descriptor impls

impl<T: CoordsFloat> CMapBuilder<T> {
/// Import and set the VTK file that will be used when building the map.
Expand All @@ -32,14 +26,6 @@ impl<T: CoordsFloat> CMapBuilder<T> {

/// Create a [`CMapBuilder`] from an imported VTK file.
///
/// This implementation is roughly equivalent to the following:
///
/// ```rust,no_run
/// # use honeycomb_core::prelude::CMapBuilder;
/// // `CMapBuilder::from_vtk_file("some/path/to/file.vtk")`, or:
/// let builder = CMapBuilder::<f64>::default().vtk_file("some/path/to/file.vtk");
/// ```
///
/// # Panics
///
/// This function may panic if the file cannot be loaded.
Expand All @@ -54,6 +40,8 @@ impl<T: CoordsFloat, P: AsRef<std::path::Path> + std::fmt::Debug> From<P> for CM
}
}

// --- building routine

macro_rules! if_predicate_return_err {
($pr: expr, $er: expr) => {
if $pr {
Expand Down Expand Up @@ -315,7 +303,3 @@ pub fn build_2d_from_vtk<T: CoordsFloat>(
}
Ok(cmap)
}

// ------ TESTS
#[cfg(test)]
mod tests;
93 changes: 0 additions & 93 deletions honeycomb-core/src/cmap/builder/io/tests.rs

This file was deleted.

4 changes: 1 addition & 3 deletions honeycomb-core/src/cmap/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
// ------ MODULE DECLARATIONS

pub mod grid;
pub mod structure;

#[cfg(feature = "io")]
pub mod io;
pub mod structure;

// ------ RE-EXPORTS

Expand Down
3 changes: 0 additions & 3 deletions honeycomb-core/src/cmap/builder/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::prelude::{AttributeBind, CMap2, GridDescriptor};
use crate::{attributes::AttrStorageManager, geometry::CoordsFloat};

use thiserror::Error;
#[cfg(feature = "io")]
use vtkio::Vtk;

// ------ CONTENT
Expand Down Expand Up @@ -53,7 +52,6 @@ pub struct CMapBuilder<T>
where
T: CoordsFloat,
{
#[cfg(feature = "io")]
pub(super) vtk_file: Option<Vtk>,
pub(super) grid_descriptor: Option<GridDescriptor<T>>,
pub(super) attributes: AttrStorageManager,
Expand Down Expand Up @@ -177,7 +175,6 @@ impl<T: CoordsFloat> CMapBuilder<T> {
///
/// See [`CMapBuilder`] example.
pub fn build(self) -> Result<CMap2<T>, BuilderError> {
#[cfg(feature = "io")]
if let Some(vfile) = self.vtk_file {
// build from vtk
// this routine should return a Result instead of the map directly
Expand Down
94 changes: 93 additions & 1 deletion honeycomb-core/src/cmap/builder/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::prelude::{CMap2, CMapBuilder, GridDescriptor};
use crate::attributes::AttrStorageManager;
use crate::prelude::{CMap2, CMapBuilder, DartIdType, GridDescriptor, Orbit2, OrbitPolicy};

use vtkio::Vtk;

// --- basic

Expand Down Expand Up @@ -357,3 +360,92 @@ fn splitsquare_cmap2_correctness() {
assert_eq!(cmap.beta::<2>(23), 0);
assert_eq!(cmap.beta::<2>(24), 0);
}

// --- IO

#[test]
fn io_read() {
let vtk = Vtk::parse_legacy_be(VTK_ASCII).unwrap();
// unwrap is fine since we know the VTK_ASCII const is correct
let cmap: CMap2<f32> =
super::io::build_2d_from_vtk(vtk, AttrStorageManager::default()).unwrap();

// check result
let faces: Vec<_> = cmap.iter_faces().collect();
assert_eq!(faces.len(), 4);
assert_eq!(cmap.iter_edges().count(), 12);
assert_eq!(cmap.iter_vertices().count(), 9);

let mut n_vertices_per_face: Vec<usize> = faces
.iter()
.map(|id| Orbit2::new(&cmap, OrbitPolicy::Face, *id as DartIdType).count())
.collect();
let (mut three_count, mut four_count, mut six_count): (usize, usize, usize) = (0, 0, 0);
while let Some(n) = n_vertices_per_face.pop() {
match n {
3 => three_count += 1,
4 => four_count += 1,
6 => six_count += 1,
_ => panic!("cmap was built incorrectly"),
}
}
assert_eq!(three_count, 2);
assert_eq!(four_count, 1);
assert_eq!(six_count, 1);
}

#[cfg(test)]
const VTK_ASCII: &[u8] = b"
# vtk DataFile Version 2.0
cmap
ASCII

DATASET UNSTRUCTURED_GRID
POINTS 9 float
0 0 0 1 0 0 1 1 0
0 1 0 2 0 0 2 1 0
2 2 0 1 3 0 0 2 0

CELLS 17 54
1 0
1 4
1 6
1 7
1 8
2 0 1
2 3 0
2 1 4
2 4 5
2 5 6
2 6 7
2 7 8
2 8 3
4 0 1 2 3
3 1 4 5
3 1 5 2
6 3 2 5 6 7 8

CELL_TYPES 17
1
1
1
1
1
3
3
3
3
3
3
3
3
9
5
5
7


POINT_DATA 9

CELL_DATA 17
";
4 changes: 1 addition & 3 deletions honeycomb-core/src/cmap/dim2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ pub mod basic_ops;
pub mod embed;
pub mod links;
pub mod orbits;
pub mod serialize;
pub mod sews;
pub mod structure;
pub mod utils;

#[cfg(feature = "io")]
pub mod io;

// ------ CONTENT

/// Number of beta functions defined for [`CMap2`].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//! Input/Output features implementation
//!
//! The support for I/O is currently very restricted since this is not the focus of this project.
//! Maps can be built from and serialized to VTK legacy files (both binary and ASCII). The
//! `DATASET` of the VTK file should be `UNSTRUCTURED_GRID`, and only a given set of `CELL_TYPES`
//! are supported, because of orientation and dimension restriction.

// ------ IMPORTS

use crate::cmap::{EdgeIdType, FaceIdType};
use crate::geometry::CoordsFloat;
use crate::prelude::{CMap2, DartIdType, Orbit2, OrbitPolicy, VertexIdType, NULL_DART_ID};
Expand All @@ -20,9 +11,9 @@ use vtkio::{
IOBuffer,
};

// ------ CONTENT
// --- VTK

/// **Serializing methods**
/// **Serialization methods**
impl<T: CoordsFloat + 'static> CMap2<T> {
/// Generate a legacy VTK file from the map.
///
Expand Down Expand Up @@ -77,9 +68,7 @@ impl<T: CoordsFloat + 'static> CMap2<T> {
}
}

// --- internals

/// Internal building routine for [`CMap2::to_vtk_file`].
/// Internal building routine for VTK serialization.
fn build_unstructured_piece<T>(map: &CMap2<T>) -> UnstructuredGridPiece
where
T: CoordsFloat + 'static,
Expand Down
2 changes: 1 addition & 1 deletion honeycomb-kernels/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors.workspace = true
publish = true

[dependencies]
honeycomb-core = { workspace = true, features = ["io"] }
honeycomb-core.workspace = true
num-traits.workspace = true
rayon = "1.10.0"
thiserror.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion honeycomb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ kernels = ["dep:honeycomb-kernels"]
render = ["dep:honeycomb-render"]

[dependencies]
honeycomb-core = { workspace = true, features = ["io"] }
honeycomb-core = { workspace = true }
honeycomb-kernels = { workspace = true, optional = true }
honeycomb-render = { workspace = true, optional = true }
Loading