Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inertia visual #326

Merged
merged 22 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions include/ignition/rendering/InertiaVisual.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_RENDERING_INERTIAVISUAL_HH_
#define IGNITION_RENDERING_INERTIAVISUAL_HH_

#include "ignition/rendering/config.hh"
#include "ignition/rendering/Object.hh"
#include "ignition/rendering/RenderTypes.hh"
#include "ignition/rendering/Visual.hh"

namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {

/// \class InertiaVisual InertiaVisual.hh
/// ignition/rendering/InertiaVisual.hh
/// \brief Represents a inertia visual
class IGNITION_RENDERING_VISIBLE InertiaVisual :
public virtual Visual
{
/// \brief Destructor
public: virtual ~InertiaVisual() {}

/// \brief Load the Inertia visual from its pose and scale
/// \param[in] _pose Pose of the Inertia visual
/// \param[in] _scale scale factor of the box visual
atharva-18 marked this conversation as resolved.
Show resolved Hide resolved
public: virtual void Load(const ignition::math::Pose3d &_pose,
const ignition::math::Vector3d &_scale) = 0;
};
}
}
}
#endif
5 changes: 5 additions & 0 deletions include/ignition/rendering/RenderTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace ignition
class Grid;
class Heightmap;
class Image;
class InertiaVisual;
class Light;
class LightVisual;
class JointVisual;
Expand Down Expand Up @@ -149,6 +150,10 @@ namespace ignition
/// \brief Shared pointer to Image
typedef shared_ptr<Image> ImagePtr;

/// \def InertiaVisualPtr
/// \def Shared pointer to InertiaVisual
typedef shared_ptr<InertiaVisual> InertiaVisualPtr;

/// \def LightPtr
/// \brief Shared pointer to Light
typedef shared_ptr<Light> LightPtr;
Expand Down
29 changes: 29 additions & 0 deletions include/ignition/rendering/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,35 @@ namespace ignition
public: virtual GizmoVisualPtr CreateGizmoVisual(
unsigned int _id, const std::string &_name) = 0;

/// \brief Create new inertia visual. A unique ID and name will
/// automatically be assigned to the inertia visual.
/// \return The created inertia visual
public: virtual InertiaVisualPtr CreateInertiaVisual() = 0;

/// \brief Create new inertia visual with the given ID. A unique name
/// will automatically be assigned to the visual. If the given ID is
/// already in use, NULL will be returned.
/// \param[in] _id ID of the new inertia visual
/// \return The created light visual
public: virtual InertiaVisualPtr CreateInertiaVisual(
unsigned int _id) = 0;

/// \brief Create new inertia visual with the given name. A unique ID
/// will automatically be assigned to the visual. If the given name is
/// already in use, NULL will be returned.
/// \param[in] _name Name of the new inertia visual
/// \return The created light visual
public: virtual InertiaVisualPtr CreateInertiaVisual(
const std::string &_name) = 0;

/// \brief Create new inertia visual with the given name. If either the
/// given ID or name is already in use, NULL will be returned.
/// \param[in] _id ID of the new inertia visual
/// \param[in] _name Name of the new inertia visual
/// \return The created inertia visual
public: virtual InertiaVisualPtr CreateInertiaVisual(
unsigned int _id, const std::string &_name) = 0;

/// \brief Create new light visual. A unique ID and name will
/// automatically be assigned to the light visual.
/// \return The created light visual
Expand Down
92 changes: 92 additions & 0 deletions include/ignition/rendering/base/BaseInertiaVisual.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_RENDERING_BASE_BASEINERTIAVISUAL_HH_
#define IGNITION_RENDERING_BASE_BASEINERTIAVISUAL_HH_

#include <vector>
atharva-18 marked this conversation as resolved.
Show resolved Hide resolved

#include "ignition/rendering/base/BaseObject.hh"
#include "ignition/rendering/base/BaseRenderTypes.hh"
#include "ignition/rendering/InertiaVisual.hh"
#include "ignition/rendering/Scene.hh"

namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
/// \brief Base implementation of an inertia visual
template <class T>
class BaseInertiaVisual :
public virtual InertiaVisual,
public virtual T
{
/// \brief Constructor
protected: BaseInertiaVisual();

/// \brief Destructor
public: virtual ~BaseInertiaVisual();

// Documentation inherited.
protected: virtual void Init() override;

// Documentation inherited.
protected: virtual void PreRender() override;

// Documentation inherited.
public: virtual void Load(const ignition::math::Pose3d &,
const ignition::math::Vector3d &) override;
};

//////////////////////////////////////////////////
template <class T>
BaseInertiaVisual<T>::BaseInertiaVisual()
{
}

//////////////////////////////////////////////////
template <class T>
BaseInertiaVisual<T>::~BaseInertiaVisual()
{
}

/////////////////////////////////////////////////
template <class T>
void BaseInertiaVisual<T>::PreRender()
{
T::PreRender();
}

//////////////////////////////////////////////////
template <class T>
void BaseInertiaVisual<T>::Init()
{
T::Init();
}

