Gazebo Rendering

API Reference

6.6.3
gz/rendering/base/BaseGeometry.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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_BASEGEOMETRY_HH_
18 #define GZ_RENDERING_BASE_BASEGEOMETRY_HH_
19 
20 #include <string>
21 
22 #include <ignition/common/Console.hh>
23 
24 #include "gz/rendering/Geometry.hh"
25 #include "gz/rendering/Scene.hh"
26 
27 namespace ignition
28 {
29  namespace rendering
30  {
31  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
32  //
33  template <class T>
34  class BaseGeometry :
35  public virtual Geometry,
36  public virtual T
37  {
38  protected: BaseGeometry();
39 
40  public: virtual ~BaseGeometry();
41 
42  public: virtual VisualPtr Parent() const override = 0;
43 
44  public: virtual void RemoveParent() override;
45 
46  // Documentation inherited
47  public: virtual void SetMaterial(const std::string &_material,
48  bool _unique = true) override;
49 
50  // Documentation inherited
51  public: virtual void SetMaterial(MaterialPtr _material,
52  bool _unique = true) override = 0;
53 
54  // Documentation inherited
55  public: virtual GeometryPtr Clone() const override;
56 
57  // Documentation inherited
58  public: virtual void Destroy() override;
59  };
60 
62  template <class T>
64  {
65  }
66 
68  template <class T>
70  {
71  }
72 
74  template <class T>
76  {
77  VisualPtr parent = this->Parent();
78 
79  if (parent)
80  {
81  auto baseShared = this->shared_from_this();
82 
83  auto thisShared =
84  std::dynamic_pointer_cast<BaseGeometry<T>>(baseShared);
85 
86  parent->RemoveGeometry(thisShared);
87  }
88  }
89 
91  template <class T>
92  void BaseGeometry<T>::SetMaterial(const std::string &_name, bool _unique)
93  {
94  MaterialPtr material = this->Scene()->Material(_name);
95  if (material) this->SetMaterial(material, _unique);
96  }
97 
99  template <class T>
101  {
102  ignwarn << "Clone functionality for Geometry does not exist yet.\n";
103  return nullptr;
104  }
105 
107  template <class T>
109  {
110  T::Destroy();
111  this->RemoveParent();
112  }
113  }
114  }
115 }
116 #endif
STL class.
STL class.
virtual ~BaseGeometry()
Definition: gz/rendering/base/BaseGeometry.hh:69
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node....
Definition: gz/rendering/Scene.hh:49
Definition: gz/rendering/base/BaseGeometry.hh:34
#define ignwarn
virtual VisualPtr Parent() const override=0
Get the parent Visual.
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: gz/rendering/base/BaseGeometry.hh:108
virtual MaterialPtr Material(const std::string &_name) const =0
Get material registered under the given name. If no material is registered under the given name,...
virtual void RemoveParent() override
Detach this Geometry from its parent Visual. If this Geometry does not have a parent,...
Definition: gz/rendering/base/BaseGeometry.hh:75
BaseGeometry()
Definition: gz/rendering/base/BaseGeometry.hh:63
virtual GeometryPtr Clone() const override
Clone the geometry.
Definition: gz/rendering/base/BaseGeometry.hh:100
virtual void SetMaterial(const std::string &_material, bool _unique=true) override
Set the materials of this Geometry. The specified material will be retrieved from the parent Scene....
Definition: gz/rendering/base/BaseGeometry.hh:92
Represents a geometric shape to be rendered.
Definition: gz/rendering/Geometry.hh:34