diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp index 2088e7d402..b1ef3de5e0 100644 --- a/modules/viz/src/shapes.cpp +++ b/modules/viz/src/shapes.cpp @@ -381,72 +381,39 @@ template<> cv::viz::WCoordinateSystem cv::viz::Widget::cast - static void copy(const Mat& source, Vec<_Tp, 3> *output, vtkSmartPointer polyLine) - { - int s_chs = source.channels(); + CV_Assert(_points.type() == CV_32FC3 || _points.type() == CV_32FC4 || _points.type() == CV_64FC3 || _points.type() == CV_64FC4); - for (int y = 0, id = 0; y < source.rows; ++y) - { - const _Tp* srow = source.ptr<_Tp>(y); - - for (int x = 0; x < source.cols; ++x, srow += s_chs, ++id) - { - *output++ = Vec<_Tp, 3>(srow); - polyLine->GetPointIds()->SetId(id,id); - } - } - } - }; -}}} - -cv::viz::WPolyLine::WPolyLine(InputArray _pointData, const Color &color) -{ - Mat pointData = _pointData.getMat(); - CV_Assert(pointData.type() == CV_32FC3 || pointData.type() == CV_32FC4 || pointData.type() == CV_64FC3 || pointData.type() == CV_64FC4); - vtkIdType nr_points = pointData.total(); + const float *fpoints = _points.getMat().ptr(); + const double *dpoints = _points.getMat().ptr(); + size_t total = _points.total(); + int s_chs = _points.channels(); vtkSmartPointer points = vtkSmartPointer::New(); - vtkSmartPointer polyData = vtkSmartPointer::New(); - vtkSmartPointer polyLine = vtkSmartPointer::New(); + points->SetDataType(_points.depth() == CV_32F ? VTK_FLOAT : VTK_DOUBLE); + points->SetNumberOfPoints(total); - if (pointData.depth() == CV_32F) - points->SetDataTypeToFloat(); - else - points->SetDataTypeToDouble(); + if (_points.depth() == CV_32F) + for(size_t i = 0; i < total; ++i, fpoints += s_chs) + points->SetPoint(i, fpoints); - points->SetNumberOfPoints(nr_points); - polyLine->GetPointIds()->SetNumberOfIds(nr_points); + if (_points.depth() == CV_64F) + for(size_t i = 0; i < total; ++i, dpoints += s_chs) + points->SetPoint(i, dpoints); - if (pointData.depth() == CV_32F) - { - // Get a pointer to the beginning of the data array - Vec3f *data_beg = vtkpoints_data(points); - PolyLineUtils::copy(pointData, data_beg, polyLine); - } - else if (pointData.depth() == CV_64F) - { - // Get a pointer to the beginning of the data array - Vec3d *data_beg = vtkpoints_data(points); - PolyLineUtils::copy(pointData, data_beg, polyLine); - } + vtkSmartPointer cell_array = vtkSmartPointer::New(); + cell_array->Allocate(cell_array->EstimateSize(1, total)); + cell_array->InsertNextCell(total); + for(size_t i = 0; i < total; ++i) + cell_array->InsertCellPoint(i); - vtkSmartPointer cells = vtkSmartPointer::New(); - cells->InsertNextCell(polyLine); - - polyData->SetPoints(points); - polyData->SetLines(cells); + vtkSmartPointer polydata = vtkSmartPointer::New(); + polydata->SetPoints(points); + polydata->SetLines(cell_array); vtkSmartPointer mapper = vtkSmartPointer::New(); -#if VTK_MAJOR_VERSION <= 5 - mapper->SetInput(polyData); -#else - mapper->SetInputData(polyData); -#endif + mapper->SetInputConnection(polydata->GetProducerPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -831,7 +798,7 @@ cv::viz::WImage3D::WImage3D(const Vec3f &position, const Vec3f &normal, const Ve // Apply the transform after texture mapping vtkSmartPointer transform = vtkSmartPointer::New(); transform->PreMultiply(); - transform->SetMatrix(vtkmatrix(pose)); + transform->SetMatrix(vtkmatrix(pose.matrix)); transform->Scale(size.width, size.height, 1.0); vtkSmartPointer transform_filter = vtkSmartPointer::New(); diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp index f311ff2b79..6f61a806c6 100644 --- a/modules/viz/test/tests_simple.cpp +++ b/modules/viz/test/tests_simple.cpp @@ -130,6 +130,18 @@ TEST(Viz, DISABLED_show_mesh_random_colors) viz.spin(); } +TEST(Viz, DISABLED_show_polyline) +{ + Mat polyline(1, 32, CV_64FC3); + for(size_t i = 0; i < polyline.total(); ++i) + polyline.at(i) = Vec3d(i/16.0, cos(i * CV_PI/6), sin(i * CV_PI/6)); + + Viz3d viz("show_polyline"); + viz.showWidget("polyline", WPolyLine(Mat(polyline), Color::apricot())); + viz.showWidget("coosys", WCoordinateSystem()); + viz.spin(); +} + TEST(Viz, DISABLED_show_sampled_normals) { Mesh3d mesh = Mesh3d::load(get_dragon_ply_file_path());