Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new overload of PointCloudColorHandler::getColor() #3187

Merged
merged 2 commits into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/modeler/src/cloud_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ pcl::modeler::CloudMesh::getColorScalarsFromField(vtkSmartPointer<vtkDataArray>
if (field == "rgb" || field == "rgba")
{
pcl::visualization::PointCloudColorHandlerRGBField<PointT> color_handler(cloud_);
color_handler.getColor(scalars);
scalars = color_handler.getColor();
return;
}

if (field == "random")
{
pcl::visualization::PointCloudColorHandlerRandom<PointT> color_handler(cloud_);
color_handler.getColor(scalars);
scalars = color_handler.getColor();
return;
}

pcl::visualization::PointCloudColorHandlerGenericField<PointT> color_handler(cloud_, field);
color_handler.getColor(scalars);
scalars = color_handler.getColor();

return;
}
Expand Down
12 changes: 4 additions & 8 deletions visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,7 @@ pcl::visualization::PCLVisualizer::fromHandlersToScreen (
// Get the colors from the handler
bool has_colors = false;
double minmax[2];
vtkSmartPointer<vtkDataArray> scalars;
if (color_handler.getColor (scalars))
if (auto scalars = color_handler.getColor ())
{
polydata->GetPointData ()->SetScalars (scalars);
scalars->GetRange (minmax);
Expand Down Expand Up @@ -1370,8 +1369,7 @@ pcl::visualization::PCLVisualizer::fromHandlersToScreen (
// Get the colors from the handler
bool has_colors = false;
double minmax[2];
vtkSmartPointer<vtkDataArray> scalars;
if (color_handler->getColor (scalars))
if (auto scalars = color_handler->getColor ())
{
polydata->GetPointData ()->SetScalars (scalars);
scalars->GetRange (minmax);
Expand Down Expand Up @@ -1434,8 +1432,7 @@ pcl::visualization::PCLVisualizer::fromHandlersToScreen (
// Get the colors from the handler
bool has_colors = false;
double minmax[2];
vtkSmartPointer<vtkDataArray> scalars;
if (color_handler.getColor (scalars))
if (auto scalars = color_handler.getColor ())
{
polydata->GetPointData ()->SetScalars (scalars);
scalars->GetRange (minmax);
Expand Down Expand Up @@ -1590,8 +1587,7 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl
// Get the colors from the handler
bool has_colors = false;
double minmax[2];
vtkSmartPointer<vtkDataArray> scalars;
if (color_handler.getColor (scalars))
if (auto scalars = color_handler.getColor ())
{
// Update the data
polydata->GetPointData ()->SetScalars (scalars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@
#include <pcl/common/colors.h>

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerCustom<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
template <typename PointT> vtkSmartPointer<vtkDataArray>
pcl::visualization::PointCloudColorHandlerCustom<PointT>::getColor () const
{
if (!capable_ || !cloud_)
return (false);
return nullptr;

if (!scalars)
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
auto scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (3);

vtkIdType nr_points = cloud_->points.size ();
reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
scalars->SetNumberOfTuples (nr_points);

// Get a random color
unsigned char* colors = new unsigned char[nr_points * 3];
Expand All @@ -68,23 +67,22 @@ pcl::visualization::PointCloudColorHandlerCustom<PointT>::getColor (vtkSmartPoin
colors[cp * 3 + 1] = static_cast<unsigned char> (g_);
colors[cp * 3 + 2] = static_cast<unsigned char> (b_);
}
reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE);
return (true);
scalars->SetArray (colors, 3 * nr_points, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE);
return scalars;
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerRandom<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
template <typename PointT> vtkSmartPointer<vtkDataArray>
pcl::visualization::PointCloudColorHandlerRandom<PointT>::getColor () const
{
if (!capable_ || !cloud_)
return (false);
return nullptr;

if (!scalars)
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
auto scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (3);

vtkIdType nr_points = cloud_->points.size ();
reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
scalars->SetNumberOfTuples (nr_points);

// Get a random color
unsigned char* colors = new unsigned char[nr_points * 3];
Expand All @@ -102,8 +100,8 @@ pcl::visualization::PointCloudColorHandlerRandom<PointT>::getColor (vtkSmartPoin
colors[cp * 3 + 1] = static_cast<unsigned char> (g_);
colors[cp * 3 + 2] = static_cast<unsigned char> (b_);
}
reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE);
return (true);
scalars->SetArray (colors, 3 * nr_points, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE);
return scalars;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -130,12 +128,12 @@ pcl::visualization::PointCloudColorHandlerRGBField<PointT>::setInputCloud (
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerRGBField<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
template <typename PointT> vtkSmartPointer<vtkDataArray>
pcl::visualization::PointCloudColorHandlerRGBField<PointT>::getColor () const
{
if (!capable_ || !cloud_)
return (false);
return nullptr;

// Get the RGB field index
std::vector<pcl::PCLPointField> fields;
int rgba_index = -1;
Expand All @@ -145,13 +143,12 @@ pcl::visualization::PointCloudColorHandlerRGBField<PointT>::getColor (vtkSmartPo

int rgba_offset = fields[rgba_index].offset;

if (!scalars)
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
auto scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (3);

vtkIdType nr_points = cloud_->points.size ();
reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);
scalars->SetNumberOfTuples (nr_points);
unsigned char* colors = scalars->GetPointer (0);

int j = 0;
// If XYZ present, check if the points are invalid
Expand Down Expand Up @@ -191,7 +188,7 @@ pcl::visualization::PointCloudColorHandlerRGBField<PointT>::getColor (vtkSmartPo
colors[idx + 2] = rgb.b;
}
}
return (true);
return scalars;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -226,19 +223,18 @@ pcl::visualization::PointCloudColorHandlerHSVField<PointT>::PointCloudColorHandl
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerHSVField<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
template <typename PointT> vtkSmartPointer<vtkDataArray>
pcl::visualization::PointCloudColorHandlerHSVField<PointT>::getColor () const
{
if (!capable_ || !cloud_)
return (false);
return nullptr;

if (!scalars)
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
auto scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (3);

vtkIdType nr_points = cloud_->points.size ();
reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);
scalars->SetNumberOfTuples (nr_points);
unsigned char* colors = scalars->GetPointer (0);

int idx = 0;
// If XYZ present, check if the points are invalid
Expand Down Expand Up @@ -360,7 +356,7 @@ pcl::visualization::PointCloudColorHandlerHSVField<PointT>::getColor (vtkSmartPo
idx +=3;
}
}
return (true);
return scalars;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -377,18 +373,17 @@ pcl::visualization::PointCloudColorHandlerGenericField<PointT>::setInputCloud (
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerGenericField<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
template <typename PointT> vtkSmartPointer<vtkDataArray>
pcl::visualization::PointCloudColorHandlerGenericField<PointT>::getColor () const
{
if (!capable_ || !cloud_)
return (false);
return nullptr;

if (!scalars)
scalars = vtkSmartPointer<vtkFloatArray>::New ();
auto scalars = vtkSmartPointer<vtkFloatArray>::New ();
scalars->SetNumberOfComponents (1);

vtkIdType nr_points = cloud_->points.size ();
reinterpret_cast<vtkFloatArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
scalars->SetNumberOfTuples (nr_points);

using FieldList = typename pcl::traits::fieldList<PointT>::type;

Expand Down Expand Up @@ -433,8 +428,8 @@ pcl::visualization::PointCloudColorHandlerGenericField<PointT>::getColor (vtkSma
j++;
}
}
reinterpret_cast<vtkFloatArray*>(&(*scalars))->SetArray (colors, j, 0, vtkFloatArray::VTK_DATA_ARRAY_DELETE);
return (true);
scalars->SetArray (colors, j, 0, vtkFloatArray::VTK_DATA_ARRAY_DELETE);
return scalars;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -452,19 +447,18 @@ pcl::visualization::PointCloudColorHandlerRGBAField<PointT>::setInputCloud (
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerRGBAField<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
template <typename PointT> vtkSmartPointer<vtkDataArray>
pcl::visualization::PointCloudColorHandlerRGBAField<PointT>::getColor () const
{
if (!capable_ || !cloud_)
return (false);
return nullptr;

if (!scalars)
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
auto scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (4);

vtkIdType nr_points = cloud_->points.size ();
reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);
scalars->SetNumberOfTuples (nr_points);
unsigned char* colors = scalars->GetPointer (0);

int j = 0;
// If XYZ present, check if the points are invalid
Expand Down Expand Up @@ -503,7 +497,7 @@ pcl::visualization::PointCloudColorHandlerRGBAField<PointT>::getColor (vtkSmartP
colors[idx + 3] = cloud_->points[cp].a;
}
}
return (true);
return scalars;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -520,19 +514,18 @@ pcl::visualization::PointCloudColorHandlerLabelField<PointT>::setInputCloud (con
}

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerLabelField<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
template <typename PointT> vtkSmartPointer<vtkDataArray>
pcl::visualization::PointCloudColorHandlerLabelField<PointT>::getColor () const
{
if (!capable_ || !cloud_)
return (false);
return nullptr;

if (!scalars)
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
auto scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
scalars->SetNumberOfComponents (3);

vtkIdType nr_points = cloud_->points.size ();
reinterpret_cast<vtkUnsignedCharArray*> (&(*scalars))->SetNumberOfTuples (nr_points);
unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*> (&(*scalars))->GetPointer (0);
scalars->SetNumberOfTuples (nr_points);
unsigned char* colors = scalars->GetPointer (0);


std::map<uint32_t, pcl::RGB> colormap;
Expand Down Expand Up @@ -562,7 +555,7 @@ pcl::visualization::PointCloudColorHandlerLabelField<PointT>::getColor (vtkSmart
}
}

return (true);
return scalars;
}

#endif // PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_
Expand Down
Loading