refactored polyline

pull/2173/head
Anatoly Baksheev 11 years ago
parent b100299644
commit 406444037d
  1. 81
      modules/viz/src/shapes.cpp
  2. 12
      modules/viz/test/tests_simple.cpp

@ -381,72 +381,39 @@ template<> cv::viz::WCoordinateSystem cv::viz::Widget::cast<cv::viz::WCoordinate
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/// polyline widget implementation /// polyline widget implementation
namespace cv { namespace viz { namespace cv::viz::WPolyLine::WPolyLine(InputArray _points, const Color &color)
{ {
struct PolyLineUtils CV_Assert(_points.type() == CV_32FC3 || _points.type() == CV_32FC4 || _points.type() == CV_64FC3 || _points.type() == CV_64FC4);
{
template<typename _Tp>
static void copy(const Mat& source, Vec<_Tp, 3> *output, vtkSmartPointer<vtkPolyLine> polyLine)
{
int s_chs = source.channels();
for (int y = 0, id = 0; y < source.rows; ++y)
{
const _Tp* srow = source.ptr<_Tp>(y);
for (int x = 0; x < source.cols; ++x, srow += s_chs, ++id)
{
*output++ = Vec<_Tp, 3>(srow);
polyLine->GetPointIds()->SetId(id,id);
}
}
}
};
}}}
cv::viz::WPolyLine::WPolyLine(InputArray _pointData, const Color &color) const float *fpoints = _points.getMat().ptr<float>();
{ const double *dpoints = _points.getMat().ptr<double>();
Mat pointData = _pointData.getMat(); size_t total = _points.total();
CV_Assert(pointData.type() == CV_32FC3 || pointData.type() == CV_32FC4 || pointData.type() == CV_64FC3 || pointData.type() == CV_64FC4); int s_chs = _points.channels();
vtkIdType nr_points = pointData.total();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New(); points->SetDataType(_points.depth() == CV_32F ? VTK_FLOAT : VTK_DOUBLE);
vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New(); points->SetNumberOfPoints(total);
if (pointData.depth() == CV_32F) if (_points.depth() == CV_32F)
points->SetDataTypeToFloat(); for(size_t i = 0; i < total; ++i, fpoints += s_chs)
else points->SetPoint(i, fpoints);
points->SetDataTypeToDouble();
points->SetNumberOfPoints(nr_points); if (_points.depth() == CV_64F)
polyLine->GetPointIds()->SetNumberOfIds(nr_points); for(size_t i = 0; i < total; ++i, dpoints += s_chs)
points->SetPoint(i, dpoints);
if (pointData.depth() == CV_32F) vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New();
{ cell_array->Allocate(cell_array->EstimateSize(1, total));
// Get a pointer to the beginning of the data array cell_array->InsertNextCell(total);
Vec3f *data_beg = vtkpoints_data<float>(points); for(size_t i = 0; i < total; ++i)
PolyLineUtils::copy(pointData, data_beg, polyLine); cell_array->InsertCellPoint(i);
}
else if (pointData.depth() == CV_64F)
{
// Get a pointer to the beginning of the data array
Vec3d *data_beg = vtkpoints_data<double>(points);
PolyLineUtils::copy(pointData, data_beg, polyLine);
}
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
cells->InsertNextCell(polyLine); polydata->SetPoints(points);
polydata->SetLines(cell_array);
polyData->SetPoints(points);
polyData->SetLines(cells);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5 mapper->SetInputConnection(polydata->GetProducerPort());
mapper->SetInput(polyData);
#else
mapper->SetInputData(polyData);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -831,7 +798,7 @@ cv::viz::WImage3D::WImage3D(const Vec3f &position, const Vec3f &normal, const Ve
// Apply the transform after texture mapping // Apply the transform after texture mapping
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply(); transform->PreMultiply();
transform->SetMatrix(vtkmatrix(pose)); transform->SetMatrix(vtkmatrix(pose.matrix));
transform->Scale(size.width, size.height, 1.0); transform->Scale(size.width, size.height, 1.0);
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();

@ -130,6 +130,18 @@ TEST(Viz, DISABLED_show_mesh_random_colors)
viz.spin(); viz.spin();
} }
TEST(Viz, DISABLED_show_polyline)
{
Mat polyline(1, 32, CV_64FC3);
for(size_t i = 0; i < polyline.total(); ++i)
polyline.at<Vec3d>(i) = Vec3d(i/16.0, cos(i * CV_PI/6), sin(i * CV_PI/6));
Viz3d viz("show_polyline");
viz.showWidget("polyline", WPolyLine(Mat(polyline), Color::apricot()));
viz.showWidget("coosys", WCoordinateSystem());
viz.spin();
}
TEST(Viz, DISABLED_show_sampled_normals) TEST(Viz, DISABLED_show_sampled_normals)
{ {
Mesh3d mesh = Mesh3d::load(get_dragon_ply_file_path()); Mesh3d mesh = Mesh3d::load(get_dragon_ply_file_path());

Loading…
Cancel
Save