Commit 0e7d4a57 authored by Anatoly Baksheev's avatar Anatoly Baksheev

First version of 'viz' module

parent 1ad7af3c
...@@ -432,6 +432,8 @@ macro(ocv_glob_module_sources) ...@@ -432,6 +432,8 @@ macro(ocv_glob_module_sources)
file(GLOB lib_hdrs "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") file(GLOB lib_hdrs "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h") file(GLOB lib_hdrs_detail "include/opencv2/${name}/detail/*.hpp" "include/opencv2/${name}/detail/*.h")
file(GLOB_RECURSE qq "src/q/*.h*")
file(GLOB lib_device_srcs "src/cuda/*.cu") file(GLOB lib_device_srcs "src/cuda/*.cu")
set(device_objs "") set(device_objs "")
set(lib_device_hdrs "") set(lib_device_hdrs "")
...@@ -445,7 +447,7 @@ macro(ocv_glob_module_sources) ...@@ -445,7 +447,7 @@ macro(ocv_glob_module_sources)
endif() endif()
ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail}
SOURCES ${lib_srcs} ${lib_int_hdrs} ${device_objs} ${lib_device_srcs} ${lib_device_hdrs}) SOURCES ${lib_srcs} ${lib_int_hdrs} ${device_objs} ${lib_device_srcs} ${lib_device_hdrs} ${qq})
source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs}) source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
source_group("Include" FILES ${lib_hdrs}) source_group("Include" FILES ${lib_hdrs})
......
...@@ -109,6 +109,8 @@ namespace cv ...@@ -109,6 +109,8 @@ namespace cv
template <typename Y> operator Affine3<Y>() const; template <typename Y> operator Affine3<Y>() const;
operator cv::Mat();
Mat4 matrix; Mat4 matrix;
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H #if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
...@@ -314,6 +316,8 @@ template<typename T> template <typename Y> inline cv::Affine3<T>::operator Affin ...@@ -314,6 +316,8 @@ template<typename T> template <typename Y> inline cv::Affine3<T>::operator Affin
return Affine3<Y>(matrix); return Affine3<Y>(matrix);
} }
template<typename T> inline cv::Affine3<T>::operator cv::Mat() { return cv::Mat(matrix, false); }
template<typename T> inline cv::Affine3<T> cv::operator*(const cv::Affine3<T>& affine1, const cv::Affine3<T>& affine2) template<typename T> inline cv::Affine3<T> cv::operator*(const cv::Affine3<T>& affine1, const cv::Affine3<T>& affine2)
{ {
return affine2.concatenate(affine1); return affine2.concatenate(affine1);
...@@ -350,7 +354,7 @@ inline cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) ...@@ -350,7 +354,7 @@ inline cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v)
return r; return r;
} }
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H #if (defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H) || defined CV_AFFINE_FORCE_EIGEN_PLUGIN
template<typename T> inline cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine) template<typename T> inline cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine)
{ {
......
###############################################################################
# Find qvtk
# This sets the following variables:
# QVTK_FOUND - True if QVTK was found.
# QVTK_INCLUDE_DIR - Directory containing the QVTK include files.
# QVTK_LIBRARY - QVTK library.
# if QVTK_FOUND then QVTK_INCLUDE_DIR is appended to VTK_INCLUDE_DIRS and QVTK_LIBRARY is appended to QVTK_LIBRARY_DIR
macro(find_qvtk)
find_library (QVTK_LIBRARY QVTK HINTS ${VTK_DIR} ${VTK_DIR}/bin)
find_path (QVTK_INCLUDE_DIR QVTKWidget.h HINT ${VTK_INCLUDE_DIRS})
find_package_handle_standard_args(QVTK DEFAULT_MSG QVTK_LIBRARY QVTK_INCLUDE_DIR)
if(NOT QVTK_FOUND)
set (VTK_USE_QVTK OFF)
else(NOT QVTK_FOUND)
get_filename_component (QVTK_LIBRARY_DIR ${QVTK_LIBRARY} PATH)
set (VTK_LIBRARY_DIRS ${VTK_LIBRARY_DIRS} ${QVTK_LIBRARY_DIR})
set (VTK_INCLUDE_DIRS ${VTK_INCLUDE_DIRS} ${QVTK_INCLUDE_DIR})
set (VTK_USE_QVTK ON)
endif()
endmacro()
macro(find_vtk)
find_package(VTK 5.8.0 REQUIRED)
if(VTK_FOUND)
if (BUILD_SHARED_LIBS OR (NOT BUILD_SHARED_LIBS AND NOT VTK_BUILD_SHARED_LIBS))
find_qvtk()
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, lib: ${VTK_LIBRARY_DIRS})")
link_directories(${VTK_LIBRARY_DIRS})
include_directories(SYSTEM ${VTK_INCLUDE_DIRS})
set(HAVE_VTK ON)
else ()
set(HAVE_VTK OFF)
message ("Warning: VTK disabled. You are to build OpenCV in STATIC but VTK is SHARED!")
endif ()
endif()
endmacro()
macro(find_boost)
# Disable the config mode of find_package(Boost)
set(Boost_NO_BOOST_CMAKE ON)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.49.0 REQUIRED COMPONENTS system thread)
if(Boost_FOUND)
set(HAVE_BOOST ON)
# Obtain diagnostic information about Boost's automatic linking outputted during compilation time.
add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
message(STATUS "Boost found (include: ${Boost_INCLUDE_DIRS})")
endif()
endmacro()
find_vtk()
find_boost()
find_package(OpenGL)
if (OPENGL_FOUND)
if(OPENGL_INCLUDE_DIR)
include_directories("${OPENGL_INCLUDE_DIR}")
endif()
if(OPENGL_DEFINITIONS)
add_definitions("${OPENGL_DEFINITIONS}")
endif()
endif()
if(NOT HAVE_VTK)
set(DEFAULT FALSE)
set(REASON "VTK was not found.")
else()
set(DEFAULT TRUE)
set(REASON)
set(VTK_USE_FILE ${VTK_USE_FILE} CACHE INTERNAL "VTK_USE_FILE")
include (${VTK_USE_FILE})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()
add_definitions(-DHAVE_VTK)
set(BUILD_opencv_viz_INIT OFF)
include_directories(src)
set(the_description "Viz")
ocv_define_module(viz opencv_core opencv_calib3d)
#${PCL_LIBRARIES}
target_link_libraries(opencv_viz vtkCommon vtkWidgets vtkHybrid vtkCharts vtkFiltering vtkRendering ${OPENGL_LIBRARIES})
if(APPLE)
target_link_libraries(opencv_viz "-framework Cocoa")
endif()
#pragma once
#include <opencv2/viz/viz3d.hpp>
#pragma once
#include <string>
#include <opencv2/viz/types.hpp>
namespace cv
{
class KeyboardEvent
{
public:
static const unsigned int Alt = 1;
static const unsigned int Ctrl = 2;
static const unsigned int Shift = 4;
/** \brief Constructor
* \param[in] action true for key was pressed, false for released
* \param[in] key_sym the key-name that caused the action
* \param[in] key the key code that caused the action
* \param[in] alt whether the alt key was pressed at the time where this event was triggered
* \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered
* \param[in] shift whether the shift was pressed at the time where this event was triggered
*/
KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
bool isAltPressed () const;
bool isCtrlPressed () const;
bool isShiftPressed () const;
unsigned char getKeyCode () const;
const std::string& getKeySym () const;
bool keyDown () const;
bool keyUp () const;
protected:
bool action_;
unsigned int modifiers_;
unsigned char key_code_;
std::string key_sym_;
};
class MouseEvent
{
public:
enum Type
{
MouseMove = 1,
MouseButtonPress,
MouseButtonRelease,
MouseScrollDown,
MouseScrollUp,
MouseDblClick
} ;
enum MouseButton
{
NoButton = 0,
LeftButton,
MiddleButton,
RightButton,
VScroll /*other buttons, scroll wheels etc. may follow*/
} ;
MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift);
Type type;
MouseButton button;
Point pointer;
unsigned int key_state;
};
}
////////////////////////////////////////////////////////////////////
/// Implementation
inline cv::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_sym, unsigned char key, bool alt, bool ctrl, bool shift)
: action_ (_action), modifiers_ (0), key_code_(key), key_sym_ (_key_sym)
{
if (alt)
modifiers_ = Alt;
if (ctrl)
modifiers_ |= Ctrl;
if (shift)
modifiers_ |= Shift;
}
inline bool cv::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; }
inline bool cv::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; }
inline bool cv::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; }
inline unsigned char cv::KeyboardEvent::getKeyCode () const { return key_code_; }
inline const std::string& cv::KeyboardEvent::getKeySym () const { return (key_sym_); }
inline bool cv::KeyboardEvent::keyDown () const { return action_; }
inline bool cv::KeyboardEvent::keyUp () const { return !action_; }
inline cv::MouseEvent::MouseEvent (const Type& _type, const MouseButton& _button, const Point& _p, bool alt, bool ctrl, bool shift)
: type(_type), button(_button), pointer(_p), key_state(0)
{
if (alt)
key_state = KeyboardEvent::Alt;
if (ctrl)
key_state |= KeyboardEvent::Ctrl;
if (shift)
key_state |= KeyboardEvent::Shift;
}
#pragma once
#include <opencv2/core.hpp>
#include <opencv2/viz/types.hpp>
#include <vector>
namespace temp_viz
{
CV_EXPORTS Mesh3d::Ptr mesh_load(const String& file);
}
#pragma once
#include <vector>
#include <opencv2/core/cvdef.h>
#include <opencv2/core.hpp>
#include <opencv2/core/affine.hpp>
namespace temp_viz
{
//qt creator hack
typedef cv::Scalar Scalar;
typedef cv::Mat Mat;
typedef std::string String;
typedef cv::Vec3d Vec3d;
typedef cv::Vec4d Vec4d;
typedef cv::Vec2d Vec2d;
typedef cv::Vec2i Vec2i;
typedef cv::Matx33d Matx33d;
typedef cv::Affine3f Affine3f;
typedef cv::Affine3d Affine3d;
typedef cv::Point3f Point3f;
typedef cv::Matx44d Matx44d;
typedef cv::Matx44f Matx44f;
typedef cv::Size Size;
typedef cv::Point Point;
struct CV_EXPORTS ModelCoefficients
{
std::vector<float> values;
};
class CV_EXPORTS Color : public Scalar
{
public:
Color();
Color(double gray);
Color(double blue, double green, double red);
Color(const Scalar& color);
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();
};
struct CV_EXPORTS Vertices
{
std::vector<unsigned int> vertices;
};
class CV_EXPORTS Mesh3d
{
public:
typedef cv::Ptr<Mesh3d> Ptr;
Mat cloud, colors;
std::vector<Vertices> polygons;
};
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 vtkpoint(const Point3f& point) { return Vec3d(point.x, point.y, point.z); }
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/cv::norm(v); }
}
#pragma once
#if !defined YES_I_AGREE_THAT_VIZ_API_IS_NOT_STABLE_NOW_AND_BINARY_COMPARTIBILITY_WONT_BE_SUPPORTED
//#error "Viz is in beta state now. Please define macro above to use it"
#endif
#include <opencv2/core/cvdef.h>
#include <opencv2/core.hpp>
#include <string>
#include <opencv2/viz/types.hpp>
namespace temp_viz
{
class CV_EXPORTS Viz3d
{
public:
typedef cv::Ptr<Viz3d> Ptr;
Viz3d(const String& window_name = String());
~Viz3d();
void setBackgroundColor(const Color& color = Color::black());
void addCoordinateSystem(double scale, const Affine3f& t, const String &id = "coordinate");
void addPointCloud(const Mat& cloud, const Mat& colors, const String& id = "cloud", const Mat& mask = Mat());
bool addPointCloudNormals (const Mat &cloud, const Mat& normals, int level = 100, float scale = 0.02f, const String &id = "cloud");
bool addPlane (const ModelCoefficients &coefficients, const String &id = "plane");
bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane");
bool removeCoordinateSystem (const String &id = "coordinate");
bool updatePointCloud (const Mat& cloud, const Mat& colors, const String& id = "cloud", const Mat& mask = Mat());
bool addPolygonMesh (const Mesh3d& mesh, const String &id = "polygon");
bool updatePolygonMesh (const Mesh3d& mesh, const String &id = "polygon");
bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String &id = "polyline");
bool addText (const String &text, int xpos, int ypos, const Color& color, int fontsize = 10, const String &id = "");
bool addPolygon(const Mat& cloud, const Color& color, const String &id = "polygon");
bool addSphere (const Point3f &center, double radius, const Color& color, const String &id = "sphere");
void spin ();
void spinOnce (int time = 1, bool force_redraw = false);
private:
Viz3d(const Viz3d&);
Viz3d& operator=(const Viz3d&);
struct VizImpl;
VizImpl* impl_;
};
}
This diff is collapsed.
This diff is collapsed.
#include <opencv2/viz/mesh_load.hpp>
#include "precomp.hpp"
#include <vtkPLYReader.h>
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkCellArray.h>
temp_viz::Mesh3d::Ptr temp_viz::mesh_load(const String& file)
{
Mesh3d::Ptr mesh = new Mesh3d();
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(file.c_str());
reader->Update();
vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput ();
typedef unsigned int uint32_t;
mesh->polygons.clear();
vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints ();
vtkIdType nr_points = mesh_points->GetNumberOfPoints ();
vtkIdType nr_polygons = poly_data->GetNumberOfPolys ();
mesh->cloud.create(1, nr_points, CV_32FC3);
double point_xyz[3];
for (vtkIdType i = 0; i < mesh_points->GetNumberOfPoints (); i++)
{
mesh_points->GetPoint (i, &point_xyz[0]);
mesh->cloud.ptr<cv::Point3f>()[i] = cv::Point3d(point_xyz[0], point_xyz[1], point_xyz[2]);;
}
// Then the color information, if any
vtkUnsignedCharArray* poly_colors = NULL;
if (poly_data->GetPointData() != NULL)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("Colors"));
// some applications do not save the name of scalars (including PCL's native vtk_io)
if (!poly_colors && poly_data->GetPointData () != NULL)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("scalars"));
if (!poly_colors && poly_data->GetPointData () != NULL)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("RGB"));
// TODO: currently only handles rgb values with 3 components
if (poly_colors && (poly_colors->GetNumberOfComponents () == 3))
{
mesh->colors.create(1, nr_points, CV_8UC3);
unsigned char point_color[3];
for (vtkIdType i = 0; i < mesh_points->GetNumberOfPoints (); i++)
{
poly_colors->GetTupleValue (i, &point_color[0]);
//RGB or BGR?????
mesh->colors.ptr<cv::Vec3b>()[i] = cv::Vec3b(point_color[0], point_color[1], point_color[2]);
}
}
else
mesh->colors.release();
// Now handle the polygons
mesh->polygons.resize (nr_polygons);
vtkIdType* cell_points;
vtkIdType nr_cell_points;
vtkCellArray * mesh_polygons = poly_data->GetPolys ();
mesh_polygons->InitTraversal ();
int id_poly = 0;
while (mesh_polygons->GetNextCell (nr_cell_points, cell_points))
{
mesh->polygons[id_poly].vertices.resize (nr_cell_points);
for (int i = 0; i < nr_cell_points; ++i)
mesh->polygons[id_poly].vertices[i] = static_cast<int> (cell_points[i]);
++id_poly;
}
return mesh;
}
#include "precomp.hpp"
\ No newline at end of file
#pragma once
#include <opencv2/core.hpp>
#include <map>
#include <vector>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/signals2.hpp>
#include <boost/thread.hpp>
#include <Eigen/Geometry>
#if defined __GNUC__
#pragma GCC system_header
#ifdef __DEPRECATED
#undef __DEPRECATED
#define __DEPRECATED_DISABLED__
#endif
#endif
#include <vtkAppendPolyData.h>
#include <vtkAssemblyPath.h>
#include <vtkAxesActor.h>
#include <vtkActor.h>
#include <vtkBoxRepresentation.h>
#include <vtkBoxWidget.h>
#include <vtkBoxWidget2.h>
#include <vtkCellData.h>
#include <vtkMath.h>
#include <vtkLoopSubdivisionFilter.h>
#include <vtkLineSource.h>
#include <vtkLegendScaleActor.h>
#include <vtkLightKit.h>
#include <vtkPlatonicSolidSource.h>
#include <vtkPropPicker.h>
#include <vtkGeneralTransform.h>
#include <vtkSmartPointer.h>
#include <vtkDataSet.h>
#include <vtkDataSetSurfaceFilter.h>
#include <vtkExecutive.h>
#include <vtkPolygon.h>
#include <vtkPointPicker.h>
#include <vtkUnstructuredGrid.h>
#include <vtkConeSource.h>
#include <vtkDiskSource.h>
#include <vtkPlaneSource.h>
#include <vtkSphereSource.h>
#include <vtkIdentityTransform.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkTubeFilter.h>
#include <vtkCubeSource.h>
#include <vtkAxes.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataReader.h>
#include <vtkPolyDataMapper.h>
#include <vtkDataSetMapper.h>
#include <vtkCellArray.h>
#include <vtkCommand.h>
#include <vtkCellLocator.h>
#include <vtkPLYReader.h>
#include <vtkTransformFilter.h>
#include <vtkPolyLine.h>
#include <vtkVectorText.h>
#include <vtkFollower.h>
#include <vtkCallbackCommand.h>
#include <vtkInteractorStyle.h>
#include <vtkInformationVector.h>
#include <vtkDataArray.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPoints.h>
#include <vtkRendererCollection.h>
#include <vtkPNGWriter.h>
#include <vtkWindowToImageFilter.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkObjectFactory.h>
#include <vtkScalarBarActor.h>
#include <vtkScalarsToColors.h>
#include <vtkClipPolyData.h>
#include <vtkPlanes.h>
#include <vtkImageImport.h>
#include <vtkImageViewer.h>
#include <vtkInteractorStyleImage.h>
#include <vtkImageFlip.h>
#include <vtkTIFFWriter.h>
#include <vtkBMPWriter.h>
#include <vtkJPEGWriter.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindow.h>
#include <vtkXYPlotActor.h>
#include <vtkTextProperty.h>
#include <vtkProperty2D.h>
#include <vtkFieldData.h>
#include <vtkDoubleArray.h>
#include <vtkLODActor.h>
#include <vtkPolyDataWriter.h>
#include <vtkTextActor.h>
#include <vtkCleanPolyData.h>
#include <vtkRenderer.h>
#include <vtkObject.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkImageReslice.h>
#include <vtkImageChangeInformation.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkImageBlend.h>
#include <vtkImageStencilData.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkChartXY.h>
#include <vtkPlot.h>
#include <vtkTable.h>
#include <vtkContextView.h>
#include <vtkContextScene.h>
#include <vtkColorSeries.h>
#include <vtkAxis.h>
#include <vtkSelection.h>
#include <vtkHardwareSelector.h>
#include <vtkTriangle.h>
#include <vtkWorldPointPicker.h>
#include <vtkInteractorStyleRubberBandPick.h>
#include <vtkInteractorStyleTrackballActor.h>
#include <vtkAreaPicker.h>
#include <vtkExtractGeometry.h>
#include <vtkExtractPolyDataGeometry.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkIdFilter.h>
#include <vtkIdTypeArray.h>
#include <vtkImageReader2Factory.h>
#include <vtkImageReader2.h>
#include <vtkImageData.h>
#include <vtkPolyDataNormals.h>
#include <vtkMapper.h>
#include <vtkSelectionNode.h>
#include <vtkAbstractPicker.h>
#include <vtkAbstractPropPicker.h>
#include <vtkPointPicker.h>
#include <vtkMatrix4x4.h>
#include <vtkInteractorObserver.h>
#if defined __GNUC__ && defined __DEPRECATED_DISABLED__
#define __DEPRECATED
#undef __DEPRECATED_DISABLED__
#endif
#pragma once
#include <opencv2/core/cvdef.h>
#include <opencv2/core.hpp>
#include <opencv2/viz/types.hpp>
//#include <vtkMatrix4x4.h>
namespace temp_viz
{
//CV_EXPORTS Eigen::Matrix4d vtkToEigen (vtkMatrix4x4* vtk_matrix);
//CV_EXPORTS Eigen::Vector2i worldToView (const Eigen::Vector4d &world_pt, const Eigen::Matrix4d &view_projection_matrix, int width, int height);
//CV_EXPORTS void getViewFrustum (const Eigen::Matrix4d &view_projection_matrix, double planes[24]);
// enum FrustumCull
// {
// PCL_INSIDE_FRUSTUM,
// PCL_INTERSECT_FRUSTUM,
// PCL_OUTSIDE_FRUSTUM
// };
//CV_EXPORTS int cullFrustum (double planes[24], const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb);
//CV_EXPORTS float viewScreenArea (const Eigen::Vector3d &eye, const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const Eigen::Matrix4d &view_projection_matrix, int width, int height);
enum RenderingProperties
{
VIZ_POINT_SIZE,
VIZ_OPACITY,
VIZ_LINE_WIDTH,
VIZ_FONT_SIZE,
VIZ_COLOR,
VIZ_REPRESENTATION,
VIZ_IMMEDIATE_RENDERING,
VIZ_SHADING
};
enum RenderingRepresentationProperties
{
REPRESENTATION_POINTS,
REPRESENTATION_WIREFRAME,
REPRESENTATION_SURFACE
};
enum ShadingRepresentationProperties
{
SHADING_FLAT,
SHADING_GOURAUD,
SHADING_PHONG
};
class CV_EXPORTS Camera
{
public:
/** Focal point or lookAt. The view direction can be obtained by (focal-pos).normalized () */
Vec3d focal;
/** \brief Position of the camera. */
Vec3d pos;
/** \brief Up vector of the camera. */
Vec3d view_up;
/** \brief Near/far clipping planes depths */
Vec2d clip;
/** \brief Field of view angle in y direction (radians). */
double fovy;
// the following variables are the actual position and size of the window on the screen and NOT the viewport!
// except for the size, which is the same the viewport is assumed to be centered and same size as the window.
Vec2i window_size;
Vec2i window_pos;
/** \brief Computes View matrix for Camera (Based on gluLookAt)
* \param[out] view_mat the resultant matrix
*/
void computeViewMatrix(Affine3d& view_mat) const;
/** \brief Computes Projection Matrix for Camera
* \param[out] proj the resultant matrix
*/
void computeProjectionMatrix(Matx44d& proj) const;
/** \brief converts point to window coordiantes
* \param[in] pt xyz point to be converted
* \param[out] window_cord vector containing the pts' window X,Y, Z and 1
*
* This function computes the projection and view matrix every time.
* It is very inefficient to use this for every point in the point cloud!
*/
void cvtWindowCoordinates (const cv::Point3f& pt, Vec4d& window_cord) const
{
Affine3d view;
computeViewMatrix (view);
Matx44d proj;
computeProjectionMatrix (proj);
cvtWindowCoordinates (pt, proj * view.matrix, window_cord);
return;
}
/** \brief converts point to window coordiantes
* \param[in] pt xyz point to be converted
* \param[out] window_cord vector containing the pts' window X,Y, Z and 1
* \param[in] composite_mat composite transformation matrix (proj*view)
*
* Use this function to compute window coordinates with a precomputed
* transformation function. The typical composite matrix will be
* the projection matrix * the view matrix. However, additional
* matrices like a camera disortion matrix can also be added.
*/
void cvtWindowCoordinates (const Point3f& pt, Matx44d& composite_mat, Vec4d& window_cord) const
{
Vec4d pte (pt.x, pt.y, pt.z, 1);
window_cord = composite_mat * pte;
window_cord = window_cord/window_cord[3];
window_cord[0] = (window_cord[0]+1.0) / 2.0*window_size[0];
window_cord[1] = (window_cord[1]+1.0) / 2.0*window_size[1];
window_cord[2] = (window_cord[2]+1.0) / 2.0;
}
};
}
#pragma once
#include <q/viz_types.h>
#include <opencv2/viz/events.hpp>
namespace temp_viz
{
/** \brief PCLVisualizerInteractorStyle defines an unique, custom VTK
* based interactory style for PCL Visualizer applications. Besides
* defining the rendering style, we also create a list of custom actions
* that are triggered on different keys being pressed:
*
* - p, P : switch to a point-based representation
* - w, W : switch to a wireframe-based representation (where available)
* - s, S : switch to a surface-based representation (where available)
* - j, J : take a .PNG snapshot of the current window view
* - c, C : display current camera/window parameters
* - f, F : fly to point mode
* - e, E : exit the interactor\
* - q, Q : stop and call VTK's TerminateApp
* - + / - : increment/decrement overall point size
* - r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]
* - ALT + s, S : turn stereo mode on/off
* - ALT + f, F : switch between maximized window mode and original size
* -
* - SHIFT + left click : select a point
*
* \author Radu B. Rusu
* \ingroup visualization
*/
class CV_EXPORTS InteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
enum KeyboardModifier
{
KB_MOD_ALT,
KB_MOD_CTRL,
KB_MOD_SHIFT
};
static InteractorStyle *New ();
InteractorStyle () {}
virtual ~InteractorStyle () {}
// this macro defines Superclass, the isA functionality and the safe downcast method
vtkTypeMacro (InteractorStyle, vtkInteractorStyleTrackballCamera);
/** \brief Initialization routine. Must be called before anything else. */
virtual void Initialize ();
/** \brief Pass a pointer to the actor map
* \param[in] actors the actor map that will be used with this style
*/
inline void setCloudActorMap (const cv::Ptr<CloudActorMap>& actors) { actors_ = actors; }
/** \brief Pass a set of renderers to the interactor style.
* \param[in] rens the vtkRendererCollection to use
*/
void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
/** \brief Register a callback function for mouse events
* \param[in] cb a boost function that will be registered as a callback for a mouse event
* \return a connection object that allows to disconnect the callback function.
*/
boost::signals2::connection registerMouseCallback (boost::function<void (const cv::MouseEvent&)> cb);
/** \brief Register a callback boost::function for keyboard events
* \param[in] cb a boost function that will be registered as a callback for a keyboard event
* \return a connection object that allows to disconnect the callback function.
*/
boost::signals2::connection registerKeyboardCallback (boost::function<void (const cv::KeyboardEvent&)> cb);
/** \brief Save the current rendered image to disk, as a PNG screenshot.
* \param[in] file the name of the PNG file
*/
void saveScreenshot (const std::string &file);
/** \brief Change the default keyboard modified from ALT to a different special key.
* Allowed values are:
* - KB_MOD_ALT
* - KB_MOD_CTRL
* - KB_MOD_SHIFT
* \param[in] modifier the new keyboard modifier
*/
inline void setKeyboardModifier (const KeyboardModifier &modifier) { modifier_ = modifier; }
protected:
/** \brief Set to true after initialization is complete. */
bool init_;
/** \brief Collection of vtkRenderers stored internally. */
//vtkSmartPointer<vtkRendererCollection> rens_;
vtkSmartPointer<vtkRenderer> renderer_;
/** \brief Actor map stored internally. */
cv::Ptr<CloudActorMap> actors_;
/** \brief The current window width/height. */
Vec2i win_size_;
/** \brief The current window position x/y. */
Vec2i win_pos_;
/** \brief The maximum resizeable window width/height. */
Vec2i max_win_size_;
/** \brief A PNG writer for screenshot captures. */
vtkSmartPointer<vtkPNGWriter> snapshot_writer_;
/** \brief Internal window to image filter. Needed by \a snapshot_writer_. */
vtkSmartPointer<vtkWindowToImageFilter> wif_;
boost::signals2::signal<void (const cv::MouseEvent&)> mouse_signal_;
boost::signals2::signal<void (const cv::KeyboardEvent&)> keyboard_signal_;
/** \brief Interactor style internal method. Gets called whenever a key is pressed. */
virtual void OnChar ();
// Keyboard events
virtual void OnKeyDown ();
virtual void OnKeyUp ();
// mouse button events
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 ();
/** \brief Interactor style internal method. Gets called periodically if a timer is set. */
virtual void OnTimer ();
void zoomIn ();
void zoomOut ();
/** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */
bool stereo_anaglyph_mask_default_;
/** \brief The keyboard modifier to use. Default: Alt. */
KeyboardModifier modifier_;
};
}
#pragma once
#include <Eigen/Core>
#include <opencv2/viz/types.hpp>
#include "precomp.hpp"
namespace temp_viz
{
CV_EXPORTS vtkSmartPointer<vtkDataSet> createLine (const cv::Point3f& pt1, const cv::Point3f& pt2);
CV_EXPORTS vtkSmartPointer<vtkDataSet> createSphere (const cv::Point3f &center, float radius, int sphere_resolution = 10);
/** \brief Create a cylinder shape from a set of model coefficients.
* \param[in] coefficients the model coefficients (point_on_axis, axis_direction, radius)
* \param[in] numsides (optional) the number of sides used for rendering the cylinder
*
* \code
* // The following are given (or computed using sample consensus techniques -- see SampleConsensusModelCylinder)
* // Eigen::Vector3f pt_on_axis, axis_direction;
* // float radius;
*
* temp_viz::ModelCoefficients cylinder_coeff;
* cylinder_coeff.values.resize (7); // We need 7 values
* cylinder_coeff.values[0] = pt_on_axis.x ();
* cylinder_coeff.values[1] = pt_on_axis.y ();
* cylinder_coeff.values[2] = pt_on_axis.z ();
*
* cylinder_coeff.values[3] = axis_direction.x ();
* cylinder_coeff.values[4] = axis_direction.y ();
* cylinder_coeff.values[5] = axis_direction.z ();
*
* cylinder_coeff.values[6] = radius;
*
* vtkSmartPointer<vtkDataSet> data = temp_viz::createCylinder (cylinder_coeff, numsides);
* \endcode
*
* \ingroup visualization
*/
CV_EXPORTS vtkSmartPointer<vtkDataSet> createCylinder (const temp_viz::ModelCoefficients &coefficients, int numsides = 30);
/** \brief Create a planar shape from a set of model coefficients.
* \param[in] coefficients the model coefficients (a, b, c, d with ax+by+cz+d=0)
*
* \code
* // The following are given (or computed using sample consensus techniques -- see SampleConsensusModelPlane)
* // Eigen::Vector4f plane_parameters;
*
* temp_viz::ModelCoefficients plane_coeff;
* plane_coeff.values.resize (4); // We need 4 values
* plane_coeff.values[0] = plane_parameters.x ();
* plane_coeff.values[1] = plane_parameters.y ();
* plane_coeff.values[2] = plane_parameters.z ();
* plane_coeff.values[3] = plane_parameters.w ();
*
* vtkSmartPointer<vtkDataSet> data = temp_viz::createPlane (plane_coeff);
* \endcode
*
* \ingroup visualization
*/
CV_EXPORTS vtkSmartPointer<vtkDataSet> createPlane (const temp_viz::ModelCoefficients &coefficients);
/** \brief Create a planar shape from a set of model coefficients.
* \param[in] coefficients the model coefficients (a, b, c, d with ax+by+cz+d=0)
* \param[in] x,y,z projection of this point on the plane is used to get the center of the plane.
* \ingroup visualization
*/
CV_EXPORTS vtkSmartPointer<vtkDataSet> createPlane (const temp_viz::ModelCoefficients &coefficients, double x, double y, double z);
/** \brief Create a 2d circle shape from a set of model coefficients.
* \param[in] coefficients the model coefficients (x, y, radius)
* \param[in] z (optional) specify a z value (default: 0)
*
* \code
* // The following are given (or computed using sample consensus techniques -- see SampleConsensusModelCircle2D)
* // float x, y, radius;
*
* temp_viz::ModelCoefficients circle_coeff;
* circle_coeff.values.resize (3); // We need 3 values
* circle_coeff.values[0] = x;
* circle_coeff.values[1] = y;
* circle_coeff.values[2] = radius;
*
* vtkSmartPointer<vtkDataSet> data = temp_viz::create2DCircle (circle_coeff, z);
* \endcode
*
* \ingroup visualization
*/
CV_EXPORTS vtkSmartPointer<vtkDataSet> create2DCircle (const temp_viz::ModelCoefficients &coefficients, double z = 0.0);
/** \brief Creaet a cube shape from a set of model coefficients.
* \param[in] coefficients the cube coefficients (Tx, Ty, Tz, Qx, Qy, Qz, Qw, width, height, depth)
* \ingroup visualization
*/
CV_EXPORTS vtkSmartPointer<vtkDataSet> createCube (const temp_viz::ModelCoefficients &coefficients);
/** \brief Creaet a cube shape from a set of model coefficients.
*
* \param[in] translation a translation to apply to the cube from 0,0,0
* \param[in] rotation a quaternion-based rotation to apply to the cube
* \param[in] width the cube's width
* \param[in] height the cube's height
* \param[in] depth the cube's depth
* \ingroup visualization
*/
CV_EXPORTS vtkSmartPointer<vtkDataSet> createCube (const Eigen::Vector3f &translation, const Eigen::Quaternionf &rotation, double width, double height, double depth);
/** \brief Create a cube from a set of bounding points
* \param[in] x_min is the minimum x value of the box
* \param[in] x_max is the maximum x value of the box
* \param[in] y_min is the minimum y value of the box
* \param[in] y_max is the maximum y value of the box
* \param[in] z_min is the minimum z value of the box
* \param[in] z_max is the maximum z value of the box
* \param[in] id the cube id/name (default: "cube")
* \param[in] viewport (optional) the id of the new viewport (default: 0)
*/
CV_EXPORTS vtkSmartPointer<vtkDataSet> createCube (double x_min, double x_max, double y_min, double y_max, double z_min, double z_max);
/** \brief Allocate a new unstructured grid smartpointer. For internal use only.
* \param[out] polydata the resultant unstructured grid.
*/
CV_EXPORTS void allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata);
}
This diff is collapsed.
#pragma once
#include "precomp.hpp"
namespace temp_viz
{
struct CV_EXPORTS CloudActor
{
/** \brief The actor holding the data to render. */
vtkSmartPointer<vtkLODActor> actor;
/** \brief The viewpoint transformation matrix. */
vtkSmartPointer<vtkMatrix4x4> viewpoint_transformation_;
/** \brief Internal cell array. Used for optimizing updatePointCloud. */
vtkSmartPointer<vtkIdTypeArray> cells;
};
typedef std::map<std::string, CloudActor> CloudActorMap;
typedef std::map<std::string, vtkSmartPointer<vtkProp> > ShapeActorMap;
}
#include <q/shapes.h>
inline float rad2deg (float alpha)
{ return (alpha * 57.29578f); }
inline double rad2deg (double alpha){return (alpha * 57.29578);}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createCylinder (const temp_viz::ModelCoefficients &coefficients, int numsides)
{
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New ();
line->SetPoint1 (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
line->SetPoint2 (coefficients.values[3]+coefficients.values[0], coefficients.values[4]+coefficients.values[1], coefficients.values[5]+coefficients.values[2]);
vtkSmartPointer<vtkTubeFilter> tuber = vtkSmartPointer<vtkTubeFilter>::New ();
tuber->SetInputConnection (line->GetOutputPort ());
tuber->SetRadius (coefficients.values[6]);
tuber->SetNumberOfSides (numsides);
return (tuber->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createCube (const temp_viz::ModelCoefficients &coefficients)
{
// coefficients = [Tx, Ty, Tz, Qx, Qy, Qz, Qw, width, height, depth]
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
t->Identity ();
t->Translate (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
Eigen::AngleAxisf a (Eigen::Quaternionf (coefficients.values[6], coefficients.values[3],
coefficients.values[4], coefficients.values[5]));
t->RotateWXYZ (rad2deg (a.angle ()), a.axis ()[0], a.axis ()[1], a.axis ()[2]);
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New ();
cube->SetXLength (coefficients.values[7]);
cube->SetYLength (coefficients.values[8]);
cube->SetZLength (coefficients.values[9]);
vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
tf->SetTransform (t);
tf->SetInputConnection (cube->GetOutputPort ());
return (tf->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createCube (const Eigen::Vector3f &translation, const Eigen::Quaternionf &rotation, double width, double height, double depth)
{
// coefficients = [Tx, Ty, Tz, Qx, Qy, Qz, Qw, width, height, depth]
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
t->Identity ();
t->Translate (translation.x (), translation.y (), translation.z ());
Eigen::AngleAxisf a (rotation);
t->RotateWXYZ (rad2deg (a.angle ()), a.axis ()[0], a.axis ()[1], a.axis ()[2]);
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New ();
cube->SetXLength (width);
cube->SetYLength (height);
cube->SetZLength (depth);
vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
tf->SetTransform (t);
tf->SetInputConnection (cube->GetOutputPort ());
return (tf->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createCube (double x_min, double x_max, double y_min, double y_max, double z_min, double z_max)
{
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New ();
cube->SetBounds (x_min, x_max, y_min, y_max, z_min, z_max);
return (cube->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createPlane (const temp_viz::ModelCoefficients &coefficients)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
plane->SetNormal (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
double norm_sqr = coefficients.values[0] * coefficients.values[0]
+ coefficients.values[1] * coefficients.values[1]
+ coefficients.values[2] * coefficients.values[2];
plane->Push (-coefficients.values[3] / sqrt(norm_sqr));
return (plane->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createPlane (const temp_viz::ModelCoefficients &coefficients, double x, double y, double z)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
double norm_sqr = 1.0 / (coefficients.values[0] * coefficients.values[0] +
coefficients.values[1] * coefficients.values[1] +
coefficients.values[2] * coefficients.values[2] );
// double nx = coefficients.values [0] * norm;
// double ny = coefficients.values [1] * norm;
// double nz = coefficients.values [2] * norm;
// double d = coefficients.values [3] * norm;
// plane->SetNormal (nx, ny, nz);
plane->SetNormal (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
double t = x * coefficients.values[0] + y * coefficients.values[1] + z * coefficients.values[2] + coefficients.values[3];
x -= coefficients.values[0] * t * norm_sqr;
y -= coefficients.values[1] * t * norm_sqr;
z -= coefficients.values[2] * t * norm_sqr;
plane->SetCenter (x, y, z);
return (plane->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::create2DCircle (const temp_viz::ModelCoefficients &coefficients, double z)
{
vtkSmartPointer<vtkDiskSource> disk = vtkSmartPointer<vtkDiskSource>::New ();
// Maybe the resolution should be lower e.g. 50 or 25
disk->SetCircumferentialResolution (100);
disk->SetInnerRadius (coefficients.values[2] - 0.001);
disk->SetOuterRadius (coefficients.values[2] + 0.001);
disk->SetCircumferentialResolution (20);
// An alternative to <vtkDiskSource> could be <vtkRegularPolygonSource> with <vtkTubeFilter>
/*
vtkSmartPointer<vtkRegularPolygonSource> circle = vtkSmartPointer<vtkRegularPolygonSource>::New();
circle->SetRadius (coefficients.values[2]);
circle->SetNumberOfSides (100);
vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
tube->SetInput (circle->GetOutput());
tube->SetNumberOfSides (25);
tube->SetRadius (0.001);
*/
// Set the circle origin
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
t->Identity ();
t->Translate (coefficients.values[0], coefficients.values[1], z);
vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
tf->SetTransform (t);
tf->SetInputConnection (disk->GetOutputPort ());
/*
tf->SetInputConnection (tube->GetOutputPort ());
*/
return (tf->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createSphere (const cv::Point3f& center, float radius, int sphere_resolution)
{
// Set the sphere origin
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
t->Identity ();
t->Translate (center.x, center.y, center.z);
vtkSmartPointer<vtkSphereSource> s_sphere = vtkSmartPointer<vtkSphereSource>::New ();
s_sphere->SetRadius (radius);
s_sphere->SetPhiResolution (sphere_resolution);
s_sphere->SetThetaResolution (sphere_resolution);
s_sphere->LatLongTessellationOff ();
vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
tf->SetTransform (t);
tf->SetInputConnection (s_sphere->GetOutputPort ());
tf->Update ();
return (tf->GetOutput ());
}
////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkDataSet> temp_viz::createLine (const cv::Point3f& pt1, const cv::Point3f& pt2)
{
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New ();
line->SetPoint1 (pt1.x, pt1.y, pt1.z);
line->SetPoint2 (pt2.x, pt2.y, pt2.z);
line->Update ();
return line->GetOutput ();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void temp_viz::allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata)
{
polydata = vtkSmartPointer<vtkUnstructuredGrid>::New ();
}
#include <opencv2/viz/types.hpp>
//////////////////////////////////////////////////////////////////////////////////////////////////////
/// cv::Color
temp_viz::Color::Color() : Scalar(0, 0, 0) {}
temp_viz::Color::Color(double gray) : Scalar(gray, gray, gray) {}
temp_viz::Color::Color(double blue, double green, double red) : Scalar(blue, green, red) {}
temp_viz::Color::Color(const Scalar& color) : Scalar(color) {}
temp_viz::Color temp_viz::Color::black() { return Color( 0, 0, 0); }
temp_viz::Color temp_viz::Color::green() { return Color( 0, 255, 0); }
temp_viz::Color temp_viz::Color::blue() { return Color(255, 0, 0); }
temp_viz::Color temp_viz::Color::cyan() { return Color(255, 255, 0); }
temp_viz::Color temp_viz::Color::red() { return Color( 0, 0, 255); }
temp_viz::Color temp_viz::Color::magenta() { return Color( 0, 255, 255); }
temp_viz::Color temp_viz::Color::yellow() { return Color(255, 0, 255); }
temp_viz::Color temp_viz::Color::white() { return Color(255, 255, 255); }
temp_viz::Color temp_viz::Color::gray() { return Color(128, 128, 128); }
#include "precomp.hpp"
\ No newline at end of file
#include <opencv2/viz/viz3d.hpp>
#include <q/viz3d_impl.hpp>
temp_viz::Viz3d::Viz3d(const String& window_name) : impl_(new VizImpl(window_name))
{
}
temp_viz::Viz3d::~Viz3d()
{
}
void temp_viz::Viz3d::setBackgroundColor(const Color& color)
{
impl_->setBackgroundColor(color);
}
void temp_viz::Viz3d::addCoordinateSystem(double scale, const Affine3f& t, const String &id)
{
impl_->addCoordinateSystem(scale, t, id);
}
void temp_viz::Viz3d::addPointCloud(const Mat& cloud, const Mat& colors, const String& id, const Mat& mask)
{
impl_->addPointCloud(cloud, colors, id, mask);
}
bool temp_viz::Viz3d::addPointCloudNormals (const Mat &cloud, const Mat& normals, int level, float scale, const String& id)
{
return impl_->addPointCloudNormals(cloud, normals, level, scale, id);
}
bool temp_viz::Viz3d::updatePointCloud(const Mat& cloud, const Mat& colors, const String& id, const Mat& mask)
{
return impl_->updatePointCloud(cloud, colors, id, mask);
}
bool temp_viz::Viz3d::addPolygonMesh (const Mesh3d& mesh, const String &id)
{
return impl_->addPolygonMesh(mesh, Mat(), id);
}
bool temp_viz::Viz3d::updatePolygonMesh (const Mesh3d& mesh, const String &id)
{
return impl_->updatePolygonMesh(mesh, Mat(), id);
}
bool temp_viz::Viz3d::addPolylineFromPolygonMesh (const Mesh3d& mesh, const String &id)
{
return impl_->addPolylineFromPolygonMesh(mesh, id);
}
bool temp_viz::Viz3d::addText (const String &text, int xpos, int ypos, const Color& color, int fontsize, const String &id)
{
return impl_->addText(text, xpos, ypos, color, fontsize, id);
}
bool temp_viz::Viz3d::addPolygon(const Mat& cloud, const Color& color, const String& id)
{
return impl_->addPolygon(cloud, color, id);
}
bool temp_viz::Viz3d::addSphere (const cv::Point3f &center, double radius, const Color& color, const std::string &id)
{
return impl_->addSphere(center, radius, color, id);
}
void temp_viz::Viz3d::spin()
{
impl_->spin();
}
void temp_viz::Viz3d::spinOnce (int time, bool force_redraw)
{
impl_->spinOnce(time, force_redraw);
}
bool temp_viz::Viz3d::addPlane (const ModelCoefficients &coefficients, const String &id)
{
return impl_->addPlane(coefficients, id);
}
bool temp_viz::Viz3d::addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String& id)
{
return impl_->addPlane(coefficients, x, y, z, id);
}
bool temp_viz::Viz3d::removeCoordinateSystem (const String &id)
{
return impl_->removeCoordinateSystem(id);
}
This diff is collapsed.
This diff is collapsed.
#include "test_precomp.hpp"
CV_TEST_MAIN("cv")
#include "test_precomp.hpp"
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
# if defined __clang__ || defined __APPLE__
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
# pragma GCC diagnostic ignored "-Wextra"
# endif
#endif
#ifndef __OPENCV_TEST_PRECOMP_HPP__
#define __OPENCV_TEST_PRECOMP_HPP__
#include "opencv2/ts.hpp"
#include "opencv2/core/core_c.h"
#include <iostream>
#endif
/*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"
#include <opencv2/viz.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <fstream>
#include <string>
#include <opencv2/viz/types.hpp>
#include <opencv2/viz/mesh_load.hpp>
cv::Mat cvcloud_load()
{
cv::Mat cloud(1, 20000, CV_32FC3);
std::ifstream ifs("d:/cloud_dragon.ply");
std::string str;
for(size_t i = 0; i < 11; ++i)
std::getline(ifs, str);
cv::Point3f* data = cloud.ptr<cv::Point3f>();
for(size_t i = 0; i < 20000; ++i)
ifs >> data[i].x >> data[i].y >> data[i].z;
return cloud;
}
TEST(Viz_viz3d, accuracy)
{
temp_viz::Viz3d v("abc");
//v.spin();
v.setBackgroundColor();
v.addCoordinateSystem(1.0, cv::Affine3f::Identity());
cv::Mat cloud = cvcloud_load();
cv::Mat colors(cloud.size(), CV_8UC3, cv::Scalar(0, 255, 0));
v.addPointCloud(cloud, colors);
cv::Mat normals(cloud.size(), CV_32FC3, cv::Scalar(0, 10, 0));
v.addPointCloudNormals(cloud, normals, 100, 0.02, "n");
temp_viz::ModelCoefficients mc;
mc.values.resize(4);
mc.values[0] = mc.values[1] = mc.values[2] = mc.values[3] = 1;
v.addPlane(mc);
temp_viz::Mesh3d::Ptr mesh = temp_viz::mesh_load("d:/horse.ply");
v.addPolygonMesh(*mesh, "pq");
v.spinOnce(1000, true);
v.removeCoordinateSystem();
for(int i = 0; i < mesh->cloud.cols; ++i)
mesh->cloud.ptr<cv::Point3f>()[i] += cv::Point3f(1, 1, 1);
v.updatePolygonMesh(*mesh, "pq");
for(int i = 0; i < mesh->cloud.cols; ++i)
mesh->cloud.ptr<cv::Point3f>()[i] -= cv::Point3f(2, 2, 2);
v.addPolylineFromPolygonMesh(*mesh);
v.addText("===Abd sadfljsadlk", 100, 100, cv::Scalar(255, 0, 0), 15);
for(int i = 0; i < cloud.cols; ++i)
cloud.ptr<cv::Point3f>()[i].x *=2;
colors.setTo(cv::Scalar(255, 0, 0));
v.addSphere(cv::Point3f(0, 0, 0), 0.3, temp_viz::Color::blue());
cv::Mat cvpoly(1, 5, CV_32FC3);
cv::Point3f* pdata = cvpoly.ptr<cv::Point3f>();
pdata[0] = cv::Point3f(0, 0, 0);
pdata[1] = cv::Point3f(0, 1, 1);
pdata[2] = cv::Point3f(3, 1, 2);
pdata[3] = cv::Point3f(0, 2, 4);
pdata[4] = cv::Point3f(7, 2, 3);
v.addPolygon(cvpoly, temp_viz::Color::white());
v.updatePointCloud(cloud, colors);
v.spin();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment