polyline now uses scalars for color data (for reuse by other widgets)

pull/2173/head
Anatoly Baksheev 11 years ago
parent e94ee94be3
commit 771d9509a8
  1. 13
      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<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();
polydata->SetPoints(points);
polydata->SetLines(cell_array);
polydata->GetPointData()->SetScalars(scalars);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polydata->GetProducerPort());
mapper->SetScalarRange(0, 255);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
WidgetAccessor::setProp(*this, actor);
setColor(color);
}
template<> cv::viz::WPolyLine cv::viz::Widget::cast<cv::viz::WPolyLine>()

Loading…
Cancel
Save