/*! * Export surface tasselation to DGF file * * \param[in] dgf_name name of dgf file * * \result on output returns an error flag for I/O error */ unsigned short SurfUnstructured::exportDGF(const string &dgf_name) { // ====================================================================== // // VARIABLES DECLARATION // // ====================================================================== // // Local variables DGFObj dgf_in(dgf_name); int nV = getVertexCount(), nS = getCellCount(); int v, nv; long vcount, ccount, idx; std::vector<std::array<double, 3>> vertex_list(nV); std::vector<std::vector<int>> simplex_list(nS); std::unordered_map<long, long> vertex_map; // Counters VertexIterator v_, ve_; CellIterator c_, ce_; // ====================================================================== // // EXPORT DATA // // ====================================================================== // // Create vertex list ve_ = vertexEnd(); vcount = 0; for (v_ = vertexBegin(); v_ != ve_; ++v_) { idx = v_->getId(); vertex_list[vcount] = v_->getCoords(); vertex_map[idx] = vcount; ++vcount; } //next v_ // Add cells ce_ = cellEnd(); ccount = 0; for (c_ = cellBegin(); c_ != ce_; ++c_) { nv = c_->getVertexCount(); simplex_list[ccount].resize(nv); for (v = 0; v < nv; ++v) { simplex_list[ccount][v] = vertex_map[c_->getVertex(v)]; } //next v ++ccount; } //next c_ // Read vertices and cells from DGF file dgf_in.save(nV, nS, vertex_list, simplex_list); return 0; }
void TriangleMesh::updateAllVertices() { VertexIterator vitr = vertexBegin(); VertexIterator end = vertexEnd(); for(; vitr != end; ++vitr) updateVertex(**vitr); }
/*! * Export surface tasselation in a STL format. No check is perfomed on element type * therefore tasselation containing vertex, line or quad elements will produce * ill-formed stl triangulation. * * \param[in] stl_name name of the stl file * \param[in] isBinary flag for binary (true) or ASCII (false) file * \param[in] exportInternalsOnly flag for exporting only internal cells (true), * or internal+ghost cells (false). * * \result on output returns an error flag for I/O error. */ unsigned short SurfUnstructured::exportSTL(const string &stl_name, const bool &isBinary, bool exportInternalsOnly) { // ====================================================================== // // VARIABLES DECLARATION // // ====================================================================== // // Local variables int nVertex; int nSimplex; vector<array<double, 3>> vertexList; vector<array<double, 3>> normalList; vector<vector<int>> connectivityList; unordered_map<long, long> vertexMap; // Counters int v_count ,j; vector<array<double, 3>>::iterator i_; vector<vector<int>>::iterator j_; vector<int>::iterator k_, ke_; VertexIterator v_, ve_; CellIterator c_, cb_, ce_; // ====================================================================== // // INITIALIZE DATA STRUCTURE // // ====================================================================== // nSimplex = m_nInternals; if (!exportInternalsOnly) nSimplex += m_nGhosts; vertexList.resize(getVertexCount()); normalList.resize(nSimplex); connectivityList.resize(nSimplex, vector<int>(3, 0)); // ====================================================================== // // CREATE VERTEX LIST // // ====================================================================== // i_ = vertexList.begin(); ve_ = vertexEnd(); v_count = 0; for (v_ = vertexBegin(); v_ != ve_; ++v_) { // Store vertex coordinates *i_ = v_->getCoords(); vertexMap[v_->getId()] = v_count; // Update counters ++v_count; ++i_; } //next v_ nVertex = getVertexCount(); // ====================================================================== // // CREATE CONNECTIVITY // // ====================================================================== // if (exportInternalsOnly) { cb_ = internalBegin(); ce_ = internalEnd(); } else { cb_ = cellBegin(); ce_ = cellEnd(); } i_ = normalList.begin(); j_ = connectivityList.begin(); for (c_ = cb_; c_ != ce_; ++c_) { // Build normals *i_ = std::move(evalFacetNormal(c_->getId())); // Build connectivity ke_ = j_->end(); j = 0; for (k_ = j_->begin(); k_ != ke_; ++k_) { *k_ = vertexMap[c_->getVertex(j)]; ++j; } //next k_ // Update counters ++j_; ++i_; } //next c_ // ====================================================================== // // EXPORT STL DATA // // ====================================================================== // STLObj STL(stl_name, isBinary); STL.save("", nVertex, nSimplex, vertexList, normalList, connectivityList); return 0; }
/*! * Extract the edge network from surface mesh. If adjacencies are not built * edges shared by more than 1 element are counted twice. Edges are appended * to the content of the input SurfUnstructured * * \param[in,out] net on output stores the network of edges */ void SurfUnstructured::extractEdgeNetwork(SurfUnstructured &net) { // ====================================================================== // // VARIABLES DECLARATION // // ====================================================================== // // Local variables bool check; int n_faces, n_adj, n_vert; long id; vector<int> face_loc_connect; vector<long> face_connect; // Counters int i, j; vector<int>::const_iterator i_; vector<long>::iterator j_; VertexIterator v_, ve_ = vertexEnd(); CellIterator c_, ce_ = cellEnd(); // ====================================================================== // // INITIALIZE DATA STRUCTURE // // ====================================================================== // net.reserveCells(net.getCellCount() + countFaces()); net.reserveVertices(net.getVertexCount() + getVertexCount()); // ====================================================================== // // ADD VERTEX TO net // // ====================================================================== // for (v_ = vertexBegin(); v_ != ve_; ++v_) { net.addVertex(v_->getCoords(), v_->getId()); } //next v_ // ====================================================================== // // ADD EDGES // // ====================================================================== // for (c_ = cellBegin(); c_ != ce_; ++c_) { id = c_->getId(); n_faces = c_->getFaceCount(); for (i = 0; i < n_faces; ++i) { check = true; n_adj = c_->getAdjacencyCount(i); for (j = 0; j < n_adj; ++j) { check = check && (id > c_->getAdjacency(i, j)); } //next j if (check) { face_loc_connect = c_->getFaceLocalConnect(i); n_vert = face_loc_connect.size(); face_connect.resize(n_vert); j_ = face_connect.begin(); for (i_ = face_loc_connect.cbegin(); i_ != face_loc_connect.cend(); ++i_) { *j_ = c_->getVertex(*i_); ++j_; } //next i_ net.addCell(c_->getFaceType(i), true, face_connect); } } //next i } //next c_ return; }