DGtalTools  1.2.0
shape.h
1 #pragma once
2 
3 #include <DGtal/base/Common.h>
4 #include <DGtal/math/linalg/EigenSupport.h>
5 
7 {
8  typedef DGtal::Z3i::Point Point;
9  typedef Eigen::Vector3d Vector;
10  typedef Eigen::Matrix3d Matrix;
11 
12  RoundedCubeShape(const Matrix& transform_, const double& size_, const double& radius_) : transform(transform_), size(size_), radius(radius_)
13  {
14  ASSERT( radius < size );
15  }
16 
17  bool operator()(const Point& point) const
18  {
19  const Vector vector_(point[0], point[1], point[2]);
20  Vector vector = transform*vector_;
21  vector = vector.cwiseAbs();
22  if (vector.maxCoeff() <= size-radius) return true;
23  Vector projected = vector;
24  for (int kk=0; kk<projected.size(); kk++)
25  if (projected[kk] > size-radius)
26  projected[kk] = size-radius;
27  return (vector-projected).norm() <= radius;
28  }
29 
31  double size;
32  double radius;
33 };
34 
35 struct TorusShape
36 {
37  typedef DGtal::Z3i::Point Point;
38  typedef Eigen::Vector3d Vector;
39  typedef Eigen::Matrix3d Matrix;
40 
41  TorusShape(const Matrix& transform_, const double& radius_large_, const double& radius_small_) : transform(transform_), radius_large(radius_large_), radius_small(radius_small_)
42  {
43  ASSERT( radius_small < radius_large );
44  }
45 
46  bool operator()(const Point& point) const
47  {
48  const Vector vector_(point[0], point[1], point[2]);
49  const Vector vector = transform*vector_;
50  Vector projected = vector;
51  projected[1] = 0;
52  if (projected.norm() == 0) return false;
53  projected *= radius_large/projected.norm();
54  return (vector-projected).norm() <= radius_small;
55  }
56 
58  double radius_large;
59  double radius_small;
60 };
61 
63 {
64  typedef DGtal::Z3i::Point Point;
65  typedef DGtal::Z3i::RealPoint RealPoint;
66 
67  SphereShape(const double& radius_, const RealPoint& center_) : radius(radius_), center(center_)
68  {
69  }
70 
71  bool operator()(const Point& point) const
72  {
73  return (point-center).norm() <= radius;
74  }
75 
76  double radius;
78 };
79 
81 {
82  typedef DGtal::Z3i::Point Point;
83  typedef DGtal::Z3i::RealPoint RealPoint;
84 
85  CapsuleShape(const double& radius_, const double& length_, const RealPoint& direction_) : radius(radius_), length(length_), direction(direction_)
86  {
87  if (direction.norm() > 0) direction /= direction.norm();
88  }
89 
90  bool operator()(const Point& point) const
91  {
92  double alpha = direction.dot(point);
93  if (alpha > length/2) alpha = length/2;
94  if (alpha < -length/2) alpha = -length/2;
95  return (point-alpha*direction).norm() <= radius;
96  }
97 
98  double radius;
99  double length;
101 };
102 
103 template <typename ImageType>
105 {
106  typedef typename ImageType::Point Point;
107  typedef Eigen::Vector3d Vector;
108  typedef Eigen::Matrix3d Matrix;
109 
110  ImageShape(const ImageType* image_, const Point& shift_) : image(image_), shift(shift_)
111  {
112  ASSERT( image );
113  }
114 
115  bool operator()(const Point& point_) const
116  {
117  const Point point = point_+shift;
118  if (!image->domain().isInside(point)) return false;
119  return (*image)(point) > 0;
120  }
121 
122  const ImageType* image;
124 };
125 
127 {
128  typedef DGtal::Z3i::Point Point;
129  typedef DGtal::Z3i::RealPoint RealPoint;
130 
131  PlaneShape(const RealPoint& normal_) : normal(normal_)
132  {
133  }
134 
135  bool operator()(const Point& point) const
136  {
137  return normal.dot(point) <= 0;
138  }
139 
141 };
CapsuleShape(const double &radius_, const double &length_, const RealPoint &direction_)
Definition: shape.h:85
double radius
Definition: shape.h:98
double length
Definition: shape.h:99
bool operator()(const Point &point) const
Definition: shape.h:90
DGtal::Z3i::Point Point
Definition: shape.h:82
RealPoint direction
Definition: shape.h:100
DGtal::Z3i::RealPoint RealPoint
Definition: shape.h:83
const ImageType * image
Definition: shape.h:122
ImageShape(const ImageType *image_, const Point &shift_)
Definition: shape.h:110
ImageType::Point Point
Definition: shape.h:106
Eigen::Matrix3d Matrix
Definition: shape.h:108
bool operator()(const Point &point_) const
Definition: shape.h:115
Eigen::Vector3d Vector
Definition: shape.h:107
Point shift
Definition: shape.h:123
DGtal::Z3i::Point Point
Definition: shape.h:128
DGtal::Z3i::RealPoint RealPoint
Definition: shape.h:129
PlaneShape(const RealPoint &normal_)
Definition: shape.h:131
RealPoint normal
Definition: shape.h:140
bool operator()(const Point &point) const
Definition: shape.h:135
bool operator()(const Point &point) const
Definition: shape.h:17
Eigen::Matrix3d Matrix
Definition: shape.h:10
Eigen::Vector3d Vector
Definition: shape.h:9
double radius
Definition: shape.h:32
double size
Definition: shape.h:31
DGtal::Z3i::Point Point
Definition: shape.h:8
RoundedCubeShape(const Matrix &transform_, const double &size_, const double &radius_)
Definition: shape.h:12
Matrix transform
Definition: shape.h:30
DGtal::Z3i::RealPoint RealPoint
Definition: shape.h:65
RealPoint center
Definition: shape.h:77
DGtal::Z3i::Point Point
Definition: shape.h:64
SphereShape(const double &radius_, const RealPoint &center_)
Definition: shape.h:67
double radius
Definition: shape.h:76
bool operator()(const Point &point) const
Definition: shape.h:71
double radius_small
Definition: shape.h:59
Matrix transform
Definition: shape.h:57
bool operator()(const Point &point) const
Definition: shape.h:46
DGtal::Z3i::Point Point
Definition: shape.h:37
Eigen::Matrix3d Matrix
Definition: shape.h:39
TorusShape(const Matrix &transform_, const double &radius_large_, const double &radius_small_)
Definition: shape.h:41
double radius_large
Definition: shape.h:58
Eigen::Vector3d Vector
Definition: shape.h:38