mass switch from Affine3f to Affine3d

pull/2173/head
Anatoly Baksheev 11 years ago
parent b1c0bf1fee
commit 186853a50f
  1. 28
      modules/viz/doc/viz3d.rst
  2. 36
      modules/viz/doc/widget.rst
  3. 7
      modules/viz/include/opencv2/viz.hpp
  4. 12
      modules/viz/include/opencv2/viz/viz3d.hpp
  5. 17
      modules/viz/include/opencv2/viz/widgets.hpp
  6. 4
      modules/viz/src/clouds.cpp
  7. 112
      modules/viz/src/shapes.cpp
  8. 12
      modules/viz/src/viz3d.cpp
  9. 58
      modules/viz/src/vizcore.cpp
  10. 40
      modules/viz/src/vizimpl.cpp
  11. 37
      modules/viz/src/vizimpl.hpp
  12. 10
      modules/viz/src/widget.cpp
  13. 18
      modules/viz/test/test_tutorial2.cpp
  14. 10
      modules/viz/test/test_tutorial3.cpp
  15. 2
      modules/viz/test/test_viz3d.cpp

@ -13,7 +13,7 @@ viz::makeTransformToGlobal
--------------------------
Takes coordinate frame data and builds transform to global coordinate frame.
.. ocv:function:: Affine3f viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0))
.. ocv:function:: Affine3d viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0))
:param axis_x: X axis vector in global coordinate frame.
:param axis_y: Y axis vector in global coordinate frame.
@ -26,7 +26,7 @@ viz::makeCameraPose
-------------------
Constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation).
.. ocv:function:: Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir)
.. ocv:function:: Affine3d makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir)
:param position: Position of the camera in global coordinate frame.
:param focal_point: Focal point of the camera in global coordinate frame.
@ -94,19 +94,19 @@ The Viz3d class represents a 3D visualizer window. This class is implicitly shar
Viz3d& operator=(const Viz3d&);
~Viz3d();
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
void removeWidget(const String &id);
Widget getWidget(const String &id) const;
void removeAllWidgets();
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const;
void setCamera(const Camera &camera);
Camera getCamera() const;
Affine3f getViewerPose();
void setViewerPose(const Affine3f &pose);
Affine3d getViewerPose();
void setViewerPose(const Affine3d &pose);
void resetCameraViewpoint (const String &id);
void resetCamera();
@ -152,7 +152,7 @@ viz::Viz3d::showWidget
----------------------
Shows a widget in the window.
.. ocv:function:: void Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity())
.. ocv:function:: void Viz3d::showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity())
:param id: A unique id for the widget.
:param widget: The widget to be displayed in the window.
@ -186,7 +186,7 @@ viz::Viz3d::setWidgetPose
-------------------------
Sets pose of a widget in the window.
.. ocv:function:: void setWidgetPose(const String &id, const Affine3f &pose)
.. ocv:function:: void setWidgetPose(const String &id, const Affine3d &pose)
:param id: The id of the widget whose pose will be set.
:param pose: The new pose of the widget.
@ -195,7 +195,7 @@ viz::Viz3d::updateWidgetPose
----------------------------
Updates pose of a widget in the window by pre-multiplying its current pose.
.. ocv:function:: void updateWidgetPose(const String &id, const Affine3f &pose)
.. ocv:function:: void updateWidgetPose(const String &id, const Affine3d &pose)
:param id: The id of the widget whose pose will be updated.
:param pose: The pose that the current pose of the widget will be pre-multiplied by.
@ -204,7 +204,7 @@ viz::Viz3d::getWidgetPose
-------------------------
Returns the current pose of a widget in the window.
.. ocv:function:: Affine3f getWidgetPose(const String &id) const
.. ocv:function:: Affine3d getWidgetPose(const String &id) const
:param id: The id of the widget whose pose will be returned.
@ -226,13 +226,13 @@ viz::Viz3d::getViewerPose
-------------------------
Returns the current pose of the viewer.
..ocv:function:: Affine3f getViewerPose()
..ocv:function:: Affine3d getViewerPose()
viz::Viz3d::setViewerPose
-------------------------
Sets pose of the viewer.
.. ocv:function:: void setViewerPose(const Affine3f &pose)
.. ocv:function:: void setViewerPose(const Affine3d &pose)
:param pose: The new pose of the viewer.

