refactoring
This commit is contained in:
@@ -41,9 +41,6 @@
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
// OpenCV Viz module is complete rewrite of
|
||||
// PCL visualization module (www.pointclouds.org)
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
@@ -55,7 +52,6 @@ class cv::viz::Widget::Impl
|
||||
{
|
||||
public:
|
||||
vtkSmartPointer<vtkProp> prop;
|
||||
|
||||
Impl() : prop(0) {}
|
||||
};
|
||||
|
||||
@@ -63,13 +59,17 @@ cv::viz::Widget::Widget() : impl_( new Impl() ) { }
|
||||
|
||||
cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() )
|
||||
{
|
||||
if (other.impl_ && other.impl_->prop) impl_->prop = other.impl_->prop;
|
||||
if (other.impl_ && other.impl_->prop)
|
||||
impl_->prop = other.impl_->prop;
|
||||
}
|
||||
|
||||
cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other)
|
||||
{
|
||||
if (!impl_) impl_ = new Impl();
|
||||
if (other.impl_) impl_->prop = other.impl_->prop;
|
||||
if (!impl_)
|
||||
impl_ = new Impl();
|
||||
|
||||
if (other.impl_)
|
||||
impl_->prop = other.impl_->prop;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -84,45 +84,22 @@ cv::viz::Widget::~Widget()
|
||||
|
||||
cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
|
||||
{
|
||||
CV_Assert(vtkPLYReader::CanReadFile(file_name.c_str()));
|
||||
|
||||
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
|
||||
reader->SetFileName(file_name.c_str());
|
||||
|
||||
vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
|
||||
CV_Assert("File does not exist or file format is not supported." && data);
|
||||
|
||||
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
|
||||
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
mapper->SetInput(data);
|
||||
#else
|
||||
mapper->SetInputData(data);
|
||||
#endif
|
||||
|
||||
vtkSmartPointer<vtkDataArray> scalars = data->GetPointData()->GetScalars();
|
||||
if (scalars)
|
||||
{
|
||||
cv::Vec2d minmax(scalars->GetRange());
|
||||
mapper->SetScalarRange(minmax.val);
|
||||
mapper->SetScalarModeToUsePointData();
|
||||
|
||||
// interpolation OFF, if data is a vtkPolyData that contains only vertices, ON for anything else.
|
||||
vtkPolyData* polyData = vtkPolyData::SafeDownCast(data);
|
||||
bool interpolation = (polyData && polyData->GetNumberOfCells() != polyData->GetNumberOfVerts());
|
||||
|
||||
mapper->SetInterpolateScalarsBeforeMapping(interpolation);
|
||||
mapper->ScalarVisibilityOn();
|
||||
}
|
||||
mapper->SetInputConnection( reader->GetOutputPort() );
|
||||
mapper->ImmediateModeRenderingOff();
|
||||
|
||||
actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, data->GetNumberOfPoints() / 10)));
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||
actor->GetProperty()->SetInterpolationToFlat();
|
||||
actor->GetProperty()->BackfaceCullingOn();
|
||||
|
||||
actor->SetMapper(mapper);
|
||||
|
||||
Widget widget;
|
||||
widget.impl_->prop = actor;
|
||||
WidgetAccessor::setProp(widget, actor);
|
||||
return widget;
|
||||
}
|
||||
|
||||
@@ -133,37 +110,15 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
|
||||
|
||||
switch (property)
|
||||
{
|
||||
case POINT_SIZE:
|
||||
{
|
||||
actor->GetProperty()->SetPointSize(float(value));
|
||||
actor->Modified();
|
||||
break;
|
||||
}
|
||||
case OPACITY:
|
||||
{
|
||||
actor->GetProperty()->SetOpacity(value);
|
||||
actor->Modified();
|
||||
break;
|
||||
}
|
||||
case IMMEDIATE_RENDERING:
|
||||
{
|
||||
actor->GetMapper()->SetImmediateModeRendering(int(value));
|
||||
actor->Modified();
|
||||
break;
|
||||
}
|
||||
case LINE_WIDTH:
|
||||
{
|
||||
actor->GetProperty()->SetLineWidth(float(value));
|
||||
actor->Modified();
|
||||
break;
|
||||
}
|
||||
case POINT_SIZE: actor->GetProperty()->SetPointSize(float(value)); break;
|
||||
case OPACITY: actor->GetProperty()->SetOpacity(value); break;
|
||||
case LINE_WIDTH: actor->GetProperty()->SetLineWidth(float(value)); break;
|
||||
case IMMEDIATE_RENDERING: actor->GetMapper()->SetImmediateModeRendering(int(value)); 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();
|
||||
text_actor->GetTextProperty()->SetFontSize(int(value));
|
||||
break;
|
||||
}
|
||||
case REPRESENTATION:
|
||||
@@ -174,7 +129,6 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
|
||||
case REPRESENTATION_WIREFRAME: actor->GetProperty()->SetRepresentationToWireframe(); break;
|
||||
case REPRESENTATION_SURFACE: actor->GetProperty()->SetRepresentationToSurface(); break;
|
||||
}
|
||||
actor->Modified();
|
||||
break;
|
||||
}
|
||||
case SHADING:
|
||||
@@ -215,14 +169,12 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
|
||||
break;
|
||||
}
|
||||
}
|
||||
actor->Modified();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
CV_Assert("setPointCloudRenderingProperties: Unknown property");
|
||||
}
|
||||
actor->Modified();
|
||||
}
|
||||
|
||||
double cv::viz::Widget::getRenderingProperty(int property) const
|
||||
@@ -233,32 +185,16 @@ double cv::viz::Widget::getRenderingProperty(int property) const
|
||||
double value = 0.0;
|
||||
switch (property)
|
||||
{
|
||||
case POINT_SIZE:
|
||||
{
|
||||
value = actor->GetProperty()->GetPointSize();
|
||||
break;
|
||||
}
|
||||
case OPACITY:
|
||||
{
|
||||
value = actor->GetProperty()->GetOpacity();
|
||||
break;
|
||||
}
|
||||
case IMMEDIATE_RENDERING:
|
||||
{
|
||||
value = actor->GetMapper()->GetImmediateModeRendering();
|
||||
break;
|
||||
}
|
||||
case LINE_WIDTH:
|
||||
{
|
||||
value = actor->GetProperty()->GetLineWidth();
|
||||
break;
|
||||
}
|
||||
case POINT_SIZE: value = actor->GetProperty()->GetPointSize(); break;
|
||||
case OPACITY: value = actor->GetProperty()->GetOpacity(); break;
|
||||
case LINE_WIDTH: value = actor->GetProperty()->GetLineWidth(); break;
|
||||
case IMMEDIATE_RENDERING: value = actor->GetMapper()->GetImmediateModeRendering(); 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();
|
||||
value = tprop->GetFontSize();
|
||||
value = text_actor->GetTextProperty()->GetFontSize();;
|
||||
break;
|
||||
}
|
||||
case REPRESENTATION:
|
||||
@@ -322,7 +258,7 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose)
|
||||
if (!matrix)
|
||||
{
|
||||
setPose(pose);
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
Affine3f updated_pose = pose * Affine3f(convertToMatx(matrix));
|
||||
|
||||
Reference in New Issue
Block a user