// ----------------------------------------------------------------------
   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);
         }
      }
   }
Esempio n. 2
0
void performHighPass(const cv::Mat& image, cv::Mat& res, int rad) {
    cv::Mat grey, tmp;
    cv::cvtColor(image, grey, CV_BGR2GRAY);


    grey.convertTo(grey, CV_32F);
    grey.copyTo(res);
    res.convertTo(res, CV_8U);
    std::vector<cv::Mat> planes(2, cv::Mat());
    std::vector<cv::Mat> polar(2, cv::Mat());

    cv::dft(grey, tmp, cv::DFT_COMPLEX_OUTPUT);
    cv::split(tmp, planes);
    cv::cartToPolar(planes[0], planes[1], polar[0], polar[1]);
    visualization(polar[0], tmp);
    concatImages(res, tmp, res);

    rearrangeQuadrants(polar[0]);
    highPassFilter(polar[0], rad);
    rearrangeQuadrants(polar[0]);

    visualization(polar[0], tmp);
    tmp.convertTo(tmp, res.type());
    concatImages(res, tmp, res);

    cv::polarToCart(polar[0], polar[1], planes[0], planes[1]);
    cv::merge(planes, tmp);
    cv::dft(tmp, tmp, cv::DFT_SCALE | cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT);
    tmp.convertTo(tmp, CV_8U);
    concatImages(res, tmp, res);
}
Esempio n. 3
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);
         }
   }
Esempio 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
   }
   // ----------------------------------------------------------------------
   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
   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);
         }
   }
Esempio n. 7
0
void TextCursor::setX(int xBegin, int xEnd)
{
	xBegin_ = xBegin;
	xEnd_ = xEnd;

	int caretX = isCursorBeforeSelection() ? xBegin : xEnd;
	setPosition(QPointF(owner()->scenePos() + QPoint(caretX + owner()->textXOffset(), 2)).toPoint());

	CursorShapeItem* ci = static_cast<CursorShapeItem*> (visualization());
	ci->setCursorCenter(position());
}
Esempio 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
   }
 // ----------------------------------------------------------------------
 const DrawableNode*
 DrawableEdgeDynamicTree::
 drawable_node( const shawn::Node& v,
                const std::string& nprefix )
    const throw( std::runtime_error )
 {
    std::string n = nprefix+std::string(".")+v.label();
    ConstElementHandle eh =
       visualization().element( n );
    if( eh.is_null() )
       throw std::runtime_error(std::string("no such element: ")+n);
    const DrawableNode* dn = dynamic_cast<const DrawableNode*>(eh.get());
    if( dn == NULL )
       throw std::runtime_error(std::string("element is no DrawableNode: ")+n);
    return dn;
 }
Esempio n. 10
0
/**
	Main routine.
	Takes 1 command line parameter, which specifies optional input file
	
	Control keys:
	- [ESC]: quit
	- [SPACE]: pause/resume simulation
	- [RIGHT]: advance single step (only when paused)
	- [s]: save current simulation
	- [r]: reset simulation	
    - [w]: toggle rendering mode

	Mouse:
	- Left button: rotating
	- Right button: panning
	- Scroll wheel: zooming

	The class concept relies on the Model-View-Controller (MVC) 
	architecture. 
	The controller class handles all user input and updates the 
	visualization and simulation correspondingly.
	The simulation (model) advances stepwise, the visualization (view) 
	displays then the updated data.
*/
int main(int argc, char *argv[])
{  
	int done = 0;

	tools::Logger::logger.printStartMessage();

	// Initialize visualization
	Visualization visualization(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE);
	printf("Initialized OpenGL window...\n\n");

	// Initialize simulation
	printf("Init simulation\n\n");
	Simulation sim;
	printf("Init visualisation\n\n");
	visualization.init(sim);

	// Initialize controller
	Controller controller(&sim, &visualization);
	
	printf("Start simulation\n\n");
    // sim.saveToFile();
	// Enter the main loop
	while ( ! done ) 
	{
		// Handle events
		done = controller.handleEvents();
		if (controller.isPaused()) {
			// We're paused, only render new display
			visualization.renderDisplay();
		}
		else if (controller.hasFocus()) {
			// Simulate, update visualization data
			sim.runCuda(visualization.getCudaWaterSurfacePtr(), visualization.getCudaNormalsPtr());
			// Render new data
			visualization.renderDisplay();
		}
	}

	// Clean everything up
	visualization.cleanUp();
        
	// delete scene;
	// delete splash;
	
	return 0;
}
Esempio n. 11
0
   // ----------------------------------------------------------------------
   void
   SingleSnapshotTask::
   run( shawn::SimulationController& sc )
      throw( std::runtime_error )
   {
      VisualizationTask::run(sc);

      double t = sc.environment().optional_double_param("time",0.0);
      int dr = sc.environment().optional_int_param("draft",0);

	   WriterFactoryHandle wfh = sc.keeper_by_name_w<WriterKeeper>("WriterKeeper")
		   ->find_w(sc.environment().optional_string_param("writer", "pdf"));
	   Writer* wr = wfh->create();

      wr->set_draft(dr);
      wr->pre_write( visualization(), sc.environment().optional_string_param("filename", "snapshot"), false );
      wr->write_frame( t );
      wr->post_write();

      delete wr;
   }
