Skip to content

Commit

Permalink
Add a list of points
Browse files Browse the repository at this point in the history
Also, change point x and y to be properties
  • Loading branch information
patricksnape committed Dec 10, 2014
1 parent 85f0c0f commit c0d0adb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tools/python/src/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <dlib/python.h>
#include <boost/shared_ptr.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <dlib/matrix.h>
#include <boost/python/slice.hpp>
#include <dlib/geometry/vector.h>
Expand All @@ -14,6 +15,9 @@ using namespace boost::python;

typedef matrix<double,0,1> cv;

template <typename T>
void resize(T& v, unsigned long n) { v.resize(n); }

void cv_set_size(cv& m, long s)
{
m.set_size(s);
Expand Down Expand Up @@ -170,16 +174,25 @@ void bind_vector()
.def("__setitem__", &cv__setitem__)
.add_property("shape", &cv_get_matrix_size)
.def_pickle(serialize_pickle<cv>());

def("dot", dotprod, "Compute the dot product between two dense column vectors.");
}
{
typedef point type;
class_<type>("point", "This object represents a single point of integer coordinates that maps directly to a dlib::point.")
.def(init<long,long>((arg("x"), arg("y"))))
.def("__repr__", &point__repr__)
.def("__str__", &point__str__)
.def("x", &point_x)
.def("y", &point_y)
.add_property("x", &point_x, "The x-coordinate of the point.")
.add_property("y", &point_y, "The y-coordinate of the point.")
.def_pickle(serialize_pickle<type>());
}
def("dot", dotprod, "Compute the dot product between two dense column vectors.");
{
typedef std::vector<point> type;
class_<type>("points", "An array of point objects.")
.def(vector_indexing_suite<type>())
.def("clear", &type::clear)
.def("resize", resize<type>)
.def_pickle(serialize_pickle<type>());
}
}

0 comments on commit c0d0adb

Please sign in to comment.