// ----------------------------------------------------------------------
   void
   CreateDynamicEdgesTransmissionRangeTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);
      GroupElement* all_edges = new GroupElement("all.edges");
      visualization_w().add_element(all_edges);

      std::string pref = sc.environment().
            optional_string_param("prefix",DrawableEdgeDynamic::PREFIX);
      std::string node_prefix = sc.environment().
            optional_string_param("node_prefix",DrawableNodeDefault::PREFIX);

      std::string _source_regex = sc.environment().optional_string_param("source_regex", ".*");
      std::string _target_regex = sc.environment().optional_string_param("target_regex", ".*");

      const shawn::Node &dummy = *(visualization().world().begin_nodes());
      std::cout << "Regex: " << _source_regex << std::endl;
      DrawableEdgeDynamicTransmissionRange* ded =
                        new DrawableEdgeDynamicTransmissionRange(dummy,dummy, pref, node_prefix, _source_regex, _target_regex);
      ded->init();
      visualization_w().add_element(ded);
      all_edges->add_element(*ded);
   }
   // ----------------------------------------------------------------------
   void
   CreateEstimatedEdgesTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);

      std::string pref = sc.environment().
         optional_string_param("prefix",DrawableEdgeEstimated::PREFIX);
      std::string node_prefix =
         sc.environment().
         optional_string_param("node_prefix",DrawableNodeDefault::PREFIX);
      GroupElement* grp = group(sc);

      for( shawn::World::const_node_iterator
              it    = visualization().world().begin_nodes(),
              endit = visualization().world().end_nodes();
           it != endit; ++it )
      {
         if( it->has_est_position())
         {
            const DrawableNode* dn = drawable_node(*it, node_prefix);
            DrawableEdgeEstimated* dee = new DrawableEdgeEstimated(*it, *dn, 
               DrawableEdgeEstimated::PREFIX);
            dee->init();
            visualization_w().add_element(dee);
            if( grp != NULL )
               grp->add_element(*dee);
         }
      }
   }
Exemplo n.º 3
0
   // ----------------------------------------------------------------------
   void
   CreateGroupTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);

      GroupElement* ge =
         new GroupElement( sc.environment().required_string_param("group") );
      ge->init();
      visualization_w().add_element( ge );
   }
Exemplo n.º 4
0
   // ----------------------------------------------------------------------
   void
   CreateEdgesTagTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);
#ifndef HAVE_BOOST_REGEX
      throw std::runtime_error("no boost::regex support compiled in");
#else
      boost::regex sources(sc.environment().required_string_param("source_regex"));
      boost::regex targets(sc.environment().required_string_param("target_regex"));
      std::string taglabel = sc.environment().required_string_param("tag");

      std::string pref = sc.environment().
         optional_string_param("prefix",DrawableEdgeDefault::PREFIX);
      std::string node_prefix =
         sc.environment().
         optional_string_param("node_prefix",DrawableNodeDefault::PREFIX);
      GroupElement* grp = group(sc);

      for( shawn::World::const_node_iterator
              it    = visualization().world().begin_nodes(),
              endit = visualization().world().end_nodes();
           it != endit; ++it )
      {
         
         if( boost::regex_search(get_stringtag(&*it,taglabel)->value(),sources))
            {
               for( shawn::Node::const_adjacency_iterator
                       ait    = it->begin_adjacent_nodes(),
                       endait = it->end_adjacent_nodes();
                    ait != endait; ++ait )
                  if( *it != *ait )
                     if( boost::regex_search(get_stringtag(&*ait,taglabel)->value(),targets) )
                        if( (ait->label() > it->label()) ||
                            (!boost::regex_search(get_stringtag(&*it,taglabel)->value(),targets)) ||
                            (!boost::regex_search(get_stringtag(&*ait,taglabel)->value(),sources)) )
                           {
                              const DrawableNode* dsrc =
                                 drawable_node(*it,node_prefix);
                              const DrawableNode* dtgt =
                                 drawable_node(*ait,node_prefix);
                              DrawableEdgeDefault* ded =
                                 new DrawableEdgeDefault(*it,*ait,*dsrc,*dtgt,pref);
                              ded->init();
                              visualization_w().add_element(ded);
                              if( grp != NULL )
                                 grp->add_element(*ded);
                           }
            }
      }
#endif
   }
Exemplo n.º 5
0
// ----------------------------------------------------------------------
void
CreateGraphicsTask::
run( shawn::SimulationController& sc )
throw( std::runtime_error )
{
    VisualizationTask::run(sc);

    DrawableGraphics* dg =
        new DrawableGraphics( sc.environment().required_string_param("name"),
                              sc.environment().required_string_param("file") );
    dg->init();
    visualization_w().add_element( dg );
}
 // ----------------------------------------------------------------------
 GroupElement*
 CreateEstimatedEdgesTask::
 group( shawn::SimulationController& sc )
    throw( std::runtime_error )
 {
    std::string n = sc.environment().optional_string_param("group","");
    if( n.empty() ) 
       return NULL;
    ElementHandle eh = 
        visualization_w().element_w( n );
    if( eh.is_null() )
       throw std::runtime_error(std::string("no such group: ")+n);
    GroupElement* ge = dynamic_cast<GroupElement*>(eh.get());
    if( ge == NULL )
       throw std::runtime_error(std::string("element is no group: ")+n);
    return ge;
 }
Exemplo n.º 7
0
   // ----------------------------------------------------------------------
   void
   ExternalAnimationTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);

      std::string file_name = sc.environment().optional_string_param(
         "filename", "animation");
      double refresh_interval = sc.environment().optional_double_param(
		  "refresh_interval", 1.0);
      std::string writer_type = sc.environment().optional_string_param("writer", "png");
      double event_time = sc.world().scheduler().current_time();

      sc.world_w().scheduler_w().new_event(*new WriteAnimationFrameEvent(
		  refresh_interval, visualization_w(), writer_type, file_name, sc ), 
		  event_time, NULL);
   }
Exemplo n.º 8
0
   // ----------------------------------------------------------------------
   void
   CreateLiveviewTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);

	  // Uses the resolution of the vis camera as texture resolution:
      int texwidth = (int)visualization().camera().width(0.0);
      int texheight = (int)visualization().camera().height(0.0);

	  // Fit the window size to the configured camera resolution:
      int width = sc.environment().optional_int_param("winwidth", 
		  texwidth + 10);
      int height = sc.environment().optional_int_param("winheight", 
		  texwidth + 10);

	  // Refresh interval in Shaun time (once every simulation round by 
	  // default):
      double refresh_interval = sc.environment().optional_double_param(
		  "refresh_interval", 1.0);
	  // Minimum interval delay in milliseconds (to make a fast simulations 
	  // visible; 0 by default):
      int refresh_delay = sc.environment().optional_int_param("refresh_delay",
		  0);

#ifdef HAVE_BOOST
	  // Creates the external window:
      createWindow(width, height, texwidth, texheight);

	  // Adds the Liveview refresh event to Shauns event scheduler:
      double event_time = sc.world().scheduler().current_time();
      sc.world_w().scheduler_w().new_event(*new RefreshLiveviewEvent(
		  refresh_interval, refresh_delay, visualization_w()), 
		  event_time, NULL);
#endif
   }