| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Software License Agreement (BSD License) | ||
| 3 | * | ||
| 4 | * Copyright (c) 2011-2014, Willow Garage, Inc. | ||
| 5 | * Copyright (c) 2014-2015, Open Source Robotics Foundation | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * * Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * * Redistributions in binary form must reproduce the above | ||
| 15 | * copyright notice, this list of conditions and the following | ||
| 16 | * disclaimer in the documentation and/or other materials provided | ||
| 17 | * with the distribution. | ||
| 18 | * * Neither the name of Open Source Robotics Foundation nor the names of its | ||
| 19 | * contributors may be used to endorse or promote products derived | ||
| 20 | * from this software without specific prior written permission. | ||
| 21 | * | ||
| 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 33 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | */ | ||
| 35 | |||
| 36 | /** \author Jia Pan */ | ||
| 37 | |||
| 38 | #ifndef COAL_SHAPE_CONVEX_H | ||
| 39 | #define COAL_SHAPE_CONVEX_H | ||
| 40 | |||
| 41 | #include "coal/shape/geometric_shapes.h" | ||
| 42 | #include <iostream> | ||
| 43 | |||
| 44 | namespace coal { | ||
| 45 | |||
| 46 | /// @brief Convex polytope | ||
| 47 | /// @tparam PolygonT the polygon class. It must have method \c size() and | ||
| 48 | /// \c operator[](int i) | ||
| 49 | template <typename PolygonT> | ||
| 50 | class ConvexTpl : public ConvexBaseTpl<typename PolygonT::IndexType> { | ||
| 51 | public: | ||
| 52 | typedef typename PolygonT::IndexType IndexType; | ||
| 53 | typedef ConvexBaseTpl<IndexType> Base; | ||
| 54 | typedef typename Base::Neighbors Neighbors; | ||
| 55 | |||
| 56 | using Base::neighbors; | ||
| 57 | using Base::num_points; | ||
| 58 | using Base::points; | ||
| 59 | |||
| 60 | /// @brief Construct an uninitialized convex object | ||
| 61 | 61253 | ConvexTpl() : Base(), num_polygons(0) {} | |
| 62 | |||
| 63 | 122776 | ~ConvexTpl() {} | |
| 64 | |||
| 65 | /// @brief Constructing a convex, providing normal and offset of each polytype | ||
| 66 | /// surface, and the points and shape topology information | ||
| 67 | /// \param points_ list of 3D points | ||
| 68 | /// \param num_points_ number of 3D points | ||
| 69 | /// \param polygons_ \copydoc Convex::polygons | ||
| 70 | /// \param num_polygons_ the number of polygons. | ||
| 71 | /// \note num_polygons_ is not the allocated size of polygons_. | ||
| 72 | ConvexTpl(std::shared_ptr<std::vector<Vec3s>> points_, | ||
| 73 | unsigned int num_points_, | ||
| 74 | std::shared_ptr<std::vector<PolygonT>> polygons_, | ||
| 75 | unsigned int num_polygons_); | ||
| 76 | |||
| 77 | /// @brief Cast Convex to ConvexBaseTpl. | ||
| 78 | /// This method should never be marked as virtual | ||
| 79 | 18 | Base &base() { return static_cast<Base &>(*this); } | |
| 80 | |||
| 81 | /// @brief Const cast Convex to ConvexBaseTpl. | ||
| 82 | /// This method should never be marked as virtual | ||
| 83 | 18 | const Base &base() const { return static_cast<const Base &>(*this); } | |
| 84 | |||
| 85 | /// @brief Copy constructor. | ||
| 86 | /// The copy constructor only shallow copies the data (it copies the shared | ||
| 87 | /// pointers but does not deep clones the data). | ||
| 88 |
1/2✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
|
18 | ConvexTpl(const ConvexTpl &other) { *this = other; } |
| 89 | |||
| 90 | /// @brief Copy operator. | ||
| 91 | /// The copy operator only shallow copies the data (it copies the shared | ||
| 92 | /// pointers but does not deep clones the data). | ||
| 93 | ConvexTpl &operator=(const ConvexTpl &other); | ||
| 94 | |||
| 95 | // Clone (deep copy). | ||
| 96 | COAL_DEPRECATED_MESSAGE(Use deepcopy instead.) | ||
| 97 | 2 | ConvexTpl *clone() const override { return this->deepcopy(); }; | |
| 98 | |||
| 99 | // Deep copy of a Convex. | ||
| 100 | // This method deep copies every field of the class. | ||
| 101 | 1 | ConvexTpl *deepcopy() const override { | |
| 102 |
0/4✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1 | ConvexTpl *copy = new ConvexTpl(); |
| 103 | 1 | deepcopy(this, copy); | |
| 104 | 1 | return copy; | |
| 105 | } | ||
| 106 | |||
| 107 | /// @brief Cast this Convex vertex indices to OtherIndexType. | ||
| 108 | /// This effectively deep copies this Convex into a new one. | ||
| 109 | template <typename OtherPolygonT> | ||
| 110 | 1 | ConvexTpl<OtherPolygonT> cast() const { | |
| 111 | 1 | ConvexTpl<OtherPolygonT> res; | |
| 112 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | deepcopy(this, &res); |
| 113 | 1 | return res; | |
| 114 | ✗ | } | |
| 115 | |||
| 116 | /// based on http://number-none.com/blow/inertia/bb_inertia.doc | ||
| 117 | virtual Matrix3s computeMomentofInertia() const override; | ||
| 118 | |||
| 119 | virtual Vec3s computeCOM() const override; | ||
| 120 | |||
| 121 | virtual Scalar computeVolume() const override; | ||
| 122 | |||
| 123 | /// | ||
| 124 | /// @brief Set the current Convex from a list of points and polygons. | ||
| 125 | /// | ||
| 126 | /// \param points list of 3D points | ||
| 127 | /// \param num_points number of 3D points | ||
| 128 | /// \param polygons \copydoc Convex::polygons | ||
| 129 | /// \param num_polygons the number of polygons. | ||
| 130 | /// \note num_polygons is not the allocated size of polygons. | ||
| 131 | /// | ||
| 132 | void set(std::shared_ptr<std::vector<Vec3s>> points, unsigned int num_points, | ||
| 133 | std::shared_ptr<std::vector<PolygonT>> polygons, | ||
| 134 | unsigned int num_polygons); | ||
| 135 | |||
| 136 | /// @brief An array of PolygonT object. | ||
| 137 | /// PolygonT should contains a list of vertices for each polygon, | ||
| 138 | /// in counter clockwise order. | ||
| 139 | std::shared_ptr<std::vector<PolygonT>> polygons; | ||
| 140 | unsigned int num_polygons; | ||
| 141 | |||
| 142 | protected: | ||
| 143 | void fillNeighbors(); | ||
| 144 | |||
| 145 | // Deep copy of a Convex. | ||
| 146 | // This method deep copies every field of the class. | ||
| 147 | template <typename OtherPolygonT> | ||
| 148 | static void deepcopy(const ConvexTpl<PolygonT> *source, | ||
| 149 | ConvexTpl<OtherPolygonT> *copy); | ||
| 150 | |||
| 151 | using Base::nneighbors_; | ||
| 152 | }; | ||
| 153 | |||
| 154 | typedef ConvexTpl<Triangle16> Convex16; | ||
| 155 | typedef ConvexTpl<Triangle32> Convex32; | ||
| 156 | |||
| 157 | } // namespace coal | ||
| 158 | |||
| 159 | #include "coal/shape/convex.hxx" | ||
| 160 | |||
| 161 | #endif | ||
| 162 |