1#ifndef PLUGINSPHEROIDMANAGER_HPP
2#define PLUGINSPHEROIDMANAGER_HPP
11#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
12#include <CGAL/point_generators_3.h>
13#include <CGAL/algorithm.h>
14#include <CGAL/Polyhedron_3.h>
15#include <CGAL/convex_hull_3.h>
16#include <CGAL/intersections.h>
21typedef CGAL::Exact_predicates_inexact_constructions_kernel
K;
35 Polyhedron_3::Halfedge_handle h = f.halfedge();
36 return Polyhedron_3::Plane_3(h->vertex()->point(),
37 h->next()->vertex()->point(),
38 h->opposite()->vertex()->point());
54 template<
typename cell_t>
71 inline static double Kernel(
const double x) {
return exp(-
pow(x, 2) / 2.) /
sqrt(2. * M_PI); }
82 double max = - INFINITY;
83 for (
auto &c : cells) {
84 r = (c->getBody().getPosition() -
centroid).length();
85 c->getBody().setDistanceFromCentroid(r);
87 points.
push_back(
Point_3(c->getBody().getPosition().x(), c->getBody().getPosition().y(), c->getBody().getPosition().z()));
98 CGAL::convex_hull_3(points.
begin(), points.
end(), poly);
100 if (poly.size_of_vertices() > 5) {
101 std::transform(poly.facets_begin(), poly.facets_end(), poly.planes_begin(),
PlaneFromFacet());
103 for (
auto &c : cells) {
104 Point_3 pCell =
Point_3(c->getBody().getPosition().x(), c->getBody().getPosition().y(),
105 c->getBody().getPosition().z());
107 Polyhedron_3::Plane_iterator pit;
108 double min = INFINITY;
109 for (pit = poly.planes_begin(); pit != poly.planes_end(); ++pit) {
110 auto result = CGAL::intersection((*pit), lCellCentroid);
112 const Point_3 *p = boost::get<Point_3>(&*result);
113 double dist = CGAL::squared_distance(pCell,(*p));
119 c->getBody().setDistanceFromCentroid( c->getBody().getDistanceFromCentroid() *
optimRad /
120 (c->getBody().getDistanceFromCentroid() +
sqrt(min) ));
133 double maxDensity = -1.;
134 double xMaxDensity = -1.;
138 for (
double i = 0.; i <= max; i += 0.2) {
140 for (
size_t j = 0; j < data.
size(); ++j) {
141 sum +=
Kernel((i - data[j]) / lambda);
144 if (val > maxDensity) {
149 return (max - (max - xMaxDensity) / 2 +
meanRadius);
160 for (
auto &c : cells) {
161 centroid += c->getBody().getPosition();
205 if (cells.
size() > 5) {
219 template<
typename world_t>
232 template<
typename world_t>
CGAL::Exact_predicates_inexact_constructions_kernel K
CGAL::Polyhedron_3< K > Polyhedron_3
general purpose 3D vector/point class.
Class for managing spheroid bodies.
void updateDistanceFromCentroid(std::vector< cell_t * > cells)
Updates the distance from centroid for each cell.
MecaCell::Vec computeCentroid(std::vector< cell_t * > cells)
Computes the centroid position.
void preBehaviorUpdate(world_t *w)
Pre-behavior update hook for MecaCell.
MecaCell::Vec getCentroid() const
Gets the centroid.
std::vector< double > Data
static double Kernel(const double x)
Gaussian probability density function.
double getOptimalRadius(const Data &data, double max)
Computes the optimal radius.
void setMeanRadius(double r)
Sets the mean radius.
double getSpheroidRadius() const
Gets the spheroid radius.
void updateSpheroid(std::vector< cell_t * > cells)
Computes everything for the spheroid.
void initSpheroid(world_t *w)
Init function to be called on scenario init.
PluginSpheroidManager(double r)
Constructor with mean radius.
PluginSpheroidManager()=default
Default constructor.
void push_back(const T &value)
Adds an element to the end of the vector.
iterator begin()
Returns an iterator to the first element.
iterator end()
Returns an iterator to the last element.
size_t size() const
Returns the number of elements in the vector.
Vector3D Vec
alias for Vector3D
Namespace for spheroid manager-related classes and functions.
double sqrt(double x)
Computes the square root of a number.
double exp(double x)
Computes the exponential function of a number.
double pow(double base, double exponent)
Computes the power of a number.
Functor computing the plane containing a triangular facet.
Polyhedron_3::Plane_3 operator()(Polyhedron_3::Facet &f)