Commit 8de46e1f authored by Ozan Tonkal's avatar Ozan Tonkal

removed trailing spaces

parent 824c28a5
...@@ -21,7 +21,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -21,7 +21,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
.. code-block:: cpp .. code-block:: cpp
#include <opencv2/viz.hpp> #include <opencv2/viz.hpp>
#include <opencv2/viz/widget_accessor.hpp> #include <opencv2/viz/widget_accessor.hpp>
#include <iostream> #include <iostream>
#include <vtkPoints.h> #include <vtkPoints.h>
...@@ -43,7 +43,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -43,7 +43,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
class WTriangle : public viz::Widget3D class WTriangle : public viz::Widget3D
{ {
public: public:
WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white()); WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
}; };
/** /**
...@@ -56,22 +56,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -56,22 +56,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
points->InsertNextPoint(pt1.x, pt1.y, pt1.z); points->InsertNextPoint(pt1.x, pt1.y, pt1.z);
points->InsertNextPoint(pt2.x, pt2.y, pt2.z); points->InsertNextPoint(pt2.x, pt2.y, pt2.z);
points->InsertNextPoint(pt3.x, pt3.y, pt3.z); points->InsertNextPoint(pt3.x, pt3.y, pt3.z);
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New(); vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId(0,0); triangle->GetPointIds()->SetId(0,0);
triangle->GetPointIds()->SetId(1,1); triangle->GetPointIds()->SetId(1,1);
triangle->GetPointIds()->SetId(2,2); triangle->GetPointIds()->SetId(2,2);
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(triangle); cells->InsertNextCell(triangle);
// Create a polydata object // Create a polydata object
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New(); vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
// Add the geometry and topology to the polydata // Add the geometry and topology to the polydata
polyData->SetPoints(points); polyData->SetPoints(points);
polyData->SetPolys(cells); polyData->SetPolys(cells);
// Create mapper and actor // Create mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
...@@ -79,13 +79,13 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -79,13 +79,13 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
#else #else
mapper->SetInputData(polyData); mapper->SetInputData(polyData);
#endif #endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
// Store this actor in the widget in order that visualizer can access it // Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor); viz::WidgetAccessor::setProp(*this, actor);
// Set the color of the widget. This has to be called after WidgetAccessor. // Set the color of the widget. This has to be called after WidgetAccessor.
setColor(color); setColor(color);
} }
...@@ -94,22 +94,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -94,22 +94,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
* @function main * @function main
*/ */
int main() int main()
{ {
/// Create a window /// Create a window
viz::Viz3d myWindow("Creating Widgets"); viz::Viz3d myWindow("Creating Widgets");
/// Create a triangle widget /// Create a triangle widget
WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red()); WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red());
/// Show widget in the visualizer window /// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw); myWindow.showWidget("TRIANGLE", tw);
/// Start event loop /// Start event loop
myWindow.spin(); myWindow.spin();
return 0; return 0;
} }
Explanation Explanation
=========== ===========
...@@ -122,33 +122,33 @@ Here is the general structure of the program: ...@@ -122,33 +122,33 @@ Here is the general structure of the program:
class WTriangle : public viz::Widget3D class WTriangle : public viz::Widget3D
{ {
public: public:
WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white()); WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
}; };
* Assign a VTK actor to the widget. * Assign a VTK actor to the widget.
.. code-block:: cpp .. code-block:: cpp
// Store this actor in the widget in order that visualizer can access it // Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor); viz::WidgetAccessor::setProp(*this, actor);
* Set color of the widget. * Set color of the widget.
.. code-block:: cpp .. code-block:: cpp
// Set the color of the widget. This has to be called after WidgetAccessor. // Set the color of the widget. This has to be called after WidgetAccessor.
setColor(color); setColor(color);
* Construct a triangle widget and display it in the window. * Construct a triangle widget and display it in the window.
.. code-block:: cpp .. code-block:: cpp
/// Create a triangle widget /// Create a triangle widget
WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red()); WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red());
/// Show widget in the visualizer window /// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw); myWindow.showWidget("TRIANGLE", tw);
Results Results
======= =======
......
...@@ -27,7 +27,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -27,7 +27,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
using namespace cv; using namespace cv;
using namespace std; using namespace std;
/** /**
* @function main * @function main
*/ */
...@@ -35,38 +35,38 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -35,38 +35,38 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
{ {
/// Create a window /// Create a window
viz::Viz3d myWindow("Viz Demo"); viz::Viz3d myWindow("Viz Demo");
/// Start event loop /// Start event loop
myWindow.spin(); myWindow.spin();
/// Event loop is over when pressed q, Q, e, E /// Event loop is over when pressed q, Q, e, E
cout << "First event loop is over" << endl; cout << "First event loop is over" << endl;
/// Access window via its name /// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo"); viz::Viz3d sameWindow = viz::get("Viz Demo");
/// Start event loop /// Start event loop
sameWindow.spin(); sameWindow.spin();
/// Event loop is over when pressed q, Q, e, E /// Event loop is over when pressed q, Q, e, E
cout << "Second event loop is over" << endl; cout << "Second event loop is over" << endl;
/// Event loop is over when pressed q, Q, e, E /// Event loop is over when pressed q, Q, e, E
/// Start event loop once for 1 millisecond /// Start event loop once for 1 millisecond
sameWindow.spinOnce(1, true); sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped()) while(!sameWindow.wasStopped())
{ {
/// Interact with window /// Interact with window
/// Event loop for 1 millisecond /// Event loop for 1 millisecond
sameWindow.spinOnce(1, true); sameWindow.spinOnce(1, true);
} }
/// Once more event loop is stopped /// Once more event loop is stopped
cout << "Last event loop is over" << endl; cout << "Last event loop is over" << endl;
return 0; return 0;
} }
Explanation Explanation
=========== ===========
...@@ -78,21 +78,21 @@ Here is the general structure of the program: ...@@ -78,21 +78,21 @@ Here is the general structure of the program:
/// Create a window /// Create a window
viz::Viz3d myWindow("Viz Demo"); viz::Viz3d myWindow("Viz Demo");
* Start event loop. This event loop will run until user terminates it by pressing **e**, **E**, **q**, **Q**. * Start event loop. This event loop will run until user terminates it by pressing **e**, **E**, **q**, **Q**.
.. code-block:: cpp .. code-block:: cpp
/// Start event loop /// Start event loop
myWindow.spin(); myWindow.spin();
* Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly the same with **myWindow**. If the name does not exist, a new window is created. * Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly the same with **myWindow**. If the name does not exist, a new window is created.
.. code-block:: cpp .. code-block:: cpp
/// Access window via its name /// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo"); viz::Viz3d sameWindow = viz::get("Viz Demo");
* Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping. Inside the while loop, user can execute other statements including those which interact with the window. * Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping. Inside the while loop, user can execute other statements including those which interact with the window.
.. code-block:: cpp .. code-block:: cpp
...@@ -103,11 +103,11 @@ Here is the general structure of the program: ...@@ -103,11 +103,11 @@ Here is the general structure of the program:
while(!sameWindow.wasStopped()) while(!sameWindow.wasStopped())
{ {
/// Interact with window /// Interact with window
/// Event loop for 1 millisecond /// Event loop for 1 millisecond
sameWindow.spinOnce(1, true); sameWindow.spinOnce(1, true);
} }
Results Results
======= =======
......
...@@ -45,7 +45,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -45,7 +45,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
float dummy1, dummy2; float dummy1, dummy2;
for(size_t i = 0; i < 1889; ++i) for(size_t i = 0; i < 1889; ++i)
ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2; ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2;
cloud *= 5.0f; cloud *= 5.0f;
return cloud; return cloud;
} }
...@@ -54,40 +54,40 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -54,40 +54,40 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
* @function main * @function main
*/ */
int main(int argn, char **argv) int main(int argn, char **argv)
{ {
if (argn < 2) if (argn < 2)
{ {
cout << "Usage: " << endl << "./transformations [ G | C ]" << endl; cout << "Usage: " << endl << "./transformations [ G | C ]" << endl;
return 1; return 1;
} }
bool camera_pov = (argv[1][0] == 'C'); bool camera_pov = (argv[1][0] == 'C');
/// Create a window /// Create a window
viz::Viz3d myWindow("Coordinate Frame"); viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes /// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// Let's assume camera has the following properties /// Let's assume camera has the following properties
Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f);
/// We can get the pose of the cam using makeCameraPose /// We can get the pose of the cam using makeCameraPose
Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
/// We can get the transformation matrix from camera coordinate system to global using /// We can get the transformation matrix from camera coordinate system to global using
/// - makeTransformToGlobal. We need the axes of the camera /// - makeTransformToGlobal. We need the axes of the camera
Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos);
/// Create a cloud widget. /// Create a cloud widget.
Mat bunny_cloud = cvcloud_load(); Mat bunny_cloud = cvcloud_load();
viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); viz::WCloud cloud_widget(bunny_cloud, viz::Color::green());
/// Pose of the widget in camera frame /// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f));
/// Pose of the widget in global frame /// Pose of the widget in global frame
Affine3f cloud_pose_global = transform * cloud_pose; Affine3f cloud_pose_global = transform * cloud_pose;
/// Visualize camera frame /// Visualize camera frame
if (!camera_pov) if (!camera_pov)
{ {
...@@ -96,21 +96,21 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -96,21 +96,21 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
myWindow.showWidget("CPW", cpw, cam_pose); myWindow.showWidget("CPW", cpw, cam_pose);
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
} }
/// Visualize widget /// Visualize widget
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
/// Set the viewer pose to that of camera /// Set the viewer pose to that of camera
if (camera_pov) if (camera_pov)
myWindow.setViewerPose(cam_pose); myWindow.setViewerPose(cam_pose);
/// Start event loop. /// Start event loop.
myWindow.spin(); myWindow.spin();
return 0; return 0;
} }
Explanation Explanation
=========== ===========
...@@ -122,17 +122,17 @@ Here is the general structure of the program: ...@@ -122,17 +122,17 @@ Here is the general structure of the program:
/// Create a window /// Create a window
viz::Viz3d myWindow("Transformations"); viz::Viz3d myWindow("Transformations");
* Get camera pose from camera position, camera focal point and y direction. * Get camera pose from camera position, camera focal point and y direction.
.. code-block:: cpp .. code-block:: cpp
/// Let's assume camera has the following properties /// Let's assume camera has the following properties
Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f);
/// We can get the pose of the cam using makeCameraPose /// We can get the pose of the cam using makeCameraPose
Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
* Obtain transform matrix knowing the axes of camera coordinate system. * Obtain transform matrix knowing the axes of camera coordinate system.
.. code-block:: cpp .. code-block:: cpp
...@@ -140,7 +140,7 @@ Here is the general structure of the program: ...@@ -140,7 +140,7 @@ Here is the general structure of the program:
/// We can get the transformation matrix from camera coordinate system to global using /// We can get the transformation matrix from camera coordinate system to global using
/// - makeTransformToGlobal. We need the axes of the camera /// - makeTransformToGlobal. We need the axes of the camera
Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos);
* Create a cloud widget from bunny.ply file * Create a cloud widget from bunny.ply file
.. code-block:: cpp .. code-block:: cpp
...@@ -148,16 +148,16 @@ Here is the general structure of the program: ...@@ -148,16 +148,16 @@ Here is the general structure of the program:
/// Create a cloud widget. /// Create a cloud widget.
Mat bunny_cloud = cvcloud_load(); Mat bunny_cloud = cvcloud_load();
viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); viz::WCloud cloud_widget(bunny_cloud, viz::Color::green());
* Given the pose in camera coordinate system, estimate the global pose. * Given the pose in camera coordinate system, estimate the global pose.
.. code-block:: cpp .. code-block:: cpp
/// Pose of the widget in camera frame /// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f));
/// Pose of the widget in global frame /// Pose of the widget in global frame
Affine3f cloud_pose_global = transform * cloud_pose; Affine3f cloud_pose_global = transform * cloud_pose;
* If the view point is set to be global, visualize camera coordinate frame and viewing frustum. * If the view point is set to be global, visualize camera coordinate frame and viewing frustum.
.. code-block:: cpp .. code-block:: cpp
...@@ -170,22 +170,22 @@ Here is the general structure of the program: ...@@ -170,22 +170,22 @@ Here is the general structure of the program:
myWindow.showWidget("CPW", cpw, cam_pose); myWindow.showWidget("CPW", cpw, cam_pose);
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
} }
* Visualize the cloud widget with the estimated global pose * Visualize the cloud widget with the estimated global pose
.. code-block:: cpp .. code-block:: cpp
/// Visualize widget /// Visualize widget
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
* If the view point is set to be camera's, set viewer pose to **cam_pose**. * If the view point is set to be camera's, set viewer pose to **cam_pose**.
.. code-block:: cpp .. code-block:: cpp
/// Set the viewer pose to that of camera /// Set the viewer pose to that of camera
if (camera_pov) if (camera_pov)
myWindow.setViewerPose(cam_pose); myWindow.setViewerPose(cam_pose);
Results Results
======= =======
......
...@@ -35,22 +35,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -35,22 +35,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
{ {
/// Create a window /// Create a window
viz::Viz3d myWindow("Coordinate Frame"); viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes /// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// Add line to represent (1,1,1) axis /// Add line to represent (1,1,1) axis
viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f)); viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis); myWindow.showWidget("Line Widget", axis);
/// Construct a cube widget /// Construct a cube widget
viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue()); viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
/// Display widget (update if already displayed) /// Display widget (update if already displayed)
myWindow.showWidget("Cube Widget", cube_widget); myWindow.showWidget("Cube Widget", cube_widget);
/// Rodrigues vector /// Rodrigues vector
Mat rot_vec = Mat::zeros(1,3,CV_32F); Mat rot_vec = Mat::zeros(1,3,CV_32F);
float translation_phase = 0.0, translation = 0.0; float translation_phase = 0.0, translation = 0.0;
...@@ -61,25 +61,25 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -61,25 +61,25 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
rot_vec.at<float>(0,0) += CV_PI * 0.01f; rot_vec.at<float>(0,0) += CV_PI * 0.01f;
rot_vec.at<float>(0,1) += CV_PI * 0.01f; rot_vec.at<float>(0,1) += CV_PI * 0.01f;
rot_vec.at<float>(0,2) += CV_PI * 0.01f; rot_vec.at<float>(0,2) += CV_PI * 0.01f;
/// Shift on (1,1,1) /// Shift on (1,1,1)
translation_phase += CV_PI * 0.01f; translation_phase += CV_PI * 0.01f;
translation = sin(translation_phase); translation = sin(translation_phase);
Mat rot_mat; Mat rot_mat;
Rodrigues(rot_vec, rot_mat); Rodrigues(rot_vec, rot_mat);
/// Construct pose /// Construct pose
Affine3f pose(rot_mat, Vec3f(translation, translation, translation)); Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
myWindow.setWidgetPose("Cube Widget", pose); myWindow.setWidgetPose("Cube Widget", pose);
myWindow.spinOnce(1, true); myWindow.spinOnce(1, true);
} }
return 0; return 0;
} }
Explanation Explanation
=========== ===========
...@@ -91,14 +91,14 @@ Here is the general structure of the program: ...@@ -91,14 +91,14 @@ Here is the general structure of the program:
/// Create a window /// Create a window
viz::Viz3d myWindow("Coordinate Frame"); viz::Viz3d myWindow("Coordinate Frame");
* Show coordinate axes in the window using CoordinateSystemWidget. * Show coordinate axes in the window using CoordinateSystemWidget.
.. code-block:: cpp .. code-block:: cpp
/// Add coordinate axes /// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
* Display a line representing the axis (1,1,1). * Display a line representing the axis (1,1,1).
.. code-block:: cpp .. code-block:: cpp
...@@ -107,7 +107,7 @@ Here is the general structure of the program: ...@@ -107,7 +107,7 @@ Here is the general structure of the program:
viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f)); viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis); myWindow.showWidget("Line Widget", axis);
* Construct a cube. * Construct a cube.
.. code-block:: cpp .. code-block:: cpp
...@@ -115,8 +115,8 @@ Here is the general structure of the program: ...@@ -115,8 +115,8 @@ Here is the general structure of the program:
/// Construct a cube widget /// Construct a cube widget
viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue()); viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Cube Widget", cube_widget); myWindow.showWidget("Cube Widget", cube_widget);
* Create rotation matrix from rodrigues vector * Create rotation matrix from rodrigues vector
.. code-block:: cpp .. code-block:: cpp
...@@ -125,20 +125,20 @@ Here is the general structure of the program: ...@@ -125,20 +125,20 @@ Here is the general structure of the program:
rot_vec.at<float>(0,0) += CV_PI * 0.01f; rot_vec.at<float>(0,0) += CV_PI * 0.01f;
rot_vec.at<float>(0,1) += CV_PI * 0.01f; rot_vec.at<float>(0,1) += CV_PI * 0.01f;
rot_vec.at<float>(0,2) += CV_PI * 0.01f; rot_vec.at<float>(0,2) += CV_PI * 0.01f;
... ...
Mat rot_mat; Mat rot_mat;
Rodrigues(rot_vec, rot_mat); Rodrigues(rot_vec, rot_mat);
* Use Affine3f to set pose of the cube. * Use Affine3f to set pose of the cube.
.. code-block:: cpp .. code-block:: cpp
/// Construct pose /// Construct pose
Affine3f pose(rot_mat, Vec3f(translation, translation, translation)); Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
myWindow.setWidgetPose("Cube Widget", pose); myWindow.setWidgetPose("Cube Widget", pose);
* Animate the rotation using wasStopped and spinOnce * Animate the rotation using wasStopped and spinOnce
.. code-block:: cpp .. code-block:: cpp
...@@ -146,10 +146,10 @@ Here is the general structure of the program: ...@@ -146,10 +146,10 @@ Here is the general structure of the program:
while(!myWindow.wasStopped()) while(!myWindow.wasStopped())
{ {
... ...
myWindow.spinOnce(1, true); myWindow.spinOnce(1, true);
} }
Results Results
======= =======
......
...@@ -3,7 +3,7 @@ macro(find_qvtk) ...@@ -3,7 +3,7 @@ macro(find_qvtk)
find_path (QVTK_INCLUDE_DIR QVTKWidget.h HINT ${VTK_INCLUDE_DIRS}) find_path (QVTK_INCLUDE_DIR QVTKWidget.h HINT ${VTK_INCLUDE_DIRS})
find_package_handle_standard_args(QVTK DEFAULT_MSG QVTK_LIBRARY QVTK_INCLUDE_DIR) find_package_handle_standard_args(QVTK DEFAULT_MSG QVTK_LIBRARY QVTK_INCLUDE_DIR)
if(QVTK_FOUND) if(QVTK_FOUND)
get_filename_component (QVTK_LIBRARY_DIR ${QVTK_LIBRARY} PATH) get_filename_component (QVTK_LIBRARY_DIR ${QVTK_LIBRARY} PATH)
list(APPEND VTK_LIBRARY_DIRS ${QVTK_LIBRARY_DIR}) list(APPEND VTK_LIBRARY_DIRS ${QVTK_LIBRARY_DIR})
list(APPEND VTK_INCLUDE_DIRS ${QVTK_INCLUDE_DIR}) list(APPEND VTK_INCLUDE_DIRS ${QVTK_INCLUDE_DIR})
...@@ -22,7 +22,7 @@ macro(find_vtk) ...@@ -22,7 +22,7 @@ macro(find_vtk)
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, lib: ${VTK_LIBRARY_DIRS})") message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, lib: ${VTK_LIBRARY_DIRS})")
link_directories(${VTK_LIBRARY_DIRS}) link_directories(${VTK_LIBRARY_DIRS})
include_directories(SYSTEM ${VTK_INCLUDE_DIRS}) include_directories(SYSTEM ${VTK_INCLUDE_DIRS})
set(HAVE_VTK ON) set(HAVE_VTK ON)
else () else ()
set(HAVE_VTK OFF) set(HAVE_VTK OFF)
message (FATAL_ERROR "VTK disabled. You are to build OpenCV in STATIC but VTK is SHARED!") message (FATAL_ERROR "VTK disabled. You are to build OpenCV in STATIC but VTK is SHARED!")
...@@ -39,7 +39,7 @@ if(DEFINED HAVE_VTK AND HAVE_VTK) ...@@ -39,7 +39,7 @@ if(DEFINED HAVE_VTK AND HAVE_VTK)
include (${VTK_USE_FILE}) include (${VTK_USE_FILE})
add_definitions(-DHAVE_VTK) add_definitions(-DHAVE_VTK)
endif() endif()
set(the_description "Viz") set(the_description "Viz")
set(BUILD_opencv_viz_INIT OFF) set(BUILD_opencv_viz_INIT OFF)
include_directories(src) include_directories(src)
......
...@@ -4,6 +4,6 @@ viz. 3D Visualizer ...@@ -4,6 +4,6 @@ viz. 3D Visualizer
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
viz3d.rst viz3d.rst
widget.rst widget.rst
This diff is collapsed.
This diff is collapsed.
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
namespace cv namespace cv
{ {
namespace viz namespace viz
{ {
//! takes coordiante frame data and builds transfrom to global coordinate frame //! takes coordiante frame data and builds transfrom to global coordinate frame
CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0)); CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0));
...@@ -87,32 +87,32 @@ namespace cv ...@@ -87,32 +87,32 @@ namespace cv
//! checks point for Nans //! checks point for Nans
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p) template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); } { return isNan(p.x) || isNan(p.y) || isNan(p.z); }
//! helper class that provides access by name infrastructure //! helper class that provides access by name infrastructure
class CV_EXPORTS VizAccessor class CV_EXPORTS VizAccessor
{ {
public: public:
static VizAccessor & getInstance(); static VizAccessor & getInstance();
static void release(); static void release();
Viz3d get(const String &window_name); Viz3d get(const String &window_name);
//! window names automatically have Viz - prefix even though not provided by the users //! window names automatically have Viz - prefix even though not provided by the users
static void generateWindowName(const String &window_name, String &output); static void generateWindowName(const String &window_name, String &output);
private: private:
VizAccessor(); // Singleton VizAccessor(); // Singleton
~VizAccessor(); ~VizAccessor();
void add(Viz3d window); void add(Viz3d window);
void remove(const String &window_name); void remove(const String &window_name);
static VizAccessor * instance_; static VizAccessor * instance_;
static bool is_instantiated_; static bool is_instantiated_;
struct VizAccessorImpl; struct VizAccessorImpl;
static VizAccessorImpl * impl_; static VizAccessorImpl * impl_;
friend class Viz3d; friend class Viz3d;
}; };
} /* namespace viz */ } /* namespace viz */
......
...@@ -88,7 +88,7 @@ namespace cv ...@@ -88,7 +88,7 @@ namespace cv
//! Loads mesh from a given ply file //! Loads mesh from a given ply file
static cv::viz::Mesh3d loadMesh(const String& file); static cv::viz::Mesh3d loadMesh(const String& file);
private: private:
struct loadMeshImpl; struct loadMeshImpl;
}; };
...@@ -135,7 +135,7 @@ namespace cv ...@@ -135,7 +135,7 @@ namespace cv
Point pointer; Point pointer;
unsigned int key_state; unsigned int key_state;
}; };
class CV_EXPORTS Camera class CV_EXPORTS Camera
{ {
public: public:
...@@ -143,26 +143,26 @@ namespace cv ...@@ -143,26 +143,26 @@ namespace cv
Camera(const Vec2f &fov, const Size &window_size); Camera(const Vec2f &fov, const Size &window_size);
Camera(const cv::Matx33f &K, const Size &window_size); Camera(const cv::Matx33f &K, const Size &window_size);
Camera(const cv::Matx44f &proj, const Size &window_size); Camera(const cv::Matx44f &proj, const Size &window_size);
inline const Vec2d & getClip() const { return clip_; } inline const Vec2d & getClip() const { return clip_; }
inline void setClip(const Vec2d &clip) { clip_ = clip; } inline void setClip(const Vec2d &clip) { clip_ = clip; }
inline const Size & getWindowSize() const { return window_size_; } inline const Size & getWindowSize() const { return window_size_; }
void setWindowSize(const Size &window_size); void setWindowSize(const Size &window_size);
inline const Vec2f & getFov() const { return fov_; } inline const Vec2f & getFov() const { return fov_; }
inline void setFov(const Vec2f & fov) { fov_ = fov; } inline void setFov(const Vec2f & fov) { fov_ = fov; }
inline const Vec2f & getPrincipalPoint() const { return principal_point_; } inline const Vec2f & getPrincipalPoint() const { return principal_point_; }
inline const Vec2f & getFocalLength() const { return focal_; } inline const Vec2f & getFocalLength() const { return focal_; }
void computeProjectionMatrix(Matx44f &proj) const; void computeProjectionMatrix(Matx44f &proj) const;
static Camera KinectCamera(const Size &window_size); static Camera KinectCamera(const Size &window_size);
private: private:
void init(float f_x, float f_y, float c_x, float c_y, const Size &window_size); void init(float f_x, float f_y, float c_x, float c_y, const Size &window_size);
Vec2d clip_; Vec2d clip_;
Vec2f fov_; Vec2f fov_;
Size window_size_; Size window_size_;
......
...@@ -81,18 +81,18 @@ namespace cv ...@@ -81,18 +81,18 @@ namespace cv
void setWidgetPose(const String &id, const Affine3f &pose); void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose); void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const; Affine3f getWidgetPose(const String &id) const;
void setCamera(const Camera &camera); void setCamera(const Camera &camera);
Camera getCamera() const; Camera getCamera() const;
Affine3f getViewerPose(); Affine3f getViewerPose();
void setViewerPose(const Affine3f &pose); void setViewerPose(const Affine3f &pose);
void resetCameraViewpoint(const String &id); void resetCameraViewpoint(const String &id);
void resetCamera(); void resetCamera();
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
Size getWindowSize() const; Size getWindowSize() const;
void setWindowSize(const Size &window_size); void setWindowSize(const Size &window_size);
String getWindowName() const; String getWindowName() const;
...@@ -107,19 +107,19 @@ namespace cv ...@@ -107,19 +107,19 @@ namespace cv
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0); void registerMouseCallback(MouseCallback callback, void* cookie = 0);
void setRenderingProperty(const String &id, int property, double value); void setRenderingProperty(const String &id, int property, double value);
double getRenderingProperty(const String &id, int property); double getRenderingProperty(const String &id, int property);
void setDesiredUpdateRate(double rate); void setDesiredUpdateRate(double rate);
double getDesiredUpdateRate(); double getDesiredUpdateRate();
void setRepresentation(int representation); void setRepresentation(int representation);
private: private:
struct VizImpl; struct VizImpl;
VizImpl* impl_; VizImpl* impl_;
void create(const String &window_name); void create(const String &window_name);
void release(); void release();
}; };
......
...@@ -81,7 +81,7 @@ namespace cv ...@@ -81,7 +81,7 @@ namespace cv
SHADING_GOURAUD, SHADING_GOURAUD,
SHADING_PHONG SHADING_PHONG
}; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/// The base class for all widgets /// The base class for all widgets
class CV_EXPORTS Widget class CV_EXPORTS Widget
...@@ -91,10 +91,10 @@ namespace cv ...@@ -91,10 +91,10 @@ namespace cv
Widget(const Widget& other); Widget(const Widget& other);
Widget& operator=(const Widget& other); Widget& operator=(const Widget& other);
~Widget(); ~Widget();
//! Create a widget directly from ply file //! Create a widget directly from ply file
static Widget fromPlyFile(const String &file_name); static Widget fromPlyFile(const String &file_name);
//! Rendering properties of this particular widget //! Rendering properties of this particular widget
void setRenderingProperty(int property, double value); void setRenderingProperty(int property, double value);
double getRenderingProperty(int property) const; double getRenderingProperty(int property) const;
...@@ -201,10 +201,10 @@ namespace cv ...@@ -201,10 +201,10 @@ namespace cv
WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
//! Creates grid based on the plane equation //! Creates grid based on the plane equation
WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
private: private:
struct GridImpl; struct GridImpl;
}; };
class CV_EXPORTS WText3D : public Widget3D class CV_EXPORTS WText3D : public Widget3D
...@@ -224,15 +224,15 @@ namespace cv ...@@ -224,15 +224,15 @@ namespace cv
void setText(const String &text); void setText(const String &text);
String getText() const; String getText() const;
}; };
class CV_EXPORTS WImageOverlay : public Widget2D class CV_EXPORTS WImageOverlay : public Widget2D
{ {
public: public:
WImageOverlay(const Mat &image, const Rect &rect); WImageOverlay(const Mat &image, const Rect &rect);
void setImage(const Mat &image); void setImage(const Mat &image);
}; };
class CV_EXPORTS WImage3D : public Widget3D class CV_EXPORTS WImage3D : public Widget3D
{ {
public: public:
...@@ -240,10 +240,10 @@ namespace cv ...@@ -240,10 +240,10 @@ namespace cv
WImage3D(const Mat &image, const Size &size); WImage3D(const Mat &image, const Size &size);
//! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation
WImage3D(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size); WImage3D(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size);
void setImage(const Mat &image); void setImage(const Mat &image);
}; };
class CV_EXPORTS WCameraPosition : public Widget3D class CV_EXPORTS WCameraPosition : public Widget3D
{ {
public: public:
...@@ -257,27 +257,27 @@ namespace cv ...@@ -257,27 +257,27 @@ namespace cv
WCameraPosition(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()); WCameraPosition(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white());
//! Creates frustum and display given image at the far plane //! Creates frustum and display given image at the far plane
WCameraPosition(const Vec2f &fov, const Mat &img, double scale = 1.0, const Color &color = Color::white()); WCameraPosition(const Vec2f &fov, const Mat &img, double scale = 1.0, const Color &color = Color::white());
private: private:
struct ProjectImage; struct ProjectImage;
}; };
class CV_EXPORTS WTrajectory : public Widget3D class CV_EXPORTS WTrajectory : public Widget3D
{ {
public: public:
enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2}; enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2};
//! Displays trajectory of the given path either by coordinate frames or polyline //! Displays trajectory of the given path either by coordinate frames or polyline
WTrajectory(const std::vector<Affine3f> &path, int display_mode = WTrajectory::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0); WTrajectory(const std::vector<Affine3f> &path, int display_mode = WTrajectory::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0);
//! Displays trajectory of the given path by frustums //! Displays trajectory of the given path by frustums
WTrajectory(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); WTrajectory(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white());
//! Displays trajectory of the given path by frustums //! Displays trajectory of the given path by frustums
WTrajectory(const std::vector<Affine3f> &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); WTrajectory(const std::vector<Affine3f> &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white());
private: private:
struct ApplyPath; struct ApplyPath;
}; };
class CV_EXPORTS WSpheresTrajectory: public Widget3D class CV_EXPORTS WSpheresTrajectory: public Widget3D
{ {
public: public:
...@@ -301,16 +301,16 @@ namespace cv ...@@ -301,16 +301,16 @@ namespace cv
{ {
public: public:
WCloudCollection(); WCloudCollection();
//! Each point in cloud is mapped to a color in colors //! Each point in cloud is mapped to a color in colors
void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()); void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity());
//! All points in cloud have the same color //! All points in cloud have the same color
void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity()); void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity());
private: private:
struct CreateCloudWidget; struct CreateCloudWidget;
}; };
class CV_EXPORTS WCloudNormals : public Widget3D class CV_EXPORTS WCloudNormals : public Widget3D
{ {
public: public:
...@@ -319,12 +319,12 @@ namespace cv ...@@ -319,12 +319,12 @@ namespace cv
private: private:
struct ApplyCloudNormals; struct ApplyCloudNormals;
}; };
class CV_EXPORTS WMesh : public Widget3D class CV_EXPORTS WMesh : public Widget3D
{ {
public: public:
WMesh(const Mesh3d &mesh); WMesh(const Mesh3d &mesh);
private: private:
struct CopyImpl; struct CopyImpl;
}; };
......
...@@ -327,7 +327,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget ...@@ -327,7 +327,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
vertices->SetCells(nr_points, cells); vertices->SetCells(nr_points, cells);
return polydata; return polydata;
} }
static void createMapper(vtkSmartPointer<vtkLODActor> actor, vtkSmartPointer<vtkPolyData> poly_data, Vec3d& minmax) static void createMapper(vtkSmartPointer<vtkLODActor> actor, vtkSmartPointer<vtkPolyData> poly_data, Vec3d& minmax)
{ {
vtkDataSetMapper *mapper = vtkDataSetMapper::SafeDownCast(actor->GetMapper()); vtkDataSetMapper *mapper = vtkDataSetMapper::SafeDownCast(actor->GetMapper());
...@@ -349,17 +349,17 @@ struct cv::viz::WCloudCollection::CreateCloudWidget ...@@ -349,17 +349,17 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
mapper_new->SetInterpolateScalarsBeforeMapping(interpolation); mapper_new->SetInterpolateScalarsBeforeMapping(interpolation);
mapper_new->ScalarVisibilityOn(); mapper_new->ScalarVisibilityOn();
mapper_new->ImmediateModeRenderingOff(); mapper_new->ImmediateModeRenderingOff();
actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, poly_data->GetNumberOfPoints() / 10))); actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, poly_data->GetNumberOfPoints() / 10)));
actor->GetProperty()->SetInterpolationToFlat(); actor->GetProperty()->SetInterpolationToFlat();
actor->GetProperty()->BackfaceCullingOn(); actor->GetProperty()->BackfaceCullingOn();
actor->SetMapper(mapper_new); actor->SetMapper(mapper_new);
return ; return ;
} }
vtkPolyData *data = vtkPolyData::SafeDownCast(mapper->GetInput()); vtkPolyData *data = vtkPolyData::SafeDownCast(mapper->GetInput());
CV_Assert("Cloud Widget without data" && data); CV_Assert("Cloud Widget without data" && data);
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New(); vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort()); appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort());
...@@ -369,7 +369,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget ...@@ -369,7 +369,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
appendFilter->AddInputData(poly_data); appendFilter->AddInputData(poly_data);
#endif #endif
mapper->SetInputConnection(appendFilter->GetOutputPort()); mapper->SetInputConnection(appendFilter->GetOutputPort());
// Update the number of cloud points // Update the number of cloud points
vtkIdType old_cloud_points = actor->GetNumberOfCloudPoints(); vtkIdType old_cloud_points = actor->GetNumberOfCloudPoints();
actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, old_cloud_points+poly_data->GetNumberOfPoints() / 10))); actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, old_cloud_points+poly_data->GetNumberOfPoints() / 10)));
...@@ -389,7 +389,7 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors, ...@@ -389,7 +389,7 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
Mat colors = _colors.getMat(); Mat colors = _colors.getMat();
CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4); CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4);
CV_Assert(colors.type() == CV_8UC3 && cloud.size() == colors.size()); CV_Assert(colors.type() == CV_8UC3 && cloud.size() == colors.size());
if (cloud.isContinuous() && colors.isContinuous()) if (cloud.isContinuous() && colors.isContinuous())
{ {
cloud.reshape(cloud.channels(), 1); cloud.reshape(cloud.channels(), 1);
...@@ -410,12 +410,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors, ...@@ -410,12 +410,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
// Assign the colors // Assign the colors
polydata->GetPointData()->SetScalars(scalars); polydata->GetPointData()->SetScalars(scalars);
// Transform the poly data based on the pose // Transform the poly data based on the pose
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply(); transform->PreMultiply();
transform->SetMatrix(convertToVtkMatrix(pose.matrix)); transform->SetMatrix(convertToVtkMatrix(pose.matrix));
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transform_filter->SetTransform(transform); transform_filter->SetTransform(transform);
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
...@@ -424,10 +424,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors, ...@@ -424,10 +424,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
transform_filter->SetInputData(polydata); transform_filter->SetInputData(polydata);
#endif #endif
transform_filter->Update(); transform_filter->Update();
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Incompatible widget type." && actor); CV_Assert("Incompatible widget type." && actor);
Vec3d minmax(scalars->GetRange()); Vec3d minmax(scalars->GetRange());
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax); CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
} }
...@@ -449,12 +449,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color, ...@@ -449,12 +449,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color,
// Assign the colors // Assign the colors
polydata->GetPointData()->SetScalars(scalars); polydata->GetPointData()->SetScalars(scalars);
// Transform the poly data based on the pose // Transform the poly data based on the pose
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply(); transform->PreMultiply();
transform->SetMatrix(convertToVtkMatrix(pose.matrix)); transform->SetMatrix(convertToVtkMatrix(pose.matrix));
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transform_filter->SetTransform(transform); transform_filter->SetTransform(transform);
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
...@@ -463,10 +463,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color, ...@@ -463,10 +463,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color,
transform_filter->SetInputData(polydata); transform_filter->SetInputData(polydata);
#endif #endif
transform_filter->Update(); transform_filter->Update();
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Incompatible widget type." && actor); CV_Assert("Incompatible widget type." && actor);
Vec3d minmax(scalars->GetRange()); Vec3d minmax(scalars->GetRange());
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax); CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
} }
...@@ -634,7 +634,7 @@ struct cv::viz::WMesh::CopyImpl ...@@ -634,7 +634,7 @@ struct cv::viz::WMesh::CopyImpl
int index = 0; int index = 0;
const _Tp* srow = source.ptr<_Tp>(0); const _Tp* srow = source.ptr<_Tp>(0);
const _Tp* mrow = nan_mask.ptr<_Tp>(0); const _Tp* mrow = nan_mask.ptr<_Tp>(0);
for (int x = 0; x < source.cols; ++x, srow += s_chs, mrow += m_chs) for (int x = 0; x < source.cols; ++x, srow += s_chs, mrow += m_chs)
{ {
if (!isNan(mrow[0]) && !isNan(mrow[1]) && !isNan(mrow[2])) if (!isNan(mrow[0]) && !isNan(mrow[1]) && !isNan(mrow[2]))
...@@ -653,13 +653,13 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh) ...@@ -653,13 +653,13 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
CV_Assert(mesh.cloud.rows == 1 && (mesh.cloud.type() == CV_32FC3 || mesh.cloud.type() == CV_64FC3 || mesh.cloud.type() == CV_32FC4 || mesh.cloud.type() == CV_64FC4)); CV_Assert(mesh.cloud.rows == 1 && (mesh.cloud.type() == CV_32FC3 || mesh.cloud.type() == CV_64FC3 || mesh.cloud.type() == CV_32FC4 || mesh.cloud.type() == CV_64FC4));
CV_Assert(mesh.colors.empty() || (mesh.colors.type() == CV_8UC3 && mesh.cloud.size() == mesh.colors.size())); CV_Assert(mesh.colors.empty() || (mesh.colors.type() == CV_8UC3 && mesh.cloud.size() == mesh.colors.size()));
CV_Assert(!mesh.polygons.empty() && mesh.polygons.type() == CV_32SC1); CV_Assert(!mesh.polygons.empty() && mesh.polygons.type() == CV_32SC1);
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkIdType nr_points = mesh.cloud.total(); vtkIdType nr_points = mesh.cloud.total();
Mat look_up_mat(1, nr_points, CV_32SC1); Mat look_up_mat(1, nr_points, CV_32SC1);
int * look_up = look_up_mat.ptr<int>(); int * look_up = look_up_mat.ptr<int>();
points->SetNumberOfPoints(nr_points); points->SetNumberOfPoints(nr_points);
// Copy data from cloud to vtkPoints // Copy data from cloud to vtkPoints
if (mesh.cloud.depth() == CV_32F) if (mesh.cloud.depth() == CV_32F)
{ {
...@@ -675,36 +675,36 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh) ...@@ -675,36 +675,36 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
Vec3d *data_end = CopyImpl::copy(mesh.cloud, data_beg, look_up, mesh.cloud); Vec3d *data_end = CopyImpl::copy(mesh.cloud, data_beg, look_up, mesh.cloud);
nr_points = data_end - data_beg; nr_points = data_end - data_beg;
} }
vtkSmartPointer<vtkUnsignedCharArray> scalars; vtkSmartPointer<vtkUnsignedCharArray> scalars;
if (!mesh.colors.empty()) if (!mesh.colors.empty())
{ {
Vec3b * colors_data = 0; Vec3b * colors_data = 0;
colors_data = new Vec3b[nr_points]; colors_data = new Vec3b[nr_points];
NanFilter::copyColor(mesh.colors, colors_data, mesh.cloud); NanFilter::copyColor(mesh.colors, colors_data, mesh.cloud);
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New(); scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
scalars->SetNumberOfComponents(3); scalars->SetNumberOfComponents(3);
scalars->SetNumberOfTuples(nr_points); scalars->SetNumberOfTuples(nr_points);
scalars->SetArray(colors_data->val, 3 * nr_points, 0); scalars->SetArray(colors_data->val, 3 * nr_points, 0);
} }
points->SetNumberOfPoints(nr_points); points->SetNumberOfPoints(nr_points);
vtkSmartPointer<vtkPointSet> data; vtkSmartPointer<vtkPointSet> data;
if (mesh.polygons.size().area() > 1) if (mesh.polygons.size().area() > 1)
{ {
vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New();
const int * polygons = mesh.polygons.ptr<int>(); const int * polygons = mesh.polygons.ptr<int>();
int idx = 0; int idx = 0;
int poly_size = mesh.polygons.total(); int poly_size = mesh.polygons.total();
for (int i = 0; i < poly_size; ++idx) for (int i = 0; i < poly_size; ++idx)
{ {
int n_points = polygons[i++]; int n_points = polygons[i++];
cell_array->InsertNextCell(n_points); cell_array->InsertNextCell(n_points);
for (int j = 0; j < n_points; ++j, ++idx) for (int j = 0; j < n_points; ++j, ++idx)
cell_array->InsertCellPoint(look_up[polygons[i++]]); cell_array->InsertCellPoint(look_up[polygons[i++]]);
...@@ -717,7 +717,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh) ...@@ -717,7 +717,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
if (scalars) if (scalars)
polydata->GetPointData()->SetScalars(scalars); polydata->GetPointData()->SetScalars(scalars);
data = polydata; data = polydata;
} }
else else
...@@ -726,20 +726,20 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh) ...@@ -726,20 +726,20 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New(); vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
const int * polygons = mesh.polygons.ptr<int>(); const int * polygons = mesh.polygons.ptr<int>();
int n_points = polygons[0]; int n_points = polygons[0];
polygon->GetPointIds()->SetNumberOfIds(n_points); polygon->GetPointIds()->SetNumberOfIds(n_points);
for (int j = 1; j < n_points+1; ++j) for (int j = 1; j < n_points+1; ++j)
polygon->GetPointIds()->SetId(j, look_up[polygons[j]]); polygon->GetPointIds()->SetId(j, look_up[polygons[j]]);
vtkSmartPointer<vtkUnstructuredGrid> poly_grid = vtkSmartPointer<vtkUnstructuredGrid>::New(); vtkSmartPointer<vtkUnstructuredGrid> poly_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
poly_grid->Allocate(1, 1); poly_grid->Allocate(1, 1);
poly_grid->InsertNextCell(polygon->GetCellType(), polygon->GetPointIds()); poly_grid->InsertNextCell(polygon->GetCellType(), polygon->GetPointIds());
poly_grid->SetPoints(points); poly_grid->SetPoints(points);
if (scalars) if (scalars)
poly_grid->GetPointData()->SetScalars(scalars); poly_grid->GetPointData()->SetScalars(scalars);
data = poly_grid; data = poly_grid;
} }
...@@ -750,7 +750,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh) ...@@ -750,7 +750,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
actor->GetProperty()->SetInterpolationToFlat(); actor->GetProperty()->SetInterpolationToFlat();
actor->GetProperty()->EdgeVisibilityOff(); actor->GetProperty()->EdgeVisibilityOff();
actor->GetProperty()->ShadingOff(); actor->GetProperty()->ShadingOff();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
mapper->SetInput(data); mapper->SetInput(data);
...@@ -758,11 +758,11 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh) ...@@ -758,11 +758,11 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
mapper->SetInputData(data); mapper->SetInputData(data);
#endif #endif
mapper->ImmediateModeRenderingOff(); mapper->ImmediateModeRenderingOff();
vtkIdType numberOfCloudPoints = nr_points * 0.1; vtkIdType numberOfCloudPoints = nr_points * 0.1;
actor->SetNumberOfCloudPoints(int(numberOfCloudPoints > 1 ? numberOfCloudPoints : 1)); actor->SetNumberOfCloudPoints(int(numberOfCloudPoints > 1 ? numberOfCloudPoints : 1));
actor->SetMapper(mapper); actor->SetMapper(mapper);
WidgetAccessor::setProp(*this, actor); WidgetAccessor::setProp(*this, actor);
} }
......
...@@ -67,11 +67,11 @@ void cv::viz::InteractorStyle::Initialize() ...@@ -67,11 +67,11 @@ void cv::viz::InteractorStyle::Initialize()
init_ = true; init_ = true;
stereo_anaglyph_mask_default_ = true; stereo_anaglyph_mask_default_ = true;
// Initialize the keyboard event callback as none // Initialize the keyboard event callback as none
keyboardCallback_ = 0; keyboardCallback_ = 0;
keyboard_callback_cookie_ = 0; keyboard_callback_cookie_ = 0;
// Initialize the mouse event callback as none // Initialize the mouse event callback as none
mouseCallback_ = 0; mouseCallback_ = 0;
mouse_callback_cookie_ = 0; mouse_callback_cookie_ = 0;
...@@ -197,7 +197,7 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K ...@@ -197,7 +197,7 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K
void void
cv::viz::InteractorStyle::OnKeyDown() cv::viz::InteractorStyle::OnKeyDown()
{ {
CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_); CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_);
CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_); CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_);
...@@ -482,7 +482,7 @@ cv::viz::InteractorStyle::OnKeyDown() ...@@ -482,7 +482,7 @@ cv::viz::InteractorStyle::OnKeyDown()
{ {
if (it == widget_actor_map_->end()) if (it == widget_actor_map_->end())
it = widget_actor_map_->begin(); it = widget_actor_map_->begin();
vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
if (actor && actor->GetUserMatrix()) if (actor && actor->GetUserMatrix())
{ {
...@@ -554,7 +554,7 @@ void cv::viz::InteractorStyle::OnKeyUp() ...@@ -554,7 +554,7 @@ void cv::viz::InteractorStyle::OnKeyUp()
// Check if there is a keyboard callback registered // Check if there is a keyboard callback registered
if (keyboardCallback_) if (keyboardCallback_)
keyboardCallback_(event, keyboard_callback_cookie_); keyboardCallback_(event, keyboard_callback_cookie_);
Superclass::OnKeyUp(); Superclass::OnKeyUp();
} }
...@@ -673,10 +673,10 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward() ...@@ -673,10 +673,10 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward()
// If a mouse callback registered, call it! // If a mouse callback registered, call it!
if (mouseCallback_) if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_); mouseCallback_(event, mouse_callback_cookie_);
if (Interactor->GetRepeatCount() && mouseCallback_) if (Interactor->GetRepeatCount() && mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_); mouseCallback_(event, mouse_callback_cookie_);
if (Interactor->GetAltKey()) if (Interactor->GetAltKey())
{ {
// zoom // zoom
......
...@@ -85,7 +85,7 @@ namespace cv ...@@ -85,7 +85,7 @@ namespace cv
/** \brief Change the default keyboard modified from ALT to a different special key.*/ /** \brief Change the default keyboard modified from ALT to a different special key.*/
inline void setKeyboardModifier(const KeyboardModifier &modifier) { modifier_ = modifier; } inline void setKeyboardModifier(const KeyboardModifier &modifier) { modifier_ = modifier; }
protected: protected:
/** \brief Set to true after initialization is complete. */ /** \brief Set to true after initialization is complete. */
bool init_; bool init_;
...@@ -95,7 +95,7 @@ namespace cv ...@@ -95,7 +95,7 @@ namespace cv
/** \brief Actor map stored internally. */ /** \brief Actor map stored internally. */
cv::Ptr<WidgetActorMap> widget_actor_map_; cv::Ptr<WidgetActorMap> widget_actor_map_;
/** \brief The current window width/height. */ /** \brief The current window width/height. */
Vec2i win_size_; Vec2i win_size_;
...@@ -107,7 +107,7 @@ namespace cv ...@@ -107,7 +107,7 @@ namespace cv
/** \brief A PNG writer for screenshot captures. */ /** \brief A PNG writer for screenshot captures. */
vtkSmartPointer<vtkPNGWriter> snapshot_writer_; vtkSmartPointer<vtkPNGWriter> snapshot_writer_;
/** \brief Internal window to image filter. Needed by \a snapshot_writer_. */ /** \brief Internal window to image filter. Needed by \a snapshot_writer_. */
vtkSmartPointer<vtkWindowToImageFilter> wif_; vtkSmartPointer<vtkWindowToImageFilter> wif_;
......
This diff is collapsed.
...@@ -120,10 +120,10 @@ struct cv::viz::Mesh3d::loadMeshImpl ...@@ -120,10 +120,10 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New(); vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(file.c_str()); reader->SetFileName(file.c_str());
reader->Update(); reader->Update();
vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput(); vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput();
CV_Assert("File does not exist or file format is not supported." && poly_data); CV_Assert("File does not exist or file format is not supported." && poly_data);
vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints(); vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints();
vtkIdType nr_points = mesh_points->GetNumberOfPoints(); vtkIdType nr_points = mesh_points->GetNumberOfPoints();
...@@ -141,7 +141,7 @@ struct cv::viz::Mesh3d::loadMeshImpl ...@@ -141,7 +141,7 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkUnsignedCharArray* poly_colors = 0; vtkUnsignedCharArray* poly_colors = 0;
if (poly_data->GetPointData()) if (poly_data->GetPointData())
poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars()); poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars());
if (poly_colors && (poly_colors->GetNumberOfComponents() == 3)) if (poly_colors && (poly_colors->GetNumberOfComponents() == 3))
{ {
mesh.colors.create(1, nr_points, CV_8UC3); mesh.colors.create(1, nr_points, CV_8UC3);
...@@ -164,9 +164,9 @@ struct cv::viz::Mesh3d::loadMeshImpl ...@@ -164,9 +164,9 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkIdType nr_cell_points; vtkIdType nr_cell_points;
vtkCellArray * mesh_polygons = poly_data->GetPolys(); vtkCellArray * mesh_polygons = poly_data->GetPolys();
mesh_polygons->InitTraversal(); mesh_polygons->InitTraversal();
mesh.polygons.create(1, mesh_polygons->GetSize(), CV_32SC1); mesh.polygons.create(1, mesh_polygons->GetSize(), CV_32SC1);
int* polygons = mesh.polygons.ptr<int>(); int* polygons = mesh.polygons.ptr<int>();
while (mesh_polygons->GetNextCell(nr_cell_points, cell_points)) while (mesh_polygons->GetNextCell(nr_cell_points, cell_points))
{ {
...@@ -213,30 +213,30 @@ cv::viz::Camera::Camera(const cv::Matx33f & K, const Size &window_size) ...@@ -213,30 +213,30 @@ cv::viz::Camera::Camera(const cv::Matx33f & K, const Size &window_size)
} }
cv::viz::Camera::Camera(const Matx44f &proj, const Size &window_size) cv::viz::Camera::Camera(const Matx44f &proj, const Size &window_size)
{ {
CV_Assert(window_size.width > 0 && window_size.height > 0); CV_Assert(window_size.width > 0 && window_size.height > 0);
double near = proj(2,3) / (proj(2,2) - 1.0); double near = proj(2,3) / (proj(2,2) - 1.0);
double far = near * (proj(2,2) - 1.0) / (proj(2,2) + 1.0); double far = near * (proj(2,2) - 1.0) / (proj(2,2) + 1.0);
double left = near * (proj(0,2)-1) / proj(0,0); double left = near * (proj(0,2)-1) / proj(0,0);
double right = 2.0 * near / proj(0,0) + left; double right = 2.0 * near / proj(0,0) + left;
double bottom = near * (proj(1,2)-1) / proj(1,1); double bottom = near * (proj(1,2)-1) / proj(1,1);
double top = 2.0 * near / proj(1,1) + bottom; double top = 2.0 * near / proj(1,1) + bottom;
double epsilon = 2.2204460492503131e-16; double epsilon = 2.2204460492503131e-16;
if (fabs(left-right) < epsilon) principal_point_[0] = static_cast<float>(window_size.width) * 0.5f; if (fabs(left-right) < epsilon) principal_point_[0] = static_cast<float>(window_size.width) * 0.5f;
else principal_point_[0] = (left * static_cast<float>(window_size.width)) / (left - right); else principal_point_[0] = (left * static_cast<float>(window_size.width)) / (left - right);
focal_[0] = -near * principal_point_[0] / left; focal_[0] = -near * principal_point_[0] / left;
if (fabs(top-bottom) < epsilon) principal_point_[1] = static_cast<float>(window_size.height) * 0.5f; if (fabs(top-bottom) < epsilon) principal_point_[1] = static_cast<float>(window_size.height) * 0.5f;
else principal_point_[1] = (top * static_cast<float>(window_size.height)) / (top - bottom); else principal_point_[1] = (top * static_cast<float>(window_size.height)) / (top - bottom);
focal_[1] = near * principal_point_[1] / top; focal_[1] = near * principal_point_[1] / top;
setClip(Vec2d(near, far)); setClip(Vec2d(near, far));
fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0])); fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0]));
fov_[1] = (atan2(principal_point_[1],focal_[1]) + atan2(window_size.height-principal_point_[1],focal_[1])); fov_[1] = (atan2(principal_point_[1],focal_[1]) + atan2(window_size.height-principal_point_[1],focal_[1]));
window_size_ = window_size; window_size_ = window_size;
} }
...@@ -244,33 +244,33 @@ void cv::viz::Camera::init(float f_x, float f_y, float c_x, float c_y, const Siz ...@@ -244,33 +244,33 @@ void cv::viz::Camera::init(float f_x, float f_y, float c_x, float c_y, const Siz
{ {
CV_Assert(window_size.width > 0 && window_size.height > 0); CV_Assert(window_size.width > 0 && window_size.height > 0);
setClip(Vec2d(0.01, 1000.01));// Default clipping setClip(Vec2d(0.01, 1000.01));// Default clipping
fov_[0] = (atan2(c_x,f_x) + atan2(window_size.width-c_x,f_x)); fov_[0] = (atan2(c_x,f_x) + atan2(window_size.width-c_x,f_x));
fov_[1] = (atan2(c_y,f_y) + atan2(window_size.height-c_y,f_y)); fov_[1] = (atan2(c_y,f_y) + atan2(window_size.height-c_y,f_y));
principal_point_[0] = c_x; principal_point_[0] = c_x;
principal_point_[1] = c_y; principal_point_[1] = c_y;
focal_[0] = f_x; focal_[0] = f_x;
focal_[1] = f_y; focal_[1] = f_y;
window_size_ = window_size; window_size_ = window_size;
} }
void cv::viz::Camera::setWindowSize(const Size &window_size) void cv::viz::Camera::setWindowSize(const Size &window_size)
{ {
CV_Assert(window_size.width > 0 && window_size.height > 0); CV_Assert(window_size.width > 0 && window_size.height > 0);
// Get the scale factor and update the principal points // Get the scale factor and update the principal points
float scalex = static_cast<float>(window_size.width) / static_cast<float>(window_size_.width); float scalex = static_cast<float>(window_size.width) / static_cast<float>(window_size_.width);
float scaley = static_cast<float>(window_size.height) / static_cast<float>(window_size_.height); float scaley = static_cast<float>(window_size.height) / static_cast<float>(window_size_.height);
principal_point_[0] *= scalex; principal_point_[0] *= scalex;
principal_point_[1] *= scaley; principal_point_[1] *= scaley;
focal_ *= scaley; focal_ *= scaley;
// Vertical field of view is fixed! Update horizontal field of view // Vertical field of view is fixed! Update horizontal field of view
fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0])); fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0]));
window_size_ = window_size; window_size_ = window_size;
} }
...@@ -280,12 +280,12 @@ void cv::viz::Camera::computeProjectionMatrix(Matx44f &proj) const ...@@ -280,12 +280,12 @@ void cv::viz::Camera::computeProjectionMatrix(Matx44f &proj) const
double left = -clip_[0] * principal_point_[0] / focal_[0]; double left = -clip_[0] * principal_point_[0] / focal_[0];
double right = clip_[0] * (window_size_.width - principal_point_[0]) / focal_[0]; double right = clip_[0] * (window_size_.width - principal_point_[0]) / focal_[0];
double bottom = -clip_[0] * (window_size_.height - principal_point_[1]) / focal_[1]; double bottom = -clip_[0] * (window_size_.height - principal_point_[1]) / focal_[1];
double temp1 = 2.0 * clip_[0]; double temp1 = 2.0 * clip_[0];
double temp2 = 1.0 / (right - left); double temp2 = 1.0 / (right - left);
double temp3 = 1.0 / (top - bottom); double temp3 = 1.0 / (top - bottom);
double temp4 = 1.0 / (clip_[0] - clip_[1]); double temp4 = 1.0 / (clip_[0] - clip_[1]);
proj = Matx44d::zeros(); proj = Matx44d::zeros();
proj(0,0) = temp1 * temp2; proj(0,0) = temp1 * temp2;
proj(1,1) = temp1 * temp3; proj(1,1) = temp1 * temp3;
...@@ -300,7 +300,7 @@ cv::viz::Camera cv::viz::Camera::KinectCamera(const Size &window_size) ...@@ -300,7 +300,7 @@ cv::viz::Camera cv::viz::Camera::KinectCamera(const Size &window_size)
{ {
// Without distortion, RGB Camera // Without distortion, RGB Camera
// Received from http://nicolas.burrus.name/index.php/Research/KinectCalibration // Received from http://nicolas.burrus.name/index.php/Research/KinectCalibration
Matx33f K = Matx33f::zeros(); Matx33f K = Matx33f::zeros();
K(0,0) = 5.2921508098293293e+02; K(0,0) = 5.2921508098293293e+02;
K(0,2) = 3.2894272028759258e+02; K(0,2) = 3.2894272028759258e+02;
K(1,1) = 5.2556393630057437e+02; K(1,1) = 5.2556393630057437e+02;
......
...@@ -72,7 +72,7 @@ cv::Affine3f cv::viz::makeCameraPose(const Vec3f& position, const Vec3f& focal_p ...@@ -72,7 +72,7 @@ cv::Affine3f cv::viz::makeCameraPose(const Vec3f& position, const Vec3f& focal_p
Vec3f n = normalize(focal_point - position); Vec3f n = normalize(focal_point - position);
Vec3f u = normalize(y_dir.cross(n)); Vec3f u = normalize(y_dir.cross(n));
Vec3f v = n.cross(u); Vec3f v = n.cross(u);
Matx44f pose_mat = Matx44f::zeros(); Matx44f pose_mat = Matx44f::zeros();
pose_mat(0,0) = u[0]; pose_mat(0,0) = u[0];
pose_mat(0,1) = u[1]; pose_mat(0,1) = u[1];
...@@ -147,9 +147,9 @@ struct cv::viz::VizAccessor::VizAccessorImpl ...@@ -147,9 +147,9 @@ struct cv::viz::VizAccessor::VizAccessorImpl
cv::viz::VizAccessor::VizAccessor() { impl_ = new cv::viz::VizAccessor::VizAccessorImpl;} cv::viz::VizAccessor::VizAccessor() { impl_ = new cv::viz::VizAccessor::VizAccessorImpl;}
cv::viz::VizAccessor::~VizAccessor() cv::viz::VizAccessor::~VizAccessor()
{ {
if(impl_) if(impl_)
{ {
delete impl_; delete impl_;
impl_ = 0; impl_ = 0;
...@@ -202,7 +202,7 @@ void cv::viz::VizAccessor::remove(const String &window_name) ...@@ -202,7 +202,7 @@ void cv::viz::VizAccessor::remove(const String &window_name)
// Add the prefix Viz // Add the prefix Viz
String name; String name;
generateWindowName(window_name, name); generateWindowName(window_name, name);
VizMap::iterator vm_itr = impl_->viz_map.find(name); VizMap::iterator vm_itr = impl_->viz_map.find(name);
bool exists = vm_itr != impl_->viz_map.end(); bool exists = vm_itr != impl_->viz_map.end();
if (!exists) return ; if (!exists) return ;
...@@ -214,7 +214,7 @@ void cv::viz::VizAccessor::generateWindowName(const String &window_name, String ...@@ -214,7 +214,7 @@ void cv::viz::VizAccessor::generateWindowName(const String &window_name, String
output = "Viz"; output = "Viz";
// Already is Viz // Already is Viz
if (window_name == output) return; if (window_name == output) return;
String prefixed = output + " - "; String prefixed = output + " - ";
if (window_name.substr(0, prefixed.length()) == prefixed) output = window_name; // Already has "Viz - " if (window_name.substr(0, prefixed.length()) == prefixed) output = window_name; // Already has "Viz - "
else if (window_name.substr(0, output.length()) == output) output = prefixed + window_name; // Doesn't have prefix else if (window_name.substr(0, output.length()) == output) output = prefixed + window_name; // Doesn't have prefix
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); } cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); }
cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_) cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_)
{ {
if (impl_) CV_XADD(&impl_->ref_counter, 1); if (impl_) CV_XADD(&impl_->ref_counter, 1);
} }
......
...@@ -125,7 +125,7 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name) ...@@ -125,7 +125,7 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name)
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
cv::viz::Viz3d::VizImpl::~VizImpl() cv::viz::Viz3d::VizImpl::~VizImpl()
{ {
if (interactor_) if (interactor_)
interactor_->DestroyTimer(timer_id_); interactor_->DestroyTimer(timer_id_);
if (renderer_) renderer_->Clear(); if (renderer_) renderer_->Clear();
} }
...@@ -368,11 +368,11 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color) ...@@ -368,11 +368,11 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color)
void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
{ {
vtkCamera& active_camera = *renderer_->GetActiveCamera(); vtkCamera& active_camera = *renderer_->GetActiveCamera();
// Set the intrinsic parameters of the camera // Set the intrinsic parameters of the camera
window_->SetSize(camera.getWindowSize().width, camera.getWindowSize().height); window_->SetSize(camera.getWindowSize().width, camera.getWindowSize().height);
double aspect_ratio = static_cast<double>(camera.getWindowSize().width)/static_cast<double>(camera.getWindowSize().height); double aspect_ratio = static_cast<double>(camera.getWindowSize().width)/static_cast<double>(camera.getWindowSize().height);
Matx44f proj_mat; Matx44f proj_mat;
camera.computeProjectionMatrix(proj_mat); camera.computeProjectionMatrix(proj_mat);
// Use the intrinsic parameters of the camera to simulate more realistically // Use the intrinsic parameters of the camera to simulate more realistically
...@@ -382,7 +382,7 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) ...@@ -382,7 +382,7 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
transform->SetMatrix(convertToVtkMatrix(proj_mat * old_proj_mat.inv())); transform->SetMatrix(convertToVtkMatrix(proj_mat * old_proj_mat.inv()));
active_camera.SetUserTransform(transform); active_camera.SetUserTransform(transform);
transform->Delete(); transform->Delete();
renderer_->ResetCameraClippingRange(); renderer_->ResetCameraClippingRange();
renderer_->Render(); renderer_->Render();
} }
...@@ -391,11 +391,11 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) ...@@ -391,11 +391,11 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
{ {
vtkCamera& active_camera = *renderer_->GetActiveCamera(); vtkCamera& active_camera = *renderer_->GetActiveCamera();
Size window_size(renderer_->GetRenderWindow()->GetSize()[0], Size window_size(renderer_->GetRenderWindow()->GetSize()[0],
renderer_->GetRenderWindow()->GetSize()[1]); renderer_->GetRenderWindow()->GetSize()[1]);
double aspect_ratio = static_cast<double>(window_size.width) / static_cast<double>(window_size.height); double aspect_ratio = static_cast<double>(window_size.width) / static_cast<double>(window_size.height);
Matx44f proj_matrix = convertToMatx(active_camera.GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f)); Matx44f proj_matrix = convertToMatx(active_camera.GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f));
Camera camera(proj_matrix, window_size); Camera camera(proj_matrix, window_size);
return camera; return camera;
...@@ -405,7 +405,7 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const ...@@ -405,7 +405,7 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose) void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
{ {
vtkCamera& camera = *renderer_->GetActiveCamera(); vtkCamera& camera = *renderer_->GetActiveCamera();
// Position = extrinsic translation // Position = extrinsic translation
cv::Vec3f pos_vec = pose.translation(); cv::Vec3f pos_vec = pose.translation();
...@@ -417,11 +417,11 @@ void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose) ...@@ -417,11 +417,11 @@ void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
// Compute the new focal point // Compute the new focal point
cv::Vec3f z_axis(0.f, 0.f, 1.f); cv::Vec3f z_axis(0.f, 0.f, 1.f);
cv::Vec3f focal_vec = pos_vec + rotation * z_axis; cv::Vec3f focal_vec = pos_vec + rotation * z_axis;
camera.SetPosition(pos_vec[0], pos_vec[1], pos_vec[2]); camera.SetPosition(pos_vec[0], pos_vec[1], pos_vec[2]);
camera.SetFocalPoint(focal_vec[0], focal_vec[1], focal_vec[2]); camera.SetFocalPoint(focal_vec[0], focal_vec[1], focal_vec[2]);
camera.SetViewUp(up_vec[0], up_vec[1], up_vec[2]); camera.SetViewUp(up_vec[0], up_vec[1], up_vec[2]);
renderer_->ResetCameraClippingRange(); renderer_->ResetCameraClippingRange();
renderer_->Render(); renderer_->Render();
} }
...@@ -465,10 +465,10 @@ void cv::viz::Viz3d::VizImpl::convertToWindowCoordinates(const Point3d &pt, Poin ...@@ -465,10 +465,10 @@ void cv::viz::Viz3d::VizImpl::convertToWindowCoordinates(const Point3d &pt, Poin
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction)
{ {
Vec4d world_pt; Vec4d world_pt;
vtkInteractorObserver::ComputeDisplayToWorld(renderer_, window_coord.x, window_coord.y, window_coord.z, world_pt.val); vtkInteractorObserver::ComputeDisplayToWorld(renderer_, window_coord.x, window_coord.y, window_coord.z, world_pt.val);
vtkCamera &active_camera = *renderer_->GetActiveCamera(); vtkCamera &active_camera = *renderer_->GetActiveCamera();
Vec3d cam_pos; Vec3d cam_pos;
active_camera.GetPosition(cam_pos.val); active_camera.GetPosition(cam_pos.val);
...@@ -525,19 +525,19 @@ void cv::viz::Viz3d::VizImpl::setRepresentation(int representation) ...@@ -525,19 +525,19 @@ void cv::viz::Viz3d::VizImpl::setRepresentation(int representation)
vtkActor * actor; vtkActor * actor;
switch (representation) switch (representation)
{ {
case REPRESENTATION_POINTS: case REPRESENTATION_POINTS:
{ {
while ((actor = actors->GetNextActor()) != NULL) while ((actor = actors->GetNextActor()) != NULL)
actor->GetProperty()->SetRepresentationToPoints(); actor->GetProperty()->SetRepresentationToPoints();
break; break;
} }
case REPRESENTATION_SURFACE: case REPRESENTATION_SURFACE:
{ {
while ((actor = actors->GetNextActor()) != NULL) while ((actor = actors->GetNextActor()) != NULL)
actor->GetProperty()->SetRepresentationToSurface(); actor->GetProperty()->SetRepresentationToSurface();
break; break;
} }
case REPRESENTATION_WIREFRAME: case REPRESENTATION_WIREFRAME:
{ {
while ((actor = actors->GetNextActor()) != NULL) while ((actor = actors->GetNextActor()) != NULL)
actor->GetProperty()->SetRepresentationToWireframe(); actor->GetProperty()->SetRepresentationToWireframe();
......
...@@ -58,20 +58,20 @@ public: ...@@ -58,20 +58,20 @@ public:
typedef cv::Ptr<VizImpl> Ptr; typedef cv::Ptr<VizImpl> Ptr;
typedef Viz3d::KeyboardCallback KeyboardCallback; typedef Viz3d::KeyboardCallback KeyboardCallback;
typedef Viz3d::MouseCallback MouseCallback; typedef Viz3d::MouseCallback MouseCallback;
int ref_counter; int ref_counter;
VizImpl(const String &name); VizImpl(const String &name);
virtual ~VizImpl(); virtual ~VizImpl();
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void removeWidget(const String &id); void removeWidget(const String &id);
Widget getWidget(const String &id) const; Widget getWidget(const String &id) const;
void removeAllWidgets(); void removeAllWidgets();
void setWidgetPose(const String &id, const Affine3f &pose); void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose); void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const; Affine3f getWidgetPose(const String &id) const;
void setDesiredUpdateRate(double rate); void setDesiredUpdateRate(double rate);
double getDesiredUpdateRate(); double getDesiredUpdateRate();
...@@ -86,7 +86,7 @@ public: ...@@ -86,7 +86,7 @@ public:
void close() void close()
{ {
stopped_ = true; stopped_ = true;
if (interactor_) if (interactor_)
{ {
interactor_->GetRenderWindow()->Finalize(); interactor_->GetRenderWindow()->Finalize();
interactor_->TerminateApp(); // This tends to close the window... interactor_->TerminateApp(); // This tends to close the window...
...@@ -94,14 +94,14 @@ public: ...@@ -94,14 +94,14 @@ public:
} }
void setRepresentation(int representation); void setRepresentation(int representation);
void setCamera(const Camera &camera); void setCamera(const Camera &camera);
Camera getCamera() const; Camera getCamera() const;
/** \brief Reset the camera to a given widget */ /** \brief Reset the camera to a given widget */
void resetCameraViewpoint(const String& id); void resetCameraViewpoint(const String& id);
void resetCamera(); void resetCamera();
void setViewerPose(const Affine3f &pose); void setViewerPose(const Affine3f &pose);
Affine3f getViewerPose(); Affine3f getViewerPose();
...@@ -182,7 +182,7 @@ private: ...@@ -182,7 +182,7 @@ private:
/** \brief The render window interactor style. */ /** \brief The render window interactor style. */
vtkSmartPointer<InteractorStyle> style_; vtkSmartPointer<InteractorStyle> style_;
/** \brief Internal list with actor pointers and name IDs for all widget actors */ /** \brief Internal list with actor pointers and name IDs for all widget actors */
cv::Ptr<WidgetActorMap> widget_actor_map_; cv::Ptr<WidgetActorMap> widget_actor_map_;
...@@ -245,7 +245,7 @@ namespace cv ...@@ -245,7 +245,7 @@ namespace cv
} }
return output; return output;
} }
static _Out* copyColor(const Mat& source, _Out* output, const Mat& nan_mask) static _Out* copyColor(const Mat& source, _Out* output, const Mat& nan_mask)
{ {
CV_Assert(DataDepth<_Tp>::value == source.depth() && source.size() == nan_mask.size()); CV_Assert(DataDepth<_Tp>::value == source.depth() && source.size() == nan_mask.size());
...@@ -282,7 +282,7 @@ namespace cv ...@@ -282,7 +282,7 @@ namespace cv
return table[nan_mask.depth() - 5](source, output, nan_mask); return table[nan_mask.depth() - 5](source, output, nan_mask);
} }
template<typename _Tp> template<typename _Tp>
static inline Vec<_Tp, 3>* copyColor(const Mat& source, Vec<_Tp, 3>* output, const Mat& nan_mask) static inline Vec<_Tp, 3>* copyColor(const Mat& source, Vec<_Tp, 3>* output, const Mat& nan_mask)
{ {
...@@ -328,7 +328,7 @@ namespace cv ...@@ -328,7 +328,7 @@ namespace cv
inline Vec3d vtkpoint(const Point3f& point) { return Vec3d(point.x, point.y, point.z); } inline Vec3d vtkpoint(const Point3f& point) { return Vec3d(point.x, point.y, point.z); }
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/cv::norm(v); } template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/cv::norm(v); }
struct ConvertToVtkImage struct ConvertToVtkImage
{ {
struct Impl struct Impl
...@@ -336,7 +336,7 @@ namespace cv ...@@ -336,7 +336,7 @@ namespace cv
static void copyImageMultiChannel(const Mat &image, vtkSmartPointer<vtkImageData> output) static void copyImageMultiChannel(const Mat &image, vtkSmartPointer<vtkImageData> output)
{ {
int i_chs = image.channels(); int i_chs = image.channels();
for (int i = 0; i < image.rows; ++i) for (int i = 0; i < image.rows; ++i)
{ {
const unsigned char * irows = image.ptr<unsigned char>(i); const unsigned char * irows = image.ptr<unsigned char>(i);
...@@ -349,7 +349,7 @@ namespace cv ...@@ -349,7 +349,7 @@ namespace cv
} }
output->Modified(); output->Modified();
} }
static void copyImageSingleChannel(const Mat &image, vtkSmartPointer<vtkImageData> output) static void copyImageSingleChannel(const Mat &image, vtkSmartPointer<vtkImageData> output)
{ {
for (int i = 0; i < image.rows; ++i) for (int i = 0; i < image.rows; ++i)
...@@ -364,7 +364,7 @@ namespace cv ...@@ -364,7 +364,7 @@ namespace cv
output->Modified(); output->Modified();
} }
}; };
static void convert(const Mat &image, vtkSmartPointer<vtkImageData> output) static void convert(const Mat &image, vtkSmartPointer<vtkImageData> output)
{ {
// Create the vtk image // Create the vtk image
...@@ -376,7 +376,7 @@ namespace cv ...@@ -376,7 +376,7 @@ namespace cv
#else #else
output->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels()); output->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels());
#endif #endif
int i_chs = image.channels(); int i_chs = image.channels();
if (i_chs > 1) if (i_chs > 1)
{ {
......
...@@ -55,14 +55,14 @@ class cv::viz::Widget::Impl ...@@ -55,14 +55,14 @@ class cv::viz::Widget::Impl
{ {
public: public:
vtkSmartPointer<vtkProp> prop; vtkSmartPointer<vtkProp> prop;
Impl() : prop(0) {} Impl() : prop(0) {}
}; };
cv::viz::Widget::Widget() : impl_( new Impl() ) { } cv::viz::Widget::Widget() : impl_( new Impl() ) { }
cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() ) cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() )
{ {
if (other.impl_ && other.impl_->prop) impl_->prop = other.impl_->prop; if (other.impl_ && other.impl_->prop) impl_->prop = other.impl_->prop;
} }
...@@ -73,8 +73,8 @@ cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other) ...@@ -73,8 +73,8 @@ cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other)
return *this; return *this;
} }
cv::viz::Widget::~Widget() cv::viz::Widget::~Widget()
{ {
if (impl_) if (impl_)
{ {
delete impl_; delete impl_;
...@@ -86,7 +86,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) ...@@ -86,7 +86,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
{ {
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New(); vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(file_name.c_str()); reader->SetFileName(file_name.c_str());
vtkSmartPointer<vtkDataSet> data = reader->GetOutput(); vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
CV_Assert("File does not exist or file format is not supported." && data); CV_Assert("File does not exist or file format is not supported." && data);
...@@ -120,7 +120,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) ...@@ -120,7 +120,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
actor->GetProperty()->BackfaceCullingOn(); actor->GetProperty()->BackfaceCullingOn();
actor->SetMapper(mapper); actor->SetMapper(mapper);
Widget widget; Widget widget;
widget.impl_->prop = actor; widget.impl_->prop = actor;
return widget; return widget;
...@@ -130,7 +130,7 @@ void cv::viz::Widget::setRenderingProperty(int property, double value) ...@@ -130,7 +130,7 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
{ {
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget type is not supported." && actor); CV_Assert("Widget type is not supported." && actor);
switch (property) switch (property)
{ {
case POINT_SIZE: case POINT_SIZE:
...@@ -218,8 +218,8 @@ void cv::viz::Widget::setRenderingProperty(int property, double value) ...@@ -218,8 +218,8 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
actor->Modified(); actor->Modified();
break; break;
} }
default: default:
CV_Assert("setPointCloudRenderingProperties: Unknown property"); CV_Assert("setPointCloudRenderingProperties: Unknown property");
} }
...@@ -229,7 +229,7 @@ double cv::viz::Widget::getRenderingProperty(int property) const ...@@ -229,7 +229,7 @@ double cv::viz::Widget::getRenderingProperty(int property) const
{ {
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget type is not supported." && actor); CV_Assert("Widget type is not supported." && actor);
double value = 0.0; double value = 0.0;
switch (property) switch (property)
{ {
...@@ -313,7 +313,7 @@ struct cv::viz::Widget3D::MatrixConverter ...@@ -313,7 +313,7 @@ struct cv::viz::Widget3D::MatrixConverter
m(i, k) = vtk_matrix->GetElement(i, k); m(i, k) = vtk_matrix->GetElement(i, k);
return m; return m;
} }
static vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix(const Matx44f& m) static vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix(const Matx44f& m)
{ {
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New(); vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
...@@ -328,7 +328,7 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose) ...@@ -328,7 +328,7 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose)
{ {
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor); CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix); vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
actor->SetUserMatrix(matrix); actor->SetUserMatrix(matrix);
actor->Modified(); actor->Modified();
...@@ -338,7 +338,7 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose) ...@@ -338,7 +338,7 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose)
{ {
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor); CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
if (!matrix) if (!matrix)
{ {
...@@ -358,7 +358,7 @@ cv::Affine3f cv::viz::Widget3D::getPose() const ...@@ -358,7 +358,7 @@ cv::Affine3f cv::viz::Widget3D::getPose() const
{ {
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor); CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
Matx44f matrix_cv = MatrixConverter::convertToMatx(matrix); Matx44f matrix_cv = MatrixConverter::convertToMatx(matrix);
return Affine3f(matrix_cv); return Affine3f(matrix_cv);
...@@ -369,7 +369,7 @@ void cv::viz::Widget3D::setColor(const Color &color) ...@@ -369,7 +369,7 @@ void cv::viz::Widget3D::setColor(const Color &color)
// Cast to actor instead of prop3d since prop3d doesn't provide getproperty // Cast to actor instead of prop3d since prop3d doesn't provide getproperty
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget type is not supported." && actor); CV_Assert("Widget type is not supported." && actor);
Color c = vtkcolor(color); Color c = vtkcolor(color);
actor->GetMapper()->ScalarVisibilityOff(); actor->GetMapper()->ScalarVisibilityOff();
actor->GetProperty()->SetColor(c.val); actor->GetProperty()->SetColor(c.val);
......
...@@ -110,23 +110,23 @@ TEST(Viz_viz3d, accuracy) ...@@ -110,23 +110,23 @@ TEST(Viz_viz3d, accuracy)
for (int i = 0, j = 0; i <= 360; ++i, j+=5) for (int i = 0, j = 0; i <= 360; ++i, j+=5)
{ {
cam_path.push_back(viz::makeCameraPose(Point3f(0.5*cos(double(i)*CV_PI/180.0), 0.5*sin(double(j)*CV_PI/180.0), 0.5*sin(double(i)*CV_PI/180.0)), cam_path.push_back(viz::makeCameraPose(Point3f(0.5*cos(double(i)*CV_PI/180.0), 0.5*sin(double(j)*CV_PI/180.0), 0.5*sin(double(i)*CV_PI/180.0)),
Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0))); Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0)));
} }
int path_counter = 0; int path_counter = 0;
int cam_path_size = cam_path.size(); int cam_path_size = cam_path.size();
// OTHER WIDGETS // OTHER WIDGETS
cv::Mat img = imread("opencv.png"); cv::Mat img = imread("opencv.png");
int downSample = 4; int downSample = 4;
int row_max = img.rows/downSample; int row_max = img.rows/downSample;
int col_max = img.cols/downSample; int col_max = img.cols/downSample;
cv::Mat *clouds = new cv::Mat[img.cols/downSample]; cv::Mat *clouds = new cv::Mat[img.cols/downSample];
cv::Mat *colors = new cv::Mat[img.cols/downSample]; cv::Mat *colors = new cv::Mat[img.cols/downSample];
for (int col = 0; col < col_max; ++col) for (int col = 0; col < col_max; ++col)
{ {
clouds[col] = Mat::zeros(img.rows/downSample, 1, CV_32FC3); clouds[col] = Mat::zeros(img.rows/downSample, 1, CV_32FC3);
...@@ -137,7 +137,7 @@ TEST(Viz_viz3d, accuracy) ...@@ -137,7 +137,7 @@ TEST(Viz_viz3d, accuracy)
colors[col].at<Vec3b>(row) = img.at<Vec3b>(row*downSample,col*downSample); colors[col].at<Vec3b>(row) = img.at<Vec3b>(row*downSample,col*downSample);
} }
} }
for (int col = 0; col < col_max; ++col) for (int col = 0; col < col_max; ++col)
{ {
std::stringstream strstrm; std::stringstream strstrm;
...@@ -146,16 +146,16 @@ TEST(Viz_viz3d, accuracy) ...@@ -146,16 +146,16 @@ TEST(Viz_viz3d, accuracy)
viz.getWidget(strstrm.str()).setRenderingProperty(viz::POINT_SIZE, 3.0); viz.getWidget(strstrm.str()).setRenderingProperty(viz::POINT_SIZE, 3.0);
viz.getWidget(strstrm.str()).setRenderingProperty(viz::OPACITY, 0.45); viz.getWidget(strstrm.str()).setRenderingProperty(viz::OPACITY, 0.45);
} }
viz.showWidget("trajectory", viz::WTrajectory(cam_path, viz::WTrajectory::DISPLAY_PATH, viz::Color::yellow())); viz.showWidget("trajectory", viz::WTrajectory(cam_path, viz::WTrajectory::DISPLAY_PATH, viz::Color::yellow()));
viz.showWidget("cam_text", viz::WText("Global View", Point2i(5,5), 28)); viz.showWidget("cam_text", viz::WText("Global View", Point2i(5,5), 28));
viz.registerKeyboardCallback(keyboard_callback, (void *) &viz); viz.registerKeyboardCallback(keyboard_callback, (void *) &viz);
int angle = 0; int angle = 0;
while(!viz.wasStopped()) while(!viz.wasStopped())
{ {
if (path_counter == cam_path_size) if (path_counter == cam_path_size)
{ {
path_counter = 0; path_counter = 0;
} }
...@@ -164,12 +164,12 @@ TEST(Viz_viz3d, accuracy) ...@@ -164,12 +164,12 @@ TEST(Viz_viz3d, accuracy)
{ {
viz.setViewerPose(cam_path[path_counter]); viz.setViewerPose(cam_path[path_counter]);
} }
if (angle == 360) angle = 0; if (angle == 360) angle = 0;
cam_1.cast<viz::WCameraPosition>().setPose(cam_path[path_counter]); cam_1.cast<viz::WCameraPosition>().setPose(cam_path[path_counter]);
cam_coordinates.cast<viz::WCameraPosition>().setPose(cam_path[path_counter++]); cam_coordinates.cast<viz::WCameraPosition>().setPose(cam_path[path_counter++]);
for (int i = 0; i < col_max; ++i) for (int i = 0; i < col_max; ++i)
{ {
std::stringstream strstrm; std::stringstream strstrm;
......
...@@ -82,7 +82,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) ...@@ -82,7 +82,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
if(NOT HAVE_opencv_gpuarithm OR NOT HAVE_opencv_gpufilters) if(NOT HAVE_opencv_gpuarithm OR NOT HAVE_opencv_gpufilters)
ocv_list_filterout(cpp_samples "/gpu/") ocv_list_filterout(cpp_samples "/gpu/")
endif() endif()
ocv_list_filterout(cpp_samples "viz") ocv_list_filterout(cpp_samples "viz")
foreach(sample_filename ${cpp_samples}) foreach(sample_filename ${cpp_samples})
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
#include <opencv2/viz.hpp> #include <opencv2/viz.hpp>
#include <opencv2/viz/widget_accessor.hpp> #include <opencv2/viz/widget_accessor.hpp>
#include <iostream> #include <iostream>
#include <vtkPoints.h> #include <vtkPoints.h>
...@@ -42,7 +42,7 @@ void help() ...@@ -42,7 +42,7 @@ void help()
class WTriangle : public viz::Widget3D class WTriangle : public viz::Widget3D
{ {
public: public:
WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white()); WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
}; };
/** /**
...@@ -56,22 +56,22 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, ...@@ -56,22 +56,22 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3,
points->InsertNextPoint(pt1.x, pt1.y, pt1.z); points->InsertNextPoint(pt1.x, pt1.y, pt1.z);
points->InsertNextPoint(pt2.x, pt2.y, pt2.z); points->InsertNextPoint(pt2.x, pt2.y, pt2.z);
points->InsertNextPoint(pt3.x, pt3.y, pt3.z); points->InsertNextPoint(pt3.x, pt3.y, pt3.z);
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New(); vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId(0,0); triangle->GetPointIds()->SetId(0,0);
triangle->GetPointIds()->SetId(1,1); triangle->GetPointIds()->SetId(1,1);
triangle->GetPointIds()->SetId(2,2); triangle->GetPointIds()->SetId(2,2);
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(triangle); cells->InsertNextCell(triangle);
// Create a polydata object // Create a polydata object
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New(); vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
// Add the geometry and topology to the polydata // Add the geometry and topology to the polydata
polyData->SetPoints(points); polyData->SetPoints(points);
polyData->SetPolys(cells); polyData->SetPolys(cells);
// Create mapper and actor // Create mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5 #if VTK_MAJOR_VERSION <= 5
...@@ -79,13 +79,13 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, ...@@ -79,13 +79,13 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3,
#else #else
mapper->SetInputData(polyData); mapper->SetInputData(polyData);
#endif #endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
// Store this actor in the widget in order that visualizer can access it // Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor); viz::WidgetAccessor::setProp(*this, actor);
// Set the color of the widget. This has to be called after WidgetAccessor. // Set the color of the widget. This has to be called after WidgetAccessor.
setColor(color); setColor(color);
} }
...@@ -96,18 +96,18 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, ...@@ -96,18 +96,18 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3,
int main() int main()
{ {
help(); help();
/// Create a window /// Create a window
viz::Viz3d myWindow("Creating Widgets"); viz::Viz3d myWindow("Creating Widgets");
/// Create a triangle widget /// Create a triangle widget
WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red()); WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red());
/// Show widget in the visualizer window /// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw); myWindow.showWidget("TRIANGLE", tw);
/// Start event loop /// Start event loop
myWindow.spin(); myWindow.spin();
return 0; return 0;
} }
...@@ -33,33 +33,33 @@ int main() ...@@ -33,33 +33,33 @@ int main()
help(); help();
/// Create a window /// Create a window
viz::Viz3d myWindow("Viz Demo"); viz::Viz3d myWindow("Viz Demo");
/// Start event loop /// Start event loop
myWindow.spin(); myWindow.spin();
/// Event loop is over when pressed q, Q, e, E /// Event loop is over when pressed q, Q, e, E
cout << "First event loop is over" << endl; cout << "First event loop is over" << endl;
/// Access window via its name /// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo"); viz::Viz3d sameWindow = viz::get("Viz Demo");
/// Start event loop /// Start event loop
sameWindow.spin(); sameWindow.spin();
/// Event loop is over when pressed q, Q, e, E /// Event loop is over when pressed q, Q, e, E
cout << "Second event loop is over" << endl; cout << "Second event loop is over" << endl;
/// Event loop is over when pressed q, Q, e, E /// Event loop is over when pressed q, Q, e, E
/// Start event loop once for 1 millisecond /// Start event loop once for 1 millisecond
sameWindow.spinOnce(1, true); sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped()) while(!sameWindow.wasStopped())
{ {
/// Interact with window /// Interact with window
/// Event loop for 1 millisecond /// Event loop for 1 millisecond
sameWindow.spinOnce(1, true); sameWindow.spinOnce(1, true);
} }
/// Once more event loop is stopped /// Once more event loop is stopped
cout << "Last event loop is over" << endl; cout << "Last event loop is over" << endl;
return 0; return 0;
......
...@@ -44,7 +44,7 @@ Mat cvcloud_load() ...@@ -44,7 +44,7 @@ Mat cvcloud_load()
float dummy1, dummy2; float dummy1, dummy2;
for(size_t i = 0; i < 1889; ++i) for(size_t i = 0; i < 1889; ++i)
ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2; ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2;
cloud *= 5.0f; cloud *= 5.0f;
return cloud; return cloud;
} }
...@@ -55,40 +55,40 @@ Mat cvcloud_load() ...@@ -55,40 +55,40 @@ Mat cvcloud_load()
int main(int argn, char **argv) int main(int argn, char **argv)
{ {
help(); help();
if (argn < 2) if (argn < 2)
{ {
cout << "Missing arguments." << endl; cout << "Missing arguments." << endl;
return 1; return 1;
} }
bool camera_pov = (argv[1][0] == 'C'); bool camera_pov = (argv[1][0] == 'C');
/// Create a window /// Create a window
viz::Viz3d myWindow("Coordinate Frame"); viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes /// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// Let's assume camera has the following properties /// Let's assume camera has the following properties
Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f);
/// We can get the pose of the cam using makeCameraPose /// We can get the pose of the cam using makeCameraPose
Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
/// We can get the transformation matrix from camera coordinate system to global using /// We can get the transformation matrix from camera coordinate system to global using
/// - makeTransformToGlobal. We need the axes of the camera /// - makeTransformToGlobal. We need the axes of the camera
Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos);
/// Create a cloud widget. /// Create a cloud widget.
Mat bunny_cloud = cvcloud_load(); Mat bunny_cloud = cvcloud_load();
viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); viz::WCloud cloud_widget(bunny_cloud, viz::Color::green());
/// Pose of the widget in camera frame /// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f));
/// Pose of the widget in global frame /// Pose of the widget in global frame
Affine3f cloud_pose_global = transform * cloud_pose; Affine3f cloud_pose_global = transform * cloud_pose;
/// Visualize camera frame /// Visualize camera frame
if (!camera_pov) if (!camera_pov)
{ {
...@@ -97,16 +97,16 @@ int main(int argn, char **argv) ...@@ -97,16 +97,16 @@ int main(int argn, char **argv)
myWindow.showWidget("CPW", cpw, cam_pose); myWindow.showWidget("CPW", cpw, cam_pose);
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
} }
/// Visualize widget /// Visualize widget
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
/// Set the viewer pose to that of camera /// Set the viewer pose to that of camera
if (camera_pov) if (camera_pov)
myWindow.setViewerPose(cam_pose); myWindow.setViewerPose(cam_pose);
/// Start event loop. /// Start event loop.
myWindow.spin(); myWindow.spin();
return 0; return 0;
} }
...@@ -32,23 +32,23 @@ void help() ...@@ -32,23 +32,23 @@ void help()
int main() int main()
{ {
help(); help();
/// Create a window /// Create a window
viz::Viz3d myWindow("Coordinate Frame"); viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes /// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// Add line to represent (1,1,1) axis /// Add line to represent (1,1,1) axis
viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f)); viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis); myWindow.showWidget("Line Widget", axis);
/// Construct a cube widget /// Construct a cube widget
viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue()); viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Cube Widget", cube_widget); myWindow.showWidget("Cube Widget", cube_widget);
/// Rodrigues vector /// Rodrigues vector
Mat rot_vec = Mat::zeros(1,3,CV_32F); Mat rot_vec = Mat::zeros(1,3,CV_32F);
float translation_phase = 0.0, translation = 0.0; float translation_phase = 0.0, translation = 0.0;
...@@ -59,21 +59,21 @@ int main() ...@@ -59,21 +59,21 @@ int main()
rot_vec.at<float>(0,0) += CV_PI * 0.01f; rot_vec.at<float>(0,0) += CV_PI * 0.01f;
rot_vec.at<float>(0,1) += CV_PI * 0.01f; rot_vec.at<float>(0,1) += CV_PI * 0.01f;
rot_vec.at<float>(0,2) += CV_PI * 0.01f; rot_vec.at<float>(0,2) += CV_PI * 0.01f;
/// Shift on (1,1,1) /// Shift on (1,1,1)
translation_phase += CV_PI * 0.01f; translation_phase += CV_PI * 0.01f;
translation = sin(translation_phase); translation = sin(translation_phase);
Mat rot_mat; Mat rot_mat;
Rodrigues(rot_vec, rot_mat); Rodrigues(rot_vec, rot_mat);
/// Construct pose /// Construct pose
Affine3f pose(rot_mat, Vec3f(translation, translation, translation)); Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
myWindow.setWidgetPose("Cube Widget", pose); myWindow.setWidgetPose("Cube Widget", pose);
myWindow.spinOnce(1, true); myWindow.spinOnce(1, true);
} }
return 0; return 0;
} }
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