Skip to content

Commit

Permalink
Improved coverage Arrow and Axis visuals and fixed some warnings (#736)
Browse files Browse the repository at this point in the history
* Improved coverage Arrow and Axis visuals and fixed some warnings

Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde authored Oct 12, 2022
1 parent 84724f5 commit 4a364a2
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/ignition/rendering/base/BaseArrowVisual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ namespace ignition
template <class T>
VisualPtr BaseArrowVisual<T>::Head() const
{
return nullptr;
return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(0));
}

//////////////////////////////////////////////////
template <class T>
VisualPtr BaseArrowVisual<T>::Shaft() const
{
return nullptr;
return std::dynamic_pointer_cast<Visual>(this->ChildByIndex(1));
}

//////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion ogre/src/OgreMaterial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void OgreMaterial::UpdateShaderParams()
void OgreMaterial::UpdateShaderParams(ConstShaderParamsPtr _params,
Ogre::GpuProgramParametersSharedPtr _ogreParams)
{
for (const auto name_param : *_params)
for (const auto & name_param : *_params)
{
if (ShaderParam::PARAM_FLOAT == name_param.second.Type())
{
Expand Down
44 changes: 44 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 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_OGRE2_OGRE2ARROWVISUAL_HH_
#define IGNITION_RENDERING_OGRE2_OGRE2ARROWVISUAL_HH_

#include "ignition/rendering/base/BaseArrowVisual.hh"
#include "ignition/rendering/ogre2/Ogre2Visual.hh"

namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2ArrowVisual :
public BaseArrowVisual<Ogre2Visual>
{
/// \brief Constructor
protected: Ogre2ArrowVisual();

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

/// \brief Only the ogre scene can instanstiate this class
private: friend class Ogre2Scene;
};
}
}
}
#endif
44 changes: 44 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 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_OGRE2_OGRE2AXISVISUAL_HH_
#define IGNITION_RENDERING_OGRE2_OGRE2AXISVISUAL_HH_

#include "ignition/rendering/base/BaseAxisVisual.hh"
#include "ignition/rendering/ogre2/Ogre2Visual.hh"

namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2AxisVisual :
public BaseAxisVisual<Ogre2Visual>
{
/// \brief Constructor
protected: Ogre2AxisVisual();

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

/// \brief Only the ogre scene can instanstiate this class
private: friend class Ogre2Scene;
};
}
}
}
#endif
4 changes: 4 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace ignition
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
class Ogre2ArrowVisual;
class Ogre2AxisVisual;
class Ogre2Camera;
class Ogre2DepthCamera;
class Ogre2DirectionalLight;
Expand Down Expand Up @@ -66,6 +68,8 @@ namespace ignition

typedef BaseMaterialMap<Ogre2Material> Ogre2MaterialMap;

typedef shared_ptr<Ogre2ArrowVisual> Ogre2ArrowVisualPtr;
typedef shared_ptr<Ogre2AxisVisual> Ogre2AxisVisualPtr;
typedef shared_ptr<Ogre2Camera> Ogre2CameraPtr;
typedef shared_ptr<Ogre2DepthCamera> Ogre2DepthCameraPtr;
typedef shared_ptr<Ogre2DirectionalLight> Ogre2DirectionalLightPtr;
Expand Down
30 changes: 30 additions & 0 deletions ogre2/src/Ogre2ArrowVisual.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 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.
*
*/
#include "ignition/rendering/ogre2/Ogre2ArrowVisual.hh"

using namespace ignition;
using namespace rendering;

//////////////////////////////////////////////////
Ogre2ArrowVisual::Ogre2ArrowVisual()
{
}

//////////////////////////////////////////////////
Ogre2ArrowVisual::~Ogre2ArrowVisual()
{
}
30 changes: 30 additions & 0 deletions ogre2/src/Ogre2AxisVisual.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 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.
*
*/
#include "ignition/rendering/ogre2/Ogre2AxisVisual.hh"

using namespace ignition;
using namespace rendering;

//////////////////////////////////////////////////
Ogre2AxisVisual::Ogre2AxisVisual()
{
}

//////////////////////////////////////////////////
Ogre2AxisVisual::~Ogre2AxisVisual()
{
}
20 changes: 12 additions & 8 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <ignition/common/Console.hh>

