removed trailing spaces

pull/1453/head
Ozan Tonkal 11 years ago
parent 824c28a588
commit 8de46e1f81
  1. 44
      doc/tutorials/viz/creating_widgets/creating_widgets.rst
  2. 30
      doc/tutorials/viz/launching_viz/launching_viz.rst
  3. 56
      doc/tutorials/viz/transformations/transformations.rst
  4. 54
      doc/tutorials/viz/widget_pose/widget_pose.rst
  5. 6
      modules/viz/CMakeLists.txt
  6. 2
      modules/viz/doc/viz.rst
  7. 122
      modules/viz/doc/viz3d.rst
  8. 202
      modules/viz/doc/widget.rst
  9. 18
      modules/viz/include/opencv2/viz.hpp
  10. 20
      modules/viz/include/opencv2/viz/types.hpp
  11. 16
      modules/viz/include/opencv2/viz/viz3d.hpp
  12. 40
      modules/viz/include/opencv2/viz/widgets.hpp
  13. 68
      modules/viz/src/cloud_widgets.cpp
  14. 14
      modules/viz/src/interactor_style.cpp
  15. 6
      modules/viz/src/interactor_style.h
  16. 398
      modules/viz/src/shape_widgets.cpp
  17. 50
      modules/viz/src/types.cpp
  18. 12
      modules/viz/src/viz.cpp
  19. 2
      modules/viz/src/viz3d.cpp
  20. 28
      modules/viz/src/viz3d_impl.cpp
  21. 30
      modules/viz/src/viz3d_impl.hpp
  22. 30
      modules/viz/src/widget.cpp
  23. 24
      modules/viz/test/test_viz3d.cpp
  24. 2
      samples/cpp/CMakeLists.txt
  25. 11480
      samples/cpp/tutorial_code/viz/bunny.ply
  26. 30
      samples/cpp/tutorial_code/viz/creating_widgets.cpp
  27. 16
      samples/cpp/tutorial_code/viz/launching_viz.cpp
  28. 30
      samples/cpp/tutorial_code/viz/transformations.cpp
  29. 26
      samples/cpp/tutorial_code/viz/widget_pose.cpp

@ -21,7 +21,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
.. code-block:: cpp
#include <opencv2/viz.hpp>
#include <opencv2/viz/widget_accessor.hpp>
#include <opencv2/viz/widget_accessor.hpp>
#include <iostream>
#include <vtkPoints.h>
@ -43,7 +43,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
class WTriangle : public viz::Widget3D
{
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
points->InsertNextPoint(pt1.x, pt1.y, pt1.z);
points->InsertNextPoint(pt2.x, pt2.y, pt2.z);
points->InsertNextPoint(pt3.x, pt3.y, pt3.z);
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId(0,0);
triangle->GetPointIds()->SetId(1,1);
triangle->GetPointIds()->SetId(2,2);
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(triangle);
// Create a polydata object
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
// Add the geometry and topology to the polydata
polyData->SetPoints(points);
polyData->SetPolys(cells);
// Create mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
@ -79,13 +79,13 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
#else
mapper->SetInputData(polyData);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor);
// Set the color of the widget. This has to be called after WidgetAccessor.
setColor(color);
}
@ -94,22 +94,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
* @function main
*/
int main()
{
{
/// Create a window
viz::Viz3d myWindow("Creating Widgets");
/// 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());
/// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw);
/// Start event loop
myWindow.spin();
return 0;
}
Explanation
===========
@ -122,33 +122,33 @@ Here is the general structure of the program:
class WTriangle : public viz::Widget3D
{
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.
.. code-block:: cpp
// Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor);
* Set color of the widget.
.. code-block:: cpp
// Set the color of the widget. This has to be called after WidgetAccessor.
setColor(color);
* Construct a triangle widget and display it in the window.
.. code-block:: cpp
/// 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());
/// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw);
Results
=======

@ -27,7 +27,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
using namespace cv;
using namespace std;
/**
* @function main
*/
@ -35,38 +35,38 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
{
/// Create a window
viz::Viz3d myWindow("Viz Demo");
/// Start event loop
myWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "First event loop is over" << endl;
/// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo");
/// Start event loop
sameWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "Second event loop is over" << endl;
/// Event loop is over when pressed q, Q, e, E
/// Start event loop once for 1 millisecond
sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped())
{
/// Interact with window
/// Event loop for 1 millisecond
sameWindow.spinOnce(1, true);
}
/// Once more event loop is stopped
cout << "Last event loop is over" << endl;
return 0;
}
Explanation
===========
@ -78,21 +78,21 @@ Here is the general structure of the program:
/// Create a window
viz::Viz3d myWindow("Viz Demo");
* Start event loop. This event loop will run until user terminates it by pressing **e**, **E**, **q**, **Q**.
.. code-block:: cpp
/// Start event loop
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.
.. code-block:: cpp
/// Access window via its name
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.
.. code-block:: cpp
@ -103,11 +103,11 @@ Here is the general structure of the program:
while(!sameWindow.wasStopped())
{
/// Interact with window
/// Event loop for 1 millisecond
sameWindow.spinOnce(1, true);
}
Results
=======

@ -45,7 +45,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
float dummy1, dummy2;
for(size_t i = 0; i < 1889; ++i)
ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2;
cloud *= 5.0f;
return cloud;
}
@ -54,40 +54,40 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
* @function main
*/
int main(int argn, char **argv)
{
{
if (argn < 2)
{
cout << "Usage: " << endl << "./transformations [ G | C ]" << endl;
return 1;
}
bool camera_pov = (argv[1][0] == 'C');
/// Create a window
viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// 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);
/// We can get the pose of the cam using makeCameraPose
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
/// - 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);
/// Create a cloud widget.
Mat bunny_cloud = cvcloud_load();
viz::WCloud cloud_widget(bunny_cloud, viz::Color::green());
/// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f));
/// Pose of the widget in global frame
Affine3f cloud_pose_global = transform * cloud_pose;
/// Visualize camera frame
if (!camera_pov)
{
@ -96,21 +96,21 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
myWindow.showWidget("CPW", cpw, cam_pose);
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
}
/// Visualize widget
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
/// Set the viewer pose to that of camera
if (camera_pov)
myWindow.setViewerPose(cam_pose);
/// Start event loop.
myWindow.spin();
return 0;
}
Explanation
===========
@ -122,17 +122,17 @@ Here is the general structure of the program:
/// Create a window
viz::Viz3d myWindow("Transformations");
* Get camera pose from camera position, camera focal point and y direction.
.. code-block:: cpp
/// 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);
/// We can get the pose of the cam using makeCameraPose
Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
* Obtain transform matrix knowing the axes of camera coordinate system.
.. code-block:: cpp
@ -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
/// - 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);
* Create a cloud widget from bunny.ply file
.. code-block:: cpp
@ -148,16 +148,16 @@ Here is the general structure of the program:
/// Create a cloud widget.
Mat bunny_cloud = cvcloud_load();
viz::WCloud cloud_widget(bunny_cloud, viz::Color::green());
* Given the pose in camera coordinate system, estimate the global pose.
.. code-block:: cpp
/// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f));
/// Pose of the widget in global frame
Affine3f cloud_pose_global = transform * cloud_pose;
* If the view point is set to be global, visualize camera coordinate frame and viewing frustum.
.. code-block:: cpp
@ -170,22 +170,22 @@ Here is the general structure of the program:
myWindow.showWidget("CPW", cpw, cam_pose);
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
}
* Visualize the cloud widget with the estimated global pose
.. code-block:: cpp
/// Visualize widget
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
* If the view point is set to be camera's, set viewer pose to **cam_pose**.
.. code-block:: cpp
/// Set the viewer pose to that of camera
if (camera_pov)
myWindow.setViewerPose(cam_pose);
Results
=======

@ -35,22 +35,22 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
{
/// Create a window
viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// 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));
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis);
/// 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());
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
/// Display widget (update if already displayed)
myWindow.showWidget("Cube Widget", cube_widget);
myWindow.showWidget("Cube Widget", cube_widget);
/// Rodrigues vector
Mat rot_vec = Mat::zeros(1,3,CV_32F);
float translation_phase = 0.0, translation = 0.0;
@ -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,1) += CV_PI * 0.01f;
rot_vec.at<float>(0,2) += CV_PI * 0.01f;
/// Shift on (1,1,1)
translation_phase += CV_PI * 0.01f;
translation = sin(translation_phase);
Mat rot_mat;
Rodrigues(rot_vec, rot_mat);
Rodrigues(rot_vec, rot_mat);
/// Construct pose
Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
myWindow.setWidgetPose("Cube Widget", pose);
myWindow.spinOnce(1, true);
}
return 0;
}
Explanation
===========
@ -91,14 +91,14 @@ Here is the general structure of the program:
/// Create a window
viz::Viz3d myWindow("Coordinate Frame");
* Show coordinate axes in the window using CoordinateSystemWidget.
.. code-block:: cpp
/// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
* Display a line representing the axis (1,1,1).
.. code-block:: cpp
@ -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));
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis);
* Construct a cube.
.. code-block:: cpp
@ -115,8 +115,8 @@ Here is the general structure of the program:
/// 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());
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
.. code-block:: cpp
@ -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,1) += CV_PI * 0.01f;
rot_vec.at<float>(0,2) += CV_PI * 0.01f;
...
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
/// Construct pose
Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
myWindow.setWidgetPose("Cube Widget", pose);
* Animate the rotation using wasStopped and spinOnce
.. code-block:: cpp
@ -146,10 +146,10 @@ Here is the general structure of the program:
while(!myWindow.wasStopped())
{
...
myWindow.spinOnce(1, true);
}
Results
=======

