Beispiel #1
0
void MainWindow::createActions()
{
    renderIntoPixmapAct = new QAction(tr("&start kinect"), this);
    renderIntoPixmapAct->setShortcut(tr("Ctrl+R"));
    connect(renderIntoPixmapAct, SIGNAL(triggered()),
            this, SLOT(start()));

    grabFrameBufferAct = new QAction(tr("&Pause/Continue"), this);
    grabFrameBufferAct->setShortcut(tr("Ctrl+G"));
    connect(grabFrameBufferAct, SIGNAL(triggered()),
            this, SLOT(grabFrameBuffer()));

    clearPixmapAct = new QAction(tr("&for feature"), this);
    clearPixmapAct->setShortcut(tr("Ctrl+L"));
    connect(clearPixmapAct, SIGNAL(triggered()), this, SLOT(clearPixmap()));

    exitAct = new QAction(tr("E&xit"), this);
    exitAct->setShortcuts(QKeySequence::Quit);
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

    aboutAct = new QAction(tr("&About"), this);
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

    aboutQtAct = new QAction(tr("About &Qt"), this);
    connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setGL(); break;
        case 1: setPixelmap(); break;
        case 2: refresh(); break;
        case 3: grabFrameBuffer(); break;
        case 4: clearPixmap(); break;
        case 5: about(); break;
        case 6: open(); break;
        case 7: hideDim(); break;
        case 8: ctxMenu((*reinterpret_cast< const QPoint(*)>(_a[1]))); break;
        case 9: dimensionClick((*reinterpret_cast< const QPoint(*)>(_a[1]))); break;
        case 10: marginClick((*reinterpret_cast< const QPoint(*)>(_a[1]))); break;
        case 11: setLinear(); break;
        case 12: setLog(); break;
        case 13: insertDim(); break;
        case 14: brush(); break;
        case 15: reset(); break;
        case 16: finishedDrawing(); break;
        default: ;
        }
        _id -= 17;
    }
    return _id;
}
Beispiel #3
0
void iDrawMainWindow::createActions()
{
    renderIntoPixmapAct = new QAction(tr("&Render into Pixmap..."), this);
    renderIntoPixmapAct->setShortcut(tr("Ctrl+R"));
    connect(renderIntoPixmapAct, SIGNAL(triggered()),
            this, SLOT(renderIntoPixmap()));

    grabFrameBufferAct = new QAction(tr("&Grab Frame Buffer"), this);
    grabFrameBufferAct->setShortcut(tr("Ctrl+G"));
    connect(grabFrameBufferAct, SIGNAL(triggered()),
            this, SLOT(grabFrameBuffer()));

    clearPixmapAct = new QAction(tr("&Clear Pixmap"), this);
    clearPixmapAct->setShortcut(tr("Ctrl+L"));
    connect(clearPixmapAct, SIGNAL(triggered()), this, SLOT(clearPixmap()));

    exitAct = new QAction(tr("E&xit"), this);
    exitAct->setShortcut(tr("Ctrl+Q"));
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

    aboutAct = new QAction(tr("&About"), this);
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

    aboutQtAct = new QAction(tr("About &Qt"), this);
    connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
Beispiel #4
0
void Grabber::createActions()
{
    renderIntoPixmapAct = new QAction(tr("&Render into Pixmap..."), this);
    renderIntoPixmapAct->setShortcut(tr("Ctrl+R"));
    connect(renderIntoPixmapAct, SIGNAL(triggered()),
            this, SLOT(renderIntoPixmap()));

    grabFrameBufferAct = new QAction(tr("&Grab Frame Buffer"), this);
    grabFrameBufferAct->setShortcut(tr("Ctrl+G"));
    connect(grabFrameBufferAct, SIGNAL(triggered()),
            this, SLOT(grabFrameBuffer()));

    clearPixmapAct = new QAction(tr("&Clear Pixmap"), this);
    clearPixmapAct->setShortcut(tr("Ctrl+L"));
    connect(clearPixmapAct, SIGNAL(triggered()), this, SLOT(clearPixmap()));

    exitAct = new QAction(tr("Close"), this);
    exitAct->setShortcuts(QKeySequence::Quit);
    connect(exitAct, SIGNAL(triggered()), this, SLOT(actionClose()));

    aboutAct = new QAction(tr("&About"), this);
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

    aboutQtAct = new QAction(tr("About &CopperSpice"), this);
    connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
Beispiel #5
0
///// saveImage ///////////////////////////////////////////////////////////////
void GLView::saveImage()
/// Saves the view to an image.
{
  QStringList saveFormatsList;

  ///// get the available output formats
        QList<QByteArray> saveFormats = QImageWriter::supportedImageFormats();
        QList<QByteArray>::Iterator it = saveFormats.begin();
  while(it != saveFormats.end())
  {
    if((*it) == "JPEG")
      *it = "JPEG (*.jpg)";
    else
      *it += " (*."+(*it).toLower()+")";  // 'BMP' -> 'BMP (*.bmp)'
    it++;
    saveFormatsList << QString(*it);
  }

  ///// set up and show the dialog
  /*
  QFileDialog saveDialog("", QString::null, this, 0, true);
  saveDialog.setFilters(saveFormats);
  saveDialog.setSelectedFilter("PNG (*.png)");
  saveDialog.setCaption(tr("Choose a filename and format"));
  saveDialog.setMode(QFileDialog::AnyFile);
  if(saveDialog.exec() != QDialog::Accepted)
    return;
  ///// get the filename and the desired extension/filter
  QString filename = saveDialog.selectedFile();
  if(filename.isEmpty())
    return;
  */
  // this way does not allow to set the selected filter. maybe put PNG at the top manually. now BMP is the default
  QString selectedFilter;
  QString filename = QFileDialog::getSaveFileName(0, tr("Choose a filename and format"), QFileDialog::tr("/tmp"), saveFormatsList.join(";;"), &selectedFilter);
  if(filename.isEmpty())
    return;

  //QString extension = saveDialog.selectedFilter();
  //extension = extension.mid(extension.find("."));
  //extension = extension.remove(")");
  //qDebug("extension: "+extension);
  QString extension = selectedFilter.mid(selectedFilter.indexOf(".")).remove(")");

  if(filename.contains(extension) == 0)
    filename += extension;

  //QString format = saveDialog.selectedFilter();
  //format = format.left(format.find(" "));
  const char* format = selectedFilter.left(selectedFilter.indexOf(" ")).toLatin1().data();

  // generate an image from the OpenGL view
  // -> It is possible to get a transparant image when using grabFrameBuffer(true)
  QImage image = grabFrameBuffer();

  // save it
  if(!image.save(filename, format))
    QMessageBox::warning(this, tr("Save image"), tr("An error occured. Image is not saved"));
}
Beispiel #6
0
// ...
void GLWidget::grabWidgetScreenshot() {
	if (grabScreenshot) {
		QImage img;
		img = grabFrameBuffer(true);
		if (!img.isNull()) { bool res = img.save("data/screenshot.bmp", "BMP", -1); }
		grabScreenshot = false;
	}
}
Beispiel #7
0
void GLTDisp::paintLock(bool sw)
{
  if (!glLock && sw) {
    QImage image = grabFrameBuffer();
    glPixmap = QPixmap::fromImage(image); 
    glLock = true;
  }
  if (glLock && !sw) glLock = false;
}
Beispiel #8
0
void GLWidget::exportFrameBuffer()
{
  qDebug() << "export";

  QString save_name = QFileDialog::getSaveFileName(this,"Save Image","","Images (*.png *.jpg)");
  if(!save_name.isEmpty()){
    QImage img = grabFrameBuffer(false);
    img.save(save_name);
  }
}
void GLWidget3D::generatePredictedData() {
	QString resultDir = "C:\\Anaconda\\caffe\\data\\pmtree2d\\pmtree2d_predicted\\";
	if (QDir(resultDir).exists()) {
		QDir(resultDir).removeRecursively();
	}
	QDir().mkpath(resultDir);

	QFile file("predicted_results.txt");
	if (file.open(QIODevice::ReadOnly)) {
		QTextStream in(&file);
		int n = 0;
		while (!in.atEnd()) {
			QStringList data = in.readLine().split(",");
			
			std::vector<std::vector<float> > params;
			for (int i = 0; i * 63 < data.size(); ++i) {
				std::vector<float> ps;
				for (int k = 0; k < 63; ++k) {
					ps.push_back(data[i * 63 + k].toFloat());
				}
				params.push_back(ps);
			}

			tree.recover(params);
			
			// 木を生成
			renderManager.removeObjects();
			tree.generateGeometry(&renderManager, false);

			// 画像を生成
			render();

			QImage img = grabFrameBuffer();
			cv::Mat sourceImage(img.height(), img.width(), CV_8UC4, img.bits(), img.bytesPerLine());
			cv::Mat grayImage;
			cv::cvtColor(sourceImage, grayImage, CV_RGB2GRAY);

			// 画像を縮小
			cv::resize(grayImage, grayImage, cv::Size(512, 512));
			cv::threshold(grayImage, grayImage, 200, 255, CV_THRESH_BINARY);
			cv::resize(grayImage, grayImage, cv::Size(256, 256));
			cv::threshold(grayImage, grayImage, 200, 255, CV_THRESH_BINARY);
			cv::resize(grayImage, grayImage, cv::Size(128, 128));
			cv::threshold(grayImage, grayImage, 200, 255, CV_THRESH_BINARY);

			// write the iamge to file
			QString filename = resultDir + QString("image_%1.png").arg(n, 6, 10, QChar('0'));

			cv::imwrite(filename.toUtf8().constData(), grayImage);

			n++;
		}
	}

}
Beispiel #10
0
void GLArea::pasteTile() {
    QString outfile;

    glPushAttrib(GL_ENABLE_BIT);
    QImage tileBuffer=grabFrameBuffer(true).mirrored(false,true);
    if(ss.tiledSave) {
        outfile=QString("%1/%2_%3-%4.png")
                .arg(ss.outdir)
                .arg(ss.basename)
                .arg(tileCol,2,10,QChar('0'))
                .arg(tileRow,2,10,QChar('0'));
        tileBuffer.mirrored(false,true).save(outfile,"PNG");
    } else {
        if (snapBuffer.isNull())
            snapBuffer = QImage(tileBuffer.width() * ss.resolution, tileBuffer.height() * ss.resolution, tileBuffer.format());

        uchar *snapPtr = snapBuffer.bits() + (tileBuffer.bytesPerLine() * tileCol) + ((totalCols * tileRow) * tileBuffer.numBytes());
        uchar *tilePtr = tileBuffer.bits();

        for (int y=0; y < tileBuffer.height(); y++) {
            memcpy((void*) snapPtr, (void*) tilePtr, tileBuffer.bytesPerLine());
            snapPtr+=tileBuffer.bytesPerLine() * totalCols;
            tilePtr+=tileBuffer.bytesPerLine();
        }
    }
    tileCol++;

    if (tileCol >= totalCols) {
        tileCol=0;
        tileRow++;

        if (tileRow >= totalRows) {
            if(ss.snapAllLayers) {
                outfile=QString("%1/%2%3_L%4.png")
                        .arg(ss.outdir).arg(ss.basename)
                        .arg(ss.counter,2,10,QChar('0'))
                        .arg(currSnapLayer,2,10,QChar('0'));
            } else {
                outfile=QString("%1/%2%3.png")
                        .arg(ss.outdir).arg(ss.basename)
                        .arg(ss.counter++,2,10,QChar('0'));
            }

            if(!ss.tiledSave) {
                bool ret = (snapBuffer.mirrored(false,true)).save(outfile,"PNG");
                if (ret) log->Logf(GLLogStream::SYSTEM, "Snapshot saved to %s",outfile.toLocal8Bit().constData());
                else log->Logf(GLLogStream::WARNING,"Error saving %s",outfile.toLocal8Bit().constData());
            }
            takeSnapTile=false;
            snapBuffer=QImage();
        }
    }
    update();
    glPopAttrib();
}
Beispiel #11
0
void GLWidget::keyPressEvent(QKeyEvent *event) {
    switch(event->key()) {
        case Qt::Key_S:
        QImage qi = grabFrameBuffer(false);
        QString filter;
        QString fileName = QFileDialog::getSaveFileName(this,
             tr("Save Image"), "", tr("PNG Image (*.png)"), &filter);
        qi.save(QFileInfo(fileName).absoluteDir().absolutePath() + "/" + QFileInfo(fileName).baseName() + ".png", "PNG", 100);
        break;
    }
    draw_engine_->key_press_event(event);
}
Beispiel #12
0
void GL_widget_2::export_to_image(QString image_filepath) {

	bool old_dlists = get_use_display_lists();
	set_use_display_lists(false);
	repaint();
	QImage image = grabFrameBuffer();
	set_use_display_lists(old_dlists);
	repaint();

	image.save(image_filepath,"PNG");
	std::cout << "Image written to " << image_filepath.toStdString() << std::endl;
}
Beispiel #13
0
void
LiGL2D::save(QString url)
{
	char nom[256];
	sprintf(nom,"folkisave/%03d.jpg",_index);
	std::cout << "ecris :" << nom << " \n";

	_index++;
//	QPixmap pixmap = renderPixmap(this->size().width(),this->size().height());
//	pixmap.save(QString(nom));
	QImage tmp = grabFrameBuffer();
	tmp.save(QString(nom));
}
Beispiel #14
0
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: renderIntoPixmap(); break;
        case 1: grabFrameBuffer(); break;
        case 2: clearPixmap(); break;
        case 3: about(); break;
        default: ;
        }
        _id -= 4;
    }
    return _id;
}
 void GraphicDebugger::keyPressEvent(QKeyEvent *event)
 {
     if (m_controlKey) {
         if (event->key() == Qt::Key_F) ; /*
                                            if (_search->isVisible()) {
                                            _search->setFocus();
                                            _search->selectAll();
                                            }
                                            else
                                            _search->reactivate(); */
         else if (event->key() == Qt::Key_S)
             grabFrameBuffer().save("capture.png");
         else if (event->key() == Qt::Key_A)
             m_scene.describeAllNodes(!m_scene.describedNodes());
     }
     // else if (event->key() == Qt::Key_F4)
     //     if (_search->isVisible())
     //         _search->hide();
     //     else
     //         _search->reactivate();
     // else if (event->key() == Qt::Key_F1)
     //     _helpDialog->setShow(!_helpDialog->isVisible());
     else if (event->key() == Qt::Key_Escape)
         QApplication::quit();
     else if (event->key() == Qt::Key_Space)
         m_viewer.centering();
     else if (event->key() == Qt::Key_Up)
         m_viewer.moveCamera(VecXf(0, m_ratioKey));
     else if (event->key() == Qt::Key_Down)
         m_viewer.moveCamera(VecXf(0, -m_ratioKey));
     else if (event->key() == Qt::Key_Right)
         m_viewer.moveCamera(VecXf(m_ratioKey, 0));
     else if (event->key() == Qt::Key_Left)
         m_viewer.moveCamera(VecXf(-m_ratioKey, 0));
     else if (event->key() == Qt::Key_Control)
         m_controlKey = true;
     else if (event->key() == Qt::Key_Shift)
         m_shiftKey = true;
 }
