Skip to content

File PointCloud.h

File List > include > point_cloud > PointCloud.h

Go to the documentation of this file

#pragma once

#include <vector>
#include <iostream>

#include "../mesh/Vector3D.h"
#include "serializer/ObjSerializer.h"

namespace Argos {

    class PointCloud
    {
    private:
        std::vector<Vector3D<double>> m_points;

    public:
        PointCloud() = default;

        explicit PointCloud(const std::vector<Vector3D<double>>& points) : m_points(points) {}

        const std::vector<Vector3D<double>>& getPoints() const {
            return m_points;
        }

        std::size_t size() const {
            return m_points.size();
        }

        bool empty() const {
            return m_points.empty();
        }

        void addPoint(const Vector3D<double>& p) {
            m_points.push_back(p);
        }

        void reserve(std::size_t n) {
            m_points.reserve(n);
        }

        void clear() {
            m_points.clear();
        }

        void print(std::ostream& os = std::cout) const {
            os << "PointCloud (" << m_points.size() << " points)" << std::endl;
            for (const auto& p : m_points) {
                os << p << std::endl;
            }
        }

        void saveAsObj(std::ostream &filename) const {
            ObjSerializer serializer;
            serializer.serialize(
                m_points,
                std::vector<Face>(),   // DEBUG : pas de faces ?
                filename
            );
        }
    };

} // namespace Argos