@ -3,7 +3,7 @@ macro(find_qvtk)
find_path (QVTK_INCLUDE_DIR QVTKWidget.h HINT ${VTK_INCLUDE_DIRS})
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)
list(APPEND VTK_LIBRARY_DIRS ${QVTK_LIBRARY_DIR})
list(APPEND VTK_INCLUDE_DIRS ${QVTK_INCLUDE_DIR})
@ -22,7 +22,7 @@ macro(find_vtk)
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, lib: ${VTK_LIBRARY_DIRS})")
link_directories(${VTK_LIBRARY_DIRS})
include_directories(SYSTEM ${VTK_INCLUDE_DIRS})
set(HAVE_VTK ON)
set(HAVE_VTK ON)
else ()
set(HAVE_VTK OFF)
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)
include (${VTK_USE_FILE})
add_definitions(-DHAVE_VTK)
endif()
set(the_description "Viz")
set(BUILD_opencv_viz_INIT OFF)
include_directories(src)

@ -4,6 +4,6 @@ viz. 3D Visualizer
.. toctree::
:maxdepth: 2
viz3d.rst
widget.rst

@ -4,7 +4,7 @@ Viz
.. highlight:: cpp
This section describes 3D visualization window as well as classes and methods
that are used to interact with it.
that are used to interact with it.
3D visualization window (see :ocv:class:`Viz3d`) is used to display widgets (see :ocv:class:`Widget`), and it provides
several methods to interact with scene and widgets.
@ -21,17 +21,17 @@ Takes coordinate frame data and builds transform to global coordinate frame.
:param origin: Origin of the coordinate frame in global coordinate frame.
This function returns affine transform that describes transformation between global coordinate frame and a given coordinate frame.
viz::makeCameraPose
-------------------
Constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation).
.. ocv:function:: Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir)
:param position: Position of the camera in global coordinate frame.
:param focal_point: Focal point of the camera in global coordinate frame.
:param y_dir: Up vector of the camera in global coordinate frame.
This function returns pose of the camera in global coordinate frame.
viz::get
@ -41,15 +41,15 @@ Retrieves a window by its name.
.. ocv:function:: Viz3d get(const String &window_name)
:param window_name: Name of the window that is to be retrieved.
This function returns a :ocv:class:`Viz3d` object with the given name.
This function returns a :ocv:class:`Viz3d` object with the given name.
.. note:: If the window with that name already exists, that window is returned. Otherwise, new window is created with the given name, and it is returned.
.. note:: Window names are automatically prefixed by "Viz - " if it is not done by the user.
.. code-block:: cpp
/// window and window_2 are the same windows.
viz::Viz3d window = viz::get("myWindow");
viz::Viz3d window_2 = viz::get("Viz - myWindow");
@ -75,7 +75,7 @@ Checks **point** for nan
.. ocv:function:: bool isNan(const Point3_<_Tp>& p)
:param p: return true if **any** of the elements of the point is *nan*.
viz::VizAccessor
----------------
.. ocv:class:: VizAccessor
@ -87,16 +87,16 @@ A singleton class that provides access by name infrastructure for 3D visualizati
public:
static VizAccessor & getInstance();
static void release();
Viz3d get(const String &window_name);
//! window names automatically have Viz - prefix even though not provided by the users
static void generateWindowName(const String &window_name, String &output);
private:
/* hidden */
};
viz::VizAccessor::getInstance
-----------------------------
Returns the single instance of VizAccessor.
@ -116,15 +116,15 @@ Retrieves a window by its name.
.. ocv:function:: Viz3d get(const String &window_name)
:param window_name: Name of the window that is to be retrieved.
This function returns a :ocv:class:`Viz3d` object with the given name.
This function returns a :ocv:class:`Viz3d` object with the given name.
.. note:: If the window with that name already exists, that window is returned. Otherwise, new window is created with the given name, and it is returned.
.. note:: Window names are automatically prefixed by "Viz - " if it is not done by the user.
.. code-block:: cpp
/// window and window_2 are the same windows.
viz::Viz3d window = viz::get("myWindow");
viz::Viz3d window_2 = viz::get("Viz - myWindow");
@ -134,7 +134,7 @@ viz::VizAccessor::generateWindowName
Generates a window name by prefixing "Viz - " if it has not already been prefixed.
.. ocv:function:: static void generateWindowName(const String &window_name, String &output)
:param window_name: Window name
:param output: Prefixed window name
@ -164,18 +164,18 @@ The Viz3d class represents a 3D visualizer window. This class is implicitly shar
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
void setCamera(const Camera &camera);
Camera getCamera() const;
Affine3f getViewerPose();
void setViewerPose(const Affine3f &pose);
void resetCameraViewpoint (const String &id);
void resetCamera();
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
Size getWindowSize() const;
void setWindowSize(const Size &window_size);
String getWindowName() const;
@ -190,13 +190,13 @@ The Viz3d class represents a 3D visualizer window. This class is implicitly shar
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
void setRenderingProperty(const String &id, int property, double value);
double getRenderingProperty(const String &id, int property);
void setDesiredUpdateRate(double rate);
double getDesiredUpdateRate();
void setRepresentation(int representation);
private:
/* hidden */
@ -219,7 +219,7 @@ Shows a widget in the window.
:param id: A unique id for the widget.
:param widget: The widget to be displayed in the window.
:param pose: Pose of the widget.
viz::Viz3d::removeWidget
------------------------
Removes a widget from the window.
@ -227,17 +227,17 @@ Removes a widget from the window.
.. ocv:function:: void removeWidget(const String &id)
:param id: The id of the widget that will be removed.
viz::Viz3d::getWidget
---------------------
Retrieves a widget from the window. A widget is implicitly shared;
that is, if the returned widget is modified, the changes will be
that is, if the returned widget is modified, the changes will be
immediately visible in the window.
.. ocv:function:: Widget getWidget(const String &id) const
:param id: The id of the widget that will be returned.
viz::Viz3d::removeAllWidgets
----------------------------
Removes all widgets from the window.
@ -305,7 +305,7 @@ Resets camera viewpoint to a 3D widget in the scene.
.. ocv:function:: void resetCameraViewpoint (const String &id)
:param pose: Id of a 3D widget.
viz::Viz3d::resetCamera
-----------------------
Resets camera.
@ -320,7 +320,7 @@ Transforms a point in world coordinate system to window coordinate system.
:param pt: Point in world coordinate system.
:param window_coord: Output point in window coordinate system.
viz::Viz3d::converTo3DRay
-------------------------
Transforms a point in window coordinate system to a 3D ray in world coordinate system.
@ -330,7 +330,7 @@ Transforms a point in window coordinate system to a 3D ray in world coordinate s
:param window_coord: Point in window coordinate system.
:param origin: Output origin of the ray.
:param direction: Output direction of the ray.
viz::Viz3d::getWindowSize
-------------------------
Returns the current size of the window.
@ -344,7 +344,7 @@ Sets the size of the window.
.. ocv:function:: void setWindowSize(const Size &window_size)
:param window_size: New size of the window.
viz::Viz3d::getWindowName
-------------------------
Returns the name of the window which has been set in the constructor.
@ -358,7 +358,7 @@ Saves screenshot of the current scene.
.. ocv:function:: void saveScreenshot(const String &file)
:param file: Name of the file.
viz::Viz3d::setWindowPosition
-----------------------------
Sets the position of the window in the screen.
@ -367,7 +367,7 @@ Sets the position of the window in the screen.
:param x: x coordinate of the window
:param y: y coordinate of the window
viz::Viz3d::setFullScreen
-------------------------
Sets or unsets full-screen rendering mode.
@ -375,7 +375,7 @@ Sets or unsets full-screen rendering mode.
.. ocv:function:: void setFullScreen(bool mode)
:param mode: If true, window will use full-screen mode.
viz::Viz3d::setBackgroundColor
------------------------------
Sets background color.
@ -411,7 +411,7 @@ Sets keyboard handler.
:param callback: Keyboard callback ``(void (*KeyboardCallbackFunction(const KeyboardEvent&, void*))``.
:param cookie: The optional parameter passed to the callback.
viz::Viz3d::registerMouseCallback
---------------------------------
Sets mouse handler.
@ -430,9 +430,9 @@ Sets rendering property of a widget.
:param id: Id of the widget.
:param property: Property that will be modified.
:param value: The new value of the property.
**Rendering property** can be one of the following:
* **POINT_SIZE**
* **OPACITY**
* **LINE_WIDTH**
@ -441,14 +441,14 @@ Sets rendering property of a widget.
* **REPRESENTATION_POINTS**
* **REPRESENTATION_WIREFRAME**
* **REPRESENTATION_SURFACE**
* **IMMEDIATE_RENDERING**:
* **IMMEDIATE_RENDERING**:
* Turn on immediate rendering by setting the value to ``1``.
* Turn off immediate rendering by setting the value to ``0``.
* **SHADING**: Expected values are
* **SHADING_FLAT**
* **SHADING_GOURAUD**
* **SHADING_PHONG**
viz::Viz3d::getRenderingProperty
--------------------------------
Returns rendering property of a widget.
@ -457,9 +457,9 @@ Returns rendering property of a widget.
:param id: Id of the widget.
:param property: Property.
**Rendering property** can be one of the following:
* **POINT_SIZE**
* **OPACITY**
* **LINE_WIDTH**
@ -468,7 +468,7 @@ Returns rendering property of a widget.
* **REPRESENTATION_POINTS**
* **REPRESENTATION_WIREFRAME**
* **REPRESENTATION_SURFACE**
* **IMMEDIATE_RENDERING**:
* **IMMEDIATE_RENDERING**:
* Turn on immediate rendering by setting the value to ``1``.
* Turn off immediate rendering by setting the value to ``0``.
* **SHADING**: Expected values are
@ -483,7 +483,7 @@ Sets desired update rate of the window.
.. ocv:function:: void setDesiredUpdateRate(double rate)
:param rate: Desired update rate. The default is 30.
viz::Viz3d::getDesiredUpdateRate
--------------------------------
Returns desired update rate of the window.
@ -497,11 +497,11 @@ Sets geometry representation of the widgets to surface, wireframe or points.
.. ocv:function:: void setRepresentation(int representation)
:param representation: Geometry representation which can be one of the following:
* **REPRESENTATION_POINTS**
* **REPRESENTATION_WIREFRAME**
* **REPRESENTATION_SURFACE**
viz::Color
----------
.. ocv:class:: Color
@ -545,11 +545,11 @@ This class wraps mesh attributes, and it can load a mesh from a ``ply`` file. ::
//! Loads mesh from a given ply file
static Mesh3d loadMesh(const String& file);
private:
/* hidden */
};
viz::Mesh3d::loadMesh
---------------------
Loads a mesh from a ``ply`` file.
@ -557,8 +557,8 @@ Loads a mesh from a ``ply`` file.
.. ocv:function:: static Mesh3d loadMesh(const String& file)
:param file: File name.
viz::KeyboardEvent
------------------
.. ocv:class:: KeyboardEvent
@ -602,7 +602,7 @@ Constructs a KeyboardEvent.
:param alt: If true, ``alt`` is pressed.
:param ctrl: If true, ``ctrl`` is pressed.
:param shift: If true, ``shift`` is pressed.
viz::MouseEvent
---------------
.. ocv:class:: MouseEvent
@ -622,7 +622,7 @@ This class represents a mouse event. ::
Point pointer;
unsigned int key_state;
};
viz::MouseEvent::MouseEvent
---------------------------
Constructs a MouseEvent.
@ -635,7 +635,7 @@ Constructs a MouseEvent.
:param alt: If true, ``alt`` is pressed.
:param ctrl: If true, ``ctrl`` is pressed.
:param shift: If true, ``shift`` is pressed.
viz::Camera
-----------
.. ocv:class:: Camera
@ -651,23 +651,23 @@ that can extract the intrinsic parameters from ``field of view``, ``intrinsic ma
Camera(const Vec2f &fov, const Size &window_size);
Camera(const cv::Matx33f &K, const Size &window_size);
Camera(const cv::Matx44f &proj, const Size &window_size);
inline const Vec2d & getClip() const { return clip_; }
inline void setClip(const Vec2d &clip) { clip_ = clip; }
inline const Size & getWindowSize() const { return window_size_; }
void setWindowSize(const Size &window_size);
inline const Vec2f & getFov() const { return fov_; }
inline void setFov(const Vec2f & fov) { fov_ = fov; }
inline const Vec2f & getPrincipalPoint() const { return principal_point_; }
inline const Vec2f & getFocalLength() const { return focal_; }
void computeProjectionMatrix(Matx44f &proj) const;
static Camera KinectCamera(const Size &window_size);
private:
/* hidden */
};
@ -690,7 +690,7 @@ Constructs a Camera.
:param window_size: Size of the window.
Principal point is at the center of the window by default.
.. ocv:function:: Camera(const cv::Matx33f &K, const Size &window_size)
:param K: Intrinsic matrix of the camera.
@ -708,7 +708,7 @@ Computes projection matrix using intrinsic parameters of the camera.
.. ocv:function:: void computeProjectionMatrix(Matx44f &proj) const
:param proj: Output projection matrix.
viz::Camera::KinectCamera
-------------------------
Creates a Kinect Camera.

