@@ -57,7 +57,7 @@ sofa::type::vector<sofa::type::Vec3> getPoints(const py::array_t<double>& array)
5757 std::vector<sofa::type::Vec3d> points;
5858 points.resize (rows);
5959 for (size_t i = 0 ; i < rows; ++i)
60- for (size_t j = 0 ; j < cols ; ++j)
60+ for (size_t j = 0 ; j < 3 ; ++j)
6161 points[i][j] = ptr[i * cols + j];
6262
6363 return points;
@@ -89,11 +89,11 @@ void moduleAddDrawTool(py::module &m)
8989{
9090 py::class_<DrawTool> dt (m, " DrawTool" , sofapython3::doc::drawtool::baseDrawToolClass);
9191
92+ // Draw points
9293 dt.def (" drawPoints" , [](DrawTool *self, py::array_t <double > points, float size, sofa::type::RGBAColor& color)
9394 {
9495 self->drawPoints (getPoints (points), size, color);
9596 });
96-
9797 dt.def (" drawPoints" , [](DrawTool *self, BaseData* dpositions, float size, sofa::type::RGBAColor& color){
9898 auto positions = dynamic_cast <Data<sofa::type::vector<sofa::type::Vec3>>*>(dpositions);
9999 if (!positions)
@@ -102,10 +102,20 @@ void moduleAddDrawTool(py::module &m)
102102 self->drawPoints (positions->getValue (), size, color);
103103 });
104104
105+ // / Draw lines
105106 dt.def (" drawLines" , [](DrawTool *self, const py::array_t <double >& positions, const float size, sofa::type::RGBAColor& color){
106107 self->drawLines (getPoints (positions), size, color);
107108 });
109+ dt.def (" drawLines" , [](DrawTool *self, BaseData* dpositions, const float size, sofa::type::RGBAColor& color){
110+ auto positions = dynamic_cast <Data<sofa::type::vector<sofa::type::Vec3>>*>(dpositions);
111+ if (!positions)
112+ throw std::runtime_error (" Invalid argument, expecting a vector<Rigid3> or vector<Vec3>, got " +dpositions->getValueTypeString ());
113+
114+ self->drawLines (positions->getValue (), size, color);
115+ });
108116
117+
118+ // Draw frames
109119 dt.def (" drawFrames" , [](DrawTool* self,
110120 const py::array_t <double >& points,
111121 const py::array_t <double >& orientations,
@@ -118,7 +128,6 @@ void moduleAddDrawTool(py::module &m)
118128 self->drawFrame (cpoints[i], corientations[i], csize);
119129 }
120130 });
121-
122131 dt.def (" drawFrames" , [](DrawTool* self, BaseData* dpositions, std::array<double , 3 >& size ){
123132 using sofa::defaulttype::Rigid3Types;
124133 using Coord = sofa::defaulttype::Rigid3Types::Coord;
@@ -134,6 +143,7 @@ void moduleAddDrawTool(py::module &m)
134143 }
135144 });
136145
146+ // Draw text
137147 dt.def (" drawText" , [](DrawTool* self,
138148 const std::array<double ,3 >& point,
139149 const float size,
@@ -143,6 +153,7 @@ void moduleAddDrawTool(py::module &m)
143153 self->draw3DText (point, size, color, text.c_str ());
144154 });
145155
156+ // Draw overlay text
146157 dt.def (" drawOverlayText" , [](DrawTool* self, const std::array<double ,2 >& point,
147158 int fontSize, char * text, sofa::type::RGBAColor& color){
148159 self->writeOverlayText (point[0 ],point[1 ], fontSize, color, text);
0 commit comments