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

Attempted Custom Rendering Sensor Example #2406

Open
wants to merge 3 commits into
base: gz-sim8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
44 changes: 44 additions & 0 deletions examples/plugin/custom_rendering_sensor/MirroredCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2024 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.
*/

//needed in order to register plugins
#include <gz/plugin/Register.hh>

//header file
#include "MirroredCamera.hh"

//headers for other code used
#include </gz/sensors/CameraSensor.hh>
#include </gz/common/Image.hh>
#include <FreeImage.h>
#include </gz/sensors/RenderingSensor.hh>

using namespace custom;

//////////////////////////////////////////////////
void MirroredCamera::PostUpdate(const gz::sim::UpdateInfo &_info,
const gz::sim::EntityComponentManager &_ecm)
{
//create a camera
gz:sensors:CameraSensor camera;
camera->CreateCamera();

//flip image horizontally by accessing the bitmap pointer?
FreeImage_FlipHorizontal(camera->image->*bitmap);
}

GZ_ADD_PLUGIN(custom_rendering_sensor::MirroredCamera, gz::sim::System,
custom_rendering_sensor::MirroredCamera::ISystemPostUpdate)
46 changes: 46 additions & 0 deletions examples/plugin/custom_rendering_sensor/MirroredCamera.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 GAZEBO_MIRROREDCAMERA_HH
#define GAZEBO_MIRROREDCAMERA_HH

#include <gz/sim/System.hh>

#include </gz/sensors/CameraSensor.hh>
#include </gz/common/Image.hh>
#include <FreeImage.h>
#include </gz/sensors/RenderingSensor.hh>

namespace custom
{
/// \brief Attempt at creating a custom rendering sensor (in this case,
/// a camera sensor with its image flipped horizontally) as an example
/// for future developers)
class MirroredCamera:
public gz::sim::System,
public gz::sim::ISystemPostUpdate

/// \brief Creates a camera sensor, then calls the FlipHorizontal method
/// from the FreeImage library on the the pointer to the bitmap data
/// from the camera sensor's image field
{
void PostUpdate(const gz::sim::UpdateInfo &_info,
const gz::sim::EntityComponentManager &_ecm)
};
}

#endif //GAZEBO_MIRROREDCAMERA_HH
20 changes: 20 additions & 0 deletions examples/plugin/custom_rendering_sensor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Custom Rendering Sensor

This is a very basic, incomplete class that's meant to demonstrate custom rendering sensors in Gazebo.

It attempts to implement the suggestions offered on Issue #1673:
[https://github.com/gazebosim/gz-sim/issues/1673]

All the code is untested due to my inability to provide a proper testing environment at this time.
No CMakeLists.txt file is included with this directory due to my lack of knowledge of CMake.
Apologies in advance for the likely non-functional code.
I am not very experienced with the tools used in this development stack.

## Build

Not currently functional.

## Run

Not currently functional.