void SVGReader::readGroup(void) { Q_ASSERT(mXml.isStartElement() && mXml.name() == "g"); bool ok = false; QString transform = mXml.attributes().value("transform").toString(); // <g transform="scale(371, 371)"> QRegExp re("(\\d+),\\s*(\\d+)"); re.indexIn(transform); QStringList scales = re.capturedTexts(); const int xs = scales.at(1).toInt(&ok); if (!ok) { mXml.raiseError(QObject::tr("invalid x scale factor in \"%1\"").arg(scales.at(0))); return; } const int ys = scales.at(2).toInt(&ok); if (!ok) { mXml.raiseError(QObject::tr("invalid y scale factor in \"%1\"").arg(scales.at(0))); return; } mDNA.setScale(QSize(xs, ys)); while (mXml.readNextStartElement()) { if (mXml.name() == "path") { readPath(); } else { mXml.skipCurrentElement(); } } }
void XmlLoader::readPicture(QDomElement const &picture) { QDomNodeList pictureAttributes = picture.childNodes(); for (unsigned i = 0; i < pictureAttributes.length(); ++i) { QDomElement type = pictureAttributes.at(i).toElement(); if (type.tagName() == "line") readLine(type); else if (type.tagName() == "ellipse") readEllipse(type); else if (type.tagName() == "arc") readArch(type); else if (type.tagName() == "rectangle") readRectangle(type); else if (type.tagName() == "stylus") readStylus(type); else if (type.tagName() == "path") readPath(type); else if (type.tagName() == "curve") readCurve(type); else if (type.tagName() == "text") readText(type); else qDebug() << "Incorrect picture tag"; } }
void SVGReader::readPath(void) { Q_ASSERT(mXml.isStartElement() && mXml.name() == "path"); QColor color; int pos; bool ok = false; // <path style="fill-opacity:0.230442;fill:rgb(14,9,206)" d="M 0.845225 0.845225 L 0.431106 0.585496 L 0.0788198 0.4925 L 0.0861273 0.692974 Z" /> const QString& style = mXml.attributes().value("style").toString(); color = getRGB(QRegExp("fill\\s*:\\s*rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)"), style, mXml, &ok); if (!color.isValid()) { // fallback to v0.4 format const QString& fill = mXml.attributes().value("fill").toString(); color = getRGB(QRegExp("(\\d+),\\s*(\\d+),\\s*(\\d+)"), fill, mXml, &ok); } if (!ok) { mXml.raiseError(QObject::tr("fill not found or invalid")); return; } QRegExp fo_re("fill-opacity\\s*:\\s*([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)"); pos = fo_re.indexIn(style); qreal alpha = (-1 != pos)? fo_re.capturedTexts().at(1).toDouble(&ok) : color.alphaF(); if (!ok) { mXml.raiseError(QObject::tr("fill-opacity (%1): not found or invalid").arg(fo_re.capturedTexts().at(1))); return; } color.setAlphaF(alpha); QPolygonF polygon; // ... 0.0788198 0.4925 ... 3.687e-4 -0.91112 ... QRegExp coords_re("([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)\\s+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)"); QString d = mXml.attributes().value("d").toString(); while ((pos = coords_re.indexIn(d)) != -1) { const QStringList& xy = coords_re.capturedTexts(); const qreal x = xy.at(1).toDouble(&ok); if (!ok) { mXml.raiseError(QObject::tr("invalid x coordinate in \"%1\"").arg(xy.at(0))); return; } const qreal y = xy.at(3).toDouble(&ok); if (!ok) { mXml.raiseError(QObject::tr("invalid y coordinate in \"%1\"").arg(xy.at(0))); return; } polygon << QPointF(x, y); d = d.right(d.size() - pos - xy.at(0).size() + 1); } mDNA.append(Gene(polygon, color)); while (mXml.readNextStartElement()) { if (mXml.name() == "path") readPath(); else mXml.skipCurrentElement(); } }
static bool readFile(Path *p, const std::string &str) { if (!str.empty()) { auto content = filesystem::readTextFile(str); CharReaderBase r(content); r.skipUntilString("<path "); if (!r.is("<path ")) { return false; } r.skipString("<path "); CharReaderBase pathContent = r.readUntil<Chars<'>'>>(); pathContent.skipUntilString("d=\""); if (r.is("d=\"")) { r.skipString("d=\""); return readPath(p, pathContent.readUntil<Chars<'"'>>()); } } return false; }
int main(int argc, char *argv[]) { if (argc > 1 && strncmp(argv[1],"-",1)!=0) { strcpy(path, argv[1]); } else { getcwd(path, MAX_PATH); } int len = strlen(path); const char *last = &path[len - 1]; if (strcmp(last, "/") != 0) { strcat(path,"/"); } printf("input path: %s", path); int c; int aoption = 0; int loption = 0; int ooption = 0; while ((c = getopt(argc, argv, "algo")) != -1) { switch (c) { case 'a': aoption = 1; break; case 'l': loption = 1; break; case 'g': loption = 2; break; case 'o': if(loption==0) loption=1; ooption = 1; break; } } readPath(path, aoption, loption, ooption); return 0; }
/** Read map layers from project file @returns \code QPair< bool, QList<QDomNode> > \endcode bool is true if function worked; else is false. list contains nodes corresponding to layers that couldn't be loaded @note XML of form: \verbatim <maplayer type="vector"> <layername>Hydrop</layername> <datasource>/data/usgs/city_shp/hydrop.shp</datasource> <zorder>0</zorder> <provider>ogr</provider> <singlesymbol> <renderitem> <value>blabla</value> <symbol> <outlinecolor red="85" green="0" blue="255" /> <outlinestyle>SolidLine</outlinestyle> <outlinewidth>1</outlinewidth> <fillcolor red="0" green="170" blue="255" /> <fillpattern>SolidPattern</fillpattern> </symbol> <label>blabla</label> </renderitem> </singlesymbol> <label>0</label> <labelattributes> <label text="Label" field="" /> <family name="Sans Serif" field="" /> <size value="12" units="pt" field="" /> <bold on="0" field="" /> <italic on="0" field="" /> <underline on="0" field="" /> <color red="0" green="0" blue="0" field="" /> <x field="" /> <y field="" /> <offset units="pt" x="0" xfield="" y="0" yfield="" /> <angle value="0" field="" /> <alignment value="center" field="" /> </labelattributes> </maplayer> \endverbatim */ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &doc ) { // Layer order is set by the restoring the legend settings from project file. // This is done on the 'readProject( ... )' signal QDomNodeList nl = doc.elementsByTagName( "maplayer" ); // XXX what is this used for? QString layerCount( QString::number(nl.count()) ); QString wk; QList<QDomNode> brokenNodes; // a list of Dom nodes corresponding to layers // that we were unable to load; this could be // because the layers were removed or // re-located after the project was last saved // process the map layer nodes if ( 0 == nl.count() ) // if we have no layers to process, bail { return qMakePair( true, brokenNodes ); // Decided to return "true" since it's // possible for there to be a project with no // layers; but also, more imporantly, this // would cause the tests/qgsproject to fail // since the test suite doesn't currently // support test layers } bool returnStatus = true; emit layerLoaded( 0, nl.count() ); //Collect vector layers with joins. //They need to refresh join caches and symbology infos after all layers are loaded QList< QPair< QgsVectorLayer*, QDomElement > > vLayerList; for ( int i = 0; i < nl.count(); i++ ) { QDomNode node = nl.item( i ); QDomElement element = node.toElement(); if ( element.attribute( "embedded" ) == "1" ) { createEmbeddedLayer( element.attribute( "id" ), readPath( element.attribute( "project" ) ), brokenNodes, vLayerList ); continue; } else { if ( !addLayer( element, brokenNodes, vLayerList ) ) { returnStatus = false; } } emit layerLoaded( i + 1, nl.count() ); } //Update field map of layers with joins and create join caches if necessary //Needs to be done here once all dependent layers are loaded QList< QPair< QgsVectorLayer*, QDomElement > >::iterator vIt = vLayerList.begin(); for ( ; vIt != vLayerList.end(); ++vIt ) { vIt->first->createJoinCaches(); vIt->first->updateFields(); } return qMakePair( returnStatus, brokenNodes ); } // _getMapLayers
int main(int argc ,char* argv[]){ if(argc != 2){ std::cout << "Usage:" << std::endl << "%s ./FeatureViewer input.txt"<<std::endl<<std::endl; return 0; } std::string nvmpath; std::string imgpath; int lengh,cam,numofimg,numofLines; if(readPath(argv[1], &imgpath, &nvmpath, &cam, &lengh, &numofimg, &numofLines) == 0){ return 0; } std::cout << "****************************************" << std::endl << "How to use..." << std::endl << " * [n] key : Move to Next Frame" << std::endl; std::cout << " * [p] key : Move to previous Frame" << std::endl; std::cout << " * [q] key : Quit thie application" << std::endl << "****************************************" << std::endl<< std::endl; std::cout << " * imgpath:" << imgpath << std::endl; std::cout << " * nvmpath:" << nvmpath << std::endl; std::cout << " * pertitition_number:" << cam << std::endl; std::cout << " * rought_lengh:" << lengh << std::endl; std::cout << " * num_of_imgs:" << numofimg << std::endl; std::cout << " * num_of_lines:" << numofLines << std::endl << std::endl; int numpic=0; ImageViewer imgv(cam,lengh, "FeatureViewer"); Reader reader(cam,imgpath,nvmpath); Drawer drawer; if(reader.setFeaturePoint(1,numofLines) != 0){ exit(0); } reader.setImg(cam, 0, numofimg-1); reader.sortKeyFrameID(); imgv.setWindow(); for(int i=lengh+1; i<reader.ik.size();i++){ std::vector<std::vector<ImageKeeper>> drawnCam(cam); for(int j=0; j<12; j++){ for(int k=0; k<lengh+1;k++){ drawnCam[j].push_back(reader.getIKbyID(j,reader.keyFrameID[i-k])); } } std::vector< std::vector<bool> > flagCam(cam); for(int j=0;j<cam;j++){ drawer.DrawPoints(drawnCam[j][0]); flagCam[j].resize(drawnCam[j][0].getFeaturesSize()); } for(int j=0;j<cam;j++){ for(int k=0;k<cam;k++){ if(j!=k){ drawnCam[k][1].getFeatureFlags(drawnCam[j][0],flagCam[j]); } } } for(int j=0;j<cam;j++){ drawer.DrawRoute(drawnCam[j],drawnCam[j][0].getIMG(),flagCam[j]); } std::vector<ImageKeeper> preimg; std::vector<ImageKeeper> viewedimg; for(int j=0;j<cam;j++){ preimg.push_back(drawnCam[j][1]); viewedimg.push_back(drawnCam[j][0]); } showData(viewedimg); imgv.showImgsTheta(viewedimg, preimg); checkCommand(&i,cv::waitKey(0)); } return 0; }
static bool readPath(Path *p, const std::string &str) { return readPath(p, CharReaderBase(str)); }