parent
b17e1531d2
commit
787f5236a9
45 changed files with 0 additions and 9928 deletions
@ -1,38 +0,0 @@ |
||||
if(NOT HAVE_VTK) |
||||
ocv_module_disable(viz) |
||||
endif() |
||||
|
||||
set(the_description "Viz") |
||||
include(${VTK_USE_FILE}) |
||||
|
||||
if(NOT BUILD_SHARED_LIBS) |
||||
# We observed conflict between builtin 3rdparty libraries and |
||||
# system-wide similar libraries (but with different versions) from VTK dependencies |
||||
set(_conflicts "") |
||||
foreach(dep ${VTK_LIBRARIES}) |
||||
if(("${dep}" MATCHES "libz\\." AND BUILD_ZLIB) |
||||
OR ("${dep}" MATCHES "libjpeg\\." AND BUILD_JPEG) |
||||
OR ("${dep}" MATCHES "libpng\\." AND BUILD_PNG) |
||||
OR ("${dep}" MATCHES "libtiff\\." AND BUILD_TIFF) |
||||
) |
||||
list(APPEND _conflicts "${dep}") |
||||
endif() |
||||
endforeach() |
||||
if(_conflicts) |
||||
message(STATUS "Disabling VIZ module due to conflicts with VTK dependencies: ${_conflicts}") |
||||
ocv_module_disable(viz) |
||||
endif() |
||||
endif() |
||||
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Winconsistent-missing-override -Wsuggest-override) |
||||
|
||||
ocv_define_module(viz opencv_core WRAP python) |
||||
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${VTK_LIBRARIES}) |
||||
|
||||
if(APPLE AND BUILD_opencv_viz) |
||||
ocv_target_link_libraries(${the_module} LINK_PRIVATE "-framework Cocoa") |
||||
endif() |
||||
|
||||
if(TARGET opencv_test_viz) |
||||
set_target_properties(opencv_test_viz PROPERTIES MACOSX_BUNDLE TRUE) |
||||
endif() |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 6.4 KiB |
@ -1,84 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIZ_HPP |
||||
#define OPENCV_VIZ_HPP |
||||
|
||||
#include <opencv2/viz/types.hpp> |
||||
#include <opencv2/viz/widgets.hpp> |
||||
#include <opencv2/viz/viz3d.hpp> |
||||
#include <opencv2/viz/vizcore.hpp> |
||||
|
||||
/**
|
||||
@defgroup viz 3D Visualizer |
||||
|
||||
This section describes 3D visualization window as well as classes and methods that are used to |
||||
interact with it. |
||||
|
||||
3D visualization window (see Viz3d) is used to display widgets (see Widget), and it provides several |
||||
methods to interact with scene and widgets. |
||||
|
||||
@{ |
||||
@defgroup viz_widget Widget |
||||
|
||||
In this section, the widget framework is explained. Widgets represent 2D or 3D objects, varying from |
||||
simple ones such as lines to complex ones such as point clouds and meshes. |
||||
|
||||
Widgets are **implicitly shared**. Therefore, one can add a widget to the scene, and modify the |
||||
widget without re-adding the widget. |
||||
|
||||
@code |
||||
// Create a cloud widget
|
||||
viz::WCloud cw(cloud, viz::Color::red()); |
||||
// Display it in a window
|
||||
myWindow.showWidget("CloudWidget1", cw); |
||||
// Modify it, and it will be modified in the window.
|
||||
cw.setColor(viz::Color::yellow()); |
||||
@endcode |
||||
|
||||
@} |
||||
*/ |
||||
|
||||
#endif /* OPENCV_VIZ_HPP */ |
@ -1,387 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIZ_TYPES_HPP |
||||
#define OPENCV_VIZ_TYPES_HPP |
||||
|
||||
#include <string> |
||||
#include <opencv2/core.hpp> |
||||
#include <opencv2/core/affine.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
|
||||
//! @addtogroup viz
|
||||
//! @{
|
||||
|
||||
/** @brief This class represents color in BGR order.
|
||||
*/ |
||||
class Color : public Scalar |
||||
{ |
||||
public: |
||||
Color(); |
||||
//! The three channels will have the same value equal to gray.
|
||||
Color(double gray); |
||||
Color(double blue, double green, double red); |
||||
|
||||
Color(const Scalar& color); |
||||
|
||||
operator Vec3b() const; |
||||
|
||||
static Color black(); |
||||
static Color blue(); |
||||
static Color green(); |
||||
static Color cyan(); |
||||
|
||||
static Color red(); |
||||
static Color magenta(); |
||||
static Color yellow(); |
||||
static Color white(); |
||||
|
||||
static Color gray(); |
||||
|
||||
static Color mlab(); |
||||
|
||||
static Color navy(); |
||||
static Color olive(); |
||||
static Color maroon(); |
||||
static Color teal(); |
||||
static Color rose(); |
||||
static Color azure(); |
||||
static Color lime(); |
||||
static Color gold(); |
||||
static Color brown(); |
||||
static Color orange(); |
||||
static Color chartreuse(); |
||||
static Color orange_red(); |
||||
static Color purple(); |
||||
static Color indigo(); |
||||
|
||||
static Color pink(); |
||||
static Color cherry(); |
||||
static Color bluberry(); |
||||
static Color raspberry(); |
||||
static Color silver(); |
||||
static Color violet(); |
||||
static Color apricot(); |
||||
static Color turquoise(); |
||||
static Color celestial_blue(); |
||||
static Color amethyst(); |
||||
|
||||
static Color not_set(); |
||||
}; |
||||
|
||||
/** @brief This class wraps mesh attributes, and it can load a mesh from a ply file. :
|
||||
*/ |
||||
class CV_EXPORTS Mesh |
||||
{ |
||||
public: |
||||
enum { |
||||
LOAD_AUTO = 0, |
||||
LOAD_PLY = 1, |
||||
LOAD_OBJ = 2 |
||||
}; |
||||
|
||||
Mat cloud; //!< point coordinates of type CV_32FC3 or CV_64FC3 with only 1 row
|
||||
Mat colors; //!< point color of type CV_8UC3 or CV_8UC4 with only 1 row
|
||||
Mat normals; //!< point normals of type CV_32FC3, CV_32FC4, CV_64FC3 or CV_64FC4 with only 1 row
|
||||
|
||||
//! Raw integer list of the form: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...)
|
||||
//! where n is the number of points in the polygon, and id is a zero-offset index into an associated cloud.
|
||||
Mat polygons; //!< CV_32SC1 with only 1 row
|
||||
|
||||
Mat texture; |
||||
Mat tcoords; //!< CV_32FC2 or CV_64FC2 with only 1 row
|
||||
|
||||
/** @brief Loads a mesh from a ply or a obj file.
|
||||
|
||||
@param file File name |
||||
@param type File type (for now only PLY and OBJ are supported) |
||||
|
||||
**File type** can be one of the following: |
||||
- **LOAD_PLY** |
||||
- **LOAD_OBJ** |
||||
*/ |
||||
static Mesh load(const String& file, int type = LOAD_PLY); |
||||
|
||||
}; |
||||
|
||||
/** @brief This class wraps intrinsic parameters of a camera.
|
||||
|
||||
It provides several constructors that can extract the intrinsic parameters from field of |
||||
view, intrinsic matrix and projection matrix. : |
||||
*/ |
||||
class CV_EXPORTS Camera |
||||
{ |
||||
public: |
||||
|
||||
/** @brief Constructs a Camera.
|
||||
|
||||
@param fx Horizontal focal length. |
||||
@param fy Vertical focal length. |
||||
@param cx x coordinate of the principal point. |
||||
@param cy y coordinate of the principal point. |
||||
@param window_size Size of the window. This together with focal length and principal |
||||
point determines the field of view. |
||||
*/ |
||||
Camera(double fx, double fy, double cx, double cy, const Size &window_size); |
||||
|
||||
/** @overload
|
||||
@param fov Field of view (horizontal, vertical) |
||||
@param window_size Size of the window. Principal point is at the center of the window |
||||
by default. |
||||
*/ |
||||
Camera(const Vec2d &fov, const Size &window_size); |
||||
|
||||
/** @overload
|
||||
@param K Intrinsic matrix of the camera with the following form |
||||
\f[ |
||||
\begin{bmatrix} |
||||
f_x & 0 & c_x\\
|
||||
0 & f_y & c_y\\
|
||||
0 & 0 & 1\\
|
||||
\end{bmatrix} |
||||
\f] |
||||
@param window_size Size of the window. This together with intrinsic matrix determines |
||||
the field of view. |
||||
*/ |
||||
Camera(const Matx33d &K, const Size &window_size); |
||||
|
||||
/** @overload
|
||||
@param proj Projection matrix of the camera with the following form |
||||
\f[ |
||||
\begin{bmatrix} |
||||
\frac{2n}{r-l} & 0 & \frac{r+l}{r-l} & 0\\
|
||||
0 & \frac{2n}{t-b} & \frac{t+b}{t-b} & 0\\
|
||||
0 & 0 & -\frac{f+n}{f-n} & -\frac{2fn}{f-n}\\
|
||||
0 & 0 & -1 & 0\\
|
||||
\end{bmatrix} |
||||
\f] |
||||
|
||||
@param window_size Size of the window. This together with projection matrix determines |
||||
the field of view. |
||||
*/ |
||||
explicit Camera(const Matx44d &proj, const Size &window_size); |
||||
|
||||
const Vec2d & getClip() const { return clip_; } |
||||
void setClip(const Vec2d &clip) { clip_ = clip; } |
||||
|
||||
const Size & getWindowSize() const { return window_size_; } |
||||
void setWindowSize(const Size &window_size); |
||||
|
||||
const Vec2d& getFov() const { return fov_; } |
||||
void setFov(const Vec2d& fov) { fov_ = fov; } |
||||
|
||||
const Vec2d& getPrincipalPoint() const { return principal_point_; } |
||||
const Vec2d& getFocalLength() const { return focal_; } |
||||
|
||||
/** @brief Computes projection matrix using intrinsic parameters of the camera.
|
||||
|
||||
|
||||
@param proj Output projection matrix with the following form |
||||
\f[ |
||||
\begin{bmatrix} |
||||
\frac{2n}{r-l} & 0 & \frac{r+l}{r-l} & 0\\
|
||||
0 & \frac{2n}{t-b} & \frac{t+b}{t-b} & 0\\
|
||||
0 & 0 & -\frac{f+n}{f-n} & -\frac{2fn}{f-n}\\
|
||||
0 & 0 & -1 & 0\\
|
||||
\end{bmatrix} |
||||
\f] |
||||
*/ |
||||
void computeProjectionMatrix(Matx44d &proj) const; |
||||
|
||||
/** @brief Creates a Kinect Camera with
|
||||
- fx = fy = 525 |
||||
- cx = 320 |
||||
- cy = 240 |
||||
|
||||
@param window_size Size of the window. This together with intrinsic matrix of a Kinect Camera |
||||
determines the field of view. |
||||
*/ |
||||
static Camera KinectCamera(const Size &window_size); |
||||
|
||||
private: |
||||
void init(double fx, double fy, double cx, double cy, const Size &window_size); |
||||
|
||||
/** The near plane and the far plane.
|
||||
* - clip_[0]: the near plane; default value is 0.01 |
||||
* - clip_[1]: the far plane; default value is 1000.01 |
||||
*/ |
||||
Vec2d clip_; |
||||
|
||||
/**
|
||||
* Field of view. |
||||
* - fov_[0]: horizontal(x-axis) field of view in radians |
||||
* - fov_[1]: vertical(y-axis) field of view in radians |
||||
*/ |
||||
Vec2d fov_; |
||||
|
||||
/** Window size.*/ |
||||
Size window_size_; |
||||
|
||||
/**
|
||||
* Principal point. |
||||
* - principal_point_[0]: cx |
||||
* - principal_point_[1]: cy |
||||
*/ |
||||
Vec2d principal_point_; |
||||
/**
|
||||
* Focal length. |
||||
* - focal_[0]: fx |
||||
* - focal_[1]: fy |
||||
*/ |
||||
Vec2d focal_; |
||||
}; |
||||
|
||||
/** @brief This class represents a keyboard event.
|
||||
*/ |
||||
class CV_EXPORTS KeyboardEvent |
||||
{ |
||||
public: |
||||
enum { NONE = 0, ALT = 1, CTRL = 2, SHIFT = 4 }; |
||||
enum Action { KEY_UP = 0, KEY_DOWN = 1 }; |
||||
|
||||
/** @brief Constructs a KeyboardEvent.
|
||||
|
||||
@param action Signals if key is pressed or released. |
||||
@param symbol Name of the key. |
||||
@param code Code of the key. |
||||
@param modifiers Signals if alt, ctrl or shift are pressed or their combination. |
||||
*/ |
||||
KeyboardEvent(Action action, const String& symbol, unsigned char code, int modifiers); |
||||
|
||||
Action action; |
||||
String symbol; |
||||
unsigned char code; |
||||
int modifiers; |
||||
}; |
||||
|
||||
/** @brief This class represents a mouse event.
|
||||
*/ |
||||
class CV_EXPORTS MouseEvent |
||||
{ |
||||
public: |
||||
enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ; |
||||
enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ; |
||||
|
||||
/** @brief Constructs a MouseEvent.
|
||||
|
||||
@param type Type of the event. This can be **MouseMove**, **MouseButtonPress**, |
||||
**MouseButtonRelease**, **MouseScrollDown**, **MouseScrollUp**, **MouseDblClick**. |
||||
@param button Mouse button. This can be **NoButton**, **LeftButton**, **MiddleButton**, |
||||
**RightButton**, **VScroll**. |
||||
@param pointer Position of the event. |
||||
@param modifiers Signals if alt, ctrl or shift are pressed or their combination. |
||||
*/ |
||||
MouseEvent(const Type& type, const MouseButton& button, const Point& pointer, int modifiers); |
||||
|
||||
Type type; |
||||
MouseButton button; |
||||
Point pointer; |
||||
int modifiers; |
||||
}; |
||||
|
||||
//! @} viz
|
||||
|
||||
} /* namespace viz */ |
||||
} /* namespace cv */ |
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// cv::viz::Color
|
||||
|
||||
inline cv::viz::Color::Color() : Scalar(0, 0, 0) {} |
||||
inline cv::viz::Color::Color(double _gray) : Scalar(_gray, _gray, _gray) {} |
||||
inline cv::viz::Color::Color(double _blue, double _green, double _red) : Scalar(_blue, _green, _red) {} |
||||
inline cv::viz::Color::Color(const Scalar& color) : Scalar(color) {} |
||||
|
||||
inline cv::viz::Color::operator cv::Vec3b() const { return cv::Vec3d(val); } |
||||
|
||||
inline cv::viz::Color cv::viz::Color::black() { return Color( 0, 0, 0); } |
||||
inline cv::viz::Color cv::viz::Color::green() { return Color( 0, 255, 0); } |
||||
inline cv::viz::Color cv::viz::Color::blue() { return Color(255, 0, 0); } |
||||
inline cv::viz::Color cv::viz::Color::cyan() { return Color(255, 255, 0); } |
||||
inline cv::viz::Color cv::viz::Color::red() { return Color( 0, 0, 255); } |
||||
inline cv::viz::Color cv::viz::Color::yellow() { return Color( 0, 255, 255); } |
||||
inline cv::viz::Color cv::viz::Color::magenta() { return Color(255, 0, 255); } |
||||
inline cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); } |
||||
inline cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); } |
||||
|
||||
inline cv::viz::Color cv::viz::Color::mlab() { return Color(255, 128, 128); } |
||||
|
||||
inline cv::viz::Color cv::viz::Color::navy() { return Color(0, 0, 128); } |
||||
inline cv::viz::Color cv::viz::Color::olive() { return Color(0, 128, 128); } |
||||
inline cv::viz::Color cv::viz::Color::maroon() { return Color(0, 0, 128); } |
||||
inline cv::viz::Color cv::viz::Color::teal() { return Color(128, 128, 0); } |
||||
inline cv::viz::Color cv::viz::Color::rose() { return Color(128, 0, 255); } |
||||
inline cv::viz::Color cv::viz::Color::azure() { return Color(255, 128, 0); } |
||||
inline cv::viz::Color cv::viz::Color::lime() { return Color(0, 255, 191); } |
||||
inline cv::viz::Color cv::viz::Color::gold() { return Color(0, 215, 255); } |
||||
inline cv::viz::Color cv::viz::Color::brown() { return Color(42, 42, 165); } |
||||
inline cv::viz::Color cv::viz::Color::orange() { return Color(0, 165, 255); } |
||||
inline cv::viz::Color cv::viz::Color::chartreuse() { return Color(0, 255, 128); } |
||||
inline cv::viz::Color cv::viz::Color::orange_red() { return Color(0, 69, 255); } |
||||
inline cv::viz::Color cv::viz::Color::purple() { return Color(128, 0, 128); } |
||||
inline cv::viz::Color cv::viz::Color::indigo() { return Color(130, 0, 75); } |
||||
|
||||
inline cv::viz::Color cv::viz::Color::pink() { return Color(203, 192, 255); } |
||||
inline cv::viz::Color cv::viz::Color::cherry() { return Color( 99, 29, 222); } |
||||
inline cv::viz::Color cv::viz::Color::bluberry() { return Color(247, 134, 79); } |
||||
inline cv::viz::Color cv::viz::Color::raspberry() { return Color( 92, 11, 227); } |
||||
inline cv::viz::Color cv::viz::Color::silver() { return Color(192, 192, 192); } |
||||
inline cv::viz::Color cv::viz::Color::violet() { return Color(226, 43, 138); } |
||||
inline cv::viz::Color cv::viz::Color::apricot() { return Color(177, 206, 251); } |
||||
inline cv::viz::Color cv::viz::Color::turquoise() { return Color(208, 224, 64); } |
||||
inline cv::viz::Color cv::viz::Color::celestial_blue() { return Color(208, 151, 73); } |
||||
inline cv::viz::Color cv::viz::Color::amethyst() { return Color(204, 102, 153); } |
||||
|
||||
inline cv::viz::Color cv::viz::Color::not_set() { return Color(-1, -1, -1); } |
||||
|
||||
//! @endcond
|
||||
|
||||
#endif |
@ -1,353 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIZ_VIZ3D_HPP |
||||
#define OPENCV_VIZ_VIZ3D_HPP |
||||
|
||||
#if !defined YES_I_AGREE_THAT_VIZ_API_IS_NOT_STABLE_NOW_AND_BINARY_COMPARTIBILITY_WONT_BE_SUPPORTED && !defined CVAPI_EXPORTS |
||||
//#error "Viz is in beta state now. Please define macro above to use it"
|
||||
#endif |
||||
|
||||
#include <opencv2/core.hpp> |
||||
#include <opencv2/viz/types.hpp> |
||||
#include <opencv2/viz/widgets.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
|
||||
//! @addtogroup viz
|
||||
//! @{
|
||||
|
||||
/** @brief The Viz3d class represents a 3D visualizer window. This class is implicitly shared.
|
||||
*/ |
||||
class CV_EXPORTS Viz3d |
||||
{ |
||||
public: |
||||
typedef cv::viz::Color Color; |
||||
typedef void (*KeyboardCallback)(const KeyboardEvent&, void*); |
||||
typedef void (*MouseCallback)(const MouseEvent&, void*); |
||||
|
||||
/** @brief The constructors.
|
||||
|
||||
@param window_name Name of the window. |
||||
*/ |
||||
Viz3d(const String& window_name = String()); |
||||
Viz3d(const Viz3d&); |
||||
Viz3d& operator=(const Viz3d&); |
||||
~Viz3d(); |
||||
|
||||
/** @brief 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. |
||||
*/ |
||||
void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity()); |
||||
|
||||
/** @brief Removes a widget from the window.
|
||||
|
||||
@param id The id of the widget that will be removed. |
||||
*/ |
||||
void removeWidget(const String &id); |
||||
|
||||
/** @brief Retrieves a widget from the window.
|
||||
|
||||
A widget is implicitly shared; that is, if the returned widget is modified, the changes |
||||
will be immediately visible in the window. |
||||
|
||||
@param id The id of the widget that will be returned. |
||||
*/ |
||||
Widget getWidget(const String &id) const; |
||||
|
||||
/** @brief Removes all widgets from the window.
|
||||
*/ |
||||
void removeAllWidgets(); |
||||
|
||||
/** @brief Removed all widgets and displays image scaled to whole window area.
|
||||
|
||||
@param image Image to be displayed. |
||||
@param window_size Size of Viz3d window. Default value means no change. |
||||
*/ |
||||
void showImage(InputArray image, const Size& window_size = Size(-1, -1)); |
||||
|
||||
/** @brief Sets pose of a widget in the window.
|
||||
|
||||
@param id The id of the widget whose pose will be set. @param pose The new pose of the widget. |
||||
*/ |
||||
void setWidgetPose(const String &id, const Affine3d &pose); |
||||
|
||||
/** @brief Updates pose of a widget in the window by pre-multiplying its current pose.
|
||||
|
||||
@param id The id of the widget whose pose will be updated. @param pose The pose that the current |
||||
pose of the widget will be pre-multiplied by. |
||||
*/ |
||||
void updateWidgetPose(const String &id, const Affine3d &pose); |
||||
|
||||
/** @brief Returns the current pose of a widget in the window.
|
||||
|
||||
@param id The id of the widget whose pose will be returned. |
||||
*/ |
||||
Affine3d getWidgetPose(const String &id) const; |
||||
|
||||
/** @brief Sets the intrinsic parameters of the viewer using Camera.
|
||||
|
||||
@param camera Camera object wrapping intrinsic parameters. |
||||
*/ |
||||
void setCamera(const Camera &camera); |
||||
|
||||
/** @brief Returns a camera object that contains intrinsic parameters of the current viewer.
|
||||
*/ |
||||
Camera getCamera() const; |
||||
|
||||
/** @brief Returns the current pose of the viewer.
|
||||
*/ |
||||
Affine3d getViewerPose() const; |
||||
|
||||
/** @brief Sets pose of the viewer.
|
||||
|
||||
@param pose The new pose of the viewer. |
||||
*/ |
||||
void setViewerPose(const Affine3d &pose); |
||||
|
||||
/** @brief Resets camera viewpoint to a 3D widget in the scene.
|
||||
|
||||
@param id Id of a 3D widget. |
||||
*/ |
||||
void resetCameraViewpoint(const String &id); |
||||
|
||||
/** @brief Resets camera.
|
||||
*/ |
||||
void resetCamera(); |
||||
|
||||
/** @brief 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. |
||||
*/ |
||||
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); |
||||
|
||||
/** @brief Transforms a point in window coordinate system to a 3D ray in world coordinate system.
|
||||
|
||||
@param window_coord Point in window coordinate system. @param origin Output origin of the ray. |
||||
@param direction Output direction of the ray. |
||||
*/ |
||||
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); |
||||
|
||||
/** @brief Returns the current size of the window.
|
||||
*/ |
||||
Size getWindowSize() const; |
||||
/** @brief Sets the size of the window.
|
||||
|
||||
@param window_size New size of the window. |
||||
*/ |
||||
void setWindowSize(const Size &window_size); |
||||
|
||||
/** @brief Returns the name of the window which has been set in the constructor.
|
||||
* `Viz - ` is prepended to the name if necessary. |
||||
*/ |
||||
String getWindowName() const; |
||||
|
||||
/** @brief Returns the Mat screenshot of the current scene.
|
||||
*/ |
||||
cv::Mat getScreenshot() const; |
||||
|
||||
/** @brief Saves screenshot of the current scene.
|
||||
|
||||
@param file Name of the file. |
||||
*/ |
||||
void saveScreenshot(const String &file); |
||||
|
||||
/** @brief Sets the position of the window in the screen.
|
||||
|
||||
@param window_position coordinates of the window |
||||
*/ |
||||
void setWindowPosition(const Point& window_position); |
||||
|
||||
/** @brief Sets or unsets full-screen rendering mode.
|
||||
|
||||
@param mode If true, window will use full-screen mode. |
||||
*/ |
||||
void setFullScreen(bool mode = true); |
||||
|
||||
/** @brief Sets background color.
|
||||
*/ |
||||
void setBackgroundColor(const Color& color = Color::black(), const Color& color2 = Color::not_set()); |
||||
void setBackgroundTexture(InputArray image = noArray()); |
||||
void setBackgroundMeshLab(); |
||||
|
||||
/** @brief The window renders and starts the event loop.
|
||||
*/ |
||||
void spin(); |
||||
|
||||
/** @brief Starts the event loop for a given time.
|
||||
|
||||
@param time Amount of time in milliseconds for the event loop to keep running. |
||||
@param force_redraw If true, window renders. |
||||
*/ |
||||
void spinOnce(int time = 1, bool force_redraw = false); |
||||
|
||||
/** @brief Create a window in memory instead of on the screen.
|
||||
*/ |
||||
void setOffScreenRendering(); |
||||
|
||||
/** @brief Remove all lights from the current scene.
|
||||
*/ |
||||
void removeAllLights(); |
||||
|
||||
/** @brief Add a light in the scene.
|
||||
|
||||
@param position The position of the light. |
||||
@param focalPoint The point at which the light is shining |
||||
@param color The color of the light |
||||
@param diffuseColor The diffuse color of the light |
||||
@param ambientColor The ambient color of the light |
||||
@param specularColor The specular color of the light |
||||
*/ |
||||
void addLight(const Vec3d &position, const Vec3d &focalPoint = Vec3d(0, 0, 0), const Color &color = Color::white(), |
||||
const Color &diffuseColor = Color::white(), const Color &ambientColor = Color::black(), |
||||
const Color &specularColor = Color::white()); |
||||
|
||||
/** @brief Returns whether the event loop has been stopped.
|
||||
*/ |
||||
bool wasStopped() const; |
||||
void close(); |
||||
|
||||
/** @brief Sets keyboard handler.
|
||||
|
||||
@param callback Keyboard callback (void (\*KeyboardCallbackFunction(const |
||||
KeyboardEvent&, void\*)). |
||||
@param cookie The optional parameter passed to the callback. |
||||
*/ |
||||
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); |
||||
|
||||
/** @brief Sets mouse handler.
|
||||
|
||||
@param callback Mouse callback (void (\*MouseCallback)(const MouseEvent&, void\*)). |
||||
@param cookie The optional parameter passed to the callback. |
||||
*/ |
||||
void registerMouseCallback(MouseCallback callback, void* cookie = 0); |
||||
|
||||
/** @brief 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** |
||||
- **FONT_SIZE** |
||||
|
||||
REPRESENTATION: Expected values are |
||||
- **REPRESENTATION_POINTS** |
||||
- **REPRESENTATION_WIREFRAME** |
||||
- **REPRESENTATION_SURFACE** |
||||
|
||||
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** |
||||
*/ |
||||
void setRenderingProperty(const String &id, int property, double value); |
||||
/** @brief 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** |
||||
- **FONT_SIZE** |
||||
|
||||
REPRESENTATION: Expected values are |
||||
- **REPRESENTATION_POINTS** |
||||
- **REPRESENTATION_WIREFRAME** |
||||
- **REPRESENTATION_SURFACE** |
||||
|
||||
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** |
||||
*/ |
||||
double getRenderingProperty(const String &id, int property); |
||||
|
||||
/** @brief Sets geometry representation of the widgets to surface, wireframe or points.
|
||||
|
||||
@param representation Geometry representation which can be one of the following: |
||||
- **REPRESENTATION_POINTS** |
||||
- **REPRESENTATION_WIREFRAME** |
||||
- **REPRESENTATION_SURFACE** |
||||
*/ |
||||
void setRepresentation(int representation); |
||||
|
||||
void setGlobalWarnings(bool enabled = false); |
||||
private: |
||||
|
||||
struct VizImpl; |
||||
VizImpl* impl_; |
||||
|
||||
void create(const String &window_name); |
||||
void release(); |
||||
|
||||
friend class VizStorage; |
||||
}; |
||||
|
||||
//! @}
|
||||
|
||||
} /* namespace viz */ |
||||
} /* namespace cv */ |
||||
|
||||
#endif |
@ -1,226 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIZCORE_HPP |
||||
#define OPENCV_VIZCORE_HPP |
||||
|
||||
#include <opencv2/viz/types.hpp> |
||||
#include <opencv2/viz/widgets.hpp> |
||||
#include <opencv2/viz/viz3d.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
|
||||
//! @addtogroup viz
|
||||
//! @{
|
||||
|
||||
/** @brief Takes coordinate frame data and builds transform to global coordinate frame.
|
||||
|
||||
@param axis_x X axis vector in global coordinate frame. |
||||
@param axis_y Y axis vector in global coordinate frame. |
||||
@param axis_z Z axis vector in global coordinate frame. |
||||
@param origin Origin of the coordinate frame in global coordinate frame. |
||||
|
||||
@return An affine transform that describes transformation between global coordinate frame |
||||
and a given coordinate frame. |
||||
The returned transforms can transform a point in the given coordinate frame to the global |
||||
coordinate frame. |
||||
*/ |
||||
CV_EXPORTS Affine3d makeTransformToGlobal(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin = Vec3d::all(0)); |
||||
|
||||
/** @brief Constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more
|
||||
information). |
||||
|
||||
@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. |
||||
*/ |
||||
CV_EXPORTS Affine3d makeCameraPose(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir); |
||||
|
||||
/** @brief Retrieves a window by its name.
|
||||
|
||||
@param window_name Name of the window that is to be retrieved. |
||||
|
||||
This function returns a 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 |
||||
/// window and window_2 are the same windows.
|
||||
viz::Viz3d window = viz::getWindowByName("myWindow"); |
||||
viz::Viz3d window_2 = viz::getWindowByName("Viz - myWindow"); |
||||
@endcode |
||||
*/ |
||||
CV_EXPORTS Viz3d getWindowByName(const String &window_name); |
||||
|
||||
//! Unregisters all Viz windows from internal database. After it 'getWindowByName()' will create new windows instead of getting existing from the database.
|
||||
CV_EXPORTS void unregisterAllWindows(); |
||||
|
||||
//! Displays image in specified window
|
||||
CV_EXPORTS Viz3d imshow(const String& window_name, InputArray image, const Size& window_size = Size(-1, -1)); |
||||
|
||||
/** @brief Checks **float/double** value for nan.
|
||||
|
||||
@param x return true if nan. |
||||
*/ |
||||
inline bool isNan(float x) |
||||
{ |
||||
unsigned int *u = reinterpret_cast<unsigned int *>(&x); |
||||
return ((u[0] & 0x7f800000) == 0x7f800000) && (u[0] & 0x007fffff); |
||||
} |
||||
|
||||
/** @brief Checks **float/double** value for nan.
|
||||
|
||||
@param x return true if nan. |
||||
*/ |
||||
inline bool isNan(double x) |
||||
{ |
||||
unsigned int *u = reinterpret_cast<unsigned int *>(&x); |
||||
return (u[1] & 0x7ff00000) == 0x7ff00000 && (u[0] != 0 || (u[1] & 0x000fffff) != 0); |
||||
} |
||||
|
||||
/** @brief Checks **float/double** value for nan.
|
||||
|
||||
@param v return true if **any** of the elements of the vector is *nan*. |
||||
*/ |
||||
template<typename _Tp, int cn> inline bool isNan(const Vec<_Tp, cn>& v) |
||||
{ return isNan(v.val[0]) || isNan(v.val[1]) || isNan(v.val[2]); } |
||||
|
||||
/** @brief Checks **float/double** value for nan.
|
||||
|
||||
@param p return true if **any** of the elements of the point is *nan*. |
||||
*/ |
||||
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p) |
||||
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); } |
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Read/write clouds. Supported formats: ply, xyz, obj and stl (readonly)
|
||||
|
||||
/**
|
||||
* @param file Filename with extension. Supported formats: PLY, XYZ and OBJ. |
||||
* @param cloud Supported depths: CV_32F and CV_64F. Supported channels: 3 and 4. |
||||
* @param colors Used by PLY format only. Supported depth: CV_8U. Supported channels: 1, 3 and 4. |
||||
* @param normals Used by PLY and OBJ format only. Supported depths: CV_32F and CV_64F. |
||||
* Supported channels: 3 and 4. |
||||
* @param binary Used only for PLY format. |
||||
*/ |
||||
CV_EXPORTS void writeCloud(const String& file, InputArray cloud, InputArray colors = noArray(), InputArray normals = noArray(), bool binary = false); |
||||
|
||||
/**
|
||||
* @param file Filename with extension. Supported formats: PLY, XYZ, OBJ and STL. |
||||
* @param colors Used by PLY and STL formats only. |
||||
* @param normals Used by PLY, OBJ and STL formats only. |
||||
* @return A mat containing the point coordinates with depth CV_32F or CV_64F and number of |
||||
* channels 3 or 4 with only 1 row. |
||||
*/ |
||||
CV_EXPORTS Mat readCloud (const String& file, OutputArray colors = noArray(), OutputArray normals = noArray()); |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Reads mesh. Only ply format is supported now and no texture load support
|
||||
|
||||
CV_EXPORTS Mesh readMesh(const String& file); |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Read/write poses and trajectories
|
||||
|
||||
/**
|
||||
* @param file Filename of type supported by cv::FileStorage. |
||||
* @param pose Output matrix. |
||||
* @param tag Name of the pose in the file. |
||||
*/ |
||||
CV_EXPORTS bool readPose(const String& file, Affine3d& pose, const String& tag = "pose"); |
||||
/**
|
||||
* @param file Filename. |
||||
* @param pose Input matrix. |
||||
* @param tag Name of the pose to be saved into the given file. |
||||
*/ |
||||
CV_EXPORTS void writePose(const String& file, const Affine3d& pose, const String& tag = "pose"); |
||||
|
||||
/** takes vector<Affine3<T>> with T = float/dobule and writes to a sequence of files with given filename format
|
||||
* @param traj Trajectory containing a list of poses. It can be |
||||
* - std::vector<cv::Mat>, each cv::Mat is of type CV_32F16 or CV_64FC16 |
||||
* - std::vector<cv::Affine3f>, std::vector<cv::Affine3d> |
||||
* - cv::Mat of type CV_32FC16 OR CV_64F16 |
||||
* @param files_format Format specifier string for constructing filenames. |
||||
* The only placeholder in the string should support `int`. |
||||
* @param start The initial counter for files_format. |
||||
* @param tag Name of the matrix in the file. |
||||
*/ |
||||
CV_EXPORTS void writeTrajectory(InputArray traj, const String& files_format = "pose%05d.xml", int start = 0, const String& tag = "pose"); |
||||
|
||||
/** takes vector<Affine3<T>> with T = float/dobule and loads poses from sequence of files
|
||||
* |
||||
* @param traj Output array containing a lists of poses. It can be |
||||
* - std::vector<cv::Affine3f>, std::vector<cv::Affine3d> |
||||
* - cv::Mat |
||||
* @param files_format Format specifier string for constructing filenames. |
||||
* The only placeholder in the string should support `int`. |
||||
* @param start The initial counter for files_format. It must be greater than or equal to 0. |
||||
* @param end The final counter for files_format. |
||||
* @param tag Name of the matrix in the file. |
||||
*/ |
||||
CV_EXPORTS void readTrajectory(OutputArray traj, const String& files_format = "pose%05d.xml", int start = 0, int end = INT_MAX, const String& tag = "pose"); |
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/** Computing normals for mesh
|
||||
* @param mesh Input mesh. |
||||
* @param normals Normals at very point in the mesh of type CV_64FC3. |
||||
*/ |
||||
CV_EXPORTS void computeNormals(const Mesh& mesh, OutputArray normals); |
||||
|
||||
//! @}
|
||||
|
||||
} /* namespace viz */ |
||||
} /* namespace cv */ |
||||
|
||||
#endif /* OPENCV_VIZCORE_HPP */ |
@ -1,89 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIZ_WIDGET_ACCESSOR_HPP |
||||
#define OPENCV_VIZ_WIDGET_ACCESSOR_HPP |
||||
|
||||
#include <opencv2/core/cvdef.h> |
||||
#include <vtkSmartPointer.h> |
||||
#include <vtkProp.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
|
||||
//! @addtogroup viz_widget
|
||||
//! @{
|
||||
|
||||
class Widget; |
||||
|
||||
/** @brief This class is for users who want to develop their own widgets using VTK library API. :
|
||||
*/ |
||||
struct CV_EXPORTS WidgetAccessor |
||||
{ |
||||
/** @brief Returns vtkProp of a given widget.
|
||||
|
||||
@param widget Widget whose vtkProp is to be returned. |
||||
|
||||
@note vtkProp has to be down cast appropriately to be modified. |
||||
@code |
||||
vtkActor * actor = vtkActor::SafeDownCast(viz::WidgetAccessor::getProp(widget)); |
||||
@endcode |
||||
*/ |
||||
static vtkSmartPointer<vtkProp> getProp(const Widget &widget); |
||||
/** @brief Sets vtkProp of a given widget.
|
||||
|
||||
@param widget Widget whose vtkProp is to be set. @param prop A vtkProp. |
||||
*/ |
||||
static void setProp(Widget &widget, vtkSmartPointer<vtkProp> prop); |
||||
}; |
||||
|
||||
//! @}
|
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
@ -1,850 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIZ_WIDGETS_HPP |
||||
#define OPENCV_VIZ_WIDGETS_HPP |
||||
|
||||
#include <opencv2/viz/types.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
|
||||
//! @addtogroup viz_widget
|
||||
//! @{
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Widget rendering properties
|
||||
enum RenderingProperties |
||||
{ |
||||
POINT_SIZE, |
||||
OPACITY, |
||||
LINE_WIDTH, |
||||
FONT_SIZE, |
||||
REPRESENTATION, |
||||
IMMEDIATE_RENDERING, |
||||
SHADING, |
||||
AMBIENT, |
||||
LIGHTING |
||||
}; |
||||
|
||||
enum RepresentationValues |
||||
{ |
||||
REPRESENTATION_POINTS, |
||||
REPRESENTATION_WIREFRAME, |
||||
REPRESENTATION_SURFACE |
||||
}; |
||||
|
||||
enum ShadingValues |
||||
{ |
||||
SHADING_FLAT, |
||||
SHADING_GOURAUD, |
||||
SHADING_PHONG |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** @brief Base class of all widgets. Widget is implicitly shared.
|
||||
*/ |
||||
class CV_EXPORTS Widget |
||||
{ |
||||
public: |
||||
Widget(); |
||||
Widget(const Widget& other); |
||||
Widget& operator=(const Widget& other); |
||||
virtual ~Widget(); |
||||
|
||||
/** @brief Creates a widget from ply file.
|
||||
|
||||
@param file_name Ply file name. |
||||
*/ |
||||
static Widget fromPlyFile(const String &file_name); |
||||
|
||||
/** @brief 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** |
||||
- **FONT_SIZE** |
||||
|
||||
REPRESENTATION: Expected values are |
||||
- **REPRESENTATION_POINTS** |
||||
- **REPRESENTATION_WIREFRAME** |
||||
- **REPRESENTATION_SURFACE** |
||||
|
||||
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** |
||||
*/ |
||||
void setRenderingProperty(int property, double value); |
||||
/** @brief Returns rendering property of the widget.
|
||||
|
||||
@param property Property. |
||||
|
||||
Rendering property can be one of the following: |
||||
- **POINT_SIZE** |
||||
- **OPACITY** |
||||
- **LINE_WIDTH** |
||||
- **FONT_SIZE** |
||||
- **AMBIENT** |
||||
|
||||
REPRESENTATION: Expected values are |
||||
- **REPRESENTATION_POINTS** |
||||
- **REPRESENTATION_WIREFRAME** |
||||
- **REPRESENTATION_SURFACE** |
||||
|
||||
**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** |
||||
*/ |
||||
double getRenderingProperty(int property) const; |
||||
|
||||
/** @brief Casts a widget to another.
|
||||
|
||||
@code |
||||
// Create a sphere widget
|
||||
viz::WSphere sw(Point3f(0.0f,0.0f,0.0f), 0.5f); |
||||
// Cast sphere widget to cloud widget
|
||||
viz::WCloud cw = sw.cast<viz::WCloud>(); |
||||
@endcode |
||||
|
||||
@note 3D Widgets can only be cast to 3D Widgets. 2D Widgets can only be cast to 2D Widgets. |
||||
*/ |
||||
template<typename _W> _W cast() const; |
||||
private: |
||||
class Impl; |
||||
Impl *impl_; |
||||
friend struct WidgetAccessor; |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** @brief Base class of all 3D widgets.
|
||||
*/ |
||||
class CV_EXPORTS Widget3D : public Widget |
||||
{ |
||||
public: |
||||
Widget3D() {} |
||||
|
||||
/** @brief Sets pose of the widget.
|
||||
|
||||
@param pose The new pose of the widget. |
||||
*/ |
||||
void setPose(const Affine3d &pose); |
||||
/** @brief Updates pose of the widget by pre-multiplying its current pose.
|
||||
|
||||
@param pose The pose that the current pose of the widget will be pre-multiplied by. |
||||
*/ |
||||
void updatePose(const Affine3d &pose); |
||||
/** @brief Returns the current pose of the widget.
|
||||
*/ |
||||
Affine3d getPose() const; |
||||
|
||||
/** @brief Transforms internal widget data (i.e. points, normals) using the given transform.
|
||||
|
||||
@param transform Specified transformation to apply. |
||||
*/ |
||||
void applyTransform(const Affine3d &transform); |
||||
|
||||
/** @brief Sets the color of the widget.
|
||||
|
||||
@param color color of type Color |
||||
*/ |
||||
void setColor(const Color &color); |
||||
|
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** @brief Base class of all 2D widgets.
|
||||
*/ |
||||
class CV_EXPORTS Widget2D : public Widget |
||||
{ |
||||
public: |
||||
Widget2D() {} |
||||
|
||||
/** @brief Sets the color of the widget.
|
||||
|
||||
@param color color of type Color |
||||
*/ |
||||
void setColor(const Color &color); |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Simple widgets
|
||||
|
||||
/** @brief This 3D Widget defines a finite line.
|
||||
*/ |
||||
class CV_EXPORTS WLine : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WLine.
|
||||
|
||||
@param pt1 Start point of the line. |
||||
@param pt2 End point of the line. |
||||
@param color Color of the line. |
||||
*/ |
||||
WLine(const Point3d &pt1, const Point3d &pt2, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a finite plane.
|
||||
*/ |
||||
class CV_EXPORTS WPlane : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a default plane with center point at origin and normal oriented along z-axis.
|
||||
|
||||
@param size Size of the plane |
||||
@param color Color of the plane. |
||||
*/ |
||||
WPlane(const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); |
||||
|
||||
/** @brief Constructs a repositioned plane
|
||||
|
||||
@param center Center of the plane |
||||
@param normal Plane normal orientation |
||||
@param new_yaxis Up-vector. New orientation of plane y-axis. |
||||
@param size |
||||
@param color Color of the plane. |
||||
*/ |
||||
WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, |
||||
const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a sphere. :
|
||||
*/ |
||||
class CV_EXPORTS WSphere : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WSphere.
|
||||
|
||||
@param center Center of the sphere. |
||||
@param radius Radius of the sphere. |
||||
@param sphere_resolution Resolution of the sphere. |
||||
@param color Color of the sphere. |
||||
*/ |
||||
WSphere(const cv::Point3d ¢er, double radius, int sphere_resolution = 10, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines an arrow.
|
||||
*/ |
||||
class CV_EXPORTS WArrow : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs an WArrow.
|
||||
|
||||
@param pt1 Start point of the arrow. |
||||
@param pt2 End point of the arrow. |
||||
@param thickness Thickness of the arrow. Thickness of arrow head is also adjusted |
||||
accordingly. |
||||
@param color Color of the arrow. |
||||
|
||||
Arrow head is located at the end point of the arrow. |
||||
*/ |
||||
WArrow(const Point3d& pt1, const Point3d& pt2, double thickness = 0.03, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a circle.
|
||||
*/ |
||||
class CV_EXPORTS WCircle : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs default planar circle centered at origin with plane normal along z-axis
|
||||
|
||||
@param radius Radius of the circle. |
||||
@param thickness Thickness of the circle. |
||||
@param color Color of the circle. |
||||
*/ |
||||
WCircle(double radius, double thickness = 0.01, const Color &color = Color::white()); |
||||
|
||||
/** @brief Constructs repositioned planar circle.
|
||||
|
||||
@param radius Radius of the circle. |
||||
@param center Center of the circle. |
||||
@param normal Normal of the plane in which the circle lies. |
||||
@param thickness Thickness of the circle. |
||||
@param color Color of the circle. |
||||
*/ |
||||
WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a cone. :
|
||||
*/ |
||||
class CV_EXPORTS WCone : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs default cone oriented along x-axis with center of its base located at origin
|
||||
|
||||
@param length Length of the cone. |
||||
@param radius Radius of the cone. |
||||
@param resolution Resolution of the cone. |
||||
@param color Color of the cone. |
||||
*/ |
||||
WCone(double length, double radius, int resolution = 6.0, const Color &color = Color::white()); |
||||
|
||||
/** @brief Constructs repositioned planar cone.
|
||||
|
||||
@param radius Radius of the cone. |
||||
@param center Center of the cone base. |
||||
@param tip Tip of the cone. |
||||
@param resolution Resolution of the cone. |
||||
@param color Color of the cone. |
||||
|
||||
*/ |
||||
WCone(double radius, const Point3d& center, const Point3d& tip, int resolution = 6.0, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a cylinder. :
|
||||
*/ |
||||
class CV_EXPORTS WCylinder : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WCylinder.
|
||||
|
||||
@param axis_point1 A point1 on the axis of the cylinder. |
||||
@param axis_point2 A point2 on the axis of the cylinder. |
||||
@param radius Radius of the cylinder. |
||||
@param numsides Resolution of the cylinder. |
||||
@param color Color of the cylinder. |
||||
*/ |
||||
WCylinder(const Point3d& axis_point1, const Point3d& axis_point2, double radius, int numsides = 30, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a cube.
|
||||
*/ |
||||
class CV_EXPORTS WCube : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WCube.
|
||||
|
||||
@param min_point Specifies minimum point of the bounding box. |
||||
@param max_point Specifies maximum point of the bounding box. |
||||
@param wire_frame If true, cube is represented as wireframe. |
||||
@param color Color of the cube. |
||||
|
||||
 |
||||
*/ |
||||
WCube(const Point3d& min_point = Vec3d::all(-0.5), const Point3d& max_point = Vec3d::all(0.5), |
||||
bool wire_frame = true, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a poly line. :
|
||||
*/ |
||||
class CV_EXPORTS WPolyLine : public Widget3D |
||||
{ |
||||
public: |
||||
WPolyLine(InputArray points, InputArray colors); |
||||
/** @brief Constructs a WPolyLine.
|
||||
|
||||
@param points Point set. |
||||
@param color Color of the poly line. |
||||
*/ |
||||
WPolyLine(InputArray points, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Text and image widgets
|
||||
|
||||
/** @brief This 2D Widget represents text overlay.
|
||||
*/ |
||||
class CV_EXPORTS WText : public Widget2D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WText.
|
||||
|
||||
@param text Text content of the widget. |
||||
@param pos Position of the text. |
||||
@param font_size Font size. |
||||
@param color Color of the text. |
||||
*/ |
||||
WText(const String &text, const Point &pos, int font_size = 20, const Color &color = Color::white()); |
||||
|
||||
/** @brief Sets the text content of the widget.
|
||||
|
||||
@param text Text content of the widget. |
||||
*/ |
||||
void setText(const String &text); |
||||
/** @brief Returns the current text content of the widget.
|
||||
*/ |
||||
String getText() const; |
||||
}; |
||||
|
||||
/** @brief This 3D Widget represents 3D text. The text always faces the camera.
|
||||
*/ |
||||
class CV_EXPORTS WText3D : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WText3D.
|
||||
|
||||
@param text Text content of the widget. |
||||
@param position Position of the text. |
||||
@param text_scale Size of the text. |
||||
@param face_camera If true, text always faces the camera. |
||||
@param color Color of the text. |
||||
*/ |
||||
WText3D(const String &text, const Point3d &position, double text_scale = 1., bool face_camera = true, const Color &color = Color::white()); |
||||
|
||||
/** @brief Sets the text content of the widget.
|
||||
|
||||
@param text Text content of the widget. |
||||
|
||||
*/ |
||||
void setText(const String &text); |
||||
/** @brief Returns the current text content of the widget.
|
||||
*/ |
||||
String getText() const; |
||||
}; |
||||
|
||||
/** @brief This 2D Widget represents an image overlay. :
|
||||
*/ |
||||
class CV_EXPORTS WImageOverlay : public Widget2D |
||||
{ |
||||
public: |
||||
/** @brief Constructs an WImageOverlay.
|
||||
|
||||
@param image BGR or Gray-Scale image. |
||||
@param rect Image is scaled and positioned based on rect. |
||||
*/ |
||||
WImageOverlay(InputArray image, const Rect &rect); |
||||
/** @brief Sets the image content of the widget.
|
||||
|
||||
@param image BGR or Gray-Scale image. |
||||
*/ |
||||
void setImage(InputArray image); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget represents an image in 3D space. :
|
||||
*/ |
||||
class CV_EXPORTS WImage3D : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs an WImage3D.
|
||||
|
||||
@param image BGR or Gray-Scale image. |
||||
@param size Size of the image. |
||||
*/ |
||||
WImage3D(InputArray image, const Size2d &size); |
||||
|
||||
/** @brief Constructs an WImage3D.
|
||||
|
||||
@param image BGR or Gray-Scale image. |
||||
@param size Size of the image. |
||||
@param center Position of the image. |
||||
@param normal Normal of the plane that represents the image. |
||||
@param up_vector Determines orientation of the image. |
||||
*/ |
||||
WImage3D(InputArray image, const Size2d &size, const Vec3d ¢er, const Vec3d &normal, const Vec3d &up_vector); |
||||
|
||||
/** @brief Sets the image content of the widget.
|
||||
|
||||
@param image BGR or Gray-Scale image. |
||||
*/ |
||||
void setImage(InputArray image); |
||||
|
||||
/** @brief Sets the image size of the widget.
|
||||
|
||||
@param size the new size of the image. |
||||
*/ |
||||
void setSize(const Size& size); |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Compound widgets
|
||||
|
||||
/** @brief This 3D Widget represents a coordinate system. :
|
||||
*/ |
||||
class CV_EXPORTS WCoordinateSystem : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WCoordinateSystem.
|
||||
|
||||
@param scale Determines the size of the axes. |
||||
*/ |
||||
WCoordinateSystem(double scale = 1.0); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a grid. :
|
||||
*/ |
||||
class CV_EXPORTS WGrid : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WGrid.
|
||||
|
||||
@param cells Number of cell columns and rows, respectively. |
||||
@param cells_spacing Size of each cell, respectively. |
||||
@param color Color of the grid. |
||||
*/ |
||||
WGrid(const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const Color &color = Color::white()); |
||||
|
||||
//! Creates repositioned grid
|
||||
WGrid(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis, |
||||
const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget represents camera position in a scene by its axes or viewing frustum. :
|
||||
*/ |
||||
class CV_EXPORTS WCameraPosition : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Creates camera coordinate frame at the origin.
|
||||
|
||||
 |
||||
*/ |
||||
WCameraPosition(double scale = 1.0); |
||||
/** @brief Display the viewing frustum
|
||||
@param K Intrinsic matrix of the camera. |
||||
@param scale Scale of the frustum. |
||||
@param color Color of the frustum. |
||||
|
||||
Creates viewing frustum of the camera based on its intrinsic matrix K. |
||||
|
||||
 |
||||
*/ |
||||
WCameraPosition(const Matx33d &K, double scale = 1.0, const Color &color = Color::white()); |
||||
/** @brief Display the viewing frustum
|
||||
@param fov Field of view of the camera (horizontal, vertical). |
||||
@param scale Scale of the frustum. |
||||
@param color Color of the frustum. |
||||
|
||||
Creates viewing frustum of the camera based on its field of view fov. |
||||
|
||||
 |
||||
*/ |
||||
WCameraPosition(const Vec2d &fov, double scale = 1.0, const Color &color = Color::white()); |
||||
/** @brief Display image on the far plane of the viewing frustum
|
||||
|
||||
@param K Intrinsic matrix of the camera. |
||||
@param image 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 Color of the frustum. |
||||
|
||||
Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on |
||||
the far end plane. |
||||
|
||||
 |
||||
*/ |
||||
WCameraPosition(const Matx33d &K, InputArray image, double scale = 1.0, const Color &color = Color::white()); |
||||
/** @brief Display image on the far plane of the viewing frustum
|
||||
|
||||
@param fov Field of view of the camera (horizontal, vertical). |
||||
@param image 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 Color of the frustum. |
||||
|
||||
Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on |
||||
the far end plane. |
||||
|
||||
 |
||||
*/ |
||||
WCameraPosition(const Vec2d &fov, InputArray image, double scale = 1.0, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Trajectories
|
||||
|
||||
/** @brief This 3D Widget represents a trajectory. :
|
||||
*/ |
||||
class CV_EXPORTS WTrajectory : public Widget3D |
||||
{ |
||||
public: |
||||
enum {FRAMES = 1, PATH = 2, BOTH = FRAMES + PATH }; |
||||
|
||||
/** @brief Constructs a WTrajectory.
|
||||
|
||||
@param path List of poses on a trajectory. Takes std::vector\<Affine\<T\>\> with T == [float | double] |
||||
@param display_mode Display mode. This can be PATH, FRAMES, and BOTH. |
||||
@param scale Scale of the frames. Polyline is not affected. |
||||
@param color Color of the polyline that represents path. |
||||
|
||||
Frames are not affected. |
||||
Displays trajectory of the given path as follows: |
||||
- PATH : Displays a poly line that represents the path. |
||||
- FRAMES : Displays coordinate frames at each pose. |
||||
- PATH & FRAMES : Displays both poly line and coordinate frames. |
||||
*/ |
||||
WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, double scale = 1.0, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget represents a trajectory. :
|
||||
*/ |
||||
class CV_EXPORTS WTrajectoryFrustums : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WTrajectoryFrustums.
|
||||
|
||||
@param path List of poses on a trajectory. Takes std::vector\<Affine\<T\>\> with T == [float | double] |
||||
@param K Intrinsic matrix of the camera. |
||||
@param scale Scale of the frustums. |
||||
@param color Color of the frustums. |
||||
|
||||
Displays frustums at each pose of the trajectory. |
||||
*/ |
||||
WTrajectoryFrustums(InputArray path, const Matx33d &K, double scale = 1., const Color &color = Color::white()); |
||||
|
||||
/** @brief Constructs a WTrajectoryFrustums.
|
||||
|
||||
@param path List of poses on a trajectory. Takes std::vector\<Affine\<T\>\> with T == [float | double] |
||||
@param fov Field of view of the camera (horizontal, vertical). |
||||
@param scale Scale of the frustums. |
||||
@param color Color of the frustums. |
||||
|
||||
Displays frustums at each pose of the trajectory. |
||||
*/ |
||||
WTrajectoryFrustums(InputArray path, const Vec2d &fov, double scale = 1., const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget represents a trajectory using spheres and lines
|
||||
|
||||
where spheres represent the positions of the camera, and lines represent the direction from |
||||
previous position to the current. : |
||||
*/ |
||||
class CV_EXPORTS WTrajectorySpheres: public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WTrajectorySpheres.
|
||||
|
||||
@param path List of poses on a trajectory. Takes std::vector\<Affine\<T\>\> with T == [float | double] |
||||
@param line_length Max length of the lines which point to previous position |
||||
@param radius Radius of the spheres. |
||||
@param from Color for first sphere. |
||||
@param to Color for last sphere. Intermediate spheres will have interpolated color. |
||||
*/ |
||||
WTrajectorySpheres(InputArray path, double line_length = 0.05, double radius = 0.007, |
||||
const Color &from = Color::red(), const Color &to = Color::white()); |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Clouds
|
||||
|
||||
/** @brief This 3D Widget defines a point cloud. :
|
||||
|
||||
@note In case there are four channels in the cloud, fourth channel is ignored. |
||||
*/ |
||||
class CV_EXPORTS WCloud: public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief 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). |
||||
*/ |
||||
WCloud(InputArray cloud, InputArray colors); |
||||
|
||||
/** @brief Constructs a WCloud.
|
||||
@param cloud Set of points which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. |
||||
@param color A single Color for the whole cloud. |
||||
|
||||
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). |
||||
*/ |
||||
WCloud(InputArray cloud, const Color &color = Color::white()); |
||||
|
||||
/** @brief 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. |
||||
@param normals Normals for each point in cloud. Size and type should match with the cloud parameter. |
||||
|
||||
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). |
||||
*/ |
||||
WCloud(InputArray cloud, InputArray colors, InputArray normals); |
||||
|
||||
/** @brief Constructs a WCloud.
|
||||
@param cloud Set of points which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. |
||||
@param color A single Color for the whole cloud. |
||||
@param normals Normals for each point in cloud. |
||||
|
||||
Size and type should match with the cloud parameter. |
||||
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). |
||||
*/ |
||||
WCloud(InputArray cloud, const Color &color, InputArray normals); |
||||
}; |
||||
|
||||
class CV_EXPORTS WPaintedCloud: public Widget3D |
||||
{ |
||||
public: |
||||
//! Paint cloud with default gradient between cloud bounds points
|
||||
WPaintedCloud(InputArray cloud); |
||||
|
||||
//! Paint cloud with default gradient between given points
|
||||
WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2); |
||||
|
||||
//! Paint cloud with gradient specified by given colors between given points
|
||||
WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2, const Color& c1, const Color c2); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget defines a collection of clouds. :
|
||||
@note In case there are four channels in the cloud, fourth channel is ignored. |
||||
*/ |
||||
class CV_EXPORTS WCloudCollection : public Widget3D |
||||
{ |
||||
public: |
||||
WCloudCollection(); |
||||
|
||||
/** @brief 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). |
||||
*/ |
||||
void addCloud(InputArray cloud, InputArray colors, const Affine3d &pose = Affine3d::Identity()); |
||||
/** @brief Adds a cloud to the collection.
|
||||
|
||||
@param cloud Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. |
||||
@param color A single 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). |
||||
*/ |
||||
void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3d &pose = Affine3d::Identity()); |
||||
/** @brief Finalizes cloud data by repacking to single cloud.
|
||||
|
||||
Useful for large cloud collections to reduce memory usage |
||||
*/ |
||||
void finalize(); |
||||
}; |
||||
|
||||
/** @brief This 3D Widget represents normals of a point cloud. :
|
||||
*/ |
||||
class CV_EXPORTS WCloudNormals : public Widget3D |
||||
{ |
||||
public: |
||||
/** @brief Constructs a WCloudNormals.
|
||||
|
||||
@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 Color of the arrows that represent normals. |
||||
|
||||
@note In case there are four channels in the cloud, fourth channel is ignored. |
||||
*/ |
||||
WCloudNormals(InputArray cloud, InputArray normals, int level = 64, double scale = 0.1, const Color &color = Color::white()); |
||||
}; |
||||
|
||||
/** @brief Constructs a WMesh.
|
||||
|
||||
@param mesh Mesh object that will be displayed. |
||||
@param cloud Points of the mesh object. |
||||
@param polygons Points of the mesh object. |
||||
@param colors Point colors. |
||||
@param normals Point normals. |
||||
*/ |
||||
class CV_EXPORTS WMesh : public Widget3D |
||||
{ |
||||
public: |
||||
WMesh(const Mesh &mesh); |
||||
WMesh(InputArray cloud, InputArray polygons, InputArray colors = noArray(), InputArray normals = noArray()); |
||||
}; |
||||
|
||||
/** @brief This class allows to merge several widgets to single one.
|
||||
|
||||
It has quite limited functionality and can't merge widgets with different attributes. For |
||||
instance, if widgetA has color array and widgetB has only global color defined, then result |
||||
of merge won't have color at all. The class is suitable for merging large amount of similar |
||||
widgets. : |
||||
*/ |
||||
class CV_EXPORTS WWidgetMerger : public Widget3D |
||||
{ |
||||
public: |
||||
WWidgetMerger(); |
||||
|
||||
//! Add widget to merge with optional position change
|
||||
void addWidget(const Widget3D& widget, const Affine3d &pose = Affine3d::Identity()); |
||||
|
||||
//! Repacks internal structure to single widget
|
||||
void finalize(); |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// Utility exports
|
||||
|
||||
template<> CV_EXPORTS Widget2D Widget::cast<Widget2D>() const; |
||||
template<> CV_EXPORTS Widget3D Widget::cast<Widget3D>() const; |
||||
template<> CV_EXPORTS WLine Widget::cast<WLine>() const; |
||||
template<> CV_EXPORTS WPlane Widget::cast<WPlane>() const; |
||||
template<> CV_EXPORTS WSphere Widget::cast<WSphere>() const; |
||||
template<> CV_EXPORTS WCylinder Widget::cast<WCylinder>() const; |
||||
template<> CV_EXPORTS WArrow Widget::cast<WArrow>() const; |
||||
template<> CV_EXPORTS WCircle Widget::cast<WCircle>() const; |
||||
template<> CV_EXPORTS WCone Widget::cast<WCone>() const; |
||||
template<> CV_EXPORTS WCube Widget::cast<WCube>() const; |
||||
template<> CV_EXPORTS WCoordinateSystem Widget::cast<WCoordinateSystem>() const; |
||||
template<> CV_EXPORTS WPolyLine Widget::cast<WPolyLine>() const; |
||||
template<> CV_EXPORTS WGrid Widget::cast<WGrid>() const; |
||||
template<> CV_EXPORTS WText3D Widget::cast<WText3D>() const; |
||||
template<> CV_EXPORTS WText Widget::cast<WText>() const; |
||||
template<> CV_EXPORTS WImageOverlay Widget::cast<WImageOverlay>() const; |
||||
template<> CV_EXPORTS WImage3D Widget::cast<WImage3D>() const; |
||||
template<> CV_EXPORTS WCameraPosition Widget::cast<WCameraPosition>() const; |
||||
template<> CV_EXPORTS WTrajectory Widget::cast<WTrajectory>() const; |
||||
template<> CV_EXPORTS WTrajectoryFrustums Widget::cast<WTrajectoryFrustums>() const; |
||||
template<> CV_EXPORTS WTrajectorySpheres Widget::cast<WTrajectorySpheres>() const; |
||||
template<> CV_EXPORTS WCloud Widget::cast<WCloud>() const; |
||||
template<> CV_EXPORTS WPaintedCloud Widget::cast<WPaintedCloud>() const; |
||||
template<> CV_EXPORTS WCloudCollection Widget::cast<WCloudCollection>() const; |
||||
template<> CV_EXPORTS WCloudNormals Widget::cast<WCloudNormals>() const; |
||||
template<> CV_EXPORTS WMesh Widget::cast<WMesh>() const; |
||||
template<> CV_EXPORTS WWidgetMerger Widget::cast<WWidgetMerger>() const; |
||||
|
||||
//! @}
|
||||
|
||||
} /* namespace viz */ |
||||
} /* namespace cv */ |
||||
|
||||
#endif |
@ -1,530 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Point Cloud Widget implementation
|
||||
|
||||
cv::viz::WCloud::WCloud(InputArray cloud, InputArray colors) |
||||
{ |
||||
WCloud cloud_widget(cloud, colors, cv::noArray()); |
||||
*this = cloud_widget; |
||||
} |
||||
|
||||
cv::viz::WCloud::WCloud(InputArray cloud, const Color &color) |
||||
{ |
||||
WCloud cloud_widget(cloud, Mat(cloud.size(), CV_8UC3, color)); |
||||
*this = cloud_widget; |
||||
} |
||||
|
||||
cv::viz::WCloud::WCloud(InputArray cloud, const Color &color, InputArray normals) |
||||
{ |
||||
WCloud cloud_widget(cloud, Mat(cloud.size(), CV_8UC3, color), normals); |
||||
*this = cloud_widget; |
||||
} |
||||
|
||||
cv::viz::WCloud::WCloud(cv::InputArray cloud, cv::InputArray colors, cv::InputArray normals) |
||||
{ |
||||
CV_Assert(!cloud.empty() && !colors.empty()); |
||||
|
||||
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); |
||||
cloud_source->SetColorCloudNormals(cloud, colors, normals); |
||||
cloud_source->Update(); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
||||
VtkUtils::SetInputData(mapper, cloud_source->GetOutput()); |
||||
mapper->SetScalarModeToUsePointData(); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
mapper->SetScalarRange(0, 255); |
||||
mapper->ScalarVisibilityOn(); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->BackfaceCullingOn(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
template<> cv::viz::WCloud cv::viz::Widget::cast<cv::viz::WCloud>() const |
||||
{ |
||||
Widget3D widget = this->cast<Widget3D>(); |
||||
return static_cast<WCloud&>(widget); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Painted Cloud Widget implementation
|
||||
|
||||
cv::viz::WPaintedCloud::WPaintedCloud(InputArray cloud) |
||||
{ |
||||
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); |
||||
cloud_source->SetCloud(cloud); |
||||
cloud_source->Update(); |
||||
|
||||
Vec6d bounds(cloud_source->GetOutput()->GetPoints()->GetBounds()); |
||||
|
||||
vtkSmartPointer<vtkElevationFilter> elevation = vtkSmartPointer<vtkElevationFilter>::New(); |
||||
elevation->SetInputConnection(cloud_source->GetOutputPort()); |
||||
elevation->SetLowPoint(bounds[0], bounds[2], bounds[4]); |
||||
elevation->SetHighPoint(bounds[1], bounds[3], bounds[5]); |
||||
elevation->SetScalarRange(0.0, 1.0); |
||||
elevation->Update(); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
||||
VtkUtils::SetInputData(mapper, vtkPolyData::SafeDownCast(elevation->GetOutput())); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
mapper->ScalarVisibilityOn(); |
||||
mapper->SetColorModeToMapScalars(); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->BackfaceCullingOn(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
cv::viz::WPaintedCloud::WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2) |
||||
{ |
||||
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); |
||||
cloud_source->SetCloud(cloud); |
||||
|
||||
vtkSmartPointer<vtkElevationFilter> elevation = vtkSmartPointer<vtkElevationFilter>::New(); |
||||
elevation->SetInputConnection(cloud_source->GetOutputPort()); |
||||
elevation->SetLowPoint(p1.x, p1.y, p1.z); |
||||
elevation->SetHighPoint(p2.x, p2.y, p2.z); |
||||
elevation->SetScalarRange(0.0, 1.0); |
||||
elevation->Update(); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
||||
VtkUtils::SetInputData(mapper, vtkPolyData::SafeDownCast(elevation->GetOutput())); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
mapper->ScalarVisibilityOn(); |
||||
mapper->SetColorModeToMapScalars(); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->BackfaceCullingOn(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
cv::viz::WPaintedCloud::WPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2, const Color& c1, const Color c2) |
||||
{ |
||||
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); |
||||
cloud_source->SetCloud(cloud); |
||||
|
||||
vtkSmartPointer<vtkElevationFilter> elevation = vtkSmartPointer<vtkElevationFilter>::New(); |
||||
elevation->SetInputConnection(cloud_source->GetOutputPort()); |
||||
elevation->SetLowPoint(p1.x, p1.y, p1.z); |
||||
elevation->SetHighPoint(p2.x, p2.y, p2.z); |
||||
elevation->SetScalarRange(0.0, 1.0); |
||||
elevation->Update(); |
||||
|
||||
Color vc1 = vtkcolor(c1), vc2 = vtkcolor(c2); |
||||
vtkSmartPointer<vtkColorTransferFunction> color_transfer = vtkSmartPointer<vtkColorTransferFunction>::New(); |
||||
color_transfer->SetColorSpaceToRGB(); |
||||
color_transfer->AddRGBPoint(0.0, vc1[0], vc1[1], vc1[2]); |
||||
color_transfer->AddRGBPoint(1.0, vc2[0], vc2[1], vc2[2]); |
||||
color_transfer->SetScaleToLinear(); |
||||
color_transfer->Build(); |
||||
|
||||
//if in future some need to replace color table with real scalars, then this can be done usine next calls:
|
||||
//vtkDataArray *float_scalars = vtkPolyData::SafeDownCast(elevation->GetOutput())->GetPointData()->GetArray("Elevation");
|
||||
//vtkSmartPointer<vtkPolyData> polydata = cloud_source->GetOutput();
|
||||
//polydata->GetPointData()->SetScalars(color_transfer->MapScalars(float_scalars, VTK_COLOR_MODE_DEFAULT, 0));
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
||||
VtkUtils::SetInputData(mapper, vtkPolyData::SafeDownCast(elevation->GetOutput())); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
mapper->ScalarVisibilityOn(); |
||||
mapper->SetColorModeToMapScalars(); |
||||
mapper->SetLookupTable(color_transfer); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->BackfaceCullingOn(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
template<> cv::viz::WPaintedCloud cv::viz::Widget::cast<cv::viz::WPaintedCloud>() const |
||||
{ |
||||
Widget3D widget = this->cast<Widget3D>(); |
||||
return static_cast<WPaintedCloud&>(widget); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Cloud Collection Widget implementation
|
||||
|
||||
cv::viz::WCloudCollection::WCloudCollection() |
||||
{ |
||||
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkSmartPointer<vtkAppendPolyData>::New(); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
||||
mapper->SetInputConnection(append_filter->GetOutputPort()); |
||||
mapper->SetScalarModeToUsePointData(); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
mapper->SetScalarRange(0, 255); |
||||
mapper->ScalarVisibilityOn(); |
||||
|
||||
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New(); |
||||
actor->SetNumberOfCloudPoints(1); |
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->BackfaceCullingOn(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, const Affine3d &pose) |
||||
{ |
||||
vtkSmartPointer<vtkCloudMatSource> source = vtkSmartPointer<vtkCloudMatSource>::New(); |
||||
source->SetColorCloud(cloud, colors); |
||||
|
||||
vtkSmartPointer<vtkPolyData> polydata = VtkUtils::TransformPolydata(source->GetOutputPort(), pose); |
||||
|
||||
vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Correctness check." && actor); |
||||
|
||||
vtkSmartPointer<vtkAlgorithm> producer = actor->GetMapper()->GetInputConnection(0, 0)->GetProducer(); |
||||
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkAppendPolyData::SafeDownCast(producer); |
||||
VtkUtils::AddInputData(append_filter, polydata); |
||||
|
||||
actor->SetNumberOfCloudPoints(std::max<vtkIdType>(1, actor->GetNumberOfCloudPoints() + polydata->GetNumberOfPoints()/10)); |
||||
} |
||||
|
||||
void cv::viz::WCloudCollection::addCloud(InputArray cloud, const Color &color, const Affine3d &pose) |
||||
{ |
||||
addCloud(cloud, Mat(cloud.size(), CV_8UC3, color), pose); |
||||
} |
||||
|
||||
void cv::viz::WCloudCollection::finalize() |
||||
{ |
||||
vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Incompatible widget type." && actor); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); |
||||
CV_Assert("Need to add at least one cloud." && mapper); |
||||
|
||||
vtkSmartPointer<vtkAlgorithm> producer = mapper->GetInputConnection(0, 0)->GetProducer(); |
||||
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkAppendPolyData::SafeDownCast(producer); |
||||
append_filter->Update(); |
||||
|
||||
vtkSmartPointer<vtkPolyData> polydata = append_filter->GetOutput(); |
||||
mapper->RemoveInputConnection(0, 0); |
||||
VtkUtils::SetInputData(mapper, polydata); |
||||
} |
||||
|
||||
template<> cv::viz::WCloudCollection cv::viz::Widget::cast<cv::viz::WCloudCollection>() const |
||||
{ |
||||
Widget3D widget = this->cast<Widget3D>(); |
||||
return static_cast<WCloudCollection&>(widget); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Cloud Normals Widget implementation
|
||||
|
||||
cv::viz::WCloudNormals::WCloudNormals(InputArray _cloud, InputArray _normals, int level, double scale, const Color &color) |
||||
{ |
||||
Mat cloud = _cloud.getMat(); |
||||
Mat normals = _normals.getMat(); |
||||
|
||||
CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4); |
||||
CV_Assert(cloud.size() == normals.size() && cloud.type() == normals.type()); |
||||
|
||||
int sqlevel = (int)std::sqrt((double)level); |
||||
int ystep = (cloud.cols > 1 && cloud.rows > 1) ? sqlevel : 1; |
||||
int xstep = (cloud.cols > 1 && cloud.rows > 1) ? sqlevel : level; |
||||
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); |
||||
points->SetDataType(cloud.depth() == CV_32F ? VTK_FLOAT : VTK_DOUBLE); |
||||
|
||||
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); |
||||
|
||||
int s_chs = cloud.channels(); |
||||
int n_chs = normals.channels(); |
||||
int total = 0; |
||||
|
||||
for(int y = 0; y < cloud.rows; y += ystep) |
||||
{ |
||||
if (cloud.depth() == CV_32F) |
||||
{ |
||||
const float *srow = cloud.ptr<float>(y); |
||||
const float *send = srow + cloud.cols * s_chs; |
||||
const float *nrow = normals.ptr<float>(y); |
||||
|
||||
for (; srow < send; srow += xstep * s_chs, nrow += xstep * n_chs) |
||||
if (!isNan(srow) && !isNan(nrow)) |
||||
{ |
||||
Vec3f endp = Vec3f(srow) + Vec3f(nrow) * (float)scale; |
||||
|
||||
points->InsertNextPoint(srow); |
||||
points->InsertNextPoint(endp.val); |
||||
|
||||
lines->InsertNextCell(2); |
||||
lines->InsertCellPoint(total++); |
||||
lines->InsertCellPoint(total++); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
const double *srow = cloud.ptr<double>(y); |
||||
const double *send = srow + cloud.cols * s_chs; |
||||
const double *nrow = normals.ptr<double>(y); |
||||
|
||||
for (; srow < send; srow += xstep * s_chs, nrow += xstep * n_chs) |
||||
if (!isNan(srow) && !isNan(nrow)) |
||||
{ |
||||
Vec3d endp = Vec3d(srow) + Vec3d(nrow) * (double)scale; |
||||
|
||||
points->InsertNextPoint(srow); |
||||
points->InsertNextPoint(endp.val); |
||||
|
||||
lines->InsertNextCell(2); |
||||
lines->InsertCellPoint(total++); |
||||
lines->InsertCellPoint(total++); |
||||
} |
||||
} |
||||
} |
||||
|
||||
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New(); |
||||
polydata->SetPoints(points); |
||||
polydata->SetLines(lines); |
||||
VtkUtils::FillScalars(polydata, color); |
||||
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); |
||||
VtkUtils::SetInputData(mapper, polydata); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
template<> cv::viz::WCloudNormals cv::viz::Widget::cast<cv::viz::WCloudNormals>() const |
||||
{ |
||||
Widget3D widget = this->cast<Widget3D>(); |
||||
return static_cast<WCloudNormals&>(widget); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Mesh Widget implementation
|
||||
|
||||
cv::viz::WMesh::WMesh(const Mesh &mesh) |
||||
{ |
||||
CV_Assert(mesh.cloud.rows == 1 && mesh.polygons.type() == CV_32SC1); |
||||
|
||||
vtkSmartPointer<vtkCloudMatSource> source = vtkSmartPointer<vtkCloudMatSource>::New(); |
||||
source->SetColorCloudNormalsTCoords(mesh.cloud, mesh.colors, mesh.normals, mesh.tcoords); |
||||
source->Update(); |
||||
|
||||
Mat lookup_buffer(1, (int)mesh.cloud.total(), CV_32SC1); |
||||
int *lookup = lookup_buffer.ptr<int>(); |
||||
for(int y = 0, index = 0; y < mesh.cloud.rows; ++y) |
||||
{ |
||||
int s_chs = mesh.cloud.channels(); |
||||
|
||||
if (mesh.cloud.depth() == CV_32F) |
||||
{ |
||||
const float* srow = mesh.cloud.ptr<float>(y); |
||||
const float* send = srow + mesh.cloud.cols * s_chs; |
||||
|
||||
for (; srow != send; srow += s_chs, ++lookup) |
||||
if (!isNan(srow[0]) && !isNan(srow[1]) && !isNan(srow[2])) |
||||
*lookup = index++; |
||||
} |
||||
|
||||
if (mesh.cloud.depth() == CV_64F) |
||||
{ |
||||
const double* srow = mesh.cloud.ptr<double>(y); |
||||
const double* send = srow + mesh.cloud.cols * s_chs; |
||||
|
||||
for (; srow != send; srow += s_chs, ++lookup) |
||||
if (!isNan(srow[0]) && !isNan(srow[1]) && !isNan(srow[2])) |
||||
*lookup = index++; |
||||
} |
||||
} |
||||
lookup = lookup_buffer.ptr<int>(); |
||||
|
||||
vtkSmartPointer<vtkPolyData> polydata = source->GetOutput(); |
||||
polydata->SetVerts(0); |
||||
|
||||
const int * polygons = mesh.polygons.ptr<int>(); |
||||
vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New(); |
||||
|
||||
int idx = 0; |
||||
size_t polygons_size = mesh.polygons.total(); |
||||
for (size_t i = 0; i < polygons_size; ++idx) |
||||
{ |
||||
int n_points = polygons[i++]; |
||||
|
||||
cell_array->InsertNextCell(n_points); |
||||
for (int j = 0; j < n_points; ++j, ++idx) |
||||
cell_array->InsertCellPoint(lookup[polygons[i++]]); |
||||
} |
||||
cell_array->GetData()->SetNumberOfValues(idx); |
||||
cell_array->Squeeze(); |
||||
polydata->SetStrips(cell_array); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
||||
mapper->SetScalarModeToUsePointData(); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
VtkUtils::SetInputData(mapper, polydata); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
//actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints() / 10));
|
||||
actor->GetProperty()->SetRepresentationToSurface(); |
||||
actor->GetProperty()->BackfaceCullingOff(); // Backface culling is off for higher efficiency
|
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->EdgeVisibilityOff(); |
||||
actor->GetProperty()->ShadingOff(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
if (!mesh.texture.empty()) |
||||
{ |
||||
vtkSmartPointer<vtkImageMatSource> image_source = vtkSmartPointer<vtkImageMatSource>::New(); |
||||
image_source->SetImage(mesh.texture); |
||||
|
||||
vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New(); |
||||
texture->SetInputConnection(image_source->GetOutputPort()); |
||||
actor->SetTexture(texture); |
||||
} |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
cv::viz::WMesh::WMesh(InputArray cloud, InputArray polygons, InputArray colors, InputArray normals) |
||||
{ |
||||
Mesh mesh; |
||||
mesh.cloud = cloud.getMat(); |
||||
mesh.colors = colors.getMat(); |
||||
mesh.normals = normals.getMat(); |
||||
mesh.polygons = polygons.getMat(); |
||||
*this = WMesh(mesh); |
||||
} |
||||
|
||||
template<> CV_EXPORTS cv::viz::WMesh cv::viz::Widget::cast<cv::viz::WMesh>() const |
||||
{ |
||||
Widget3D widget = this->cast<Widget3D>(); |
||||
return static_cast<WMesh&>(widget); |
||||
} |
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Widget Merger implementation
|
||||
|
||||
cv::viz::WWidgetMerger::WWidgetMerger() |
||||
{ |
||||
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkSmartPointer<vtkAppendPolyData>::New(); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
||||
mapper->SetInputConnection(append_filter->GetOutputPort()); |
||||
mapper->SetScalarModeToUsePointData(); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
mapper->SetScalarRange(0, 255); |
||||
mapper->ScalarVisibilityOn(); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->BackfaceCullingOn(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
WidgetAccessor::setProp(*this, actor); |
||||
} |
||||
|
||||
void cv::viz::WWidgetMerger::addWidget(const Widget3D& widget, const Affine3d &pose) |
||||
{ |
||||
vtkActor *widget_actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(widget)); |
||||
CV_Assert("Widget is not 3D actor." && widget_actor); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> widget_mapper = vtkPolyDataMapper::SafeDownCast(widget_actor->GetMapper()); |
||||
CV_Assert("Widget doesn't have a polydata mapper" && widget_mapper); |
||||
widget_mapper->Update(); |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
vtkSmartPointer<vtkAlgorithm> producer = actor->GetMapper()->GetInputConnection(0, 0)->GetProducer(); |
||||
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkAppendPolyData::SafeDownCast(producer); |
||||
CV_Assert("Correctness check" && append_filter); |
||||
|
||||
VtkUtils::AddInputData(append_filter, VtkUtils::TransformPolydata(widget_mapper->GetInput(), pose)); |
||||
} |
||||
|
||||
void cv::viz::WWidgetMerger::finalize() |
||||
{ |
||||
vtkSmartPointer<vtkActor> actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
vtkSmartPointer<vtkAlgorithm> producer = actor->GetMapper()->GetInputConnection(0, 0)->GetProducer(); |
||||
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkAppendPolyData::SafeDownCast(producer); |
||||
CV_Assert("Correctness check" && append_filter); |
||||
append_filter->Update(); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); |
||||
mapper->RemoveInputConnection(0, 0); |
||||
VtkUtils::SetInputData(mapper, append_filter->GetOutput()); |
||||
mapper->Modified(); |
||||
} |
||||
|
||||
template<> CV_EXPORTS cv::viz::WWidgetMerger cv::viz::Widget::cast<cv::viz::WWidgetMerger>() const |
||||
{ |
||||
Widget3D widget = this->cast<Widget3D>(); |
||||
return static_cast<WWidgetMerger&>(widget); |
||||
} |
@ -1,343 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIZ_PRECOMP_HPP__ |
||||
#define __OPENCV_VIZ_PRECOMP_HPP__ |
||||
|
||||
#include <map> |
||||
#include <ctime> |
||||
#include <list> |
||||
#include <vector> |
||||
#include <iomanip> |
||||
#include <limits> |
||||
|
||||
#include <vtkAppendPolyData.h> |
||||
#include <vtkAssemblyPath.h> |
||||
#include <vtkCellData.h> |
||||
#include <vtkLineSource.h> |
||||
#include <vtkPropPicker.h> |
||||
#include <vtkSmartPointer.h> |
||||
#include <vtkDataSet.h> |
||||
#include <vtkPolygon.h> |
||||
#include <vtkUnstructuredGrid.h> |
||||
#include <vtkDiskSource.h> |
||||
#include <vtkPlaneSource.h> |
||||
#include <vtkSphereSource.h> |
||||
#include <vtkArrowSource.h> |
||||
#include <vtkOutlineSource.h> |
||||
#include <vtkTransform.h> |
||||
#include <vtkTransformPolyDataFilter.h> |
||||
#include <vtkTubeFilter.h> |
||||
#include <vtkCubeSource.h> |
||||
#include <vtkAxes.h> |
||||
#include <vtkFloatArray.h> |
||||
#include <vtkDoubleArray.h> |
||||
#include <vtkPointData.h> |
||||
#include <vtkPolyData.h> |
||||
#include <vtkPolyDataMapper.h> |
||||
#include <vtkDataSetMapper.h> |
||||
#include <vtkCellArray.h> |
||||
#include <vtkCommand.h> |
||||
#include <vtkPLYReader.h> |
||||
#include <vtkPolyLine.h> |
||||
#include <vtkVectorText.h> |
||||
#include <vtkFollower.h> |
||||
#include <vtkInteractorStyle.h> |
||||
#include <vtkUnsignedCharArray.h> |
||||
#include <vtkRendererCollection.h> |
||||
#include <vtkPNGWriter.h> |
||||
#include <vtkWindowToImageFilter.h> |
||||
#include <vtkInteractorStyleTrackballCamera.h> |
||||
#include <vtkProperty.h> |
||||
#include <vtkCamera.h> |
||||
#include <vtkPlanes.h> |
||||
#include <vtkImageFlip.h> |
||||
#include <vtkRenderWindow.h> |
||||
#include <vtkTextProperty.h> |
||||
#include <vtkProperty2D.h> |
||||
#include <vtkLODActor.h> |
||||
#include <vtkActor.h> |
||||
#include <vtkTextActor.h> |
||||
#include <vtkRenderWindowInteractor.h> |
||||
#include <vtkMath.h> |
||||
#include <vtkExtractEdges.h> |
||||
#include <vtkFrustumSource.h> |
||||
#include <vtkTexture.h> |
||||
#include <vtkTextureMapToPlane.h> |
||||
#include <vtkPolyDataNormals.h> |
||||
#include <vtkAlgorithmOutput.h> |
||||
#include <vtkImageMapper.h> |
||||
#include <vtkPoints.h> |
||||
#include <vtkInformation.h> |
||||
#include <vtkInformationVector.h> |
||||
#include <vtkObjectFactory.h> |
||||
#include <vtkPolyDataAlgorithm.h> |
||||
#include <vtkMergeFilter.h> |
||||
#include <vtkErrorCode.h> |
||||
#include <vtkPLYWriter.h> |
||||
#include <vtkSTLWriter.h> |
||||
#include <vtkPLYReader.h> |
||||
#include <vtkOBJReader.h> |
||||
#include <vtkSTLReader.h> |
||||
#include <vtkPNGReader.h> |
||||
#include <vtkOBJExporter.h> |
||||
#include <vtkVRMLExporter.h> |
||||
#include <vtkTensorGlyph.h> |
||||
#include <vtkImageAlgorithm.h> |
||||
#include <vtkTransformFilter.h> |
||||
#include <vtkConeSource.h> |
||||
#include <vtkElevationFilter.h> |
||||
#include <vtkColorTransferFunction.h> |
||||
#include <vtkStreamingDemandDrivenPipeline.h> |
||||
#include <vtkLight.h> |
||||
#include "vtkCallbackCommand.h" |
||||
|
||||
#if !defined(_WIN32) || defined(__CYGWIN__) |
||||
# include <unistd.h> /* unlink */ |
||||
#else |
||||
# include <io.h> /* unlink */ |
||||
#endif |
||||
|
||||
#include "vtk/vtkOBJWriter.h" |
||||
#include "vtk/vtkXYZWriter.h" |
||||
#include "vtk/vtkXYZReader.h" |
||||
#include "vtk/vtkCloudMatSink.h" |
||||
#include "vtk/vtkCloudMatSource.h" |
||||
#include "vtk/vtkTrajectorySource.h" |
||||
#include "vtk/vtkImageMatSource.h" |
||||
|
||||
|
||||
#include <opencv2/core.hpp> |
||||
#include <opencv2/viz.hpp> |
||||
#include <opencv2/viz/widget_accessor.hpp> |
||||
#include <opencv2/core/utility.hpp> |
||||
|
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
typedef std::map<String, vtkSmartPointer<vtkProp> > WidgetActorMap; |
||||
|
||||
struct VizMap |
||||
{ |
||||
typedef std::map<String, Viz3d> type; |
||||
typedef type::iterator iterator; |
||||
|
||||
type m; |
||||
~VizMap(); |
||||
void replace_clear(); |
||||
}; |
||||
|
||||
class VizStorage |
||||
{ |
||||
public: |
||||
static void unregisterAll(); |
||||
|
||||
//! window names automatically have Viz - prefix even though not provided by the users
|
||||
static String generateWindowName(const String &window_name); |
||||
|
||||
private: |
||||
VizStorage(); // Static
|
||||
|
||||
static void add(const Viz3d& window); |
||||
static Viz3d& get(const String &window_name); |
||||
static void remove(const String &window_name); |
||||
static bool windowExists(const String &window_name); |
||||
static void removeUnreferenced(); |
||||
|
||||
static VizMap storage; |
||||
friend class Viz3d; |
||||
|
||||
static VizStorage init; |
||||
}; |
||||
|
||||
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/norm(v); } |
||||
|
||||
template<typename _Tp> inline bool isNan(const _Tp* data) |
||||
{ |
||||
return isNan(data[0]) || isNan(data[1]) || isNan(data[2]); |
||||
} |
||||
|
||||
inline vtkSmartPointer<vtkActor> getActor(const Widget3D& widget) |
||||
{ |
||||
return vtkActor::SafeDownCast(WidgetAccessor::getProp(widget)); |
||||
} |
||||
|
||||
inline vtkSmartPointer<vtkPolyData> getPolyData(const Widget3D& widget) |
||||
{ |
||||
vtkSmartPointer<vtkMapper> mapper = getActor(widget)->GetMapper(); |
||||
return vtkPolyData::SafeDownCast(mapper->GetInput()); |
||||
} |
||||
|
||||
inline vtkSmartPointer<vtkMatrix4x4> vtkmatrix(const cv::Matx44d &matrix) |
||||
{ |
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New(); |
||||
vtk_matrix->DeepCopy(matrix.val); |
||||
return vtk_matrix; |
||||
} |
||||
|
||||
inline Color vtkcolor(const Color& color) |
||||
{ |
||||
Color scaled_color = color * (1.0/255.0); |
||||
std::swap(scaled_color[0], scaled_color[2]); |
||||
return scaled_color; |
||||
} |
||||
|
||||
inline Vec3d get_random_vec(double from = -10.0, double to = 10.0) |
||||
{ |
||||
RNG& rng = theRNG(); |
||||
return Vec3d(rng.uniform(from, to), rng.uniform(from, to), rng.uniform(from, to)); |
||||
} |
||||
|
||||
struct VtkUtils |
||||
{ |
||||
template<class Filter> |
||||
static void SetInputData(vtkSmartPointer<Filter> filter, vtkPolyData* polydata) |
||||
{ |
||||
#if VTK_MAJOR_VERSION <= 5 |
||||
filter->SetInput(polydata); |
||||
#else |
||||
filter->SetInputData(polydata); |
||||
#endif |
||||
} |
||||
template<class Filter> |
||||
static void SetSourceData(vtkSmartPointer<Filter> filter, vtkPolyData* polydata) |
||||
{ |
||||
#if VTK_MAJOR_VERSION <= 5 |
||||
filter->SetSource(polydata); |
||||
#else |
||||
filter->SetSourceData(polydata); |
||||
#endif |
||||
} |
||||
|
||||
template<class Filter> |
||||
static void SetInputData(vtkSmartPointer<Filter> filter, vtkImageData* polydata) |
||||
{ |
||||
#if VTK_MAJOR_VERSION <= 5 |
||||
filter->SetInput(polydata); |
||||
#else |
||||
filter->SetInputData(polydata); |
||||
#endif |
||||
} |
||||
|
||||
template<class Filter> |
||||
static void AddInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata) |
||||
{ |
||||
#if VTK_MAJOR_VERSION <= 5 |
||||
filter->AddInput(polydata); |
||||
#else |
||||
filter->AddInputData(polydata); |
||||
#endif |
||||
} |
||||
|
||||
static vtkSmartPointer<vtkUnsignedCharArray> FillScalars(size_t size, const Color& color) |
||||
{ |
||||
Vec3b rgb = Vec3d(color[2], color[1], color[0]); |
||||
Vec3b* color_data = new Vec3b[size]; |
||||
std::fill(color_data, color_data + size, rgb); |
||||
|
||||
vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New(); |
||||
scalars->SetName("Colors"); |
||||
scalars->SetNumberOfComponents(3); |
||||
scalars->SetNumberOfTuples((vtkIdType)size); |
||||
scalars->SetArray(color_data->val, (vtkIdType)(size * 3), 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE); |
||||
return scalars; |
||||
} |
||||
|
||||
static vtkSmartPointer<vtkPolyData> FillScalars(vtkSmartPointer<vtkPolyData> polydata, const Color& color) |
||||
{ |
||||
return polydata->GetPointData()->SetScalars(FillScalars(polydata->GetNumberOfPoints(), color)), polydata; |
||||
} |
||||
|
||||
static vtkSmartPointer<vtkPolyData> ComputeNormals(vtkSmartPointer<vtkPolyData> polydata) |
||||
{ |
||||
vtkSmartPointer<vtkPolyDataNormals> normals_generator = vtkSmartPointer<vtkPolyDataNormals>::New(); |
||||
normals_generator->ComputePointNormalsOn(); |
||||
normals_generator->ComputeCellNormalsOff(); |
||||
normals_generator->SetFeatureAngle(0.1); |
||||
normals_generator->SetSplitting(0); |
||||
normals_generator->SetConsistency(1); |
||||
normals_generator->SetAutoOrientNormals(0); |
||||
normals_generator->SetFlipNormals(0); |
||||
normals_generator->SetNonManifoldTraversal(1); |
||||
VtkUtils::SetInputData(normals_generator, polydata); |
||||
normals_generator->Update(); |
||||
return normals_generator->GetOutput(); |
||||
} |
||||
|
||||
static vtkSmartPointer<vtkPolyData> TransformPolydata(vtkSmartPointer<vtkAlgorithmOutput> algorithm_output_port, const Affine3d& pose) |
||||
{ |
||||
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); |
||||
transform->SetMatrix(vtkmatrix(pose.matrix)); |
||||
|
||||
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); |
||||
transform_filter->SetTransform(transform); |
||||
transform_filter->SetInputConnection(algorithm_output_port); |
||||
transform_filter->Update(); |
||||
return transform_filter->GetOutput(); |
||||
} |
||||
|
||||
static vtkSmartPointer<vtkPolyData> TransformPolydata(vtkSmartPointer<vtkPolyData> polydata, const Affine3d& pose) |
||||
{ |
||||
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); |
||||
transform->SetMatrix(vtkmatrix(pose.matrix)); |
||||
|
||||
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); |
||||
VtkUtils::SetInputData(transform_filter, polydata); |
||||
transform_filter->SetTransform(transform); |
||||
transform_filter->Update(); |
||||
return transform_filter->GetOutput(); |
||||
} |
||||
}; |
||||
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> vtkCocoaRenderWindowInteractorNew(); |
||||
} |
||||
} |
||||
|
||||
#include "vtk/vtkVizInteractorStyle.hpp" |
||||
#include "vizimpl.hpp" |
||||
|
||||
#endif |
File diff suppressed because it is too large
Load Diff
@ -1,228 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// Events
|
||||
|
||||
cv::viz::KeyboardEvent::KeyboardEvent(Action _action, const String& _symbol, unsigned char _code, int _modifiers) |
||||
: action(_action), symbol(_symbol), code(_code), modifiers(_modifiers) {} |
||||
|
||||
cv::viz::MouseEvent::MouseEvent(const Type& _type, const MouseButton& _button, const Point& _pointer, int _modifiers) |
||||
: type(_type), button(_button), pointer(_pointer), modifiers(_modifiers) {} |
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// cv::viz::Mesh3d
|
||||
|
||||
cv::viz::Mesh cv::viz::Mesh::load(const String& file, int type) |
||||
{ |
||||
vtkSmartPointer<vtkPolyDataAlgorithm> reader = vtkSmartPointer<vtkPolyDataAlgorithm>::New(); |
||||
switch (type) { |
||||
case LOAD_AUTO: |
||||
{ |
||||
CV_Error(Error::StsError, "cv::viz::Mesh::LOAD_AUTO: Not implemented yet"); |
||||
} |
||||
case LOAD_PLY: |
||||
{ |
||||
vtkSmartPointer<vtkPLYReader> ply_reader = vtkSmartPointer<vtkPLYReader>::New(); |
||||
ply_reader->SetFileName(file.c_str()); |
||||
ply_reader->Update(); |
||||
reader = ply_reader; |
||||
break; |
||||
} |
||||
case LOAD_OBJ: |
||||
{ |
||||
vtkSmartPointer<vtkOBJReader> obj_reader = vtkSmartPointer<vtkOBJReader>::New(); |
||||
obj_reader->SetFileName(file.c_str()); |
||||
obj_reader->Update(); |
||||
reader = obj_reader; |
||||
break; |
||||
} |
||||
default: |
||||
CV_Error(Error::StsError, "cv::viz::Mesh::load: Unknown file type"); |
||||
} |
||||
|
||||
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput(); |
||||
CV_Assert("File does not exist or file format is not supported." && polydata); |
||||
|
||||
Mesh mesh; |
||||
vtkSmartPointer<vtkCloudMatSink> sink = vtkSmartPointer<vtkCloudMatSink>::New(); |
||||
sink->SetOutput(mesh.cloud, mesh.colors, mesh.normals, mesh.tcoords); |
||||
sink->SetInputConnection(reader->GetOutputPort()); |
||||
sink->Write(); |
||||
|
||||
// Now handle the polygons
|
||||
vtkSmartPointer<vtkCellArray> polygons = polydata->GetPolys(); |
||||
mesh.polygons.create(1, polygons->GetSize(), CV_32SC1); |
||||
int* poly_ptr = mesh.polygons.ptr<int>(); |
||||
|
||||
polygons->InitTraversal(); |
||||
vtkIdType nr_cell_points, *cell_points; |
||||
while (polygons->GetNextCell(nr_cell_points, cell_points)) |
||||
{ |
||||
*poly_ptr++ = nr_cell_points; |
||||
for (vtkIdType i = 0; i < nr_cell_points; ++i) |
||||
*poly_ptr++ = (int)cell_points[i]; |
||||
} |
||||
|
||||
return mesh; |
||||
} |
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// Camera implementation
|
||||
|
||||
cv::viz::Camera::Camera(double fx, double fy, double cx, double cy, const Size &window_size) |
||||
{ |
||||
init(fx, fy, cx, cy, window_size); |
||||
} |
||||
|
||||
cv::viz::Camera::Camera(const Vec2d &fov, const Size &window_size) |
||||
{ |
||||
CV_Assert(window_size.width > 0 && window_size.height > 0); |
||||
setClip(Vec2d(0.01, 1000.01)); // Default clipping
|
||||
setFov(fov); |
||||
window_size_ = window_size; |
||||
// Principal point at the center
|
||||
principal_point_ = Vec2f(static_cast<float>(window_size.width)*0.5f, static_cast<float>(window_size.height)*0.5f); |
||||
focal_ = Vec2f(principal_point_[0] / tan(fov_[0]*0.5f), principal_point_[1] / tan(fov_[1]*0.5f)); |
||||
} |
||||
|
||||
cv::viz::Camera::Camera(const cv::Matx33d & K, const Size &window_size) |
||||
{ |
||||
double f_x = K(0,0); |
||||
double f_y = K(1,1); |
||||
double c_x = K(0,2); |
||||
double c_y = K(1,2); |
||||
init(f_x, f_y, c_x, c_y, window_size); |
||||
} |
||||
|
||||
cv::viz::Camera::Camera(const Matx44d &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; |
||||
|
||||
principal_point_[0] = fabs(left-right) < epsilon ? window_size.width * 0.5 : (left * window_size.width) / (left - right); |
||||
principal_point_[1] = fabs(top-bottom) < epsilon ? window_size.height * 0.5 : (top * window_size.height) / (top - bottom); |
||||
|
||||
focal_[0] = -near * principal_point_[0] / left; |
||||
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; |
||||
} |
||||
|
||||
void cv::viz::Camera::init(double fx, double fy, double cx, double cy, const Size &window_size) |
||||
{ |
||||
CV_Assert(window_size.width > 0 && window_size.height > 0); |
||||
setClip(Vec2d(0.01, 1000.01));// Default clipping
|
||||
|
||||
fov_[0] = atan2(cx, fx) + atan2(window_size.width - cx, fx); |
||||
fov_[1] = atan2(cy, fy) + atan2(window_size.height - cy, fy); |
||||
|
||||
principal_point_[0] = cx; |
||||
principal_point_[1] = cy; |
||||
|
||||
focal_[0] = fx; |
||||
focal_[1] = fy; |
||||
|
||||
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; |
||||
} |
||||
|
||||
void cv::viz::Camera::computeProjectionMatrix(Matx44d &proj) const |
||||
{ |
||||
double top = clip_[0] * principal_point_[1] / focal_[1]; |
||||
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; |
||||
proj(0,2) = (right + left) * temp2; |
||||
proj(1,2) = (top + bottom) * temp3; |
||||
proj(2,2) = (clip_[1]+clip_[0]) * temp4; |
||||
proj(3,2) = -1.0; |
||||
proj(2,3) = (temp1 * clip_[1]) * temp4; |
||||
} |
||||
|
||||
cv::viz::Camera cv::viz::Camera::KinectCamera(const Size &window_size) |
||||
{ |
||||
Matx33d K(525.0, 0.0, 320.0, 0.0, 525.0, 240.0, 0.0, 0.0, 1.0); |
||||
return Camera(K, window_size); |
||||
} |
@ -1,156 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); } |
||||
|
||||
cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_) |
||||
{ |
||||
if (impl_) |
||||
CV_XADD(&impl_->ref_counter, 1); |
||||
} |
||||
|
||||
cv::viz::Viz3d& cv::viz::Viz3d::operator=(const Viz3d& other) |
||||
{ |
||||
if (this != &other) |
||||
{ |
||||
release(); |
||||
impl_ = other.impl_; |
||||
if (impl_) |
||||
CV_XADD(&impl_->ref_counter, 1); |
||||
} |
||||
return *this; |
||||
} |
||||
|
||||
cv::viz::Viz3d::~Viz3d() { release(); } |
||||
|
||||
void cv::viz::Viz3d::create(const String &window_name) |
||||
{ |
||||
if (impl_) |
||||
release(); |
||||
|
||||
if (VizStorage::windowExists(window_name)) |
||||
*this = VizStorage::get(window_name); |
||||
else |
||||
{ |
||||
impl_ = new VizImpl(window_name); |
||||
impl_->ref_counter = 1; |
||||
|
||||
// Register the window
|
||||
VizStorage::add(*this); |
||||
} |
||||
} |
||||
|
||||
void cv::viz::Viz3d::release() |
||||
{ |
||||
if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) |
||||
{ |
||||
delete impl_; |
||||
impl_ = 0; |
||||
} |
||||
|
||||
if (impl_ && impl_->ref_counter == 1) |
||||
VizStorage::removeUnreferenced(); |
||||
|
||||
impl_ = 0; |
||||
} |
||||
|
||||
void cv::viz::Viz3d::spin() { impl_->spin(); } |
||||
void cv::viz::Viz3d::spinOnce(int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); } |
||||
void cv::viz::Viz3d::setOffScreenRendering() { impl_->setOffScreenRendering(); } |
||||
void cv::viz::Viz3d::removeAllLights() { impl_->removeAllLights(); } |
||||
void cv::viz::Viz3d::addLight(const Vec3d &position, const Vec3d &focalPoint, const Color &color, |
||||
const Color &diffuseColor, const Color &ambientColor, const Color &specularColor) |
||||
{ impl_->addLight(position, focalPoint, color, diffuseColor, ambientColor, specularColor); } |
||||
bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); } |
||||
void cv::viz::Viz3d::close() { impl_->close(); } |
||||
|
||||
void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* cookie) |
||||
{ impl_->registerKeyboardCallback(callback, cookie); } |
||||
|
||||
void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie) |
||||
{ impl_->registerMouseCallback(callback, cookie); } |
||||
|
||||
void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3d &pose) { impl_->showWidget(id, widget, pose); } |
||||
void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); } |
||||
cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); } |
||||
void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); } |
||||
|
||||
void cv::viz::Viz3d::showImage(InputArray image, const Size& window_size) { impl_->showImage(image, window_size); } |
||||
|
||||
void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3d &pose) { impl_->setWidgetPose(id, pose); } |
||||
void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3d &pose) { impl_->updateWidgetPose(id, pose); } |
||||
cv::Affine3d cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } |
||||
|
||||
void cv::viz::Viz3d::setCamera(const Camera &camera) { impl_->setCamera(camera); } |
||||
cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); } |
||||
void cv::viz::Viz3d::setViewerPose(const Affine3d &pose) { impl_->setViewerPose(pose); } |
||||
cv::Affine3d cv::viz::Viz3d::getViewerPose() const { return impl_->getViewerPose(); } |
||||
|
||||
void cv::viz::Viz3d::resetCameraViewpoint(const String &id) { impl_->resetCameraViewpoint(id); } |
||||
void cv::viz::Viz3d::resetCamera() { impl_->resetCamera(); } |
||||
|
||||
void cv::viz::Viz3d::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) { impl_->convertToWindowCoordinates(pt, window_coord); } |
||||
void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) { impl_->converTo3DRay(window_coord, origin, direction); } |
||||
|
||||
cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); } |
||||
void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size); } |
||||
cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); } |
||||
cv::Mat cv::viz::Viz3d::getScreenshot() const { return impl_->getScreenshot(); } |
||||
void cv::viz::Viz3d::saveScreenshot(const String &file) { impl_->saveScreenshot(file); } |
||||
void cv::viz::Viz3d::setWindowPosition(const Point& window_position) { impl_->setWindowPosition(window_position); } |
||||
void cv::viz::Viz3d::setFullScreen(bool mode) { impl_->setFullScreen(mode); } |
||||
void cv::viz::Viz3d::setBackgroundColor(const Color& color, const Color& color2) { impl_->setBackgroundColor(color, color2); } |
||||
|
||||
void cv::viz::Viz3d::setBackgroundTexture(InputArray image) { impl_->setBackgroundTexture(image); } |
||||
void cv::viz::Viz3d::setBackgroundMeshLab() {impl_->setBackgroundMeshLab(); } |
||||
|
||||
void cv::viz::Viz3d::setRenderingProperty(const String &id, int property, double value) { getWidget(id).setRenderingProperty(property, value); } |
||||
double cv::viz::Viz3d::getRenderingProperty(const String &id, int property) { return getWidget(id).getRenderingProperty(property); } |
||||
|
||||
void cv::viz::Viz3d::setRepresentation(int representation) { impl_->setRepresentation(representation); } |
||||
|
||||
void cv::viz::Viz3d::setGlobalWarnings(bool enabled) { vtkObject::SetGlobalWarningDisplay(enabled ? 1 : 0); } |
@ -1,352 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
cv::Affine3d cv::viz::makeTransformToGlobal(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin) |
||||
{ |
||||
Affine3d::Mat3 R(axis_x[0], axis_y[0], axis_z[0], |
||||
axis_x[1], axis_y[1], axis_z[1], |
||||
axis_x[2], axis_y[2], axis_z[2]); |
||||
|
||||
return Affine3d(R, origin); |
||||
} |
||||
|
||||
cv::Affine3d cv::viz::makeCameraPose(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir) |
||||
{ |
||||
// Compute the transformation matrix for drawing the camera frame in a scene
|
||||
Vec3d n = normalize(focal_point - position); |
||||
Vec3d u = normalize(y_dir.cross(n)); |
||||
Vec3d v = n.cross(u); |
||||
|
||||
return makeTransformToGlobal(u, v, n, position); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// VizStorage implementation
|
||||
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__) |
||||
|
||||
#include <windows.h> |
||||
|
||||
static BOOL WINAPI ConsoleHandlerRoutine(DWORD /*dwCtrlType*/) |
||||
{ |
||||
vtkObject::GlobalWarningDisplayOff(); |
||||
return FALSE; |
||||
} |
||||
|
||||
static void register_console_handler() |
||||
{ |
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); |
||||
CONSOLE_SCREEN_BUFFER_INFO hOutInfo; |
||||
if (GetConsoleScreenBufferInfo(hOut, &hOutInfo)) |
||||
SetConsoleCtrlHandler(ConsoleHandlerRoutine, TRUE); |
||||
} |
||||
|
||||
#else |
||||
|
||||
void register_console_handler(); |
||||
void register_console_handler() {} |
||||
|
||||
#endif |
||||
|
||||
|
||||
cv::viz::VizStorage cv::viz::VizStorage::init; |
||||
cv::viz::VizMap cv::viz::VizStorage::storage; |
||||
|
||||
void cv::viz::VizMap::replace_clear() { type().swap(m); } |
||||
cv::viz::VizMap::~VizMap() { replace_clear(); } |
||||
|
||||
cv::viz::VizStorage::VizStorage() |
||||
{ |
||||
register_console_handler(); |
||||
} |
||||
void cv::viz::VizStorage::unregisterAll() { storage.replace_clear(); } |
||||
|
||||
cv::viz::Viz3d& cv::viz::VizStorage::get(const String &window_name) |
||||
{ |
||||
String name = generateWindowName(window_name); |
||||
VizMap::iterator vm_itr = storage.m.find(name); |
||||
CV_Assert(vm_itr != storage.m.end()); |
||||
return vm_itr->second; |
||||
} |
||||
|
||||
void cv::viz::VizStorage::add(const Viz3d& window) |
||||
{ |
||||
String window_name = window.getWindowName(); |
||||
VizMap::iterator vm_itr = storage.m.find(window_name); |
||||
CV_Assert(vm_itr == storage.m.end()); |
||||
storage.m.insert(std::make_pair(window_name, window)); |
||||
} |
||||
|
||||
bool cv::viz::VizStorage::windowExists(const String &window_name) |
||||
{ |
||||
String name = generateWindowName(window_name); |
||||
return storage.m.find(name) != storage.m.end(); |
||||
} |
||||
|
||||
void cv::viz::VizStorage::removeUnreferenced() |
||||
{ |
||||
for(VizMap::iterator pos = storage.m.begin(); pos != storage.m.end();) |
||||
if(pos->second.impl_->ref_counter == 1) |
||||
storage.m.erase(pos++); |
||||
else |
||||
++pos; |
||||
} |
||||
|
||||
cv::String cv::viz::VizStorage::generateWindowName(const String &window_name) |
||||
{ |
||||
String output = "Viz"; |
||||
// Already is Viz
|
||||
if (window_name == output) |
||||
return output; |
||||
|
||||
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
|
||||
else |
||||
output = (window_name == "" ? output : prefixed + window_name); |
||||
|
||||
return output; |
||||
} |
||||
|
||||
cv::viz::Viz3d cv::viz::getWindowByName(const String &window_name) { return Viz3d (window_name); } |
||||
void cv::viz::unregisterAllWindows() { VizStorage::unregisterAll(); } |
||||
|
||||
cv::viz::Viz3d cv::viz::imshow(const String& window_name, InputArray image, const Size& window_size) |
||||
{ |
||||
Viz3d viz = getWindowByName(window_name); |
||||
viz.showImage(image, window_size); |
||||
return viz; |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Read/write clouds. Supported formats: ply, stl, xyz, obj
|
||||
|
||||
void cv::viz::writeCloud(const String& file, InputArray cloud, InputArray colors, InputArray normals, bool binary) |
||||
{ |
||||
CV_Assert(file.size() > 4 && "Extension is required"); |
||||
String extension = file.substr(file.size()-4); |
||||
|
||||
vtkSmartPointer<vtkCloudMatSource> source = vtkSmartPointer<vtkCloudMatSource>::New(); |
||||
source->SetColorCloudNormals(cloud, colors, normals); |
||||
|
||||
vtkSmartPointer<vtkWriter> writer; |
||||
if (extension == ".xyz") |
||||
{ |
||||
writer = vtkSmartPointer<vtkXYZWriter>::New(); |
||||
vtkXYZWriter::SafeDownCast(writer)->SetFileName(file.c_str()); |
||||
} |
||||
else if (extension == ".ply") |
||||
{ |
||||
writer = vtkSmartPointer<vtkPLYWriter>::New(); |
||||
vtkPLYWriter::SafeDownCast(writer)->SetFileName(file.c_str()); |
||||
vtkPLYWriter::SafeDownCast(writer)->SetFileType(binary ? VTK_BINARY : VTK_ASCII); |
||||
vtkPLYWriter::SafeDownCast(writer)->SetArrayName("Colors"); |
||||
} |
||||
else if (extension == ".obj") |
||||
{ |
||||
writer = vtkSmartPointer<vtkOBJWriter>::New(); |
||||
vtkOBJWriter::SafeDownCast(writer)->SetFileName(file.c_str()); |
||||
} |
||||
else |
||||
CV_Error(Error::StsError, "Unsupported format"); |
||||
|
||||
writer->SetInputConnection(source->GetOutputPort()); |
||||
writer->Write(); |
||||
} |
||||
|
||||
cv::Mat cv::viz::readCloud(const String& file, OutputArray colors, OutputArray normals) |
||||
{ |
||||
CV_Assert(file.size() > 4 && "Extension is required"); |
||||
String extension = file.substr(file.size()-4); |
||||
|
||||
vtkSmartPointer<vtkPolyDataAlgorithm> reader; |
||||
if (extension == ".xyz") |
||||
{ |
||||
reader = vtkSmartPointer<vtkXYZReader>::New(); |
||||
vtkXYZReader::SafeDownCast(reader)->SetFileName(file.c_str()); |
||||
} |
||||
else if (extension == ".ply") |
||||
{ |
||||
reader = vtkSmartPointer<vtkPLYReader>::New(); |
||||
CV_Assert(vtkPLYReader::CanReadFile(file.c_str())); |
||||
vtkPLYReader::SafeDownCast(reader)->SetFileName(file.c_str()); |
||||
} |
||||
else if (extension == ".obj") |
||||
{ |
||||
reader = vtkSmartPointer<vtkOBJReader>::New(); |
||||
vtkOBJReader::SafeDownCast(reader)->SetFileName(file.c_str()); |
||||
} |
||||
else if (extension == ".stl") |
||||
{ |
||||
reader = vtkSmartPointer<vtkSTLReader>::New(); |
||||
vtkSTLReader::SafeDownCast(reader)->SetFileName(file.c_str()); |
||||
} |
||||
else |
||||
CV_Error(Error::StsError, "Unsupported format"); |
||||
|
||||
cv::Mat cloud; |
||||
|
||||
vtkSmartPointer<vtkCloudMatSink> sink = vtkSmartPointer<vtkCloudMatSink>::New(); |
||||
sink->SetInputConnection(reader->GetOutputPort()); |
||||
sink->SetOutput(cloud, colors, normals); |
||||
sink->Write(); |
||||
|
||||
return cloud; |
||||
} |
||||
|
||||
cv::viz::Mesh cv::viz::readMesh(const String& file) { return Mesh::load(file); } |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Read/write poses and trajectories
|
||||
|
||||
bool cv::viz::readPose(const String& file, Affine3d& pose, const String& tag) |
||||
{ |
||||
FileStorage fs(file, FileStorage::READ); |
||||
if (!fs.isOpened()) |
||||
return false; |
||||
|
||||
Mat hdr(pose.matrix, false); |
||||
fs[tag] >> hdr; |
||||
if (hdr.empty() || hdr.cols != pose.matrix.cols || hdr.rows != pose.matrix.rows) |
||||
return false; |
||||
|
||||
hdr.convertTo(pose.matrix, CV_64F); |
||||
return true; |
||||
} |
||||
|
||||
void cv::viz::writePose(const String& file, const Affine3d& pose, const String& tag) |
||||
{ |
||||
FileStorage fs(file, FileStorage::WRITE); |
||||
fs << tag << Mat(pose.matrix, false); |
||||
} |
||||
|
||||
void cv::viz::readTrajectory(OutputArray _traj, const String& files_format, int start, int end, const String& tag) |
||||
{ |
||||
CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT); |
||||
|
||||
start = max(0, std::min(start, end)); |
||||
end = std::max(start, end); |
||||
|
||||
std::vector<Affine3d> traj; |
||||
|
||||
for(int i = start; i < end; ++i) |
||||
{ |
||||
Affine3d affine; |
||||
bool ok = readPose(cv::format(files_format.c_str(), i), affine, tag); |
||||
if (!ok) |
||||
break; |
||||
|
||||
traj.push_back(affine); |
||||
} |
||||
|
||||
Mat(traj).convertTo(_traj, _traj.depth()); |
||||
} |
||||
|
||||
void cv::viz::writeTrajectory(InputArray _traj, const String& files_format, int start, const String& tag) |
||||
{ |
||||
if (_traj.kind() == _InputArray::STD_VECTOR_MAT) |
||||
{ |
||||
#if CV_MAJOR_VERSION < 3 |
||||
std::vector<Mat>& v = *(std::vector<Mat>*)_traj.obj; |
||||
#else |
||||
std::vector<Mat>& v = *(std::vector<Mat>*)_traj.getObj(); |
||||
#endif |
||||
|
||||
for(size_t i = 0, index = max(0, start); i < v.size(); ++i, ++index) |
||||
{ |
||||
Affine3d affine; |
||||
Mat pose = v[i]; |
||||
CV_Assert(pose.type() == CV_32FC(16) || pose.type() == CV_64FC(16)); |
||||
pose.copyTo(affine.matrix); |
||||
writePose(cv::format(files_format.c_str(), index), affine, tag); |
||||
} |
||||
return; |
||||
} |
||||
|
||||
if (_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT) |
||||
{ |
||||
CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16)); |
||||
|
||||
Mat traj = _traj.getMat(); |
||||
|
||||
if (traj.depth() == CV_32F) |
||||
for(size_t i = 0, index = max(0, start); i < traj.total(); ++i, ++index) |
||||
writePose(cv::format(files_format.c_str(), index), traj.at<Affine3f>((int)i), tag); |
||||
|
||||
if (traj.depth() == CV_64F) |
||||
for(size_t i = 0, index = max(0, start); i < traj.total(); ++i, ++index) |
||||
writePose(cv::format(files_format.c_str(), index), traj.at<Affine3d>((int)i), tag); |
||||
return; |
||||
} |
||||
|
||||
CV_Error(Error::StsError, "Unsupported array kind"); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Computing normals for mesh
|
||||
|
||||
void cv::viz::computeNormals(const Mesh& mesh, OutputArray _normals) |
||||
{ |
||||
vtkSmartPointer<vtkPolyData> polydata = getPolyData(WMesh(mesh)); |
||||
vtkSmartPointer<vtkPolyData> with_normals = VtkUtils::ComputeNormals(polydata); |
||||
|
||||
vtkSmartPointer<vtkDataArray> generic_normals = with_normals->GetPointData()->GetNormals(); |
||||
if(generic_normals) |
||||
{ |
||||
Mat normals(1, generic_normals->GetNumberOfTuples(), CV_64FC3); |
||||
Vec3d *optr = normals.ptr<Vec3d>(); |
||||
|
||||
for(int i = 0; i < generic_normals->GetNumberOfTuples(); ++i, ++optr) |
||||
generic_normals->GetTuple(i, optr->val); |
||||
|
||||
normals.convertTo(_normals, mesh.cloud.type()); |
||||
} |
||||
else |
||||
_normals.release(); |
||||
} |
@ -1,622 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false), |
||||
window_position_(Vec2i(std::numeric_limits<int>::min())), widget_actor_map_(new WidgetActorMap) |
||||
{ |
||||
renderer_ = vtkSmartPointer<vtkRenderer>::New(); |
||||
window_name_ = VizStorage::generateWindowName(name); |
||||
|
||||
// Create render window
|
||||
window_ = vtkSmartPointer<vtkRenderWindow>::New(); |
||||
cv::Vec2i window_size = cv::Vec2i(window_->GetScreenSize()) / 2; |
||||
window_->SetSize(window_size.val); |
||||
window_->AddRenderer(renderer_); |
||||
|
||||
// Create the interactor style
|
||||
style_ = vtkSmartPointer<vtkVizInteractorStyle>::New(); |
||||
style_->setWidgetActorMap(widget_actor_map_); |
||||
style_->UseTimersOn(); |
||||
|
||||
timer_callback_ = vtkSmartPointer<TimerCallback>::New(); |
||||
exit_callback_ = vtkSmartPointer<ExitCallback>::New(); |
||||
exit_callback_->viz = this; |
||||
|
||||
offScreenMode_ = false; |
||||
|
||||
setBackgroundMeshLab(); |
||||
} |
||||
|
||||
cv::viz::Viz3d::VizImpl::~VizImpl() { close(); } |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::TimerCallback::Execute(vtkObject* caller, unsigned long event_id, void* cookie) |
||||
{ |
||||
if (event_id == vtkCommand::TimerEvent && timer_id == *reinterpret_cast<int*>(cookie)) |
||||
{ |
||||
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkRenderWindowInteractor::SafeDownCast(caller); |
||||
interactor->TerminateApp(); |
||||
} |
||||
} |
||||
|
||||
void cv::viz::Viz3d::VizImpl::ExitCallback::Execute(vtkObject*, unsigned long event_id, void*) |
||||
{ |
||||
if (event_id == vtkCommand::ExitEvent && viz->interactor_) |
||||
{ |
||||
viz->interactor_->TerminateApp(); |
||||
viz->interactor_ = 0; |
||||
} |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool cv::viz::Viz3d::VizImpl::wasStopped() const |
||||
{ |
||||
bool stopped = spin_once_state_ ? interactor_ == 0 : false; |
||||
spin_once_state_ &= !stopped; |
||||
return stopped; |
||||
} |
||||
|
||||
void cv::viz::Viz3d::VizImpl::close() |
||||
{ |
||||
if (!interactor_) |
||||
return; |
||||
interactor_->GetRenderWindow()->Finalize(); |
||||
interactor_->TerminateApp(); // This tends to close the window...
|
||||
interactor_ = 0; |
||||
} |
||||
|
||||
void cv::viz::Viz3d::VizImpl::recreateRenderWindow() |
||||
{ |
||||
#if !defined _MSC_VER && !defined __APPLE__ |
||||
//recreating is workaround for Ubuntu -- a crash in x-server
|
||||
Vec2i window_size(window_->GetSize()); |
||||
int fullscreen = window_->GetFullScreen(); |
||||
|
||||
window_->Finalize(); |
||||
window_ = vtkSmartPointer<vtkRenderWindow>::New(); |
||||
if (window_position_[0] != std::numeric_limits<int>::min()) //also workaround
|
||||
window_->SetPosition(window_position_.val); |
||||
|
||||
window_->SetSize(window_size.val); |
||||
window_->SetFullScreen(fullscreen); |
||||
window_->AddRenderer(renderer_); |
||||
#endif |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::spin() |
||||
{ |
||||
recreateRenderWindow(); |
||||
#if defined __APPLE__ |
||||
interactor_ = vtkCocoaRenderWindowInteractorNew(); |
||||
#else |
||||
interactor_ = vtkSmartPointer<vtkRenderWindowInteractor>::New(); |
||||
#endif |
||||
interactor_->SetRenderWindow(window_); |
||||
interactor_->SetInteractorStyle(style_); |
||||
window_->AlphaBitPlanesOff(); |
||||
window_->PointSmoothingOff(); |
||||
window_->LineSmoothingOff(); |
||||
window_->PolygonSmoothingOff(); |
||||
window_->SwapBuffersOn(); |
||||
window_->SetStereoTypeToAnaglyph(); |
||||
window_->Render(); |
||||
window_->SetWindowName(window_name_.c_str()); |
||||
interactor_->Start(); |
||||
interactor_ = 0; |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::spinOnce(int time, bool force_redraw) |
||||
{ |
||||
if (interactor_ == 0) |
||||
{ |
||||
spin_once_state_ = true; |
||||
recreateRenderWindow(); |
||||
#if defined __APPLE__ |
||||
interactor_ = vtkCocoaRenderWindowInteractorNew(); |
||||
#else |
||||
interactor_ = vtkSmartPointer<vtkRenderWindowInteractor>::New(); |
||||
#endif |
||||
interactor_->SetRenderWindow(window_); |
||||
interactor_->SetInteractorStyle(style_); |
||||
interactor_->AddObserver(vtkCommand::TimerEvent, timer_callback_); |
||||
interactor_->AddObserver(vtkCommand::ExitEvent, exit_callback_); |
||||
window_->AlphaBitPlanesOff(); |
||||
window_->PointSmoothingOff(); |
||||
window_->LineSmoothingOff(); |
||||
window_->PolygonSmoothingOff(); |
||||
window_->SwapBuffersOn(); |
||||
window_->SetStereoTypeToAnaglyph(); |
||||
window_->Render(); |
||||
window_->SetWindowName(window_name_.c_str()); |
||||
} |
||||
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> local = interactor_; |
||||
|
||||
if (force_redraw) |
||||
local->Render(); |
||||
|
||||
timer_callback_->timer_id = local->CreateRepeatingTimer(std::max(1, time)); |
||||
local->Start(); |
||||
local->DestroyTimer(timer_callback_->timer_id); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setOffScreenRendering() |
||||
{ |
||||
window_->SetOffScreenRendering(1); |
||||
offScreenMode_ = true; |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::removeAllLights() |
||||
{ |
||||
renderer_->RemoveAllLights(); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::addLight(Vec3d position, Vec3d focalPoint, const Color &color, const Color &diffuseColor, |
||||
const Color &ambientColor, const Color &specularColor) |
||||
{ |
||||
Color color_ = vtkcolor(color); |
||||
Color diffuseColor_ = vtkcolor(diffuseColor); |
||||
Color ambientColor_ = vtkcolor(ambientColor); |
||||
Color specularColor_ = vtkcolor(specularColor); |
||||
|
||||
vtkSmartPointer<vtkLight> light = vtkSmartPointer<vtkLight>::New(); |
||||
light->SetPosition(position.val); |
||||
light->SetFocalPoint(focalPoint.val); |
||||
light->SetColor(color_.val); |
||||
light->SetDiffuseColor(diffuseColor_.val); |
||||
light->SetAmbientColor(ambientColor_.val); |
||||
light->SetSpecularColor(specularColor_.val); |
||||
|
||||
renderer_->AddLight(light); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3d &pose) |
||||
{ |
||||
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); |
||||
bool exists = wam_itr != widget_actor_map_->end(); |
||||
if (exists) |
||||
{ |
||||
// Remove it if it exists and add it again
|
||||
removeActorFromRenderer(wam_itr->second); |
||||
} |
||||
// Get the actor and set the user matrix
|
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget)); |
||||
if (actor) |
||||
{ |
||||
// If the actor is 3D, apply pose
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = vtkmatrix(pose.matrix); |
||||
actor->SetUserMatrix(matrix); |
||||
actor->Modified(); |
||||
} |
||||
// If the actor is a vtkFollower, then it should always face the camera
|
||||
vtkFollower *follower = vtkFollower::SafeDownCast(actor); |
||||
if (follower) |
||||
{ |
||||
follower->SetCamera(renderer_->GetActiveCamera()); |
||||
} |
||||
|
||||
renderer_->AddActor(WidgetAccessor::getProp(widget)); |
||||
(*widget_actor_map_)[id] = WidgetAccessor::getProp(widget); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) |
||||
{ |
||||
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); |
||||
bool exists = wam_itr != widget_actor_map_->end(); |
||||
CV_Assert("Widget does not exist." && exists); |
||||
CV_Assert("Widget could not be removed." && removeActorFromRenderer(wam_itr->second)); |
||||
widget_actor_map_->erase(wam_itr); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const |
||||
{ |
||||
WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); |
||||
bool exists = wam_itr != widget_actor_map_->end(); |
||||
CV_Assert("Widget does not exist." && exists); |
||||
|
||||
Widget widget; |
||||
WidgetAccessor::setProp(widget, wam_itr->second); |
||||
return widget; |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3d &pose) |
||||
{ |
||||
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); |
||||
bool exists = wam_itr != widget_actor_map_->end(); |
||||
CV_Assert("Widget does not exist." && exists); |
||||
|
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); |
||||
CV_Assert("Widget is not 3D." && actor); |
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = vtkmatrix(pose.matrix); |
||||
actor->SetUserMatrix(matrix); |
||||
actor->Modified(); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3d &pose) |
||||
{ |
||||
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); |
||||
bool exists = wam_itr != widget_actor_map_->end(); |
||||
CV_Assert("Widget does not exist." && exists); |
||||
|
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); |
||||
CV_Assert("Widget is not 3D." && actor); |
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); |
||||
if (!matrix) |
||||
{ |
||||
setWidgetPose(id, pose); |
||||
return ; |
||||
} |
||||
Affine3d updated_pose = pose * Affine3d(*matrix->Element); |
||||
matrix = vtkmatrix(updated_pose.matrix); |
||||
|
||||
actor->SetUserMatrix(matrix); |
||||
actor->Modified(); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::Affine3d cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const |
||||
{ |
||||
WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); |
||||
bool exists = wam_itr != widget_actor_map_->end(); |
||||
CV_Assert("Widget does not exist." && exists); |
||||
|
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); |
||||
CV_Assert("Widget is not 3D." && actor); |
||||
|
||||
return Affine3d(*actor->GetUserMatrix()->Element); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::saveScreenshot(const String &file) { style_->saveScreenshot(file.c_str()); } |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::Mat cv::viz::Viz3d::VizImpl::getScreenshot() const |
||||
{ |
||||
vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = |
||||
vtkSmartPointer<vtkWindowToImageFilter>::New(); |
||||
windowToImageFilter->SetInput(window_); |
||||
windowToImageFilter->ReadFrontBufferOff(); // read from the back buffer
|
||||
windowToImageFilter->Update(); |
||||
|
||||
vtkImageData *resultImage = windowToImageFilter->GetOutput(); |
||||
int * dim = resultImage->GetDimensions(); |
||||
cv::Mat image(dim[1], dim[0], CV_8UC3); |
||||
|
||||
Vec3b* dptr = reinterpret_cast<Vec3b*>(resultImage->GetScalarPointer()); |
||||
size_t elem_step = resultImage->GetIncrements()[1]/sizeof(Vec3b); |
||||
|
||||
for (int y = 0; y < image.rows; ++y) |
||||
{ |
||||
const Vec3b* drow = dptr + elem_step * y; |
||||
unsigned char *srow = image.ptr<unsigned char>(image.rows - y - 1); |
||||
for (int x = 0; x < image.cols; ++x, srow += image.channels()) |
||||
{ |
||||
srow[0] = drow[x][2]; |
||||
srow[1] = drow[x][1]; |
||||
srow[2] = drow[x][0]; |
||||
} |
||||
} |
||||
|
||||
resultImage = 0; |
||||
|
||||
return image; |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::registerMouseCallback(MouseCallback callback, void* cookie) |
||||
{ style_->registerMouseCallback(callback, cookie); } |
||||
|
||||
void cv::viz::Viz3d::VizImpl::registerKeyboardCallback(KeyboardCallback callback, void* cookie) |
||||
{ style_->registerKeyboardCallback(callback, cookie); } |
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::removeAllWidgets() |
||||
{ |
||||
widget_actor_map_->clear(); |
||||
renderer_->RemoveAllViewProps(); |
||||
} |
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::showImage(InputArray image, const Size& window_size) |
||||
{ |
||||
removeAllWidgets(); |
||||
if (window_size.width > 0 && window_size.height > 0) |
||||
setWindowSize(window_size); |
||||
|
||||
showWidget("showImage", WImageOverlay(image, Rect(Point(0,0), getWindowSize()))); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer(vtkSmartPointer<vtkProp> actor) |
||||
{ |
||||
vtkPropCollection* actors = renderer_->GetViewProps(); |
||||
actors->InitTraversal(); |
||||
vtkProp* current_actor = NULL; |
||||
while ((current_actor = actors->GetNextProp()) != NULL) |
||||
if (current_actor == actor) |
||||
{ |
||||
renderer_->RemoveActor(actor); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color, const Color& color2) |
||||
{ |
||||
Color c = vtkcolor(color), c2 = vtkcolor(color2); |
||||
bool gradient = color2[0] >= 0 && color2[1] >= 0 && color2[2] >= 0; |
||||
|
||||
if (gradient) |
||||
{ |
||||
renderer_->SetBackground(c2.val); |
||||
renderer_->SetBackground2(c.val); |
||||
renderer_->GradientBackgroundOn(); |
||||
} |
||||
else |
||||
{ |
||||
renderer_->SetBackground(c.val); |
||||
renderer_->GradientBackgroundOff(); |
||||
} |
||||
} |
||||
|
||||
void cv::viz::Viz3d::VizImpl::setBackgroundMeshLab() |
||||
{ setBackgroundColor(Color(2, 1, 1), Color(240, 120, 120)); } |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setBackgroundTexture(InputArray image) |
||||
{ |
||||
if (image.empty()) |
||||
{ |
||||
renderer_->SetBackgroundTexture(0); |
||||
renderer_->TexturedBackgroundOff(); |
||||
return; |
||||
} |
||||
|
||||
vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New(); |
||||
source->SetImage(image); |
||||
|
||||
vtkSmartPointer<vtkImageFlip> image_flip = vtkSmartPointer<vtkImageFlip>::New(); |
||||
image_flip->SetFilteredAxis(1); // Vertical flip
|
||||
image_flip->SetInputConnection(source->GetOutputPort()); |
||||
|
||||
vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New(); |
||||
texture->SetInputConnection(image_flip->GetOutputPort()); |
||||
//texture->Update();
|
||||
|
||||
renderer_->SetBackgroundTexture(texture); |
||||
renderer_->TexturedBackgroundOn(); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) |
||||
{ |
||||
vtkSmartPointer<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); |
||||
|
||||
Matx44d proj_mat; |
||||
camera.computeProjectionMatrix(proj_mat); |
||||
|
||||
// Use the intrinsic parameters of the camera to simulate more realistically
|
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = active_camera->GetProjectionTransformMatrix(aspect_ratio, -1.0, 1.0); |
||||
Matx44d old_proj_mat(*vtk_matrix->Element); |
||||
|
||||
// This is a hack around not being able to set Projection Matrix
|
||||
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); |
||||
transform->SetMatrix(vtkmatrix(proj_mat * old_proj_mat.inv())); |
||||
active_camera->SetUserTransform(transform); |
||||
|
||||
renderer_->ResetCameraClippingRange(); |
||||
renderer_->Render(); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const |
||||
{ |
||||
vtkSmartPointer<vtkCamera> active_camera = renderer_->GetActiveCamera(); |
||||
|
||||
Size window_size(renderer_->GetRenderWindow()->GetSize()[0], |
||||
renderer_->GetRenderWindow()->GetSize()[1]); |
||||
double aspect_ratio = window_size.width / (double)window_size.height; |
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> proj_matrix = active_camera->GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f); |
||||
return Camera(Matx44d(*proj_matrix->Element), window_size); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3d &pose) |
||||
{ |
||||
vtkCamera& camera = *renderer_->GetActiveCamera(); |
||||
|
||||
// Position = extrinsic translation
|
||||
cv::Vec3d pos_vec = pose.translation(); |
||||
|
||||
// Rotate the view vector
|
||||
cv::Matx33d rotation = pose.rotation(); |
||||
cv::Vec3d y_axis(0.0, -1.0, 0.0); // In Computer Vision Camera Y-axis is oriented down
|
||||
cv::Vec3d up_vec(rotation * y_axis); |
||||
|
||||
// Compute the new focal point
|
||||
cv::Vec3d z_axis(0.0, 0.0, 1.0); |
||||
cv::Vec3d focal_vec = pose * z_axis; |
||||
|
||||
camera.SetPosition(pos_vec.val); |
||||
camera.SetFocalPoint(focal_vec.val); |
||||
camera.SetViewUp(up_vec.val); |
||||
|
||||
renderer_->ResetCameraClippingRange(); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::Affine3d cv::viz::Viz3d::VizImpl::getViewerPose() const |
||||
{ |
||||
vtkCamera& camera = *renderer_->GetActiveCamera(); |
||||
|
||||
Vec3d pos(camera.GetPosition()); |
||||
Vec3d view_up(camera.GetViewUp()); |
||||
Vec3d focal(camera.GetFocalPoint()); |
||||
|
||||
Vec3d y_axis = normalized(-view_up); // In Computer Vision Camera Y-axis is oriented down
|
||||
Vec3d z_axis = normalized(focal - pos); |
||||
Vec3d x_axis = normalized(y_axis.cross(z_axis)); |
||||
|
||||
return makeTransformToGlobal(x_axis, y_axis, z_axis, pos); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) |
||||
{ |
||||
Vec3d window_pt; |
||||
vtkInteractorObserver::ComputeWorldToDisplay(renderer_, pt.x, pt.y, pt.z, window_pt.val); |
||||
window_coord = window_pt; |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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); |
||||
Vec3d cam_pos(renderer_->GetActiveCamera()->GetPosition()); |
||||
origin = cam_pos; |
||||
direction = normalize(Vec3d(world_pt.val) - cam_pos); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::resetCameraViewpoint(const String &id) |
||||
{ |
||||
vtkSmartPointer<vtkMatrix4x4> camera_pose; |
||||
static WidgetActorMap::iterator it = widget_actor_map_->find(id); |
||||
if (it != widget_actor_map_->end()) |
||||
{ |
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second); |
||||
CV_Assert("Widget is not 3D." && actor); |
||||
camera_pose = actor->GetUserMatrix(); |
||||
} |
||||
else |
||||
return; |
||||
|
||||
// Prevent a segfault
|
||||
if (!camera_pose) return; |
||||
|
||||
vtkSmartPointer<vtkCamera> cam = renderer_->GetActiveCamera(); |
||||
cam->SetPosition(camera_pose->GetElement(0, 3), |
||||
camera_pose->GetElement(1, 3), |
||||
camera_pose->GetElement(2, 3)); |
||||
|
||||
cam->SetFocalPoint(camera_pose->GetElement(0, 3) - camera_pose->GetElement(0, 2), |
||||
camera_pose->GetElement(1, 3) - camera_pose->GetElement(1, 2), |
||||
camera_pose->GetElement(2, 3) - camera_pose->GetElement(2, 2)); |
||||
|
||||
cam->SetViewUp(camera_pose->GetElement(0, 1), |
||||
camera_pose->GetElement(1, 1), |
||||
camera_pose->GetElement(2, 1)); |
||||
|
||||
renderer_->SetActiveCamera(cam); |
||||
renderer_->ResetCameraClippingRange(); |
||||
renderer_->ResetCamera(); |
||||
renderer_->Render(); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::resetCamera() |
||||
{ |
||||
renderer_->ResetCamera(); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setRepresentation(int representation) |
||||
{ |
||||
vtkActorCollection * actors = renderer_->GetActors(); |
||||
actors->InitTraversal(); |
||||
vtkActor * actor; |
||||
switch (representation) |
||||
{ |
||||
case REPRESENTATION_POINTS: |
||||
{ |
||||
while ((actor = actors->GetNextActor()) != NULL) |
||||
actor->GetProperty()->SetRepresentationToPoints(); |
||||
break; |
||||
} |
||||
case REPRESENTATION_SURFACE: |
||||
{ |
||||
while ((actor = actors->GetNextActor()) != NULL) |
||||
actor->GetProperty()->SetRepresentationToSurface(); |
||||
break; |
||||
} |
||||
case REPRESENTATION_WIREFRAME: |
||||
{ |
||||
while ((actor = actors->GetNextActor()) != NULL) |
||||
actor->GetProperty()->SetRepresentationToWireframe(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::String cv::viz::Viz3d::VizImpl::getWindowName() const { return window_name_; } |
||||
void cv::viz::Viz3d::VizImpl::setFullScreen(bool mode) { window_->SetFullScreen(mode); } |
||||
void cv::viz::Viz3d::VizImpl::setWindowPosition(const Point& position) { window_position_ = position; window_->SetPosition(position.x, position.y); } |
||||
void cv::viz::Viz3d::VizImpl::setWindowSize(const Size& window_size) { window_->SetSize(window_size.width, window_size.height); } |
||||
cv::Size cv::viz::Viz3d::VizImpl::getWindowSize() const { return Size(Point(Vec2i(window_->GetSize()))); } |
@ -1,146 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIZ_VIZ3D_IMPL_HPP__ |
||||
#define __OPENCV_VIZ_VIZ3D_IMPL_HPP__ |
||||
|
||||
struct cv::viz::Viz3d::VizImpl |
||||
{ |
||||
public: |
||||
typedef Viz3d::KeyboardCallback KeyboardCallback; |
||||
typedef Viz3d::MouseCallback MouseCallback; |
||||
|
||||
int ref_counter; |
||||
|
||||
VizImpl(const String &name); |
||||
virtual ~VizImpl(); |
||||
|
||||
bool wasStopped() const; |
||||
void close(); |
||||
|
||||
void spin(); |
||||
void spinOnce(int time = 1, bool force_redraw = false); |
||||
void setOffScreenRendering(); |
||||
|
||||
void removeAllLights(); |
||||
void addLight(Vec3d position, Vec3d focalPoint, const Color &color, const Color &diffuseColor, |
||||
const Color &ambientColor, const Color &specularColor); |
||||
|
||||
void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity()); |
||||
void removeWidget(const String &id); |
||||
Widget getWidget(const String &id) const; |
||||
void removeAllWidgets(); |
||||
|
||||
void showImage(InputArray image, const Size& window_size); |
||||
|
||||
void setWidgetPose(const String &id, const Affine3d &pose); |
||||
void updateWidgetPose(const String &id, const Affine3d &pose); |
||||
Affine3d getWidgetPose(const String &id) const; |
||||
|
||||
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 Affine3d &pose); |
||||
Affine3d getViewerPose() const; |
||||
|
||||
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); |
||||
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); |
||||
|
||||
Mat getScreenshot() const; |
||||
void saveScreenshot(const String &file); |
||||
void setWindowPosition(const Point& position); |
||||
Size getWindowSize() const; |
||||
void setWindowSize(const Size& window_size); |
||||
void setFullScreen(bool mode); |
||||
String getWindowName() const; |
||||
void setBackgroundColor(const Color& color, const Color& color2); |
||||
void setBackgroundTexture(InputArray image); |
||||
void setBackgroundMeshLab(); |
||||
|
||||
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); |
||||
void registerMouseCallback(MouseCallback callback, void* cookie = 0); |
||||
|
||||
private: |
||||
struct TimerCallback : public vtkCommand |
||||
{ |
||||
static TimerCallback* New() { return new TimerCallback; } |
||||
virtual void Execute(vtkObject* caller, unsigned long event_id, void* cookie); |
||||
int timer_id; |
||||
}; |
||||
|
||||
struct ExitCallback : public vtkCommand |
||||
{ |
||||
static ExitCallback* New() { return new ExitCallback; } |
||||
virtual void Execute(vtkObject*, unsigned long event_id, void*); |
||||
VizImpl* viz; |
||||
}; |
||||
|
||||
mutable bool spin_once_state_; |
||||
vtkSmartPointer<vtkRenderWindowInteractor> interactor_; |
||||
|
||||
vtkSmartPointer<vtkRenderWindow> window_; |
||||
String window_name_; |
||||
Vec2i window_position_; |
||||
|
||||
vtkSmartPointer<TimerCallback> timer_callback_; |
||||
vtkSmartPointer<ExitCallback> exit_callback_; |
||||
|
||||
vtkSmartPointer<vtkRenderer> renderer_; |
||||
vtkSmartPointer<vtkVizInteractorStyle> style_; |
||||
Ptr<WidgetActorMap> widget_actor_map_; |
||||
|
||||
bool offScreenMode_; |
||||
|
||||
bool removeActorFromRenderer(vtkSmartPointer<vtkProp> actor); |
||||
void recreateRenderWindow(); |
||||
}; |
||||
|
||||
#endif |
@ -1,174 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
vtkStandardNewMacro(vtkCloudMatSink); |
||||
}} |
||||
|
||||
cv::viz::vtkCloudMatSink::vtkCloudMatSink() {} |
||||
cv::viz::vtkCloudMatSink::~vtkCloudMatSink() {} |
||||
|
||||
void cv::viz::vtkCloudMatSink::SetOutput(OutputArray _cloud, OutputArray _colors, OutputArray _normals, OutputArray _tcoords) |
||||
{ |
||||
cloud = _cloud; |
||||
colors = _colors; |
||||
normals = _normals; |
||||
tcoords = _tcoords; |
||||
} |
||||
|
||||
void cv::viz::vtkCloudMatSink::WriteData() |
||||
{ |
||||
vtkPolyData *input = this->GetInput(); |
||||
if (!input) |
||||
return; |
||||
|
||||
vtkSmartPointer<vtkPoints> points_Data = input->GetPoints(); |
||||
|
||||
if (cloud.needed() && points_Data) |
||||
{ |
||||
int vtktype = points_Data->GetDataType(); |
||||
CV_Assert(vtktype == VTK_FLOAT || vtktype == VTK_DOUBLE); |
||||
|
||||
cloud.create(1, points_Data->GetNumberOfPoints(), vtktype == VTK_FLOAT ? CV_32FC3 : CV_64FC3); |
||||
Vec3d *ddata = cloud.getMat().ptr<Vec3d>(); |
||||
Vec3f *fdata = cloud.getMat().ptr<Vec3f>(); |
||||
|
||||
if (cloud.depth() == CV_32F) |
||||
for(size_t i = 0; i < cloud.total(); ++i) |
||||
*fdata++ = Vec3d(points_Data->GetPoint((vtkIdType)i)); |
||||
|
||||
if (cloud.depth() == CV_64F) |
||||
for(size_t i = 0; i < cloud.total(); ++i) |
||||
*ddata++ = Vec3d(points_Data->GetPoint((vtkIdType)i)); |
||||
} |
||||
else |
||||
cloud.release(); |
||||
|
||||
vtkSmartPointer<vtkDataArray> scalars_data = input->GetPointData() ? input->GetPointData()->GetScalars() : 0; |
||||
|
||||
if (colors.needed() && scalars_data) |
||||
{ |
||||
int channels = scalars_data->GetNumberOfComponents(); |
||||
int vtktype = scalars_data->GetDataType(); |
||||
|
||||
CV_Assert((channels == 3 || channels == 4) && "Only 3- or 4-channel color data support is implemented"); |
||||
CV_Assert(cloud.total() == (size_t)scalars_data->GetNumberOfTuples()); |
||||
|
||||
Mat buffer(cloud.size(), CV_64FC(channels)); |
||||
Vec3d *cptr = buffer.ptr<Vec3d>(); |
||||
for(size_t i = 0; i < buffer.total(); ++i) |
||||
*cptr++ = Vec3d(scalars_data->GetTuple((vtkIdType)i)); |
||||
|
||||
buffer.convertTo(colors, CV_8U, vtktype == VTK_FLOAT || VTK_FLOAT == VTK_DOUBLE ? 255.0 : 1.0); |
||||
} |
||||
else |
||||
colors.release(); |
||||
|
||||
vtkSmartPointer<vtkDataArray> normals_data = input->GetPointData() ? input->GetPointData()->GetNormals() : 0; |
||||
|
||||
if (normals.needed() && normals_data) |
||||
{ |
||||
int channels = normals_data->GetNumberOfComponents(); |
||||
int vtktype = normals_data->GetDataType(); |
||||
|
||||
CV_Assert((vtktype == VTK_FLOAT || VTK_FLOAT == VTK_DOUBLE) && (channels == 3 || channels == 4)); |
||||
CV_Assert(cloud.total() == (size_t)normals_data->GetNumberOfTuples()); |
||||
|
||||
Mat buffer(cloud.size(), CV_64FC(channels)); |
||||
Vec3d *cptr = buffer.ptr<Vec3d>(); |
||||
for(size_t i = 0; i < buffer.total(); ++i) |
||||
*cptr++ = Vec3d(normals_data->GetTuple((vtkIdType)i)); |
||||
|
||||
buffer.convertTo(normals, vtktype == VTK_FLOAT ? CV_32F : CV_64F); |
||||
} |
||||
else |
||||
normals.release(); |
||||
|
||||
vtkSmartPointer<vtkDataArray> coords_data = input->GetPointData() ? input->GetPointData()->GetTCoords() : 0; |
||||
|
||||
if (tcoords.needed() && coords_data) |
||||
{ |
||||
int vtktype = coords_data->GetDataType(); |
||||
|
||||
CV_Assert(vtktype == VTK_FLOAT || VTK_FLOAT == VTK_DOUBLE); |
||||
CV_Assert(cloud.total() == (size_t)coords_data->GetNumberOfTuples()); |
||||
|
||||
Mat buffer(cloud.size(), CV_64FC2); |
||||
Vec2d *cptr = buffer.ptr<Vec2d>(); |
||||
for(size_t i = 0; i < buffer.total(); ++i) |
||||
*cptr++ = Vec2d(coords_data->GetTuple((vtkIdType)i)); |
||||
|
||||
buffer.convertTo(tcoords, vtktype == VTK_FLOAT ? CV_32F : CV_64F); |
||||
|
||||
} |
||||
else |
||||
tcoords.release(); |
||||
} |
||||
|
||||
void cv::viz::vtkCloudMatSink::PrintSelf(ostream& os, vtkIndent indent) |
||||
{ |
||||
Superclass::PrintSelf(os, indent); |
||||
os << indent << "Cloud: " << cloud.needed() << "\n"; |
||||
os << indent << "Colors: " << colors.needed() << "\n"; |
||||
os << indent << "Normals: " << normals.needed() << "\n"; |
||||
} |
||||
|
||||
int cv::viz::vtkCloudMatSink::FillInputPortInformation(int, vtkInformation *info) |
||||
{ |
||||
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData"); |
||||
return 1; |
||||
} |
||||
|
||||
vtkPolyData* cv::viz::vtkCloudMatSink::GetInput() |
||||
{ |
||||
return vtkPolyData::SafeDownCast(this->Superclass::GetInput()); |
||||
} |
||||
|
||||
vtkPolyData* cv::viz::vtkCloudMatSink::GetInput(int port) |
||||
{ |
||||
return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port)); |
||||
} |
@ -1,88 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __vtkCloudMatSink_h |
||||
#define __vtkCloudMatSink_h |
||||
|
||||
#include <opencv2/core.hpp> |
||||
#include <vtkWriter.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkCloudMatSink : public vtkWriter |
||||
{ |
||||
public: |
||||
static vtkCloudMatSink *New(); |
||||
vtkTypeMacro(vtkCloudMatSink,vtkWriter) |
||||
void PrintSelf(ostream& os, vtkIndent indent); |
||||
|
||||
void SetOutput(OutputArray cloud, OutputArray colors = noArray(), OutputArray normals = noArray(), OutputArray tcoords = noArray()); |
||||
|
||||
// Description:
|
||||
// Get the input to this writer.
|
||||
vtkPolyData* GetInput(); |
||||
vtkPolyData* GetInput(int port); |
||||
|
||||
protected: |
||||
vtkCloudMatSink(); |
||||
~vtkCloudMatSink(); |
||||
|
||||
void WriteData(); |
||||
int FillInputPortInformation(int port, vtkInformation *info); |
||||
|
||||
_OutputArray cloud; //!< point coordinates of type CV_32FC3 or CV_64FC3 with only 1 row
|
||||
_OutputArray colors; //!< point color of type CV_8UC3 or CV_8UC4 with only 1 row
|
||||
_OutputArray normals; //!< point normal of type CV_32FC3, CV_32FC4, CV_64FC3 or CV_64FC4 with only 1 row
|
||||
_OutputArray tcoords; //!< texture coordinates of type CV_32FC2 or CV_64FC2 with only 1 row
|
||||
|
||||
private: |
||||
vtkCloudMatSink(const vtkCloudMatSink&); // Not implemented.
|
||||
void operator=(const vtkCloudMatSink&); // Not implemented.
|
||||
}; |
||||
} // end namespace viz
|
||||
} // end namespace cv
|
||||
|
||||
#endif |
@ -1,286 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
vtkStandardNewMacro(vtkCloudMatSource); |
||||
|
||||
template<typename _Tp> struct VtkDepthTraits; |
||||
|
||||
template<> struct VtkDepthTraits<float> |
||||
{ |
||||
const static int data_type = VTK_FLOAT; |
||||
typedef vtkFloatArray array_type; |
||||
}; |
||||
|
||||
template<> struct VtkDepthTraits<double> |
||||
{ |
||||
const static int data_type = VTK_DOUBLE; |
||||
typedef vtkDoubleArray array_type; |
||||
}; |
||||
}} |
||||
|
||||
cv::viz::vtkCloudMatSource::vtkCloudMatSource() { SetNumberOfInputPorts(0); } |
||||
cv::viz::vtkCloudMatSource::~vtkCloudMatSource() {} |
||||
|
||||
int cv::viz::vtkCloudMatSource::SetCloud(InputArray _cloud) |
||||
{ |
||||
CV_Assert(_cloud.depth() == CV_32F || _cloud.depth() == CV_64F); |
||||
CV_Assert(_cloud.channels() == 3 || _cloud.channels() == 4); |
||||
|
||||
Mat cloud = _cloud.getMat(); |
||||
|
||||
int total = _cloud.depth() == CV_32F ? filterNanCopy<float>(cloud) : filterNanCopy<double>(cloud); |
||||
|
||||
vertices = vtkSmartPointer<vtkCellArray>::New(); |
||||
vertices->Allocate(vertices->EstimateSize(1, total)); |
||||
vertices->InsertNextCell(total); |
||||
for(int i = 0; i < total; ++i) |
||||
vertices->InsertCellPoint(i); |
||||
|
||||
return total; |
||||
} |
||||
|
||||
int cv::viz::vtkCloudMatSource::SetColorCloud(InputArray _cloud, InputArray _colors) |
||||
{ |
||||
int total = SetCloud(_cloud); |
||||
|
||||
if (_colors.empty()) |
||||
return total; |
||||
|
||||
CV_Assert(_colors.depth() == CV_8U && _colors.channels() <= 4 && _colors.channels() != 2); |
||||
CV_Assert(_colors.size() == _cloud.size()); |
||||
|
||||
Mat cloud = _cloud.getMat(); |
||||
Mat colors = _colors.getMat(); |
||||
|
||||
if (cloud.depth() == CV_32F) |
||||
filterNanColorsCopy<float>(colors, cloud, total); |
||||
else if (cloud.depth() == CV_64F) |
||||
filterNanColorsCopy<double>(colors, cloud, total); |
||||
|
||||
return total; |
||||
} |
||||
|
||||
int cv::viz::vtkCloudMatSource::SetColorCloudNormals(InputArray _cloud, InputArray _colors, InputArray _normals) |
||||
{ |
||||
int total = SetColorCloud(_cloud, _colors); |
||||
|
||||
if (_normals.empty()) |
||||
return total; |
||||
|
||||
CV_Assert(_normals.depth() == CV_32F || _normals.depth() == CV_64F); |
||||
CV_Assert(_normals.channels() == 3 || _normals.channels() == 4); |
||||
CV_Assert(_normals.size() == _cloud.size()); |
||||
|
||||
Mat c = _cloud.getMat(); |
||||
Mat n = _normals.getMat(); |
||||
|
||||
if (n.depth() == CV_32F && c.depth() == CV_32F) |
||||
filterNanNormalsCopy<float, float>(n, c, total); |
||||
else if (n.depth() == CV_32F && c.depth() == CV_64F) |
||||
filterNanNormalsCopy<float, double>(n, c, total); |
||||
else if (n.depth() == CV_64F && c.depth() == CV_32F) |
||||
filterNanNormalsCopy<double, float>(n, c, total); |
||||
else if (n.depth() == CV_64F && c.depth() == CV_64F) |
||||
filterNanNormalsCopy<double, double>(n, c, total); |
||||
else |
||||
CV_Error(Error::StsError, "Unsupported normals/cloud type"); |
||||
|
||||
return total; |
||||
} |
||||
|
||||
int cv::viz::vtkCloudMatSource::SetColorCloudNormalsTCoords(InputArray _cloud, InputArray _colors, InputArray _normals, InputArray _tcoords) |
||||
{ |
||||
int total = SetColorCloudNormals(_cloud, _colors, _normals); |
||||
|
||||
if (_tcoords.empty()) |
||||
return total; |
||||
|
||||
CV_Assert(_tcoords.depth() == CV_32F || _tcoords.depth() == CV_64F); |
||||
CV_Assert(_tcoords.channels() == 2 && _tcoords.size() == _cloud.size()); |
||||
|
||||
Mat cl = _cloud.getMat(); |
||||
Mat tc = _tcoords.getMat(); |
||||
|
||||
if (tc.depth() == CV_32F && cl.depth() == CV_32F) |
||||
filterNanTCoordsCopy<float, float>(tc, cl, total); |
||||
else if (tc.depth() == CV_32F && cl.depth() == CV_64F) |
||||
filterNanTCoordsCopy<float, double>(tc, cl, total); |
||||
else if (tc.depth() == CV_64F && cl.depth() == CV_32F) |
||||
filterNanTCoordsCopy<double, float>(tc, cl, total); |
||||
else if (tc.depth() == CV_64F && cl.depth() == CV_64F) |
||||
filterNanTCoordsCopy<double, double>(tc, cl, total); |
||||
else |
||||
CV_Error(Error::StsError, "Unsupported tcoords/cloud type"); |
||||
|
||||
return total; |
||||
} |
||||
|
||||
int cv::viz::vtkCloudMatSource::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector) |
||||
{ |
||||
vtkInformation *outInfo = outputVector->GetInformationObject(0); |
||||
vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); |
||||
|
||||
output->SetPoints(points); |
||||
output->SetVerts(vertices); |
||||
if (scalars) |
||||
output->GetPointData()->SetScalars(scalars); |
||||
|
||||
if (normals) |
||||
output->GetPointData()->SetNormals(normals); |
||||
|
||||
if (tcoords) |
||||
output->GetPointData()->SetTCoords(tcoords); |
||||
|
||||
return 1; |
||||
} |
||||
|
||||
template<typename _Tp> |
||||
int cv::viz::vtkCloudMatSource::filterNanCopy(const Mat& cloud) |
||||
{ |
||||
CV_DbgAssert(DataType<_Tp>::depth == cloud.depth()); |
||||
points = vtkSmartPointer<vtkPoints>::New(); |
||||
points->SetDataType(VtkDepthTraits<_Tp>::data_type); |
||||
points->Allocate((vtkIdType)cloud.total()); |
||||
points->SetNumberOfPoints((vtkIdType)cloud.total()); |
||||
|
||||
int s_chs = cloud.channels(); |
||||
int total = 0; |
||||
for (int y = 0; y < cloud.rows; ++y) |
||||
{ |
||||
const _Tp* srow = cloud.ptr<_Tp>(y); |
||||
const _Tp* send = srow + cloud.cols * s_chs; |
||||
|
||||
for (; srow != send; srow += s_chs) |
||||
if (!isNan(srow)) |
||||
points->SetPoint(total++, srow); |
||||
} |
||||
points->SetNumberOfPoints(total); |
||||
points->Squeeze(); |
||||
return total; |
||||
} |
||||
|
||||
template<typename _Msk> |
||||
void cv::viz::vtkCloudMatSource::filterNanColorsCopy(const Mat& cloud_colors, const Mat& mask, int total) |
||||
{ |
||||
Vec3b* array = new Vec3b[total]; |
||||
Vec3b* pos = array; |
||||
|
||||
int s_chs = cloud_colors.channels(); |
||||
int m_chs = mask.channels(); |
||||
for (int y = 0; y < cloud_colors.rows; ++y) |
||||
{ |
||||
const unsigned char* srow = cloud_colors.ptr<unsigned char>(y); |
||||
const unsigned char* send = srow + cloud_colors.cols * s_chs; |
||||
const _Msk* mrow = mask.ptr<_Msk>(y); |
||||
|
||||
if (cloud_colors.channels() == 1) |
||||
{ |
||||
for (; srow != send; srow += s_chs, mrow += m_chs) |
||||
if (!isNan(mrow)) |
||||
*pos++ = Vec3b(srow[0], srow[0], srow[0]); |
||||
} |
||||
else |
||||
for (; srow != send; srow += s_chs, mrow += m_chs) |
||||
if (!isNan(mrow)) |
||||
*pos++ = Vec3b(srow[2], srow[1], srow[0]); |
||||
|
||||
} |
||||
|
||||
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New(); |
||||
scalars->SetName("Colors"); |
||||
scalars->SetNumberOfComponents(3); |
||||
scalars->SetNumberOfTuples(total); |
||||
scalars->SetArray(array->val, total * 3, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE); |
||||
} |
||||
|
||||
template<typename _Tn, typename _Msk> |
||||
void cv::viz::vtkCloudMatSource::filterNanNormalsCopy(const Mat& cloud_normals, const Mat& mask, int total) |
||||
{ |
||||
normals = vtkSmartPointer< typename VtkDepthTraits<_Tn>::array_type >::New(); |
||||
normals->SetName("Normals"); |
||||
normals->SetNumberOfComponents(3); |
||||
normals->SetNumberOfTuples(total); |
||||
|
||||
int s_chs = cloud_normals.channels(); |
||||
int m_chs = mask.channels(); |
||||
|
||||
int pos = 0; |
||||
for (int y = 0; y < cloud_normals.rows; ++y) |
||||
{ |
||||
const _Tn* srow = cloud_normals.ptr<_Tn>(y); |
||||
const _Tn* send = srow + cloud_normals.cols * s_chs; |
||||
|
||||
const _Msk* mrow = mask.ptr<_Msk>(y); |
||||
|
||||
for (; srow != send; srow += s_chs, mrow += m_chs) |
||||
if (!isNan(mrow)) |
||||
normals->SetTuple(pos++, srow); |
||||
} |
||||
} |
||||
|
||||
template<typename _Tn, typename _Msk> |
||||
void cv::viz::vtkCloudMatSource::filterNanTCoordsCopy(const Mat& _tcoords, const Mat& mask, int total) |
||||
{ |
||||
typedef Vec<_Tn, 2> Vec2; |
||||
tcoords = vtkSmartPointer< typename VtkDepthTraits<_Tn>::array_type >::New(); |
||||
tcoords->SetName("TextureCoordinates"); |
||||
tcoords->SetNumberOfComponents(2); |
||||
tcoords->SetNumberOfTuples(total); |
||||
|
||||
int pos = 0; |
||||
for (int y = 0; y < mask.rows; ++y) |
||||
{ |
||||
const Vec2* srow = _tcoords.ptr<Vec2>(y); |
||||
const Vec2* send = srow + _tcoords.cols; |
||||
const _Msk* mrow = mask.ptr<_Msk>(y); |
||||
|
||||
for (; srow != send; ++srow, mrow += mask.channels()) |
||||
if (!isNan(mrow)) |
||||
tcoords->SetTuple(pos++, srow->val); |
||||
} |
||||
} |
@ -1,96 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __vtkCloudMatSource_h |
||||
#define __vtkCloudMatSource_h |
||||
|
||||
#include <opencv2/core.hpp> |
||||
#include <vtkPolyDataAlgorithm.h> |
||||
#include <vtkSmartPointer.h> |
||||
#include <vtkPoints.h> |
||||
#include <vtkCellArray.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkCloudMatSource : public vtkPolyDataAlgorithm |
||||
{ |
||||
public: |
||||
static vtkCloudMatSource *New(); |
||||
vtkTypeMacro(vtkCloudMatSource,vtkPolyDataAlgorithm) |
||||
|
||||
virtual int SetCloud(InputArray cloud); |
||||
virtual int SetColorCloud(InputArray cloud, InputArray colors); |
||||
virtual int SetColorCloudNormals(InputArray cloud, InputArray colors, InputArray normals); |
||||
virtual int SetColorCloudNormalsTCoords(InputArray cloud, InputArray colors, InputArray normals, InputArray tcoords); |
||||
|
||||
protected: |
||||
vtkCloudMatSource(); |
||||
~vtkCloudMatSource(); |
||||
|
||||
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); |
||||
|
||||
vtkSmartPointer<vtkPoints> points; |
||||
vtkSmartPointer<vtkCellArray> vertices; |
||||
vtkSmartPointer<vtkUnsignedCharArray> scalars; |
||||
vtkSmartPointer<vtkDataArray> normals; |
||||
vtkSmartPointer<vtkDataArray> tcoords; |
||||
private: |
||||
vtkCloudMatSource(const vtkCloudMatSource&); // Not implemented.
|
||||
void operator=(const vtkCloudMatSource&); // Not implemented.
|
||||
|
||||
template<typename _Tp> int filterNanCopy(const Mat& cloud); |
||||
template<typename _Msk> void filterNanColorsCopy(const Mat& cloud_colors, const Mat& mask, int total); |
||||
|
||||
template<typename _Tn, typename _Msk> |
||||
void filterNanNormalsCopy(const Mat& cloud_normals, const Mat& mask, int total); |
||||
|
||||
template<typename _Tn, typename _Msk> |
||||
void filterNanTCoordsCopy(const Mat& tcoords, const Mat& mask, int total); |
||||
}; |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -1,226 +0,0 @@ |
||||
/*M/////////////////////////////////////////////////////////////////////////////////////// |
||||
// |
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
||||
// |
||||
// By downloading, copying, installing or using the software you agree to this license. |
||||
// If you do not agree to this license, do not download, install, |
||||
// copy or use the software. |
||||
// |
||||
// |
||||
// License Agreement |
||||
// For Open Source Computer Vision Library |
||||
// |
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
||||
// Third party copyrights are property of their respective owners. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without modification, |
||||
// are permitted provided that the following conditions are met: |
||||
// |
||||
// * Redistribution's of source code must retain the above copyright notice, |
||||
// this list of conditions and the following disclaimer. |
||||
// |
||||
// * Redistribution's in binary form must reproduce the above copyright notice, |
||||
// this list of conditions and the following disclaimer in the documentation |
||||
// and/or other materials provided with the distribution. |
||||
// |
||||
// * The name of the copyright holders may not be used to endorse or promote products |
||||
// derived from this software without specific prior written permission. |
||||
// |
||||
// This software is provided by the copyright holders and contributors "as is" and |
||||
// any express or implied warranties, including, but not limited to, the implied |
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed. |
||||
// In no event shall the Intel Corporation or contributors be liable for any direct, |
||||
// indirect, incidental, special, exemplary, or consequential damages |
||||
// (including, but not limited to, procurement of substitute goods or services; |
||||
// loss of use, data, or profits; or business interruption) however caused |
||||
// and on any theory of liability, whether in contract, strict liability, |
||||
// or tort (including negligence or otherwise) arising in any way out of |
||||
// the use of this software, even if advised of the possibility of such damage. |
||||
// |
||||
// Authors: |
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com |
||||
// |
||||
// This workaround code was taken from PCL library(www.pointclouds.org) |
||||
// |
||||
//M*/ |
||||
|
||||
#import <Cocoa/Cocoa.h> |
||||
#include <vtkCocoaRenderWindow.h> |
||||
#include <vtkCocoaRenderWindowInteractor.h> |
||||
#include <vtkObjectFactory.h> |
||||
#include <vtkSmartPointer.h> |
||||
|
||||
namespace cv { namespace viz { |
||||
vtkSmartPointer<vtkRenderWindowInteractor> vtkCocoaRenderWindowInteractorNew(); |
||||
}} // namespace |
||||
|
||||
#if ((VTK_MAJOR_VERSION < 6) || ((VTK_MAJOR_VERSION == 6) && (VTK_MINOR_VERSION < 2))) |
||||
|
||||
|
||||
//---------------------------------------------------------------------------- |
||||
@interface vtkCocoaServerFix : NSObject |
||||
{ |
||||
vtkCocoaRenderWindow* renWin; |
||||
} |
||||
|
||||
+ (id)cocoaServerWithRenderWindow:(vtkCocoaRenderWindow*)inRenderWindow; |
||||
|
||||
- (void)start; |
||||
- (void)stop; |
||||
- (void)breakEventLoop; |
||||
|
||||
@end |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
@implementation vtkCocoaServerFix |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
- (id)initWithRenderWindow:(vtkCocoaRenderWindow *)inRenderWindow |
||||
{ |
||||
self = [super init]; |
||||
if (self) |
||||
renWin = inRenderWindow; |
||||
return self; |
||||
} |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
+ (id)cocoaServerWithRenderWindow:(vtkCocoaRenderWindow *)inRenderWindow |
||||
{ |
||||
vtkCocoaServerFix *server = [[[vtkCocoaServerFix alloc] initWithRenderWindow:inRenderWindow] autorelease]; |
||||
return server; |
||||
} |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
- (void)start |
||||
{ |
||||
// Retrieve the NSWindow. |
||||
NSWindow *win = nil; |
||||
if (renWin) |
||||
{ |
||||
win = reinterpret_cast<NSWindow*> (renWin->GetRootWindow ()); |
||||
|
||||
// We don't want to be informed of every window closing, so check for nil. |
||||
if (win != nil) |
||||
{ |
||||
// Register for the windowWillClose notification in order to stop the run loop if the window closes. |
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
||||
[nc addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:win]; |
||||
} |
||||
} |
||||
// Start the NSApplication's run loop |
||||
NSApplication* application = [NSApplication sharedApplication]; |
||||
[application run]; |
||||
} |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
- (void)stop |
||||
{ |
||||
[self breakEventLoop]; |
||||
} |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
- (void)breakEventLoop |
||||
{ |
||||
NSApplication* application = [NSApplication sharedApplication]; |
||||
[application stop:application]; |
||||
|
||||
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined |
||||
location:NSMakePoint(0.0,0.0) |
||||
modifierFlags:0 |
||||
timestamp:0 |
||||
windowNumber:-1 |
||||
context:nil |
||||
subtype:0 |
||||
data1:0 |
||||
data2:0]; |
||||
[application postEvent:event atStart:YES]; |
||||
} |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
- (void)windowWillClose:(NSNotification*)aNotification |
||||
{ |
||||
(void)aNotification; |
||||
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
||||
[nc removeObserver:self name:NSWindowWillCloseNotification object:nil]; |
||||
|
||||
if (renWin) |
||||
{ |
||||
int windowCreated = renWin->GetWindowCreated (); |
||||
if (windowCreated) |
||||
{ |
||||
[self breakEventLoop]; |
||||
|
||||
// The NSWindow is closing, so prevent anyone from accidentally using it |
||||
renWin->SetRootWindow(NULL); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@end |
||||
|
||||
//---------------------------------------------------------------------------- |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
class vtkCocoaRenderWindowInteractorFix : public vtkCocoaRenderWindowInteractor |
||||
{ |
||||
public: |
||||
static vtkCocoaRenderWindowInteractorFix *New (); |
||||
vtkTypeMacro (vtkCocoaRenderWindowInteractorFix, vtkCocoaRenderWindowInteractor) |
||||
|
||||
virtual void Start (); |
||||
virtual void TerminateApp (); |
||||
|
||||
protected: |
||||
vtkCocoaRenderWindowInteractorFix () {} |
||||
~vtkCocoaRenderWindowInteractorFix () {} |
||||
|
||||
private: |
||||
vtkCocoaRenderWindowInteractorFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented. |
||||
void operator = (const vtkCocoaRenderWindowInteractorFix&); // Not implemented. |
||||
}; |
||||
|
||||
vtkStandardNewMacro (vtkCocoaRenderWindowInteractorFix) |
||||
}} |
||||
|
||||
void cv::viz::vtkCocoaRenderWindowInteractorFix::Start () |
||||
{ |
||||
vtkCocoaRenderWindow* renWin = vtkCocoaRenderWindow::SafeDownCast(this->GetRenderWindow ()); |
||||
if (renWin != NULL) |
||||
{ |
||||
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ()); |
||||
if (!this->GetCocoaServer ()) |
||||
{ |
||||
server = [vtkCocoaServerFix cocoaServerWithRenderWindow:renWin]; |
||||
this->SetCocoaServer (reinterpret_cast<void*> (server)); |
||||
} |
||||
|
||||
[server start]; |
||||
} |
||||
} |
||||
|
||||
void cv::viz::vtkCocoaRenderWindowInteractorFix::TerminateApp () |
||||
{ |
||||
vtkCocoaRenderWindow *renWin = vtkCocoaRenderWindow::SafeDownCast (this->RenderWindow); |
||||
if (renWin) |
||||
{ |
||||
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ()); |
||||
[server stop]; |
||||
} |
||||
} |
||||
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> cv::viz::vtkCocoaRenderWindowInteractorNew() |
||||
{ |
||||
return vtkSmartPointer<vtkCocoaRenderWindowInteractorFix>::New(); |
||||
} |
||||
|
||||
|
||||
#else |
||||
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> cv::viz::vtkCocoaRenderWindowInteractorNew() |
||||
{ |
||||
return vtkSmartPointer<vtkCocoaRenderWindowInteractor>::New(); |
||||
} |
||||
|
||||
#endif |
@ -1,143 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
vtkStandardNewMacro(vtkImageMatSource); |
||||
}} |
||||
|
||||
cv::viz::vtkImageMatSource::vtkImageMatSource() |
||||
{ |
||||
this->SetNumberOfInputPorts(0); |
||||
this->ImageData = vtkSmartPointer<vtkImageData>::New(); |
||||
} |
||||
|
||||
int cv::viz::vtkImageMatSource::RequestInformation(vtkInformation *, vtkInformationVector**, vtkInformationVector *outputVector) |
||||
{ |
||||
vtkInformation* outInfo = outputVector->GetInformationObject(0); |
||||
|
||||
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), this->ImageData->GetExtent(), 6); |
||||
outInfo->Set(vtkDataObject::SPACING(), 1.0, 1.0, 1.0); |
||||
outInfo->Set(vtkDataObject::ORIGIN(), 0.0, 0.0, 0.0); |
||||
|
||||
vtkDataObject::SetPointDataActiveScalarInfo(outInfo, this->ImageData->GetScalarType(), this->ImageData->GetNumberOfScalarComponents()); |
||||
return 1; |
||||
} |
||||
|
||||
int cv::viz::vtkImageMatSource::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector *outputVector) |
||||
{ |
||||
vtkInformation *outInfo = outputVector->GetInformationObject(0); |
||||
|
||||
vtkImageData *output = vtkImageData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()) ); |
||||
output->ShallowCopy(this->ImageData); |
||||
return 1; |
||||
} |
||||
|
||||
void cv::viz::vtkImageMatSource::SetImage(InputArray _image) |
||||
{ |
||||
CV_Assert(_image.depth() == CV_8U && (_image.channels() == 1 || _image.channels() == 3 || _image.channels() == 4)); |
||||
|
||||
Mat image = _image.getMat(); |
||||
|
||||
this->ImageData->SetDimensions(image.cols, image.rows, 1); |
||||
#if VTK_MAJOR_VERSION <= 5 |
||||
this->ImageData->SetNumberOfScalarComponents(image.channels()); |
||||
this->ImageData->SetScalarTypeToUnsignedChar(); |
||||
this->ImageData->AllocateScalars(); |
||||
#else |
||||
this->ImageData->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels()); |
||||
#endif |
||||
|
||||
switch(image.channels()) |
||||
{ |
||||
case 1: copyGrayImage(image, this->ImageData); break; |
||||
case 3: copyRGBImage (image, this->ImageData); break; |
||||
case 4: copyRGBAImage(image, this->ImageData); break; |
||||
} |
||||
this->ImageData->Modified(); |
||||
} |
||||
|
||||
void cv::viz::vtkImageMatSource::copyGrayImage(const Mat &source, vtkSmartPointer<vtkImageData> output) |
||||
{ |
||||
unsigned char* dptr = reinterpret_cast<unsigned char*>(output->GetScalarPointer()); |
||||
size_t elem_step = output->GetIncrements()[1]/sizeof(unsigned char); |
||||
|
||||
for (int y = 0; y < source.rows; ++y) |
||||
{ |
||||
unsigned char* drow = dptr + elem_step * y; |
||||
const unsigned char *srow = source.ptr<unsigned char>(y); |
||||
for (int x = 0; x < source.cols; ++x) |
||||
drow[x] = *srow++; |
||||
} |
||||
} |
||||
|
||||
void cv::viz::vtkImageMatSource::copyRGBImage(const Mat &source, vtkSmartPointer<vtkImageData> output) |
||||
{ |
||||
Vec3b* dptr = reinterpret_cast<Vec3b*>(output->GetScalarPointer()); |
||||
size_t elem_step = output->GetIncrements()[1]/sizeof(Vec3b); |
||||
|
||||
for (int y = 0; y < source.rows; ++y) |
||||
{ |
||||
Vec3b* drow = dptr + elem_step * y; |
||||
const unsigned char *srow = source.ptr<unsigned char>(y); |
||||
for (int x = 0; x < source.cols; ++x, srow += source.channels()) |
||||
drow[x] = Vec3b(srow[2], srow[1], srow[0]); |
||||
} |
||||
} |
||||
|
||||
void cv::viz::vtkImageMatSource::copyRGBAImage(const Mat &source, vtkSmartPointer<vtkImageData> output) |
||||
{ |
||||
Vec4b* dptr = reinterpret_cast<Vec4b*>(output->GetScalarPointer()); |
||||
size_t elem_step = output->GetIncrements()[1]/sizeof(Vec4b); |
||||
|
||||
for (int y = 0; y < source.rows; ++y) |
||||
{ |
||||
Vec4b* drow = dptr + elem_step * y; |
||||
const unsigned char *srow = source.ptr<unsigned char>(y); |
||||
for (int x = 0; x < source.cols; ++x, srow += source.channels()) |
||||
drow[x] = Vec4b(srow[2], srow[1], srow[0], srow[3]); |
||||
} |
||||
} |
@ -1,82 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
#ifndef __vtkImageMatSource_h |
||||
#define __vtkImageMatSource_h |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkImageMatSource : public vtkImageAlgorithm |
||||
{ |
||||
public: |
||||
static vtkImageMatSource *New(); |
||||
vtkTypeMacro(vtkImageMatSource,vtkImageAlgorithm); |
||||
|
||||
void SetImage(InputArray image); |
||||
|
||||
protected: |
||||
vtkImageMatSource(); |
||||
~vtkImageMatSource() {} |
||||
|
||||
vtkSmartPointer<vtkImageData> ImageData; |
||||
|
||||
int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*); |
||||
int RequestData (vtkInformation*, vtkInformationVector**, vtkInformationVector*); |
||||
private: |
||||
vtkImageMatSource(const vtkImageMatSource&); // Not implemented.
|
||||
void operator=(const vtkImageMatSource&); // Not implemented.
|
||||
|
||||
static void copyGrayImage(const Mat &source, vtkSmartPointer<vtkImageData> output); |
||||
static void copyRGBImage (const Mat &source, vtkSmartPointer<vtkImageData> output); |
||||
static void copyRGBAImage(const Mat &source, vtkSmartPointer<vtkImageData> output); |
||||
}; |
||||
} |
||||
} |
||||
|
||||
|
||||
#endif |
@ -1,270 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
vtkStandardNewMacro(vtkOBJWriter); |
||||
}} |
||||
|
||||
cv::viz::vtkOBJWriter::vtkOBJWriter() |
||||
{ |
||||
std::ofstream fout; // only used to extract the default precision
|
||||
this->DecimalPrecision = fout.precision(); |
||||
this->FileName = NULL; |
||||
} |
||||
|
||||
cv::viz::vtkOBJWriter::~vtkOBJWriter(){} |
||||
|
||||
void cv::viz::vtkOBJWriter::WriteData() |
||||
{ |
||||
vtkPolyData *input = this->GetInput(); |
||||
if (!input) |
||||
return; |
||||
|
||||
if (!this->FileName ) |
||||
{ |
||||
vtkErrorMacro(<< "No FileName specified! Can't write!"); |
||||
this->SetErrorCode(vtkErrorCode::NoFileNameError); |
||||
return; |
||||
} |
||||
|
||||
vtkDebugMacro(<<"Opening vtk file for writing..."); |
||||
ostream *outfilep = new ofstream(this->FileName, ios::out); |
||||
if (outfilep->fail()) |
||||
{ |
||||
vtkErrorMacro(<< "Unable to open file: "<< this->FileName); |
||||
this->SetErrorCode(vtkErrorCode::CannotOpenFileError); |
||||
delete outfilep; |
||||
return; |
||||
} |
||||
|
||||
std::ostream& outfile = *outfilep; |
||||
|
||||
//write header
|
||||
outfile << "# wavefront obj file written by opencv viz module" << std::endl << std::endl; |
||||
outfile << "mtllib NONE" << std::endl << std::endl; |
||||
|
||||
// write out the points
|
||||
for (int i = 0; i < input->GetNumberOfPoints(); i++) |
||||
{ |
||||
Vec3d p; |
||||
input->GetPoint(i, p.val); |
||||
outfile << std::setprecision(this->DecimalPrecision) << "v " << p[0] << " " << p[1] << " " << p[2] << std::endl; |
||||
} |
||||
|
||||
const int idStart = 1; |
||||
|
||||
// write out the point data
|
||||
vtkSmartPointer<vtkDataArray> normals = input->GetPointData()->GetNormals(); |
||||
if(normals) |
||||
{ |
||||
for (int i = 0; i < normals->GetNumberOfTuples(); i++) |
||||
{ |
||||
Vec3d p; |
||||
normals->GetTuple(i, p.val); |
||||
outfile << std::setprecision(this->DecimalPrecision) << "vn " << p[0] << " " << p[1] << " " << p[2] << std::endl; |
||||
} |
||||
} |
||||
|
||||
vtkSmartPointer<vtkDataArray> tcoords = input->GetPointData()->GetTCoords(); |
||||
if (tcoords) |
||||
{ |
||||
for (int i = 0; i < tcoords->GetNumberOfTuples(); i++) |
||||
{ |
||||
Vec2d p; |
||||
tcoords->GetTuple(i, p.val); |
||||
outfile << std::setprecision(this->DecimalPrecision) << "vt " << p[0] << " " << p[1] << std::endl; |
||||
} |
||||
} |
||||
|
||||
// write out a group name and material
|
||||
outfile << std::endl << "g grp" << idStart << std::endl; |
||||
outfile << "usemtl mtlNONE" << std::endl; |
||||
|
||||
// write out verts if any
|
||||
if (input->GetNumberOfVerts() > 0) |
||||
{ |
||||
vtkIdType npts = 0, *index = 0; |
||||
vtkCellArray *cells = input->GetVerts(); |
||||
for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) |
||||
{ |
||||
outfile << "p "; |
||||
for (int i = 0; i < npts; i++) |
||||
outfile << index[i] + idStart << " "; |
||||
outfile << std::endl; |
||||
} |
||||
} |
||||
|
||||
// write out lines if any
|
||||
if (input->GetNumberOfLines() > 0) |
||||
{ |
||||
vtkIdType npts = 0, *index = 0; |
||||
vtkCellArray *cells = input->GetLines(); |
||||
for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) |
||||
{ |
||||
outfile << "l "; |
||||
if (tcoords) |
||||
{ |
||||
for (int i = 0; i < npts; i++) |
||||
outfile << index[i] + idStart << "/" << index[i] + idStart << " "; |
||||
} |
||||
else |
||||
for (int i = 0; i < npts; i++) |
||||
outfile << index[i] + idStart << " "; |
||||
|
||||
outfile << std::endl; |
||||
} |
||||
} |
||||
|
||||
// write out polys if any
|
||||
if (input->GetNumberOfPolys() > 0) |
||||
{ |
||||
vtkIdType npts = 0, *index = 0; |
||||
vtkCellArray *cells = input->GetPolys(); |
||||
for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) |
||||
{ |
||||
outfile << "f "; |
||||
for (int i = 0; i < npts; i++) |
||||
{ |
||||
if (normals) |
||||
{ |
||||
if (tcoords) |
||||
outfile << index[i] + idStart << "/" << index[i] + idStart << "/" << index[i] + idStart << " "; |
||||
else |
||||
outfile << index[i] + idStart << "//" << index[i] + idStart << " "; |
||||
} |
||||
else |
||||
{ |
||||
if (tcoords) |
||||
outfile << index[i] + idStart << " " << index[i] + idStart << " "; |
||||
else |
||||
outfile << index[i] + idStart << " "; |
||||
} |
||||
} |
||||
outfile << std::endl; |
||||
} |
||||
} |
||||
|
||||
// write out tstrips if any
|
||||
if (input->GetNumberOfStrips() > 0) |
||||
{ |
||||
vtkIdType npts = 0, *index = 0; |
||||
vtkCellArray *cells = input->GetStrips(); |
||||
for (cells->InitTraversal(); cells->GetNextCell(npts, index); ) |
||||
{ |
||||
for (int i = 2, i1, i2; i < npts; ++i) |
||||
{ |
||||
if (i % 2) |
||||
{ |
||||
i1 = i - 1; |
||||
i2 = i - 2; |
||||
} |
||||
else |
||||
{ |
||||
i1 = i - 1; |
||||
i2 = i - 2; |
||||
} |
||||
|
||||
if(normals) |
||||
{ |
||||
if (tcoords) |
||||
{ |
||||
outfile << "f " << index[i1] + idStart << "/" << index[i1] + idStart << "/" << index[i1] + idStart << " " |
||||
<< index[i2]+ idStart << "/" << index[i2] + idStart << "/" << index[i2] + idStart << " " |
||||
<< index[i] + idStart << "/" << index[i] + idStart << "/" << index[i] + idStart << std::endl; |
||||
} |
||||
else |
||||
{ |
||||
outfile << "f " << index[i1] + idStart << "//" << index[i1] + idStart << " " << index[i2] + idStart |
||||
<< "//" << index[i2] + idStart << " " << index[i] + idStart << "//" << index[i] + idStart << std::endl; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
if (tcoords) |
||||
{ |
||||
outfile << "f " << index[i1] + idStart << "/" << index[i1] + idStart << " " << index[i2] + idStart |
||||
<< "/" << index[i2] + idStart << " " << index[i] + idStart << "/" << index[i] + idStart << std::endl; |
||||
} |
||||
else |
||||
outfile << "f " << index[i1] + idStart << " " << index[i2] + idStart << " " << index[i] + idStart << std::endl; |
||||
} |
||||
} /* for (int i = 2; i < npts; ++i) */ |
||||
} |
||||
} /* if (input->GetNumberOfStrips() > 0) */ |
||||
|
||||
vtkDebugMacro(<<"Closing vtk file\n"); |
||||
delete outfilep; |
||||
|
||||
// Delete the file if an error occurred
|
||||
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError) |
||||
{ |
||||
vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName); |
||||
unlink(this->FileName); |
||||
} |
||||
} |
||||
|
||||
void cv::viz::vtkOBJWriter::PrintSelf(ostream& os, vtkIndent indent) |
||||
{ |
||||
Superclass::PrintSelf(os, indent); |
||||
os << indent << "DecimalPrecision: " << DecimalPrecision << "\n"; |
||||
} |
||||
|
||||
int cv::viz::vtkOBJWriter::FillInputPortInformation(int, vtkInformation *info) |
||||
{ |
||||
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData"); |
||||
return 1; |
||||
} |
||||
|
||||
vtkPolyData* cv::viz::vtkOBJWriter::GetInput() |
||||
{ |
||||
return vtkPolyData::SafeDownCast(this->Superclass::GetInput()); |
||||
} |
||||
|
||||
vtkPolyData* cv::viz::vtkOBJWriter::GetInput(int port) |
||||
{ |
||||
return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port)); |
||||
} |
@ -1,91 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __vtkOBJWriter_h |
||||
#define __vtkOBJWriter_h |
||||
|
||||
#include <vtkWriter.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkOBJWriter : public vtkWriter |
||||
{ |
||||
public: |
||||
static vtkOBJWriter *New(); |
||||
vtkTypeMacro(vtkOBJWriter,vtkWriter) |
||||
void PrintSelf(ostream& os, vtkIndent indent); |
||||
|
||||
vtkGetMacro(DecimalPrecision, int) |
||||
vtkSetMacro(DecimalPrecision, int) |
||||
|
||||
// Description:
|
||||
// Specify file name of data file to write.
|
||||
vtkSetStringMacro(FileName) |
||||
vtkGetStringMacro(FileName) |
||||
|
||||
// Description:
|
||||
// Get the input to this writer.
|
||||
vtkPolyData* GetInput(); |
||||
vtkPolyData* GetInput(int port); |
||||
|
||||
protected: |
||||
vtkOBJWriter(); |
||||
~vtkOBJWriter(); |
||||
|
||||
void WriteData(); |
||||
int FillInputPortInformation(int port, vtkInformation *info); |
||||
|
||||
int DecimalPrecision; |
||||
char *FileName; |
||||
|
||||
private: |
||||
vtkOBJWriter(const vtkOBJWriter&); // Not implemented.
|
||||
void operator=(const vtkOBJWriter&); // Not implemented.
|
||||
}; |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -1,110 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
vtkStandardNewMacro(vtkTrajectorySource); |
||||
}} |
||||
|
||||
cv::viz::vtkTrajectorySource::vtkTrajectorySource() { SetNumberOfInputPorts(0); } |
||||
cv::viz::vtkTrajectorySource::~vtkTrajectorySource() {} |
||||
|
||||
void cv::viz::vtkTrajectorySource::SetTrajectory(InputArray _traj) |
||||
{ |
||||
CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT); |
||||
CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16)); |
||||
|
||||
Mat traj; |
||||
_traj.getMat().convertTo(traj, CV_64F); |
||||
const Affine3d* dpath = traj.ptr<Affine3d>(); |
||||
size_t total = traj.total(); |
||||
|
||||
points = vtkSmartPointer<vtkPoints>::New(); |
||||
points->SetDataType(VTK_DOUBLE); |
||||
points->SetNumberOfPoints((vtkIdType)total); |
||||
|
||||
tensors = vtkSmartPointer<vtkDoubleArray>::New(); |
||||
tensors->SetNumberOfComponents(9); |
||||
tensors->SetNumberOfTuples((vtkIdType)total); |
||||
|
||||
for(size_t i = 0; i < total; ++i, ++dpath) |
||||
{ |
||||
Matx33d R = dpath->rotation().t(); // transposed because of
|
||||
tensors->SetTuple((vtkIdType)i, R.val); // column major order
|
||||
|
||||
Vec3d p = dpath->translation(); |
||||
points->SetPoint((vtkIdType)i, p.val); |
||||
} |
||||
} |
||||
|
||||
cv::Mat cv::viz::vtkTrajectorySource::ExtractPoints(InputArray _traj) |
||||
{ |
||||
CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT); |
||||
CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16)); |
||||
|
||||
Mat points(1, (int)_traj.total(), CV_MAKETYPE(_traj.depth(), 3)); |
||||
const Affine3d* dpath = _traj.getMat().ptr<Affine3d>(); |
||||
const Affine3f* fpath = _traj.getMat().ptr<Affine3f>(); |
||||
|
||||
if (_traj.depth() == CV_32F) |
||||
for(int i = 0; i < points.cols; ++i) |
||||
points.at<Vec3f>(i) = fpath[i].translation(); |
||||
|
||||
if (_traj.depth() == CV_64F) |
||||
for(int i = 0; i < points.cols; ++i) |
||||
points.at<Vec3d>(i) = dpath[i].translation(); |
||||
|
||||
return points; |
||||
} |
||||
|
||||
int cv::viz::vtkTrajectorySource::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector) |
||||
{ |
||||
vtkInformation *outInfo = outputVector->GetInformationObject(0); |
||||
vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); |
||||
output->SetPoints(points); |
||||
output->GetPointData()->SetTensors(tensors); |
||||
return 1; |
||||
} |
@ -1,84 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __vtkTrajectorySource_h |
||||
#define __vtkTrajectorySource_h |
||||
|
||||
#include <opencv2/core/mat.hpp> |
||||
#include <vtkPolyDataAlgorithm.h> |
||||
#include <vtkSmartPointer.h> |
||||
#include <vtkPoints.h> |
||||
#include <vtkCellArray.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkTrajectorySource : public vtkPolyDataAlgorithm |
||||
{ |
||||
public: |
||||
static vtkTrajectorySource *New(); |
||||
vtkTypeMacro(vtkTrajectorySource,vtkPolyDataAlgorithm) |
||||
|
||||
virtual void SetTrajectory(InputArray trajectory); |
||||
|
||||
static Mat ExtractPoints(InputArray trajectory); |
||||
|
||||
protected: |
||||
vtkTrajectorySource(); |
||||
~vtkTrajectorySource(); |
||||
|
||||
vtkSmartPointer<vtkPoints> points; |
||||
vtkSmartPointer<vtkDoubleArray> tensors; |
||||
|
||||
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); |
||||
private: |
||||
vtkTrajectorySource(const vtkTrajectorySource&); // Not implemented.
|
||||
void operator=(const vtkTrajectorySource&); // Not implemented.
|
||||
|
||||
}; |
||||
} |
||||
} |
||||
|
||||
#endif |
File diff suppressed because it is too large
Load Diff
@ -1,169 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__ |
||||
#define __OPENCV_VIZ_INTERACTOR_STYLE_H__ |
||||
|
||||
#include <vtkInteractorStyle.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkVizInteractorStyle : public vtkInteractorStyle |
||||
{ |
||||
public: |
||||
static vtkVizInteractorStyle *New(); |
||||
vtkTypeMacro(vtkVizInteractorStyle, vtkInteractorStyle) |
||||
void PrintSelf(ostream& os, vtkIndent indent); |
||||
|
||||
virtual void OnChar(); |
||||
virtual void OnKeyDown(); |
||||
virtual void OnKeyUp(); |
||||
|
||||
virtual void OnMouseMove(); |
||||
virtual void OnLeftButtonDown(); |
||||
virtual void OnLeftButtonUp(); |
||||
virtual void OnMiddleButtonDown(); |
||||
virtual void OnMiddleButtonUp(); |
||||
virtual void OnRightButtonDown(); |
||||
virtual void OnRightButtonUp(); |
||||
virtual void OnMouseWheelForward(); |
||||
virtual void OnMouseWheelBackward(); |
||||
virtual void OnTimer(); |
||||
|
||||
virtual void Rotate(); |
||||
virtual void Spin(); |
||||
virtual void Pan(); |
||||
virtual void Dolly(); |
||||
|
||||
vtkSetMacro(FlyMode,bool) |
||||
vtkGetMacro(FlyMode,bool) |
||||
|
||||
|
||||
vtkSetMacro(MotionFactor, double) |
||||
vtkGetMacro(MotionFactor, double) |
||||
|
||||
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); |
||||
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); |
||||
|
||||
void setWidgetActorMap(const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; } |
||||
void saveScreenshot(const String &file); |
||||
void exportScene(const String &file); |
||||
void exportScene(); |
||||
void changePointsSize(float delta); |
||||
void setRepresentationToPoints(); |
||||
void printCameraParams(); |
||||
void toggleFullScreen(); |
||||
void resetViewerPose(); |
||||
void toggleStereo(); |
||||
void printHelp(); |
||||
|
||||
// Set the basic unit step size : by default 1/250 of bounding diagonal
|
||||
vtkSetMacro(MotionStepSize,double) |
||||
vtkGetMacro(MotionStepSize,double) |
||||
|
||||
// Set acceleration factor when shift key is applied : default 10
|
||||
vtkSetMacro(MotionAccelerationFactor,double) |
||||
vtkGetMacro(MotionAccelerationFactor,double) |
||||
|
||||
// Set the basic angular unit for turning : default 1 degree
|
||||
vtkSetMacro(AngleStepSize,double) |
||||
vtkGetMacro(AngleStepSize,double) |
||||
|
||||
private: |
||||
Ptr<WidgetActorMap> widget_actor_map_; |
||||
|
||||
Vec2i win_size_; |
||||
Vec2i win_pos_; |
||||
Vec2i max_win_size_; |
||||
|
||||
void zoomIn(); |
||||
void zoomOut(); |
||||
|
||||
protected: |
||||
vtkVizInteractorStyle(); |
||||
~vtkVizInteractorStyle(); |
||||
|
||||
virtual void Dolly(double factor); |
||||
|
||||
void Fly(); |
||||
void FlyByMouse(); |
||||
void FlyByKey(); |
||||
void SetupMotionVars(); |
||||
void MotionAlongVector(const Vec3d& vector, double amount, vtkCamera* cam); |
||||
|
||||
private: |
||||
vtkVizInteractorStyle(const vtkVizInteractorStyle&); |
||||
vtkVizInteractorStyle& operator=(const vtkVizInteractorStyle&); |
||||
|
||||
//! True for red-blue colors, false for magenta-green.
|
||||
bool stereo_anaglyph_redblue_; |
||||
|
||||
void (*keyboardCallback_)(const KeyboardEvent&, void*); |
||||
void *keyboard_callback_cookie_; |
||||
|
||||
void (*mouseCallback_)(const MouseEvent&, void*); |
||||
void *mouse_callback_cookie_; |
||||
|
||||
bool FlyMode; |
||||
double MotionFactor; |
||||
|
||||
int getModifiers(); |
||||
|
||||
// from fly
|
||||
unsigned char KeysDown; |
||||
double DiagonalLength; |
||||
double MotionStepSize; |
||||
double MotionUserScale; |
||||
double MotionAccelerationFactor; |
||||
double AngleStepSize; |
||||
double DeltaYaw; |
||||
double DeltaPitch; |
||||
}; |
||||
} // end namespace viz
|
||||
} // end namespace cv
|
||||
|
||||
#endif |
@ -1,107 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
vtkStandardNewMacro(vtkXYZReader); |
||||
}} |
||||
|
||||
|
||||
cv::viz::vtkXYZReader::vtkXYZReader() |
||||
{ |
||||
this->FileName = 0; |
||||
this->SetNumberOfInputPorts(0); |
||||
} |
||||
|
||||
cv::viz::vtkXYZReader::~vtkXYZReader() |
||||
{ |
||||
this->SetFileName(0); |
||||
} |
||||
|
||||
void cv::viz::vtkXYZReader::PrintSelf(ostream& os, vtkIndent indent) |
||||
{ |
||||
this->Superclass::PrintSelf(os,indent); |
||||
os << indent << "FileName: " << (this->FileName ? this->FileName : "(none)") << "\n"; |
||||
} |
||||
|
||||
int cv::viz::vtkXYZReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) |
||||
{ |
||||
// Make sure we have a file to read.
|
||||
if(!this->FileName) |
||||
{ |
||||
vtkErrorMacro("A FileName must be specified."); |
||||
return 0; |
||||
} |
||||
|
||||
// Open the input file.
|
||||
ifstream fin(this->FileName); |
||||
if(!fin) |
||||
{ |
||||
vtkErrorMacro("Error opening file " << this->FileName); |
||||
return 0; |
||||
} |
||||
|
||||
// Allocate objects to hold points and vertex cells.
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); |
||||
vtkSmartPointer<vtkCellArray> verts = vtkSmartPointer<vtkCellArray>::New(); |
||||
|
||||
// Read points from the file.
|
||||
vtkDebugMacro("Reading points from file " << this->FileName); |
||||
double x[3]; |
||||
while(fin >> x[0] >> x[1] >> x[2]) |
||||
{ |
||||
vtkIdType id = points->InsertNextPoint(x); |
||||
verts->InsertNextCell(1, &id); |
||||
} |
||||
vtkDebugMacro("Read " << points->GetNumberOfPoints() << " points."); |
||||
|
||||
// Store the points and cells in the output data object.
|
||||
vtkPolyData* output = vtkPolyData::GetData(outputVector); |
||||
output->SetPoints(points); |
||||
output->SetVerts(verts); |
||||
|
||||
return 1; |
||||
} |
@ -1,80 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __vtkXYZReader_h |
||||
#define __vtkXYZReader_h |
||||
|
||||
#include "vtkPolyDataAlgorithm.h" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkXYZReader : public vtkPolyDataAlgorithm |
||||
{ |
||||
public: |
||||
static vtkXYZReader* New(); |
||||
vtkTypeMacro(vtkXYZReader,vtkPolyDataAlgorithm) |
||||
void PrintSelf(ostream& os, vtkIndent indent); |
||||
|
||||
// Description:
|
||||
// Set/Get the name of the file from which to read points.
|
||||
vtkSetStringMacro(FileName) |
||||
vtkGetStringMacro(FileName) |
||||
|
||||
protected: |
||||
vtkXYZReader(); |
||||
~vtkXYZReader(); |
||||
|
||||
char* FileName; |
||||
|
||||
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*); |
||||
private: |
||||
vtkXYZReader(const vtkXYZReader&); // Not implemented.
|
||||
void operator=(const vtkXYZReader&); // Not implemented.
|
||||
}; |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -1,122 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../precomp.hpp" |
||||
|
||||
namespace cv { namespace viz |
||||
{ |
||||
vtkStandardNewMacro(vtkXYZWriter); |
||||
}} |
||||
|
||||
cv::viz::vtkXYZWriter::vtkXYZWriter() |
||||
{ |
||||
std::ofstream fout; // only used to extract the default precision
|
||||
this->DecimalPrecision = fout.precision(); |
||||
} |
||||
|
||||
void cv::viz::vtkXYZWriter::WriteData() |
||||
{ |
||||
vtkPolyData *input = this->GetInput(); |
||||
if (!input) |
||||
return; |
||||
|
||||
if (!this->FileName ) |
||||
{ |
||||
vtkErrorMacro(<< "No FileName specified! Can't write!"); |
||||
this->SetErrorCode(vtkErrorCode::NoFileNameError); |
||||
return; |
||||
} |
||||
|
||||
vtkDebugMacro(<<"Opening vtk file for writing..."); |
||||
ostream *outfilep = new ofstream(this->FileName, ios::out); |
||||
if (outfilep->fail()) |
||||
{ |
||||
vtkErrorMacro(<< "Unable to open file: "<< this->FileName); |
||||
this->SetErrorCode(vtkErrorCode::CannotOpenFileError); |
||||
delete outfilep; |
||||
return; |
||||
} |
||||
|
||||
ostream &outfile = *outfilep; |
||||
|
||||
for(vtkIdType i = 0; i < input->GetNumberOfPoints(); ++i) |
||||
{ |
||||
Vec3d p; |
||||
input->GetPoint(i, p.val); |
||||
outfile << std::setprecision(this->DecimalPrecision) << p[0] << " " << p[1] << " " << p[2] << std::endl; |
||||
} |
||||
|
||||
// Close the file
|
||||
vtkDebugMacro(<<"Closing vtk file\n"); |
||||
delete outfilep; |
||||
|
||||
// Delete the file if an error occurred
|
||||
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError) |
||||
{ |
||||
vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName); |
||||
unlink(this->FileName); |
||||
} |
||||
} |
||||
|
||||
int cv::viz::vtkXYZWriter::FillInputPortInformation(int, vtkInformation *info) |
||||
{ |
||||
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData"); |
||||
return 1; |
||||
} |
||||
|
||||
void cv::viz::vtkXYZWriter::PrintSelf(ostream& os, vtkIndent indent) |
||||
{ |
||||
this->Superclass::PrintSelf(os,indent); |
||||
os << indent << "DecimalPrecision: " << this->DecimalPrecision << "\n"; |
||||
} |
||||
|
||||
vtkPolyData* cv::viz::vtkXYZWriter::GetInput() |
||||
{ |
||||
return vtkPolyData::SafeDownCast(this->Superclass::GetInput()); |
||||
} |
||||
|
||||
vtkPolyData* cv::viz::vtkXYZWriter::GetInput(int port) |
||||
{ |
||||
return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port)); |
||||
} |
@ -1,90 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __vtkXYZWriter_h |
||||
#define __vtkXYZWriter_h |
||||
|
||||
#include "vtkWriter.h" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace viz |
||||
{ |
||||
class vtkXYZWriter : public vtkWriter |
||||
{ |
||||
public: |
||||
static vtkXYZWriter *New(); |
||||
vtkTypeMacro(vtkXYZWriter,vtkWriter) |
||||
void PrintSelf(ostream& os, vtkIndent indent); |
||||
|
||||
vtkGetMacro(DecimalPrecision, int) |
||||
vtkSetMacro(DecimalPrecision, int) |
||||
|
||||
// Description:
|
||||
// Specify file name of data file to write.
|
||||
vtkSetStringMacro(FileName) |
||||
vtkGetStringMacro(FileName) |
||||
|
||||
// Description:
|
||||
// Get the input to this writer.
|
||||
vtkPolyData* GetInput(); |
||||
vtkPolyData* GetInput(int port); |
||||
|
||||
protected: |
||||
vtkXYZWriter(); |
||||
~vtkXYZWriter(){} |
||||
|
||||
void WriteData(); |
||||
int FillInputPortInformation(int port, vtkInformation *info); |
||||
|
||||
int DecimalPrecision; |
||||
char *FileName; |
||||
|
||||
private: |
||||
vtkXYZWriter(const vtkXYZWriter&); // Not implemented.
|
||||
void operator=(const vtkXYZWriter&); // Not implemented.
|
||||
}; |
||||
} |
||||
} |
||||
#endif |
@ -1,352 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// widget implementation
|
||||
|
||||
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; |
||||
} |
||||
|
||||
cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other) |
||||
{ |
||||
if (!impl_) |
||||
impl_ = new Impl(); |
||||
|
||||
if (other.impl_) |
||||
impl_->prop = other.impl_->prop; |
||||
return *this; |
||||
} |
||||
|
||||
cv::viz::Widget::~Widget() |
||||
{ |
||||
if (impl_) |
||||
{ |
||||
delete impl_; |
||||
impl_ = 0; |
||||
} |
||||
} |
||||
|
||||
cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) |
||||
{ |
||||
CV_Assert(vtkPLYReader::CanReadFile(file_name.c_str())); |
||||
|
||||
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New(); |
||||
reader->SetFileName(file_name.c_str()); |
||||
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); |
||||
mapper->SetInputConnection( reader->GetOutputPort() ); |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
mapper->ImmediateModeRenderingOff(); |
||||
#endif |
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
||||
actor->GetProperty()->SetInterpolationToFlat(); |
||||
actor->GetProperty()->BackfaceCullingOn(); |
||||
actor->SetMapper(mapper); |
||||
|
||||
Widget widget; |
||||
WidgetAccessor::setProp(widget, actor); |
||||
return widget; |
||||
} |
||||
|
||||
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: actor->GetProperty()->SetPointSize(float(value)); break; |
||||
case OPACITY: actor->GetProperty()->SetOpacity(value); break; |
||||
case LINE_WIDTH: actor->GetProperty()->SetLineWidth(float(value)); break; |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
case IMMEDIATE_RENDERING: actor->GetMapper()->SetImmediateModeRendering(int(value)); break; |
||||
#else |
||||
case IMMEDIATE_RENDERING: std::cerr << "this property has no effect" << std::endl; break; |
||||
#endif |
||||
case AMBIENT: actor->GetProperty()->SetAmbient(float(value)); break; |
||||
case LIGHTING: |
||||
{ |
||||
if (value == 0) |
||||
actor->GetProperty()->LightingOff(); |
||||
else |
||||
actor->GetProperty()->LightingOn(); |
||||
break; |
||||
} |
||||
case FONT_SIZE: |
||||
{ |
||||
vtkTextActor* text_actor = vtkTextActor::SafeDownCast(actor); |
||||
CV_Assert("Widget does not have text content." && text_actor); |
||||
text_actor->GetTextProperty()->SetFontSize(int(value)); |
||||
break; |
||||
} |
||||
case REPRESENTATION: |
||||
{ |
||||
switch (int(value)) |
||||
{ |
||||
case REPRESENTATION_POINTS: actor->GetProperty()->SetRepresentationToPoints(); break; |
||||
case REPRESENTATION_WIREFRAME: actor->GetProperty()->SetRepresentationToWireframe(); break; |
||||
case REPRESENTATION_SURFACE: actor->GetProperty()->SetRepresentationToSurface(); break; |
||||
} |
||||
break; |
||||
} |
||||
case SHADING: |
||||
{ |
||||
switch (int(value)) |
||||
{ |
||||
case SHADING_FLAT: actor->GetProperty()->SetInterpolationToFlat(); break; |
||||
case SHADING_GOURAUD: |
||||
{ |
||||
if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals()) |
||||
{ |
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); |
||||
CV_Assert("Can't set shading property for such type of widget" && mapper); |
||||
|
||||
vtkSmartPointer<vtkPolyData> with_normals = VtkUtils::ComputeNormals(mapper->GetInput()); |
||||
VtkUtils::SetInputData(mapper, with_normals); |
||||
} |
||||
actor->GetProperty()->SetInterpolationToGouraud(); |
||||
break; |
||||
} |
||||
case SHADING_PHONG: |
||||
{ |
||||
if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals()) |
||||
{ |
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); |
||||
CV_Assert("Can't set shading property for such type of widget" && mapper); |
||||
|
||||
vtkSmartPointer<vtkPolyData> with_normals = VtkUtils::ComputeNormals(mapper->GetInput()); |
||||
VtkUtils::SetInputData(mapper, with_normals); |
||||
} |
||||
actor->GetProperty()->SetInterpolationToPhong(); |
||||
break; |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
default: |
||||
CV_Assert("setRenderingProperty: Unknown property"); |
||||
} |
||||
actor->Modified(); |
||||
} |
||||
|
||||
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) |
||||
{ |
||||
case POINT_SIZE: value = actor->GetProperty()->GetPointSize(); break; |
||||
case OPACITY: value = actor->GetProperty()->GetOpacity(); break; |
||||
case LINE_WIDTH: value = actor->GetProperty()->GetLineWidth(); break; |
||||
#if VTK_MAJOR_VERSION < 8 |
||||
case IMMEDIATE_RENDERING: value = actor->GetMapper()->GetImmediateModeRendering(); break; |
||||
#else |
||||
case IMMEDIATE_RENDERING: std::cerr << "this property has no effect" << std::endl; break; |
||||
#endif |
||||
case AMBIENT: value = actor->GetProperty()->GetAmbient(); break; |
||||
case LIGHTING: value = actor->GetProperty()->GetLighting(); break; |
||||
case FONT_SIZE: |
||||
{ |
||||
vtkTextActor* text_actor = vtkTextActor::SafeDownCast(actor); |
||||
CV_Assert("Widget does not have text content." && text_actor); |
||||
value = text_actor->GetTextProperty()->GetFontSize();; |
||||
break; |
||||
} |
||||
case REPRESENTATION: |
||||
{ |
||||
switch (actor->GetProperty()->GetRepresentation()) |
||||
{ |
||||
case VTK_POINTS: value = REPRESENTATION_POINTS; break; |
||||
case VTK_WIREFRAME: value = REPRESENTATION_WIREFRAME; break; |
||||
case VTK_SURFACE: value = REPRESENTATION_SURFACE; break; |
||||
} |
||||
break; |
||||
} |
||||
case SHADING: |
||||
{ |
||||
switch (actor->GetProperty()->GetInterpolation()) |
||||
{ |
||||
case VTK_FLAT: value = SHADING_FLAT; break; |
||||
case VTK_GOURAUD: value = SHADING_GOURAUD; break; |
||||
case VTK_PHONG: value = SHADING_PHONG; break; |
||||
} |
||||
break; |
||||
} |
||||
default: |
||||
CV_Assert("getRenderingProperty: Unknown property"); |
||||
} |
||||
return value; |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// widget accessor implementation
|
||||
|
||||
vtkSmartPointer<vtkProp> cv::viz::WidgetAccessor::getProp(const Widget& widget) |
||||
{ |
||||
return widget.impl_->prop; |
||||
} |
||||
|
||||
void cv::viz::WidgetAccessor::setProp(Widget& widget, vtkSmartPointer<vtkProp> prop) |
||||
{ |
||||
widget.impl_->prop = prop; |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// widget3D implementation
|
||||
|
||||
void cv::viz::Widget3D::setPose(const Affine3d &pose) |
||||
{ |
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Widget is not 3D." && actor); |
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = vtkmatrix(pose.matrix); |
||||
actor->SetUserMatrix(matrix); |
||||
actor->Modified(); |
||||
} |
||||
|
||||
void cv::viz::Widget3D::updatePose(const Affine3d &pose) |
||||
{ |
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Widget is not 3D." && actor); |
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); |
||||
if (!matrix) |
||||
{ |
||||
setPose(pose); |
||||
return; |
||||
} |
||||
|
||||
Affine3d updated_pose = pose * Affine3d(*matrix->Element); |
||||
matrix = vtkmatrix(updated_pose.matrix); |
||||
|
||||
actor->SetUserMatrix(matrix); |
||||
actor->Modified(); |
||||
} |
||||
|
||||
cv::Affine3d cv::viz::Widget3D::getPose() const |
||||
{ |
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Widget is not 3D." && actor); |
||||
if (!actor->GetUserMatrix()) |
||||
{ |
||||
return Affine3d(); // empty user matrix, return an identity transform.
|
||||
} |
||||
return Affine3d(*actor->GetUserMatrix()->Element); |
||||
} |
||||
|
||||
void cv::viz::Widget3D::applyTransform(const Affine3d &transform) |
||||
{ |
||||
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Widget is not 3D actor." && actor); |
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); |
||||
CV_Assert("Widget doesn't have a polydata mapper" && mapper); |
||||
|
||||
mapper->Update(); // #10945
|
||||
VtkUtils::SetInputData(mapper, VtkUtils::TransformPolydata(mapper->GetInput(), transform)); |
||||
mapper->Update(); |
||||
} |
||||
|
||||
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); |
||||
actor->GetProperty()->SetEdgeColor(c.val); |
||||
actor->Modified(); |
||||
} |
||||
|
||||
template<> cv::viz::Widget3D cv::viz::Widget::cast<cv::viz::Widget3D>() const |
||||
{ |
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Widget cannot be cast." && actor); |
||||
|
||||
Widget3D widget; |
||||
WidgetAccessor::setProp(widget, actor); |
||||
return widget; |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// widget2D implementation
|
||||
|
||||
void cv::viz::Widget2D::setColor(const Color &color) |
||||
{ |
||||
vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Widget type is not supported." && actor); |
||||
Color c = vtkcolor(color); |
||||
actor->GetProperty()->SetColor(c.val); |
||||
actor->Modified(); |
||||
} |
||||
|
||||
template<> cv::viz::Widget2D cv::viz::Widget::cast<cv::viz::Widget2D>() const |
||||
{ |
||||
vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); |
||||
CV_Assert("Widget cannot be cast." && actor); |
||||
|
||||
Widget2D widget; |
||||
WidgetAccessor::setProp(widget, actor); |
||||
return widget; |
||||
} |
@ -1,27 +0,0 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "test_precomp.hpp" |
||||
|
||||
cv::String cv::Path::combine(const String& item1, const String& item2) |
||||
{ |
||||
if (item1.empty()) |
||||
return item2; |
||||
|
||||
if (item2.empty()) |
||||
return item1; |
||||
|
||||
char last = item1[item1.size()-1]; |
||||
|
||||
bool need_append = last != '/' && last != '\\'; |
||||
return item1 + (need_append ? "/" : "") + item2; |
||||
} |
||||
|
||||
cv::String cv::Path::combine(const String& item1, const String& item2, const String& item3) |
||||
{ return combine(combine(item1, item2), item3); } |
||||
|
||||
cv::String cv::Path::change_extension(const String& file, const String& ext) |
||||
{ |
||||
String::size_type pos = file.find_last_of('.'); |
||||
return pos == String::npos ? file : file.substr(0, pos+1) + ext; |
||||
} |
@ -1,87 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// Authors:
|
||||
// * Ozan Tonkal, ozantonkal@gmail.com
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIZ_TEST_COMMON_HPP |
||||
#define OPENCV_VIZ_TEST_COMMON_HPP |
||||
|
||||
#include <opencv2/viz/vizcore.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
struct Path |
||||
{ |
||||
static String combine(const String& item1, const String& item2); |
||||
static String combine(const String& item1, const String& item2, const String& item3); |
||||
static String change_extension(const String& file, const String& ext); |
||||
}; |
||||
|
||||
inline cv::String get_dragon_ply_file_path() |
||||
{ |
||||
return Path::combine(cvtest::TS::ptr()->get_data_path(), "dragon.ply"); |
||||
} |
||||
|
||||
template<typename _Tp> |
||||
inline std::vector< Affine3<_Tp> > generate_test_trajectory() |
||||
{ |
||||
std::vector< Affine3<_Tp> > result; |
||||
|
||||
for (int i = 0, j = 0; i <= 270; i += 3, j += 10) |
||||
{ |
||||
double x = 2 * cos(i * 3 * CV_PI/180.0) * (1.0 + 0.5 * cos(1.2 + i * 1.2 * CV_PI/180.0)); |
||||
double y = 0.25 + i/270.0 + sin(j * CV_PI/180.0) * 0.2 * sin(0.6 + j * 1.5 * CV_PI/180.0); |
||||
double z = 2 * sin(i * 3 * CV_PI/180.0) * (1.0 + 0.5 * cos(1.2 + i * CV_PI/180.0)); |
||||
result.push_back(viz::makeCameraPose(Vec3d(x, y, z), Vec3d::all(0.0), Vec3d(0.0, 1.0, 0.0))); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
inline Mat make_gray(const Mat& image) |
||||
{ |
||||
Mat chs[3]; split(image, chs); |
||||
return 0.114 * chs[0] + 0.58 * chs[1] + 0.3 * chs[2]; |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -1,6 +0,0 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "test_precomp.hpp" |
||||
|
||||
CV_TEST_MAIN("viz") |
@ -1,10 +0,0 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "opencv2/ts.hpp" |
||||
#include "test_common.hpp" |
||||
|
||||
namespace opencv_test |
||||
{ |
||||
using namespace cv::viz; |
||||
} |
@ -1,58 +0,0 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "test_precomp.hpp" |
||||
|
||||
namespace opencv_test { namespace { |
||||
|
||||
static void tutorial2() |
||||
{ |
||||
/// 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.0, -1.0, -1.0), Point3d(1.0, 1.0, 1.0)); |
||||
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); |
||||
myWindow.showWidget("Line Widget", axis); |
||||
|
||||
/// Construct a cube widget
|
||||
viz::WCube cube_widget(Point3d(0.5, 0.5, 0.0), Point3d(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); |
||||
|
||||
/// Rodrigues vector
|
||||
Vec3d rot_vec = Vec3d::all(0); |
||||
double translation_phase = 0.0, translation = 0.0; |
||||
while(!myWindow.wasStopped()) |
||||
{ |
||||
/* Rotation using rodrigues */ |
||||
/// Rotate around (1,1,1)
|
||||
rot_vec[0] += CV_PI * 0.01; |
||||
rot_vec[1] += CV_PI * 0.01; |
||||
rot_vec[2] += CV_PI * 0.01; |
||||
|
||||
/// Shift on (1,1,1)
|
||||
translation_phase += CV_PI * 0.01; |
||||
translation = sin(translation_phase); |
||||
|
||||
/// Construct pose
|
||||
Affine3d pose(rot_vec, Vec3d(translation, translation, translation)); |
||||
|
||||
myWindow.setWidgetPose("Cube Widget", pose); |
||||
|
||||
myWindow.spinOnce(1, true); |
||||
} |
||||
} |
||||
|
||||
|
||||
TEST(Viz, DISABLED_tutorial2_pose_of_widget) |
||||
{ |
||||
tutorial2(); |
||||
} |
||||
|
||||
}} // namespace
|
@ -1,64 +0,0 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "test_precomp.hpp" |
||||
|
||||
namespace opencv_test { namespace { |
||||
|
||||
/**
|
||||
* @function main |
||||
*/ |
||||
static void tutorial3(bool camera_pov) |
||||
{ |
||||
/// 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
|
||||
Point3d cam_origin(3.0, 3.0, 3.0), cam_focal_point(3.0, 3.0, 2.0), cam_y_dir(-1.0, 0.0, 0.0); |
||||
|
||||
/// We can get the pose of the cam using makeCameraPose
|
||||
Affine3d camera_pose = viz::makeCameraPose(cam_origin, 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
|
||||
Affine3d transform = viz::makeTransformToGlobal(Vec3d(0.0, -1.0, 0.0), Vec3d(-1.0, 0.0, 0.0), Vec3d(0.0, 0.0, -1.0), cam_origin); |
||||
|
||||
/// Create a cloud widget.
|
||||
Mat dragon_cloud = viz::readCloud(get_dragon_ply_file_path()); |
||||
viz::WCloud cloud_widget(dragon_cloud, viz::Color::green()); |
||||
|
||||
/// Pose of the widget in camera frame
|
||||
Affine3d cloud_pose = Affine3d().rotate(Vec3d(0.0, CV_PI/2, 0.0)).rotate(Vec3d(0.0, 0.0, CV_PI)).translate(Vec3d(0.0, 0.0, 3.0)); |
||||
/// Pose of the widget in global frame
|
||||
Affine3d cloud_pose_global = transform * cloud_pose; |
||||
|
||||
/// Visualize camera frame
|
||||
myWindow.showWidget("CPW_FRUSTUM", viz::WCameraPosition(Vec2f(0.889484f, 0.523599f)), camera_pose); |
||||
if (!camera_pov) |
||||
myWindow.showWidget("CPW", viz::WCameraPosition(0.5), camera_pose); |
||||
|
||||
/// Visualize widget
|
||||
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); |
||||
|
||||
/// Set the viewer pose to that of camera
|
||||
if (camera_pov) |
||||
myWindow.setViewerPose(camera_pose); |
||||
|
||||
/// Start event loop.
|
||||
myWindow.spin(); |
||||
} |
||||
|
||||
TEST(Viz, tutorial3_global_view) |
||||
{ |
||||
tutorial3(false); |
||||
} |
||||
|
||||
TEST(Viz, tutorial3_camera_view) |
||||
{ |
||||
tutorial3(true); |
||||
} |
||||
|
||||
}} // namespace
|
@ -1,65 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2013, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and / or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
#include "test_precomp.hpp" |
||||
|
||||
namespace opencv_test { namespace { |
||||
|
||||
TEST(Viz_viz3d, DISABLED_develop) |
||||
{ |
||||
cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); |
||||
|
||||
cv::viz::Viz3d viz("abc"); |
||||
viz.setBackgroundMeshLab(); |
||||
viz.showWidget("coo", cv::viz::WCoordinateSystem(1)); |
||||
viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud)); |
||||
|
||||
//---->>>>> <to_test_in_future>
|
||||
//std::vector<cv::Affine3d> gt, es;
|
||||
//cv::viz::readTrajectory(gt, "d:/Datasets/trajs/gt%05d.xml");
|
||||
//cv::viz::readTrajectory(es, "d:/Datasets/trajs/es%05d.xml");
|
||||
//cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path());
|
||||
//---->>>>> </to_test_in_future>
|
||||
|
||||
viz.spin(); |
||||
} |
||||
|
||||
}} // namespace
|
@ -1,454 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2013, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and / or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
|
||||
namespace opencv_test { namespace { |
||||
|
||||
TEST(Viz, show_cloud_bluberry) |
||||
{ |
||||
Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); |
||||
|
||||
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); |
||||
|
||||
Viz3d viz("show_cloud_bluberry"); |
||||
viz.setBackgroundColor(Color::black()); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("dragon", WCloud(dragon_cloud, Color::bluberry()), pose); |
||||
|
||||
viz.showWidget("text2d", WText("Bluberry cloud", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_cloud_random_color) |
||||
{ |
||||
Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); |
||||
|
||||
Mat colors(dragon_cloud.size(), CV_8UC3); |
||||
theRNG().fill(colors, RNG::UNIFORM, 0, 255); |
||||
|
||||
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); |
||||
|
||||
Viz3d viz("show_cloud_random_color"); |
||||
viz.setBackgroundMeshLab(); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("dragon", WCloud(dragon_cloud, colors), pose); |
||||
viz.showWidget("text2d", WText("Random color cloud", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_cloud_masked) |
||||
{ |
||||
Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); |
||||
|
||||
Vec3f qnan = Vec3f::all(std::numeric_limits<float>::quiet_NaN()); |
||||
for(int i = 0; i < (int)dragon_cloud.total(); ++i) |
||||
if (i % 15 != 0) |
||||
dragon_cloud.at<Vec3f>(i) = qnan; |
||||
|
||||
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); |
||||
|
||||
Viz3d viz("show_cloud_masked"); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("dragon", WCloud(dragon_cloud), pose); |
||||
viz.showWidget("text2d", WText("Nan masked cloud", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_cloud_collection) |
||||
{ |
||||
Mat cloud = readCloud(get_dragon_ply_file_path()); |
||||
|
||||
WCloudCollection ccol; |
||||
ccol.addCloud(cloud, Color::white(), Affine3d().translate(Vec3d(0, 0, 0)).rotate(Vec3d(CV_PI/2, 0, 0))); |
||||
ccol.addCloud(cloud, Color::blue(), Affine3d().translate(Vec3d(1, 0, 0))); |
||||
ccol.addCloud(cloud, Color::red(), Affine3d().translate(Vec3d(2, 0, 0))); |
||||
ccol.finalize(); |
||||
|
||||
Viz3d viz("show_cloud_collection"); |
||||
viz.setBackgroundColor(Color::mlab()); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("ccol", ccol); |
||||
viz.showWidget("text2d", WText("Cloud collection", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_painted_clouds) |
||||
{ |
||||
Mat cloud = readCloud(get_dragon_ply_file_path()); |
||||
|
||||
Viz3d viz("show_painted_clouds"); |
||||
viz.setBackgroundMeshLab(); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("cloud1", WPaintedCloud(cloud), Affine3d(Vec3d(0.0, -CV_PI/2, 0.0), Vec3d(-1.5, 0.0, 0.0))); |
||||
viz.showWidget("cloud2", WPaintedCloud(cloud, Vec3d(0.0, -0.75, -1.0), Vec3d(0.0, 0.75, 0.0)), Affine3d(Vec3d(0.0, CV_PI/2, 0.0), Vec3d(1.5, 0.0, 0.0))); |
||||
viz.showWidget("cloud3", WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0), Color::blue(), Color::red())); |
||||
viz.showWidget("arrow", WArrow(Vec3d(0.0, 1.0, -1.0), Vec3d(0.0, 1.0, 1.0), 0.009, Color::raspberry())); |
||||
viz.showWidget("text2d", WText("Painted clouds", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_mesh) |
||||
{ |
||||
Mesh mesh = Mesh::load(get_dragon_ply_file_path()); |
||||
|
||||
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); |
||||
|
||||
Viz3d viz("show_mesh"); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("mesh", WMesh(mesh), pose); |
||||
viz.showWidget("text2d", WText("Just mesh", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_mesh_random_colors) |
||||
{ |
||||
Mesh mesh = Mesh::load(get_dragon_ply_file_path()); |
||||
theRNG().fill(mesh.colors, RNG::UNIFORM, 0, 255); |
||||
|
||||
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); |
||||
|
||||
Viz3d viz("show_mesh_random_color"); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("mesh", WMesh(mesh), pose); |
||||
viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG); |
||||
viz.showWidget("text2d", WText("Random color mesh", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_widget_merger) |
||||
{ |
||||
WWidgetMerger merger; |
||||
merger.addWidget(WCube(Vec3d::all(0.0), Vec3d::all(1.0), true, Color::gold())); |
||||
|
||||
RNG& rng = theRNG(); |
||||
for(int i = 0; i < 77; ++i) |
||||
{ |
||||
Vec3b c; |
||||
rng.fill(c, RNG::NORMAL, Scalar::all(128), Scalar::all(48), true); |
||||
merger.addWidget(WSphere(Vec3d(c)*(1.0/255.0), 7.0/255.0, 10, Color(c[2], c[1], c[0]))); |
||||
} |
||||
merger.finalize(); |
||||
|
||||
Viz3d viz("show_mesh_random_color"); |
||||
viz.showWidget("coo", WCoordinateSystem()); |
||||
viz.showWidget("merger", merger); |
||||
viz.showWidget("text2d", WText("Widget merger", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_textured_mesh) |
||||
{ |
||||
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); |
||||
|
||||
std::vector<Vec3d> points; |
||||
std::vector<Vec2d> tcoords; |
||||
std::vector<int> polygons; |
||||
for(size_t i = 0; i < 64; ++i) |
||||
{ |
||||
double angle = CV_PI/2 * i/64.0; |
||||
points.push_back(Vec3d(0.00, cos(angle), sin(angle))*0.75); |
||||
points.push_back(Vec3d(1.57, cos(angle), sin(angle))*0.75); |
||||
tcoords.push_back(Vec2d(0.0, i/64.0)); |
||||
tcoords.push_back(Vec2d(1.0, i/64.0)); |
||||
} |
||||
|
||||
for(int i = 0; i < (int)points.size()/2-1; ++i) |
||||
{ |
||||
int polys[] = {3, 2*i, 2*i+1, 2*i+2, 3, 2*i+1, 2*i+2, 2*i+3}; |
||||
polygons.insert(polygons.end(), polys, polys + sizeof(polys)/sizeof(polys[0])); |
||||
} |
||||
|
||||
cv::viz::Mesh mesh; |
||||
mesh.cloud = Mat(points, true).reshape(3, 1); |
||||
mesh.tcoords = Mat(tcoords, true).reshape(2, 1); |
||||
mesh.polygons = Mat(polygons, true).reshape(1, 1); |
||||
mesh.texture = lena; |
||||
|
||||
Viz3d viz("show_textured_mesh"); |
||||
viz.setBackgroundMeshLab(); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("mesh", WMesh(mesh)); |
||||
viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG); |
||||
viz.showWidget("text2d", WText("Textured mesh", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_polyline) |
||||
{ |
||||
const Color palette[] = { Color::red(), Color::green(), Color::blue(), Color::gold(), Color::raspberry(), Color::bluberry(), Color::lime() }; |
||||
size_t palette_size = sizeof(palette)/sizeof(palette[0]); |
||||
|
||||
Mat polyline(1, 32, CV_64FC3), colors(1, 32, CV_8UC3); |
||||
for(int i = 0; i < (int)polyline.total(); ++i) |
||||
{ |
||||
polyline.at<Vec3d>(i) = Vec3d(i/16.0, cos(i * CV_PI/6), sin(i * CV_PI/6)); |
||||
colors.at<Vec3b>(i) = palette[i & palette_size]; |
||||
} |
||||
|
||||
Viz3d viz("show_polyline"); |
||||
viz.showWidget("polyline", WPolyLine(polyline, colors)); |
||||
viz.showWidget("coosys", WCoordinateSystem()); |
||||
viz.showWidget("text2d", WText("Polyline", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_sampled_normals) |
||||
{ |
||||
Mesh mesh = Mesh::load(get_dragon_ply_file_path()); |
||||
computeNormals(mesh, mesh.normals); |
||||
|
||||
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); |
||||
|
||||
Viz3d viz("show_sampled_normals"); |
||||
viz.showWidget("mesh", WMesh(mesh), pose); |
||||
viz.showWidget("normals", WCloudNormals(mesh.cloud, mesh.normals, 30, 0.1f, Color::green()), pose); |
||||
viz.setRenderingProperty("normals", LINE_WIDTH, 2.0); |
||||
viz.showWidget("text2d", WText("Cloud or mesh normals", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_cloud_shaded_by_normals) |
||||
{ |
||||
Mesh mesh = Mesh::load(get_dragon_ply_file_path()); |
||||
computeNormals(mesh, mesh.normals); |
||||
|
||||
Affine3d pose = Affine3d().rotate(Vec3d(0, 0.8, 0)); |
||||
|
||||
WCloud cloud(mesh.cloud, Color::white(), mesh.normals); |
||||
cloud.setRenderingProperty(SHADING, SHADING_GOURAUD); |
||||
|
||||
Viz3d viz("show_cloud_shaded_by_normals"); |
||||
viz.showWidget("cloud", cloud, pose); |
||||
viz.showWidget("text2d", WText("Cloud shaded by normals", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_trajectories) |
||||
{ |
||||
std::vector<Affine3d> path = generate_test_trajectory<double>(), sub0, sub1, sub2, sub3, sub4, sub5; |
||||
int size =(int)path.size(); |
||||
|
||||
Mat(path).rowRange(0, size/10+1).copyTo(sub0); |
||||
Mat(path).rowRange(size/10, size/5+1).copyTo(sub1); |
||||
Mat(path).rowRange(size/5, 11*size/12).copyTo(sub2); |
||||
Mat(path).rowRange(11*size/12, size).copyTo(sub3); |
||||
Mat(path).rowRange(3*size/4, 33*size/40).copyTo(sub4); |
||||
Mat(path).rowRange(33*size/40, 9*size/10).copyTo(sub5); |
||||
Matx33d K(1024.0, 0.0, 320.0, 0.0, 1024.0, 240.0, 0.0, 0.0, 1.0); |
||||
|
||||
Viz3d viz("show_trajectories"); |
||||
viz.showWidget("coos", WCoordinateSystem()); |
||||
viz.showWidget("sub0", WTrajectorySpheres(sub0, 0.25, 0.07)); |
||||
viz.showWidget("sub1", WTrajectory(sub1, WTrajectory::PATH, 0.2, Color::brown())); |
||||
viz.showWidget("sub2", WTrajectory(sub2, WTrajectory::FRAMES, 0.2)); |
||||
viz.showWidget("sub3", WTrajectory(sub3, WTrajectory::BOTH, 0.2, Color::green())); |
||||
viz.showWidget("sub4", WTrajectoryFrustums(sub4, K, 0.3, Color::yellow())); |
||||
viz.showWidget("sub5", WTrajectoryFrustums(sub5, Vec2d(0.78, 0.78), 0.15)); |
||||
viz.showWidget("text2d", WText("Different kinds of supported trajectories", Point(20, 20), 20, Color::green())); |
||||
|
||||
int i = 0; |
||||
while(!viz.wasStopped()) |
||||
{ |
||||
double a = --i % 360; |
||||
Vec3d pose(sin(a * CV_PI/180), 0.7, cos(a * CV_PI/180)); |
||||
viz.setViewerPose(makeCameraPose(pose * 7.5, Vec3d(0.0, 0.5, 0.0), Vec3d(0.0, 0.1, 0.0))); |
||||
viz.spinOnce(20, true); |
||||
} |
||||
viz.resetCamera(); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_trajectory_reposition) |
||||
{ |
||||
std::vector<Affine3f> path = generate_test_trajectory<float>(); |
||||
|
||||
Viz3d viz("show_trajectory_reposition_to_origin"); |
||||
viz.showWidget("coos", WCoordinateSystem()); |
||||
viz.showWidget("sub3", WTrajectory(Mat(path).rowRange(0, (int)path.size()/3), WTrajectory::BOTH, 0.2, Color::brown()), path.front().inv()); |
||||
viz.showWidget("text2d", WText("Trajectory resposition to origin", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_camera_positions) |
||||
{ |
||||
Matx33d K(1024.0, 0.0, 320.0, 0.0, 1024.0, 240.0, 0.0, 0.0, 1.0); |
||||
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); |
||||
Mat gray = make_gray(lena); |
||||
|
||||
Affine3d poses[2]; |
||||
for(int i = 0; i < 2; ++i) |
||||
{ |
||||
Vec3d pose = 5 * Vec3d(sin(3.14 + 2.7 + i*60 * CV_PI/180), 0.4 - i*0.3, cos(3.14 + 2.7 + i*60 * CV_PI/180)); |
||||
poses[i] = makeCameraPose(pose, Vec3d(0.0, 0.0, 0.0), Vec3d(0.0, -0.1, 0.0)); |
||||
} |
||||
|
||||
Viz3d viz("show_camera_positions"); |
||||
viz.showWidget("sphe", WSphere(Point3d(0,0,0), 1.0, 10, Color::orange_red())); |
||||
viz.showWidget("coos", WCoordinateSystem(1.5)); |
||||
viz.showWidget("pos1", WCameraPosition(0.75), poses[0]); |
||||
viz.showWidget("pos2", WCameraPosition(Vec2d(0.78, 0.78), lena, 2.2, Color::green()), poses[0]); |
||||
viz.showWidget("pos3", WCameraPosition(0.75), poses[1]); |
||||
viz.showWidget("pos4", WCameraPosition(K, gray, 3, Color::indigo()), poses[1]); |
||||
viz.showWidget("text2d", WText("Camera positions with images", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_overlay_image) |
||||
{ |
||||
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); |
||||
Mat gray = make_gray(lena); |
||||
|
||||
Size2d half_lsize = Size2d(lena.size()) * 0.5; |
||||
|
||||
Viz3d viz("show_overlay_image"); |
||||
viz.setBackgroundMeshLab(); |
||||
Size vsz = viz.getWindowSize(); |
||||
|
||||
viz.showWidget("coos", WCoordinateSystem()); |
||||
viz.showWidget("cube", WCube()); |
||||
viz.showWidget("img1", WImageOverlay(lena, Rect(Point(10, 10), half_lsize))); |
||||
viz.showWidget("img2", WImageOverlay(gray, Rect(Point(vsz.width-10-lena.cols/2, 10), half_lsize))); |
||||
viz.showWidget("img3", WImageOverlay(gray, Rect(Point(10, vsz.height-10-lena.rows/2), half_lsize))); |
||||
viz.showWidget("img5", WImageOverlay(lena, Rect(Point(vsz.width-10-lena.cols/2, vsz.height-10-lena.rows/2), half_lsize))); |
||||
viz.showWidget("text2d", WText("Overlay images", Point(20, 20), 20, Color::green())); |
||||
|
||||
int i = 0; |
||||
while(!viz.wasStopped()) |
||||
{ |
||||
double a = ++i % 360; |
||||
Vec3d pose(sin(a * CV_PI/180), 0.7, cos(a * CV_PI/180)); |
||||
viz.setViewerPose(makeCameraPose(pose * 3, Vec3d(0.0, 0.5, 0.0), Vec3d(0.0, 0.1, 0.0))); |
||||
viz.getWidget("img1").cast<WImageOverlay>().setImage(lena * pow(sin(i*10*CV_PI/180) * 0.5 + 0.5, 1.0)); |
||||
viz.spinOnce(1, true); |
||||
} |
||||
viz.showWidget("text2d", WText("Overlay images (stopped)", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
|
||||
TEST(Viz, show_image_method) |
||||
{ |
||||
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); |
||||
|
||||
Viz3d viz("show_image_method"); |
||||
viz.showImage(lena); |
||||
viz.spinOnce(1500, true); |
||||
viz.showImage(lena, lena.size()); |
||||
viz.spinOnce(1500, true); |
||||
|
||||
cv::viz::imshow("show_image_method", make_gray(lena)).spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_image_3d) |
||||
{ |
||||
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); |
||||
Mat gray = make_gray(lena); |
||||
|
||||
Viz3d viz("show_image_3d"); |
||||
viz.setBackgroundMeshLab(); |
||||
viz.showWidget("coos", WCoordinateSystem()); |
||||
viz.showWidget("cube", WCube()); |
||||
viz.showWidget("arr0", WArrow(Vec3d(0.5, 0.0, 0.0), Vec3d(1.5, 0.0, 0.0), 0.009, Color::raspberry())); |
||||
viz.showWidget("img0", WImage3D(lena, Size2d(1.0, 1.0)), Affine3d(Vec3d(0.0, CV_PI/2, 0.0), Vec3d(.5, 0.0, 0.0))); |
||||
viz.showWidget("arr1", WArrow(Vec3d(-0.5, -0.5, 0.0), Vec3d(0.2, 0.2, 0.0), 0.009, Color::raspberry())); |
||||
viz.showWidget("img1", WImage3D(gray, Size2d(1.0, 1.0), Vec3d(-0.5, -0.5, 0.0), Vec3d(1.0, 1.0, 0.0), Vec3d(0.0, 1.0, 0.0))); |
||||
|
||||
viz.showWidget("arr3", WArrow(Vec3d::all(-0.5), Vec3d::all(0.5), 0.009, Color::raspberry())); |
||||
|
||||
viz.showWidget("text2d", WText("Images in 3D", Point(20, 20), 20, Color::green())); |
||||
|
||||
int i = 0; |
||||
while(!viz.wasStopped()) |
||||
{ |
||||
viz.getWidget("img0").cast<WImage3D>().setImage(lena * pow(sin(i++*7.5*CV_PI/180) * 0.5 + 0.5, 1.0)); |
||||
viz.spinOnce(1, true); |
||||
} |
||||
viz.showWidget("text2d", WText("Images in 3D (stopped)", Point(20, 20), 20, Color::green())); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_simple_widgets) |
||||
{ |
||||
Viz3d viz("show_simple_widgets"); |
||||
viz.setBackgroundMeshLab(); |
||||
|
||||
viz.showWidget("coos", WCoordinateSystem()); |
||||
viz.showWidget("cube", WCube()); |
||||
viz.showWidget("cub0", WCube(Vec3d::all(-1.0), Vec3d::all(-0.5), false, Color::indigo())); |
||||
viz.showWidget("arro", WArrow(Vec3d::all(-0.5), Vec3d::all(0.5), 0.009, Color::raspberry())); |
||||
viz.showWidget("cir1", WCircle(0.5, 0.01, Color::bluberry())); |
||||
viz.showWidget("cir2", WCircle(0.5, Point3d(0.5, 0.0, 0.0), Vec3d(1.0, 0.0, 0.0), 0.01, Color::apricot())); |
||||
|
||||
viz.showWidget("cyl0", WCylinder(Vec3d(-0.5, 0.5, -0.5), Vec3d(0.5, 0.5, -0.5), 0.125, 30, Color::brown())); |
||||
viz.showWidget("con0", WCone(0.25, 0.125, 6, Color::azure())); |
||||
viz.showWidget("con1", WCone(0.125, Point3d(0.5, -0.5, 0.5), Point3d(0.5, -1.0, 0.5), 6, Color::turquoise())); |
||||
|
||||
viz.showWidget("text2d", WText("Different simple widgets", Point(20, 20), 20, Color::green())); |
||||
viz.showWidget("text3d", WText3D("Simple 3D text", Point3d( 0.5, 0.5, 0.5), 0.125, false, Color::green())); |
||||
|
||||
viz.showWidget("plane1", WPlane(Size2d(0.25, 0.75))); |
||||
viz.showWidget("plane2", WPlane(Vec3d(0.5, -0.5, -0.5), Vec3d(0.0, 1.0, 1.0), Vec3d(1.0, 1.0, 0.0), Size2d(1.0, 0.5), Color::gold())); |
||||
|
||||
viz.showWidget("grid1", WGrid(Vec2i(7,7), Vec2d::all(0.75), Color::gray()), Affine3d().translate(Vec3d(0.0, 0.0, -1.0))); |
||||
|
||||
viz.spin(); |
||||
viz.getWidget("text2d").cast<WText>().setText("Different simple widgets (updated)"); |
||||
viz.getWidget("text3d").cast<WText3D>().setText("Updated text 3D"); |
||||
viz.spin(); |
||||
} |
||||
|
||||
TEST(Viz, show_follower) |
||||
{ |
||||
Viz3d viz("show_follower"); |
||||
|
||||
viz.showWidget("coos", WCoordinateSystem()); |
||||
viz.showWidget("cube", WCube()); |
||||
viz.showWidget("t3d_2", WText3D("Simple 3D follower", Point3d(-0.5, -0.5, 0.5), 0.125, true, Color::green())); |
||||
viz.showWidget("text2d", WText("Follower: text always facing camera", Point(20, 20), 20, Color::green())); |
||||
viz.setBackgroundMeshLab(); |
||||
viz.spin(); |
||||
viz.getWidget("t3d_2").cast<WText3D>().setText("Updated follower 3D"); |
||||
viz.spin(); |
||||
} |
||||
|
||||
}} // namespace
|
Loading…
Reference in new issue