@ -170,9 +170,9 @@ Base class of all 3D widgets. ::
public:
Widget3D() {}
void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose);
Affine3f getPose() const;
void setPose(const Affine3d &pose);
void updatePose(const Affine3d &pose);
Affine3d getPose() const;
void setColor(const Color &color);
private:
@ -183,7 +183,7 @@ viz::Widget3D::setPose
----------------------
Sets pose of the widget.
.. ocv:function:: void setPose(const Affine3f &pose)
.. ocv:function:: void setPose(const Affine3d &pose)
:param pose: The new pose of the widget.
@ -191,7 +191,7 @@ viz::Widget3D::updateWidgetPose
-------------------------------
Updates pose of the widget by pre-multiplying its current pose.
.. ocv:function:: void updateWidgetPose(const Affine3f &pose)
.. ocv:function:: void updateWidgetPose(const Affine3d &pose)
:param pose: The pose that the current pose of the widget will be pre-multiplied by.
@ -199,7 +199,7 @@ viz::Widget3D::getPose
----------------------
Returns the current pose of the widget.
.. ocv:function:: Affine3f getWidgetPose() const
.. ocv:function:: Affine3d getWidgetPose() const
viz::Widget3D::setColor
-----------------------
@ -732,14 +732,14 @@ This 3D Widget represents a trajectory. ::
enum {FRAMES = 1, PATH = 2, BOTH = FRAMES + PATH};
//! Displays trajectory of the given path either by coordinate frames or polyline
WTrajectory(const std::vector<Affine3f> &path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white(),;
WTrajectory(const std::vector<Affine3d> &path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white(),;
};
viz::WTrajectory::WTrajectory
-----------------------------
Constructs a WTrajectory.
.. ocv:function:: WTrajectory(const std::vector<Affine3f> &path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white())
.. ocv:function:: WTrajectory(const std::vector<Affine3d> &path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white())
:param path: List of poses on a trajectory.
:param display_mode: Display mode. This can be PATH, FRAMES, and BOTH.
@ -762,16 +762,16 @@ This 3D Widget represents a trajectory. ::
{
public:
//! Displays trajectory of the given path by frustums
WTrajectoryFrustums(const std::vector<Affine3f> &path, const Matx33f &K, float scale = 1.0, const Color &color = Color::white());
WTrajectoryFrustums(const std::vector<Affine3d> &path, const Matx33f &K, float scale = 1.0, const Color &color = Color::white());
//! Displays trajectory of the given path by frustums
WTrajectoryFrustums(const std::vector<Affine3f> &path, const Vec2f &fov, float scale = 1.0, const Color &color = Color::white());
WTrajectoryFrustums(const std::vector<Affine3d> &path, const Vec2f &fov, float scale = 1.0, const Color &color = Color::white());
};
viz::WTrajectoryFrustums::WTrajectoryFrustums
-----------------------------
Constructs a WTrajectoryFrustums.
.. ocv:function:: WTrajectoryFrustums(const std::vector<Affine3f> &path, const Matx33f &K, float scale = 1.0, const Color &color = Color::white())
.. ocv:function:: WTrajectoryFrustums(const std::vector<Affine3d> &path, const Matx33f &K, float scale = 1.0, const Color &color = Color::white())
:param path: List of poses on a trajectory.
:param K: Intrinsic matrix of the camera.
@ -780,7 +780,7 @@ Constructs a WTrajectoryFrustums.
Displays frustums at each pose of the trajectory.
.. ocv:function:: WTrajectoryFrustums(const std::vector<Affine3f> &path, const Vec2f &fov, float scale = 1.0, const Color &color = Color::white())
.. ocv:function:: WTrajectoryFrustums(const std::vector<Affine3d> &path, const Vec2f &fov, float scale = 1.0, const Color &color = Color::white())
:param path: List of poses on a trajectory.
:param fov: Field of view of the camera (horizontal, vertical).
@ -799,7 +799,7 @@ represent the direction from previous position to the current. ::
class CV_EXPORTS WTrajectorySpheres : public Widget3D
{
public:
WTrajectorySpheres(const std::vector<Affine3f> &path, float line_length = 0.05f,
WTrajectorySpheres(const std::vector<Affine3d> &path, float line_length = 0.05f,
float init_sphere_radius = 0.021, sphere_radius = 0.007,
Color &line_color = Color::white(), const Color &sphere_color = Color::white());
};
@ -808,7 +808,7 @@ viz::WTrajectorySpheres::WTrajectorySpheres
-------------------------------------------
Constructs a WTrajectorySpheres.
.. ocv:function:: WTrajectorySpheres(const std::vector<Affine3f> &path, float line_length = 0.05f, float init_sphere_radius = 0.021, float sphere_radius = 0.007, const Color &line_color = Color::white(), const Color &sphere_color = Color::white())
.. ocv:function:: WTrajectorySpheres(const std::vector<Affine3d> &path, float line_length = 0.05f, float init_sphere_radius = 0.021, float sphere_radius = 0.007, const Color &line_color = Color::white(), const Color &sphere_color = Color::white())
:param path: List of poses on a trajectory.
:param line_length: Length of the lines.
@ -867,9 +867,9 @@ This 3D Widget defines a collection of clouds. ::
WCloudCollection();
//! 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 Affine3d &pose = Affine3d::Identity());
//! All points in cloud have the same color
void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3f &pose = Affine3f::Identity());
void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3d &pose = Affine3d::Identity());
private:
/* hidden */
@ -885,7 +885,7 @@ viz::WCloudCollection::addCloud
-------------------------------
Adds a cloud to the collection.
.. ocv:function:: void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity())
.. ocv:function:: void addCloud(InputArray cloud, InputArray colors, const Affine3d &pose = Affine3d::Identity())
:param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``.
:param colors: Set of colors. It has to be of the same size with cloud.
@ -893,7 +893,7 @@ Adds a cloud to the collection.
Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
.. ocv:function:: void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity())
.. ocv:function:: void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3d &pose = Affine3d::Identity())
:param cloud: Point set which can be of type: ``CV_32FC3``, ``CV_32FC4``, ``CV_64FC3``, ``CV_64FC4``.
:param colors: A single :ocv:class:`Color` for the whole cloud.

