polygon.h
Go to the documentation of this file.
00001 
00060 #ifndef POLYGON_H_
00061 #define POLYGON_H_
00062 
00063 #include <pcl/point_cloud.h>
00064 #include <pcl/point_types.h>
00065 
00066 #include "cob_3d_mapping_common/shape.h"
00067 #include <boost/shared_ptr.hpp>
00068 #include <boost/enable_shared_from_this.hpp>
00069 extern "C" {
00070 #include "gpc/gpc.h"
00071 }
00072 #include <polypartition/polypartition.h>
00073 #include <cob_3d_mapping_common/dominant_color.h>
00074 #include <fstream>
00075 #include <iostream>
00076 
00077 //#include "cob_3d_mapping_common/stop_watch.h"
00078 
00079 namespace cob_3d_mapping
00080 {
00086   struct MergeConfig
00087   {
00088     MergeConfig()
00089     : angle_thresh(0.97),
00090       d_thresh(0.1),
00091       weighting_method("AREA")
00092     {};
00093 
00099     double angle_thresh;
00105     float  d_thresh;
00112     std::string weighting_method;
00113   };
00114 
00115 
00120   class Polygon : public Shape
00121   {
00122   public:
00126     typedef boost::shared_ptr<Polygon> Ptr;
00131     typedef boost::shared_ptr<const Polygon> ConstPtr;
00132 
00136     Polygon()
00137       : Shape(),
00138         normal_(Eigen::Vector3f::Zero()),
00139         d_(0.0),
00140         merge_weight_(1.0)
00141     { }
00142 
00143     Polygon(unsigned int id,
00144             Eigen::Vector3f normal,
00145             Eigen::Vector3f centroid,
00146             std::vector<std::vector<Eigen::Vector3f> >& contours_3d,
00147             std::vector<bool> holes,
00148             std::vector<float> color);
00149 
00150     Polygon(unsigned int id,
00151             Eigen::Vector3f normal,
00152             Eigen::Vector3f centroid,
00153             std::vector<pcl::PointCloud<pcl::PointXYZ> >& contours_3d,
00154             std::vector<bool> holes,
00155             std::vector<float> color);
00156 
00157     //Polygon(Polygon::Ptr polygon);
00158 
00159 
00164     inline size_t outerContourIndex() const
00165     {
00166       for(size_t i = 0; i < contours_.size(); ++i) { if(!holes_[i]) { return i; } };
00167       return 0;
00168     }
00169 
00170     virtual void setContours3D(std::vector<std::vector<Eigen::Vector3f> >& contours_3d);
00171     virtual std::vector<std::vector<Eigen::Vector3f> > getContours3D();
00172 
00173 
00174     void setContours2D(std::vector<std::vector<Eigen::Vector2f> >& contours_2d) {contours_ = contours_2d;};
00175     std::vector<std::vector<Eigen::Vector2f> > getContours2D() {return contours_;};
00176 
00177     //##########methods for instantiation##############
00178 
00186     virtual void updateAttributes(const Eigen::Vector3f &new_normal, const Eigen::Vector3f & new_centroid);
00187 
00188 
00196     virtual void transform(const Eigen::Affine3f& trafo);
00197     //virtual void transform2tf(const Eigen::Affine3f& trafo);
00198 
00199 
00206     void smoothContours();
00207 
00208 
00209     //###########methods for merging##################
00216     virtual void getMergeCandidates(const std::vector<Polygon::Ptr>& poly_vec, std::vector<int>& intersections) const;
00217 
00218 
00224     virtual bool isIntersectedWith(const Polygon::Ptr& poly) const;
00225 
00226 
00227 
00237     bool getContourOverlap(const Polygon::Ptr& poly, float& rel_overlap, int& abs_overlap) const;
00238 
00239 
00247     float computeSimilarity(const Polygon::Ptr& poly) const;
00248 
00249 
00257     virtual void merge(std::vector<Polygon::Ptr>& poly_vec);
00258 
00259 
00260     void mergeDifference(Polygon::Ptr& p_merge);
00261 
00262     virtual void projectContour(const Polygon& p, std::vector<std::vector<Eigen::Vector2f> >& contours) const;
00263 
00271     void assignWeight();
00272 
00273 
00274     virtual void setParamsFrom(Polygon::Ptr& p);
00275 
00276 
00283     inline bool hasSimilarParametersWith(const Polygon::Ptr& poly) const
00284     {
00285       Eigen::Vector3f d = (this->pose_.translation() - poly->pose_.translation());
00286       return ( fabs(poly->normal_.dot(this->normal_)) > this->merge_settings_.angle_thresh &&
00287                fabs( d.dot(this->normal_) ) < this->merge_settings_.d_thresh &&
00288                fabs( d.dot(poly->normal_) ) < this->merge_settings_.d_thresh );
00289     }
00290 
00291     //#######methods for calculation#####################
00292 
00293 
00294     //void computePose();
00295 
00296     void computePose(std::vector<std::vector<Eigen::Vector3f> >& contours_3d);
00297 
00301     Eigen::Vector3f computeCentroid();
00302 
00303     Eigen::Vector3f computeCentroid(std::vector<std::vector<Eigen::Vector3f> >& contours_3d);
00304 
00305 
00312     //double computeArea() const;  // http://paulbourke.net/geometry/polyarea/
00313 
00314 
00320     double computeArea3d() const;
00321 
00322 
00323     virtual void triangulate(list<TPPLPoly>& tri_list) const;
00324 
00331     //void computePoseAndBoundingBox(Eigen::Affine3f& pose, Eigen::Vector4f& min_pt, Eigen::Vector4f& max_pt);
00332 
00333 
00334 
00335     //#############debugging methods#######################
00336 
00337 
00343     void debugOutput(std::string name);
00344 
00345 
00346     //########## member variables#################
00347     //needed for 32-bit systems: see http://eigen.tuxfamily.org/dox/TopicStructHavingEigenMembers.html
00348     //EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00349     std::vector<std::vector<Eigen::Vector2f> > contours_;
00350     Eigen::Vector3f normal_;
00351     double d_;
00352     //Eigen::Affine3f transform_from_world_to_plane;/**< Transformation from world coordinate system to coordinate system on polygon. */
00353     std::vector<bool> holes_;
00354     double merge_weight_;
00355     MergeConfig merge_settings_;
00357   protected:
00367     virtual void computeAverage(const std::vector<Polygon::Ptr>& poly_vec, Polygon::Ptr& p_average);
00368 
00375     void getIntersection(const Polygon::Ptr& poly, gpc_polygon* gpc_intersection) const;
00376 
00386     void mergeUnion(std::vector<Polygon::Ptr>& poly_vec, Polygon::Ptr&  p_average);
00387 
00395     void getGpcStructure(gpc_polygon* gpc_p, const std::vector<std::vector<Eigen::Vector2f> >& contours) const;
00396 
00397 
00405     void applyGpcStructure(const gpc_polygon* gpc_p);
00406 
00413     void assignID(const std::vector<Polygon::Ptr>& poly_vec);
00414 
00415     DominantColor d_color_;
00416 
00417 
00418   };
00419 }
00420 #endif /* POLYGON_H_ */


cob_3d_mapping_common
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:02:19