mirror of https://github.com/opencv/opencv.git
parent
daa2a205a4
commit
efa7f09048
12 changed files with 195 additions and 180 deletions
@ -1,3 +1,6 @@ |
||||
#pragma once |
||||
|
||||
#include <opencv2/viz/types.hpp> |
||||
#include <opencv2/viz/widgets.hpp> |
||||
#include <opencv2/viz/viz3d.hpp> |
||||
|
||||
|
@ -1,11 +1,15 @@ |
||||
#pragma once |
||||
|
||||
#include <opencv2/viz/types.hpp> |
||||
#include <opencv2/viz/widgets.hpp> |
||||
#include <vtkSmartPointer.h> |
||||
#include <vtkLODActor.h> |
||||
|
||||
namespace temp_viz |
||||
{ |
||||
struct WidgetAccessor |
||||
//The class is only that depends on VTK in its interface.
|
||||
//It is indended for those user who want to develop own widgets system using VTK library API.
|
||||
struct CV_EXPORTS WidgetAccessor |
||||
{ |
||||
static CV_EXPORTS vtkSmartPointer<vtkLODActor> getActor(const Widget &widget); |
||||
static vtkSmartPointer<vtkLODActor> getActor(const Widget &widget); |
||||
}; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,38 @@ |
||||
#pragma once |
||||
|
||||
#include <opencv2/viz/types.hpp> |
||||
|
||||
|
||||
namespace temp_viz |
||||
{ |
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// brief The base class for all widgets
|
||||
class CV_EXPORTS Widget |
||||
{ |
||||
public: |
||||
Widget(); |
||||
Widget(const Widget &other); |
||||
Widget& operator =(const Widget &other); |
||||
|
||||
void copyTo(Widget &dst); |
||||
|
||||
void setColor(const Color &color); |
||||
void setPose(const Affine3f &pose); |
||||
void updatePose(const Affine3f &pose); |
||||
Affine3f getPose() const; |
||||
|
||||
private: |
||||
class Impl; |
||||
cv::Ptr<Impl> impl_; |
||||
friend struct WidgetAccessor; |
||||
}; |
||||
|
||||
|
||||
class CV_EXPORTS LineWidget : public Widget |
||||
{ |
||||
public: |
||||
LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
|
||||
} |
@ -0,0 +1,18 @@ |
||||
#include "precomp.hpp" |
||||
|
||||
|
||||
temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color) |
||||
{ |
||||
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New(); |
||||
line->SetPoint1 (pt1.x, pt1.y, pt1.z); |
||||
line->SetPoint2 (pt2.x, pt2.y, pt2.z); |
||||
line->Update (); |
||||
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New (); |
||||
mapper->SetInput(line->GetOutput ()); |
||||
|
||||
vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this); |
||||
actor->SetMapper(mapper); |
||||
|
||||
setColor(color); |
||||
} |
@ -0,0 +1,110 @@ |
||||
#include "precomp.hpp" |
||||
|
||||
class temp_viz::Widget::Impl |
||||
{ |
||||
public: |
||||
vtkSmartPointer<vtkLODActor> actor; |
||||
|
||||
Impl() : actor(vtkSmartPointer<vtkLODActor>::New()) {} |
||||
|
||||
void setColor(const Color& color) |
||||
{ |
||||
Color c = vtkcolor(color); |
||||
actor->GetMapper ()->ScalarVisibilityOff (); |
||||
actor->GetProperty ()->SetColor (c.val); |
||||
actor->GetProperty ()->SetEdgeColor (c.val); |
||||
actor->GetProperty ()->SetAmbient (0.8); |
||||
actor->GetProperty ()->SetDiffuse (0.8); |
||||
actor->GetProperty ()->SetSpecular (0.8); |
||||
actor->GetProperty ()->SetLighting (0); |
||||
actor->Modified (); |
||||
} |
||||
|
||||
void setPose(const Affine3f& pose) |
||||
{ |
||||
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix); |
||||
actor->SetUserMatrix (matrix); |
||||
actor->Modified (); |
||||
} |
||||
|
||||
void updatePose(const Affine3f& pose) |
||||
{ |
||||
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); |
||||
Matx44f matrix_cv = convertToMatx(matrix); |
||||
|
||||
Affine3f updated_pose = pose * Affine3f(matrix_cv); |
||||
matrix = convertToVtkMatrix(updated_pose.matrix); |
||||
|
||||
actor->SetUserMatrix (matrix); |
||||
actor->Modified (); |
||||
} |
||||
|
||||
Affine3f getPose() const |
||||
{ |
||||
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); |
||||
Matx44f matrix_cv = convertToMatx(matrix); |
||||
return Affine3f(matrix_cv); |
||||
} |
||||
|
||||
protected: |
||||
|
||||
static vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const cv::Matx44f& m) |
||||
{ |
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New (); |
||||
for (int i = 0; i < 4; i++) |
||||
for (int k = 0; k < 4; k++) |
||||
vtk_matrix->SetElement(i, k, m(i, k)); |
||||
return vtk_matrix; |
||||
} |
||||
|
||||
static cv::Matx44f convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix) |
||||
{ |
||||
cv::Matx44f m; |
||||
for (int i = 0; i < 4; i++) |
||||
for (int k = 0; k < 4; k++) |
||||
m(i, k) = vtk_matrix->GetElement (i, k); |
||||
return m; |
||||
} |
||||
}; |
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// stream accessor implementaion
|
||||
|
||||
vtkSmartPointer<vtkLODActor> temp_viz::WidgetAccessor::getActor(const Widget& widget) |
||||
{ |
||||
return widget.impl_->actor; |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// widget implementaion
|
||||
|
||||
temp_viz::Widget::Widget() |
||||
{ |
||||
impl_ = new Impl(); |
||||
} |
||||
|
||||
temp_viz::Widget::Widget(const Widget& other) |
||||
{ |
||||
impl_ = other.impl_; |
||||
} |
||||
|
||||
temp_viz::Widget& temp_viz::Widget::operator =(const Widget &other) |
||||
{ |
||||
if (this != &other) |
||||
impl_ = other.impl_; |
||||
return *this; |
||||
} |
||||
|
||||
void temp_viz::Widget::copyTo(Widget& /*dst*/) |
||||
{ |
||||
// TODO Deep copy the data if there is any
|
||||
} |
||||
|
||||
void temp_viz::Widget::setColor(const Color& color) { impl_->setColor(color); } |
||||
void temp_viz::Widget::setPose(const Affine3f& pose) { impl_->setPose(pose); } |
||||
void temp_viz::Widget::updatePose(const Affine3f& pose) { impl_->updatePose(pose); } |
||||
temp_viz::Affine3f temp_viz::Widget::getPose() const { return impl_->getPose(); } |
||||
|
||||
|
||||
|
Loading…
Reference in new issue