rendering properties in Widget and Viz3d

This commit is contained in:
ozantonkal 2013-08-24 11:49:56 +02:00 committed by Ozan Tonkal
parent b032b4dded
commit cf36b8f817
6 changed files with 137 additions and 183 deletions

View File

@ -7,7 +7,6 @@
#include <opencv2/core.hpp>
#include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp>
#include <boost/concept_check.hpp>
namespace cv
{
@ -55,6 +54,9 @@ namespace cv
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
void setRenderingProperty(int property, double value, const String &id);
double getRenderingProperty(int property, const String &id);
private:
struct VizImpl;

View File

@ -16,10 +16,12 @@ namespace cv
Widget();
Widget(const Widget &other);
Widget& operator =(const Widget &other);
~Widget();
static Widget fromPlyFile(const String &file_name);
~Widget();
void setRenderingProperty(int property, double value);
double getRenderingProperty(int property) const;
template<typename _W> _W cast();
private:
@ -43,7 +45,6 @@ namespace cv
Affine3f getPose() const;
void setColor(const Color &color);
private:
struct MatrixConverter;

View File

@ -54,8 +54,6 @@ void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* c
void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie)
{ impl_->registerMouseCallback(callback, cookie); }
void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); }
void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); }
cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); }
@ -75,3 +73,6 @@ void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin,
cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); }
void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); }
cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); }
void cv::viz::Viz3d::setRenderingProperty(int property, double value, const String &id) { getWidget(id).setRenderingProperty(property, value); }
double cv::viz::Viz3d::getRenderingProperty(int property, const String &id) { return getWidget(id).getRenderingProperty(property); }

View File

