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 using namespace std;
00010
00011 namespace DualCoding {
00012
00013 BaseData::BaseData(ShapeSpace& _space, ShapeType_t _type, int _parentId) :
00014 space(&_space), name(data_name(_type)), type(_type),
00015 id(0), parentId(_parentId), lastMatchId(0),
00016 refcount(0), viewable(true),
00017 color_rgb((ProjectInterface::getNumColors() != -1U) ? ProjectInterface::getColorRGB(1) : rgb(0,0,255)),
00018 confidence(1),
00019 mobile(false),
00020 obstacle(true),
00021 rendering_sketch(NULL)
00022 {};
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 BaseData::BaseData(const BaseData& other)
00039 : space(other.space), name(other.name), type(other.type),
00040 id(0), parentId(other.parentId), lastMatchId(other.lastMatchId),
00041 refcount(0), viewable(other.viewable),
00042 color_rgb(other.color_rgb),
00043 confidence(other.confidence),
00044 mobile(other.mobile),
00045 obstacle(other.obstacle),
00046 rendering_sketch(NULL)
00047 {
00048
00049 };
00050
00051
00052 BaseData::~BaseData(void) {
00053 if ( rendering_sketch != NULL )
00054 delete rendering_sketch;
00055 }
00056
00057 Shape<PointData> BaseData::getCentroidPtShape() const {
00058 PointData *pt = new PointData(*space,getCentroid());
00059 pt->inheritFrom(*this);
00060 return Shape<PointData>(pt);
00061 }
00062
00063 BaseData& BaseData::operator=(const BaseData& other) {
00064
00065
00066
00067
00068 space = other.space ? &(*other.space) : NULL;
00069 name = other.name;
00070 type = other.type;
00071 id = other.id;
00072 parentId = other.parentId;
00073 lastMatchId = other.lastMatchId;
00074 refcount = other.refcount;
00075 viewable = other.viewable;
00076 color_rgb = other.color_rgb;
00077 confidence = other.confidence;
00078 mobile = other.mobile;
00079 obstacle = other.obstacle;
00080 rendering_sketch = other.rendering_sketch ? &(*rendering_sketch) : NULL;
00081 return *this;
00082 }
00083
00084 void BaseData::inheritFrom(const BaseData &parent) {
00085 setParentId(parent.getViewableId());
00086 setColor(parent.getColor());
00087 }
00088
00089 void BaseData::inheritFrom(const ShapeRoot &parent) {
00090 setParentId(parent->getViewableId());
00091 setColor(parent->getColor());
00092 }
00093
00094 void BaseData::inheritFrom(const SketchDataRoot &parent) {
00095 setParentId(parent.getViewableId());
00096 setColor(parent.getColor());
00097 }
00098
00099 void BaseData::V(std::string const &_name) {
00100 setViewable(true);
00101 if ( !_name.empty() ) setName(_name);
00102 }
00103
00104 void BaseData::N(std::string const &_name) {
00105 setViewable(false);
00106 if ( !_name.empty() ) setName(_name);
00107 }
00108
00109 ReferenceFrameType_t BaseData::getRefFrameType() const {
00110 return space->getRefFrameType(); }
00111
00112
00113
00114
00115
00116 const char* BaseData::getTypeName() const { return data_name(type); }
00117
00118
00119 bool BaseData::isType(ShapeType_t this_type) const { return this_type == type; }
00120
00121
00122 bool BaseData::isSameTypeAs(const ShapeRoot& other) const {
00123 return((bool)(isType(other->type))); }
00124
00125
00126 bool BaseData::isSameColorAs(const ShapeRoot& other) const {
00127 return getColor() == other->getColor(); }
00128
00129 void BaseData::setColor(const std::string &color_name) {
00130 setColor(ProjectInterface::getColorRGB(color_name));
00131 }
00132
00133 void BaseData::setColor(const rgb &new_color) {
00134 color_rgb = new_color;
00135 if ( rendering_sketch != NULL )
00136 (*rendering_sketch)->setColor(new_color);
00137 }
00138
00139 void BaseData::setColor(const unsigned int color_index) {
00140 setColor(ProjectInterface::getColorRGB(color_index));
00141 }
00142
00143
00144 bool BaseData::getMobile() const { return mobile; }
00145
00146 void BaseData::setMobile(bool _mobile) { mobile = _mobile; }
00147
00148 void BaseData::deleteRendering() {
00149 delete rendering_sketch;
00150 rendering_sketch = NULL;
00151 }
00152
00153 Sketch<bool>& BaseData::getRendering() {
00154 if ( rendering_sketch != NULL )
00155 return *rendering_sketch;
00156 rendering_sketch = render();
00157 (*rendering_sketch)->setColor(getColor());
00158 (*rendering_sketch)->setParentId(id);
00159 (*rendering_sketch)->setName("render("+getName()+")");
00160 return *rendering_sketch;
00161 }
00162
00163
00164 void BaseData::increaseConfidence(int n, int maxConfidence) {
00165 confidence += n;
00166 if ( maxConfidence > 0 )
00167 confidence = std::min(confidence, maxConfidence);
00168 }
00169
00170 void BaseData::increaseConfidence(const BaseData& other, int maxConfidence) {
00171 increaseConfidence(other.getConfidence() > 0 ? other.getConfidence()+1 : 2, maxConfidence);
00172 }
00173
00174 void BaseData::increaseConfidence(const ShapeRoot& other, int maxConfidence) {
00175 increaseConfidence(other.getData(), maxConfidence);
00176 }
00177
00178 }