00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "itemfactory.h"
00023
00024 #include <typeinfo>
00025
00026 #include <QVApplication>
00027
00028 #include <QVProcessingBlock>
00029
00030 #include <QVPointBlock>
00031
00032 #include <QVImageCanvas>
00033 #include <QVNumericPlot>
00034 #include <QVHistogramPlot>
00035 #include <QVFunctionPlot>
00036 #include <QVCPUPlot>
00037
00038 #include <QVSynchronizerBlock>
00039
00040 #ifdef QVIPP
00041 #include <QVGraphsBlock>
00042 #include <QVFilterSelectorBlock>
00043 #include <QVYUV4MPEG2WriterBlock>
00044 #include <QVYUV4MPEG2ReaderBlock>
00045 #include <QVImageRetarderBlock>
00046 #include <QVImageMeansBlock>
00047 #endif
00048
00049
00050
00051
00052 #include <QVVideoReaderBlock>
00053
00055 ItemFactory::ItemFactory(): QObject()
00056 {
00057 inputItems.insert("Input node", QList<QString>());
00058 #ifdef QVMPLAYER
00059 inputItems["Input node"].append("QVMPlayerReaderBlock");
00060 #endif
00061 #ifdef QVIPP
00062 inputItems["Input node"].append("QVYUV4MPEG2ReaderBlock");
00063 #endif
00064 inputItems["Input node"].append("QVPointBlock");
00065
00066 outputItems.insert("Output node", QList<QString>());
00067 outputItems["Output node"].append("QVImageCanvas");
00068 outputItems["Output node"].append("QVNumericPlot");
00069 outputItems["Output node"].append("QVHistogramPlot");
00070 outputItems["Output node"].append("QVFunctionPlot");
00071 outputItems["Output node"].append("QVCPUPlot");
00072 #ifdef QVIPP
00073 outputItems["Output node"].append("QVYUV4MPEG2WriterBlock");
00074 #endif
00075 outputItems["Output node"].append("QVSynchronizer");
00076
00077 middleItems.insert("QVision block", QList<QString>());
00078 #ifdef QVIPP
00079 middleItems["QVision block"].append("QVGraphsBlock");
00080 middleItems["QVision block"].append("QVFilterSelectorBlock<uchar,1>");
00081 middleItems["QVision block"].append("QVFilterSelectorBlock<uchar,3>");
00082 middleItems["QVision block"].append("QVImageRetarderBlock<uchar,3>");
00083 middleItems["QVision block"].append("QVImageRetarderBlock<uchar,1>");
00084 middleItems["QVision block"].append("QVImageMeans<uChar,1>");
00085 middleItems["QVision block"].append("QVImageMeans<uChar,3>");
00086
00087
00088 QMap<QString, QString> ippBlocks = getQVIPPBlocksNames();
00089 foreach(QString ippGroup, ippBlocks.keys())
00090 {
00091 middleItems.insert(ippGroup, QList<QString>());
00092 foreach(QString qvippBlockName, ippBlocks.values(ippGroup))
00093 middleItems[ippGroup].append(qvippBlockName);
00094 }
00095 #endif
00096
00097
00098
00099
00100
00101
00102
00103 }
00104
00105 QMap<QString, QList<QString> > ItemFactory::getItemTypes() const
00106 {
00107 QMap<QString, QList<QString> > items = inputItems;
00108
00109 foreach(QString group, middleItems.keys()) {
00110 if (items.contains(group))
00111 items[group] = items.value(group) + middleItems.value(group);
00112 else
00113 items.insert(group, middleItems.value(group));
00114 }
00115
00116 foreach(QString group, outputItems.keys()) {
00117 if (items.contains(group))
00118 items[group] = items.value(group) + outputItems.value(group);
00119 else
00120 items.insert(group, outputItems.value(group));
00121 }
00122
00123 return items;
00124 }
00125
00126 QMap<QString, QList<QString> > ItemFactory::getInputItemTypes() const
00127 {
00128 return inputItems;
00129 }
00130
00131 QMap<QString, QList<QString> > ItemFactory::getMiddleItemTypes() const
00132 {
00133 return middleItems;
00134 }
00135
00136 QMap<QString, QList<QString> > ItemFactory::getOutputItemTypes() const
00137 {
00138 return outputItems;
00139 }
00140
00141 QVPropertyContainer *ItemFactory::createContainer(QString type, QString name) const
00142 {
00143 #ifdef QVIPP
00144 QVPropertyContainer *qvippBlock = newQVIPPBlock(type, name);
00145 if (qvippBlock != NULL)
00146 return qvippBlock;
00147 #endif
00148
00149
00150
00151
00152
00153
00154
00155 if (type == "QVImageCanvas") return new QVImageCanvas(name);
00156 else if (type == "QVNumericPlot") return new QVNumericPlot(name);
00157 else if (type == "QVHistogramPlot") return new QVHistogramPlot(name);
00158 else if (type == "QVFunctionPlot") return new QVFunctionPlot(name);
00159 else if (type == "QVCPUPlot") return new QVCPUPlot(name);
00160
00161 else if (type == "QVPointBlock") return new QVPointBlock(name);
00162 else if (type == "QVSynchronizer") return new QVSynchronizer(name);
00163 else if (type == "QVCPUPlot") return new QVCPUPlot(name);
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 else if (type == "QVVideoReaderBlock") {
00182 QVVideoReaderBlock* mpc = new QVVideoReaderBlock(name);
00183 if (mpc->getPropertyValue<QString>("URL").isEmpty())
00184 mpc->setPropertyValue("URL", QString("http://perception.inf.um.es/public_data/videos/misc/penguin.dv"));
00185 return mpc;
00186 }
00187
00188 #ifdef QVIPP
00189 else if (type == "QVYUV4MPEG2WriterBlock") return new QVYUV4MPEG2WriterBlock(name);
00190 else if (type == "QVImageRetarderBlock<uchar,3>") return new QVImageRetarderBlock<uchar, 3>(name);
00191 else if (type == "QVImageRetarderBlock<uchar,1>") return new QVImageRetarderBlock<uchar, 1>(name);
00192 else if (type == "QVImageMeans<uChar,1>") return new QVImageMeans<uChar, 1>(name);
00193 else if (type == "QVFilterSelectorBlock<uchar,1>") return new QVFilterSelectorBlock<uchar, 1>(name);
00194 else if (type == "QVFilterSelectorBlock<uchar,3>") return new QVFilterSelectorBlock<uchar, 3>(name);
00195 else if (type == "QVGraphsBlock") return new QVGraphsBlock(name);
00196 #endif // QVIPP
00197 else if (userBlocks.contains(type)) {
00198 QVProcessingBlock * newBlock = (QVProcessingBlock *)QMetaType::construct(userBlocks.value(type), (void *)0);
00199 newBlock->setName(name);
00200 return newBlock;
00201 }
00202 return 0;
00203 }
00204
00205 bool ItemFactory::deleteContainer(QVPropertyContainer *cont) const
00206 {
00207
00208 QString type = typeName(cont);
00209
00210
00211
00212
00213
00214
00215
00216 delete cont;
00217
00218 return TRUE;
00219 }
00220
00221 QString ItemFactory::containerType(QVPropertyContainer *cont) const
00222 {
00223
00224 return QString(typeName(cont));
00225 }
00226
00227 const QString ItemFactory::registerUserBlock(QVProcessingBlock * block)
00228 {
00229 const char * choptypeidname = typeName(block);
00230
00231
00232 QString typeString(choptypeidname);
00233 int type = QMetaType::type(choptypeidname);
00234
00235
00236 bool middleItemsContainsType = false;
00237 foreach(QList<QString> groupItems, middleItems.values())
00238 if (groupItems.contains(typeString)) {
00239 middleItemsContainsType = true;
00240 break;
00241 }
00242 if ( (type != 0) && (!middleItemsContainsType) ) {
00243 if (!middleItems.contains("User block")) middleItems.insert("User block", QList<QString>());
00244 middleItems["User block"].append(typeString);
00245 userBlocks.insert(typeString, type);
00246 return typeString;
00247 }
00248 return QString();
00249 }
00250
00251 bool ItemFactory::isUserType(QString type) const
00252 {
00253 return userBlocks.contains(type);
00254 }
00255
00256 const char *ItemFactory::typeName(QVPropertyContainer *cont) const
00257 {
00258 char *qvippBlockName = NULL;
00259 if (qvippBlockName != NULL)
00260 return qvippBlockName;
00261
00262 if(dynamic_cast<QVImageCanvas*>(cont) != NULL) return "QVImageCanvas";
00263 else if(dynamic_cast<QVNumericPlot*>(cont) != NULL) return "QVNumericPlot";
00264 else if(dynamic_cast<QVHistogramPlot*>(cont) != NULL) return "QVHistogramPlot";
00265 else if(dynamic_cast<QVFunctionPlot*>(cont) != NULL) return "QVFunctionPlot";
00266 else if(dynamic_cast<QVCPUPlot*>(cont) != NULL) return "QVCPUPlot";
00267 else if(dynamic_cast<QVPointBlock*>(cont) != NULL) return "QVPointBlock";
00268 else if(dynamic_cast<QVSynchronizer*>(cont) != NULL) return "QVSynchronizer";
00269 #ifdef QVIPP
00270 else if(dynamic_cast<QVGraphsBlock*>(cont) != NULL) return "QVGraphsBlock";
00271
00272 else if(dynamic_cast<QVYUV4MPEG2WriterBlock*>(cont) != NULL) return "QVYUV4MPEG2WriterBlock";
00273 else if(dynamic_cast<QVFilterSelectorBlock<uchar,1>*>(cont) != NULL) return "QVFilterSelectorBlock<uchar,1>";
00274 else if(dynamic_cast<QVFilterSelectorBlock<uchar,3>*>(cont) != NULL) return "QVFilterSelectorBlock<uchar,3>";
00275 else if(dynamic_cast<QVImageRetarderBlock<uchar,3>*>(cont) != NULL) return "QVImageRetarderBlock<uchar,3>";
00276 else if(dynamic_cast<QVImageRetarderBlock<uchar,1>*>(cont) != NULL) return "QVImageRetarderBlock<uchar,1>";
00277 else if(dynamic_cast<QVImageMeans<uChar,1>*>(cont) != NULL) return "QVImageMeans<uChar,1>";
00278 else if(dynamic_cast<QVImageMeans<uChar,3>*>(cont) != NULL) return "QVImageMeans<uChar,3>";
00279 #endif
00280
00281
00282 const char * typeidname = typeid(*cont).name();
00283
00284
00285 int i = 0;
00286 while ( (typeidname[i] != '\0') && ((typeidname[i] == '0') || (typeidname[i] == '1') || (typeidname[i] == '2') || (typeidname[i] == '3') ||
00287 (typeidname[i] == '4') || (typeidname[i] == '5') || (typeidname[i] == '6') || (typeidname[i] == '7') || (typeidname[i] == '8') ||
00288 (typeidname[i] == '9')) ) {
00289 i++;
00290 }
00291 return (typeidname + i*(sizeof(char)));
00292 }
00293
00294