Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
061c28cd
Commit
061c28cd
authored
Jul 08, 2013
by
Anatoly Baksheev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14 from ozantonkal/implementing_widgets
Implementing widgets
parents
653eda45
b50d7779
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
451 additions
and
30 deletions
+451
-30
viz3d.hpp
modules/viz/include/opencv2/viz/viz3d.hpp
+4
-0
widgets.hpp
modules/viz/include/opencv2/viz/widgets.hpp
+18
-1
viz3d_impl.hpp
modules/viz/src/q/viz3d_impl.hpp
+4
-0
simple_widgets.cpp
modules/viz/src/simple_widgets.cpp
+318
-13
viz3d.cpp
modules/viz/src/viz3d.cpp
+15
-0
viz3d_impl.cpp
modules/viz/src/viz3d_impl.cpp
+63
-4
widget.cpp
modules/viz/src/widget.cpp
+4
-4
test_viz3d.cpp
modules/viz/test/test_viz3d.cpp
+25
-8
No files found.
modules/viz/include/opencv2/viz/viz3d.hpp
View file @
061c28cd
...
...
@@ -48,6 +48,10 @@ namespace temp_viz
void
showWidget
(
const
String
&
id
,
const
Widget
&
widget
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
bool
removeWidget
(
const
String
&
id
);
bool
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
bool
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
Affine3f
getWidgetPose
(
const
String
&
id
)
const
;
private
:
Viz3d
(
const
Viz3d
&
);
Viz3d
&
operator
=
(
const
Viz3d
&
);
...
...
modules/viz/include/opencv2/viz/widgets.hpp
View file @
061c28cd
...
...
@@ -81,7 +81,7 @@ namespace temp_viz
class
CV_EXPORTS
CubeWidget
:
public
Widget
{
public
:
CubeWidget
(
const
Point3f
&
pt_min
,
const
Point3f
&
pt_max
,
const
Color
&
color
=
Color
::
white
());
CubeWidget
(
const
Point3f
&
pt_min
,
const
Point3f
&
pt_max
,
bool
wire_frame
=
true
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
CoordinateSystemWidget
:
public
Widget
...
...
@@ -97,4 +97,21 @@ namespace temp_viz
// TODO Overload setColor method, and hide setPose, updatePose, getPose methods
};
class
CV_EXPORTS
CloudWidget
:
public
Widget
{
public
:
CloudWidget
(
InputArray
_cloud
,
InputArray
_colors
);
CloudWidget
(
InputArray
_cloud
,
const
Color
&
color
=
Color
::
white
());
private
:
struct
CreateCloudWidget
;
};
class
CV_EXPORTS
CloudNormalsWidget
:
public
Widget
{
public
:
CloudNormalsWidget
(
InputArray
_cloud
,
InputArray
_normals
,
int
level
=
100
,
float
scale
=
0.02
f
,
const
Color
&
color
=
Color
::
white
());
private
:
struct
ApplyCloudNormals
;
};
}
modules/viz/src/q/viz3d_impl.hpp
View file @
061c28cd
...
...
@@ -202,6 +202,10 @@ public:
void
showWidget
(
const
String
&
id
,
const
Widget
&
widget
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
bool
removeWidget
(
const
String
&
id
);
bool
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
bool
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
Affine3f
getWidgetPose
(
const
String
&
id
)
const
;
void
all_data
();
private
:
...
...
modules/viz/src/simple_widgets.cpp
View file @
061c28cd
#include "precomp.hpp"
namespace
temp_viz
{
template
<
typename
_Tp
>
Vec
<
_Tp
,
3
>*
vtkpoints_data
(
vtkSmartPointer
<
vtkPoints
>&
points
);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// line widget implementation
temp_viz
::
LineWidget
::
LineWidget
(
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
const
Color
&
color
)
...
...
@@ -12,7 +17,7 @@ temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const C
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
line
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -20,13 +25,13 @@ temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const C
void
temp_viz
::
LineWidget
::
setLineWidth
(
float
line_width
)
{
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
GetProperty
()
->
SetLineWidth
(
line_width
);
}
float
temp_viz
::
LineWidget
::
getLineWidth
()
{
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
return
actor
->
GetProperty
()
->
GetLineWidth
();
}
...
...
@@ -43,7 +48,7 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
plane
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
actor
->
SetScale
(
size
);
...
...
@@ -64,7 +69,7 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
plane
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
actor
->
SetScale
(
size
);
...
...
@@ -87,7 +92,7 @@ temp_viz::SphereWidget::SphereWidget(const cv::Point3f ¢er, float radius, in
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
sphere
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -149,7 +154,7 @@ temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
transformPD
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -178,7 +183,7 @@ temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius,
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tf
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -202,7 +207,7 @@ temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tuber
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -211,7 +216,7 @@ temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3
///////////////////////////////////////////////////////////////////////////////////////////////
/// cylinder widget implementation
temp_viz
::
CubeWidget
::
CubeWidget
(
const
Point3f
&
pt_min
,
const
Point3f
&
pt_max
,
const
Color
&
color
)
temp_viz
::
CubeWidget
::
CubeWidget
(
const
Point3f
&
pt_min
,
const
Point3f
&
pt_max
,
bool
wire_frame
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkCubeSource
>
cube
=
vtkSmartPointer
<
vtkCubeSource
>::
New
();
cube
->
SetBounds
(
pt_min
.
x
,
pt_max
.
x
,
pt_min
.
y
,
pt_max
.
y
,
pt_min
.
z
,
pt_max
.
z
);
...
...
@@ -219,9 +224,12 @@ temp_viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, c
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
cube
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
if
(
wire_frame
)
actor
->
GetProperty
()
->
SetRepresentationToWireframe
();
setColor
(
color
);
}
...
...
@@ -256,7 +264,7 @@ temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Aff
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetInput
(
axes_tubes
->
GetOutput
());
vtk
SmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
LODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
cv
::
Vec3d
t
=
affine
.
translation
();
...
...
@@ -274,9 +282,12 @@ temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Aff
actor
->
RotateWXYZ
(
r_angle
*
180
/
CV_PI
,
rvec
[
0
],
rvec
[
1
],
rvec
[
2
]);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// text widget implementation
temp_viz
::
TextWidget
::
TextWidget
(
const
String
&
text
,
const
Point2i
&
pos
,
int
font_size
,
const
Color
&
color
)
:
Widget
(
true
)
{
vtk
SmartPointer
<
vtkTextActor
>
actor
=
vtkTextActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtk
TextActor
*
actor
=
vtkTextActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetPosition
(
pos
.
x
,
pos
.
y
);
actor
->
SetInput
(
text
.
c_str
());
...
...
@@ -289,3 +300,296 @@ temp_viz::TextWidget::TextWidget(const String &text, const Point2i &pos, int fon
Color
c
=
vtkcolor
(
color
);
tprop
->
SetColor
(
c
.
val
);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// point cloud widget implementation
struct
temp_viz
::
CloudWidget
::
CreateCloudWidget
{
static
inline
vtkSmartPointer
<
vtkPolyData
>
create
(
const
Mat
&
cloud
,
vtkIdType
&
nr_points
)
{
vtkSmartPointer
<
vtkPolyData
>
polydata
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkCellArray
>
vertices
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
polydata
->
SetVerts
(
vertices
);
vtkSmartPointer
<
vtkPoints
>
points
=
polydata
->
GetPoints
();
vtkSmartPointer
<
vtkIdTypeArray
>
initcells
;
nr_points
=
cloud
.
total
();
points
=
polydata
->
GetPoints
();
if
(
!
points
)
{
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
if
(
cloud
.
depth
()
==
CV_32F
)
points
->
SetDataTypeToFloat
();
else
if
(
cloud
.
depth
()
==
CV_64F
)
points
->
SetDataTypeToDouble
();
polydata
->
SetPoints
(
points
);
}
points
->
SetNumberOfPoints
(
nr_points
);
if
(
cloud
.
depth
()
==
CV_32F
)
{
// Get a pointer to the beginning of the data array
Vec3f
*
data_beg
=
vtkpoints_data
<
float
>
(
points
);
Vec3f
*
data_end
=
NanFilter
::
copy
(
cloud
,
data_beg
,
cloud
);
nr_points
=
data_end
-
data_beg
;
}
else
if
(
cloud
.
depth
()
==
CV_64F
)
{
// Get a pointer to the beginning of the data array
Vec3d
*
data_beg
=
vtkpoints_data
<
double
>
(
points
);
Vec3d
*
data_end
=
NanFilter
::
copy
(
cloud
,
data_beg
,
cloud
);
nr_points
=
data_end
-
data_beg
;
}
points
->
SetNumberOfPoints
(
nr_points
);
// Update cells
vtkSmartPointer
<
vtkIdTypeArray
>
cells
=
vertices
->
GetData
();
// If no init cells and cells has not been initialized...
if
(
!
cells
)
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If we have less values then we need to recreate the array
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
{
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If init cells is given, and there's enough data in it, use it
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
{
cells
->
DeepCopy
(
initcells
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
}
else
{
// If the number of tuples is still too small, we need to recreate the array
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
vtkIdType
*
cell
=
cells
->
GetPointer
(
0
);
// Fill it with 1s
std
::
fill_n
(
cell
,
nr_points
*
2
,
1
);
cell
++
;
for
(
vtkIdType
i
=
0
;
i
<
nr_points
;
++
i
,
cell
+=
2
)
*
cell
=
i
;
// Save the results in initcells
initcells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
initcells
->
DeepCopy
(
cells
);
}
}
else
{
// The assumption here is that the current set of cells has more data than needed
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
}
// Set the cells and the vertices
vertices
->
SetCells
(
nr_points
,
cells
);
return
polydata
;
}
};
temp_viz
::
CloudWidget
::
CloudWidget
(
InputArray
_cloud
,
InputArray
_colors
)
{
Mat
cloud
=
_cloud
.
getMat
();
Mat
colors
=
_colors
.
getMat
();
CV_Assert
(
cloud
.
type
()
==
CV_32FC3
||
cloud
.
type
()
==
CV_64FC3
||
cloud
.
type
()
==
CV_32FC4
||
cloud
.
type
()
==
CV_64FC4
);
CV_Assert
(
colors
.
type
()
==
CV_8UC3
&&
cloud
.
size
()
==
colors
.
size
());
vtkLODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtkIdType
nr_points
;
vtkSmartPointer
<
vtkPolyData
>
polydata
=
CreateCloudWidget
::
create
(
cloud
,
nr_points
);
// Filter colors
Vec3b
*
colors_data
=
new
Vec3b
[
nr_points
];
NanFilter
::
copy
(
colors
,
colors_data
,
cloud
);
vtkSmartPointer
<
vtkUnsignedCharArray
>
scalars
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
scalars
->
SetNumberOfComponents
(
3
);
scalars
->
SetNumberOfTuples
(
nr_points
);
scalars
->
SetArray
(
colors_data
->
val
,
3
*
nr_points
,
0
);
// Assign the colors
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polydata
);
cv
::
Vec3d
minmax
(
scalars
->
GetRange
());
mapper
->
SetScalarRange
(
minmax
.
val
);
mapper
->
SetScalarModeToUsePointData
();
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOn
();
mapper
->
ImmediateModeRenderingOff
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
}
temp_viz
::
CloudWidget
::
CloudWidget
(
InputArray
_cloud
,
const
Color
&
color
)
{
Mat
cloud
=
_cloud
.
getMat
();
CV_Assert
(
cloud
.
type
()
==
CV_32FC3
||
cloud
.
type
()
==
CV_64FC3
||
cloud
.
type
()
==
CV_32FC4
||
cloud
.
type
()
==
CV_64FC4
);
vtkLODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
vtkIdType
nr_points
;
vtkSmartPointer
<
vtkPolyData
>
polydata
=
CreateCloudWidget
::
create
(
cloud
,
nr_points
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polydata
);
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOff
();
mapper
->
ImmediateModeRenderingOff
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// cloud normals widget implementation
struct
temp_viz
::
CloudNormalsWidget
::
ApplyCloudNormals
{
template
<
typename
_Tp
>
struct
Impl
{
static
vtkSmartPointer
<
vtkCellArray
>
applyOrganized
(
const
cv
::
Mat
&
cloud
,
const
cv
::
Mat
&
normals
,
int
level
,
float
scale
,
_Tp
*&
pts
,
vtkIdType
&
nr_normals
)
{
vtkIdType
point_step
=
static_cast
<
vtkIdType
>
(
sqrt
(
double
(
level
)));
nr_normals
=
(
static_cast
<
vtkIdType
>
((
cloud
.
cols
-
1
)
/
point_step
)
+
1
)
*
(
static_cast
<
vtkIdType
>
((
cloud
.
rows
-
1
)
/
point_step
)
+
1
);
vtkSmartPointer
<
vtkCellArray
>
lines
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
pts
=
new
_Tp
[
2
*
nr_normals
*
3
];
int
cch
=
cloud
.
channels
();
vtkIdType
cell_count
=
0
;
for
(
vtkIdType
y
=
0
;
y
<
cloud
.
rows
;
y
+=
point_step
)
{
const
_Tp
*
prow
=
cloud
.
ptr
<
_Tp
>
(
y
);
const
_Tp
*
nrow
=
normals
.
ptr
<
_Tp
>
(
y
);
for
(
vtkIdType
x
=
0
;
x
<
cloud
.
cols
;
x
+=
point_step
*
cch
)
{
pts
[
2
*
cell_count
*
3
+
0
]
=
prow
[
x
];
pts
[
2
*
cell_count
*
3
+
1
]
=
prow
[
x
+
1
];
pts
[
2
*
cell_count
*
3
+
2
]
=
prow
[
x
+
2
];
pts
[
2
*
cell_count
*
3
+
3
]
=
prow
[
x
]
+
nrow
[
x
]
*
scale
;
pts
[
2
*
cell_count
*
3
+
4
]
=
prow
[
x
+
1
]
+
nrow
[
x
+
1
]
*
scale
;
pts
[
2
*
cell_count
*
3
+
5
]
=
prow
[
x
+
2
]
+
nrow
[
x
+
2
]
*
scale
;
lines
->
InsertNextCell
(
2
);
lines
->
InsertCellPoint
(
2
*
cell_count
);
lines
->
InsertCellPoint
(
2
*
cell_count
+
1
);
cell_count
++
;
}
}
return
lines
;
}
static
vtkSmartPointer
<
vtkCellArray
>
applyUnorganized
(
const
cv
::
Mat
&
cloud
,
const
cv
::
Mat
&
normals
,
int
level
,
float
scale
,
_Tp
*&
pts
,
vtkIdType
&
nr_normals
)
{
vtkSmartPointer
<
vtkCellArray
>
lines
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
nr_normals
=
(
cloud
.
size
().
area
()
-
1
)
/
level
+
1
;
pts
=
new
_Tp
[
2
*
nr_normals
*
3
];
int
cch
=
cloud
.
channels
();
const
_Tp
*
p
=
cloud
.
ptr
<
_Tp
>
();
const
_Tp
*
n
=
normals
.
ptr
<
_Tp
>
();
for
(
vtkIdType
i
=
0
,
j
=
0
;
j
<
nr_normals
;
j
++
,
i
=
j
*
level
*
cch
)
{
pts
[
2
*
j
*
3
+
0
]
=
p
[
i
];
pts
[
2
*
j
*
3
+
1
]
=
p
[
i
+
1
];
pts
[
2
*
j
*
3
+
2
]
=
p
[
i
+
2
];
pts
[
2
*
j
*
3
+
3
]
=
p
[
i
]
+
n
[
i
]
*
scale
;
pts
[
2
*
j
*
3
+
4
]
=
p
[
i
+
1
]
+
n
[
i
+
1
]
*
scale
;
pts
[
2
*
j
*
3
+
5
]
=
p
[
i
+
2
]
+
n
[
i
+
2
]
*
scale
;
lines
->
InsertNextCell
(
2
);
lines
->
InsertCellPoint
(
2
*
j
);
lines
->
InsertCellPoint
(
2
*
j
+
1
);
}
return
lines
;
}
};
template
<
typename
_Tp
>
static
inline
vtkSmartPointer
<
vtkCellArray
>
apply
(
const
cv
::
Mat
&
cloud
,
const
cv
::
Mat
&
normals
,
int
level
,
float
scale
,
_Tp
*&
pts
,
vtkIdType
&
nr_normals
)
{
if
(
cloud
.
cols
>
1
&&
cloud
.
rows
>
1
)
return
ApplyCloudNormals
::
Impl
<
_Tp
>::
applyOrganized
(
cloud
,
normals
,
level
,
scale
,
pts
,
nr_normals
);
else
return
ApplyCloudNormals
::
Impl
<
_Tp
>::
applyUnorganized
(
cloud
,
normals
,
level
,
scale
,
pts
,
nr_normals
);
}
};
temp_viz
::
CloudNormalsWidget
::
CloudNormalsWidget
(
InputArray
_cloud
,
InputArray
_normals
,
int
level
,
float
scale
,
const
Color
&
color
)
{
Mat
cloud
=
_cloud
.
getMat
();
Mat
normals
=
_normals
.
getMat
();
CV_Assert
(
cloud
.
type
()
==
CV_32FC3
||
cloud
.
type
()
==
CV_64FC3
||
cloud
.
type
()
==
CV_32FC4
||
cloud
.
type
()
==
CV_64FC4
);
CV_Assert
(
cloud
.
size
()
==
normals
.
size
()
&&
cloud
.
type
()
==
normals
.
type
());
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
vtkSmartPointer
<
vtkCellArray
>
lines
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
vtkIdType
nr_normals
=
0
;
if
(
cloud
.
depth
()
==
CV_32F
)
{
points
->
SetDataTypeToFloat
();
vtkSmartPointer
<
vtkFloatArray
>
data
=
vtkSmartPointer
<
vtkFloatArray
>::
New
();
data
->
SetNumberOfComponents
(
3
);
float
*
pts
=
0
;
lines
=
ApplyCloudNormals
::
apply
(
cloud
,
normals
,
level
,
scale
,
pts
,
nr_normals
);
data
->
SetArray
(
&
pts
[
0
],
2
*
nr_normals
*
3
,
0
);
points
->
SetData
(
data
);
}
else
{
points
->
SetDataTypeToDouble
();
vtkSmartPointer
<
vtkDoubleArray
>
data
=
vtkSmartPointer
<
vtkDoubleArray
>::
New
();
data
->
SetNumberOfComponents
(
3
);
double
*
pts
=
0
;
lines
=
ApplyCloudNormals
::
apply
(
cloud
,
normals
,
level
,
scale
,
pts
,
nr_normals
);
data
->
SetArray
(
&
pts
[
0
],
2
*
nr_normals
*
3
,
0
);
points
->
SetData
(
data
);
}
vtkSmartPointer
<
vtkPolyData
>
polyData
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
polyData
->
SetPoints
(
points
);
polyData
->
SetLines
(
lines
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polyData
);
mapper
->
SetColorModeToMapScalars
();
mapper
->
SetScalarModeToUsePointData
();
vtkLODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
}
\ No newline at end of file
modules/viz/src/viz3d.cpp
View file @
061c28cd
...
...
@@ -88,3 +88,18 @@ bool temp_viz::Viz3d::removeWidget(const String &id)
{
return
impl_
->
removeWidget
(
id
);
}
bool
temp_viz
::
Viz3d
::
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
{
return
impl_
->
setWidgetPose
(
id
,
pose
);
}
bool
temp_viz
::
Viz3d
::
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
{
return
impl_
->
updateWidgetPose
(
id
,
pose
);
}
temp_viz
::
Affine3f
temp_viz
::
Viz3d
::
getWidgetPose
(
const
String
&
id
)
const
{
return
impl_
->
getWidgetPose
(
id
);
}
modules/viz/src/viz3d_impl.cpp
View file @
061c28cd
...
...
@@ -874,7 +874,7 @@ void temp_viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget
removeActorFromRenderer
(
wam_itr
->
second
.
actor
);
}
// Get the actor and set the user matrix
vtk
SmartPointer
<
vtkLODActor
>
actor
;
vtk
LODActor
*
actor
;
if
(
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
widget
)))
{
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
...
...
@@ -889,9 +889,7 @@ bool temp_viz::Viz3d::VizImpl::removeWidget(const String &id)
{
WidgetActorMap
::
iterator
wam_itr
=
widget_actor_map_
->
find
(
id
);
bool
exists
=
wam_itr
!=
widget_actor_map_
->
end
();
if
(
!
exists
)
return
std
::
cout
<<
"[removeWidget] A widget with id <"
<<
id
<<
"> does not exist!"
<<
std
::
endl
,
false
;
CV_Assert
(
exists
);
if
(
!
removeActorFromRenderer
(
wam_itr
->
second
.
actor
))
return
false
;
...
...
@@ -899,3 +897,63 @@ bool temp_viz::Viz3d::VizImpl::removeWidget(const String &id)
widget_actor_map_
->
erase
(
wam_itr
);
return
true
;
}
bool
temp_viz
::
Viz3d
::
VizImpl
::
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
{
WidgetActorMap
::
iterator
wam_itr
=
widget_actor_map_
->
find
(
id
);
bool
exists
=
wam_itr
!=
widget_actor_map_
->
end
();
CV_Assert
(
exists
);
vtkLODActor
*
actor
;
if
((
actor
=
vtkLODActor
::
SafeDownCast
(
wam_itr
->
second
.
actor
)))
{
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
return
true
;
}
return
false
;
}
bool
temp_viz
::
Viz3d
::
VizImpl
::
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
{
WidgetActorMap
::
iterator
wam_itr
=
widget_actor_map_
->
find
(
id
);
bool
exists
=
wam_itr
!=
widget_actor_map_
->
end
();
CV_Assert
(
exists
);
vtkLODActor
*
actor
;
if
((
actor
=
vtkLODActor
::
SafeDownCast
(
wam_itr
->
second
.
actor
)))
{
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
actor
->
GetUserMatrix
();
if
(
!
matrix
)
{
setWidgetPose
(
id
,
pose
);
return
true
;
}
Matx44f
matrix_cv
=
convertToMatx
(
matrix
);
Affine3f
updated_pose
=
pose
*
Affine3f
(
matrix_cv
);
matrix
=
convertToVtkMatrix
(
updated_pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
return
true
;
}
return
false
;
}
temp_viz
::
Affine3f
temp_viz
::
Viz3d
::
VizImpl
::
getWidgetPose
(
const
String
&
id
)
const
{
WidgetActorMap
::
const_iterator
wam_itr
=
widget_actor_map_
->
find
(
id
);
bool
exists
=
wam_itr
!=
widget_actor_map_
->
end
();
CV_Assert
(
exists
);
vtkLODActor
*
actor
;
if
((
actor
=
vtkLODActor
::
SafeDownCast
(
wam_itr
->
second
.
actor
)))
{
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
actor
->
GetUserMatrix
();
Matx44f
matrix_cv
=
convertToMatx
(
matrix
);
return
Affine3f
(
matrix_cv
);
}
return
Affine3f
();
}
\ No newline at end of file
modules/viz/src/widget.cpp
View file @
061c28cd
...
...
@@ -18,7 +18,7 @@ public:
void
setColor
(
const
Color
&
color
)
{
vtk
SmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtk
LODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
Color
c
=
vtkcolor
(
color
);
lod_actor
->
GetMapper
()
->
ScalarVisibilityOff
();
lod_actor
->
GetProperty
()
->
SetColor
(
c
.
val
);
...
...
@@ -32,7 +32,7 @@ public:
void
setPose
(
const
Affine3f
&
pose
)
{
vtk
SmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtk
LODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
lod_actor
->
SetUserMatrix
(
matrix
);
lod_actor
->
Modified
();
...
...
@@ -40,7 +40,7 @@ public:
void
updatePose
(
const
Affine3f
&
pose
)
{
vtk
SmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtk
LODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
lod_actor
->
GetUserMatrix
();
if
(
!
matrix
)
{
...
...
@@ -58,7 +58,7 @@ public:
Affine3f
getPose
()
const
{
vtk
SmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtk
LODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
lod_actor
->
GetUserMatrix
();
Matx44f
matrix_cv
=
convertToMatx
(
matrix
);
return
Affine3f
(
matrix_cv
);
...
...
modules/viz/test/test_viz3d.cpp
View file @
061c28cd
...
...
@@ -96,26 +96,38 @@ TEST(Viz_viz3d, accuracy)
temp_viz
::
ArrowWidget
aw
(
cv
::
Point3f
(
0
,
0
,
0
),
cv
::
Point3f
(
1
,
1
,
1
),
temp_viz
::
Color
(
255
,
0
,
0
));
temp_viz
::
CircleWidget
cw
(
cv
::
Point3f
(
0
,
0
,
0
),
0.5
,
0.01
,
temp_viz
::
Color
(
0
,
255
,
0
));
temp_viz
::
CylinderWidget
cyw
(
cv
::
Point3f
(
0
,
0
,
0
),
cv
::
Point3f
(
-
1
,
-
1
,
-
1
),
0.5
,
30
,
temp_viz
::
Color
(
0
,
255
,
0
));
temp_viz
::
CubeWidget
cuw
(
cv
::
Point3f
(
-
2
,
-
2
,
-
2
),
cv
::
Point3f
(
-
1
,
-
1
,
-
1
)
,
temp_viz
::
Color
(
0
,
0
,
255
)
);
temp_viz
::
CubeWidget
cuw
(
cv
::
Point3f
(
-
2
,
-
2
,
-
2
),
cv
::
Point3f
(
-
1
,
-
1
,
-
1
));
temp_viz
::
CoordinateSystemWidget
csw
(
1.0
f
,
cv
::
Affine3f
::
Identity
());
temp_viz
::
TextWidget
tw
(
"TEST"
,
cv
::
Point2i
(
100
,
100
),
20
);
temp_viz
::
CloudWidget
pcw
(
cloud
,
colors
);
temp_viz
::
CloudWidget
pcw2
(
cloud
,
temp_viz
::
Color
(
0
,
255
,
255
));
// v.showWidget("line", lw);
v
.
showWidget
(
"plane"
,
pw
);
//
v.showWidget("plane", pw);
// v.showWidget("sphere", sw);
// v.showWidget("arrow", aw);
// v.showWidget("circle", cw);
// v.showWidget("cylinder", cyw);
// v.showWidget("cube", cuw);
v
.
showWidget
(
"coordinateSystem"
,
csw
);
v
.
showWidget
(
"text"
,
tw
);
// v.showWidget("text",tw);
// v.showWidget("pcw",pcw);
v
.
showWidget
(
"pcw2"
,
pcw2
);
temp_viz
::
LineWidget
lw2
=
lw
;
// v.showPointCloud("cld",cloud, colors);
cv
::
Mat
normals
(
cloud
.
size
(),
cloud
.
type
(),
cv
::
Scalar
(
0
,
10
,
0
));
// v.addPointCloudNormals(cloud, normals, 100, 0.02, "n");
temp_viz
::
CloudNormalsWidget
cnw
(
cloud
,
normals
);
v
.
showWidget
(
"n"
,
cnw
);
while
(
!
v
.
wasStopped
())
{
// Creating new point cloud with id cloud1
cv
::
Affine3f
cloudPosition
(
angle_x
,
angle_y
,
angle_z
,
cv
::
Vec3f
(
pos_x
,
pos_y
,
pos_z
));
cv
::
Affine3f
cloudPosition2
(
angle_x
,
angle_y
,
angle_z
,
cv
::
Vec3f
(
pos_x
+
0.2
,
pos_y
+
0.2
,
pos_z
+
0.2
));
lw2
.
setColor
(
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
));
lw
.
setLineWidth
(
lw
.
getLineWidth
()
+
pos_x
*
10
);
...
...
@@ -128,9 +140,16 @@ TEST(Viz_viz3d, accuracy)
cw
.
setPose
(
cloudPosition
);
cyw
.
setPose
(
cloudPosition
);
lw
.
setPose
(
cloudPosition
);
cuw
.
setPose
(
cloudPosition
);
cuw
.
setPose
(
cloudPosition
);
// cnw.setPose(cloudPosition);
// v.showWidget("pcw",pcw, cloudPosition);
// v.showWidget("pcw2",pcw2, cloudPosition2);
// v.showWidget("plane", pw, cloudPosition);
v
.
showWidget
(
"plane"
,
pw
,
cloudPosition
);
v
.
setWidgetPose
(
"n"
,
cloudPosition
);
v
.
setWidgetPose
(
"pcw2"
,
cloudPosition
);
cnw
.
setColor
(
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
));
pcw2
.
setColor
(
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
));
angle_x
+=
0.1
f
;
angle_y
-=
0.1
f
;
...
...
@@ -145,9 +164,7 @@ TEST(Viz_viz3d, accuracy)
v
.
spinOnce
(
1
,
true
);
}
// cv::Mat normals(cloud.size(), CV_32FC3, cv::Scalar(0, 10, 0));
//
// v.addPointCloudNormals(cloud, normals, 100, 0.02, "n");
//
//
// temp_viz::ModelCoefficients mc;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment