link_model.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
41 
42 namespace moveit
43 {
44 namespace core
45 {
46 LinkModel::LinkModel(const std::string& name)
47  : name_(name)
48  , parent_joint_model_(NULL)
49  , parent_link_model_(NULL)
50  , is_parent_joint_fixed_(false)
51  , joint_origin_transform_is_identity_(true)
52  , first_collision_body_transform_index_(-1)
53  , link_index_(-1)
54 {
55  joint_origin_transform_.setIdentity();
56 }
57 
59 {
60 }
61 
62 void LinkModel::setJointOriginTransform(const Eigen::Affine3d& transform)
63 {
64  joint_origin_transform_ = transform;
66  joint_origin_transform_.rotation().isIdentity() &&
67  joint_origin_transform_.translation().norm() < std::numeric_limits<double>::epsilon();
68 }
69 
71 {
72  parent_joint_model_ = joint;
74 }
75 
76 void LinkModel::setGeometry(const std::vector<shapes::ShapeConstPtr>& shapes, const EigenSTL::vector_Affine3d& origins)
77 {
78  shapes_ = shapes;
81 
82  core::AABB aabb;
83 
84  for (std::size_t i = 0; i < shapes_.size(); ++i)
85  {
87  (collision_origin_transform_[i].rotation().isIdentity() &&
88  collision_origin_transform_[i].translation().norm() < std::numeric_limits<double>::epsilon()) ?
89  1 :
90  0;
91  Eigen::Affine3d transform = collision_origin_transform_[i];
92 
93  if (shapes_[i]->type != shapes::MESH)
94  {
95  Eigen::Vector3d extents = shapes::computeShapeExtents(shapes_[i].get());
96  aabb.extendWithTransformedBox(transform, extents);
97  }
98  else
99  {
100  // we cannot use shapes::computeShapeExtents() for meshes, since that method does not provide information about
101  // the offset of the mesh origin
102  const shapes::Mesh* mesh = dynamic_cast<const shapes::Mesh*>(shapes_[i].get());
103  for (unsigned int j = 0; j < mesh->vertex_count; ++j)
104  {
105  aabb.extend(transform * Eigen::Map<Eigen::Vector3d>(&mesh->vertices[3 * j]));
106  }
107  }
108  }
109 
110  centered_bounding_box_offset_ = aabb.center();
111  if (shapes_.empty())
112  shape_extents_.setZero();
113  else
114  shape_extents_ = aabb.sizes();
115 }
116 
117 void LinkModel::setVisualMesh(const std::string& visual_mesh, const Eigen::Affine3d& origin,
118  const Eigen::Vector3d& scale)
119 {
120  visual_mesh_filename_ = visual_mesh;
121  visual_mesh_origin_ = origin;
122  visual_mesh_scale_ = scale;
123 }
124 
125 } // end of namespace core
126 } // end of namespace moveit
std::vector< Eigen::Affine3d, Eigen::aligned_allocator< Eigen::Affine3d > > vector_Affine3d
void setJointOriginTransform(const Eigen::Affine3d &transform)
Definition: link_model.cpp:62
Eigen::Vector3d visual_mesh_scale_
Scale factor associated with the visual geometry mesh of this link.
Definition: link_model.h:275
const JointModel * parent_joint_model_
JointModel that connects this link to the parent link.
Definition: link_model.h:232
std::vector< int > collision_origin_transform_is_identity_
Flag indicating if the constant transform applied to the collision geometry of the link (local) is id...
Definition: link_model.h:254
unsigned int vertex_count
double * vertices
void extendWithTransformedBox(const Eigen::Affine3d &transform, const Eigen::Vector3d &box)
Extend with a box transformed by the given transform.
Definition: aabb.cpp:39
Eigen::Affine3d visual_mesh_origin_
The additional origin transform for the mesh.
Definition: link_model.h:272
A joint from the robot. Models the transform that this joint applies in the kinematic chain...
Definition: joint_model.h:108
Eigen::Vector3d shape_extents_
The extents of shape (dimensions of axis aligned bounding box when shape is at origin).
Definition: link_model.h:263
bool joint_origin_transform_is_identity_
True of the joint origin transform is identity.
Definition: link_model.h:244
void setGeometry(const std::vector< shapes::ShapeConstPtr > &shapes, const EigenSTL::vector_Affine3d &origins)
Definition: link_model.cpp:76
Eigen::Vector3d centered_bounding_box_offset_
Center of the axis aligned bounding box with size shape_extents_ (zero if symmetric along all axes)...
Definition: link_model.h:266
std::string visual_mesh_filename_
Filename associated with the visual geometry mesh of this link. If empty, no mesh was used...
Definition: link_model.h:269
Eigen::Affine3d joint_origin_transform_
The constant transform applied to the link (local)
Definition: link_model.h:247
EigenSTL::vector_Affine3d collision_origin_transform_
The constant transform applied to the collision geometry of the link (local)
Definition: link_model.h:250
void setParentJointModel(const JointModel *joint)
Definition: link_model.cpp:70
Main namespace for MoveIt!
Eigen::Vector3d computeShapeExtents(const ShapeMsg &shape_msg)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW LinkModel(const std::string &name)
Definition: link_model.cpp:46
JointType getType() const
Get the type of joint.
Definition: joint_model.h:137
void setVisualMesh(const std::string &visual_mesh, const Eigen::Affine3d &origin, const Eigen::Vector3d &scale)
Definition: link_model.cpp:117
std::vector< shapes::ShapeConstPtr > shapes_
The collision geometry of the link.
Definition: link_model.h:260
Represents an axis-aligned bounding box.
Definition: aabb.h:47
bool is_parent_joint_fixed_
True if the parent joint of this link is fixed.
Definition: link_model.h:241


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Wed Apr 18 2018 02:49:03