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
.. 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
This diff is collapsed.
This diff is collapsed.
......@@ -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_;
......
This diff is collapsed.
......@@ -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})
......
This diff is collapsed.
......@@ -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;
}
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