示例#1
0
文件: projection.C 项目: baku89/4DVJ
int Projector::select (int X, int Y)
{
    if (in_stereo) { //select viewport
        if (X > W) { //left side
            X -= static_cast<int>(W);
            drawing->reproject(animator->twist_theta(TWIST_ANGLE));
        } else {
            drawing->reproject(animator->twist_theta(-TWIST_ANGLE));
        }
    }

    float x = convert_x(X);
    float y = convert_y(Y);
    return drawing->select(x,y);
}
// ------------------------------------------------------------------------
double f(const std::vector<double> &x, std::vector<double> &grad, void *f_data)
{
    OptData *data = (OptData*) f_data;

    VectorType point, normal;

    convert_x(x, point, normal);

    for(unsigned int i = 0; i < 5; i++)
    {
        std::cout << x[i] << " ";
    }
    std::cout << "\n";

    PlaneMeasurementType mv;
    for(unsigned int i = 0; i < 3; i++)
    {
        mv[i] = point(i);
        mv[i+3] = normal(i);
    }

    PlaneMembershipType::Pointer planeMember = PlaneMembershipType::New();
    planeMember->SetMean(data->planeMember->GetMean());
    planeMember->SetCovariance(data->planeMember->GetCovarianceMatrix());

    double planeProb = planeMember->Evaluate(mv);
    double planeCost = -log(std::max(planeProb, 0.00000001));


    grad.clear();


    double val = imageCost(data->params, data->testData, point, normal, data->classifiers, data->lengths, false);
    double total = val;
    std::cout << "Plane: " << planeCost << std::endl;
    std::cout << "val: " << val << std::endl;
    std::cout << "Total: " << total << std::endl;
    std::cout << "---------------------------------" << std::endl;
    return total;

}
示例#3
0
static int PeMGetEvent(PeMData *event){
	
     PeMReadPacket(event->fd, packet);
     /* Sync bit always must be set to 1 */
     if ((*packet & PeM_PANEL_SYNC_MASK) == 0)
          return 0;
     
     if (*packet & PeM_PANEL_TOUCH_MASK)
          event->action = PEM_PANEL_TOUCH;
     else
          event->action = PEM_PANEL_UNTOUCH;
          
	 event->y = convert_y( WORD_ASSEMBLY(packet[2], packet[1]),event);
	 event->x = convert_x( WORD_ASSEMBLY(packet[4], packet[3]),event);

     if (event->min_x)
          event->x = event->min_x - event->x;
     if (event->min_y)
          event->y = event->min_y - event->y;

     return 1;
}
示例#4
0
bool
seqdata::on_motion_notify_event (GdkEventMotion * ev)
{
    bool result = false;
#ifdef USE_STAZED_SEQDATA_EXTENSIONS
    if (m_drag_handle)
    {
        m_current_y = int(ev->y = 3);
        m_current_y = c_dataarea_y - m_current_y;
        if (m_current_y < 0)
            m_current_y = 0;

        if (m_current_y > SEQ64_MAX_DATA_VALUE)             /* 127 */
            m_current_y = SEQ64_MAX_DATA_VALUE;

        m_seq.adjust_data_handle(m_status, m_current_y);
        update_pixmap();
        draw_events_on(m_window);
    }
#endif
    if (m_dragging)
    {
        int adj_x_min, adj_x_max, adj_y_min, adj_y_max;
        m_current_x = int(ev->x) + m_scroll_offset_x;
        m_current_y = int(ev->y);
        if (m_current_x < m_drop_x)
        {
            adj_x_min = m_current_x;
            adj_y_min = m_current_y;
            adj_x_max = m_drop_x;
            adj_y_max = m_drop_y;
        }
        else
        {
            adj_x_max = m_current_x;
            adj_y_max = m_current_y;
            adj_x_min = m_drop_x;
            adj_y_min = m_drop_y;
        }

        midipulse tick_s, tick_f;
        convert_x(adj_x_min, tick_s);
        convert_x(adj_x_max, tick_f);
        result = m_seq.change_event_data_range
        (
            tick_s, tick_f, m_status, m_cc,
            c_dataarea_y - adj_y_min - 1, c_dataarea_y - adj_y_max - 1
        );
        update_pixmap();                /* calls draw_events_on_pixmap()    */
        draw_events_on(m_window);
        draw_line_on_window();

        /*
         * \change ca 2016-06-19
         *  Why do we modify here?
         *
         *  if (result)
         *      perf().modify();
         */
    }
    return result;
}
示例#5
0
文件: perfroll.cpp 项目: Stazed/seq32
bool
perfroll::on_key_press_event(GdkEventKey* a_p0)
{
    if (a_p0->keyval == m_mainperf->m_key_pointer)         /* Move to mouse position */
    {
        int x = 0;
        int y = 0;

        long a_tick = 0;

        get_pointer(x, y);
        if(x < 0)
            x = 0;
        snap_x(&x);
        convert_x(x, &a_tick);

        if(m_mainperf->is_jack_running())
        {
            m_mainperf->set_reposition();
            m_mainperf->set_starting_tick(a_tick);
            m_mainperf->position_jack(true, a_tick);
        }
        else
        {
            m_mainperf->set_reposition();
            m_mainperf->set_starting_tick(a_tick);
        }

        return true;
    }

    bool ret = false;

    if ( m_mainperf->is_active( m_drop_sequence))
    {
        if ( a_p0->type == GDK_KEY_PRESS )
        {
            if ( a_p0->keyval ==  GDK_Delete || a_p0->keyval == GDK_BackSpace )
            {
                m_mainperf->push_trigger_undo(m_drop_sequence);
                m_mainperf->get_sequence( m_drop_sequence )->del_selected_trigger();

                ret = true;
            }

            if ( a_p0->state & GDK_CONTROL_MASK )
            {
                /* cut */
                if ( a_p0->keyval == GDK_x || a_p0->keyval == GDK_X )
                {
                    m_mainperf->push_trigger_undo(m_drop_sequence);
                    m_mainperf->get_sequence( m_drop_sequence )->cut_selected_trigger();
                    ret = true;
                }
                /* copy */
                if ( a_p0->keyval == GDK_c || a_p0->keyval == GDK_C )
                {
                    m_mainperf->get_sequence( m_drop_sequence )->copy_selected_trigger();
                    ret = true;
                }

                /* paste */
                if ( a_p0->keyval == GDK_v || a_p0->keyval == GDK_V )
                {
                    m_mainperf->push_trigger_undo(m_drop_sequence);
                    m_mainperf->get_sequence( m_drop_sequence )->paste_trigger();
                    ret = true;
                }
            }
        }
    }

    if ( ret == true )
    {
        fill_background_pixmap();
        queue_draw();
        return true;
    }
    else
        return false;
}
示例#6
0
int main(int argc, char ** argv)
{
	const std::string patchParamsFilename = argv[1];
	const std::string testDataFilename = argv[2];
	const std::string valveDataFilename = "/home/om0000/ValveTracking/TrainingData/MV-Planes.hdf5";
	PatchParams params(patchParamsFilename);

	TestData::Pointer testData = TestData::Initialise(testDataFilename);
	LengthData::Pointer lengthData = LengthData::Load("/home/om0000/ValveTracking/TrainingData/Lengths");
	lengthData->Prepare(testData->GetId());

	std::cout << "Loading Plane Data" << std::endl;
	ValveTrainingData::Pointer valveData = ValveTrainingData::Load(valveDataFilename);


	std::cout << "Loading PatchData" << std::endl;
	//PatchTrainingData::Pointer patchData = PatchTrainingData::Load(patchParamsFilename);
	PatchTrainingData::Pointer patchData = PatchTrainingData::New();

	VectorType startPoint, startNormal;


	for(unsigned int runs = 0; runs < 1; runs++)
	{
		
		for(params.timeStep = 0; params.timeStep < params.numberOfTimeSteps; params.timeStep++)
		{


			std::cout << "Working on: " << params.timeStep << std::endl;


			// load the input points and create the bounding box
			MatrixType pointsData;
			valveData->GetTrainingPoints(testData->GetId(), params.timeStep, pointsData);
			
			std::vector<MatrixType> pointsData2;
			valveData->GetTrainingPoints(testData->GetId(), params.timeStep, pointsData2);


			vtkBoundingBox boundingBox;


			computeBoundingBox(pointsData, boundingBox);


			std::cout << "Loading / Training Classifiers" << std::endl;
			ClassifierMap classifiers;
			loadOrTrainClassifiers(params, 1000, patchData, classifiers);



			testData->Prepare(params.timeStep, boundingBox);
			testData->SaveImageGroup("2C", "MV-2C");


			// compute the distribution for the plane and get the mean for initialisation
			MatrixType planeData;
			valveData->GetTrainingData(testData->GetId(), params.timeStep, planeData);
			PlaneCovarianceFilterType::Pointer planeDistribution = PlaneCovarianceFilterType::New();
			computePlaneCovariance(planeData, planeDistribution);


			TestData::VectorType point, normal;

			if(params.timeStep == 0 && runs == 0)
			{
				for(unsigned int i = 0; i < 3; i++)
				{
					point(i) = planeDistribution->GetMean()[i];
					normal(i) = planeDistribution->GetMean()[i+3];
				}
				//startingPlane(pointsData2, point, normal);
			}
			else
			{
				point = startPoint;
				normal = startNormal;
			}

			OptData * optData = new OptData;
			optData->testData = testData;
			optData->classifiers = classifiers;
			optData->params = params;
			optData->lengths = lengthData;
			optData->planeMember = planeDistribution;




			nlopt::opt opt(nlopt::LN_BOBYQA, 5);
			opt.set_min_objective(f, (void*) optData);
			opt.set_xtol_rel(1e-4);
			opt.set_maxeval(100);


			std::vector<double> initStep(5);
			double pointStep = atof(argv[3]);
			double normalStep = atof(argv[4]);
			for(unsigned int i = 0; i < 3; i++)
			{
				initStep[i] = pointStep;
			}

			initStep[3] = normalStep;
			initStep[4] = normalStep;

			opt.set_default_initial_step(initStep);

			std::vector<double> xStart;
			convert_plane(point, normal, xStart);

			double minf;
			nlopt::result result = opt.optimize(xStart,minf);
			std::cout << "Final: " << result << std::endl;

			MatrixType initialPlane(1,6), finalPlane(1,6);
			VectorType finalPoint, finalNormal;
			convert_x(xStart, finalPoint, finalNormal);


			imageCost(params, testData, finalPoint, finalNormal, classifiers, lengthData, true);


			for(unsigned int i = 0; i < 3; i++)
			{
				finalPlane(0,i) = finalPoint(i);
				finalPlane(0,i+3) = finalNormal(i);
			}


			std::cout << finalPlane << std::endl;
			for(unsigned int i = 0; i < 6; i++)
			{
				initialPlane(0,i) = planeDistribution->GetMean()[i];
			}

			startPoint = finalPoint;
			startNormal = finalNormal;


			MatrixType gt;
			valveData->GetTestData(testData->GetId(), params.timeStep, gt);
			VectorType gtPoint, gtNormal;
			for(unsigned int i = 0; i < 3; i++)
			{
				gtPoint(i) = gt(0,i);
				gtNormal(i) = gt(0,i+3);
			}



			std::vector<ImageType::Pointer> vimages;
			testData->GetImages(vimages);
			ResultViewer::Pointer viewer = ResultViewer::New();
			viewer->SetImages(vimages);
			viewer->SetBoundingBox(boundingBox);
			viewer->SetPlane(finalPoint, finalNormal);
			viewer->SetStartPlane(gtPoint, gtNormal);
			viewer->SetUp();

			std::stringstream ss; 
			ss << params.name << "/" << testData->GetId() << "-" << params.timeStep << "-image.png";

			viewer->Save(ss.str());
			//viewer->View();

			//testData->SaveImageGroup("2C", "2C");
			//testData->SaveImageGroup("3C", "3C");
			//testData->SaveImageGroup("4C", "4C");
			//savePlane(initialPlane, "initialPlane.vtk");
			//savePlane(finalPlane, "finalPlane.vtk");
			

		}

	}






	return 0;
}