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

Breaking: Turn Z component into a generic property #20

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ serde_derive = "1.0"
serde_json = "1.0"
geojson = "0.24"
las = { version = "0.8", features = ["laz"] }
gdal = { version = "0.15" }
# gdal = { version = "0.12.0", features = ["bindgen"] }
# gdal = { version = "0.15", optional = true }
assert_approx_eq = "1.1.0"

[features]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You can read the complete documentation [here](https://docs.rs/startin)
```rust
extern crate startin;
fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
let mut pts = Vec::new();
pts.push([20.0, 30.0, 2.0]);
pts.push([120.0, 33.0, 12.5]);
pts.push([124.0, 222.0, 7.65]);
Expand Down
2 changes: 1 addition & 1 deletion examples/example1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn read_xyz_file() -> Result<Vec<[f64; 3]>, Box<dyn Error>> {
let mut rdr = csv::ReaderBuilder::new()
.delimiter(b' ')
.from_reader(io::stdin());
let mut vpts: Vec<[f64; 3]> = Vec::new();
let mut vpts = Vec::new();
for result in rdr.deserialize() {
let record: CSVPoint = result?;
vpts.push([record.x, record.y, record.z]);
Expand Down
8 changes: 4 additions & 4 deletions examples/example10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ fn main() {
// println!("Duplicates? none.\n");
// }

let _re = dt.insert(&vec, startin::InsertionStrategy::AsIs);
let _re = dt.insert(vec, startin::InsertionStrategy::AsIs);
// let _re = dt.insert(&vec, Some(vec![434366.0, 19722.0, 900289.0, 337914.0]));
println!("{}", dt);
}

fn read_xyz_file() -> Result<Vec<[f64; 3]>, Box<dyn Error>> {
fn read_xyz_file() -> Result<Vec<(f64, f64, f64)>, Box<dyn Error>> {
let mut rdr = csv::ReaderBuilder::new()
.delimiter(b' ')
.from_reader(io::stdin());
let mut vpts: Vec<[f64; 3]> = Vec::new();
let mut vpts = Vec::new();
for result in rdr.deserialize() {
let record: CSVPoint = result?;
if record.z != -9999.0 {
vpts.push([record.x, record.y, record.z]);
vpts.push((record.x, record.y, record.z));
}
}
Ok(vpts)
Expand Down
22 changes: 11 additions & 11 deletions examples/example11.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([1.1, 1.07, 12.5]);
pts.push([11.0, 1.02, 7.65]);
pts.push([11.05, 11.1, 33.0]);
pts.push([1.0, 11.0, 21.0]);
pts.push([9.0, 5.0, 21.0]);
pts.push([12.0, 5.1, 21.0]);
pts.push([8.0, 8.0, 21.0]);
pts.push([12.0, 8.1, 21.0]);
pts.push([4.0, 5.15, 33.0]);
let mut pts = Vec::new();
pts.push((1.1, 1.07, 12.5));
pts.push((11.0, 1.02, 7.65));
pts.push((11.05, 11.1, 33.0));
pts.push((1.0, 11.0, 21.0));
pts.push((9.0, 5.0, 21.0));
pts.push((12.0, 5.1, 21.0));
pts.push((8.0, 8.0, 21.0));
pts.push((12.0, 8.1, 21.0));
pts.push((4.0, 5.15, 33.0));

let mut dt = startin::Triangulation::new();
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);

let mut _re = dt.remove(7);
_re = dt.remove(2);
Expand Down
18 changes: 9 additions & 9 deletions examples/example2.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([20 as f64, 30.0, 0.0]);
pts.push([20 as f64, 30.0, 1.1]);
pts.push([120.0, 33.0, 12.5]);
pts.push([124.0, 222.0, 7.65]);
pts.push([20.0, 133.0, 21.0]);
pts.push([60.0, 60.0, 33.0]);
let mut pts = Vec::new();
pts.push((20 as f64, 30.0, 0.0));
pts.push((20 as f64, 30.0, 1.1));
pts.push((120.0, 33.0, 12.5));
pts.push((124.0, 222.0, 7.65));
pts.push((20.0, 133.0, 21.0));
pts.push((60.0, 60.0, 33.0));

let mut dt = startin::Triangulation::new();
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);

println!("*****");
println!("Number of points in DT: {}", dt.number_of_vertices());
Expand All @@ -20,7 +20,7 @@ fn main() {
for (i, each) in dt.all_vertices().iter().enumerate() {
// skip the first one, the infinite vertex
if i > 0 {
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each[0], each[1], each[2]);
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each.0, each.1, each.2);
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/example4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use rand::prelude::*;

fn main() {
let num_pts = 1000;
let mut pts: Vec<[f64; 3]> = Vec::new();
let mut pts = Vec::new();

let mut rng = rand::thread_rng();
for _i in 0..num_pts {
let x: f64 = rng.gen();
let y: f64 = rng.gen();
pts.push([x * 100.0, y * 100.0, 2.0]);
pts.push((x * 100.0, y * 100.0, 2.0));
}

let mut dt = startin::Triangulation::new();
dt.set_jump_and_walk(false);
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);
println!("{}", dt.printme(false));

//-- delete 5 vertices on convex hull
Expand Down
18 changes: 9 additions & 9 deletions examples/example5.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([0.0, 0.0, 12.5]);
pts.push([1.0, 0.0, 7.65]);
pts.push([1.1, 1.1, 33.0]);
pts.push([0.0, 1.0, 33.0]);
pts.push([0.5, 0.9, 33.0]);
pts.push([0.9, 0.5, 33.0]);
pts.push([0.67, 0.66, 33.0]);
let mut pts = Vec::new();
pts.push((0.0, 0.0, 12.5));
pts.push((1.0, 0.0, 7.65));
pts.push((1.1, 1.1, 33.0));
pts.push((0.0, 1.0, 33.0));
pts.push((0.5, 0.9, 33.0));
pts.push((0.9, 0.5, 33.0));
pts.push((0.67, 0.66, 33.0));
let mut dt = startin::Triangulation::new();
dt.set_jump_and_walk(false);
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);
println!("{}", dt.printme(true));

// let _re = dt.remove(3);
Expand Down
8 changes: 4 additions & 4 deletions examples/example7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ fn main() {
break;
}
let num_pts = 20;
let mut pts: Vec<[f64; 3]> = Vec::new();
let mut pts = Vec::new();

let mut rng = rand::thread_rng();
for _i in 0..num_pts {
let x: f64 = rng.gen();
let y: f64 = rng.gen();
pts.push([x * 100.0, y * 100.0, 2.0]);
pts.push((x * 100.0, y * 100.0, 2.0));
}

let mut dt = startin::Triangulation::new();
dt.set_jump_and_walk(false);
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts.clone(), startin::InsertionStrategy::AsIs);
// println!("{}", dt.printme(false));

loop {
Expand All @@ -28,7 +28,7 @@ fn main() {
let _re = dt.remove(j);
if dt.is_valid() == false {
for p in pts {
println!("{} {} {}", p[0], p[1], p[2]);
println!("{} {} {}", p.0, p.1, p.2);
// s.push_str(&format!("\t{:?}\n", self.stars[i].pt));
}
println!("vertex === {}", j);
Expand Down
30 changes: 15 additions & 15 deletions examples/example9.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([0.0, 0.0, 0.125]);
pts.push([0.0, 0.0, 0.1111]);
pts.push([1.0, 0.0, 0.2222]);
pts.push([1.0, 1.0, 0.3333]);
pts.push([0.0, 1.0, 0.440]);
pts.push([0.5, 0.49, 0.440]);
pts.push([0.45, 0.69, 0.440]);
pts.push([0.65, 0.49, 0.440]);
pts.push([0.75, 0.29, 0.440]);
pts.push([1.5, 1.49, 0.440]);
pts.push([0.6, 0.2, 0.440]);
pts.push([0.45, 0.4, 0.440]);
pts.push([0.1, 0.8, 0.440]);
let mut pts = Vec::new();
pts.push((0.0, 0.0, 0.125));
pts.push((0.0, 0.0, 0.1111));
pts.push((1.0, 0.0, 0.2222));
pts.push((1.0, 1.0, 0.3333));
pts.push((0.0, 1.0, 0.440));
pts.push((0.5, 0.49, 0.440));
pts.push((0.45, 0.69, 0.440));
pts.push((0.65, 0.49, 0.440));
pts.push((0.75, 0.29, 0.440));
pts.push((1.5, 1.49, 0.440));
pts.push((0.6, 0.2, 0.440));
pts.push((0.45, 0.4, 0.440));
pts.push((0.1, 0.8, 0.440));

let mut dt = startin::Triangulation::new();

dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);

// let re = dt.interpolate_nn(2., 1.);
// let re = dt.interpolate_nn(11., 11.);
Expand Down
116 changes: 58 additions & 58 deletions examples/geotiff2tin.rs
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
extern crate gdal;
extern crate startin;
// extern crate gdal;
// extern crate startin;

use gdal::raster::RasterBand;
use gdal::{Dataset, Metadata};
// use gdal::raster::RasterBand;
// use gdal::{Dataset, Metadata};

fn main() {
let path = std::env::args()
.skip(1)
.next()
.expect("Must provide a path to a GeoTIFF file");
let dataset = Dataset::open(path).unwrap();
// let path = std::env::args()
// .skip(1)
// .next()
// .expect("Must provide a path to a GeoTIFF file");
// let dataset = Dataset::open(path).unwrap();

println!("Reading GeoTIFF file: {:?}", dataset.description());
println!("CRS: {:?}", dataset.geo_transform());
let crs = dataset.geo_transform().unwrap();
// println!("Reading GeoTIFF file: {:?}", dataset.description());
// println!("CRS: {:?}", dataset.geo_transform());
// let crs = dataset.geo_transform().unwrap();

let rasterband: RasterBand = dataset.rasterband(1).unwrap();
// let rasterband: RasterBand = dataset.rasterband(1).unwrap();

println!("rasterband offset: {:?}", rasterband.offset());
println!("rasterband x-size: {:?}", rasterband.x_size());
println!("rasterband y-size: {:?}", rasterband.y_size());
println!("no_data: {:?}", rasterband.no_data_value());
// println!("rasterband offset: {:?}", rasterband.offset());
// println!("rasterband x-size: {:?}", rasterband.x_size());
// println!("rasterband y-size: {:?}", rasterband.y_size());
// println!("no_data: {:?}", rasterband.no_data_value());

let mut pts: Vec<[f64; 3]> = Vec::new();
// let mut pts = Vec::new();

let nodatavalue = rasterband.no_data_value().unwrap();
let xsize = rasterband.x_size();
let ysize = rasterband.y_size();
//-- for each line, starting from the top-left
for j in 0..ysize {
if let Ok(rv) =
rasterband.read_as::<f64>((0, j.try_into().unwrap()), (xsize, 1), (xsize, 1), None)
{
for (i, each) in rv.data.iter().enumerate() {
let x = crs[0] + (i as f64 * crs[1]) + crs[1];
let y = crs[3] + (j as f64 * crs[5]) + crs[5];
let z = each;
if *z != nodatavalue {
pts.push([x, y, *z]);
}
}
}
}
// let nodatavalue = rasterband.no_data_value().unwrap();
// let xsize = rasterband.x_size();
// let ysize = rasterband.y_size();
// //-- for each line, starting from the top-left
// for j in 0..ysize {
// if let Ok(rv) =
// rasterband.read_as::<f64>((0, j.try_into().unwrap()), (xsize, 1), (xsize, 1), None)
// {
// for (i, each) in rv.data.iter().enumerate() {
// let x = crs[0] + (i as f64 * crs[1]) + crs[1];
// let y = crs[3] + (j as f64 * crs[5]) + crs[5];
// let z = each;
// if *z != nodatavalue {
// pts.push([x, y, *z]);
// }
// }
// }
// }

let mut dt = startin::Triangulation::new();
// dt.set_jump_and_walk(true);
// let bbox = [
// crs[0],
// crs[3] + (ysize as f64 * crs[5]),
// crs[0] + (xsize as f64 * crs[1]),
// crs[3],
// ];
// dt.insert_with_bbox(&pts, &bbox);
dt.insert(&pts, startin::InsertionStrategy::BBox);
// let mut dt = startin::Triangulation::new();
// // dt.set_jump_and_walk(true);
// // let bbox = [
// // crs[0],
// // crs[3] + (ysize as f64 * crs[5]),
// // crs[0] + (xsize as f64 * crs[1]),
// // crs[3],
// // ];
// // dt.insert_with_bbox(&pts, &bbox);
// dt.insert(&pts, startin::InsertionStrategy::BBox);

println!("Number of points in DT: {}", dt.number_of_vertices());
println!("Number of triangles in DT: {}", dt.number_of_triangles());
println!("bbox: {:?}", dt.get_bbox());
// println!("Number of points in DT: {}", dt.number_of_vertices());
// println!("Number of triangles in DT: {}", dt.number_of_triangles());
// println!("bbox: {:?}", dt.get_bbox());

dt.vertical_exaggeration(2.0);
// let _re = dt.write_geojson("/Users/hugo/temp/g1.geojson".to_string());
let pathout = "/Users/hugo/temp/out.obj";
println!("Writing OBJ file...");
let re = dt.write_obj(pathout.to_string());
match re {
Ok(_x) => println!("--> OBJ output saved to: {}", pathout),
Err(_x) => println!("ERROR: path {} doesn't exist, abort.", pathout),
}
// dt.vertical_exaggeration(2.0);
// // let _re = dt.write_geojson("/Users/hugo/temp/g1.geojson".to_string());
// let pathout = "/Users/hugo/temp/out.obj";
// println!("Writing OBJ file...");
// let re = dt.write_obj(pathout.to_string());
// match re {
// Ok(_x) => println!("--> OBJ output saved to: {}", pathout),
// Err(_x) => println!("ERROR: path {} doesn't exist, abort.", pathout),
// }
}
16 changes: 8 additions & 8 deletions examples/readme_snippet.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([20.0, 30.0, 2.0]);
pts.push([120.0, 33.0, 12.5]);
pts.push([124.0, 222.0, 7.65]);
pts.push([20.0, 133.0, 21.0]);
pts.push([60.0, 60.0, 33.0]);
let mut pts: Vec<(f64, f64, f64)> = Vec::new();
pts.push((20.0, 30.0, 2.0));
pts.push((120.0, 33.0, 12.5));
pts.push((124.0, 222.0, 7.65));
pts.push((20.0, 133.0, 21.0));
pts.push((60.0, 60.0, 33.0));
let mut dt = startin::Triangulation::new();
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);
println!("{}", dt);
//-- print all the vertices
for (i, each) in dt.all_vertices().iter().enumerate() {
// skip the first one, the infinite vertex
if i > 0 {
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each[0], each[1], each[2]);
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each.0, each.1, each.2);
}
}
//-- insert a new vertex
Expand Down
Loading
Loading