Gazebo Rendering

API Reference

9.0.0
BaseCapsule.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
18#ifndef GZ_RENDERING_BASECAPSULE_HH_
19#define GZ_RENDERING_BASECAPSULE_HH_
20
21#include <gz/common/Console.hh>
22
24#include "gz/rendering/Scene.hh"
26
27namespace gz
28{
29 namespace rendering
30 {
31 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
33 template <class T>
35 public virtual Capsule,
36 public virtual T
37 {
38 // Documentation inherited
39 protected: BaseCapsule();
40
41 // Documentation inherited
42 public: virtual ~BaseCapsule();
43
44 // Documentation inherited
45 public: virtual void SetRadius(double _radius) override;
46
47 // Documentation inherited
48 public: virtual void SetLength(double _length) override;
49
50 // Documentation inherited
51 public: virtual double Radius() const override;
52
53 // Documentation inherited
54 public: virtual double Length() const override;
55
56 // Documentation inherited
57 public: virtual GeometryPtr Clone() const override;
58
60 protected: double radius = 0.5;
61
63 protected: double length = 0.5;
64
66 protected: bool capsuleDirty = false;
67 };
68
70 // BaseCapsule
72 template <class T>
76
78 template <class T>
82
84 template <class T>
85 void BaseCapsule<T>::SetRadius(double _radius)
86 {
87 this->radius = _radius;
88 this->capsuleDirty = true;
89 }
90
92 template <class T>
94 {
95 return this->radius;
96 }
97
99 template <class T>
100 void BaseCapsule<T>::SetLength(double _length)
101 {
102 this->length = _length;
103 this->capsuleDirty = true;
104 }
105
107 template <class T>
109 {
110 return this->length;
111 }
112
114 template <class T>
116 {
117 if (!this->Scene())
118 {
119 gzerr << "Cloning a Capsule failed because the capsule to be "
120 << "cloned does not belong to a scene.\n";
121 return nullptr;
122 }
123
124 auto result = this->Scene()->CreateCapsule();
125 if (result)
126 {
127 result->SetRadius(this->Radius());
128 result->SetLength(this->Length());
129
130 if (this->Material())
131 result->SetMaterial(this->Material());
132 }
133
134 return result;
135 }
136 }
137 }
138}
139#endif