Revision: 65295
http://sourceforge.net/p/brlcad/code/65295
Author: ejno
Date: 2015-06-15 13:19:25 +0000 (Mon, 15 Jun 2015)
Log Message:
-----------
move COMPSPLT information up into RegionManager
Modified Paths:
--------------
brlcad/trunk/src/libgcv/conv/fastgen4/fastgen4_write.cpp
Modified: brlcad/trunk/src/libgcv/conv/fastgen4/fastgen4_write.cpp
===================================================================
--- brlcad/trunk/src/libgcv/conv/fastgen4/fastgen4_write.cpp 2015-06-15
13:15:18 UTC (rev 65294)
+++ brlcad/trunk/src/libgcv/conv/fastgen4/fastgen4_write.cpp 2015-06-15
13:19:25 UTC (rev 65295)
@@ -202,8 +202,8 @@
if (rt_db_get_internal(&m_internal, &dir, &db, NULL, &rt_uniresource) < 0)
throw std::runtime_error("rt_db_get_internal() failed");
+ m_valid = true;
RT_CK_DB_INTERNAL(&m_internal);
- m_valid = true;
}
@@ -606,9 +606,6 @@
break;
}
}
-
- if (results.at(i) > MAX_GRID_POINTS)
- throw std::length_error("invalid grid ID");
}
return results;
@@ -618,6 +615,9 @@
void
GridManager::write(RecordWriter &writer) const
{
+ if (m_next_grid_id - 1 > MAX_GRID_POINTS)
+ throw std::length_error("max grid points exceeded");
+
for (std::map<Point, std::vector<std::size_t>,
PointComparator>::const_iterator
it = m_grids.begin(); it != m_grids.end(); ++it)
for (std::vector<std::size_t>::const_iterator id_it =
it->second.begin();
@@ -637,10 +637,11 @@
Section(const std::string &name, bool volume_mode);
bool empty() const;
+ bool has_color() const;
+ Color get_color() const;
void set_color(const Color &value);
- void set_compsplt(fastf_t z_coordinate);
- void write(FastgenWriter &writer) const;
+ void write(FastgenWriter &writer, const FastgenWriter::SectionID &id)
const;
// create a comment describing an element
void write_name(const std::string &value);
@@ -673,7 +674,6 @@
const std::size_t m_material_id;
std::pair<bool, Color> m_color; // optional color
- std::pair<bool, fastf_t> m_compsplt;
GridManager m_grids;
StringBuffer m_elements;
@@ -686,7 +686,6 @@
m_volume_mode(volume_mode),
m_material_id(1),
m_color(false, Color()),
- m_compsplt(false, 0.0),
m_grids(),
m_elements(),
m_next_element_id(1)
@@ -700,38 +699,31 @@
}
-void
-Section::set_color(const Color &value)
+inline bool
+Section::has_color() const
{
- m_color.first = true;
- m_color.second = value;
+ return m_color.first;
}
-void
-Section::set_compsplt(fastf_t z_coordinate)
+inline Color
+Section::get_color() const
{
- if (m_compsplt.first)
- throw std::logic_error("already a COMPSPLT");
-
- m_compsplt.first = true;
- m_compsplt.second = z_coordinate;
+ return m_color.second;
}
void
-Section::write(FastgenWriter &writer) const
+Section::set_color(const Color &value)
{
- const FastgenWriter::SectionID id = writer.take_next_section_id();
+ m_color.first = true;
+ m_color.second = value;
+}
- if (m_compsplt.first) {
- const FastgenWriter::SectionID split_id = writer.write_compsplt(id,
- m_compsplt.second);
- if (m_color.first)
- writer.write_section_color(split_id, m_color.second);
- }
-
+void
+Section::write(FastgenWriter &writer, const FastgenWriter::SectionID &id) const
+{
{
std::string new_name = m_name;
@@ -749,8 +741,8 @@
RecordWriter::Record(writer) << "SECTION" << id.first << id.second <<
(m_volume_mode ? 2 : 1);
- if (m_color.first)
- writer.write_section_color(id, m_color.second);
+ if (has_color())
+ writer.write_section_color(id, get_color());
m_grids.write(writer);
m_elements.write(writer);
@@ -962,7 +954,7 @@
// set a very small thickness if face thickness is zero
if (bot.thickness)
result.first = !NEAR_ZERO(bot.thickness[i],
- RT_LEN_TOL) ? bot.thickness[i] : 2 *
RT_LEN_TOL;
+ RT_LEN_TOL) ? bot.thickness[i] : 2.0 *
RT_LEN_TOL;
if (bot.face_mode)
result.second = !BU_BITTEST(bot.face_mode, i);
@@ -1580,7 +1572,7 @@
// Organize Section objects by their corresponding region, and store
-// additional conversion data pertinent to these sections.
+// additional conversion state regarding those Sections.
class FastgenConversion::RegionManager
{
public:
@@ -1589,9 +1581,12 @@
void write(FastgenWriter &writer) const;
- // don't write this Section
+ // don't write these Sections
void disable();
+ // mark these Sections as having a COMPSPLT
+ void set_compsplt(fastf_t z_coordinate);
+
// returns true if the given member shouldn't be written
bool member_ignored(const directory &member_dir) const;
@@ -1604,6 +1599,7 @@
RegionManager &operator=(const RegionManager &source);
bool m_enabled;
+ std::pair<bool, fastf_t> m_compsplt;
const std::set<const directory *> m_ignored_members;
std::map<std::string, Section *> m_sections;
};
@@ -1612,6 +1608,7 @@
FastgenConversion::RegionManager::RegionManager(const db_i &db,
const directory ®ion_dir) :
m_enabled(true),
+ m_compsplt(false, 0.0),
m_ignored_members(find_walls(db, region_dir)),
m_sections()
{}
@@ -1632,9 +1629,24 @@
return;
for (std::map<std::string, Section *>::const_iterator it =
m_sections.begin();
- it != m_sections.end(); ++it)
- if (!it->second->empty())
- it->second->write(writer);
+ it != m_sections.end(); ++it) {
+ if (it->second->empty())
+ continue;
+
+ const FastgenWriter::SectionID id = writer.take_next_section_id();
+
+ if (m_compsplt.first) {
+ const FastgenWriter::SectionID split_id = writer.write_compsplt(id,
+ m_compsplt.second);
+
+ if (it->second->has_color()) {
+ Color color = it->second->get_color();
+ writer.write_section_color(split_id, color);
+ }
+ }
+
+ it->second->write(writer, id);
+ }
}
@@ -1648,6 +1660,17 @@
}
+void
+FastgenConversion::RegionManager::set_compsplt(fastf_t z_coordinate)
+{
+ if (m_compsplt.first)
+ throw std::logic_error("already a COMPSPLT");
+
+ m_compsplt.first = true;
+ m_compsplt.second = z_coordinate;
+}
+
+
bool
FastgenConversion::RegionManager::member_ignored(const directory &member_dir)
const
@@ -1743,8 +1766,7 @@
if (this_id == 1)
data.get_region(*parent_region_dir).disable();
else
-
data.get_region(*parent_region_dir).get_section(get_region_path(data.m_db,
- half_path)).set_compsplt(half.eqn[3]);
+ data.get_region(*parent_region_dir).set_compsplt(half.eqn[3]);
return true;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits