void GameScene::update(float dt) { this->updatePhysics(dt); // Interpret collisions handleCollisions(); // Player update playerUpdate(dt); // Missile update missilesUpdate(dt); // Enemy update enemiesUpdate(dt); // Star update starsUpdate(dt); // GUI update guiUpdate(dt); if (isGameOver && time <= 10.f) { time += dt; fadeIn <Label>(mGameOverInfo, 3.f); if (time >= 5.f) { time = 1000.f; Director::getInstance()->replaceScene(TransitionFade::create(3, MenuScene::createScene(), Color3B(0, 0, 0))); return; } } }
void RealtimeWindow::Stop(int deviceStatus) // when stop button is pressed { if ((status&RT_RUNNING) == 0) return; status &= ~RT_RUNNING; startButton->setText(tr("Start")); deviceController->stop(); gui_timer->stop(); if (status & RT_RECORDING) { disk_timer->stop(); // close and reset File recordFile->close(); if(deviceStatus == DEVICE_ERROR) { recordFile->remove(); } else { // add to the view - using basename ONLY QString name; name = recordFile->fileName(); main->addRide(QFileInfo(name).fileName(), true); } } if (status & RT_STREAMING) { stream_timer->stop(); streamController->stop(); } if (status & RT_WORKOUT) { load_timer->stop(); load_msecs = 0; ergPlot->setNow(load_msecs); ergPlot->replot(); } // Re-enable gui elements recordSelector->setEnabled(true); streamSelector->setEnabled(true); deviceSelector->setEnabled(true); // reset counters etc pwrcount = 0; cadcount = 0; hrcount = 0; spdcount = 0; lodcount = 0; displayWorkoutLap = displayLap =0; lap_msecs = 0; total_msecs = 0; avgPower= avgHeartRate= avgSpeed= avgCadence= avgLoad= 0; displayWorkoutDistance = displayDistance = 0; guiUpdate(); return; }
//___________________________________________________________ // Generic Save Avi loop // //___________________________________________________________ // uint8_t GenericAviSave::saveAvi (const char *name) { uint32_t size; uint8_t ret=0; strcpy(_name,name); //frametogo = frameEnd - frameStart + 1; frametogo=0; writter = new aviWrite (); // 1- setup audio guiStart(); if (!setupAudio ()) { guiStop(); GUI_Error_HIG (QT_TR_NOOP("Error initalizing audio filters"), NULL); delete writter; writter = NULL; return 0; } if (!setupVideo (_name)) { guiStop(); GUI_Error_HIG (QT_TR_NOOP("Error initalizing video filters"), NULL); delete writter; writter = NULL; // guiStop(); return 0; } // 3- setup video frametogo=_incoming->getInfo()->nb_frames; fps1000=_incoming->getInfo()->fps1000; printf ("\n writing %lu frames\n", frametogo); //__________________________________ // now go to main loop..... //__________________________________ int frameDelay = 0; int videoSize; for (uint32_t cf = 0; cf < frametogo; cf++) { if (guiUpdate(cf, frametogo)) goto abortme; for (;;) { videoSize = writeVideoChunk(cf + frameDelay); if (videoSize == 0 && _encode && (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH)) { printf("skipping frame: %u size: %i\n", cf + frameDelay, videoSize); frameDelay++; } else break; } writeAudioChunk(cf); } ret=1; abortme: guiStop (); //__________________________________ // and end save //__________________________________ writter->setEnd (); delete writter; writter = NULL; // resync GUI printf ("\n Saving AVI (v_engine)... done\n"); return ret; }
RealtimeWindow::RealtimeWindow(MainWindow *parent, TrainTool *trainTool, const QDir &home) : QWidget(parent) { // set home this->home = home; this->trainTool = trainTool; main = parent; deviceController = NULL; streamController = NULL; ergFile = NULL; // metric or imperial? boost::shared_ptr<QSettings> settings = GetApplicationSettings(); QVariant unit = settings->value(GC_UNIT); useMetricUnits = (unit.toString() == "Metric"); // main layout for the window main_layout = new QVBoxLayout(this); timer_layout = new QGridLayout(); // BUTTONS AND LCDS button_layout = new QHBoxLayout(); option_layout = new QHBoxLayout(); controls_layout = new QVBoxLayout(); deviceSelector = new QComboBox(this); streamSelector = new QComboBox(this); // get configured devices DeviceConfigurations all; Devices = all.getList(); streamSelector->addItem("No streaming", -1); for (int i=0; i<Devices.count(); i++) { // add streamers if ( Devices.at(i).type == DEV_GSERVER || Devices.at(i).type == DEV_GCLIENT ) streamSelector->addItem(Devices.at(i).name, i); // add data sources deviceSelector->addItem(Devices.at(i).name, i); } deviceSelector->setCurrentIndex(0); streamSelector->setCurrentIndex(0); recordSelector = new QCheckBox(this); recordSelector->setText(tr("Save")); recordSelector->setChecked(Qt::Checked); startButton = new QPushButton(tr("Start"), this); startButton->setMaximumHeight(100); pauseButton = new QPushButton(tr("Pause"), this); pauseButton->setMaximumHeight(100); stopButton = new QPushButton(tr("Stop"), this); stopButton->setMaximumHeight(100); button_layout->addWidget(startButton); button_layout->addWidget(pauseButton); button_layout->addWidget(stopButton); option_layout->addWidget(deviceSelector); option_layout->addSpacing(10); option_layout->addWidget(recordSelector); option_layout->addSpacing(10); option_layout->addWidget(streamSelector); // XXX NETWORK STREAMING DISABLED IN THIS RELEASE SO HIDE THE COMBO streamSelector->hide(); option_layout->addSpacing(10); controls_layout->addItem(option_layout); controls_layout->addItem(button_layout); // handle config changes connect(main, SIGNAL(configChanged()), this, SLOT(configUpdate())); connect(deviceSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(SelectDevice(int))); connect(recordSelector, SIGNAL(clicked()), this, SLOT(SelectRecord())); connect(streamSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(SelectStream(int))); connect(trainTool, SIGNAL(workoutSelected()), this, SLOT(SelectWorkout())); if (Devices.count() > 0) { connect(startButton, SIGNAL(clicked()), this, SLOT(Start())); connect(pauseButton, SIGNAL(clicked()), this, SLOT(Pause())); connect(stopButton, SIGNAL(clicked()), this, SLOT(Stop())); } else { connect(startButton, SIGNAL(clicked()), this, SLOT(warnnoConfig())); connect(pauseButton, SIGNAL(clicked()), this, SLOT(warnnoConfig())); connect(stopButton, SIGNAL(clicked()), this, SLOT(warnnoConfig())); } powerLabel = new QLabel(tr("WATTS"), this); powerLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); heartrateLabel = new QLabel(tr("BPM"), this); heartrateLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); speedLabel = new QLabel(useMetricUnits ? tr("KPH") : tr("MPH"), this); speedLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); cadenceLabel = new QLabel(tr("RPM"), this); cadenceLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); lapLabel = new QLabel(tr("Lap/Interval"), this); lapLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); loadLabel = new QLabel(tr("Load WATTS"), this); loadLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); distanceLabel = new QLabel(useMetricUnits ? tr("Distance (KM)") : tr("Distance (Miles)"), this); distanceLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); avgpowerLabel = new QLabel(tr("Avg WATTS"), this); avgpowerLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); avgheartrateLabel = new QLabel(tr("Avg BPM"), this); avgheartrateLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); avgspeedLabel = new QLabel(useMetricUnits ? tr("Avg KPH") : tr("Avg MPH"), this); avgspeedLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); avgcadenceLabel = new QLabel(tr("Avg RPM"), this); avgcadenceLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); avgloadLabel = new QLabel(tr("Avg Load WATTS"), this); avgloadLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); laptimeLabel = new QLabel(tr("LAP TIME"), this); laptimeLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); timeLabel = new QLabel(tr("TIME"), this); timeLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); powerLCD = new QLCDNumber(this); powerLCD->setSegmentStyle(QLCDNumber::Filled); heartrateLCD = new QLCDNumber(this); heartrateLCD->setSegmentStyle(QLCDNumber::Filled); speedLCD = new QLCDNumber(this); speedLCD->setSegmentStyle(QLCDNumber::Filled); cadenceLCD = new QLCDNumber(this); cadenceLCD->setSegmentStyle(QLCDNumber::Filled); lapLCD = new QLCDNumber(this); lapLCD->setSegmentStyle(QLCDNumber::Filled); loadLCD = new QLCDNumber(this); loadLCD->setSegmentStyle(QLCDNumber::Filled); distanceLCD = new QLCDNumber(this); distanceLCD->setSegmentStyle(QLCDNumber::Filled); avgpowerLCD = new QLCDNumber(this); avgpowerLCD->setSegmentStyle(QLCDNumber::Filled); avgheartrateLCD = new QLCDNumber(this); avgheartrateLCD->setSegmentStyle(QLCDNumber::Filled); avgspeedLCD = new QLCDNumber(this); avgspeedLCD->setSegmentStyle(QLCDNumber::Filled); avgcadenceLCD = new QLCDNumber(this); avgcadenceLCD->setSegmentStyle(QLCDNumber::Filled); avgloadLCD = new QLCDNumber(this); avgloadLCD->setSegmentStyle(QLCDNumber::Filled); laptimeLCD = new QLCDNumber(this); laptimeLCD->setSegmentStyle(QLCDNumber::Filled); laptimeLCD->setNumDigits(9); timeLCD = new QLCDNumber(this); timeLCD->setSegmentStyle(QLCDNumber::Filled); timeLCD->setNumDigits(9); gridLayout = new QGridLayout(); gridLayout->addWidget(powerLabel, 1, 0); gridLayout->addWidget(cadenceLabel, 1, 1); gridLayout->addWidget(heartrateLabel, 1, 2); gridLayout->addWidget(speedLabel, 1, 3); gridLayout->addWidget(distanceLabel, 1, 4); gridLayout->addWidget(lapLabel, 1, 5); gridLayout->addWidget(powerLCD, 2, 0); gridLayout->addWidget(cadenceLCD, 2, 1); gridLayout->addWidget(heartrateLCD, 2, 2); gridLayout->addWidget(speedLCD, 2, 3); gridLayout->addWidget(distanceLCD, 2, 4); gridLayout->addWidget(lapLCD, 2, 5); gridLayout->addWidget(avgpowerLabel, 3, 0); gridLayout->addWidget(avgcadenceLabel, 3, 1); gridLayout->addWidget(avgheartrateLabel, 3, 2); gridLayout->addWidget(avgspeedLabel, 3, 3); gridLayout->addWidget(avgloadLabel, 3, 4); gridLayout->addWidget(loadLabel, 3, 5); gridLayout->addWidget(loadLCD, 4, 5); gridLayout->addWidget(avgpowerLCD, 4, 0); gridLayout->addWidget(avgcadenceLCD, 4, 1); gridLayout->addWidget(avgheartrateLCD, 4, 2); gridLayout->addWidget(avgspeedLCD, 4, 3); gridLayout->addWidget(avgloadLCD, 4, 4); gridLayout->setRowStretch(2, 4); gridLayout->setRowStretch(4, 3); // timers etc timer_layout->addWidget(timeLabel, 0, 0); timer_layout->addWidget(laptimeLabel, 0, 3); timer_layout->addWidget(timeLCD, 1, 0); timer_layout->addItem(controls_layout, 1,1); timer_layout->addWidget(laptimeLCD, 1, 3); timer_layout->setRowStretch(0, 1); timer_layout->setRowStretch(1, 4); // REALTIME PLOT rtPlot = new RealtimePlot(); connect(main, SIGNAL(configChanged()), rtPlot, SLOT(configChanged())); // COURSE PLOT ergPlot = new ErgFilePlot(0); ergPlot->setVisible(false); // LAYOUT main_layout->addWidget(ergPlot); main_layout->addItem(timer_layout); main_layout->addItem(gridLayout); main_layout->addWidget(rtPlot); displaymode=2; main_layout->setStretch(0,1); main_layout->setStretch(1,1); main_layout->setStretch(2,2); main_layout->setStretch(3, displaymode); // now the GUI is setup lets sort our control variables gui_timer = new QTimer(this); disk_timer = new QTimer(this); stream_timer = new QTimer(this); load_timer = new QTimer(this); session_time = QTime(); session_elapsed_msec = 0; lap_time = QTime(); lap_elapsed_msec = 0; recordFile = NULL; status = 0; status |= RT_RECORDING; // recording is on by default! - add others here status |= RT_MODE_ERGO; // ergo mode by default displayWorkoutLap = displayLap = 0; pwrcount = 0; cadcount = 0; hrcount = 0; spdcount = 0; lodcount = 0; load_msecs = total_msecs = lap_msecs = 0; displayWorkoutDistance = displayDistance = displayPower = displayHeartRate = displaySpeed = displayCadence = displayGradient = displayLoad = 0; avgPower= avgHeartRate= avgSpeed= avgCadence= avgLoad= 0; connect(gui_timer, SIGNAL(timeout()), this, SLOT(guiUpdate())); connect(disk_timer, SIGNAL(timeout()), this, SLOT(diskUpdate())); connect(stream_timer, SIGNAL(timeout()), this, SLOT(streamUpdate())); connect(load_timer, SIGNAL(timeout()), this, SLOT(loadUpdate())); // setup the controller based upon currently selected device setDeviceController(); rtPlot->replot(); }
//-------------------------------------------------------------- void testApp::draw() { //set background to pretty gray gradient ofBackgroundGradient(ofColor::black, ofColor::gray); //Update the GUI elements guiUpdate(); ofSetColor(255); // Set color to white //onscreen instructions if(camMode) { string msg; msg += "Instructions:\n"; msg += "Press up and down arrow keys to adjust contour contrast level\n"; msg += "Press the space bar to reset the background\n"; myFont.drawString(msg, 210, 20); } else if (ILDAmode) { string msg; msg += "Instructions:\n"; msg += "Press \"n\" or right arrow to go to next file, \"b\" or left arrow to go to previous file\n"; msg += "Toggle \"Draw ILDA\" off to make the framerate faster\n"; msg += "ILDA files are in \"data/ildaFiles\""; myFont.drawString(msg, 210, 20); } else if (manualControl) { string msg; msg += "Instructions:\n"; msg += "Turn laser on and off with \"Laser\" toggle\n"; msg += "Click and drag within 2D pad to control laser point\n"; myFont.drawString(msg, 210, 20); } else { string msg; msg += "Instructions:\n"; msg += "Click on the \"Serial Devices\" dropdown to select your serial comm port\n"; msg += "To rescan serial ports, click refresh\n"; myFont.drawString(msg, 210, 20); } /* -------- DRAW CURRENT ILDA GRAPHIC ----------- */ if(ILDAmode && drawILDA && fileLoaded && !manualControl && !camMode ) { ofSetLineWidth(1); // Draw the current idla file in the center of the CUI for(int i = 0; i < (nPts-1); i++) { // Draw circle around "Point" currently selected in point inspector if(point == (i+1)) { ofSetColor(0,255,255); ofNoFill(); //draw circle outline, thus nofill ofCircle(gui_ctr.x+x_grd[i],gui_ctr.y-y_grd[i],10); } // If laser if on, draw red line, otherwise white line if(l_state[i]) { ofSetColor(153,0,0); ofLine(gui_ctr.x+x_grd[i],gui_ctr.y-y_grd[i], \ gui_ctr.x+x_grd[i+1],gui_ctr.y-y_grd[i+1]); } else if(!l_state[i]) { ofSetColor(150,150,150); ofLine(gui_ctr.x+x_grd[i],gui_ctr.y-y_grd[i], \ gui_ctr.x+x_grd[i+1],gui_ctr.y-y_grd[i+1]); } } } /* ------- DRAW MANUAL POINT POSITION ----------- */ if(manualControl) { ofPushStyle(); ofEnableBlendMode(OF_BLENDMODE_ALPHA); //draw laser cursor on screen ofSetColor(255, 100, 100, 150); ofFill(); ofCircle(positionDraw.x,positionDraw.y, radius); ofPopStyle(); } /* --------- DRAW EDGE CONTOUR -------------------- */ if(camMode) { // Set coordinate for CV video feed int x_max = 320; int y_max = 240; int xCam_ctr = gui_ctr.x - (x_max/2); int yCam_ctr = gui_ctr.y; // Draw Color Image, All blob contours colorImg.draw(xCam_ctr,(yCam_ctr-1.15*y_max)); contourFinder.draw(xCam_ctr - 0.6*x_max,yCam_ctr); //label webcam images myFont.drawString("Webcam Image", xCam_ctr+110, yCam_ctr-1.15*y_max-5 ); myFont.drawString("Blobs", xCam_ctr - 0.6*x_max + 135, yCam_ctr - 5 ); myFont.drawString("Contours", xCam_ctr + 0.6*x_max + 125, yCam_ctr -5 ); // Draw first blob if(contourFinder.nBlobs) { if(multiContours) { //draw multiple blobs // Iterate through each blob for(int i = 0; i < contourFinder.nBlobs; i++) { int edg_pts = contourFinder.blobs[i].nPts; // Number of points in contour // Iterate through each point in each blob for(int j = 0; j < (edg_pts-1); j++) { // Draw contour lines ofLine( xCam_ctr + 0.6*x_max + contourFinder.blobs[i].pts[j].x, \ yCam_ctr + contourFinder.blobs[i].pts[j].y, \ xCam_ctr + 0.6*x_max + contourFinder.blobs[i].pts[j+1].x, \ yCam_ctr + contourFinder.blobs[i].pts[j+1].y); // Draw connecting lines } } // Draw border lines ofLine( xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + 0, \ xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + 0); ofLine( xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + 0, \ xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + y_max); ofLine( xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + y_max, \ xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + y_max); ofLine( xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + y_max, \ xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + 0); } else { //draw only the first blob int n = contourFinder.blobs[0].nPts; for(int i = 0; i < (n-1); i++) { // Draw contour lines ofLine( xCam_ctr + 0.6*x_max + contourFinder.blobs[0].pts[i].x, \ yCam_ctr + contourFinder.blobs[0].pts[i].y, \ xCam_ctr + 0.6*x_max + contourFinder.blobs[0].pts[i+1].x, \ yCam_ctr + contourFinder.blobs[0].pts[i+1].y); // Draw connecting lines } // Draw border lines ofLine( xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + 0, \ xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + 0); ofLine( xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + 0, \ xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + y_max); ofLine( xCam_ctr + 0.6*x_max + x_max, \ yCam_ctr + y_max, \ xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + y_max); ofLine( xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + y_max, \ xCam_ctr + 0.6*x_max + 0, \ yCam_ctr + 0); } } } }
//___________________________________________________________ // Generic Save Avi loop // //___________________________________________________________ // uint8_t GenericAviSave::saveAvi (const char *name) { uint32_t size; uint8_t ret=0; strcpy(_name,name); //frametogo = frameEnd - frameStart + 1; frametogo=0; writter = new aviWrite (); // 1- setup audio guiStart(); if (!setupAudio ()) { guiStop(); GUI_Error_HIG (QT_TR_NOOP("Error initalizing audio filters"), NULL); delete writter; writter = NULL; return 0; } if (!setupVideo (_name)) { guiStop(); GUI_Error_HIG (QT_TR_NOOP("Error initalizing video filters"), NULL); delete writter; writter = NULL; // guiStop(); return 0; } // 3- setup video frametogo=_incoming->getInfo()->nb_frames; fps1000=_incoming->getInfo()->fps1000; printf ("\n writing %lu frames\n", frametogo); //__________________________________ // now go to main loop..... //__________________________________ for (uint32_t cf = 0; cf < frametogo; cf++) { if (guiUpdate (cf, frametogo)) goto abortme; // printf("\n %lu / %lu",cf,frametogo); writeVideoChunk (cf); writeAudioChunk (cf); //writter->sync(); }; // end for ret=1; abortme: guiStop (); //__________________________________ // and end save //__________________________________ writter->setEnd (); delete writter; writter = NULL; // resync GUI printf ("\n Saving AVI (v_engine)... done\n"); return ret; }
uint8_t GenericAviSaveProcess::setupVideo (char *name) { _notnull=0; _incoming = getLastVideoFilter (frameStart,frameEnd-frameStart); frametogo=_incoming->getInfo()->nb_frames; encoding_gui->setFps(_incoming->getInfo()->fps1000); // anish if(_incoming->getInfo()->width%8) { if(!GUI_Question("Width is not a multiple of 8\n continue anyway ?")) return 0; } _encode = getVideoEncoder (_incoming->getInfo()->width,_incoming->getInfo()->height); if (!_encode) return 0; // init compressor TwoPassLogFile=new char[strlen(name)+6]; strcpy(TwoPassLogFile,name); strcat(TwoPassLogFile,".stat"); _encode->setLogFile(TwoPassLogFile,frametogo); if (!_encode->configure (_incoming)) { delete _encode; _encode = NULL; GUI_Error_HIG ("Filter init failed", NULL); return 0; }; memcpy (&_bih, video_body->getBIH (), sizeof (_bih)); _bih.biWidth = _incoming->getInfo ()->width; _bih.biHeight = _incoming->getInfo ()->height; _bih.biSize=sizeof(_bih); _bih.biXPelsPerMeter=_bih.biClrUsed=_bih.biYPelsPerMeter=0; _mainaviheader.dwTotalFrames= _incoming->getInfo ()->nb_frames; _mainaviheader.dwMicroSecPerFrame=0; printf("\n Saved as %ld x %ld\n",_bih.biWidth,_bih.biHeight); _bih.biCompression=fourCC::get((uint8_t *)_encode->getCodecName()); encoding_gui->setCodec(_encode->getDisplayName()); // init save avi //-----------------------VBR-------------------------------------- if (_encode->isDualPass ()) { uint8_t *buffer; uint32_t len, flag; FILE *tmp; uint8_t reuse=0; aprintf("\n** Dual pass encoding**\n"); if((tmp=fopen(TwoPassLogFile,"rt"))) { fclose(tmp); if(GUI_Question("\n Reuse the existing log-file ?")) { reuse=1; } } if(!reuse) { guiSetPhasis ("1st Pass"); aprintf("**Pass 1:%lu\n",frametogo); buffer = new uint8_t[_incoming->getInfo ()->width * _incoming->getInfo ()->height * 3]; _encode->startPass1 (); //__________________________________ // now go to main loop..... //__________________________________ for (uint32_t cf = 0; cf < frametogo; cf++) { if (guiUpdate (cf, frametogo)) { abt: GUI_Error_HIG ("Aborting", NULL); delete[]buffer; return 0; } if (!_encode->encode (cf, &len, buffer, &flag)) { printf("\n Encoding of frame %lu failed !\n",cf); goto abt; } encoding_gui->setQuant(_encode->getLastQz()); encoding_gui->feedFrame(len); } // guiStop (); encoding_gui->reset(); delete[]buffer; aprintf("**Pass 1:done\n"); }// End of reuse if(!_encode->startPass2 ()) { printf("Pass2 ignition failed\n"); return 0; } } //-------------------------/VBR----------------------------------- // init save avi // now we build the new stream ! aprintf("**main pass:\n"); memcpy(&_videostreamheader,video_body->getVideoStreamHeader (),sizeof(_videostreamheader)); memcpy(&_videostreamheader.fccHandler ,_encode->getFCCHandler(),4); _videostreamheader.fccType =fourCC::get((uint8_t *)"vids"); _videostreamheader.dwScale=1000; _videostreamheader.dwRate= _incoming->getInfo ()->fps1000; memcpy(&_mainaviheader ,video_body->getMainHeader (),sizeof(_mainaviheader)); _mainaviheader.dwWidth=_bih.biWidth; _mainaviheader.dwHeight=_bih.biHeight; _videostreamheader.dwQuality=10000; uint8_t *data; uint32_t dataLen=0; _encode->hasExtraHeaderData( &dataLen,&data); if (!writter->saveBegin (name, &_mainaviheader, frameEnd - frameStart + 1, &_videostreamheader, &_bih, data,dataLen, (AVDMGenericAudioStream *) audio_filter, NULL)) { return 0; } aprintf("Setup video done\n"); return 1; //--------------------- }
uint8_t GenericAviSaveProcess::setupVideo (char *name) { _incoming = getLastVideoFilter (frameStart,frameEnd-frameStart); frametogo=_incoming->getInfo()->nb_frames; encoding_gui->setFps(_incoming->getInfo()->fps1000); // anish if(_incoming->getInfo()->width%8) { if(!GUI_Question(QT_TR_NOOP("Width is not a multiple of 8\n continue anyway ?"))) return 0; } _encode = getVideoEncoder (_incoming->getInfo()->width,_incoming->getInfo()->height); if (!_encode) return 0; // init compressor TwoPassLogFile=new char[strlen(name)+6]; strcpy(TwoPassLogFile,name); strcat(TwoPassLogFile,".stat"); _encode->setLogFile(TwoPassLogFile,frametogo); int reuse = 0; if (_encode->isDualPass()) { FILE *tmp; if ((tmp = fopen(TwoPassLogFile,"rt"))) { fclose(tmp); if (GUI_Question(QT_TR_NOOP("Reuse the existing log file?"))) reuse = 1; } } if (!_encode->configure (_incoming, reuse)) { delete _encode; _encode = NULL; GUI_Error_HIG (QT_TR_NOOP("Filter init failed"), NULL); return 0; }; memcpy (&_bih, video_body->getBIH (), sizeof (_bih)); _bih.biWidth = _incoming->getInfo ()->width; _bih.biHeight = _incoming->getInfo ()->height; _bih.biSize=sizeof(_bih); _bih.biXPelsPerMeter=_bih.biClrUsed=_bih.biYPelsPerMeter=0; _mainaviheader.dwTotalFrames= _incoming->getInfo ()->nb_frames; _mainaviheader.dwMicroSecPerFrame=0; printf("\n Saved as %ld x %ld\n",_bih.biWidth,_bih.biHeight); _bih.biCompression=fourCC::get((uint8_t *)_encode->getCodecName()); encoding_gui->setCodec(_encode->getDisplayName()); // init save avi //-----------------------2 Pass-------------------------------------- if (_encode->isDualPass ()) { uint8_t *buffer; uint32_t len, flag; int r, frameDelay = 0; aprintf("\n** Dual pass encoding**\n"); if(!reuse) { guiSetPhasis (QT_TR_NOOP("1st Pass")); aprintf("**Pass 1:%lu\n",frametogo); buffer = new uint8_t[_incoming->getInfo ()->width * _incoming->getInfo ()->height * 3]; _encode->startPass1 (); bitstream.bufferSize = _incoming->getInfo()->width * _incoming->getInfo()->height * 3; bitstream.data=buffer; for (uint32_t cf = 0; cf < frametogo; cf++) { if (guiUpdate (cf, frametogo)) { abt: GUI_Error_HIG (QT_TR_NOOP("Aborting"), NULL); delete[] buffer; return 0; } for (;;) { bitstream.cleanup(cf); if (cf + frameDelay >= frametogo) { if (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH) r = _encode->encode(UINT32_MAX, &bitstream); else r = 0; } else r = _encode->encode(cf + frameDelay, &bitstream); if (!r) { printf("Encoding of frame %lu failed!\n", cf); goto abt; } if (bitstream.len == 0 && (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH)) { printf("skipping frame: %u size: %i\n", cf + frameDelay, bitstream.len); frameDelay++; } else break; } encoding_gui->setFrame(cf,bitstream.len,bitstream.out_quantizer,frametogo); } encoding_gui->reset(); delete[]buffer; aprintf("**Pass 1:done\n"); }// End of reuse if(!_encode->startPass2 ()) { printf("Pass2 ignition failed\n"); return 0; } } //-------------------------/VBR----------------------------------- // init save avi // now we build the new stream ! aprintf("**main pass:\n"); memcpy(&_videostreamheader,video_body->getVideoStreamHeader (),sizeof(_videostreamheader)); memcpy(&_videostreamheader.fccHandler ,_encode->getFCCHandler(),4); _videostreamheader.fccType =fourCC::get((uint8_t *)"vids"); _videostreamheader.dwScale=1000; _videostreamheader.dwRate= _incoming->getInfo ()->fps1000; memcpy(&_mainaviheader ,video_body->getMainHeader (),sizeof(_mainaviheader)); _mainaviheader.dwWidth=_bih.biWidth; _mainaviheader.dwHeight=_bih.biHeight; _videostreamheader.dwQuality=10000; uint8_t *data; uint32_t dataLen=0; _encode->hasExtraHeaderData( &dataLen,&data); if (!writter->saveBegin (name, &_mainaviheader, frameEnd - frameStart + 1, &_videostreamheader, &_bih, data,dataLen, (AVDMGenericAudioStream *) audio_filter, NULL)) { return 0; } aprintf("Setup video done\n"); bitstream.data=vbuffer; bitstream.bufferSize=MAXIMUM_SIZE * MAXIMUM_SIZE * 3; return 1; //--------------------- }
void RSphericalParticles::initGTK() { _optList.reset(new Gtk::VBox);//The Vbox of options _colorMap.reset(new magnet::gtk::ColorMapSelector); _singleColorMode.reset(new Gtk::RadioButton("Single Color")); _colorByIDMode.reset(new Gtk::RadioButton("Color by ID")); _RFixed.reset(new Gtk::SpinButton); _GFixed.reset(new Gtk::SpinButton); _BFixed.reset(new Gtk::SpinButton); _AFixed.reset(new Gtk::SpinButton); { _optList->add(*_colorMap); _colorMap->show(); //Horizontal seperator Gtk::HSeparator* line = manage(new Gtk::HSeparator); line->show(); _optList->add(*line); } {//Single color and RGBA boxes Gtk::HBox* box = manage(new Gtk::HBox); box->pack_start(*_singleColorMode, true, true);_singleColorMode->show(); if (_mode == SINGLE_COLOR) _singleColorMode->set_active(); Gtk::Label* label = manage(new Gtk::Label("RGBA")); box->pack_start(*label, false, false); label->show(); _RFixed->set_increments(1.0, 1.0); _RFixed->set_range(0.0, 255.0); _RFixed->set_value(_colorFixed.s[0]); _GFixed->set_increments(1.0, 1.0); _GFixed->set_range(0.0, 255.0); _GFixed->set_value(_colorFixed.s[1]); _BFixed->set_increments(1.0, 1.0); _BFixed->set_range(0.0, 255.0); _BFixed->set_value(_colorFixed.s[2]); _AFixed->set_increments(1.0, 1.0); _AFixed->set_range(0.0, 255.0); _AFixed->set_value(_colorFixed.s[3]); box->pack_start(*_RFixed, false, false); _RFixed->show(); box->pack_start(*_GFixed, false, false); _GFixed->show(); box->pack_start(*_BFixed, false, false); _BFixed->show(); box->pack_start(*_AFixed, false, false); _AFixed->show(); _optList->add(*box); box->show(); //Horizontal seperator Gtk::HSeparator* line = manage(new Gtk::HSeparator); line->show(); _optList->add(*line); } Gtk::RadioButton::Group group = _singleColorMode->get_group(); {//Color by ID _colorByIDMode->set_group(group); _colorByIDMode->show(); if (_mode == COLOR_BY_ID) _colorByIDMode->set_active(); _optList->add(*_colorByIDMode); //Horizontal seperator Gtk::HSeparator* line = manage(new Gtk::HSeparator); line->show(); _optList->add(*line); } _optList->show(); _singleColorMode->signal_toggled() .connect(sigc::mem_fun(*this, &RSphericalParticles::guiUpdate)); _colorMap->signal_changed() .connect(sigc::mem_fun(*this, &RSphericalParticles::guiUpdate)); _RFixed->signal_value_changed() .connect(sigc::mem_fun(*this, &RSphericalParticles::guiUpdate)); _GFixed->signal_value_changed() .connect(sigc::mem_fun(*this, &RSphericalParticles::guiUpdate)); _BFixed->signal_value_changed() .connect(sigc::mem_fun(*this, &RSphericalParticles::guiUpdate)); _AFixed->signal_value_changed() .connect(sigc::mem_fun(*this, &RSphericalParticles::guiUpdate)); _colorByIDMode->signal_toggled() .connect(sigc::mem_fun(*this, &RSphericalParticles::guiUpdate)); guiUpdate(); }
void RVolume::initGTK() { _optList.reset(new Gtk::VBox);//The Vbox of options {//Transfer function widget _transferFunction.reset(new magnet::gtk::TransferFunction (magnet::function::MakeDelegate (this, &RVolume::transferFunctionUpdated))); _transferFunction->set_size_request(-1, 100); _optList->add(*_transferFunction); _transferFunction->show(); transferFunctionUpdated(); //Force an update of the transfer function now we have the widget } {//Volume renderer step size _stepSize.reset(new Gtk::Entry); Gtk::HBox* box = manage(new Gtk::HBox); Gtk::Label* label = manage(new Gtk::Label("Raytrace Step Size")); box->pack_start(*label, false, false); label->show(); box->pack_end(*_stepSize, false, false); _stepSize->show(); _stepSize->set_text("0.01"); _optList->add(*box); box->show(); } {//Diffusive lighting Gtk::HBox* box = manage(new Gtk::HBox); Gtk::Label* label = manage(new Gtk::Label("Diffuse Lighting")); box->pack_start(*label, false, false); label->show(); _diffusiveLighting.reset(new Gtk::HScale); box->pack_end(*_diffusiveLighting, true, true); _diffusiveLighting->set_range(0,2); _diffusiveLighting->set_digits(3); _diffusiveLighting->show(); _diffusiveLighting->set_value(1.0); _optList->add(*box); box->show(); } {//Specular lighting Gtk::HBox* box = manage(new Gtk::HBox); Gtk::Label* label = manage(new Gtk::Label("Specular Lighting")); box->pack_start(*label, false, false); label->show(); _specularLighting.reset(new Gtk::HScale); box->pack_end(*_specularLighting, true, true); _specularLighting->set_range(0,2); _specularLighting->set_digits(3); _specularLighting->show(); _specularLighting->set_value(1.0); _optList->add(*box); box->show(); } {//Ray Dithering Gtk::HBox* box = manage(new Gtk::HBox); Gtk::Label* label = manage(new Gtk::Label("Ray Dithering")); box->pack_start(*label, false, false); label->show(); _ditherRay.reset(new Gtk::HScale); box->pack_end(*_ditherRay, true, true); _ditherRay->set_range(0, 1); _ditherRay->set_digits(3); _ditherRay->show(); _ditherRay->set_value(1.0); _optList->add(*box); box->show(); } _optList->show(); //Callbacks _stepSize->signal_changed() .connect(sigc::bind<Gtk::Entry&>(&magnet::Gtk::forceNumericEntry, *_stepSize)); _stepSize->signal_activate().connect(sigc::mem_fun(*this, &RVolume::guiUpdate)); guiUpdate(); }