From 771d9509a8dcf50b84ecd60c1340e49a4c62cf81 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Tue, 7 Jan 2014 21:32:54 +0400 Subject: [PATCH] polyline now uses scalars for color data (for reuse by other widgets) --- modules/viz/src/shapes.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp index c8395c6644..67fa43cf70 100644 --- a/modules/viz/src/shapes.cpp +++ b/modules/viz/src/shapes.cpp @@ -400,18 +400,29 @@ cv::viz::WPolyLine::WPolyLine(InputArray _points, const Color &color) for(size_t i = 0; i < total; ++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 scalars = vtkSmartPointer::New(); + scalars->SetName("Colors"); + scalars->SetNumberOfComponents(3); + scalars->SetNumberOfTuples(total); + scalars->SetArray(color_data->val, total * 3, 0); + vtkSmartPointer polydata = vtkSmartPointer::New(); polydata->SetPoints(points); polydata->SetLines(cell_array); + polydata->GetPointData()->SetScalars(scalars); vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputConnection(polydata->GetProducerPort()); + mapper->SetScalarRange(0, 255); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); WidgetAccessor::setProp(*this, actor); - setColor(color); } template<> cv::viz::WPolyLine cv::viz::Widget::cast()