@ -1,13 +1,13 @@
Widget
======
.. highlight:: cpp
In this section, the widget framework is explained. Widgets represent
2D or 3D objects, varying from simple ones such as lines to complex one such as
2D or 3D objects, varying from simple ones such as lines to complex one such as
point clouds and meshes.
Widgets are **implicitly shared**. Therefore, one can add a widget to the scene,
Widgets are **implicitly shared**. Therefore, one can add a widget to the scene,
and modify the widget without re-adding the widget.
.. code-block:: cpp
@ -34,10 +34,10 @@ Base class of all widgets. Widget is implicitly shared. ::
Widget(const Widget& other);
Widget& operator=(const Widget& other);
~Widget();
//! Create a widget directly from ply file
static Widget fromPlyFile(const String &file_name);
//! Rendering properties of this particular widget
void setRenderingProperty(int property, double value);
double getRenderingProperty(int property) const;
@ -55,7 +55,7 @@ Creates a widget from ply file.
.. ocv:function:: static Widget fromPlyFile(const String &file_name)
:param file_name: Ply file name.
viz::Widget::setRenderingProperty
---------------------------------
Sets rendering property of the widget.
@ -64,9 +64,9 @@ Sets rendering property of the widget.
:param property: Property that will be modified.
:param value: The new value of the property.
**Rendering property** can be one of the following:
* **POINT_SIZE**
* **OPACITY**
* **LINE_WIDTH**
@ -75,14 +75,14 @@ Sets rendering property of the widget.
* **REPRESENTATION_POINTS**
* **REPRESENTATION_WIREFRAME**
* **REPRESENTATION_SURFACE**
* **IMMEDIATE_RENDERING**:
* **IMMEDIATE_RENDERING**:
* Turn on immediate rendering by setting the value to ``1``.
* Turn off immediate rendering by setting the value to ``0``.
* **SHADING**: Expected values are
* **SHADING_FLAT**
* **SHADING_GOURAUD**
* **SHADING_PHONG**
viz::Widget::getRenderingProperty
---------------------------------
Returns rendering property of the widget.
@ -90,9 +90,9 @@ Returns rendering property of the widget.
.. ocv:function:: double getRenderingProperty(int property) const
:param property: Property.
**Rendering property** can be one of the following:
* **POINT_SIZE**
* **OPACITY**
* **LINE_WIDTH**
@ -101,14 +101,14 @@ Returns rendering property of the widget.
* **REPRESENTATION_POINTS**
* **REPRESENTATION_WIREFRAME**
* **REPRESENTATION_SURFACE**
* **IMMEDIATE_RENDERING**:
* **IMMEDIATE_RENDERING**:
* Turn on immediate rendering by setting the value to ``1``.
* Turn off immediate rendering by setting the value to ``0``.
* **SHADING**: Expected values are
* **SHADING_FLAT**
* **SHADING_GOURAUD**
* **SHADING_PHONG**
viz::Widget::cast
-----------------
Casts a widget to another.
@ -135,7 +135,7 @@ This class is for users who want to develop their own widgets using VTK library
static vtkSmartPointer<vtkProp> getProp(const Widget &widget);
static void setProp(Widget &widget, vtkSmartPointer<vtkProp> prop);
};
viz::WidgetAccessor::getProp
----------------------------
Returns ``vtkProp`` of a given widget.
@ -147,9 +147,9 @@ Returns ``vtkProp`` of a given widget.
.. note:: vtkProp has to be down cast appropriately to be modified.
.. code-block:: cpp
vtkActor * actor = vtkActor::SafeDownCast(viz::WidgetAccessor::getProp(widget));
viz::WidgetAccessor::setProp
----------------------------
Sets ``vtkProp`` of a given widget.
@ -158,7 +158,7 @@ Sets ``vtkProp`` of a given widget.
:param widget: Widget whose ``vtkProp`` is to be set.
:param prop: A ``vtkProp``.
viz::Widget3D
-------------
.. ocv:class:: Widget3D
@ -186,7 +186,7 @@ Sets pose of the widget.
.. ocv:function:: void setPose(const Affine3f &pose)
:param pose: The new pose of the widget.
viz::Widget3D::updateWidgetPose
-------------------------------
Updates pose of the widget by pre-multiplying its current pose.
@ -207,8 +207,8 @@ Sets the color of the widget.
.. ocv:function:: void setColor(const Color &color)
:param color: color of type :ocv:class:`Color`
:param color: color of type :ocv:class:`Color`
viz::Widget2D
-------------
.. ocv:class:: Widget2D
@ -222,7 +222,7 @@ Base class of all 2D widgets. ::
void setColor(const Color &color);
};
viz::Widget2D::setColor
-----------------------
Sets the color of the widget.
@ -242,7 +242,7 @@ This 3D Widget defines a finite line. ::
public:
WLine(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white());
};
viz::WLine::WLine
-----------------
Constructs a WLine.
@ -252,7 +252,7 @@ Constructs a WLine.
:param pt1: Start point of the line.
:param pt2: End point of the line.
:param color: :ocv:class:`Color` of the line.
viz::WPlane
-----------
.. ocv:class:: WPlane
@ -267,13 +267,13 @@ This 3D Widget defines a finite plane. ::
private:
/* hidden */
};
viz::WPlane::WPlane
-------------------
Constructs a WPlane.
.. ocv:function:: WPlane(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white())
:param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0.
:param size: Size of the plane.
:param color: :ocv:class:`Color` of the plane.
@ -284,7 +284,7 @@ Constructs a WPlane.
:param pt: Position of the plane.
:param size: Size of the plane.
:param color: :ocv:class:`Color` of the plane.
viz::WSphere
------------
.. ocv:class:: WSphere
@ -319,7 +319,7 @@ This 3D Widget defines an arrow. ::
public:
WArrow(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white());
};
viz::WArrow::WArrow
-----------------------------
Constructs an WArrow.
@ -330,9 +330,9 @@ Constructs an WArrow.
:param pt2: End point of the arrow.
:param thickness: Thickness of the arrow. Thickness of arrow head is also adjusted accordingly.
:param color: :ocv:class:`Color` of the arrow.
Arrow head is located at the end point of the arrow.
viz::WCircle
-----------------
.. ocv:class:: WCircle
@ -344,7 +344,7 @@ This 3D Widget defines a circle. ::
public:
WCircle(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white());
};
viz::WCircle::WCircle
-------------------------------
Constructs a WCircle.
@ -355,7 +355,7 @@ Constructs a WCircle.
:param radius: Radius of the circle.
:param thickness: Thickness of the circle.
:param color: :ocv:class:`Color` of the circle.
viz::WCylinder
--------------
.. ocv:class:: WCylinder
@ -379,7 +379,7 @@ Constructs a WCylinder.
:param radius: Radius of the cylinder.
:param numsides: Resolution of the cylinder.
:param color: :ocv:class:`Color` of the cylinder.
viz::WCube
----------
.. ocv:class:: WCube
@ -391,7 +391,7 @@ This 3D Widget defines a cube. ::
public:
WCube(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white());
};
viz::WCube::WCube
---------------------------
Constructs a WCube.
@ -402,11 +402,11 @@ Constructs a WCube.
:param pt_max: Specifies maximum point of the bounding box.
:param wire_frame: If true, cube is represented as wireframe.
:param color: :ocv:class:`Color` of the cube.
.. image:: images/cube_widget.png
:alt: Cube Widget
:align: center
viz::WCoordinateSystem
----------------------
.. ocv:class:: WCoordinateSystem
@ -418,7 +418,7 @@ This 3D Widget represents a coordinate system. ::
public:
WCoordinateSystem(double scale = 1.0);
};
viz::WCoordinateSystem::WCoordinateSystem
---------------------------------------------------
Constructs a WCoordinateSystem.
@ -426,7 +426,7 @@ Constructs a WCoordinateSystem.
.. ocv:function:: WCoordinateSystem(double scale = 1.0)
:param scale: Determines the size of the axes.
viz::WPolyLine
--------------
.. ocv:class:: WPolyLine
@ -447,10 +447,10 @@ viz::WPolyLine::WPolyLine
Constructs a WPolyLine.
.. ocv:function:: WPolyLine(InputArray points, const Color &color = Color::white())
:param points: Point set.
:param color: :ocv:class:`Color` of the poly line.
viz::WGrid
----------
.. ocv:class:: WGrid
@ -467,7 +467,7 @@ This 3D Widget defines a grid. ::
private:
/* hidden */
};
viz::WGrid::WGrid
---------------------------
Constructs a WGrid.
@ -477,14 +477,14 @@ Constructs a WGrid.
:param dimensions: Number of columns and rows, respectively.
:param spacing: Size of each column and row, respectively.
:param color: :ocv:class:`Color` of the grid.
.. ocv:function: WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white())
:param coeffs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0.
:param dimensions: Number of columns and rows, respectively.
:param spacing: Size of each column and row, respectively.
:param color: :ocv:class:`Color` of the grid.
viz::WText3D
------------
.. ocv:class:: WText3D
@ -499,7 +499,7 @@ This 3D Widget represents 3D text. The text always faces the camera. ::
void setText(const String &text);
String getText() const;
};
viz::WText3D::WText3D
-------------------------------
Constructs a WText3D.
@ -511,7 +511,7 @@ Constructs a WText3D.
:param text_scale: Size of the text.
:param face_camera: If true, text always faces the camera.
:param color: :ocv:class:`Color` of the text.
viz::WText3D::setText
---------------------
Sets the text content of the widget.
@ -540,7 +540,7 @@ This 2D Widget represents text overlay. ::
void setText(const String &text);
String getText() const;
};
viz::WText::WText
-----------------
Constructs a WText.
@ -551,7 +551,7 @@ Constructs a WText.
:param pos: Position of the text.
:param font_size: Font size.
:param color: :ocv:class:`Color` of the text.
viz::WText::setText
-------------------
Sets the text content of the widget.
@ -576,10 +576,10 @@ This 2D Widget represents an image overlay. ::
{
public:
WImageOverlay(const Mat &image, const Rect &rect);
void setImage(const Mat &image);
};
viz::WImageOverlay::WImageOverlay
---------------------------------
Constructs an WImageOverlay.
@ -588,7 +588,7 @@ Constructs an WImageOverlay.
:param image: BGR or Gray-Scale image.
:param rect: Image is scaled and positioned based on rect.
viz::WImageOverlay::setImage
----------------------------
Sets the image content of the widget.
@ -596,7 +596,7 @@ Sets the image content of the widget.
.. ocv:function:: void setImage(const Mat &image)
:param image: BGR or Gray-Scale image.
viz::WImage3D
-------------
.. ocv:class:: WImage3D
@ -610,7 +610,7 @@ This 3D Widget represents an image in 3D space. ::
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
WImage3D(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size);
void setImage(const Mat &image);
};
@ -619,10 +619,10 @@ viz::WImage3D::WImage3D
Constructs an WImage3D.
.. ocv:function:: WImage3D(const Mat &image, const Size &size)
:param image: BGR or Gray-Scale image.
:param size: Size of the image.
.. ocv:function:: WImage3D(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size)
:param position: Position of the image.
@ -630,7 +630,7 @@ Constructs an WImage3D.
:param up_vector: Determines orientation of the image.
:param image: BGR or Gray-Scale image.
:param size: Size of the image.
viz::WImage3D::setImage
-----------------------
Sets the image content of the widget.
@ -638,7 +638,7 @@ Sets the image content of the widget.
.. ocv:function:: void setImage(const Mat &image)
:param image: BGR or Gray-Scale image.
viz::WCameraPosition
--------------------
.. ocv:class:: WCameraPosition
@ -659,7 +659,7 @@ This 3D Widget represents camera position in a scene by its axes or viewing frus
//! 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());
};
viz::WCameraPosition::WCameraPosition
-------------------------------------
Constructs a WCameraPosition.
@ -669,7 +669,7 @@ Constructs a WCameraPosition.
.. ocv:function:: WCameraPosition(double scale = 1.0)
Creates camera coordinate frame at the origin.
.. image:: images/cpw1.png
:alt: Camera coordinate frame
:align: center
@ -681,15 +681,15 @@ Constructs a WCameraPosition.
:param K: Intrinsic matrix of the camera.
:param scale: Scale of the frustum.
:param color: :ocv:class:`Color` of the frustum.
Creates viewing frustum of the camera based on its intrinsic matrix K.
.. ocv:function:: WCameraPosition(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white())
:param fov: Field of view of the camera (horizontal, vertical).
:param scale: Scale of the frustum.
:param color: :ocv:class:`Color` of the frustum.
Creates viewing frustum of the camera based on its field of view fov.
.. image:: images/cpw2.png
@ -704,7 +704,7 @@ Constructs a WCameraPosition.
:param img: BGR or Gray-Scale image that is going to be displayed on the far plane of the frustum.
:param scale: Scale of the frustum and image.
:param color: :ocv:class:`Color` of the frustum.
Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on the far end plane.
.. ocv:function:: WCameraPosition(const Vec2f &fov, const Mat &img, double scale = 1.0, const Color &color = Color::white())
@ -713,9 +713,9 @@ Constructs a WCameraPosition.
:param img: BGR or Gray-Scale image that is going to be displayed on the far plane of the frustum.
:param scale: Scale of the frustum and image.
:param color: :ocv:class:`Color` of the frustum.
Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on the far end plane.
.. image:: images/cpw3.png
:alt: Camera viewing frustum with image
:align: center
@ -730,18 +730,18 @@ This 3D Widget represents a trajectory. ::
{
public:
enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2};
//! 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);
//! 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());
//! 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());
private:
/* hidden */
};
viz::WTrajectory::WTrajectory
-----------------------------
Constructs a WTrajectory.
@ -752,29 +752,29 @@ Constructs a WTrajectory.
:param display_mode: Display mode. This can be DISPLAY_PATH, DISPLAY_FRAMES, DISPLAY_PATH & DISPLAY_FRAMES.
:param color: :ocv:class:`Color` of the polyline that represents path. Frames are not affected.
:param scale: Scale of the frames. Polyline is not affected.
Displays trajectory of the given path as follows:
* DISPLAY_PATH : Displays a poly line that represents the path.
* DISPLAY_FRAMES : Displays coordinate frames at each pose.
* DISPLAY_PATH & DISPLAY_FRAMES : Displays both poly line and coordinate frames.
.. ocv:function:: WTrajectory(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white())
:param path: List of poses on a trajectory.
:param K: Intrinsic matrix of the camera.
:param scale: Scale of the frustums.
:param color: :ocv:class:`Color` of the frustums.
Displays frustums at each pose of the trajectory.
.. ocv:function:: WTrajectory(const std::vector<Affine3f> &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white())
:param path: List of poses on a trajectory.
:param fov: Field of view of the camera (horizontal, vertical).
:param scale: Scale of the frustums.
:param color: :ocv:class:`Color` of the frustums.
Displays frustums at each pose of the trajectory.
viz::WSpheresTrajectory
@ -787,24 +787,24 @@ represent the direction from previous position to the current. ::
class CV_EXPORTS WSpheresTrajectory : public Widget3D
{
public:
WSpheresTrajectory(const std::vector<Affine3f> &path, float line_length = 0.05f,
double init_sphere_radius = 0.021, sphere_radius = 0.007,
WSpheresTrajectory(const std::vector<Affine3f> &path, float line_length = 0.05f,
double init_sphere_radius = 0.021, sphere_radius = 0.007,
Color &line_color = Color::white(), const Color &sphere_color = Color::white());
};
viz::WSpheresTrajectory::WSpheresTrajectory
-------------------------------------------
Constructs a WSpheresTrajectory.
.. ocv:function:: WSpheresTrajectory(const std::vector<Affine3f> &path, float line_length = 0.05f, double init_sphere_radius = 0.021, double sphere_radius = 0.007, const Color &line_color = Color::white(), const Color &sphere_color = Color::white())
:param path: List of poses on a trajectory.
:param line_length: Length of the lines.
:param init_sphere_radius: Radius of the first sphere which represents the initial position of the camera.
:param sphere_radius: Radius of the rest of the spheres.
:param line_color: :ocv:class:`Color` of the lines.
:param sphere_color: :ocv:class:`Color` of the spheres.
viz::WCloud
-----------
.. ocv:class:: WCloud
@ -822,7 +822,7 @@ This 3D Widget defines a point cloud. ::
private:
/* hidden */
};
viz::WCloud::WCloud
-------------------
Constructs a WCloud.
@ -831,16 +831,16 @@ Constructs a WCloud.
:param cloud: Set of points which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``.
:param colors: Set of colors. It has to be of the same size with cloud.
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
.. ocv:function:: WCloud(InputArray cloud, const Color &color = Color::white())
:param cloud: Set of points which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``.
:param color: A single :ocv:class:`Color` for the whole cloud.
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
.. note:: In case there are four channels in the cloud, fourth channel is ignored.
viz::WCloudCollection
@ -853,16 +853,16 @@ This 3D Widget defines a collection of clouds. ::
{
public:
WCloudCollection();
//! Each point in cloud is mapped to a color in colors
void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity());
//! All points in cloud have the same color
void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3f &pose = Affine3f::Identity());
private:
/* hidden */
};
viz::WCloudCollection::WCloudCollection
---------------------------------------
Constructs a WCloudCollection.
@ -878,19 +878,19 @@ Adds a cloud to the collection.
:param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``.
:param colors: Set of colors. It has to be of the same size with cloud.
:param pose: Pose of the cloud.
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
.. ocv:function:: void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity())
:param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``.
:param colors: A single :ocv:class:`Color` for the whole cloud.
:param pose: Pose of the cloud.
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
.. note:: In case there are four channels in the cloud, fourth channel is ignored.
viz::WCloudNormals
------------------
.. ocv:class:: WCloudNormals
@ -905,36 +905,36 @@ This 3D Widget represents normals of a point cloud. ::
private:
/* hidden */
};
viz::WCloudNormals::WCloudNormals
---------------------------------
Constructs a WCloudNormals.
.. ocv:function:: WCloudNormals(InputArray cloud, InputArray normals, int level = 100, float scale = 0.02f, const Color &color = Color::white())
:param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``.
:param normals: A set of normals that has to be of same type with cloud.
:param level: Display only every ``level`` th normal.
:param scale: Scale of the arrows that represent normals.
:param color: :ocv:class:`Color` of the arrows that represent normals.
.. note:: In case there are four channels in the cloud, fourth channel is ignored.
viz::WMesh
----------
.. ocv:class:: WMesh
This 3D Widget defines a mesh. ::
class CV_EXPORTS WMesh : public Widget3D
{
public:
WMesh(const Mesh3d &mesh);
private:
/* hidden */
};
viz::WMesh::WMesh
-----------------
Constructs a WMesh.

