Homepage Demos Overview Downloads Tutorials Reference
Credits

BaseData.cc

Go to the documentation of this file.
00001 #include "Macrodefs.h"
00002 #include "Measures.h"
00003 
00004 #include "Sketch.h"   // this must precede references to Sketch
00005 #include "BaseData.h"
00006 #include "ShapeRoot.h"
00007 #include "ShapePoint.h"
00008 #include "SketchDataRoot.h"
00009 #include "ShapeSpace.h"
00010 
00011 namespace DualCoding {
00012 
00013 BoundingBox::BoundingBox(const BoundingBox &b1, const BoundingBox &b2) :
00014   xmin(min(b1.xmin,b2.xmin)), ymin(min(b1.ymin,b2.ymin)),
00015   xmax(max(b1.xmax,b2.xmax)), ymax(max(b1.ymax,b2.ymax)) {}
00016 
00017 BoundingBox::BoundingBox(const std::vector<ShapeRoot> &vec) :
00018   xmin(0), ymin(0), xmax(0), ymax(0) {
00019   if ( vec.size() > 0 ) {
00020     *this = vec[0]->getBoundingBox();
00021     for ( size_t i = 1; i<vec.size(); i++ )
00022       *this = BoundingBox(*this,vec[i]->getBoundingBox());
00023   }
00024 }
00025 
00026 std::ostream& operator<< (std::ostream& out, const BoundingBox &b) {
00027   out << "BoundingBox(" << b.xmin << "," << b.ymin << ","
00028       << b.xmax << "," << b.ymax << ")";
00029   return out;
00030 }
00031 
00032 
00033 BaseData::BaseData(ShapeSpace& _space, ShapeType_t _type, int _parentId) :
00034   space(&_space), name(data_name(_type)), type(_type), 
00035   id(0), parentId(_parentId), lastMatchId(0),
00036   refcount(0), viewable(true),
00037   color_rgb((ProjectInterface::getNumColors() != -1U) ? ProjectInterface::getColorRGB(1) : rgb(0,0,255)), // color 0 is invalid, so use color 1 as default, or blue if colors aren't loaded yet
00038   confidence(1),
00039   mobile(false),
00040   rendering_sketch(NULL)
00041 {};
00042 
00043 
00044   /*
00045 BaseData::BaseData(ShapeType_t _type, int _parentId) :
00046   space(NULL), name(data_name(_type)), type(_type), 
00047   id(0), parentId(_parentId), lastMatchId(0),
00048   refcount(0), viewable(true),
00049   color_rgb(ProjectInterface::defSegmentedColorGenerator?ProjectInterface::getColorRGB(1):rgb(0,0,255)), // color 0 is invalid, so use color 1 as default, or blue if colors aren't loaded yet
00050   confidence(1),
00051   mobile(false),
00052   rendering_sketch(NULL)
00053 {};
00054   */
00055     
00056 BaseData::BaseData(const BaseData& other)
00057   : space(other.space), name(other.name), type(other.type),
00058     id(0), parentId(other.parentId), lastMatchId(other.lastMatchId),
00059     refcount(0), viewable(other.viewable),
00060     color_rgb(other.color_rgb),
00061     confidence(other.confidence),
00062     mobile(other.mobile),
00063     rendering_sketch(NULL)
00064 {
00065   //  cout << "copied BaseData: parentID " << parentId << " <-> " << other.parentId << endl;
00066 };
00067 
00068 
00069 BaseData::~BaseData(void) { 
00070   if ( rendering_sketch != NULL )
00071     delete rendering_sketch;
00072 }
00073 
00074 Shape<PointData> BaseData::getCentroidPtShape() const {
00075   PointData *pt = new PointData(*space,getCentroid());
00076   pt->inheritFrom(*this);
00077   return Shape<PointData>(pt);
00078 }
00079 
00080 BaseData& BaseData::operator=(const BaseData& other) {
00081   // assumes &other =? this check is done by the sub class using BaseData::operator=
00082   //  if (&other == this)
00083   //    return *this;
00084 
00085   space = other.space ? &(*other.space) : NULL;
00086   name = other.name;
00087   type = other.type;  
00088   id = other.id;
00089   parentId = other.parentId;
00090   lastMatchId = other.lastMatchId;
00091   refcount = other.refcount;
00092   viewable = other.viewable;
00093   color_rgb = other.color_rgb;
00094   confidence = other.confidence;
00095   mobile = other.mobile;  
00096   rendering_sketch = other.rendering_sketch ? &(*rendering_sketch) : NULL;
00097   return *this;
00098 }
00099 
00100 void BaseData::inheritFrom(const BaseData &parent) {   // used by leftPtShape, etc.
00101   setParentId(parent.getViewableId());
00102   setColor(parent.getColor());
00103 }
00104 
00105 void BaseData::inheritFrom(const ShapeRoot &parent) {
00106   setParentId(parent->getViewableId());
00107   setColor(parent->getColor());
00108 }
00109 
00110 void BaseData::inheritFrom(const SketchDataRoot &parent) {
00111   setParentId(parent.getViewableId());
00112   setColor(parent.getColor());
00113 }
00114 
00115 void BaseData::V(std::string const &_name) {
00116   setViewable(true);
00117   if ( !_name.empty() ) setName(_name);
00118 }
00119 
00120 void BaseData::N(std::string const &_name) {
00121   setViewable(false);
00122   if ( !_name.empty() ) setName(_name);
00123 }
00124 
00125 ReferenceFrameType_t BaseData::getRefFrameType() const {
00126   return space->getRefFrameType(); }
00127 
00128 
00129 //!Type.
00130 //{
00131 //! Get shape type name.
00132 const char* BaseData::getTypeName() const { return data_name(type); }
00133 
00134 //! Test the shape type.
00135 bool BaseData::isType(ShapeType_t this_type) const { return this_type == type; }
00136 
00137 //! Test that two shapes are of same type.
00138 bool BaseData::isSameTypeAs(const ShapeRoot& other) const {
00139   return((bool)(isType(other->type))); }
00140 
00141 
00142 bool BaseData::isSameColorAs(const ShapeRoot& other) const {
00143   return getColor() == other->getColor(); }
00144 
00145 void BaseData::setColor(string const &color_name) {
00146   setColor(ProjectInterface::getColorRGB(color_name));
00147 }
00148 
00149 void BaseData::setColor(rgb new_color) {
00150   color_rgb = new_color;
00151   if ( rendering_sketch != NULL )
00152     (*rendering_sketch)->setColor(new_color);
00153 }
00154 
00155 
00156 bool BaseData::isMobile() const { return mobile; }
00157 
00158 void BaseData::setMobile(bool _mobile) { mobile = _mobile; }
00159 
00160 void BaseData::deleteRendering() {
00161   delete rendering_sketch;
00162   rendering_sketch = NULL;
00163 }
00164 
00165 Sketch<bool>& BaseData::getRendering() {
00166   if ( rendering_sketch != NULL )
00167     return *rendering_sketch;
00168   rendering_sketch = render();
00169   (*rendering_sketch)->setColor(getColor());
00170   (*rendering_sketch)->setParentId(id);
00171   (*rendering_sketch)->setName("render("+getName()+")");
00172   return *rendering_sketch;
00173 }
00174 
00175 
00176 void BaseData::increaseConfidence(int n, int maxConfidence) {
00177   confidence += n;
00178   if ( maxConfidence > 0 )
00179     confidence = min(confidence, maxConfidence);
00180 }
00181   
00182 void BaseData::increaseConfidence(const BaseData& other, int maxConfidence) {
00183   increaseConfidence(other.getConfidence() > 0 ? other.getConfidence()+1 : 2, maxConfidence);
00184 }
00185   
00186 void BaseData::increaseConfidence(const ShapeRoot& other, int maxConfidence) { 
00187   increaseConfidence(other.getData(), maxConfidence);
00188 }
00189 
00190 } // namespace

DualCoding 3.0beta
Generated Wed Oct 4 00:01:53 2006 by Doxygen 1.4.7