/** \brief This function constructs a heuristic coloring for the graph and returns the number of colors */ size_t compute_coloring() { // Reset the colors #pragma omp parallel for for(int v = 0; v < (int)num_vertices(); ++v) set_color(v, 0); // Recolor size_t max_color = 0; std::set<vertex_color_type> neighbor_colors; for(vertex_id_type vid = 0; vid < num_vertices(); ++vid) { neighbor_colors.clear(); // Get the neighbor colors foreach(vertex_id_type neighbor_vid, in_vertices(vid)){ const vertex_color_type& neighbor_color = get_color(neighbor_vid); neighbor_colors.insert(neighbor_color); } foreach(vertex_id_type neighbor_vid, out_vertices(vid)){ const vertex_color_type& neighbor_color = get_color(neighbor_vid); neighbor_colors.insert(neighbor_color); } vertex_color_type vertex_color = 0; foreach(vertex_color_type neighbor_color, neighbor_colors) { if(vertex_color != neighbor_color) break; else vertex_color++; // Ensure no wrap around ASSERT_NE(vertex_color, 0); } set_color(vid, vertex_color); max_color = std::max(max_color, size_t(vertex_color) ); } // Return the NUMBER of colors propagate_coloring(); ncolors = max_color + 1; return max_color + 1; }
void indexVBO(std::vector<natVec3<>>& vertices, std::vector<natVec2<>>& uvs, std::vector<natVec3<>>& normals, std::vector<unsigned short>& out_indices) { out_indices.clear(); std::vector<natVec3<>> out_vertices(vertices); std::vector<natVec2<>> out_uvs(uvs); std::vector<natVec3<>> out_normals(normals); std::map<PackedVertex, nuShort> VertexToOutIndex; nuInt count = static_cast<nuInt>(std::min({ vertices.size(), uvs.size(), normals.size() })); for (nuInt i = 0u; i < count; ++i) { PackedVertex packed = { vertices[i], uvs[i], normals[i] }; // Try to find a similar vertex in out_XXXX nuShort index; if (getSimilarVertexIndex(packed, VertexToOutIndex, index)) { // A similar vertex is already in the VBO, use it instead ! out_indices.push_back(index); } else { // If not, it needs to be added in the output data. out_vertices.push_back(vertices[i]); out_uvs.push_back(uvs[i]); out_normals.push_back(normals[i]); unsigned short newindex = static_cast<unsigned short>(out_vertices.size()) - 1; out_indices.push_back(newindex); VertexToOutIndex[packed] = newindex; } } /*vertices.swap(out_vertices); uvs.swap(out_uvs); normals.swap(out_normals);*/ vertices.assign(out_vertices.begin(), out_vertices.end()); uvs.assign(out_uvs.begin(), out_uvs.end()); normals.assign(out_normals.begin(), out_normals.end()); }