@ -56,7 +56,7 @@
namespace cv
{
namespace viz
{
{
//! 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));
@ -87,32 +87,32 @@ namespace cv
//! checks point for Nans
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); }
//! helper class that provides access by name infrastructure
class CV_EXPORTS VizAccessor
{
public:
static VizAccessor & getInstance();
static void release();
Viz3d get(const String &window_name);
//! window names automatically have Viz - prefix even though not provided by the users
static void generateWindowName(const String &window_name, String &output);
private:
VizAccessor(); // Singleton
~VizAccessor();
void add(Viz3d window);
void remove(const String &window_name);
static VizAccessor * instance_;
static bool is_instantiated_;
struct VizAccessorImpl;
static VizAccessorImpl * impl_;
friend class Viz3d;
};
} /* namespace viz */

@ -88,7 +88,7 @@ namespace cv
//! Loads mesh from a given ply file
static cv::viz::Mesh3d loadMesh(const String& file);
private:
struct loadMeshImpl;
};
@ -135,7 +135,7 @@ namespace cv
Point pointer;
unsigned int key_state;
};
class CV_EXPORTS Camera
{
public:
@ -143,26 +143,26 @@ namespace cv
Camera(const Vec2f &fov, const Size &window_size);
Camera(const cv::Matx33f &K, const Size &window_size);
Camera(const cv::Matx44f &proj, const Size &window_size);
inline const Vec2d & getClip() const { return clip_; }
inline void setClip(const Vec2d &clip) { clip_ = clip; }
inline const Size & getWindowSize() const { return window_size_; }
void setWindowSize(const Size &window_size);
inline const Vec2f & getFov() const { return fov_; }
inline void setFov(const Vec2f & fov) { fov_ = fov; }
inline const Vec2f & getPrincipalPoint() const { return principal_point_; }
inline const Vec2f & getFocalLength() const { return focal_; }
void computeProjectionMatrix(Matx44f &proj) const;
static Camera KinectCamera(const Size &window_size);
private:
void init(float f_x, float f_y, float c_x, float c_y, const Size &window_size);
Vec2d clip_;
Vec2f fov_;
Size window_size_;

@ -81,18 +81,18 @@ namespace cv
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
void setCamera(const Camera &camera);
Camera getCamera() const;
Affine3f getViewerPose();
void setViewerPose(const Affine3f &pose);
void resetCameraViewpoint(const String &id);
void resetCamera();
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
Size getWindowSize() const;
void setWindowSize(const Size &window_size);
String getWindowName() const;
@ -107,19 +107,19 @@ namespace cv
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
void setRenderingProperty(const String &id, int property, double value);
double getRenderingProperty(const String &id, int property);
void setDesiredUpdateRate(double rate);
double getDesiredUpdateRate();
void setRepresentation(int representation);
private:
struct VizImpl;
VizImpl* impl_;
void create(const String &window_name);
void release();
};

