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
ea8d485d
Commit
ea8d485d
authored
Jul 11, 2013
by
Anatoly Baksheev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15 from ozantonkal/implementing_widgets
Implementing widgets
parents
061c28cd
eef81955
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
268 additions
and
316 deletions
+268
-316
viz3d.hpp
modules/viz/include/opencv2/viz/viz3d.hpp
+4
-8
widget_accessor.hpp
modules/viz/include/opencv2/viz/widget_accessor.hpp
+3
-2
widgets.hpp
modules/viz/include/opencv2/viz/widgets.hpp
+86
-23
viz3d_impl.hpp
modules/viz/src/q/viz3d_impl.hpp
+4
-24
simple_widgets.cpp
modules/viz/src/simple_widgets.cpp
+0
-0
viz3d.cpp
modules/viz/src/viz3d.cpp
+11
-26
viz3d_impl.cpp
modules/viz/src/viz3d_impl.cpp
+0
-0
viz_main.cpp
modules/viz/src/viz_main.cpp
+0
-113
widget.cpp
modules/viz/src/widget.cpp
+125
-111
test_viz3d.cpp
modules/viz/test/test_viz3d.cpp
+35
-9
No files found.
modules/viz/include/opencv2/viz/viz3d.hpp
View file @
ea8d485d
...
...
@@ -26,16 +26,11 @@ namespace temp_viz
void
setBackgroundColor
(
const
Color
&
color
=
Color
::
black
());
void
showPointCloud
(
const
String
&
id
,
InputArray
cloud
,
InputArray
colors
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
void
showPointCloud
(
const
String
&
id
,
InputArray
cloud
,
const
Color
&
color
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
bool
addPointCloudNormals
(
const
Mat
&
cloud
,
const
Mat
&
normals
,
int
level
=
100
,
float
scale
=
0.02
f
,
const
String
&
id
=
"cloud"
);
bool
addPolygonMesh
(
const
Mesh3d
&
mesh
,
const
String
&
id
=
"polygon"
);
bool
updatePolygonMesh
(
const
Mesh3d
&
mesh
,
const
String
&
id
=
"polygon"
);
bool
addPolylineFromPolygonMesh
(
const
Mesh3d
&
mesh
,
const
String
&
id
=
"polyline"
);
bool
addText
(
const
String
&
text
,
int
xpos
,
int
ypos
,
const
Color
&
color
,
int
fontsize
=
10
,
const
String
&
id
=
""
);
bool
addPolygon
(
const
Mat
&
cloud
,
const
Color
&
color
,
const
String
&
id
=
"polygon"
);
void
spin
();
...
...
@@ -47,10 +42,11 @@ namespace temp_viz
bool
wasStopped
()
const
;
void
showWidget
(
const
String
&
id
,
const
Widget
&
widget
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
bool
removeWidget
(
const
String
&
id
);
void
removeWidget
(
const
String
&
id
);
Widget
getWidget
(
const
String
&
id
)
const
;
bool
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
bool
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
void
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
void
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
Affine3f
getWidgetPose
(
const
String
&
id
)
const
;
private
:
Viz3d
(
const
Viz3d
&
);
...
...
modules/viz/include/opencv2/viz/widget_accessor.hpp
View file @
ea8d485d
...
...
@@ -2,7 +2,7 @@
#include <opencv2/core/cvdef.h>
#include <vtkSmartPointer.h>
#include <vtk
LODActor
.h>
#include <vtk
Prop
.h>
namespace
temp_viz
{
...
...
@@ -12,6 +12,7 @@ namespace temp_viz
//It is indended for those users who want to develop own widgets system using VTK library API.
struct
CV_EXPORTS
WidgetAccessor
{
static
vtkSmartPointer
<
vtkProp
>
getActor
(
const
Widget
&
widget
);
static
vtkSmartPointer
<
vtkProp
>
getProp
(
const
Widget
&
widget
);
static
void
setProp
(
Widget
&
widget
,
vtkSmartPointer
<
vtkProp
>
prop
);
};
}
modules/viz/include/opencv2/viz/widgets.hpp
View file @
ea8d485d
...
...
@@ -16,29 +16,45 @@ namespace temp_viz
~
Widget
();
void
copyTo
(
Widget
&
dst
);
template
<
typename
_W
>
_W
cast
();
private
:
class
Impl
;
Impl
*
impl_
;
friend
struct
WidgetAccessor
;
void
create
();
void
release
();
};
/////////////////////////////////////////////////////////////////////////////
/// The base class for all 3D widgets
class
CV_EXPORTS
Widget3D
:
public
Widget
{
public
:
Widget3D
()
{}
void
setColor
(
const
Color
&
color
);
void
setPose
(
const
Affine3f
&
pose
);
void
updatePose
(
const
Affine3f
&
pose
);
Affine3f
getPose
()
const
;
protected
:
Widget
(
bool
text_widget
);
void
setColor
(
const
Color
&
color
);
private
:
class
Impl
;
Impl
*
impl_
;
void
create
();
void
release
();
void
create
(
bool
text_widget
);
struct
MatrixConverter
;
friend
struct
WidgetAccessor
;
};
/////////////////////////////////////////////////////////////////////////////
/// The base class for all 2D widgets
class
CV_EXPORTS
Widget2D
:
public
Widget
{
public
:
Widget2D
()
{}
class
CV_EXPORTS
LineWidget
:
public
Widget
void
setColor
(
const
Color
&
color
);
};
class
CV_EXPORTS
LineWidget
:
public
Widget3D
{
public
:
LineWidget
(
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
const
Color
&
color
=
Color
::
white
());
...
...
@@ -47,71 +63,118 @@ namespace temp_viz
float
getLineWidth
();
};
class
CV_EXPORTS
PlaneWidget
:
public
Widget
class
CV_EXPORTS
PlaneWidget
:
public
Widget
3D
{
public
:
PlaneWidget
(
const
Vec4f
&
coefs
,
double
size
=
1.0
,
const
Color
&
color
=
Color
::
white
());
PlaneWidget
(
const
Vec4f
&
coefs
,
const
Point3f
&
pt
,
double
size
=
1.0
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
SphereWidget
:
public
Widget
class
CV_EXPORTS
SphereWidget
:
public
Widget
3D
{
public
:
SphereWidget
(
const
cv
::
Point3f
&
center
,
float
radius
,
int
sphere_resolution
=
10
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
ArrowWidget
:
public
Widget
class
CV_EXPORTS
ArrowWidget
:
public
Widget
3D
{
public
:
ArrowWidget
(
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
CircleWidget
:
public
Widget
class
CV_EXPORTS
CircleWidget
:
public
Widget
3D
{
public
:
CircleWidget
(
const
Point3f
&
pt
,
double
radius
,
double
thickness
=
0.01
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
CylinderWidget
:
public
Widget
class
CV_EXPORTS
CylinderWidget
:
public
Widget
3D
{
public
:
CylinderWidget
(
const
Point3f
&
pt_on_axis
,
const
Point3f
&
axis_direction
,
double
radius
,
int
numsides
=
30
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
CubeWidget
:
public
Widget
class
CV_EXPORTS
CubeWidget
:
public
Widget
3D
{
public
:
CubeWidget
(
const
Point3f
&
pt_min
,
const
Point3f
&
pt_max
,
bool
wire_frame
=
true
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
CoordinateSystemWidget
:
public
Widget
class
CV_EXPORTS
CoordinateSystemWidget
:
public
Widget
3D
{
public
:
CoordinateSystemWidget
(
double
scale
,
const
Affine3f
&
affine
);
};
class
CV_EXPORTS
TextWidget
:
public
Widget
class
CV_EXPORTS
PolyLineWidget
:
public
Widget3D
{
public
:
PolyLineWidget
(
InputArray
_points
,
const
Color
&
color
=
Color
::
white
());
private
:
struct
CopyImpl
;
};
class
CV_EXPORTS
GridWidget
:
public
Widget3D
{
public
:
GridWidget
(
Vec2i
dimensions
,
Vec2d
spacing
,
const
Color
&
color
=
Color
::
white
());
};
class
CV_EXPORTS
Text3DWidget
:
public
Widget3D
{
public
:
Text3DWidget
(
const
String
&
text
,
const
Point3f
&
position
,
double
text_scale
=
1.0
,
const
Color
&
color
=
Color
::
white
());
void
setText
(
const
String
&
text
);
String
getText
()
const
;
};
class
CV_EXPORTS
TextWidget
:
public
Widget2D
{
public
:
TextWidget
(
const
String
&
text
,
const
Point2i
&
pos
,
int
font_size
=
10
,
const
Color
&
color
=
Color
::
white
());
// TODO Overload setColor method, and hide setPose, updatePose, getPose methods
void
setText
(
const
String
&
text
);
String
getText
()
const
;
};
class
CV_EXPORTS
CloudWidget
:
public
Widget
class
CV_EXPORTS
CloudWidget
:
public
Widget
3D
{
public
:
CloudWidget
(
InputArray
_cloud
,
InputArray
_colors
);
CloudWidget
(
InputArray
_cloud
,
const
Color
&
color
=
Color
::
white
());
private
:
struct
CreateCloudWidget
;
};
class
CV_EXPORTS
CloudNormalsWidget
:
public
Widget
class
CV_EXPORTS
CloudNormalsWidget
:
public
Widget
3D
{
public
:
CloudNormalsWidget
(
InputArray
_cloud
,
InputArray
_normals
,
int
level
=
100
,
float
scale
=
0.02
f
,
const
Color
&
color
=
Color
::
white
());
private
:
struct
ApplyCloudNormals
;
};
template
<>
CV_EXPORTS
Widget2D
Widget
::
cast
<
Widget2D
>
();
template
<>
CV_EXPORTS
Widget3D
Widget
::
cast
<
Widget3D
>
();
template
<>
CV_EXPORTS
LineWidget
Widget
::
cast
<
LineWidget
>
();
template
<>
CV_EXPORTS
PlaneWidget
Widget
::
cast
<
PlaneWidget
>
();
template
<>
CV_EXPORTS
SphereWidget
Widget
::
cast
<
SphereWidget
>
();
template
<>
CV_EXPORTS
CylinderWidget
Widget
::
cast
<
CylinderWidget
>
();
template
<>
CV_EXPORTS
ArrowWidget
Widget
::
cast
<
ArrowWidget
>
();
template
<>
CV_EXPORTS
CircleWidget
Widget
::
cast
<
CircleWidget
>
();
template
<>
CV_EXPORTS
CubeWidget
Widget
::
cast
<
CubeWidget
>
();
template
<>
CV_EXPORTS
CoordinateSystemWidget
Widget
::
cast
<
CoordinateSystemWidget
>
();
template
<>
CV_EXPORTS
PolyLineWidget
Widget
::
cast
<
PolyLineWidget
>
();
template
<>
CV_EXPORTS
GridWidget
Widget
::
cast
<
GridWidget
>
();
template
<>
CV_EXPORTS
Text3DWidget
Widget
::
cast
<
Text3DWidget
>
();
template
<>
CV_EXPORTS
TextWidget
Widget
::
cast
<
TextWidget
>
();
template
<>
CV_EXPORTS
CloudWidget
Widget
::
cast
<
CloudWidget
>
();
template
<>
CV_EXPORTS
CloudNormalsWidget
Widget
::
cast
<
CloudNormalsWidget
>
();
}
modules/viz/src/q/viz3d_impl.hpp
View file @
ea8d485d
...
...
@@ -52,36 +52,15 @@ public:
void
setBackgroundColor
(
const
Color
&
color
);
bool
addText
(
const
String
&
text
,
int
xpos
,
int
ypos
,
const
Color
&
color
,
int
fontsize
=
10
,
const
String
&
id
=
""
);
bool
updateText
(
const
String
&
text
,
int
xpos
,
int
ypos
,
const
Color
&
color
,
int
fontsize
=
10
,
const
String
&
id
=
""
);
/** \brief Set the pose of an existing shape. Returns false if the shape doesn't exist, true if the pose was succesfully updated. */
bool
updateShapePose
(
const
String
&
id
,
const
Affine3f
&
pose
);
bool
addText3D
(
const
String
&
text
,
const
Point3f
&
position
,
const
Color
&
color
,
double
textScale
=
1.0
,
const
String
&
id
=
""
);
bool
addPointCloudNormals
(
const
cv
::
Mat
&
cloud
,
const
cv
::
Mat
&
normals
,
int
level
=
100
,
float
scale
=
0.02
f
,
const
String
&
id
=
"cloud"
);
/** \brief If the id exists, updates the point cloud; otherwise, adds a new point cloud to the scene
* \param[in] id a variable to identify the point cloud
* \param[in] cloud cloud input in x,y,z coordinates
* \param[in] colors color input in the same order of the points or single uniform color
* \param[in] pose transform to be applied on the point cloud
*/
void
showPointCloud
(
const
String
&
id
,
InputArray
cloud
,
InputArray
colors
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
void
showPointCloud
(
const
String
&
id
,
InputArray
cloud
,
const
Color
&
color
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
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"
);
void
setPointCloudColor
(
const
Color
&
color
,
const
String
&
id
=
"cloud"
);
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
);
void
setShapeColor
(
const
Color
&
color
,
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)
...
...
@@ -200,10 +179,11 @@ public:
void
setSize
(
int
xw
,
int
yw
);
void
showWidget
(
const
String
&
id
,
const
Widget
&
widget
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
bool
removeWidget
(
const
String
&
id
);
void
removeWidget
(
const
String
&
id
);
Widget
getWidget
(
const
String
&
id
)
const
;
bool
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
bool
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
void
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
void
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
);
Affine3f
getWidgetPose
(
const
String
&
id
)
const
;
void
all_data
();
...
...
modules/viz/src/simple_widgets.cpp
View file @
ea8d485d
This diff is collapsed.
Click to expand it.
modules/viz/src/viz3d.cpp
View file @
ea8d485d
...
...
@@ -17,21 +17,6 @@ void temp_viz::Viz3d::setBackgroundColor(const Color& color)
impl_
->
setBackgroundColor
(
color
);
}
void
temp_viz
::
Viz3d
::
showPointCloud
(
const
String
&
id
,
InputArray
cloud
,
InputArray
colors
,
const
Affine3f
&
pose
)
{
impl_
->
showPointCloud
(
id
,
cloud
,
colors
,
pose
);
}
void
temp_viz
::
Viz3d
::
showPointCloud
(
const
String
&
id
,
InputArray
cloud
,
const
Color
&
color
,
const
Affine3f
&
pose
)
{
impl_
->
showPointCloud
(
id
,
cloud
,
color
,
pose
);
}
bool
temp_viz
::
Viz3d
::
addPointCloudNormals
(
const
Mat
&
cloud
,
const
Mat
&
normals
,
int
level
,
float
scale
,
const
String
&
id
)
{
return
impl_
->
addPointCloudNormals
(
cloud
,
normals
,
level
,
scale
,
id
);
}
bool
temp_viz
::
Viz3d
::
addPolygonMesh
(
const
Mesh3d
&
mesh
,
const
String
&
id
)
{
return
impl_
->
addPolygonMesh
(
mesh
,
Mat
(),
id
);
...
...
@@ -47,11 +32,6 @@ bool temp_viz::Viz3d::addPolylineFromPolygonMesh (const Mesh3d& mesh, const Stri
return
impl_
->
addPolylineFromPolygonMesh
(
mesh
,
id
);
}
bool
temp_viz
::
Viz3d
::
addText
(
const
String
&
text
,
int
xpos
,
int
ypos
,
const
Color
&
color
,
int
fontsize
,
const
String
&
id
)
{
return
impl_
->
addText
(
text
,
xpos
,
ypos
,
color
,
fontsize
,
id
);
}
bool
temp_viz
::
Viz3d
::
addPolygon
(
const
Mat
&
cloud
,
const
Color
&
color
,
const
String
&
id
)
{
return
impl_
->
addPolygon
(
cloud
,
color
,
id
);
...
...
@@ -84,19 +64,24 @@ void temp_viz::Viz3d::showWidget(const String &id, const Widget &widget, const A
impl_
->
showWidget
(
id
,
widget
,
pose
);
}
bool
temp_viz
::
Viz3d
::
removeWidget
(
const
String
&
id
)
void
temp_viz
::
Viz3d
::
removeWidget
(
const
String
&
id
)
{
impl_
->
removeWidget
(
id
);
}
temp_viz
::
Widget
temp_viz
::
Viz3d
::
getWidget
(
const
String
&
id
)
const
{
return
impl_
->
remove
Widget
(
id
);
return
impl_
->
get
Widget
(
id
);
}
bool
temp_viz
::
Viz3d
::
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
void
temp_viz
::
Viz3d
::
setWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
{
return
impl_
->
setWidgetPose
(
id
,
pose
);
impl_
->
setWidgetPose
(
id
,
pose
);
}
bool
temp_viz
::
Viz3d
::
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
void
temp_viz
::
Viz3d
::
updateWidgetPose
(
const
String
&
id
,
const
Affine3f
&
pose
)
{
return
impl_
->
updateWidgetPose
(
id
,
pose
);
impl_
->
updateWidgetPose
(
id
,
pose
);
}
temp_viz
::
Affine3f
temp_viz
::
Viz3d
::
getWidgetPose
(
const
String
&
id
)
const
...
...
modules/viz/src/viz3d_impl.cpp
View file @
ea8d485d
This diff is collapsed.
Click to expand it.
modules/viz/src/viz_main.cpp
View file @
ea8d485d
...
...
@@ -350,21 +350,6 @@ void temp_viz::Viz3d::VizImpl::setBackgroundColor (const Color& color)
renderer_
->
SetBackground
(
c
.
val
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
temp_viz
::
Viz3d
::
VizImpl
::
setPointCloudColor
(
const
Color
&
color
,
const
std
::
string
&
id
)
{
CloudActorMap
::
iterator
am_it
=
cloud_actor_map_
->
find
(
id
);
if
(
am_it
!=
cloud_actor_map_
->
end
())
{
vtkLODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
am_it
->
second
.
actor
);
Color
c
=
vtkcolor
(
color
);
actor
->
GetProperty
()
->
SetColor
(
c
.
val
);
actor
->
GetMapper
()
->
ScalarVisibilityOff
();
actor
->
Modified
();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool
temp_viz
::
Viz3d
::
VizImpl
::
getPointCloudRenderingProperties
(
int
property
,
double
&
value
,
const
std
::
string
&
id
)
{
...
...
@@ -470,26 +455,6 @@ bool temp_viz::Viz3d::VizImpl::setPointCloudSelected (const bool selected, const
return
true
;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
temp_viz
::
Viz3d
::
VizImpl
::
setShapeColor
(
const
Color
&
color
,
const
std
::
string
&
id
)
{
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
id
);
if
(
am_it
!=
shape_actor_map_
->
end
())
{
vtkActor
*
actor
=
vtkActor
::
SafeDownCast
(
am_it
->
second
);
Color
c
=
vtkcolor
(
color
);
actor
->
GetMapper
()
->
ScalarVisibilityOff
();
actor
->
GetProperty
()
->
SetColor
(
c
.
val
);
actor
->
GetProperty
()
->
SetEdgeColor
(
c
.
val
);
actor
->
GetProperty
()
->
SetAmbient
(
0.8
);
actor
->
GetProperty
()
->
SetDiffuse
(
0.8
);
actor
->
GetProperty
()
->
SetSpecular
(
0.8
);
actor
->
GetProperty
()
->
SetLighting
(
0
);
actor
->
Modified
();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool
temp_viz
::
Viz3d
::
VizImpl
::
setShapeRenderingProperties
(
int
property
,
double
value
,
const
std
::
string
&
id
)
{
...
...
@@ -618,28 +583,6 @@ void temp_viz::Viz3d::VizImpl::updateCamera ()
renderer_
->
Render
();
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool
temp_viz
::
Viz3d
::
VizImpl
::
updateShapePose
(
const
std
::
string
&
id
,
const
cv
::
Affine3f
&
pose
)
{
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
id
);
vtkLODActor
*
actor
;
if
(
am_it
==
shape_actor_map_
->
end
())
return
(
false
);
else
actor
=
vtkLODActor
::
SafeDownCast
(
am_it
->
second
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
vtkSmartPointer
<
vtkMatrix4x4
>::
New
();
convertToVtkMatrix
(
pose
.
matrix
,
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
return
(
true
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
temp_viz
::
Viz3d
::
VizImpl
::
getCameras
(
temp_viz
::
Camera
&
camera
)
{
...
...
@@ -916,62 +859,6 @@ bool temp_viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename,
return
(
true
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool
temp_viz
::
Viz3d
::
VizImpl
::
addText
(
const
std
::
string
&
text
,
int
xpos
,
int
ypos
,
const
Color
&
color
,
int
fontsize
,
const
std
::
string
&
id
)
{
std
::
string
tid
=
id
.
empty
()
?
text
:
id
;
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
tid
);
if
(
am_it
!=
shape_actor_map_
->
end
())
return
std
::
cout
<<
"[addText] A text with id <"
<<
id
<<
"> already exists! Please choose a different id and retry.
\n
"
<<
std
::
endl
,
false
;
// Create an Actor
vtkSmartPointer
<
vtkTextActor
>
actor
=
vtkSmartPointer
<
vtkTextActor
>::
New
();
actor
->
SetPosition
(
xpos
,
ypos
);
actor
->
SetInput
(
text
.
c_str
());
vtkSmartPointer
<
vtkTextProperty
>
tprop
=
actor
->
GetTextProperty
();
tprop
->
SetFontSize
(
fontsize
);
tprop
->
SetFontFamilyToArial
();
tprop
->
SetJustificationToLeft
();
tprop
->
BoldOn
();
Color
c
=
vtkcolor
(
color
);
tprop
->
SetColor
(
c
.
val
);
renderer_
->
AddActor
(
actor
);
// Save the pointer/ID pair to the global actor map
(
*
shape_actor_map_
)[
tid
]
=
actor
;
return
(
true
);
}
//////////////////////////////////////////////////////////////////////////////////////////
bool
temp_viz
::
Viz3d
::
VizImpl
::
updateText
(
const
std
::
string
&
text
,
int
xpos
,
int
ypos
,
const
Color
&
color
,
int
fontsize
,
const
std
::
string
&
id
)
{
std
::
string
tid
=
id
.
empty
()
?
text
:
id
;
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
tid
);
if
(
am_it
==
shape_actor_map_
->
end
())
return
false
;
// Retrieve the Actor
vtkTextActor
*
actor
=
vtkTextActor
::
SafeDownCast
(
am_it
->
second
);
actor
->
SetPosition
(
xpos
,
ypos
);
actor
->
SetInput
(
text
.
c_str
());
vtkTextProperty
*
tprop
=
actor
->
GetTextProperty
();
tprop
->
SetFontSize
(
fontsize
);
Color
c
=
vtkcolor
(
color
);
tprop
->
SetColor
(
c
.
val
);
actor
->
Modified
();
return
(
true
);
}
bool
temp_viz
::
Viz3d
::
VizImpl
::
addPolylineFromPolygonMesh
(
const
Mesh3d
&
mesh
,
const
std
::
string
&
id
)
{
CV_Assert
(
mesh
.
cloud
.
rows
==
1
&&
mesh
.
cloud
.
type
()
==
CV_32FC3
);
...
...
modules/viz/src/widget.cpp
View file @
ea8d485d
#include "precomp.hpp"
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget implementation
class
temp_viz
::
Widget
::
Impl
{
public
:
vtkSmartPointer
<
vtkProp
>
actor
;
vtkSmartPointer
<
vtkProp
>
prop
;
int
ref_counter
;
Impl
()
:
actor
(
vtkSmartPointer
<
vtkLODActor
>::
New
())
{}
Impl
()
:
prop
(
0
)
{}
};
Impl
(
bool
text_widget
)
{
if
(
text_widget
)
actor
=
vtkSmartPointer
<
vtkTextActor
>::
New
();
else
actor
=
vtkSmartPointer
<
vtkLeaderActor2D
>::
New
();
}
temp_viz
::
Widget
::
Widget
()
:
impl_
(
0
)
{
create
();
}
void
setColor
(
const
Color
&
color
)
{
vtkLODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
Color
c
=
vtkcolor
(
color
);
lod_actor
->
GetMapper
()
->
ScalarVisibilityOff
();
lod_actor
->
GetProperty
()
->
SetColor
(
c
.
val
);
lod_actor
->
GetProperty
()
->
SetEdgeColor
(
c
.
val
);
lod_actor
->
GetProperty
()
->
SetAmbient
(
0.8
);
lod_actor
->
GetProperty
()
->
SetDiffuse
(
0.8
);
lod_actor
->
GetProperty
()
->
SetSpecular
(
0.8
);
lod_actor
->
GetProperty
()
->
SetLighting
(
0
);
lod_actor
->
Modified
();
}
temp_viz
::
Widget
::
Widget
(
const
Widget
&
other
)
:
impl_
(
other
.
impl_
)
{
if
(
impl_
)
CV_XADD
(
&
impl_
->
ref_counter
,
1
);
}
void
setPose
(
const
Affine3f
&
pose
)
temp_viz
::
Widget
&
temp_viz
::
Widget
::
operator
=
(
const
Widget
&
other
)
{
if
(
this
!=
&
other
)
{
vtkLODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
lod_actor
->
SetUserMatrix
(
matrix
);
lod_actor
->
Modified
();
release
();
impl_
=
other
.
impl_
;
if
(
impl_
)
CV_XADD
(
&
impl_
->
ref_counter
,
1
);
}
return
*
this
;
}
void
updatePose
(
const
Affine3f
&
pose
)
{
vtkLODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
lod_actor
->
GetUserMatrix
();
if
(
!
matrix
)
temp_viz
::
Widget
::~
Widget
()
{
release
();
}
void
temp_viz
::
Widget
::
create
()
{
if
(
impl_
)
release
();
impl_
=
new
Impl
();
impl_
->
ref_counter
=
1
;
}
void
temp_viz
::
Widget
::
release
()
{
if
(
impl_
&&
CV_XADD
(
&
impl_
->
ref_counter
,
-
1
)
==
1
)
{
setPose
(
pose
)
;
return
;
delete
impl_
;
impl_
=
0
;
}
Matx44f
matrix_cv
=
convertToMatx
(
matrix
);
}
Affine3f
updated_pose
=
pose
*
Affine3f
(
matrix_cv
);
matrix
=
convertToVtkMatrix
(
updated_pose
.
matrix
);
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget accessor implementaion
lod_actor
->
SetUserMatrix
(
matrix
);
lod_actor
->
Modified
();
}
vtkSmartPointer
<
vtkProp
>
temp_viz
::
WidgetAccessor
::
getProp
(
const
Widget
&
widget
)
{
return
widget
.
impl_
->
prop
;
}
Affine3f
getPose
()
const
{
vtkLODActor
*
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
lod_actor
->
GetUserMatrix
();
Matx44f
matrix_cv
=
convertToMatx
(
matrix
);
return
Affine3f
(
matrix_cv
);
}
void
temp_viz
::
WidgetAccessor
::
setProp
(
Widget
&
widget
,
vtkSmartPointer
<
vtkProp
>
prop
)
{
widget
.
impl_
->
prop
=
prop
;
}
protected
:
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget3D implementation
static
vtkSmartPointer
<
vtkMatrix4x4
>
convertToVtkMatrix
(
const
cv
::
Matx44f
&
m
)
struct
temp_viz
::
Widget3D
::
MatrixConverter
{
static
cv
::
Matx44f
convertToMatx
(
const
vtkSmartPointer
<
vtkMatrix4x4
>&
vtk_matrix
)
{
vtkSmartPointer
<
vtkMatrix4x4
>
vtk_matrix
=
vtkSmartPointer
<
vtkMatrix4x4
>::
New
()
;
cv
::
Matx44f
m
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
for
(
int
k
=
0
;
k
<
4
;
k
++
)
vtk_matrix
->
SetElement
(
i
,
k
,
m
(
i
,
k
)
);
return
vtk_matrix
;
m
(
i
,
k
)
=
vtk_matrix
->
GetElement
(
i
,
k
);
return
m
;
}
static
cv
::
Matx44f
convertToMatx
(
const
vtkSmartPointer
<
vtkMatrix4x4
>&
vtk_matrix
)
static
vtkSmartPointer
<
vtkMatrix4x4
>
convertToVtkMatrix
(
const
cv
::
Matx44f
&
m
)
{
cv
::
Matx44f
m
;
vtkSmartPointer
<
vtkMatrix4x4
>
vtk_matrix
=
vtkSmartPointer
<
vtkMatrix4x4
>::
New
()
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
for
(
int
k
=
0
;
k
<
4
;
k
++
)
m
(
i
,
k
)
=
vtk_matrix
->
GetElement
(
i
,
k
);
return
m
;
vtk_matrix
->
SetElement
(
i
,
k
,
m
(
i
,
k
)
);
return
vtk_matrix
;
}
};
void
temp_viz
::
Widget3D
::
setPose
(
const
Affine3f
&
pose
)
{
vtkProp3D
*
actor
=
vtkProp3D
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
));
CV_Assert
(
actor
);
///////////////////////////////////////////////////////////////////////////////////////////////
/// stream accessor implementaion
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
}
v
tkSmartPointer
<
vtkProp
>
temp_viz
::
WidgetAccessor
::
getActor
(
const
Widget
&
widget
)
v
oid
temp_viz
::
Widget3D
::
updatePose
(
const
Affine3f
&
pose
)
{
return
widget
.
impl_
->
actor
;
}
vtkProp3D
*
actor
=
vtkProp3D
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
))
;
CV_Assert
(
actor
);
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget implementaion
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
actor
->
GetUserMatrix
();
if
(
!
matrix
)
{
setPose
(
pose
);
return
;
}
Matx44f
matrix_cv
=
MatrixConverter
::
convertToMatx
(
matrix
);
temp_viz
::
Widget
::
Widget
()
:
impl_
(
0
)
{
create
();
}
Affine3f
updated_pose
=
pose
*
Affine3f
(
matrix_cv
);
matrix
=
MatrixConverter
::
convertToVtkMatrix
(
updated_pose
.
matrix
);
temp_viz
::
Widget
::
Widget
(
bool
text_widget
)
:
impl_
(
0
)
{
create
(
text_widget
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
}
temp_viz
::
Widget
::
Widget
(
const
Widget
&
other
)
:
impl_
(
other
.
impl_
)
temp_viz
::
Affine3f
temp_viz
::
Widget3D
::
getPose
()
const
{
if
(
impl_
)
CV_XADD
(
&
impl_
->
ref_counter
,
1
);
}
vtkProp3D
*
actor
=
vtkProp3D
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
));
CV_Assert
(
actor
);
temp_viz
::
Widget
&
temp_viz
::
Widget
::
operator
=
(
const
Widget
&
other
)
{
if
(
this
!=
&
other
)
{
release
();
impl_
=
other
.
impl_
;
if
(
impl_
)
CV_XADD
(
&
impl_
->
ref_counter
,
1
);
}
return
*
this
;
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
actor
->
GetUserMatrix
();
Matx44f
matrix_cv
=
MatrixConverter
::
convertToMatx
(
matrix
);
return
Affine3f
(
matrix_cv
);
}
temp_viz
::
Widget
::~
Widget
(
)
void
temp_viz
::
Widget3D
::
setColor
(
const
Color
&
color
)
{
release
();
// Cast to actor instead of prop3d since prop3d doesn't provide getproperty
vtkActor
*
actor
=
vtkActor
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
));
CV_Assert
(
actor
);
Color
c
=
vtkcolor
(
color
);
actor
->
GetMapper
()
->
ScalarVisibilityOff
();
actor
->
GetProperty
()
->
SetColor
(
c
.
val
);
actor
->
GetProperty
()
->
SetEdgeColor
(
c
.
val
);
actor
->
GetProperty
()
->
SetAmbient
(
0.8
);
actor
->
GetProperty
()
->
SetDiffuse
(
0.8
);
actor
->
GetProperty
()
->
SetSpecular
(
0.8
);
actor
->
GetProperty
()
->
SetLighting
(
0
);
actor
->
Modified
();
}
void
temp_viz
::
Widget
::
copyTo
(
Widget
&
/*dst*/
)
template
<>
temp_viz
::
Widget3D
temp_viz
::
Widget
::
cast
<
temp_viz
::
Widget3D
>
(
)
{
// TODO Deep copy the data if there is any
vtkProp3D
*
actor
=
vtkProp3D
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
));
CV_Assert
(
actor
);
Widget3D
widget
;
WidgetAccessor
::
setProp
(
widget
,
actor
);
return
widget
;
}
void
temp_viz
::
Widget
::
setColor
(
const
Color
&
color
)
{
impl_
->
setColor
(
color
);
}
void
temp_viz
::
Widget
::
setPose
(
const
Affine3f
&
pose
)
{
impl_
->
setPose
(
pose
);
}
void
temp_viz
::
Widget
::
updatePose
(
const
Affine3f
&
pose
)
{
impl_
->
updatePose
(
pose
);
}
temp_viz
::
Affine3f
temp_viz
::
Widget
::
getPose
()
const
{
return
impl_
->
getPose
();
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// widget2D implementation
void
temp_viz
::
Widget
::
create
(
)
void
temp_viz
::
Widget
2D
::
setColor
(
const
Color
&
color
)
{
if
(
impl_
)
release
();
impl_
=
new
Impl
();
impl_
->
ref_counter
=
1
;
vtkActor2D
*
actor
=
vtkActor2D
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
));
CV_Assert
(
actor
);
Color
c
=
vtkcolor
(
color
);
actor
->
GetProperty
()
->
SetColor
(
c
.
val
);
actor
->
Modified
();
}
void
temp_viz
::
Widget
::
release
()
template
<>
temp_viz
::
Widget2D
temp_viz
::
Widget
::
cast
<
temp_viz
::
Widget2D
>
()
{
if
(
impl_
&&
CV_XADD
(
&
impl_
->
ref_counter
,
-
1
)
==
1
)
{
delete
impl_
;
impl_
=
0
;
}
}
vtkActor2D
*
actor
=
vtkActor2D
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
));
CV_Assert
(
actor
);
void
temp_viz
::
Widget
::
create
(
bool
text_widget
)
{
if
(
impl_
)
release
();
impl_
=
new
Impl
(
text_widget
);
impl_
->
ref_counter
=
1
;
Widget2D
widget
;
WidgetAccessor
::
setProp
(
widget
,
actor
);
return
widget
;
}
modules/viz/test/test_viz3d.cpp
View file @
ea8d485d
...
...
@@ -112,16 +112,40 @@ TEST(Viz_viz3d, accuracy)
v
.
showWidget
(
"coordinateSystem"
,
csw
);
// v.showWidget("text",tw);
// v.showWidget("pcw",pcw);
v
.
showWidget
(
"pcw2"
,
pcw2
);
//
v.showWidget("pcw2",pcw2);
temp_viz
::
LineWidget
lw2
=
lw
;
//
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
);
// v.showWidget("n", cnw);
// lw = v.getWidget("n").cast<temp_viz::LineWidget>();
// pw = v.getWidget("n").cast<temp_viz::PlaneWidget>();
cv
::
Mat
points
(
1
,
4
,
CV_64FC4
);
cv
::
Vec4d
*
data
=
points
.
ptr
<
cv
::
Vec4d
>
();
data
[
0
]
=
cv
::
Vec4d
(
0.0
,
0.0
,
0.0
,
0.0
);
data
[
1
]
=
cv
::
Vec4d
(
1.0
,
1.0
,
1.0
,
1.0
);
data
[
2
]
=
cv
::
Vec4d
(
0.0
,
2.0
,
0.0
,
0.0
);
data
[
3
]
=
cv
::
Vec4d
(
3.0
,
4.0
,
1.0
,
1.0
);
points
=
points
.
reshape
(
0
,
2
);
temp_viz
::
PolyLineWidget
plw
(
points
);
// v.showWidget("polyline",plw);
// lw = v.getWidget("polyline").cast<temp_viz::LineWidget>();
temp_viz
::
GridWidget
gw
(
temp_viz
::
Vec2i
(
10
,
10
),
temp_viz
::
Vec2d
(
0.1
,
0.1
));
v
.
showWidget
(
"grid"
,
gw
);
lw
=
v
.
getWidget
(
"grid"
).
cast
<
temp_viz
::
LineWidget
>
();
temp_viz
::
Text3DWidget
t3w
(
"OpenCV"
,
cv
::
Point3f
(
0.0
,
2.0
,
0.0
),
1.0
,
temp_viz
::
Color
(
255
,
255
,
0
));
v
.
showWidget
(
"txt3d"
,
t3w
);
// float grid_x_angle = 0.0;
while
(
!
v
.
wasStopped
())
{
...
...
@@ -129,28 +153,30 @@ TEST(Viz_viz3d, accuracy)
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
));
lw
2
.
setColor
(
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
));
lw
.
setLineWidth
(
lw
.
getLineWidth
()
+
pos_x
*
10
);
lw
.
setColor
(
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
));
// lw.setLineWidth(
pos_x * 10);
pw
.
setColor
(
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
));
p
l
w
.
setColor
(
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
));
sw
.
setPose
(
cloudPosition
);
// pw.setPose(cloudPosition);
aw
.
setPose
(
cloudPosition
);
cw
.
setPose
(
cloudPosition
);
cyw
.
setPose
(
cloudPosition
);
lw
.
setPose
(
cloudPosition
);
//
lw.setPose(cloudPosition);
cuw
.
setPose
(
cloudPosition
);
// cnw.setPose(cloudPosition);
// v.showWidget("pcw",pcw, cloudPosition);
// v.showWidget("pcw2",pcw2, cloudPosition2);
// v.showWidget("plane", pw, cloudPosition);
v
.
setWidgetPose
(
"n"
,
cloudPosition
);
v
.
setWidgetPose
(
"pcw2"
,
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
));
gw
.
updatePose
(
temp_viz
::
Affine3f
(
0.0
,
0.1
,
0.0
,
cv
::
Vec3f
(
0.0
,
0.0
,
0.0
)));
angle_x
+=
0.1
f
;
angle_y
-=
0.1
f
;
angle_z
+=
0.1
f
;
...
...
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