Esempio n. 12
0
void Hdd::themeChanged()
{
    foreach (const QString& source, connectedSources()) {
        applyTheme(qobject_cast<Plasma::Meter*>(visualization(source)));
    }
Esempio n. 13
0
   // ----------------------------------------------------------------------
   void
   RefreshLiveviewEvent::
   write_frame()
      throw( std::runtime_error )
   {
      double t = 0.0;
      unsigned char* texture_ = getTexture();
      const Camera& cam = visualization().camera();
      bool freezed = cam.cam_properties().freeze(t)>.5;
      cairo_surface_t* surface_;

      if( (!freezed) )
         {
            int w = int(ceil(cam.width(t)));
            int h = int(ceil(cam.height(t)));

            if( (w<5) || (h<5) )
               {
                  std::ostringstream oss;
                  oss << "Picture dimension too small: "
                      << w << "x" << h;
                  throw std::runtime_error(oss.str());
               }

            double scale = cam.scale(t);
            if( scale < EPSILON )
               {
                  std::ostringstream oss;
                  oss << "Scale too small: " << scale;
                  throw std::runtime_error(oss.str());
               }

            shawn::Vec cam_pos = cam.position(t);
            shawn::Vec cam_pos_shift = cam.position_shift(t);

            // ALLOC SURFACE
            // make_surface(w,h);
            surface_ =
               cairo_image_surface_create_for_data ( texture_,
                                                     CAIRO_FORMAT_ARGB32,
                                                     w,h,
                                                      w*4);


            // CLEAR
            shawn::Vec cam_bg = cam.background(t);
            cairo_t* cr = cairo_create(surface_);
            cairo_rectangle (cr, 0, 0, w, h);
            cairo_set_source_rgb (cr,cam_bg.x(),cam_bg.y(),cam_bg.z());
            cairo_fill (cr);

            shawn::Vec trans( (-cam_pos.x()*scale) + (double(w)/2.0) + cam_pos_shift.x(),
                              (-cam_pos.y()*scale) - (double(h)/2.0) - cam_pos_shift.y() );

            Context C(trans/scale,scale,w,h, 0);

            cairo_save(cr);
            // TRANSFORMATION
            cairo_translate( cr, trans.x(), -trans.y() );
            cairo_scale(cr,scale,-scale);

            //
            visualization().draw(cr,t,C);

            cairo_restore(cr);

            cairo_destroy (cr);
      }
   }
Esempio n. 14
0
void TextCursor::setVisualizationSize(const QSize& size)
{
	CursorShapeItem* ci = static_cast<CursorShapeItem*> (visualization());
	ci->setCursorSize(size);
}
Esempio n. 15
0
bool task3_5(const cv::Mat& image, const cv::Mat& orig) {
    cv::Mat grey, tmp, res;
    image.copyTo(grey);
    grey.convertTo(grey, CV_32F);

    grey.copyTo(res);
    res.convertTo(res, CV_8U);
    std::vector<cv::Mat> planes(2, cv::Mat());
    std::vector<cv::Mat> polar(2, cv::Mat());

    cv::dft(grey, tmp, cv::DFT_COMPLEX_OUTPUT);
    cv::split(tmp, planes);
    cv::cartToPolar(planes[0], planes[1], polar[0], polar[1]);

    int cx = polar[0].cols / 2;
    int cy = polar[0].rows / 2;
    cv::Point max;

    cv::Mat top = polar[0].rowRange(0, cx);
    cv::Mat bot = polar[0].rowRange(cx, polar[0].rows);

    int row = 0;
    do {
        cv::minMaxLoc(top.rowRange(row++, top.rows), 0, 0, 0, &max);
    } while (max.x == 0);


    int r = 3;

    cv::Mat noizeCol = polar[0].colRange(max.x - r, max.x + r);
    cv::Mat noizeRow = polar[0].rowRange(max.y - r, max.y + r);
    cv::Mat blurCol = polar[0].colRange(max.x - 12, max.x - 12 + 2 * r);
    cv::Mat blurRow = polar[0].rowRange(max.y - 3 * r, max.y - r);

    blurCol.copyTo(noizeCol);
    blurRow.copyTo(noizeRow);


    cv::Mat noizeColB = polar[0].colRange(polar[0].cols - max.x - r, polar[0].cols - max.x + r);
    cv::Mat noizeRowB = polar[0].rowRange(polar[0].rows - max.y - r, polar[0].rows - max.y + r);

    blurCol.copyTo(noizeColB);
    blurRow.copyTo(noizeRowB);

    cv::Mat roi = polar[0];
    cv::Mat mean, stddev, tmp1;
    roi = roi.colRange(max.x + 20, roi.cols - max.x - 20).rowRange(max.y + 20, roi.cols - max.y - 20);
    for (int i = 0; i < roi.rows; ++i) {
        cv::Mat row = roi.row(i);
        cv::meanStdDev(row, mean, stddev);
        float m = mean.at<double>(0, 0);
        float st = stddev.at<double>(0, 0);
        for (Mfit mfit = row.begin<float>(); mfit != row.end<float>(); ++mfit) {
            if (*mfit > m + 1.5 * st) {
                *mfit = 0.5 * m;
            }
        }
    }
    visualization(polar[0], tmp);

    //    
    //    
    //    cv::namedWindow("Lesson 2", CV_WINDOW_NORMAL);
    //    cv::imshow("Lesson 2", tmp);
    //    cv::waitKey(0);


    cv::polarToCart(polar[0], polar[1], planes[0], planes[1]);
    cv::merge(planes, tmp);
    cv::dft(tmp, tmp, cv::DFT_SCALE | cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT);



    tmp.convertTo(tmp, CV_8U);



    cv::Mat lut(1, 256, CV_32F, cv::Scalar(0));
    for (int i = 0; i < 256; ++i) {
        lut.at<float>(0, i) = i;
    }

    for (int i = 65; i < 200; ++i) {
        lut.at<float>(0, i) = i - 30;
    }
    
    for (int i = 200; i < 220; ++i) {
        lut.at<float>(0, i) = i - 20;
    }
    
    lut.convertTo(lut, CV_8U);

    tmp.convertTo(tmp, CV_8U);

    cv::normalize(tmp, tmp, 0, 255, cv::NORM_MINMAX);
    
    cv::LUT(tmp, lut, tmp);


    cv::GaussianBlur(tmp, tmp, cv::Size(3, 3), 1);
    cv::medianBlur(tmp, tmp, 3);
    cv::Mat result;
    cv::matchTemplate(orig, tmp, result, CV_TM_SQDIFF);
    std::cout << "RMSE Task 3.5: " << result / (orig.cols * orig.rows) << std::endl;

    concatImages(res, tmp, res);
    cv::absdiff(tmp, orig, tmp);
    concatImages(res, tmp, res);

    cv::absdiff(image, orig, tmp);
    concatImages(res, tmp, res);
    concatImages(res, orig, res);

//    cv::namedWindow("Lesson 2", CV_WINDOW_NORMAL);
//    cv::imshow("Lesson 2", res);
//    cv::waitKey(0);

    return cv::imwrite(PATH + "Task3_5.jpg", res);
}