@ -81,7 +81,7 @@ namespace cv
SHADING_GOURAUD,
SHADING_PHONG
};
/////////////////////////////////////////////////////////////////////////////
/// The base class for all widgets
class CV_EXPORTS Widget
@ -91,10 +91,10 @@ namespace cv
Widget(const Widget& other);
Widget& operator=(const Widget& other);
~Widget();
//! Create a widget directly from ply file
static Widget fromPlyFile(const String &file_name);
//! Rendering properties of this particular widget
void setRenderingProperty(int property, double value);
double getRenderingProperty(int property) const;
@ -201,10 +201,10 @@ namespace cv
WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
//! Creates grid based on the plane equation
WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
private:
struct GridImpl;
};
class CV_EXPORTS WText3D : public Widget3D
@ -224,15 +224,15 @@ namespace cv
void setText(const String &text);
String getText() const;
};
class CV_EXPORTS WImageOverlay : public Widget2D
{
public:
WImageOverlay(const Mat &image, const Rect &rect);
void setImage(const Mat &image);
};
class CV_EXPORTS WImage3D : public Widget3D
{
public:
@ -240,10 +240,10 @@ namespace cv
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
WImage3D(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size);
void setImage(const Mat &image);
};
class CV_EXPORTS WCameraPosition : public Widget3D
{
public:
@ -257,27 +257,27 @@ namespace cv
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
WCameraPosition(const Vec2f &fov, const Mat &img, double scale = 1.0, const Color &color = Color::white());
private:
struct ProjectImage;
};
class CV_EXPORTS WTrajectory : public Widget3D
{
public:
enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2};
//! 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);
//! 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());
//! 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());
private:
struct ApplyPath;
};
class CV_EXPORTS WSpheresTrajectory: public Widget3D
{
public:
@ -301,16 +301,16 @@ namespace cv
{
public:
WCloudCollection();
//! Each point in cloud is mapped to a color in colors
void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity());
//! All points in cloud have the same color
void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity());
private:
struct CreateCloudWidget;
};
class CV_EXPORTS WCloudNormals : public Widget3D
{
public:
@ -319,12 +319,12 @@ namespace cv
private:
struct ApplyCloudNormals;
};
class CV_EXPORTS WMesh : public Widget3D
{
public:
WMesh(const Mesh3d &mesh);
private:
struct CopyImpl;
};

