Commit 45879fb9 authored by Anatoly Baksheev's avatar Anatoly Baksheev

more refactoring

parent a8556134
...@@ -188,7 +188,7 @@ namespace cv ...@@ -188,7 +188,7 @@ namespace cv
struct VtkUtils struct VtkUtils
{ {
template<class Filter> template<class Filter>
static inline void SetInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata) static void SetInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata)
{ {
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
filter->SetInput(polydata); filter->SetInput(polydata);
...@@ -198,7 +198,7 @@ namespace cv ...@@ -198,7 +198,7 @@ namespace cv
} }
template<class Filter> template<class Filter>
static inline void AddInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata) static void AddInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata)
{ {
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
filter->AddInput(polydata); filter->AddInput(polydata);
...@@ -206,6 +206,20 @@ namespace cv ...@@ -206,6 +206,20 @@ namespace cv
filter->AddInputData(polydata); filter->AddInputData(polydata);
#endif #endif
} }
static vtkSmartPointer<vtkUnsignedCharArray> FillScalars(size_t size, const Color& color)
{
Vec3b rgb = Vec3d(color[2], color[1], color[0]);
Vec3b* color_data = new Vec3b[size];
std::fill(color_data, color_data + size, rgb);
vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
scalars->SetName("Colors");
scalars->SetNumberOfComponents(3);
scalars->SetNumberOfTuples(size);
scalars->SetArray(color_data->val, size * 3, 0);
return scalars;
}
}; };
} }
} }
......
...@@ -400,15 +400,7 @@ cv::viz::WPolyLine::WPolyLine(InputArray _points, const Color &color) ...@@ -400,15 +400,7 @@ 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]); vtkSmartPointer<vtkUnsignedCharArray> scalars = VtkUtils::FillScalars(total, color);
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);
...@@ -913,9 +905,9 @@ namespace cv { namespace viz { namespace ...@@ -913,9 +905,9 @@ namespace cv { namespace viz { namespace
// Create frustum // Create frustum
camera->SetViewAngle(fovy); camera->SetViewAngle(fovy);
camera->SetPosition(0.0,0.0,0.0); camera->SetPosition(0.0, 0.0, 0.0);
camera->SetViewUp(0.0,1.0,0.0); camera->SetViewUp(0.0, 1.0, 0.0);
camera->SetFocalPoint(0.0,0.0,1.0); camera->SetFocalPoint(0.0, 0.0, 1.0);
camera->SetClippingRange(0.01, scale); camera->SetClippingRange(0.01, scale);
double planesArray[24]; double planesArray[24];
...@@ -955,39 +947,10 @@ namespace cv { namespace viz { namespace ...@@ -955,39 +947,10 @@ namespace cv { namespace viz { namespace
cv::viz::WCameraPosition::WCameraPosition(double scale) cv::viz::WCameraPosition::WCameraPosition(double scale)
{ {
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
axes->SetOrigin(0, 0, 0);
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();
#endif
axes_data->GetPointData()->SetScalars(axes_colors);
vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::New();
#if VTK_MAJOR_VERSION <= 5
axes_tubes->SetInput(axes_data);
#else
axes_tubes->SetInputData(axes_data);
#endif
axes_tubes->SetRadius(axes->GetScaleFactor() / 50.0);
axes_tubes->SetNumberOfSides(6);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, getPolyData(WCoordinateSystem(scale)));
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
mapper->SetInputConnection(axes_tubes->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
...@@ -1035,7 +998,6 @@ cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, double scale, const ...@@ -1035,7 +998,6 @@ cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, double scale, const
setColor(color); setColor(color);
} }
cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, double scale, const Color &color) cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, double scale, const Color &color)
{ {
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New(); vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
...@@ -1299,28 +1261,19 @@ cv::viz::WTrajectorySpheres::WTrajectorySpheres(const std::vector<Affine3d> &pat ...@@ -1299,28 +1261,19 @@ cv::viz::WTrajectorySpheres::WTrajectorySpheres(const std::vector<Affine3d> &pat
line_scalars->InsertNextTuple3(line_color[2], line_color[1], line_color[0]); line_scalars->InsertNextTuple3(line_color[2], line_color[1], line_color[0]);
// Create color array for sphere // Create color array for sphere
vtkSphereSource * dummy_sphere = vtkSphereSource::New(); vtkSmartPointer<vtkSphereSource> dummy_sphere = vtkSmartPointer<vtkSphereSource>::New();
// Create the array for big sphere // Create the array for big sphere
dummy_sphere->SetRadius(init_sphere_radius); dummy_sphere->SetRadius(init_sphere_radius);
dummy_sphere->Update(); dummy_sphere->Update();
vtkIdType nr_points = dummy_sphere->GetOutput()->GetNumberOfCells(); vtkIdType nr_points = dummy_sphere->GetOutput()->GetNumberOfCells();
vtkSmartPointer<vtkUnsignedCharArray> sphere_scalars_init = vtkSmartPointer<vtkUnsignedCharArray>::New(); vtkSmartPointer<vtkUnsignedCharArray> sphere_scalars_init = VtkUtils::FillScalars(nr_points, sphere_color);
sphere_scalars_init->SetNumberOfComponents(3);
sphere_scalars_init->SetNumberOfTuples(nr_points);
sphere_scalars_init->FillComponent(0, sphere_color[2]);
sphere_scalars_init->FillComponent(1, sphere_color[1]);
sphere_scalars_init->FillComponent(2, sphere_color[0]);
// Create the array for small sphere // Create the array for small sphere
dummy_sphere->SetRadius(sphere_radius); dummy_sphere->SetRadius(sphere_radius);
dummy_sphere->Update(); dummy_sphere->Update();
nr_points = dummy_sphere->GetOutput()->GetNumberOfCells(); nr_points = dummy_sphere->GetOutput()->GetNumberOfCells();
vtkSmartPointer<vtkUnsignedCharArray> sphere_scalars = vtkSmartPointer<vtkUnsignedCharArray>::New(); vtkSmartPointer<vtkUnsignedCharArray> sphere_scalars = VtkUtils::FillScalars(nr_points, sphere_color);
sphere_scalars->SetNumberOfComponents(3);
sphere_scalars->SetNumberOfTuples(nr_points);
sphere_scalars->FillComponent(0, sphere_color[2]);
sphere_scalars->FillComponent(1, sphere_color[1]);
sphere_scalars->FillComponent(2, sphere_color[0]);
dummy_sphere->Delete();
for (vtkIdType i = 0; i < nr_poses; ++i) for (vtkIdType i = 0; i < nr_poses; ++i)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment