コード例 #1
0
Mesh_Ptr Mesh_File_Reader::read(
    const Label & name,
    bool load_vertices,
    bool load_triangles,
    bool load_triangle_strips,
    bool load_mapping
)  /* throw IO_Error */
{
    Mesh_Ptr mesh_ptr(new Mesh());
    Mesh &mesh = *mesh_ptr.get();
    
    Filename binary_filename(_mesh_path / (name + ".bin"));    
    if(!boost::filesystem::exists(binary_filename)) 
    {
        Filename vertex_filename, triangle_filename, 
            triangle_strip_filename, mapping_filename;
        if (load_vertices)
            vertex_filename = _mesh_path / (name + ".vert");
        if (load_triangles)
            triangle_filename = _mesh_path / (name + ".tri");
        if (load_triangle_strips)
            triangle_strip_filename = _mesh_path / (name + ".strip");
        if (load_mapping)
            mapping_filename = _mesh_path / (name + ".map");
        Mesh_ASCII_File_Parser parser;
        parser.read_mesh(
            vertex_filename,
            triangle_filename,
            triangle_strip_filename,
            mapping_filename,
            vertex_count(mesh),
            triangle_count(mesh),
            triangle_strip_length(mesh),
            vertices(mesh),
            vertex_sections(mesh),
            vertex_relative_distances(mesh),
            triangles(mesh),
            triangle_strip(mesh));
    } else {
        Mesh_Binary_File_Parser parser;
        parser.read_mesh(
            binary_filename,
            load_vertices,
            load_triangles,
            load_triangle_strips,
            load_mapping,
            vertex_count(mesh),
            triangle_count(mesh),
            triangle_strip_length(mesh),
            vertices(mesh),
            vertex_sections(mesh),
            vertex_relative_distances(mesh),
            triangles(mesh),
            triangle_strip(mesh));
    }
    
    return mesh_ptr;
}
コード例 #2
0
/* Checks whether the graph is connected.
 * For directed graphs, it returns false.
 * Complexity: O(|V| + |E|); since it uses BFS algorithm.
 */
bool graph_using_AL::is_connected() {
    /* Return false if the graph is a directed graph. */
    if(d_type == directed_graph) return false;

    map<string, string>  parent  ;
    map<string,    int>  distance;

    /* Let us start from any arbitrary vertex. */
    string start_vertex = data.begin()->first;

    /* Construct the BFS tree.
     * If it contains all the vertices of the graph, then the graph is connected.
     * Complexity: O(|V| + |E|).
     */
    BFS_visit(parent, distance, start_vertex);

    /* Check how many nodes have non-null parents. */
    int temp_counter = 0;
    for(map<string, string>::iterator p_itr = parent.begin(); p_itr != parent.end(); p_itr++) {
        if(debug_flag) cout << p_itr->first << " <-- " << p_itr->second << endl;
        if(p_itr->second != "") {
            temp_counter ++;
        }
    }

    if(debug_flag) cout << "temp_counter: " << temp_counter << endl;

    /* '+1' because, for the start vertex, the parent will be Null/Empty. */
    return ((temp_counter + 1) == vertex_count());
}
コード例 #3
0
ファイル: translated.hpp プロジェクト: matus-chochlik/oglplu2
	void attrib_values(vertex_attrib_kind attr, const span<float>& dest)
	override
	{
		delegated_gen::attrib_values(attr, dest);

		if(attr == vertex_attrib_kind::position)
		{
			for(unsigned v=0, n=vertex_count(); v<n; ++v)
			for(unsigned c=0, m=values_per_vertex(attr); c<m; ++c)
			{
				dest[v*m+c] += _d[c];
			}
		}
	}
コード例 #4
0
ファイル: QGearsPFile.cpp プロジェクト: adrielvel/q-gears
    //---------------------------------------------------------------------
    void
    PFile::addGroup( const Group &group, ManualObject &mo
                    ,const String &sub_name, const String &material_base_name
                    ,const Ogre::Bone *bone ) const
    {
        size_t material_index( 0 );
        if( group.has_texture )
        {
            material_index = group.texture_index + 1;
        }
        String material_name( material_base_name + "/" + Ogre::StringConverter::toString( material_index ) );
        const uint16 bone_handle( bone->getHandle() );
        const Ogre::Vector3 bone_position( getPosition( bone ) );

        size_t index( 0 );
        size_t vertex_count( group.num_polygons * 3 );
        size_t index_count( vertex_count );
        size_t polygon_end_index( group.polygon_start_index + group.num_polygons );
        mo.begin( sub_name, material_name, vertex_count, index_count );
        for( size_t p( group.polygon_start_index ); p < polygon_end_index; ++p )
        {
            const PolygonDefinition& polygon( m_polygon_definitions[p] );
            for( int i(3); i--; )
            {
                uint32 v( group.vertex_start_index
                         +polygon.vertex[i] )
                      ,n( 0 + polygon.normal[i] )
                      ,t( group.texture_coordinate_start_index
                         +polygon.vertex[i] );
                Ogre::Vector3 pos( m_vertices[ v ] );
                mo.position((STATIC_ROTATION *  (pos / HRCFile::kDownScaler)) + bone_position);
                mo.colour( m_vertex_colors[ v ] );
                mo.normal( STATIC_ROTATION * m_normals[ n ] );
                if( group.has_texture )
                {
                    mo.textureCoord(m_texture_coordinates[t]);
                }
                mo.bone( index, bone_handle );
                mo.index( index++ );
            }
        }
        mo.end();
    }
