PathVector Path::dirs() const { PathVector ret; bfs::directory_iterator dit(_p->path); for (; dit != bfs::directory_iterator(); ++dit) { if (bfs::is_directory(*dit)) ret.push_back(Path(*dit)); } return ret; }
PathVector Path::files() const { PathVector ret; bfs::directory_iterator dit(_p->path); for (; dit != bfs::directory_iterator(); ++dit) { if (bfs::is_regular_file(*dit)) ret.push_back(Path(new PrivatePath(*dit))); } return ret; }
void LPECopyRotate::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) { using namespace Geom; Path path(start_pos); path.appendNew<LineSegment>((Geom::Point) origin); path.appendNew<LineSegment>(rot_pos); PathVector pathv; pathv.push_back(path); hp_vec.push_back(pathv); }
void draw_areas(cairo_t *cr, Areas const &areas, PathVector const &pa) { PathVector ps = areas_to_paths(pa, areas); for(unsigned i = 0; i < ps.size(); i++) { double area; Point centre; Geom::centroid(ps[i].toPwSb(), centre, area); double d = 5.; if(area < 0) cairo_set_dash(cr, &d, 1, 0); cairo_path(cr, ps[i]); cairo_stroke(cr); cairo_set_dash(cr, &d, 0, 0); } }
void Path::addVector(PathVector vector) { if(m_pathPoints.empty()) { m_pathPoints.push_back(vector.getEdge().getStart()); m_pathPoints.push_back(vector.getEdge().getEnd()); } else { m_pathPoints.push_back(vector.getEdge().getEnd()); } m_path.push_back(vector); }
virtual void draw(cairo_t *cr, std::ostringstream *notify, int width, int height, bool save, std::ostringstream *timer_stream) { Geom::Translate t(offset_handle.pos); //Shape bst = bs * t; //Region bt = Region(b * t, b.isFill()); cairo_set_line_width(cr, 1); cairo_set_source_rgb(cr, 0,0,0); //cairo_shape(cr, bst); cairo_path(cr, pv*t); cairo_stroke(cr); for(unsigned i = 0; i < pv.size(); i++) { if(pv[i].size() == 0) { *notify << "naked moveto;"; } else for(unsigned j = 0; j < pv[i].size(); j++) { const Curve* c = &pv[i][j]; const BezierCurve* bc = dynamic_cast<const BezierCurve*>(c); if(bc) { for(unsigned k = 0; k < bc->order(); k++) { *notify << (*bc)[k]; } } else { *notify << typeid(*c).name() << ';' ; } } } Toy::draw(cr, notify, width, height, save,timer_stream); }
// // Get all the paths corresponding to the linear components of the graph // Precondition: all vertices have in/out degree at most 1 (no branching) // PathVector Bigraph::getLinearComponents() { PathVector outPaths; setColors(GC_WHITE); VertexPtrMapIter iter = m_vertices.begin(); for(; iter != m_vertices.end(); ++iter) { // Output the linear path containing this vertex if it hasnt been visited already if(iter->second->getColor() != GC_BLACK) { outPaths.push_back(constructLinearPath(iter->second->getID())); } } assert(checkColors(GC_BLACK)); return outPaths; }
bool SGPairedPathResolveVisitor::visit(StringGraph* /*pGraph*/, Vertex* /*pVertex*/) { assert(false); #if 0 if(pVertex->getColor() == GC_BLACK) return false; // has been resolved already // Get the vertex of the pair std::string pairID = getPairID(pVertex->getID()); Vertex* pPair = pGraph->getVertex(pairID); if(pPair != NULL) { PathVector paths; // get the expected direction between the vertices based on the PE info EdgeDir dir = SGPairedAlgorithms::getDirectionToPair(pVertex->getID()); SGPairedAlgorithms::searchPaths(pVertex, pPair, dir, 300, paths); pVertex->setColor(GC_BLACK); pPair->setColor(GC_BLACK); std::cout << "Found " << paths.size() << " paths from " << pVertex->getID() << " to " << pPair->getID() << "\n"; if(paths.size() == 1) { std::string fragment = SGPairedAlgorithms::pathToString(pVertex, paths[0]); SeqRecord record; record.id = pVertex->getID(); record.seq = fragment; record.write(*m_pWriter); } else { SeqRecord recordX; recordX.id = pVertex->getID(); recordX.seq = pVertex->getSeq().toString(); recordX.write(*m_pWriter); SeqRecord recordY; recordY.id = pVertex->getID(); recordY.seq = pVertex->getSeq().toString(); recordY.write(*m_pWriter); } } #endif return false; }
void first_time(int argc, char** argv) { const char *path_b_name="star.svgd"; if (argc > 1) path_b_name = argv[1]; pv = read_svgd(path_b_name); bounds = pv.boundsExact(); if (!bounds) { std::cerr << "Empty path, aborting" << std::endl; std::exit(1); } }
/** * Clean up paths that lead nowhere and the root path. * @param source_id ID of the root node. * @param paths Paths to be cleaned up. */ void MultiCommodityFlow::CleanupPaths(NodeID source_id, PathVector &paths) { Path *source = paths[source_id]; paths[source_id] = NULL; for (PathVector::iterator i = paths.begin(); i != paths.end(); ++i) { Path *path = *i; if (path == NULL) continue; if (path->GetParent() == source) path->Detach(); while (path != source && path != NULL && path->GetFlow() == 0) { Path *parent = path->GetParent(); path->Detach(); if (path->GetNumChildren() == 0) { paths[path->GetNode()] = NULL; delete path; } path = parent; } } delete source; paths.clear(); }
std::string ContextGen::printable(const PathVector& val) { std::string res; if(val.empty()) return "(empty vector)"; else res = "(vector)"; Color col(getColorMode()); for(PathVector::const_iterator it = val.begin(); it != val.end(); ++it) { res.append(col.red("\n * ")); if(it->isNative()) res.append(col.yellow("[NATIVE] ")); else if(it->isForeign()) res.append(col.yellow("[FOREIGN] ")); else res.append(col.yellow("[NEITHER] ")); // is ok, if windows parity build and unix path with windows backend res.append(it->get()); } return res; }
Entity Serializer::parseNode(QDomElement const & domElement) { QString name = domElement.attribute(nodeNameKey, ""); PathVector components; QString path = domElement.attribute(pathKey, ""); if (!path.isEmpty()) { components = Parser::stringToPath(path); } else { QDomNodeList geometricElements = domElement.elementsByTagName(lineKey); for (int i = 0; i < geometricElements.size(); i++) { QDomElement geometricElement = geometricElements.at(i).toElement(); Line line(geometricElement); components.push_back(line.getCurve()); } geometricElements = domElement.elementsByTagName(ellipseKey); for (int i = 0; i < geometricElements.size(); i++) { QDomElement geometricElement = geometricElements.at(i).toElement(); Ellipse ellipse(geometricElement); components.push_back(ellipse.getCurve()); } geometricElements = domElement.elementsByTagName(rectangleKey); for (int i = 0; i < geometricElements.size(); i++) { QDomElement geometricElement = geometricElements.at(i).toElement(); Rectangle rectangle(geometricElement); components.push_back(rectangle.getCurve()); } } Entity entity; entity.first = name; entity.second = components; return entity; }
void BuildPackage( const std::string& FolderName, std::string FileName ) { if( FileName.empty() ) { fs::path Path( FolderName ); FileName = Path.filename().string() + ".pkg"; } AutoFile f( new OsFile( FileName, std::ios_base::out | std::ios_base::trunc ) ); PackageWriter writer( f ); PathVector Paths; fs::path Dir( FolderName ); BuildFilesList( Dir, Paths ); fs::path BasePath = Dir.is_absolute() ? Dir : fs::current_path() / FolderName; for( PathVector::const_iterator i = Paths.begin(), e = Paths.end(); i != e; ++i ) { const fs::path& RelPath = *i; const fs::path PathInPack = RelativePath( BasePath, RelPath ); LOG( "Adding %s as %s\n", RelPath.string().c_str(), PathInPack.string().c_str() ); writer.Add( RelPath, PathInPack ); } writer.Save(); LOG( "All done." ); }
bool Triggers::parseRunsElement(const XMLElement* runs) { Range<unsigned> runRange(runs->UnsignedAttribute("from"), runs->UnsignedAttribute("to")); PathVector runPaths; const XMLElement* paths = runs->FirstChildElement("path"); for (; paths; paths = paths->NextSiblingElement("path")) { const std::string name = paths->FirstChildElement("name")->GetText(); const XMLElement* pt = paths->FirstChildElement("pt"); Range<float> ptRange(pt->FloatAttribute("from"), pt->FloatAttribute("to")); const XMLElement* weightElement = paths->FirstChildElement("weight"); float weight = weightElement->FloatAttribute("value"); Trigger t { ptRange, weight }; runPaths.push_back(std::make_pair(boost::regex(name, boost::regex_constants::icase), t)); } mTriggers[runRange] = runPaths; return true; }
static void split_vec(PathVector &full_vec, PathVector &new_vec, const Path &split_path){ PathVector old_full; old_full.insert(old_full.begin(),full_vec.begin(),full_vec.end()); full_vec.erase(full_vec.begin(),full_vec.end()); for( PathVector::const_iterator path=old_full.begin() ; path!=old_full.end() ; path++ ){ if(starts_with(*path,split_path)) new_vec.push_back(*path); else full_vec.push_back(*path); } }
void first_time(int argc, char** argv) { const char *path_b_name="star.svgd"; if(argc > 1) path_b_name = argv[1]; pv = read_svgd(path_b_name); std::cout << pv.size() << "\n"; std::cout << pv[0].size() << "\n"; pv *= Translate(-pv[0].initialPoint()); Rect bounds = *pv[0].boundsExact(); std::cout << crossings_among(pv)[0].size() << "\n"; handles.push_back(&offset_handle); offset_handle.pos = bounds.midpoint() - bounds.corner(0); //bs = cleanup(pv); }
void BuildFilesList( fs::path Dir, PathVector& Elems ) { if( !fs::exists( Dir ) || !fs::is_directory( Dir ) ) { return; } for( fs::recursive_directory_iterator dir_iter( Dir ), end_iter; dir_iter != end_iter; ++dir_iter ) { if( !fs::is_regular_file( dir_iter->status() ) ) { continue; } const fs::path& p = *dir_iter; Elems.push_back( p ); } }
void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths) { typedef std::set<Tannotation *, typename Tannotation::Comparator> AnnoSet; Tedge_iterator iter(this->job); uint size = this->job.Size(); AnnoSet annos; paths.resize(size, nullptr); for (NodeID node = 0; node < size; ++node) { Tannotation *anno = new Tannotation(node, node == source_node); anno->UpdateAnnotation(); annos.insert(anno); paths[node] = anno; } while (!annos.empty()) { typename AnnoSet::iterator i = annos.begin(); Tannotation *source = *i; annos.erase(i); NodeID from = source->GetNode(); iter.SetNode(source_node, from); for (NodeID to = iter.Next(); to != INVALID_NODE; to = iter.Next()) { if (to == from) continue; // Not a real edge but a consumption sign. Edge edge = this->job[from][to]; uint capacity = edge.Capacity(); if (this->max_saturation != UINT_MAX) { capacity *= this->max_saturation; capacity /= 100; if (capacity == 0) capacity = 1; } /* punish in-between stops a little */ uint distance = DistanceMaxPlusManhattan(this->job[from].XY(), this->job[to].XY()) + 1; Tannotation *dest = static_cast<Tannotation *>(paths[to]); if (dest->IsBetter(source, capacity, capacity - edge.Flow(), distance)) { annos.erase(dest); dest->Fork(source, capacity, capacity - edge.Flow(), distance); dest->UpdateAnnotation(); annos.insert(dest); } } } }
QList<QPoint> ValidPathCreator::createPath(PathVector const & components) { if (components.size() == 0) { return QList<QPoint>(); } PathVector paths; foreach (PointVector component, components) { int j = 0; while (j < paths.size()) { if (getDistance(paths[j], component) == 0) { component = merge(paths[j], component, 0); paths.erase(paths.begin() + j); } else { j++; } } paths.push_back(component); }
int main( int argc, char* argv[] ) { std::cout << "\nImporting FACETRACER Data from Annotation Tool into SQLite3 DB " << std::endl; //----------------- program options po::positional_options_description pod; pod.add("sqldb-file",1); pod.add("imgdbname",1); pod.add("imgfolder",1); pod.add("faceindex-file",1); pod.add("facestats-file",1); pod.add("facelabel-file",1); pod.add("attribute-file",1); pod.add("clear-sqldb",1); po::options_description description("Options"); description.add_options() ("help", "produce help message") ("sqldb-file", po::value< string >(), "sql database file") ("imgdbname", po::value< string >(), "image database name") ("image-folder", po::value< string >(), "image folder") ("faceindex-file", po::value< string >(), "faceindex file (../faceindex.txt)") ("facestats-file", po::value< string >(), "facestats file (../facestats.txt)") ("facelabel-file", po::value< string >(), "facelabel file (../facelabel.txt)") ("attribute-file", po::value< string >(), "attribute file (../attribute.txt)") ("clear-sqldb", po::value< string >(), "optinal: clear sql database (default: false)") ; po::variables_map variablesMap; try { po::store(po::command_line_parser(argc, argv).options(description).positional(pod).run(), variablesMap); po::notify(variablesMap); } catch ( const boost::program_options::error& e ) { std::cerr << e.what() << std::endl; } bool showHelp = false; string sqlDBFile; if (variablesMap.count("sqldb-file")) sqlDBFile = variablesMap["sqldb-file"].as<string>(); else showHelp = true; string imgDBName; if (variablesMap.count("imgdbname")) imgDBName = variablesMap["imgdbname"].as<string>(); else showHelp = true; string imgFolder; if (variablesMap.count("image-folder")) imgFolder = variablesMap["image-folder"].as<string>(); else showHelp = true; string faceindexFile; if (variablesMap.count("faceindex-file")) faceindexFile = variablesMap["faceindex-file"].as<string>(); else showHelp = true; string facestatsFile; if (variablesMap.count("facestats-file")) facestatsFile = variablesMap["facestats-file"].as<string>(); else showHelp = true; string facelabelFile; if (variablesMap.count("facelabel-file")) facelabelFile = variablesMap["facelabel-file"].as<string>(); else showHelp = true; string attributeFile; if (variablesMap.count("attribute-file")) attributeFile = variablesMap["attribute-file"].as<string>(); else showHelp = true; string clearSqlDB; if (variablesMap.count("clear-sqldb")) clearSqlDB = variablesMap["clear-sqldb"].as<string>(); else clearSqlDB = "false"; if (variablesMap.count("help") || showHelp) { cout << description << "\n"; return 1; } std::string basePath = ""; std::cout << "-------------------------------------------------------" << std::endl; std::cout << " Config:" << std::endl; std::cout << " SQL DB Name: " << sqlDBFile << std::endl; std::cout << " Image DB Name: " << imgDBName << std::endl; std::cout << " Image Folder: " << imgFolder << std::endl; std::cout << " FaceIndex File: " << faceindexFile << std::endl; std::cout << " FaceStats File: " << facestatsFile << std::endl; std::cout << " FaceLabel File: " << facelabelFile << std::endl; std::cout << " Attribute File: " << attributeFile << std::endl; std::cout << " Optional: clear SqlDB -> " << clearSqlDB << std::endl; std::cout << " Base Path: " << basePath << std::endl; std::cout << "-------------------------------------------------------" << std::endl; //------------------ DELETE db entries from sql database if (clearSqlDB.compare("true") == 0) { cout << " \nCLEAR Sql Database " << endl; DeleteSqlEntries dsde; dsde.deleteAllSqlEntries(sqlDBFile); return 0; } else { std::cout << " \nADD data to Sql Database" << std::endl; std::string::size_type pos = sqlDBFile.find_last_of("\\/"); if (pos != std::string::npos) { basePath = sqlDBFile.substr(0,pos+1); } } //------------------ INSERT dbname INTO sql database DeleteSqlEntries dnsf; bool deleted = false; deleted = dnsf.deleteDBName(sqlDBFile, imgDBName); if (deleted == true) { dnsf.insertDBName(sqlDBFile, imgDBName); } // get all *jpg files in img file folder ImagesFromFolder iff; PathVector paths = iff.getImagesFromFolder(imgFolder, ".JPG"); if (paths.empty()) { std::cout << " FACETRACERIMPORTER -> Folderpath '" << imgFolder << "' is empty! " << std::endl; } else { iff.printFoundFiles(paths); bool available = true; for (unsigned int n = 0; n < paths.size(); ++n) { // extract faceId from path int faceId = utils::convertToInt(paths.at(n).stem().string()); FaceTracerFileReader faceTracerFileReader; std::string faceindexFileName = faceindexFile; available = faceTracerFileReader.loadFaceindex(faceId, faceindexFileName, imgFolder); std::string facestatsFileName = facestatsFile; available = faceTracerFileReader.loadFacestats(faceId, facestatsFileName); std::string facelabelFileName = facelabelFile; available = faceTracerFileReader.loadFacelabel(faceId, facelabelFileName); // faceTracerFileReader.printFaceTracerData(); // Draw landmarks to image. //faceTracerFileReader.drawFacestats(faceId); if (available == false) { std::cout << "facetrace_import::main() data for faceId('" << faceId << "') missing." << std::endl; break; } //------------------ INSERT INTO sql db SQLiteDBConnection sqlConn; if (sqlConn.open(sqlDBFile)) { int annotTypeID_FACETRACER = getAnnotTypeID(&sqlConn); // get the feature IDs from the database - matching the feature codes from the input file FeatureCoordTypes fct; fct.load(&sqlConn); //fct.debugPrint(); vector<int> featIDs; for (int i = 0; i < FaceTracerFileData::numFeaturesFileFeatureCodes; ++i) { string featCode = FaceTracerFileData::featuresFileFeatureCodes[i]; int featID = fct.getIDByCode(featCode); if (featID < 0) std::cout << "Error: No ID for feature '" << featCode << "'" << std::endl; else { featIDs.push_back(featID); } } string insertFaceSqlStmtStr = "INSERT INTO Faces(file_id,db_id) VALUES (?1,?2)"; SQLiteStmt *insertFaceSqlStmt = sqlConn.prepare(insertFaceSqlStmtStr); string insertFeatureCoordsSqlStmtStr = "INSERT INTO FeatureCoords(face_id,feature_id,x,y) VALUES (?1, ?2, ?3, ?4)"; SQLiteStmt *insertFeatureCoordsSqlStmt = sqlConn.prepare(insertFeatureCoordsSqlStmtStr); string insertImageSqlStmtStr = "INSERT INTO FaceImages(db_id,file_id,filepath,bw,width,height) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"; SQLiteStmt *insertImageSqlStmt = sqlConn.prepare(insertImageSqlStmtStr); string insertPoseSqlStmtStr = "INSERT INTO FacePose(face_id,roll,pitch,yaw,annot_type_id) VALUES (?1, ?2, ?3, ?4, ?5)"; SQLiteStmt *insertPoseSqlStmt = sqlConn.prepare(insertPoseSqlStmtStr); string insertMetaDataSqlStmtStr = "INSERT INTO FaceMetadata(face_id,sex,occluded,glasses,bw,annot_type_id) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"; SQLiteStmt *insertMetaDataSqlStmt = sqlConn.prepare(insertMetaDataSqlStmtStr); bool allOK = true; if (insertFaceSqlStmt && insertFeatureCoordsSqlStmt) { sqlConn.exec("PRAGMA synchronous = OFF;"); sqlConn.exec("BEGIN TRANSACTION;"); std::map<int, FaceTracerFileData>::iterator faceTracerIt = faceTracerFileReader.m_faceTracerDataMap.begin(); vector<std::pair<double, double> >::iterator facestatsIt = faceTracerIt->second.facestats.begin(); std::string fileName = faceTracerIt->second.faceIdFilename; insertFaceSqlStmt->reset(); insertFaceSqlStmt->bind(1,fileName); insertFaceSqlStmt->bind(2,imgDBName); allOK = allOK && (sqlConn.step(insertFaceSqlStmt) == SQLITE_DONE); if (!allOK) { break; } // get database id of inserted face int dbFaceId = sqlConn.getLastInsertRowid(); // insert image std::string filePath = (boost::filesystem::path(faceTracerIt->second.imageFoldername) / boost::filesystem::path(faceTracerIt->second.faceIdFilename)).string(); cv::Mat img = cv::imread(filePath, -1); if (!img.data) { std::cout << "Could not load image: " << filePath.c_str() << std::endl; allOK = false; } else { std::string relativeFilePath = ""; if (filePath.size() > imgFolder.size()) { relativeFilePath = filePath.substr(imgFolder.size()+1); } //db_id,file_id,filepath,bw,width,height insertImageSqlStmt->bind(1,imgDBName); insertImageSqlStmt->bind(2,fileName); insertImageSqlStmt->bind(3,relativeFilePath); insertImageSqlStmt->bind(4,img.channels() == 1); insertImageSqlStmt->bind(5,img.cols); insertImageSqlStmt->bind(6,img.rows); allOK = allOK && (sqlConn.step(insertImageSqlStmt) == SQLITE_DONE); if (!allOK) { break; } insertImageSqlStmt->reset(); } // insert features insertFeatureCoordsSqlStmt->bind(1,dbFaceId); for (unsigned int i = 0 ; facestatsIt != faceTracerIt->second.facestats.end(); ++facestatsIt, ++i) { if ( (facestatsIt->first > 0) && (facestatsIt->second > 0) ) { if (i >= featIDs.size()) { allOK = false; } if ((facestatsIt->first >= img.cols) || (facestatsIt->second >= img.rows)) { allOK = false; } insertFeatureCoordsSqlStmt->bind(2,featIDs[i]); insertFeatureCoordsSqlStmt->bind(3,static_cast<float>(facestatsIt->first)); insertFeatureCoordsSqlStmt->bind(4,static_cast<float>(facestatsIt->second)); allOK = allOK && (sqlConn.step(insertFeatureCoordsSqlStmt) == SQLITE_DONE); if (!allOK) { break; } insertFeatureCoordsSqlStmt->reset(); } } // insert pose insertPoseSqlStmt->reset(); insertPoseSqlStmt->bind(1,dbFaceId); insertPoseSqlStmt->bind(2,faceTracerIt->second.roll); insertPoseSqlStmt->bind(3,faceTracerIt->second.pitch); insertPoseSqlStmt->bind(4,faceTracerIt->second.yaw); insertPoseSqlStmt->bind(5,annotTypeID_FACETRACER); allOK = allOK && (sqlConn.step(insertPoseSqlStmt) == SQLITE_DONE); if (!allOK) { // break; } //// insert meta data //insertMetaDataSqlStmt->reset(); //insertMetaDataSqlStmt->bind(1,dbFaceId); //insertMetaDataSqlStmt->bind(2,faceTracerIt->second.sex); //insertMetaDataSqlStmt->bind(3,faceTracerIt->second.occluded); //insertMetaDataSqlStmt->bind(4,faceTracerIt->second.glasses); //insertMetaDataSqlStmt->bind(5,faceTracerIt->second.bw); //insertMetaDataSqlStmt->bind(6,annotTypeID_FACETRACER); //allOK = allOK && (sqlConn.step(insertMetaDataSqlStmt) == SQLITE_DONE); //if (!allOK) { // // break; //} if (allOK) { sqlConn.exec("COMMIT;"); std::cout << "Reading ... Inserting... File: '" << faceId << "' into Database" << std::endl; } else { sqlConn.exec("ROLLBACK TRANSACTION;"); } sqlConn.exec("PRAGMA synchronous = NORMAL;"); sqlConn.finalize(insertFaceSqlStmt); delete insertFaceSqlStmt; sqlConn.finalize(insertFeatureCoordsSqlStmt); delete insertFeatureCoordsSqlStmt; sqlConn.finalize(insertPoseSqlStmt); delete insertPoseSqlStmt; sqlConn.finalize(insertMetaDataSqlStmt); delete insertMetaDataSqlStmt; } sqlConn.close(); } else { std::cout << "failed to open sql db file ('" << sqlDBFile << "')" << std::endl; } } } std::cout << "done." << std::endl; }
static void fill_data(NXhandle handle, Data &data, PathVector &data_tree, const PrintConfig &config){ // local variables to put stuff in Path units_path; Path signal_path; PathVector attr_paths; // sort out everything for( PathVector::const_iterator path=data_tree.begin() ; path!=data_tree.end() ; path++ ){ Node end_node=*((*path).rbegin()); if(end_node.type==ATTR){ if(end_node.name=="units"){ units_path=*path; }else if(end_node.name=="signal"){ signal_path=*path; }else{ attr_paths.push_back(*path); } }else{ data.path=*path; data.name=end_node.name; //data.type=end_node.type; } } // get the attributes and fill the structure data.units=read_attr_as_string(handle,units_path,config); data.signal=read_int_attr(handle,signal_path); // get the unknown attributes for( PathVector::const_iterator path=attr_paths.begin() ; path!=attr_paths.end() ; path++ ){ string value=read_attr_as_string(handle,*path,config); string key=(*path).rbegin()->name; data.unknown[key]=value; } // ----- from here down gets the data // open up to the right place open_path(handle,data.path); // get the rank, dimensions and type if(NXgetinfo(handle,&data.rank,data.dims,&data.type)!=NX_OK){ close_path(handle,data.path); throw "NXgetinfo failed"; } // allocate space for the data if(NXmalloc(&data.data,data.rank,data.dims,data.type)!=NX_OK){ close_path(handle,data.path); throw "NXmalloc failed"; } // retrieve the data from the file if(NXgetdata(handle,data.data)!=NX_OK){ close_path(handle,data.path); throw "NXgetdata failed"; } // close the path close_path(handle,data.path); }
void Algorithm::findPath(const Location& start, const Location& end, PathVector& output) { NodeMap l_open; NodeMap l_closed; std::priority_queue<Node> l_priority; // Create Start Node Location origin; Node startNode(start, 0, 0, origin); // Add start to priority queue and open set l_priority.push(startNode); l_open[start] = startNode; while (!l_priority.empty()) { Node l_current = l_priority.top(); l_priority.pop(); l_open.erase(l_current.location); l_closed[l_current.location] = l_current; // Check whether this is the target node if (l_current.location == end) { Location current = l_current.location; while (current != start) { // output.push_back (index); output.insert(output.begin(), current); NodeMapIter open_iter = l_closed.find(current); current = open_iter->second.origin; if (current.x == UINT_MAX) break; } return; } // Process neighbours Location* neighbours = new Location[m_numNeighbours]; unsigned int validNeighbours = m_neighbourFunction(l_current.location, neighbours, m_customData); for (size_t ii = 0; ii < validNeighbours; ii++) { // TODO: not needed? if (neighbours[ii] < 0) continue; // Not a // valid neighbour int cost = m_costFunction(neighbours[ii], m_customData); // If cost is -ve, we will close the node unsigned int path = l_current.distance + cost; unsigned int priority = path + m_distanceFunction(neighbours[ii], end, m_customData) + 1; Node neighbour(neighbours[ii], path, priority, l_current.location); // Is it closed? NodeMapIter closed_iter = l_closed.find(neighbours[ii]); if (closed_iter != l_closed.end()) { // But dow we now have a better path? if (cost > 0 && path < closed_iter->second.distance) { l_closed.erase(closed_iter); } else { continue; // It's closed and there's no better path } } NodeMapIter open_iter = l_open.find(neighbours[ii]); if (open_iter != l_open.end()) { // Remove it from open if there's a better path now l_open.erase(open_iter); } else if (cost >= 0) { // Neighbour not in open l_open[neighbours[ii]] = neighbour; l_priority.push(neighbour); } } delete[] neighbours; } }
int main( int argc, char* argv[] ) { std::cout << "\nImporting PUT Data from Annotation Tool into SQLite3 DB " << std::endl; //----------------- program options po::positional_options_description pod; pod.add("sqldb-file",1); pod.add("imgdbname",1); pod.add("image-dir",1); pod.add("landmarks-dir",1); pod.add("regions-dir",1); pod.add("clear-sqldb",1); po::options_description description("Options"); description.add_options() ("help", "produce help message") ("sqldb-file", po::value< string >(), "sql database file") ("imgdbname", po::value< string >(), "image database name") ("image-dir", po::value< string >(), "image file path (../Images/XXXX/xxxxxxxx.jpg)") ("landmarks-dir", po::value< string >(), "landmarks file path (../LXXX/xxxxxxxx.yml)") ("regions-dir", po::value< string >(), "regions file path (../RXXX/xxxxxxxx.yml)") ("clear-sqldb", po::value< string >(), "optinal: clear sql database (default: false)") ; po::variables_map variablesMap; try { po::store(po::command_line_parser(argc, argv).options(description).positional(pod).run(), variablesMap); po::notify(variablesMap); } catch ( const boost::program_options::error& e ) { std::cerr << e.what() << std::endl; } bool showHelp = false; string sqlDBFile; if (variablesMap.count("sqldb-file")) sqlDBFile = variablesMap["sqldb-file"].as<string>(); else showHelp = true; string imgDBName; if (variablesMap.count("imgdbname")) imgDBName = variablesMap["imgdbname"].as<string>(); else showHelp = true; string imgDir; if (variablesMap.count("image-dir")) imgDir = variablesMap["image-dir"].as<string>(); else showHelp = true; string landmarksDir; if (variablesMap.count("landmarks-dir")) landmarksDir = variablesMap["landmarks-dir"].as<string>(); else showHelp = true; string regionsDir; if (variablesMap.count("regions-dir")) regionsDir = variablesMap["regions-dir"].as<string>(); else showHelp = true; string clearSqlDB; if (variablesMap.count("clear-sqldb")) clearSqlDB = variablesMap["clear-sqldb"].as<string>(); else clearSqlDB = "false"; if (variablesMap.count("help") || showHelp) { cout << description << "\n"; return 1; } std::string basePath = ""; std::cout << "-------------------------------------------------------" << std::endl; std::cout << " Config:" << std::endl; std::cout << " SQL DB Name: " << sqlDBFile << std::endl; std::cout << " Image DB Name: " << imgDBName << std::endl; std::cout << " Image Folder: " << imgDir << std::endl; std::cout << " Landmarks Folder:" << landmarksDir << std::endl; std::cout << " Regions Folder: " << regionsDir << std::endl; std::cout << " Optional: clear SqlDB -> " << clearSqlDB << std::endl; std::cout << " Base Path: " << basePath << std::endl; std::cout << "-------------------------------------------------------" << std::endl; //------------------ DELETE db entries from sql database if (clearSqlDB.compare("true") == 0) { cout << " \nCLEAR Sql Database " << endl; DeleteSqlEntries dsde; dsde.deleteAllSqlEntries(sqlDBFile); return 0; } else { std::cout << " \nADD data to Sql Database" << std::endl; std::string::size_type pos = sqlDBFile.find_last_of("\\/"); if (pos != std::string::npos) { basePath = sqlDBFile.substr(0,pos+1); } } //------------------ INSERT dbname INTO sql database DeleteSqlEntries dnsf; bool deleted = false; deleted = dnsf.deleteDBName(sqlDBFile, imgDBName); if (deleted == true) { dnsf.insertDBName(sqlDBFile, imgDBName); } // get all *jpg files from img file folder ImagesFromFolder iff; // PathVector paths = iff.getImagesFromFolder(imgDir + "\\0" + folderName, ".JPG"); // paths.clear(); PathVector pathImages = iff.getFilesFromFolderStruct(imgDir, ".JPG"); iff.clearPathVector(); PathVector pathLandmarks = iff.getFilesFromFolderStruct(landmarksDir, ".YML"); iff.clearPathVector(); if (pathImages.empty()) { std::cout << " PUTIMPORTER -> Warning: NO Files in Folderpath '" << imgDir << "' found! " << std::endl; } else if (pathLandmarks.empty()) { std::cout << " PUTIMPORTER -> Warning: NO Files in Folderpath '" << landmarksDir << "' found! " << std::endl; } else { // iff.printFoundFiles(paths); // iff.printFoundFiles(pathLandmarks); PutFileReader putFileReader; // first read all images for (unsigned int n = 0; n < pathImages.size(); ++n) { std::string imgFileName = pathImages.at(n).string(); putFileReader.loadImage(imgFileName); std::cout << " Insert '" << imgFileName << "' into putFileReader structure. " << std::endl; } // second add landmarks to images (if no images available ignore landmark) for (unsigned int n = 0; n < pathLandmarks.size(); ++n) { std: string landmarksFileName = pathLandmarks.at(n).string(); putFileReader.loadLandmarks(landmarksFileName); std::cout << " Insert '" << landmarksFileName << "' into putFileReader structure. " << std::endl; } // insert all images into sql database std::map<int, PutFileData>::iterator putIt = putFileReader.m_putDataMap.begin(); for (; putIt != putFileReader.m_putDataMap.end(); ++putIt) { //putFileReader.printPutData(); // Draw landmarks to image. //putFileReader.drawLandmarks(); //------------------ INSERT INTO sql db SQLiteDBConnection sqlConn; if (sqlConn.open(sqlDBFile)) { //int annotTypeID_PUT= getAnnotTypeID(&sqlConn); // get the feature IDs from the database - matching the feature codes from the input file FeatureCoordTypes fct; fct.load(&sqlConn); //fct.debugPrint(); vector<int> featIDs; for (int i = 0; i < PutFileData::numFeaturesFileFeatureCodes; ++i) { string featCode = PutFileData::featuresFileFeatureCodes[i]; int featID = fct.getIDByCode(featCode); if (featID < 0) std::cout << "Error: No ID for feature '" << featCode << "'" << std::endl; else { featIDs.push_back(featID); } } string insertFaceSqlStmtStr = "INSERT INTO Faces(file_id,db_id) VALUES (?1,?2)"; SQLiteStmt *insertFaceSqlStmt = sqlConn.prepare(insertFaceSqlStmtStr); string insertFeatureCoordsSqlStmtStr = "INSERT INTO FeatureCoords(face_id,feature_id,x,y) VALUES (?1, ?2, ?3, ?4)"; SQLiteStmt *insertFeatureCoordsSqlStmt = sqlConn.prepare(insertFeatureCoordsSqlStmtStr); string insertImageSqlStmtStr = "INSERT INTO FaceImages(db_id,file_id,filepath,bw,width,height) VALUES (?1, ?2, ?3, ?4, ?5, ?6)"; SQLiteStmt *insertImageSqlStmt = sqlConn.prepare(insertImageSqlStmtStr); bool allOK = true; if (insertFaceSqlStmt && insertFeatureCoordsSqlStmt) { sqlConn.exec("PRAGMA synchronous = OFF;"); sqlConn.exec("BEGIN TRANSACTION;"); vector<std::pair<double, double> >::iterator landmarksIt = putIt->second.landmarks.begin(); if (landmarksIt == putIt->second.landmarks.end()) { std::cout << " NO Landmarks for Image: " << putIt->second.imgFilename << " found." << std::endl; allOK = false; } // extract fileName and filePath std::string fileName = ""; std::string filePath = putIt->second.imgFilename; std::string::size_type pos = filePath.find_last_of("\\"); if (pos != std::string::npos) { fileName = filePath.substr(pos+1); pos = filePath.find("\\"); // find first space while ( pos != string::npos ) { filePath.replace( pos, 1, "/" ); pos = filePath.find( "\\", pos + 1 ); } } insertFaceSqlStmt->reset(); insertFaceSqlStmt->bind(1,fileName); insertFaceSqlStmt->bind(2,imgDBName); allOK = allOK && (sqlConn.step(insertFaceSqlStmt) == SQLITE_DONE); // get database id of inserted face int face_id = sqlConn.getLastInsertRowid(); // insert features insertFeatureCoordsSqlStmt->bind(1,face_id); for (unsigned int i = 0 ; landmarksIt != putIt->second.landmarks.end(); ++landmarksIt, ++i) { if ( (landmarksIt->first > 0) && (landmarksIt->second > 0) ) { if (i >= featIDs.size()) { break; } insertFeatureCoordsSqlStmt->bind(2,featIDs[i]); insertFeatureCoordsSqlStmt->bind(3,static_cast<float>(landmarksIt->first)); insertFeatureCoordsSqlStmt->bind(4,static_cast<float>(landmarksIt->second)); allOK = allOK && (sqlConn.step(insertFeatureCoordsSqlStmt) == SQLITE_DONE); if (!allOK) { break; } insertFeatureCoordsSqlStmt->reset(); } } // insert image std::string totalFileName = filePath; fs::path tmppath(totalFileName); totalFileName = tmppath.relative_path().string(); cv::Mat img = cv::imread(tmppath.string(),-1); if (img.empty()) { std::cout << "Error: Could not load Image: '" << totalFileName << "'" << std::endl; allOK = false; } else { std::string relativeFilePath = ""; if (filePath.size() > imgDir.size()) { relativeFilePath = filePath.substr(imgDir.size()+1); } //db_id,file_id,filepath,bw,width,height insertImageSqlStmt->bind(1,imgDBName); insertImageSqlStmt->bind(2,fileName); insertImageSqlStmt->bind(3,relativeFilePath); insertImageSqlStmt->bind(4,img.channels() == 1); insertImageSqlStmt->bind(5,img.cols); insertImageSqlStmt->bind(6,img.rows); allOK = allOK && (sqlConn.step(insertImageSqlStmt) == SQLITE_DONE); insertImageSqlStmt->reset(); } if (allOK) { sqlConn.exec("COMMIT;"); std::cout << "Reading ... Inserting... File: '" << putIt->second.filenumber << "' into Database" << std::endl; } else { sqlConn.exec("ROLLBACK TRANSACTION;"); } sqlConn.exec("PRAGMA synchronous = NORMAL;"); sqlConn.finalize(insertFaceSqlStmt); delete insertFaceSqlStmt; sqlConn.finalize(insertFeatureCoordsSqlStmt); delete insertFeatureCoordsSqlStmt; } sqlConn.close(); } else { std::cout << "failed to open sql db file '" << sqlDBFile << "'" << std::endl; } } } std::cout << "done." << std::endl; }
void ContextGen::convert(PathVector& target, const std::string& ref) { target.push_back(ref); }
static void fill_axis(NXhandle handle, Axis &axis, PathVector &tree, const PrintConfig &config){ axis.name=(axis.path.rbegin())->name; axis.type=-1; axis.dims[0]=-1; Path units_path; Path primary_path; Path axis_path; PathVector attr_paths; // sort out everything for( PathVector::const_iterator path=tree.begin() ; path!=tree.end() ; path++ ){ Node end_node=*((*path).rbegin()); if(end_node.type==ATTR){ if(end_node.name=="units"){ units_path=*path; }else if(end_node.name=="primary"){ primary_path=*path; }else if(end_node.name=="axis"){ axis_path=*path; }else{ attr_paths.push_back(*path); } } } // get the attributes and fill the structure if(units_path.size()>0) axis.units=read_attr_as_string(handle,units_path,config); if(axis_path.size()>0) axis.axis=read_int_attr(handle,axis_path); if(primary_path.size()>0) axis.primary=read_int_attr(handle,primary_path); else axis.primary=-1; // get the unknown attributes for( PathVector::const_iterator path=attr_paths.begin() ; path!=attr_paths.end() ; path++ ){ string value=read_attr_as_string(handle,*path,config); string key=(*path).rbegin()->name; axis.unknown[key]=value; } // -- from here down gets the data open_path(handle,axis.path); // get the rank, dimensions and type int rank; if(NXgetinfo(handle,&rank,axis.dims,&axis.type)!=NX_OK){ close_path(handle,axis.path); throw "NXgetinfo failed"; } if(rank>1){ close_path(handle,axis.path); throw "RANK>1"; } // allocate space for the data if(NXmalloc(&axis.data,rank,axis.dims,axis.type)!=NX_OK){ close_path(handle,axis.path); throw "NXmalloc failed"; } // retrieve the data from the file if(NXgetdata(handle,axis.data)!=NX_OK){ close_path(handle,axis.path); throw "NXgetdata failed"; } // close the path close_path(handle,axis.path); }