Skip to content

Commit

Permalink
finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Dec 4, 2024
1 parent 6465aeb commit 74dd688
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 29 deletions.
2 changes: 1 addition & 1 deletion crates/store/re_chunk/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl Chunk {
timelines == rhs_timelines
}
// TODO(cmc): we cannot compare tags yet, need to support Python & C++ first
&& *components == rhs.components // TODO
// && *components == rhs.components
&& {
let lhs_components_no_tags: ChunkComponents = components
.clone()
Expand Down
18 changes: 6 additions & 12 deletions docs/snippets/all/descriptors/descr_custom_archetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,17 @@ struct rerun::AsComponents<CustomPoints3D> {
CustomPoints3D::IndicatorComponent indicator;
batches.push_back(ComponentBatch::from_loggable(indicator).value_or_throw());

// TODO: with_methods would be nice
auto positions_descr = rerun::ComponentDescriptor(
"user.CustomArchetype",
"positions",
Loggable<CustomPosition3D>::Descriptor.component_name
);
auto positions_descr = rerun::Loggable<CustomPosition3D>::Descriptor
.or_with_archetype_name("user.CustomArchetype")
.or_with_archetype_field_name("positions");
batches.push_back(
ComponentBatch::from_loggable(archetype.positions, positions_descr).value_or_throw()
);

if (archetype.colors) {
// TODO: with_methods would be nice
auto colors_descr = rerun::ComponentDescriptor(
"user.CustomArchetype",
"colors",
Loggable<rerun::Color>::Descriptor.component_name
);
auto colors_descr = rerun::Loggable<rerun::Color>::Descriptor
.or_with_archetype_name("user.CustomArchetype")
.or_with_archetype_field_name("colors");
batches.push_back(
ComponentBatch::from_loggable(archetype.colors, colors_descr).value_or_throw()
);
Expand Down
9 changes: 3 additions & 6 deletions docs/snippets/all/tutorials/custom_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ struct rerun::AsComponents<CustomPoints3D> {

// Add custom confidence components if present.
if (archetype.confidences) {
// TODO: with_methods would be nice
auto descriptor = rerun::ComponentDescriptor(
"user.CustomPoints3D",
"confidences",
rerun::Loggable<Confidence>::Descriptor.component_name
);
auto descriptor = rerun::Loggable<Confidence>::Descriptor
.or_with_archetype_name("user.CustomPoints3D")
.or_with_archetype_field_name("confidences");
batches.push_back(
ComponentBatch::from_loggable(*archetype.confidences, descriptor).value_or_throw()
);
Expand Down
2 changes: 0 additions & 2 deletions rerun_cpp/src/rerun/as_components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "indicator_component.hpp"
#include "loggable.hpp"

// TODO: do we need to care about this one? im kinda lost at this point...

namespace rerun {
/// The AsComponents trait is used to convert a type into a list of serialized component.
///
Expand Down
78 changes: 73 additions & 5 deletions rerun_cpp/src/rerun/component_descriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <optional>
#include <string_view>

// TODO: to_string maybe?

namespace rerun {
/// A `ComponentDescriptor` fully describes the semantics of a column of data.
///
Expand Down Expand Up @@ -32,8 +30,6 @@ namespace rerun {
/// Example: `rerun.components.Position3D`.
std::string_view component_name;

// TODO: {entity_path}@{archetype_name}:{component_name}#{archetype_field_name}

constexpr ComponentDescriptor(
std::optional<std::string_view> archetype_name_,
std::optional<std::string_view> archetype_field_name_, std::string_view component_name_
Expand All @@ -56,6 +52,78 @@ namespace rerun {
constexpr ComponentDescriptor(const char* component_name_)
: component_name(component_name_) {}

// TODO: override helpers?
/// Unconditionally sets `archetype_name` to the given one.
ComponentDescriptor with_archetype_name(std::optional<std::string_view> archetype_name_
) const {
ComponentDescriptor descriptor = *this;
descriptor.archetype_name = archetype_name_;
return descriptor;
}

/// Unconditionally sets `archetype_name` to the given one.
ComponentDescriptor with_archetype_name(const char* archetype_name_) const {
ComponentDescriptor descriptor = *this;
descriptor.archetype_name = archetype_name_;
return descriptor;
}

/// Unconditionally sets `archetype_field_name` to the given one.
ComponentDescriptor with_archetype_field_name(
std::optional<std::string_view> archetype_field_name_
) const {
ComponentDescriptor descriptor = *this;
descriptor.archetype_field_name = archetype_field_name_;
return descriptor;
}

/// Unconditionally sets `archetype_field_name` to the given one.
ComponentDescriptor with_archetype_field_name(const char* archetype_field_name_) const {
ComponentDescriptor descriptor = *this;
descriptor.archetype_field_name = archetype_field_name_;
return descriptor;
}

/// Sets `archetype_name` to the given one iff it's not already set.
ComponentDescriptor or_with_archetype_name(std::optional<std::string_view> archetype_name_
) const {
if (this->archetype_field_name.has_value()) {
return *this;
}
ComponentDescriptor descriptor = *this;
descriptor.archetype_name = archetype_name_;
return descriptor;
}

/// Sets `archetype_name` to the given one iff it's not already set.
ComponentDescriptor or_with_archetype_name(const char* archetype_name_) const {
if (this->archetype_field_name.has_value()) {
return *this;
}
ComponentDescriptor descriptor = *this;
descriptor.archetype_name = archetype_name_;
return descriptor;
}

/// Sets `archetype_field_name` to the given one iff it's not already set.
ComponentDescriptor or_with_archetype_field_name(
std::optional<std::string_view> archetype_field_name_
) const {
if (this->archetype_field_name.has_value()) {
return *this;
}
ComponentDescriptor descriptor = *this;
descriptor.archetype_field_name = archetype_field_name_;
return descriptor;
}

/// Sets `archetype_field_name` to the given one iff it's not already set.
ComponentDescriptor or_with_archetype_field_name(const char* archetype_field_name_) const {
if (this->archetype_field_name.has_value()) {
return *this;
}
ComponentDescriptor descriptor = *this;
descriptor.archetype_field_name = archetype_field_name_;
return descriptor;
}
};
} // namespace rerun
3 changes: 0 additions & 3 deletions rerun_cpp/tests/component_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

#define TEST_TAG "[component_type]"

// TODO: should we keep these tests working by having a special constructor for
// ComponentType with just a ComponentName?

SCENARIO("Component type registration" TEST_TAG) {
GIVEN("A valid component type") {
rerun::ComponentType type("test", arrow::float64());
Expand Down

0 comments on commit 74dd688

Please sign in to comment.