c++ - memcpy vtkPoints using GetVoidPointer method -
i have opencv 3-channel mat each pixel contains 3d point. want copy mat (points) vtk points , polydata visualize it. there example here showing want copy cv::mat vtkpoints directly using memcpy.
i did:
// create colored point clodu in opencv format cv::mat cld_cv = cv::mat::zeros(1, 3, cv_32fc3); int num_points = cld_cv.cols * cld_cv.rows; // fill cld_cv code here // ..... vtksmartpointer<vtkpoints> points = vtksmartpointer<vtkpoints>::new(); points->setnumberofpoints(num_points); ::memcpy(points->getvoidpointer(0), cld_cv.data, sizeof(float) * num_points * 3); vtksmartpointer<vtkpolydata> pointspolydata = vtksmartpointer<vtkpolydata>::new(); pointspolydata->setpoints(points); // normal vtk pipeline shown in example
however can see 1 point seems @ origin. please point out have done wrong.
what version of opencv using? don't see cv::mat::data
in currents docs.
also, there no guarantee vtkpoints
or cv::mat
stored in contiguous block of memory. looking @ vtk 6.2 source, data inside vtkpoints
stored floatarray
default, has contiguous storage, should ok there. opencv provides method check. try
if (cld_cv.iscontinuous()) ::memcpy(points->getvoidpointer(0), cld_cv.ptr<float>(), sizeof(float) * num_points * 3); else { std::cerr << "cv mat not contiguous" << std::endl; // other, perhaps not fast, method of copy }
see opencv docs iscontinous details.
Comments
Post a Comment