Commit 07d55b05 authored by Anatoly Baksheev's avatar Anatoly Baksheev

Merge pull request #20 from ozantonkal/low_order_tasks

Low order tasks
parents 35e79529 5eed0d6b
.. _viz:
Launching Viz
*************
Goal
====
In this tutorial you will learn how to
.. container:: enumeratevisibleitemswithsquare
* Open a visualization window.
* Access a window by its name.
* Start event loop.
* Start event loop for a given amount of time.
Code
====
You can download the code from `here <../../../../samples/cpp/tutorial_code/viz/launching_viz.cpp>`_.
.. code-block:: cpp
#include <opencv2/viz.hpp>
#include <iostream>
using namespace cv;
using namespace std;
/**
* @function main
*/
int main()
{
/// Create a window
viz::Viz3d myWindow("Viz Demo");
/// Start event loop
myWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "First event loop is over" << endl;
/// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo");
/// Start event loop
sameWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "Second event loop is over" << endl;
/// Event loop is over when pressed q, Q, e, E
/// Start event loop once for 1 millisecond
sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped())
{
/// Interact with window
/// Event loop for 1 millisecond
sameWindow.spinOnce(1, true);
}
/// Once more event loop is stopped
cout << "Last event loop is over" << endl;
return 0;
}
Explanation
===========
Here is the general structure of the program:
* Create a window.
.. code-block:: cpp
/// Create a window
viz::Viz3d myWindow("Viz Demo");
* Start event loop. This event loop will run until user terminates it by pressing **e**, **E**, **q**, **Q**.
.. code-block:: cpp
/// Start event loop
myWindow.spin();
* Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly the same with **myWindow**. If the name does not exist, a new window is created.
.. code-block:: cpp
/// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo");
* Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping. Inside the while loop, user can execute other statements including those which interact with the window.
.. code-block:: cpp
/// Event loop is over when pressed q, Q, e, E
/// Start event loop once for 1 millisecond
sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped())
{
/// Interact with window
/// Event loop for 1 millisecond
sameWindow.spinOnce(1, true);
}
Results
=======
Here is the result of the program.
.. image:: images/window_demo.png
:alt: Launching Viz
:align: center
...@@ -49,4 +49,3 @@ if(BUILD_opencv_viz) ...@@ -49,4 +49,3 @@ if(BUILD_opencv_viz)
target_link_libraries(opencv_viz "-framework Cocoa") target_link_libraries(opencv_viz "-framework Cocoa")
endif() endif()
endif() endif()
***********************
viz. 3D Visualizer
***********************
.. toctree::
:maxdepth: 2
viz3d.rst
widget.rst
This diff is collapsed.
This diff is collapsed.
...@@ -65,9 +65,10 @@ namespace cv ...@@ -65,9 +65,10 @@ namespace cv
//! takes coordiante frame data and builds transfrom to global coordinate frame //! 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)); 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 position, 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& y_dir); CV_EXPORTS Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir);
//! retrieves a window by its name
CV_EXPORTS Viz3d get(const String &window_name); CV_EXPORTS Viz3d get(const String &window_name);
//! checks float value for Nan //! checks float value for Nan
...@@ -92,6 +93,7 @@ namespace cv ...@@ -92,6 +93,7 @@ namespace cv
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p) template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); } { return isNan(p.x) || isNan(p.y) || isNan(p.z); }
//! helper class that provides access by name infrastructure
class CV_EXPORTS VizAccessor class CV_EXPORTS VizAccessor
{ {
public: public:
...@@ -102,6 +104,7 @@ namespace cv ...@@ -102,6 +104,7 @@ namespace cv
void add(Viz3d window); void add(Viz3d window);
void remove(const String &window_name); void remove(const String &window_name);
//! window names automatically have Viz - prefix even though not provided by the users
static void generateWindowName(const String &window_name, String &output); static void generateWindowName(const String &window_name, String &output);
private: private:
...@@ -112,8 +115,8 @@ namespace cv ...@@ -112,8 +115,8 @@ namespace cv
static bool is_instantiated_; static bool is_instantiated_;
static VizMap viz_map_; static VizMap viz_map_;
}; };
} } /* namespace viz */
} } /* namespace cv */
#endif /* __OPENCV_VIZ_HPP__ */ #endif /* __OPENCV_VIZ_HPP__ */
......
...@@ -39,6 +39,7 @@ namespace cv ...@@ -39,6 +39,7 @@ namespace cv
Mat cloud, colors; Mat cloud, colors;
Mat polygons; Mat polygons;
//! Loads mesh from a given ply file
static cv::viz::Mesh3d loadMesh(const String& file); static cv::viz::Mesh3d loadMesh(const String& file);
private: private:
...@@ -52,14 +53,8 @@ namespace cv ...@@ -52,14 +53,8 @@ namespace cv
static const unsigned int Ctrl = 2; static const unsigned int Ctrl = 2;
static const unsigned int Shift = 4; static const unsigned int Shift = 4;
/** \brief Constructor //! Create a keyboard event
* \param[in] action true for key was pressed, false for released //! - Note that action is true if key is pressed, false if 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); KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
bool isAltPressed () const; bool isAltPressed () const;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include <opencv2/viz/types.hpp> #include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp> #include <opencv2/viz/widgets.hpp>
#include <boost/concept_check.hpp>
namespace cv namespace cv
{ {
...@@ -25,18 +24,10 @@ namespace cv ...@@ -25,18 +24,10 @@ namespace cv
Viz3d& operator=(const Viz3d&); Viz3d& operator=(const Viz3d&);
~Viz3d(); ~Viz3d();
void setBackgroundColor(const Color& color = Color::black());
//to refactor
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 addPolygon(const Mat& cloud, const Color& color, const String& id = "polygon");
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void removeWidget(const String &id); void removeWidget(const String &id);
Widget getWidget(const String &id) const; Widget getWidget(const String &id) const;
void removeAllWidgets();
void setWidgetPose(const String &id, const Affine3f &pose); void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose); void updateWidgetPose(const String &id, const Affine3f &pose);
...@@ -47,13 +38,19 @@ namespace cv ...@@ -47,13 +38,19 @@ namespace cv
Affine3f getViewerPose(); Affine3f getViewerPose();
void setViewerPose(const Affine3f &pose); void setViewerPose(const Affine3f &pose);
void resetCameraViewpoint (const String &id);
void resetCamera();
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
Size getWindowSize() const; Size getWindowSize() const;
void setWindowSize(const Size &window_size); void setWindowSize(const Size &window_size);
String getWindowName() const; String getWindowName() const;
void saveScreenshot (const String &file);
void setWindowPosition (int x, int y);
void setFullScreen (bool mode);
void setBackgroundColor(const Color& color = Color::black());
void spin(); void spin();
void spinOnce(int time = 1, bool force_redraw = false); void spinOnce(int time = 1, bool force_redraw = false);
...@@ -61,6 +58,16 @@ namespace cv ...@@ -61,6 +58,16 @@ namespace cv
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0); void registerMouseCallback(MouseCallback callback, void* cookie = 0);
void setRenderingProperty(const String &id, int property, double value);
double getRenderingProperty(const String &id, int property);
void setDesiredUpdateRate(double time);
double getDesiredUpdateRate();
void setRepresentationToSurface();
void setRepresentationToWireframe();
void setRepresentationToPoints();
private: private:
struct VizImpl; struct VizImpl;
......
#pragma once #pragma once
#include <opencv2/viz/types.hpp> #include <opencv2/viz/types.hpp>
#include <common.h>
namespace cv namespace cv
{ {
...@@ -14,19 +12,23 @@ namespace cv ...@@ -14,19 +12,23 @@ namespace cv
{ {
public: public:
Widget(); Widget();
Widget(const Widget &other); Widget(const Widget& other);
Widget& operator =(const Widget &other); Widget& operator=(const Widget& other);
~Widget(); ~Widget();
//! Create a widget directly from ply file
static Widget fromPlyFile(const String &file_name);
//! Rendering properties of this particular widget
void setRenderingProperty(int property, double value);
double getRenderingProperty(int property) const;
//! Casting between widgets
template<typename _W> _W cast(); template<typename _W> _W cast();
private: private:
class Impl; class Impl;
Impl *impl_; Impl *impl_;
friend struct WidgetAccessor; friend struct WidgetAccessor;
void create();
void release();
}; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -41,7 +43,6 @@ namespace cv ...@@ -41,7 +43,6 @@ namespace cv
Affine3f getPose() const; Affine3f getPose() const;
void setColor(const Color &color); void setColor(const Color &color);
private: private:
struct MatrixConverter; struct MatrixConverter;
...@@ -61,9 +62,6 @@ namespace cv ...@@ -61,9 +62,6 @@ namespace cv
{ {
public: public:
LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white());
void setLineWidth(float line_width);
float getLineWidth();
}; };
class CV_EXPORTS PlaneWidget : public Widget3D class CV_EXPORTS PlaneWidget : public Widget3D
...@@ -123,7 +121,9 @@ namespace cv ...@@ -123,7 +121,9 @@ namespace cv
class CV_EXPORTS GridWidget : public Widget3D class CV_EXPORTS GridWidget : public Widget3D
{ {
public: public:
//! Creates grid at the origin
GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
//! Creates grid based on the plane equation
GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
private: private:
...@@ -160,7 +160,9 @@ namespace cv ...@@ -160,7 +160,9 @@ namespace cv
class CV_EXPORTS Image3DWidget : public Widget3D class CV_EXPORTS Image3DWidget : public Widget3D
{ {
public: public:
//! Creates 3D image at the origin
Image3DWidget(const Mat &image, const Size &size); Image3DWidget(const Mat &image, const Size &size);
//! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation
Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size); Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size);
void setImage(const Mat &image); void setImage(const Mat &image);
...@@ -169,11 +171,14 @@ namespace cv ...@@ -169,11 +171,14 @@ namespace cv
class CV_EXPORTS CameraPositionWidget : public Widget3D class CV_EXPORTS CameraPositionWidget : public Widget3D
{ {
public: public:
//! Creates camera coordinate frame (axes) at the origin
CameraPositionWidget(double scale = 1.0); CameraPositionWidget(double scale = 1.0);
//! Creates frustum based on the intrinsic marix K at the origin
CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white());
//! Creates frustum based on the field of view at the origin
CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white());
//! Creates frustum and display given image at the far plane
CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()); CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white());
}; };
class CV_EXPORTS TrajectoryWidget : public Widget3D class CV_EXPORTS TrajectoryWidget : public Widget3D
...@@ -181,9 +186,12 @@ namespace cv ...@@ -181,9 +186,12 @@ namespace cv
public: public:
enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2}; enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2};
//! Displays trajectory of the given path either by coordinate frames or polyline
TrajectoryWidget(const std::vector<Affine3f> &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0); TrajectoryWidget(const std::vector<Affine3f> &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0);
TrajectoryWidget(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); // Camera frustums //! Displays trajectory of the given path by frustums
TrajectoryWidget(const std::vector<Affine3f> &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); // Camera frustums TrajectoryWidget(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white());
//! Displays trajectory of the given path by frustums
TrajectoryWidget(const std::vector<Affine3f> &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white());
private: private:
struct ApplyPath; struct ApplyPath;
...@@ -199,7 +207,9 @@ namespace cv ...@@ -199,7 +207,9 @@ namespace cv
class CV_EXPORTS CloudWidget : public Widget3D class CV_EXPORTS CloudWidget : public Widget3D
{ {
public: public:
//! Each point in cloud is mapped to a color in colors
CloudWidget(InputArray cloud, InputArray colors); CloudWidget(InputArray cloud, InputArray colors);
//! All points in cloud have the same color
CloudWidget(InputArray cloud, const Color &color = Color::white()); CloudWidget(InputArray cloud, const Color &color = Color::white());
private: private:
...@@ -211,7 +221,9 @@ namespace cv ...@@ -211,7 +221,9 @@ namespace cv
public: public:
CloudCollectionWidget(); CloudCollectionWidget();
//! Each point in cloud is mapped to a color in colors
void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()); void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity());
//! All points in cloud have the same color
void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity()); void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity());
private: private:
......
...@@ -298,7 +298,7 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget ...@@ -298,7 +298,7 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget
} }
vtkPolyData *data = vtkPolyData::SafeDownCast(mapper->GetInput()); vtkPolyData *data = vtkPolyData::SafeDownCast(mapper->GetInput());
CV_Assert(data); CV_Assert("Cloud Widget without data" && data);
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New(); vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort()); appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort());
...@@ -357,7 +357,7 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, InputArray _col ...@@ -357,7 +357,7 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, InputArray _col
transform_filter->Update(); transform_filter->Update();
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("Incompatible widget type." && actor);
Vec3d minmax(scalars->GetRange()); Vec3d minmax(scalars->GetRange());
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax); CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
...@@ -392,7 +392,7 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, const Color &co ...@@ -392,7 +392,7 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, const Color &co
transform_filter->Update(); transform_filter->Update();
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("Incompatible widget type." && actor);
Vec3d minmax(scalars->GetRange()); Vec3d minmax(scalars->GetRange());
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax); CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
......
This diff is collapsed.
...@@ -8,20 +8,6 @@ namespace cv ...@@ -8,20 +8,6 @@ namespace cv
{ {
namespace viz namespace 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 enum RenderingProperties
{ {
VIZ_POINT_SIZE, VIZ_POINT_SIZE,
......
#include "precomp.hpp" #include "precomp.hpp"
#include "interactor_style.h" #include "interactor_style.h"
//#include <q/visualization/vtk/vtkVertexBufferObjectMapper.h>
using namespace cv; using namespace cv;
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
...@@ -152,17 +149,9 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K ...@@ -152,17 +149,9 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K
void void
cv::viz::InteractorStyle::OnKeyDown () cv::viz::InteractorStyle::OnKeyDown ()
{ {
if (!init_)
{
std::cout << "Interactor style not initialized. Please call Initialize () before continuing" << std::endl;
return;
}
if (!renderer_) CV_Assert("Interactor style not initialized. Please call Initialize () before continuing" && init_);
{ CV_Assert("No renderer given! Use SetRendererCollection () before continuing." && renderer_);
std::cout << "No renderer given! Use SetRendererCollection () before continuing." << std::endl;
return;
}
FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]);
...@@ -235,7 +224,7 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -235,7 +224,7 @@ cv::viz::InteractorStyle::OnKeyDown ()
{ {
for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); )
{ {
vtkSmartPointer<vtkActor> apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ()); vtkActor* apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ());
apart->GetProperty ()->SetRepresentationToPoints (); apart->GetProperty ()->SetRepresentationToPoints ();
} }
} }
...@@ -258,15 +247,12 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -258,15 +247,12 @@ cv::viz::InteractorStyle::OnKeyDown ()
cam->GetFocalPoint (focal); cam->GetFocalPoint (focal);
cam->GetPosition (pos); cam->GetPosition (pos);
cam->GetViewUp (view); cam->GetViewUp (view);
#ifndef M_PI
# define M_PI 3.14159265358979323846 // pi
#endif
int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); int *win_pos = Interactor->GetRenderWindow ()->GetPosition ();
int *win_size = Interactor->GetRenderWindow ()->GetSize (); int *win_size = Interactor->GetRenderWindow ()->GetSize ();
ofs_cam << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" << ofs_cam << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" <<
pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" << pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" <<
cam->GetViewAngle () / 180.0 * M_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] cam->GetViewAngle () / 180.0 * CV_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1]
<< endl; << endl;
ofs_cam.close (); ofs_cam.close ();
...@@ -310,7 +296,7 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -310,7 +296,7 @@ cv::viz::InteractorStyle::OnKeyDown ()
{ {
for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); )
{ {
vtkSmartPointer<vtkActor> apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ()); vtkActor* apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ());
float psize = apart->GetProperty ()->GetPointSize (); float psize = apart->GetProperty ()->GetPointSize ();
if (psize < 63.0f) if (psize < 63.0f)
apart->GetProperty ()->SetPointSize (psize + 1.0f); apart->GetProperty ()->SetPointSize (psize + 1.0f);
...@@ -331,7 +317,7 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -331,7 +317,7 @@ cv::viz::InteractorStyle::OnKeyDown ()
{ {
for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); )
{ {
vtkSmartPointer<vtkActor> apart = static_cast<vtkActor*> (path->GetLastNode ()->GetViewProp ()); vtkActor* apart = static_cast<vtkActor*> (path->GetLastNode ()->GetViewProp ());
float psize = apart->GetProperty ()->GetPointSize (); float psize = apart->GetProperty ()->GetPointSize ();
if (psize > 1.0f) if (psize > 1.0f)
apart->GetProperty ()->SetPointSize (psize - 1.0f); apart->GetProperty ()->SetPointSize (psize - 1.0f);
...@@ -432,17 +418,17 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -432,17 +418,17 @@ cv::viz::InteractorStyle::OnKeyDown ()
vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera (); vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera ();
static CloudActorMap::iterator it = actors_->begin (); static WidgetActorMap::iterator it = widget_actor_map_->begin ();
// it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault. // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault.
bool found_transformation = false; bool found_transformation = false;
for (size_t idx = 0; idx < actors_->size (); ++idx, ++it) for (size_t idx = 0; idx < widget_actor_map_->size (); ++idx, ++it)
{ {
if (it == actors_->end ()) if (it == widget_actor_map_->end ())
it = actors_->begin (); it = widget_actor_map_->begin ();
const CloudActor& actor = it->second; vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
if (actor.viewpoint_transformation_.GetPointer ()) if (actor && actor->GetUserMatrix())
{ {
found_transformation = true; found_transformation = true;
break; break;
...@@ -452,18 +438,18 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -452,18 +438,18 @@ cv::viz::InteractorStyle::OnKeyDown ()
// if a valid transformation was found, use it otherwise fall back to default view point. // if a valid transformation was found, use it otherwise fall back to default view point.
if (found_transformation) if (found_transformation)
{ {
const CloudActor& actor = it->second; vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
cam->SetPosition (actor.viewpoint_transformation_->GetElement (0, 3), cam->SetPosition (actor->GetUserMatrix()->GetElement (0, 3),
actor.viewpoint_transformation_->GetElement (1, 3), actor->GetUserMatrix()->GetElement (1, 3),
actor.viewpoint_transformation_->GetElement (2, 3)); actor->GetUserMatrix()->GetElement (2, 3));
cam->SetFocalPoint (actor.viewpoint_transformation_->GetElement (0, 3) - actor.viewpoint_transformation_->GetElement (0, 2), cam->SetFocalPoint (actor->GetUserMatrix()->GetElement (0, 3) - actor->GetUserMatrix()->GetElement (0, 2),
actor.viewpoint_transformation_->GetElement (1, 3) - actor.viewpoint_transformation_->GetElement (1, 2), actor->GetUserMatrix()->GetElement (1, 3) - actor->GetUserMatrix()->GetElement (1, 2),
actor.viewpoint_transformation_->GetElement (2, 3) - actor.viewpoint_transformation_->GetElement (2, 2)); actor->GetUserMatrix()->GetElement (2, 3) - actor->GetUserMatrix()->GetElement (2, 2));
cam->SetViewUp (actor.viewpoint_transformation_->GetElement (0, 1), cam->SetViewUp (actor->GetUserMatrix()->GetElement (0, 1),
actor.viewpoint_transformation_->GetElement (1, 1), actor->GetUserMatrix()->GetElement (1, 1),
actor.viewpoint_transformation_->GetElement (2, 1)); actor->GetUserMatrix()->GetElement (2, 1));
} }
else else
{ {
...@@ -473,10 +459,10 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -473,10 +459,10 @@ cv::viz::InteractorStyle::OnKeyDown ()
} }
// go to the next actor for the next key-press event. // go to the next actor for the next key-press event.
if (it != actors_->end ()) if (it != widget_actor_map_->end ())
++it; ++it;
else else
it = actors_->begin (); it = widget_actor_map_->begin ();
CurrentRenderer->SetActiveCamera (cam); CurrentRenderer->SetActiveCamera (cam);
CurrentRenderer->ResetCameraClippingRange (); CurrentRenderer->ResetCameraClippingRange ();
...@@ -659,17 +645,8 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward () ...@@ -659,17 +645,8 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward ()
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnTimer () void cv::viz::InteractorStyle::OnTimer ()
{ {
if (!init_) CV_Assert("Interactor style not initialized." && init_);
{ CV_Assert("Renderer has not been set." && renderer_);
std::cout << "[PCLVisualizerInteractorStyle] Interactor style not initialized. Please call Initialize () before continuing.\n" << std::endl;
return;
}
if (!renderer_)
{
std::cout << "[PCLVisualizerInteractorStyle] No renderer collection given! Use SetRendererCollection () before continuing." << std::endl;
return;
}
renderer_->Render (); renderer_->Render ();
Interactor->Render (); Interactor->Render ();
} }
......
...@@ -50,7 +50,7 @@ namespace cv ...@@ -50,7 +50,7 @@ namespace cv
/** \brief Initialization routine. Must be called before anything else. */ /** \brief Initialization routine. Must be called before anything else. */
virtual void Initialize (); virtual void Initialize ();
inline void setCloudActorMap (const Ptr<CloudActorMap>& actors) { actors_ = actors; } inline void setWidgetActorMap (const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; }
void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; } void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0);
...@@ -73,7 +73,7 @@ namespace cv ...@@ -73,7 +73,7 @@ namespace cv
vtkSmartPointer<vtkRenderer> renderer_; vtkSmartPointer<vtkRenderer> renderer_;
/** \brief Actor map stored internally. */ /** \brief Actor map stored internally. */
cv::Ptr<CloudActorMap> actors_; cv::Ptr<WidgetActorMap> widget_actor_map_;
/** \brief The current window width/height. */ /** \brief The current window width/height. */
Vec2i win_size_; Vec2i win_size_;
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <Eigen/Geometry>
#if defined __GNUC__ #if defined __GNUC__
#pragma GCC system_header #pragma GCC system_header
#ifdef __DEPRECATED #ifdef __DEPRECATED
...@@ -17,34 +15,19 @@ ...@@ -17,34 +15,19 @@
#include <vtkAppendPolyData.h> #include <vtkAppendPolyData.h>
#include <vtkAssemblyPath.h> #include <vtkAssemblyPath.h>
#include <vtkAxesActor.h>
#include <vtkActor.h>
#include <vtkBoxRepresentation.h>
#include <vtkBoxWidget.h>
#include <vtkBoxWidget2.h>
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkMath.h>
#include <vtkLoopSubdivisionFilter.h>
#include <vtkLineSource.h> #include <vtkLineSource.h>
#include <vtkLegendScaleActor.h>
#include <vtkLightKit.h>
#include <vtkPlatonicSolidSource.h>
#include <vtkPropPicker.h> #include <vtkPropPicker.h>
#include <vtkGeneralTransform.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>
#include <vtkDataSet.h> #include <vtkDataSet.h>
#include <vtkDataSetSurfaceFilter.h>
#include <vtkExecutive.h>
#include <vtkPolygon.h> #include <vtkPolygon.h>
#include <vtkPointPicker.h> #include <vtkPointPicker.h>
#include <vtkUnstructuredGrid.h> #include <vtkUnstructuredGrid.h>
#include <vtkConeSource.h>
#include <vtkDiskSource.h> #include <vtkDiskSource.h>
#include <vtkPlaneSource.h> #include <vtkPlaneSource.h>
#include <vtkSphereSource.h> #include <vtkSphereSource.h>
#include <vtkArrowSource.h> #include <vtkArrowSource.h>
#include <vtkOutlineSource.h> #include <vtkOutlineSource.h>
#include <vtkIdentityTransform.h>
#include <vtkTransform.h> #include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h> #include <vtkTransformPolyDataFilter.h>
#include <vtkTubeFilter.h> #include <vtkTubeFilter.h>
...@@ -59,18 +42,12 @@ ...@@ -59,18 +42,12 @@
#include <vtkDataSetMapper.h> #include <vtkDataSetMapper.h>
#include <vtkCellArray.h> #include <vtkCellArray.h>
#include <vtkCommand.h> #include <vtkCommand.h>
#include <vtkCellLocator.h>
#include <vtkPLYReader.h> #include <vtkPLYReader.h>
#include <vtkTransformFilter.h>
#include <vtkPolyLine.h> #include <vtkPolyLine.h>
#include <vtkVectorText.h> #include <vtkVectorText.h>
#include <vtkFollower.h> #include <vtkFollower.h>
#include <vtkCallbackCommand.h>
#include <vtkInteractorStyle.h> #include <vtkInteractorStyle.h>
#include <vtkInformationVector.h>
#include <vtkDataArray.h>
#include <vtkUnsignedCharArray.h> #include <vtkUnsignedCharArray.h>
#include <vtkPoints.h>
#include <vtkRendererCollection.h> #include <vtkRendererCollection.h>
#include <vtkPNGWriter.h> #include <vtkPNGWriter.h>
#include <vtkWindowToImageFilter.h> #include <vtkWindowToImageFilter.h>
...@@ -78,78 +55,22 @@ ...@@ -78,78 +55,22 @@
#include <vtkProperty.h> #include <vtkProperty.h>
#include <vtkCamera.h> #include <vtkCamera.h>
#include <vtkObjectFactory.h> #include <vtkObjectFactory.h>
#include <vtkScalarBarActor.h>
#include <vtkScalarsToColors.h>
#include <vtkClipPolyData.h>
#include <vtkPlanes.h> #include <vtkPlanes.h>
#include <vtkImageImport.h>
#include <vtkImageViewer.h> #include <vtkImageViewer.h>
#include <vtkInteractorStyleImage.h>
#include <vtkImageFlip.h> #include <vtkImageFlip.h>
#include <vtkTIFFWriter.h>
#include <vtkBMPWriter.h>
#include <vtkJPEGWriter.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindow.h> #include <vtkRenderWindow.h>
#include <vtkXYPlotActor.h>
#include <vtkTextProperty.h> #include <vtkTextProperty.h>
#include <vtkProperty2D.h> #include <vtkProperty2D.h>
#include <vtkFieldData.h>
#include <vtkDoubleArray.h>
#include <vtkLODActor.h> #include <vtkLODActor.h>
#include <vtkPolyDataWriter.h>
#include <vtkTextActor.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 <vtkImageActor.h>
#include <vtkRenderWindowInteractor.h> #include <vtkRenderWindowInteractor.h>
#include <vtkChartXY.h> #include <vtkMath.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 <vtkExtractEdges.h> #include <vtkExtractEdges.h>
#include <vtkFrustumSource.h> #include <vtkFrustumSource.h>
#include <vtkTextureMapToPlane.h> #include <vtkTextureMapToPlane.h>
#include <vtkPolyDataNormals.h> #include <vtkPolyDataNormals.h>
#include <vtkMapper.h>
#include <vtkSelectionNode.h>
#include <vtkAbstractPicker.h>
#include <vtkAbstractPropPicker.h>
#include <vtkMatrix4x4.h>
#include <vtkInteractorObserver.h>
#include <vtkMapper2D.h>
#include <vtkLeaderActor2D.h>
#include <vtkAlgorithmOutput.h> #include <vtkAlgorithmOutput.h>
#if defined __GNUC__ && defined __DEPRECATED_DISABLED__ #if defined __GNUC__ && defined __DEPRECATED_DISABLED__
#define __DEPRECATED #define __DEPRECATED
#undef __DEPRECATED_DISABLED__ #undef __DEPRECATED_DISABLED__
......
...@@ -27,20 +27,6 @@ cv::viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Co ...@@ -27,20 +27,6 @@ cv::viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Co
setColor(color); setColor(color);
} }
void cv::viz::LineWidget::setLineWidth(float line_width)
{
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor);
actor->GetProperty()->SetLineWidth(line_width);
}
float cv::viz::LineWidget::getLineWidth()
{
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor);
return actor->GetProperty()->GetLineWidth();
}
template<> cv::viz::LineWidget cv::viz::Widget::cast<cv::viz::LineWidget>() template<> cv::viz::LineWidget cv::viz::Widget::cast<cv::viz::LineWidget>()
{ {
Widget3D widget = this->cast<Widget3D>(); Widget3D widget = this->cast<Widget3D>();
...@@ -556,12 +542,12 @@ cv::viz::Text3DWidget::Text3DWidget(const String &text, const Point3f &position, ...@@ -556,12 +542,12 @@ cv::viz::Text3DWidget::Text3DWidget(const String &text, const Point3f &position,
void cv::viz::Text3DWidget::setText(const String &text) void cv::viz::Text3DWidget::setText(const String &text)
{ {
vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this)); vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("This widget does not support text." && actor);
// Update text source // Update text source
vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer()); vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer());
CV_Assert(textSource); CV_Assert("This widget does not support text." && textSource);
textSource->SetText(text.c_str()); textSource->SetText(text.c_str());
textSource->Update(); textSource->Update();
...@@ -570,11 +556,11 @@ void cv::viz::Text3DWidget::setText(const String &text) ...@@ -570,11 +556,11 @@ void cv::viz::Text3DWidget::setText(const String &text)
cv::String cv::viz::Text3DWidget::getText() const cv::String cv::viz::Text3DWidget::getText() const
{ {
vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this)); vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("This widget does not support text." && actor);
vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer()); vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer());
CV_Assert(textSource); CV_Assert("This widget does not support text." && textSource);
return textSource->GetText(); return textSource->GetText();
} }
...@@ -615,14 +601,14 @@ template<> cv::viz::TextWidget cv::viz::Widget::cast<cv::viz::TextWidget>() ...@@ -615,14 +601,14 @@ template<> cv::viz::TextWidget cv::viz::Widget::cast<cv::viz::TextWidget>()
void cv::viz::TextWidget::setText(const String &text) void cv::viz::TextWidget::setText(const String &text)
{ {
vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("This widget does not support text." && actor);
actor->SetInput(text.c_str()); actor->SetInput(text.c_str());
} }
cv::String cv::viz::TextWidget::getText() const cv::String cv::viz::TextWidget::getText() const
{ {
vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("This widget does not support text." && actor);
return actor->GetInput(); return actor->GetInput();
} }
...@@ -671,10 +657,10 @@ void cv::viz::ImageOverlayWidget::setImage(const Mat &image) ...@@ -671,10 +657,10 @@ void cv::viz::ImageOverlayWidget::setImage(const Mat &image)
CV_Assert(!image.empty() && image.depth() == CV_8U); CV_Assert(!image.empty() && image.depth() == CV_8U);
vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("This widget does not support overlay image." && actor);
vtkImageMapper *mapper = vtkImageMapper::SafeDownCast(actor->GetMapper()); vtkImageMapper *mapper = vtkImageMapper::SafeDownCast(actor->GetMapper());
CV_Assert(mapper); CV_Assert("This widget does not support overlay image." && mapper);
// Create the vtk image and set its parameters based on input image // Create the vtk image and set its parameters based on input image
vtkSmartPointer<vtkImageData> vtk_image = vtkSmartPointer<vtkImageData>::New(); vtkSmartPointer<vtkImageData> vtk_image = vtkSmartPointer<vtkImageData>::New();
...@@ -821,7 +807,7 @@ void cv::viz::Image3DWidget::setImage(const Mat &image) ...@@ -821,7 +807,7 @@ void cv::viz::Image3DWidget::setImage(const Mat &image)
CV_Assert(!image.empty() && image.depth() == CV_8U); CV_Assert(!image.empty() && image.depth() == CV_8U);
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert(actor); CV_Assert("This widget does not support 3D image." && actor);
// Create the vtk image and set its parameters based on input image // Create the vtk image and set its parameters based on input image
vtkSmartPointer<vtkImageData> vtk_image = vtkSmartPointer<vtkImageData>::New(); vtkSmartPointer<vtkImageData> vtk_image = vtkSmartPointer<vtkImageData>::New();
...@@ -969,7 +955,6 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Matx33f &K, const Mat ...@@ -969,7 +955,6 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Matx33f &K, const Mat
// Create a camera // Create a camera
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New(); vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
float f_x = K(0,0);
float f_y = K(1,1); float f_y = K(1,1);
float c_y = K(1,2); float c_y = K(1,2);
float aspect_ratio = float(image.cols)/float(image.rows); float aspect_ratio = float(image.cols)/float(image.rows);
......
...@@ -14,8 +14,8 @@ cv::viz::Color cv::viz::Color::blue() { return Color(255, 0, 0); } ...@@ -14,8 +14,8 @@ cv::viz::Color cv::viz::Color::blue() { return Color(255, 0, 0); }
cv::viz::Color cv::viz::Color::cyan() { return Color(255, 255, 0); } cv::viz::Color cv::viz::Color::cyan() { return Color(255, 255, 0); }
cv::viz::Color cv::viz::Color::red() { return Color( 0, 0, 255); } cv::viz::Color cv::viz::Color::red() { return Color( 0, 0, 255); }
cv::viz::Color cv::viz::Color::magenta() { return Color( 0, 255, 255); } cv::viz::Color cv::viz::Color::yellow() { return Color( 0, 255, 255); }
cv::viz::Color cv::viz::Color::yellow() { return Color(255, 0, 255); } cv::viz::Color cv::viz::Color::magenta() { return Color(255, 0, 255); }
cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); } cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); }
cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); } cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); }
...@@ -72,11 +72,12 @@ struct cv::viz::Mesh3d::loadMeshImpl ...@@ -72,11 +72,12 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New(); vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(file.c_str()); reader->SetFileName(file.c_str());
reader->Update(); reader->Update();
vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput (); vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput ();
CV_Assert("File does not exist or file format is not supported." && poly_data);
vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints (); vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints ();
vtkIdType nr_points = mesh_points->GetNumberOfPoints (); vtkIdType nr_points = mesh_points->GetNumberOfPoints ();
//vtkIdType nr_polygons = poly_data->GetNumberOfPolys ();
mesh.cloud.create(1, nr_points, CV_32FC3); mesh.cloud.create(1, nr_points, CV_32FC3);
...@@ -89,18 +90,10 @@ struct cv::viz::Mesh3d::loadMeshImpl ...@@ -89,18 +90,10 @@ struct cv::viz::Mesh3d::loadMeshImpl
} }
// Then the color information, if any // Then the color information, if any
vtkUnsignedCharArray* poly_colors = NULL; vtkUnsignedCharArray* poly_colors = 0;
if (poly_data->GetPointData() != NULL) if (poly_data->GetPointData())
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("Colors")); poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars());
// 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)) if (poly_colors && (poly_colors->GetNumberOfComponents () == 3))
{ {
mesh.colors.create(1, nr_points, CV_8UC3); mesh.colors.create(1, nr_points, CV_8UC3);
......
...@@ -33,7 +33,9 @@ void cv::viz::Viz3d::create(const String &window_name) ...@@ -33,7 +33,9 @@ void cv::viz::Viz3d::create(const String &window_name)
void cv::viz::Viz3d::release() void cv::viz::Viz3d::release()
{ {
if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) // If the current referene count is equal to 2, we can delete it
// - 2 : because minimum there will be two instances, one of which is in the map
if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 2)
{ {
// Erase the window // Erase the window
cv::viz::VizAccessor::getInstance().remove(getWindowName()); cv::viz::VizAccessor::getInstance().remove(getWindowName());
...@@ -42,28 +44,6 @@ void cv::viz::Viz3d::release() ...@@ -42,28 +44,6 @@ void cv::viz::Viz3d::release()
} }
} }
void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); }
bool cv::viz::Viz3d::addPolygonMesh (const Mesh3d& mesh, const String& id)
{
return impl_->addPolygonMesh(mesh, Mat(), id);
}
bool cv::viz::Viz3d::updatePolygonMesh (const Mesh3d& mesh, const String& id)
{
return impl_->updatePolygonMesh(mesh, Mat(), id);
}
bool cv::viz::Viz3d::addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id)
{
return impl_->addPolylineFromPolygonMesh(mesh, id);
}
bool cv::viz::Viz3d::addPolygon(const Mat& cloud, const Color& color, const String& id)
{
return impl_->addPolygon(cloud, color, id);
}
void cv::viz::Viz3d::spin() { impl_->spin(); } 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::spinOnce (int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); }
bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); } bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); }
...@@ -74,11 +54,10 @@ void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* c ...@@ -74,11 +54,10 @@ void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* c
void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie) void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie)
{ impl_->registerMouseCallback(callback, cookie); } { impl_->registerMouseCallback(callback, cookie); }
void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); } void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); }
void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); } 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); } 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::setWidgetPose(const String &id, const Affine3f &pose) { impl_->setWidgetPose(id, pose); } void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3f &pose) { impl_->setWidgetPose(id, pose); }
void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose) { impl_->updateWidgetPose(id, pose); } void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose) { impl_->updateWidgetPose(id, pose); }
cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); }
...@@ -88,9 +67,26 @@ cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); } ...@@ -88,9 +67,26 @@ cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); }
void cv::viz::Viz3d::setViewerPose(const Affine3f &pose) { impl_->setViewerPose(pose); } void cv::viz::Viz3d::setViewerPose(const Affine3f &pose) { impl_->setViewerPose(pose); }
cv::Affine3f cv::viz::Viz3d::getViewerPose() { return impl_->getViewerPose(); } cv::Affine3f cv::viz::Viz3d::getViewerPose() { 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::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); } 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(); } cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); }
void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); } void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); }
cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); } cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); }
void cv::viz::Viz3d::saveScreenshot (const String &file) { impl_->saveScreenshot(file); }
void cv::viz::Viz3d::setWindowPosition (int x, int y) { impl_->setWindowPosition(x,y); }
void cv::viz::Viz3d::setFullScreen (bool mode) { impl_->setFullScreen(mode); }
void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); }
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::setDesiredUpdateRate(double time) { impl_->setDesiredUpdateRate(time); }
double cv::viz::Viz3d::getDesiredUpdateRate() { return impl_->getDesiredUpdateRate(); }
void cv::viz::Viz3d::setRepresentationToSurface() { impl_->setRepresentationToSurface(); }
void cv::viz::Viz3d::setRepresentationToWireframe() { impl_->setRepresentationToWireframe(); }
void cv::viz::Viz3d::setRepresentationToPoints() { impl_->setRepresentationToPoints(); }
\ No newline at end of file
This diff is collapsed.
...@@ -17,47 +17,17 @@ public: ...@@ -17,47 +17,17 @@ public:
VizImpl (const String &name); VizImpl (const String &name);
virtual ~VizImpl (); virtual ~VizImpl ();
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void removeWidget(const String &id);
Widget getWidget(const String &id) const;
void removeAllWidgets();
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
void setDesiredUpdateRate(double time);
double getDesiredUpdateRate();
//to refactor
bool removePointCloud (const String& id = "cloud");
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 ();
//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 */ /** \brief Returns true when the user tried to close the window */
bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; } bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; }
...@@ -76,78 +46,29 @@ public: ...@@ -76,78 +46,29 @@ public:
} }
} }
void setRepresentationToSurface();
void setRepresentationToPoints();
void setRepresentationToWireframe();
// 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");
// 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");
// to implement in Viz3d with shorter name
void setRepresentationToSurfaceForAllActors();
void setRepresentationToPointsForAllActors();
void setRepresentationToWireframeForAllActors();
// ////////////////////////////////////////////////////////////////////////////////////
// All camera methods to refactor into set/getViewwerPose, setCamera()
// and 'Camera' class itself with various constructors/fields
void setCamera(const Camera &camera); void setCamera(const Camera &camera);
Camera getCamera() const; Camera getCamera() const;
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. /** \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"); void resetCameraViewpoint(const String& id);
void resetCamera();
//to implement Viz3d set/getViewerPose()
void setViewerPose(const Affine3f &pose); void setViewerPose(const Affine3f &pose);
Affine3f getViewerPose(); Affine3f getViewerPose();
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
//to implemnt in Viz3d
void saveScreenshot (const String &file); void saveScreenshot (const String &file);
void setWindowPosition (int x, int y); void setWindowPosition (int x, int y);
Size getWindowSize() const; Size getWindowSize() const;
void setWindowSize (int xw, int yw); void setWindowSize (int xw, int yw);
void setFullScreen (bool mode); void setFullScreen (bool mode);
void setWindowName (const String &name);
String getWindowName() const; String getWindowName() const;
void setBackgroundColor (const Color& color); void setBackgroundColor (const Color& color);
...@@ -157,22 +78,6 @@ public: ...@@ -157,22 +78,6 @@ public:
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback 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;
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
private: private:
vtkSmartPointer<vtkRenderWindowInteractor> interactor_; vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
...@@ -209,6 +114,7 @@ private: ...@@ -209,6 +114,7 @@ private:
if (event_id == vtkCommand::ExitEvent) if (event_id == vtkCommand::ExitEvent)
{ {
viz_->stopped_ = true; viz_->stopped_ = true;
viz_->interactor_->GetRenderWindow()->Finalize();
viz_->interactor_->TerminateApp (); viz_->interactor_->TerminateApp ();
} }
} }
...@@ -233,25 +139,14 @@ private: ...@@ -233,25 +139,14 @@ private:
/** \brief The render window interactor style. */ /** \brief The render window interactor style. */
vtkSmartPointer<InteractorStyle> style_; vtkSmartPointer<InteractorStyle> style_;
/** \brief Internal list with actor pointers and name IDs for point clouds. */
cv::Ptr<CloudActorMap> cloud_actor_map_;
/** \brief Internal list with actor pointers and name IDs for shapes. */
cv::Ptr<ShapeActorMap> shape_actor_map_;
/** \brief Internal list with actor pointers and name IDs for all widget actors */ /** \brief Internal list with actor pointers and name IDs for all widget actors */
cv::Ptr<WidgetActorMap> widget_actor_map_; cv::Ptr<WidgetActorMap> widget_actor_map_;
/** \brief Boolean that holds whether or not the camera parameters were manually initialized*/ /** \brief Boolean that holds whether or not the camera parameters were manually initialized*/
bool camera_set_; bool camera_set_;
bool removeActorFromRenderer (const vtkSmartPointer<vtkLODActor> &actor);
bool removeActorFromRenderer (const vtkSmartPointer<vtkActor> &actor);
bool removeActorFromRenderer (const vtkSmartPointer<vtkProp> &actor); bool removeActorFromRenderer (const vtkSmartPointer<vtkProp> &actor);
//void addActorToRenderer (const vtkSmartPointer<vtkProp> &actor);
/** \brief Internal method. Creates a vtk actor from a vtk polydata object. /** \brief Internal method. Creates a vtk actor from a vtk polydata object.
* \param[in] data the vtk polydata object to create an actor for * \param[in] data the vtk polydata object to create an actor for
* \param[out] actor the resultant vtk actor object * \param[out] actor the resultant vtk actor object
...@@ -268,10 +163,6 @@ private: ...@@ -268,10 +163,6 @@ private:
* generate * generate
*/ */
void updateCells (vtkSmartPointer<vtkIdTypeArray> &cells, vtkSmartPointer<vtkIdTypeArray> &initcells, vtkIdType nr_points); void updateCells (vtkSmartPointer<vtkIdTypeArray> &cells, vtkSmartPointer<vtkIdTypeArray> &initcells, vtkIdType nr_points);
void allocVtkPolyData (vtkSmartPointer<vtkAppendPolyData> &polydata);
void allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata);
void allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata);
}; };
...@@ -280,17 +171,9 @@ namespace cv ...@@ -280,17 +171,9 @@ namespace cv
{ {
namespace viz namespace viz
{ {
//void getTransformationMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternionf& orientation, Eigen::Matrix4f &transformation);
vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const cv::Matx44f &m); vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const cv::Matx44f &m);
cv::Matx44f convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix); cv::Matx44f convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix);
/** \brief Convert origin and orientation to vtkMatrix4x4
* \param[in] origin the point cloud origin
* \param[in] orientation the point cloud orientation
* \param[out] vtk_matrix the resultant VTK 4x4 matrix
*/
void convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternion<float> &orientation, vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
struct NanFilter struct NanFilter
{ {
template<typename _Tp, typename _Msk> template<typename _Tp, typename _Msk>
......
...@@ -6,29 +6,7 @@ namespace cv ...@@ -6,29 +6,7 @@ namespace cv
{ {
namespace viz namespace viz
{ {
struct CV_EXPORTS CloudActor typedef std::map<std::string, vtkSmartPointer<vtkProp> > WidgetActorMap;
{
/** \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;
};
// TODO This will be used to contain both cloud and shape actors
struct CV_EXPORTS WidgetActor
{
vtkSmartPointer<vtkProp> actor;
vtkSmartPointer<vtkMatrix4x4> viewpoint_transformation_;
vtkSmartPointer<vtkIdTypeArray> cells;
};
typedef std::map<std::string, CloudActor> CloudActorMap;
typedef std::map<std::string, vtkSmartPointer<vtkProp> > ShapeActorMap;
typedef std::map<std::string, WidgetActor> WidgetActorMap;
} }
} }
This diff is collapsed.
/**
* @file creating_widgets.cpp
* @brief Creating custom widgets using VTK
* @author Ozan Cagri Tonkal
*/
#include <opencv2/viz.hpp>
#include <opencv2/viz/widget_accessor.hpp>
#include <iostream>
#include <vtkPoints.h>
#include <vtkTriangle.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkIdList.h>
#include <vtkActor.h>
#include <vtkProp.h>
using namespace cv;
using namespace std;
/**
* @function help
* @brief Display instructions to use this tutorial program
*/
void help()
{
cout
<< "--------------------------------------------------------------------------" << endl
<< "This program shows how to create a custom widget. You can create your own "
<< "widgets by extending Widget2D/Widget3D, and with the help of WidgetAccessor." << endl
<< "Usage:" << endl
<< "./creating_widgets" << endl
<< endl;
}
/**
* @class TriangleWidget
* @brief Defining our own 3D Triangle widget
*/
class TriangleWidget : public viz::Widget3D
{
public:
TriangleWidget(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
};
/**
* @function TriangleWidget::TriangleWidget
* @brief Constructor
*/
TriangleWidget::TriangleWidget(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color)
{
// Create a triangle
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(pt1.x, pt1.y, pt1.z);
points->InsertNextPoint(pt2.x, pt2.y, pt2.z);
points->InsertNextPoint(pt3.x, pt3.y, pt3.z);
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId(0,0);
triangle->GetPointIds()->SetId(1,1);
triangle->GetPointIds()->SetId(2,2);
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(triangle);
// Create a polydata object
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
// Add the geometry and topology to the polydata
polyData->SetPoints(points);
polyData->SetPolys(cells);
// Create mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(polyData);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor);
}
/**
* @function main
*/
int main()
{
help();
/// Create a window
viz::Viz3d myWindow("Creating Widgets");
/// Create a triangle widget
TriangleWidget tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0));
/// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw);
/// Start event loop
myWindow.spin();
return 0;
}
/**
* @file launching_viz.cpp
* @brief Launching visualization window
* @author Ozan Cagri Tonkal
*/
#include <opencv2/viz.hpp>
#include <iostream>
using namespace cv;
using namespace std;
/**
* @function help
* @brief Display instructions to use this tutorial program
*/
void help()
{
cout
<< "--------------------------------------------------------------------------" << endl
<< "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. "
<< "You can access the same window via its name. You can run event loop for a given period of time. " << endl
<< "Usage:" << endl
<< "./launching_viz" << endl
<< endl;
}
/**
* @function main
*/
int main()
{
help();
/// Create a window
viz::Viz3d myWindow("Viz Demo");
/// Start event loop
myWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "First event loop is over" << endl;
/// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo");
/// Start event loop
sameWindow.spin();
/// Event loop is over when pressed q, Q, e, E
cout << "Second event loop is over" << endl;
/// Event loop is over when pressed q, Q, e, E
/// Start event loop once for 1 millisecond
sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped())
{
/// Interact with window
/// Event loop for 1 millisecond
sameWindow.spinOnce(1, true);
}
/// Once more event loop is stopped
cout << "Last event loop is over" << endl;
return 0;
}
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