2929#include < SofaPython3/Sofa/Core/Binding_DrawTool.h>
3030#include < SofaPython3/Sofa/Core/Binding_DrawTool_doc.h>
3131
32+ #include < sofa/core/topology/BaseMeshTopology.h>
33+
3234#include < SofaPython3/PythonFactory.h>
3335#include < sofa/core/objectmodel/Data.h>
3436#include < sofa/type/RGBAColor.h>
@@ -114,6 +116,85 @@ void moduleAddDrawTool(py::module &m)
114116 self->drawLines (positions->getValue (), size, color);
115117 });
116118
119+ // Draw disk
120+ dt.def (" drawDisk" , [](DrawTool *self, float radius, double from, double to, int resolution, sofa::type::RGBAColor& color) {
121+ self->drawDisk (radius, from, to, resolution, color);
122+ });
123+ dt.def (" drawCircle" , [](DrawTool *self, float radius, float lineThickness, int resolution, sofa::type::RGBAColor& color) {
124+ self->drawCircle (radius, lineThickness, resolution, color);
125+ });
126+
127+ // Draw mesh
128+ dt.def (" drawTriangles" , [](DrawTool *self, BaseData* dpositions, BaseData* dtriangles, sofa::type::RGBAColor& color){
129+ auto positions = dynamic_cast <Data<sofa::type::vector<sofa::type::Vec3d>>*>(dpositions);
130+ if (!positions)
131+ throw std::runtime_error (" Invalid argument, expecting a vector<Rigid3> or vector<Vec3>, got " +dpositions->getValueTypeString ());
132+
133+ auto triangles = dynamic_cast <Data<sofa::type::vector<sofa::topology::Triangle>>*>(dtriangles);
134+ if (!triangles)
135+ throw std::runtime_error (" Invalid argument, expecting vector<Triangle>, got " +dtriangles->getValueTypeString ());
136+
137+ auto & cpos = positions->getValue ();
138+ auto & ctris = triangles->getValue ();
139+
140+ std::vector<sofa::type::Vec3> tripos;
141+ tripos.resize (ctris.size ()*3 );
142+
143+ for (auto & ctri : ctris)
144+ {
145+ tripos.emplace_back (cpos[ctri[0 ]]);
146+ tripos.emplace_back (cpos[ctri[1 ]]);
147+ tripos.emplace_back (cpos[ctri[2 ]]);
148+ }
149+
150+ self->drawTriangles (tripos, color);
151+ });
152+
153+ // Draw mesh
154+ dt.def (" drawQuads" , [](DrawTool *self, BaseData* dpositions, BaseData* dquads, sofa::type::RGBAColor& color){
155+ auto positions = dynamic_cast <Data<sofa::type::vector<sofa::type::Vec3d>>*>(dpositions);
156+ if (!positions)
157+ throw std::runtime_error (" Invalid argument, expecting a vector<Rigid3> or vector<Vec3>, got " +dpositions->getValueTypeString ());
158+
159+ auto quads = dynamic_cast <Data<sofa::type::vector<sofa::topology::Quad>>*>(dquads);
160+ if (!quads)
161+ throw std::runtime_error (" Invalid argument, expecting vector<Quad>, got " +dquads->getValueTypeString ());
162+
163+ auto & cpos = positions->getValue ();
164+ auto & ctris = quads->getValue ();
165+
166+ std::vector<sofa::type::Vec3> quadpos;
167+ quadpos.resize (ctris.size ()*4 );
168+
169+ for (auto & ctri : ctris)
170+ {
171+ quadpos.emplace_back (cpos[ctri[0 ]]);
172+ quadpos.emplace_back (cpos[ctri[1 ]]);
173+ quadpos.emplace_back (cpos[ctri[2 ]]);
174+ quadpos.emplace_back (cpos[ctri[3 ]]);
175+ }
176+
177+ self->drawQuads (quadpos, color);
178+ });
179+
180+
181+ // Draw spheres
182+ dt.def (" drawSpheres" , [](DrawTool *self, const py::array_t <double >& positions, const std::vector<float >& radius, sofa::type::RGBAColor& color){
183+ self->drawSpheres (getPoints (positions), radius, color);
184+ });
185+ dt.def (" drawSpheres" , [](DrawTool *self, BaseData* dpositions, const float radius, sofa::type::RGBAColor& color){
186+ auto positions = dynamic_cast <Data<sofa::type::vector<sofa::type::Vec3>>*>(dpositions);
187+ if (!positions)
188+ throw std::runtime_error (" Invalid argument, expecting a vector<Rigid3> or vector<Vec3>, got " +dpositions->getValueTypeString ());
189+ self->drawSpheres (positions->getValue (), radius, color);
190+ });
191+
192+ // Draw boundingBox
193+ dt.def (" boundingBox" , [](DrawTool *self, const std::array<double ,4 >& min, const std::array<double , 4 >& max, double width){
194+ sofa::type::Vec3d cmin { min[0 ], min[1 ], min[2 ] };
195+ sofa::type::Vec3d cmax { max[0 ], max[1 ], max[2 ] };
196+ self->drawBoundingBox ( cmin, cmax, width);
197+ });
117198
118199 // Draw frames
119200 dt.def (" drawFrames" , [](DrawTool* self,
@@ -143,6 +224,9 @@ void moduleAddDrawTool(py::module &m)
143224 }
144225 });
145226
227+ dt.def (" enableLighting" , [](DrawTool* self){ self->enableLighting (); });
228+ dt.def (" disableLighting" , [](DrawTool* self){ self->disableLighting (); });
229+
146230 // Draw text
147231 dt.def (" drawText" , [](DrawTool* self,
148232 const std::array<double ,3 >& point,
@@ -158,6 +242,9 @@ void moduleAddDrawTool(py::module &m)
158242 int fontSize, char * text, sofa::type::RGBAColor& color){
159243 self->writeOverlayText (point[0 ],point[1 ], fontSize, color, text);
160244 });
245+
246+
247+
161248}
162249
163250} // / namespace sofapython3
0 commit comments