@ -58,10 +58,10 @@ namespace cv
namespace viz
{
//! takes coordiante frame data and builds transfrom to global coordinate frame
CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0));
CV_EXPORTS Affine3d makeTransformToGlobal(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin = Vec3d::all(0));
//! 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 Affine3d makeCameraPose(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir);
//! retrieves a window by its name. If no window with such name, then it creates new.
CV_EXPORTS Viz3d get(const String &window_name);
@ -101,10 +101,7 @@ namespace cv
///////////////////////////////////////////////////////////////////////////////////////////////
/// Read/write poses and trajectories
CV_EXPORTS bool readPose(const String& file, Affine3f& pose, const String& tag = "pose");
CV_EXPORTS bool readPose(const String& file, Affine3d& pose, const String& tag = "pose");
CV_EXPORTS void writePose(const String& file, const Affine3f& pose, const String& tag = "pose");
CV_EXPORTS void writePose(const String& file, const Affine3d& pose, const String& tag = "pose");
CV_EXPORTS void writeTrajectory(const std::vector<Affine3f>& traj, const String& files_format = "pose%05d.xml", int start = 0, const String& tag = "pose");

@ -70,19 +70,19 @@ namespace cv
Viz3d& operator=(const Viz3d&);
~Viz3d();
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
void removeWidget(const String &id);
Widget getWidget(const String &id) const;
void removeAllWidgets();
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const;
void setCamera(const Camera &camera);
Camera getCamera() const;
Affine3f getViewerPose();
void setViewerPose(const Affine3f &pose);
Affine3d getViewerPose();
void setViewerPose(const Affine3d &pose);
void resetCameraViewpoint(const String &id);
void resetCamera();

@ -111,9 +111,9 @@ namespace cv
public:
Widget3D() {}
void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose);
Affine3f getPose() const;
void setPose(const Affine3d &pose);
void updatePose(const Affine3d &pose);
Affine3d getPose() const;
void setColor(const Color &color);
@ -264,21 +264,22 @@ namespace cv
//! Displays trajectory of the given path either by coordinate frames or polyline
WTrajectory(const std::vector<Affine3f> &path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white());
WTrajectory(const std::vector<Affine3d> &path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white());
};
class CV_EXPORTS WTrajectoryFrustums : public Widget3D
{
public:
//! Displays trajectory of the given path by frustums
WTrajectoryFrustums(const std::vector<Affine3f> &path, const Matx33f &K, float scale = 1.f, const Color &color = Color::white());
WTrajectoryFrustums(const std::vector<Affine3d> &path, const Matx33f &K, float scale = 1.f, const Color &color = Color::white());
//! Displays trajectory of the given path by frustums
WTrajectoryFrustums(const std::vector<Affine3f> &path, const Vec2f &fov, float scale = 1.f, const Color &color = Color::white());
WTrajectoryFrustums(const std::vector<Affine3d> &path, const Vec2f &fov, float scale = 1.f, const Color &color = Color::white());
};
class CV_EXPORTS WTrajectorySpheres: public Widget3D
{
public:
WTrajectorySpheres(const std::vector<Affine3f> &path, float line_length = 0.05f, float init_sphere_radius = 0.021f,
WTrajectorySpheres(const std::vector<Affine3d> &path, float line_length = 0.05f, float init_sphere_radius = 0.021f,
float sphere_radius = 0.007f, const Color &line_color = Color::white(), const Color &sphere_color = Color::white());
};
@ -300,9 +301,9 @@ namespace cv
WCloudCollection();
//! 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 Affine3d &pose = Affine3d::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 Affine3d &pose = Affine3d::Identity());
};
class CV_EXPORTS WCloudNormals : public Widget3D

