Skip to content

Commit

Permalink
Very, VERY rough attempt at creating a solution to Issue gazebosim#1673
Browse files Browse the repository at this point in the history
…; code is completely untested and no tests have been written for it.
  • Loading branch information
JEller98 committed May 14, 2024
1 parent 6af7445 commit 071271f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
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.

0 comments on commit 071271f

Please sign in to comment.