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
f99e8747
Commit
f99e8747
authored
Sep 05, 2013
by
Ozan Tonkal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tutorial: creating_widgets code
parent
b60894c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
5 deletions
+124
-5
creating_widgets.cpp
samples/cpp/tutorial_code/viz/creating_widgets.cpp
+106
-0
launching_viz.cpp
samples/cpp/tutorial_code/viz/launching_viz.cpp
+18
-5
No files found.
samples/cpp/tutorial_code/viz/creating_widgets.cpp
0 → 100644
View file @
f99e8747
/**
* @file creating_widgets.cpp
* @brief Creating custom widgets using VTK
* @author Ozan Cagri Tonkal
*/
#include <opencv2/viz.hpp>
#include <opencv2/viz/widget_accessor.hpp>
#include <iostream>
#include <vtkPoints.h>
#include <vtkTriangle.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkIdList.h>
#include <vtkActor.h>
#include <vtkProp.h>
using
namespace
cv
;
using
namespace
std
;
/**
* @function help
* @brief Display instructions to use this tutorial program
*/
void
help
()
{
cout
<<
"--------------------------------------------------------------------------"
<<
endl
<<
"This program shows how to create a custom widget. You can create your own "
<<
"widgets by extending Widget2D/Widget3D, and with the help of WidgetAccessor."
<<
endl
<<
"Usage:"
<<
endl
<<
"./creating_widgets"
<<
endl
<<
endl
;
}
/**
* @class TriangleWidget
* @brief Defining our own 3D Triangle widget
*/
class
TriangleWidget
:
public
viz
::
Widget3D
{
public
:
TriangleWidget
(
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
const
Point3f
&
pt3
,
const
viz
::
Color
&
color
=
viz
::
Color
::
white
());
};
/**
* @function TriangleWidget::TriangleWidget
* @brief Constructor
*/
TriangleWidget
::
TriangleWidget
(
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
const
Point3f
&
pt3
,
const
viz
::
Color
&
color
)
{
// Create a triangle
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
points
->
InsertNextPoint
(
pt1
.
x
,
pt1
.
y
,
pt1
.
z
);
points
->
InsertNextPoint
(
pt2
.
x
,
pt2
.
y
,
pt2
.
z
);
points
->
InsertNextPoint
(
pt3
.
x
,
pt3
.
y
,
pt3
.
z
);
vtkSmartPointer
<
vtkTriangle
>
triangle
=
vtkSmartPointer
<
vtkTriangle
>::
New
();
triangle
->
GetPointIds
()
->
SetId
(
0
,
0
);
triangle
->
GetPointIds
()
->
SetId
(
1
,
1
);
triangle
->
GetPointIds
()
->
SetId
(
2
,
2
);
vtkSmartPointer
<
vtkCellArray
>
cells
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
cells
->
InsertNextCell
(
triangle
);
// Create a polydata object
vtkSmartPointer
<
vtkPolyData
>
polyData
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
// Add the geometry and topology to the polydata
polyData
->
SetPoints
(
points
);
polyData
->
SetPolys
(
cells
);
// Create mapper and actor
vtkSmartPointer
<
vtkPolyDataMapper
>
mapper
=
vtkSmartPointer
<
vtkPolyDataMapper
>::
New
();
mapper
->
SetInput
(
polyData
);
vtkSmartPointer
<
vtkActor
>
actor
=
vtkSmartPointer
<
vtkActor
>::
New
();
actor
->
SetMapper
(
mapper
);
// Store this actor in the widget in order that visualizer can access it
viz
::
WidgetAccessor
::
setProp
(
*
this
,
actor
);
}
/**
* @function main
*/
int
main
()
{
help
();
/// Create a window
viz
::
Viz3d
myWindow
(
"Creating Widgets"
);
/// Create a triangle widget
TriangleWidget
tw
(
Point3f
(
0.0
,
0.0
,
0.0
),
Point3f
(
1.0
,
1.0
,
1.0
),
Point3f
(
0.0
,
1.0
,
0.0
));
/// Show widget in the visualizer window
myWindow
.
showWidget
(
"TRIANGLE"
,
tw
);
/// Start event loop
myWindow
.
spin
();
return
0
;
}
samples/cpp/tutorial_code/viz/launching_viz.cpp
View file @
f99e8747
/**
* @file launching_viz.cpp
* @brief Launching visualization window
* @author Ozan Cagri Tonkal
*/
#include <opencv2/viz.hpp>
#include <iostream>
using
namespace
cv
;
using
namespace
std
;
/**
* @function help
* @brief Display instructions to use this tutorial program
*/
void
help
()
{
cout
...
...
@@ -11,10 +21,13 @@ void help()
<<
"This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. "
<<
"You can access the same window via its name. You can run event loop for a given period of time. "
<<
endl
<<
"Usage:"
<<
endl
<<
"./
window_demo"
<<
endl
<<
"./
launching_viz"
<<
endl
<<
endl
;
}
/**
* @function main
*/
int
main
()
{
help
();
...
...
@@ -41,10 +54,10 @@ int main()
sameWindow
.
spinOnce
(
1
,
true
);
while
(
!
sameWindow
.
wasStopped
())
{
/// Interact with window
/// Event loop for 1 millisecond
sameWindow
.
spinOnce
(
1
,
true
);
/// Interact with window
/// Event loop for 1 millisecond
sameWindow
.
spinOnce
(
1
,
true
);
}
/// Once more event loop is stopped
...
...
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