@ -250,7 +250,7 @@ cv::viz::WCloudCollection::WCloudCollection()
WidgetAccessor::setProp(*this, actor);
}
void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors, const Affine3f &pose)
void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors, const Affine3d &pose)
{
Mat cloud = _cloud.getMat();
Mat colors = _colors.getMat();
@ -292,7 +292,7 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
CloudCollectionUtils::createMapper(actor, transform_filter->GetOutput());
}
void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color, const Affine3f &pose)
void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color, const Affine3d &pose)
{
Mat cloud = _cloud.getMat();
CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4);

@ -1182,7 +1182,7 @@ namespace cv { namespace viz { namespace
{
struct TrajectoryUtils
{
static void applyPath(vtkSmartPointer<vtkPolyData> poly_data, vtkSmartPointer<vtkAppendPolyData> append_filter, const std::vector<Affine3f> &path)
static void applyPath(vtkSmartPointer<vtkPolyData> poly_data, vtkSmartPointer<vtkAppendPolyData> append_filter, const std::vector<Affine3d> &path)
{
vtkIdType nr_points = path.size();
@ -1213,7 +1213,105 @@ namespace cv { namespace viz { namespace
};
}}}
cv::viz::WTrajectory::WTrajectory(const std::vector<Affine3f> &path, int display_mode, float scale, const Color &color)
cv::viz::WTrajectory::WTrajectory(const std::vector<Affine3f> &_path, int display_mode, float scale, const Color &color)
{
std::vector<Affine3d> path(_path.begin(), _path.end());
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
// Bitwise and with 3 in order to limit the domain to 2 bits
if ((~display_mode & 3) ^ WTrajectory::PATH)
{
// Create a poly line along the path
vtkIdType nr_points = path.size();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->SetDataTypeToFloat();
points->SetNumberOfPoints(nr_points);
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
polyLine->GetPointIds()->SetNumberOfIds(nr_points);
Vec3f *data_beg = vtkpoints_data<float>(points);
for (vtkIdType i = 0; i < nr_points; ++i)
{
Vec3f cam_pose = path[i].translation();
*data_beg++ = cam_pose;
polyLine->GetPointIds()->SetId(i,i);
}
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell(polyLine);
polyData->SetPoints(points);
polyData->SetLines(cells);
// Set the color for polyData
vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetNumberOfTuples(nr_points);
colors->FillComponent(0, color[2]);
colors->FillComponent(1, color[1]);
colors->FillComponent(2, color[0]);
polyData->GetPointData()->SetScalars(colors);
#if VTK_MAJOR_VERSION <= 5
appendFilter->AddInputConnection(polyData->GetProducerPort());
#else
appendFilter->AddInputData(polyData);
#endif
}
if ((~display_mode & 3) ^ WTrajectory::FRAMES)
{
// Create frames and transform along the path
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
axes->SetOrigin(0, 0, 0);
axes->SetScaleFactor(scale);
vtkSmartPointer<vtkUnsignedCharArray> axes_colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
axes_colors->SetNumberOfComponents(3);
axes_colors->InsertNextTuple3(255,0,0);
axes_colors->InsertNextTuple3(255,0,0);
axes_colors->InsertNextTuple3(0,255,0);
axes_colors->InsertNextTuple3(0,255,0);
axes_colors->InsertNextTuple3(0,0,255);
axes_colors->InsertNextTuple3(0,0,255);
vtkSmartPointer<vtkPolyData> axes_data = axes->GetOutput();
#if VTK_MAJOR_VERSION <= 5
axes_data->Update();
#else
axes->Update();
#endif
axes_data->GetPointData()->SetScalars(axes_colors);
vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::New();
#if VTK_MAJOR_VERSION <= 5
axes_tubes->SetInput(axes_data);
#else
axes_tubes->SetInputData(axes_data);
#endif
axes_tubes->SetRadius(axes->GetScaleFactor() / 50.0);
axes_tubes->SetNumberOfSides(6);
axes_tubes->Update();
TrajectoryUtils::applyPath(axes_tubes->GetOutput(), appendFilter, path);
}
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetScalarModeToUsePointData();
mapper->SetInputConnection(appendFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
WidgetAccessor::setProp(*this, actor);
}
cv::viz::WTrajectory::WTrajectory(const std::vector<Affine3d> &path, int display_mode, float scale, const Color &color)
{
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
@ -1318,7 +1416,7 @@ template<> cv::viz::WTrajectory cv::viz::Widget::cast<cv::viz::WTrajectory>()
///////////////////////////////////////////////////////////////////////////////////////////////
/// WTrajectoryFrustums widget implementation
cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(const std::vector<Affine3f> &path, const Matx33f &K, float scale, const Color &color)
cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(const std::vector<Affine3d> &path, const Matx33f &K, float scale, const Color &color)
{
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
float f_x = K(0,0);
@ -1362,7 +1460,7 @@ cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(const std::vector<Affine3f> &p
setColor(color);
}
cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(const std::vector<Affine3f> &path, const Vec2f &fov, float scale, const Color &color)
cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(const std::vector<Affine3d> &path, const Vec2f &fov, float scale, const Color &color)
{
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
@ -1411,7 +1509,7 @@ template<> cv::viz::WTrajectoryFrustums cv::viz::Widget::cast<cv::viz::WTrajecto
///////////////////////////////////////////////////////////////////////////////////////////////
/// WTrajectorySpheres widget implementation
cv::viz::WTrajectorySpheres::WTrajectorySpheres(const std::vector<Affine3f> &path, float line_length, float init_sphere_radius, float sphere_radius,
cv::viz::WTrajectorySpheres::WTrajectorySpheres(const std::vector<Affine3d> &path, float line_length, float init_sphere_radius, float sphere_radius,
const Color &line_color, const Color &sphere_color)
{
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
@ -1469,8 +1567,8 @@ cv::viz::WTrajectorySpheres::WTrajectorySpheres(const std::vector<Affine3f> &pat
}
Affine3f relativeAffine = path[i].inv() * path[i-1];
Vec3f v = path[i].rotation() * relativeAffine.translation();
Affine3d relativeAffine = path[i].inv() * path[i-1];
Vec3d v = path[i].rotation() * relativeAffine.translation();
v = normalize(v) * line_length;
vtkSmartPointer<vtkLineSource> line_source = vtkSmartPointer<vtkLineSource>::New();

@ -108,18 +108,18 @@ void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* c
void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie)
{ impl_->registerMouseCallback(callback, cookie); }
void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); }
void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3d &pose) { impl_->showWidget(id, widget, pose); }
void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); }
cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); }
void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); }
void cv::viz::Viz3d::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); }
cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); }
void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3d &pose) { impl_->setWidgetPose(id, pose); }
void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3d &pose) { impl_->updateWidgetPose(id, pose); }
cv::Affine3d cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); }
void cv::viz::Viz3d::setCamera(const Camera &camera) { impl_->setCamera(camera); }
cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); }
void cv::viz::Viz3d::setViewerPose(const Affine3f &pose) { impl_->setViewerPose(pose); }
cv::Affine3f cv::viz::Viz3d::getViewerPose() { return impl_->getViewerPose(); }
void cv::viz::Viz3d::setViewerPose(const Affine3d &pose) { impl_->setViewerPose(pose); }
cv::Affine3d 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(); }

