File Cylinder.h
File List > src > Cylinder.h
Go to the documentation of this file
// Copyright (c) 2024-2024, Oslandia.
// SPDX-License-Identifier: LGPL-2.0-or-later
#ifndef _SFCGAL_CYLINDER_H_
#define _SFCGAL_CYLINDER_H_
#include "SFCGAL/Kernel.h"
#include "SFCGAL/export.h"
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Surface_mesh.h>
#include <optional>
#include <vector>
namespace SFCGAL {
class SFCGAL_API Cylinder {
public:
using Point_3 = Kernel::Point_3;
using Vector_3 = Kernel::Vector_3;
using Polyhedron_3 = CGAL::Polyhedron_3<Kernel>;
using Surface_mesh = CGAL::Surface_mesh<Point_3>;
Cylinder(const Point_3 &base_center = Point_3(0, 0, 0),
const Vector_3 &axis = Vector_3(0, 0, 1),
const Kernel::FT &radius = 1.0, const Kernel::FT &height = 1.0,
int num_radial = 32);
Cylinder(const Cylinder &other) = default;
Cylinder &
operator=(Cylinder other);
~Cylinder() = default;
void
setBaseCenter(const Point_3 &base_center);
void
setAxis(const Vector_3 &axis);
void
setRadius(const Kernel::FT &radius);
void
setHeight(const Kernel::FT &height);
void
setNumRadial(int num);
const Point_3 &
baseCenter() const
{
return m_base_center;
}
const Vector_3 &
axis() const
{
return m_axis;
}
const Kernel::FT &
radius() const
{
return m_radius;
}
const Kernel::FT &
height() const
{
return m_height;
}
int
numRadial() const
{
return m_num_radial;
}
Polyhedron_3
generatePolyhedron();
Surface_mesh
generateSurfaceMesh();
double
volume() const
{
return CGAL::to_double(m_radius * m_radius * m_height * CGAL_PI);
}
double
area() const
{
return CGAL::to_double(2 * m_radius * m_radius * CGAL_PI +
2 * m_radius * m_height * CGAL_PI);
}
private:
Point_3 m_base_center;
Vector_3 m_axis;
Kernel::FT m_radius;
Kernel::FT m_height;
int m_num_radial;
std::optional<Polyhedron_3> m_polyhedron;
std::optional<Surface_mesh> m_surface_mesh;
void
invalidateCache();
Vector_3
normalize(const Vector_3 &v);
};
} // namespace SFCGAL
#endif // _SFCGAL_CYLINDER_H_