mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
* Revert "#4377 Octave : Use RiaLogging for error messages instead of QErrorMessage " This reverts commitf758a8edb2
. * Revert "#4380 Preferences : Changing scene font size when geo mech view is open causes crash" This reverts commitdf62a41397
. * Revert "#4379 Documentation : Update command line parser for import of summary files" This reverts commitd0b5357ed4
. * Unfinished WIP * Builds but crashes * Refactored code now builds and runs * ResInsight can now run the unittests headless * Can run some command files successfully * Build on Linux * Extra headless hack header * Moved PdmUiItem hack to cpp file * Fix headless crash in RimWellAllocationPlot * Handle error gracefully if ExportSnapshots command is executed from console * Add caf::QIconProvider and remove some hacks * Also made the greying out of disabled icons work for a couple of cases where it didn't. * Linux build fix * #4380 Reimplement fixdf62a41397
by @magnesj on top of Headless code changes * #4379 Reintroduce kode fromd0b5357ed4
by @magnesj * #4377 Restoref758a8edb2
in new Headless code
132 lines
4.4 KiB
C++
132 lines
4.4 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2018- Equinor ASA
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RiuCvfOverlayItemWidget.h"
|
|
|
|
#include "RiaGuiApplication.h"
|
|
|
|
#include "cafTitledOverlayFrame.h"
|
|
#include "cafViewer.h"
|
|
|
|
#include "cvfqtUtils.h"
|
|
#include "cvfRenderSequence.h"
|
|
#include "cvfFramebufferObject.h"
|
|
#include "cvfRenderbufferObject.h"
|
|
#include "cvfRendering.h"
|
|
#include "cvfCamera.h"
|
|
|
|
#include <QApplication>
|
|
#include <QFrame>
|
|
#include <QLabel>
|
|
#include <QPixmap>
|
|
#include <QPushButton>
|
|
#include <QResizeEvent>
|
|
#include <QBoxLayout>
|
|
|
|
#include "glew/GL/glew.h"
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiuCvfOverlayItemWidget::RiuCvfOverlayItemWidget(QWidget* parent/*=0*/, QWidget* widgetToSnapTo)
|
|
: RiuDraggableOverlayFrame(parent, widgetToSnapTo)
|
|
{
|
|
this->layout()->setMargin(0);
|
|
this->layout()->setSpacing(0);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RiuCvfOverlayItemWidget::~RiuCvfOverlayItemWidget()
|
|
{
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RiuCvfOverlayItemWidget::updateFromOverlayItem( caf::TitledOverlayFrame * item)
|
|
{
|
|
unsigned int width = item->renderSize().x();
|
|
unsigned int height = item->renderSize().y();
|
|
|
|
QGLFormat glFormat;
|
|
glFormat.setDirectRendering(RiaGuiApplication::instance()->useShaders());
|
|
|
|
// Enforce no border to avoid
|
|
item->setBackgroundFrameColor(cvf::Color4f(0, 0, 0, 0));
|
|
|
|
caf::Viewer* viewer = new caf::Viewer(glFormat, nullptr);
|
|
cvf::OpenGLContext* cvfOglContext = viewer->cvfOpenGLContext();
|
|
viewer->resize(width, height);
|
|
|
|
// Create a rendering
|
|
|
|
cvf::ref<cvf::Rendering> rendering = new cvf::Rendering;
|
|
item->setLayoutFixedPosition({0,0});
|
|
rendering->addOverlayItem(item);
|
|
|
|
|
|
rendering->camera()->setViewport(0,0,width, height);
|
|
rendering->camera()->viewport()->setClearColor({1,1,1,0});
|
|
|
|
cvf::ref<cvf::RenderSequence> renderingSequence = new cvf::RenderSequence;
|
|
renderingSequence->addRendering(rendering.p());
|
|
|
|
if (RiaGuiApplication::instance()->useShaders())
|
|
{
|
|
// Set up frame and render buffers
|
|
|
|
cvf::ref<cvf::FramebufferObject> fbo = new cvf::FramebufferObject;
|
|
|
|
cvf::ref<cvf::RenderbufferObject> rboColor = new cvf::RenderbufferObject(cvf::RenderbufferObject::RGBA, width, height);
|
|
cvf::ref<cvf::RenderbufferObject> rboDepth = new cvf::RenderbufferObject(cvf::RenderbufferObject::DEPTH_COMPONENT24, width, height);
|
|
|
|
fbo->attachDepthRenderbuffer(rboDepth.p());
|
|
fbo->attachColorRenderbuffer(0, rboColor.p());
|
|
|
|
fbo->applyOpenGL(cvfOglContext);
|
|
rendering->setTargetFramebuffer(fbo.p());
|
|
fbo->bind(cvfOglContext);
|
|
}
|
|
|
|
renderingSequence->render(cvfOglContext);
|
|
|
|
// Read data from framebuffer
|
|
|
|
cvf::UByteArray arr(4*width*height);
|
|
glReadPixels(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height), GL_RGBA, GL_UNSIGNED_BYTE, arr.ptr());
|
|
|
|
// Create a cvf texture image
|
|
|
|
cvf::ref<cvf::TextureImage> img = new cvf::TextureImage;
|
|
img->setData(arr.ptr(), width, height);
|
|
|
|
QImage image = cvfqt::Utils::toQImage(*img.p());
|
|
//image.save("jjsLegendImageTest.png");
|
|
|
|
QPixmap pixmap = QPixmap::fromImage(image);
|
|
|
|
delete viewer;
|
|
|
|
m_overlayItemLabel->setPixmap(pixmap);
|
|
this->setMinimumSize(QSize(width, height));
|
|
this->resize(QSize(width, height));
|
|
|
|
}
|