diff --git a/modules/viz/src/shape_widgets.cpp b/modules/viz/src/shape_widgets.cpp index 569d934cee..882b82d1ee 100644 --- a/modules/viz/src/shape_widgets.cpp +++ b/modules/viz/src/shape_widgets.cpp @@ -1140,10 +1140,7 @@ template<> cv::viz::CameraPositionWidget cv::viz::Widget::cast poly_data, vtkSmartPointer append_filter, const std::vector &path) - { - vtkSmartPointer mat_trans = vtkSmartPointer::New(); - mat_trans->Identity(); - + { vtkIdType nr_points = path.size(); for (vtkIdType i = 0; i < nr_points; ++i) @@ -1154,7 +1151,8 @@ struct cv::viz::TrajectoryWidget::ApplyPath // Transform the default coordinate frame vtkSmartPointer transform = vtkSmartPointer::New(); transform->PreMultiply(); - vtkMatrix4x4::Multiply4x4(convertToVtkMatrix(path[i].matrix), mat_trans, mat_trans); + vtkSmartPointer mat_trans = vtkSmartPointer::New(); + mat_trans = convertToVtkMatrix(path[i].matrix); transform->SetMatrix(mat_trans); vtkSmartPointer filter = vtkSmartPointer::New(); @@ -1185,13 +1183,12 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, i points->SetNumberOfPoints(nr_points); polyLine->GetPointIds()->SetNumberOfIds(nr_points); - Vec3f last_pos(0.0f,0.0f,0.0f); Vec3f *data_beg = vtkpoints_data(points); for (vtkIdType i = 0; i < nr_points; ++i) { - last_pos = path[i] * last_pos; - *data_beg++ = last_pos; + Vec3f cam_pose = path[i].translation(); + *data_beg++ = cam_pose; polyLine->GetPointIds()->SetId(i,i); } @@ -1257,7 +1254,6 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, f { vtkSmartPointer appendFilter = vtkSmartPointer::New(); vtkIdType nr_poses = path.size(); - Point3f last_pos(0.0f,0.0f,0.0f); // Create color arrays vtkSmartPointer line_scalars = vtkSmartPointer::New(); @@ -1290,7 +1286,7 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, f for (vtkIdType i = 0; i < nr_poses; ++i) { - Point3f new_pos = path[i] * last_pos; + Point3f new_pos = path[i].translation(); vtkSmartPointer sphere_source = vtkSmartPointer::New(); sphere_source->SetCenter (new_pos.x, new_pos.y, new_pos.z); @@ -1300,7 +1296,6 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, f sphere_source->Update(); sphere_source->GetOutput()->GetCellData()->SetScalars(sphere_scalars_init); appendFilter->AddInputConnection(sphere_source->GetOutputPort()); - last_pos = new_pos; continue; } else @@ -1311,7 +1306,9 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, f appendFilter->AddInputConnection(sphere_source->GetOutputPort()); } - Vec3f v = last_pos - new_pos; + + Affine3f relativeAffine = path[i].inv() * path[i-1]; + Vec3f v = path[i].rotation() * relativeAffine.translation(); v = normalize(v) * line_length; vtkSmartPointer line_source = vtkSmartPointer::New(); @@ -1321,7 +1318,6 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, f line_source->GetOutput()->GetCellData()->SetScalars(line_scalars); appendFilter->AddInputConnection(line_source->GetOutputPort()); - last_pos = new_pos; } vtkSmartPointer mapper = vtkSmartPointer::New();