Exemplo n.º 1
0
double compareSpatiograms(const spatiogram &p, const spatiogram &q ){
    CV_Assert(p.bins==q.bins);

    cv::Mat temp = cv::Mat::zeros(1, p.bins, CV_64FC1);
    cv::Mat w = cv::Mat::zeros(1, p.bins, CV_64FC1);

    for (int i=0; i<p.bins; i++){
        // Means
        cv::Mat ub1(2,1,CV_64FC1);
        ub1.at<double>(0,0)=p.mu.at<double>(0,i);
        ub1.at<double>(1,0)=p.mu.at<double>(1,i);
        cv::Mat ub2(2,1,CV_64FC1);
        ub2.at<double>(0,0)=q.mu.at<double>(0,i);
        ub2.at<double>(1,0)=q.mu.at<double>(1,i);
        // covariances in matrix format and clipped to 1
        cv::Mat cm1=cv::Mat::ones(2,2,CV_64FC1);
        cm1.at<double>(0,0) += p.cm.at<double>(0,i);
        cm1.at<double>(1,1) += p.cm.at<double>(1,i);
        cv::Mat cm2=cv::Mat::ones(2,2,CV_64FC1);
        cm2.at<double>(0,0) += q.cm.at<double>(0,i);
        cm2.at<double>(1,1) += q.cm.at<double>(1,i);
        // weightening factor
        cv::Mat invS = cm1.inv(cv::DECOMP_LU) + cm2.inv(cv::DECOMP_LU);
        cv::Mat diff = ub2-ub1;
        cv::Mat expo = (-0.5)*diff.t()*invS*diff;
        w.at<double>(0,i) = std::exp( expo.at<double>(0,0) );
        // Bhattacharyya coefficient
        double rho = sqrt( p.cd.at<double>(0,i)*q.cd.at<double>(0,i) );
        temp.at<double>(0,i) = (w.at<double>(0,i)) * rho;
    }
    return cv::sum(temp)[0];
}
Exemplo n.º 2
0
  ExecStatus
  SuperOfInter<View0,View1,View2>::propagate(Space& home, const ModEventDelta& med) {

    bool allassigned = x0.assigned() && x1.assigned() && x2.assigned();

    ModEvent me0 = View0::me(med);
    ModEvent me1 = View1::me(med);
    ModEvent me2 = View2::me(med);

    bool modified = false;

    do {
      // glb(x2) >= glb(x0) ^ glb(x1)
      if ( modified || Rel::testSetEventLB(me0,me1)) {
        GlbRanges<View0> lb0(x0);
        GlbRanges<View1> lb1(x1);
        Iter::Ranges::Inter<GlbRanges<View0>,GlbRanges<View1> >
          is(lb0, lb1);

        GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is));
      }

      // lub(x0) -= glb(x1)-lub(x2)
      // lub(x1) -= glb(x0)-lub(x2)
      if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) {
         modified = false;
        GlbRanges<View1> lb12(x1);
        LubRanges<View2> ub22(x2);
        Iter::Ranges::Diff<GlbRanges<View1>, LubRanges<View2> >
          diff1(lb12, ub22);

        GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1));

        GlbRanges<View0> lb01(x0);
        LubRanges<View2> ub23(x2);
        Iter::Ranges::Diff<GlbRanges<View0>, LubRanges<View2> >
          diff2(lb01, ub23);

        GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2));
      } else {
         modified = false;
      }

      // Cardinality propagation
      if ( modified ||
            Rel::testSetEventCard(me0,me1,me2) ||
           Rel::testSetEventUB(me0,me1)
           ) {

        LubRanges<View0> ub0(x0);
        LubRanges<View1> ub1(x1);
        Iter::Ranges::Union<LubRanges<View0>, LubRanges<View1> > u(ub0,ub1);

        unsigned int m = Iter::Ranges::size(u);

        if (m < x0.cardMin() + x1.cardMin()) {
          GECODE_ME_CHECK_MODIFIED(modified,
                            x2.cardMin( home,
                                        x0.cardMin()+x1.cardMin() - m ) );
        }
        if (m + x2.cardMax() > x1.cardMin()) {
          GECODE_ME_CHECK_MODIFIED(modified,
                            x0.cardMax( home,
                                        m+x2.cardMax()-x1.cardMin() )  );
        }
        if (m + x2.cardMax() > x0.cardMin()) {
          GECODE_ME_CHECK_MODIFIED(modified,
                            x1.cardMax( home,
                                        m+x2.cardMax()-x0.cardMin() )  );
        }
      }
    } while (modified);


    if (shared(x0,x1,x2)) {
      if (allassigned) {
        return home.ES_SUBSUMED(*this);
      } else {
        return ES_NOFIX;
      }
    } else {
      if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
         return home.ES_SUBSUMED(*this);
      } else {
        return ES_FIX;
      }
    }

  }
