trajectory widget display options: display path, display frames, display both
This commit is contained in:
parent
aa2594c06c
commit
7d458e852e
@ -180,7 +180,9 @@ namespace cv
|
|||||||
class CV_EXPORTS TrajectoryWidget : public Widget3D
|
class CV_EXPORTS TrajectoryWidget : public Widget3D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TrajectoryWidget(const std::vector<Affine3f> &path, const Color &color = Color::white(), bool show_frames = false, double scale = 1.0);
|
enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2};
|
||||||
|
|
||||||
|
TrajectoryWidget(const std::vector<Affine3f> &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0);
|
||||||
TrajectoryWidget(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); // Camera frustums
|
TrajectoryWidget(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); // Camera frustums
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1162,8 +1162,13 @@ 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)
|
||||||
{
|
{
|
||||||
|
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
|
||||||
|
|
||||||
|
if (display_mode & TrajectoryWidget::DISPLAY_PATH)
|
||||||
|
{
|
||||||
|
// Create a poly line along the path
|
||||||
vtkIdType nr_points = path.size();
|
vtkIdType nr_points = path.size();
|
||||||
|
|
||||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ();
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ();
|
||||||
@ -1176,7 +1181,6 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, c
|
|||||||
|
|
||||||
Vec3f last_pos(0.0f,0.0f,0.0f);
|
Vec3f last_pos(0.0f,0.0f,0.0f);
|
||||||
Vec3f *data_beg = vtkpoints_data<float>(points);
|
Vec3f *data_beg = vtkpoints_data<float>(points);
|
||||||
*data_beg = path[0] * last_pos;
|
|
||||||
|
|
||||||
for (vtkIdType i = 0; i < nr_points; ++i)
|
for (vtkIdType i = 0; i < nr_points; ++i)
|
||||||
{
|
{
|
||||||
@ -1191,9 +1195,21 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, c
|
|||||||
polyData->SetPoints(points);
|
polyData->SetPoints(points);
|
||||||
polyData->SetLines(cells);
|
polyData->SetLines(cells);
|
||||||
|
|
||||||
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
|
// Set the color for polyData
|
||||||
if (show_frames)
|
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();
|
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
|
||||||
axes->SetOrigin (0, 0, 0);
|
axes->SetOrigin (0, 0, 0);
|
||||||
axes->SetScaleFactor (scale);
|
axes->SetScaleFactor (scale);
|
||||||
@ -1220,18 +1236,6 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, c
|
|||||||
ApplyPath::applyPath(axes_tubes->GetOutput(), appendFilter, path);
|
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();
|
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetScalarModeToUsePointData ();
|
mapper->SetScalarModeToUsePointData ();
|
||||||
mapper->SetInput(appendFilter->GetOutput());
|
mapper->SetInput(appendFilter->GetOutput());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user