[vtkusers] VTK render coordinates
Toepfer, Randall
randall at scandy.co
Mon Jun 19 18:49:17 EDT 2017
I have a mesh in vtk. I created a function to convert the mesh to point
cloud library pcl::PointCloud.
int vtk2pcl(vtkPolyData* poly_data, pcl::PointCloud<pcl::PointXYZ>::Ptr&
pcl_cloud)
{
pcl_cloud->clear();
vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints();
vtkIdType nr_points = mesh_points->GetNumberOfPoints();
if (nr_points == 0)
return 0;
pcl_cloud->points.resize(nr_points);
double point_xyz[3];
for (vtkIdType i = 0; i < mesh_points->GetNumberOfPoints(); ++i)
{
mesh_points->GetPoint(i, &point_xyz[0]);
pcl_cloud->points[i].x = static_cast<float>(point_xyz[0]);
pcl_cloud->points[i].y = static_cast<float>(point_xyz[1]);
pcl_cloud->points[i].z = static_cast<float>(point_xyz[2]);
}
pcl_cloud->width = static_cast<uint32_t>(pcl_cloud->points.size());
pcl_cloud->height = 1;
pcl_cloud->is_dense = true;
return (static_cast<int>(nr_points));
}
I then use this point cloud in PCL's segmentation methods to find planes in
my mesh.
If I compare the bounds and centroid of my mesh to my point cloud - both
are equal.
I display the planes in VTK:
auto A = plane[0];
auto B = plane[1];
auto C = plane[2];
auto D = plane[3];
double z = (-1 * D) / (-1 * ((A * min_x) + (B * 1)) * C);
plane_source->SetCenter(min_x, 1, z);
z = (-1 * D) / (-1 * ((A * min_x) + (B * max_y)) * C);
plane_source->SetPoint1(min_x, max_y, z);
z = (-1 * D) / (-1 * ((A * max_x) + (B * max_y)) * C);
plane_source->SetPoint2(max_x, max_y, z);
plane_source->Update();
vtkPolyData* vtk_plane = plane_source->GetOutput();
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(vtk_plane);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
I display the mesh in VTK:
// vtkPolyData* mesh ....
auto mesh_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mesh_mapper->SetInputData(mesh);
auto mesh_actor = vtkSmartPointer<vtkActor>::New();
mesh_actor->SetMapper(mesh_mapper.GetPointer());
renderer->AddActor(mesh_actor);
VTK shows my planes but the mesh and planes aren't aligned correctly.
Shouldn't they be aligned since my bounds and centroid are equal? How do
they get unaligned?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170619/c37ef320/attachment.html>
More information about the vtkusers
mailing list