Skip to content

Commit

Permalink
Improved coverage: MeshDescriptor, Mesh, MoveToHelper, OrbitViewContr…
Browse files Browse the repository at this point in the history
…oller, PixelFormat and ShadersParams (#748)

Signed-off-by: ahcorde <ahcorde@gmail.com>
  • Loading branch information
ahcorde authored Nov 7, 2022
1 parent ab0b0b7 commit 7418a1b
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 40 deletions.
3 changes: 2 additions & 1 deletion examples/text_geom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(ignition-rendering-text-geom)

find_package(ignition-rendering3)
find_package(ignition-common3)

find_package(GLUT REQUIRED)
include_directories(SYSTEM ${GLUT_INCLUDE_DIRS})
Expand All @@ -26,5 +27,5 @@ target_link_libraries(text_geom
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${IGNITION-RENDERING_LIBRARIES}
${IGNITION-COMMON_LIBRARIES}
)

13 changes: 11 additions & 2 deletions ogre2/src/Ogre2Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,17 @@ VisualPtr Ogre2Camera::VisualAt(const math::Vector2i &_mousePos)
//////////////////////////////////////////////////
RenderWindowPtr Ogre2Camera::CreateRenderWindow()
{
// TODO(anyone)
return RenderWindowPtr();
RenderWindowPtr base = this->scene->CreateRenderWindow();
Ogre2RenderWindowPtr renderWindow =
std::dynamic_pointer_cast<Ogre2RenderWindow>(base);
renderWindow->SetWidth(this->ImageWidth());
renderWindow->SetHeight(this->ImageHeight());
renderWindow->SetDevicePixelRatio(1);
renderWindow->SetCamera(this->ogreCamera);
renderWindow->SetBackgroundColor(this->scene->BackgroundColor());

this->renderTexture = renderWindow;
return base;
}

//////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions ogre2/src/Ogre2Grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ Ogre2Grid::Ogre2Grid()
//////////////////////////////////////////////////
Ogre2Grid::~Ogre2Grid()
{
BaseGrid::Destroy();
}

//////////////////////////////////////////////////
void Ogre2Grid::PreRender()
{
BaseGrid::PreRender();

if (this->gridDirty)
{
this->Create();
Expand Down
6 changes: 6 additions & 0 deletions ogre2/src/Ogre2Marker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ Ogre2Marker::~Ogre2Marker()
//////////////////////////////////////////////////
void Ogre2Marker::PreRender()
{
BaseMarker::PreRender();
this->dataPtr->dynamicRenderable->Update();
}

//////////////////////////////////////////////////
void Ogre2Marker::Destroy()
{
BaseMarker::Destroy();

if (!this->Scene())
return;

Expand Down Expand Up @@ -192,19 +195,22 @@ MaterialPtr Ogre2Marker::Material() const
void Ogre2Marker::SetPoint(unsigned int _index,
const math::Vector3d &_value)
{
BaseMarker::SetPoint(_index, _value);
this->dataPtr->dynamicRenderable->SetPoint(_index, _value);
}

//////////////////////////////////////////////////
void Ogre2Marker::AddPoint(const math::Vector3d &_pt,
const math::Color &_color)
{
BaseMarker::AddPoint(_pt, _color);
this->dataPtr->dynamicRenderable->AddPoint(_pt, _color);
}

//////////////////////////////////////////////////
void Ogre2Marker::ClearPoints()
{
BaseMarker::ClearPoints();
this->dataPtr->dynamicRenderable->Clear();
}

Expand Down
3 changes: 2 additions & 1 deletion ogre2/src/Ogre2RenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Ogre2RenderEngine::Ogre2RenderEngine() :
//////////////////////////////////////////////////
Ogre2RenderEngine::~Ogre2RenderEngine()
{
this->Fini();
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -141,7 +142,7 @@ void Ogre2RenderEngine::Destroy()
//////////////////////////////////////////////////
bool Ogre2RenderEngine::IsEnabled() const
{
return this->initialized;
return BaseRenderEngine::IsEnabled();
}

//////////////////////////////////////////////////
Expand Down
9 changes: 5 additions & 4 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,12 @@ RenderTexturePtr Ogre2Scene::CreateRenderTextureImpl(unsigned int _id,
}

//////////////////////////////////////////////////
RenderWindowPtr Ogre2Scene::CreateRenderWindowImpl(unsigned int /*_id*/,
const std::string &/*_name*/)
RenderWindowPtr Ogre2Scene::CreateRenderWindowImpl(unsigned int _id,
const std::string &_name)
{
// TODO(anyone)
return RenderWindowPtr();
Ogre2RenderWindowPtr renderWindow(new Ogre2RenderWindow);
bool result = this->InitObject(renderWindow, _id, _name);
return (result) ? renderWindow : nullptr;
}

//////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/Marker_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void MarkerTest::Marker(const std::string &_renderEngine)
// exercise point api
EXPECT_NO_THROW(marker->AddPoint(math::Vector3d(0, 1, 2),
math::Color::White));
EXPECT_NO_THROW(marker->AddPoint(-2, -1, 0, math::Color::White));

EXPECT_NO_THROW(marker->SetPoint(0, math::Vector3d(3, 1, 2)));
EXPECT_NO_THROW(marker->ClearPoints());

Expand Down
6 changes: 6 additions & 0 deletions src/MeshDescriptor_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ void MeshDescriptorTest::Descriptor(const std::string &_renderEngine)
ScenePtr scene = engine->CreateScene("scene");
ASSERT_TRUE(scene != nullptr);

MeshDescriptor failDescriptor;
failDescriptor.Load();

MeshDescriptor failDescriptor2("non_existing_mesh");
failDescriptor2.Load();

// empty constructor
MeshDescriptor emptyDescriptor;
EXPECT_TRUE(emptyDescriptor.meshName.empty());
Expand Down
10 changes: 10 additions & 0 deletions src/Mesh_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ void MeshTest::MeshSubMesh(const std::string &_renderEngine)

EXPECT_FALSE(mesh->HasSkeleton());

std::map<std::string, ignition::math::Matrix4d> skinFrames;
mesh->SetSkeletonLocalTransforms(skinFrames);
auto skeletonLocalTransforms = mesh->SkeletonLocalTransforms();
EXPECT_EQ(0u, skeletonLocalTransforms.size());

// test submesh API
MaterialPtr mat = submesh->Material();
ASSERT_TRUE(mat != nullptr);
Expand All @@ -90,6 +95,8 @@ void MeshTest::MeshSubMesh(const std::string &_renderEngine)
EXPECT_EQ(matClone, submesh->Material());
EXPECT_NE(mat, submesh->Material());

submesh->SetMaterial(MaterialPtr(), false);

submesh->SetMaterial("Default/White", false);
EXPECT_EQ("Default/White", submesh->Material()->Name());

Expand Down Expand Up @@ -181,6 +188,9 @@ void MeshTest::MeshSkeleton(const std::string &_renderEngine)
mesh->SetSkeletonLocalTransforms(skinFrames);
}

auto skeletonLocalTransforms = mesh->SkeletonLocalTransforms();
EXPECT_EQ(31u, skeletonLocalTransforms.size());

// Clean up
engine->DestroyScene(scene);
unloadEngine(engine->Name());
Expand Down
22 changes: 22 additions & 0 deletions src/MoveToHelper_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <gtest/gtest.h>

#include <chrono>
#include <cmath>

#include <ignition/rendering/MoveToHelper.hh>
#include <ignition/common/Console.hh>
Expand Down Expand Up @@ -111,6 +112,11 @@ void MoveToHelperTest::MoveTo(const std::string &_renderEngine)

NodePtr target = scene->NodeByName("center");

moveToHelper.SetInitCameraPose(math::Pose3d());

// This call should return, there is no camera
moveToHelper.AddTime(0.1);

moveToHelper.MoveTo(camera, target, 0.5,
std::bind(&MoveToHelperTest::OnMoveToComplete, this));
EXPECT_FALSE(moveToHelper.Idle());
Expand All @@ -136,6 +142,22 @@ void MoveToHelperTest::MoveTo(const std::string &_renderEngine)
EXPECT_EQ(math::Vector3d(0.0, -1, 0.0), camera->LocalPosition());
EXPECT_EQ(math::Quaterniond(0.0, -0.785398, 1.5708), camera->LocalRotation());

moveToHelper.LookDirection(camera,
math::Vector3d::Zero, lookAt,
0.5, std::bind(&MoveToHelperTest::OnMoveToComplete, this));
EXPECT_FALSE(moveToHelper.Idle());
checkIsCompleted(0.5);
EXPECT_TRUE(moveToHelper.Idle());
EXPECT_EQ(math::Vector3d(0.0, 0, 0.0), camera->LocalPosition());
EXPECT_EQ(math::Quaterniond(0.0, 0, 0), camera->LocalRotation());

moveToHelper.MoveTo(camera, math::Pose3d(INFINITY, 0.0, 0.0, 0, 0, 0), 0.5,
std::bind(&MoveToHelperTest::OnMoveToComplete, this));
EXPECT_FALSE(moveToHelper.Idle());
checkIsCompleted(0.5);
EXPECT_EQ(math::Vector3d(0.0, 0, 0.0), camera->LocalPosition());
EXPECT_TRUE(moveToHelper.Idle());

engine->DestroyScene(scene);
unloadEngine(engine->Name());
}
Expand Down
31 changes: 0 additions & 31 deletions src/OrbitViewController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ class ignition::rendering::OrbitViewControllerPrivate

/// \brief Target point for camera movements
public: math::Vector3d target;

/// \brief Keep yaw within limits
/// \return Normalized yaw
public: double NormalizeYaw(double _yaw);

/// \brief Keep pitch within limits
/// \return Normalized pitch
public: double NormalizePitch(double _pitch);
};

using namespace ignition;
Expand Down Expand Up @@ -178,26 +170,3 @@ void OrbitViewController::Orbit(const math::Vector2d &_value)
this->dataPtr->camera->SetWorldPosition(
this->dataPtr->camera->WorldPosition() + this->dataPtr->target);
}

//////////////////////////////////////////////////
double OrbitViewControllerPrivate::NormalizeYaw(double _yaw)
{
_yaw = fmod(_yaw, IGN_PI*2);
if (_yaw < 0.0f)
{
_yaw = IGN_PI * 2 + _yaw;
}

return _yaw;
}

//////////////////////////////////////////////////
double OrbitViewControllerPrivate::NormalizePitch(double _pitch)
{
if (_pitch < PITCH_LIMIT_LOW)
_pitch = PITCH_LIMIT_LOW;
else if (_pitch > PITCH_LIMIT_HIGH)
_pitch = PITCH_LIMIT_HIGH;

return _pitch;
}
51 changes: 51 additions & 0 deletions src/OrbitViewController_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class OrbitViewControllerTest : public testing::Test,
/// \brief Test basic api
public: void OrbitViewControl(const std::string &_renderEngine);

/// \brief Test basic api
public: void OrbitViewControlCameraConstructor(
const std::string &_renderEngine);

/// \brief test zoom, pan, orbit
public: void Control(const std::string &_renderEngine);
};
Expand Down Expand Up @@ -83,6 +87,43 @@ void OrbitViewControllerTest::OrbitViewControl(const std::string &_renderEngine)
unloadEngine(engine->Name());
}