@ -249,179 +249,6 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor (const Color& color)
renderer_->SetBackground (c.val);
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool cv::viz::Viz3d::VizImpl::getPointCloudRenderingProperties (int property, double &value, const std::string &id)
{
CloudActorMap::iterator am_it = cloud_actor_map_->find (id);
if (am_it == cloud_actor_map_->end ())
return false;
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
switch (property)
{
case VIZ_POINT_SIZE:
{
value = actor->GetProperty ()->GetPointSize ();
actor->Modified ();
break;
}
case VIZ_OPACITY:
{
value = actor->GetProperty ()->GetOpacity ();
actor->Modified ();
break;
}
case VIZ_LINE_WIDTH:
{
value = actor->GetProperty ()->GetLineWidth ();
actor->Modified ();
break;
}
default:
CV_Assert("getPointCloudRenderingProperties: Unknown property");
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool cv::viz::Viz3d::VizImpl::setPointCloudRenderingProperties (int property, double value, const std::string &id)
{
CloudActorMap::iterator am_it = cloud_actor_map_->find (id);
if (am_it == cloud_actor_map_->end ())
return std::cout << "[setPointCloudRenderingProperties] Could not find any PointCloud datasets with id <" << id << ">!" << std::endl, false;
vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor);
switch (property)
{
case VIZ_POINT_SIZE:
{
actor->GetProperty ()->SetPointSize (float (value));
actor->Modified ();
break;
}
case VIZ_OPACITY:
{
actor->GetProperty ()->SetOpacity (value);
actor->Modified ();
break;
}
// Turn on/off flag to control whether data is rendered using immediate
// mode or note. Immediate mode rendering tends to be slower but it can
// handle larger datasets. The default value is immediate mode off. If you
// are having problems rendering a large dataset you might want to consider
// using immediate more rendering.
case VIZ_IMMEDIATE_RENDERING:
{
actor->GetMapper ()->SetImmediateModeRendering (int (value));
actor->Modified ();
break;
}
case VIZ_LINE_WIDTH:
{
actor->GetProperty ()->SetLineWidth (float (value));
actor->Modified ();
break;
}
default:
CV_Assert("setPointCloudRenderingProperties: Unknown property");
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool cv::viz::Viz3d::VizImpl::setShapeRenderingProperties (int property, double value, const std::string &id)
{
ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
if (am_it == shape_actor_map_->end ())
return std::cout << "[setShapeRenderingProperties] Could not find any shape with id <" << id << ">!\n" << std::endl, false;
vtkActor* actor = vtkActor::SafeDownCast (am_it->second);
switch (property)
{
case VIZ_POINT_SIZE:
{
actor->GetProperty ()->SetPointSize (float (value));
actor->Modified ();
break;
}
case VIZ_OPACITY:
{
actor->GetProperty ()->SetOpacity (value);
actor->Modified ();
break;
}
case VIZ_LINE_WIDTH:
{
actor->GetProperty ()->SetLineWidth (float (value));
actor->Modified ();
break;
}
case VIZ_FONT_SIZE:
{
vtkTextActor* text_actor = vtkTextActor::SafeDownCast (am_it->second);
vtkSmartPointer<vtkTextProperty> tprop = text_actor->GetTextProperty ();
tprop->SetFontSize (int (value));
text_actor->Modified ();
break;
}
case VIZ_REPRESENTATION:
{
switch (int (value))
{
case REPRESENTATION_POINTS: actor->GetProperty ()->SetRepresentationToPoints (); break;
case REPRESENTATION_WIREFRAME: actor->GetProperty ()->SetRepresentationToWireframe (); break;
case REPRESENTATION_SURFACE: actor->GetProperty ()->SetRepresentationToSurface (); break;
}
actor->Modified ();
break;
}
case VIZ_SHADING:
{
switch (int (value))
{
case SHADING_FLAT: actor->GetProperty ()->SetInterpolationToFlat (); break;
case SHADING_GOURAUD:
{
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ())
{
std::cout << "[cv::viz::PCLVisualizer::setShapeRenderingProperties] Normals do not exist in the dataset, but Gouraud shading was requested. Estimating normals...\n" << std::endl;
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New ();
normals->SetInput (actor->GetMapper ()->GetInput ());
normals->Update ();
vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ());
}
actor->GetProperty ()->SetInterpolationToGouraud ();
break;
}
case SHADING_PHONG:
{
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ())
{
std::cout << "[cv::viz::PCLVisualizer::setShapeRenderingProperties] Normals do not exist in the dataset, but Phong shading was requested. Estimating normals...\n" << std::endl;
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New ();
normals->SetInput (actor->GetMapper ()->GetInput ());
normals->Update ();
vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ());
}
actor->GetProperty ()->SetInterpolationToPhong ();
break;
}
}
actor->Modified ();
break;
}
default:
CV_Assert("setShapeRenderingProperties: Unknown property");
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::initCameraParameters ()
{

View File

@ -19,10 +19,8 @@ public:
void removeAllWidgets();
// to refactor: Widget3D:: & Viz3d::
bool setPointCloudRenderingProperties (int property, double value, const String& id = "cloud");
bool getPointCloudRenderingProperties (int property, double &value, const String& id = "cloud");
bool setShapeRenderingProperties (int property, double value, const String& id);
void setRenderingProperty(int property, double value, const String &id);
double getRenderingProperty(int property, const String &id);
/** \brief Returns true when the user tried to close the window */
bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; }

View File

@ -94,6 +94,131 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
return widget;
}
void cv::viz::Widget::setRenderingProperty(int property, double value)
{
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor);
switch (property)
{
case VIZ_POINT_SIZE:
{
actor->GetProperty ()->SetPointSize (float (value));
actor->Modified ();
break;
}
case VIZ_OPACITY:
{
actor->GetProperty ()->SetOpacity (value);
actor->Modified ();
break;
}
// Turn on/off flag to control whether data is rendered using immediate
// mode or note. Immediate mode rendering tends to be slower but it can
// handle larger datasets. The default value is immediate mode off. If you
// are having problems rendering a large dataset you might want to consider
// using immediate more rendering.
case VIZ_IMMEDIATE_RENDERING:
{
actor->GetMapper ()->SetImmediateModeRendering (int (value));
actor->Modified ();
break;
}
case VIZ_LINE_WIDTH:
{
actor->GetProperty ()->SetLineWidth (float (value));
actor->Modified ();
break;
}
default:
CV_Assert("setPointCloudRenderingProperties: Unknown property");
}
}
double cv::viz::Widget::getRenderingProperty(int property) const
{
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor);
double value = 0.0;
switch (property)
{
case VIZ_POINT_SIZE:
{
value = actor->GetProperty ()->GetPointSize ();
actor->Modified ();
break;
}
case VIZ_OPACITY:
{
value = actor->GetProperty ()->GetOpacity ();
actor->Modified ();
break;
}
case VIZ_LINE_WIDTH:
{
value = actor->GetProperty ()->GetLineWidth ();
actor->Modified ();
break;
}
case VIZ_FONT_SIZE:
{
vtkTextActor* text_actor = vtkTextActor::SafeDownCast (actor);
vtkSmartPointer<vtkTextProperty> tprop = text_actor->GetTextProperty ();
tprop->SetFontSize (int (value));
text_actor->Modified ();
break;
}
case VIZ_REPRESENTATION:
{
switch (int (value))
{
case REPRESENTATION_POINTS: actor->GetProperty ()->SetRepresentationToPoints (); break;
case REPRESENTATION_WIREFRAME: actor->GetProperty ()->SetRepresentationToWireframe (); break;
case REPRESENTATION_SURFACE: actor->GetProperty ()->SetRepresentationToSurface (); break;
}
actor->Modified ();
break;
}
case VIZ_SHADING:
{
switch (int (value))
{
case SHADING_FLAT: actor->GetProperty ()->SetInterpolationToFlat (); break;
case SHADING_GOURAUD:
{
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ())
{
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New ();
normals->SetInput (actor->GetMapper ()->GetInput ());
normals->Update ();
vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ());
}
actor->GetProperty ()->SetInterpolationToGouraud ();
break;
}
case SHADING_PHONG:
{
if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ())
{
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New ();
normals->SetInput (actor->GetMapper ()->GetInput ());
normals->Update ();
vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ());
}
actor->GetProperty ()->SetInterpolationToPhong ();
break;
}
}
actor->Modified ();
break;
}
default:
CV_Assert("getPointCloudRenderingProperties: Unknown property");
}
return value;
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget accessor implementaion