added comments with future work for VizImpl
added authors to license header
This commit is contained in:
parent
d6e2b657f9
commit
6ca1822f36
@ -1,3 +1,6 @@
|
||||
set(BUILD_opencv_viz_INIT OFF)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Find qvtk
|
||||
# This sets the following variables:
|
||||
@ -36,20 +39,23 @@ macro(find_vtk)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
|
||||
|
||||
#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()
|
||||
|
||||
|
||||
find_vtk()
|
||||
|
||||
|
||||
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.")
|
||||
@ -65,14 +71,13 @@ 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}
|
||||
set(BUILD_opencv_viz_INIT OFF)
|
||||
include_directories(src)
|
||||
ocv_define_module(viz opencv_core)
|
||||
|
||||
target_link_libraries(opencv_viz vtkCommon vtkWidgets vtkHybrid vtkCharts vtkFiltering vtkRendering ${OPENGL_LIBRARIES})
|
||||
target_link_libraries(opencv_viz vtkCommon vtkWidgets vtkFiltering vtkRendering)
|
||||
#${OPENGL_LIBRARIES})
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(opencv_viz "-framework Cocoa")
|
||||
|
@ -38,9 +38,12 @@
|
||||
// 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.
|
||||
//
|
||||
// * Point Cloud Library (PCL) - www.pointclouds.org
|
||||
// During implementation if OpenCV Viz module, similar module
|
||||
// from PCL was used as reference implementation.
|
||||
// Authors:
|
||||
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
|
||||
// * Ozan Tonkal
|
||||
//
|
||||
// During implementation of OpenCV Viz module, similar module
|
||||
// from PCL (www.pointclouds.org) was used as reference implementation.
|
||||
//
|
||||
//M*/
|
||||
|
||||
@ -60,9 +63,10 @@ namespace cv
|
||||
//! takes coordiante frame data and builds transfrom to global coordinate frame
|
||||
CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0));
|
||||
|
||||
//! constructs camera pose from posiont, focal_point and up_vector (see gluLookAt() for more infromation
|
||||
//! constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation
|
||||
CV_EXPORTS Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& up_vector);
|
||||
|
||||
|
||||
//! checks float value for Nan
|
||||
inline bool isNan(float x)
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <opencv2/core/cvdef.h>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/affine.hpp>
|
||||
|
||||
|
@ -18,3 +18,22 @@ cv::Affine3f cv::viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& ax
|
||||
|
||||
return Affine3f(R, origin);
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix (const cv::Matx44f &m)
|
||||
{
|
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
vtk_matrix->SetElement(i, k, m(i, k));
|
||||
return vtk_matrix;
|
||||
}
|
||||
|
||||
cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix)
|
||||
{
|
||||
cv::Matx44f m;
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
m(i, k) = vtk_matrix->GetElement (i, k);
|
||||
return m;
|
||||
}
|
||||
|
@ -626,11 +626,9 @@ void cv::viz::Viz3d::VizImpl::resetCamera ()
|
||||
renderer_->ResetCamera ();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::setCameraPosition (const cv::Vec3d& pos, const cv::Vec3d& view, const cv::Vec3d& up)
|
||||
{
|
||||
|
||||
vtkSmartPointer<vtkCamera> cam = renderer_->GetActiveCamera ();
|
||||
cam->SetPosition (pos[0], pos[1], pos[2]);
|
||||
cam->SetFocalPoint (view[0], view[1], view[2]);
|
||||
@ -642,13 +640,10 @@ void cv::viz::Viz3d::VizImpl::setCameraPosition (const cv::Vec3d& pos, const cv:
|
||||
void cv::viz::Viz3d::VizImpl::setCameraPosition (double pos_x, double pos_y, double pos_z, double up_x, double up_y, double up_z)
|
||||
{
|
||||
//rens_->InitTraversal ();
|
||||
|
||||
|
||||
vtkSmartPointer<vtkCamera> cam = renderer_->GetActiveCamera ();
|
||||
cam->SetPosition (pos_x, pos_y, pos_z);
|
||||
cam->SetViewUp (up_x, up_y, up_z);
|
||||
renderer_->Render ();
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -980,20 +975,13 @@ void cv::viz::Viz3d::VizImpl::updateCells (vtkSmartPointer<vtkIdTypeArray> &cell
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::allocVtkPolyData (vtkSmartPointer<vtkAppendPolyData> &polydata)
|
||||
{
|
||||
polydata = vtkSmartPointer<vtkAppendPolyData>::New ();
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata)
|
||||
{
|
||||
polydata = vtkSmartPointer<vtkPolyData>::New ();
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata)
|
||||
{
|
||||
polydata = vtkSmartPointer<vtkUnstructuredGrid>::New ();
|
||||
}
|
||||
{polydata = vtkSmartPointer<vtkAppendPolyData>::New (); }
|
||||
|
||||
void cv::viz::Viz3d::VizImpl::allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata)
|
||||
{ polydata = vtkSmartPointer<vtkPolyData>::New (); }
|
||||
|
||||
void cv::viz::Viz3d::VizImpl::allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata)
|
||||
{ polydata = vtkSmartPointer<vtkUnstructuredGrid>::New (); }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternion<float> &orientation, vtkSmartPointer<vtkMatrix4x4> &vtk_matrix)
|
||||
@ -1011,23 +999,6 @@ void cv::viz::convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Qu
|
||||
vtk_matrix->SetElement (3, 3, 1.0f);
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix (const cv::Matx44f &m)
|
||||
{
|
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
vtk_matrix->SetElement(i, k, m(i, k));
|
||||
return vtk_matrix;
|
||||
}
|
||||
|
||||
cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix)
|
||||
{
|
||||
cv::Matx44f m;
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
m(i, k) = vtk_matrix->GetElement (i, k);
|
||||
return m;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -1043,8 +1014,8 @@ void cv::viz::Viz3d::VizImpl::setWindowName (const std::string &name)
|
||||
window_->SetWindowName (name.c_str ());
|
||||
}
|
||||
|
||||
void cv::viz::Viz3d::VizImpl::setPosition (int x, int y) { window_->SetPosition (x, y); }
|
||||
void cv::viz::Viz3d::VizImpl::setSize (int xw, int yw) { window_->SetSize (xw, yw); }
|
||||
void cv::viz::Viz3d::VizImpl::setWindowPosition (int x, int y) { window_->SetPosition (x, y); }
|
||||
void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize (xw, yw); }
|
||||
|
||||
bool cv::viz::Viz3d::VizImpl::addPolygonMesh (const Mesh3d& mesh, const Mat& mask, const std::string &id)
|
||||
{
|
||||
|
@ -13,47 +13,50 @@ public:
|
||||
typedef Viz3d::MouseCallback MouseCallback;
|
||||
|
||||
VizImpl (const String &name);
|
||||
|
||||
virtual ~VizImpl ();
|
||||
void setFullScreen (bool mode);
|
||||
void setWindowName (const String &name);
|
||||
|
||||
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
|
||||
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
|
||||
|
||||
void spin ();
|
||||
void spinOnce (int time = 1, bool force_redraw = false);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//to refactor
|
||||
bool removePointCloud (const String& id = "cloud");
|
||||
inline bool removePolygonMesh (const String& id = "polygon")
|
||||
{
|
||||
// Polygon Meshes are represented internally as point clouds with special cell array structures since 1.4
|
||||
return removePointCloud (id);
|
||||
}
|
||||
inline bool removePolygonMesh (const String& id = "polygon") { return removePointCloud (id); }
|
||||
bool removeShape (const String& id = "cloud");
|
||||
|
||||
bool removeText3D (const String& id = "cloud");
|
||||
bool removeAllPointClouds ();
|
||||
|
||||
//create Viz3d::removeAllWidgets()
|
||||
bool removeAllShapes ();
|
||||
|
||||
void setBackgroundColor (const Color& color);
|
||||
|
||||
//to refactor
|
||||
bool addPolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon");
|
||||
bool updatePolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon");
|
||||
|
||||
bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline");
|
||||
|
||||
// to refactor: Widget3D:: & Viz3d::
|
||||
bool setPointCloudRenderingProperties (int property, double value, const String& id = "cloud");
|
||||
bool getPointCloudRenderingProperties (int property, double &value, const String& id = "cloud");
|
||||
|
||||
bool setShapeRenderingProperties (int property, double value, const String& id);
|
||||
|
||||
/** \brief Set whether the point cloud is selected or not
|
||||
* \param[in] selected whether the cloud is selected or not (true = selected)
|
||||
* \param[in] id the point cloud object id (default: cloud)
|
||||
*/
|
||||
// probably should just remove
|
||||
bool setPointCloudSelected (const bool selected, const String& id = "cloud" );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** \brief Returns true when the user tried to close the window */
|
||||
bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; }
|
||||
|
||||
@ -64,106 +67,113 @@ public:
|
||||
void close ()
|
||||
{
|
||||
stopped_ = true;
|
||||
// This tends to close the window...
|
||||
interactor_->TerminateApp ();
|
||||
interactor_->TerminateApp (); // This tends to close the window...
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// to refactor
|
||||
bool addPolygon(const cv::Mat& cloud, const Color& color, const String& id = "polygon");
|
||||
bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color, bool display_length, const String& id = "arrow");
|
||||
bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color_line, const Color& color_text, const String& id = "arrow");
|
||||
|
||||
// Add a vtkPolydata as a mesh
|
||||
// Probably remove this
|
||||
bool addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata, const String& id = "PolyData");
|
||||
bool addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata, vtkSmartPointer<vtkTransform> transform, const String& id = "PolyData");
|
||||
|
||||
// I think this should be moved to 'static Widget Widget::fromPlyFile(const String&)';
|
||||
bool addModelFromPLYFile (const String &filename, const String& id = "PLYModel");
|
||||
bool addModelFromPLYFile (const String &filename, vtkSmartPointer<vtkTransform> transform, const String& id = "PLYModel");
|
||||
|
||||
/** \brief Changes the visual representation for all actors to surface representation. */
|
||||
void setRepresentationToSurfaceForAllActors ();
|
||||
|
||||
/** \brief Changes the visual representation for all actors to points representation. */
|
||||
void setRepresentationToPointsForAllActors ();
|
||||
// to implement in Viz3d with shorter name
|
||||
void setRepresentationToSurfaceForAllActors();
|
||||
void setRepresentationToPointsForAllActors();
|
||||
void setRepresentationToWireframeForAllActors();
|
||||
|
||||
/** \brief Changes the visual representation for all actors to wireframe representation. */
|
||||
void setRepresentationToWireframeForAllActors ();
|
||||
|
||||
/** \brief Initialize camera parameters with some default values. */
|
||||
void initCameraParameters ();
|
||||
|
||||
/** \brief Search for camera parameters at the command line and set them internally.
|
||||
bool getCameraParameters (int argc, char **argv);
|
||||
|
||||
/** \brief Checks whether the camera parameters were manually loaded from file.*/
|
||||
bool cameraParamsSet () const;
|
||||
|
||||
/** \brief Update camera parameters and render. */
|
||||
void updateCamera ();
|
||||
|
||||
/** \brief Reset camera parameters and render. */
|
||||
void resetCamera ();
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////
|
||||
// All camera methods to refactor into set/getViewwerPose, setCamera()
|
||||
// and 'Camera' class itself with various constructors/fields
|
||||
|
||||
void initCameraParameters (); /** \brief Initialize camera parameters with some default values. */
|
||||
bool cameraParamsSet () const; /** \brief Checks whether the camera parameters were manually loaded from file.*/
|
||||
void updateCamera (); /** \brief Update camera parameters and render. */
|
||||
void resetCamera (); /** \brief Reset camera parameters and render. */
|
||||
|
||||
/** \brief Reset the camera direction from {0, 0, 0} to the center_{x, y, z} of a given dataset.
|
||||
* \param[in] id the point cloud object id (default: cloud)
|
||||
*/
|
||||
* \param[in] id the point cloud object id (default: cloud) */
|
||||
void resetCameraViewpoint (const String& id = "cloud");
|
||||
|
||||
/** \brief Set the camera pose given by position, viewpoint and up vector
|
||||
* \param[in] pos_x the x coordinate of the camera location
|
||||
* \param[in] pos_y the y coordinate of the camera location
|
||||
* \param[in] pos_z the z coordinate of the camera location
|
||||
* \param[in] view_x the x component of the view point of the camera
|
||||
* \param[in] view_y the y component of the view point of the camera
|
||||
* \param[in] view_z the z component of the view point of the camera
|
||||
* \param[in] up_x the x component of the view up direction of the camera
|
||||
* \param[in] up_y the y component of the view up direction of the camera
|
||||
* \param[in] up_z the y component of the view up direction of the camera
|
||||
*/
|
||||
* \param[in] pos camera location
|
||||
* \param[in] view the view point of the camera
|
||||
* \param[in] up the view up direction of the camera */
|
||||
void setCameraPosition (const cv::Vec3d& pos, const cv::Vec3d& view, const cv::Vec3d& up);
|
||||
|
||||
/** \brief Set the camera location and viewup according to the given arguments
|
||||
* \param[in] pos_x the x coordinate of the camera location
|
||||
* \param[in] pos_y the y coordinate of the camera location
|
||||
* \param[in] pos_z the z coordinate of the camera location
|
||||
* \param[in] up_x the x component of the view up direction of the camera
|
||||
* \param[in] up_y the y component of the view up direction of the camera
|
||||
* \param[in] up_z the z component of the view up direction of the camera
|
||||
*/
|
||||
* \param[in] pos_x,y,z the x,y,z coordinate of the camera location
|
||||
* \param[in] up_x,y,z the x,y,z component of the view up direction of the camera */
|
||||
void setCameraPosition (double pos_x, double pos_y, double pos_z, double up_x, double up_y, double up_z);
|
||||
|
||||
/** \brief Set the camera parameters via an intrinsics and and extrinsics matrix
|
||||
* \note This assumes that the pixels are square and that the center of the image is at the center of the sensor.
|
||||
* \param[in] intrinsics the intrinsics that will be used to compute the VTK camera parameters
|
||||
* \param[in] extrinsics the extrinsics that will be used to compute the VTK camera parameters
|
||||
*/
|
||||
* \note This assumes that the pixels are square and that the center of the image is at the center of the sensor.
|
||||
* \param[in] intrinsics the intrinsics that will be used to compute the VTK camera parameters
|
||||
* \param[in] extrinsics the extrinsics that will be used to compute the VTK camera parameters */
|
||||
void setCameraParameters (const cv::Matx33f& intrinsics, const Affine3f& extrinsics);
|
||||
|
||||
/** \brief Set the camera parameters by given a full camera data structure.
|
||||
* \param[in] camera camera structure containing all the camera parameters.
|
||||
*/
|
||||
void setCameraParameters (const Camera &camera);
|
||||
|
||||
/** \brief Set the camera clipping distances.
|
||||
* \param[in] near the near clipping distance (no objects closer than this to the camera will be drawn)
|
||||
* \param[in] far the far clipping distance (no objects further away than this to the camera will be drawn)
|
||||
*/
|
||||
void setCameraClipDistances (double near, double far);
|
||||
|
||||
/** \brief Set the camera vertical field of view in radians */
|
||||
void setCameraFieldOfView (double fovy);
|
||||
|
||||
/** \brief Get the current camera parameters. */
|
||||
void getCameras (Camera& camera);
|
||||
|
||||
/** \brief Get the current viewing pose. */
|
||||
Affine3f getViewerPose ();
|
||||
//to implement Viz3d set/getViewerPose()
|
||||
Affine3f getViewerPose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//to implemnt in Viz3d
|
||||
void saveScreenshot (const String &file);
|
||||
void setWindowPosition (int x, int y);
|
||||
void setWindowSize (int xw, int yw);
|
||||
void setFullScreen (bool mode);
|
||||
void setWindowName (const String &name);
|
||||
void setBackgroundColor (const Color& color);
|
||||
|
||||
/** \brief Return a pointer to the underlying VTK Render Window used. */
|
||||
//vtkSmartPointer<vtkRenderWindow> getRenderWindow () { return (window_); }
|
||||
void spin ();
|
||||
void spinOnce (int time = 1, bool force_redraw = false);
|
||||
|
||||
void setPosition (int x, int y);
|
||||
void setSize (int xw, int yw);
|
||||
|
||||
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
|
||||
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//declare above (to move to up)
|
||||
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
|
||||
void removeWidget(const String &id);
|
||||
Widget getWidget(const String &id) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user