@ -45,21 +45,21 @@
#include "precomp.hpp"
cv::Affine3f cv::viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin)
cv::Affine3d cv::viz::makeTransformToGlobal(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin)
{
Affine3f::Mat3 R(axis_x[0], axis_y[0], axis_z[0],
Affine3d::Mat3 R(axis_x[0], axis_y[0], axis_z[0],
axis_x[1], axis_y[1], axis_z[1],
axis_x[2], axis_y[2], axis_z[2]);
return Affine3f(R, origin);
return Affine3d(R, origin);
}
cv::Affine3f cv::viz::makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir)
cv::Affine3d cv::viz::makeCameraPose(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir)
{
// Compute the transformation matrix for drawing the camera frame in a scene
Vec3f n = normalize(focal_point - position);
Vec3f u = normalize(y_dir.cross(n));
Vec3f v = n.cross(u);
Vec3d n = normalize(focal_point - position);
Vec3d u = normalize(y_dir.cross(n));
Vec3d v = n.cross(u);
return makeTransformToGlobal(u, v, n, position);
}
@ -240,27 +240,29 @@ cv::Mat cv::viz::readCloud(const String& file, OutputArray colors, OutputArray n
///////////////////////////////////////////////////////////////////////////////////////////////
/// Read/write poses and trajectories
namespace cv { namespace viz { namespace impl
bool cv::viz::readPose(const String& file, Affine3d& pose, const String& tag)
{
template <typename _Tp>
bool readPose(const String& file, Affine3<_Tp>& pose, const String& tag)
{
FileStorage fs(file, FileStorage::READ);
if (!fs.isOpened())
return false;
FileStorage fs(file, FileStorage::READ);
if (!fs.isOpened())
return false;
Mat hdr(pose.matrix, false);
fs[tag] >> hdr;
return !hdr.empty() && hdr.depth() == DataDepth<_Tp>::value;
}
Mat hdr(pose.matrix, false);
fs[tag] >> hdr;
if (hdr.empty() || hdr.cols != pose.matrix.cols || hdr.rows != pose.matrix.rows)
return false;
template <typename _Tp>
void writePose(const String& file, const Affine3<_Tp>& pose, const String& tag)
{
FileStorage fs(file, FileStorage::WRITE);
fs << tag << Mat(pose.matrix, false);
}
hdr.convertTo(pose.matrix, CV_64F);
return true;
}
void cv::viz::writePose(const String& file, const Affine3d& pose, const String& tag)
{
FileStorage fs(file, FileStorage::WRITE);
fs << tag << Mat(pose.matrix, false);
}
namespace cv { namespace viz { namespace impl
{
template <typename _Tp>
void readTrajectory(std::vector<Affine3<_Tp> >& traj, const String& files_format, int start, int end, const String& tag)
{
@ -271,8 +273,8 @@ namespace cv { namespace viz { namespace impl
for(int i = start; i < end; ++i)
{
Affine3<_Tp> affine;
bool ok = readPose(cv::format(files_format.c_str(), i),affine, tag);
Affine3d affine;
bool ok = readPose(cv::format(files_format.c_str(), i), affine, tag);
if (!ok)
break;
@ -290,11 +292,7 @@ namespace cv { namespace viz { namespace impl
}}}
bool cv::viz::readPose(const String& file, Affine3f& pose, const String& tag) { return impl::readPose(file, pose, tag); }
bool cv::viz::readPose(const String& file, Affine3d& pose, const String& tag) { return impl::readPose(file, pose, tag); }
void cv::viz::writePose(const String& file, const Affine3f& pose, const String& tag) { impl::writePose(file, pose, tag); }
void cv::viz::writePose(const String& file, const Affine3d& pose, const String& tag) { impl::writePose(file, pose, tag); }
void cv::viz::readTrajectory(std::vector<Affine3f>& traj, const String& files_format, int start, int end, const String& tag)
{ impl::readTrajectory(traj, files_format, start, end, tag); }

@ -120,7 +120,7 @@ cv::viz::Viz3d::VizImpl::~VizImpl()
}
/////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3f &pose)
void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3d &pose)
{
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
bool exists = wam_itr != widget_actor_map_->end();
@ -172,7 +172,7 @@ cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const
}
/////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &pose)
void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3d &pose)
{
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
bool exists = wam_itr != widget_actor_map_->end();
@ -187,7 +187,7 @@ void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &po
}
/////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f &pose)
void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3d &pose)
{
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
bool exists = wam_itr != widget_actor_map_->end();
@ -202,8 +202,8 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f
setWidgetPose(id, pose);
return ;
}
Matx44f matrix_cv = convertToMatx(matrix);
Affine3f updated_pose = pose * Affine3f(matrix_cv);
Matx44d matrix_cv = convertToMatx(matrix);
Affine3d updated_pose = pose * Affine3d(matrix_cv);
matrix = convertToVtkMatrix(updated_pose.matrix);
actor->SetUserMatrix(matrix);
@ -211,7 +211,7 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f
}
/////////////////////////////////////////////////////////////////////////////////////////////
cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const
cv::Affine3d cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const
{
WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id);
bool exists = wam_itr != widget_actor_map_->end();
@ -221,8 +221,8 @@ cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const
CV_Assert("Widget is not 3D." && actor);
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
Matx44f matrix_cv = convertToMatx(matrix);
return Affine3f(matrix_cv);
Matx44d matrix_cv = convertToMatx(matrix);
return Affine3d(matrix_cv);
}
/////////////////////////////////////////////////////////////////////////////////////////////
@ -350,32 +350,32 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
}
/////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3d &pose)
{
vtkCamera& camera = *renderer_->GetActiveCamera();
// Position = extrinsic translation
cv::Vec3f pos_vec = pose.translation();
cv::Vec3d pos_vec = pose.translation();
// Rotate the view vector
cv::Matx33f rotation = pose.rotation();
cv::Vec3f y_axis(0.f, 1.f, 0.f);
cv::Vec3f up_vec(rotation * y_axis);
cv::Matx33d rotation = pose.rotation();
cv::Vec3d y_axis(0.0, 1.0, 0.0);
cv::Vec3d up_vec(rotation * y_axis);
// Compute the new focal point
cv::Vec3f z_axis(0.f, 0.f, 1.f);
cv::Vec3f focal_vec = pos_vec + rotation * z_axis;
cv::Vec3d z_axis(0.0, 0.0, 1.0);
cv::Vec3d focal_vec = pos_vec + rotation * z_axis;
camera.SetPosition(pos_vec[0], pos_vec[1], pos_vec[2]);
camera.SetFocalPoint(focal_vec[0], focal_vec[1], focal_vec[2]);
camera.SetViewUp(up_vec[0], up_vec[1], up_vec[2]);
camera.SetPosition(pos_vec.val);
camera.SetFocalPoint(focal_vec.val);
camera.SetViewUp(up_vec.val);
renderer_->ResetCameraClippingRange();
renderer_->Render();
}
/////////////////////////////////////////////////////////////////////////////////////////////
cv::Affine3f cv::viz::Viz3d::VizImpl::getViewerPose()
cv::Affine3d cv::viz::Viz3d::VizImpl::getViewerPose()
{
vtkCamera& camera = *renderer_->GetActiveCamera();
@ -400,7 +400,7 @@ cv::Affine3f cv::viz::Viz3d::VizImpl::getViewerPose()
R(2, 1) = y_axis[2];
R(2, 2) = z_axis[2];
return cv::Affine3f(R, pos);
return cv::Affine3d(R, pos);
}
/////////////////////////////////////////////////////////////////////////////////////////////

@ -57,14 +57,14 @@ public:
VizImpl(const String &name);
virtual ~VizImpl();
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
void removeWidget(const String &id);
Widget getWidget(const String &id) const;
void removeAllWidgets();
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const;
void setDesiredUpdateRate(double rate);
double getDesiredUpdateRate();
@ -95,8 +95,8 @@ public:
void resetCameraViewpoint(const String& id);
void resetCamera();
void setViewerPose(const Affine3f &pose);
Affine3f getViewerPose();
void setViewerPose(const Affine3d &pose);
Affine3d getViewerPose();
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
@ -280,31 +280,6 @@ namespace cv
}
};
struct ApplyAffine
{
const Affine3f& affine_;
ApplyAffine(const Affine3f& affine) : affine_(affine) {}
template<typename _Tp> Point3_<_Tp> operator()(const Point3_<_Tp>& p) const { return affine_ * p; }
template<typename _Tp> Vec<_Tp, 3> operator()(const Vec<_Tp, 3>& v) const
{
const float* m = affine_.matrix.val;
Vec<_Tp, 3> result;
result[0] = (_Tp)(m[0] * v[0] + m[1] * v[1] + m[ 2] * v[2] + m[ 3]);
result[1] = (_Tp)(m[4] * v[0] + m[5] * v[1] + m[ 6] * v[2] + m[ 7]);
result[2] = (_Tp)(m[8] * v[0] + m[9] * v[1] + m[10] * v[2] + m[11]);
return result;
}
private:
ApplyAffine(const ApplyAffine&);
ApplyAffine& operator=(const ApplyAffine&);
};
struct ConvertToVtkImage
{
struct Impl

@ -239,7 +239,7 @@ void cv::viz::WidgetAccessor::setProp(Widget& widget, vtkSmartPointer<vtkProp> p
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget3D implementation
void cv::viz::Widget3D::setPose(const Affine3f &pose)
void cv::viz::Widget3D::setPose(const Affine3d &pose)
{
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor);
@ -249,7 +249,7 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose)
actor->Modified();
}
void cv::viz::Widget3D::updatePose(const Affine3f &pose)
void cv::viz::Widget3D::updatePose(const Affine3d &pose)
{
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor);
@ -261,18 +261,18 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose)
return;
}
Affine3f updated_pose = pose * Affine3f(convertToMatx(matrix));
Affine3d updated_pose = pose * Affine3d(convertToMatx(matrix));
matrix = convertToVtkMatrix(updated_pose.matrix);
actor->SetUserMatrix(matrix);
actor->Modified();
}
cv::Affine3f cv::viz::Widget3D::getPose() const
cv::Affine3d cv::viz::Widget3D::getPose() const
{
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
CV_Assert("Widget is not 3D." && actor);
return Affine3f(convertToMatx(actor->GetUserMatrix()));
return Affine3d(convertToMatx(actor->GetUserMatrix()));
}
void cv::viz::Widget3D::setColor(const Color &color)