Exemplo n.º 3
0
void test_nodeui_base(){
  
  RtAudio dac;
  RtAudio::StreamParameters parm;
  parm.deviceId = 0;//dac.getDefaultOutputDevice();
  parm.nChannels = 2;
  parm.firstChannel = 0;

  RtAudio::StreamOptions so;
  
  unsigned int bufferFrames = BUFFERSIZE;
  AudioScheduler a_sched;
  ControlScheduler c_sched;

  dac.openStream(&parm,NULL,RTAUDIO_SINT16, 44100, &bufferFrames, & saw, (void *) &a_sched);
  dac.startStream();
  
  
  init_ogl(1024,1024);
  

  GLProgram shader = make_program("shaders/naive.vert","shaders/naive.frag");
  UiBox ub1(Vec2f(-400.0,-300.0),Vec2f(800.0,600.0),{0.0,0.0,0.0,1.0},0.0,{0.0,0.0,0.0,0.0});
  
  square_vbo  = make_buffer<float>( {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}, 2,ARRAY_BUFFER, STATIC_DRAW);
  line_vbo = make_buffer<float>({0.0,0.0,1.0,1.0}, 2,ARRAY_BUFFER, STATIC_DRAW);
  float it = 0.0;
  scale =0.5;
  camera_x = 200.0;
  camera_y = -50.0;

  bool running = true;
  bool pause_proc = false;
  bool pause_ready = false;
  NodeGridInputHandler ngrid(&pause_proc, &pause_ready);;
  ngrid.backend.register_scheduler(&a_sched);
  ngrid.backend.register_scheduler(&c_sched);
  ngrid.shader = shader;
  ngrid.node_creators["osc"] = [](){return new Osc(440);};
  ngrid.node_creators["add-audio"] = [](){return new AddAudio();};
  ngrid.node_creators["audio-out"] = [](){return new AudioOut3();};
  ngrid.node_creators["line-play"] = [](){return new line_play(1.0,std::vector<float>({0.0})) ;};
  ngrid.node_creators["phasor"] = [](){return new Phasor(440) ;};
  ngrid.node_creators["multiply"] = []() {return new MultNode();};
  ngrid.node_creators["sub-audio"] = [](){return new SubAudio();};
  ngrid.node_creators["divide"] = []() {return new DivNode();};
  ngrid.node_creators["clip"] = []() {return new ClipNode();};
  ngrid.node_creators["quit-program"] = [&running](){return new QuitProgramNode(&running);};
  ngrid.node_creators["save-patch"] = [&ngrid](){return new SavePatchNode(&ngrid);};
  ngrid.node_creators["load-patch"] = [&ngrid](){return new LoadPatchNode(&ngrid);};
  Node * n1 = ngrid.create_and_insert_node("osc", Vec2f(0.0,0.0));
  Node *n2 = ngrid.create_and_insert_node("audio-out", Vec2f(0.0,50.0));
  Node *n3 = ngrid.create_and_insert_node("line-play 0.01 10 12 10 8",Vec2f(0.0,-100));
  ngrid.connect(n1,0,n2,0);
  ngrid.connect(n3,0,n1,0);
  mouse_move_spawner.register_listener(&ngrid);
  mouse_click_handler.register_listener(&ngrid);
  char_event_spawner.register_listener(&ngrid);
  key_event_handler.register_listener(&ngrid);
  mouse_wheel_event_spawner.register_listener(&ngrid);
  
  std::thread ngrid_thread([&](){
      while(running){
	
	if(pause_proc){
	  pause_ready = true;
	}else{
	  pause_ready = false;
	  ngrid.backend.update();
	}
	
      }
    });

  while(running){
    float t = get_time();
    if(ngrid.change){
      shader.uniformf("camera_scale",1.0,1.0);
      shader.uniformf("camera_translate",0.0,0.0);
      bind_buffer_object(square_vbo,0);
      shader.uniformf("size",2.0,2.0);
      shader.uniformf("pos",-1.0,-1.0);
      shader.uniformf("color",0.0,0.0,0.5,1.0);
      draw_buffers_triangle_fan(4);


      shader.uniformf("camera_scale",2.0/1024.0*scale,2.0/1024.0*scale);
      shader.uniformf("camera_translate",camera_x,camera_y);
      ngrid.draw();
      ngrid.draw2(shader);
      ngrid.change = false;
    }else{
      std::cout << "Graphics sleeping.. \n";
    }
    swapbuffers();
    std::cout << "DT: " << get_time() - t << "\n";
    float t_left = 1.0/30.0 - (get_time() - t);
    std::cout << t_left << "\n";
    if(t_left > 0){
      sleep_sec(t_left);
    }
    
  }

  ngrid_thread.join();

}
Exemplo n.º 4
0
//Construct the kdTree
kdTree::kdTree(vector<vector<double>> points, const string& method, 
			int cutdimension): 
		splitMethod(method){
	if (points.empty())
    {
    	kdTreeRoot = nullptr;
    	return;
    }
    // Select intial splitting axis
    int dimension = (int)(points[0].size());
    int axis = cutdimension % dimension;
    size_t lb1(0),lb2(0),ub1(0),ub2(0);
    size_t pivotLocation;
    size_t numpoints = points.size();
    if(numpoints == 1)
    {
    	kdTreeRoot = shared_ptr<kdTreeNode>(new kdTreeNode(points[0]));
    }
    else
    {
        sort(points.begin(), points.end(), sorter(axis));
        
    		if (method == "median")
    		{
    			pivotLocation = (size_t)(numpoints/2);
    			}
   			else if (method == "mean")
   			{
   				double mean(0.0);
   				for (size_t i=0;i<numpoints;i++)
   				{
   					mean = mean + points[i][axis];
   				}
   				mean =mean/(double)numpoints;
   				for (size_t i=0;i<numpoints;i++)
   				{
   					
   					if (points[i][axis]>= mean)
   					{
   						pivotLocation = i;
   						break;
   					}   						 
   				}

   			}
    
    /* lb1 = 0; */
    ub1 = pivotLocation;
    lb2 = pivotLocation +1;
    ub2 = (size_t)points.size();

	// Recursively create Left SubTree
 	unique_ptr<kdTree> left_child = move(unique_ptr<kdTree> (new kdTree(
 					slice<vector<double>>(points,lb1,ub1),
 										method,axis+1)));	

	// Recursively create Right SubTree
 	unique_ptr<kdTree> right_child = move(unique_ptr<kdTree> (new kdTree(
 					slice<vector<double>>(points,lb2,ub2),
 										method,axis+1)));
 	
 	kdTreeRoot = shared_ptr<kdTreeNode>(
    					new kdTreeNode(
    						points[pivotLocation],
    						axis,
    						right_child->kdTreeRoot,
    					 	left_child->kdTreeRoot));									
 	}										
}