void setWindowPosition(const Point& window_position);
void setFullScreen(bool mode = true);
void setBackgroundColor(const Color& color = Color::black());
+ void setBackgroundTexture(InputArray image = noArray());
+ void setBackgroundMeshLab();
void spin();
void spinOnce(int time = 1, bool force_redraw = false);
///////////////////////////////////////////////////////////////////////////////////////////////
/// plane widget implementation
-namespace cv { namespace viz { namespace
-{
- struct PlaneUtils
- {
- template<typename _Tp>
- static vtkSmartPointer<vtkTransformPolyDataFilter> setSize(const Vec<_Tp, 3> ¢er, vtkSmartPointer<vtkAlgorithmOutput> poly_data_port, double size)
- {
- vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
- transform->PreMultiply();
- transform->Translate(center[0], center[1], center[2]);
- transform->Scale(size, size, size);
- transform->Translate(-center[0], -center[1], -center[2]);
-
- vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
- transform_filter->SetInputConnection(poly_data_port);
- transform_filter->SetTransform(transform);
- transform_filter->Update();
-
- return transform_filter;
- }
- };
-}}}
-
cv::viz::WPlane::WPlane(const Size2d& size, const Color &color)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New();
cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); }
void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); }
-
-void cv::viz::Viz3d::showImage(InputArray image, const Size& window_size)
-{
- removeAllWidgets();
- if (window_size.width > 0 && window_size.height > 0)
- setWindowSize(window_size);
-
- showWidget("showImage", WImageOverlay(image, Rect(Point(0,0), getWindowSize())));
-}
+void cv::viz::Viz3d::showImage(InputArray image, const Size& window_size) { impl_->showImage(image, window_size); }
void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3d &pose) { impl_->setWidgetPose(id, pose); }
void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3d &pose) { impl_->updateWidgetPose(id, pose); }
void cv::viz::Viz3d::setFullScreen(bool mode) { impl_->setFullScreen(mode); }
void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); }
+void cv::viz::Viz3d::setBackgroundTexture(InputArray image) { impl_->setBackgroundTexture(image); }
+void cv::viz::Viz3d::setBackgroundMeshLab() {impl_->setBackgroundMeshLab(); }
+
void cv::viz::Viz3d::setRenderingProperty(const String &id, int property, double value) { getWidget(id).setRenderingProperty(property, value); }
double cv::viz::Viz3d::getRenderingProperty(const String &id, int property) { return getWidget(id).getRenderingProperty(property); }
widget_actor_map_->clear();
renderer_->RemoveAllViewProps();
}
+/////////////////////////////////////////////////////////////////////////////////////////////
+void cv::viz::Viz3d::VizImpl::showImage(InputArray image, const Size& window_size)
+{
+ removeAllWidgets();
+ if (window_size.width > 0 && window_size.height > 0)
+ setWindowSize(window_size);
+
+ showWidget("showImage", WImageOverlay(image, Rect(Point(0,0), getWindowSize())));
+}
/////////////////////////////////////////////////////////////////////////////////////////////
bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer(vtkSmartPointer<vtkProp> actor)
renderer_->SetBackground(c.val);
}
+//////////////////////////////////////////////////////////////////////////////////////////////
+void cv::viz::Viz3d::VizImpl::setBackgroundTexture(InputArray image)
+{
+ if (image.empty())
+ {
+ renderer_->SetBackgroundTexture(0);
+ renderer_->TexturedBackgroundOff();
+ return;
+ }
+
+ vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New();
+ source->SetImage(image);
+
+ vtkSmartPointer<vtkImageFlip> image_flip = vtkSmartPointer<vtkImageFlip>::New();
+ image_flip->SetFilteredAxis(1); // Vertical flip
+ image_flip->SetInputConnection(source->GetOutputPort());
+
+ vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
+ texture->SetInputConnection(image_flip->GetOutputPort());
+ //texture->Update();
+
+ renderer_->SetBackgroundTexture(texture);
+ renderer_->TexturedBackgroundOn();
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+void cv::viz::Viz3d::VizImpl::setBackgroundMeshLab()
+{
+ static Color up(2, 1, 1), down(240, 120, 120);
+ static Mat meshlab_texture;
+
+ if (meshlab_texture.empty())
+ {
+ meshlab_texture.create(2048, 2048, CV_8UC4);
+
+ for (int y = 0; y < meshlab_texture.rows; ++y)
+ {
+ double alpha = (y+1)/(double)meshlab_texture.rows;
+ Vec4b color = up * (1 - alpha) + down * alpha;
+
+ Vec4b *row = meshlab_texture.ptr<Vec4b>(y);
+ for(int x = 0; x < meshlab_texture.cols; ++x)
+ row[x] = color;
+ }
+
+ }
+ setBackgroundTexture(meshlab_texture);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
{
Widget getWidget(const String &id) const;
void removeAllWidgets();
+ void showImage(InputArray image, const Size& window_size);
+
void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const;
String getWindowName() const;
void setBackgroundColor(const Color& color);
+ void setBackgroundTexture(InputArray image);
+ void setBackgroundMeshLab();
+
void spin();
void spinOnce(int time = 1, bool force_redraw = false);
viz.spin();
}
-TEST(Viz, DISABLED_show_cloud_random_color)
+TEST(Viz, show_cloud_random_color)
{
Mat dragon_cloud = readCloud(get_dragon_ply_file_path());
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0));
Viz3d viz("show_cloud_random_color");
+ viz.setBackgroundMeshLab();
viz.showWidget("coosys", WCoordinateSystem());
viz.showWidget("dragon", WCloud(dragon_cloud, colors), pose);
viz.spin();
Size2d half_lsize = Size2d(lena.size()) * 0.5;
Viz3d viz("show_overlay_image");
+ viz.setBackgroundMeshLab();
Size vsz = viz.getWindowSize();
viz.showWidget("coos", WCoordinateSystem());
cv::viz::imshow("show_image_method", make_gray(lena)).spin();
}
-TEST(Viz, DISABLED_show_image_3d)
+TEST(Viz, show_image_3d)
{
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png"));
Mat gray = make_gray(lena);
Viz3d viz("show_image_3d");
+ viz.setBackgroundMeshLab();
viz.showWidget("coos", WCoordinateSystem());
viz.showWidget("cube", WCube());
viz.showWidget("arr0", WArrow(Vec3d(0.5, 0.0, 0.0), Vec3d(1.5, 0.0, 0.0), 0.009, Color::raspberry()));
TEST(Viz, show_simple_widgets)
{
Viz3d viz("show_simple_widgets");
+ viz.setBackgroundMeshLab();
viz.showWidget("coos", WCoordinateSystem());
viz.showWidget("cube", WCube());
viz.spin();
}
-TEST(Viz, DISABLED_show_follower)
+TEST(Viz, show_follower)
{
Viz3d viz("show_follower");
viz.showWidget("coos", WCoordinateSystem());
viz.showWidget("cube", WCube());
viz.showWidget("t3d_2", WText3D("Simple 3D follower", Point3d(-0.5, -0.5, 0.5), 0.125, true, Color::green()));
+ viz.setBackgroundMeshLab();
viz.spinOnce(1500, true);
- //viz.getWidget("t3d_2").cast<WText3D>().setText("Updated follower 3D");
+ viz.getWidget("t3d_2").cast<WText3D>().setText("Updated follower 3D");
viz.spin();
}