void FusionForeverWidget::DrawSection(Section_ptr section, std::string name, std::vector<std::pair<std::string, QPixmap*> >& icons)
{
	if(section)
	{
		float radius = section->GetRadius();
		
		Camera::Instance().SetSmallestDimension(40);

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		Camera::Instance().SetupCamera();
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		//Draw Section
		section->DeathTick();
		section->SetOutlineColor(GLColor(0,0,0));
		section->DrawSelf();
		
		glFlush();


		QImage icon = grabFrameBuffer();
		if(height() > width())
		{
			int top = (height() - width()) / 2;
			QImage icon2 = icon.copy(0, top, width(), width());
			QPixmap pm = QPixmap::fromImage(icon2);
			icons.push_back(std::pair<std::string, QPixmap*>(name, new QPixmap(pm.pixmapData())));
		} else
		{
			int left = (width() - height()) / 2;
			QImage icon2 = icon.copy(left, 0, height(), height());
			QPixmap pm = QPixmap::fromImage(icon2);
			icons.push_back(std::pair<std::string, QPixmap*>(name, new QPixmap(pm.pixmapData())));
		}

		delete section;
	}
}
Beispiel #17
0
GLObjectWindow::GLObjectWindow( QWidget* parent, const char* name )
    : QWidget( parent, name )
{
    // Create a menu
    file = new QPopupMenu( this );
    file->setCheckable( TRUE );
    file->insertItem( "Grab Frame Buffer", this, SLOT(grabFrameBuffer()) );
    file->insertItem( "Render Pixmap", this, SLOT(makePixmap()) );
    file->insertItem( "Render Pixmap Hidden", this, SLOT(makePixmapHidden()) );
    file->insertSeparator();
    fixMenuItemId = file->insertItem( "Use Fixed Pixmap Size", this, 
				      SLOT(useFixedPixmapSize()) );
    file->insertSeparator();
    insertMenuItemId = file->insertItem( "Insert Pixmap Here", this, 
					 SLOT(makePixmapForMenu()) );
    file->insertSeparator();
    file->insertItem( "Exit",  qApp, SLOT(quit()), CTRL+Key_Q );

    // Create a menu bar
    QMenuBar *m = new QMenuBar( this );
    m->setSeparator( QMenuBar::InWindowsStyle );
    m->insertItem("&File", file );

    // Create nice frames to put around the OpenGL widgets
    QFrame* f1 = new QFrame( this, "frame1" );
    f1->setFrameStyle( QFrame::Sunken | QFrame::Panel );
    f1->setLineWidth( 2 );

    // Create an OpenGL widget
    c1 = new GLBox( f1, "glbox1");

    // Create a label that can display the pixmap
    lb = new QLabel( this, "pixlabel" );
    lb->setFrameStyle( QFrame::Sunken | QFrame::Panel );
    lb->setLineWidth( 2 );
    lb->setAlignment( AlignCenter );
    lb->setMargin( 0 );
    lb->setIndent( 0 );

    // Create the three sliders; one for each rotation axis
    QSlider* x = new QSlider ( 0, 360, 60, 0, QSlider::Vertical, this, "xsl" );
    x->setTickmarks( QSlider::Left );
    connect( x, SIGNAL(valueChanged(int)), c1, SLOT(setXRotation(int)) );

    QSlider* y = new QSlider ( 0, 360, 60, 0, QSlider::Vertical, this, "ysl" );
    y->setTickmarks( QSlider::Left );
    connect( y, SIGNAL(valueChanged(int)), c1, SLOT(setYRotation(int)) );

    QSlider* z = new QSlider ( 0, 360, 60, 0, QSlider::Vertical, this, "zsl" );
    z->setTickmarks( QSlider::Left );
    connect( z, SIGNAL(valueChanged(int)), c1, SLOT(setZRotation(int)) );


    // Now that we have all the widgets, put them into a nice layout

    // Put the sliders on top of each other
    QVBoxLayout* vlayout = new QVBoxLayout( 20, "vlayout");
    vlayout->addWidget( x );
    vlayout->addWidget( y );
    vlayout->addWidget( z );

    // Put the GL widget inside the frame
    QHBoxLayout* flayout1 = new QHBoxLayout( f1, 2, 2, "flayout1");
    flayout1->addWidget( c1, 1 );

    // Top level layout, puts the sliders to the left of the frame/GL widget
    QHBoxLayout* hlayout = new QHBoxLayout( this, 20, 20, "hlayout");
    hlayout->setMenuBar( m );
    hlayout->addLayout( vlayout );
    hlayout->addWidget( f1, 1 );
    hlayout->addWidget( lb, 1 );

}
Beispiel #18
0
QFile* Snapshot::savedFileForSnapshot(bool isTemporary) {
    auto glCanvas = DependencyManager::get<GLCanvas>();
    QImage shot = glCanvas->grabFrameBuffer();
    
    Avatar* avatar = Application::getInstance()->getAvatar();
    
    glm::vec3 location = avatar->getPosition();
    glm::quat orientation = avatar->getHead()->getOrientation();
    
    // add metadata
    shot.setText(LOCATION_X, QString::number(location.x));
    shot.setText(LOCATION_Y, QString::number(location.y));
    shot.setText(LOCATION_Z, QString::number(location.z));
    
    shot.setText(ORIENTATION_X, QString::number(orientation.x));
    shot.setText(ORIENTATION_Y, QString::number(orientation.y));
    shot.setText(ORIENTATION_Z, QString::number(orientation.z));
    shot.setText(ORIENTATION_W, QString::number(orientation.w));
    
    shot.setText(DOMAIN_KEY, DependencyManager::get<NodeList>()->getDomainHandler().getHostname());

    QString formattedLocation = QString("%1_%2_%3").arg(location.x).arg(location.y).arg(location.z);
    // replace decimal . with '-'
    formattedLocation.replace('.', '-');
    
    QString username = AccountManager::getInstance().getAccountInfo().getUsername();
    // normalize username, replace all non alphanumeric with '-'
    username.replace(QRegExp("[^A-Za-z0-9_]"), "-");
    
    QDateTime now = QDateTime::currentDateTime();
    
    QString filename = FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT), formattedLocation);
    
    const int IMAGE_QUALITY = 100;
    
    if (!isTemporary) {
        QString snapshotFullPath = Menu::getInstance()->getSnapshotsLocation();
        
        if (!snapshotFullPath.endsWith(QDir::separator())) {
            snapshotFullPath.append(QDir::separator());
        }
        
        snapshotFullPath.append(filename);
        
        QFile* imageFile = new QFile(snapshotFullPath);
        imageFile->open(QIODevice::WriteOnly);
        
        shot.save(imageFile, 0, IMAGE_QUALITY);
        imageFile->close();
        
        return imageFile;
    } else {
        QTemporaryFile* imageTempFile = new QTemporaryFile(QDir::tempPath() + "/XXXXXX-" + filename);
        
        if (!imageTempFile->open()) {
            qDebug() << "Unable to open QTemporaryFile for temp snapshot. Will not save.";
            return NULL;
        }
        
        shot.save(imageTempFile, 0, IMAGE_QUALITY);
        imageTempFile->close();
        
        return imageTempFile;
    }
}
Beispiel #19
0
void CQOpenGL::GlSaveScreenShot(QString FilePath)
{
    QImage Image;
    Image = grabFrameBuffer();
    Image.save(FilePath, 0, 95);
}
Beispiel #20
0
void GLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45,double(_width)/_height,1,100);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Position the camera
    _camera.applyTransformation();

    glPushMatrix();

    // Save the matrices for ray picking
    glGetDoublev(GL_MODELVIEW_MATRIX,_modelviewMatrix.v);
    glGetDoublev(GL_PROJECTION_MATRIX,_projectionMatrix.v);

    // Place the light
    OpenGL::lightPosition(GL_LIGHT0,Vector(1,1,1));

    _character->root()->display();

    // Draw selected joint as a cyan colored sphere
    GLUquadric *q = gluNewQuadric();

    for(std::map<Joint*,Point>::const_iterator i = _endEffectorsTarget.begin(); i != _endEffectorsTarget.end(); ++i) {
        // Draw the target position
        glPushMatrix();
        {
            OpenGL::color(Color::yellow());

            OpenGL::translate(i->second);
            gluSphere(q, 0.15, 20, 20);
        }
        glPopMatrix();

        GLMatrix m = i->first->calculateGlobalTransformation();

        // Draw line from target position and current position
        glBegin(GL_LINES);
        {
            Color c = Color::yellow();

            OpenGL::color(c);
            OpenGL::vertex(i->second);

            c = Color::red();

            OpenGL::color(c);
            OpenGL::vertex(m*Point());
        }
        glEnd();
    }

    gluDeleteQuadric(q);

    glPopMatrix();

    // Draw floor plane
    OpenGL::color(Color(0.6,0.6,0.6,0.8));

    OpenGL::translate(Vector(0,0,-0.1));

    glBegin(GL_QUADS);
    {
        OpenGL::normal(Vector(0,0,1));

        OpenGL::vertex(Point(-100,-100));
        OpenGL::vertex(Point(100,-100));
        OpenGL::vertex(Point(100,100));
        OpenGL::vertex(Point(-100,100));
    }
    glEnd();

    glClear(GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrtho(0,_width,0,_height,10,-10);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    OpenGL::color(Color::white());

    char buffer[512];

    sprintf(buffer,"Move: W A S D / Right mouse button");
    renderText(20, _height - 80, buffer);

    sprintf(buffer,"Zoom: Q Z / Middle mouse button");
    renderText(20, _height - 60, buffer);

    sprintf(buffer,"Pick/drag: Left mouse button");
    renderText(20, _height - 40, buffer);

    sprintf(buffer,"Toggle IK solving method: T");
    renderText(20, _height - 20, buffer);

    if(_animationEnabled) {
        sprintf(buffer,"Animations enabled / Picking disabled");
    }
    else {
        sprintf(buffer,"Animations disabled / Picking enabled");
    }

    renderText(20,20,buffer);

    const char *ikName;

    switch(_currentIKMethod) {
    case IKSolver::DAMPED_LEAST_SQUARES: {
        ikName = "Damped Least Squares";
        break;
    }

    case IKSolver::TRANSPOSE: {
        ikName = "Transpose";
    }

    default:
    { }
    }

    sprintf(buffer,"IK Method: %s",ikName);
    renderText(20,40,buffer);

    //----- Commands below removed because of Windows flickering issues -----//
    //glFlush(); // Send the commands to the OpenGL state machine
    //this->swapBuffers(); // Display the off-screen rendered buffer

    if(_isRecording) { // Save frame to disk, if recording is enabled
        _frameExporter->writeFrame(grabFrameBuffer());
    }
}
Beispiel #21
0
QImage MeshView::image()
{
    return grabFrameBuffer();
}
void GLWidget3D::generateTrainingData() {
	srand(2);

	QString baseResultDir = "C:\\Anaconda\\caffe\\data\\pmtree2dgrid\\pmtree2dgrid\\";

	if (QDir(baseResultDir).exists()) {
		QDir(baseResultDir).removeRecursively();
	}
	QDir().mkpath(baseResultDir);

	std::vector<int> count(4, 0);
	for (int n = 0; n < 300; ++n) {
		// 枝が地面にぶつからないよう、ランダムに生成
		while (true) {
			renderManager.removeObjects();
			tree.generateRandom();
			if (!tree.generateGeometry(&renderManager, false)) break;
		}

		// render the tree with color
		renderManager.renderingMode = RenderManager::RENDERING_MODE_BASIC;
		render();

		// cv::Mat形式に変換
		QImage img = grabFrameBuffer();
		cv::Mat imageMat = cv::Mat(img.height(), img.width(), CV_8UC4, img.bits(), img.bytesPerLine()).clone();

		// 2560x2560に変換
		cv::resize(imageMat, imageMat, cv::Size(2560, 2560));

		// render the tree with line rendering
		renderManager.renderingMode = RenderManager::RENDERING_MODE_LINE;
		render();

		// cv::Mat形式に変換
		QImage img2 = grabFrameBuffer();
		cv::Mat imageMat2 = cv::Mat(img2.height(), img2.width(), CV_8UC4, img2.bits(), img2.bytesPerLine()).clone();

		// 2560x2560に変換
		cv::resize(imageMat2, imageMat2, cv::Size(2560, 2560));

		// 10x10に分割
		int patch_width = imageMat.cols / 10;
		int patch_height = imageMat.rows / 10;
		int stride = patch_width / 3;
		for (int r = 0; r < imageMat.rows - patch_height; r += stride) {
			for (int c = 0; c < imageMat.cols - patch_width; c += stride) {
				cv::Mat patch(imageMat, cv::Rect(c, r, patch_width, patch_height));
				cv::Mat patch2(imageMat2, cv::Rect(c, r, patch_width, patch_height));

				// patchのタイプを計算
				int type = computePatchType(patch);

				// make directory
				QString resultDir = QString(baseResultDir + "pmtree2dgrid_%1\\").arg(type, 2, 10, QChar('0'));
				if (!QDir(resultDir).exists()) {
					QDir().mkdir(resultDir);
				}

				// 画像をファイルに保存
				QString filename = resultDir + QString("image_%1.png").arg(count[type]++, 6, 10, QChar('0'));
				cv::imwrite(filename.toUtf8().constData(), patch2);
			}
		}
	}
}
QImage LightPathsWidget::capture()
{
    return grabFrameBuffer();
}
void SimObjectWidget::copy()
{
  QApplication::clipboard()->clear();
  QApplication::clipboard()->setPixmap(QPixmap::fromImage(grabFrameBuffer()));
}
Beispiel #25
0
void GLWidget::saveImage()
{
    QImage image = grabFrameBuffer(true);
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"/home/stup",tr("Images (*.png *.xpm *.jpg *.tif *.bmp)"));
    image.save(fileName);
}
Beispiel #26
0
	void ChallengeViewer::sceneCompletedHook()
	{
		// create a map with names and scores
		qglColor(Qt::black);
		QMultiMap<int, QStringList> scores;
		for (World::ObjectsIterator it = world->objects.begin(); it != world->objects.end(); ++it)
		{
			AsebaFeedableEPuck *epuck = dynamic_cast<AsebaFeedableEPuck*>(*it);
			if (epuck)
			{
				QStringList entry;
				entry << epuck->name << QString::number(epuck->port) << QString::number((int)epuck->energy) << QString::number((int)epuck->score);
				scores.insert((int)epuck->score, entry);
				renderText(epuck->pos.x, epuck->pos.y, 10, epuck->name, labelFont);
			}
		}
		
		// build score texture
		QImage scoreBoard(512, 256, QImage::Format_ARGB32);
		scoreBoard.setDotsPerMeterX(2350);
		scoreBoard.setDotsPerMeterY(2350);
		QPainter painter(&scoreBoard);
		//painter.fillRect(scoreBoard.rect(), QColor(224,224,255,196));
		painter.fillRect(scoreBoard.rect(), QColor(224,255,224,196));
		
		// draw lines
		painter.setBrush(Qt::NoBrush);
		QPen pen(Qt::black);
		pen.setWidth(2);
		painter.setPen(pen);
		painter.drawRect(scoreBoard.rect());
		pen.setWidth(1);
		painter.setPen(pen);
		painter.drawLine(22, 34, 504, 34);
		painter.drawLine(312, 12, 312, 247);
		painter.drawLine(312, 240, 504, 240);
		
		// draw title
		painter.setFont(titleFont);
		painter.drawText(35, 28, "name");
		painter.drawText(200, 28, "port");
		painter.drawText(324, 28, "energy");
		painter.drawText(430, 28, "points");
		
		// display entries
		QMapIterator<int, QStringList> it(scores);
		
		it.toBack();
		int pos = 61;
		while (it.hasPrevious())
		{
			it.previous();
			painter.drawText(200, pos, it.value().at(1));
			pos += 24;
		}
		
		it.toBack();
		painter.setFont(entryFont);
		pos = 61;
		while (it.hasPrevious())
		{
			it.previous();
			painter.drawText(35, pos, it.value().at(0));
			painter.drawText(335, pos, it.value().at(2));
			painter.drawText(445, pos, it.value().at(3));
			pos += 24;
		}
		
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		GLuint tex = bindTexture(scoreBoard, GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
		glCullFace(GL_FRONT);
		glColor4d(1, 1, 1, 0.75);
		for (int i = 0; i < 4; i++)
		{
			glPushMatrix();
			glTranslated(world->w/2, world->h/2, 50);
			glRotated(90*i, 0, 0, 1);
			glBegin(GL_QUADS);
			glTexCoord2d(0, 0);
			glVertex3d(-20, -20, 0);
			glTexCoord2d(1, 0);
			glVertex3d(20, -20, 0);
			glTexCoord2d(1, 1);
			glVertex3d(20, -20, 20);
			glTexCoord2d(0, 1);
			glVertex3d(-20, -20, 20);
			glEnd();
			glPopMatrix();
		}
		
		glCullFace(GL_BACK);
		glColor3d(1, 1, 1);
		for (int i = 0; i < 4; i++)
		{
			glPushMatrix();
			glTranslated(world->w/2, world->h/2, 50);
			glRotated(90*i, 0, 0, 1);
			glBegin(GL_QUADS);
			glTexCoord2d(0, 0);
			glVertex3d(-20, -20, 0);
			glTexCoord2d(1, 0);
			glVertex3d(20, -20, 0);
			glTexCoord2d(1, 1);
			glVertex3d(20, -20, 20);
			glTexCoord2d(0, 1);
			glVertex3d(-20, -20, 20);
			glEnd();
			glPopMatrix();
		}
		
		deleteTexture(tex);
		
		glDisable(GL_TEXTURE_2D);
		glColor4d(7./8.,7./8.,1,0.75);
		glPushMatrix();
		glTranslated(world->w/2, world->h/2, 50);
		glBegin(GL_QUADS);
		glVertex3d(-20,-20,20);
		glVertex3d(20,-20,20);
		glVertex3d(20,20,20);
		glVertex3d(-20,20,20);
		
		glVertex3d(-20,20,0);
		glVertex3d(20,20,0);
		glVertex3d(20,-20,0);
		glVertex3d(-20,-20,0);
		glEnd();
		glPopMatrix();
		
		// save image
		static int imageCounter = 0;
		if (savingVideo)
			grabFrameBuffer().save(QString("frame%0.bmp").arg(imageCounter++), "BMP");
	}