Skip to content

Commit

Permalink
Remove support for int32, uint32 for the attributes schema
Browse files Browse the repository at this point in the history
Rust serde Value are 64, and I was accepting only those and casting
to 64bits in the background so better to just say that all attributes
are 64bits (except bool and String)
  • Loading branch information
hugoledoux committed Sep 16, 2024
1 parent 55b7656 commit 5c8ef29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
15 changes: 5 additions & 10 deletions demo/add_normals.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -- add the normals, as extra attributes (nx, ny, nz), for all the vertices in the DT

#-- add the normals, as extra attributes (nx, ny, nz), for all the vertices in the DT
import json

import startinpy
import numpy as np
import laspy
import json
import numpy as np
import startinpy

las = laspy.read("../data/small.laz")
dt = startinpy.DT()
dt.set_attributes_schema(np.dtype([("nx", np.float32), ("ny", float), ("nz", float)]))
dt.set_attributes_schema(np.dtype([("nx", np.float64), ("ny", float), ("nz", float)]))
dt.duplicates_handling = "Highest"

dt.insert(las.xyz)
Expand All @@ -32,8 +32,3 @@
# # together = np.stack((dt.points, a))
# # together = np.concatenate((dt.points, a), axis=1)
# print(together)





6 changes: 3 additions & 3 deletions docs/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

It is possible to store extra attributes with each vertex (besides the xyz-coordinates).

Those attributes are stored as a JSON object/dictionary, a key-value pair where the key is a string and the value is one of the following [NumPy data types](https://numpy.org/doc/stable/user/basics.types.html): numpy.bool_, numpy.int32, numpy.int64, numpy.uint32, numpy.uint64, unicode (string), numpy.float32, numpy.float64.
Those attributes are stored as a JSON object/dictionary, a key-value pair where the key is a string and the value is one of the following [NumPy data types](https://numpy.org/doc/stable/user/basics.types.html): `numpy.bool_`, `numpy.int64`, `numpy.uint64`, unicode (string), and `numpy.float64`.

To attach extra attributes, you first need to define a *schema*, it a list of the attribute names and their data types.
[NumPy data types](https://numpy.org/doc/stable/reference/arrays.dtypes.html#arrays-dtypes) must be used to create the schema.

```python
dt = startinpy.DT()
myschema = np.dtype([('classification', np.uint32), ('intensity', float)])
myschema = np.dtype([('classification', np.uint64), ('intensity', float)])
dt.set_attributes_schema(myschema)
```

or

```python
dt = startinpy.DT(np.dtype([('classification', np.uint32), ('intensity', float)]))
dt = startinpy.DT(np.dtype([('classification', np.uint64), ('intensity', float)]))
```

Adding attributes to a triangulation that has no schema defined will result in no extra attributes being stored; only those compliant with the schema are stored.
Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,13 @@ impl DT {
/// schema are stored.
///
/// Only the following data types for each attribute are allowed:
/// 'numpy.bool_', 'numpy.int32', 'numpy.int64', 'numpy.uint32', 'numpy.uint64', unicode (string),
/// 'numpy.float32', 'numpy.float64'.
/// 'numpy.bool_', 'numpy.int64', 'numpy.uint64', unicode (string), 'numpy.float64'.
///
/// :param dtype: a `NumPy Data type object (dtype) <https://numpy.org/doc/stable/reference/arrays.dtypes.html#arrays-dtypes>`_
/// :return: True if the schema is valid, otherwise an error is thrown.
///
/// >>> dt = startinpy.DT()
/// >>> myschema = np.dtype([('classification', np.uint32), ('intensity', float)])
/// >>> myschema = np.dtype([('classification', np.uint64), ('intensity', float)])
/// >>> dt.set_attributes_schema(myschema)
/// >>> dt.insert_one_pt([85000.0, 444003.2, 2.2], classification=2, intensity=111.1)
#[pyo3(signature = (dtype))]
Expand Down Expand Up @@ -389,7 +388,7 @@ impl DT {
self.dtype.push((name.to_string(), "<u4".to_string()));
}
"uint64" => {
v.push((name.to_string(), "i64".to_string()));
v.push((name.to_string(), "u64".to_string()));
self.dtype.push((name.to_string(), "<u8".to_string()));
}
other if other.starts_with("<U") => {
Expand All @@ -414,11 +413,11 @@ impl DT {
///
/// :return: a NumPy Data type object (dtype)
///
/// >>> d = np.dtype([('classification', np.float32), ('name', '<U8')])
/// >>> d = np.dtype([('classification', np.float64), ('name', '<U8')])
/// >>> dt.set_attributes_schema(d)
/// True
/// >>> dt.get_attributes_schema()
/// [('classification', '<f4'), ('name', '<U8')]
/// [('classification', '<f8'), ('name', '<U8')]
fn get_attributes_schema(&self) -> Vec<(String, String)> {
self.dtype.clone()
}
Expand All @@ -432,7 +431,7 @@ impl DT {
/// vertex). The array is empty if the extra attributes don't exist.
///
/// >>> dt = startinpy.DT()
/// >>> dt.add_attribute_map(np.dtype([("classification", np.uint32)]))
/// >>> dt.add_attribute_map(np.dtype([("classification", np.uint64)]))
/// >>> dt.insert_one_pt([85000.0, 444003.2, 2.2], classification=6)
/// >>> ...
/// >>> dt.attributes[1:]
Expand Down

0 comments on commit 5c8ef29

Please sign in to comment.