Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
7dbf6bc8
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7dbf6bc8
编写于
12月 12, 2013
作者:
A
Anatoly Baksheev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rewrote cloud widget in vtk filters style
Conflicts: modules/viz/src/clouds.cpp
上级
159de9cc
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
675 addition
and
140 deletion
+675
-140
modules/viz/src/clouds.cpp
modules/viz/src/clouds.cpp
+13
-140
modules/viz/src/precomp.hpp
modules/viz/src/precomp.hpp
+4
-0
modules/viz/src/vtk/vtkCloudColorMatSource.cpp
modules/viz/src/vtk/vtkCloudColorMatSource.cpp
+168
-0
modules/viz/src/vtk/vtkCloudColorMatSource.h
modules/viz/src/vtk/vtkCloudColorMatSource.h
+88
-0
modules/viz/src/vtk/vtkCloudMatSource.cpp
modules/viz/src/vtk/vtkCloudMatSource.cpp
+105
-0
modules/viz/src/vtk/vtkCloudMatSource.h
modules/viz/src/vtk/vtkCloudMatSource.h
+83
-0
modules/viz/src/vtk/vtkColorMatSource.cpp
modules/viz/src/vtk/vtkColorMatSource.cpp
+132
-0
modules/viz/src/vtk/vtkColorMatSource.h
modules/viz/src/vtk/vtkColorMatSource.h
+82
-0
未找到文件。
modules/viz/src/clouds.cpp
浏览文件 @
7dbf6bc8
...
...
@@ -59,103 +59,10 @@ namespace cv
///////////////////////////////////////////////////////////////////////////////////////////////
/// Point Cloud Widget implementation
namespace
cv
{
namespace
viz
{
namespace
{
struct
CloudUtils
{
static
inline
vtkSmartPointer
<
vtkPolyData
>
create
(
const
Mat
&
cloud
,
vtkIdType
&
nr_points
)
{
vtkSmartPointer
<
vtkPolyData
>
polydata
=
vtkSmartPointer
<
vtkPolyData
>::
New
();
vtkSmartPointer
<
vtkCellArray
>
vertices
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
polydata
->
SetVerts
(
vertices
);
vtkSmartPointer
<
vtkPoints
>
points
=
polydata
->
GetPoints
();
vtkSmartPointer
<
vtkIdTypeArray
>
initcells
;
nr_points
=
cloud
.
total
();
if
(
!
points
)
{
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
if
(
cloud
.
depth
()
==
CV_32F
)
points
->
SetDataTypeToFloat
();
else
if
(
cloud
.
depth
()
==
CV_64F
)
points
->
SetDataTypeToDouble
();
polydata
->
SetPoints
(
points
);
}
points
->
SetNumberOfPoints
(
nr_points
);
if
(
cloud
.
depth
()
==
CV_32F
)
{
// Get a pointer to the beginning of the data array
Vec3f
*
data_beg
=
vtkpoints_data
<
float
>
(
points
);
Vec3f
*
data_end
=
NanFilter
::
copy
(
cloud
,
data_beg
,
cloud
);
nr_points
=
data_end
-
data_beg
;
}
else
if
(
cloud
.
depth
()
==
CV_64F
)
{
// Get a pointer to the beginning of the data array
Vec3d
*
data_beg
=
vtkpoints_data
<
double
>
(
points
);
Vec3d
*
data_end
=
NanFilter
::
copy
(
cloud
,
data_beg
,
cloud
);
nr_points
=
data_end
-
data_beg
;
}
points
->
SetNumberOfPoints
(
nr_points
);
// Update cells
vtkSmartPointer
<
vtkIdTypeArray
>
cells
=
vertices
->
GetData
();
// If no init cells and cells has not been initialized...
if
(
!
cells
)
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If we have less values then we need to recreate the array
if
(
cells
->
GetNumberOfTuples
()
<
nr_points
)
{
cells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
// If init cells is given, and there's enough data in it, use it
if
(
initcells
&&
initcells
->
GetNumberOfTuples
()
>=
nr_points
)
{
cells
->
DeepCopy
(
initcells
);
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
}
else
{
// If the number of tuples is still too small, we need to recreate the array
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
vtkIdType
*
cell
=
cells
->
GetPointer
(
0
);
// Fill it with 1s
std
::
fill
(
cell
,
cell
+
nr_points
*
2
,
1
);
cell
++
;
for
(
vtkIdType
i
=
0
;
i
<
nr_points
;
++
i
,
cell
+=
2
)
*
cell
=
i
;
// Save the results in initcells
initcells
=
vtkSmartPointer
<
vtkIdTypeArray
>::
New
();
initcells
->
DeepCopy
(
cells
);
}
}
else
{
// The assumption here is that the current set of cells has more data than needed
cells
->
SetNumberOfComponents
(
2
);
cells
->
SetNumberOfTuples
(
nr_points
);
}
// Set the cells and the vertices
vertices
->
SetCells
(
nr_points
,
cells
);
return
polydata
;
}
};
}}}
cv
::
viz
::
WCloud
::
WCloud
(
InputArray
_cloud
,
InputArray
_colors
)
{
Mat
cloud
=
_cloud
.
getMat
();
Mat
colors
=
_colors
.
getMat
();
CV_Assert
(
cloud
.
type
()
==
CV_32FC3
||
cloud
.
type
()
==
CV_64FC3
||
cloud
.
type
()
==
CV_32FC4
||
cloud
.
type
()
==
CV_64FC4
);
CV_Assert
(
colors
.
depth
()
==
CV_8U
&&
cloud
.
size
()
==
colors
.
size
());
if
(
cloud
.
isContinuous
()
&&
colors
.
isContinuous
())
{
...
...
@@ -163,41 +70,18 @@ cv::viz::WCloud::WCloud(InputArray _cloud, InputArray _colors)
colors
=
colors
.
reshape
(
colors
.
channels
(),
1
);
}
vtkIdType
nr_points
;
vtkSmartPointer
<
vtkPolyData
>
polydata
=
CloudUtils
::
create
(
cloud
,
nr_points
);
// Filter 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
);
// Assign the colors
polydata
->
GetPointData
()
->
SetScalars
(
scalars
);
vtkSmartPointer
<
vtkCloudColorMatSource
>
cloud_source
=
vtkSmartPointer
<
vtkCloudColorMatSource
>::
New
();
cloud_source
->
SetCloud
(
cloud
);
cloud_source
->
SetColors
(
colors
,
cloud
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
#if VTK_MAJOR_VERSION <= 5
mapper
->
SetInput
(
polydata
);
#else
mapper
->
SetInputData
(
polydata
);
#endif
Vec2d
minmax
(
scalars
->
GetRange
());
mapper
->
SetScalarRange
(
minmax
.
val
);
mapper
->
SetInputConnection
(
cloud_source
->
GetOutputPort
());
mapper
->
SetScalarModeToUsePointData
();
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOn
();
mapper
->
ImmediateModeRenderingOff
();
mapper
->
SetScalarRange
(
0
,
255
);
mapper
->
ScalarVisibilityOn
();
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
vtkSmartPointer
<
vtkActor
>
actor
=
vtkSmartPointer
<
vtkActor
>::
New
();
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -208,27 +92,16 @@ cv::viz::WCloud::WCloud(InputArray _cloud, InputArray _colors)
cv
::
viz
::
WCloud
::
WCloud
(
InputArray
_cloud
,
const
Color
&
color
)
{
Mat
cloud
=
_cloud
.
getMat
();
CV_Assert
(
cloud
.
type
()
==
CV_32FC3
||
cloud
.
type
()
==
CV_64FC3
||
cloud
.
type
()
==
CV_32FC4
||
cloud
.
type
()
==
CV_64FC4
);
vtk
IdType
nr_points
;
vtkSmartPointer
<
vtkPolyData
>
polydata
=
CloudUtils
::
create
(
cloud
,
nr_points
);
vtk
SmartPointer
<
vtkCloudMatSource
>
cloud_source
=
vtkSmartPointer
<
vtkCloudMatSource
>::
New
()
;
cloud_source
->
SetCloud
(
cloud
);
vtkSmartPointer
<
vtkDataSetMapper
>
mapper
=
vtkSmartPointer
<
vtkDataSetMapper
>::
New
();
#if VTK_MAJOR_VERSION <= 5
mapper
->
SetInput
(
polydata
);
#else
mapper
->
SetInputData
(
polydata
);
#endif
bool
interpolation
=
(
polydata
&&
polydata
->
GetNumberOfCells
()
!=
polydata
->
GetNumberOfVerts
());
mapper
->
SetInterpolateScalarsBeforeMapping
(
interpolation
);
mapper
->
ScalarVisibilityOff
();
mapper
->
SetInputConnection
(
cloud_source
->
GetOutputPort
());
mapper
->
ImmediateModeRenderingOff
();
mapper
->
ScalarVisibilityOff
();
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkSmartPointer
<
vtkLODActor
>::
New
();
actor
->
SetNumberOfCloudPoints
(
int
(
std
::
max
<
vtkIdType
>
(
1
,
polydata
->
GetNumberOfPoints
()
/
10
)));
vtkSmartPointer
<
vtkActor
>
actor
=
vtkSmartPointer
<
vtkActor
>::
New
();
actor
->
GetProperty
()
->
SetInterpolationToFlat
();
actor
->
GetProperty
()
->
BackfaceCullingOn
();
actor
->
SetMapper
(
mapper
);
...
...
@@ -435,8 +308,8 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
vtkLODActor
*
actor
=
vtkLODActor
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
*
this
));
CV_Assert
(
"Incompatible widget type."
&&
actor
);
CloudCollectionUtils
::
createMapper
(
actor
,
transform_filter
->
GetOutput
());
}
void
cv
::
viz
::
WCloudCollection
::
addCloud
(
InputArray
_cloud
,
const
Color
&
color
,
const
Affine3f
&
pose
)
...
...
modules/viz/src/precomp.hpp
浏览文件 @
7dbf6bc8
...
...
@@ -114,6 +114,10 @@
#include <vtkPolyDataAlgorithm.h>
#include <vtkMergeFilter.h>
#include <vtk/vtkCloudMatSource.h>
#include <vtk/vtkColorMatSource.h>
#include <vtk/vtkCloudColorMatSource.h>
#include <opencv2/core.hpp>
#include <opencv2/viz.hpp>
#include <opencv2/viz/widget_accessor.hpp>
...
...
modules/viz/src/vtk/vtkCloudColorMatSource.cpp
0 → 100644
浏览文件 @
7dbf6bc8
/*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:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
//M*/
#include "precomp.hpp"
namespace
cv
{
namespace
viz
{
vtkStandardNewMacro
(
vtkCloudColorMatSource
);
struct
IsNotNan
{
template
<
typename
_Tp
>
bool
operator
()(
const
_Tp
*
data
)
const
{
return
!
isNan
(
data
[
0
])
&&
!
isNan
(
data
[
1
])
&&
!
isNan
(
data
[
2
]);
}
};
}}
cv
::
viz
::
vtkCloudColorMatSource
::
vtkCloudColorMatSource
()
{
SetNumberOfInputPorts
(
0
);
}
cv
::
viz
::
vtkCloudColorMatSource
::~
vtkCloudColorMatSource
()
{}
void
cv
::
viz
::
vtkCloudColorMatSource
::
SetCloud
(
const
Mat
&
cloud
)
{
CV_Assert
(
cloud
.
depth
()
==
CV_32F
||
cloud
.
depth
()
==
CV_64F
);
CV_Assert
(
cloud
.
channels
()
==
3
||
cloud
.
channels
()
==
4
);
int
total
=
cloud
.
depth
()
==
CV_32F
?
filterNanCopy
<
float
>
(
cloud
,
VTK_FLOAT
)
:
filterNanCopy
<
double
>
(
cloud
,
VTK_DOUBLE
);
vertices
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
vertices
->
Allocate
(
vertices
->
EstimateSize
(
1
,
total
));
vertices
->
InsertNextCell
(
total
);
for
(
int
i
=
0
;
i
<
total
;
++
i
)
vertices
->
InsertCellPoint
(
i
);
}
void
cv
::
viz
::
vtkCloudColorMatSource
::
SetColors
(
const
Mat
&
colors
,
const
Mat
&
cloud_mask
)
{
CV_Assert
(
colors
.
depth
()
==
CV_8U
&&
colors
.
channels
()
<=
4
&&
colors
.
channels
()
!=
2
);
CV_Assert
(
cloud_mask
.
depth
()
==
CV_32F
||
cloud_mask
.
depth
()
==
CV_64F
);
CV_Assert
(
colors
.
size
()
==
cloud_mask
.
size
());
if
(
cloud_mask
.
depth
()
==
CV_32F
)
filterNanCopy
<
float
,
IsNotNan
>
(
colors
,
cloud_mask
);
else
if
(
cloud_mask
.
depth
()
==
CV_64F
)
filterNanCopy
<
double
,
IsNotNan
>
(
colors
,
cloud_mask
);
}
int
cv
::
viz
::
vtkCloudColorMatSource
::
RequestData
(
vtkInformation
*
vtkNotUsed
(
request
),
vtkInformationVector
**
vtkNotUsed
(
inputVector
),
vtkInformationVector
*
outputVector
)
{
vtkInformation
*
outInfo
=
outputVector
->
GetInformationObject
(
0
);
vtkPolyData
*
output
=
vtkPolyData
::
SafeDownCast
(
outInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
output
->
SetPoints
(
points
);
output
->
SetVerts
(
vertices
);
output
->
GetPointData
()
->
SetScalars
(
scalars
);
return
1
;
}
template
<
typename
_Tp
>
int
cv
::
viz
::
vtkCloudColorMatSource
::
filterNanCopy
(
const
Mat
&
source
,
int
dataType
)
{
CV_DbgAssert
(
DataType
<
_Tp
>::
depth
==
source
.
depth
());
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
points
->
SetDataType
(
dataType
);
points
->
Allocate
(
source
.
total
());
points
->
SetNumberOfPoints
(
source
.
total
());
int
cn
=
source
.
channels
();
int
total
=
0
;
for
(
int
y
=
0
;
y
<
source
.
rows
;
++
y
)
{
const
_Tp
*
srow
=
source
.
ptr
<
_Tp
>
(
y
);
const
_Tp
*
send
=
srow
+
source
.
cols
*
cn
;
for
(;
srow
!=
send
;
srow
+=
cn
)
if
(
!
isNan
(
srow
[
0
])
&&
!
isNan
(
srow
[
1
])
&&
!
isNan
(
srow
[
2
]))
points
->
SetPoint
(
total
++
,
srow
);
}
points
->
SetNumberOfPoints
(
total
);
points
->
Squeeze
();
return
total
;
}
template
<
typename
_Msk
,
class
_NanPred
>
void
cv
::
viz
::
vtkCloudColorMatSource
::
filterNanCopy
(
const
Mat
&
colors
,
const
Mat
&
mask
)
{
Mat
buffer
(
colors
.
size
(),
CV_8UC3
);
Vec3b
*
pos
=
buffer
.
ptr
<
Vec3b
>
();
int
s_chs
=
colors
.
channels
();
int
m_chs
=
mask
.
channels
();
_NanPred
pred
;
for
(
int
y
=
0
;
y
<
colors
.
rows
;
++
y
)
{
const
unsigned
char
*
srow
=
colors
.
ptr
<
unsigned
char
>
(
y
);
const
unsigned
char
*
send
=
srow
+
colors
.
cols
*
colors
.
channels
();
const
_Msk
*
mrow
=
mask
.
empty
()
?
0
:
mask
.
ptr
<
_Msk
>
(
y
);
if
(
colors
.
channels
()
==
1
)
{
for
(;
srow
!=
send
;
srow
+=
s_chs
,
mrow
+=
m_chs
)
if
(
pred
(
mrow
))
*
pos
++
=
Vec3b
(
srow
[
0
],
srow
[
0
],
srow
[
0
]);
}
else
for
(;
srow
!=
send
;
srow
+=
s_chs
,
mrow
+=
m_chs
)
if
(
pred
(
mrow
))
*
pos
++
=
Vec3b
(
srow
[
2
],
srow
[
1
],
srow
[
0
]);
}
int
total
=
pos
-
buffer
.
ptr
<
Vec3b
>
();
Vec3b
*
array
=
new
Vec3b
[
total
];
std
::
copy
(
buffer
.
ptr
<
Vec3b
>
(),
pos
,
array
);
scalars
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
scalars
->
SetName
(
"colors"
);
scalars
->
SetNumberOfComponents
(
3
);
scalars
->
SetNumberOfTuples
(
total
);
scalars
->
SetArray
(
array
->
val
,
total
*
3
,
0
);
}
modules/viz/src/vtk/vtkCloudColorMatSource.h
0 → 100644
浏览文件 @
7dbf6bc8
/*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:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
//M*/
#ifndef __vtkCloudColorMatSource_h
#define __vtkCloudColorMatSource_h
#include <opencv2/core/mat.hpp>
#include <vtkPolyDataAlgorithm.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
namespace
cv
{
namespace
viz
{
class
vtkCloudColorMatSource
:
public
vtkPolyDataAlgorithm
{
public:
static
vtkCloudColorMatSource
*
New
();
vtkTypeMacro
(
vtkCloudColorMatSource
,
vtkPolyDataAlgorithm
);
virtual
void
SetCloud
(
const
Mat
&
cloud
);
virtual
void
SetColors
(
const
Mat
&
colors
,
const
Mat
&
cloud_mask
);
protected:
vtkCloudColorMatSource
();
~
vtkCloudColorMatSource
();
int
RequestData
(
vtkInformation
*
,
vtkInformationVector
**
,
vtkInformationVector
*
);
vtkSmartPointer
<
vtkPoints
>
points
;
vtkSmartPointer
<
vtkCellArray
>
vertices
;
vtkSmartPointer
<
vtkUnsignedCharArray
>
scalars
;
private:
vtkCloudColorMatSource
(
const
vtkCloudColorMatSource
&
);
// Not implemented.
void
operator
=
(
const
vtkCloudColorMatSource
&
);
// Not implemented.
template
<
typename
_Tp
>
int
filterNanCopy
(
const
Mat
&
source
,
int
dataType
);
template
<
typename
_Msk
,
class
_NanPred
>
void
filterNanCopy
(
const
Mat
&
colors
,
const
Mat
&
mask
);
};
}
}
#endif
modules/viz/src/vtk/vtkCloudMatSource.cpp
0 → 100644
浏览文件 @
7dbf6bc8
/*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:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
//M*/
#include "precomp.hpp"
namespace
cv
{
namespace
viz
{
vtkStandardNewMacro
(
vtkCloudMatSource
);
}}
cv
::
viz
::
vtkCloudMatSource
::
vtkCloudMatSource
()
{
SetNumberOfInputPorts
(
0
);
}
cv
::
viz
::
vtkCloudMatSource
::~
vtkCloudMatSource
()
{}
void
cv
::
viz
::
vtkCloudMatSource
::
SetCloud
(
const
Mat
&
cloud
)
{
CV_Assert
(
cloud
.
depth
()
==
CV_32F
||
cloud
.
depth
()
==
CV_64F
);
CV_Assert
(
cloud
.
channels
()
==
3
||
cloud
.
channels
()
==
4
);
int
total
=
cloud
.
depth
()
==
CV_32F
?
filterNanCopy
<
float
>
(
cloud
,
VTK_FLOAT
)
:
filterNanCopy
<
double
>
(
cloud
,
VTK_DOUBLE
);
vertices
=
vtkSmartPointer
<
vtkCellArray
>::
New
();
vertices
->
Allocate
(
vertices
->
EstimateSize
(
1
,
total
));
vertices
->
InsertNextCell
(
total
);
for
(
int
i
=
0
;
i
<
total
;
++
i
)
vertices
->
InsertCellPoint
(
i
);
}
int
cv
::
viz
::
vtkCloudMatSource
::
RequestData
(
vtkInformation
*
vtkNotUsed
(
request
),
vtkInformationVector
**
vtkNotUsed
(
inputVector
),
vtkInformationVector
*
outputVector
)
{
vtkInformation
*
outInfo
=
outputVector
->
GetInformationObject
(
0
);
vtkPolyData
*
output
=
vtkPolyData
::
SafeDownCast
(
outInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
output
->
SetPoints
(
points
);
output
->
SetVerts
(
vertices
);
return
1
;
}
template
<
typename
_Tp
>
int
cv
::
viz
::
vtkCloudMatSource
::
filterNanCopy
(
const
Mat
&
source
,
int
dataType
)
{
CV_DbgAssert
(
DataType
<
_Tp
>::
depth
==
source
.
depth
());
points
=
vtkSmartPointer
<
vtkPoints
>::
New
();
points
->
SetDataType
(
dataType
);
points
->
Allocate
(
source
.
total
());
points
->
SetNumberOfPoints
(
source
.
total
());
int
cn
=
source
.
channels
();
int
total
=
0
;
for
(
int
y
=
0
;
y
<
source
.
rows
;
++
y
)
{
const
_Tp
*
srow
=
source
.
ptr
<
_Tp
>
(
y
);
const
_Tp
*
send
=
srow
+
source
.
cols
*
cn
;
for
(;
srow
!=
send
;
srow
+=
cn
)
if
(
!
isNan
(
srow
[
0
])
&&
!
isNan
(
srow
[
1
])
&&
!
isNan
(
srow
[
2
]))
points
->
SetPoint
(
total
++
,
srow
);
}
points
->
SetNumberOfPoints
(
total
);
points
->
Squeeze
();
return
total
;
}
modules/viz/src/vtk/vtkCloudMatSource.h
0 → 100644
浏览文件 @
7dbf6bc8
/*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:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
//M*/
#ifndef __vtkCloudMatSource_h
#define __vtkCloudMatSource_h
#include <opencv2/core/mat.hpp>
#include <vtkPolyDataAlgorithm.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
namespace
cv
{
namespace
viz
{
class
vtkCloudMatSource
:
public
vtkPolyDataAlgorithm
{
public:
static
vtkCloudMatSource
*
New
();
vtkTypeMacro
(
vtkCloudMatSource
,
vtkPolyDataAlgorithm
);
virtual
void
SetCloud
(
const
Mat
&
cloud
);
protected:
vtkCloudMatSource
();
~
vtkCloudMatSource
();
int
RequestData
(
vtkInformation
*
,
vtkInformationVector
**
,
vtkInformationVector
*
);
vtkSmartPointer
<
vtkPoints
>
points
;
vtkSmartPointer
<
vtkCellArray
>
vertices
;
private:
vtkCloudMatSource
(
const
vtkCloudMatSource
&
);
// Not implemented.
void
operator
=
(
const
vtkCloudMatSource
&
);
// Not implemented.
template
<
typename
_Tp
>
int
filterNanCopy
(
const
Mat
&
source
,
int
dataType
);
};
}
}
#endif
modules/viz/src/vtk/vtkColorMatSource.cpp
0 → 100644
浏览文件 @
7dbf6bc8
/*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:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
//M*/
#include "precomp.hpp"
namespace
cv
{
namespace
viz
{
vtkStandardNewMacro
(
vtkColorMatSource
);
struct
IsNotNan
{
template
<
typename
_Tp
>
bool
operator
()(
const
_Tp
*
data
)
const
{
return
!
isNan
(
data
[
0
])
&&
!
isNan
(
data
[
1
])
&&
!
isNan
(
data
[
2
]);
}
};
struct
AllOk
{
template
<
typename
_Tp
>
bool
operator
()(
const
_Tp
*
)
const
{
return
true
;
}
};
}}
cv
::
viz
::
vtkColorMatSource
::
vtkColorMatSource
()
{
SetNumberOfInputPorts
(
0
);
}
cv
::
viz
::
vtkColorMatSource
::~
vtkColorMatSource
()
{}
void
cv
::
viz
::
vtkColorMatSource
::
SetColors
(
const
Mat
&
colors
,
const
Mat
&
mask
)
{
CV_Assert
(
colors
.
depth
()
==
CV_8U
&&
colors
.
channels
()
<=
4
&&
colors
.
channels
()
!=
2
);
CV_Assert
(
mask
.
empty
()
||
mask
.
depth
()
==
CV_32F
||
mask
.
depth
()
==
CV_64F
);
if
(
!
mask
.
empty
()
&&
mask
.
depth
()
==
CV_32F
)
filterNanCopy
<
float
,
IsNotNan
>
(
colors
,
mask
);
else
if
(
!
mask
.
empty
()
&&
mask
.
depth
()
==
CV_64F
)
filterNanCopy
<
double
,
IsNotNan
>
(
colors
,
mask
);
else
/* mask.empty() */
filterNanCopy
<
double
,
AllOk
>
(
colors
,
mask
);
}
int
cv
::
viz
::
vtkColorMatSource
::
RequestData
(
vtkInformation
*
vtkNotUsed
(
request
),
vtkInformationVector
**
vtkNotUsed
(
inputVector
),
vtkInformationVector
*
outputVector
)
{
vtkInformation
*
outInfo
=
outputVector
->
GetInformationObject
(
0
);
vtkPolyData
*
output
=
vtkPolyData
::
SafeDownCast
(
outInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
output
->
GetPointData
()
->
SetScalars
(
scalars
);
return
1
;
}
template
<
typename
_Msk
,
class
_NanPred
>
void
cv
::
viz
::
vtkColorMatSource
::
filterNanCopy
(
const
Mat
&
colors
,
const
Mat
&
cloud_mask
)
{
Mat
buffer
(
colors
.
size
(),
CV_8UC3
);
Vec3b
*
pos
=
buffer
.
ptr
<
Vec3b
>
();
int
s_chs
=
colors
.
channels
();
int
m_chs
=
cloud_mask
.
channels
();
_NanPred
pred
;
for
(
int
y
=
0
;
y
<
colors
.
rows
;
++
y
)
{
const
unsigned
char
*
srow
=
colors
.
ptr
<
unsigned
char
>
(
y
);
const
unsigned
char
*
send
=
srow
+
colors
.
cols
*
colors
.
channels
();
const
_Msk
*
mrow
=
cloud_mask
.
empty
()
?
0
:
cloud_mask
.
ptr
<
_Msk
>
(
y
);
if
(
colors
.
channels
()
==
1
)
{
for
(;
srow
!=
send
;
srow
+=
s_chs
,
mrow
+=
m_chs
)
if
(
pred
(
mrow
))
*
pos
++
=
Vec3b
(
srow
[
0
],
srow
[
0
],
srow
[
0
]);
}
else
for
(;
srow
!=
send
;
srow
+=
s_chs
,
mrow
+=
m_chs
)
if
(
pred
(
mrow
))
*
pos
++
=
Vec3b
(
srow
[
2
],
srow
[
1
],
srow
[
0
]);
}
int
total
=
pos
-
buffer
.
ptr
<
Vec3b
>
();
Vec3b
*
array
=
new
Vec3b
[
total
];
std
::
copy
(
buffer
.
ptr
<
Vec3b
>
(),
pos
,
array
);
scalars
=
vtkSmartPointer
<
vtkUnsignedCharArray
>::
New
();
scalars
->
SetName
(
"colors"
);
scalars
->
SetNumberOfComponents
(
3
);
scalars
->
SetNumberOfTuples
(
total
);
scalars
->
SetArray
(
array
->
val
,
total
*
3
,
0
);
}
modules/viz/src/vtk/vtkColorMatSource.h
0 → 100644
浏览文件 @
7dbf6bc8
/*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:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
//M*/
#ifndef __vtkColorMatSource_h
#define __vtkColorMatSource_h
#include <opencv2/core/mat.hpp>
#include <vtkPolyDataAlgorithm.h>
#include <vtkSmartPointer.h>
namespace
cv
{
namespace
viz
{
class
vtkColorMatSource
:
public
vtkPolyDataAlgorithm
{
public:
static
vtkColorMatSource
*
New
();
vtkTypeMacro
(
vtkColorMatSource
,
vtkPolyDataAlgorithm
);
virtual
void
SetColors
(
const
Mat
&
colors
,
const
Mat
&
cloud_mask
=
Mat
());
protected:
vtkColorMatSource
();
~
vtkColorMatSource
();
int
RequestData
(
vtkInformation
*
,
vtkInformationVector
**
,
vtkInformationVector
*
);
vtkSmartPointer
<
vtkUnsignedCharArray
>
scalars
;
private:
vtkColorMatSource
(
const
vtkColorMatSource
&
);
// Not implemented.
void
operator
=
(
const
vtkColorMatSource
&
);
// Not implemented.
template
<
typename
_Msk
,
class
_NanPred
>
void
filterNanCopy
(
const
Mat
&
colors
,
const
Mat
&
mask
);
};
}
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录