Exemplo n.º 1
0
void LadybugWidget::navigationMousePress(QMouseEvent* e)
{
  QRect arrowRect = QRect(QPoint(-5, 0), QPoint(5, -10));

  QPoint centerPt = NAVIGATION_RECT.center();
  QMatrix m;
  m.translate(centerPt.x(), centerPt.y());

  for (int i = 0; i < 5; i++)
  {
    QMatrix m2 = m;
    m2.rotate(i*360/5);
    m2.translate(0,-16);

    QPoint resPt = m2.inverted().map(e->pos());
    if (arrowRect.contains(resPt))
    {
      // invert camera on/off setting
      setCameraState(i, !cameraState(i));

      if (mPaused)
        updateVideo(getSingleFrame(mCurrentFrame));
    }
  }
}
Exemplo n.º 2
0
void LadybugWidget::wheelEvent(QWheelEvent* e)
{
  for (int cam = 0; cam < CAMERAS; cam++)
  {
    QRect r = cameraRect(cam);
    if (r.contains(e->pos()))
    {
      QPointF oldOffset;
      double oldZoom = cameraZoom(cam, &oldOffset);
      // negative = zoom in
      const double FACTOR = 1.25;
      double zoom = oldZoom * (e->delta() > 0 ? 1/FACTOR : FACTOR);
      if (zoom < 1) zoom = 1;
      if (zoom > 4) zoom = 4;
      if (zoom == oldZoom) return;

      QPointF pos = (e->pos()-r.topLeft())/oldZoom;
      QPointF newPos = pos * oldZoom/zoom;
      QPointF offset = oldOffset + pos - newPos;

      printf("delta %d | pos %.1f,%.1f | new_pos %.1f,%.1f | zoom %.2f | offset %.1f,%.1f\n", e->delta(), pos.x(),pos.y(), newPos.x(), newPos.y(), zoom, offset.x(), offset.y());

      setCameraZoom(cam, zoom, offset);
      if (mPaused)
        updateVideo(getSingleFrame(mCurrentFrame));
      break;
    }
  }

}
Exemplo n.º 3
0
void LadybugWidget::mousePressEvent(QMouseEvent* e)
{
  if (NAVIGATION_RECT.contains(e->pos()))
  {
    // handle navigation
    navigationMousePress(e);
  }
  else
  {
    // handle images from cameras

    // we're interested only to right click - reset zoom
    if (e->button() != Qt::RightButton)
      return;

    for (int i = 0; i < CAMERAS; i++)
    {
      if (cameraRect(i).contains(e->pos()))
      {
        setCameraZoom(i, 1);
        if (mPaused)
          updateVideo(getSingleFrame(mCurrentFrame));
        break;
      }
    }
  }
}
Exemplo n.º 4
0
void LadybugWidget::pause()
{
  mPaused = !mPaused;

  if (mPaused)
  {
    mTimer.stop();
    mPlaybackStartTime = QTime();

    // terminate thread
    stopPlayerThread();

    // make sure we're where we paused the video
    updateVideo(getSingleFrame(mCurrentFrame));
  }
  else
  {
    // create thread, pass the stream
    mThread = new LadybugPlayerThread(mStream);
    mThread->setCameras(cameraMask());
    mThread->start();

    // in update routine: show frame + get next frame + run timer
    updateVideoPlayback();
  }

  if (mPauseButton)
    mPauseButton->setText(mPaused ? "|>" : "||");
}
void GameStateConfigDesktop::update() {
	GameStateConfigBase::update();

	updateVideo();
	updateInput();
	updateKeybinds();
}
Exemplo n.º 6
0
void VideoEditor::saveVideo(){

    updateVideo();
    workspace::Workspace::getInstance()->save_note("video",video->getId());
    QMessageBox::information(this, "Save","Your video has been saved.");
    ui->pushButtonSave->setEnabled(false);

    ui->pushButtonDelete->setEnabled(true);
}
Exemplo n.º 7
0
void LadybugWidget::seekToTime(uint msecs)
{
  mStream.seekToTime(msecs);
  int frameId = mStream.currentFrame();
  printf("frame id: %d\n", frameId);

  if (mPaused)
  {
    updateVideo(getSingleFrame(frameId));
  }
  else
  {
    //mThread->seekToFrame(frameId);
    pause();
    updateVideo(getSingleFrame(frameId));
    pause();
  }
  update();
}
Exemplo n.º 8
0
void LadybugWidget::seekToFrame(int frameId)
{
  if (frameId < 0)
    frameId = 0;

  if (frameId == mCurrentFrame)
    return;

  printf("SEEK! %d\n", frameId);

  if (mPaused)
  {
    updateVideo(getSingleFrame(frameId));
  }
  else
  {
    //mThread->seekToFrame(frameId);
    pause();
    updateVideo(getSingleFrame(frameId));
    pause();
  }
  update();
}
Exemplo n.º 9
0
bool LadybugWidget::openStream(QString baseName)
{
  bool res = mStream.openForReading(baseName);
  if (!res)
    return false;
  if (mSlider)
    mSlider->setRange(0, mStream.framesCount()-1);

  // show first frame
  LadybugPlayerFrame f = getSingleFrame(0);
  mStartTime = f.time;
  updateVideo(f);

  return true;
}
Exemplo n.º 10
0
void LadybugWidget::keyPressEvent(QKeyEvent* e)
{
  if (e->key() >= Qt::Key_1 && e->key() <= Qt::Key_5)
  {
    int i = e->key()-Qt::Key_1;

    // invert camera on/off setting
    setCameraState(i, !cameraState(i));

    if (mPaused)
      updateVideo(getSingleFrame(mCurrentFrame));
  }

  switch (e->key())
  {
    case Qt::Key_Space:
      pause();
      break;
    case Qt::Key_Left:
      seekToFrame(mCurrentFrame-1);
      break;
    case Qt::Key_Right:
      seekToFrame(mCurrentFrame+1);
      break;
    case Qt::Key_Home:
      seekToFrame(0);
      break;
    case Qt::Key_End:
      seekToFrame(mStream.framesCount()-1);
      break;
    case Qt::Key_PageUp:
      seekToFrame(mCurrentFrame-25);
      break;
    case Qt::Key_PageDown:
      seekToFrame(mCurrentFrame+25);
      break;

    // %%% seek to random position (for testing)
    case Qt::Key_S:
      {
        uint msecs = rand() % (mStream.framesCount() / 15 * 1000);
        printf("RANDOM TIME SEEK! %d ms\n", msecs);
        seekToTime(msecs);
        break;
      }
  }
}
Exemplo n.º 11
0
void LadybugWidget::updateVideoPlayback()
{
  if (mPlaybackStartTime.isNull())
  {
    // we're starting playback
    mPlaybackStartTime.start();
    mPlaybackFirstFrameTime = mCurrentTime;
  }
  else
  {
    // draw prepared frame
    updateVideo(*mNextFrame);
  }

  // get next frame
  *mNextFrame = mThread->getFrame();

  if (mNextFrame->frameId == -1)
  {
    // the thread has finished... we're pausing!
    pause();
    return;
  }

  // find out waiting time + run timer
  int timeElapsed = mPlaybackStartTime.elapsed();
  int timeNext = (mNextFrame->time - mPlaybackFirstFrameTime);
  int waitTime = timeNext-timeElapsed;
  printf("wait time %d\n", waitTime);

  // make sure we set a valid interval
  if (waitTime <= 0)
    waitTime = 1;

  mTimer.start(waitTime);
}
Exemplo n.º 12
0
void MC6845::scheduleTimer(OESLong cycles)
{
    updateVideo();
    
    if (imageModified)
    {
        imageModified = false;
        
        if (videoEnabled)
            postImage();
    }
    
    if ((powerState == CONTROLBUS_POWERSTATE_ON) && blinkEnabled)
    {
        blinkCount++;
        
        if (blinkCount >= blinkFrameNum)
        {
            blink = !blink;
            blinkCount = 0;
            
            refreshVideo();
        }
    }
    
    controlBus->postMessage(this, CONTROLBUS_GET_CYCLES, &frameStart);
    frameStart += cycles;
    
    ControlBusTimer timer = { cycles + ceil(frameCycleNum / clockMultiplier), 0 };
    controlBus->postMessage(this, CONTROLBUS_SCHEDULE_TIMER, &timer);
    
    if (frameStartAddress.w.l != startAddress.w.l)
        refreshVideo();
    
    frameStartAddress.w = startAddress.w;
}
Exemplo n.º 13
0
//--------------------------------------------------------------
void testApp::update(){
	 
    
    
    //Check for new text message
	
	char textMessage[100000];
	textMessageConnection.Receive(textMessage, 100000);
	
	if (textMessage[0] != 0) {
        
			string grt = textMessage;
            messages.push_back(grt);
		    messageSent.push_back(0);
            messagePositions.push_back(0);
			
	}
	
	//Check for new trigger message
	char triggerInMessage[10];
	triggerInConnection.Receive(triggerInMessage, 10);
	int tm;
	
	tm = atoi(triggerInMessage);  //Char to Int

	if (tm == 1 || tm == 3 || tm == 4 || tm == 5) { //Show State Trigger
		//showState += 1;
	    showState = tm;
     }
	
    
	if (tm == 6){  //Record Trigger
		record = 1;
		
	}
    
	if (tm == 7){ 
        getBackground = true;
    }
	
    
	
	//Show management
	if (showState > 4) {  // Check at beginning of update because multiple functions use this
		showState = 0;
	}
		
	
	if (showState == 0 ) {
		
		hold = 0;   
		end = 0;	
		play = 0;
		
		messages.clear();
        messagePositions.clear();
		messageSent.clear();
		
    }
    
    
	//Reset show variables
	if (showState == 1) {
        
        
        
        messages.clear();
        messagePositions.clear();
        
        for(int i = 0; i < flock.boids.size(); i ++){
			
			flock.boids[i].setLoc(ofVec2f(ofRandom(-100, -700),ofRandom(200,700)));
			
		}
		
		if (showBoidsHead > nrDisplaySequences) {
		
			showBoidsTail = showBoidsHead - nrDisplaySequences;
		
		}
		
		showBoids = true;
		
		showState += 1;          
		
	
	}
	
	//Bring flock of video onscreen
	if (showState == 2) {  
		
		play = 1;
		
		if (pan < 0) {
			pan -= pan/100;
		}
        
	}
	
	//Flock flies around
	if (showState == 3) {  
		
        hold = 1;
        
	}
	
	//Flock leaves screen
	if (showState == 4) {  
		
        if(pan < ofGetWidth()){
            pan += pan/100;
        }
        
        if (pan > ofGetWidth()) {
            
            showState+= 1;
            
        }
        
        showBoids = false;
        
	}
	
	updateVideo();
	
}
Exemplo n.º 14
0
//--------------------------------------------------------------
void ofxThreadedVideo::threadedFunction(){

    while (isThreadRunning()){

        if(lock()){

            // if there's a movie to load...
            if(loadPath != ""){

                loadVideoID = getNextLoadID();

                paths[loadVideoID] = loadPath;
                loadPath = "";
#ifdef TARGET_OSX
                vector<string> pathParts = ofSplitString(paths[loadVideoID], "/");
#else
                vector<string> pathParts = ofSplitString(paths[loadVideoID], "\\");
#endif
                names[loadVideoID] = pathParts[pathParts.size() - 1];

                // using a static mutex blocks all threads (including the main app) until we've loaded
                ofxThreadedVideoMutex.lock();

                // load that movie!
                if(videos[loadVideoID].loadMovie(paths[loadVideoID])){

                    ofLogVerbose() << "Loaded" << names[loadVideoID] << " " << loadVideoID;

                    // start rolling if AutoPlay is true
                    if (bUseAutoPlay) videos[loadVideoID].play();

                    // set pixel refs
                    pixels[loadVideoID] = &videos[loadVideoID].getPixelsRef();

                }else{

                    ofLogVerbose() << "Could not load video";
                    loadVideoID = VIDEO_NONE;

                    // send event notification
                    ofxThreadedVideoEvent videoEvent = ofxThreadedVideoEvent(paths[loadVideoID], VIDEO_EVENT_LOAD_FAIL, this);
                    ofNotifyEvent(threadedVideoEvent, videoEvent, this);
                }


                ofxThreadedVideoMutex.unlock();

            }

            // do threaded update of videos
            updateVideo(currentVideoID);
            updateVideo(loadVideoID);

            unlock();

            // sleep a bit so we don't thrash the cores!!
            ofSleepMillis(1000/30); // TODO: implement target frame rate? US might need 30 here?

        }
    }
}
Exemplo n.º 15
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    _marker_detector.setMinMaxSize(0.0001,0.5);

    ui->cameraResolutionComboBox->addItem("640x480");
    ui->cameraResolutionComboBox->addItem("1920x1080");

    _serial_port = new QSerialPort();
    refreshSerialPortOptions();
    connect(ui->serialConnectButton,SIGNAL(clicked()),SLOT(updateSerialPort()));
    connect(ui->serialDisconnectButton,SIGNAL(clicked()),SLOT(disconnectSerialPort()));
    connect(_serial_port,SIGNAL(readyRead()),SLOT(receiveData()));
    connect(ui->sendSerialDataButton,SIGNAL(clicked()),SLOT(sendTextEditSerialData()));
    connect(ui->sendSerialDataLineEdit,SIGNAL(returnPressed()),SLOT(sendTextEditSerialData()));
    connect(ui->refreshSerialOptionsButton,SIGNAL(clicked()),SLOT(refreshSerialPortOptions()));
    loadDefaultSettings();
    //applySettings();

    //Timer connects to the kcamera object to call grabFrame every 30 milliseconds
    _timer = new QTimer(this);
    connect(_timer,SIGNAL(timeout()),SLOT(update()));
    _timer->start(20);

    //Update video every 20ms
    QTimer* video_timer = new QTimer(this);
    connect(video_timer,SIGNAL(timeout()),SLOT(updateVideo()));
    video_timer->start(20);

    connect(ui->applySettingsButton,SIGNAL(clicked()),SLOT(applySettings()));

    QFileDialog* file_dialog = new QFileDialog();
    connect(file_dialog,SIGNAL(fileSelected(QString)),ui->calibrationFileLineEdit,SLOT(setText(QString)));
    connect(ui->browseCalibrationFileButton,SIGNAL(clicked()),file_dialog,SLOT(open()));

    //Connections for selecting view (image/2D trace)
    connect(ui->viewSelectComboBox,SIGNAL(currentIndexChanged(QString)),SLOT(selectView(QString)));

    connect(ui->saveSentDataButton,SIGNAL(clicked()),SLOT(saveSentData()));
    connect(ui->clearSentDataButton,SIGNAL(clicked()),SLOT(clearSentData()));

    ui->markerTracePlot->addGraph();
    ui->markerTracePlot->graph(0)->addData(1.5,1.5);

    ui->markerTracePlot->graph(0)->addData(1.9,1.9);
    ui->markerTracePlot->graph(0)->addData(1.5,1.9);
    ui->markerTracePlot->graph(0)->setScatterStyle(QCPScatterStyle::ssCross);
    ui->markerTracePlot->replot();

    _running = false;
    _frame_count = 0;
    connect(ui->startRunButton,SIGNAL(clicked()),this,SLOT(startRun()));
    connect(ui->stopRunButton,SIGNAL(clicked()),this,SLOT(stopRun()));

    _received_data_max_length = 1000;
    _sent_data_max_length = 1000;

    //Camera Sliders
    connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBrightness(int)));
    connect(ui->sharpnessSlider, SIGNAL(valueChanged(int)), this, SLOT(updateSharpness(int)));
    connect(ui->autofocusCheckbox, SIGNAL(toggled(bool)), this, SLOT(updateAutoFocus(bool)));
    connect(ui->focusSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFocus(int)));
}
Exemplo n.º 16
0
void MC6845::refreshVideo()
{
    updateVideo();
    
    pendingCycles = frameCycleNum;
}