From 1a43cc534e5ec68de6f11ab9fa3b58f526b3a8bc Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 18 Oct 2023 10:13:00 +0200 Subject: [PATCH] improve channel name comments and add overload for directly passing width/height/channel --- crates/re_types/src/archetypes/image_ext.rs | 2 +- .../annotation_context_segmentation.cpp | 2 +- docs/code-examples/depth_image_3d.cpp | 2 +- docs/code-examples/depth_image_simple.cpp | 2 +- docs/code-examples/image_simple.cpp | 2 +- .../rerun/archetypes/annotation_context.hpp | 2 +- .../src/rerun/archetypes/depth_image.hpp | 30 ++++++++----- .../src/rerun/archetypes/depth_image_ext.cpp | 31 ++++++++----- rerun_cpp/src/rerun/archetypes/image.hpp | 43 +++++++++++++------ rerun_cpp/src/rerun/archetypes/image_ext.cpp | 41 +++++++++++++----- .../rerun/archetypes/segmentation_image.hpp | 30 ++++++++----- .../archetypes/segmentation_image_ext.cpp | 32 +++++++++----- 12 files changed, 147 insertions(+), 72 deletions(-) diff --git a/crates/re_types/src/archetypes/image_ext.rs b/crates/re_types/src/archetypes/image_ext.rs index 3813191a21820..45f2bbd65ee22 100644 --- a/crates/re_types/src/archetypes/image_ext.rs +++ b/crates/re_types/src/archetypes/image_ext.rs @@ -28,7 +28,7 @@ impl Image { assign_if_none(&mut data.shape[non_empty_dim_inds[1]].name, "width"); } 3 => match data.shape[non_empty_dim_inds[2]].size { - 1 | 3 | 4 => { + 3 | 4 => { assign_if_none(&mut data.shape[non_empty_dim_inds[0]].name, "height"); assign_if_none(&mut data.shape[non_empty_dim_inds[1]].name, "width"); assign_if_none(&mut data.shape[non_empty_dim_inds[2]].name, "depth"); diff --git a/docs/code-examples/annotation_context_segmentation.cpp b/docs/code-examples/annotation_context_segmentation.cpp index e3e75e6f3bd74..fcccf8705c083 100644 --- a/docs/code-examples/annotation_context_segmentation.cpp +++ b/docs/code-examples/annotation_context_segmentation.cpp @@ -28,5 +28,5 @@ int main() { std::fill_n(data.begin() + y * WIDTH + 6, 6, 2); // right half } - rec.log("segmentation/image", rerun::SegmentationImage({HEIGHT, WIDTH}, std::move(data))); + rec.log("segmentation/image", rerun::SegmentationImage(WIDTH, HEIGHT, std::move(data))); } diff --git a/docs/code-examples/depth_image_3d.cpp b/docs/code-examples/depth_image_3d.cpp index 028ad3a976f4a..c838da069d9d6 100644 --- a/docs/code-examples/depth_image_3d.cpp +++ b/docs/code-examples/depth_image_3d.cpp @@ -30,6 +30,6 @@ int main() { rec.log( "world/camera/depth", - rerun::DepthImage({HEIGHT, WIDTH}, std::move(data)).with_meter(10000.0) + rerun::DepthImage(WIDTH, HEIGHT, std::move(data)).with_meter(10000.0) ); } diff --git a/docs/code-examples/depth_image_simple.cpp b/docs/code-examples/depth_image_simple.cpp index f6a8abe27d969..738e4bddafd94 100644 --- a/docs/code-examples/depth_image_simple.cpp +++ b/docs/code-examples/depth_image_simple.cpp @@ -19,5 +19,5 @@ int main() { std::fill_n(data.begin() + y * WIDTH + 6, 6, 45000); // right half } - rec.log("depth", rerun::DepthImage({HEIGHT, WIDTH}, std::move(data)).with_meter(10000.0)); + rec.log("depth", rerun::DepthImage(WIDTH, HEIGHT, std::move(data)).with_meter(10000.0)); } diff --git a/docs/code-examples/image_simple.cpp b/docs/code-examples/image_simple.cpp index 093f010c03109..2ca4c10b0de62 100644 --- a/docs/code-examples/image_simple.cpp +++ b/docs/code-examples/image_simple.cpp @@ -21,5 +21,5 @@ int main() { } } - rec.log("image", rerun::Image({HEIGHT, WIDTH, 3}, std::move(data))); + rec.log("image", rerun::Image(WIDTH, HEIGHT, 3, std::move(data))); } diff --git a/rerun_cpp/src/rerun/archetypes/annotation_context.hpp b/rerun_cpp/src/rerun/archetypes/annotation_context.hpp index 350b9c98ff625..597d3deca18cd 100644 --- a/rerun_cpp/src/rerun/archetypes/annotation_context.hpp +++ b/rerun_cpp/src/rerun/archetypes/annotation_context.hpp @@ -55,7 +55,7 @@ namespace rerun { /// std::fill_n(data.begin() + y * WIDTH + 6, 6, 2); // right half /// } /// - /// rec.log("segmentation/image", rerun::SegmentationImage({HEIGHT, WIDTH}, std::move(data))); + /// rec.log("segmentation/image", rerun::SegmentationImage(WIDTH, HEIGHT, std::move(data))); /// } /// ``` struct AnnotationContext { diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.hpp b/rerun_cpp/src/rerun/archetypes/depth_image.hpp index 96c75ed22e622..8f7ef9f48f41e 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.hpp @@ -58,7 +58,7 @@ namespace rerun { /// /// rec.log( /// "world/camera/depth", - /// rerun::DepthImage({HEIGHT, WIDTH}, std::move(data)).with_meter(10000.0) + /// rerun::DepthImage(WIDTH, HEIGHT, std::move(data)).with_meter(10000.0) /// ); /// } /// ``` @@ -85,21 +85,31 @@ namespace rerun { public: // Extensions to generated type defined in 'depth_image_ext.cpp' - /// New DepthImage from dimensions and tensor buffer. + /// New depth image from width, height and tensor buffer. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. + /// Sets the dimension names to "width" and "height" if they are not specified. DepthImage( - std::vector shape, - rerun::datatypes::TensorBuffer buffer + datatypes::TensorDimension width, datatypes::TensorDimension height, + datatypes::TensorBuffer buffer ) - : DepthImage(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} + : DepthImage(datatypes::TensorData( + {std::move(height), std::move(width)}, std::move(buffer) + )) {} + + /// New depth image from height/width and tensor buffer. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + DepthImage( + std::vector shape, datatypes::TensorBuffer buffer + ) + : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} /// New depth image from tensor data. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. - explicit DepthImage(rerun::components::TensorData _data); + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit DepthImage(components::TensorData _data); public: DepthImage() = default; diff --git a/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp b/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp index 0dd87d26ae3ba..0291ada0c2c9e 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp @@ -10,25 +10,36 @@ namespace rerun { #ifdef EDIT_EXTENSION // [CODEGEN COPY TO HEADER START] - /// New DepthImage from dimensions and tensor buffer. + /// New depth image from width, height and tensor buffer. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. + /// Sets the dimension names to "width" and "height" if they are not specified. DepthImage( - std::vector shape, - rerun::datatypes::TensorBuffer buffer + datatypes::TensorDimension width, + datatypes::TensorDimension height, + datatypes::TensorBuffer buffer ) - : DepthImage(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} + : DepthImage(datatypes::TensorData({std::move(height), std::move(width)}, std::move(buffer))) {} + + /// New depth image from height/width and tensor buffer. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + DepthImage( + std::vector shape, + datatypes::TensorBuffer buffer + ) + : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} /// New depth image from tensor data. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. - explicit DepthImage(rerun::components::TensorData _data); + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit DepthImage(components::TensorData _data); + // [CODEGEN COPY TO HEADER END] #endif - DepthImage::DepthImage(rerun::components::TensorData _data) : data(std::move(_data)) { + DepthImage::DepthImage(components::TensorData _data) : data(std::move(_data)) { auto& shape = data.data.shape; if (shape.size() != 2) { Error(ErrorCode::InvalidTensorDimension, "Shape must be rank 2.").handle(); diff --git a/rerun_cpp/src/rerun/archetypes/image.hpp b/rerun_cpp/src/rerun/archetypes/image.hpp index 339c73547d6b7..5f954e73e97d4 100644 --- a/rerun_cpp/src/rerun/archetypes/image.hpp +++ b/rerun_cpp/src/rerun/archetypes/image.hpp @@ -42,7 +42,7 @@ namespace rerun { /// const int HEIGHT = 8; /// const int WIDTH = 12; /// std::vector data(WIDTH * HEIGHT * 3, 0); - /// for (auto i = 0; i shape, - rerun::datatypes::TensorBuffer buffer + datatypes::TensorDimension width, datatypes::TensorDimension height, + datatypes::TensorBuffer buffer ) - : Image(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} + : Image(datatypes::TensorData( + {std::move(height), std::move(width)}, std::move(buffer) + )) {} - /// New image from tensor data. + /// New Image from width, height, channels and tensor buffer. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2 or 3 or - /// has neither 1, 3 or 4 channels. + /// Sets the dimension names to "width", "height" and "channel" if they are not specified. + Image( + datatypes::TensorDimension width, datatypes::TensorDimension height, + datatypes::TensorDimension channels, datatypes::TensorBuffer buffer + ) + : Image(datatypes::TensorData( + {std::move(height), std::move(width), std::move(channels)}, std::move(buffer) + )) {} + + /// New Image from height/width/channel and tensor buffer. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. + Image(std::vector shape, datatypes::TensorBuffer buffer) + : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + + /// New depth image from tensor data. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. explicit Image(rerun::components::TensorData _data); public: diff --git a/rerun_cpp/src/rerun/archetypes/image_ext.cpp b/rerun_cpp/src/rerun/archetypes/image_ext.cpp index 51103ce441c71..1695466122ef3 100644 --- a/rerun_cpp/src/rerun/archetypes/image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/image_ext.cpp @@ -10,22 +10,41 @@ namespace rerun { #ifdef EDIT_EXTENSION // [CODEGEN COPY TO HEADER START] - /// New image from dimensions and tensor buffer. + /// New Image from width, height and tensor buffer. /// - /// Sets dimensions to width/height/channel if they are not specified. - /// Calls Error::handle() if the shape is not rank 2 or 3 or - /// has neither 1, 3 or 4 channels. + /// Sets the dimension names to "width" and "height" if they are not specified. Image( - std::vector shape, - rerun::datatypes::TensorBuffer buffer + datatypes::TensorDimension width, + datatypes::TensorDimension height, + datatypes::TensorBuffer buffer ) - : Image(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} + : Image(datatypes::TensorData({std::move(height), std::move(width)}, std::move(buffer))) {} - /// New image from tensor data. + /// New Image from width, height, channels and tensor buffer. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2 or 3 or - /// has neither 1, 3 or 4 channels. + /// Sets the dimension names to "width", "height" and "channel" if they are not specified. + Image( + datatypes::TensorDimension width, + datatypes::TensorDimension height, + datatypes::TensorDimension channels, + datatypes::TensorBuffer buffer + ) + : Image(datatypes::TensorData({std::move(height), std::move(width), std::move(channels)}, std::move(buffer))) {} + + /// New Image from height/width/channel and tensor buffer. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. + Image( + std::vector shape, + datatypes::TensorBuffer buffer + ) + : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + + /// New depth image from tensor data. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. explicit Image(rerun::components::TensorData _data); // [CODEGEN COPY TO HEADER END] #endif diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp index 4681ab87d4572..2f1e6d26638ba 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp @@ -78,23 +78,31 @@ namespace rerun { public: // Extensions to generated type defined in 'segmentation_image_ext.cpp' - /// New SegmentationImage from dimensions and tensor buffer. + /// New segmentation image from width, height and tensor buffer. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. + /// Sets the dimension names to "width" and "height" if they are not specified. SegmentationImage( - std::vector shape, - rerun::datatypes::TensorBuffer buffer + datatypes::TensorDimension width, datatypes::TensorDimension height, + datatypes::TensorBuffer buffer ) - : SegmentationImage( - rerun::datatypes::TensorData(std::move(shape), std::move(buffer)) - ) {} + : SegmentationImage(datatypes::TensorData( + {std::move(height), std::move(width)}, std::move(buffer) + )) {} + + /// New segmentation image from height/width and tensor buffer. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + SegmentationImage( + std::vector shape, datatypes::TensorBuffer buffer + ) + : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} /// New segmentation image from tensor data. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. - explicit SegmentationImage(rerun::components::TensorData _data); + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit SegmentationImage(components::TensorData _data); public: SegmentationImage() = default; diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp b/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp index 934e9ef2253c7..84465b0a7947f 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp @@ -10,26 +10,36 @@ namespace rerun { #ifdef EDIT_EXTENSION // [CODEGEN COPY TO HEADER START] - /// New SegmentationImage from dimensions and tensor buffer. + /// New segmentation image from width, height and tensor buffer. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. + /// Sets the dimension names to "width" and "height" if they are not specified. SegmentationImage( - std::vector shape, - rerun::datatypes::TensorBuffer buffer + datatypes::TensorDimension width, + datatypes::TensorDimension height, + datatypes::TensorBuffer buffer ) - : SegmentationImage(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) { - } + : SegmentationImage(datatypes::TensorData({std::move(height), std::move(width)}, std::move(buffer))) {} + + /// New segmentation image from height/width and tensor buffer. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + SegmentationImage( + std::vector shape, + datatypes::TensorBuffer buffer + ) + : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} /// New segmentation image from tensor data. /// - /// Sets dimensions to width/height if they are not specified. - /// Calls Error::handle() if the shape is not rank 2. - explicit SegmentationImage(rerun::components::TensorData _data); + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit SegmentationImage(components::TensorData _data); + // [CODEGEN COPY TO HEADER END] #endif - SegmentationImage::SegmentationImage(rerun::components::TensorData _data) + SegmentationImage::SegmentationImage(components::TensorData _data) : data(std::move(_data)) { auto& shape = data.data.shape; if (shape.size() != 2) {