Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
c0097a78
Commit
c0097a78
authored
May 20, 2018
by
Davis King
Browse files
Added dpoint to the python API.
parent
da943c69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
tools/python/src/opaque_types.h
tools/python/src/opaque_types.h
+1
-0
tools/python/src/vector.cpp
tools/python/src/vector.cpp
+35
-0
No files found.
tools/python/src/opaque_types.h
View file @
c0097a78
...
...
@@ -50,6 +50,7 @@ PYBIND11_MAKE_OPAQUE(sparse_ranking_pairs);
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
dlib
::
point
>
);
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
dlib
::
dpoint
>
);
#endif // DLIB_PyTHON_OPAQUE_TYPES_H_
tools/python/src/vector.cpp
View file @
c0097a78
...
...
@@ -138,8 +138,24 @@ string point__str__(const point& p)
return
sout
.
str
();
}
string
dpoint__repr__
(
const
dpoint
&
p
)
{
std
::
ostringstream
sout
;
sout
<<
"dpoint("
<<
p
.
x
()
<<
", "
<<
p
.
y
()
<<
")"
;
return
sout
.
str
();
}
string
dpoint__str__
(
const
dpoint
&
p
)
{
std
::
ostringstream
sout
;
sout
<<
"("
<<
p
.
x
()
<<
", "
<<
p
.
y
()
<<
")"
;
return
sout
.
str
();
}
long
point_x
(
const
point
&
p
)
{
return
p
.
x
();
}
long
point_y
(
const
point
&
p
)
{
return
p
.
y
();
}
double
dpoint_x
(
const
dpoint
&
p
)
{
return
p
.
x
();
}
double
dpoint_y
(
const
dpoint
&
p
)
{
return
p
.
y
();
}
// ----------------------------------------------------------------------------------------
void
bind_vector
(
py
::
module
&
m
)
...
...
@@ -179,4 +195,23 @@ void bind_vector(py::module& m)
.
def
(
"extend"
,
extend_vector_with_python_list
<
point
>
)
.
def
(
py
::
pickle
(
&
getstate
<
type
>
,
&
setstate
<
type
>
));
}
{
typedef
dpoint
type
;
py
::
class_
<
type
>
(
m
,
"dpoint"
,
"This object represents a single point of floating point coordinates that maps directly to a dlib::dpoint."
)
.
def
(
py
::
init
<
double
,
double
>
(),
py
::
arg
(
"x"
),
py
::
arg
(
"y"
))
.
def
(
"__repr__"
,
&
dpoint__repr__
)
.
def
(
"__str__"
,
&
dpoint__str__
)
.
def_property
(
"x"
,
&
dpoint_x
,
[](
dpoint
&
p
,
double
x
){
p
.
x
()
=
x
;},
"The x-coordinate of the dpoint."
)
.
def_property
(
"y"
,
&
dpoint_y
,
[](
dpoint
&
p
,
double
y
){
p
.
x
()
=
y
;},
"The y-coordinate of the dpoint."
)
.
def
(
py
::
pickle
(
&
getstate
<
type
>
,
&
setstate
<
type
>
));
}
{
typedef
std
::
vector
<
dpoint
>
type
;
py
::
bind_vector
<
type
>
(
m
,
"dpoints"
,
"An array of dpoint objects."
)
.
def
(
"clear"
,
&
type
::
clear
)
.
def
(
"resize"
,
resize
<
type
>
)
.
def
(
"extend"
,
extend_vector_with_python_list
<
dpoint
>
)
.
def
(
py
::
pickle
(
&
getstate
<
type
>
,
&
setstate
<
type
>
));
}
}
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