set background texture method
This commit is contained in:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user