Skip to content

Commit ff9a184

Browse files
committed
Merge pull request #1714 from paroj:ovis_texup
2 parents a83b78e + c655c31 commit ff9a184

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

modules/ovis/include/opencv2/ovis.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ enum MaterialProperty
3535
MATERIAL_POINT_SIZE,
3636
MATERIAL_OPACITY,
3737
MATERIAL_EMISSIVE,
38-
MATERIAL_TEXTURE
38+
MATERIAL_TEXTURE0,
39+
MATERIAL_TEXTURE = MATERIAL_TEXTURE0,
40+
MATERIAL_TEXTURE1,
41+
MATERIAL_TEXTURE2,
42+
MATERIAL_TEXTURE3,
3943
};
4044

4145
enum EntityProperty
@@ -281,6 +285,15 @@ CV_EXPORTS_W void createPointCloudMesh(const String& name, InputArray vertices,
281285
* @param segments number of segments per side
282286
*/
283287
CV_EXPORTS_W void createGridMesh(const String& name, const Size2f& size, const Size& segments = Size(1, 1));
288+
289+
/**
290+
* updates an existing texture
291+
*
292+
* A new texture can be created with @ref createPlaneMesh
293+
* @param name name of the texture
294+
* @param image the image data
295+
*/
296+
CV_EXPORTS_W void updateTexture(const String& name, InputArray image);
284297
//! @}
285298
}
286299
}

modules/ovis/src/ovis.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,28 @@ WindowScene::~WindowScene() {}
3131

3232
void _createTexture(const String& name, Mat image)
3333
{
34+
PixelFormat format;
35+
switch(image.type())
36+
{
37+
case CV_8UC4:
38+
format = PF_BYTE_BGRA;
39+
break;
40+
case CV_8UC3:
41+
format = PF_BYTE_BGR;
42+
break;
43+
case CV_8UC1:
44+
format = PF_BYTE_L;
45+
break;
46+
default:
47+
CV_Error(Error::StsBadArg, "currently only CV_8UC1, CV_8UC3, CV_8UC4 textures are supported");
48+
break;
49+
}
50+
3451
TextureManager& texMgr = TextureManager::getSingleton();
3552
TexturePtr tex = texMgr.getByName(name, RESOURCEGROUP_NAME);
3653

3754
Image im;
38-
im.loadDynamicImage(image.ptr(), image.cols, image.rows, 1, PF_BYTE_BGR);
55+
im.loadDynamicImage(image.ptr(), image.cols, image.rows, 1, format);
3956

4057
if (tex)
4158
{
@@ -323,7 +340,7 @@ class WindowSceneImpl : public WindowScene
323340

324341
void setBackground(InputArray image)
325342
{
326-
CV_Assert(image.type() == CV_8UC3, bgplane);
343+
CV_Assert(bgplane);
327344

328345
String name = sceneMgr->getName() + "_Background";
329346

@@ -700,20 +717,23 @@ void setMaterialProperty(const String& name, int prop, const Scalar& val)
700717

701718
void setMaterialProperty(const String& name, int prop, const String& value)
702719
{
703-
CV_Assert(prop == MATERIAL_TEXTURE, _app);
720+
CV_Assert(prop >= MATERIAL_TEXTURE0, prop <= MATERIAL_TEXTURE3, _app);
704721

705722
MaterialPtr mat = MaterialManager::getSingleton().getByName(name, RESOURCEGROUP_NAME);
706723
CV_Assert(mat);
707724

708725
Pass* rpass = mat->getTechniques()[0]->getPasses()[0];
709726

710-
if (rpass->getTextureUnitStates().empty())
727+
size_t texUnit = prop - MATERIAL_TEXTURE0;
728+
CV_Assert(texUnit <= rpass->getTextureUnitStates().size());
729+
730+
if (rpass->getTextureUnitStates().size() <= texUnit)
711731
{
712732
rpass->createTextureUnitState(value);
713733
return;
714734
}
715735

716-
rpass->getTextureUnitStates()[0]->setTextureName(value);
736+
rpass->getTextureUnitStates()[texUnit]->setTextureName(value);
717737
}
718738

719739
static bool setShaderProperty(const GpuProgramParametersSharedPtr& params, const String& prop,
@@ -770,5 +790,13 @@ void setMaterialProperty(const String& name, const String& prop, const Scalar& v
770790
if(!set)
771791
CV_Error_(Error::StsBadArg, ("shader parameter named '%s' not found", prop.c_str()));
772792
}
793+
794+
void updateTexture(const String& name, InputArray image)
795+
{
796+
CV_Assert(_app);
797+
TexturePtr tex = TextureManager::getSingleton().getByName(name, RESOURCEGROUP_NAME);
798+
CV_Assert(tex);
799+
_createTexture(name, image.getMat());
800+
}
773801
}
774802
}

0 commit comments

Comments
 (0)