Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

TableDataSourceFlickrPhotoList.h

Go to the documentation of this file.
00001 #ifndef TABLEDATASOURCEFLICKRPHOTOLIST_H
00002 #define TABLEDATASOURCEFLICKRPHOTOLIST_H
00003 
00004 #include "TableDataSource.h"
00005 
00006 #include "RemoteRetriever.h"
00007 
00008 #include "Util/XmlDoc.h"
00009 #include "Persistency/XmlFileReader.h"
00010 
00011 namespace Impala { namespace Application { namespace MediaTable {
00012 
00013 class TableDataSourceFlickrPhotoList : public TableDataSource, public Util::XmlDoc
00014 {
00015 public:
00016         TableDataSourceFlickrPhotoList(std::string url = ""):
00017         TableDataSource()
00018     {
00019         mRemoteRetriever = RemoteRetriever::GetInstance();
00020         Init(url);
00021     }
00022 
00023     ~TableDataSourceFlickrPhotoList()
00024     {
00025     }
00026 
00027 
00028     /* get individual row characteristics ************************/
00029     virtual String
00030     GetTextDataByID(String column, int row)
00031     {
00032                 return GetAttributeValue(mPhotos[row], column.c_str());
00033     }
00034 
00035     virtual int
00036     GetIntDataByID(String column, int row)
00037     {
00038         return atoi(GetTextDataByID(column, row));
00039     }
00040 
00041     virtual double
00042     GetDoubleDataByID(String column, int row)
00043     {
00044         return atof(GetTextDataByID(column, row));
00045     }
00046 
00047     //virtual int
00048     //GetRowHeight(int row)
00049     //{
00050     //    return 40;
00051     //}
00052 
00053     virtual double
00054     GetNormalizedDataByID(String column, int row)
00055     {
00056         double v = row / (double)mTotalRows;
00057         if (column == "red")
00058             return v;
00059         if (column == "green")
00060             return 1.0 - v;
00061         if (column == "blue") {
00062             return (row % 10) / 10.0;
00063         }
00064 
00065         return atof(GetTextDataByID(column, row));
00066     }
00067 
00068     virtual Array2dVec3UInt8*
00069     GetImageDataByID(String column, int row)
00070     {
00071         std::string sizeSuffix = "s";
00072         std::string imageUrl = "http://farm";
00073         imageUrl += GetAttributeValue(mPhotos[row], "farm") + ".static.flickr.com/";
00074         imageUrl += GetAttributeValue(mPhotos[row], "server") + "/";
00075         imageUrl += GetAttributeValue(mPhotos[row], "id") + "_";
00076         imageUrl += GetAttributeValue(mPhotos[row], "secret");
00077         if(sizeSuffix.length() > 0) imageUrl += "_" + sizeSuffix;
00078         imageUrl += ".jpg";
00079 
00080         Array2dVec3UInt8* ar = 0;
00081         ar = mRemoteRetriever->RetrieveImageData(imageUrl);
00082         return ar;
00083     }
00084 
00085     int GetTotalRows() {
00086         return mTotalRows;
00087     }
00088 
00089 private:
00090 
00091     void Init(std::string url)
00092     {
00093         AddStaticColumn("id", TYPE_TEXT, 50);
00094         AddStaticColumn("photo", TYPE_IMAGE, 50);
00095         AddColumn("secret", TYPE_TEXT, 50);
00096         AddColumn("farm", TYPE_INT, 50);
00097         AddColumn("server", TYPE_INT, 50);
00098         AddColumn("owner", TYPE_TEXT, 50);
00099         AddColumn("title", TYPE_TEXT, 50);
00100         AddColumn("ownername", TYPE_TEXT, 50);
00101         AddColumn("latitude", TYPE_DOUBLE, 50);
00102         AddColumn("longitude", TYPE_DOUBLE, 50);
00103         AddColumn("views", TYPE_INT, 50);
00104         AddColumn("tags", TYPE_TEXT, 50);
00105         AddColumn("red", TYPE_NORMALIZEDVALUE, 50, 1);
00106         AddColumn("green", TYPE_NORMALIZEDVALUE, 50, 2);
00107         AddColumn("blue", TYPE_NORMALIZEDVALUE, 50, 3);
00108 
00109         loadXML(url);
00110     }
00111 
00112         void loadXML(std::string url) {
00113                 //string url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=78c291da0267f70420521d1a04b788a0&sort=date-posted-asc&tag_mode=all&media=photos&extras=license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media&per_page=500&tags=obama";
00114                 if(url == "")
00115                         url = "http://api.flickr.com/services/rest/?method=flickr.panda.getPhotos&api_key=78c291da0267f70420521d1a04b788a0&extras=license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media&per_page=500&panda_name=wang%20wang";
00116                 std::string xmlFile = "photos.xml";
00117 
00118                 mRemoteRetriever->RetrieveFile(url, false, true, xmlFile);
00119 
00120         ILOG_INFO("reading XML file: " + xmlFile);
00121                 DOMDocument* doc = reader.Read(xmlFile);
00122                 DOMNode* root = GetChildNode(GetChildNode(doc, "rsp", true), "photos", true);
00123 
00124                 mPhotos = GetChildNodes(root, "photo");
00125                 mTotalRows = mPhotos.size();
00126         }
00127 
00128         Persistency::XmlFileReader      reader;
00129         std::vector<DOMNode*>           mPhotos;
00130     RemoteRetriever*                    mRemoteRetriever;
00131     int                                                 mTotalRows;
00132 
00133     ILOG_VAR_DEC;
00134 };
00135 
00136 ILOG_VAR_INIT(TableDataSourceFlickrPhotoList, Application.MediaTable);
00137 
00138 } } } // namespace Impala::Application::MediaTable
00139 
00140 #endif // TABLEDATASOURCEFLICKRPHOTOLIST_H

Generated on Fri Mar 19 09:30:34 2010 for ImpalaSrc by  doxygen 1.5.1