mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
polyline now uses scalars for color data (for reuse by other widgets)
This commit is contained in:
parent
e94ee94be3
commit
771d9509a8
@ -400,18 +400,29 @@ cv::viz::WPolyLine::WPolyLine(InputArray _points, const Color &color)
|
|||||||
for(size_t i = 0; i < total; ++i)
|
for(size_t i = 0; i < total; ++i)
|
||||||
cell_array->InsertCellPoint(i);
|
cell_array->InsertCellPoint(i);
|
||||||
|
|
||||||
|
Vec3b rgb = Vec3d(color[2], color[1], color[0]);
|
||||||
|
Vec3b* color_data = new Vec3b[total];
|
||||||
|
std::fill(color_data, color_data + total, rgb);
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
|
||||||
|
scalars->SetName("Colors");
|
||||||
|
scalars->SetNumberOfComponents(3);
|
||||||
|
scalars->SetNumberOfTuples(total);
|
||||||
|
scalars->SetArray(color_data->val, total * 3, 0);
|
||||||
|
|
||||||
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
|
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
|
||||||
polydata->SetPoints(points);
|
polydata->SetPoints(points);
|
||||||
polydata->SetLines(cell_array);
|
polydata->SetLines(cell_array);
|
||||||
|
polydata->GetPointData()->SetScalars(scalars);
|
||||||
|
|
||||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(polydata->GetProducerPort());
|
mapper->SetInputConnection(polydata->GetProducerPort());
|
||||||
|
mapper->SetScalarRange(0, 255);
|
||||||
|
|
||||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||||
actor->SetMapper(mapper);
|
actor->SetMapper(mapper);
|
||||||
|
|
||||||
WidgetAccessor::setProp(*this, actor);
|
WidgetAccessor::setProp(*this, actor);
|
||||||
setColor(color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> cv::viz::WPolyLine cv::viz::Widget::cast<cv::viz::WPolyLine>()
|
template<> cv::viz::WPolyLine cv::viz::Widget::cast<cv::viz::WPolyLine>()
|
||||||
|
Loading…
Reference in New Issue
Block a user