//////////////////////////////////////////////////////////////////////////////
| 3541 | |
| 3542 | /////////////////////////////////////////////////////////////////////////////////// |
| 3543 | void |
| 3544 | pcl::visualization::PCLVisualizer::renderViewTesselatedSphere ( |
| 3545 | int xres, |
| 3546 | int yres, |
| 3547 | pcl::PointCloud<pcl::PointXYZ>::CloudVectorType &clouds, |
| 3548 | std::vector<Eigen::Matrix4f, Eigen::aligned_allocator< |
| 3549 | Eigen::Matrix4f> > & poses, |
| 3550 | std::vector<float> & enthropies, int tesselation_level, |
| 3551 | float view_angle, float radius_sphere, bool use_vertices) |
| 3552 | { |
| 3553 | if (rens_->GetNumberOfItems () > 1) |
| 3554 | { |
| 3555 | PCL_WARN ("[renderViewTesselatedSphere] Method works only with one renderer.\n"); |
| 3556 | return; |
| 3557 | } |
| 3558 | |
| 3559 | rens_->InitTraversal (); |
| 3560 | vtkRenderer* renderer_pcl_vis = rens_->GetNextItem (); |
| 3561 | vtkActorCollection * actors = renderer_pcl_vis->GetActors (); |
| 3562 | |
| 3563 | if (actors->GetNumberOfItems () > 1) |
| 3564 | PCL_INFO ("[renderViewTesselatedSphere] Method only consider the first actor on the scene, more than one found.\n"); |
| 3565 | |
| 3566 | //get vtk object from the visualizer |
| 3567 | actors->InitTraversal (); |
| 3568 | vtkActor * actor = actors->GetNextActor (); |
| 3569 | vtkSmartPointer<vtkPolyData> polydata; |
| 3570 | allocVtkPolyData (polydata); |
| 3571 | polydata->CopyStructure (actor->GetMapper ()->GetInput ()); |
| 3572 | |
| 3573 | //center object |
| 3574 | double CoM[3]; |
| 3575 | vtkIdType npts_com = 0; |
| 3576 | vtkCellPtsPtr ptIds_com = nullptr; |
| 3577 | vtkSmartPointer<vtkCellArray> cells_com = polydata->GetPolys (); |
| 3578 | |
| 3579 | double center[3], p1_com[3], p2_com[3], p3_com[3], totalArea_com = 0; |
| 3580 | double comx = 0, comy = 0, comz = 0; |
| 3581 | for (cells_com->InitTraversal (); cells_com->GetNextCell (npts_com, ptIds_com);) |
| 3582 | { |
| 3583 | polydata->GetPoint (ptIds_com[0], p1_com); |
| 3584 | polydata->GetPoint (ptIds_com[1], p2_com); |
| 3585 | polydata->GetPoint (ptIds_com[2], p3_com); |
| 3586 | vtkTriangle::TriangleCenter (p1_com, p2_com, p3_com, center); |
| 3587 | double area_com = vtkTriangle::TriangleArea (p1_com, p2_com, p3_com); |
| 3588 | comx += center[0] * area_com; |
| 3589 | comy += center[1] * area_com; |
| 3590 | comz += center[2] * area_com; |
| 3591 | totalArea_com += area_com; |
| 3592 | } |
| 3593 | |
| 3594 | CoM[0] = comx / totalArea_com; |
| 3595 | CoM[1] = comy / totalArea_com; |
| 3596 | CoM[2] = comz / totalArea_com; |
| 3597 | |
| 3598 | vtkSmartPointer<vtkTransform> trans_center = vtkSmartPointer<vtkTransform>::New (); |
| 3599 | trans_center->Translate (-CoM[0], -CoM[1], -CoM[2]); |
| 3600 | vtkSmartPointer<vtkMatrix4x4> matrixCenter = trans_center->GetMatrix (); |