Skip to content

Commit e916e24

Browse files
committed
Add python binding for DrawTool::drawRGBAImage()
1 parent 6bd294b commit e916e24

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_VisualParams.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ void moduleAddVisualParams(py::module &m)
9595
dt.def("drawText", [](DrawTool* self, int x, int y, int fontSize, char* text){
9696
self->writeOverlayText(x,y, fontSize, sofa::type::RGBAColor::white(), text);
9797
});
98+
dt.def("drawRGBAImage", [](DrawTool* self, const std::string& id, const sofa::type::Vec3& pos, const int w, const int h, const int mode, const char* data){
99+
self->drawRGBAImage(id, pos, w, h, mode, data);
100+
});
101+
dt.def("drawRGBAImage", [](DrawTool* self, const std::string& id, const sofa::type::Vec3& pos, const std::string& filename){
102+
self->drawRGBAImage(id, pos, filename);
103+
});
104+
98105
}
99106

100107
} /// namespace sofapython3

examples/example-drawing-controller.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import Sofa
22
import SofaTypes
33

4+
from PIL import Image
5+
46
class DrawingExamples(Sofa.Core.Controller):
57
def __init__(self, *args, **kwargs):
68
# These are needed (and the normal way to override from a python class)
79
Sofa.Core.Controller.__init__(self, *args, **kwargs)
810

911
self.target = kwargs.get("target", None)
1012
self.mo = kwargs.get("mo", None)
13+
self.img = Image.open("oip.jpeg").convert("RGBA")
1114

1215
def draw(self, visual_context):
1316
dt = visual_context.getDrawTool()
@@ -23,10 +26,14 @@ def draw(self, visual_context):
2326
dt.drawText(10,10, 12, "Overlay text")
2427

2528
dt.drawFrames(self.mo.position, SofaTypes.Vec3d(0.1,0.1,0.1))
29+
w,h = self.img.size
30+
dt.drawRGBAImage("memory", SofaTypes.Vec3d(0.0,0.0,0.0), w ,h, 32, self.img.tobytes())
31+
#dt.drawRGBAImage("image", SofaTypes.Vec3d(0.0,0.0,0.0), "oip.jpeg")
2632

2733
def createScene(root):
2834
root.dt = 0.01
2935
root.bbox = [[-1,-1,-1],[1,1,1]]
36+
root.addObject('RequiredPlugin', name="Sofa.GL.Component.Shader")
3037
root.addObject('DefaultVisualManagerLoop')
3138
root.addObject('DefaultAnimationLoop')
3239

examples/oip.jpeg

24 KB
Loading

0 commit comments

Comments
 (0)