コード例 #5
0
ファイル: QGearsPFile.cpp プロジェクト: adrielvel/q-gears
    //---------------------------------------------------------------------
    bool
    PFile::isPolygonDefinitionListValid( void )
    {
        Ogre::Log::Stream log( Ogre::LogManager::getSingleton().stream() );

        size_t vertex_count( m_vertices.size() )
              ,normal_count( m_normals.size() )
              ,edge_count  ( m_edges.size() );
        for( size_t p( m_polygon_definitions.size() ); p--; )
        {
            PolygonDefinition& def( m_polygon_definitions[p] );
            for( int i(3); i--; )
            {
                if( def.vertex[i] >= vertex_count )
                {
                    log << "Error: index to vertex is out of Bounds "
                        << " m_polygon_definitions[" << p << "]"
                        << ".vertex[" << i << "]: " << def.vertex[i];
                    return false;
                }
                if( def.normal[i] >= normal_count )
                {
                    log << "Error: index to normal is out of Bounds "
                        << " m_polygon_definitions[" << p << "]"
                        << ".normal[" << i << "]: " << def.normal[i];
                    return false;
                }
                if( def.edge[i] >= edge_count )
                {
                    log << "Error: index to edge is out of Bounds "
                        << " m_polygon_definitions[" << p << "]"
                        << ".edge[" << i << "]: " << def.edge[i];
                    return false;
                }
            }
        }

        return true;
    }
コード例 #6
0
ファイル: gen_base.hpp プロジェクト: deranen/oglplu2
	unsigned value_count(vertex_attrib_kind attr)
	{
		return vertex_count()*values_per_vertex(attr);
	}
コード例 #7
0
/* To find the minimum spanning tree using Kruskal's algorithm.
 * The mst_tree_edges will be populated by the MST edges.
 */
