// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
// Based on "crates/store/re_types/definitions/rerun/archetypes/transform3d.fbs".

#include "transform3d.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    Transform3D Transform3D::clear_fields() {
        auto archetype = Transform3D();
        archetype.translation =
            ComponentBatch::empty<rerun::components::Translation3D>(Descriptor_translation)
                .value_or_throw();
        archetype.rotation_axis_angle = ComponentBatch::empty<rerun::components::RotationAxisAngle>(
                                            Descriptor_rotation_axis_angle
        )
                                            .value_or_throw();
        archetype.quaternion =
            ComponentBatch::empty<rerun::components::RotationQuat>(Descriptor_quaternion)
                .value_or_throw();
        archetype.scale =
            ComponentBatch::empty<rerun::components::Scale3D>(Descriptor_scale).value_or_throw();
        archetype.mat3x3 =
            ComponentBatch::empty<rerun::components::TransformMat3x3>(Descriptor_mat3x3)
                .value_or_throw();
        archetype.relation =
            ComponentBatch::empty<rerun::components::TransformRelation>(Descriptor_relation)
                .value_or_throw();
        archetype.child_frame =
            ComponentBatch::empty<rerun::components::TransformFrameId>(Descriptor_child_frame)
                .value_or_throw();
        archetype.parent_frame =
            ComponentBatch::empty<rerun::components::TransformFrameId>(Descriptor_parent_frame)
                .value_or_throw();
        archetype.axis_length =
            ComponentBatch::empty<rerun::components::AxisLength>(Descriptor_axis_length)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> Transform3D::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(9);
        if (translation.has_value()) {
            columns.push_back(translation.value().partitioned(lengths_).value_or_throw());
        }
        if (rotation_axis_angle.has_value()) {
            columns.push_back(rotation_axis_angle.value().partitioned(lengths_).value_or_throw());
        }
        if (quaternion.has_value()) {
            columns.push_back(quaternion.value().partitioned(lengths_).value_or_throw());
        }
        if (scale.has_value()) {
            columns.push_back(scale.value().partitioned(lengths_).value_or_throw());
        }
        if (mat3x3.has_value()) {
            columns.push_back(mat3x3.value().partitioned(lengths_).value_or_throw());
        }
        if (relation.has_value()) {
            columns.push_back(relation.value().partitioned(lengths_).value_or_throw());
        }
        if (child_frame.has_value()) {
            columns.push_back(child_frame.value().partitioned(lengths_).value_or_throw());
        }
        if (parent_frame.has_value()) {
            columns.push_back(parent_frame.value().partitioned(lengths_).value_or_throw());
        }
        if (axis_length.has_value()) {
            columns.push_back(axis_length.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> Transform3D::columns() {
        if (translation.has_value()) {
            return columns(std::vector<uint32_t>(translation.value().length(), 1));
        }
        if (rotation_axis_angle.has_value()) {
            return columns(std::vector<uint32_t>(rotation_axis_angle.value().length(), 1));
        }
        if (quaternion.has_value()) {
            return columns(std::vector<uint32_t>(quaternion.value().length(), 1));
        }
        if (scale.has_value()) {
            return columns(std::vector<uint32_t>(scale.value().length(), 1));
        }
        if (mat3x3.has_value()) {
            return columns(std::vector<uint32_t>(mat3x3.value().length(), 1));
        }
        if (relation.has_value()) {
            return columns(std::vector<uint32_t>(relation.value().length(), 1));
        }
        if (child_frame.has_value()) {
            return columns(std::vector<uint32_t>(child_frame.value().length(), 1));
        }
        if (parent_frame.has_value()) {
            return columns(std::vector<uint32_t>(parent_frame.value().length(), 1));
        }
        if (axis_length.has_value()) {
            return columns(std::vector<uint32_t>(axis_length.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

    Result<Collection<ComponentBatch>> AsComponents<archetypes::Transform3D>::as_batches(
        const archetypes::Transform3D& archetype
    ) {
        using namespace archetypes;
        std::vector<ComponentBatch> cells;
        cells.reserve(9);

        if (archetype.translation.has_value()) {
            cells.push_back(archetype.translation.value());
        }
        if (archetype.rotation_axis_angle.has_value()) {
            cells.push_back(archetype.rotation_axis_angle.value());
        }
        if (archetype.quaternion.has_value()) {
            cells.push_back(archetype.quaternion.value());
        }
        if (archetype.scale.has_value()) {
            cells.push_back(archetype.scale.value());
        }
        if (archetype.mat3x3.has_value()) {
            cells.push_back(archetype.mat3x3.value());
        }
        if (archetype.relation.has_value()) {
            cells.push_back(archetype.relation.value());
        }
        if (archetype.child_frame.has_value()) {
            cells.push_back(archetype.child_frame.value());
        }
        if (archetype.parent_frame.has_value()) {
            cells.push_back(archetype.parent_frame.value());
        }
        if (archetype.axis_length.has_value()) {
            cells.push_back(archetype.axis_length.value());
        }

        return rerun::take_ownership(std::move(cells));
    }
} // namespace rerun
