BaseData.cc
Go to the documentation of this file.00001 #include "BaseData.h"
00002 #include "Sketch.h"
00003 #include "ShapeRoot.h"
00004 #include "ShapePoint.h"
00005 #include "SketchDataRoot.h"
00006 #include "ShapeSpace.h"
00007 #include "Shared/Measures.h"
00008
00009
00010 #include "LineData.h"
00011 #include "EllipseData.h"
00012 #include "PointData.h"
00013 #include "AgentData.h"
00014 #include "SphereData.h"
00015 #include "PolygonData.h"
00016 #include "BlobData.h"
00017 #include "BrickData.h"
00018 #include "PyramidData.h"
00019 #include "LocalizationParticleData.h"
00020 #include "TargetData.h"
00021 #include "MarkerData.h"
00022 #include "CylinderData.h"
00023 #include "SiftData.h"
00024 #include "AprilTagData.h"
00025 #include "GraphicsData.h"
00026 #include "SkeletonData.h"
00027
00028 using namespace std;
00029
00030 namespace DualCoding {
00031
00032 BaseData::BaseData(ShapeSpace& _space, ShapeType_t _type, int _parentId) :
00033 space(&_space), name(data_name(_type)), type(_type),
00034 id(0), parentId(_parentId), lastMatchId(0),
00035 refcount(0), viewable(true),
00036 color_rgb((ProjectInterface::getNumColors() != -1U) ? ProjectInterface::getColorRGB(1) : rgb(0,0,255)),
00037 confidence(1),
00038 mobile(false), obstacle(true), landmark(false),
00039 rendering_sketch(NULL)
00040 {};
00041
00042 BaseData::BaseData(const BaseData& other)
00043 : space(other.space), name(other.name), type(other.type),
00044 id(0), parentId(other.parentId), lastMatchId(other.lastMatchId),
00045 refcount(0), viewable(other.viewable),
00046 color_rgb(other.color_rgb),
00047 confidence(other.confidence),
00048 mobile(other.mobile), obstacle(other.obstacle), landmark(other.landmark),
00049 rendering_sketch(NULL)
00050 {};
00051
00052
00053 BaseData::~BaseData(void) {
00054 if ( rendering_sketch != NULL )
00055 delete rendering_sketch;
00056 }
00057
00058 Shape<PointData> BaseData::getCentroidPtShape() const {
00059 PointData *pt = new PointData(*space,getCentroid());
00060 pt->inheritFrom(*this);
00061 return Shape<PointData>(pt);
00062 }
00063
00064 BaseData& BaseData::operator=(const BaseData& other) {
00065
00066
00067
00068
00069 space = other.space ? &(*other.space) : NULL;
00070 name = other.name;
00071 type = other.type;
00072 id = other.id;
00073 parentId = other.parentId;
00074 lastMatchId = other.lastMatchId;
00075 refcount = other.refcount;
00076 viewable = other.viewable;
00077 color_rgb = other.color_rgb;
00078 confidence = other.confidence;
00079 mobile = other.mobile;
00080 obstacle = other.obstacle;
00081 landmark = other.landmark;
00082 rendering_sketch = other.rendering_sketch ? &(*rendering_sketch) : NULL;
00083 return *this;
00084 }
00085
00086 void BaseData::inheritFrom(const BaseData &parent) {
00087 setParentId(parent.getViewableId());
00088 setColor(parent.getColor());
00089 }
00090
00091 void BaseData::inheritFrom(const ShapeRoot &parent) {
00092 setParentId(parent->getViewableId());
00093 setColor(parent->getColor());
00094 }
00095
00096 void BaseData::inheritFrom(const SketchDataRoot &parent) {
00097 setParentId(parent.getViewableId());
00098 setColor(parent.getColor());
00099 }
00100
00101 void BaseData::V(std::string const &_name) {
00102 setViewable(true);
00103 if ( !_name.empty() ) setName(_name);
00104 }
00105
00106 void BaseData::N(std::string const &_name) {
00107 setViewable(false);
00108 if ( !_name.empty() ) setName(_name);
00109 }
00110
00111 ReferenceFrameType_t BaseData::getRefFrameType() const {
00112 return space->getRefFrameType(); }
00113
00114
00115
00116
00117
00118 const char* BaseData::getTypeName() const { return data_name(type); }
00119
00120
00121 bool BaseData::isType(ShapeType_t this_type) const { return this_type == type; }
00122
00123
00124 bool BaseData::isSameTypeAs(const ShapeRoot& other) const {
00125 return((bool)(isType(other->type))); }
00126
00127
00128 bool BaseData::isSameColorAs(const ShapeRoot& other) const {
00129 return getColor() == other->getColor(); }
00130
00131 void BaseData::setColor(const std::string &color_name) {
00132 setColor(ProjectInterface::getColorRGB(color_name));
00133 }
00134
00135 void BaseData::setColor(const rgb &new_color) {
00136 color_rgb = new_color;
00137 if ( rendering_sketch != NULL )
00138 (*rendering_sketch)->setColor(new_color);
00139 }
00140
00141 void BaseData::setColor(const unsigned int color_index) {
00142 setColor(ProjectInterface::getColorRGB(color_index));
00143 }
00144
00145
00146 bool BaseData::getMobile() const { return mobile; }
00147
00148 void BaseData::setMobile(bool _mobile) { mobile = _mobile; }
00149
00150 void BaseData::deleteRendering() {
00151 delete rendering_sketch;
00152 rendering_sketch = NULL;
00153 }
00154
00155 Sketch<bool>& BaseData::getRendering() {
00156 if ( rendering_sketch != NULL )
00157 return *rendering_sketch;
00158 rendering_sketch = render();
00159 (*rendering_sketch)->setColor(getColor());
00160 (*rendering_sketch)->setParentId(id);
00161 (*rendering_sketch)->setName("render("+getName()+")");
00162 return *rendering_sketch;
00163 }
00164
00165 BaseData* BaseData::clone() const {
00166 switch ( type ) {
00167 case unknownDataType:
00168 std::cerr << "Error: tried to clone a BaseData with unknownDataType!" << std::endl;
00169 return NULL;
00170 break;
00171 case lineDataType: return new LineData(*(const LineData*)this);
00172 case ellipseDataType: return new EllipseData(*(const EllipseData*)this);
00173 case pointDataType: return new PointData(*(const PointData*)this);
00174 case agentDataType: return new AgentData(*(const AgentData*)this);
00175 case sphereDataType: return new SphereData(*(const SphereData*)this);
00176 case polygonDataType: return new PolygonData(*(const PolygonData*)this);
00177 case blobDataType: return new BlobData(*(const BlobData*)this);
00178 case brickDataType: return new BrickData(*(const BrickData*)this);
00179 case pyramidDataType: return new PyramidData(*(const PyramidData*)this);
00180 case localizationParticleDataType: return new LocalizationParticleData(*(const LocalizationParticleData*)this);
00181 case targetDataType: return new TargetData(*(const TargetData*)this);
00182 case markerDataType: return new MarkerData(*(const MarkerData*)this);
00183 case cylinderDataType: return new CylinderData(*(const CylinderData*)this);
00184 case siftDataType: return new SiftData(*(const SiftData*)this);
00185 case aprilTagDataType: return new AprilTagData(*(const AprilTagData*)this);
00186 case graphicsDataType: return new GraphicsData(*(const GraphicsData*)this);
00187 case skeletonDataType: return new SkeletonData(*(const SkeletonData*)this);
00188 default: return NULL;
00189 }
00190 }
00191
00192 ShapeRoot BaseData::copy() const { return ShapeRoot(clone()); }
00193
00194 void BaseData::increaseConfidence(int n, int maxConfidence) {
00195 confidence += n;
00196 if ( maxConfidence > 0 )
00197 confidence = std::min(confidence, maxConfidence);
00198
00199 }
00200
00201 void BaseData::increaseConfidence(const BaseData& other, int maxConfidence) {
00202 increaseConfidence(other.getConfidence() > 0 ? other.getConfidence()+1 : 2, maxConfidence);
00203 }
00204
00205 void BaseData::increaseConfidence(const ShapeRoot& other, int maxConfidence) {
00206 increaseConfidence(other.getData(), maxConfidence);
00207 }
00208
00209 void BaseData::decreaseConfidence() {
00210 confidence--;
00211
00212 }
00213
00214 void BaseData::setPosition(const Point &pt) {
00215 const Point diff = pt - getCentroid();
00216 applyTransform(fmat::Transform::offset(diff.getCoords()), getRefFrameType());
00217 }
00218
00219 }