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

Update Marker test #673

Merged
merged 7 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/LidarVisual_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ void LidarVisualTest::LidarVisual(const std::string &_renderEngine)
10, 3.5};
lidar->SetPoints(pts);
EXPECT_EQ(pts.size(), lidar->PointCount());

lidar->PreRender();

lidar->ClearPoints();
EXPECT_EQ(lidar->PointCount(), 0u);

Expand Down
81 changes: 80 additions & 1 deletion src/Marker_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#include <ignition/common/Console.hh>

#include "test_config.h" // NOLINT(build/include)
#include "ignition/rendering/Marker.hh"
#include "ignition/rendering/Material.hh"
#include "ignition/rendering/RenderEngine.hh"
#include "ignition/rendering/RenderingIface.hh"
#include "ignition/rendering/Marker.hh"
#include "ignition/rendering/Scene.hh"

using namespace ignition;
Expand All @@ -32,6 +33,9 @@ class MarkerTest : public testing::Test,
public testing::WithParamInterface<const char *>
{
public: void Marker(const std::string &_renderEngine);

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

/////////////////////////////////////////////////
Expand Down Expand Up @@ -79,12 +83,26 @@ void MarkerTest::Marker(const std::string &_renderEngine)
marker->SetType(MarkerType::MT_CAPSULE);
EXPECT_EQ(MarkerType::MT_CAPSULE, marker->Type());

// test attaching marker to visual
VisualPtr visual = scene->CreateVisual();
ASSERT_NE(nullptr, visual);
visual->AddGeometry(marker);

marker->SetType(MarkerType::MT_CYLINDER);
EXPECT_EQ(MarkerType::MT_CYLINDER, marker->Type());

marker->SetType(MarkerType::MT_BOX);
EXPECT_EQ(MarkerType::MT_BOX, marker->Type());

marker->SetType(MarkerType::MT_SPHERE);
EXPECT_EQ(MarkerType::MT_SPHERE, marker->Type());

marker->SetType(MarkerType::MT_NONE);
EXPECT_EQ(MarkerType::MT_NONE, marker->Type());

marker->SetType(static_cast<MarkerType>(99));
EXPECT_EQ(static_cast<MarkerType>(99), marker->Type());

marker->SetType(MarkerType::MT_POINTS);
EXPECT_EQ(MarkerType::MT_POINTS, marker->Type());

Expand All @@ -103,6 +121,13 @@ void MarkerTest::Marker(const std::string &_renderEngine)
marker->SetType(MarkerType::MT_TRIANGLE_FAN);
EXPECT_EQ(MarkerType::MT_TRIANGLE_FAN, marker->Type());

// set same type again
marker->SetType(MarkerType::MT_TRIANGLE_FAN);
EXPECT_EQ(MarkerType::MT_TRIANGLE_FAN, marker->Type());

// attach to visual again
EXPECT_NO_THROW(visual->AddGeometry(marker));

// exercise point api
EXPECT_NO_THROW(marker->AddPoint(math::Vector3d(0, 1, 2),
math::Color::White));
Expand All @@ -118,12 +143,66 @@ void MarkerTest::Marker(const std::string &_renderEngine)
rendering::unloadEngine(engine->Name());
}

/////////////////////////////////////////////////
void MarkerTest::Material(const std::string &_renderEngine)
{
if (_renderEngine == "optix")
{
igndbg << "Marker not supported yet in rendering engine: "
<< _renderEngine << std::endl;
iche033 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

iche033 marked this conversation as resolved.
Show resolved Hide resolved

RenderEngine *engine = rendering::engine(_renderEngine);
if (!engine)
{
igndbg << "Engine '" << _renderEngine
<< "' is not supported" << std::endl;
return;
}

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

MarkerPtr marker = scene->CreateMarker();
ASSERT_NE(nullptr, marker);

EXPECT_NO_THROW(marker->SetMaterial(MaterialPtr(), false));
EXPECT_EQ(nullptr, marker->Material());

MaterialPtr material = scene->CreateMaterial();
ASSERT_NE(nullptr, material);
material->SetDiffuse(0.1, 0.2, 0.3);

marker->SetType(MarkerType::MT_NONE);
EXPECT_EQ(MarkerType::MT_NONE, marker->Type());
marker->SetMaterial(material, false);
EXPECT_EQ(material, marker->Material());

marker->SetType(MarkerType::MT_BOX);
EXPECT_EQ(MarkerType::MT_BOX, marker->Type());
marker->SetMaterial(material, false);
EXPECT_EQ(material, marker->Material());

marker->SetType(MarkerType::MT_LINE_STRIP);
EXPECT_EQ(MarkerType::MT_LINE_STRIP, marker->Type());
marker->SetMaterial(material, true);
EXPECT_NE(material, marker->Material());
EXPECT_EQ(math::Color(0.1, 0.2, 0.3), marker->Material()->Diffuse());
}

/////////////////////////////////////////////////
TEST_P(MarkerTest, Marker)
{
Marker(GetParam());
}

/////////////////////////////////////////////////
TEST_P(MarkerTest, Material)
{
Material(GetParam());
}

INSTANTIATE_TEST_CASE_P(Marker, MarkerTest,
RENDER_ENGINE_VALUES,
ignition::rendering::PrintToStringParam());
Expand Down