From fd08fee5056913f11f6ad4e30bc332df23311a8e Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 12 Oct 2022 21:42:17 +0200 Subject: [PATCH 1/2] Improved coverage Arrow and Axis visuals and fixed some warnings Signed-off-by: ahcorde --- .../rendering/base/BaseArrowVisual.hh | 4 +- ogre/src/OgreMaterial.cc | 2 +- .../rendering/ogre2/Ogre2ArrowVisual.hh | 44 ++++++++++ .../rendering/ogre2/Ogre2AxisVisual.hh | 44 ++++++++++ .../rendering/ogre2/Ogre2RenderTypes.hh | 4 + ogre2/src/Ogre2ArrowVisual.cc | 30 +++++++ ogre2/src/Ogre2AxisVisual.cc | 30 +++++++ ogre2/src/Ogre2Scene.cc | 20 +++-- src/ArrowVisual_TEST.cc | 85 +++++++++++++++++++ src/AxisVisual_TEST.cc | 79 +++++++++++++++++ src/ShaderParams_TEST.cc | 2 +- 11 files changed, 332 insertions(+), 12 deletions(-) create mode 100644 ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh create mode 100644 ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh create mode 100644 ogre2/src/Ogre2ArrowVisual.cc create mode 100644 ogre2/src/Ogre2AxisVisual.cc create mode 100644 src/ArrowVisual_TEST.cc create mode 100644 src/AxisVisual_TEST.cc diff --git a/include/ignition/rendering/base/BaseArrowVisual.hh b/include/ignition/rendering/base/BaseArrowVisual.hh index dd198804c..0418aa7fe 100644 --- a/include/ignition/rendering/base/BaseArrowVisual.hh +++ b/include/ignition/rendering/base/BaseArrowVisual.hh @@ -58,14 +58,14 @@ namespace ignition template VisualPtr BaseArrowVisual::Head() const { - return nullptr; + return std::dynamic_pointer_cast(this->ChildByIndex(0)); } ////////////////////////////////////////////////// template VisualPtr BaseArrowVisual::Shaft() const { - return nullptr; + return std::dynamic_pointer_cast(this->ChildByIndex(1)); } ////////////////////////////////////////////////// diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index 29eb8a821..dfef22767 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -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()) { diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh new file mode 100644 index 000000000..3a646db40 --- /dev/null +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2ArrowVisual.hh @@ -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 + { + /// \brief Constructor + protected: Ogre2ArrowVisual(); + + /// \brief Destructor + public: virtual ~Ogre2ArrowVisual(); + + /// \brief Only the ogre scene can instanstiate this class + private: friend class Ogre2Scene; + }; + } + } +} +#endif diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh new file mode 100644 index 000000000..2605c6f2a --- /dev/null +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2AxisVisual.hh @@ -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 + { + /// \brief Constructor + protected: Ogre2AxisVisual(); + + /// \brief Destructor + public: virtual ~Ogre2AxisVisual(); + + /// \brief Only the ogre scene can instanstiate this class + private: friend class Ogre2Scene; + }; + } + } +} +#endif diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh index 225598eb8..53d7ec89e 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2RenderTypes.hh @@ -28,6 +28,8 @@ namespace ignition { inline namespace IGNITION_RENDERING_VERSION_NAMESPACE { // + class Ogre2ArrowVisual; + class Ogre2AxisVisual; class Ogre2Camera; class Ogre2DepthCamera; class Ogre2DirectionalLight; @@ -66,6 +68,8 @@ namespace ignition typedef BaseMaterialMap Ogre2MaterialMap; + typedef shared_ptr Ogre2ArrowVisualPtr; + typedef shared_ptr Ogre2AxisVisualPtr; typedef shared_ptr Ogre2CameraPtr; typedef shared_ptr Ogre2DepthCameraPtr; typedef shared_ptr Ogre2DirectionalLightPtr; diff --git a/ogre2/src/Ogre2ArrowVisual.cc b/ogre2/src/Ogre2ArrowVisual.cc new file mode 100644 index 000000000..e403dbeab --- /dev/null +++ b/ogre2/src/Ogre2ArrowVisual.cc @@ -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() +{ +} diff --git a/ogre2/src/Ogre2AxisVisual.cc b/ogre2/src/Ogre2AxisVisual.cc new file mode 100644 index 000000000..6fee68b2a --- /dev/null +++ b/ogre2/src/Ogre2AxisVisual.cc @@ -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() +{ +} diff --git a/ogre2/src/Ogre2Scene.cc b/ogre2/src/Ogre2Scene.cc index 5b631f897..379b5e22f 100644 --- a/ogre2/src/Ogre2Scene.cc +++ b/ogre2/src/Ogre2Scene.cc @@ -18,6 +18,8 @@ #include #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" @@ -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; } ////////////////////////////////////////////////// diff --git a/src/ArrowVisual_TEST.cc b/src/ArrowVisual_TEST.cc new file mode 100644 index 000000000..3a2394068 --- /dev/null +++ b/src/ArrowVisual_TEST.cc @@ -0,0 +1,85 @@ +/* + * 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 +#include + +#include + +#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 +{ + /// \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 axis = scene->CreateArrowVisual(); + EXPECT_NE(nullptr, axis); + EXPECT_EQ(2u, axis->ChildCount()); + + EXPECT_NE(nullptr, axis->Head()); + EXPECT_NE(nullptr, axis->Shaft()); + + EXPECT_NE(axis->Head(), axis->Shaft()); + + // 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(); +} diff --git a/src/AxisVisual_TEST.cc b/src/AxisVisual_TEST.cc new file mode 100644 index 000000000..e226f1cd0 --- /dev/null +++ b/src/AxisVisual_TEST.cc @@ -0,0 +1,79 @@ +/* + * 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 +#include + +#include + +#include "test_config.h" // NOLINT(build/include) + +#include "ignition/rendering/AxisVisual.hh" +#include "ignition/rendering/RenderEngine.hh" +#include "ignition/rendering/RenderingIface.hh" +#include "ignition/rendering/Scene.hh" + +using namespace ignition; +using namespace rendering; + +class AxisVisualTest : public testing::Test, + public testing::WithParamInterface +{ + /// \brief Test basic API + public: void AxisVisual(const std::string &_renderEngine); + + /// \brief Test gizmo material + public: void Material(const std::string &_renderEngine); +}; + +///////////////////////////////////////////////// +void AxisVisualTest::AxisVisual(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 + AxisVisualPtr axis = scene->CreateAxisVisual(); + EXPECT_NE(nullptr, axis); + + // Clean up + engine->DestroyScene(scene); + rendering::unloadEngine(engine->Name()); +} + +///////////////////////////////////////////////// +TEST_P(AxisVisualTest, AxisVisual) +{ + AxisVisual(GetParam()); +} + +INSTANTIATE_TEST_CASE_P(Visual, AxisVisualTest, + RENDER_ENGINE_VALUES, + ignition::rendering::PrintToStringParam()); + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/ShaderParams_TEST.cc b/src/ShaderParams_TEST.cc index f8f9dfb7e..3b824a0cf 100644 --- a/src/ShaderParams_TEST.cc +++ b/src/ShaderParams_TEST.cc @@ -66,7 +66,7 @@ TEST(ShaderParams, ConstRangeForLoopDoesNotDirty) params["some_parameter"] = 4.0f; params.ClearDirty(); - for (const auto name_param : params) + for (const auto & name_param : params) { EXPECT_EQ(std::string("some_parameter"), name_param.first); } From 9d4a36c4ad371d830cf23267b76ddee4901c542e Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 12 Oct 2022 22:14:20 +0200 Subject: [PATCH 2/2] Increased coverage Signed-off-by: ahcorde --- src/ArrowVisual_TEST.cc | 20 ++++++++++++++------ src/AxisVisual_TEST.cc | 7 +++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/ArrowVisual_TEST.cc b/src/ArrowVisual_TEST.cc index 3a2394068..b9c4ca073 100644 --- a/src/ArrowVisual_TEST.cc +++ b/src/ArrowVisual_TEST.cc @@ -54,14 +54,22 @@ void ArrowVisualTest::ArrowVisual(const std::string &_renderEngine) ScenePtr scene = engine->CreateScene("scene"); // create visual - ArrowVisualPtr axis = scene->CreateArrowVisual(); - EXPECT_NE(nullptr, axis); - EXPECT_EQ(2u, axis->ChildCount()); + ArrowVisualPtr arrow = scene->CreateArrowVisual(); + EXPECT_NE(nullptr, arrow); + EXPECT_EQ(2u, arrow->ChildCount()); - EXPECT_NE(nullptr, axis->Head()); - EXPECT_NE(nullptr, axis->Shaft()); + EXPECT_NE(nullptr, arrow->Head()); + EXPECT_NE(nullptr, arrow->Shaft()); - EXPECT_NE(axis->Head(), axis->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); diff --git a/src/AxisVisual_TEST.cc b/src/AxisVisual_TEST.cc index e226f1cd0..1222d72bc 100644 --- a/src/AxisVisual_TEST.cc +++ b/src/AxisVisual_TEST.cc @@ -57,6 +57,13 @@ void AxisVisualTest::AxisVisual(const std::string &_renderEngine) AxisVisualPtr axis = scene->CreateAxisVisual(); EXPECT_NE(nullptr, axis); + // create visual + AxisVisualPtr axis_name = scene->CreateAxisVisual("axis_name"); + EXPECT_NE(nullptr, axis_name); + + AxisVisualPtr axis_id = scene->CreateAxisVisual(101); + EXPECT_NE(nullptr, axis_id); + // Clean up engine->DestroyScene(scene); rendering::unloadEngine(engine->Name());