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
26005a19
Commit
26005a19
authored
Sep 08, 2013
by
Ozan Tonkal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add license headers
parent
c7730614
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1533 additions
and
743 deletions
+1533
-743
viz.hpp
modules/viz/include/opencv2/viz.hpp
+1
-5
types.hpp
modules/viz/include/opencv2/viz/types.hpp
+61
-10
viz3d.hpp
modules/viz/include/opencv2/viz/viz3d.hpp
+55
-7
widget_accessor.hpp
modules/viz/include/opencv2/viz/widget_accessor.hpp
+53
-1
widgets.hpp
modules/viz/include/opencv2/viz/widgets.hpp
+53
-3
cloud_widgets.cpp
modules/viz/src/cloud_widgets.cpp
+181
-133
interactor_style.cpp
modules/viz/src/interactor_style.cpp
+253
-206
interactor_style.h
modules/viz/src/interactor_style.h
+80
-55
precomp.cpp
modules/viz/src/precomp.cpp
+49
-2
precomp.hpp
modules/viz/src/precomp.hpp
+52
-1
shape_widgets.cpp
modules/viz/src/shape_widgets.cpp
+181
-134
types.cpp
modules/viz/src/types.cpp
+71
-24
viz.cpp
modules/viz/src/viz.cpp
+51
-5
viz3d.cpp
modules/viz/src/viz3d.cpp
+53
-6
viz3d_impl.cpp
modules/viz/src/viz3d_impl.cpp
+165
-121
viz3d_impl.hpp
modules/viz/src/viz3d_impl.hpp
+78
-30
widget.cpp
modules/viz/src/widget.cpp
+48
-0
test_precomp.hpp
modules/viz/test/test_precomp.hpp
+48
-0
No files found.
modules/viz/include/opencv2/viz.hpp
View file @
26005a19
...
...
@@ -38,7 +38,7 @@
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal
// * Ozan Tonkal
, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
...
...
@@ -49,12 +49,10 @@
#ifndef __OPENCV_VIZ_HPP__
#define __OPENCV_VIZ_HPP__
#include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp>
#include <opencv2/viz/viz3d.hpp>
namespace
cv
{
namespace
viz
...
...
@@ -121,6 +119,4 @@ namespace cv
}
/* namespace viz */
}
/* namespace cv */
#endif
/* __OPENCV_VIZ_HPP__ */
modules/viz/include/opencv2/viz/types.hpp
View file @
26005a19
#pragma once
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifndef __OPENCV_VIZ_TYPES_HPP__
#define __OPENCV_VIZ_TYPES_HPP__
#include <string>
#include <opencv2/core.hpp>
...
...
@@ -55,17 +104,17 @@ namespace cv
//! Create a keyboard event
//! - Note that action is true if key is pressed, false if released
KeyboardEvent
(
bool
action
,
const
std
::
string
&
key_sym
,
unsigned
char
key
,
bool
alt
,
bool
ctrl
,
bool
shift
);
KeyboardEvent
(
bool
action
,
const
std
::
string
&
key_sym
,
unsigned
char
key
,
bool
alt
,
bool
ctrl
,
bool
shift
);
bool
isAltPressed
()
const
;
bool
isCtrlPressed
()
const
;
bool
isShiftPressed
()
const
;
bool
isAltPressed
()
const
;
bool
isCtrlPressed
()
const
;
bool
isShiftPressed
()
const
;
unsigned
char
getKeyCode
()
const
;
unsigned
char
getKeyCode
()
const
;
const
String
&
getKeySym
()
const
;
bool
keyDown
()
const
;
bool
keyUp
()
const
;
const
String
&
getKeySym
()
const
;
bool
keyDown
()
const
;
bool
keyUp
()
const
;
protected
:
...
...
@@ -81,7 +130,7 @@ namespace cv
enum
Type
{
MouseMove
=
1
,
MouseButtonPress
,
MouseButtonRelease
,
MouseScrollDown
,
MouseScrollUp
,
MouseDblClick
}
;
enum
MouseButton
{
NoButton
=
0
,
LeftButton
,
MiddleButton
,
RightButton
,
VScroll
}
;
MouseEvent
(
const
Type
&
type
,
const
MouseButton
&
button
,
const
Point
&
p
,
bool
alt
,
bool
ctrl
,
bool
shift
);
MouseEvent
(
const
Type
&
type
,
const
MouseButton
&
button
,
const
Point
&
p
,
bool
alt
,
bool
ctrl
,
bool
shift
);
Type
type
;
MouseButton
button
;
...
...
@@ -125,3 +174,5 @@ namespace cv
}
/* namespace viz */
}
/* namespace cv */
#endif
modules/viz/include/opencv2/viz/viz3d.hpp
View file @
26005a19
#pragma once
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifndef __OPENCV_VIZ_VIZ3D_HPP__
#define __OPENCV_VIZ_VIZ3D_HPP__
#if !defined YES_I_AGREE_THAT_VIZ_API_IS_NOT_STABLE_NOW_AND_BINARY_COMPARTIBILITY_WONT_BE_SUPPORTED
//#error "Viz is in beta state now. Please define macro above to use it"
...
...
@@ -38,7 +87,7 @@ namespace cv
Affine3f
getViewerPose
();
void
setViewerPose
(
const
Affine3f
&
pose
);
void
resetCameraViewpoint
(
const
String
&
id
);
void
resetCameraViewpoint
(
const
String
&
id
);
void
resetCamera
();
void
convertToWindowCoordinates
(
const
Point3d
&
pt
,
Point3d
&
window_coord
);
...
...
@@ -47,9 +96,9 @@ namespace cv
Size
getWindowSize
()
const
;
void
setWindowSize
(
const
Size
&
window_size
);
String
getWindowName
()
const
;
void
saveScreenshot
(
const
String
&
file
);
void
setWindowPosition
(
int
x
,
int
y
);
void
setFullScreen
(
bool
mode
);
void
saveScreenshot
(
const
String
&
file
);
void
setWindowPosition
(
int
x
,
int
y
);
void
setFullScreen
(
bool
mode
);
void
setBackgroundColor
(
const
Color
&
color
=
Color
::
black
());
void
spin
();
...
...
@@ -78,5 +127,4 @@ namespace cv
}
/* namespace viz */
}
/* namespace cv */
#endif
modules/viz/include/opencv2/viz/widget_accessor.hpp
View file @
26005a19
#pragma once
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifndef __OPENCV_VIZ_WIDGET_ACCESSOR_HPP__
#define __OPENCV_VIZ_WIDGET_ACCESSOR_HPP__
#include <opencv2/core/cvdef.h>
#include <vtkSmartPointer.h>
...
...
@@ -19,3 +68,5 @@ namespace cv
};
}
}
#endif
\ No newline at end of file
modules/viz/include/opencv2/viz/widgets.hpp
View file @
26005a19
#pragma once
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifndef __OPENCV_VIZ_WIDGETS_HPP__
#define __OPENCV_VIZ_WIDGETS_HPP__
#include <opencv2/viz/types.hpp>
...
...
@@ -305,4 +354,6 @@ namespace cv
template
<>
CV_EXPORTS
MeshWidget
Widget
::
cast
<
MeshWidget
>
();
}
/* namespace viz */
}
/* namespace cv */
\ No newline at end of file
}
/* namespace cv */
#endif
modules/viz/src/cloud_widgets.cpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
namespace
cv
...
...
@@ -15,10 +63,10 @@ struct cv::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
();
vtkSmartPointer
<
vtkPolyData
>
polydata
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkCellArray
>
vertices
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
polydata
->
SetVerts
(
vertices
);
polydata
->
SetVerts
(
vertices
);
vtkSmartPointer
<
vtkPoints
>
points
=
polydata
->
GetPoints
();
vtkSmartPointer
<
vtkIdTypeArray
>
initcells
;
...
...
@@ -26,14 +74,14 @@ struct cv::viz::CloudWidget::CreateCloudWidget
if
(
!
points
)
{
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
if
(
cloud
.
depth
()
==
CV_32F
)
points
->
SetDataTypeToFloat
();
else
if
(
cloud
.
depth
()
==
CV_64F
)
points
->
SetDataTypeToDouble
();
polydata
->
SetPoints
(
points
);
polydata
->
SetPoints
(
points
);
}
points
->
SetNumberOfPoints
(
nr_points
);
points
->
SetNumberOfPoints
(
nr_points
);
if
(
cloud
.
depth
()
==
CV_32F
)
{
...
...
@@ -49,51 +97,51 @@ struct cv::viz::CloudWidget::CreateCloudWidget
Vec3d
*
data_end
=
NanFilter
::
copy
(
cloud
,
data_beg
,
cloud
);
nr_points
=
data_end
-
data_beg
;
}
points
->
SetNumberOfPoints
(
nr_points
);
points
->
SetNumberOfPoints
(
nr_points
);
// Update cells
vtkSmartPointer
<
vtkIdTypeArray
>
cells
=
vertices
->
GetData
();
vtkSmartPointer
<
vtkIdTypeArray
>
cells
=
vertices
->
GetData
();
// If no init cells and cells has not been initialized...
if
(
!
cells
)
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If we have less values then we need to recreate the array
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
{
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If init cells is given, and there's enough data in it, use it
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
{
cells
->
DeepCopy
(
initcells
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
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
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
vtkIdType
*
cell
=
cells
->
GetPointer
(
0
);
// Fill it with 1s
std
::
fill_n
(
cell
,
nr_points
*
2
,
1
);
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
);
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
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
}
// Set the cells and the vertices
vertices
->
SetCells
(
nr_points
,
cells
);
vertices
->
SetCells
(
nr_points
,
cells
);
return
polydata
;
}
};
...
...
@@ -118,33 +166,33 @@ cv::viz::CloudWidget::CloudWidget(InputArray _cloud, InputArray _colors)
Vec3b
*
colors_data
=
new
Vec3b
[
nr_points
];
NanFilter
::
copyColor
(
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
);
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
);
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polydata
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polydata
);
Vec3d
minmax
(
scalars
->
GetRange
());
mapper
->
SetScalarRange
(
minmax
.
val
);
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetScalarModeToUsePointData
();
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOn
();
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOn
();
mapper
->
ImmediateModeRenderingOff
();
mapper
->
ImmediateModeRenderingOff
();
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
WidgetAccessor
::
setProp
(
*
this
,
actor
);
}
...
...
@@ -157,21 +205,21 @@ cv::viz::CloudWidget::CloudWidget(InputArray _cloud, const Color &color)
vtkIdType
nr_points
;
vtkSmartPointer
<
vtkPolyData
>
polydata
=
CreateCloudWidget
::
create
(
cloud
,
nr_points
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polydata
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polydata
);
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOff
();
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOff
();
mapper
->
ImmediateModeRenderingOff
();
mapper
->
ImmediateModeRenderingOff
();
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
WidgetAccessor
::
setProp
(
*
this
,
actor
);
setColor
(
color
);
...
...
@@ -190,10 +238,10 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget
{
static
inline
vtkSmartPointer
<
vtkPolyData
>
create
(
const
Mat
&
cloud
,
vtkIdType
&
nr_points
)
{
vtkSmartPointer
<
vtkPolyData
>
polydata
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkCellArray
>
vertices
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
vtkSmartPointer
<
vtkPolyData
>
polydata
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkCellArray
>
vertices
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
polydata
->
SetVerts
(
vertices
);
polydata
->
SetVerts
(
vertices
);
vtkSmartPointer
<
vtkPoints
>
points
=
polydata
->
GetPoints
();
vtkSmartPointer
<
vtkIdTypeArray
>
initcells
;
...
...
@@ -201,14 +249,14 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget
if
(
!
points
)
{
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
if
(
cloud
.
depth
()
==
CV_32F
)
points
->
SetDataTypeToFloat
();
else
if
(
cloud
.
depth
()
==
CV_64F
)
points
->
SetDataTypeToDouble
();
polydata
->
SetPoints
(
points
);
polydata
->
SetPoints
(
points
);
}
points
->
SetNumberOfPoints
(
nr_points
);
points
->
SetNumberOfPoints
(
nr_points
);
if
(
cloud
.
depth
()
==
CV_32F
)
{
...
...
@@ -224,51 +272,51 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget
Vec3d
*
data_end
=
NanFilter
::
copy
(
cloud
,
data_beg
,
cloud
);
nr_points
=
data_end
-
data_beg
;
}
points
->
SetNumberOfPoints
(
nr_points
);
points
->
SetNumberOfPoints
(
nr_points
);
// Update cells
vtkSmartPointer
<
vtkIdTypeArray
>
cells
=
vertices
->
GetData
();
vtkSmartPointer
<
vtkIdTypeArray
>
cells
=
vertices
->
GetData
();
// If no init cells and cells has not been initialized...
if
(
!
cells
)
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If we have less values then we need to recreate the array
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
{
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If init cells is given, and there's enough data in it, use it
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
{
cells
->
DeepCopy
(
initcells
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
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
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
vtkIdType
*
cell
=
cells
->
GetPointer
(
0
);
// Fill it with 1s
std
::
fill_n
(
cell
,
nr_points
*
2
,
1
);
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
);
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
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
}
// Set the cells and the vertices
vertices
->
SetCells
(
nr_points
,
cells
);
vertices
->
SetCells
(
nr_points
,
cells
);
return
polydata
;
}
...
...
@@ -278,19 +326,19 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget
if
(
!
mapper
)
{
// This is the first cloud
vtkSmartPointer
<
vtkDataSetMapper
>
mapper_new
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper_new
->
SetInputConnection
(
poly_data
->
GetProducerPort
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper_new
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper_new
->
SetInputConnection
(
poly_data
->
GetProducerPort
());
mapper_new
->
SetScalarRange
(
minmax
.
val
);
mapper_new
->
SetScalarModeToUsePointData
();
mapper_new
->
SetScalarModeToUsePointData
();
bool
interpolation
=
(
poly_data
&&
poly_data
->
GetNumberOfCells
()
!=
poly_data
->
GetNumberOfVerts
());
bool
interpolation
=
(
poly_data
&&
poly_data
->
GetNumberOfCells
()
!=
poly_data
->
GetNumberOfVerts
());
mapper_new
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper_new
->
ScalarVisibilityOn
();
mapper_new
->
ImmediateModeRenderingOff
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
poly_data
->
GetNumberOfPoints
()
/
10
)));
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
poly_data
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper_new
);
...
...
@@ -307,7 +355,7 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget
// Update the number of cloud points
vtkIdType
old_cloud_points
=
actor
->
GetNumberOfCloudPoints
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
old_cloud_points
+
poly_data
->
GetNumberOfPoints
()
/
10
)));
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
old_cloud_points
+
poly_data
->
GetNumberOfPoints
()
/
10
)));
}
};
...
...
@@ -338,13 +386,13 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, InputArray _col
Vec3b
*
colors_data
=
new
Vec3b
[
nr_points
];
NanFilter
::
copyColor
(
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
);
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
);
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
// Transform the poly data based on the pose
vtkSmartPointer
<
vtkTransform
>
transform
=
vtkSmartPointer
<
vtkTransform
>::
New
();
...
...
@@ -371,15 +419,15 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, const Color &co
vtkIdType
nr_points
;
vtkSmartPointer
<
vtkPolyData
>
polydata
=
CreateCloudWidget
::
create
(
cloud
,
nr_points
);
vtkSmartPointer
<
vtkUnsignedCharArray
>
scalars
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
scalars
->
SetNumberOfComponents
(
3
);
scalars
->
SetNumberOfTuples
(
nr_points
);
vtkSmartPointer
<
vtkUnsignedCharArray
>
scalars
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
scalars
->
SetNumberOfComponents
(
3
);
scalars
->
SetNumberOfTuples
(
nr_points
);
scalars
->
FillComponent
(
0
,
color
[
2
]);
scalars
->
FillComponent
(
1
,
color
[
1
]);
scalars
->
FillComponent
(
2
,
color
[
0
]);
// Assign the colors
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
// Transform the poly data based on the pose
vtkSmartPointer
<
vtkTransform
>
transform
=
vtkSmartPointer
<
vtkTransform
>::
New
();
...
...
@@ -415,8 +463,8 @@ struct cv::viz::CloudNormalsWidget::ApplyCloudNormals
static
vtkSmartPointer
<
vtkCellArray
>
applyOrganized
(
const
Mat
&
cloud
,
const
Mat
&
normals
,
double
level
,
float
scale
,
_Tp
*&
pts
,
vtkIdType
&
nr_normals
)
{
vtkIdType
point_step
=
static_cast
<
vtkIdType
>
(
std
::
sqrt
(
level
));
nr_normals
=
(
static_cast
<
vtkIdType
>
((
cloud
.
cols
-
1
)
/
point_step
)
+
1
)
*
(
static_cast
<
vtkIdType
>
((
cloud
.
rows
-
1
)
/
point_step
)
+
1
);
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
];
...
...
@@ -436,9 +484,9 @@ struct cv::viz::CloudNormalsWidget::ApplyCloudNormals
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
);
lines
->
InsertNextCell
(
2
);
lines
->
InsertCellPoint
(
2
*
cell_count
);
lines
->
InsertCellPoint
(
2
*
cell_count
+
1
);
cell_count
++
;
}
}
...
...
@@ -464,9 +512,9 @@ struct cv::viz::CloudNormalsWidget::ApplyCloudNormals
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
);
lines
->
InsertNextCell
(
2
);
lines
->
InsertCellPoint
(
2
*
j
);
lines
->
InsertCellPoint
(
2
*
j
+
1
);
}
return
lines
;
}
...
...
@@ -497,33 +545,33 @@ cv::viz::CloudNormalsWidget::CloudNormalsWidget(InputArray _cloud, InputArray _n
{
points
->
SetDataTypeToFloat
();
vtkSmartPointer
<
vtkFloatArray
>
data
=
vtkSmartPointer
<
vtkFloatArray
>::
New
();
data
->
SetNumberOfComponents
(
3
);
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
);
data
->
SetArray
(
&
pts
[
0
],
2
*
nr_normals
*
3
,
0
);
points
->
SetData
(
data
);
}
else
{
points
->
SetDataTypeToDouble
();
vtkSmartPointer
<
vtkDoubleArray
>
data
=
vtkSmartPointer
<
vtkDoubleArray
>::
New
();
data
->
SetNumberOfComponents
(
3
);
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
);
data
->
SetArray
(
&
pts
[
0
],
2
*
nr_normals
*
3
,
0
);
points
->
SetData
(
data
);
}
vtkSmartPointer
<
vtkPolyData
>
polyData
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
polyData
->
SetPoints
(
points
);
polyData
->
SetLines
(
lines
);
polyData
->
SetPoints
(
points
);
polyData
->
SetLines
(
lines
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polyData
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
polyData
);
mapper
->
SetColorModeToMapScalars
();
mapper
->
SetScalarModeToUsePointData
();
...
...
@@ -558,7 +606,7 @@ struct cv::viz::MeshWidget::CopyImpl
const
_Tp
*
srow
=
source
.
ptr
<
_Tp
>
(
0
);
const
_Tp
*
mrow
=
nan_mask
.
ptr
<
_Tp
>
(
0
);
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
mrow
+=
m_chs
)
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
mrow
+=
m_chs
)
{
if
(
!
isNan
(
mrow
[
0
])
&&
!
isNan
(
mrow
[
1
])
&&
!
isNan
(
mrow
[
2
]))
{
...
...
@@ -577,11 +625,11 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh)
CV_Assert
(
mesh
.
colors
.
empty
()
||
(
mesh
.
colors
.
type
()
==
CV_8UC3
&&
mesh
.
cloud
.
size
()
==
mesh
.
colors
.
size
()));
CV_Assert
(
!
mesh
.
polygons
.
empty
()
&&
mesh
.
polygons
.
type
()
==
CV_32SC1
);
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
vtkIdType
nr_points
=
mesh
.
cloud
.
total
();
Mat
look_up_mat
(
1
,
nr_points
,
CV_32SC1
);
int
*
look_up
=
look_up_mat
.
ptr
<
int
>
();
points
->
SetNumberOfPoints
(
nr_points
);
points
->
SetNumberOfPoints
(
nr_points
);
// Copy data from cloud to vtkPoints
if
(
mesh
.
cloud
.
depth
()
==
CV_32F
)
...
...
@@ -607,10 +655,10 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh)
colors_data
=
new
Vec3b
[
nr_points
];
NanFilter
::
copyColor
(
mesh
.
colors
,
colors_data
,
mesh
.
cloud
);
scalars
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
scalars
->
SetNumberOfComponents
(
3
);
scalars
->
SetNumberOfTuples
(
nr_points
);
scalars
->
SetArray
(
colors_data
->
val
,
3
*
nr_points
,
0
);
scalars
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
scalars
->
SetNumberOfComponents
(
3
);
scalars
->
SetNumberOfTuples
(
nr_points
);
scalars
->
SetArray
(
colors_data
->
val
,
3
*
nr_points
,
0
);
}
points
->
SetNumberOfPoints
(
nr_points
);
...
...
@@ -633,36 +681,36 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh)
cell_array
->
InsertCellPoint
(
look_up
[
polygons
[
i
++
]]);
}
vtkSmartPointer
<
vtkPolyData
>
polydata
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
cell_array
->
GetData
()
->
SetNumberOfValues
(
idx
);
cell_array
->
Squeeze
();
polydata
->
SetStrips
(
cell_array
);
polydata
->
SetPoints
(
points
);
cell_array
->
GetData
()
->
SetNumberOfValues
(
idx
);
cell_array
->
Squeeze
();
polydata
->
SetStrips
(
cell_array
);
polydata
->
SetPoints
(
points
);
if
(
scalars
)
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
data
=
polydata
;
}
else
{
// Only one polygon
vtkSmartPointer
<
vtkPolygon
>
polygon
=
vtkSmartPointer
<
vtkPolygon
>::
New
();
vtkSmartPointer
<
vtkPolygon
>
polygon
=
vtkSmartPointer
<
vtkPolygon
>::
New
();
const
int
*
polygons
=
mesh
.
polygons
.
ptr
<
int
>
();
int
n_points
=
polygons
[
0
];
polygon
->
GetPointIds
()
->
SetNumberOfIds
(
n_points
);
for
(
int
j
=
1
;
j
<
n_points
+
1
;
++
j
)
polygon
->
GetPointIds
()
->
SetId
(
j
,
look_up
[
polygons
[
j
]]);
polygon
->
GetPointIds
()
->
SetId
(
j
,
look_up
[
polygons
[
j
]]);
vtkSmartPointer
<
vtkUnstructuredGrid
>
poly_grid
=
vtkSmartPointer
<
vtkUnstructuredGrid
>::
New
();
poly_grid
->
Allocate
(
1
,
1
);
poly_grid
->
InsertNextCell
(
polygon
->
GetCellType
(),
polygon
->
GetPointIds
());
poly_grid
->
SetPoints
(
points
);
poly_grid
->
Update
();
poly_grid
->
Allocate
(
1
,
1
);
poly_grid
->
InsertNextCell
(
polygon
->
GetCellType
(),
polygon
->
GetPointIds
());
poly_grid
->
SetPoints
(
points
);
poly_grid
->
Update
();
if
(
scalars
)
poly_grid
->
GetPointData
()
->
SetScalars
(
scalars
);
poly_grid
->
GetPointData
()
->
SetScalars
(
scalars
);
data
=
poly_grid
;
}
...
...
@@ -675,13 +723,13 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh)
actor
->
GetProperty
()
->
EdgeVisibilityOff
();
actor
->
GetProperty
()
->
ShadingOff
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
data
);
mapper
->
ImmediateModeRenderingOff
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
data
);
mapper
->
ImmediateModeRenderingOff
();
vtkIdType
numberOfCloudPoints
=
nr_points
*
0.1
;
actor
->
SetNumberOfCloudPoints
(
int
(
numberOfCloudPoints
>
1
?
numberOfCloudPoints
:
1
));
actor
->
SetMapper
(
mapper
);
actor
->
SetNumberOfCloudPoints
(
int
(
numberOfCloudPoints
>
1
?
numberOfCloudPoints
:
1
));
actor
->
SetMapper
(
mapper
);
WidgetAccessor
::
setProp
(
*
this
,
actor
);
}
...
...
modules/viz/src/interactor_style.cpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
#include "interactor_style.h"
using
namespace
cv
;
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
Initialize
()
void
cv
::
viz
::
InteractorStyle
::
Initialize
()
{
modifier_
=
cv
::
viz
::
InteractorStyle
::
KB_MOD_ALT
;
// Set windows size (width, height) to unknown (-1)
...
...
@@ -13,9 +61,9 @@ void cv::viz::InteractorStyle::Initialize ()
max_win_size_
=
Vec2i
(
-
1
,
-
1
);
// Create the image filter and PNG writer objects
wif_
=
vtkSmartPointer
<
vtkWindowToImageFilter
>::
New
();
snapshot_writer_
=
vtkSmartPointer
<
vtkPNGWriter
>::
New
();
snapshot_writer_
->
SetInputConnection
(
wif_
->
GetOutputPort
());
wif_
=
vtkSmartPointer
<
vtkWindowToImageFilter
>::
New
();
snapshot_writer_
=
vtkSmartPointer
<
vtkPNGWriter
>::
New
();
snapshot_writer_
->
SetInputConnection
(
wif_
->
GetOutputPort
());
init_
=
true
;
stereo_anaglyph_mask_default_
=
true
;
...
...
@@ -30,72 +78,72 @@ void cv::viz::InteractorStyle::Initialize ()
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
saveScreenshot
(
const
std
::
string
&
file
)
void
cv
::
viz
::
InteractorStyle
::
saveScreenshot
(
const
std
::
string
&
file
)
{
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
wif_
->
SetInput
(
Interactor
->
GetRenderWindow
());
wif_
->
Modified
();
// Update the WindowToImageFilter
snapshot_writer_
->
Modified
();
snapshot_writer_
->
SetFileName
(
file
.
c_str
());
snapshot_writer_
->
Write
();
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
wif_
->
SetInput
(
Interactor
->
GetRenderWindow
());
wif_
->
Modified
();
// Update the WindowToImageFilter
snapshot_writer_
->
Modified
();
snapshot_writer_
->
SetFileName
(
file
.
c_str
());
snapshot_writer_
->
Write
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
zoomIn
()
void
cv
::
viz
::
InteractorStyle
::
zoomIn
()
{
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
// Zoom in
StartDolly
();
StartDolly
();
double
factor
=
10.0
*
0.2
*
.5
;
Dolly
(
std
::
pow
(
1.1
,
factor
));
EndDolly
();
Dolly
(
std
::
pow
(
1.1
,
factor
));
EndDolly
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
zoomOut
()
void
cv
::
viz
::
InteractorStyle
::
zoomOut
()
{
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
// Zoom out
StartDolly
();
StartDolly
();
double
factor
=
10.0
*
-
0.2
*
.5
;
Dolly
(
std
::
pow
(
1.1
,
factor
));
EndDolly
();
Dolly
(
std
::
pow
(
1.1
,
factor
));
EndDolly
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnChar
()
void
cv
::
viz
::
InteractorStyle
::
OnChar
()
{
// Make sure we ignore the same events we handle in OnKeyDown to avoid calling things twice
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
if
(
Interactor
->
GetKeyCode
()
>=
'0'
&&
Interactor
->
GetKeyCode
()
<=
'9'
)
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
if
(
Interactor
->
GetKeyCode
()
>=
'0'
&&
Interactor
->
GetKeyCode
()
<=
'9'
)
return
;
std
::
string
key
(
Interactor
->
GetKeySym
());
if
(
key
.
find
(
"XF86ZoomIn"
)
!=
std
::
string
::
npos
)
zoomIn
();
else
if
(
key
.
find
(
"XF86ZoomOut"
)
!=
std
::
string
::
npos
)
zoomOut
();
std
::
string
key
(
Interactor
->
GetKeySym
());
if
(
key
.
find
(
"XF86ZoomIn"
)
!=
std
::
string
::
npos
)
zoomIn
();
else
if
(
key
.
find
(
"XF86ZoomOut"
)
!=
std
::
string
::
npos
)
zoomOut
();
int
keymod
=
false
;
switch
(
modifier_
)
{
case
KB_MOD_ALT
:
{
keymod
=
Interactor
->
GetAltKey
();
keymod
=
Interactor
->
GetAltKey
();
break
;
}
case
KB_MOD_CTRL
:
{
keymod
=
Interactor
->
GetControlKey
();
keymod
=
Interactor
->
GetControlKey
();
break
;
}
case
KB_MOD_SHIFT
:
{
keymod
=
Interactor
->
GetShiftKey
();
keymod
=
Interactor
->
GetShiftKey
();
break
;
}
}
switch
(
Interactor
->
GetKeyCode
())
switch
(
Interactor
->
GetKeyCode
())
{
// All of the options below simply exit
case
'h'
:
case
'H'
:
...
...
@@ -118,12 +166,12 @@ void cv::viz::InteractorStyle::OnChar ()
case
's'
:
case
'S'
:
{
if
(
!
keymod
)
Superclass
::
OnChar
();
Superclass
::
OnChar
();
break
;
}
default
:
{
Superclass
::
OnChar
();
Superclass
::
OnChar
();
break
;
}
}
...
...
@@ -147,30 +195,30 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnKeyDown
()
cv
::
viz
::
InteractorStyle
::
OnKeyDown
()
{
CV_Assert
(
"Interactor style not initialized. Please call Initialize
() before continuing"
&&
init_
);
CV_Assert
(
"No renderer given! Use SetRendererCollection
() before continuing."
&&
renderer_
);
CV_Assert
(
"Interactor style not initialized. Please call Initialize() before continuing"
&&
init_
);
CV_Assert
(
"No renderer given! Use SetRendererCollection() before continuing."
&&
renderer_
);
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
FindPokedRenderer
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
]);
if
(
wif_
->
GetInput
()
==
NULL
)
if
(
wif_
->
GetInput
()
==
NULL
)
{
wif_
->
SetInput
(
Interactor
->
GetRenderWindow
());
wif_
->
Modified
();
snapshot_writer_
->
Modified
();
wif_
->
SetInput
(
Interactor
->
GetRenderWindow
());
wif_
->
Modified
();
snapshot_writer_
->
Modified
();
}
// Save the initial windows width/height
if
(
win_size_
[
0
]
==
-
1
||
win_size_
[
1
]
==
-
1
)
win_size_
=
Vec2i
(
Interactor
->
GetRenderWindow
()
->
GetSize
());
win_size_
=
Vec2i
(
Interactor
->
GetRenderWindow
()
->
GetSize
());
// Get the status of special keys (Cltr+Alt+Shift)
bool
shift
=
Interactor
->
GetShiftKey
();
bool
ctrl
=
Interactor
->
GetControlKey
();
bool
alt
=
Interactor
->
GetAltKey
();
bool
shift
=
Interactor
->
GetShiftKey
();
bool
ctrl
=
Interactor
->
GetControlKey
();
bool
alt
=
Interactor
->
GetAltKey
();
bool
keymod
=
false
;
switch
(
modifier_
)
...
...
@@ -180,13 +228,13 @@ cv::viz::InteractorStyle::OnKeyDown ()
case
KB_MOD_SHIFT
:
keymod
=
shift
;
break
;
}
std
::
string
key
(
Interactor
->
GetKeySym
());
if
(
key
.
find
(
"XF86ZoomIn"
)
!=
std
::
string
::
npos
)
zoomIn
();
else
if
(
key
.
find
(
"XF86ZoomOut"
)
!=
std
::
string
::
npos
)
zoomOut
();
std
::
string
key
(
Interactor
->
GetKeySym
());
if
(
key
.
find
(
"XF86ZoomIn"
)
!=
std
::
string
::
npos
)
zoomIn
();
else
if
(
key
.
find
(
"XF86ZoomOut"
)
!=
std
::
string
::
npos
)
zoomOut
();
switch
(
Interactor
->
GetKeyCode
())
switch
(
Interactor
->
GetKeyCode
())
{
case
'h'
:
case
'H'
:
{
...
...
@@ -218,14 +266,14 @@ cv::viz::InteractorStyle::OnKeyDown ()
// Switch representation to points
case
'p'
:
case
'P'
:
{
vtkSmartPointer
<
vtkActorCollection
>
ac
=
CurrentRenderer
->
GetActors
();
vtkSmartPointer
<
vtkActorCollection
>
ac
=
CurrentRenderer
->
GetActors
();
vtkCollectionSimpleIterator
ait
;
for
(
ac
->
InitTraversal
(
ait
);
vtkActor
*
actor
=
ac
->
GetNextActor
(
ait
);
)
for
(
ac
->
InitTraversal
(
ait
);
vtkActor
*
actor
=
ac
->
GetNextActor
(
ait
);
)
{
for
(
actor
->
InitPathTraversal
();
vtkAssemblyPath
*
path
=
actor
->
GetNextPath
();
)
for
(
actor
->
InitPathTraversal
();
vtkAssemblyPath
*
path
=
actor
->
GetNextPath
();
)
{
vtkActor
*
apart
=
reinterpret_cast
<
vtkActor
*>
(
path
->
GetLastNode
()
->
GetViewProp
());
apart
->
GetProperty
()
->
SetRepresentationToPoints
();
vtkActor
*
apart
=
reinterpret_cast
<
vtkActor
*>
(
path
->
GetLastNode
()
->
GetViewProp
());
apart
->
GetProperty
()
->
SetRepresentationToPoints
();
}
}
break
;
...
...
@@ -234,27 +282,27 @@ cv::viz::InteractorStyle::OnKeyDown ()
case
'j'
:
case
'J'
:
{
char
cam_fn
[
80
],
snapshot_fn
[
80
];
unsigned
t
=
static_cast
<
unsigned
>
(
time
(
0
));
sprintf
(
snapshot_fn
,
"screenshot-%d.png"
,
t
);
saveScreenshot
(
snapshot_fn
);
unsigned
t
=
static_cast
<
unsigned
>
(
time
(
0
));
sprintf
(
snapshot_fn
,
"screenshot-%d.png"
,
t
);
saveScreenshot
(
snapshot_fn
);
sprintf
(
cam_fn
,
"screenshot-%d.cam"
,
t
);
sprintf
(
cam_fn
,
"screenshot-%d.cam"
,
t
);
ofstream
ofs_cam
;
ofs_cam
.
open
(
cam_fn
);
vtkSmartPointer
<
vtkCamera
>
cam
=
Interactor
->
GetRenderWindow
()
->
GetRenderers
()
->
GetFirstRenderer
()
->
GetActiveCamera
();
ofs_cam
.
open
(
cam_fn
);
vtkSmartPointer
<
vtkCamera
>
cam
=
Interactor
->
GetRenderWindow
()
->
GetRenderers
()
->
GetFirstRenderer
()
->
GetActiveCamera
();
double
clip
[
2
],
focal
[
3
],
pos
[
3
],
view
[
3
];
cam
->
GetClippingRange
(
clip
);
cam
->
GetFocalPoint
(
focal
);
cam
->
GetPosition
(
pos
);
cam
->
GetViewUp
(
view
);
cam
->
GetClippingRange
(
clip
);
cam
->
GetFocalPoint
(
focal
);
cam
->
GetPosition
(
pos
);
cam
->
GetViewUp
(
view
);
int
*
win_pos
=
Interactor
->
GetRenderWindow
()
->
GetPosition
();
int
*
win_size
=
Interactor
->
GetRenderWindow
()
->
GetSize
();
int
*
win_pos
=
Interactor
->
GetRenderWindow
()
->
GetPosition
();
int
*
win_size
=
Interactor
->
GetRenderWindow
()
->
GetSize
();
ofs_cam
<<
clip
[
0
]
<<
","
<<
clip
[
1
]
<<
"/"
<<
focal
[
0
]
<<
","
<<
focal
[
1
]
<<
","
<<
focal
[
2
]
<<
"/"
<<
pos
[
0
]
<<
","
<<
pos
[
1
]
<<
","
<<
pos
[
2
]
<<
"/"
<<
view
[
0
]
<<
","
<<
view
[
1
]
<<
","
<<
view
[
2
]
<<
"/"
<<
cam
->
GetViewAngle
()
/
180.0
*
CV_PI
<<
"/"
<<
win_size
[
0
]
<<
","
<<
win_size
[
1
]
<<
"/"
<<
win_pos
[
0
]
<<
","
<<
win_pos
[
1
]
cam
->
GetViewAngle
()
/
180.0
*
CV_PI
<<
"/"
<<
win_size
[
0
]
<<
","
<<
win_size
[
1
]
<<
"/"
<<
win_pos
[
0
]
<<
","
<<
win_pos
[
1
]
<<
endl
;
ofs_cam
.
close
();
ofs_cam
.
close
();
std
::
cout
<<
"Screenshot ("
<<
snapshot_fn
<<
") and camera information ("
<<
cam_fn
<<
") successfully captured."
<<
std
::
endl
;
break
;
...
...
@@ -262,14 +310,14 @@ cv::viz::InteractorStyle::OnKeyDown ()
// display current camera settings/parameters
case
'c'
:
case
'C'
:
{
vtkSmartPointer
<
vtkCamera
>
cam
=
Interactor
->
GetRenderWindow
()
->
GetRenderers
()
->
GetFirstRenderer
()
->
GetActiveCamera
();
vtkSmartPointer
<
vtkCamera
>
cam
=
Interactor
->
GetRenderWindow
()
->
GetRenderers
()
->
GetFirstRenderer
()
->
GetActiveCamera
();
Vec2d
clip
;
Vec3d
focal
,
pose
,
view
;
cam
->
GetClippingRange
(
clip
.
val
);
cam
->
GetFocalPoint
(
focal
.
val
);
cam
->
GetPosition
(
pose
.
val
);
cam
->
GetViewUp
(
view
.
val
);
cam
->
GetClippingRange
(
clip
.
val
);
cam
->
GetFocalPoint
(
focal
.
val
);
cam
->
GetPosition
(
pose
.
val
);
cam
->
GetViewUp
(
view
.
val
);
Vec2i
win_pos
(
Interactor
->
GetRenderWindow
()
->
GetPosition
());
Vec2i
win_size
(
Interactor
->
GetRenderWindow
()
->
GetSize
());
...
...
@@ -286,20 +334,20 @@ cv::viz::InteractorStyle::OnKeyDown ()
}
case
43
:
// KEY_PLUS
{
if
(
alt
)
zoomIn
();
if
(
alt
)
zoomIn
();
else
{
vtkSmartPointer
<
vtkActorCollection
>
ac
=
CurrentRenderer
->
GetActors
();
vtkSmartPointer
<
vtkActorCollection
>
ac
=
CurrentRenderer
->
GetActors
();
vtkCollectionSimpleIterator
ait
;
for
(
ac
->
InitTraversal
(
ait
);
vtkActor
*
actor
=
ac
->
GetNextActor
(
ait
);
)
for
(
ac
->
InitTraversal
(
ait
);
vtkActor
*
actor
=
ac
->
GetNextActor
(
ait
);
)
{
for
(
actor
->
InitPathTraversal
();
vtkAssemblyPath
*
path
=
actor
->
GetNextPath
();
)
for
(
actor
->
InitPathTraversal
();
vtkAssemblyPath
*
path
=
actor
->
GetNextPath
();
)
{
vtkActor
*
apart
=
reinterpret_cast
<
vtkActor
*>
(
path
->
GetLastNode
()
->
GetViewProp
());
float
psize
=
apart
->
GetProperty
()
->
GetPointSize
();
vtkActor
*
apart
=
reinterpret_cast
<
vtkActor
*>
(
path
->
GetLastNode
()
->
GetViewProp
());
float
psize
=
apart
->
GetProperty
()
->
GetPointSize
();
if
(
psize
<
63.0
f
)
apart
->
GetProperty
()
->
SetPointSize
(
psize
+
1.0
f
);
apart
->
GetProperty
()
->
SetPointSize
(
psize
+
1.0
f
);
}
}
}
...
...
@@ -307,20 +355,20 @@ cv::viz::InteractorStyle::OnKeyDown ()
}
case
45
:
// KEY_MINUS
{
if
(
alt
)
zoomOut
();
if
(
alt
)
zoomOut
();
else
{
vtkSmartPointer
<
vtkActorCollection
>
ac
=
CurrentRenderer
->
GetActors
();
vtkSmartPointer
<
vtkActorCollection
>
ac
=
CurrentRenderer
->
GetActors
();
vtkCollectionSimpleIterator
ait
;
for
(
ac
->
InitTraversal
(
ait
);
vtkActor
*
actor
=
ac
->
GetNextActor
(
ait
);
)
for
(
ac
->
InitTraversal
(
ait
);
vtkActor
*
actor
=
ac
->
GetNextActor
(
ait
);
)
{
for
(
actor
->
InitPathTraversal
();
vtkAssemblyPath
*
path
=
actor
->
GetNextPath
();
)
for
(
actor
->
InitPathTraversal
();
vtkAssemblyPath
*
path
=
actor
->
GetNextPath
();
)
{
vtkActor
*
apart
=
static_cast
<
vtkActor
*>
(
path
->
GetLastNode
()
->
GetViewProp
());
float
psize
=
apart
->
GetProperty
()
->
GetPointSize
();
vtkActor
*
apart
=
static_cast
<
vtkActor
*>
(
path
->
GetLastNode
()
->
GetViewProp
());
float
psize
=
apart
->
GetProperty
()
->
GetPointSize
();
if
(
psize
>
1.0
f
)
apart
->
GetProperty
()
->
SetPointSize
(
psize
-
1.0
f
);
apart
->
GetProperty
()
->
SetPointSize
(
psize
-
1.0
f
);
}
}
}
...
...
@@ -331,39 +379,39 @@ cv::viz::InteractorStyle::OnKeyDown ()
{
if
(
keymod
)
{
Vec2i
screen_size
(
Interactor
->
GetRenderWindow
()
->
GetScreenSize
());
Vec2i
win_size
(
Interactor
->
GetRenderWindow
()
->
GetSize
());
Vec2i
screen_size
(
Interactor
->
GetRenderWindow
()
->
GetScreenSize
());
Vec2i
win_size
(
Interactor
->
GetRenderWindow
()
->
GetSize
());
// Is window size = max?
if
(
win_size
==
max_win_size_
)
{
Interactor
->
GetRenderWindow
()
->
SetSize
(
win_size_
.
val
);
Interactor
->
GetRenderWindow
()
->
SetPosition
(
win_pos_
.
val
);
Interactor
->
GetRenderWindow
()
->
Render
();
Interactor
->
Render
();
Interactor
->
GetRenderWindow
()
->
SetSize
(
win_size_
.
val
);
Interactor
->
GetRenderWindow
()
->
SetPosition
(
win_pos_
.
val
);
Interactor
->
GetRenderWindow
()
->
Render
();
Interactor
->
Render
();
}
// Set to max
else
{
win_pos_
=
Vec2i
(
Interactor
->
GetRenderWindow
()
->
GetPosition
());
win_pos_
=
Vec2i
(
Interactor
->
GetRenderWindow
()
->
GetPosition
());
win_size_
=
win_size
;
Interactor
->
GetRenderWindow
()
->
SetSize
(
screen_size
.
val
);
Interactor
->
GetRenderWindow
()
->
Render
();
Interactor
->
Render
();
max_win_size_
=
Vec2i
(
Interactor
->
GetRenderWindow
()
->
GetSize
());
Interactor
->
GetRenderWindow
()
->
SetSize
(
screen_size
.
val
);
Interactor
->
GetRenderWindow
()
->
Render
();
Interactor
->
Render
();
max_win_size_
=
Vec2i
(
Interactor
->
GetRenderWindow
()
->
GetSize
());
}
}
else
{
AnimState
=
VTKIS_ANIM_ON
;
vtkAssemblyPath
*
path
=
NULL
;
Interactor
->
GetPicker
()
->
Pick
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
],
0.0
,
CurrentRenderer
);
Interactor
->
GetPicker
()
->
Pick
(
Interactor
->
GetEventPosition
()[
0
],
Interactor
->
GetEventPosition
()[
1
],
0.0
,
CurrentRenderer
);
vtkAbstractPropPicker
*
picker
;
if
((
picker
=
vtkAbstractPropPicker
::
SafeDownCast
(
Interactor
->
GetPicker
())))
path
=
picker
->
GetPath
();
if
((
picker
=
vtkAbstractPropPicker
::
SafeDownCast
(
Interactor
->
GetPicker
())))
path
=
picker
->
GetPath
();
if
(
path
!=
NULL
)
Interactor
->
FlyTo
(
CurrentRenderer
,
picker
->
GetPickPosition
());
Interactor
->
FlyTo
(
CurrentRenderer
,
picker
->
GetPickPosition
());
AnimState
=
VTKIS_ANIM_OFF
;
}
break
;
...
...
@@ -373,37 +421,37 @@ cv::viz::InteractorStyle::OnKeyDown ()
{
if
(
keymod
)
{
int
stereo_render
=
Interactor
->
GetRenderWindow
()
->
GetStereoRender
();
int
stereo_render
=
Interactor
->
GetRenderWindow
()
->
GetStereoRender
();
if
(
!
stereo_render
)
{
if
(
stereo_anaglyph_mask_default_
)
{
Interactor
->
GetRenderWindow
()
->
SetAnaglyphColorMask
(
4
,
3
);
Interactor
->
GetRenderWindow
()
->
SetAnaglyphColorMask
(
4
,
3
);
stereo_anaglyph_mask_default_
=
false
;
}
else
{
Interactor
->
GetRenderWindow
()
->
SetAnaglyphColorMask
(
2
,
5
);
Interactor
->
GetRenderWindow
()
->
SetAnaglyphColorMask
(
2
,
5
);
stereo_anaglyph_mask_default_
=
true
;
}
}
Interactor
->
GetRenderWindow
()
->
SetStereoRender
(
!
stereo_render
);
Interactor
->
GetRenderWindow
()
->
Render
();
Interactor
->
Render
();
Interactor
->
GetRenderWindow
()
->
SetStereoRender
(
!
stereo_render
);
Interactor
->
GetRenderWindow
()
->
Render
();
Interactor
->
Render
();
}
else
Superclass
::
OnKeyDown
();
Superclass
::
OnKeyDown
();
break
;
}
case
'o'
:
case
'O'
:
{
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
int
flag
=
cam
->
GetParallelProjection
();
cam
->
SetParallelProjection
(
!
flag
);
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
int
flag
=
cam
->
GetParallelProjection
();
cam
->
SetParallelProjection
(
!
flag
);
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
Render
();
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
Render
();
break
;
}
...
...
@@ -412,20 +460,20 @@ cv::viz::InteractorStyle::OnKeyDown ()
{
if
(
!
keymod
)
{
Superclass
::
OnKeyDown
();
Superclass
::
OnKeyDown
();
break
;
}
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
static
WidgetActorMap
::
iterator
it
=
widget_actor_map_
->
begin
();
static
WidgetActorMap
::
iterator
it
=
widget_actor_map_
->
begin
();
// it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault.
bool
found_transformation
=
false
;
for
(
size_t
idx
=
0
;
idx
<
widget_actor_map_
->
size
();
++
idx
,
++
it
)
for
(
size_t
idx
=
0
;
idx
<
widget_actor_map_
->
size
();
++
idx
,
++
it
)
{
if
(
it
==
widget_actor_map_
->
end
())
it
=
widget_actor_map_
->
begin
();
if
(
it
==
widget_actor_map_
->
end
())
it
=
widget_actor_map_
->
begin
();
vtkProp3D
*
actor
=
vtkProp3D
::
SafeDownCast
(
it
->
second
);
if
(
actor
&&
actor
->
GetUserMatrix
())
...
...
@@ -439,219 +487,218 @@ cv::viz::InteractorStyle::OnKeyDown ()
if
(
found_transformation
)
{
vtkProp3D
*
actor
=
vtkProp3D
::
SafeDownCast
(
it
->
second
);
cam
->
SetPosition
(
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
3
),
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
3
),
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
3
));
cam
->
SetPosition
(
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
3
),
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
3
),
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
3
));
cam
->
SetFocalPoint
(
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
3
)
-
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
2
),
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
3
)
-
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
2
),
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
3
)
-
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
2
));
cam
->
SetFocalPoint
(
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
3
)
-
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
2
),
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
3
)
-
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
2
),
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
3
)
-
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
2
));
cam
->
SetViewUp
(
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
1
),
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
1
),
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
1
));
cam
->
SetViewUp
(
actor
->
GetUserMatrix
()
->
GetElement
(
0
,
1
),
actor
->
GetUserMatrix
()
->
GetElement
(
1
,
1
),
actor
->
GetUserMatrix
()
->
GetElement
(
2
,
1
));
}
else
{
cam
->
SetPosition
(
0
,
0
,
0
);
cam
->
SetFocalPoint
(
0
,
0
,
1
);
cam
->
SetViewUp
(
0
,
-
1
,
0
);
cam
->
SetPosition
(
0
,
0
,
0
);
cam
->
SetFocalPoint
(
0
,
0
,
1
);
cam
->
SetViewUp
(
0
,
-
1
,
0
);
}
// go to the next actor for the next key-press event.
if
(
it
!=
widget_actor_map_
->
end
())
if
(
it
!=
widget_actor_map_
->
end
())
++
it
;
else
it
=
widget_actor_map_
->
begin
();
it
=
widget_actor_map_
->
begin
();
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
ResetCameraClippingRange
();
CurrentRenderer
->
Render
();
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
ResetCameraClippingRange
();
CurrentRenderer
->
Render
();
break
;
}
case
'q'
:
case
'Q'
:
{
Interactor
->
ExitCallback
();
Interactor
->
ExitCallback
();
return
;
}
default
:
{
Superclass
::
OnKeyDown
();
Superclass
::
OnKeyDown
();
break
;
}
}
KeyboardEvent
event
(
true
,
Interactor
->
GetKeySym
(),
Interactor
->
GetKeyCode
(),
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
KeyboardEvent
event
(
true
,
Interactor
->
GetKeySym
(),
Interactor
->
GetKeyCode
(),
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
// Check if there is a keyboard callback registered
if
(
keyboardCallback_
)
keyboardCallback_
(
event
,
keyboard_callback_cookie_
);
renderer_
->
Render
();
Interactor
->
Render
();
renderer_
->
Render
();
Interactor
->
Render
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnKeyUp
()
void
cv
::
viz
::
InteractorStyle
::
OnKeyUp
()
{
KeyboardEvent
event
(
false
,
Interactor
->
GetKeySym
(),
Interactor
->
GetKeyCode
(),
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
KeyboardEvent
event
(
false
,
Interactor
->
GetKeySym
(),
Interactor
->
GetKeyCode
(),
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
// Check if there is a keyboard callback registered
if
(
keyboardCallback_
)
keyboardCallback_
(
event
,
keyboard_callback_cookie_
);
Superclass
::
OnKeyUp
();
Superclass
::
OnKeyUp
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnMouseMove
()
void
cv
::
viz
::
InteractorStyle
::
OnMouseMove
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
event
(
MouseEvent
::
MouseMove
,
MouseEvent
::
NoButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
MouseEvent
::
MouseMove
,
MouseEvent
::
NoButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
Superclass
::
OnMouseMove
();
Superclass
::
OnMouseMove
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnLeftButtonDown
()
void
cv
::
viz
::
InteractorStyle
::
OnLeftButtonDown
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
::
Type
type
=
(
Interactor
->
GetRepeatCount
()
==
0
)
?
MouseEvent
::
MouseButtonPress
:
MouseEvent
::
MouseDblClick
;
MouseEvent
event
(
type
,
MouseEvent
::
LeftButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
type
,
MouseEvent
::
LeftButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
Superclass
::
OnLeftButtonDown
();
Superclass
::
OnLeftButtonDown
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnLeftButtonUp
()
void
cv
::
viz
::
InteractorStyle
::
OnLeftButtonUp
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
event
(
MouseEvent
::
MouseButtonRelease
,
MouseEvent
::
LeftButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
MouseEvent
::
MouseButtonRelease
,
MouseEvent
::
LeftButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
Superclass
::
OnLeftButtonUp
();
Superclass
::
OnLeftButtonUp
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnMiddleButtonDown
()
void
cv
::
viz
::
InteractorStyle
::
OnMiddleButtonDown
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
::
Type
type
=
(
Interactor
->
GetRepeatCount
()
==
0
)
?
MouseEvent
::
MouseButtonPress
:
MouseEvent
::
MouseDblClick
;
MouseEvent
event
(
type
,
MouseEvent
::
MiddleButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
type
,
MouseEvent
::
MiddleButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
Superclass
::
OnMiddleButtonDown
();
Superclass
::
OnMiddleButtonDown
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnMiddleButtonUp
()
void
cv
::
viz
::
InteractorStyle
::
OnMiddleButtonUp
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
event
(
MouseEvent
::
MouseButtonRelease
,
MouseEvent
::
MiddleButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
MouseEvent
::
MouseButtonRelease
,
MouseEvent
::
MiddleButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
Superclass
::
OnMiddleButtonUp
();
Superclass
::
OnMiddleButtonUp
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnRightButtonDown
()
void
cv
::
viz
::
InteractorStyle
::
OnRightButtonDown
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
::
Type
type
=
(
Interactor
->
GetRepeatCount
()
==
0
)
?
MouseEvent
::
MouseButtonPress
:
MouseEvent
::
MouseDblClick
;
MouseEvent
event
(
type
,
MouseEvent
::
RightButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
type
,
MouseEvent
::
RightButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
Superclass
::
OnRightButtonDown
();
Superclass
::
OnRightButtonDown
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnRightButtonUp
()
void
cv
::
viz
::
InteractorStyle
::
OnRightButtonUp
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
event
(
MouseEvent
::
MouseButtonRelease
,
MouseEvent
::
RightButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
MouseEvent
::
MouseButtonRelease
,
MouseEvent
::
RightButton
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
Superclass
::
OnRightButtonUp
();
Superclass
::
OnRightButtonUp
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnMouseWheelForward
()
void
cv
::
viz
::
InteractorStyle
::
OnMouseWheelForward
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
event
(
MouseEvent
::
MouseScrollUp
,
MouseEvent
::
VScroll
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
MouseEvent
::
MouseScrollUp
,
MouseEvent
::
VScroll
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
// If a mouse callback registered, call it!
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
if
(
Interactor
->
GetRepeatCount
()
&&
mouseCallback_
)
if
(
Interactor
->
GetRepeatCount
()
&&
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
if
(
Interactor
->
GetAltKey
())
if
(
Interactor
->
GetAltKey
())
{
// zoom
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
double
opening_angle
=
cam
->
GetViewAngle
();
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
double
opening_angle
=
cam
->
GetViewAngle
();
if
(
opening_angle
>
15.0
)
opening_angle
-=
1.0
;
cam
->
SetViewAngle
(
opening_angle
);
cam
->
Modified
();
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
ResetCameraClippingRange
();
CurrentRenderer
->
Modified
();
CurrentRenderer
->
Render
();
renderer_
->
Render
();
Interactor
->
Render
();
cam
->
SetViewAngle
(
opening_angle
);
cam
->
Modified
();
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
ResetCameraClippingRange
();
CurrentRenderer
->
Modified
();
CurrentRenderer
->
Render
();
renderer_
->
Render
();
Interactor
->
Render
();
}
else
Superclass
::
OnMouseWheelForward
();
Superclass
::
OnMouseWheelForward
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnMouseWheelBackward
()
void
cv
::
viz
::
InteractorStyle
::
OnMouseWheelBackward
()
{
Vec2i
p
(
Interactor
->
GetEventPosition
());
MouseEvent
event
(
MouseEvent
::
MouseScrollDown
,
MouseEvent
::
VScroll
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
MouseEvent
event
(
MouseEvent
::
MouseScrollDown
,
MouseEvent
::
VScroll
,
p
,
Interactor
->
GetAltKey
(),
Interactor
->
GetControlKey
(),
Interactor
->
GetShiftKey
());
// If a mouse callback registered, call it!
if
(
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
if
(
Interactor
->
GetRepeatCount
()
&&
mouseCallback_
)
if
(
Interactor
->
GetRepeatCount
()
&&
mouseCallback_
)
mouseCallback_
(
event
,
mouse_callback_cookie_
);
if
(
Interactor
->
GetAltKey
())
if
(
Interactor
->
GetAltKey
())
{
// zoom
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
double
opening_angle
=
cam
->
GetViewAngle
();
vtkSmartPointer
<
vtkCamera
>
cam
=
CurrentRenderer
->
GetActiveCamera
();
double
opening_angle
=
cam
->
GetViewAngle
();
if
(
opening_angle
<
170.0
)
opening_angle
+=
1.0
;
cam
->
SetViewAngle
(
opening_angle
);
cam
->
Modified
();
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
ResetCameraClippingRange
();
CurrentRenderer
->
Modified
();
CurrentRenderer
->
Render
();
renderer_
->
Render
();
Interactor
->
Render
();
cam
->
SetViewAngle
(
opening_angle
);
cam
->
Modified
();
CurrentRenderer
->
SetActiveCamera
(
cam
);
CurrentRenderer
->
ResetCameraClippingRange
();
CurrentRenderer
->
Modified
();
CurrentRenderer
->
Render
();
renderer_
->
Render
();
Interactor
->
Render
();
}
else
Superclass
::
OnMouseWheelBackward
();
Superclass
::
OnMouseWheelBackward
();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
InteractorStyle
::
OnTimer
()
void
cv
::
viz
::
InteractorStyle
::
OnTimer
()
{
CV_Assert
(
"Interactor style not initialized."
&&
init_
);
CV_Assert
(
"Renderer has not been set."
&&
renderer_
);
renderer_
->
Render
();
Interactor
->
Render
();
renderer_
->
Render
();
Interactor
->
Render
();
}
namespace
cv
{
namespace
viz
...
...
modules/viz/src/interactor_style.h
View file @
26005a19
#pragma once
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__
#define __OPENCV_VIZ_INTERACTOR_STYLE_H__
#include <opencv2/viz/types.hpp>
...
...
@@ -6,27 +55,6 @@ namespace cv
{
namespace
viz
{
/** \brief InteractorStyle defines an unique, custom VTK based interactory style Viz applications.
* Besides defining the rendering style, we also create a list of custom actions
* that are triggered on different keys being pressed:
*
* - p, P : switch to a point-based representation
* - w, W : switch to a wireframe-based representation (where available)
* - s, S : switch to a surface-based representation (where available)
* - j, J : take a .PNG snapshot of the current window view
* - c, C : display current camera/window parameters
* - f, F : fly to point mode
* - e, E : exit the interactor
* - q, Q : stop and call VTK's TerminateApp
* - + / - : increment/decrement overall point size
* - r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]
* - ALT + s, S : turn stereo mode on/off
* - ALT + f, F : switch between maximized window mode and original size
* -
* - SHIFT + left click : select a point
*
* \author Radu B. Rusu
*/
class
InteractorStyle
:
public
vtkInteractorStyleTrackballCamera
{
public
:
...
...
@@ -38,37 +66,31 @@ namespace cv
KB_MOD_SHIFT
};
static
InteractorStyle
*
New
();
static
InteractorStyle
*
New
();
InteractorStyle
()
{}
virtual
~
InteractorStyle
()
{}
InteractorStyle
()
{}
virtual
~
InteractorStyle
()
{}
// this macro defines Superclass, the isA functionality and the safe downcast method
vtkTypeMacro
(
InteractorStyle
,
vtkInteractorStyleTrackballCamera
)
vtkTypeMacro
(
InteractorStyle
,
vtkInteractorStyleTrackballCamera
)
/** \brief Initialization routine. Must be called before anything else. */
virtual
void
Initialize
();
virtual
void
Initialize
();
inline
void
setWidgetActorMap
(
const
Ptr
<
WidgetActorMap
>&
actors
)
{
widget_actor_map_
=
actors
;
}
void
setRenderer
(
vtkSmartPointer
<
vtkRenderer
>&
ren
)
{
renderer_
=
ren
;
}
inline
void
setWidgetActorMap
(
const
Ptr
<
WidgetActorMap
>&
actors
)
{
widget_actor_map_
=
actors
;
}
void
setRenderer
(
vtkSmartPointer
<
vtkRenderer
>&
ren
)
{
renderer_
=
ren
;
}
void
registerMouseCallback
(
void
(
*
callback
)(
const
MouseEvent
&
,
void
*
),
void
*
cookie
=
0
);
void
registerKeyboardCallback
(
void
(
*
callback
)(
const
KeyboardEvent
&
,
void
*
),
void
*
cookie
=
0
);
void
saveScreenshot
(
const
std
::
string
&
file
);
/** \brief Change the default keyboard modified from ALT to a different special key.
* Allowed values are:
* - KB_MOD_ALT
* - KB_MOD_CTRL
* - KB_MOD_SHIFT
* \param[in] modifier the new keyboard modifier
*/
inline
void
setKeyboardModifier
(
const
KeyboardModifier
&
modifier
)
{
modifier_
=
modifier
;
}
void
saveScreenshot
(
const
std
::
string
&
file
);
/** \brief Change the default keyboard modified from ALT to a different special key.*/
inline
void
setKeyboardModifier
(
const
KeyboardModifier
&
modifier
)
{
modifier_
=
modifier
;
}
protected
:
/** \brief Set to true after initialization is complete. */
bool
init_
;
/** \brief Collection of vtkRenderers stored internally. */
//vtkSmartPointer<vtkRendererCollection> rens_;
vtkSmartPointer
<
vtkRenderer
>
renderer_
;
/** \brief Actor map stored internally. */
...
...
@@ -85,32 +107,33 @@ namespace cv
/** \brief A PNG writer for screenshot captures. */
vtkSmartPointer
<
vtkPNGWriter
>
snapshot_writer_
;
/** \brief Internal window to image filter. Needed by \a snapshot_writer_. */
vtkSmartPointer
<
vtkWindowToImageFilter
>
wif_
;
/** \brief Interactor style internal method. Gets called whenever a key is pressed. */
virtual
void
OnChar
();
virtual
void
OnChar
();
// Keyboard events
virtual
void
OnKeyDown
();
virtual
void
OnKeyUp
();
virtual
void
OnKeyDown
();
virtual
void
OnKeyUp
();
// mouse button events
virtual
void
OnMouseMove
();
virtual
void
OnLeftButtonDown
();
virtual
void
OnLeftButtonUp
();
virtual
void
OnMiddleButtonDown
();
virtual
void
OnMiddleButtonUp
();
virtual
void
OnRightButtonDown
();
virtual
void
OnRightButtonUp
();
virtual
void
OnMouseWheelForward
();
virtual
void
OnMouseWheelBackward
();
virtual
void
OnMouseMove
();
virtual
void
OnLeftButtonDown
();
virtual
void
OnLeftButtonUp
();
virtual
void
OnMiddleButtonDown
();
virtual
void
OnMiddleButtonUp
();
virtual
void
OnRightButtonDown
();
virtual
void
OnRightButtonUp
();
virtual
void
OnMouseWheelForward
();
virtual
void
OnMouseWheelBackward
();
/** \brief Interactor style internal method. Gets called periodically if a timer is set. */
virtual
void
OnTimer
();
virtual
void
OnTimer
();
void
zoomIn
();
void
zoomOut
();
void
zoomIn
();
void
zoomOut
();
/** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */
bool
stereo_anaglyph_mask_default_
;
...
...
@@ -125,3 +148,5 @@ namespace cv
};
}
}
#endif
modules/viz/src/precomp.cpp
View file @
26005a19
#include "precomp.hpp"
\ No newline at end of file
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
modules/viz/src/precomp.hpp
View file @
26005a19
#pragma once
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifndef __OPENCV_VIZ_PRECOMP_HPP__
#define __OPENCV_VIZ_PRECOMP_HPP__
#include <map>
#include <ctime>
...
...
@@ -89,3 +138,5 @@ namespace cv
#include <opencv2/viz.hpp>
#include <opencv2/viz/types.hpp>
#include "opencv2/viz/widget_accessor.hpp"
#endif
modules/viz/src/shape_widgets.cpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
namespace
cv
...
...
@@ -13,12 +61,12 @@ namespace cv
cv
::
viz
::
LineWidget
::
LineWidget
(
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkLineSource
>
line
=
vtkSmartPointer
<
vtkLineSource
>::
New
();
line
->
SetPoint1
(
pt1
.
x
,
pt1
.
y
,
pt1
.
z
);
line
->
SetPoint2
(
pt2
.
x
,
pt2
.
y
,
pt2
.
z
);
line
->
Update
();
line
->
SetPoint1
(
pt1
.
x
,
pt1
.
y
,
pt1
.
z
);
line
->
SetPoint2
(
pt2
.
x
,
pt2
.
y
,
pt2
.
z
);
line
->
Update
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
line
->
GetOutput
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
line
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -58,15 +106,15 @@ struct cv::viz::PlaneWidget::SetSizeImpl
cv
::
viz
::
PlaneWidget
::
PlaneWidget
(
const
Vec4f
&
coefs
,
double
size
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkPlaneSource
>
plane
=
vtkSmartPointer
<
vtkPlaneSource
>::
New
();
plane
->
SetNormal
(
coefs
[
0
],
coefs
[
1
],
coefs
[
2
]);
vtkSmartPointer
<
vtkPlaneSource
>
plane
=
vtkSmartPointer
<
vtkPlaneSource
>::
New
();
plane
->
SetNormal
(
coefs
[
0
],
coefs
[
1
],
coefs
[
2
]);
double
norm
=
cv
::
norm
(
Vec3f
(
coefs
.
val
));
plane
->
Push
(
-
coefs
[
3
]
/
norm
);
plane
->
Push
(
-
coefs
[
3
]
/
norm
);
Vec3d
p_center
;
plane
->
GetOrigin
(
p_center
.
val
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
SetSizeImpl
::
setSize
(
p_center
,
plane
->
GetOutput
(),
size
));
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
...
...
@@ -78,16 +126,16 @@ cv::viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color &
cv
::
viz
::
PlaneWidget
::
PlaneWidget
(
const
Vec4f
&
coefs
,
const
Point3f
&
pt
,
double
size
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkPlaneSource
>
plane
=
vtkSmartPointer
<
vtkPlaneSource
>::
New
();
vtkSmartPointer
<
vtkPlaneSource
>
plane
=
vtkSmartPointer
<
vtkPlaneSource
>::
New
();
Point3f
coefs3
(
coefs
[
0
],
coefs
[
1
],
coefs
[
2
]);
double
norm_sqr
=
1.0
/
coefs3
.
dot
(
coefs3
);
double
norm_sqr
=
1.0
/
coefs3
.
dot
(
coefs3
);
plane
->
SetNormal
(
coefs
[
0
],
coefs
[
1
],
coefs
[
2
]);
double
t
=
coefs3
.
dot
(
pt
)
+
coefs
[
3
];
Vec3f
p_center
=
pt
-
coefs3
*
t
*
norm_sqr
;
plane
->
SetCenter
(
p_center
[
0
],
p_center
[
1
],
p_center
[
2
]);
plane
->
SetCenter
(
p_center
[
0
],
p_center
[
1
],
p_center
[
2
]);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
SetSizeImpl
::
setSize
(
p_center
,
plane
->
GetOutput
(),
size
));
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
...
...
@@ -108,16 +156,16 @@ template<> cv::viz::PlaneWidget cv::viz::Widget::cast<cv::viz::PlaneWidget>()
cv
::
viz
::
SphereWidget
::
SphereWidget
(
const
Point3f
&
center
,
float
radius
,
int
sphere_resolution
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkSphereSource
>
sphere
=
vtkSmartPointer
<
vtkSphereSource
>::
New
();
sphere
->
SetRadius
(
radius
);
sphere
->
SetCenter
(
center
.
x
,
center
.
y
,
center
.
z
);
sphere
->
SetPhiResolution
(
sphere_resolution
);
sphere
->
SetThetaResolution
(
sphere_resolution
);
sphere
->
LatLongTessellationOff
();
sphere
->
Update
();
vtkSmartPointer
<
vtkSphereSource
>
sphere
=
vtkSmartPointer
<
vtkSphereSource
>::
New
();
sphere
->
SetRadius
(
radius
);
sphere
->
SetCenter
(
center
.
x
,
center
.
y
,
center
.
z
);
sphere
->
SetPhiResolution
(
sphere_resolution
);
sphere
->
SetThetaResolution
(
sphere_resolution
);
sphere
->
LatLongTessellationOff
();
sphere
->
Update
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
sphere
->
GetOutput
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
sphere
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -137,7 +185,7 @@ template<> cv::viz::SphereWidget cv::viz::Widget::cast<cv::viz::SphereWidget>()
cv
::
viz
::
ArrowWidget
::
ArrowWidget
(
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
double
thickness
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkArrowSource
>
arrowSource
=
vtkSmartPointer
<
vtkArrowSource
>::
New
();
vtkSmartPointer
<
vtkArrowSource
>
arrowSource
=
vtkSmartPointer
<
vtkArrowSource
>::
New
();
arrowSource
->
SetShaftRadius
(
thickness
);
// The thickness and radius of the tip are adjusted based on the thickness of the arrow
arrowSource
->
SetTipRadius
(
thickness
*
3.0
);
...
...
@@ -189,8 +237,8 @@ cv::viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, double
transformPD
->
SetTransform
(
transform
);
transformPD
->
SetInputConnection
(
arrowSource
->
GetOutputPort
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
transformPD
->
GetOutput
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
transformPD
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -210,23 +258,23 @@ template<> cv::viz::ArrowWidget cv::viz::Widget::cast<cv::viz::ArrowWidget>()
cv
::
viz
::
CircleWidget
::
CircleWidget
(
const
Point3f
&
pt
,
double
radius
,
double
thickness
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkDiskSource
>
disk
=
vtkSmartPointer
<
vtkDiskSource
>::
New
();
vtkSmartPointer
<
vtkDiskSource
>
disk
=
vtkSmartPointer
<
vtkDiskSource
>::
New
();
// Maybe the resolution should be lower e.g. 50 or 25
disk
->
SetCircumferentialResolution
(
50
);
disk
->
SetInnerRadius
(
radius
-
thickness
);
disk
->
SetOuterRadius
(
radius
+
thickness
);
disk
->
SetCircumferentialResolution
(
50
);
disk
->
SetInnerRadius
(
radius
-
thickness
);
disk
->
SetOuterRadius
(
radius
+
thickness
);
// Set the circle origin
vtkSmartPointer
<
vtkTransform
>
t
=
vtkSmartPointer
<
vtkTransform
>::
New
();
t
->
Identity
();
t
->
Translate
(
pt
.
x
,
pt
.
y
,
pt
.
z
);
vtkSmartPointer
<
vtkTransform
>
t
=
vtkSmartPointer
<
vtkTransform
>::
New
();
t
->
Identity
();
t
->
Translate
(
pt
.
x
,
pt
.
y
,
pt
.
z
);
vtkSmartPointer
<
vtkTransformPolyDataFilter
>
tf
=
vtkSmartPointer
<
vtkTransformPolyDataFilter
>::
New
();
tf
->
SetTransform
(
t
);
tf
->
SetInputConnection
(
disk
->
GetOutputPort
());
vtkSmartPointer
<
vtkTransformPolyDataFilter
>
tf
=
vtkSmartPointer
<
vtkTransformPolyDataFilter
>::
New
();
tf
->
SetTransform
(
t
);
tf
->
SetInputConnection
(
disk
->
GetOutputPort
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tf
->
GetOutput
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tf
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -247,19 +295,19 @@ template<> cv::viz::CircleWidget cv::viz::Widget::cast<cv::viz::CircleWidget>()
cv
::
viz
::
CylinderWidget
::
CylinderWidget
(
const
Point3f
&
pt_on_axis
,
const
Point3f
&
axis_direction
,
double
radius
,
int
numsides
,
const
Color
&
color
)
{
const
Point3f
pt2
=
pt_on_axis
+
axis_direction
;
vtkSmartPointer
<
vtkLineSource
>
line
=
vtkSmartPointer
<
vtkLineSource
>::
New
();
line
->
SetPoint1
(
pt_on_axis
.
x
,
pt_on_axis
.
y
,
pt_on_axis
.
z
);
line
->
SetPoint2
(
pt2
.
x
,
pt2
.
y
,
pt2
.
z
);
vtkSmartPointer
<
vtkLineSource
>
line
=
vtkSmartPointer
<
vtkLineSource
>::
New
();
line
->
SetPoint1
(
pt_on_axis
.
x
,
pt_on_axis
.
y
,
pt_on_axis
.
z
);
line
->
SetPoint2
(
pt2
.
x
,
pt2
.
y
,
pt2
.
z
);
vtkSmartPointer
<
vtkTubeFilter
>
tuber
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
tuber
->
SetInputConnection
(
line
->
GetOutputPort
());
tuber
->
SetRadius
(
radius
);
tuber
->
SetNumberOfSides
(
numsides
);
vtkSmartPointer
<
vtkTubeFilter
>
tuber
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
tuber
->
SetInputConnection
(
line
->
GetOutputPort
());
tuber
->
SetRadius
(
radius
);
tuber
->
SetNumberOfSides
(
numsides
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tuber
->
GetOutput
());
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
tuber
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetMapper
(
mapper
);
WidgetAccessor
::
setProp
(
*
this
,
actor
);
...
...
@@ -277,18 +325,18 @@ template<> cv::viz::CylinderWidget cv::viz::Widget::cast<cv::viz::CylinderWidget
cv
::
viz
::
CubeWidget
::
CubeWidget
(
const
Point3f
&
pt_min
,
const
Point3f
&
pt_max
,
bool
wire_frame
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
if
(
wire_frame
)
{
vtkSmartPointer
<
vtkOutlineSource
>
cube
=
vtkSmartPointer
<
vtkOutlineSource
>::
New
();
cube
->
SetBounds
(
pt_min
.
x
,
pt_max
.
x
,
pt_min
.
y
,
pt_max
.
y
,
pt_min
.
z
,
pt_max
.
z
);
mapper
->
SetInput
(
cube
->
GetOutput
());
cube
->
SetBounds
(
pt_min
.
x
,
pt_max
.
x
,
pt_min
.
y
,
pt_max
.
y
,
pt_min
.
z
,
pt_max
.
z
);
mapper
->
SetInput
(
cube
->
GetOutput
());
}
else
{
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
);
mapper
->
SetInput
(
cube
->
GetOutput
());
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
);
mapper
->
SetInput
(
cube
->
GetOutput
());
}
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
...
...
@@ -309,31 +357,31 @@ template<> cv::viz::CubeWidget cv::viz::Widget::cast<cv::viz::CubeWidget>()
cv
::
viz
::
CoordinateSystemWidget
::
CoordinateSystemWidget
(
double
scale
)
{
vtkSmartPointer
<
vtkAxes
>
axes
=
vtkSmartPointer
<
vtkAxes
>::
New
();
axes
->
SetOrigin
(
0
,
0
,
0
);
axes
->
SetScaleFactor
(
scale
);
vtkSmartPointer
<
vtkFloatArray
>
axes_colors
=
vtkSmartPointer
<
vtkFloatArray
>::
New
();
axes_colors
->
Allocate
(
6
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
1.0
);
axes_colors
->
InsertNextValue
(
1.0
);
vtkSmartPointer
<
vtkPolyData
>
axes_data
=
axes
->
GetOutput
();
axes_data
->
Update
();
axes_data
->
GetPointData
()
->
SetScalars
(
axes_colors
);
vtkSmartPointer
<
vtkTubeFilter
>
axes_tubes
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
axes_tubes
->
SetInput
(
axes_data
);
axes_tubes
->
SetRadius
(
axes
->
GetScaleFactor
()
/
50.0
);
axes_tubes
->
SetNumberOfSides
(
6
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetInput
(
axes_tubes
->
GetOutput
());
vtkSmartPointer
<
vtkAxes
>
axes
=
vtkSmartPointer
<
vtkAxes
>::
New
();
axes
->
SetOrigin
(
0
,
0
,
0
);
axes
->
SetScaleFactor
(
scale
);
vtkSmartPointer
<
vtkFloatArray
>
axes_colors
=
vtkSmartPointer
<
vtkFloatArray
>::
New
();
axes_colors
->
Allocate
(
6
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
1.0
);
axes_colors
->
InsertNextValue
(
1.0
);
vtkSmartPointer
<
vtkPolyData
>
axes_data
=
axes
->
GetOutput
();
axes_data
->
Update
();
axes_data
->
GetPointData
()
->
SetScalars
(
axes_colors
);
vtkSmartPointer
<
vtkTubeFilter
>
axes_tubes
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
axes_tubes
->
SetInput
(
axes_data
);
axes_tubes
->
SetRadius
(
axes
->
GetScaleFactor
()
/
50.0
);
axes_tubes
->
SetNumberOfSides
(
6
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetInput
(
axes_tubes
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -357,11 +405,11 @@ struct cv::viz::PolyLineWidget::CopyImpl
{
int
s_chs
=
source
.
channels
();
for
(
int
y
=
0
,
id
=
0
;
y
<
source
.
rows
;
++
y
)
for
(
int
y
=
0
,
id
=
0
;
y
<
source
.
rows
;
++
y
)
{
const
_Tp
*
srow
=
source
.
ptr
<
_Tp
>
(
y
);
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
++
id
)
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
++
id
)
{
*
output
++
=
Vec
<
_Tp
,
3
>
(
srow
);
polyLine
->
GetPointIds
()
->
SetId
(
id
,
id
);
...
...
@@ -376,9 +424,9 @@ cv::viz::PolyLineWidget::PolyLineWidget(InputArray _pointData, const Color &colo
CV_Assert
(
pointData
.
type
()
==
CV_32FC3
||
pointData
.
type
()
==
CV_32FC4
||
pointData
.
type
()
==
CV_64FC3
||
pointData
.
type
()
==
CV_64FC4
);
vtkIdType
nr_points
=
pointData
.
total
();
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
vtkSmartPointer
<
vtkPolyData
>
polyData
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkPolyLine
>
polyLine
=
vtkSmartPointer
<
vtkPolyLine
>::
New
();
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
vtkSmartPointer
<
vtkPolyData
>
polyData
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkPolyLine
>
polyLine
=
vtkSmartPointer
<
vtkPolyLine
>::
New
();
if
(
pointData
.
depth
()
==
CV_32F
)
points
->
SetDataTypeToFloat
();
...
...
@@ -528,7 +576,7 @@ cv::viz::Text3DWidget::Text3DWidget(const String &text, const Point3f &position,
textSource
->
Update
();
vtkSmartPointer
<
vtkPolyDataMapper
>
mapper
=
vtkSmartPointer
<
vtkPolyDataMapper
>::
New
();
mapper
->
SetInputConnection
(
textSource
->
GetOutputPort
());
mapper
->
SetInputConnection
(
textSource
->
GetOutputPort
());
if
(
face_camera
)
{
...
...
@@ -588,17 +636,17 @@ template<> cv::viz::Text3DWidget cv::viz::Widget::cast<cv::viz::Text3DWidget>()
cv
::
viz
::
TextWidget
::
TextWidget
(
const
String
&
text
,
const
Point2i
&
pos
,
int
font_size
,
const
Color
&
color
)
{
vtkSmartPointer
<
vtkTextActor
>
actor
=
vtkSmartPointer
<
vtkTextActor
>::
New
();
actor
->
SetPosition
(
pos
.
x
,
pos
.
y
);
actor
->
SetInput
(
text
.
c_str
());
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
();
vtkSmartPointer
<
vtkTextProperty
>
tprop
=
actor
->
GetTextProperty
();
tprop
->
SetFontSize
(
font_size
);
tprop
->
SetFontFamilyToArial
();
tprop
->
SetJustificationToLeft
();
tprop
->
BoldOn
();
Color
c
=
vtkcolor
(
color
);
tprop
->
SetColor
(
c
.
val
);
tprop
->
SetColor
(
c
.
val
);
WidgetAccessor
::
setProp
(
*
this
,
actor
);
}
...
...
@@ -938,31 +986,31 @@ struct cv::viz::CameraPositionWidget::ProjectImage
cv
::
viz
::
CameraPositionWidget
::
CameraPositionWidget
(
double
scale
)
{
vtkSmartPointer
<
vtkAxes
>
axes
=
vtkSmartPointer
<
vtkAxes
>::
New
();
axes
->
SetOrigin
(
0
,
0
,
0
);
axes
->
SetScaleFactor
(
scale
);
vtkSmartPointer
<
vtkFloatArray
>
axes_colors
=
vtkSmartPointer
<
vtkFloatArray
>::
New
();
axes_colors
->
Allocate
(
6
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
1.0
);
axes_colors
->
InsertNextValue
(
1.0
);
vtkSmartPointer
<
vtkPolyData
>
axes_data
=
axes
->
GetOutput
();
axes_data
->
Update
();
axes_data
->
GetPointData
()
->
SetScalars
(
axes_colors
);
vtkSmartPointer
<
vtkTubeFilter
>
axes_tubes
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
axes_tubes
->
SetInput
(
axes_data
);
axes_tubes
->
SetRadius
(
axes
->
GetScaleFactor
()
/
50.0
);
axes_tubes
->
SetNumberOfSides
(
6
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetInput
(
axes_tubes
->
GetOutput
());
vtkSmartPointer
<
vtkAxes
>
axes
=
vtkSmartPointer
<
vtkAxes
>::
New
();
axes
->
SetOrigin
(
0
,
0
,
0
);
axes
->
SetScaleFactor
(
scale
);
vtkSmartPointer
<
vtkFloatArray
>
axes_colors
=
vtkSmartPointer
<
vtkFloatArray
>::
New
();
axes_colors
->
Allocate
(
6
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.0
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
0.5
);
axes_colors
->
InsertNextValue
(
1.0
);
axes_colors
->
InsertNextValue
(
1.0
);
vtkSmartPointer
<
vtkPolyData
>
axes_data
=
axes
->
GetOutput
();
axes_data
->
Update
();
axes_data
->
GetPointData
()
->
SetScalars
(
axes_colors
);
vtkSmartPointer
<
vtkTubeFilter
>
axes_tubes
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
axes_tubes
->
SetInput
(
axes_data
);
axes_tubes
->
SetRadius
(
axes
->
GetScaleFactor
()
/
50.0
);
axes_tubes
->
SetNumberOfSides
(
6
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetInput
(
axes_tubes
->
GetOutput
());
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -1122,9 +1170,9 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, i
// Create a poly line along the path
vtkIdType
nr_points
=
path
.
size
();
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
vtkSmartPointer
<
vtkPolyData
>
polyData
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkPolyLine
>
polyLine
=
vtkSmartPointer
<
vtkPolyLine
>::
New
();
vtkSmartPointer
<
vtkPoints
>
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
vtkSmartPointer
<
vtkPolyData
>
polyData
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkPolyLine
>
polyLine
=
vtkSmartPointer
<
vtkPolyLine
>::
New
();
points
->
SetDataTypeToFloat
();
points
->
SetNumberOfPoints
(
nr_points
);
...
...
@@ -1161,10 +1209,10 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, i
{
// Create frames and transform along the path
vtkSmartPointer
<
vtkAxes
>
axes
=
vtkSmartPointer
<
vtkAxes
>::
New
();
axes
->
SetOrigin
(
0
,
0
,
0
);
axes
->
SetScaleFactor
(
scale
);
axes
->
SetOrigin
(
0
,
0
,
0
);
axes
->
SetScaleFactor
(
scale
);
vtkSmartPointer
<
vtkUnsignedCharArray
>
axes_colors
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
vtkSmartPointer
<
vtkUnsignedCharArray
>
axes_colors
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
axes_colors
->
SetNumberOfComponents
(
3
);
axes_colors
->
InsertNextTuple3
(
255
,
0
,
0
);
axes_colors
->
InsertNextTuple3
(
255
,
0
,
0
);
...
...
@@ -1173,21 +1221,21 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, i
axes_colors
->
InsertNextTuple3
(
0
,
0
,
255
);
axes_colors
->
InsertNextTuple3
(
0
,
0
,
255
);
vtkSmartPointer
<
vtkPolyData
>
axes_data
=
axes
->
GetOutput
();
axes_data
->
Update
();
axes_data
->
GetPointData
()
->
SetScalars
(
axes_colors
);
vtkSmartPointer
<
vtkPolyData
>
axes_data
=
axes
->
GetOutput
();
axes_data
->
Update
();
axes_data
->
GetPointData
()
->
SetScalars
(
axes_colors
);
vtkSmartPointer
<
vtkTubeFilter
>
axes_tubes
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
axes_tubes
->
SetInput
(
axes_data
);
axes_tubes
->
SetRadius
(
axes
->
GetScaleFactor
()
/
50.0
);
axes_tubes
->
SetNumberOfSides
(
6
);
vtkSmartPointer
<
vtkTubeFilter
>
axes_tubes
=
vtkSmartPointer
<
vtkTubeFilter
>::
New
();
axes_tubes
->
SetInput
(
axes_data
);
axes_tubes
->
SetRadius
(
axes
->
GetScaleFactor
()
/
50.0
);
axes_tubes
->
SetNumberOfSides
(
6
);
axes_tubes
->
Update
();
ApplyPath
::
applyPath
(
axes_tubes
->
GetOutput
(),
appendFilter
,
path
);
}
vtkSmartPointer
<
vtkPolyDataMapper
>
mapper
=
vtkSmartPointer
<
vtkPolyDataMapper
>::
New
();
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetInput
(
appendFilter
->
GetOutput
());
vtkSmartPointer
<
vtkActor
>
actor
=
vtkSmartPointer
<
vtkActor
>::
New
();
...
...
@@ -1329,7 +1377,7 @@ cv::viz::SpheresTrajectoryWidget::SpheresTrajectoryWidget(const std::vector<Affi
Point3f
new_pos
=
path
[
i
].
translation
();
vtkSmartPointer
<
vtkSphereSource
>
sphere_source
=
vtkSmartPointer
<
vtkSphereSource
>::
New
();
sphere_source
->
SetCenter
(
new_pos
.
x
,
new_pos
.
y
,
new_pos
.
z
);
sphere_source
->
SetCenter
(
new_pos
.
x
,
new_pos
.
y
,
new_pos
.
z
);
if
(
i
==
0
)
{
sphere_source
->
SetRadius
(
init_sphere_radius
);
...
...
@@ -1374,4 +1422,4 @@ template<> cv::viz::SpheresTrajectoryWidget cv::viz::Widget::cast<cv::viz::Spher
{
Widget3D
widget
=
this
->
cast
<
Widget3D
>
();
return
static_cast
<
SpheresTrajectoryWidget
&>
(
widget
);
}
\ No newline at end of file
}
modules/viz/src/types.cpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
//////////////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -23,8 +71,8 @@ cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); }
////////////////////////////////////////////////////////////////////
/// cv::viz::KeyboardEvent
cv
::
viz
::
KeyboardEvent
::
KeyboardEvent
(
bool
_action
,
const
std
::
string
&
_key_sym
,
unsigned
char
key
,
bool
alt
,
bool
ctrl
,
bool
shift
)
:
action_
(
_action
),
modifiers_
(
0
),
key_code_
(
key
),
key_sym_
(
_key_sym
)
cv
::
viz
::
KeyboardEvent
::
KeyboardEvent
(
bool
_action
,
const
std
::
string
&
_key_sym
,
unsigned
char
key
,
bool
alt
,
bool
ctrl
,
bool
shift
)
:
action_
(
_action
),
modifiers_
(
0
),
key_code_
(
key
),
key_sym_
(
_key_sym
)
{
if
(
alt
)
modifiers_
=
Alt
;
...
...
@@ -36,18 +84,18 @@ cv::viz::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_sym
modifiers_
|=
Shift
;
}
bool
cv
::
viz
::
KeyboardEvent
::
isAltPressed
()
const
{
return
(
modifiers_
&
Alt
)
!=
0
;
}
bool
cv
::
viz
::
KeyboardEvent
::
isCtrlPressed
()
const
{
return
(
modifiers_
&
Ctrl
)
!=
0
;
}
bool
cv
::
viz
::
KeyboardEvent
::
isShiftPressed
()
const
{
return
(
modifiers_
&
Shift
)
!=
0
;
}
unsigned
char
cv
::
viz
::
KeyboardEvent
::
getKeyCode
()
const
{
return
key_code_
;
}
const
cv
::
String
&
cv
::
viz
::
KeyboardEvent
::
getKeySym
()
const
{
return
key_sym_
;
}
bool
cv
::
viz
::
KeyboardEvent
::
keyDown
()
const
{
return
action_
;
}
bool
cv
::
viz
::
KeyboardEvent
::
keyUp
()
const
{
return
!
action_
;
}
bool
cv
::
viz
::
KeyboardEvent
::
isAltPressed
()
const
{
return
(
modifiers_
&
Alt
)
!=
0
;
}
bool
cv
::
viz
::
KeyboardEvent
::
isCtrlPressed
()
const
{
return
(
modifiers_
&
Ctrl
)
!=
0
;
}
bool
cv
::
viz
::
KeyboardEvent
::
isShiftPressed
()
const
{
return
(
modifiers_
&
Shift
)
!=
0
;
}
unsigned
char
cv
::
viz
::
KeyboardEvent
::
getKeyCode
()
const
{
return
key_code_
;
}
const
cv
::
String
&
cv
::
viz
::
KeyboardEvent
::
getKeySym
()
const
{
return
key_sym_
;
}
bool
cv
::
viz
::
KeyboardEvent
::
keyDown
()
const
{
return
action_
;
}
bool
cv
::
viz
::
KeyboardEvent
::
keyUp
()
const
{
return
!
action_
;
}
////////////////////////////////////////////////////////////////////
/// cv::viz::MouseEvent
cv
::
viz
::
MouseEvent
::
MouseEvent
(
const
Type
&
_type
,
const
MouseButton
&
_button
,
const
Point
&
_p
,
bool
alt
,
bool
ctrl
,
bool
shift
)
cv
::
viz
::
MouseEvent
::
MouseEvent
(
const
Type
&
_type
,
const
MouseButton
&
_button
,
const
Point
&
_p
,
bool
alt
,
bool
ctrl
,
bool
shift
)
:
type
(
_type
),
button
(
_button
),
pointer
(
_p
),
key_state
(
0
)
{
if
(
alt
)
...
...
@@ -73,19 +121,19 @@ struct cv::viz::Mesh3d::loadMeshImpl
reader
->
SetFileName
(
file
.
c_str
());
reader
->
Update
();
vtkSmartPointer
<
vtkPolyData
>
poly_data
=
reader
->
GetOutput
();
vtkSmartPointer
<
vtkPolyData
>
poly_data
=
reader
->
GetOutput
();
CV_Assert
(
"File does not exist or file format is not supported."
&&
poly_data
);
vtkSmartPointer
<
vtkPoints
>
mesh_points
=
poly_data
->
GetPoints
();
vtkIdType
nr_points
=
mesh_points
->
GetNumberOfPoints
();
vtkSmartPointer
<
vtkPoints
>
mesh_points
=
poly_data
->
GetPoints
();
vtkIdType
nr_points
=
mesh_points
->
GetNumberOfPoints
();
mesh
.
cloud
.
create
(
1
,
nr_points
,
CV_32FC3
);
Vec3f
*
mesh_cloud
=
mesh
.
cloud
.
ptr
<
Vec3f
>
();
for
(
vtkIdType
i
=
0
;
i
<
mesh_points
->
GetNumberOfPoints
();
i
++
)
for
(
vtkIdType
i
=
0
;
i
<
mesh_points
->
GetNumberOfPoints
();
i
++
)
{
Vec3d
point
;
mesh_points
->
GetPoint
(
i
,
point
.
val
);
mesh_points
->
GetPoint
(
i
,
point
.
val
);
mesh_cloud
[
i
]
=
point
;
}
...
...
@@ -94,15 +142,15 @@ struct cv::viz::Mesh3d::loadMeshImpl
if
(
poly_data
->
GetPointData
())
poly_colors
=
vtkUnsignedCharArray
::
SafeDownCast
(
poly_data
->
GetPointData
()
->
GetScalars
());
if
(
poly_colors
&&
(
poly_colors
->
GetNumberOfComponents
()
==
3
))
if
(
poly_colors
&&
(
poly_colors
->
GetNumberOfComponents
()
==
3
))
{
mesh
.
colors
.
create
(
1
,
nr_points
,
CV_8UC3
);
Vec3b
*
mesh_colors
=
mesh
.
colors
.
ptr
<
cv
::
Vec3b
>
();
for
(
vtkIdType
i
=
0
;
i
<
mesh_points
->
GetNumberOfPoints
();
i
++
)
for
(
vtkIdType
i
=
0
;
i
<
mesh_points
->
GetNumberOfPoints
();
i
++
)
{
Vec3b
point_color
;
poly_colors
->
GetTupleValue
(
i
,
point_color
.
val
);
poly_colors
->
GetTupleValue
(
i
,
point_color
.
val
);
std
::
swap
(
point_color
[
0
],
point_color
[
2
]);
// RGB -> BGR
mesh_colors
[
i
]
=
point_color
;
...
...
@@ -114,17 +162,17 @@ struct cv::viz::Mesh3d::loadMeshImpl
// Now handle the polygons
vtkIdType
*
cell_points
;
vtkIdType
nr_cell_points
;
vtkCellArray
*
mesh_polygons
=
poly_data
->
GetPolys
();
mesh_polygons
->
InitTraversal
();
vtkCellArray
*
mesh_polygons
=
poly_data
->
GetPolys
();
mesh_polygons
->
InitTraversal
();
mesh
.
polygons
.
create
(
1
,
mesh_polygons
->
GetSize
(),
CV_32SC1
);
int
*
polygons
=
mesh
.
polygons
.
ptr
<
int
>
();
while
(
mesh_polygons
->
GetNextCell
(
nr_cell_points
,
cell_points
))
while
(
mesh_polygons
->
GetNextCell
(
nr_cell_points
,
cell_points
))
{
*
polygons
++
=
nr_cell_points
;
for
(
int
i
=
0
;
i
<
nr_cell_points
;
++
i
)
*
polygons
++
=
static_cast
<
int
>
(
cell_points
[
i
]);
*
polygons
++
=
static_cast
<
int
>
(
cell_points
[
i
]);
}
return
mesh
;
...
...
@@ -257,4 +305,4 @@ cv::viz::Camera cv::viz::Camera::KinectCamera(const Size &window_size)
K
(
1
,
2
)
=
2.6748068171871557e+02
;
K
(
2
,
2
)
=
1.0
f
;
return
Camera
(
K
,
window_size
);
}
\ No newline at end of file
}
modules/viz/src/viz.cpp
View file @
26005a19
#include "precomp.hpp"
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
cv
::
Affine3f
cv
::
viz
::
makeTransformToGlobal
(
const
Vec3f
&
axis_x
,
const
Vec3f
&
axis_y
,
const
Vec3f
&
axis_z
,
const
Vec3f
&
origin
)
{
...
...
@@ -44,7 +91,7 @@ cv::Affine3f cv::viz::makeCameraPose(const Vec3f& position, const Vec3f& focal_p
return
pose_mat
;
}
vtkSmartPointer
<
vtkMatrix4x4
>
cv
::
viz
::
convertToVtkMatrix
(
const
cv
::
Matx44f
&
m
)
vtkSmartPointer
<
vtkMatrix4x4
>
cv
::
viz
::
convertToVtkMatrix
(
const
cv
::
Matx44f
&
m
)
{
vtkSmartPointer
<
vtkMatrix4x4
>
vtk_matrix
=
vtkSmartPointer
<
vtkMatrix4x4
>::
New
();
for
(
int
i
=
0
;
i
<
4
;
i
++
)
...
...
@@ -58,7 +105,7 @@ cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matr
cv
::
Matx44f
m
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
for
(
int
k
=
0
;
k
<
4
;
k
++
)
m
(
i
,
k
)
=
vtk_matrix
->
GetElement
(
i
,
k
);
m
(
i
,
k
)
=
vtk_matrix
->
GetElement
(
i
,
k
);
return
m
;
}
...
...
@@ -165,4 +212,4 @@ void cv::viz::VizAccessor::generateWindowName(const String &window_name, String
cv
::
viz
::
Viz3d
cv
::
viz
::
get
(
const
String
&
window_name
)
{
return
cv
::
viz
::
VizAccessor
::
getInstance
().
get
(
window_name
);
}
\ No newline at end of file
}
modules/viz/src/viz3d.cpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include <opencv2/viz/viz3d.hpp>
#include "viz3d_impl.hpp"
cv
::
viz
::
Viz3d
::
Viz3d
(
const
String
&
window_name
)
:
impl_
(
0
)
{
create
(
window_name
);
}
cv
::
viz
::
Viz3d
::
Viz3d
(
const
Viz3d
&
other
)
:
impl_
(
other
.
impl_
)
...
...
@@ -45,7 +92,7 @@ void cv::viz::Viz3d::release()
}
void
cv
::
viz
::
Viz3d
::
spin
()
{
impl_
->
spin
();
}
void
cv
::
viz
::
Viz3d
::
spinOnce
(
int
time
,
bool
force_redraw
)
{
impl_
->
spinOnce
(
time
,
force_redraw
);
}
void
cv
::
viz
::
Viz3d
::
spinOnce
(
int
time
,
bool
force_redraw
)
{
impl_
->
spinOnce
(
time
,
force_redraw
);
}
bool
cv
::
viz
::
Viz3d
::
wasStopped
()
const
{
return
impl_
->
wasStopped
();
}
void
cv
::
viz
::
Viz3d
::
registerKeyboardCallback
(
KeyboardCallback
callback
,
void
*
cookie
)
...
...
@@ -67,7 +114,7 @@ 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
::
resetCameraViewpoint
(
const
String
&
id
)
{
impl_
->
resetCameraViewpoint
(
id
);
}
void
cv
::
viz
::
Viz3d
::
resetCameraViewpoint
(
const
String
&
id
)
{
impl_
->
resetCameraViewpoint
(
id
);
}
void
cv
::
viz
::
Viz3d
::
resetCamera
()
{
impl_
->
resetCamera
();
}
void
cv
::
viz
::
Viz3d
::
convertToWindowCoordinates
(
const
Point3d
&
pt
,
Point3d
&
window_coord
)
{
impl_
->
convertToWindowCoordinates
(
pt
,
window_coord
);
}
...
...
@@ -76,9 +123,9 @@ void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin,
cv
::
Size
cv
::
viz
::
Viz3d
::
getWindowSize
()
const
{
return
impl_
->
getWindowSize
();
}
void
cv
::
viz
::
Viz3d
::
setWindowSize
(
const
Size
&
window_size
)
{
impl_
->
setWindowSize
(
window_size
.
width
,
window_size
.
height
);
}
cv
::
String
cv
::
viz
::
Viz3d
::
getWindowName
()
const
{
return
impl_
->
getWindowName
();
}
void
cv
::
viz
::
Viz3d
::
saveScreenshot
(
const
String
&
file
)
{
impl_
->
saveScreenshot
(
file
);
}
void
cv
::
viz
::
Viz3d
::
setWindowPosition
(
int
x
,
int
y
)
{
impl_
->
setWindowPosition
(
x
,
y
);
}
void
cv
::
viz
::
Viz3d
::
setFullScreen
(
bool
mode
)
{
impl_
->
setFullScreen
(
mode
);
}
void
cv
::
viz
::
Viz3d
::
saveScreenshot
(
const
String
&
file
)
{
impl_
->
saveScreenshot
(
file
);
}
void
cv
::
viz
::
Viz3d
::
setWindowPosition
(
int
x
,
int
y
)
{
impl_
->
setWindowPosition
(
x
,
y
);
}
void
cv
::
viz
::
Viz3d
::
setFullScreen
(
bool
mode
)
{
impl_
->
setFullScreen
(
mode
);
}
void
cv
::
viz
::
Viz3d
::
setBackgroundColor
(
const
Color
&
color
)
{
impl_
->
setBackgroundColor
(
color
);
}
void
cv
::
viz
::
Viz3d
::
setRenderingProperty
(
const
String
&
id
,
int
property
,
double
value
)
{
getWidget
(
id
).
setRenderingProperty
(
property
,
value
);
}
...
...
modules/viz/src/viz3d_impl.cpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
#include "viz3d_impl.hpp"
#include <vtkRenderWindowInteractor.h>
#if 1 || !defined __APPLE__
vtkRenderWindowInteractor
*
vtkRenderWindowInteractorFixNew
()
vtkRenderWindowInteractor
*
vtkRenderWindowInteractorFixNew
()
{
return
vtkRenderWindowInteractor
::
New
();
}
#endif
/////////////////////////////////////////////////////////////////////////////////////////////
cv
::
viz
::
Viz3d
::
VizImpl
::
VizImpl
(
const
std
::
string
&
name
)
:
style_
(
vtkSmartPointer
<
cv
::
viz
::
InteractorStyle
>::
New
())
,
widget_actor_map_
(
new
WidgetActorMap
)
cv
::
viz
::
Viz3d
::
VizImpl
::
VizImpl
(
const
std
::
string
&
name
)
:
style_
(
vtkSmartPointer
<
cv
::
viz
::
InteractorStyle
>::
New
())
,
widget_actor_map_
(
new
WidgetActorMap
)
,
s_lastDone_
(
0.0
)
{
renderer_
=
vtkSmartPointer
<
vtkRenderer
>::
New
();
renderer_
=
vtkSmartPointer
<
vtkRenderer
>::
New
();
// Create a RendererWindow
window_
=
vtkSmartPointer
<
vtkRenderWindow
>::
New
();
window_
=
vtkSmartPointer
<
vtkRenderWindow
>::
New
();
// Set the window size as 1/2 of the screen size
cv
::
Vec2i
window_size
=
cv
::
Vec2i
(
window_
->
GetScreenSize
())
/
2
;
window_
->
SetSize
(
window_size
.
val
);
window_
->
SetSize
(
window_size
.
val
);
window_
->
AddRenderer
(
renderer_
);
window_
->
AddRenderer
(
renderer_
);
// Create the interactor style
style_
->
Initialize
();
style_
->
setRenderer
(
renderer_
);
style_
->
setWidgetActorMap
(
widget_actor_map_
);
style_
->
UseTimersOn
();
style_
->
Initialize
();
style_
->
setRenderer
(
renderer_
);
style_
->
setWidgetActorMap
(
widget_actor_map_
);
style_
->
UseTimersOn
();
/////////////////////////////////////////////////
interactor_
=
vtkSmartPointer
<
vtkRenderWindowInteractor
>::
Take
(
vtkRenderWindowInteractorFixNew
());
interactor_
=
vtkSmartPointer
<
vtkRenderWindowInteractor
>::
Take
(
vtkRenderWindowInteractorFixNew
());
window_
->
AlphaBitPlanesOff
();
window_
->
PointSmoothingOff
();
window_
->
LineSmoothingOff
();
window_
->
PolygonSmoothingOff
();
window_
->
SwapBuffersOn
();
window_
->
SetStereoTypeToAnaglyph
();
window_
->
AlphaBitPlanesOff
();
window_
->
PointSmoothingOff
();
window_
->
LineSmoothingOff
();
window_
->
PolygonSmoothingOff
();
window_
->
SwapBuffersOn
();
window_
->
SetStereoTypeToAnaglyph
();
interactor_
->
SetRenderWindow
(
window_
);
interactor_
->
SetInteractorStyle
(
style_
);
interactor_
->
SetDesiredUpdateRate
(
30.0
);
interactor_
->
SetRenderWindow
(
window_
);
interactor_
->
SetInteractorStyle
(
style_
);
interactor_
->
SetDesiredUpdateRate
(
30.0
);
// Initialize and create timer, also create window
interactor_
->
Initialize
();
timer_id_
=
interactor_
->
CreateRepeatingTimer
(
5000L
);
interactor_
->
Initialize
();
timer_id_
=
interactor_
->
CreateRepeatingTimer
(
5000L
);
// Set a simple PointPicker
vtkSmartPointer
<
vtkPointPicker
>
pp
=
vtkSmartPointer
<
vtkPointPicker
>::
New
();
pp
->
SetTolerance
(
pp
->
GetTolerance
()
*
2
);
interactor_
->
SetPicker
(
pp
);
vtkSmartPointer
<
vtkPointPicker
>
pp
=
vtkSmartPointer
<
vtkPointPicker
>::
New
();
pp
->
SetTolerance
(
pp
->
GetTolerance
()
*
2
);
interactor_
->
SetPicker
(
pp
);
exit_main_loop_timer_callback_
=
vtkSmartPointer
<
ExitMainLoopTimerCallback
>::
New
();
exit_main_loop_timer_callback_
=
vtkSmartPointer
<
ExitMainLoopTimerCallback
>::
New
();
exit_main_loop_timer_callback_
->
viz_
=
this
;
exit_main_loop_timer_callback_
->
right_timer_id
=
-
1
;
interactor_
->
AddObserver
(
vtkCommand
::
TimerEvent
,
exit_main_loop_timer_callback_
);
interactor_
->
AddObserver
(
vtkCommand
::
TimerEvent
,
exit_main_loop_timer_callback_
);
exit_callback_
=
vtkSmartPointer
<
ExitCallback
>::
New
();
exit_callback_
=
vtkSmartPointer
<
ExitCallback
>::
New
();
exit_callback_
->
viz_
=
this
;
interactor_
->
AddObserver
(
vtkCommand
::
ExitEvent
,
exit_callback_
);
interactor_
->
AddObserver
(
vtkCommand
::
ExitEvent
,
exit_callback_
);
resetStoppedFlag
();
resetStoppedFlag
();
//////////////////////////////
String
window_name
;
VizAccessor
::
generateWindowName
(
name
,
window_name
);
window_
->
SetWindowName
(
window_name
.
c_str
());
window_
->
SetWindowName
(
window_name
.
c_str
());
}
/////////////////////////////////////////////////////////////////////////////////////////////
cv
::
viz
::
Viz3d
::
VizImpl
::~
VizImpl
()
cv
::
viz
::
Viz3d
::
VizImpl
::~
VizImpl
()
{
if
(
interactor_
)
interactor_
->
DestroyTimer
(
timer_id_
);
...
...
@@ -98,7 +146,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget,
{
// If the actor is 3D, apply pose
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
}
// If the actor is a vtkFollower, then it should always face the camera
...
...
@@ -118,7 +166,7 @@ void cv::viz::Viz3d::VizImpl::removeWidget(const String &id)
WidgetActorMap
::
iterator
wam_itr
=
widget_actor_map_
->
find
(
id
);
bool
exists
=
wam_itr
!=
widget_actor_map_
->
end
();
CV_Assert
(
"Widget does not exist."
&&
exists
);
CV_Assert
(
"Widget could not be removed."
&&
removeActorFromRenderer
(
wam_itr
->
second
));
CV_Assert
(
"Widget could not be removed."
&&
removeActorFromRenderer
(
wam_itr
->
second
));
widget_actor_map_
->
erase
(
wam_itr
);
}
...
...
@@ -145,8 +193,8 @@ void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &po
CV_Assert
(
"Widget is not 3D."
&&
actor
);
vtkSmartPointer
<
vtkMatrix4x4
>
matrix
=
convertToVtkMatrix
(
pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
}
/////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -169,8 +217,8 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f
Affine3f
updated_pose
=
pose
*
Affine3f
(
matrix_cv
);
matrix
=
convertToVtkMatrix
(
updated_pose
.
matrix
);
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
actor
->
SetUserMatrix
(
matrix
);
actor
->
Modified
();
}
/////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -204,7 +252,7 @@ double cv::viz::Viz3d::VizImpl::getDesiredUpdateRate()
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
saveScreenshot
(
const
std
::
string
&
file
)
{
style_
->
saveScreenshot
(
file
);
}
void
cv
::
viz
::
Viz3d
::
VizImpl
::
saveScreenshot
(
const
std
::
string
&
file
)
{
style_
->
saveScreenshot
(
file
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
registerMouseCallback
(
MouseCallback
callback
,
void
*
cookie
)
...
...
@@ -214,33 +262,33 @@ void cv::viz::Viz3d::VizImpl::registerKeyboardCallback(KeyboardCallback callback
{
style_
->
registerKeyboardCallback
(
callback
,
cookie
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
spin
()
void
cv
::
viz
::
Viz3d
::
VizImpl
::
spin
()
{
resetStoppedFlag
();
window_
->
Render
();
interactor_
->
Start
();
resetStoppedFlag
();
window_
->
Render
();
interactor_
->
Start
();
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
spinOnce
(
int
time
,
bool
force_redraw
)
void
cv
::
viz
::
Viz3d
::
VizImpl
::
spinOnce
(
int
time
,
bool
force_redraw
)
{
resetStoppedFlag
();
resetStoppedFlag
();
if
(
time
<=
0
)
time
=
1
;
if
(
force_redraw
)
interactor_
->
Render
();
interactor_
->
Render
();
double
s_now_
=
cv
::
getTickCount
()
/
cv
::
getTickFrequency
();
if
(
s_lastDone_
>
s_now_
)
s_lastDone_
=
s_now_
;
if
((
s_now_
-
s_lastDone_
)
>
(
1.0
/
interactor_
->
GetDesiredUpdateRate
()))
if
((
s_now_
-
s_lastDone_
)
>
(
1.0
/
interactor_
->
GetDesiredUpdateRate
()))
{
exit_main_loop_timer_callback_
->
right_timer_id
=
interactor_
->
CreateRepeatingTimer
(
time
);
interactor_
->
Start
();
interactor_
->
DestroyTimer
(
exit_main_loop_timer_callback_
->
right_timer_id
);
exit_main_loop_timer_callback_
->
right_timer_id
=
interactor_
->
CreateRepeatingTimer
(
time
);
interactor_
->
Start
();
interactor_
->
DestroyTimer
(
exit_main_loop_timer_callback_
->
right_timer_id
);
s_lastDone_
=
s_now_
;
}
}
...
...
@@ -253,67 +301,63 @@ void cv::viz::Viz3d::VizImpl::removeAllWidgets()
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool
cv
::
viz
::
Viz3d
::
VizImpl
::
removeActorFromRenderer
(
const
vtkSmartPointer
<
vtkProp
>
&
actor
)
bool
cv
::
viz
::
Viz3d
::
VizImpl
::
removeActorFromRenderer
(
const
vtkSmartPointer
<
vtkProp
>
&
actor
)
{
vtkProp
*
actor_to_remove
=
vtkProp
::
SafeDownCast
(
actor
);
vtkPropCollection
*
actors
=
renderer_
->
GetViewProps
();
actors
->
InitTraversal
();
vtkPropCollection
*
actors
=
renderer_
->
GetViewProps
();
actors
->
InitTraversal
();
vtkProp
*
current_actor
=
NULL
;
while
((
current_actor
=
actors
->
GetNextProp
())
!=
NULL
)
while
((
current_actor
=
actors
->
GetNextProp
())
!=
NULL
)
{
if
(
current_actor
!=
actor_to_remove
)
continue
;
renderer_
->
RemoveActor
(
actor
);
renderer_
->
RemoveActor
(
actor
);
return
true
;
}
return
false
;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
createActorFromVTKDataSet
(
const
vtkSmartPointer
<
vtkDataSet
>
&
data
,
vtkSmartPointer
<
vtkLODActor
>
&
actor
,
bool
use_scalars
)
void
cv
::
viz
::
Viz3d
::
VizImpl
::
createActorFromVTKDataSet
(
const
vtkSmartPointer
<
vtkDataSet
>
&
data
,
vtkSmartPointer
<
vtkLODActor
>
&
actor
,
bool
use_scalars
)
{
if
(
!
actor
)
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
data
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
mapper
->
SetInput
(
data
);
if
(
use_scalars
)
{
vtkSmartPointer
<
vtkDataArray
>
scalars
=
data
->
GetPointData
()
->
GetScalars
();
vtkSmartPointer
<
vtkDataArray
>
scalars
=
data
->
GetPointData
()
->
GetScalars
();
if
(
scalars
)
{
cv
::
Vec3d
minmax
(
scalars
->
GetRange
());
mapper
->
SetScalarRange
(
minmax
.
val
);
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetScalarModeToUsePointData
();
// interpolation OFF, if data is a vtkPolyData that contains only vertices, ON for anything else.
vtkPolyData
*
polyData
=
vtkPolyData
::
SafeDownCast
(
data
);
bool
interpolation
=
(
polyData
&&
polyData
->
GetNumberOfCells
()
!=
polyData
->
GetNumberOfVerts
());
vtkPolyData
*
polyData
=
vtkPolyData
::
SafeDownCast
(
data
);
bool
interpolation
=
(
polyData
&&
polyData
->
GetNumberOfCells
()
!=
polyData
->
GetNumberOfVerts
());
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOn
();
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOn
();
}
}
mapper
->
ImmediateModeRenderingOff
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
data
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
mapper
->
ImmediateModeRenderingOff
();
/// FIXME disabling backface culling due to known VTK bug: vtkTextActors are not
/// shown when there is a vtkActor with backface culling on present in the scene
/// Please see VTK bug tracker for more details: http://www.vtk.org/Bug/view.php?id=12588
// actor->GetProperty ()->BackfaceCullingOn ();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
data
->
GetNumberOfPoints
()
/
10
)));
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
actor
->
SetMapper
(
mapper
);
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setBackgroundColor
(
const
Color
&
color
)
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setBackgroundColor
(
const
Color
&
color
)
{
Color
c
=
vtkcolor
(
color
);
renderer_
->
SetBackground
(
c
.
val
);
renderer_
->
SetBackground
(
c
.
val
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -322,7 +366,7 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
vtkCamera
&
active_camera
=
*
renderer_
->
GetActiveCamera
();
// Set the intrinsic parameters of the camera
window_
->
SetSize
(
camera
.
getWindowSize
().
width
,
camera
.
getWindowSize
().
height
);
window_
->
SetSize
(
camera
.
getWindowSize
().
width
,
camera
.
getWindowSize
().
height
);
double
aspect_ratio
=
static_cast
<
double
>
(
camera
.
getWindowSize
().
width
)
/
static_cast
<
double
>
(
camera
.
getWindowSize
().
height
);
Matx44f
proj_mat
;
...
...
@@ -353,18 +397,18 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
/////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setViewerPose
(
const
Affine3f
&
pose
)
{
vtkCamera
&
camera
=
*
renderer_
->
GetActiveCamera
();
vtkCamera
&
camera
=
*
renderer_
->
GetActiveCamera
();
// Position = extrinsic translation
cv
::
Vec3f
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
::
Vec3f
y_axis
(
0.
f
,
1.
f
,
0.
f
);
cv
::
Vec3f
up_vec
(
rotation
*
y_axis
);
// Compute the new focal point
cv
::
Vec3f
z_axis
(
0.
f
,
0.
f
,
1.
f
);
cv
::
Vec3f
z_axis
(
0.
f
,
0.
f
,
1.
f
);
cv
::
Vec3f
focal_vec
=
pos_vec
+
rotation
*
z_axis
;
camera
.
SetPosition
(
pos_vec
[
0
],
pos_vec
[
1
],
pos_vec
[
2
]);
...
...
@@ -373,9 +417,9 @@ void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
}
/////////////////////////////////////////////////////////////////////////////////////////////
cv
::
Affine3f
cv
::
viz
::
Viz3d
::
VizImpl
::
getViewerPose
()
cv
::
Affine3f
cv
::
viz
::
Viz3d
::
VizImpl
::
getViewerPose
()
{
vtkCamera
&
camera
=
*
renderer_
->
GetActiveCamera
();
vtkCamera
&
camera
=
*
renderer_
->
GetActiveCamera
();
Vec3d
pos
(
camera
.
GetPosition
());
Vec3d
view_up
(
camera
.
GetViewUp
());
...
...
@@ -423,11 +467,11 @@ void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d
}
/////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
resetCameraViewpoint
(
const
String
&
id
)
void
cv
::
viz
::
Viz3d
::
VizImpl
::
resetCameraViewpoint
(
const
String
&
id
)
{
vtkSmartPointer
<
vtkMatrix4x4
>
camera_pose
;
static
WidgetActorMap
::
iterator
it
=
widget_actor_map_
->
find
(
id
);
if
(
it
!=
widget_actor_map_
->
end
())
static
WidgetActorMap
::
iterator
it
=
widget_actor_map_
->
find
(
id
);
if
(
it
!=
widget_actor_map_
->
end
())
{
vtkProp3D
*
actor
=
vtkProp3D
::
SafeDownCast
(
it
->
second
);
CV_Assert
(
"Widget is not 3D."
&&
actor
);
...
...
@@ -439,22 +483,22 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const String &id)
// Prevent a segfault
if
(
!
camera_pose
)
return
;
vtkSmartPointer
<
vtkCamera
>
cam
=
renderer_
->
GetActiveCamera
();
cam
->
SetPosition
(
camera_pose
->
GetElement
(
0
,
3
),
camera_pose
->
GetElement
(
1
,
3
),
camera_pose
->
GetElement
(
2
,
3
));
vtkSmartPointer
<
vtkCamera
>
cam
=
renderer_
->
GetActiveCamera
();
cam
->
SetPosition
(
camera_pose
->
GetElement
(
0
,
3
),
camera_pose
->
GetElement
(
1
,
3
),
camera_pose
->
GetElement
(
2
,
3
));
cam
->
SetFocalPoint
(
camera_pose
->
GetElement
(
0
,
3
)
-
camera_pose
->
GetElement
(
0
,
2
),
camera_pose
->
GetElement
(
1
,
3
)
-
camera_pose
->
GetElement
(
1
,
2
),
camera_pose
->
GetElement
(
2
,
3
)
-
camera_pose
->
GetElement
(
2
,
2
));
cam
->
SetFocalPoint
(
camera_pose
->
GetElement
(
0
,
3
)
-
camera_pose
->
GetElement
(
0
,
2
),
camera_pose
->
GetElement
(
1
,
3
)
-
camera_pose
->
GetElement
(
1
,
2
),
camera_pose
->
GetElement
(
2
,
3
)
-
camera_pose
->
GetElement
(
2
,
2
));
cam
->
SetViewUp
(
camera_pose
->
GetElement
(
0
,
1
),
camera_pose
->
GetElement
(
1
,
1
),
camera_pose
->
GetElement
(
2
,
1
));
cam
->
SetViewUp
(
camera_pose
->
GetElement
(
0
,
1
),
camera_pose
->
GetElement
(
1
,
1
),
camera_pose
->
GetElement
(
2
,
1
));
renderer_
->
SetActiveCamera
(
cam
);
renderer_
->
ResetCameraClippingRange
();
renderer_
->
Render
();
renderer_
->
SetActiveCamera
(
cam
);
renderer_
->
ResetCameraClippingRange
();
renderer_
->
Render
();
}
///////////////////////////////////////////////////////////////////////////////////
...
...
@@ -493,53 +537,53 @@ void cv::viz::Viz3d::VizImpl::setRepresentation(int representation)
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
updateCells
(
vtkSmartPointer
<
vtkIdTypeArray
>
&
cells
,
vtkSmartPointer
<
vtkIdTypeArray
>
&
initcells
,
vtkIdType
nr_points
)
void
cv
::
viz
::
Viz3d
::
VizImpl
::
updateCells
(
vtkSmartPointer
<
vtkIdTypeArray
>
&
cells
,
vtkSmartPointer
<
vtkIdTypeArray
>
&
initcells
,
vtkIdType
nr_points
)
{
// If no init cells and cells has not been initialized...
if
(
!
cells
)
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If we have less values then we need to recreate the array
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
{
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If init cells is given, and there's enough data in it, use it
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
{
cells
->
DeepCopy
(
initcells
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
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
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
vtkIdType
*
cell
=
cells
->
GetPointer
(
0
);
// Fill it with 1s
std
::
fill_n
(
cell
,
nr_points
*
2
,
1
);
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
);
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
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setFullScreen
(
bool
mode
)
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setFullScreen
(
bool
mode
)
{
if
(
window_
)
window_
->
SetFullScreen
(
mode
);
window_
->
SetFullScreen
(
mode
);
}
//////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -549,6 +593,6 @@ cv::String cv::viz::Viz3d::VizImpl::getWindowName() const
}
//////////////////////////////////////////////////////////////////////////////////////////////
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setWindowPosition
(
int
x
,
int
y
)
{
window_
->
SetPosition
(
x
,
y
);
}
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setWindowSize
(
int
xw
,
int
yw
)
{
window_
->
SetSize
(
xw
,
yw
);
}
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setWindowPosition
(
int
x
,
int
y
)
{
window_
->
SetPosition
(
x
,
y
);
}
void
cv
::
viz
::
Viz3d
::
VizImpl
::
setWindowSize
(
int
xw
,
int
yw
)
{
window_
->
SetSize
(
xw
,
yw
);
}
cv
::
Size
cv
::
viz
::
Viz3d
::
VizImpl
::
getWindowSize
()
const
{
return
Size
(
window_
->
GetSize
()[
0
],
window_
->
GetSize
()[
1
]);
}
modules/viz/src/viz3d_impl.hpp
View file @
26005a19
#pragma once
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifndef __OPENCV_VIZ_VIZ3D_IMPL_HPP__
#define __OPENCV_VIZ_VIZ3D_IMPL_HPP__
#include <opencv2/viz.hpp>
#include "interactor_style.h"
...
...
@@ -12,8 +61,8 @@ public:
int
ref_counter
;
VizImpl
(
const
String
&
name
);
virtual
~
VizImpl
();
VizImpl
(
const
String
&
name
);
virtual
~
VizImpl
();
void
showWidget
(
const
String
&
id
,
const
Widget
&
widget
,
const
Affine3f
&
pose
=
Affine3f
::
Identity
());
void
removeWidget
(
const
String
&
id
);
...
...
@@ -28,19 +77,19 @@ public:
double
getDesiredUpdateRate
();
/** \brief Returns true when the user tried to close the window */
bool
wasStopped
()
const
{
if
(
interactor_
!=
NULL
)
return
(
stopped_
);
else
return
true
;
}
bool
wasStopped
()
const
{
if
(
interactor_
!=
NULL
)
return
(
stopped_
);
else
return
true
;
}
/** \brief Set the stopped flag back to false */
void
resetStoppedFlag
()
{
if
(
interactor_
!=
NULL
)
stopped_
=
false
;
}
void
resetStoppedFlag
()
{
if
(
interactor_
!=
NULL
)
stopped_
=
false
;
}
/** \brief Stop the interaction and close the visualizaton window. */
void
close
()
void
close
()
{
stopped_
=
true
;
if
(
interactor_
)
{
interactor_
->
GetRenderWindow
()
->
Finalize
();
interactor_
->
TerminateApp
();
// This tends to close the window...
interactor_
->
TerminateApp
();
// This tends to close the window...
}
}
...
...
@@ -49,8 +98,7 @@ public:
void
setCamera
(
const
Camera
&
camera
);
Camera
getCamera
()
const
;
/** \brief Reset the camera direction from {0, 0, 0} to the center_{x, y, z} of a given dataset.
* \param[in] id the point cloud object id (default: cloud) */
/** \brief Reset the camera to a given widget */
void
resetCameraViewpoint
(
const
String
&
id
);
void
resetCamera
();
...
...
@@ -60,16 +108,16 @@ public:
void
convertToWindowCoordinates
(
const
Point3d
&
pt
,
Point3d
&
window_coord
);
void
converTo3DRay
(
const
Point3d
&
window_coord
,
Point3d
&
origin
,
Vec3d
&
direction
);
void
saveScreenshot
(
const
String
&
file
);
void
setWindowPosition
(
int
x
,
int
y
);
void
saveScreenshot
(
const
String
&
file
);
void
setWindowPosition
(
int
x
,
int
y
);
Size
getWindowSize
()
const
;
void
setWindowSize
(
int
xw
,
int
yw
);
void
setFullScreen
(
bool
mode
);
void
setWindowSize
(
int
xw
,
int
yw
);
void
setFullScreen
(
bool
mode
);
String
getWindowName
()
const
;
void
setBackgroundColor
(
const
Color
&
color
);
void
setBackgroundColor
(
const
Color
&
color
);
void
spin
();
void
spinOnce
(
int
time
=
1
,
bool
force_redraw
=
false
);
void
spin
();
void
spinOnce
(
int
time
=
1
,
bool
force_redraw
=
false
);
void
registerKeyboardCallback
(
KeyboardCallback
callback
,
void
*
cookie
=
0
);
void
registerMouseCallback
(
MouseCallback
callback
,
void
*
cookie
=
0
);
...
...
@@ -88,12 +136,12 @@ private:
if
(
event_id
!=
vtkCommand
::
TimerEvent
)
return
;
int
timer_id
=
*
reinterpret_cast
<
int
*>
(
call_data
);
int
timer_id
=
*
reinterpret_cast
<
int
*>
(
call_data
);
if
(
timer_id
!=
right_timer_id
)
return
;
// Stop vtk loop and send notification to app to wake it up
viz_
->
interactor_
->
TerminateApp
();
viz_
->
interactor_
->
TerminateApp
();
}
int
right_timer_id
;
VizImpl
*
viz_
;
...
...
@@ -101,17 +149,17 @@ private:
struct
ExitCallback
:
public
vtkCommand
{
static
ExitCallback
*
New
()
static
ExitCallback
*
New
()
{
return
new
ExitCallback
;
}
virtual
void
Execute
(
vtkObject
*
,
unsigned
long
event_id
,
void
*
)
virtual
void
Execute
(
vtkObject
*
,
unsigned
long
event_id
,
void
*
)
{
if
(
event_id
==
vtkCommand
::
ExitEvent
)
{
viz_
->
stopped_
=
true
;
viz_
->
interactor_
->
GetRenderWindow
()
->
Finalize
();
viz_
->
interactor_
->
TerminateApp
();
viz_
->
interactor_
->
TerminateApp
();
}
}
VizImpl
*
viz_
;
...
...
@@ -141,14 +189,14 @@ private:
/** \brief Boolean that holds whether or not the camera parameters were manually initialized*/
bool
camera_set_
;
bool
removeActorFromRenderer
(
const
vtkSmartPointer
<
vtkProp
>
&
actor
);
bool
removeActorFromRenderer
(
const
vtkSmartPointer
<
vtkProp
>
&
actor
);
/** \brief Internal method. Creates a vtk actor from a vtk polydata object.
* \param[in] data the vtk polydata object to create an actor for
* \param[out] actor the resultant vtk actor object
* \param[in] use_scalars set scalar properties to the mapper if it exists in the data. Default: true.
*/
void
createActorFromVTKDataSet
(
const
vtkSmartPointer
<
vtkDataSet
>
&
data
,
vtkSmartPointer
<
vtkLODActor
>
&
actor
,
bool
use_scalars
=
true
);
void
createActorFromVTKDataSet
(
const
vtkSmartPointer
<
vtkDataSet
>
&
data
,
vtkSmartPointer
<
vtkLODActor
>
&
actor
,
bool
use_scalars
=
true
);
/** \brief Updates a set of cells (vtkIdTypeArray) if the number of points in a cloud changes
* \param[out] cells the vtkIdTypeArray object (set of cells) to update
...
...
@@ -158,7 +206,7 @@ private:
* \param[in] nr_points the number of points in the new cloud. This dictates how many cells we need to
* generate
*/
void
updateCells
(
vtkSmartPointer
<
vtkIdTypeArray
>
&
cells
,
vtkSmartPointer
<
vtkIdTypeArray
>
&
initcells
,
vtkIdType
nr_points
);
void
updateCells
(
vtkSmartPointer
<
vtkIdTypeArray
>
&
cells
,
vtkSmartPointer
<
vtkIdTypeArray
>
&
initcells
,
vtkIdType
nr_points
);
};
...
...
@@ -167,7 +215,7 @@ namespace cv
{
namespace
viz
{
vtkSmartPointer
<
vtkMatrix4x4
>
convertToVtkMatrix
(
const
cv
::
Matx44f
&
m
);
vtkSmartPointer
<
vtkMatrix4x4
>
convertToVtkMatrix
(
const
cv
::
Matx44f
&
m
);
cv
::
Matx44f
convertToMatx
(
const
vtkSmartPointer
<
vtkMatrix4x4
>&
vtk_matrix
);
struct
NanFilter
...
...
@@ -186,12 +234,12 @@ namespace cv
int
s_chs
=
source
.
channels
();
int
m_chs
=
nan_mask
.
channels
();
for
(
int
y
=
0
;
y
<
source
.
rows
;
++
y
)
for
(
int
y
=
0
;
y
<
source
.
rows
;
++
y
)
{
const
_Tp
*
srow
=
source
.
ptr
<
_Tp
>
(
y
);
const
_Msk
*
mrow
=
nan_mask
.
ptr
<
_Msk
>
(
y
);
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
mrow
+=
m_chs
)
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
mrow
+=
m_chs
)
if
(
!
isNan
(
mrow
[
0
])
&&
!
isNan
(
mrow
[
1
])
&&
!
isNan
(
mrow
[
2
]))
*
output
++
=
_Out
(
srow
);
}
...
...
@@ -207,12 +255,12 @@ namespace cv
int
s_chs
=
source
.
channels
();
int
m_chs
=
nan_mask
.
channels
();
for
(
int
y
=
0
;
y
<
source
.
rows
;
++
y
)
for
(
int
y
=
0
;
y
<
source
.
rows
;
++
y
)
{
const
_Tp
*
srow
=
source
.
ptr
<
_Tp
>
(
y
);
const
_Msk
*
mrow
=
nan_mask
.
ptr
<
_Msk
>
(
y
);
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
mrow
+=
m_chs
)
for
(
int
x
=
0
;
x
<
source
.
cols
;
++
x
,
srow
+=
s_chs
,
mrow
+=
m_chs
)
if
(
!
isNan
(
mrow
[
0
])
&&
!
isNan
(
mrow
[
1
])
&&
!
isNan
(
mrow
[
2
]))
{
*
output
=
_Out
(
srow
);
...
...
@@ -338,6 +386,6 @@ namespace cv
}
};
}
}
#endif
modules/viz/src/widget.cpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
///////////////////////////////////////////////////////////////////////////////////////////////
...
...
modules/viz/test/test_precomp.hpp
View file @
26005a19
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
// Authors:
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
# if defined __clang__ || defined __APPLE__
...
...
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