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
653eda45
Commit
653eda45
authored
Jul 08, 2013
by
ozantonkal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
text widget implementation
parent
c4f4727e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
36 deletions
+94
-36
types.hpp
modules/viz/include/opencv2/viz/types.hpp
+1
-0
widget_accessor.hpp
modules/viz/include/opencv2/viz/widget_accessor.hpp
+1
-1
widgets.hpp
modules/viz/include/opencv2/viz/widgets.hpp
+13
-2
simple_widgets.cpp
modules/viz/src/simple_widgets.cpp
+27
-11
viz3d_impl.cpp
modules/viz/src/viz3d_impl.cpp
+9
-6
widget.cpp
modules/viz/src/widget.cpp
+41
-16
test_viz3d.cpp
modules/viz/test/test_viz3d.cpp
+2
-0
No files found.
modules/viz/include/opencv2/viz/types.hpp
View file @
653eda45
...
...
@@ -22,6 +22,7 @@ namespace temp_viz
typedef
cv
::
Matx33d
Matx33d
;
typedef
cv
::
Affine3f
Affine3f
;
typedef
cv
::
Affine3d
Affine3d
;
typedef
cv
::
Point2i
Point2i
;
typedef
cv
::
Point3f
Point3f
;
typedef
cv
::
Point3d
Point3d
;
typedef
cv
::
Matx44d
Matx44d
;
...
...
modules/viz/include/opencv2/viz/widget_accessor.hpp
View file @
653eda45
...
...
@@ -12,6 +12,6 @@ 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
<
vtk
LODActor
>
getActor
(
const
Widget
&
widget
);
static
vtkSmartPointer
<
vtk
Prop
>
getActor
(
const
Widget
&
widget
);
};
}
modules/viz/include/opencv2/viz/widgets.hpp
View file @
653eda45
...
...
@@ -22,13 +22,17 @@ namespace temp_viz
void
setPose
(
const
Affine3f
&
pose
);
void
updatePose
(
const
Affine3f
&
pose
);
Affine3f
getPose
()
const
;
protected
:
Widget
(
bool
text_widget
);
private
:
class
Impl
;
Impl
*
impl_
;
void
create
();
void
release
();
void
create
(
bool
text_widget
);
friend
struct
WidgetAccessor
;
};
...
...
@@ -85,5 +89,12 @@ namespace temp_viz
public
:
CoordinateSystemWidget
(
double
scale
,
const
Affine3f
&
affine
);
};
class
CV_EXPORTS
TextWidget
:
public
Widget
{
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
};
}
modules/viz/src/simple_widgets.cpp
View file @
653eda45
...
...
@@ -12,7 +12,7 @@ temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const C
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
line
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -20,13 +20,13 @@ temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const C
void
temp_viz
::
LineWidget
::
setLineWidth
(
float
line_width
)
{
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
GetProperty
()
->
SetLineWidth
(
line_width
);
}
float
temp_viz
::
LineWidget
::
getLineWidth
()
{
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
return
actor
->
GetProperty
()
->
GetLineWidth
();
}
...
...
@@ -43,7 +43,7 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
plane
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
actor
->
SetScale
(
size
);
...
...
@@ -64,7 +64,7 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
plane
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
actor
->
SetScale
(
size
);
...
...
@@ -87,7 +87,7 @@ temp_viz::SphereWidget::SphereWidget(const cv::Point3f ¢er, float radius, in
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
sphere
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -149,7 +149,7 @@ temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
transformPD
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -178,7 +178,7 @@ temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius,
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tf
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -202,7 +202,7 @@ temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tuber
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -219,7 +219,7 @@ temp_viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, c
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
cube
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
setColor
(
color
);
...
...
@@ -256,7 +256,7 @@ temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Aff
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetInput
(
axes_tubes
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
WidgetAccessor
::
getActor
(
*
this
);
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
)
);
actor
->
SetMapper
(
mapper
);
cv
::
Vec3d
t
=
affine
.
translation
();
...
...
@@ -273,3 +273,19 @@ temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Aff
actor
->
SetOrientation
(
0
,
0
,
0
);
actor
->
RotateWXYZ
(
r_angle
*
180
/
CV_PI
,
rvec
[
0
],
rvec
[
1
],
rvec
[
2
]);
}
temp_viz
::
TextWidget
::
TextWidget
(
const
String
&
text
,
const
Point2i
&
pos
,
int
font_size
,
const
Color
&
color
)
:
Widget
(
true
)
{
vtkSmartPointer
<
vtkTextActor
>
actor
=
vtkTextActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
*
this
));
actor
->
SetPosition
(
pos
.
x
,
pos
.
y
);
actor
->
SetInput
(
text
.
c_str
());
vtkSmartPointer
<
vtkTextProperty
>
tprop
=
actor
->
GetTextProperty
();
tprop
->
SetFontSize
(
font_size
);
tprop
->
SetFontFamilyToArial
();
tprop
->
SetJustificationToLeft
();
tprop
->
BoldOn
();
Color
c
=
vtkcolor
(
color
);
tprop
->
SetColor
(
c
.
val
);
}
modules/viz/src/viz3d_impl.cpp
View file @
653eda45
...
...
@@ -874,12 +874,15 @@ 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
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
widget
));
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
renderer_
->
AddActor
(
actor
);
(
*
widget_actor_map_
)[
id
].
actor
=
actor
;
vtkSmartPointer
<
vtkLODActor
>
actor
;
if
(
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getActor
(
widget
)))
{
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
}
renderer_
->
AddActor
(
WidgetAccessor
::
getActor
(
widget
));
(
*
widget_actor_map_
)[
id
].
actor
=
WidgetAccessor
::
getActor
(
widget
);
}
bool
temp_viz
::
Viz3d
::
VizImpl
::
removeWidget
(
const
String
&
id
)
...
...
modules/viz/src/widget.cpp
View file @
653eda45
...
...
@@ -3,34 +3,45 @@
class
temp_viz
::
Widget
::
Impl
{
public
:
vtkSmartPointer
<
vtk
LODActor
>
actor
;
vtkSmartPointer
<
vtk
Prop
>
actor
;
int
ref_counter
;
Impl
()
:
actor
(
vtkSmartPointer
<
vtkLODActor
>::
New
())
{}
Impl
(
bool
text_widget
)
{
if
(
text_widget
)
actor
=
vtkSmartPointer
<
vtkTextActor
>::
New
();
else
actor
=
vtkSmartPointer
<
vtkLeaderActor2D
>::
New
();
}
void
setColor
(
const
Color
&
color
)
{
vtkSmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
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
();
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
();
}
void
setPose
(
const
Affine3f
&
pose
)
{
vtkSmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
lod_
actor
->
SetUserMatrix
(
matrix
);
lod_
actor
->
Modified
();
}
void
updatePose
(
const
Affine3f
&
pose
)
{
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
actor
->
GetUserMatrix
();
vtkSmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
lod_actor
->
GetUserMatrix
();
if
(
!
matrix
)
{
setPose
(
pose
);
...
...
@@ -41,13 +52,14 @@ public:
Affine3f
updated_pose
=
pose
*
Affine3f
(
matrix_cv
);
matrix
=
convertToVtkMatrix
(
updated_pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
lod_
actor
->
SetUserMatrix
(
matrix
);
lod_
actor
->
Modified
();
}
Affine3f
getPose
()
const
{
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
actor
->
GetUserMatrix
();
vtkSmartPointer
<
vtkLODActor
>
lod_actor
=
vtkLODActor
::
SafeDownCast
(
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
lod_actor
->
GetUserMatrix
();
Matx44f
matrix_cv
=
convertToMatx
(
matrix
);
return
Affine3f
(
matrix_cv
);
}
...
...
@@ -77,7 +89,7 @@ protected:
///////////////////////////////////////////////////////////////////////////////////////////////
/// stream accessor implementaion
vtkSmartPointer
<
vtk
LODActor
>
temp_viz
::
WidgetAccessor
::
getActor
(
const
Widget
&
widget
)
vtkSmartPointer
<
vtk
Prop
>
temp_viz
::
WidgetAccessor
::
getActor
(
const
Widget
&
widget
)
{
return
widget
.
impl_
->
actor
;
}
...
...
@@ -90,6 +102,11 @@ temp_viz::Widget::Widget() : impl_(0)
create
();
}
temp_viz
::
Widget
::
Widget
(
bool
text_widget
)
:
impl_
(
0
)
{
create
(
text_widget
);
}
temp_viz
::
Widget
::
Widget
(
const
Widget
&
other
)
:
impl_
(
other
.
impl_
)
{
if
(
impl_
)
...
...
@@ -140,3 +157,11 @@ void temp_viz::Widget::release()
}
}
void
temp_viz
::
Widget
::
create
(
bool
text_widget
)
{
if
(
impl_
)
release
();
impl_
=
new
Impl
(
text_widget
);
impl_
->
ref_counter
=
1
;
}
modules/viz/test/test_viz3d.cpp
View file @
653eda45
...
...
@@ -98,6 +98,7 @@ TEST(Viz_viz3d, accuracy)
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
::
CoordinateSystemWidget
csw
(
1.0
f
,
cv
::
Affine3f
::
Identity
());
temp_viz
::
TextWidget
tw
(
"TEST"
,
cv
::
Point2i
(
100
,
100
),
20
);
// v.showWidget("line", lw);
v
.
showWidget
(
"plane"
,
pw
);
...
...
@@ -107,6 +108,7 @@ TEST(Viz_viz3d, accuracy)
// v.showWidget("cylinder", cyw);
// v.showWidget("cube", cuw);
v
.
showWidget
(
"coordinateSystem"
,
csw
);
v
.
showWidget
(
"text"
,
tw
);
temp_viz
::
LineWidget
lw2
=
lw
;
...
...
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