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

#include "instance_poses3d.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    InstancePoses3D InstancePoses3D::clear_fields() {
        auto archetype = InstancePoses3D();
        archetype.translations =
            ComponentBatch::empty<rerun::components::Translation3D>(Descriptor_translations)
                .value_or_throw();
        archetype.rotation_axis_angles =
            ComponentBatch::empty<rerun::components::RotationAxisAngle>(
                Descriptor_rotation_axis_angles
            )
                .value_or_throw();
        archetype.quaternions =
            ComponentBatch::empty<rerun::components::RotationQuat>(Descriptor_quaternions)
                .value_or_throw();
        archetype.scales =
            ComponentBatch::empty<rerun::components::Scale3D>(Descriptor_scales).value_or_throw();
        archetype.mat3x3 =
            ComponentBatch::empty<rerun::components::TransformMat3x3>(Descriptor_mat3x3)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> InstancePoses3D::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(5);
        if (translations.has_value()) {
            columns.push_back(translations.value().partitioned(lengths_).value_or_throw());
        }
        if (rotation_axis_angles.has_value()) {
            columns.push_back(rotation_axis_angles.value().partitioned(lengths_).value_or_throw());
        }
        if (quaternions.has_value()) {
            columns.push_back(quaternions.value().partitioned(lengths_).value_or_throw());
        }
        if (scales.has_value()) {
            columns.push_back(scales.value().partitioned(lengths_).value_or_throw());
        }
        if (mat3x3.has_value()) {
            columns.push_back(mat3x3.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> InstancePoses3D::columns() {
        if (translations.has_value()) {
            return columns(std::vector<uint32_t>(translations.value().length(), 1));
        }
        if (rotation_axis_angles.has_value()) {
            return columns(std::vector<uint32_t>(rotation_axis_angles.value().length(), 1));
        }
        if (quaternions.has_value()) {
            return columns(std::vector<uint32_t>(quaternions.value().length(), 1));
        }
        if (scales.has_value()) {
            return columns(std::vector<uint32_t>(scales.value().length(), 1));
        }
        if (mat3x3.has_value()) {
            return columns(std::vector<uint32_t>(mat3x3.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.translations.has_value()) {
            cells.push_back(archetype.translations.value());
        }
        if (archetype.rotation_axis_angles.has_value()) {
            cells.push_back(archetype.rotation_axis_angles.value());
        }
        if (archetype.quaternions.has_value()) {
            cells.push_back(archetype.quaternions.value());
        }
        if (archetype.scales.has_value()) {
            cells.push_back(archetype.scales.value());
        }
        if (archetype.mat3x3.has_value()) {
            cells.push_back(archetype.mat3x3.value());
        }

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