From dbffd5351e06d3957b79f072192db9cec26cf759 Mon Sep 17 00:00:00 2001 From: 3dpass <3dpass@example.com> Date: Wed, 30 Sep 2020 09:32:02 +0300 Subject: [PATCH] Draft implementaion of 3Dpass --- Cargo.lock | 740 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 13 + README.md | 12 +- p3d/Cargo.lock | 601 +++++++++++++++++++++++++++++++++++ p3d/Cargo.toml | 18 ++ p3d/src/algo_grid.rs | 284 +++++++++++++++++ p3d/src/contour.rs | 104 ++++++ p3d/src/lib.rs | 235 ++++++++++++++ p3d/src/polyline.rs | 292 +++++++++++++++++ src/main.rs | 55 ++++ 10 files changed, 2353 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 p3d/Cargo.lock create mode 100644 p3d/Cargo.toml create mode 100644 p3d/src/algo_grid.rs create mode 100644 p3d/src/contour.rs create mode 100644 p3d/src/lib.rs create mode 100644 p3d/src/polyline.rs create mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..5d4d378 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,740 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "approx" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitvec" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" +dependencies = [ + "either", + "radium", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cgmath" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c" +dependencies = [ + "approx", + "num-traits 0.1.43", + "rand 0.4.6", +] + +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + +[[package]] +name = "getrandom" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.112" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" + +[[package]] +name = "libm" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" + +[[package]] +name = "matrixmultiply" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916806ba0031cd542105d916a97c8572e1fa6dd79c9c51e7eb43a09ec2dd84c1" +dependencies = [ + "rawpointer", +] + +[[package]] +name = "matrixmultiply" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" +dependencies = [ + "num_cpus", + "once_cell", + "rawpointer", + "thread-tree", +] + +[[package]] +name = "ndarray" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac06db03ec2f46ee0ecdca1a1c34a99c0d188a0d83439b84bf0cb4b386e4ab09" +dependencies = [ + "matrixmultiply 0.2.4", + "num-complex", + "num-integer", + "num-traits 0.2.14", + "rawpointer", +] + +[[package]] +name = "num" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits 0.2.14", +] + +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.14", +] + +[[package]] +name = "num-complex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +dependencies = [ + "autocfg", + "num-traits 0.2.14", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits 0.2.14", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.14", +] + +[[package]] +name = "num-rational" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits 0.2.14", +] + +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.14", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "obj-rs" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "296defd880abbe9e7707c9950375a99432faf97be9f7560d8e555e763040d7e2" +dependencies = [ + "num-traits 0.2.14", + "serde", + "vec_map", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "order-stat" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efa535d5117d3661134dbf1719b6f0ffe06f2375843b13935db186cd094105eb" + +[[package]] +name = "p3d" +version = "0.1.0" +dependencies = [ + "cgmath", + "ndarray", + "obj-rs", + "peroxide", + "rust-3d", + "rust-crypto", + "tri-mesh", +] + +[[package]] +name = "pass3d" +version = "0.1.0" +dependencies = [ + "p3d", + "structopt", +] + +[[package]] +name = "peroxide" +version = "0.30.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acb182c4e420fa22bc0a6a9eecb4162c744d8262b7ce238a424aff7fd301735c" +dependencies = [ + "matrixmultiply 0.3.2", + "order-stat", + "peroxide-ad", + "puruspe", + "rand 0.8.4", + "rand_distr", +] + +[[package]] +name = "peroxide-ad" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6fba8ff3f40b67996f7c745f699babaa3e57ef5c8178ec999daf7eedc51dc8c" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "puruspe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b7e158a385023d209d6d5f2585c4b468f6dcb3dd5aca9b75c4f1678c05bb375" + +[[package]] +name = "quote" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" + +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +dependencies = [ + "libc", + "rand 0.4.6", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core 0.6.3", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_distr" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "964d548f8e7d12e102ef183a0de7e98180c9f8729f555897a857b96e48122d2f" +dependencies = [ + "num-traits 0.2.14", + "rand 0.8.4", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core 0.6.3", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rust-3d" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce1e81ec1eec57188d13fdeb9fcdf961914eb0f57e3b40c723be3b9245de9bb" +dependencies = [ + "bitvec", + "fnv", + "num", +] + +[[package]] +name = "rust-crypto" +version = "0.2.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" +dependencies = [ + "gcc", + "libc", + "rand 0.3.23", + "rustc-serialize", + "time", +] + +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" + +[[package]] +name = "serde" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thread-tree" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbd370cb847953a25954d9f63e14824a36113f8c72eecf6eccef5dc4b45d630" +dependencies = [ + "crossbeam-channel", +] + +[[package]] +name = "time" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "tri-mesh" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec6e05d7489133f9255b20c5d5b132e766ac8c4c6837bc27e8b4de39006e8a5" +dependencies = [ + "bincode", + "cgmath", + "serde", + "wavefront_obj", +] + +[[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wavefront_obj" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33c9cbb65c5aac6493000cdabe11f49588d19b547ccd7501f44fc96a6b9406ff" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..702122b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "pass3d" +version = "0.1.0" +authors = ["3Dpass"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +structopt = "0.3.13" + +[dependencies.p3d] +path = "p3d" \ No newline at end of file diff --git a/README.md b/README.md index fd60c46..870b471 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ -# pass3d \ No newline at end of file +# pass3d + +CLI tools to calculate hashes from 3d object + +## Example: + +cargo run -- --algo grid2d --grid 6 --sect 4 --infile data/st1.obj + +## Licence + +This project is licensed under the MIT License \ No newline at end of file diff --git a/p3d/Cargo.lock b/p3d/Cargo.lock new file mode 100644 index 0000000..952a5ca --- /dev/null +++ b/p3d/Cargo.lock @@ -0,0 +1,601 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "approx" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" +dependencies = [ + "either", + "radium", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cgmath" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c" +dependencies = [ + "approx", + "num-traits 0.1.43", + "rand 0.4.6", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + +[[package]] +name = "getrandom" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.112" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" + +[[package]] +name = "libm" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" + +[[package]] +name = "matrixmultiply" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916806ba0031cd542105d916a97c8572e1fa6dd79c9c51e7eb43a09ec2dd84c1" +dependencies = [ + "rawpointer", +] + +[[package]] +name = "matrixmultiply" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" +dependencies = [ + "num_cpus", + "once_cell", + "rawpointer", + "thread-tree", +] + +[[package]] +name = "ndarray" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac06db03ec2f46ee0ecdca1a1c34a99c0d188a0d83439b84bf0cb4b386e4ab09" +dependencies = [ + "matrixmultiply 0.2.4", + "num-complex", + "num-integer", + "num-traits 0.2.14", + "rawpointer", +] + +[[package]] +name = "num" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits 0.2.14", +] + +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.14", +] + +[[package]] +name = "num-complex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +dependencies = [ + "autocfg", + "num-traits 0.2.14", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits 0.2.14", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.14", +] + +[[package]] +name = "num-rational" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits 0.2.14", +] + +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.14", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "obj-rs" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "296defd880abbe9e7707c9950375a99432faf97be9f7560d8e555e763040d7e2" +dependencies = [ + "num-traits 0.2.14", + "serde", + "vec_map", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "order-stat" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efa535d5117d3661134dbf1719b6f0ffe06f2375843b13935db186cd094105eb" + +[[package]] +name = "p3d" +version = "0.1.0" +dependencies = [ + "cgmath", + "ndarray", + "obj-rs", + "peroxide", + "rust-3d", + "rust-crypto", + "tri-mesh", +] + +[[package]] +name = "peroxide" +version = "0.30.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acb182c4e420fa22bc0a6a9eecb4162c744d8262b7ce238a424aff7fd301735c" +dependencies = [ + "matrixmultiply 0.3.2", + "order-stat", + "peroxide-ad", + "puruspe", + "rand 0.8.4", + "rand_distr", +] + +[[package]] +name = "peroxide-ad" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6fba8ff3f40b67996f7c745f699babaa3e57ef5c8178ec999daf7eedc51dc8c" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "puruspe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b7e158a385023d209d6d5f2585c4b468f6dcb3dd5aca9b75c4f1678c05bb375" + +[[package]] +name = "quote" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" + +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +dependencies = [ + "libc", + "rand 0.4.6", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core 0.6.3", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_distr" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "964d548f8e7d12e102ef183a0de7e98180c9f8729f555897a857b96e48122d2f" +dependencies = [ + "num-traits 0.2.14", + "rand 0.8.4", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core 0.6.3", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rust-3d" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce1e81ec1eec57188d13fdeb9fcdf961914eb0f57e3b40c723be3b9245de9bb" +dependencies = [ + "bitvec", + "fnv", + "num", +] + +[[package]] +name = "rust-crypto" +version = "0.2.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" +dependencies = [ + "gcc", + "libc", + "rand 0.3.23", + "rustc-serialize", + "time", +] + +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" + +[[package]] +name = "serde" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thread-tree" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbd370cb847953a25954d9f63e14824a36113f8c72eecf6eccef5dc4b45d630" +dependencies = [ + "crossbeam-channel", +] + +[[package]] +name = "time" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "tri-mesh" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec6e05d7489133f9255b20c5d5b132e766ac8c4c6837bc27e8b4de39006e8a5" +dependencies = [ + "bincode", + "cgmath", + "serde", + "wavefront_obj", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wavefront_obj" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33c9cbb65c5aac6493000cdabe11f49588d19b547ccd7501f44fc96a6b9406ff" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/p3d/Cargo.toml b/p3d/Cargo.toml new file mode 100644 index 0000000..966c5b5 --- /dev/null +++ b/p3d/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "p3d" +version = "0.1.0" +authors = ["3Dpass"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +cgmath = "0.16.1" +tri-mesh = "0.5.0" +rust-3d = "0.34.0" +obj-rs = "0.6" +rust-crypto = "0.2" + +ndarray = { version = "0.13" } +peroxide = { version = "0.30" } diff --git a/p3d/src/algo_grid.rs b/p3d/src/algo_grid.rs new file mode 100644 index 0000000..e7db3bf --- /dev/null +++ b/p3d/src/algo_grid.rs @@ -0,0 +1,284 @@ +use crypto::digest::Digest; +use crypto::sha2::Sha256; + +use std::ops::SubAssign; + +use peroxide::numerical::eigen::EigenMethod; +use peroxide::fuga::*; + +use ndarray::{Array1, Array2, Array3, Axis, ArrayView2, ArrayView1, ArrayBase}; +use ndarray::arr1; + +use tri_mesh::prelude::*; + +use crate::polyline::PolyLine; +use crate::polyline::GenPolyLines; + +type VctrTriangles = Array3; +//type Triangle = Array3; +// [[x0, y0, z0],[x1, y1, z1],[x3, y3, z3]] +// [[x0, y0, z0],[x1, y1, z1],[x3, y3, z3]] +// [[x0, y0, z0],[x1, y1, z1],[x3, y3, z3]] +type Vec2 = Point2; + + +pub(crate) fn find_top_std(depth: usize, grid_size: i16, cntrs: &Vec>) -> Vec { + let ss = GenPolyLines::select_top(cntrs, grid_size, depth); //, calc_sco); + let mut res: Vec = vec![]; + let mut hashes = vec![]; + + for a in ss[0..depth].iter() { + res.push(a.1.clone()); + + let mut hasher = Sha256::new(); + let b = a.1.nodes.as_slice().iter() + .flat_map(|&p| [p.x.to_be_bytes(), p.y.to_be_bytes()].concat()) + .collect::>(); + + hasher.input(b.as_slice()); + hashes.push(hasher.result_str()); + } + hashes +} + +fn cross(triangles: &VctrTriangles) -> Array2 { + let dims = triangles.dim(); + let mut d = Array3::zeros((dims.0, 2, dims.1)); + + for (i, m) in triangles.axis_iter(Axis(0)).enumerate() { + for (j, p) in m.axis_iter(Axis(1)).enumerate() { + d[[i, 0, j]] = p[1] - p[0]; + d[[i, 1, j]] = p[2] - p[1]; + } + } + + let mut cr = Array2::zeros((dims.0, dims.1)); + + for (i, m) in d.axis_iter(Axis(0)).enumerate() { + let a: ArrayView1 = m.slice(s![0, ..]); + let b: ArrayView1 = m.slice(s![1, ..]); + cr[[i, 0]] = a[1]*b[2] - a[2]*b[1]; + cr[[i, 1]] = a[2]*b[0] - a[0]*b[2]; + cr[[i, 2]] = a[0]*b[1] - a[1]*b[0]; + } + + cr +} + + +pub fn mass_properties(triangles: VctrTriangles) -> (Array1, Array2) { + let p0: ArrayView2 = triangles.slice(s![0.., 0, 0..]); + let p1: ArrayView2 = triangles.slice(s![0.., 1, 0..]); + let p2: ArrayView2 = triangles.slice(s![0.., 2, 0..]); + + let f1 = &p0 + &p1 + &p2; + let f2 = &p0 * &p0 + &p1 * &p1 + &p0 * &p1 + &p1 * &f1; + let f3 = &p0 * &p0 * &p0 + &p0 * &p0 * &p1 + &p0 * &p1 * &p1 + &p1 * &p1 * &p1 + &p2 * &f2; + + let g0 = &(&f2 + &(&(&p0 + &f1) * &p0)); + let g1 = &(&f2 + &(&(&p1 + &f1) * &p1)); + let g2 = &(&f2 + &(&(&p2 + &f1) * &p2)); + + let d = f1.nrows(); + let mut integral: Array2 = Array2::zeros((10, d)); + + let crosses = cross(&triangles); + + integral.slice_mut(s![0..1, ..]).assign(&(&crosses.slice(s![.., 0]) * &f1.slice(s![.., 0]))); + integral.slice_mut(s![1..4, ..]).assign(&(&crosses * &f2).t().slice(s![.., ..])); + integral.slice_mut(s![4..7, ..]).assign(&(&crosses * &f3).t().slice(s![.., ..])); + + for i in 0..3 { + let triangle_i = (i + 1) % 3; + integral.slice_mut(s![i+7, ..]).assign( + &(&crosses.slice(s![.., i]) * &( + &triangles.slice(s![.., 0, triangle_i]) * &g0.slice(s![.., i]) + + &triangles.slice(s![.., 0, triangle_i]) * &g1.slice(s![.., i]) + + &triangles.slice(s![.., 0, triangle_i]) * &g2.slice(s![.., i])) + ) + ); + } + + let coefficients: Array1 = arr1(&[1./6., 1./24., 1./24., 1./24., 1./60., 1./60., 1./60., 1./120., 1./120., 1./120.]); + let integrated: Array1 = integral.sum_axis(Axis(1)) * coefficients; + let volume = integrated[0]; + let center_mass: Array1 = if volume.abs() < 1e-10 { + arr1(&[0., 0., 0.]) + } + else { + let a = &integrated.slice(s![1..4]); + a / volume + }; + + let density = 1.0; + + + let mut inertia: Array2 = Array2::zeros((3, 3)); + + inertia[[0, 0]] = integrated[5] + integrated[6] - + volume * (center_mass[1].powi(2) + center_mass[2].powi(2)); + + inertia[[1, 1]] = integrated[4] + integrated[6] - + volume * (center_mass[0].powi(2) + center_mass[2].powi(2)); + + inertia[[2, 2]] = integrated[4] + integrated[5] - + volume * (center_mass[0].powi(2) + center_mass[1].powi(2)); + + inertia[[0, 1]] = integrated[7] - + volume * center_mass[0] * center_mass[1]; + + inertia[[1, 2]] = integrated[8] - + volume * center_mass[1] * center_mass[2]; + + inertia[[0, 2]] = integrated[9] - + volume * center_mass[0] * center_mass[2]; + + inertia[[2, 0]] = inertia[[0, 2]]; + inertia[[2, 1]] = inertia[[1, 2]]; + inertia[[1, 0]] = inertia[[0, 1]]; + inertia *= density; + + // println!("{}", center_mass); + (center_mass, inertia) +} + + +fn principal_axis(inertia: Array2) -> (Array1, Array2) { + let negate_nondiagonal: Array2 = &(Array2::eye(3) * 2.0) - 1.0; + let a: Array2 = inertia * negate_nondiagonal; + + let m = matrix(a.as_slice().unwrap().to_vec(), 3, 3, Row); + let e = eigen(&m, EigenMethod::Jacobi); + let (c, v) = e.extract(); + + let components =arr1(c.as_slice()); + let vectors: Array2 = ArrayBase::from_shape_vec((3, 3), v.data).unwrap(); + + // eigh returns them as column vectors, change them to row vectors + (components, vectors.reversed_axes()) +} + + +#[allow(dead_code)] +fn transform_arround(matrix: Array2, point: &Array1) -> Array2 { + // def transform_around(matrix, point): + // """ + // Given a transformation matrix, apply its rotation + // around a point in space. + // + // Parameters + // ---------- + // matrix: (4,4) or (3, 3) float, transformation matrix + // point: (3,) or (2,) float, point in space + // + // Returns + // --------- + // result: (4,4) transformation matrix + // """ + // point = np.asanyarray(point) + // matrix = np.asanyarray(matrix) + // dim = len(point) + // if matrix.shape != (dim + 1, + // dim + 1): + // raise ValueError('matrix must be (d+1, d+1)') + // + // translate = np.eye(dim + 1) + // translate[:dim, dim] = -point + // result = np.dot(matrix, translate) + // translate[:dim, dim] = point + // result = np.dot(translate, result) + // + // return result + + let mut translate: Array2 = Array2::eye(4); + translate.slice_mut(s![..3, ..3]).sub_assign(point); + + let mut result = matrix.dot(&translate); + translate.slice_mut(s![..3, 3]).assign(point); + result = translate.dot(&result); + + return result + +} + +pub fn principal_inertia_transform(triangles: VctrTriangles) -> Array2{ + let (center_mass, inertia) = mass_properties(triangles); + let (_components, vectors) = principal_axis(inertia); + + // let pic = principal_inertia_axis(inertia)[0]; + // println!("center_mass: {}", center_mass); + // println!("vectors: {:?}", vectors); + // println!("_components: {:?}", _components); + + let vcts = vectors; + + // TODO: Reorder vectors by components + let mut transform = Array2::eye(4); + + // TODO: + transform.slice_mut(s![..3, ..3]).assign(&vcts); + + + // let mut tr = transform_arround(transform, ¢er_mass); + transform.slice_mut(s![..3, 3]).sub_assign(¢er_mass); + + transform +} + + +pub fn get_contour(mesh: &Mesh, z_sect: f64) -> Vec> { + // construct plane section + let mut sect = Vec::::new(); + + for vertex_id in mesh.vertex_iter() { + let p = mesh.vertex_position(vertex_id); + if (p.z - z_sect).abs() < 0.15 { + sect.push(Vec2{x: p.x, y: p.y}); + } + } + + let len = sect.len(); + let mut mt: Vec> = Vec::with_capacity(len); + let mut v: Vec = Vec::with_capacity(len); + v.resize(len, 0f32); + mt.resize(len, v); + + for (i, p) in sect.iter().enumerate() { + for (j, q) in sect.iter().enumerate() { + mt[i][j] = p.distance2(*q) as f32; + } + } + + let mut ii: Vec = (0..len).collect(); + for i in 0..len-1 { + let v = &mt[ ii[ i ] ]; + let j = (i+1..len).min_by_key(|&k| (v[ ii[ k ] ] * 10000.0) as u32).unwrap(); + ii.swap(i + 1, j); + } + + let mut cntr: Vec> = sect + .iter().enumerate() + .map(|(i, &_a)| sect[ ii[ i ] ]) + .collect(); + + cntr.push(cntr.as_slice()[0]); + + // println!("contour len: {}", sect.len()); + // println!("contour: {:?}", cntr); + + let p0 = *cntr.first().unwrap(); + let pn = *cntr.last().unwrap(); + let d = cntr.first().unwrap().distance(*cntr.last().unwrap()).sqrt(); + let d2 = cntr[0].distance(cntr[1]).sqrt(); + + let nn = (d / d2) as i32; + for n in 0..nn { + let k = (pn.y - p0.y) / (pn.x - p0.x); + + let p = Point2{x: p0.x + (n as f64) * d2, y: p0.y + (n as f64) * d2 * k}; + cntr.push(p); + } + + // println!("{:?}", cntr); + cntr +} diff --git a/p3d/src/contour.rs b/p3d/src/contour.rs new file mode 100644 index 0000000..599938a --- /dev/null +++ b/p3d/src/contour.rs @@ -0,0 +1,104 @@ +use std::collections::HashSet; +use cgmath::Point2; + +pub(crate) type CellSet = HashSet<(i32, i32)>; + +pub(crate) struct Cntr { + pub(crate) points: Vec>, + pub(crate) n_size: i16, +} + +impl Cntr { + pub(crate) fn new(vp: Option>>, grid_size: i16) -> Self { + + Self { + points: match vp { + Some(v) => v, + None => vec![], + }, + n_size: grid_size, + } + } + + pub(crate) fn push(&mut self, p: Point2) { + self.points.push(p); + } + + pub(crate) fn line_zone(&self) -> CellSet { + fn chk_add(z: &mut CellSet, n: i32, i: i32, j: i32) { + if (0..n).contains(&i) && (0..n).contains(&j) { + z.insert((i, j)); + } + } + + let n = self.n_size as i32; + let min_x = self.points.iter().map(|a| a.x).min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap(); + let min_y = self.points.iter().map(|a| a.y).min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap(); + let max_x = self.points.iter().map(|a| a.x).max_by(|a, b| a.partial_cmp(b).unwrap()).unwrap(); + let max_y = self.points.iter().map(|a| a.y).max_by(|a, b| a.partial_cmp(b).unwrap()).unwrap(); + + let w = max_x - min_x; + let h = max_y - min_y; + + let grid_dx: f64 = w / n as f64; + let grid_dy: f64 = h / n as f64; + + let dx = 0.1 * grid_dx; + let dy = 0.1 * grid_dy; + + let _len = self.points.len(); + + let mut z = CellSet::new(); + + for pp in self.points.iter() { + let Point2{x: px, y: py} = *pp; + let mut i = ((px - min_x) / grid_dx) as i32; + let mut j = ((py - min_y) / grid_dy) as i32; + + if i == n { + i = n - 1; + } + if j == n { + j = n - 1; + } + + z.insert((i, j)); + + let xx = px.round() - px; + let yy = py.round() - py; + + if xx.abs() < dx { + if xx >= 0.0 { + chk_add(&mut z, n, i + 1, j); + } else { + chk_add(&mut z, n, i - 1, j); + } + } + if yy.abs() < dy { + if yy >= 0.0 { + chk_add(&mut z, n, i, j + 1); + } else { + chk_add(&mut z, n, i, j - 1); + } + } + + if yy.abs() < dy && xx.abs() < dx { + if xx >= 0.0 && yy >= 0.0 { + chk_add(&mut z, n, i + 1, j + 1); + } + if xx >= 0.0 && yy < 0.0 { + chk_add(&mut z, n, i + 1, j - 1); + } + if xx < 0.0 && yy >= 0.0 { + chk_add(&mut z, n, i - 1, j + 1); + } + if xx < 0.0 && yy < 0.0 { + chk_add(&mut z, n, i - 1, j - 1); + } + } + } + z.clone() + } + + +} diff --git a/p3d/src/lib.rs b/p3d/src/lib.rs new file mode 100644 index 0000000..1e40c4d --- /dev/null +++ b/p3d/src/lib.rs @@ -0,0 +1,235 @@ +use std::fs::File; +use std::io::{ BufReader }; +use std::path::PathBuf; + +use obj::{load_obj, Obj, Vertex}; +use tri_mesh::prelude::*; + +#[macro_use(s)] +extern crate ndarray; + +use ndarray::arr2; +use ndarray::Array3; +use crate::algo_grid::get_contour; + +mod polyline; +mod contour; +mod algo_grid; +use algo_grid::find_top_std; +type Vec2 = Point2; + + +#[derive(Debug)] +pub enum AlgoType { + Grid2d, + Spectr, +} + +// type ProgressFunc = |pct: i64, status: i64, descr: String| -> u32; + +// pub fn calc(par1: i16, par2: i16, path: String, fptr: F) -> String +// where F: Fn(i64, i64, String) -> i64 +// { +// // a.wrapping_add(b) +// //let path = PathBuf::from(r"assets/st1.obj"); +// let p = PathBuf::from(path.clone()); +// +// dbg!("rust: {:?}", p.clone()); +// +// // path + "-res" +// +// let res_hashes = p3d_process(&p, AlgoType::Grid2d, par1, par2, Some(fptr)); +// // println!("{:?}", res_hashes); +// let r = match res_hashes { +// Ok(h) => h, +// Err(e) => vec![format!("{:?}", e)], +// }; +// +// //format!("{}", r) +// r.join("\n") +// } + + +#[allow(unused_variables)] +//pub fn p3d_process(scan_name: &PathBuf, algo: AlgoType, par1: i16, par2: i16, fptr: Option) -> Result, std::io::Error> +// where F: Fn(i64, i64, String) -> i64 +pub fn p3d_process(scan_name: &PathBuf, algo: AlgoType, par1: i16, par2: i16 ) -> Result, std::io::Error> +{ + let grid_size: i16 = par1; + let n_sections: i16 = par2; + + // let a = fptr(15, 1, "Start".to_owned()); + + // use crate::algo_grid::mass_properties; + // let triangles: Array3 = arr3( + // &[ + // [[1.,2.,3.], [1.,2.,3.], [1.,2.,3.]], + // [[1.,2.,3.], [1.,2.,3.], [1.,2.,3.]], + // [[1.,2.,3.], [1.,2.,3.], [1.,2.,3.]], + // [[1.,2.,3.], [1.,2.,3.], [1.,2.,3.]], + // [[1.,2.,3.], [1.,2.,3.], [1.,2.,3.]], + // [[1.,2.,3.], [1.,2.,3.], [1.,2.,3.]], + // ]); + + //let res = mass_properties(triangles); + + // let result = std::fs::read_to_string(&args.infile); + // + // let content = match result { + // Ok(content) => { content }, + // Err(error) => { return Err(error.into()); } + // }; + // println!("file content: {}", content); + + // let mut mesh = MeshBuilder::new().with_obj(scan_name.clone().into_os_string().into_string().unwrap()).build().unwrap(); + + //let _input = File::open(scan_name)?; + // let input = BufReader::new(input); + + let input = BufReader::new(File::open(scan_name)?); + let model: Obj = load_obj(input).unwrap(); + + let verts = model.vertices + .iter() + .flat_map(|v| v.position.iter()) + .map(|v| f64::from(*v)) + .collect(); + + let mut mesh = MeshBuilder::new() + .with_indices(model.indices) + .with_positions(verts) + .build().unwrap(); + + let mut triangles: Array3 = Array3::zeros((mesh.no_faces(), 3, 3)); + + for (i, fid) in mesh.face_iter().enumerate() { + let vs = mesh.face_vertices(fid); + let v1 = mesh.vertex_position(vs.0); + let v2 = mesh.vertex_position(vs.1); + let v3 = mesh.vertex_position(vs.2); + triangles.slice_mut(s![i, .., ..]) + .assign( + &arr2(&[ + [v1.x as f64, v1.y as f64, v1.z as f64], + [v2.x as f64, v2.y as f64, v2.z as f64], + [v3.x as f64, v3.y as f64, v3.z as f64], + ] + )); + } + + let pit1 = algo_grid::principal_inertia_transform(triangles); + + // println!("Transform matrix:"); + // println!("{}", pit1); + + let pit = pit1; //.t(); + + let a: Matrix4 = Matrix4::new( + pit[[0,0]], pit[[0,1]], pit[[0,2]], pit[[0,3]], + pit[[1,0]], pit[[1,1]], pit[[1,2]], pit[[1,3]], + pit[[2,0]], pit[[2,1]], pit[[2,2]], pit[[2,3]], + pit[[3,0]], pit[[3,1]], pit[[3,2]], pit[[3,3]], + ); //.transpose(); + + let a: Matrix3 = Matrix3::new( + pit[[0,0]], pit[[0,1]], pit[[0,2]], + pit[[1,0]], pit[[1,1]], pit[[1,2]], + pit[[2,0]], pit[[2,1]], pit[[2,2]], + ); //.transpose(); + + let b = a.invert().unwrap(); + + let tr: Matrix4 = Matrix4::new( + b.x[0], b.x[1], b.x[2], 0.0, + b.y[0], b.y[1], b.y[2], 0.0, + b.z[0], b.z[1], b.z[2], 0.0, + 0.0, 0.0, 0.0, 1.0 + ); //.transpose(); + + let shift = Vector3::new(pit[[0,3]], pit[[1,3]], pit[[2,3]]); + + + // let m: Matrix4 = Matrix4::new( + // bbb.x[0], bbb.y[0], bbb.z[0], pit[[0,3]], + // bbb.x[1], bbb.y[1], bbb.z[1], pit[[1,3]], + // bbb.x[2], bbb.y[2], bbb.z[2], pit[[2,3]], + // pit[[3,0]], pit[[3,1]], pit[[3,2]], pit[[3,3]], + // ); + + // let m: Matrix4 = Matrix4::new( + // bbb.x[0], bbb.y[0], bbb.z[0], pit[[3, 0]], + // bbb.x[1], bbb.y[1], bbb.z[1], pit[[3, 1]], + // bbb.x[2], bbb.y[2], bbb.z[2], pit[[3, 2]], + // pit[[0,3]], pit[[1,3]], pit[[2,3]], pit[[3,3]], + // ); + + // semi good + // let m: Matrix4 = Matrix4::new( + // bbb.x[0], bbb.y[0], bbb.z[0], pit[[3, 0]], + // bbb.x[1], bbb.y[1], bbb.z[1], pit[[3, 1]], + // bbb.x[2], bbb.y[2], bbb.z[2], pit[[3, 2]], + // pit[[0,3]], pit[[1,3]], pit[[2,3]], pit[[3,3]], + // ); + + + // let m: Matrix4 = Matrix4::new( + // 1.0, 0.0, 0.0,0.0, + // 0.0, 1.0, 0.0,50.0, + // 0.0, 0.0, 1.0,0.0, + // 0.0, 0.0, 0.0,1.0, + // ); + + // let m: Matrix4 = Matrix4::new( + // bbb.x[0], bbb.y[0], bbb.z[0], 60.0, + // bbb.x[1], bbb.y[1], bbb.z[1], 0.0, + // bbb.x[2], bbb.y[2], bbb.z[2], 0.0, + // 0.0, 0.0, 0.0, 1.0, + // ); + + + //let mm = m.transpose(); + //println!("{:?}", tr); + + mesh.translate(shift); + mesh.apply_transformation(tr); + + + // let p = Vec3::new(0.0, 0.0, 0.0); + // let p_new = (mm * p.extend(1.0)).truncate(); + + // + // let obj_source = mesh.parse_as_obj(); + // // // // + // // // // Write the string to an .obj file + // std::fs::write("foo.obj", obj_source)?; + + let (mut mi, mut ma) = (1.0e10, -1.0e10); + + for vid in mesh.vertex_iter() { + let v = mesh.vertex_position(vid); + if v.z < mi { + mi = v.z; + } + if v.z > ma { + ma = v.z; + } + } + + // let z_sect = (ma + mi) / 2.0; + // let depth: i32 = (10.0 * (10.0 / (1.0f64 + n_sections as f64)).log10()).floor() as i32; + // let mut results: Vec> = Vec::with_capacity(depth.pow(n_sections as u32) as usize); + + let depth = 10; + let mut cntrs: Vec> = Vec::with_capacity(depth); + println!("Select top {} hashes", depth); + let step = (ma - mi) / (1.0f64 + n_sections as f64); + for n in 0..n_sections { + let z_sect = mi + (n as f64 + 1.0f64) * step; + let cntr = get_contour(&mesh, z_sect); + cntrs.push(cntr); + } + + let res = find_top_std(depth as usize, grid_size, &cntrs); + + Ok(res) +} diff --git a/p3d/src/polyline.rs b/p3d/src/polyline.rs new file mode 100644 index 0000000..26d187b --- /dev/null +++ b/p3d/src/polyline.rs @@ -0,0 +1,292 @@ +use std::vec::IntoIter; +use std::collections::vec_deque::VecDeque; + +use tri_mesh::prelude::*; + +use crate::contour::CellSet; +use crate::contour::Cntr; + +pub(crate) const DISTANCE: i32 = 2; +type Vec2 = Point2; + +#[derive(Clone)] +pub(crate) struct PolyLine { + pub(crate) nodes: Vec>, + pub(crate) grid_size: i16, +} + +impl<'a> PolyLine { + pub(crate) fn new(pts: Vec>, grid_size: i16) -> Self { + Self { + nodes: pts, + grid_size, + } + } + + pub(crate) fn to_cntr(&self, n_points: usize) -> Cntr { + self.line2points(n_points) + } + + fn line2points(&self, n: usize) -> Cntr { + let mut l: f64 = 0.0; + + let mut res: Cntr = Cntr::new(None, self.grid_size); + let line2: Cntr = Cntr::new(Some(self.nodes.iter().map(|v| Point2::new(v.x as f64 + 0.5, v.y as f64 + 0.5)).collect()), self.grid_size); + + let mut p1 = line2.points[0]; + let mut ll: Vec<(Point2, f64)> = vec![(p1, 0.0)]; + + for p2 in line2.points[1..].iter() { + l = l + p1.distance(*p2); + ll.push((*p2, l)); + p1 = *p2; + } + + let tot_len = ll.last().unwrap().1; + let dl = tot_len / n as f64; + let mut m = 0; + let mut p = ll[0].0; + + res.push(ll[0].0); + + for k in 1..n { + let r: f64 = (k as f64) * dl; + while m < ll.len() { + let l = ll[m].1; + if r < l { + // cur_path = r; + break; + } + p = ll[m].0; + m += 1; + } + + let s1 = ll[m - 1]; + let s2 = ll[m]; + // # px = (p2[0] - p1[0]) / l * dl # TODO!!! + // # py = (p2[1] - p1[1]) / l * dl # TODO!!! + + let dd = r - s1.1; + //let (mut dx, mut dy): (f64, f64) = (0.0, 0.0); + let (dx, dy): (f64, f64) = + if (s2.0.x - s1.0.x).abs() > 1.0e-10 { + let kk = (s2.0.y - s1.0.y) / (s2.0.x - s1.0.x); + let dx = dd / (1.0 + kk*kk).sqrt(); + let dy = kk * dx; + (dx, dy) + } + else { + let dx = 0.0; + let dy = dd; + (dx, dy) + }; + + res.push(Point2 {x: p.x + dx, y: p.y + dy} ); + } + res + } +} + + +pub(crate) struct GenPolyLines { + cells: CellSet, + line_buf: PolyLine, + lev: i32, +} + +impl GenPolyLines { + pub(crate) fn new(z: CellSet, grid_size: i16) -> Self { + Self { + cells: z, + line_buf: PolyLine::new(Vec::with_capacity(100), grid_size), + lev: 0, + } + } + + fn sco2(v1: &Cntr, v2: &Cntr) -> f64 { + let mut s = 0f64; + + for (a1, a2) in v1.points.iter().zip(v2.points.iter()) { + s += (a2.x - a1.x) * (a2.x - a1.x) + (a2.y - a1.y) * (a2.y - a1.y) + } + s / (v1.points.len() as f64) + } + + pub (crate) fn select_top(cntrs: &Vec>, grid_size: i16, n: usize) -> Vec<(f64, PolyLine)> { + + let mut top_heap: VecDeque<(f64, PolyLine)> = VecDeque::with_capacity(n); + // TODO: select strt point from self.cells + + for cntr in cntrs.iter() { + let cn = Cntr::new(Some(cntr.to_vec()), grid_size); + let zone = cn.line_zone(); + + let mut gen_lines = GenPolyLines::new(zone, grid_size); + let start_point = Point2 { x: 0, y: 0 }; + gen_lines.line_buf.nodes.push(start_point); + + let cntr_size = cn.points.len(); + let calc_sco = |pl: &PolyLine| GenPolyLines::sco2(&cn, &pl.to_cntr(cntr_size)); + + let mut ff = |pl: &PolyLine| { + let d = calc_sco(pl); + let len = top_heap.len(); + if len > 0 { + if d < top_heap.get(len - 1).unwrap().0 || len <= n { + if len == n { + top_heap.pop_front(); + } + top_heap.push_back((d, pl.clone())); + top_heap.make_contiguous().sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap()); + } + } else { + top_heap.push_back((d, pl.clone())); + // top_heap.make_contiguous().sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap()); + } + }; + + gen_lines.complete_line(&mut ff); + } + let v = top_heap.iter().cloned().collect(); + + v + + } + + fn complete_line(&mut self, f: &mut F) + where + F: FnMut(&PolyLine) { + + self.lev += 1; + // println!("Enter {} with line_buf: {:?}", self.lev, self.line_buf.nodes); + let start_point = self.line_buf.nodes.last().unwrap().clone(); + let first_point = self.line_buf.nodes.first().unwrap().clone(); + let neib_nodes = NeiborNodes::new(&self.cells, &self.line_buf, start_point, self.line_buf.grid_size); + + let _last = self.line_buf.nodes.last().unwrap(); + // println!("point: {:?}, neibs: {:?}", last, neib_nodes.neibs); + + for p in neib_nodes.into_iter() { + if p == first_point { + // println!("line_buf: {:?}", self.line_buf.nodes); + self.line_buf.nodes.push(p); + (*f)(&self.line_buf); + self.line_buf.nodes.pop(); + continue; + } + + self.line_buf.nodes.push(p); + self.complete_line(f); + self.line_buf.nodes.pop(); + } + // println!("Exit {}", self.lev); + self.lev -= 1; + } +} + + +#[derive(Clone)] +struct NeiborNodes { + pub(crate) neibs: Vec>, + grid_size: i16, +} + +impl NeiborNodes { + fn new(permited_points: &CellSet, line: &PolyLine, start_point: Point2, grid_size: i16) -> Self { + // println!("permitted_points: {:?}", permited_points); + Self { + //cells: permited_points, + //cur_point: start_point, + neibs: Self::near_points(permited_points, line, start_point, DISTANCE, grid_size), + grid_size, + } + } + + fn near_points(z: &CellSet, line: &PolyLine, start_point: Point2, dist: i32, grid_size: i16) -> Vec> { + let gsize = grid_size as i32; + let chk_zone = |i: i32, j: i32, z: &CellSet, line: &PolyLine| -> bool { + if i < 0 || i >= gsize || j < 0 || j >= gsize { + return false; + } + + let first = line.nodes.first().unwrap().clone(); + // println!("first: {:?}", first); + if first == (Point2{x:i, y: j}) && line.nodes.len() > 5 { + //println!("first: {:?}", first); + return true; + } + if !z.contains(&(i, j)) { + return false; + } + for p in line.nodes.iter() { + let Point2{x: pi, y: pj} = *p; + if (pi - i).abs() < dist as i32 && (pj - j).abs() < dist as i32{ + return false + } + } + true + }; + + let Point2{x:i0, y:j0} = start_point; + let mut v: Vec> = Vec::with_capacity(((grid_size - 1) * 4) as usize); + + let min_i = i0 - dist; + let min_j = j0 - dist + 1; + let max_i = i0 + dist; + let max_j = j0 + dist - 1; + + for i in min_i..=max_i { + let j = min_j - 1; + if chk_zone(i, j, z, line) { + v.push(Point2::new(i, j)); + } + } + + for j in min_j..=max_j{ + let i = max_i; + if chk_zone(i, j, z, line) { + v.push(Point2::new(i, j)); + } + } + + for i in min_i..=max_i { + let j = max_j + 1; + if chk_zone(i, j, z, line) { + v.push(Point2::new(i, j)); + } + } + + for j in min_j..=max_j { + let i = min_i; + if chk_zone(i, j, z, line) { + v.push(Point2::new(i, j)); + } + } + + v.clone() + } +} + +impl IntoIterator for NeiborNodes { + type Item = Point2; + type IntoIter = NeiborNodesIter; + + // note that into_iter() is consuming self + fn into_iter(self) -> Self::IntoIter { + Self::IntoIter { + iter: self.neibs.into_iter(), + } + } +} + +struct NeiborNodesIter { + iter: IntoIter>, +} + +impl<'a> Iterator for NeiborNodesIter { + type Item = Point2; + + fn next(&mut self) -> Option { + self.iter.next() + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ed1a363 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,55 @@ +use structopt::StructOpt; +// use std::fs::File; +// use std::io::Write; + +use p3d::p3d_process; +use p3d::AlgoType; + +/// Search for a pattern in a file and display the lines that contain it. +#[derive(StructOpt)] +struct Cli { + /// 3d hash algorithm + #[structopt(short, long)] + /// Algorithm. Supported algorithms: Grid2d + algo: String, + + #[structopt(short, long)] + /// Number of cells in Grid2d algorithm + grid: i16, + + #[structopt(short, long)] + /// Number of sections in Grid2d algorithm + sect: i16, + + #[structopt(short, long, parse(from_os_str))] //, default_value = "data/st1.obj")] + /// The path to the file to read + infile: std::path::PathBuf, + + // #[structopt(short, long, parse(from_os_str))] //, default_value = "data/st1.hash")] + // // The path to the file to save results + // outfile: std::path::PathBuf, +} + +fn main() -> Result<(), Box> { + let args = Cli::from_args(); + + let mut res_hashes = Ok(vec![]); + if args.algo == "grid2d" { + res_hashes = p3d_process(&args.infile, AlgoType::Grid2d, args.grid, args.sect); //, None); + } + + let hashes = res_hashes.unwrap(); + + // match std::fs::write(&args.outfile, hashes) { + // Ok(()) => { println!("write file OK"); }, + // Err(error) => { return Err(error.into()); } + // } + // let mut f = File::create(&args.outfile)?; + + for h in &hashes { + // write!(f, "{}", h)?; + println!("{:?}", h); + } + Ok(()) +} +