Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PointData.cc

Go to the documentation of this file.
00001 //-*-c++-*-
00002 
00003 #include <iostream>
00004 #include <vector>
00005 
00006 #include "BaseData.h"    // superclass
00007 #include "Point.h"       // Point data member
00008 #include "ShapeTypes.h"  // pointDataType
00009 
00010 #include "SketchSpace.h"
00011 #include "Sketch.h"
00012 #include "visops.h"
00013 
00014 #include "ShapeSpace.h"  // required by DATASTUFF_CC
00015 #include "ShapeRoot.h"   // required by DATASTUFF_CC
00016 
00017 #include "PointData.h"
00018 #include "ShapePoint.h"
00019 
00020 using namespace std;
00021 
00022 namespace DualCoding {
00023 
00024 PointData::PointData(ShapeSpace& _space, const Point &c) 
00025   : BaseData(_space,getStaticType()), Point(c) {
00026   refFrameType = space->getRefFrameType();
00027 }
00028   
00029 DATASTUFF_CC(PointData);
00030 
00031 bool PointData::isMatchFor(const ShapeRoot& other) const {
00032   if (!(isSameTypeAs(other) && isSameColorAs(other)))
00033     return false;
00034   const Shape<PointData>& other_point = ShapeRootTypeConst(other,PointData);
00035   float dist = distanceFrom(other_point->getCentroid());
00036   return dist < 20; // *** DST hack
00037 }
00038 
00039 void PointData::mergeWith(const ShapeRoot& other) {
00040   const Shape<PointData>& other_point = ShapeRootTypeConst(other,PointData);
00041   if (other_point->confidence <= 0)
00042     return;
00043   const int other_conf = other_point->confidence;
00044   confidence += other_conf;
00045   Point::operator=(((*this)*confidence + other_point->getCentroid()*other_conf) / (confidence+other_conf));
00046 }
00047 
00048 bool PointData::updateParams(const ShapeRoot& other, bool) {
00049   const Shape<PointData>& other_point = *static_cast<const Shape<PointData>*>(&other);
00050   ++confidence;
00051   Point::operator=(((*this)*(confidence-1) + other_point->getCentroid())/confidence);
00052   deleteRendering();
00053   return true;
00054 }
00055 
00056 void
00057 PointData::printParams() const {
00058   cout << "Type = " << getTypeName();
00059   cout << "Shape ID = " << getId() << endl;
00060   cout << "Parent ID = " << getParentId() << endl;
00061   
00062   // Print critical points.
00063   cout << endl;
00064   cout << "center{" << getCentroid().coordX() << ", " << getCentroid().coordY() << "}" << endl;
00065   printf("color = %d %d %d\n",getColor().red,getColor().green,getColor().blue);
00066   cout << "viewable = " << isViewable() << endl;
00067 }
00068 
00069 
00070 void PointData::applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref) {
00071   Point::applyTransform(Tmat,newref);
00072 }
00073 
00074 void PointData::projectToGround(const fmat::Transform& camToBase, const PlaneEquation& groundplane) {
00075   Point::projectToGround(camToBase,groundplane);  // call Point's method
00076 }
00077 
00078 // ==================================================
00079 // BEGIN SKETCH MANIPULATION AND POINT EXTRACTION CODE
00080 // ==================================================
00081 
00082 
00083 //! Point extraction.
00084 
00085 std::vector<ShapeRoot> PointData::extractPoints(const Sketch<bool>& sketch)
00086 {
00087   SketchSpace &SkS = sketch->getSpace();
00088   ShapeSpace &ShS = SkS.getDualSpace();
00089   std::vector<ShapeRoot> result;
00090   size_t num_pixels = sketch.width * sketch.height;
00091   for ( size_t i=0; i < num_pixels; i++ )
00092     if ( sketch[i] ) {
00093       int const y = int(i/sketch.width);
00094       int const x = i - y*sketch.width;
00095       Point pt(x,y,0);
00096       SkS.applyTmat(pt.getCoords());
00097       Shape<PointData> new_point_shape(new PointData(ShS,pt));
00098       new_point_shape->inheritFrom(*sketch.rootGetData());
00099       result.push_back(new_point_shape);
00100     }
00101   return result;
00102 }
00103 
00104 
00105 //! Render into a sketch space and return a pointer. (Private.)
00106 Sketch<bool>* PointData::render() const {
00107   SketchSpace &SkS = space->getDualSpace();
00108   fmat::Column<3> ctr(getCentroid().getCoords());
00109   SkS.applyTmat(ctr);
00110   int const cx = int(ctr[0]);
00111   int const cy = int(ctr[1]);
00112   Sketch<bool>& draw_result = 
00113     *new Sketch<bool>(SkS, "render("+getName()+")");
00114   draw_result = false;
00115   draw_result(cx,cy) = true;  
00116   return &draw_result;
00117 }
00118 
00119 PointData& PointData::operator=(const PointData& other) {
00120   if (&other == this)
00121     return *this;
00122   BaseData::operator=(other);
00123   Point::operator=(other);
00124   return *this;
00125 }
00126 
00127 } // namespace

DualCoding 5.1CVS
Generated Mon May 9 04:56:27 2016 by Doxygen 1.6.3