//static void CityOnPlanet::SetCityModelPatterns(const SystemPath &path) { Uint32 _init[5] = { path.systemIndex, Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), UNIVERSE_SEED }; Random rand(_init, 5); typedef std::set<SceneGraph::Model*, ModelNameComparator> ModelSet; typedef ModelSet::iterator TSetIter; ModelSet modelSet; { for (unsigned int j=0; j < s_buildingList.numBuildings; j++) { SceneGraph::Model *m = s_buildingList.buildings[j].resolvedModel; modelSet.insert(m); } } SceneGraph::ModelSkin skin; for (TSetIter it=modelSet.begin(), itEnd=modelSet.end(); it!=itEnd; ++it) { SceneGraph::Model *m = (*it); if (!m->SupportsPatterns()) continue; skin.SetRandomColors(rand); skin.Apply(m); m->SetPattern(rand.Int32(0, m->GetNumPatterns())); } }
void writeEgMgGraphViz( std::ostream& o, bool verbose, const FinalEvalGraph& eg, const ModelGraphT& mg, boost::optional<std::set<typename ModelGraphT::Model> > onlyForModels = boost::none) { typedef typename ModelGraphT::ModelList ModelList; typedef typename ModelGraphT::Model Model; typedef typename ModelGraphT::PredecessorIterator ModelPredecessorIterator; typedef typename ModelGraphT::ModelIterator ModelIterator; typedef std::set<typename ModelGraphT::Model> ModelSet; ModelSet printModels; if( !!onlyForModels ) { // we need a hash map, as component graph is no graph with vecS-storage typedef boost::unordered_map<Model, boost::default_color_type> ColorHashMap; typedef boost::associative_property_map<ColorHashMap> ColorMap; ColorHashMap whiteHashMap; // fill white hash map ModelIterator mit, mit_end; for(boost::tie(mit, mit_end) = mg.getModels(); mit != mit_end; ++mit) { whiteHashMap[*mit] = boost::white_color; } // one hash map for all! ColorHashMap myHashMap(whiteHashMap); ColorMap myColorMap(myHashMap); for(typename ModelSet::const_iterator it = onlyForModels.get().begin(); it != onlyForModels.get().end(); ++it) { //LOG(INFO,"doing dfs visit for " << *it); boost::depth_first_visit( mg.getInternalGraph(), *it, boost::default_dfs_visitor(), myColorMap); } for(boost::tie(mit, mit_end) = mg.getModels(); mit != mit_end; ++mit) { if( myHashMap[*mit] == boost::white_color ) { //LOG(INFO,"model " << *mit << " still white"); } else { //LOG(INFO,"model " << *mit << " not white -> printing"); printModels.insert(*mit); } } } else { // include all ModelIterator mit, mit_end; for(boost::tie(mit, mit_end) = mg.getModels(); mit != mit_end; ++mit) { printModels.insert(*mit); } } // boost::graph::graphviz is horribly broken! // therefore we print it ourselves o << "digraph G {" << std::endl << "rankdir=BT;" << std::endl << // print root nodes at bottom, leaves at top! "concentrate=true;" << std::endl << //"center=false;" << std::endl << "pagedir=BL;" << std::endl << //"ranksep=\"0.5\";" << std::endl << //"nodesep=\"0.5\";" << std::endl << //"page=\"44,35\";" << std::endl << "compound=true;" << std::endl; // print clusters = eval units, inside nodes = models // stream deps into this stream std::stringstream odeps; FinalEvalGraph::EvalUnitIterator uit, ubegin, uend; boost::tie(ubegin, uend) = eg.getEvalUnits(); for(uit = ubegin; uit != uend; ++uit) { EvalUnit u = *uit; o << "subgraph clusteru" << u << "{" << std::endl; o << "node [shape=box];" << std::endl; o << "label=\""; { std::stringstream s; if( eg.propsOf(u).mgf != 0 ) { s << *eg.propsOf(u).mgf; } else { s << "NULL"; } // escape " into \" breakLinesAndGraphViz(s.str(), o); } o << "\";" << std::endl; // models in this subgraph { for(ModelType t = MT_IN; t <= MT_OUTPROJ; t = static_cast<ModelType>(static_cast<unsigned>(t)+1)) { const ModelList& modelsAt = mg.modelsAt(u, t); typename ModelList::const_iterator mit; for(mit = modelsAt.begin(); mit != modelsAt.end(); ++mit) { if( printModels.find(*mit) == printModels.end() ) continue; Model m = *mit; o << "m" << m << "[label=\""; { std::stringstream s; s << toString(mg.propsOf(m).type) << " " << m << " @" << mg.propsOf(m).location << "\\n"; if( mg.propsOf(m).interpretation != 0 ) s << *mg.propsOf(m).interpretation; breakLinesAndGraphViz(s.str(), o); } o << "\"];" << std::endl; // model dependencies (preds) ModelPredecessorIterator pit, pbegin, pend; boost::tie(pbegin, pend) = mg.getPredecessors(m); for(pit = pbegin; pit != pend; ++pit) { odeps << "m" << m << " -> m" << mg.targetOf(*pit) << "[label=\"" << mg.propsOf(*pit).joinOrder << "\"];" << std::endl; } } // through all models } } o << "}" << std::endl; /* // unit dependencies typename EvalGraphT::PredecessorIterator pit, pbegin, pend; boost::tie(pbegin, pend) = eg.getPredecessors(u); for(pit = pbegin; pit != pend; ++pit) { LOG(INFO,"-> depends on unit " << eg.targetOf(*pit) << "/join order " << eg.propsOf(*pit).joinOrder); } */ } // deps between models o << odeps.str() << std::endl; o << "}" << std::endl; }