Commit f3193174 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #1555 from paroj:ovisup

parents 2c0eb14f 0520753d
...@@ -5,9 +5,15 @@ find_package(OGRE 1.10 QUIET) ...@@ -5,9 +5,15 @@ find_package(OGRE 1.10 QUIET)
if(NOT OGRE_FOUND) if(NOT OGRE_FOUND)
message(STATUS "Module opencv_ovis disabled because OGRE3D was not found") message(STATUS "Module opencv_ovis disabled because OGRE3D was not found")
ocv_module_disable(ovis) ocv_module_disable(ovis)
elseif(OGRE_VERSION VERSION_LESS 1.10) elseif(OGRE_VERSION VERSION_LESS 1.10 OR OGRE_VERSION VERSION_GREATER 2.0)
message(STATUS "Module opencv_ovis disabled because OGRE3D version is less than 1.10 (${OGRE_VERSION})") message(STATUS "Module opencv_ovis disabled because of incompatible OGRE3D version (${OGRE_VERSION})")
ocv_module_disable(ovis) ocv_module_disable(ovis)
elseif(OGRE_VERSION VERSION_GREATER 1.10) # we need C++11 for OGRE 1.11
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qstd=c++11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif() endif()
include_directories(${OGRE_INCLUDE_DIRS}}) include_directories(${OGRE_INCLUDE_DIRS}})
......
...@@ -70,6 +70,12 @@ public: ...@@ -70,6 +70,12 @@ public:
CV_WRAP virtual void createEntity(const String& name, const String& meshname, CV_WRAP virtual void createEntity(const String& name, const String& meshname,
InputArray tvec = noArray(), InputArray rot = noArray()) = 0; InputArray tvec = noArray(), InputArray rot = noArray()) = 0;
/**
* remove an entity from the scene
* @param name entity name
*/
CV_WRAP virtual void removeEntity(const String& name) = 0;
/** /**
* convenience method to visualize a camera position * convenience method to visualize a camera position
* *
......
...@@ -107,13 +107,13 @@ static void _setCameraIntrinsics(Camera* cam, InputArray _K, const Size& imsize) ...@@ -107,13 +107,13 @@ static void _setCameraIntrinsics(Camera* cam, InputArray _K, const Size& imsize)
cam->setFrustumOffset(toOGRE_SS * Vector2(pp_offset.val)); cam->setFrustumOffset(toOGRE_SS * Vector2(pp_offset.val));
} }
static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name) static SceneNode& _getSceneNode(SceneManager* sceneMgr, const String& name)
{ {
MovableObject* mo = NULL; MovableObject* mo = NULL;
try try
{ {
mo = sceneMgr->getCamera(name); mo = sceneMgr->getMovableObject(name, "Camera");
} }
catch (ItemIdentityException&) catch (ItemIdentityException&)
{ {
...@@ -123,7 +123,7 @@ static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name) ...@@ -123,7 +123,7 @@ static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name)
try try
{ {
if (!mo) if (!mo)
mo = sceneMgr->getLight(name); mo = sceneMgr->getMovableObject(name, "Light");
} }
catch (ItemIdentityException&) catch (ItemIdentityException&)
{ {
...@@ -131,9 +131,9 @@ static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name) ...@@ -131,9 +131,9 @@ static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name)
} }
if (!mo) if (!mo)
mo = sceneMgr->getEntity(name); mo = sceneMgr->getMovableObject(name, "Entity"); // throws if not found
return mo->getParentSceneNode(); return *mo->getParentSceneNode();
} }
struct Application : public OgreBites::ApplicationContext, public OgreBites::InputListener struct Application : public OgreBites::ApplicationContext, public OgreBites::InputListener
...@@ -323,12 +323,21 @@ public: ...@@ -323,12 +323,21 @@ public:
Pass* rpass = bgplane->getMaterial()->getBestTechnique()->getPasses()[0]; Pass* rpass = bgplane->getMaterial()->getBestTechnique()->getPasses()[0];
rpass->getTextureUnitStates()[0]->setTextureName(name); rpass->getTextureUnitStates()[0]->setTextureName(name);
// ensure bgplane is visible
bgplane->setVisible(true);
} }
void setBackground(const Scalar& color) void setBackground(const Scalar& color)
{ {
Mat img(1, 1, CV_8UC3, color); // hide background plane
setBackground(img); bgplane->setVisible(false);
// BGRA as uchar
ColourValue _color = ColourValue(color[2], color[1], color[0], color[3]) / 255;
rWin->getViewport(0)->setBackgroundColour(_color);
if(frameSrc != rWin)
frameSrc->getViewport(0)->setBackgroundColour(_color);
} }
void createEntity(const String& name, const String& meshname, InputArray tvec, InputArray rot) void createEntity(const String& name, const String& meshname, InputArray tvec, InputArray rot)
...@@ -342,6 +351,13 @@ public: ...@@ -342,6 +351,13 @@ public:
node->attachObject(ent); node->attachObject(ent);
} }
void removeEntity(const String& name) {
SceneNode& node = _getSceneNode(sceneMgr, name);
node.getAttachedObject(name)->detachFromParent();
sceneMgr->destroyEntity(name);
sceneMgr->destroySceneNode(&node);
}
Rect2d createCameraEntity(const String& name, InputArray K, const Size& imsize, float zFar, Rect2d createCameraEntity(const String& name, InputArray K, const Size& imsize, float zFar,
InputArray tvec, InputArray rot) InputArray tvec, InputArray rot)
{ {
...@@ -391,22 +407,22 @@ public: ...@@ -391,22 +407,22 @@ public:
void updateEntityPose(const String& name, InputArray tvec, InputArray rot) void updateEntityPose(const String& name, InputArray tvec, InputArray rot)
{ {
SceneNode* node = _getSceneNode(sceneMgr, name); SceneNode& node = _getSceneNode(sceneMgr, name);
Quaternion q; Quaternion q;
Vector3 t; Vector3 t;
_convertRT(rot, tvec, q, t); _convertRT(rot, tvec, q, t);
node->rotate(q, Ogre::Node::TS_LOCAL); node.rotate(q, Ogre::Node::TS_LOCAL);
node->translate(t, Ogre::Node::TS_LOCAL); node.translate(t, Ogre::Node::TS_LOCAL);
} }
void setEntityPose(const String& name, InputArray tvec, InputArray rot, bool invert) void setEntityPose(const String& name, InputArray tvec, InputArray rot, bool invert)
{ {
SceneNode* node = _getSceneNode(sceneMgr, name); SceneNode& node = _getSceneNode(sceneMgr, name);
Quaternion q; Quaternion q;
Vector3 t; Vector3 t;
_convertRT(rot, tvec, q, t, invert); _convertRT(rot, tvec, q, t, invert);
node->setOrientation(q); node.setOrientation(q);
node->setPosition(t); node.setPosition(t);
} }
void _createBackground() void _createBackground()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment