DART  6.7.3
LineSegmentShape.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
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  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_DYNAMICS_LINESEGMENTSHAPE_HPP_
34 #define DART_DYNAMICS_LINESEGMENTSHAPE_HPP_
35 
36 #include "dart/dynamics/Shape.hpp"
37 
38 namespace dart {
39 namespace dynamics {
40 
45 class LineSegmentShape : public Shape
46 {
47 public:
49  LineSegmentShape(float _thickness = 1.0f);
50 
52  LineSegmentShape(const Eigen::Vector3d& _v1, const Eigen::Vector3d& _v2,
53  float _thickness = 1.0f);
54 
55  // Documentation inherited.
56  const std::string& getType() const override;
57 
59  static const std::string& getStaticType();
60 
62  void setThickness(float _thickness);
63 
65  float getThickness() const;
66 
68  std::size_t addVertex(const Eigen::Vector3d& _v);
69 
71  std::size_t addVertex(const Eigen::Vector3d& _v, std::size_t _parent);
72 
78  void removeVertex(std::size_t _idx);
79 
81  void setVertex(std::size_t _idx, const Eigen::Vector3d& _v);
82 
85  const Eigen::Vector3d& getVertex(std::size_t _idx) const;
86 
88  const std::vector<Eigen::Vector3d>& getVertices() const;
89 
91  void addConnection(std::size_t _idx1, std::size_t _idx2);
92 
95  void removeConnection(std::size_t _vertexIdx1, std::size_t _vertexIdx2);
96 
100  void removeConnection(std::size_t _connectionIdx);
101 
104 
107  Eigen::Matrix3d computeInertia(double mass) const override;
108 
109  // TODO(MXG): Consider supporting colors-per-vertex
110 
111 protected:
112  // Documentation inherited.
113  void updateBoundingBox() const override;
114 
115  // Documentation inherited
116  void updateVolume() const override;
117 
119  float mThickness;
120 
122  std::vector<Eigen::Vector3d> mVertices;
123 
126 
129  static const Eigen::Vector3d mDummyVertex;
130 };
131 
132 } // namespace dynamics
133 } // namespace dart
134 
135 #endif // DART_DYNAMICS_LINESEGMENTSHAPE_HPP_
The LineSegmentShape facilitates creating graphs of line segments.
Definition: LineSegmentShape.hpp:46
static const Eigen::Vector3d mDummyVertex
A dummy vertex that can be returned when an out-of-bounds vertex is requested.
Definition: LineSegmentShape.hpp:129
float getThickness() const
Get the line thickness/width used for rendering.
Definition: LineSegmentShape.cpp:107
Eigen::Matrix3d computeInertia(double mass) const override
The returned inertia matrix will be like a very thin cylinder.
Definition: LineSegmentShape.cpp:292
void updateVolume() const override
Updates volume.
Definition: LineSegmentShape.cpp:383
const Eigen::Vector3d & getVertex(std::size_t _idx) const
Get the location of the specified vertex.
Definition: LineSegmentShape.cpp:194
void setThickness(float _thickness)
Set the line thickness/width for rendering.
Definition: LineSegmentShape.cpp:93
float mThickness
Line thickness for rendering.
Definition: LineSegmentShape.hpp:119
std::vector< Eigen::Vector3d > mVertices
Vector of vertices.
Definition: LineSegmentShape.hpp:122
static const std::string & getStaticType()
Returns shape type for this class.
Definition: LineSegmentShape.cpp:86
void updateBoundingBox() const override
Updates bounding box.
Definition: LineSegmentShape.cpp:355
void addConnection(std::size_t _idx1, std::size_t _idx2)
Create a connection between the two specified vertices.
Definition: LineSegmentShape.cpp:221
std::size_t addVertex(const Eigen::Vector3d &_v)
Add a vertex as a child to the last vertex that was added.
Definition: LineSegmentShape.cpp:113
common::aligned_vector< Eigen::Vector2i > mConnections
Vector of connections.
Definition: LineSegmentShape.hpp:125
void removeConnection(std::size_t _vertexIdx1, std::size_t _vertexIdx2)
Search for a connection between two vertices and break it if it exists.
Definition: LineSegmentShape.cpp:243
LineSegmentShape(float _thickness=1.0f)
Default constructor.
Definition: LineSegmentShape.cpp:44
const std::string & getType() const override
Returns a string representing the shape type.
Definition: LineSegmentShape.cpp:80
void removeVertex(std::size_t _idx)
Remove a vertex from the list of vertices.
Definition: LineSegmentShape.cpp:152
void setVertex(std::size_t _idx, const Eigen::Vector3d &_v)
Change the location of the specified vertex.
Definition: LineSegmentShape.cpp:174
const std::vector< Eigen::Vector3d > & getVertices() const
Get all the vertices.
Definition: LineSegmentShape.cpp:215
const common::aligned_vector< Eigen::Vector2i > & getConnections() const
Get all the connections.
Definition: LineSegmentShape.cpp:286
Definition: Shape.hpp:53
std::vector< _Tp, Eigen::aligned_allocator< _Tp > > aligned_vector
Definition: Memory.hpp:66
Definition: BulletCollisionDetector.cpp:63