CloudViewer: added getColor(id) and setColor(id) to change color of an actor

This commit is contained in:
matlabbe
2018-08-25 11:41:28 -04:00
parent c0a2efe7e2
commit f498cf1b1a
2 changed files with 87 additions and 1 deletions

View File

@@ -309,6 +309,8 @@ public:
const QColor & getBackgroundColor() const; const QColor & getBackgroundColor() const;
Transform getTargetPose() const; Transform getTargetPose() const;
std::string getIdByActor(vtkProp * actor) const; std::string getIdByActor(vtkProp * actor) const;
QColor getColor(const std::string & id);
void setColor(const std::string & id, const QColor & color);
void setBackfaceCulling(bool enabled, bool frontfaceCulling); void setBackfaceCulling(bool enabled, bool frontfaceCulling);
void setPolygonPicking(bool enabled); void setPolygonPicking(bool enabled);

View File

@@ -2105,13 +2105,97 @@ std::string CloudViewer::getIdByActor(vtkProp * actor) const
{ {
if(iter->second.GetPointer() == actor) if(iter->second.GetPointer() == actor)
{ {
return iter->first; std::string id = iter->first;
while(id.back() == '*')
{
id.erase(id.size()-1);
}
return id;
} }
} }
#endif #endif
return std::string(); return std::string();
} }
QColor CloudViewer::getColor(const std::string & id)
{
QColor color;
pcl::visualization::CloudActorMap::iterator iter = _visualizer->getCloudActorMap()->find(id);
if(iter != _visualizer->getCloudActorMap()->end())
{
double r,g,b,a;
iter->second.actor->GetProperty()->GetColor(r,g,b);
a = iter->second.actor->GetProperty()->GetOpacity();
color.setRgbF(r, g, b, a);
}
#if PCL_VERSION_COMPARE(>=, 1, 7, 2)
// getShapeActorMap() not available in version < 1.7.2
else
{
std::string idLayer1 = id+"*";
std::string idLayer2 = id+"**";
pcl::visualization::ShapeActorMap::iterator iter = _visualizer->getShapeActorMap()->find(id);
if(iter == _visualizer->getShapeActorMap()->end())
{
iter = _visualizer->getShapeActorMap()->find(idLayer1);
if(iter == _visualizer->getShapeActorMap()->end())
{
iter = _visualizer->getShapeActorMap()->find(idLayer2);
}
}
if(iter != _visualizer->getShapeActorMap()->end())
{
vtkActor * actor = vtkActor::SafeDownCast(iter->second);
if(actor)
{
double r,g,b,a;
actor->GetProperty()->GetColor(r,g,b);
a = actor->GetProperty()->GetOpacity();
color.setRgbF(r, g, b, a);
}
}
}
#endif
return color;
}
void CloudViewer::setColor(const std::string & id, const QColor & color)
{
pcl::visualization::CloudActorMap::iterator iter = _visualizer->getCloudActorMap()->find(id);
if(iter != _visualizer->getCloudActorMap()->end())
{
iter->second.actor->GetProperty()->SetColor(color.redF(),color.greenF(),color.blueF());
iter->second.actor->GetProperty()->SetOpacity(color.alphaF());
}
#if PCL_VERSION_COMPARE(>=, 1, 7, 2)
// getShapeActorMap() not available in version < 1.7.2
else
{
std::string idLayer1 = id+"*";
std::string idLayer2 = id+"**";
pcl::visualization::ShapeActorMap::iterator iter = _visualizer->getShapeActorMap()->find(id);
if(iter == _visualizer->getShapeActorMap()->end())
{
iter = _visualizer->getShapeActorMap()->find(idLayer1);
if(iter == _visualizer->getShapeActorMap()->end())
{
iter = _visualizer->getShapeActorMap()->find(idLayer2);
}
}
if(iter != _visualizer->getShapeActorMap()->end())
{
vtkActor * actor = vtkActor::SafeDownCast(iter->second);
if(actor)
{
actor->GetProperty()->SetColor(color.redF(),color.greenF(),color.blueF());
actor->GetProperty()->SetOpacity(color.alphaF());
}
}
}
#endif
}
void CloudViewer::setBackfaceCulling(bool enabled, bool frontfaceCulling) void CloudViewer::setBackfaceCulling(bool enabled, bool frontfaceCulling)
{ {
_aBackfaceCulling->setChecked(enabled); _aBackfaceCulling->setChecked(enabled);