|
|
|
@ -1162,38 +1162,54 @@ struct cv::viz::TrajectoryWidget::ApplyPath |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, const Color &color, bool show_frames, double scale) |
|
|
|
|
cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, int display_mode, const Color &color, double scale) |
|
|
|
|
{ |
|
|
|
|
vtkIdType nr_points = path.size();
|
|
|
|
|
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New(); |
|
|
|
|
|
|
|
|
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New (); |
|
|
|
|
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New (); |
|
|
|
|
vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New (); |
|
|
|
|
if (display_mode & TrajectoryWidget::DISPLAY_PATH) |
|
|
|
|
{ |
|
|
|
|
// Create a poly line along the path
|
|
|
|
|
vtkIdType nr_points = path.size();
|
|
|
|
|
|
|
|
|
|
points->SetDataTypeToFloat(); |
|
|
|
|
points->SetNumberOfPoints(nr_points); |
|
|
|
|
polyLine->GetPointIds()->SetNumberOfIds(nr_points); |
|
|
|
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New (); |
|
|
|
|
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New (); |
|
|
|
|
vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New (); |
|
|
|
|
|
|
|
|
|
Vec3f last_pos(0.0f,0.0f,0.0f); |
|
|
|
|
Vec3f *data_beg = vtkpoints_data<float>(points); |
|
|
|
|
*data_beg = path[0] * last_pos; |
|
|
|
|
points->SetDataTypeToFloat(); |
|
|
|
|
points->SetNumberOfPoints(nr_points); |
|
|
|
|
polyLine->GetPointIds()->SetNumberOfIds(nr_points); |
|
|
|
|
|
|
|
|
|
for (vtkIdType i = 0; i < nr_points; ++i) |
|
|
|
|
{ |
|
|
|
|
last_pos = path[i] * last_pos; |
|
|
|
|
*data_beg++ = last_pos; |
|
|
|
|
polyLine->GetPointIds()->SetId(i,i); |
|
|
|
|
} |
|
|
|
|
Vec3f last_pos(0.0f,0.0f,0.0f); |
|
|
|
|
Vec3f *data_beg = vtkpoints_data<float>(points); |
|
|
|
|
|
|
|
|
|
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); |
|
|
|
|
cells->InsertNextCell(polyLine); |
|
|
|
|
for (vtkIdType i = 0; i < nr_points; ++i) |
|
|
|
|
{ |
|
|
|
|
last_pos = path[i] * last_pos; |
|
|
|
|
*data_beg++ = last_pos; |
|
|
|
|
polyLine->GetPointIds()->SetId(i,i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
polyData->SetPoints(points); |
|
|
|
|
polyData->SetLines(cells); |
|
|
|
|
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); |
|
|
|
|
cells->InsertNextCell(polyLine); |
|
|
|
|
|
|
|
|
|
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New(); |
|
|
|
|
if (show_frames) |
|
|
|
|
polyData->SetPoints(points); |
|
|
|
|
polyData->SetLines(cells); |
|
|
|
|
|
|
|
|
|
// Set the color for polyData
|
|
|
|
|
vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New(); |
|
|
|
|
colors->SetNumberOfComponents(3); |
|
|
|
|
|
|
|
|
|
// TODO Make this more efficient
|
|
|
|
|
for (int i = 0; i < nr_points; ++i) |
|
|
|
|
colors->InsertNextTuple3(color[2], color[1], color[0]); |
|
|
|
|
|
|
|
|
|
polyData->GetPointData()->SetScalars(colors); |
|
|
|
|
appendFilter->AddInputConnection(polyData->GetProducerPort()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (display_mode & TrajectoryWidget::DISPLAY_FRAMES) |
|
|
|
|
{ |
|
|
|
|
// Create frames and transform along the path
|
|
|
|
|
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New(); |
|
|
|
|
axes->SetOrigin (0, 0, 0); |
|
|
|
|
axes->SetScaleFactor (scale); |
|
|
|
@ -1220,18 +1236,6 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, c |
|
|
|
|
ApplyPath::applyPath(axes_tubes->GetOutput(), appendFilter, path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set the color for polyData
|
|
|
|
|
vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New(); |
|
|
|
|
colors->SetNumberOfComponents(3); |
|
|
|
|
|
|
|
|
|
// TODO Make this more efficient
|
|
|
|
|
for (int i = 0; i < nr_points; ++i) |
|
|
|
|
colors->InsertNextTuple3(color[2], color[1], color[0]); |
|
|
|
|
|
|
|
|
|
polyData->GetPointData()->SetScalars(colors); |
|
|
|
|
|
|
|
|
|
appendFilter->AddInputConnection(polyData->GetProducerPort()); |
|
|
|
|
|
|
|
|
|
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
|
|
|
|
mapper->SetScalarModeToUsePointData (); |
|
|
|
|
mapper->SetInput(appendFilter->GetOutput()); |
|
|
|
|