Commit 94ca5d65 authored by Ozan Tonkal's avatar Ozan Tonkal

remove VIZ prefix from rendering properties, fix setRenderingProperties and…

remove VIZ prefix from rendering properties, fix setRenderingProperties and getRenderingProperties methods
parent fdbf20c1
...@@ -10,14 +10,14 @@ namespace cv ...@@ -10,14 +10,14 @@ namespace cv
/// Widget rendering properties /// Widget rendering properties
enum RenderingProperties enum RenderingProperties
{ {
VIZ_POINT_SIZE, POINT_SIZE,
VIZ_OPACITY, OPACITY,
VIZ_LINE_WIDTH, LINE_WIDTH,
VIZ_FONT_SIZE, FONT_SIZE,
VIZ_COLOR, COLOR,
VIZ_REPRESENTATION, REPRESENTATION,
VIZ_IMMEDIATE_RENDERING, IMMEDIATE_RENDERING,
VIZ_SHADING SHADING
}; };
enum RenderingRepresentationProperties enum RenderingRepresentationProperties
......
...@@ -36,38 +36,38 @@ cv::viz::Widget::~Widget() ...@@ -36,38 +36,38 @@ cv::viz::Widget::~Widget()
cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
{ {
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New (); vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName (file_name.c_str ()); reader->SetFileName(file_name.c_str());
vtkSmartPointer<vtkDataSet> data = reader->GetOutput(); vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
CV_Assert("File does not exist or file format is not supported." && data); CV_Assert("File does not exist or file format is not supported." && data);
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New(); vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New (); vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput (data); mapper->SetInput(data);
vtkSmartPointer<vtkDataArray> scalars = data->GetPointData ()->GetScalars (); vtkSmartPointer<vtkDataArray> scalars = data->GetPointData()->GetScalars();
if (scalars) if (scalars)
{ {
cv::Vec3d minmax(scalars->GetRange()); cv::Vec3d minmax(scalars->GetRange());
mapper->SetScalarRange(minmax.val); mapper->SetScalarRange(minmax.val);
mapper->SetScalarModeToUsePointData (); mapper->SetScalarModeToUsePointData();
// interpolation OFF, if data is a vtkPolyData that contains only vertices, ON for anything else. // interpolation OFF, if data is a vtkPolyData that contains only vertices, ON for anything else.
vtkPolyData* polyData = vtkPolyData::SafeDownCast (data); vtkPolyData* polyData = vtkPolyData::SafeDownCast(data);
bool interpolation = (polyData && polyData->GetNumberOfCells () != polyData->GetNumberOfVerts ()); bool interpolation = (polyData && polyData->GetNumberOfCells() != polyData->GetNumberOfVerts());
mapper->SetInterpolateScalarsBeforeMapping (interpolation); mapper->SetInterpolateScalarsBeforeMapping(interpolation);
mapper->ScalarVisibilityOn (); mapper->ScalarVisibilityOn();
} }
mapper->ImmediateModeRenderingOff (); mapper->ImmediateModeRenderingOff();
actor->SetNumberOfCloudPoints (int (std::max<vtkIdType> (1, data->GetNumberOfPoints () / 10))); actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, data->GetNumberOfPoints() / 10)));
actor->GetProperty ()->SetInterpolationToFlat (); actor->GetProperty()->SetInterpolationToFlat();
actor->GetProperty ()->BackfaceCullingOn (); actor->GetProperty()->BackfaceCullingOn();
actor->SetMapper (mapper); actor->SetMapper(mapper);
Widget widget; Widget widget;
widget.impl_->prop = actor; widget.impl_->prop = actor;
...@@ -81,35 +81,85 @@ void cv::viz::Widget::setRenderingProperty(int property, double value) ...@@ -81,35 +81,85 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
switch (property) switch (property)
{ {
case VIZ_POINT_SIZE: case POINT_SIZE:
{ {
actor->GetProperty ()->SetPointSize (float (value)); actor->GetProperty()->SetPointSize(float(value));
actor->Modified (); actor->Modified();
break; break;
} }
case VIZ_OPACITY: case OPACITY:
{ {
actor->GetProperty ()->SetOpacity (value); actor->GetProperty()->SetOpacity(value);
actor->Modified (); actor->Modified();
break; break;
} }
// Turn on/off flag to control whether data is rendered using immediate case IMMEDIATE_RENDERING:
// 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->GetMapper()->SetImmediateModeRendering(int(value));
actor->Modified (); actor->Modified();
break; break;
} }
case VIZ_LINE_WIDTH: case LINE_WIDTH:
{ {
actor->GetProperty ()->SetLineWidth (float (value)); actor->GetProperty()->SetLineWidth(float(value));
actor->Modified (); actor->Modified();
break; break;
} }
case FONT_SIZE:
{
vtkTextActor* text_actor = vtkTextActor::SafeDownCast(actor);
CV_Assert("Widget does not have text content." && text_actor);
vtkSmartPointer<vtkTextProperty> tprop = text_actor->GetTextProperty();
tprop->SetFontSize(int(value));
text_actor->Modified();
break;
}
case 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 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: default:
CV_Assert("setPointCloudRenderingProperties: Unknown property"); CV_Assert("setPointCloudRenderingProperties: Unknown property");
} }
...@@ -123,74 +173,52 @@ double cv::viz::Widget::getRenderingProperty(int property) const ...@@ -123,74 +173,52 @@ double cv::viz::Widget::getRenderingProperty(int property) const
double value = 0.0; double value = 0.0;
switch (property) switch (property)
{ {
case VIZ_POINT_SIZE: case POINT_SIZE:
{ {
value = actor->GetProperty ()->GetPointSize (); value = actor->GetProperty()->GetPointSize();
actor->Modified ();
break; break;
} }
case VIZ_OPACITY: case OPACITY:
{ {
value = actor->GetProperty ()->GetOpacity (); value = actor->GetProperty()->GetOpacity();
actor->Modified ();
break; break;
} }
case VIZ_LINE_WIDTH: case IMMEDIATE_RENDERING:
{ {
value = actor->GetProperty ()->GetLineWidth (); value = actor->GetMapper()->GetImmediateModeRendering();
actor->Modified ();
break; break;
} }
case VIZ_FONT_SIZE: case LINE_WIDTH:
{ {
vtkTextActor* text_actor = vtkTextActor::SafeDownCast (actor); value = actor->GetProperty()->GetLineWidth();
vtkSmartPointer<vtkTextProperty> tprop = text_actor->GetTextProperty ();
tprop->SetFontSize (int (value));
text_actor->Modified ();
break; break;
} }
case VIZ_REPRESENTATION: case FONT_SIZE:
{ {
switch (int (value)) vtkTextActor* text_actor = vtkTextActor::SafeDownCast(actor);
CV_Assert("Widget does not have text content." && text_actor);
vtkSmartPointer<vtkTextProperty> tprop = text_actor->GetTextProperty();
value = tprop->GetFontSize();
break;
}
case REPRESENTATION:
{
switch (actor->GetProperty()->GetRepresentation())
{ {
case REPRESENTATION_POINTS: actor->GetProperty ()->SetRepresentationToPoints (); break; case VTK_POINTS: value = REPRESENTATION_POINTS; break;
case REPRESENTATION_WIREFRAME: actor->GetProperty ()->SetRepresentationToWireframe (); break; case VTK_WIREFRAME: value = REPRESENTATION_WIREFRAME; break;
case REPRESENTATION_SURFACE: actor->GetProperty ()->SetRepresentationToSurface (); break; case VTK_SURFACE: value = REPRESENTATION_SURFACE; break;
} }
actor->Modified ();
break; break;
} }
case VIZ_SHADING: case SHADING:
{ {
switch (int (value)) switch (actor->GetProperty()->GetInterpolation())
{ {
case SHADING_FLAT: actor->GetProperty ()->SetInterpolationToFlat (); break; case VTK_FLAT: value = SHADING_FLAT; break;
case SHADING_GOURAUD: case VTK_GOURAUD: value = SHADING_GOURAUD; break;
{ case VTK_PHONG: value = SHADING_PHONG; break;
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; break;
} }
default: default:
...@@ -222,13 +250,13 @@ struct cv::viz::Widget3D::MatrixConverter ...@@ -222,13 +250,13 @@ struct cv::viz::Widget3D::MatrixConverter
Matx44f m; Matx44f m;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
for (int k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
m(i, k) = vtk_matrix->GetElement (i, k); m(i, k) = vtk_matrix->GetElement(i, k);
return m; return m;
} }
static vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const Matx44f& m) static vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix(const Matx44f& m)
{ {
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New (); vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
for (int k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
vtk_matrix->SetElement(i, k, m(i, k)); vtk_matrix->SetElement(i, k, m(i, k));
...@@ -242,8 +270,8 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose) ...@@ -242,8 +270,8 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose)
CV_Assert("Widget is not 3D." && actor); CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix); vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
actor->SetUserMatrix (matrix); actor->SetUserMatrix(matrix);
actor->Modified (); actor->Modified();
} }
void cv::viz::Widget3D::updatePose(const Affine3f &pose) void cv::viz::Widget3D::updatePose(const Affine3f &pose)
...@@ -262,8 +290,8 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose) ...@@ -262,8 +290,8 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose)
Affine3f updated_pose = pose * Affine3f(matrix_cv); Affine3f updated_pose = pose * Affine3f(matrix_cv);
matrix = MatrixConverter::convertToVtkMatrix(updated_pose.matrix); matrix = MatrixConverter::convertToVtkMatrix(updated_pose.matrix);
actor->SetUserMatrix (matrix); actor->SetUserMatrix(matrix);
actor->Modified (); actor->Modified();
} }
cv::Affine3f cv::viz::Widget3D::getPose() const cv::Affine3f cv::viz::Widget3D::getPose() const
...@@ -283,10 +311,10 @@ void cv::viz::Widget3D::setColor(const Color &color) ...@@ -283,10 +311,10 @@ void cv::viz::Widget3D::setColor(const Color &color)
CV_Assert("Widget type is not supported." && actor); CV_Assert("Widget type is not supported." && actor);
Color c = vtkcolor(color); Color c = vtkcolor(color);
actor->GetMapper ()->ScalarVisibilityOff (); actor->GetMapper()->ScalarVisibilityOff();
actor->GetProperty ()->SetColor (c.val); actor->GetProperty()->SetColor(c.val);
actor->GetProperty ()->SetEdgeColor (c.val); actor->GetProperty()->SetEdgeColor(c.val);
actor->Modified (); actor->Modified();
} }
template<> cv::viz::Widget3D cv::viz::Widget::cast<cv::viz::Widget3D>() template<> cv::viz::Widget3D cv::viz::Widget::cast<cv::viz::Widget3D>()
...@@ -307,8 +335,8 @@ void cv::viz::Widget2D::setColor(const Color &color) ...@@ -307,8 +335,8 @@ void cv::viz::Widget2D::setColor(const Color &color)
vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget type is not supported." && actor); CV_Assert("Widget type is not supported." && actor);
Color c = vtkcolor(color); Color c = vtkcolor(color);
actor->GetProperty ()->SetColor (c.val); actor->GetProperty()->SetColor(c.val);
actor->Modified (); actor->Modified();
} }
template<> cv::viz::Widget2D cv::viz::Widget::cast<cv::viz::Widget2D>() template<> cv::viz::Widget2D cv::viz::Widget::cast<cv::viz::Widget2D>()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment