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

Allow changing LUT properties of a shape actor #1668

Merged
merged 1 commit into from
Aug 30, 2017
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
14 changes: 13 additions & 1 deletion visualization/include/pcl/visualization/pcl_visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,19 @@ namespace pcl
setShapeRenderingProperties (int property, double value,
const std::string &id, int viewport = 0);

/** \brief Set the rendering properties of a shape (3x values - e.g., RGB)
/** \brief Set the rendering properties of a shape (2x values - e.g., LUT minmax values)
* \param[in] property the property type
* \param[in] val1 the first value to be set
* \param[in] val2 the second value to be set
* \param[in] id the shape object id
* \param[in] viewport the view port where the shape's properties should be modified (default: all)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see, this parameter is not used at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean viewport? Yes, it is not used in any of the setShapeRenderingProperties or 'setPointCloudRenderingProperties' functions. I am not sure why it is there in the first place. Should we remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it left there to allow (in the future) individual control over which viewport those properties are applied?

But to be honest that's not the only thing that bothers me with the signatures. The int property should be strong typed to the corresponding enum, like RenderingPropertiesfor instance. Just by reading the function signature description and help, it's impossible to know which properties are accepted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Viewport is in pretty much all the functions but sometimes it's not implemented, which is is bad because it lures the user.

Changing the int property should be done in an other PR in my opinion because it must be done everywhere in PCLVisualizer code (including interactor_style.cpp)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand that it seems to be a convention to have a viewport parameter even if we don't really need it, but I think the documentation should be clear about that it is not used.

Yep, centralized int -> enum conversion would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can work on the int -> enum conversion. I have created an issue for that #1692. I will work on it after this PR is merged.

* \note When using \ref addPolygonMesh you you should use \ref setPointCloudRenderingProperties
*/
bool
setShapeRenderingProperties (int property, double val1, double val2,
const std::string &id, int viewport = 0);

/** \brief Set the rendering properties of a shape (3x values - e.g., RGB)
* \param[in] property the property type
* \param[in] val1 the first value to be set
* \param[in] val2 the second value to be set
Expand Down
90 changes: 85 additions & 5 deletions visualization/src/pcl_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,58 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
return (true);
}

/////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
int property, double val1, double val2, const std::string &id, int)
{
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);

if (am_it == shape_actor_map_->end ())
{
pcl::console::print_error ("[setShapeRenderingProperties] Could not find any shape with id <%s>!\n", id.c_str ());
return (false);
}
// Get the actor pointer
vtkActor* actor = vtkActor::SafeDownCast (am_it->second);
if (!actor)
return (false);

switch (property)
{
case PCL_VISUALIZER_LUT_RANGE:
{
// Check if the mapper has scalars
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ())
break;

// Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default)
if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray"))
break;

// Check that range values are correct
if (val1 >= val2)
{
PCL_WARN ("[setShapeRenderingProperties] Range max must be greater than range min!\n");
return (false);
}

// Update LUT
actor->GetMapper ()->GetLookupTable ()->SetRange (val1, val2);
actor->GetMapper()->UseLookupTableScalarRangeOn ();
style_->updateLookUpTableDisplay (false);
break;
}
default:
{
pcl::console::print_error ("[setShapeRenderingProperties] Unknown property (%d) specified!\n", property);
return (false);
}
}
return (true);
}

/////////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
Expand Down Expand Up @@ -1733,17 +1785,45 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties (
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ())
break;

double range[2];
actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->GetRange (range);
// Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default)
if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray"))
break;

// Get range limits from existing LUT
double *range;
range = actor->GetMapper ()->GetLookupTable ()->GetRange ();

actor->GetMapper ()->ScalarVisibilityOn ();
actor->GetMapper ()->SetScalarRange (range[0], range[1]);
vtkSmartPointer<vtkLookupTable> table = vtkSmartPointer<vtkLookupTable>::New ();
getColormapLUT (static_cast<LookUpTableRepresentationProperties>(static_cast<int>(value)), table);
vtkSmartPointer<vtkLookupTable> table;
if (!pcl::visualization::getColormapLUT (static_cast<LookUpTableRepresentationProperties>(static_cast<int>(value)), table))
break;
table->SetRange (range[0], range[1]);
actor->GetMapper ()->SetLookupTable (table);
style_->updateLookUpTableDisplay (false);
break;
}
case PCL_VISUALIZER_LUT_RANGE:
{
// Check if the mapper has scalars
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ())
break;

// Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default)
if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray"))
break;

switch (int(value))
{
case PCL_VISUALIZER_LUT_RANGE_AUTO:
double range[2];
actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->GetRange (range);
actor->GetMapper ()->GetLookupTable ()->SetRange (range[0], range[1]);
actor->GetMapper ()->UseLookupTableScalarRangeOn ();
style_->updateLookUpTableDisplay (false);
break;
}
break;
}
default:
{
pcl::console::print_error ("[setShapeRenderingProperties] Unknown property (%d) specified!\n", property);
Expand Down