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()), the_point(c) {
00026   the_point.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 = the_point.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   the_point = (the_point*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   the_point = (the_point*(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 NEWMAT::Matrix& Tmat, const ReferenceFrameType_t newref) {
00071     the_point.applyTransform(Tmat,newref);
00072 }
00073 
00074 void PointData::projectToGround(const NEWMAT::Matrix& camToBase,
00075         const NEWMAT::ColumnVector& groundplane) {
00076   the_point.projectToGround(camToBase,groundplane);
00077 }
00078 
00079 // ==================================================
00080 // BEGIN SKETCH MANIPULATION AND POINT EXTRACTION CODE
00081 // ==================================================
00082 
00083 
00084 //! Point extraction.
00085 
00086 std::vector<ShapeRoot> PointData::extractPoints(const Sketch<bool>& sketch)
00087 {
00088   SketchSpace &SkS = sketch->getSpace();
00089   ShapeSpace &ShS = SkS.getDualSpace();
00090   std::vector<ShapeRoot> result;
00091   size_t num_pixels = sketch.width * sketch.height;
00092   for ( size_t i=0; i < num_pixels; i++ )
00093     if ( sketch[i] ) {
00094       int const y = int(i/sketch.width);
00095       int const x = i - y*sketch.width;
00096       Point pt(x,y,0);
00097       SkS.applyTmat(pt.getCoords());
00098       Shape<PointData> new_point_shape(new PointData(ShS,pt));
00099       new_point_shape->inheritFrom(*sketch.rootGetData());
00100       result.push_back(new_point_shape);
00101     }
00102   return result;
00103 }
00104 
00105 
00106 //! Render into a sketch space and return a pointer. (Private.)
00107 Sketch<bool>* PointData::render() const {
00108   SketchSpace &SkS = space->getDualSpace();
00109   NEWMAT::ColumnVector ctr(getCentroid().getCoords());
00110   SkS.applyTmat(ctr);
00111   int const cx = int(ctr(1));
00112   int const cy = int(ctr(2));
00113   Sketch<bool>& draw_result = 
00114     *new Sketch<bool>(SkS, "render("+getName()+")");
00115   draw_result = false;
00116   draw_result(cx,cy) = true;  
00117   return &draw_result;
00118 }
00119 
00120 PointData& PointData::operator=(const PointData& other) {
00121   if (&other == this)
00122     return *this;
00123   BaseData::operator=(other);
00124   the_point = other.the_point;
00125   return *this;
00126 }
00127 
00128 } // namespace

DualCoding 4.0
Generated Thu Nov 22 00:52:36 2007 by Doxygen 1.5.4