DominoData.cc
Go to the documentation of this file.00001 #include "DominoData.h"
00002 #include "ShapeDomino.h"
00003
00004 namespace DualCoding {
00005
00006 DATASTUFF_CC(DominoData);
00007
00008 void DominoData::flipLeftRight() {
00009 std::swap(GFL,GBR);
00010 std::swap(GFR,GBL);
00011 std::swap(TFL,TBR);
00012 std::swap(TFR,TBL);
00013 orientation = fmat::Quaternion::aboutZ(M_PI) * orientation;
00014 }
00015
00016 bool DominoData::isMatchFor(const ShapeRoot& other) const {
00017 if (!(isSameTypeAs(other) && isSameColorAs(other)))
00018 return false;
00019 const Shape<DominoData>& other_domino = ShapeRootTypeConst(other,DominoData);
00020 if ( lowValue != other_domino->getLowValue() ||
00021 highValue != other_domino->getHighValue() )
00022 return false;
00023 float dist = getCentroid().distanceFrom(other_domino->getCentroid());
00024 return dist < 100;
00025 }
00026
00027 void DominoData::computeGraspPoint(const ObjectFeature pos,
00028 Point &location,
00029 AngTwoPi &orient) const {
00030 if ( pos == center )
00031 location = getCentroid();
00032 else if ( pos == highEnd )
00033 location = LineData(getSpace(),getTFR(),getGBR()).getCentroid();
00034 else if ( pos == lowEnd )
00035 location = LineData(getSpace(),getTFL(),getGBL()).getCentroid();
00036
00037 orient = (getTFR() - getTFL()).atanYX() + AngTwoPi(pos == highEnd ? M_PI : 0.f);
00038 }
00039
00040 void DominoData::computeTargetPosition(const ObjectFeature pos,
00041 Point &location,
00042 AngTwoPi &orient) const {
00043 orient = (getTFR() - getTFL()).atanYX() + (AngTwoPi)(pos == highEnd) ? M_PI : 0.f;
00044 switch (pos) {
00045 case none:
00046 case center:
00047 case lowEnd:
00048 case highEnd:
00049 computeGraspPoint(pos,location,orient);
00050 location = ((location - getCentroid()) * 2) + getCentroid();
00051 break;
00052 case rightSide:
00053 location = (LineData(getSpace(),getTBR(),getGBL()).getCentroid() -
00054 getCentroid()).unitVector()*((75./2) + (200./2)) + getCentroid();
00055 orient += (AngTwoPi)(M_PI/2);
00056 break;
00057 case leftSide:
00058 location = (LineData(getSpace(),getTFR(),getGFL()).getCentroid() -
00059 getCentroid()).unitVector()*((75./2) + (200./2)) + getCentroid();
00060 orient -= (AngTwoPi)(M_PI/2);
00061 break;
00062 }
00063 }
00064
00065
00066 }