//////////////////////////////////////////////////
template <class T>
void BaseInertiaVisual<T>::Load(const ignition::math::Pose3d &,
const ignition::math::Vector3d &)
{
// no op
}
}
}
}
#endif
21 changes: 21 additions & 0 deletions include/ignition/rendering/base/BaseScene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ namespace ignition
public: virtual PointLightPtr CreatePointLight(unsigned int _id,
const std::string &_name) override;

/// \brief Implementation for creating Inertia visual.
/// \param[in] _id Unique id
/// \param[in] _name Name of inertia visual
protected: virtual InertiaVisualPtr CreateInertiaVisualImpl(
unsigned int _id, const std::string &_name) = 0;

/// \brief Implementation for creating Light visual.
/// \param[in] _id Unique id
/// \param[in] _name Name of light visual
Expand Down Expand Up @@ -360,6 +366,21 @@ namespace ignition
public: virtual AxisVisualPtr CreateAxisVisual(unsigned int _id,
const std::string &_name) override;

// Documentation inherited
public: virtual InertiaVisualPtr CreateInertiaVisual() override;

// Documentation inherited
public: virtual InertiaVisualPtr CreateInertiaVisual(unsigned int _id)
override;

// Documentation inherited
public: virtual InertiaVisualPtr CreateInertiaVisual(
const std::string &_name) override;

// Documentation inherited
public: virtual InertiaVisualPtr CreateInertiaVisual(unsigned int _id,
const std::string &_name) override;

// Documentation inherited
public: virtual LightVisualPtr CreateLightVisual() override;

Expand Down
85 changes: 85 additions & 0 deletions ogre/include/ignition/rendering/ogre/OgreInertiaVisual.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef IGNITION_RENDERING_OGRE_OGREINERTIAVISUAL_HH_
#define IGNITION_RENDERING_OGRE_OGREINERTIAVISUAL_HH_

#include <memory>

#include "ignition/rendering/base/BaseInertiaVisual.hh"
#include "ignition/rendering/ogre/OgreIncludes.hh"
#include "ignition/rendering/ogre/OgreMaterial.hh"
#include "ignition/rendering/ogre/OgreVisual.hh"

namespace Ogre
{
class MovableObject;
}

namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {

// Forward declaration
class OgreInertiaVisualPrivate;

class IGNITION_RENDERING_OGRE_VISIBLE OgreInertiaVisual :
public BaseInertiaVisual<OgreVisual>
{
/// \brief Constructor
protected: OgreInertiaVisual();

/// \brief Destructor
public: virtual ~OgreInertiaVisual();

// Documentation inherited.
public: virtual void Init() override;

// Documentation inherited.
public: virtual void PreRender() override;

// Documentation inherited.
public: Ogre::MovableObject *OgreObject() const;

/// \brief Load the Inertia visual from its pose and scale
/// \param[in] _pose Pose of the Inertia visual
/// \param[in] _scale scale factor of the box visual
atharva-18 marked this conversation as resolved.
Show resolved Hide resolved
public: void Load(const ignition::math::Pose3d &_pose,
const ignition::math::Vector3d &_scale) override;

// Documentation inherited.
public: virtual MaterialPtr Material() const;

// Documentation inherited.
public: virtual void SetMaterial(
MaterialPtr _material, bool _unique) override;

/// \brief Set material to grid geometry.
atharva-18 marked this conversation as resolved.
Show resolved Hide resolved
/// \param[in] _material Ogre material.
protected: virtual void SetMaterialImpl(OgreMaterialPtr _material);

private: friend class OgreScene;

/// \brief Private data class
private: std::unique_ptr<OgreInertiaVisualPrivate> dataPtr;
};
}
}
}
#endif
2 changes: 2 additions & 0 deletions ogre/include/ignition/rendering/ogre/OgreRenderTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace ignition
class OgreGpuRays;
class OgreGrid;
class OgreHeightmap;
class OgreInertiaVisual;
class OgreJointVisual;
class OgreLight;
class OgreLightVisual;
Expand Down Expand Up @@ -86,6 +87,7 @@ namespace ignition
typedef shared_ptr<OgreGpuRays> OgreGpuRaysPtr;
typedef shared_ptr<OgreGrid> OgreGridPtr;
typedef shared_ptr<OgreHeightmap> OgreHeightmapPtr;
typedef shared_ptr<OgreInertiaVisual> OgreInertiaVisualPtr;
typedef shared_ptr<OgreJointVisual> OgreJointVisualPtr;
typedef shared_ptr<OgreLight> OgreLightPtr;
typedef shared_ptr<OgreLightVisual> OgreLightVisualPtr;
Expand Down
3 changes: 3 additions & 0 deletions ogre/include/ignition/rendering/ogre/OgreScene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ namespace ignition
unsigned int _id, const std::string &_name) override;

// Documentation inherited
protected: virtual InertiaVisualPtr CreateInertiaVisualImpl(
unsigned int _id, const std::string &_name) override;

protected: virtual LightVisualPtr CreateLightVisualImpl(unsigned int _id,
const std::string &_name) override;

Expand Down
Loading