@ -327,7 +327,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
vertices->SetCells(nr_points, cells);
return polydata;
}
static void createMapper(vtkSmartPointer<vtkLODActor> actor, vtkSmartPointer<vtkPolyData> poly_data, Vec3d& minmax)
{
vtkDataSetMapper *mapper = vtkDataSetMapper::SafeDownCast(actor->GetMapper());
@ -349,17 +349,17 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
mapper_new->SetInterpolateScalarsBeforeMapping(interpolation);
mapper_new->ScalarVisibilityOn();
mapper_new->ImmediateModeRenderingOff();
actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, poly_data->GetNumberOfPoints() / 10)));
actor->GetProperty()->SetInterpolationToFlat();
actor->GetProperty()->BackfaceCullingOn();
actor->SetMapper(mapper_new);
return ;
}
vtkPolyData *data = vtkPolyData::SafeDownCast(mapper->GetInput());
CV_Assert("Cloud Widget without data" && data);
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
#if VTK_MAJOR_VERSION <= 5
appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort());
@ -369,7 +369,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
appendFilter->AddInputData(poly_data);
#endif
mapper->SetInputConnection(appendFilter->GetOutputPort());
// Update the number of cloud points
vtkIdType old_cloud_points = actor->GetNumberOfCloudPoints();
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,
Mat colors = _colors.getMat();
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());
if (cloud.isContinuous() && colors.isContinuous())
{
cloud.reshape(cloud.channels(), 1);
@ -410,12 +410,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
// Assign the colors
polydata->GetPointData()->SetScalars(scalars);
// Transform the poly data based on the pose
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply();
transform->SetMatrix(convertToVtkMatrix(pose.matrix));
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transform_filter->SetTransform(transform);
#if VTK_MAJOR_VERSION <= 5
@ -424,10 +424,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
transform_filter->SetInputData(polydata);
#endif
transform_filter->Update();
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Incompatible widget type." && actor);
Vec3d minmax(scalars->GetRange());
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
}
@ -449,12 +449,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color,
// Assign the colors
polydata->GetPointData()->SetScalars(scalars);
// Transform the poly data based on the pose
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply();
transform->SetMatrix(convertToVtkMatrix(pose.matrix));
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transform_filter->SetTransform(transform);
#if VTK_MAJOR_VERSION <= 5
@ -463,10 +463,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color,
transform_filter->SetInputData(polydata);
#endif
transform_filter->Update();
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Incompatible widget type." && actor);
Vec3d minmax(scalars->GetRange());
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
}
@ -634,7 +634,7 @@ struct cv::viz::WMesh::CopyImpl
int index = 0;
const _Tp* srow = source.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)
{
if (!isNan(mrow[0]) && !isNan(mrow[1]) && !isNan(mrow[2]))
@ -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.colors.empty() || (mesh.colors.type() == CV_8UC3 && mesh.cloud.size() == mesh.colors.size()));
CV_Assert(!mesh.polygons.empty() && mesh.polygons.type() == CV_32SC1);
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkIdType nr_points = mesh.cloud.total();
Mat look_up_mat(1, nr_points, CV_32SC1);
int * look_up = look_up_mat.ptr<int>();
points->SetNumberOfPoints(nr_points);
// Copy data from cloud to vtkPoints
if (mesh.cloud.depth() == CV_32F)
{
@ -675,36 +675,36 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
Vec3d *data_end = CopyImpl::copy(mesh.cloud, data_beg, look_up, mesh.cloud);
nr_points = data_end - data_beg;
}
vtkSmartPointer<vtkUnsignedCharArray> scalars;
if (!mesh.colors.empty())
{
Vec3b * colors_data = 0;
colors_data = new Vec3b[nr_points];
NanFilter::copyColor(mesh.colors, colors_data, mesh.cloud);
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
scalars->SetNumberOfComponents(3);
scalars->SetNumberOfTuples(nr_points);
scalars->SetArray(colors_data->val, 3 * nr_points, 0);
}
points->SetNumberOfPoints(nr_points);
vtkSmartPointer<vtkPointSet> data;
if (mesh.polygons.size().area() > 1)
{
vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New();
const int * polygons = mesh.polygons.ptr<int>();
int idx = 0;
int poly_size = mesh.polygons.total();
for (int i = 0; i < poly_size; ++idx)
{
int n_points = polygons[i++];
cell_array->InsertNextCell(n_points);
for (int j = 0; j < n_points; ++j, ++idx)
cell_array->InsertCellPoint(look_up[polygons[i++]]);
@ -717,7 +717,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
if (scalars)
polydata->GetPointData()->SetScalars(scalars);
data = polydata;
}
else
@ -726,20 +726,20 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
const int * polygons = mesh.polygons.ptr<int>();
int n_points = polygons[0];
polygon->GetPointIds()->SetNumberOfIds(n_points);
for (int j = 1; j < n_points+1; ++j)
polygon->GetPointIds()->SetId(j, look_up[polygons[j]]);
vtkSmartPointer<vtkUnstructuredGrid> poly_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
poly_grid->Allocate(1, 1);
poly_grid->InsertNextCell(polygon->GetCellType(), polygon->GetPointIds());
poly_grid->SetPoints(points);
if (scalars)
poly_grid->GetPointData()->SetScalars(scalars);
data = poly_grid;
}
@ -750,7 +750,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
actor->GetProperty()->SetInterpolationToFlat();
actor->GetProperty()->EdgeVisibilityOff();
actor->GetProperty()->ShadingOff();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(data);
@ -758,11 +758,11 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
mapper->SetInputData(data);
#endif
mapper->ImmediateModeRenderingOff();
vtkIdType numberOfCloudPoints = nr_points * 0.1;
actor->SetNumberOfCloudPoints(int(numberOfCloudPoints > 1 ? numberOfCloudPoints : 1));
actor->SetMapper(mapper);
WidgetAccessor::setProp(*this, actor);
}

