~gimaker/peekabot/coord-sys-default

« back to all changes in this revision

Viewing changes to src/IDTranslationTable.cc

  • Committer: Staffan Gimåker
  • Date: 2009-06-29 10:09:26 UTC
  • mfrom: (665.1.39 renderer-redux)
  • Revision ID: staffan@gimaker.se-20090629100926-ju5kx8jwzy422rwu
Merged the renderer-redux branch.

This represents a major overhaul to the rendering engine, with a less contrived
design and better performance. Both memory and CPU utilization should be 
better in general.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of peekabot.
3
 
 *
4
 
 * peekabot is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * peekabot is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
 
18
 
#include "IDTranslationTable.hh"
19
 
#include "SceneObject.hh"
20
 
 
21
 
 
22
 
using namespace peekabot;
23
 
 
24
 
 
25
 
// --------------------- IDTranslationTable implementation ---------------------
26
 
 
27
 
void IDTranslationTable::add_node_translation_entry(
28
 
    ObjectID object_id, NodeID node_id) throw()
29
 
{
30
 
    m_node_id_map.insert(std::make_pair(object_id, node_id));
31
 
}
32
 
 
33
 
 
34
 
void IDTranslationTable::remove_node_translation_entry(
35
 
    ObjectID object_id) throw()
36
 
{
37
 
    m_node_id_map.erase(object_id);
38
 
}
39
 
 
40
 
void IDTranslationTable::remove_node_translation_entries(
41
 
    SceneObject *subtree) throw()
42
 
{
43
 
    remove_node_translation_entry(subtree->get_object_id());
44
 
    
45
 
    SceneObject::ChildContainer &children = subtree->get_children();
46
 
    for( SceneObject::ChildContainer::iterator it = children.begin();
47
 
         it != children.end(); ++it )
48
 
    {
49
 
        remove_node_translation_entries(*it);
50
 
    }
51
 
}
52
 
 
53
 
NodeID IDTranslationTable::get_node_id(
54
 
    ObjectID object_id) const throw()
55
 
{
56
 
    NodeIDMap::const_iterator it = m_node_id_map.find(object_id);
57
 
    
58
 
    if( it != m_node_id_map.end() )
59
 
        return it->second;
60
 
    else
61
 
        return -1; /// \todo We should report errors somehow. Throw?
62
 
}
63
 
 
64
 
 
65
 
void IDTranslationTable::add_primitive_translation_entry(
66
 
    ObjectID object_id, PrimitiveID primitive_id) throw()
67
 
{
68
 
    m_primitive_id_map.insert(std::make_pair(object_id, primitive_id));
69
 
}
70
 
 
71
 
 
72
 
void IDTranslationTable::remove_primitive_translation_entry(
73
 
    ObjectID object_id) throw()
74
 
{
75
 
    m_primitive_id_map.erase(object_id);
76
 
}
77
 
 
78
 
void IDTranslationTable::remove_primitive_translation_entries(
79
 
    SceneObject *subtree) throw()
80
 
{
81
 
    remove_primitive_translation_entry(subtree->get_object_id());
82
 
    
83
 
    SceneObject::ChildContainer &children = subtree->get_children();
84
 
    for( SceneObject::ChildContainer::iterator it = children.begin();
85
 
         it != children.end(); ++it )
86
 
    {
87
 
        remove_primitive_translation_entries(*it);
88
 
    }
89
 
}
90
 
 
91
 
PrimitiveID IDTranslationTable::get_primitive_id(
92
 
    ObjectID object_id) const throw()
93
 
{
94
 
    PrimitiveIDMap::const_iterator it = m_primitive_id_map.find(object_id);
95
 
    
96
 
    if( it != m_primitive_id_map.end() )
97
 
        return it->second;
98
 
    else
99
 
        return -1; /// \todo We should report errors somehow. Throw?
100
 
}