void verifyMatching(BipartiteGraph g, unsigned expectedSize) { Matching matching = findMaximumMatching(g); typedef boost::unordered_set<unsigned> VertexSet; VertexSet first; VertexSet second; for (auto elem : matching) { ASSERT_TRUE(first.insert(elem.first).second); ASSERT_TRUE(second.insert(elem.second).second); ASSERT_TRUE(g.edgeExists(elem)); } ASSERT_EQ(expectedSize, matching.size()); }
size_t load_transactions_from_binary(string& data, VertexTransactions& transactions, VertexSet& bad_vertices) { char* bytearray = (char*) data.c_str(); size_t byte_pos = 0; // get number of transactions uint64* num_transactions = (uint64 *)(bytearray); byte_pos += 8; // get vertex / transaction list for (int i = 0; i < int(*num_transactions); ++i) { VertexID* vertex_id = (VertexID *)(bytearray+byte_pos); byte_pos += 8; TransactionID* transaction_id = (TransactionID *)(bytearray+byte_pos); byte_pos += 8; transactions[*vertex_id] = *transaction_id; } // find failed transactions uint64* num_failed_transactions = (uint64*)(bytearray+byte_pos); byte_pos += 8; for (int i = 0; i < int(*num_failed_transactions); ++i) { VertexID* vertex_id = (VertexID *)(bytearray+byte_pos); byte_pos += 8; bad_vertices.insert(*vertex_id); } // byte position indicates the location of the rest of the binary payload return byte_pos; }
PoseGraph::VertexSet PoseGraph::allVertices () const { VertexSet nodes; BOOST_FOREACH (const VertexMap::value_type& e, _vertexMap) nodes.insert(e.first); return nodes; }
void used_vertices(const Graph& graph, VertexSet& vertex_set) { typedef boost::graph_traits <Graph> traits; typename traits::edge_iterator edge_iter, edge_end; for (boost::tie(edge_iter, edge_end) = boost::edges(graph); edge_iter != edge_end; ++edge_iter) { vertex_set.insert(boost::source(*edge_iter, graph)); vertex_set.insert(boost::target(*edge_iter, graph)); } }
bool Decompress( const std::vector<unsigned int>& indices, const std::vector<unsigned int>& normalIndices, const std::vector<unsigned int>& textureIndices, const std::vector<Vector3f>& vertices, const std::vector<Vector3f>& normals, const std::vector<Vector3f>& textureCoords, const std::vector<Vector4f>& tangents, std::vector<Vertex>& outVertices, std::vector<TriangleFace>& outFaces ) { VertexSet vertexSet; unsigned int triangleCount = static_cast<unsigned int>(indices.size()) / TRIANGLE_EDGE_COUNT; unsigned int index = 0; unsigned int freeIndex = 0; Vector3f v1, v2, v3; Vector3f n1, n2, n3; Vector3f t1, t2, t3; TriangleFace face; Vertex v; for ( unsigned int i = 0; i < triangleCount; i++ ) { unsigned int vIndex, nIndex, tIndex; for ( unsigned int j = 0; j < TRIANGLE_EDGE_COUNT; j++ ) { vIndex = indices[index + j]; nIndex = normalIndices[index + j]; tIndex = textureIndices[index + j]; v.position = vertices[vIndex]; v.normal = normals[nIndex]; v.textureCoord = textureCoords[tIndex]; VertexSet::const_iterator it = vertexSet.find(v); if ( it != vertexSet.end() ) { face.indices[j] = vertexSet.find(v)->second; } else { vertexSet.insert(std::make_pair(v, freeIndex)); face.indices[j] = freeIndex; outVertices.push_back(v); freeIndex++; } } outFaces.push_back(face); index += TRIANGLE_EDGE_COUNT; } return true; }
void Map(const MatchSet* match, string& key, string& match_signature, VertexSet& vertex_set) { stringstream strm; for (vector<uint64_t>::iterator it = group_by_vertices__.begin(); it != group_by_vertices__.end(); it++) { strm << "_" << match->GetMatch(*it); } key = strm.str(); stringstream strm1; for (int i = 0, N = match->NumVertices(); i < N; i++) { int i_match = match->vertex_map[i].second; vertex_set.insert(i_match); strm1 << "_" << i_match; } match_signature = strm1.str(); return; }
/** * Main function. * * Usage: VtkToFld session.xml input.vtk output.fld [options] */ int main(int argc, char* argv[]) { // Set up available options po::options_description desc("Available options"); desc.add_options() ("help,h", "Produce this help message.") ("name,n", po::value<string>()->default_value("Intensity"), "Name of field in VTK file to use for intensity.") ("outname,m", po::value<string>()->default_value("intensity"), "Name of field in output FLD file.") ("precision,p", po::value<double>()->default_value(1), "Precision of vertex matching."); po::options_description hidden("Hidden options"); hidden.add_options() ("file", po::value<vector<string> >(), "Input filename"); po::options_description cmdline_options; cmdline_options.add(desc).add(hidden); po::positional_options_description p; p.add("file", -1); po::variables_map vm; // Parse command-line options try { po::store(po::command_line_parser(argc, argv). options(cmdline_options).positional(p).run(), vm); po::notify(vm); } catch (const std::exception& e) { cerr << e.what() << endl; cerr << desc; return 1; } if ( vm.count("help") || vm.count("file") == 0 || vm["file"].as<vector<string> >().size() != 3) { cerr << "Usage: VtkToFld session.xml intensity.vtk output.fld [options]" << endl; cerr << desc; return 1; } // Extract command-line argument values std::vector<std::string> vFiles = vm["file"].as<vector<string> >(); const string infile = vFiles[1]; const string outfile = vFiles[2]; const double factor = vm["precision"].as<double>(); const string name = vm["name"].as<string>(); const string outname = vm["outname"].as<string>(); std::vector<std::string> vFilenames; LibUtilities::SessionReaderSharedPtr vSession; SpatialDomains::MeshGraphSharedPtr graph2D; MultiRegions::ExpList2DSharedPtr Exp; vFilenames.push_back(vFiles[0]); vSession = LibUtilities::SessionReader::CreateInstance(2, argv, vFilenames); try { //---------------------------------------------- // Read in mesh from input file graph2D = MemoryManager<SpatialDomains::MeshGraph2D>:: AllocateSharedPtr(vSession); //---------------------------------------------- //---------------------------------------------- // Define Expansion Exp = MemoryManager<MultiRegions::ExpList2D>:: AllocateSharedPtr(vSession,graph2D); //---------------------------------------------- //---------------------------------------------- // Set up coordinates of mesh int coordim = Exp->GetCoordim(0); int nq = Exp->GetNpoints(); Array<OneD, NekDouble> xc0(nq,0.0); Array<OneD, NekDouble> xc1(nq,0.0); Array<OneD, NekDouble> xc2(nq,0.0); switch(coordim) { case 2: Exp->GetCoords(xc0,xc1); break; case 3: Exp->GetCoords(xc0,xc1,xc2); break; default: ASSERTL0(false,"Coordim not valid"); break; } //---------------------------------------------- vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New(); vtkMeshReader->SetFileName(infile.c_str()); vtkMeshReader->Update(); vtkPolyData *vtkMesh = vtkMeshReader->GetOutput(); vtkCellDataToPointData* c2p = vtkCellDataToPointData::New(); #if VTK_MAJOR_VERSION <= 5 c2p->SetInput(vtkMesh); #else c2p->SetInputData(vtkMesh); #endif c2p->PassCellDataOn(); c2p->Update(); vtkPolyData *vtkDataAtPoints = c2p->GetPolyDataOutput(); vtkPoints *vtkPoints = vtkMesh->GetPoints(); ASSERTL0(vtkPoints, "ERROR: cannot get points from mesh."); vtkCellArray *vtkPolys = vtkMesh->GetPolys(); ASSERTL0(vtkPolys, "ERROR: cannot get polygons from mesh."); vtkPointData *vtkPData = vtkDataAtPoints->GetPointData(); ASSERTL0(vtkPolys, "ERROR: cannot get point data from file."); VertexSet points; VertexSet::iterator vIter; double p[3]; double val; double x, y, z; int coeff_idx; int i,j,n; if (!vtkDataAtPoints->GetPointData()->HasArray(name.c_str())) { n = vtkDataAtPoints->GetPointData()->GetNumberOfArrays(); cerr << "Input file '" << infile << "' does not have a field named '" << name << "'" << endl; cerr << "There are " << n << " arrays in this file." << endl; for (int i = 0; i < n; ++i) { cerr << " " << vtkDataAtPoints->GetPointData()->GetArray(i)->GetName() << endl; } return 1; } // Build up an unordered set of vertices from the VTK file. For each // vertex a hashed value of the coordinates is generated to within a // given tolerance. n = vtkPoints->GetNumberOfPoints(); for (i = 0; i < n; ++i) { vtkPoints->GetPoint(i,p); val = vtkPData->GetScalars(name.c_str())->GetTuple1(i); boost::shared_ptr<Vertex> v(new Vertex(p[0],p[1],p[2],val,factor)); points.insert(v); } // Now process each vertex of each element in the mesh SpatialDomains::PointGeomSharedPtr vert; for (i = 0; i < Exp->GetNumElmts(); ++i) { StdRegions::StdExpansionSharedPtr e = Exp->GetExp(i); for (j = 0; j < e->GetNverts(); ++j) { // Get the index of the coefficient corresponding to this vertex coeff_idx = Exp->GetCoeff_Offset(i) + e->GetVertexMap(j); // Get the coordinates of the vertex vert = e->as<LocalRegions::Expansion2D>()->GetGeom2D() ->GetVertex(j); vert->GetCoords(x,y,z); // Look up the vertex in the VertexSet boost::shared_ptr<Vertex> v(new Vertex(x,y,z,0.0,factor)); vIter = points.find(v); // If not found, maybe the tolerance should be reduced? // If found, record the scalar value from the VTK file in the // corresponding coefficient. if (vIter == points.end()) { cerr << "Vertex " << i << " not found. Looking for (" << x << ", " << y << ", " << z << ")" << endl; } else { Exp->UpdateCoeffs()[coeff_idx] = (*vIter)->scalar; } } } Exp->SetPhysState(false); //----------------------------------------------- // Write solution to file std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef = Exp->GetFieldDefinitions(); std::vector<std::vector<NekDouble> > FieldData(FieldDef.size()); for(i = 0; i < FieldDef.size(); ++i) { FieldDef[i]->m_fields.push_back(outname); Exp->AppendFieldData(FieldDef[i], FieldData[i]); } LibUtilities::FieldIO vFld(vSession->GetComm()); vFld.Write(outfile, FieldDef, FieldData); //----------------------------------------------- } catch (...) { cout << "An error occurred." << endl; } }
void Atoms::ComputeAtoms() { // Get minimal triangulation EliminationOrder* eo = new EliminationOrder(G_); FillEdges* F = new FillEdges(G_); VertexList* minsep_generators = new VertexList(); MCSmPlus::Run(*G_, eo, F, minsep_generators); std::list< VertexSet* > vertices_of_atoms; SeparatorComponents cc(G_); Vertices deleted_vertices; // in paper, this is V(G_) - V(G_') std::vector< bool > is_deleted(G_->order(), false); // Examine minsep_generators, eo-earliest first for (int i : *minsep_generators) { // Check to see if minimal separator is a clique Vertex v = eo->VertexAt(i); Vertices S; for (Vertex u : G_->N(v)) { if (eo->Before(v, u) && !is_deleted[u]) { S.push_back(u); } } for (Vertex u : (*F)[v]) { if (eo->Before(v, u) && !is_deleted[u]) { S.push_back(u); } } if (G_->IsClique(S)) { clique_minimal_separators_.Insert(S); for (Vertex u : deleted_vertices) { S.push_back(u); } cc.Separate(S); Vertices C = cc.ConnectedComponent(v); VertexSet* atom = new VertexSet(); for (Vertex u : C) { if (!is_deleted[u]) { deleted_vertices.push_back(u); is_deleted[u] = true; atom->insert(u); } } for (Vertex u : S) { if (!is_deleted[u]) { atom->insert(u); } } vertices_of_atoms.push_back(atom); } } // Remaining vertices form an atom Vertices C; for (Vertex v : *G_) { if (!is_deleted[v]) { C.push_back(v); } } if (!C.empty()) { VertexSet* atom = new VertexSet(); for (Vertex v : C) { atom->insert(v); } vertices_of_atoms.push_back(atom); } for (VertexSet* U : vertices_of_atoms) { atom_subgraphs_.push_back(new InducedSubgraph(G_, *U)); delete U; } delete eo; delete F; delete minsep_generators; return; }