diff --git a/dlib/geometry/point_transforms.h b/dlib/geometry/point_transforms.h index 1c939a2b1..7bb2c7032 100644 --- a/dlib/geometry/point_transforms.h +++ b/dlib/geometry/point_transforms.h @@ -19,6 +19,13 @@ namespace dlib class point_rotator { public: + point_rotator ( + ) + { + sin_angle = 0; + cos_angle = 1; + } + point_rotator ( const double& angle ) @@ -47,6 +54,18 @@ namespace dlib return temp; } + inline friend void serialize (const point_rotator& item, std::ostream& out) + { + serialize(item.sin_angle, out); + serialize(item.cos_angle, out); + } + + inline friend void deserialize (point_rotator& item, std::istream& in) + { + deserialize(item.sin_angle, in); + deserialize(item.cos_angle, in); + } + private: double sin_angle; double cos_angle; @@ -57,6 +76,16 @@ namespace dlib class point_transform { public: + + point_transform ( + ) + { + sin_angle = 0; + cos_angle = 1; + translate.x() = 0; + translate.y() = 0; + } + point_transform ( const double& angle, const dlib::vector& translate_ @@ -90,6 +119,20 @@ namespace dlib const dlib::vector get_b( ) const { return translate; } + inline friend void serialize (const point_transform& item, std::ostream& out) + { + serialize(item.sin_angle, out); + serialize(item.cos_angle, out); + serialize(item.translate, out); + } + + inline friend void deserialize (point_transform& item, std::istream& in) + { + deserialize(item.sin_angle, in); + deserialize(item.cos_angle, in); + deserialize(item.translate, in); + } + private: double sin_angle; double cos_angle; @@ -101,6 +144,15 @@ namespace dlib class point_transform_affine { public: + + point_transform_affine ( + ) + { + m = identity_matrix(2); + b.x() = 0; + b.y() = 0; + } + point_transform_affine ( const matrix& m_, const dlib::vector& b_ @@ -121,6 +173,18 @@ namespace dlib const dlib::vector& get_b( ) const { return b; } + inline friend void serialize (const point_transform_affine& item, std::ostream& out) + { + serialize(item.m, out); + serialize(item.b, out); + } + + inline friend void deserialize (point_transform_affine& item, std::istream& in) + { + deserialize(item.m, in); + deserialize(item.b, in); + } + private: matrix m; dlib::vector b; @@ -175,6 +239,13 @@ namespace dlib class point_transform_projective { public: + + point_transform_projective ( + ) + { + m = identity_matrix(3); + } + point_transform_projective ( const matrix& m_ ) :m(m_) @@ -208,6 +279,15 @@ namespace dlib const matrix& get_m( ) const { return m; } + inline friend void serialize (const point_transform_projective& item, std::ostream& out) + { + serialize(item.m, out); + } + + inline friend void deserialize (point_transform_projective& item, std::istream& in) + { + deserialize(item.m, in); + } private: matrix m; diff --git a/dlib/geometry/point_transforms_abstract.h b/dlib/geometry/point_transforms_abstract.h index 5bcc361a3..9bc596ce3 100644 --- a/dlib/geometry/point_transforms_abstract.h +++ b/dlib/geometry/point_transforms_abstract.h @@ -20,6 +20,15 @@ namespace dlib applies an affine transformation to them. !*/ public: + + point_transform_affine ( + ); + /*! + ensures + - This object will perform the identity transform. That is, given a point + as input it will return the same point as output. + !*/ + point_transform_affine ( const matrix& m, const dlib::vector& b @@ -57,6 +66,12 @@ namespace dlib }; + void serialize (const point_transform_affine& item, std::ostream& out); + void deserialize (point_transform_affine& item, std::istream& in); + /*! + provides serialization support + !*/ + // ---------------------------------------------------------------------------------------- point_transform_affine inv ( @@ -104,6 +119,14 @@ namespace dlib public: + point_transform_projective ( + ); + /*! + ensures + - This object will perform the identity transform. That is, given a point + as input it will return the same point as output. + !*/ + point_transform_projective ( const matrix& m ); @@ -145,6 +168,12 @@ namespace dlib }; + void serialize (const point_transform_projective& item, std::ostream& out); + void deserialize (point_transform_projective& item, std::istream& in); + /*! + provides serialization support + !*/ + // ---------------------------------------------------------------------------------------- point_transform_projective inv ( @@ -186,6 +215,15 @@ namespace dlib translates them. !*/ public: + + point_transform ( + ); + /*! + ensures + - This object will perform the identity transform. That is, given a point + as input it will return the same point as output. + !*/ + point_transform ( const double& angle, const dlib::vector& translate @@ -226,6 +264,12 @@ namespace dlib }; + void serialize (const point_transform& item, std::ostream& out); + void deserialize (point_transform& item, std::istream& in); + /*! + provides serialization support + !*/ + // ---------------------------------------------------------------------------------------- class point_rotator @@ -236,6 +280,15 @@ namespace dlib rotates them around the origin by a given angle. !*/ public: + + point_rotator ( + ); + /*! + ensures + - This object will perform the identity transform. That is, given a point + as input it will return the same point as output. + !*/ + point_rotator ( const double& angle ); @@ -267,6 +320,12 @@ namespace dlib !*/ }; + void serialize (const point_rotator& item, std::ostream& out); + void deserialize (point_rotator& item, std::istream& in); + /*! + provides serialization support + !*/ + // ---------------------------------------------------------------------------------------- template diff --git a/dlib/test/geometry.cpp b/dlib/test/geometry.cpp index 50702181c..946c18e43 100644 --- a/dlib/test/geometry.cpp +++ b/dlib/test/geometry.cpp @@ -648,6 +648,14 @@ namespace DLIB_TEST(length(t(tinv(from[i]))-from[i]) < 1e-14); } + ostringstream sout; + serialize(t, sout); + istringstream sin(sout.str()); + point_transform_affine t2; + DLIB_TEST(length(t2(point(2,3)) - point(2,3)) < 1e-14); + deserialize(t2, sin); + DLIB_TEST(max(abs(t2.get_m()-t.get_m())) < 1e-14); + DLIB_TEST(max(abs(t2.get_b()-t.get_b())) < 1e-14); } // ---------------------------------------------------------------------------------------- @@ -706,6 +714,14 @@ namespace dlog << LINFO << " errors: mean/max: " << rs.mean() << " " << rs.max(); pass_rate.add(0); } + + ostringstream sout; + serialize(tran, sout); + istringstream sin(sout.str()); + point_transform_projective tran3; + DLIB_TEST(length(tran3(point(2,3)) - point(2,3)) < 1e-14); + deserialize(tran3, sin); + DLIB_TEST(max(abs(tran3.get_m()-tran.get_m())) < 1e-14); } dlog << LINFO << " pass_rate.mean(): "<< pass_rate.mean();