Gazebo Rendering

API Reference

7.4.2
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 GZ_RENDERING_BASE_BASEINERTIAVISUAL_HH_
18 #define GZ_RENDERING_BASE_BASEINERTIAVISUAL_HH_
19 
20 #include "gz/common/Console.hh"
21 
25 #include "gz/rendering/Scene.hh"
26 
27 namespace gz
28 {
29  namespace rendering
30  {
31  inline namespace GZ_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 gz::math::Inertiald &_inertial) override;
54 
55  // Documentation inherited.
56  public: virtual void Load(const gz::math::Pose3d &,
57  const gz::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 gz::math::Inertiald &_inertial)
93  {
94  auto xyz = _inertial.Pose().Pos();
95  auto q = _inertial.Pose().Rot();
96 
97  // Use gz::math::MassMatrix3 to compute
98  // equivalent box size and rotation
99  auto m = _inertial.MassMatrix();
100  gz::math::Vector3d boxScale;
101  gz::math::Quaterniond boxRot;
102  if (!m.EquivalentBox(boxScale, boxRot))
103  {
104  // Invalid inertia, load with default scale
105  gzlog << "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(gz::math::Pose3d(xyz, q * boxRot), boxScale);
112  }
113  }
114 
116  template <class T>
118  const gz::math::Vector3d &)
119  {
120  // no op
121  }
122 
124  template <class T>
126  {
127  return nullptr;
128  }
129  }
130  }
131 }
132 #endif