Commit b032b4dd authored by ozantonkal's avatar ozantonkal Committed by Ozan Tonkal

move frompolyfile to widget class as static method, remove addpolygon and its alikes

parent 0bbaf5d4
......@@ -27,13 +27,6 @@ namespace cv
void setBackgroundColor(const Color& color = Color::black());
//to refactor
bool addPolygonMesh(const Mesh3d& mesh, const String& id = "polygon");
bool updatePolygonMesh(const Mesh3d& mesh, const String& id = "polygon");
bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline");
bool addPolygon(const Mat& cloud, const Color& color, const String& id = "polygon");
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void removeWidget(const String &id);
Widget getWidget(const String &id) const;
......
......@@ -16,6 +16,8 @@ namespace cv
Widget();
Widget(const Widget &other);
Widget& operator =(const Widget &other);
static Widget fromPlyFile(const String &file_name);
~Widget();
......
......@@ -969,7 +969,6 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Matx33f &K, const Mat
// Create a camera
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
float f_x = K(0,0);
float f_y = K(1,1);
float c_y = K(1,2);
float aspect_ratio = float(image.cols)/float(image.rows);
......
......@@ -44,26 +44,6 @@ void cv::viz::Viz3d::release()
void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); }
bool cv::viz::Viz3d::addPolygonMesh (const Mesh3d& mesh, const String& id)
{
return impl_->addPolygonMesh(mesh, Mat(), id);
}
bool cv::viz::Viz3d::updatePolygonMesh (const Mesh3d& mesh, const String& id)
{
return impl_->updatePolygonMesh(mesh, Mat(), id);
}
bool cv::viz::Viz3d::addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id)
{
return impl_->addPolylineFromPolygonMesh(mesh, id);
}
bool cv::viz::Viz3d::addPolygon(const Mat& cloud, const Color& color, const String& id)
{
return impl_->addPolygon(cloud, color, id);
}
void cv::viz::Viz3d::spin() { impl_->spin(); }
void cv::viz::Viz3d::spinOnce (int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); }
bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); }
......@@ -94,4 +74,4 @@ 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(); }
\ No newline at end of file
cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); }
This diff is collapsed.
......@@ -19,30 +19,11 @@ public:
void removeAllWidgets();
//to refactor
bool addPolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon");
bool updatePolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon");
bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline");
// 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);
/** \brief Set whether the point cloud is selected or not
* \param[in] selected whether the cloud is selected or not (true = selected)
* \param[in] id the point cloud object id (default: cloud)
*/
// probably should just remove
bool setPointCloudSelected (const bool selected, const String& id = "cloud" );
/** \brief Returns true when the user tried to close the window */
bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; }
......@@ -60,30 +41,6 @@ public:
}
}
// to refactor
bool addPolygon(const cv::Mat& cloud, const Color& color, const String& id = "polygon");
bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color, bool display_length, const String& id = "arrow");
bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color_line, const Color& color_text, const String& id = "arrow");
// Probably remove this
bool addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata, const String& id = "PolyData");
bool addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata, vtkSmartPointer<vtkTransform> transform, const String& id = "PolyData");
// I think this should be moved to 'static Widget Widget::fromPlyFile(const String&)';
bool addModelFromPLYFile (const String &filename, const String& id = "PLYModel");
bool addModelFromPLYFile (const String &filename, vtkSmartPointer<vtkTransform> transform, const String& id = "PLYModel");
// to implement in Viz3d with shorter name
void setRepresentationToSurfaceForAllActors();
void setRepresentationToPointsForAllActors();
......
......@@ -54,6 +54,46 @@ void cv::viz::Widget::release()
}
}
cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
{
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New ();
reader->SetFileName (file_name.c_str ());
vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
CV_Assert(data);
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput (data);
vtkSmartPointer<vtkDataArray> scalars = data->GetPointData ()->GetScalars ();
if (scalars)
{
cv::Vec3d 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->ImmediateModeRenderingOff ();
actor->SetNumberOfCloudPoints (int (std::max<vtkIdType> (1, data->GetNumberOfPoints () / 10)));
actor->GetProperty ()->SetInterpolationToFlat ();
actor->GetProperty ()->BackfaceCullingOn ();
actor->SetMapper (mapper);
Widget widget;
widget.impl_->prop = actor;
return widget;
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget accessor implementaion
......
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