Caribou
SphereIsoSurface.h
1 #pragma once
2 
3 #include <sofa/defaulttype/VecTypes.h>
4 #include <SofaCaribou/Topology/IsoSurface.h>
5 
6 namespace SofaCaribou::topology {
7 
8 class SphereIsoSurface : public IsoSurface<sofa::defaulttype::Vec3Types> {
9  template < class T = void* >
10  using Data = sofa::core::objectmodel::Data<T>;
12  using Base::Coord;
13  using Base::Real;
14 public:
15 
17  : p_radius(initData(&p_radius, 1., "radius", "Radius of the sphere."))
18  , p_center(initData(&p_center, Coord(0, 0, 0), "center", "Coordinates at the center of the sphere."))
19  {}
20 
21  inline Real iso_value(const Eigen::Matrix<Real, 3, 1> & x) const final {
22  const auto & r = p_radius.getValue();
23  Eigen::Map<const Eigen::Matrix<Real, 3, 1>> c (p_center.getValue().data());
24 
25  const auto d = (x-c).dot(x-c);
26  return d - r*r;
27  }
28 
29 private:
30  Data<Real> p_radius;
31  Data<Coord> p_center;
32 };
33 
34 }
SofaCaribou::topology::IsoSurface
Definition: IsoSurface.h:9
SofaCaribou::topology::SphereIsoSurface
Definition: SphereIsoSurface.h:8