@ -12,34 +12,34 @@ void tutorial2()
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// Add line to represent (1,1,1) axis
viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
viz::WLine axis(Point3f(-1.0, -1.0, -1.0), Point3d(1.0, 1.0, 1.0));
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis);
/// Construct a cube widget
viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
viz::WCube cube_widget(Point3d(0.5, 0.5, 0.0), Point3d(0.0, 0.0, -0.5), true, viz::Color::blue());
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
/// Display widget (update if already displayed)
myWindow.showWidget("Cube Widget", cube_widget);
/// Rodrigues vector
Mat rot_vec = Mat::zeros(1,3,CV_32F);
float translation_phase = 0.0, translation = 0.0;
Vec3d rot_vec = Vec3d::all(0);
double translation_phase = 0.0, translation = 0.0;
while(!myWindow.wasStopped())
{
/* Rotation using rodrigues */
/// Rotate around (1,1,1)
rot_vec.at<float>(0,0) += CV_PI * 0.01f;
rot_vec.at<float>(0,1) += CV_PI * 0.01f;
rot_vec.at<float>(0,2) += CV_PI * 0.01f;
rot_vec[0] += CV_PI * 0.01;
rot_vec[1] += CV_PI * 0.01;
rot_vec[2] += CV_PI * 0.01;
/// Shift on (1,1,1)
translation_phase += CV_PI * 0.01f;
translation_phase += CV_PI * 0.01;
translation = sin(translation_phase);
/// Construct pose
Affine3f pose(rot_vec, Vec3f(translation, translation, translation));
Affine3d pose(rot_vec, Vec3d(translation, translation, translation));
myWindow.setWidgetPose("Cube Widget", pose);

@ -15,23 +15,23 @@ void tutorial3(bool camera_pov)
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
/// Let's assume camera has the following properties
Point3f cam_pos(3.f, 3.f, 3.f), cam_focal_point(3.f, 3.f, 2.f), cam_y_dir(-1.f, 0.f, 0.f);
Point3d cam_pos(3.0, 3.0, 3.0), cam_focal_point(3.0, 3.0, 2.0), cam_y_dir(-1.0, 0.0, 0.0);
/// We can get the pose of the cam using makeCameraPose
Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
Affine3d cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
/// We can get the transformation matrix from camera coordinate system to global using
/// - makeTransformToGlobal. We need the axes of the camera
Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.f, -1.f, 0.f), Vec3f(-1.f, 0.f, 0.f), Vec3f(0.f, 0.f, -1.f), cam_pos);
Affine3d transform = viz::makeTransformToGlobal(Vec3d(0.0, -1.0, 0.0), Vec3d(-1.0, 0.0, 0.0), Vec3d(0.0, 0.0, -1.0), cam_pos);
/// Create a cloud widget.
Mat dragon_cloud = viz::readCloud(get_dragon_ply_file_path());
viz::WCloud cloud_widget(dragon_cloud, viz::Color::green());
/// Pose of the widget in camera frame
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.f, 0.f, 3.f));
Affine3d cloud_pose = Affine3d().translate(Vec3d(0.0, 0.0, 3.0));
/// Pose of the widget in global frame
Affine3f cloud_pose_global = transform * cloud_pose;
Affine3d cloud_pose_global = transform * cloud_pose;
/// Visualize camera frame
if (!camera_pov)

@ -67,7 +67,7 @@ TEST(Viz_viz3d, develop)
//viz.showWidget("h", cv::viz::Widget::fromPlyFile("d:/horse-red.ply"));
//viz.showWidget("a", cv::viz::WArrow(cv::Point3f(0,0,0), cv::Point3f(1,1,1)));
std::vector<cv::Affine3f> gt, es;
std::vector<cv::Affine3d> gt, es;
cv::viz::readTrajectory(gt, "d:/Datasets/trajs/gt%05d.xml");
cv::viz::readTrajectory(es, "d:/Datasets/trajs/es%05d.xml");

Loading…
Cancel
Save