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