Gazebo Rendering

API Reference

6.6.3
gz/rendering/base/BaseInertiaVisual.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef IGNITION_RENDERING_BASE_BASEINERTIAVISUAL_HH_
18 #define IGNITION_RENDERING_BASE_BASEINERTIAVISUAL_HH_
19 
20 #include "ignition/common/Console.hh"
21 
26 
27 namespace ignition
28 {
29  namespace rendering
30  {
31  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
32  //
34  template <class T>
36  public virtual InertiaVisual,
37  public virtual T
38  {
40  protected: BaseInertiaVisual();
41 
43  public: virtual ~BaseInertiaVisual();
44 
45  // Documentation inherited.
46  protected: virtual void Init() override;
47 
48  // Documentation inherited.
49  protected: virtual void PreRender() override;
50 
51  // Documentation inherited.
52  public: virtual void SetInertial(
53  const ignition::math::Inertiald &_inertial) override;
54 
55  // Documentation inherited.
56  public: virtual void Load(const ignition::math::Pose3d &,
57  const ignition::math::Vector3d &) override;
58 
59  // Documentation inherited
60  public: virtual VisualPtr BoxVisual() const override;
61  };
62 
64  template <class T>
66  {
67  }
68 
70  template <class T>
72  {
73  }
74 
76  template <class T>
78  {
79  T::PreRender();
80  }
81 
83  template <class T>
85  {
86  T::Init();
87  }
88 
90  template <class T>
92  const ignition::math::Inertiald &_inertial)
93  {
94  auto xyz = _inertial.Pose().Pos();
95  auto q = _inertial.Pose().Rot();
96 
97  // Use ignition::math::MassMatrix3 to compute
98  // equivalent box size and rotation
99  auto m = _inertial.MassMatrix();
100  ignition::math::Vector3d boxScale;
102  if (!m.EquivalentBox(boxScale, boxRot))
103  {
104  // Invalid inertia, load with default scale
105  ignlog << "The link is static or has unrealistic "
106  << "inertia, so the equivalent inertia box will not be shown.\n";
107  }
108  else
109  {
110  // Apply additional rotation by boxRot
111  this->Load(ignition::math::Pose3d(xyz, q * boxRot), boxScale);
112  }
113  }
114 
116  template <class T>
118  const ignition::math::Vector3d &)
119  {
120  // no op
121  }
122 
124  template <class T>
126  {
127  return nullptr;
128  }
129  }
130  }
131 }
132 #endif
virtual void Init() override
Definition: gz/rendering/base/BaseInertiaVisual.hh:84
STL class.
#define ignlog
BaseInertiaVisual()
Constructor.
Definition: gz/rendering/base/BaseInertiaVisual.hh:65
Represents a inertia visual.
Definition: gz/rendering/InertiaVisual.hh:35
virtual ~BaseInertiaVisual()
Destructor.
Definition: gz/rendering/base/BaseInertiaVisual.hh:71
const MassMatrix3< T > & MassMatrix() const
virtual VisualPtr BoxVisual() const override
Get the box visual.
Definition: gz/rendering/base/BaseInertiaVisual.hh:125
virtual void SetInertial(const ignition::math::Inertiald &_inertial) override
Set the inertial component of the visual.
Definition: gz/rendering/base/BaseInertiaVisual.hh:91
const Pose3< T > & Pose() const
virtual void Load(const ignition::math::Pose3d &, const ignition::math::Vector3d &) override
Load the Inertia visual from its pose and scale.
Definition: gz/rendering/base/BaseInertiaVisual.hh:117
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: gz/rendering/base/BaseInertiaVisual.hh:77
Base implementation of an inertia visual.
Definition: gz/rendering/base/BaseInertiaVisual.hh:35