15 #include "eggBinMaker.h"
16 #include "eggGroupNode.h"
35 int bin_number_a = _ebm->get_bin_number(a);
36 int bin_number_b = _ebm->get_bin_number(b);
38 if (bin_number_a != bin_number_b) {
41 return bin_number_a < bin_number_b;
80 collect_nodes(root_group);
83 GroupNodes::const_iterator gi;
84 for (gi = _group_nodes.begin(); gi != _group_nodes.end(); ++gi) {
85 num_bins += get_bins_for_group(gi);
156 if (collapse_from == (
EggGroup *)NULL) {
159 return new EggBin(*collapse_from);
174 EggGroupNode::iterator i, next;
176 bool first_in_group =
true;
177 GroupNodes::iterator gni = _group_nodes.end();
181 while (i != group->end()) {
182 EggNode *node = (*i);
187 if (get_bin_number(node) != 0) {
190 if (first_in_group) {
194 pair<GroupNodes::iterator, bool> result;
195 result = _group_nodes.insert
196 (GroupNodes::value_type
199 nassertv(result.second);
201 first_in_group =
false;
206 nassertv(gni != _group_nodes.end());
207 (*gni).second.insert(node);
213 if (node->
is_of_type(EggGroupNode::get_class_type())) {
230 get_bins_for_group(GroupNodes::const_iterator gi) {
232 const SortedNodes &nodes = (*gi).second;
235 nassertr(!nodes.empty(), 0);
239 SortedNodes::const_iterator sni, last;
243 bins.push_back(Nodes());
244 bins.back().push_back(*sni);
246 while (sni != nodes.end()) {
247 if (cn(*last, *sni)) {
249 bins.push_back(Nodes());
251 bins.back().push_back(*sni);
257 make_bins_for_group(group, bins);
268 make_bins_for_group(
EggGroupNode *group,
const Bins &bins) {
270 nassertv(!bins.empty());
277 bool collapse =
false;
279 if (group->empty() &&
281 group->get_parent() != NULL &&
282 group->
is_of_type(EggGroup::get_class_type())) {
283 const Nodes &nodes = bins.front();
284 nassertv(!nodes.empty());
285 int bin_number = get_bin_number(nodes.front());
290 const Nodes &nodes = bins.front();
291 nassertv(!nodes.empty());
292 int bin_number = get_bin_number(nodes.front());
293 PT(
EggBin) bin = make_bin(bin_number, nodes.front(), DCAST(
EggGroup, group));
294 setup_bin(bin, nodes);
297 parent->remove_child(group);
298 parent->add_child(bin);
301 Bins::const_iterator bi;
302 for (bi = bins.begin(); bi != bins.end(); ++bi) {
303 const Nodes &nodes = (*bi);
304 nassertv(!nodes.empty());
305 int bin_number = get_bin_number(nodes.front());
306 PT(
EggBin) bin = make_bin(bin_number, nodes.front(), NULL);
307 setup_bin(bin, nodes);
309 group->add_child(bin);
322 setup_bin(
EggBin *bin, const Nodes &nodes) {
323 nassertv(!nodes.empty());
324 int bin_number = get_bin_number(nodes.front());
325 bin->set_bin_number(bin_number);
327 string bin_name =
get_bin_name(bin_number, nodes.front());
328 if (!bin_name.empty()) {
329 bin->set_name(bin_name);
332 Nodes::const_iterator ni;
333 for (ni = nodes.begin(); ni != nodes.end(); ++ni) {
virtual void prepare_node(EggNode *node)
May be overridden in derived classes to perform some setup work as each node is encountered.
virtual string get_bin_name(int bin_number, const EggNode *child)
May be overridden in derived classes to define a name for each new bin, based on its bin number...
A base class for nodes in the hierarchy that are not leaf nodes.
bool operator()(const EggNode *a, const EggNode *b) const
Called by the SortedNodes set to put nodes into bin order.
virtual bool sorts_less(int bin_number, const EggNode *a, const EggNode *b)
May be overridden in derived classes to create additional bins within a particular bin number...
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
This is a handy class for collecting related nodes together.
A base class for things that may be directly added into the egg hierarchy.
int make_bins(EggGroupNode *root_group)
The main entry point to EggBinMaker.
virtual bool collapse_group(const EggGroup *group, int bin_number)
May be overridden in derived classes to specify whether a particular group node, apparently redundant...
TypeHandle is the identifier used to differentiate C++ class types.
This is just an STL function object, used to sort nodes within EggBinMaker.
A type of group node that holds related subnodes.