Exemplo n.º 1
0
   // ----------------------------------------------------------------------
   void
   DrawableEdgeDynamicTags::
   draw( cairo_t* cr, double t, const Context& C )
      const throw(std::runtime_error)
   {
      Drawable::draw(cr,t,C);
      if( visible() )
         {
            double lw       = edge_properties().line_width(t);
            shawn::Vec col  = edge_properties().color(t);
            double blend   = edge_properties().blend(t);

            cairo_save(cr);
            cairo_set_line_width( cr, lw );

            cairo_set_source_rgba(cr,col.x(),col.y(),col.z(),1.0-blend);

            for( shawn::World::const_node_iterator
                  it    = visualization().world().begin_nodes(),
                  endit = visualization().world().end_nodes();
                  it != endit; ++it )
            {
               const shawn::Node& _srcNode = *it;
               for(shawn::TagContainer::tag_iterator
            	  tit = _srcNode.begin_tags(),
            	  tendit = _srcNode.end_tags();
                  tit != tendit; ++tit)
               {
            	   std::string curTagName = (*tit).first;
            	   boost::regex targets(tagname_regex_);
            	   if(boost::regex_search(curTagName, targets))
            	   {
            		   shawn::NodeReferenceTag *tag =
            			   dynamic_cast<shawn::NodeReferenceTag *>((*tit).second.get());
            		   if(tag != NULL)
            		   {
            			   shawn::Node *ntgt = tag->value();
            			   const DrawableNode* dsrc = drawable_node( *it, DrawableNodeDefault::PREFIX );
            			   const DrawableNode* dtgt = drawable_node( *ntgt, DrawableNodeDefault::PREFIX );
            			   shawn::Vec pos1 = dsrc->position(t);
						   shawn::Vec pos2 = dtgt->position(t);
						   cairo_move_to(cr,pos1.x(),pos1.y());
						   cairo_line_to(cr,pos2.x(),pos2.y());
						   cairo_stroke(cr);
            		   }
            		   else
            		   {
            			   WARN("DrawableEdgeDynamicTags", "Tag is not of type NodeReferenceTag as expected");
            		   }
            	   }
               }
            }

            cairo_restore(cr);
         }
   }
Exemplo n.º 2
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
   }
   // ----------------------------------------------------------------------
   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);
         }
      }
   }
   // ----------------------------------------------------------------------
   void
   DrawableEdgeDynamicTree::
   draw( cairo_t* cr, double t, const Context& C )
      const throw(std::runtime_error)
   {
      Drawable::draw(cr,t,C);
      if( visible() )
         {
            double lw       = edge_properties().line_width(t);
            shawn::Vec col  = edge_properties().color(t);
            double blend   = edge_properties().blend(t);
            
            const std::string taglabel = "predecessor";

            cairo_save(cr);
            cairo_set_line_width( cr, lw );

            cairo_set_source_rgba(cr,col.x(),col.y(),col.z(),1.0-blend);

            for( shawn::World::const_node_iterator
                  it    = visualization().world().begin_nodes(),
                  endit = visualization().world().end_nodes();
                  it != endit; ++it )
            {
               std::string pred = read_predecessor( *it, taglabel );
               if ( pred.empty() )
                  continue;
            
               const shawn::Node *predecessor = visualization().world().find_node_by_label( pred );
               if ( !predecessor )
                  continue;   
               const DrawableNode* dsrc = drawable_node( *it, DrawableNodeDefault::PREFIX );
               const DrawableNode* dtgt = drawable_node( *predecessor, DrawableNodeDefault::PREFIX );
               shawn::Vec pos1 = dsrc->position(t);
               shawn::Vec pos2 = dtgt->position(t);
               cairo_move_to(cr,pos1.x(),pos1.y());
               cairo_line_to(cr,pos2.x(),pos2.y());
               cairo_stroke(cr);
            }

            cairo_restore(cr);
         }
   }