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
f94c2414
Commit
f94c2414
authored
Jun 21, 2013
by
ozantonkal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
showPlane implementation
parent
26a68232
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
85 deletions
+80
-85
viz3d.hpp
modules/viz/include/opencv2/viz/viz3d.hpp
+2
-0
viz3d_impl.hpp
modules/viz/src/q/viz3d_impl.hpp
+2
-22
viz3d.cpp
modules/viz/src/viz3d.cpp
+4
-4
viz3d_impl.cpp
modules/viz/src/viz3d_impl.cpp
+63
-0
viz_main.cpp
modules/viz/src/viz_main.cpp
+0
-56
test_viz3d.cpp
modules/viz/test/test_viz3d.cpp
+9
-3
No files found.
modules/viz/include/opencv2/viz/viz3d.hpp
View file @
f94c2414
...
...
@@ -33,6 +33,8 @@ namespace temp_viz
bool
addPointCloudNormals
(
const
Mat
&
cloud
,
const
Mat
&
normals
,
int
level
=
100
,
float
scale
=
0.02
f
,
const
String
&
id
=
"cloud"
);
void
showLine
(
const
String
&
id
,
const
Point3f
&
pt1
,
const
Point3f
&
pt2
,
const
Color
&
color
);
void
showPlane
(
const
String
&
id
,
const
Vec4f
&
coefs
);
void
showPlane
(
const
String
&
id
,
const
Vec4f
&
coefs
,
const
Point3f
&
pt
);
bool
addPlane
(
const
ModelCoefficients
&
coefficients
,
const
String
&
id
=
"plane"
);
bool
addPlane
(
const
ModelCoefficients
&
coefficients
,
double
x
,
double
y
,
double
z
,
const
String
&
id
=
"plane"
);
...
...
modules/viz/src/q/viz3d_impl.hpp
View file @
f94c2414
...
...
@@ -139,6 +139,8 @@ public:
}
void
showLine
(
const
String
&
id
,
const
cv
::
Point3f
&
pt1
,
const
cv
::
Point3f
&
pt2
,
const
Color
&
color
);
void
showPlane
(
const
String
&
id
,
const
cv
::
Vec4f
&
coefs
);
void
showPlane
(
const
String
&
id
,
const
cv
::
Vec4f
&
coefs
,
const
cv
::
Point3f
&
pt
);
bool
addPolygon
(
const
cv
::
Mat
&
cloud
,
const
Color
&
color
,
const
std
::
string
&
id
=
"polygon"
);
bool
addArrow
(
const
cv
::
Point3f
&
pt1
,
const
cv
::
Point3f
&
pt2
,
const
Color
&
color
,
bool
display_length
,
const
std
::
string
&
id
=
"arrow"
);
...
...
@@ -178,28 +180,6 @@ public:
*/
bool
addCylinder
(
const
temp_viz
::
ModelCoefficients
&
coefficients
,
const
std
::
string
&
id
=
"cylinder"
);
/** \brief Add a plane from a set of given model coefficients
* \param[in] coefficients the model coefficients (a, b, c, d with ax+by+cz+d=0)
* \param[in] id the plane id/name (default: "plane")
*
* \code
* // The following are given (or computed using sample consensus techniques)
* // See SampleConsensusModelPlane for more information
*
* temp_viz::ModelCoefficients plane_coeff;
* plane_coeff.values.resize (4); // We need 4 values
* plane_coeff.values[0] = plane_parameters.x ();
* plane_coeff.values[1] = plane_parameters.y ();
* plane_coeff.values[2] = plane_parameters.z ();
* plane_coeff.values[3] = plane_parameters.w ();
*
* addPlane (plane_coeff);
* \endcode
*/
bool
addPlane
(
const
temp_viz
::
ModelCoefficients
&
coefficients
,
const
std
::
string
&
id
=
"plane"
);
bool
addPlane
(
const
temp_viz
::
ModelCoefficients
&
coefficients
,
double
x
,
double
y
,
double
z
,
const
std
::
string
&
id
=
"plane"
);
/** \brief Add a circle from a set of given model coefficients
* \param[in] coefficients the model coefficients (x, y, radius)
* \param[in] id the circle id/name (default: "circle")
...
...
modules/viz/src/viz3d.cpp
View file @
f94c2414
...
...
@@ -83,14 +83,14 @@ void temp_viz::Viz3d::showLine(const String &id, const Point3f &pt1, const Point
impl_
->
showLine
(
id
,
pt1
,
pt2
,
color
);
}
bool
temp_viz
::
Viz3d
::
addPlane
(
const
ModelCoefficients
&
coefficients
,
const
String
&
id
)
void
temp_viz
::
Viz3d
::
showPlane
(
const
String
&
id
,
const
Vec4f
&
coefs
)
{
return
impl_
->
addPlane
(
coefficients
,
id
);
impl_
->
showPlane
(
id
,
coefs
);
}
bool
temp_viz
::
Viz3d
::
addPlane
(
const
ModelCoefficients
&
coefficients
,
double
x
,
double
y
,
double
z
,
const
String
&
id
)
void
temp_viz
::
Viz3d
::
showPlane
(
const
String
&
id
,
const
Vec4f
&
coefs
,
const
Point3f
&
pt
)
{
return
impl_
->
addPlane
(
coefficients
,
x
,
y
,
z
,
id
);
impl_
->
showPlane
(
id
,
coefs
,
pt
);
}
bool
temp_viz
::
Viz3d
::
removeCoordinateSystem
(
const
String
&
id
)
...
...
modules/viz/src/viz3d_impl.cpp
View file @
f94c2414
...
...
@@ -302,6 +302,69 @@ void temp_viz::Viz3d::VizImpl::showLine (const String &id, const cv::Point3f &pt
}
}
void
temp_viz
::
Viz3d
::
VizImpl
::
showPlane
(
const
String
&
id
,
const
cv
::
Vec4f
&
coefs
)
{
// Check if this Id already exists
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
id
);
bool
exists
=
(
am_it
!=
shape_actor_map_
->
end
());
// If it exists just update
if
(
exists
)
{
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
am_it
->
second
);
reinterpret_cast
<
vtkDataSetMapper
*>
(
actor
->
GetMapper
())
->
SetInput
(
createPlane
(
coefs
));
actor
->
Modified
();
}
else
{
// Create a plane
vtkSmartPointer
<
vtkDataSet
>
data
=
createPlane
(
coefs
);
// Create an Actor
vtkSmartPointer
<
vtkLODActor
>
actor
;
createActorFromVTKDataSet
(
data
,
actor
);
// actor->GetProperty ()->SetRepresentationToWireframe ();
actor
->
GetProperty
()
->
SetRepresentationToSurface
();
actor
->
GetProperty
()
->
SetLighting
(
false
);
renderer_
->
AddActor
(
actor
);
// Save the pointer/ID pair to the global actor map
(
*
shape_actor_map_
)[
id
]
=
actor
;
}
}
void
temp_viz
::
Viz3d
::
VizImpl
::
showPlane
(
const
String
&
id
,
const
cv
::
Vec4f
&
coefs
,
const
cv
::
Point3f
&
pt
)
{
// Check if this Id already exists
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
id
);
bool
exists
=
(
am_it
!=
shape_actor_map_
->
end
());
// If it exists just update
if
(
exists
)
{
vtkSmartPointer
<
vtkLODActor
>
actor
=
vtkLODActor
::
SafeDownCast
(
am_it
->
second
);
reinterpret_cast
<
vtkDataSetMapper
*>
(
actor
->
GetMapper
())
->
SetInput
(
createPlane
(
coefs
,
pt
));
actor
->
Modified
();
}
else
{
// Create a plane
vtkSmartPointer
<
vtkDataSet
>
data
=
createPlane
(
coefs
,
pt
);
// Create an Actor
vtkSmartPointer
<
vtkLODActor
>
actor
;
createActorFromVTKDataSet
(
data
,
actor
);
// actor->GetProperty ()->SetRepresentationToWireframe ();
actor
->
GetProperty
()
->
SetRepresentationToSurface
();
actor
->
GetProperty
()
->
SetLighting
(
false
);
renderer_
->
AddActor
(
actor
);
// Save the pointer/ID pair to the global actor map
(
*
shape_actor_map_
)[
id
]
=
actor
;
}
}
bool
temp_viz
::
Viz3d
::
VizImpl
::
addPolygonMesh
(
const
Mesh3d
&
mesh
,
const
Mat
&
mask
,
const
std
::
string
&
id
)
{
CV_Assert
(
mesh
.
cloud
.
type
()
==
CV_32FC3
&&
mesh
.
cloud
.
rows
==
1
&&
!
mesh
.
polygons
.
empty
());
...
...
modules/viz/src/viz_main.cpp
View file @
f94c2414
...
...
@@ -1088,62 +1088,6 @@ bool temp_viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename,
return
(
true
);
}
////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Add a plane from a set of given model coefficients
* \param coefficients the model coefficients (a, b, c, d with ax+by+cz+d=0)
* \param id the plane id/name (default: "plane")
* \param viewport (optional) the id of the new viewport (default: 0)
*/
bool
temp_viz
::
Viz3d
::
VizImpl
::
addPlane
(
const
temp_viz
::
ModelCoefficients
&
coefficients
,
const
std
::
string
&
id
)
{
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
id
);
if
(
am_it
!=
shape_actor_map_
->
end
())
{
std
::
cout
<<
"[addPlane] A shape with id <"
<<
id
<<
"> already exists! Please choose a different id and retry."
<<
std
::
endl
;
return
(
false
);
}
vtkSmartPointer
<
vtkDataSet
>
data
=
createPlane
(
coefficients
);
// Create an Actor
vtkSmartPointer
<
vtkLODActor
>
actor
;
createActorFromVTKDataSet
(
data
,
actor
);
// actor->GetProperty ()->SetRepresentationToWireframe ();
actor
->
GetProperty
()
->
SetRepresentationToSurface
();
actor
->
GetProperty
()
->
SetLighting
(
false
);
renderer_
->
AddActor
(
actor
);
// Save the pointer/ID pair to the global actor map
(
*
shape_actor_map_
)[
id
]
=
actor
;
return
(
true
);
}
bool
temp_viz
::
Viz3d
::
VizImpl
::
addPlane
(
const
temp_viz
::
ModelCoefficients
&
coefficients
,
double
x
,
double
y
,
double
z
,
const
std
::
string
&
id
)
{
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
ShapeActorMap
::
iterator
am_it
=
shape_actor_map_
->
find
(
id
);
if
(
am_it
!=
shape_actor_map_
->
end
())
{
std
::
cout
<<
"[addPlane] A shape with id <"
<<
id
<<
"> already exists! Please choose a different id and retry.
\n
"
<<
std
::
endl
;
return
(
false
);
}
vtkSmartPointer
<
vtkDataSet
>
data
=
createPlane
(
coefficients
,
x
,
y
,
z
);
// Create an Actor
vtkSmartPointer
<
vtkLODActor
>
actor
;
createActorFromVTKDataSet
(
data
,
actor
);
actor
->
GetProperty
()
->
SetRepresentationToWireframe
();
actor
->
GetProperty
()
->
SetLighting
(
false
);
renderer_
->
AddActor
(
actor
);
// Save the pointer/ID pair to the global actor map
(
*
shape_actor_map_
)[
id
]
=
actor
;
return
(
true
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
bool
temp_viz
::
Viz3d
::
VizImpl
::
addCircle
(
const
temp_viz
::
ModelCoefficients
&
coefficients
,
const
std
::
string
&
id
)
{
...
...
modules/viz/test/test_viz3d.cpp
View file @
f94c2414
...
...
@@ -93,19 +93,25 @@ TEST(Viz_viz3d, accuracy)
int
col_green
=
0
;
int
col_red
=
0
;
v
.
showPlane
(
"plane1"
,
cv
::
Vec4f
(
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
));
while
(
!
v
.
wasStopped
())
{
// Creating new point cloud with id cloud1
cv
::
Affine3f
cloudPosition
(
angle_x
,
angle_y
,
angle_z
,
cv
::
Vec3f
(
pos_x
,
pos_y
,
pos_z
));
v
.
showPointCloud
(
"cloud1"
,
cloud
,
temp_viz
::
Color
(
col_blue
,
col_green
,
col_red
),
cloudPosition
);
v
.
showLine
(
"line1"
,
cv
::
Point3f
(
0.0
,
0.0
,
0.0
),
cv
::
Point3f
(
pos_x
,
pos_y
,
pos_z
)
,
temp_viz
::
Color
(
255
-
col_blue
,
255
-
col_green
,
255
-
col_red
));
v
.
showLine
(
"line2"
,
cv
::
Point3f
(
0.0
,
0.0
,
0.0
),
cv
::
Point3f
(
1.0
f
-
pos_x
,
pos_y
,
pos_z
)
,
temp_viz
::
Color
(
255
-
col_blue
,
255
-
col_green
,
255
-
col_red
));
v
.
showLine
(
"line3"
,
cv
::
Point3f
(
0.0
,
0.0
,
0.0
),
cv
::
Point3f
(
pos_x
,
1.0
f
-
pos_y
,
pos_z
)
,
temp_viz
::
Color
(
255
-
col_blue
,
255
-
col_green
,
255
-
col_red
));
v
.
showLine
(
"line4"
,
cv
::
Point3f
(
0.0
,
0.0
,
0.0
),
cv
::
Point3f
(
pos_x
,
pos_y
,
1.0
f
-
pos_z
)
,
temp_viz
::
Color
(
255
-
col_blue
,
255
-
col_green
,
255
-
col_red
));
v
.
showPlane
(
"plane1"
,
cv
::
Vec4f
(
pos_x
*
pos_y
,
pos_y
,
pos_z
,
pos_x
+
pos_y
*
pos_z
));
angle_x
+=
0.1
f
;
angle_y
-=
0.1
f
;
angle_z
+=
0.1
f
;
pos_x
=
std
::
sin
(
angle_x
);
pos_y
=
std
::
sin
(
angle_
x
);
pos_z
=
std
::
sin
(
angle_
x
);
pos_y
=
std
::
sin
(
angle_
y
);
pos_z
=
std
::
sin
(
angle_
z
);
col_blue
=
int
(
angle_x
*
10
)
%
256
;
col_green
=
int
(
angle_x
*
20
)
%
256
;
col_red
=
int
(
angle_x
*
30
)
%
256
;
...
...
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