refactored WCoordinateSystem widget

This commit is contained in:
Anatoly Baksheev 2014-01-07 21:28:29 +04:00
parent 56819eaf19
commit e94ee94be3

View File

@ -335,36 +335,28 @@ cv::viz::WCoordinateSystem::WCoordinateSystem(double scale)
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);
vtkSmartPointer<vtkFloatArray> axes_colors = vtkSmartPointer<vtkFloatArray>::New();
axes_colors->Allocate(6);
axes_colors->InsertNextValue(0.0);
axes_colors->InsertNextValue(0.0);
axes_colors->InsertNextValue(0.5);
axes_colors->InsertNextValue(0.5);
axes_colors->InsertNextValue(1.0);
axes_colors->InsertNextValue(1.0);
vtkSmartPointer<vtkPolyData> axes_data = axes->GetOutput();
#if VTK_MAJOR_VERSION <= 5
axes_data->Update();
#else
axes->Update(); axes->Update();
#endif
axes_data->GetPointData()->SetScalars(axes_colors);
vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::New(); vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
#if VTK_MAJOR_VERSION <= 5 colors->SetNumberOfComponents(3);
axes_tubes->SetInput(axes_data); colors->InsertNextTuple3(255, 0, 0);
#else colors->InsertNextTuple3(255, 0, 0);
axes_tubes->SetInputData(axes_data); colors->InsertNextTuple3(0, 255, 0);
#endif colors->InsertNextTuple3(0, 255, 0);
axes_tubes->SetRadius(axes->GetScaleFactor() / 50.0); colors->InsertNextTuple3(0, 0, 255);
axes_tubes->SetNumberOfSides(6); colors->InsertNextTuple3(0, 0, 255);
vtkSmartPointer<vtkPolyData> polydata = axes->GetOutput();
polydata->GetPointData()->SetScalars(colors);
vtkSmartPointer<vtkTubeFilter> tube_filter = vtkSmartPointer<vtkTubeFilter>::New();
VtkUtils::SetInputData(tube_filter, polydata);
tube_filter->SetRadius(axes->GetScaleFactor() / 50.0);
tube_filter->SetNumberOfSides(6);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
mapper->SetInputConnection(axes_tubes->GetOutputPort()); VtkUtils::SetInputData(mapper, tube_filter->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);