38 #ifndef COAL_GEOMETRIC_SHAPES_HXX
39 #define COAL_GEOMETRIC_SHAPES_HXX
49 template <
typename IndexType>
66 template <
typename IndexType>
68 std::shared_ptr<std::vector<Vec3s>> points_,
unsigned int num_points_) {
69 this->points = points_;
70 this->num_points = num_points_;
71 COAL_ASSERT(this->points->size() == this->num_points,
72 "The number of points is not consistent with the size of the "
75 this->num_normals_and_offsets = 0;
76 this->normals.reset();
77 this->offsets.reset();
78 this->computeCenter();
81 template <
typename IndexType>
83 unsigned int num_points_) {
87 template <
typename IndexType>
92 this->base() = other.
base();
95 this->points = other.
points;
102 this->center = other.
center;
109 template <
typename IndexType>
110 template <
typename OtherIndexType>
113 if (source ==
nullptr || copy ==
nullptr) {
121 if (source->
points !=
nullptr) {
122 copy->
points.reset(
new std::vector<Vec3s>(*source->
points));
129 if (source->
normals !=
nullptr) {
135 if (source->
offsets !=
nullptr) {
148 if (source->
points->size() >=
149 (std::size_t)(std::numeric_limits<OtherIndexType>::max())) {
151 "The source has more points than the max of OtherIndexType.",
156 const std::vector<IndexType>& source_nneighbors = *(source->
nneighbors_);
158 new std::vector<OtherIndexType>(source_nneighbors.size()));
159 std::vector<OtherIndexType>& copy_nneighbors = *(copy->
nneighbors_);
160 for (std::size_t i = 0; i < source_nneighbors.size(); ++i) {
161 copy_nneighbors[i] = OtherIndexType(source_nneighbors[i]);
170 const std::vector<Neighbors>& source_neighbors = *(source->
neighbors);
172 new std::vector<OtherNeighbors>(source_neighbors.size()));
173 std::vector<OtherNeighbors>& copy_neighbors = *(copy->
neighbors);
174 for (std::size_t i = 0; i < source_neighbors.size(); ++i) {
175 copy_neighbors[i].count = source_neighbors[i].count;
176 copy_neighbors[i].begin_id = OtherIndexType(source_neighbors[i].begin_id);
183 template <
typename IndexType>
186 const std::vector<Vec3s>& points_ = *points;
187 for (std::size_t i = 0; i < num_points; ++i)
188 center += points_[i];
189 center /=
Scalar(num_points);
193 template <
typename BV,
typename S>
196 template <
typename IndexType>
198 computeBV<AABB, ConvexBaseTpl<IndexType>>(*
this,
Transform3s(), aabb_local);
199 const Scalar ssr = this->getSweptSphereRadius();
201 aabb_local.min_ -= Vec3s::Constant(ssr);
202 aabb_local.max_ += Vec3s::Constant(ssr);
204 aabb_center = aabb_local.center();
205 aabb_radius = (aabb_local.min_ - aabb_center).norm();
210 template <
typename IndexType>
214 p0 = (*(convex_tri->points))[tri[0]];
215 p1 = (*(convex_tri->points))[tri[1]];
216 p2 = (*(convex_tri->points))[tri[2]];
218 Vec3s barycentre_tri, center_barycenter;
219 barycentre_tri = (p0 + p1 + p2) / 3;
220 center_barycenter = barycentre_tri - convex_tri->center;
222 Vec3s edge_tri1, edge_tri2, n_tri;
225 n_tri = edge_tri1.cross(edge_tri2);
227 if (center_barycenter.dot(n_tri) < 0) {
228 tri.
set(tri[1], tri[0], tri[2]);
Base for convex polytope.
Definition: geometric_shapes.h:691
unsigned int num_points
Definition: geometric_shapes.h:797
std::shared_ptr< std::vector< Vec3s > > normals
An array of the normals of the polygon.
Definition: geometric_shapes.h:800
SupportWarmStartPolytope support_warm_starts
Support warm start polytopes.
Definition: geometric_shapes.h:822
std::shared_ptr< std::vector< Vec3s > > points
An array of the points of the polygon.
Definition: geometric_shapes.h:796
Vec3s center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition: geometric_shapes.h:813
std::shared_ptr< std::vector< Neighbors > > neighbors
Neighbors of each vertex. It is an array of size num_points. For each vertex, it contains the number ...
Definition: geometric_shapes.h:809
NODE_TYPE getNodeType() const
Get node type: a convex polytope.
Definition: geometric_shapes.hxx:50
std::shared_ptr< std::vector< Scalar > > offsets
An array of the offsets to the normals of the polygon. Note: there are as many offsets as normals.
Definition: geometric_shapes.h:803
Base & base()
Cast ConvexBaseTpl to ShapeBase. This method should never be marked as virtual.
Definition: geometric_shapes.h:727
unsigned int num_normals_and_offsets
Definition: geometric_shapes.h:804
std::shared_ptr< std::vector< IndexType > > nneighbors_
Array of indices of the neighbors of each vertex. Since we don't know a priori the number of neighbor...
Definition: geometric_shapes.h:861
Convex polytope.
Definition: convex.h:50
Triangle with 3 indices for points.
Definition: data_types.h:122
void set(IndexType p1, IndexType p2, IndexType p3)
Set the vertex indices of the triangle.
Definition: data_types.h:170
#define COAL_ASSERT(check, message, exception)
Definition: fwd.hh:82
#define COAL_THROW_PRETTY(message, exception)
Definition: fwd.hh:64
@ GEOM_CONVEX32
Definition: collision_object.h:80
@ NODE_COUNT
Definition: collision_object.h:89
@ GEOM_CONVEX16
Definition: collision_object.h:79
Main namespace.
Definition: broadphase_bruteforce.h:44
void computeBV(const S &s, const Transform3s &tf, BV &bv)
calculate a bounding volume for a shape in a specific configuration
Definition: geometric_shapes_utility.h:82
void reorderTriangle(const ConvexTpl< TriangleTpl< IndexType >> *convex_tri, TriangleTpl< IndexType > &tri)
Definition: geometric_shapes.hxx:211
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition: collision_object.h:64
Eigen::Matrix< Scalar, 3, 1 > Vec3s
Definition: data_types.h:70
double Scalar
Definition: data_types.h:68
Definition: geometric_shapes.h:638
bool initialize(MeshCollisionTraversalNode< BV, RelativeTransformationIsIdentity > &node, BVHModel< BV > &model1, Transform3s &tf1, BVHModel< BV > &model2, Transform3s &tf2, CollisionResult &result, bool use_refit=false, bool refit_bottomup=false)
Initialize traversal node for collision between two meshes, given the current transforms.
Definition: traversal_node_setup.h:467