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

@@ -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