Program Listing for File support_functions.h

Return to documentation for file (include/coal/narrowphase/support_functions.h)

/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2011-2014, Willow Garage, Inc.
 *  Copyright (c) 2014-2015, Open Source Robotics Foundation
 *  Copyright (c) 2021-2024, INRIA
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Open Source Robotics Foundation nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef COAL_SUPPORT_FUNCTIONS_H
#define COAL_SUPPORT_FUNCTIONS_H

#include "coal/shape/geometric_shapes.h"
#include "coal/math/transform.h"
#include "coal/collision_data.h"
#include "coal/narrowphase/support_data.h"

namespace coal {
namespace details {

// ============================================================================
// ============================ SUPPORT FUNCTIONS =============================
// ============================================================================
template <int _SupportOptions = SupportOptions::NoSweptSphere>
Vec3s getSupport(const ShapeBase* shape, const Vec3s& dir, int& hint);

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupport(const TriangleP* triangle, const Vec3s& dir,
                     Vec3s& support, int& /*unused*/,
                     ShapeSupportData& /*unused*/);

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupport(const Box* box, const Vec3s& dir, Vec3s& support,
                     int& /*unused*/, ShapeSupportData& /*unused*/);

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupport(const Sphere* sphere, const Vec3s& dir, Vec3s& support,
                     int& /*unused*/, ShapeSupportData& /*unused*/);

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupport(const Ellipsoid* ellipsoid, const Vec3s& dir,
                     Vec3s& support, int& /*unused*/,
                     ShapeSupportData& /*unused*/);

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupport(const Capsule* capsule, const Vec3s& dir, Vec3s& support,
                     int& /*unused*/, ShapeSupportData& /*unused*/);

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupport(const Cone* cone, const Vec3s& dir, Vec3s& support,
                     int& /*unused*/, ShapeSupportData& /*unused*/);

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupport(const Cylinder* cylinder, const Vec3s& dir, Vec3s& support,
                     int& /*unused*/, ShapeSupportData& /*unused*/);

template <int _SupportOptions = SupportOptions::NoSweptSphere,
          typename IndexType>
void getShapeSupport(const ConvexBaseTpl<IndexType>* convex, const Vec3s& dir,
                     Vec3s& support, int& hint, ShapeSupportData& /*unused*/);

template <typename IndexType>
struct LargeConvex : ConvexBaseTpl<IndexType> {};
typedef LargeConvex<Triangle16::IndexType> LargeConvex16;
typedef LargeConvex<Triangle32::IndexType> LargeConvex32;

template <typename IndexType>
struct SmallConvex : ConvexBaseTpl<IndexType> {};
typedef SmallConvex<Triangle16::IndexType> SmallConvex16;
typedef SmallConvex<Triangle32::IndexType> SmallConvex32;

template <int _SupportOptions = SupportOptions::NoSweptSphere,
          typename IndexType>
void getShapeSupport(const SmallConvex<IndexType>* convex, const Vec3s& dir,
                     Vec3s& support, int& hint, ShapeSupportData& data);

template <int _SupportOptions = SupportOptions::NoSweptSphere,
          typename IndexType>
void getShapeSupport(const LargeConvex<IndexType>* convex, const Vec3s& dir,
                     Vec3s& support, int& hint, ShapeSupportData& support_data);

// ============================================================================
// ========================== SUPPORT SET FUNCTIONS ===========================
// ============================================================================
template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getSupportSet(const ShapeBase* shape, SupportSet& support_set, int& hint,
                   size_t num_sampled_supports = 6, Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getSupportSet(const ShapeBase* shape, const Vec3s& dir,
                   SupportSet& support_set, int& hint,
                   size_t num_sampled_supports = 6, Scalar tol = Scalar(1e-3)) {
  support_set.tf.rotation() = constructOrthonormalBasisFromVector(dir);
  const Vec3s& support_dir = support_set.getNormal();
  const Vec3s support = getSupport<_SupportOptions>(shape, support_dir, hint);
  getSupportSet<_SupportOptions>(shape, support_set, hint, num_sampled_supports,
                                 tol);
}

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupportSet(const TriangleP* triangle, SupportSet& support_set,
                        int& /*unused*/, ShapeSupportData& /*unused*/,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupportSet(const Box* box, SupportSet& support_set,
                        int& /*unused*/, ShapeSupportData& support_data,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupportSet(const Sphere* sphere, SupportSet& support_set,
                        int& /*unused*/, ShapeSupportData& /*unused*/,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar /*unused*/ tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupportSet(const Ellipsoid* ellipsoid, SupportSet& support_set,
                        int& /*unused*/, ShapeSupportData& /*unused*/,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar /*unused*/ tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupportSet(const Capsule* capsule, SupportSet& support_set,
                        int& /*unused*/, ShapeSupportData& /*unused*/,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupportSet(const Cone* cone, SupportSet& support_set,
                        int& /*unused*/, ShapeSupportData& /*unused*/,
                        size_t num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere>
void getShapeSupportSet(const Cylinder* cylinder, SupportSet& support_set,
                        int& /*unused*/, ShapeSupportData& /*unused*/,
                        size_t num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere,
          typename IndexType>
void getShapeSupportSet(const ConvexBaseTpl<IndexType>* convex,
                        SupportSet& support_set, int& hint,
                        ShapeSupportData& support_data,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere,
          typename IndexType>
void getShapeSupportSet(const SmallConvex<IndexType>* convex,
                        SupportSet& support_set, int& /*unused*/,
                        ShapeSupportData& /*unused*/,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

template <int _SupportOptions = SupportOptions::NoSweptSphere,
          typename IndexType>
void getShapeSupportSet(const LargeConvex<IndexType>* convex,
                        SupportSet& support_set, int& hint,
                        ShapeSupportData& support_data,
                        size_t /*unused*/ num_sampled_supports = 6,
                        Scalar tol = Scalar(1e-3));

COAL_DLLAPI void computeSupportSetConvexHull(SupportSet::Polygon& cloud,
                                             SupportSet::Polygon& cvx_hull);

}  // namespace details
}  // namespace coal

#endif  // COAL_SUPPORT_FUNCTIONS_H