set background texture method
This commit is contained in:
parent
e2ef558c8a
commit
d7c30281a5
modules/viz
@ -99,6 +99,8 @@ namespace cv
|
||||
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);
|
||||
|
@ -102,29 +102,6 @@ template<> cv::viz::WSphere cv::viz::Widget::cast<cv::viz::WSphere>()
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// 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();
|
||||
|
@ -113,15 +113,7 @@ void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); }
|
||||
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); }
|
||||
@ -146,6 +138,9 @@ void cv::viz::Viz3d::setWindowPosition(const Point& window_position) { impl_->se
|
||||
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); }
|
||||
|
||||
|
@ -269,6 +269,15 @@ void cv::viz::Viz3d::VizImpl::removeAllWidgets()
|
||||
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)
|
||||
@ -295,6 +304,55 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color)
|
||||
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)
|
||||
{
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
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;
|
||||
@ -109,6 +111,9 @@ public:
|
||||
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);
|
||||
|
||||
|
@ -57,7 +57,7 @@ TEST(Viz, DISABLED_show_cloud_bluberry)
|
||||
viz.spin();
|
||||
}
|
||||
|
||||
TEST(Viz, DISABLED_show_cloud_random_color)
|
||||
TEST(Viz, show_cloud_random_color)
|
||||
{
|
||||
Mat dragon_cloud = readCloud(get_dragon_ply_file_path());
|
||||
|
||||
@ -67,6 +67,7 @@ TEST(Viz, DISABLED_show_cloud_random_color)
|
||||
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();
|
||||
@ -229,6 +230,7 @@ TEST(Viz, DISABLED_show_overlay_image)
|
||||
Size2d half_lsize = Size2d(lena.size()) * 0.5;
|
||||
|
||||
Viz3d viz("show_overlay_image");
|
||||
viz.setBackgroundMeshLab();
|
||||
Size vsz = viz.getWindowSize();
|
||||
|
||||
viz.showWidget("coos", WCoordinateSystem());
|
||||
@ -264,12 +266,13 @@ TEST(Viz, DISABLED_show_image_method)
|
||||
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()));
|
||||
@ -291,6 +294,7 @@ TEST(Viz, DISABLED_show_image_3d)
|
||||
TEST(Viz, show_simple_widgets)
|
||||
{
|
||||
Viz3d viz("show_simple_widgets");
|
||||
viz.setBackgroundMeshLab();
|
||||
|
||||
viz.showWidget("coos", WCoordinateSystem());
|
||||
viz.showWidget("cube", WCube());
|
||||
@ -317,15 +321,16 @@ TEST(Viz, show_simple_widgets)
|
||||
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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user