/////////////////////////////////////////////////
void OrbitViewControllerTest::OrbitViewControlCameraConstructor(
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");
EXPECT_NE(scene, nullptr);

CameraPtr camera = scene->CreateCamera("camera");
EXPECT_NE(camera, nullptr);

OrbitViewController viewControl(camera);

// verify intial values
EXPECT_EQ(camera, viewControl.Camera());
EXPECT_EQ(math::Vector3d::Zero, viewControl.Target());

// test setting target
math::Vector3d target(1, 0, 0);
viewControl.SetTarget(target);
EXPECT_EQ(target, viewControl.Target());

target.Set(-0.3, -5, 1);
viewControl.SetTarget(target);
EXPECT_EQ(target, viewControl.Target());

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

/////////////////////////////////////////////////
void OrbitViewControllerTest::Control(const std::string &_renderEngine)
{
Expand All @@ -107,6 +148,10 @@ void OrbitViewControllerTest::Control(const std::string &_renderEngine)

OrbitViewController viewControl;

viewControl.Zoom(0);
viewControl.Pan(math::Vector2d(0, 0));
viewControl.Orbit(math::Vector2d(0, 0));

// test setting camera
viewControl.SetCamera(camera);
EXPECT_EQ(camera, viewControl.Camera());
Expand Down Expand Up @@ -229,6 +274,12 @@ TEST_P(OrbitViewControllerTest, OrbitViewController)
OrbitViewControl(GetParam());
}

/////////////////////////////////////////////////
TEST_P(OrbitViewControllerTest, OrbitViewControllerCameraConstructor)
{
OrbitViewControlCameraConstructor(GetParam());
}

/////////////////////////////////////////////////
TEST_P(OrbitViewControllerTest, Control)
{
Expand Down
21 changes: 21 additions & 0 deletions src/PixelFormat_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,47 @@ TEST(PixelFormatTest, PixelUtil)
EXPECT_EQ(3u, PixelUtil::BytesPerPixel(format));
EXPECT_EQ(1u, PixelUtil::BytesPerChannel(format));
EXPECT_EQ(3072u, PixelUtil::MemorySize(format, 32, 32));
EXPECT_EQ("R8G8B8", PixelUtil::Name(format));
EXPECT_EQ(format, PixelUtil::Enum("R8G8B8"));

format = PF_FLOAT32_R;
EXPECT_EQ(4u, PixelUtil::BytesPerPixel(format));
EXPECT_EQ(4u, PixelUtil::BytesPerChannel(format));
EXPECT_EQ(4096u, PixelUtil::MemorySize(format, 32, 32));
EXPECT_EQ("FLOAT32_R", PixelUtil::Name(format));
EXPECT_EQ(format, PixelUtil::Enum("FLOAT32_R"));

format = PF_FLOAT32_RGB;
EXPECT_EQ(12u, PixelUtil::BytesPerPixel(format));
EXPECT_EQ(4u, PixelUtil::BytesPerChannel(format));
EXPECT_EQ(12288u, PixelUtil::MemorySize(format, 32, 32));
EXPECT_EQ("FLOAT32_RGB", PixelUtil::Name(format));
EXPECT_EQ(format, PixelUtil::Enum("FLOAT32_RGB"));

format = PF_FLOAT32_RGBA;
EXPECT_EQ(16u, PixelUtil::BytesPerPixel(format));
EXPECT_EQ(4u, PixelUtil::BytesPerChannel(format));
EXPECT_EQ(16384u, PixelUtil::MemorySize(format, 32, 32));
EXPECT_EQ("FLOAT32_RGBA", PixelUtil::Name(format));
EXPECT_EQ(format, PixelUtil::Enum("FLOAT32_RGBA"));

format = PF_L16;
EXPECT_EQ(2u, PixelUtil::BytesPerPixel(format));
EXPECT_EQ(2u, PixelUtil::BytesPerChannel(format));
EXPECT_EQ(2048u, PixelUtil::MemorySize(format, 32, 32));
EXPECT_EQ("L16", PixelUtil::Name(format));
EXPECT_EQ(format, PixelUtil::Enum("L16"));
}

/////////////////////////////////////////////////
TEST(PixelFormatTest, PixelUtilInvalid)
{
PixelFormat format = static_cast<PixelFormat>(16);

EXPECT_EQ(PF_UNKNOWN, PixelUtil::Sanitize(format));
EXPECT_EQ("UNKNOWN", PixelUtil::Name(format));

EXPECT_EQ(PF_UNKNOWN, PixelUtil::Enum("invalid"));
}

int main(int argc, char **argv)
Expand Down
Loading

0 comments on commit 7418a1b

Please sign in to comment.