#include "ignition/rendering/RenderTypes.hh"
#include "ignition/rendering/ogre2/Ogre2ArrowVisual.hh"
#include "ignition/rendering/ogre2/Ogre2AxisVisual.hh"
#include "ignition/rendering/ogre2/Ogre2Camera.hh"
#include "ignition/rendering/ogre2/Ogre2Conversions.hh"
#include "ignition/rendering/ogre2/Ogre2DepthCamera.hh"
Expand Down Expand Up @@ -278,19 +280,21 @@ VisualPtr Ogre2Scene::CreateVisualImpl(unsigned int _id,
}

//////////////////////////////////////////////////
ArrowVisualPtr Ogre2Scene::CreateArrowVisualImpl(unsigned int /*_id*/,
const std::string &/*_name*/)
ArrowVisualPtr Ogre2Scene::CreateArrowVisualImpl(unsigned int _id,
const std::string &_name)
{
// TODO(anyone)
return ArrowVisualPtr();
Ogre2ArrowVisualPtr visual(new Ogre2ArrowVisual);
bool result = this->InitObject(visual, _id, _name);
return (result) ? visual : nullptr;
}

//////////////////////////////////////////////////
AxisVisualPtr Ogre2Scene::CreateAxisVisualImpl(unsigned int /*_id*/,
const std::string &/*_name*/)
AxisVisualPtr Ogre2Scene::CreateAxisVisualImpl(unsigned int _id,
const std::string &_name)
{
// TODO(anyone)
return AxisVisualPtr();
Ogre2AxisVisualPtr visual(new Ogre2AxisVisual);
bool result = this->InitObject(visual, _id, _name);
return (result) ? visual : nullptr;
}

//////////////////////////////////////////////////
Expand Down
93 changes: 93 additions & 0 deletions src/ArrowVisual_TEST.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2022 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.
*
*/

#include <gtest/gtest.h>
#include <string>

#include <ignition/common/Console.hh>

#include "test_config.h" // NOLINT(build/include)

#include "ignition/rendering/ArrowVisual.hh"
#include "ignition/rendering/RenderEngine.hh"
#include "ignition/rendering/RenderingIface.hh"
#include "ignition/rendering/Scene.hh"

using namespace ignition;
using namespace rendering;

class ArrowVisualTest : public testing::Test,
public testing::WithParamInterface<const char *>
{
/// \brief Test basic API
public: void ArrowVisual(const std::string &_renderEngine);

/// \brief Test gizmo material
public: void Material(const std::string &_renderEngine);
};

/////////////////////////////////////////////////
void ArrowVisualTest::ArrowVisual(const std::string &_renderEngine)
{
RenderEngine *engine = rendering::engine(_renderEngine);
if (!engine)
{
igndbg << "Engine '" << _renderEngine
<< "' is not supported" << std::endl;
return;
}

ScenePtr scene = engine->CreateScene("scene");

// create visual
ArrowVisualPtr arrow = scene->CreateArrowVisual();
EXPECT_NE(nullptr, arrow);
EXPECT_EQ(2u, arrow->ChildCount());

EXPECT_NE(nullptr, arrow->Head());
EXPECT_NE(nullptr, arrow->Shaft());

EXPECT_NE(arrow->Head(), arrow->Shaft());

ArrowVisualPtr arrow_name = scene->CreateArrowVisual("arrow_name");
EXPECT_NE(nullptr, arrow_name);
EXPECT_EQ(2u, arrow_name->ChildCount());

ArrowVisualPtr arrow_id = scene->CreateArrowVisual(98);
EXPECT_NE(nullptr, arrow_id);
EXPECT_EQ(2u, arrow_id->ChildCount());

// Clean up
engine->DestroyScene(scene);
rendering::unloadEngine(engine->Name());
}

/////////////////////////////////////////////////
TEST_P(ArrowVisualTest, ArrowVisual)
{
ArrowVisual(GetParam());
}

INSTANTIATE_TEST_CASE_P(Visual, ArrowVisualTest,
RENDER_ENGINE_VALUES,
ignition::rendering::PrintToStringParam());

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading

0 comments on commit 4a364a2

Please sign in to comment.