void graph_using_AL::find_MST_using_Kruskal(vector<pair<string, string> > &mst_tree_edges) {
    list<set<string> >					forest		;
    set<string>							temp_set	;
    map<string, set<string> >::iterator map_itr		;

    /* Populate forest. Each vertex is separte tree. */
    for(map_itr = data.begin(); map_itr != data.end(); map_itr ++) {
        temp_set.insert(map_itr->first);
        forest.push_back(temp_set);
        temp_set.clear();
    }

    /* Sorting based on weight.
     * Create a map with weight as the key and the edge as the value.
     */
    multimap<int, pair<string, string> >					temp_edge_weights	;
    map<pair<string, string>, int>::iterator				w_itr				;
    typedef multimap<int, pair<string, string> >::iterator	mm_itr				;

    /* For each edge in the graph. */
    for(w_itr = edge_weights.begin(); w_itr != edge_weights.end(); w_itr++) {
        if(d_type == undirected_graph) {
            /* Find the list of edges with this weight. */
            pair<mm_itr, mm_itr> mm_itr_pair = temp_edge_weights.equal_range(w_itr->second);

            /* Make sure the find is successful. */
            if(mm_itr_pair.first != mm_itr_pair.second) {
                if(debug_flag) cout << "Weight found: " << w_itr->second << endl;

                /* Traverse each edge with this weight. */
                bool found_flag = false;
                for(mm_itr mm_itr_1 = mm_itr_pair.first; mm_itr_1 != mm_itr_pair.second; mm_itr_1 ++) {
                    if(debug_flag) cout << "Comparing: " << mm_itr_1->second.first  << ", " << w_itr->first.second << endl;
                    if(debug_flag) cout << "Comparing: " << mm_itr_1->second.second << ", " << w_itr->first.first  << endl;

                    if((mm_itr_1->second.first == w_itr->first.second) && (mm_itr_1->second.second == w_itr->first.first)) {
                        found_flag = true;
                        break;
                    }
                }

                /* Check if found. */
                if(found_flag == false) {
                    /* None of the edge matched. */
                    if(debug_flag) cout << "inserting " << w_itr->second << ", " << w_itr->first.first << ", "
                                            << w_itr->first.second << endl;
                    temp_edge_weights.insert(pair<int, pair<string, string> >(w_itr->second, w_itr->first));
                }
                else {
                    /* One of the edge matched. */
                    if(debug_flag) cout << "Edge " << w_itr->first.first << ", " << w_itr->first.second
                                            << " need not be inserted" << endl;
                }
            }
            else {
                /* Find is unsuccessful. */
                if(debug_flag) cout << "Weight not found: " << w_itr->second << endl;
                if(debug_flag) cout << "inserting " << w_itr->second << ", " << w_itr->first.first << ", "
                                        << w_itr->first.second << endl;

                /* Insert the new edge. */
                temp_edge_weights.insert(pair<int, pair<string, string> >(w_itr->second, w_itr->first));
            }
        }
        else {
            /* Directed graph; so insert both pair of edges. */
            temp_edge_weights.insert(pair<int, pair<string, string> >(w_itr->second, w_itr->first));
        }
    }

    /* Printing the sorted list. */
    multimap<int, pair<string, string> >::iterator w_temp_itr;
    if(debug_flag) {
        cout << "Sorted list of edges: " << endl;
        for(w_temp_itr = temp_edge_weights.begin(); w_temp_itr != temp_edge_weights.end(); w_temp_itr ++) {
            cout << w_temp_itr->second.first << "->" << w_temp_itr->second.second << ": " << w_temp_itr->first << endl;
        }
    }

    /* Printing forest. */
    if(debug_flag) {
        cout << "Current forest: " << endl;
        for(list<set<string> >::iterator f_itr = forest.begin(); f_itr != forest.end(); f_itr ++) {
            if(! f_itr->empty()) {
                cout << "{";
                for(set<string>::iterator set_string_itr = f_itr->begin(); set_string_itr != f_itr->end(); set_string_itr ++) {
                    cout << *set_string_itr << " ";
                }
                cout << "} " << endl;
            }
        }
    }

    /* For each edge in increasing order of weight. */
    for(w_temp_itr = temp_edge_weights.begin(); w_temp_itr != temp_edge_weights.end(); w_temp_itr ++) {
        if(debug_flag) {
            cout << "Testing edge " << w_temp_itr->second.first << " -> " << w_temp_itr->second.second;
            cout << " (" << w_temp_itr->first << ")" << endl;
        }

        if(debug_flag) cout << "Checking whether in same set: "
                                << w_temp_itr->second.first << ", " << w_temp_itr->second.second << endl;
        list<set<string> >::iterator itr_1, itr_2;
        set<string>  ::iterator itr_3, itr_4;
        bool found_flag = false;

        /* Find the set of the first element. */
        found_flag = false;
        for(itr_1 = forest.begin(); itr_1 != forest.end(); itr_1 ++) {
            itr_3 = itr_1->find(w_temp_itr->second.first);
            if(itr_3 != itr_1->end()) {
                found_flag = true;
                break;
            }
        }
        assert(found_flag == true);

        /* Find the set of the second element. */
        for(itr_2 = forest.begin(); itr_2 != forest.end(); itr_2 ++) {
            itr_4 = itr_2->find(w_temp_itr->second.second);
            if(itr_4 != itr_2->end()) {
                found_flag = true;
                break;
            }
        }
        assert(found_flag == true);


        /* See if they are in the same set or not. */
        if(itr_1 != itr_2) {
            /* They are in different trees. */
            if(debug_flag) cout << "They are in different trees. " << endl;

            /* Add them to the set of edges in the MST. */
            if(debug_flag) cout << "Adding the edges " << *itr_3 << ", " << *itr_4 << " to the MST. " << endl;
            mst_tree_edges.push_back(pair<string, string>(*itr_3, *itr_4));

            /* Combine them into a single tree (set). */
            for(set<string>::iterator itr_5 = itr_2->begin(); itr_5 != itr_2->end(); itr_5++) {
                itr_1->insert(*itr_5);
            }
            itr_2->clear();

        }
        else {
            if(debug_flag) cout << "They are in the same tree. So cannot be added" << endl;
        }

        if(debug_flag) {
            for(vector<pair<string, string> >::iterator te_itr = mst_tree_edges.begin(); te_itr != mst_tree_edges.end(); te_itr ++) {
                cout << te_itr->first << ", " << te_itr->second << endl;
            }
        }

        /* If all the edges are added, you can stop.
         * For a graph with n vertices, its MST will contain (n-1) edges.
         */
        if(mst_tree_edges.size() == vertex_count() - 1) {
            if(debug_flag) cout << "All the edges have been added. " << endl;
            break;
        }

        /* Printing forest. */
        if(debug_flag) {
            cout << "Current forest: " << endl;
            for(list<set<string> >::iterator f_itr = forest.begin(); f_itr != forest.end(); f_itr ++) {
                if(! f_itr->empty()) {
                    cout << "{";
                    for(set<string>::iterator set_string_itr = f_itr->begin(); set_string_itr != f_itr->end(); set_string_itr ++) {
                        cout << *set_string_itr << " ";
                    }
                    cout << "} " << endl;
                }
            }
        }
    }

    return;
}
コード例 #8
0
void Mesh_File_Reader::insert_new_or_updated
(const std::string & name, Meshes & final_meshes, Meshes & meshes,
 bool load_vertices, bool load_triangles, bool load_triangle_strips,
 bool load_mapping)
{
    Mesh_Ptr mesh;
    
    // Serching if the mesh already exists
    Meshes::iterator old_mesh = final_meshes.find(name);
    if (old_mesh != final_meshes.end())
    {
        bool needs_vertices = 
            load_vertices && old_mesh->vertices().pointer() == 0;
        bool needs_triangles = 
            load_triangles && old_mesh->triangles().pointer() == 0;
        bool needs_triangle_strips = 
            load_triangle_strips && old_mesh->triangle_strip().pointer() == 0;
        bool needs_mapping = 
            load_mapping && old_mesh->vertex_sections().pointer() == 0;
        
        if (needs_vertices || needs_triangles || 
            needs_triangle_strips || needs_mapping)
        {
            // Loading missing datasets into mesh variable
            mesh = read(name, needs_vertices, needs_triangles, 
                        needs_triangle_strips, needs_mapping);

            // Add data not loaded from original mesh (if it has it)
            if (!needs_vertices)
            {
                vertices(*mesh) = vertices(*old_mesh);
                vertex_count(*mesh) = vertex_count(*old_mesh);
            }
            if (!needs_triangles)
            {
                triangles(*mesh) = triangles(*old_mesh);
                triangle_count(*mesh) = triangle_count(*old_mesh);
            }
            if (!needs_triangle_strips)
            {
                triangles(*mesh) = triangles(*old_mesh);
                triangle_count(*mesh) = triangle_count(*old_mesh);
            }
            if (!needs_mapping)
            {
                vertex_sections(*mesh) = vertex_sections(*old_mesh);
                vertex_relative_distances(*mesh) = 
                    vertex_relative_distances(*old_mesh);
            }
            normals(*mesh) = normals(*old_mesh);
        }
    }
    else
    {
        mesh = read(name, load_vertices, load_triangles, 
                    load_triangle_strips, load_mapping);
    }

    // Checking if something new has been read
    if (mesh.get() == 0)
        return;

    // computing additionnal data from the raw data if needed
    if (mesh->vertices().pointer() != 0 && 
        (mesh->triangles().pointer() != 0 || 
         mesh->triangle_strip().pointer() != 0) && 
        mesh->normals().pointer() == 0)
    {
        compute_per_vertex_normals(*mesh);
    }

    // Writing binary file if the whole mesh has been loaded and the binary
    // file doesn't exist yet.
    Filename binary_filename(_mesh_path / (name + ".bin"));    
    if(!boost::filesystem::exists(binary_filename)) 
    {
        if (mesh->vertices().pointer() != 0 && 
            mesh->triangles().pointer() != 0 && 
            mesh->triangle_strip().pointer() != 0 &&
            mesh->vertex_sections().pointer() != 0)
        {
            try
            {
                Mesh_Binary_File_Writer writer;
                writer.write_mesh(binary_filename, *mesh);
            } 
            catch (IO_Error)
            {
                std::cerr << "Error when writing the Binary file !\n";
            }
        }
    }

    if (old_mesh == final_meshes.end())
    {
        final_meshes.insert(name, mesh);
    }
    else
    {
        vertices(*old_mesh) = vertices(*mesh);
        vertex_count(*old_mesh) = vertex_count(*mesh);
        triangles(*old_mesh) = triangles(*mesh);
        triangle_count(*old_mesh) = triangle_count(*mesh);
        vertex_sections(*old_mesh) = vertex_sections(*mesh);
        vertex_relative_distances(*old_mesh) = vertex_relative_distances(*mesh);
        normals(*old_mesh) = normals(*mesh);
    }
}