Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

CrossData.cc

Go to the documentation of this file.
00001 #include "CrossData.h"
00002 
00003 #include "LineData.h"
00004 #include "ShapeCross.h"
00005 #include "VRmixin.h"
00006 
00007 #include "Crew/MapBuilderRequest.h"  // for defaultMarkerHeight
00008 
00009 namespace DualCoding {
00010 
00011   DATASTUFF_CC(CrossData);
00012   
00013   // CONSTRUCTOR
00014   CrossData::CrossData(ShapeSpace& _space, const LineData& _line1, const LineData& _line2, 
00015              const fmat::Column<3>& extents) :
00016               BaseData(_space, crossDataType), center(), armWidth(extents[1]), 
00017               crossHeight(extents[2]), line1(_line1), line2(_line2) {
00018     center = line1.intersectionWithLine(line2);
00019   }
00020 
00021   // Compute Bounding Box via the lines endpoints
00022   BoundingBox2D CrossData::getBoundingBox() const {
00023     BoundingBox2D b;
00024     Point endPt1 = line1.end1Pt();
00025     Point endPt2 = line1.end2Pt();
00026     Point endPt3 = line2.end1Pt();
00027     Point endPt4 = line2.end2Pt();
00028     
00029     fmat::Column<3>  p1 = endPt1.getCoords();
00030     fmat::Column<3>  p2 = endPt2.getCoords();
00031     fmat::Column<3>  p3 = endPt3.getCoords();
00032     fmat::Column<3>  p4 = endPt4.getCoords();
00033 
00034     b.expand(p1);
00035     b.expand(p2);
00036     b.expand(p3);
00037     b.expand(p4);
00038     return b;
00039   }
00040 
00041   // Get Points of Bounding Box
00042   Point CrossData::getTopLeft() const {
00043     BoundingBox2D b = getBoundingBox();
00044     fmat::Column<2> pt1 = b.min;
00045     fmat::Column<2> pt2 = b.min;
00046   
00047     float x1 = pt1[0];
00048     float y1 = pt1[1];
00049     float x2 = pt2[0];
00050     float y2 = pt2[1];
00051     
00052     Point p = Point(min(x1,x2), max(y1,y2));
00053     return p;
00054   }
00055   Point CrossData::getTopRight() const {
00056     BoundingBox2D b = getBoundingBox();
00057     fmat::Column<2> pt1 = b.min;
00058     fmat::Column<2> pt2 = b.min;
00059   
00060     float x1 = pt1[0];
00061     float y1 = pt1[1];
00062     float x2 = pt2[0];
00063     float y2 = pt2[1];
00064     
00065     Point p = Point(max(x1,x2), max(y1,y2));
00066     return p;
00067   }
00068   Point CrossData::getBottomLeft() const {
00069     BoundingBox2D b = getBoundingBox();
00070     fmat::Column<2> pt1 = b.min;
00071     fmat::Column<2> pt2 = b.min;
00072   
00073     float x1 = pt1[0];
00074     float y1 = pt1[1];
00075     float x2 = pt2[0];
00076     float y2 = pt2[1];
00077     
00078     Point p = Point(min(x1,x2), min(y1,y2));
00079     return p;
00080   }
00081 
00082   Point CrossData::getBottomRight() const {
00083     BoundingBox2D b = getBoundingBox();
00084     fmat::Column<2> pt1 = b.min;
00085     fmat::Column<2> pt2 = b.min;
00086   
00087     float x1 = pt1[0];
00088     float y1 = pt1[1];
00089     float x2 = pt2[0];
00090     float y2 = pt2[1];
00091     
00092     Point p = Point(max(x1,x2),min(y1,y2));
00093     return p;
00094   }
00095 
00096   // Matching by checking both type and color and then moves on to look at the lines themselves
00097   bool CrossData::isMatchFor(const ShapeRoot& other) const {
00098     if ( !isSameTypeAs(other) || !isSameColorAs(other) )
00099       return false;
00100     else {
00101       cout << "CrossData::isMatchFor " << getId() << "@" << getCentroid() << " against " << other << endl;
00102       const Shape<CrossData>& other_ln = ShapeRootTypeConst(other,CrossData);
00103       return isMatchFor(other_ln.getData());
00104     }
00105   }
00106 
00107   // Checks to make sure both lines are a match (either ordering of them)
00108   bool CrossData::isMatchFor(const CrossData& other) const {
00109     if ( (line1.isMatchFor(other.getLine1()) && line2.isMatchFor(other.getLine2())) ||
00110          (line2.isMatchFor(other.getLine1()) && line1.isMatchFor(other.getLine2())))
00111       return true;  
00112     else
00113       return false;
00114   }
00115 
00116   // updates the lines and the center point given a new cross
00117   bool CrossData::updateParams(const ShapeRoot& ground_root, bool force) {
00118     const Shape<CrossData>& ground_cross = ShapeRootTypeConst(ground_root,CrossData);
00119     return updateParams(ground_cross.getData(), force);
00120   }
00121 
00122   bool CrossData::updateParams(const CrossData &ground_cross, bool force) {
00123     if (force) {
00124       setCentroid(ground_cross.getCentroid());
00125       setLine1(ground_cross.getLine1());
00126       setLine2(ground_cross.getLine2());
00127     }
00128     return force;
00129   }
00130 
00131   // Print out centerpoint and the line data for both lines
00132   void CrossData::printParams() const {
00133     cout << "Type = " << getTypeName() << "  ID=" << getId() << "  ParentID=" << getParentId() << endl;
00134     printf("  color = %d %d %d\n",getColor().red,getColor().green,getColor().blue);
00135     cout << "Centroid: " << center << endl;
00136     line1.printParams();
00137     line2.printParams();
00138   }
00139   
00140   // The 2 line representation of a cross allows us to transform the lines and the intersection point
00141   void CrossData::applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref) {
00142     line1.applyTransform(Tmat,newref);
00143     line2.applyTransform(Tmat,newref);
00144     center.applyTransform(Tmat,newref);
00145   }
00146 
00147   // The 2 line representation of a cross allows us to project to ground the lines and the intersection point
00148   void CrossData::projectToGround(const fmat::Transform& camToBase, const PlaneEquation& groundplane) {
00149     line1.projectToGround(camToBase,groundplane);
00150     line2.projectToGround(camToBase,groundplane);
00151     line1.setSpace(space); // this will be useful if we ever try to recognize crosses in camera space
00152     line2.setSpace(space);
00153     center.projectToGround(camToBase,groundplane);
00154   }
00155 
00156   // The 2 line representation of a cross allows us to render a dcross by rendering both lines
00157   Sketch<bool>* CrossData::render() const {
00158     SketchSpace &renderspace = space->getDualSpace();
00159     Sketch<bool>* draw_result = new Sketch<bool>(renderspace, "render("+getName()+")");
00160     (*draw_result)->inheritFrom(*this);
00161     *draw_result = 0;
00162     line1.renderOnTo(draw_result);
00163     line2.renderOnTo(draw_result);
00164     return draw_result;
00165   }
00166   
00167   std::vector<Point> CrossData::computeGraspPoints() const {
00168     std::vector<Point> results;
00169     results.push_back(line1.end1Pt());
00170     results.push_back(line1.end2Pt());
00171     results.push_back(line2.end1Pt());
00172     results.push_back(line2.end2Pt());
00173     return results;
00174   }
00175 } 
00176 
00177 
00178 
00179 
00180 
00181 
00182 

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