@ -67,11 +67,11 @@ void cv::viz::InteractorStyle::Initialize()
init_ = true;
stereo_anaglyph_mask_default_ = true;
// Initialize the keyboard event callback as none
keyboardCallback_ = 0;
keyboard_callback_cookie_ = 0;
// Initialize the mouse event callback as none
mouseCallback_ = 0;
mouse_callback_cookie_ = 0;
@ -197,7 +197,7 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K
void
cv::viz::InteractorStyle::OnKeyDown()
{
CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_);
CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_);
@ -482,7 +482,7 @@ cv::viz::InteractorStyle::OnKeyDown()
{
if (it == widget_actor_map_->end())
it = widget_actor_map_->begin();
vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
if (actor && actor->GetUserMatrix())
{
@ -554,7 +554,7 @@ void cv::viz::InteractorStyle::OnKeyUp()
// Check if there is a keyboard callback registered
if (keyboardCallback_)
keyboardCallback_(event, keyboard_callback_cookie_);
Superclass::OnKeyUp();
}
@ -673,10 +673,10 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward()
// If a mouse callback registered, call it!
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
if (Interactor->GetRepeatCount() && mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
if (Interactor->GetAltKey())
{
// zoom

@ -85,7 +85,7 @@ namespace cv
/** \brief Change the default keyboard modified from ALT to a different special key.*/
inline void setKeyboardModifier(const KeyboardModifier &modifier) { modifier_ = modifier; }
protected:
/** \brief Set to true after initialization is complete. */
bool init_;
@ -95,7 +95,7 @@ namespace cv
/** \brief Actor map stored internally. */
cv::Ptr<WidgetActorMap> widget_actor_map_;
/** \brief The current window width/height. */
Vec2i win_size_;
@ -107,7 +107,7 @@ namespace cv
/** \brief A PNG writer for screenshot captures. */
vtkSmartPointer<vtkPNGWriter> snapshot_writer_;
/** \brief Internal window to image filter. Needed by \a snapshot_writer_. */
vtkSmartPointer<vtkWindowToImageFilter> wif_;

File diff suppressed because it is too large Load Diff

@ -120,10 +120,10 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(file.c_str());
reader->Update();
vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput();
CV_Assert("File does not exist or file format is not supported." && poly_data);
vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints();
vtkIdType nr_points = mesh_points->GetNumberOfPoints();
@ -141,7 +141,7 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkUnsignedCharArray* poly_colors = 0;
if (poly_data->GetPointData())
poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars());
if (poly_colors && (poly_colors->GetNumberOfComponents() == 3))
{
mesh.colors.create(1, nr_points, CV_8UC3);
@ -164,9 +164,9 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkIdType nr_cell_points;
vtkCellArray * mesh_polygons = poly_data->GetPolys();
mesh_polygons->InitTraversal();
mesh.polygons.create(1, mesh_polygons->GetSize(), CV_32SC1);
int* polygons = mesh.polygons.ptr<int>();
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)
}
cv::viz::Camera::Camera(const Matx44f &proj, const Size &window_size)
{
{
CV_Assert(window_size.width > 0 && window_size.height > 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 left = near * (proj(0,2)-1) / proj(0,0);
double right = 2.0 * near / proj(0,0) + left;
double bottom = near * (proj(1,2)-1) / proj(1,1);
double top = 2.0 * near / proj(1,1) + bottom;
double epsilon = 2.2204460492503131e-16;
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;
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);
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);
focal_[1] = near * principal_point_[1] / top;
setClip(Vec2d(near, far));
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]));
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
{
CV_Assert(window_size.width > 0 && window_size.height > 0);
setClip(Vec2d(0.01, 1000.01));// Default clipping
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));
principal_point_[0] = c_x;
principal_point_[1] = c_y;
focal_[0] = f_x;
focal_[1] = f_y;
window_size_ = window_size;
}
void cv::viz::Camera::setWindowSize(const Size &window_size)
{
CV_Assert(window_size.width > 0 && window_size.height > 0);
// Get the scale factor and update the principal points
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);
principal_point_[0] *= scalex;
principal_point_[1] *= scaley;
focal_ *= scaley;
// 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]));
window_size_ = window_size;
}
@ -280,12 +280,12 @@ void cv::viz::Camera::computeProjectionMatrix(Matx44f &proj) const
double left = -clip_[0] * 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 temp1 = 2.0 * clip_[0];
double temp2 = 1.0 / (right - left);
double temp3 = 1.0 / (top - bottom);
double temp4 = 1.0 / (clip_[0] - clip_[1]);
proj = Matx44d::zeros();
proj(0,0) = temp1 * temp2;
proj(1,1) = temp1 * temp3;
@ -300,7 +300,7 @@ cv::viz::Camera cv::viz::Camera::KinectCamera(const Size &window_size)
{
// Without distortion, RGB Camera
// 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,2) = 3.2894272028759258e+02;
K(1,1) = 5.2556393630057437e+02;

@ -72,7 +72,7 @@ cv::Affine3f cv::viz::makeCameraPose(const Vec3f& position, const Vec3f& focal_p
Vec3f n = normalize(focal_point - position);
Vec3f u = normalize(y_dir.cross(n));
Vec3f v = n.cross(u);
Matx44f pose_mat = Matx44f::zeros();
pose_mat(0,0) = u[0];
pose_mat(0,1) = u[1];
@ -147,9 +147,9 @@ struct cv::viz::VizAccessor::VizAccessorImpl
cv::viz::VizAccessor::VizAccessor() { impl_ = new cv::viz::VizAccessor::VizAccessorImpl;}
cv::viz::VizAccessor::~VizAccessor()
{
if(impl_)
cv::viz::VizAccessor::~VizAccessor()
{
if(impl_)
{
delete impl_;
impl_ = 0;
@ -202,7 +202,7 @@ void cv::viz::VizAccessor::remove(const String &window_name)
// Add the prefix Viz
String name;
generateWindowName(window_name, name);
VizMap::iterator vm_itr = impl_->viz_map.find(name);
bool exists = vm_itr != impl_->viz_map.end();
if (!exists) return ;
@ -214,7 +214,7 @@ void cv::viz::VizAccessor::generateWindowName(const String &window_name, String
output = "Viz";
// Already is Viz
if (window_name == output) return;
String prefixed = output + " - ";
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

@ -51,7 +51,7 @@
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);
}

@ -125,7 +125,7 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name)
/////////////////////////////////////////////////////////////////////////////////////////////
cv::viz::Viz3d::VizImpl::~VizImpl()
{
if (interactor_)
if (interactor_)
interactor_->DestroyTimer(timer_id_);
if (renderer_) renderer_->Clear();
}
@ -368,11 +368,11 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color)
void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
{
vtkCamera& active_camera = *renderer_->GetActiveCamera();
// Set the intrinsic parameters of the camera
window_->SetSize(camera.getWindowSize().width, camera.getWindowSize().height);
double aspect_ratio = static_cast<double>(camera.getWindowSize().width)/static_cast<double>(camera.getWindowSize().height);
Matx44f proj_mat;
camera.computeProjectionMatrix(proj_mat);
// Use the intrinsic parameters of the camera to simulate more realistically
@ -382,7 +382,7 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
transform->SetMatrix(convertToVtkMatrix(proj_mat * old_proj_mat.inv()));
active_camera.SetUserTransform(transform);
transform->Delete();
renderer_->ResetCameraClippingRange();
renderer_->Render();
}
@ -391,11 +391,11 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
{
vtkCamera& active_camera = *renderer_->GetActiveCamera();
Size window_size(renderer_->GetRenderWindow()->GetSize()[0],
renderer_->GetRenderWindow()->GetSize()[1]);
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));
Camera camera(proj_matrix, window_size);
return camera;
@ -405,7 +405,7 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
{
vtkCamera& camera = *renderer_->GetActiveCamera();
// Position = extrinsic translation
cv::Vec3f pos_vec = pose.translation();
@ -417,11 +417,11 @@ void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
// Compute the new focal point
cv::Vec3f z_axis(0.f, 0.f, 1.f);
cv::Vec3f focal_vec = pos_vec + rotation * z_axis;
camera.SetPosition(pos_vec[0], pos_vec[1], pos_vec[2]);
camera.SetFocalPoint(focal_vec[0], focal_vec[1], focal_vec[2]);
camera.SetViewUp(up_vec[0], up_vec[1], up_vec[2]);
renderer_->ResetCameraClippingRange();
renderer_->Render();
}
@ -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)
{
{
Vec4d world_pt;
vtkInteractorObserver::ComputeDisplayToWorld(renderer_, window_coord.x, window_coord.y, window_coord.z, world_pt.val);
vtkCamera &active_camera = *renderer_->GetActiveCamera();
Vec3d cam_pos;
active_camera.GetPosition(cam_pos.val);
@ -525,19 +525,19 @@ void cv::viz::Viz3d::VizImpl::setRepresentation(int representation)
vtkActor * actor;
switch (representation)
{
case REPRESENTATION_POINTS:
case REPRESENTATION_POINTS:
{
while ((actor = actors->GetNextActor()) != NULL)
actor->GetProperty()->SetRepresentationToPoints();
break;
}
case REPRESENTATION_SURFACE:
case REPRESENTATION_SURFACE:
{
while ((actor = actors->GetNextActor()) != NULL)
actor->GetProperty()->SetRepresentationToSurface();
break;
}
case REPRESENTATION_WIREFRAME:
case REPRESENTATION_WIREFRAME:
{
while ((actor = actors->GetNextActor()) != NULL)
actor->GetProperty()->SetRepresentationToWireframe();

@ -58,20 +58,20 @@ public:
typedef cv::Ptr<VizImpl> Ptr;
typedef Viz3d::KeyboardCallback KeyboardCallback;
typedef Viz3d::MouseCallback MouseCallback;
int ref_counter;
VizImpl(const String &name);
virtual ~VizImpl();
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void removeWidget(const String &id);
Widget getWidget(const String &id) const;
void removeAllWidgets();
void setWidgetPose(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);
double getDesiredUpdateRate();
@ -86,7 +86,7 @@ public:
void close()
{
stopped_ = true;
if (interactor_)
if (interactor_)
{
interactor_->GetRenderWindow()->Finalize();
interactor_->TerminateApp(); // This tends to close the window...
@ -94,14 +94,14 @@ public:
}
void setRepresentation(int representation);
void setCamera(const Camera &camera);
Camera getCamera() const;
/** \brief Reset the camera to a given widget */
void resetCameraViewpoint(const String& id);
void resetCamera();
void setViewerPose(const Affine3f &pose);
Affine3f getViewerPose();
@ -182,7 +182,7 @@ private:
/** \brief The render window interactor style. */
vtkSmartPointer<InteractorStyle> style_;
/** \brief Internal list with actor pointers and name IDs for all widget actors */
cv::Ptr<WidgetActorMap> widget_actor_map_;
@ -245,7 +245,7 @@ namespace cv
}
return output;
}
static _Out* copyColor(const Mat& source, _Out* output, const Mat& nan_mask)
{
CV_Assert(DataDepth<_Tp>::value == source.depth() && source.size() == nan_mask.size());
@ -282,7 +282,7 @@ namespace cv
return table[nan_mask.depth() - 5](source, output, nan_mask);
}
template<typename _Tp>
static inline Vec<_Tp, 3>* copyColor(const Mat& source, Vec<_Tp, 3>* output, const Mat& nan_mask)
{
@ -328,7 +328,7 @@ namespace cv
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); }
struct ConvertToVtkImage
{
struct Impl
@ -336,7 +336,7 @@ namespace cv
static void copyImageMultiChannel(const Mat &image, vtkSmartPointer<vtkImageData> output)
{
int i_chs = image.channels();
for (int i = 0; i < image.rows; ++i)
{
const unsigned char * irows = image.ptr<unsigned char>(i);
@ -349,7 +349,7 @@ namespace cv
}
output->Modified();
}
static void copyImageSingleChannel(const Mat &image, vtkSmartPointer<vtkImageData> output)
{
for (int i = 0; i < image.rows; ++i)
@ -364,7 +364,7 @@ namespace cv
output->Modified();
}
};
static void convert(const Mat &image, vtkSmartPointer<vtkImageData> output)
{
// Create the vtk image
@ -376,7 +376,7 @@ namespace cv
#else
output->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels());
#endif
int i_chs = image.channels();
if (i_chs > 1)
{

@ -55,14 +55,14 @@ class cv::viz::Widget::Impl
{
public:
vtkSmartPointer<vtkProp> prop;
Impl() : prop(0) {}
};
cv::viz::Widget::Widget() : impl_( new Impl() ) { }
cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() )
{
{
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)
return *this;
}
cv::viz::Widget::~Widget()
{
cv::viz::Widget::~Widget()
{
if (impl_)
{
delete impl_;
@ -86,7 +86,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
{
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(file_name.c_str());
vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
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)
actor->GetProperty()->BackfaceCullingOn();
actor->SetMapper(mapper);
Widget widget;
widget.impl_->prop = actor;
return widget;
@ -130,7 +130,7 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
{
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget type is not supported." && actor);
switch (property)
{
case POINT_SIZE:
@ -218,8 +218,8 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
actor->Modified();
break;
}
default:
CV_Assert("setPointCloudRenderingProperties: Unknown property");
}
@ -229,7 +229,7 @@ double cv::viz::Widget::getRenderingProperty(int property) const
{
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget type is not supported." && actor);
double value = 0.0;
switch (property)
{
@ -313,7 +313,7 @@ struct cv::viz::Widget3D::MatrixConverter
m(i, k) = vtk_matrix->GetElement(i, k);
return m;
}
static vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix(const Matx44f& m)
{
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
@ -328,7 +328,7 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose)
{
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
actor->SetUserMatrix(matrix);
actor->Modified();
@ -338,7 +338,7 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose)
{
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
if (!matrix)
{
@ -358,7 +358,7 @@ cv::Affine3f cv::viz::Widget3D::getPose() const
{
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
Matx44f matrix_cv = MatrixConverter::convertToMatx(matrix);
return Affine3f(matrix_cv);
@ -369,7 +369,7 @@ void cv::viz::Widget3D::setColor(const Color &color)
// Cast to actor instead of prop3d since prop3d doesn't provide getproperty
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget type is not supported." && actor);
Color c = vtkcolor(color);
actor->GetMapper()->ScalarVisibilityOff();
actor->GetProperty()->SetColor(c.val);

@ -110,23 +110,23 @@ TEST(Viz_viz3d, accuracy)
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)),
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 cam_path_size = cam_path.size();
// OTHER WIDGETS
cv::Mat img = imread("opencv.png");
int downSample = 4;
int row_max = img.rows/downSample;
int col_max = img.cols/downSample;
cv::Mat *clouds = new cv::Mat[img.cols/downSample];
cv::Mat *colors = new cv::Mat[img.cols/downSample];
for (int col = 0; col < col_max; ++col)
{
clouds[col] = Mat::zeros(img.rows/downSample, 1, CV_32FC3);
@ -137,7 +137,7 @@ TEST(Viz_viz3d, accuracy)
colors[col].at<Vec3b>(row) = img.at<Vec3b>(row*downSample,col*downSample);
}
}
for (int col = 0; col < col_max; ++col)
{
std::stringstream strstrm;
@ -146,16 +146,16 @@ TEST(Viz_viz3d, accuracy)
viz.getWidget(strstrm.str()).setRenderingProperty(viz::POINT_SIZE, 3.0);
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("cam_text", viz::WText("Global View", Point2i(5,5), 28));
viz.registerKeyboardCallback(keyboard_callback, (void *) &viz);
int angle = 0;
while(!viz.wasStopped())
{
if (path_counter == cam_path_size)
if (path_counter == cam_path_size)
{
path_counter = 0;
}
@ -164,12 +164,12 @@ TEST(Viz_viz3d, accuracy)
{
viz.setViewerPose(cam_path[path_counter]);
}
if (angle == 360) angle = 0;
cam_1.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)
{
std::stringstream strstrm;

@ -82,7 +82,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
if(NOT HAVE_opencv_gpuarithm OR NOT HAVE_opencv_gpufilters)
ocv_list_filterout(cpp_samples "/gpu/")
endif()
ocv_list_filterout(cpp_samples "viz")
foreach(sample_filename ${cpp_samples})

File diff suppressed because it is too large Load Diff

@ -5,7 +5,7 @@
*/
#include <opencv2/viz.hpp>
#include <opencv2/viz/widget_accessor.hpp>
#include <opencv2/viz/widget_accessor.hpp>
#include <iostream>
#include <vtkPoints.h>
@ -42,7 +42,7 @@ void help()
class WTriangle : public viz::Widget3D
{
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,
points->InsertNextPoint(pt1.x, pt1.y, pt1.z);
points->InsertNextPoint(pt2.x, pt2.y, pt2.z);
points->InsertNextPoint(pt3.x, pt3.y, pt3.z);
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId(0,0);
triangle->GetPointIds()->SetId(1,1);
triangle->GetPointIds()->SetId(2,2);
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(triangle);
// Create a polydata object
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
// Add the geometry and topology to the polydata
polyData->SetPoints(points);
polyData->SetPolys(cells);
// Create mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
@ -79,13 +79,13 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3,
#else
mapper->SetInputData(polyData);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor);
// Set the color of the widget. This has to be called after WidgetAccessor.
setColor(color);
}
@ -96,18 +96,18 @@ WTriangle::WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3,
int main()
{
help();
/// Create a window
viz::Viz3d myWindow("Creating Widgets");
/// 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());
/// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw);
/// Start event loop
myWindow.spin();
return 0;
}

@ -33,33 +33,33 @@ int main()
help();
/// Create a window
viz::Viz3d myWindow("Viz Demo");
/// Start event loop
myWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "First event loop is over" << endl;
/// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo");
/// Start event loop
sameWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "Second event loop is over" << endl;
/// Event loop is over when pressed q, Q, e, E
/// Start event loop once for 1 millisecond
sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped())
{
/// Interact with window
/// Event loop for 1 millisecond
sameWindow.spinOnce(1, true);
}
/// Once more event loop is stopped
cout << "Last event loop is over" << endl;
return 0;

@ -44,7 +44,7 @@ Mat cvcloud_load()
float dummy1, dummy2;
for(size_t i = 0; i < 1889; ++i)
ifs >> data[i].x >> data[i].y >> data[i].z >> dummy1 >> dummy2;
cloud *= 5.0f;
return cloud;
}
@ -55,40 +55,40 @@ Mat cvcloud_load()
int main(int argn, char **argv)
{
help();
if (argn < 2)
{
cout << "Missing arguments." << endl;
return 1;
}
bool camera_pov = (argv[1][0] == 'C');
/// Create a window
viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// 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);
/// We can get the pose of the cam using makeCameraPose
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
/// - 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);
/// Create a cloud widget.
Mat bunny_cloud = cvcloud_load();
viz::WCloud cloud_widget(bunny_cloud, viz::Color::green());
/// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f));
/// Pose of the widget in global frame
Affine3f cloud_pose_global = transform * cloud_pose;
/// Visualize camera frame
if (!camera_pov)
{
@ -97,16 +97,16 @@ int main(int argn, char **argv)
myWindow.showWidget("CPW", cpw, cam_pose);
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
}
/// Visualize widget
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
/// Set the viewer pose to that of camera
if (camera_pov)
myWindow.setViewerPose(cam_pose);
/// Start event loop.
myWindow.spin();
return 0;
}

@ -32,23 +32,23 @@ void help()
int main()
{
help();
/// Create a window
viz::Viz3d myWindow("Coordinate Frame");
/// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// 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));
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis);
/// 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());
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Cube Widget", cube_widget);
myWindow.showWidget("Cube Widget", cube_widget);
/// Rodrigues vector
Mat rot_vec = Mat::zeros(1,3,CV_32F);
float translation_phase = 0.0, translation = 0.0;
@ -59,21 +59,21 @@ int main()
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,2) += CV_PI * 0.01f;
/// Shift on (1,1,1)
translation_phase += CV_PI * 0.01f;
translation = sin(translation_phase);
Mat rot_mat;
Rodrigues(rot_vec, rot_mat);
Rodrigues(rot_vec, rot_mat);
/// Construct pose
Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
myWindow.setWidgetPose("Cube Widget", pose);
myWindow.spinOnce(1, true);
}
return 0;
}

Loading…
Cancel
Save