Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SketchDataRoot.cc

Go to the documentation of this file.
00001 // These have to go in the .cc file because SketchSpace.h circularly depends
00002 // on SketchData.h, so we can't reference members of SketchSpace in the
00003 // SketchDataRoot.h file.
00004 
00005 #include "SketchDataRoot.h"
00006 #include "SketchSpace.h"  // can't include this in SketchDataRoot.h due to circularities
00007 #include "ShapeRoot.h"
00008 #include "SketchSpace.h"
00009 #include "ViewerConnection.h"
00010 
00011 #include "Shared/LoadSave.h"
00012 #include "Shared/Config.h"
00013 #include "Shared/get_time.h"
00014 #include "Shared/ProjectInterface.h" // needed for defSegmentedColorGenerator
00015 #include "Vision/SegmentedColorGenerator.h"
00016 
00017 namespace DualCoding {
00018 
00019 ShapeSpace& SketchDataRoot::getDualSpace() const { return space->getDualSpace(); }
00020 
00021 const unsigned int SketchDataRoot::getWidth() const { return space->getWidth(); }
00022 const unsigned int SketchDataRoot::getHeight() const { return space->getHeight(); }
00023 const unsigned int SketchDataRoot::getNumPixels() const { return space->getNumPixels(); }
00024 
00025 void SketchDataRoot::inheritFrom(const SketchDataRoot &parent) {
00026   setParentId(parent.getViewableId());
00027   setColor(parent.getColor());
00028   if ( getType() == sketchBool )
00029     setColorMap(segMap);
00030   else
00031     setColorMap(parent.getColorMap());
00032 }
00033 
00034 void SketchDataRoot::inheritFrom(const ShapeRoot &parent) {
00035   setParentId(parent->getViewableId());
00036   setColor(parent->getColor());
00037 }
00038 
00039 void SketchDataRoot::inheritFrom(const BaseData &parent) {
00040   setParentId(parent.getViewableId());
00041   setColor(parent.getColor());
00042 }
00043 
00044 void SketchDataRoot::V(std::string const &_name) {
00045   setViewable(true);
00046   if ( !_name.empty() ) setName(_name);
00047 }
00048 
00049 void SketchDataRoot::N(std::string const &_name) {
00050   setViewable(false);
00051   if ( !_name.empty() ) setName(_name);
00052 }
00053 
00054 void SketchDataRoot:: setColor(const std::string &colorname) {
00055   setColor(ProjectInterface::getColorRGB(colorname));
00056 }
00057 
00058 void SketchDataRoot::setColor(const color_index cindex) {
00059   setColor(ProjectInterface::getColorRGB(cindex));
00060 }
00061 
00062 Point SketchDataRoot::indexPoint(const int index) {
00063   float x = (float)indexX(index);
00064   float y = (float)indexY(index);
00065   fmat::Column<3> pt = space->getTmatinv() * fmat::pack(x,y,0);
00066   return Point(pt, space->getDualSpace().getRefFrameType());
00067 }
00068 
00069 #define SKETCHDATA_ENCODE(a) \
00070 if(!LoadSave::encodeInc(a,buf,avail,"SketchData encode ran out of space at %s:%u\n",__FILE__,__LINE__)) return 0;
00071   
00072 unsigned int SketchDataRoot::saveBuffer(char buf[], unsigned int avail) const
00073 {
00074   char* packet = buf; // beginning of packet
00075   static int frameNum = 0; // should this become a static member variable?
00076   
00077   SKETCHDATA_ENCODE("TekkotsuImage");
00078   SKETCHDATA_ENCODE(Config::vision_config::ENCODE_SINGLE_CHANNEL);
00079   SKETCHDATA_ENCODE(Config::vision_config::RawCamConfig::COMPRESS_NONE);
00080   SKETCHDATA_ENCODE(getWidth());
00081   SKETCHDATA_ENCODE(getHeight());
00082   SKETCHDATA_ENCODE(get_time()); // is this what should be used for time stamp?
00083   SKETCHDATA_ENCODE(frameNum++);
00084   
00085   // encode filterbank info
00086   SKETCHDATA_ENCODE("FbkImage");
00087   SKETCHDATA_ENCODE(getWidth());
00088   SKETCHDATA_ENCODE(getHeight());
00089   SKETCHDATA_ENCODE(CAM_LAYER);
00090   SKETCHDATA_ENCODE(CAM_CHANNEL);
00091   
00092   // encode actual image data
00093   SKETCHDATA_ENCODE("SketchImage");
00094   SKETCHDATA_ENCODE((unsigned char)getType());
00095   const unsigned int imglength  = savePixels(buf,avail);
00096   if(imglength==0)
00097     return 0; // savePixels should have already reported the error
00098   avail-=imglength;
00099   buf+=imglength;
00100   
00101   // encode color table(same as color table of segmentedcolorgenerator for now
00102   (dynamic_cast<SegmentedColorGenerator*>(ProjectInterface::defSegmentedColorGenerator))->encodeColorsInc(buf,avail);
00103   return buf-packet;
00104 }
00105 
00106 } // namespace

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