Revision: 61529 http://sourceforge.net/p/brlcad/code/61529 Author: ejno Date: 2014-07-02 15:04:05 +0000 (Wed, 02 Jul 2014) Log Message: ----------- fix performance when converting large models
Modified Paths: -------------- brlcad/trunk/src/conv/3dm/conv3dm-g.cpp brlcad/trunk/src/conv/3dm/conv3dm-g.hpp Modified: brlcad/trunk/src/conv/3dm/conv3dm-g.cpp =================================================================== --- brlcad/trunk/src/conv/3dm/conv3dm-g.cpp 2014-07-02 15:03:51 UTC (rev 61528) +++ brlcad/trunk/src/conv/3dm/conv3dm-g.cpp 2014-07-02 15:04:05 UTC (rev 61529) @@ -130,6 +130,25 @@ +std::string +unique_name(std::map<std::string, int> &count_map, + const std::string &prefix, + const std::string &suffix) +{ + std::string name = prefix + suffix; + int count = count_map[name]++; + + if (count) { + std::ostringstream ss; + ss << prefix << count << suffix; + return ss.str(); + } else + return name; +} + + + + static void xform2mat_t(const ON_Xform &source, mat_t dest) { @@ -461,6 +480,8 @@ void RhinoConverter::map_uuid_names() { + std::map<std::string, int> count_map; + for (int i = 0; i < m_model->m_object_table.Count(); ++i) { const ON_Object *object = m_model->m_object_table[i].m_object; const ON_3dmObjectAttributes &myAttributes = @@ -472,10 +493,10 @@ suffix = ".c"; if (m_use_uuidnames) - m_obj_map[obj_uuid].m_name = unique_name(obj_uuid, suffix); + m_obj_map[obj_uuid].m_name = unique_name(count_map, obj_uuid, suffix); else m_obj_map[obj_uuid].m_name = - unique_name(CleanName(myAttributes.m_name), suffix); + unique_name(count_map, CleanName(myAttributes.m_name), suffix); } @@ -485,10 +506,10 @@ const std::string idef_uuid = UUIDstr(idef.m_uuid); if (m_use_uuidnames) - m_obj_map[idef_uuid].m_name = unique_name(idef_uuid, ".c"); + m_obj_map[idef_uuid].m_name = unique_name(count_map, idef_uuid, ".c"); else m_obj_map[idef_uuid].m_name = - unique_name(CleanName(idef.Name()), ".c"); + unique_name(count_map, CleanName(idef.Name()), ".c"); } @@ -501,10 +522,10 @@ suffix = ".r"; if (m_use_uuidnames) - m_obj_map[layer_uuid].m_name = unique_name(layer_uuid, suffix); + m_obj_map[layer_uuid].m_name = unique_name(count_map, layer_uuid, suffix); else m_obj_map[layer_uuid].m_name = - unique_name(CleanName(layer.m_name), suffix); + unique_name(count_map, CleanName(layer.m_name), suffix); } @@ -513,13 +534,13 @@ const std::string bitmap_uuid = gen_bitmap_id(i); if (m_use_uuidnames) - m_obj_map[bitmap_uuid].m_name = unique_name(bitmap_uuid, ".pix"); + m_obj_map[bitmap_uuid].m_name = unique_name(count_map, bitmap_uuid, ".pix"); else { std::string bitmap_name = CleanName(bitmap->m_bitmap_name); if (bitmap_name == DEFAULT_NAME) bitmap_name = CleanName(bitmap->m_bitmap_filename); - m_obj_map[bitmap_uuid].m_name = unique_name(bitmap_name, ".pix"); + m_obj_map[bitmap_uuid].m_name = unique_name(count_map, bitmap_name, ".pix"); } } } @@ -751,39 +772,6 @@ -bool -RhinoConverter::is_name_taken(const std::string &name) const -{ - for (std::map<std::string, ModelObject>::const_iterator it = m_obj_map.begin(); - it != m_obj_map.end(); ++it) - if (name == it->second.m_name) - return true; - - - return false; -} - - - - -std::string -RhinoConverter::unique_name(const std::string &name, - const std::string &suffix) const -{ - std::string new_name = name + suffix; - int counter = 0; - while (is_name_taken(new_name)) { - std::ostringstream s; - s << ++counter; - new_name = name + s.str() + suffix; - } - - return new_name; -} - - - - RhinoConverter::Color RhinoConverter::get_color(const ON_3dmObjectAttributes &obj_attrs) const { Modified: brlcad/trunk/src/conv/3dm/conv3dm-g.hpp =================================================================== --- brlcad/trunk/src/conv/3dm/conv3dm-g.hpp 2014-07-02 15:03:51 UTC (rev 61528) +++ brlcad/trunk/src/conv/3dm/conv3dm-g.hpp 2014-07-02 15:04:05 UTC (rev 61529) @@ -98,13 +98,7 @@ std::pair<std::string, std::string> get_shader(int index) const; - bool is_name_taken(const std::string &name) const; - std::string unique_name(const std::string &name, - const std::string &suffix) const; - - - const bool m_verbose_mode; bool m_use_uuidnames; bool m_random_colors; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards http://p.sf.net/sfu/Bonitasoft _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits