////////////////////////////////////////////////////////////////////////////////////////
| 2943 | |
| 2944 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 2945 | bool |
| 2946 | pcl::visualization::PCLVisualizer::updateColorHandlerIndex (const std::string &id, int index) |
| 2947 | { |
| 2948 | auto am_it = cloud_actor_map_->find (id); |
| 2949 | if (am_it == cloud_actor_map_->end ()) |
| 2950 | { |
| 2951 | pcl::console::print_warn (stderr, "[updateColorHandlerIndex] PointCloud with id <%s> doesn't exist!\n", id.c_str ()); |
| 2952 | return (false); |
| 2953 | } |
| 2954 | |
| 2955 | std::size_t color_handler_size = am_it->second.color_handlers.size (); |
| 2956 | if (!(static_cast<std::size_t>(index) < color_handler_size)) |
| 2957 | { |
| 2958 | pcl::console::print_warn (stderr, "[updateColorHandlerIndex] Invalid index <%d> given! Index must be less than %d.\n", index, static_cast<int>(color_handler_size)); |
| 2959 | return (false); |
| 2960 | } |
| 2961 | // Get the handler |
| 2962 | PointCloudColorHandler<pcl::PCLPointCloud2>::ConstPtr color_handler = am_it->second.color_handlers[index]; |
| 2963 | |
| 2964 | auto scalars = color_handler->getColor (); |
| 2965 | double minmax[2]; |
| 2966 | scalars->GetRange (minmax); |
| 2967 | // Update the data |
| 2968 | auto *data = dynamic_cast<vtkPolyData*>(am_it->second.actor->GetMapper ()->GetInput ()); |
| 2969 | data->GetPointData ()->SetScalars (scalars); |
| 2970 | // Modify the mapper |
| 2971 | auto* mapper = dynamic_cast<vtkDataSetMapper*>(am_it->second.actor->GetMapper ()); |
| 2972 | mapper->SetScalarRange (minmax); |
| 2973 | mapper->SetScalarModeToUsePointData (); |
| 2974 | mapper->SetInputData (data); |
| 2975 | // Modify the actor |
| 2976 | am_it->second.actor->SetMapper (mapper); |
| 2977 | am_it->second.actor->Modified (); |
| 2978 | am_it->second.color_handler_index_ = index; |
| 2979 | |
| 2980 | //style_->setCloudActorMap (cloud_actor_map_); |
| 2981 | |
| 2982 | return (true); |
| 2983 | } |
| 2984 | |
| 2985 | |
| 2986 |