From fbfbdfca84c71234fd5de5cdea53364b0b350bea Mon Sep 17 00:00:00 2001 From: sigurdp Date: Thu, 31 Oct 2013 14:57:52 +0100 Subject: [PATCH] Integrate Fwk updates from ResInsight/Perforce Integrated Fwk updates in Resinsight branch up to changelist 173. Summary of changes: * Rewrite of cvf::OverlayItem to allow fixed user controlled positioning of the items. * Removed pure virtual functions OverlayItem::maximumSize() and OverlayItem::minimumSize(). * Use caf::AboutDialog instead of modified cvfqt::BasicAboutDialog. * Removed lapack from link line due to fail on Ubuntu 12.04 when lapack isn't installed. * Fix in OpenGLContext::saveOpenGLState() to avoid application corruption when running on RedHat with VMWare. * Removed unused font manager. * Console assert handler only calls __debugbreak() if debugger is present. Otherwise, calls abort(). Done after trouble running gtest death tests. * Made component access functions in Color3f, Color3ub, Color4f, Color4ub inline. * Added conversion functions between TextureImage and QImage to cvfqt::Utils class. * Optimized TextureImage::setPixel() - relies on new inlined component-wise access functions for Color4ub. * Added TextureImage::clear() and non-const version of TextureImage::ptr(). --- .../CMakeLists.txt | 1 - .../UserInterface/RiuMainWindow.cpp | 9 +- ApplicationCode/UserInterface/RiuViewer.cpp | 9 +- Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 5 +- ...asicAboutDialog.cpp => cafAboutDialog.cpp} | 82 ++++--- ...cafBasicAboutDialog.h => cafAboutDialog.h} | 10 +- Fwk/AppFwk/cafViewer/cafViewer.cpp | 6 +- Fwk/VizFwk/LibCore/cvfAssert.cpp | 9 +- Fwk/VizFwk/LibCore/cvfColor3.cpp | 114 --------- Fwk/VizFwk/LibCore/cvfColor3.h | 26 ++- Fwk/VizFwk/LibCore/cvfColor4.cpp | 152 ------------ Fwk/VizFwk/LibCore/cvfColor4.h | 33 +-- Fwk/VizFwk/LibGuiQt/CMakeLists.txt | 12 +- Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.cpp | 97 ++------ Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.h | 41 ++-- Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp | 10 +- Fwk/VizFwk/LibGuiQt/cvfqtUtils.cpp | 137 +++++++---- Fwk/VizFwk/LibGuiQt/cvfqtUtils.h | 15 +- Fwk/VizFwk/LibRender/CMakeLists.txt | 8 +- Fwk/VizFwk/LibRender/cvfDrawableGeo.cpp | 174 ++++++++------ Fwk/VizFwk/LibRender/cvfFontManager.cpp | 111 --------- Fwk/VizFwk/LibRender/cvfFontManager.h | 80 ------- Fwk/VizFwk/LibRender/cvfLibRender.h | 1 - Fwk/VizFwk/LibRender/cvfOverlayAxisCross.cpp | 18 -- Fwk/VizFwk/LibRender/cvfOverlayAxisCross.h | 2 - .../LibRender/cvfOverlayColorLegend.cpp | 18 -- Fwk/VizFwk/LibRender/cvfOverlayColorLegend.h | 2 - Fwk/VizFwk/LibRender/cvfOverlayImage.cpp | 18 -- Fwk/VizFwk/LibRender/cvfOverlayImage.h | 2 - Fwk/VizFwk/LibRender/cvfOverlayItem.cpp | 112 +++++++-- Fwk/VizFwk/LibRender/cvfOverlayItem.h | 41 ++-- .../LibRender/cvfOverlayNavigationCube.cpp | 25 +- .../LibRender/cvfOverlayNavigationCube.h | 8 +- .../cvfOverlayScalarMapperLegend.cpp | 18 -- .../LibRender/cvfOverlayScalarMapperLegend.h | 2 - Fwk/VizFwk/LibRender/cvfOverlayTextBox.cpp | 18 -- Fwk/VizFwk/LibRender/cvfOverlayTextBox.h | 2 - .../LibRender/cvfScalarMapperUniformLevels.h | 5 + Fwk/VizFwk/LibRender/cvfTextureImage.cpp | 32 ++- Fwk/VizFwk/LibRender/cvfTextureImage.h | 2 + Fwk/VizFwk/LibViewing/cvfRendering.cpp | 218 +++++++----------- Fwk/VizFwk/LibViewing/cvfRendering.h | 15 +- 42 files changed, 607 insertions(+), 1093 deletions(-) rename Fwk/AppFwk/cafUserInterface/{cafBasicAboutDialog.cpp => cafAboutDialog.cpp} (78%) rename Fwk/AppFwk/cafUserInterface/{cafBasicAboutDialog.h => cafAboutDialog.h} (94%) delete mode 100644 Fwk/VizFwk/LibRender/cvfFontManager.cpp delete mode 100644 Fwk/VizFwk/LibRender/cvfFontManager.h diff --git a/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt b/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt index 732f0927cf..dfdfc68085 100644 --- a/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt +++ b/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt @@ -77,7 +77,6 @@ add_executable( ${ProjectName} IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set ( LINUX_LINK_LIBRARIES - lapack pthread ) diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index 8013128714..7176fe2fae 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -49,7 +49,7 @@ #include "cafAnimationToolBar.h" #include "cafPdmUiPropertyView.h" -#include "cvfqtBasicAboutDialog.h" +#include "cafAboutDialog.h" #include "cvfTimer.h" #include "cafPdmFieldCvfMat4d.h" @@ -702,13 +702,12 @@ void RiuMainWindow::refreshAnimationActions() //-------------------------------------------------------------------------------------------------- void RiuMainWindow::slotAbout() { - cvfqt::BasicAboutDialog dlg(this); + caf::AboutDialog dlg(this); dlg.setApplicationName(RI_APPLICATION_NAME); dlg.setApplicationVersion(RiaApplication::getVersionStringApp(true)); dlg.setCopyright("Copyright 2011-2013 Statoil ASA, Ceetron AS"); - dlg.showCeeVizVersion(false); - + dlg.showQtVersion(false); #ifdef _DEBUG dlg.setIsDebugBuild(true); #endif @@ -719,7 +718,7 @@ void RiuMainWindow::slotAbout() dlg.addVersionEntry(" ", " "); dlg.addVersionEntry(" ", "Technical Information"); dlg.addVersionEntry(" ", QString(" Qt ") + qVersion()); - dlg.addVersionEntry(" ", QString(" ") + dlg.openGLVersionString()); + dlg.addVersionEntry(" ", QString(" ") + caf::AboutDialog::versionStringForcurrentOpenGLContext()); dlg.addVersionEntry(" ", caf::Viewer::isShadersSupported() ? " Hardware OpenGL" : " Software OpenGL"); dlg.create(); diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 42065f1538..f9208669c2 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -70,7 +70,8 @@ RiuViewer::RiuViewer(const QGLFormat& format, QWidget* parent) cvf::Font* standardFont = RiaApplication::instance()->standardFont(); cvf::OverlayAxisCross* axisCross = new cvf::OverlayAxisCross(m_mainCamera.p(), standardFont); axisCross->setAxisLabels("E", "N", "Z"); - m_mainRendering->addOverlayItem(axisCross, cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL); + axisCross->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT); + m_mainRendering->addOverlayItem(axisCross); this->enableOverlyPainting(true); this->setReleaseOGLResourcesEachFrame(true); @@ -181,12 +182,14 @@ void RiuViewer::updateLegends() if (m_legend1.notNull()) { - firstRendering->addOverlayItem(m_legend1.p(), cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL); + m_legend1->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT); + firstRendering->addOverlayItem(m_legend1.p()); } if (m_legend2.notNull()) { - firstRendering->addOverlayItem(m_legend2.p(), cvf::OverlayItem::BOTTOM_LEFT, cvf::OverlayItem::VERTICAL); + m_legend2->setLayout(cvf::OverlayItem::VERTICAL, cvf::OverlayItem::BOTTOM_LEFT); + firstRendering->addOverlayItem(m_legend2.p()); } } diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index fdf3cde039..9db951500d 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -8,7 +8,6 @@ include_directories( # These headers need to go through Qt's MOC compiler set( QOBJECT_HEADERS - cafBasicAboutDialog.h cafUiTreeModelPdm.h cafUiProcess.h @@ -36,8 +35,8 @@ endif() add_library( ${PROJECT_NAME} - cafBasicAboutDialog.cpp - cafBasicAboutDialog.h + cafAboutDialog.cpp + cafAboutDialog.h cafPdmUiCheckBoxEditor.cpp cafPdmUiCheckBoxEditor.h cafPdmUiColorEditor.cpp diff --git a/Fwk/AppFwk/cafUserInterface/cafBasicAboutDialog.cpp b/Fwk/AppFwk/cafUserInterface/cafAboutDialog.cpp similarity index 78% rename from Fwk/AppFwk/cafUserInterface/cafBasicAboutDialog.cpp rename to Fwk/AppFwk/cafUserInterface/cafAboutDialog.cpp index 8a31f887c6..19bf80e9e9 100644 --- a/Fwk/AppFwk/cafUserInterface/cafBasicAboutDialog.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafAboutDialog.cpp @@ -35,12 +35,13 @@ //################################################################################################## -#include "cafBasicAboutDialog.h" +#include "cafAboutDialog.h" #include #include #include #include +#include #include namespace caf { @@ -49,8 +50,7 @@ namespace caf { //================================================================================================== /// -/// \class cvfqt::BasicAboutDialog -/// \ingroup GuiQt +/// \class caf::BasicAboutDialog /// /// /// @@ -59,7 +59,7 @@ namespace caf { //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -BasicAboutDialog::BasicAboutDialog(QWidget* parent) +AboutDialog::AboutDialog(QWidget* parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint) { m_isCreated = false; @@ -68,7 +68,6 @@ BasicAboutDialog::BasicAboutDialog(QWidget* parent) //m_appVersion; //m_appCopyright; - m_showVizLibraryVersion = true; m_showQtVersion = true; m_isDebugBuild = false; @@ -79,7 +78,7 @@ BasicAboutDialog::BasicAboutDialog(QWidget* parent) //-------------------------------------------------------------------------------------------------- /// Set application name to show in the dialog. Must be specified if any other app info is to be displayed //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::setApplicationName(const QString& appName) +void AboutDialog::setApplicationName(const QString& appName) { assert(!m_isCreated); m_appName = appName; @@ -89,7 +88,7 @@ void BasicAboutDialog::setApplicationName(const QString& appName) //-------------------------------------------------------------------------------------------------- /// Set application version info to display //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::setApplicationVersion(const QString& ver) +void AboutDialog::setApplicationVersion(const QString& ver) { assert(!m_isCreated); m_appVersion = ver; @@ -99,27 +98,17 @@ void BasicAboutDialog::setApplicationVersion(const QString& ver) //-------------------------------------------------------------------------------------------------- /// Set copyright info to display //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::setCopyright(const QString& copyright) +void AboutDialog::setCopyright(const QString& copyright) { assert(!m_isCreated); m_appCopyright = copyright; } -//-------------------------------------------------------------------------------------------------- -/// Enable display of visualization library version -//-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::showVizLibraryVersion(bool show) -{ - assert(!m_isCreated); - m_showVizLibraryVersion = show; -} - - //-------------------------------------------------------------------------------------------------- /// Enable display of Qt version //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::showQtVersion(bool show) +void AboutDialog::showQtVersion(bool show) { assert(!m_isCreated); m_showQtVersion = show; @@ -129,7 +118,7 @@ void BasicAboutDialog::showQtVersion(bool show) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::addVersionEntry(const QString& verLabel, const QString& verText) +void AboutDialog::addVersionEntry(const QString& verLabel, const QString& verText) { assert(!m_isCreated); @@ -143,7 +132,7 @@ void BasicAboutDialog::addVersionEntry(const QString& verLabel, const QString& v //-------------------------------------------------------------------------------------------------- /// Set to true to show text in dialog to indicate that we're running a debug build of our app //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::setIsDebugBuild(bool isDebugBuild) +void AboutDialog::setIsDebugBuild(bool isDebugBuild) { assert(!m_isCreated); m_isDebugBuild = isDebugBuild; @@ -153,7 +142,7 @@ void BasicAboutDialog::setIsDebugBuild(bool isDebugBuild) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::create() +void AboutDialog::create() { // Only allowed to call once assert(!m_isCreated); @@ -239,8 +228,7 @@ void BasicAboutDialog::create() // Possibly show extend version info - if (m_showVizLibraryVersion || - m_showQtVersion || + if (m_showQtVersion || m_verLabels.size() > 0) { QGridLayout* verInfoLayout = new QGridLayout; @@ -248,14 +236,6 @@ void BasicAboutDialog::create() int insertRow = 0; - if (m_showVizLibraryVersion) - { -// QString ver; -// ver.sprintf("%s.%s%s-%s", CVF_MAJOR_VERSION, CVF_MINOR_VERSION, CVF_SPECIAL_BUILD, CVF_BUILD_NUMBER); -// -// addStringPairToVerInfoLayout("Visualization ver.: ", ver, verInfoLayout, insertRow++); - } - // Qt version if (m_showQtVersion) { @@ -317,7 +297,7 @@ void BasicAboutDialog::create() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow) +void AboutDialog::addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow) { QLabel* label = new QLabel(this); label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); @@ -331,11 +311,39 @@ void BasicAboutDialog::addStringPairToVerInfoLayout(const QString& labelStr, con } -} // namespace cvfqt +//-------------------------------------------------------------------------------------------------- +/// Get an OpenGL version string for the OpenGL context that is current at the moment +//-------------------------------------------------------------------------------------------------- +QString AboutDialog::versionStringForcurrentOpenGLContext() +{ + QString versionString("OpenGL "); + + QGLFormat::OpenGLVersionFlags flags = QGLFormat::openGLVersionFlags(); + + if (flags & QGLFormat::OpenGL_Version_4_0 ) versionString += "4.0"; + else if (flags & QGLFormat::OpenGL_Version_3_3 ) versionString += "3.3"; + else if (flags & QGLFormat::OpenGL_Version_3_2 ) versionString += "3.2"; + else if (flags & QGLFormat::OpenGL_Version_3_1 ) versionString += "3.1"; + else if (flags & QGLFormat::OpenGL_Version_3_0 ) versionString += "3.0"; + else if (flags & QGLFormat::OpenGL_ES_Version_2_0 ) versionString += "ES_Version 2.0"; + else if (flags & QGLFormat::OpenGL_ES_CommonLite_Version_1_1) versionString += "ES_CommonLite_Version 1.1"; + else if (flags & QGLFormat::OpenGL_ES_Common_Version_1_1 ) versionString += "ES_Common_Version 1.1"; + else if (flags & QGLFormat::OpenGL_ES_CommonLite_Version_1_0) versionString += "ES_CommonLite_Version 1.0"; + else if (flags & QGLFormat::OpenGL_ES_Common_Version_1_0 ) versionString += "ES_Common_Version 1.0"; + else if (flags & QGLFormat::OpenGL_Version_2_1 ) versionString += "2.1"; + else if (flags & QGLFormat::OpenGL_Version_2_0 ) versionString += "2.0"; + else if (flags & QGLFormat::OpenGL_Version_1_5 ) versionString += "1.5"; + else if (flags & QGLFormat::OpenGL_Version_1_4 ) versionString += "1.4"; + else if (flags & QGLFormat::OpenGL_Version_1_3 ) versionString += "1.3"; + else if (flags & QGLFormat::OpenGL_Version_1_2 ) versionString += "1.2"; + else if (flags & QGLFormat::OpenGL_Version_1_1 ) versionString += "1.1"; + else if (flags & QGLFormat::OpenGL_Version_None ) versionString += "None"; + else versionString += "Unknown"; + + return versionString; +} +} // namespace caf -//######################################################## -//#include "GeneratedFiles/moc_cvfqtBasicAboutDialog.cpp" -//######################################################## diff --git a/Fwk/AppFwk/cafUserInterface/cafBasicAboutDialog.h b/Fwk/AppFwk/cafUserInterface/cafAboutDialog.h similarity index 94% rename from Fwk/AppFwk/cafUserInterface/cafBasicAboutDialog.h rename to Fwk/AppFwk/cafUserInterface/cafAboutDialog.h index 7f4df36178..11702c1c21 100644 --- a/Fwk/AppFwk/cafUserInterface/cafBasicAboutDialog.h +++ b/Fwk/AppFwk/cafUserInterface/cafAboutDialog.h @@ -49,24 +49,23 @@ namespace caf { // // //================================================================================================== -class BasicAboutDialog : public QDialog +class AboutDialog : public QDialog { - Q_OBJECT - public: - BasicAboutDialog(QWidget* parent); + AboutDialog(QWidget* parent); void setApplicationName(const QString& appName); void setApplicationVersion(const QString& ver); void setCopyright(const QString& copyright); - void showVizLibraryVersion(bool show); void showQtVersion(bool show); void addVersionEntry(const QString& verLabel, const QString& verText); void setIsDebugBuild(bool isDebugBuild); void create(); + static QString versionStringForcurrentOpenGLContext(); + private: void addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow); @@ -77,7 +76,6 @@ private: QString m_appVersion; // Application version info. Can be empty QString m_appCopyright; // Application copyright string. Can be empty - bool m_showVizLibraryVersion; bool m_showQtVersion; // Flags whether Qt version info should be shown QStringList m_verLabels; // Labels for user specified version entries QStringList m_verTexts; // The actual version text for user specified version entries diff --git a/Fwk/AppFwk/cafViewer/cafViewer.cpp b/Fwk/AppFwk/cafViewer/cafViewer.cpp index 32674d327c..79293c8701 100644 --- a/Fwk/AppFwk/cafViewer/cafViewer.cpp +++ b/Fwk/AppFwk/cafViewer/cafViewer.cpp @@ -113,7 +113,7 @@ caf::Viewer::Viewer(const QGLFormat& format, QWidget* parent) m_overlayTextureImage = new cvf::TextureImage; m_overlayImage = new cvf::OverlayImage(m_overlayTextureImage.p()); m_overlayImage->setBlending(cvf::OverlayImage::TEXTURE_ALPHA); - m_overlayImage->setUnmanagedPosition(cvf::Vec2i(0,0)); + m_overlayImage->setLayoutFixedPosition(cvf::Vec2i(0,0)); setupMainRendering(); setupRenderingSequence(); @@ -459,7 +459,7 @@ void caf::Viewer::paintEvent(QPaintEvent* event) m_overlayTextureImage->allocate(this->width(), this->height()); } - cvfqt::Utils::copyFromQImage(m_overlayTextureImage.p(), m_overlayPaintingQImage); + cvfqt::Utils::fromQImage(m_overlayPaintingQImage, m_overlayTextureImage.p()); m_overlayImage->setImage(m_overlayTextureImage.p()); m_overlayImage->setPixelSize(cvf::Vec2ui(this->width(), this->height())); @@ -784,7 +784,7 @@ void caf::Viewer::updateOverlayImagePresence() { if (m_isOverlyPaintingEnabled || m_showPerfInfoHud) { - m_mainRendering->addOverlayItem(m_overlayImage.p(), cvf::OverlayItem::UNMANAGED, cvf::OverlayItem::VERTICAL); + m_mainRendering->addOverlayItem(m_overlayImage.p()); } else { diff --git a/Fwk/VizFwk/LibCore/cvfAssert.cpp b/Fwk/VizFwk/LibCore/cvfAssert.cpp index d5f300925a..bc74657cb5 100644 --- a/Fwk/VizFwk/LibCore/cvfAssert.cpp +++ b/Fwk/VizFwk/LibCore/cvfAssert.cpp @@ -114,11 +114,14 @@ Assert::FailAction AssertHandlerConsole::handleAssert(const char* fileName, int reportToConsole(fileName, lineNumber, expr, msg); #ifdef WIN32 - __debugbreak(); -#else - abort(); + if (::IsDebuggerPresent()) + { + __debugbreak(); + } #endif + abort(); + // Shouldn't really matter since we always abort return Assert::CONTINUE; } diff --git a/Fwk/VizFwk/LibCore/cvfColor3.cpp b/Fwk/VizFwk/LibCore/cvfColor3.cpp index cab22e0023..b948d5effc 100644 --- a/Fwk/VizFwk/LibCore/cvfColor3.cpp +++ b/Fwk/VizFwk/LibCore/cvfColor3.cpp @@ -166,66 +166,6 @@ bool Color3f::operator!=(const Color3f& rhs) const } -//-------------------------------------------------------------------------------------------------- -/// Returns the red color component of this color -//-------------------------------------------------------------------------------------------------- -float Color3f::r() const -{ - return m_rgb[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Returns the green color component of this color -//-------------------------------------------------------------------------------------------------- -float Color3f::g() const -{ - return m_rgb[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Returns the blue color component of this color -//-------------------------------------------------------------------------------------------------- -float Color3f::b() const -{ - return m_rgb[2]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the red color component. -/// -/// Used for setting the color, e.g. r() = 0.5f -//-------------------------------------------------------------------------------------------------- -float& Color3f::r() -{ - return m_rgb[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the green color component. -/// -/// Used for setting the color, e.g. g() = 0.5f -//-------------------------------------------------------------------------------------------------- -float& Color3f::g() -{ - return m_rgb[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the blue color component. -/// -/// Used for setting the color, e.g. b() = 0.5f -//-------------------------------------------------------------------------------------------------- -float& Color3f::b() -{ - return m_rgb[2]; -} - - //-------------------------------------------------------------------------------------------------- /// Sets all color components //-------------------------------------------------------------------------------------------------- @@ -473,60 +413,6 @@ bool Color3ub::operator!=(const Color3ub& rhs) const } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -ubyte Color3ub::r() const -{ - return m_rgb[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -ubyte Color3ub::g() const -{ - return m_rgb[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -ubyte Color3ub::b() const -{ - return m_rgb[2]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the red color component. -//-------------------------------------------------------------------------------------------------- -ubyte& Color3ub::r() -{ - return m_rgb[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the green color component. -//-------------------------------------------------------------------------------------------------- -ubyte& Color3ub::g() -{ - return m_rgb[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the blue color component. -//-------------------------------------------------------------------------------------------------- -ubyte& Color3ub::b() -{ - return m_rgb[2]; -} - - //-------------------------------------------------------------------------------------------------- /// Sets all color components //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibCore/cvfColor3.h b/Fwk/VizFwk/LibCore/cvfColor3.h index 524ba5227e..75f593de60 100644 --- a/Fwk/VizFwk/LibCore/cvfColor3.h +++ b/Fwk/VizFwk/LibCore/cvfColor3.h @@ -117,12 +117,13 @@ public: bool operator==(const Color3f& rhs) const; bool operator!=(const Color3f& rhs) const; - float r() const; - float g() const; - float b() const; - float& r(); - float& g(); - float& b(); + const float& r() const { return m_rgb[0]; } ///< Returns the red color component + const float& g() const { return m_rgb[1]; } ///< Returns the green color component + const float& b() const { return m_rgb[2]; } ///< Returns the blue color component + float& r() { return m_rgb[0]; } ///< Get modifiable reference to the red color component, used for setting the component. + float& g() { return m_rgb[1]; } ///< Get modifiable reference to the green color component, used for setting the component + float& b() { return m_rgb[2]; } ///< Get modifiable reference to the blue color component, used for setting the component + void set(float r, float g, float b); bool isValid() const; @@ -159,12 +160,13 @@ public: bool operator==(const Color3ub& rhs) const; bool operator!=(const Color3ub& rhs) const; - ubyte r() const; - ubyte g() const; - ubyte b() const; - ubyte& r(); - ubyte& g(); - ubyte& b(); + ubyte r() const { return m_rgb[0]; } ///< Returns the red color component + ubyte g() const { return m_rgb[1]; } ///< Returns the green color component + ubyte b() const { return m_rgb[2]; } ///< Returns the blue color component + ubyte& r() { return m_rgb[0]; } ///< Get modifiable reference to the red color component. + ubyte& g() { return m_rgb[1]; } ///< Get modifiable reference to the green color component. + ubyte& b() { return m_rgb[2]; } ///< Get modifiable reference to the blue color component. + void set(ubyte r, ubyte g, ubyte b); const ubyte* ptr() const; diff --git a/Fwk/VizFwk/LibCore/cvfColor4.cpp b/Fwk/VizFwk/LibCore/cvfColor4.cpp index 9a3bb013e4..3d964b88a1 100644 --- a/Fwk/VizFwk/LibCore/cvfColor4.cpp +++ b/Fwk/VizFwk/LibCore/cvfColor4.cpp @@ -180,86 +180,6 @@ bool Color4f::operator!=(const Color4f& rhs) const } -//-------------------------------------------------------------------------------------------------- -/// Returns the red color component of this color -//-------------------------------------------------------------------------------------------------- -const float& Color4f::r() const -{ - return m_rgba[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Returns the green color component of this color -//-------------------------------------------------------------------------------------------------- -const float& Color4f::g() const -{ - return m_rgba[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Returns the blue color component of this color -//-------------------------------------------------------------------------------------------------- -const float& Color4f::b() const -{ - return m_rgba[2]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Returns the alpha color component of this color -//-------------------------------------------------------------------------------------------------- -const float& Color4f::a() const -{ - return m_rgba[3]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the red color component. -/// -/// Used for setting the color, e.g. r() = 0.5f -//-------------------------------------------------------------------------------------------------- -float& Color4f::r() -{ - return m_rgba[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the green color component. -/// -/// Used for setting the color, e.g. g() = 0.5f -//-------------------------------------------------------------------------------------------------- -float& Color4f::g() -{ - return m_rgba[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the blue color component. -/// -/// Used for setting the color, e.g. b() = 0.5f -//-------------------------------------------------------------------------------------------------- -float& Color4f::b() -{ - return m_rgba[2]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the alpha component. -/// -/// Used for setting the color, e.g. a() = 0.5f -//-------------------------------------------------------------------------------------------------- -float& Color4f::a() -{ - return m_rgba[3]; -} - - //-------------------------------------------------------------------------------------------------- /// Sets all color components //-------------------------------------------------------------------------------------------------- @@ -464,78 +384,6 @@ bool Color4ub::operator!=(const Color4ub& rhs) const } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -ubyte Color4ub::r() const -{ - return m_rgba[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -ubyte Color4ub::g() const -{ - return m_rgba[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -ubyte Color4ub::b() const -{ - return m_rgba[2]; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -ubyte Color4ub::a() const -{ - return m_rgba[3]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the red color component. -//-------------------------------------------------------------------------------------------------- -ubyte& Color4ub::r() -{ - return m_rgba[0]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the green color component. -//-------------------------------------------------------------------------------------------------- -ubyte& Color4ub::g() -{ - return m_rgba[1]; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the blue color component. -//-------------------------------------------------------------------------------------------------- -ubyte& Color4ub::b() -{ - return m_rgba[2]; -} - - - -//-------------------------------------------------------------------------------------------------- -/// Get modifiable reference to the alpha color component. -//-------------------------------------------------------------------------------------------------- -ubyte& Color4ub::a() -{ - return m_rgba[3]; -} - - //-------------------------------------------------------------------------------------------------- /// Sets all color components //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibCore/cvfColor4.h b/Fwk/VizFwk/LibCore/cvfColor4.h index db4764527e..3d5b737103 100644 --- a/Fwk/VizFwk/LibCore/cvfColor4.h +++ b/Fwk/VizFwk/LibCore/cvfColor4.h @@ -63,14 +63,14 @@ public: bool operator==(const Color4f& rhs) const; bool operator!=(const Color4f& rhs) const; - const float& r() const; - const float& g() const; - const float& b() const; - const float& a() const; - float& r(); - float& g(); - float& b(); - float& a(); + const float& r() const { return m_rgba[0]; } ///< Returns the red color component + const float& g() const { return m_rgba[1]; } ///< Returns the green color component + const float& b() const { return m_rgba[2]; } ///< Returns the blue color component + const float& a() const { return m_rgba[3]; } ///< Returns the alpha component + float& r() { return m_rgba[0]; } ///< Get modifiable reference to the red color component, used for setting the component. + float& g() { return m_rgba[1]; } ///< Get modifiable reference to the green color component, used for setting the component + float& b() { return m_rgba[2]; } ///< Get modifiable reference to the blue color component, used for setting the component + float& a() { return m_rgba[3]; } ///< Get modifiable reference to the alpha component, used for setting the component void set(float r, float g, float b, float alpha); void set(const Color3f& rgbColor, float alpha); @@ -106,14 +106,15 @@ public: bool operator==(const Color4ub& rhs) const; bool operator!=(const Color4ub& rhs) const; - ubyte r() const; - ubyte g() const; - ubyte b() const; - ubyte a() const; - ubyte& r(); - ubyte& g(); - ubyte& b(); - ubyte& a(); + ubyte r() const { return m_rgba[0]; } ///< Returns the red color component + ubyte g() const { return m_rgba[1]; } ///< Returns the green color component + ubyte b() const { return m_rgba[2]; } ///< Returns the blue color component + ubyte a() const { return m_rgba[3]; } ///< Returns the alpha component + ubyte& r() { return m_rgba[0]; } ///< Get modifiable reference to the red color component. + ubyte& g() { return m_rgba[1]; } ///< Get modifiable reference to the green color component. + ubyte& b() { return m_rgba[2]; } ///< Get modifiable reference to the blue color component. + ubyte& a() { return m_rgba[3]; } ///< Get modifiable reference to the alpha component. + void set(ubyte r, ubyte g, ubyte b, ubyte a); const ubyte* ptr() const; diff --git a/Fwk/VizFwk/LibGuiQt/CMakeLists.txt b/Fwk/VizFwk/LibGuiQt/CMakeLists.txt index 2a52355e46..5184988103 100644 --- a/Fwk/VizFwk/LibGuiQt/CMakeLists.txt +++ b/Fwk/VizFwk/LibGuiQt/CMakeLists.txt @@ -21,6 +21,16 @@ include_directories(../LibRender) include_directories(../LibViewing) +set(CEE_HEADER_FILES +cvfqtBasicAboutDialog.h +cvfqtCvfBoundQGLContext.h +cvfqtMouseState.h +cvfqtOpenGLContext.h +cvfqtOpenGLWidget.h +cvfqtPerformanceInfoHud.h +cvfqtUtils.h +) + set(CEE_SOURCE_FILES cvfqtBasicAboutDialog.cpp cvfqtCvfBoundQGLContext.cpp @@ -31,5 +41,5 @@ cvfqtPerformanceInfoHud.cpp cvfqtUtils.cpp ) -add_library(${PROJECT_NAME} ${CEE_SOURCE_FILES}) +add_library(${PROJECT_NAME} ${CEE_HEADER_FILES} ${CEE_SOURCE_FILES}) diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.cpp b/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.cpp index a10f9779cc..d05f149cb5 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.cpp +++ b/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.cpp @@ -44,7 +44,6 @@ #include #include #include -#include namespace cvfqt { @@ -71,7 +70,7 @@ BasicAboutDialog::BasicAboutDialog(QWidget* parent) //m_appVersion; //m_appCopyright; - m_showCeeVizVersion = true; + m_showLibraryVersion = true; m_showQtVersion = true; m_isDebugBuild = false; @@ -110,21 +109,12 @@ void BasicAboutDialog::setCopyright(const QString& copyright) //-------------------------------------------------------------------------------------------------- -/// Set application icon to display +/// //-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::setApplicationIcon(const QIcon& icon) -{ - m_appIcon = icon; -} - - -//-------------------------------------------------------------------------------------------------- -/// Enable display of CeeViz version -//-------------------------------------------------------------------------------------------------- -void BasicAboutDialog::showCeeVizVersion(bool show) +void BasicAboutDialog::showLibraryVersion(bool show) { CVF_ASSERT(!m_isCreated); - m_showCeeVizVersion = show; + m_showLibraryVersion = show; } @@ -202,15 +192,6 @@ void BasicAboutDialog::create() QVBoxLayout* appInfoLayout = new QVBoxLayout; appInfoLayout->setSpacing(3); - QHBoxLayout* appNameLayout = new QHBoxLayout; - if (!m_appIcon.isNull()) - { - QLabel* iconLabel = new QLabel(this); - iconLabel->setPixmap(m_appIcon.pixmap(QSize(200, 200))); - - appNameLayout->addWidget(iconLabel); - } - // Always do app name CVF_ASSERT(!m_appName.isEmpty()); QLabel* appNameLabel = new QLabel(this); @@ -220,10 +201,7 @@ void BasicAboutDialog::create() appNameFont.setBold(true); appNameLabel->setFont(appNameFont); appNameLabel->setText(m_appName); - - appNameLayout->addWidget(appNameLabel); - - appInfoLayout->addLayout(appNameLayout); + appInfoLayout->addWidget(appNameLabel); // Application version if specified if (!m_appVersion.isEmpty()) @@ -264,8 +242,8 @@ void BasicAboutDialog::create() // Possibly show extend version info - if (m_showCeeVizVersion || - m_showQtVersion || + if (m_showLibraryVersion || + m_showQtVersion || m_verLabels.size() > 0) { QGridLayout* verInfoLayout = new QGridLayout; @@ -273,20 +251,20 @@ void BasicAboutDialog::create() int insertRow = 0; -// // CeeViz version -// if (m_showCeeVizVersion) -// { -// QString ver; -// ver.sprintf("%s.%s%s-%s", CVF_MAJOR_VERSION, CVF_MINOR_VERSION, CVF_SPECIAL_BUILD, CVF_BUILD_NUMBER); -// -// addStringPairToVerInfoLayout("CeeViz ver.: ", ver, verInfoLayout, insertRow++); -// } -// -// // Qt version -// if (m_showQtVersion) -// { -// addStringPairToVerInfoLayout("Qt ver.: ", qVersion(), verInfoLayout, insertRow++); -// } + // Library version + if (m_showLibraryVersion) + { + QString ver; + ver.sprintf("%s.%s%s-%s", CVF_MAJOR_VERSION, CVF_MINOR_VERSION, CVF_SPECIAL_BUILD, CVF_BUILD_NUMBER); + + addStringPairToVerInfoLayout("Library ver.: ", ver, verInfoLayout, insertRow++); + } + + // Qt version + if (m_showQtVersion) + { + addStringPairToVerInfoLayout("Qt ver.: ", qVersion(), verInfoLayout, insertRow++); + } // Custom specified labels if (m_verLabels.size() > 0) @@ -356,39 +334,6 @@ void BasicAboutDialog::addStringPairToVerInfoLayout(const QString& labelStr, con } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString BasicAboutDialog::openGLVersionString() const -{ - QString versionString("OpenGL "); - - QGLFormat::OpenGLVersionFlags flags = QGLFormat::openGLVersionFlags(); - - if (flags & QGLFormat::OpenGL_Version_4_0 ) versionString += "4.0"; - else if (flags & QGLFormat::OpenGL_Version_3_3 ) versionString += "3.3"; - else if (flags & QGLFormat::OpenGL_Version_3_2 ) versionString += "3.2"; - else if (flags & QGLFormat::OpenGL_Version_3_1 ) versionString += "3.1"; - else if (flags & QGLFormat::OpenGL_Version_3_0 ) versionString += "3.0"; - else if (flags & QGLFormat::OpenGL_ES_Version_2_0 ) versionString += "ES_Version 2.0"; - else if (flags & QGLFormat::OpenGL_ES_CommonLite_Version_1_1) versionString += "ES_CommonLite_Version 1.1"; - else if (flags & QGLFormat::OpenGL_ES_Common_Version_1_1 ) versionString += "ES_Common_Version 1.1"; - else if (flags & QGLFormat::OpenGL_ES_CommonLite_Version_1_0) versionString += "ES_CommonLite_Version 1.0"; - else if (flags & QGLFormat::OpenGL_ES_Common_Version_1_0 ) versionString += "ES_Common_Version 1.0"; - else if (flags & QGLFormat::OpenGL_Version_2_1 ) versionString += "2.1"; - else if (flags & QGLFormat::OpenGL_Version_2_0 ) versionString += "2.0"; - else if (flags & QGLFormat::OpenGL_Version_1_5 ) versionString += "1.5"; - else if (flags & QGLFormat::OpenGL_Version_1_4 ) versionString += "1.4"; - else if (flags & QGLFormat::OpenGL_Version_1_3 ) versionString += "1.3"; - else if (flags & QGLFormat::OpenGL_Version_1_2 ) versionString += "1.2"; - else if (flags & QGLFormat::OpenGL_Version_1_1 ) versionString += "1.1"; - else if (flags & QGLFormat::OpenGL_Version_None ) versionString += "None"; - else versionString += "Unknown"; - - return versionString; -} - - } // namespace cvfqt diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.h b/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.h index 7e70e11789..ebbfe715d4 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.h +++ b/Fwk/VizFwk/LibGuiQt/cvfqtBasicAboutDialog.h @@ -38,7 +38,6 @@ #pragma once #include -#include class QGridLayout; @@ -56,37 +55,35 @@ class BasicAboutDialog : public QDialog public: BasicAboutDialog(QWidget* parent); - void setApplicationName(const QString& appName); - void setApplicationVersion(const QString& ver); - void setCopyright(const QString& copyright); - void setApplicationIcon(const QIcon& icon); + void setApplicationName(const QString& appName); + void setApplicationVersion(const QString& ver); + void setCopyright(const QString& copyright); - void showCeeVizVersion(bool show); - void showQtVersion(bool show); - void addVersionEntry(const QString& verLabel, const QString& verText); - void setIsDebugBuild(bool isDebugBuild); + void showLibraryVersion(bool show); + void showQtVersion(bool show); + void addVersionEntry(const QString& verLabel, const QString& verText); + void setIsDebugBuild(bool isDebugBuild); - void create(); + void create(); - QString openGLVersionString() const; private: - void addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow); + void addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow); private: - bool m_isCreated; // Indicates if the create() function has been called + bool m_isCreated; // Indicates if the create() function has been called - QString m_appName; // Application name, appears in bold at the top of the dialog. - QString m_appVersion; // Application version info. Can be empty - QString m_appCopyright; // Application copyright string. Can be empty - QIcon m_appIcon; + QString m_appName; // Application name, appears in bold at the top of the dialog. + QString m_appVersion; // Application version info. Can be empty + QString m_appCopyright; // Application copyright string. Can be empty - bool m_showCeeVizVersion; // Flags whether CeeViz version info should be shown - bool m_showQtVersion; // Flags whether Qt version info should be shown - QStringList m_verLabels; // Labels for user specified version entries - QStringList m_verTexts; // The actual version text for user specified version entries + bool m_showLibraryVersion; // Flags whether version info should be shown for visualization framework + bool m_showQtVersion; // Flags whether Qt version info should be shown + QStringList m_verLabels; // Labels for user specified version entries + QStringList m_verTexts; // The actual version text for user specified version entries - bool m_isDebugBuild; // If set to true, will show info in dlg to indicate that this is a debug build + bool m_isDebugBuild; // If set to true, will show info in dlg to indicate that this is a debug build }; } + diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp b/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp index 088aadc42c..79932e385a 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp +++ b/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp @@ -149,7 +149,12 @@ void OpenGLContext::saveOpenGLState(cvf::OpenGLContext* oglContext) CVF_CHECK_OGL(oglContext); - glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); + glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + CVF_CHECK_OGL(oglContext); + + // For now disable pushing of the vertex array related attributes as it gives a mystical + // crash on Redhat5 under VMWare. Not a big issue, but maybe we can do without this push? + //glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); CVF_CHECK_OGL(oglContext); glPushAttrib(GL_ALL_ATTRIB_BITS); @@ -209,6 +214,9 @@ void OpenGLContext::restoreOpenGLState(cvf::OpenGLContext* oglContext) glPopAttrib(); CVF_CHECK_OGL(oglContext); + + // Currently not pushing vertex attribs, so comment out the pop + //glPopClientAttrib(); glPopClientAttrib(); CVF_CHECK_OGL(oglContext); diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtUtils.cpp b/Fwk/VizFwk/LibGuiQt/cvfqtUtils.cpp index 2ccf57d775..74c97e3f25 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtUtils.cpp +++ b/Fwk/VizFwk/LibGuiQt/cvfqtUtils.cpp @@ -36,12 +36,9 @@ #include "cvfBase.h" -#include "cvfTextureImage.h" - +#include "cvfVector2.h" #include "cvfqtUtils.h" -#include - namespace cvfqt { @@ -58,7 +55,7 @@ namespace cvfqt { //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString Utils::toQString(const cvf::String& ceeString) +QString Utils::toQString(const cvf::String& ceeString) { if (ceeString.isEmpty()) { @@ -112,67 +109,126 @@ cvf::String Utils::fromQString(const QString& qtString) return cvf::String(); } + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void Utils::copyFromQImage(cvf::TextureImage* textureImage, const QImage& qtImage) +QImage Utils::toQImage(const cvf::TextureImage& textureImage) +{ + const int width = static_cast(textureImage.width()); + const int height = static_cast(textureImage.height()); + if (width <= 0 || height <= 0) + { + return QImage(); + } + + const cvf::ubyte* rgbData = textureImage.ptr(); + QImage qimg(width, height, QImage::Format_ARGB32); + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + const int srcIdx = 4*y*width + 4*x; + qimg.setPixel(x, height - y - 1, qRgba(rgbData[srcIdx], rgbData[srcIdx + 1], rgbData[srcIdx + 2], rgbData[srcIdx + 3])); + } + } + + return qimg; + +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void Utils::fromQImage(const QImage& qImage, cvf::TextureImage* textureImage) { CVF_ASSERT(textureImage); - if (qtImage.isNull()) + const int width = qImage.width(); + const int height = qImage.height(); + if (width <= 0 || height <= 0) { + textureImage->clear(); return; } - if (((int)textureImage->height()) != qtImage.height() || ((int)textureImage->width() != qtImage.width())) + return fromQImageRegion(qImage, cvf::Vec2ui(0, 0), cvf::Vec2ui(static_cast(width), static_cast(height)), textureImage); +} + + +//-------------------------------------------------------------------------------------------------- +/// Convert a region of a QImage to a TextureImage +/// +/// \attention The source position \a srcPos is specified in QImage's coordinate system, where +/// the pixel position (0,0) if the upper left corner. +//-------------------------------------------------------------------------------------------------- +void Utils::fromQImageRegion(const QImage& qImage, const cvf::Vec2ui& srcPos, const cvf::Vec2ui& size, cvf::TextureImage* textureImage) +{ + CVF_ASSERT(qImage.width() >= 0); + CVF_ASSERT(qImage.height() >= 0); + const cvf::uint qImgWidth = static_cast(qImage.width()); + const cvf::uint qImgHeight = static_cast(qImage.height()); + + CVF_ASSERT(srcPos.x() < qImgWidth); + CVF_ASSERT(srcPos.y() < qImgHeight); + CVF_ASSERT(srcPos.x() + size.x() <= qImgWidth); + CVF_ASSERT(srcPos.y() + size.y() <= qImgHeight); + CVF_ASSERT(textureImage); + + if (size.x() < 1 || size.y() < 1) { - textureImage->allocate(qtImage.width(), qtImage.height()); + textureImage->clear(); + return; } - int height = textureImage->height(); - int width = textureImage->width(); - - // Check if QImage has format QImage::Format_ARGB32, and perform a direct memory copy of image data - if (qtImage.format() == QImage::Format_ARGB32) + if (textureImage->width() != size.x() || textureImage->height() != size.y()) { - cvf::ubyte* dataPtr = const_cast(textureImage->ptr()); + textureImage->allocate(size.x(), size.y()); + } - int negy = 0; - uint idx = 0; - QRgb qtRgbaVal = 0; - // This loop is a candidate for multi-threading. Testing with OpenMP has so far indicated - // quite large variance in performance (Windows Intel i7 with 8 cores). - // When this function is called from the paint event, - // the user experience is considered better when the paint time is consistent. - for (int y = 0 ; y < height; ++y) + const cvf::uint sizeX = size.x(); + const cvf::uint sizeY = size.y(); + const cvf::uint srcPosX = srcPos.x(); + const cvf::uint srcPosY = srcPos.y(); + cvf::ubyte* textureImageDataPtr = textureImage->ptr(); + + // Check if QImage has format QImage::Format_ARGB32, and use a more optimized path + if (qImage.format() == QImage::Format_ARGB32) + { + for (cvf::uint y = 0; y < sizeY; ++y) { - negy = height - 1 - y; - const uchar* s = qtImage.scanLine(negy); + const cvf::uint scanLineIdx = srcPosY + sizeY - y - 1; + const QRgb* qWholeScanLine = reinterpret_cast(qImage.scanLine(scanLineIdx)); + const QRgb* qPixels = &qWholeScanLine[srcPosX]; - for (int x = 0 ; x < width; ++x) + const cvf::uint dstStartIdx = 4*(y*sizeX); + cvf::ubyte* dstRgba = &textureImageDataPtr[dstStartIdx]; + for (cvf::uint x = 0; x < sizeX; ++x) { - qtRgbaVal = ((QRgb*)s)[x]; // Taken from QImage::pixel(int x, int y) - - idx = 4*(y*width + x); - dataPtr[idx] = qRed(qtRgbaVal); - dataPtr[idx + 1] = qGreen(qtRgbaVal); - dataPtr[idx + 2] = qBlue(qtRgbaVal); - dataPtr[idx + 3] = qAlpha(qtRgbaVal); + QRgb qRgbaVal = qPixels[x]; + dstRgba[0] = qRed(qRgbaVal); + dstRgba[1] = qGreen(qRgbaVal); + dstRgba[2] = qBlue(qRgbaVal); + dstRgba[3] = qAlpha(qRgbaVal); + dstRgba += 4; } } } else { - for (int y = 0 ; y < height; ++y) + cvf::Color4ub cvfRgbVal; + for (cvf::uint y = 0; y < sizeY; ++y) { - int negy = height - 1 - y; - QRgb qtRgbaVal; - cvf::Color4ub cvfRgbVal; - for (int x = 0 ; x < width; ++x) + const cvf::uint qImageYPos = srcPosY + sizeY - y - 1; + for (cvf::uint x = 0; x < sizeX; ++x) { - qtRgbaVal = qtImage.pixel(x, negy); - cvfRgbVal.set(qRed(qtRgbaVal), qGreen(qtRgbaVal), qBlue(qtRgbaVal), qAlpha(qtRgbaVal)); + const QRgb qRgbaVal = qImage.pixel(srcPosX + x, qImageYPos); + cvfRgbVal.r() = qRed(qRgbaVal); + cvfRgbVal.g() = qGreen(qRgbaVal); + cvfRgbVal.b() = qBlue(qRgbaVal); + cvfRgbVal.a() = qAlpha(qRgbaVal); textureImage->setPixel(x, y, cvfRgbVal); } } @@ -180,6 +236,7 @@ void Utils::copyFromQImage(cvf::TextureImage* textureImage, const QImage& qtImag } + } // namespace cvfqt diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtUtils.h b/Fwk/VizFwk/LibGuiQt/cvfqtUtils.h index 1e0f2bca48..9609dd26c4 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtUtils.h +++ b/Fwk/VizFwk/LibGuiQt/cvfqtUtils.h @@ -38,13 +38,10 @@ #pragma once #include "cvfString.h" +#include "cvfTextureImage.h" #include -#include - -namespace cvf { - class TextureImage; -} +#include namespace cvfqt { @@ -57,10 +54,12 @@ namespace cvfqt { class Utils { public: - static QString toQString(const cvf::String& ceeString); - static cvf::String fromQString(const QString& qtString); + static QString toQString(const cvf::String& ceeString); + static cvf::String fromQString(const QString& qtString); - static void copyFromQImage(cvf::TextureImage* textureImage, const QImage& qtImage); + static QImage toQImage(const cvf::TextureImage& textureImage); + static void fromQImage(const QImage& qImage, cvf::TextureImage* textureImage); + static void fromQImageRegion(const QImage& qImage, const cvf::Vec2ui& srcPos, const cvf::Vec2ui& size, cvf::TextureImage* textureImage); }; } diff --git a/Fwk/VizFwk/LibRender/CMakeLists.txt b/Fwk/VizFwk/LibRender/CMakeLists.txt index d4ea84debf..d2e28dee6c 100644 --- a/Fwk/VizFwk/LibRender/CMakeLists.txt +++ b/Fwk/VizFwk/LibRender/CMakeLists.txt @@ -6,6 +6,12 @@ project(LibRender) # Use our strict compile flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_STRICT_CXX_FLAGS}") +# For now, disable warning about unknown pragmas locally here (due to usage of OpenMP) +# Probably need to do this more centralized whenever we use OpenMP more extensively +if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") +endif() + # For now, remove pedantic flag for OSX since it clashes with glew if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") string(REPLACE "-pedantic" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) @@ -27,7 +33,6 @@ cvfDrawableText.h cvfDrawableVectors.h cvfFixedAtlasFont.h cvfFont.h -cvfFontManager.h cvfFramebufferObject.h cvfGeometryBuilderDrawableGeo.h cvfGlyph.h @@ -107,7 +112,6 @@ cvfDrawableText.cpp cvfFramebufferObject.cpp cvfFixedAtlasFont.cpp cvfFont.cpp -cvfFontManager.cpp cvfGeometryBuilderDrawableGeo.cpp cvfGlyph.cpp cvfHitDetail.cpp diff --git a/Fwk/VizFwk/LibRender/cvfDrawableGeo.cpp b/Fwk/VizFwk/LibRender/cvfDrawableGeo.cpp index 4804e28329..f3cddc528b 100644 --- a/Fwk/VizFwk/LibRender/cvfDrawableGeo.cpp +++ b/Fwk/VizFwk/LibRender/cvfDrawableGeo.cpp @@ -536,7 +536,7 @@ void DrawableGeo::setFromFaceList(const UIntArray& faceList) size_t numFaceListEntries = faceList.size(); ref triangleConnects = new UIntArray; - triangleConnects->reserve(numFaceListEntries*3); // Usually too much, but temporary and will be squeezed if kept. + triangleConnects->reserve(numFaceListEntries*3); // Usually too much, but temporary and will be squeezed if kept. size_t i = 0; while (i < numFaceListEntries) @@ -546,12 +546,12 @@ void DrawableGeo::setFromFaceList(const UIntArray& faceList) if (numConnects == 3) { - triangleConnects->add(faceList[i++]); - triangleConnects->add(faceList[i++]); - triangleConnects->add(faceList[i++]); - } - else - { + triangleConnects->add(faceList[i++]); + triangleConnects->add(faceList[i++]); + triangleConnects->add(faceList[i++]); + } + else + { size_t j; for (j = 0; j < numConnects - 2; j++) { @@ -561,38 +561,38 @@ void DrawableGeo::setFromFaceList(const UIntArray& faceList) } i += numConnects; - } + } } // Check if the largest index used in the triangle connects exceeds short representation - if (triangleConnects->max() < std::numeric_limits::max()) - { - // Create an USHORT primitive set - size_t arraySize = triangleConnects->size(); + if (triangleConnects->max() < std::numeric_limits::max()) + { + // Create an USHORT primitive set + size_t arraySize = triangleConnects->size(); - ref shortIndices = new UShortArray; - shortIndices->resize(arraySize); + ref shortIndices = new UShortArray; + shortIndices->resize(arraySize); - size_t j; - for (j = 0; j < arraySize; j++) - { - shortIndices->set(j, static_cast(triangleConnects->get(j))); - } + size_t j; + for (j = 0; j < arraySize; j++) + { + shortIndices->set(j, static_cast(triangleConnects->get(j))); + } - ref prim = new PrimitiveSetIndexedUShort(PT_TRIANGLES); - prim->setIndices(shortIndices.p()); + ref prim = new PrimitiveSetIndexedUShort(PT_TRIANGLES); + prim->setIndices(shortIndices.p()); - m_primitiveSets.push_back(prim.p()); - } - else - { - // Create a UINT primitive set - ref prim = new PrimitiveSetIndexedUInt(PT_TRIANGLES); + m_primitiveSets.push_back(prim.p()); + } + else + { + // Create a UINT primitive set + ref prim = new PrimitiveSetIndexedUInt(PT_TRIANGLES); - triangleConnects->squeeze(); - prim->setIndices(triangleConnects.p()); - m_primitiveSets.push_back(prim.p()); - } + triangleConnects->squeeze(); + prim->setIndices(triangleConnects.p()); + m_primitiveSets.push_back(prim.p()); + } } @@ -643,24 +643,24 @@ void DrawableGeo::setFromQuadVertexArray(Vec3fArray* vertexArray) m_primitiveSets.clear(); size_t numVertices = vertexArray->size(); - size_t numQuads = numVertices/4; - CVF_ASSERT(numVertices%4 == 0); + size_t numQuads = numVertices/4; + CVF_ASSERT(numVertices%4 == 0); // Two triangles per quad ref indices = new UIntArray; - indices->resize(numQuads*2*3); + indices->resize(numQuads*2*3); - size_t index = 0; + size_t index = 0; uint i; for (i = 0; i < numQuads; i++) { indices->set(index++, i*4); - indices->set(index++, i*4 + 1); - indices->set(index++, i*4 + 2); + indices->set(index++, i*4 + 1); + indices->set(index++, i*4 + 2); - indices->set(index++, i*4); - indices->set(index++, i*4 + 2); - indices->set(index++, i*4 + 3); + indices->set(index++, i*4); + indices->set(index++, i*4 + 2); + indices->set(index++, i*4 + 3); } ref prim = new PrimitiveSetIndexedUInt(PT_TRIANGLES); @@ -777,8 +777,8 @@ void DrawableGeo::mergeInto(const Collection& drawableGeos) size_t j = 0; for (j = 0; j < otherDrawable->primitiveSetCount(); j++) { - const PrimitiveSet* primSet = otherDrawable->primitiveSet(j); - CVF_ASSERT(primSet); + const PrimitiveSet* primSet = otherDrawable->primitiveSet(j); + CVF_ASSERT(primSet); ref indices = new UIntArray; indices->resize(primSet->indexCount()); @@ -918,7 +918,7 @@ int DrawableGeo::convertFromUIntToUShort() PrimitiveSetIndexedUInt* primitiveSetUInt = dynamic_cast(primitive); PrimitiveSetIndexedUIntScoped* primitiveSetUIntScoped = dynamic_cast(primitive); - if (vertexCount() < std::numeric_limits::max() && primitiveSetUInt) + if (vertexCount() < std::numeric_limits::max() && primitiveSetUInt) { const UIntArray* uiIndices = primitiveSetUInt->indices(); @@ -1006,7 +1006,7 @@ void DrawableGeo::transform(const Mat4d& transformation) m_vertexBundle->setVertexArray(newVertexArr.p()); - recomputeBoundingBox(); + recomputeBoundingBox(); } @@ -1293,22 +1293,25 @@ bool DrawableGeo::rayIntersect(const Ray& ray, Vec3d* intersectionPoint, uint* f { bool anyHits = false; double minDistSquared = 1.0e300; + Vec3d bestIntersectionPoint(0, 0, 0); + size_t bestFaceHit = 0; cref vertexArr = m_vertexBundle->vertexArray(); - size_t numPrimitiveSets = m_primitiveSets.size(); - size_t iPrimSet; - int accumulatedFaceCount = 0; - - for (iPrimSet = 0; iPrimSet < numPrimitiveSets; iPrimSet++) + size_t accumulatedFaceCount = 0; + const size_t numPrimitiveSets = m_primitiveSets.size(); + for (size_t iPrimSet = 0; iPrimSet < numPrimitiveSets; iPrimSet++) { const PrimitiveSet* primSet = m_primitiveSets.at(iPrimSet); CVF_TIGHT_ASSERT(primSet); UIntArray conn; - int numPrimFaces = static_cast(primSet->faceCount()); -#pragma omp parallel for private (conn) + // Need to use signed integer type with OpenMP, so for now cast it + CVF_ASSERT(primSet->faceCount() < static_cast(std::numeric_limits::max())); + const int numPrimFaces = static_cast(primSet->faceCount()); + + #pragma omp parallel for private (conn) for (int i = 0; i < numPrimFaces; i++) { bool hitThisFace = false; @@ -1327,31 +1330,44 @@ bool DrawableGeo::rayIntersect(const Ray& ray, Vec3d* intersectionPoint, uint* f if (hitThisFace) { - double distSquared = (ray.origin() - localIntersect).lengthSquared(); + const double distSquared = (ray.origin() - localIntersect).lengthSquared(); + #pragma omp critical - { - if (distSquared < minDistSquared) { - if (intersectionPoint) + if (distSquared < minDistSquared) { - *intersectionPoint = localIntersect; + bestIntersectionPoint = localIntersect; + bestFaceHit = i + accumulatedFaceCount; + minDistSquared = distSquared; } - - minDistSquared = distSquared; - if (faceHit) - { - *faceHit = i + accumulatedFaceCount; - } + anyHits = true; } - anyHits = true; } - } } // End omp parallel for + accumulatedFaceCount += numPrimFaces; } - return anyHits; + if (anyHits) + { + if (intersectionPoint) + { + *intersectionPoint = bestIntersectionPoint; + } + + if (faceHit) + { + CVF_ASSERT(bestFaceHit < std::numeric_limits::max()); + *faceHit = static_cast(bestFaceHit); + } + + return true; + } + else + { + return false; + } } @@ -1367,18 +1383,21 @@ bool DrawableGeo::rayIntersect(const Ray& ray, Vec3dArray* intersectionPoints, U std::vector faceIndices; cref vertexArr = m_vertexBundle->vertexArray(); - int accumulatedFaceCount = 0; - size_t numPrimitiveSets = m_primitiveSets.size(); - size_t iPrimSet; - for (iPrimSet = 0; iPrimSet < numPrimitiveSets; iPrimSet++) + size_t accumulatedFaceCount = 0; + const size_t numPrimitiveSets = m_primitiveSets.size(); + for (size_t iPrimSet = 0; iPrimSet < numPrimitiveSets; iPrimSet++) { const PrimitiveSet* primSet = m_primitiveSets.at(iPrimSet); CVF_TIGHT_ASSERT(primSet); UIntArray conn; - int numPrimFaces = static_cast(primSet->faceCount()); -#pragma omp parallel for private(conn) + + // Need to use signed integer type with OpenMP, so for now cast it + CVF_ASSERT(primSet->faceCount() < static_cast(std::numeric_limits::max())); + const int numPrimFaces = static_cast(primSet->faceCount()); + + #pragma omp parallel for private(conn) for (int i = 0; i < numPrimFaces; i++) { bool hitThisFace = false; @@ -1396,13 +1415,16 @@ bool DrawableGeo::rayIntersect(const Ray& ray, Vec3dArray* intersectionPoints, U if (hitThisFace) { - #pragma omp critical - { - isectPts.push_back(localIntersect); - faceIndices.push_back(i + accumulatedFaceCount); - } + #pragma omp critical + { + isectPts.push_back(localIntersect); + + CVF_TIGHT_ASSERT(i + accumulatedFaceCount < std::numeric_limits::max()); + faceIndices.push_back(static_cast(i + accumulatedFaceCount)); + } } } + accumulatedFaceCount += numPrimFaces; } diff --git a/Fwk/VizFwk/LibRender/cvfFontManager.cpp b/Fwk/VizFwk/LibRender/cvfFontManager.cpp deleted file mode 100644 index 99b91476c3..0000000000 --- a/Fwk/VizFwk/LibRender/cvfFontManager.cpp +++ /dev/null @@ -1,111 +0,0 @@ -//################################################################################################## -// -// Custom Visualization Core library -// Copyright (C) 2011-2013 Ceetron AS -// -// This library may be used under the terms of either the GNU General Public License or -// the GNU Lesser General Public License as follows: -// -// GNU General Public License Usage -// This library 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. -// -// This library 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 <> -// for more details. -// -// GNU Lesser General Public License Usage -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library 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 Lesser General Public License at <> -// for more details. -// -//################################################################################################## - - -#include "cvfBase.h" -#include "cvfFontManager.h" - - -namespace cvf { - -//================================================================================================== -/// -/// \class cvf::FontManager -/// \ingroup Render -/// -/// -//================================================================================================== - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -FontManager::FontManager() -{ -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -FontManager::~FontManager() -{ -} - - -//-------------------------------------------------------------------------------------------------- -/// Get number of loaded fonts -//-------------------------------------------------------------------------------------------------- -uint FontManager::numFonts() const -{ - return 0;//m_fonts.size(); -} - - -//-------------------------------------------------------------------------------------------------- -/// Get already loaded font -//-------------------------------------------------------------------------------------------------- -ref FontManager::getFontById(uint id) -{ - CVF_UNUSED(id); - - return NULL; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get embedded font. Load if needed -//-------------------------------------------------------------------------------------------------- -ref FontManager::getEmbeddedFont(EmbeddedFont font) -{ - CVF_UNUSED(font); - - return NULL; -} - - -//-------------------------------------------------------------------------------------------------- -/// Get font located on file. Load if needed. -//-------------------------------------------------------------------------------------------------- -ref FontManager::getFontFromFile(const String& path) -{ - CVF_UNUSED(path); - CVF_ASSERT(!path.isEmpty()); - - // Not supported in this class - return NULL; -} - -} // namespace cvf diff --git a/Fwk/VizFwk/LibRender/cvfFontManager.h b/Fwk/VizFwk/LibRender/cvfFontManager.h deleted file mode 100644 index 33de4a9498..0000000000 --- a/Fwk/VizFwk/LibRender/cvfFontManager.h +++ /dev/null @@ -1,80 +0,0 @@ -//################################################################################################## -// -// Custom Visualization Core library -// Copyright (C) 2011-2013 Ceetron AS -// -// This library may be used under the terms of either the GNU General Public License or -// the GNU Lesser General Public License as follows: -// -// GNU General Public License Usage -// This library 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. -// -// This library 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 <> -// for more details. -// -// GNU Lesser General Public License Usage -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library 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 Lesser General Public License at <> -// for more details. -// -//################################################################################################## - - -#pragma once - -#include "cvfObject.h" -#include "cvfString.h" -#include "cvfFont.h" - -#include - - -namespace cvf { - - -//================================================================================================== -// -// Font management -// -//================================================================================================== -class FontManager : public Object -{ -public: - enum EmbeddedFont - { - DEFAULT, - CVF_1, - CVF_2 - }; - -public: - FontManager(); - virtual ~FontManager(); - - uint numFonts() const; - virtual ref getFontById(uint id); - virtual ref getEmbeddedFont(EmbeddedFont font); - virtual ref getFontFromFile(const String& path); - -private: - static uint uniqueIdCounter; - std::map > m_fonts; -}; - - -} // namespace cvf diff --git a/Fwk/VizFwk/LibRender/cvfLibRender.h b/Fwk/VizFwk/LibRender/cvfLibRender.h index 4b46fbcd0b..61076e85ca 100644 --- a/Fwk/VizFwk/LibRender/cvfLibRender.h +++ b/Fwk/VizFwk/LibRender/cvfLibRender.h @@ -49,7 +49,6 @@ #include "cvfDrawableVectors.h" #include "cvfFixedAtlasFont.h" #include "cvfFont.h" -#include "cvfFontManager.h" #include "cvfFramebufferObject.h" #include "cvfGeometryBuilderDrawableGeo.h" #include "cvfGlyph.h" diff --git a/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.cpp b/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.cpp index 209c02c162..9d32e2b866 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.cpp +++ b/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.cpp @@ -128,24 +128,6 @@ cvf::Vec2ui OverlayAxisCross::sizeHint() } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayAxisCross::maximumSize() -{ - return sizeHint(); -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayAxisCross::minimumSize() -{ - return sizeHint(); -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.h b/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.h index 0dc8bb5524..a08a449235 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.h +++ b/Fwk/VizFwk/LibRender/cvfOverlayAxisCross.h @@ -64,8 +64,6 @@ public: ~OverlayAxisCross(); virtual Vec2ui sizeHint(); - virtual Vec2ui maximumSize(); - virtual Vec2ui minimumSize(); virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); diff --git a/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.cpp b/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.cpp index 715b16c405..b32588bcb9 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.cpp +++ b/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.cpp @@ -115,24 +115,6 @@ cvf::Vec2ui OverlayColorLegend::sizeHint() } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayColorLegend::maximumSize() -{ - return m_sizeHint; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayColorLegend::minimumSize() -{ - return Vec2ui(100,100); -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.h b/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.h index 6bccec27d3..127c5d5e8e 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.h +++ b/Fwk/VizFwk/LibRender/cvfOverlayColorLegend.h @@ -64,8 +64,6 @@ public: virtual ~OverlayColorLegend(); virtual Vec2ui sizeHint(); - virtual Vec2ui maximumSize(); - virtual Vec2ui minimumSize(); virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); diff --git a/Fwk/VizFwk/LibRender/cvfOverlayImage.cpp b/Fwk/VizFwk/LibRender/cvfOverlayImage.cpp index dd1a09311c..3728ab19e7 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayImage.cpp +++ b/Fwk/VizFwk/LibRender/cvfOverlayImage.cpp @@ -107,24 +107,6 @@ cvf::Vec2ui OverlayImage::sizeHint() } -//-------------------------------------------------------------------------------------------------- -/// Returns the maximum size of the text box in pixels -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayImage::maximumSize() -{ - return sizeHint(); -} - - -//-------------------------------------------------------------------------------------------------- -/// Returns the minimum size of the text box in pixels -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayImage::minimumSize() -{ - return sizeHint(); -} - - //-------------------------------------------------------------------------------------------------- /// Render using Shaders //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibRender/cvfOverlayImage.h b/Fwk/VizFwk/LibRender/cvfOverlayImage.h index 5e5508df2b..b3f1ee8629 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayImage.h +++ b/Fwk/VizFwk/LibRender/cvfOverlayImage.h @@ -67,8 +67,6 @@ public: ~OverlayImage(); virtual Vec2ui sizeHint(); - virtual Vec2ui maximumSize(); - virtual Vec2ui minimumSize(); virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); diff --git a/Fwk/VizFwk/LibRender/cvfOverlayItem.cpp b/Fwk/VizFwk/LibRender/cvfOverlayItem.cpp index e8e4f6fbf6..0077f16ff4 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayItem.cpp +++ b/Fwk/VizFwk/LibRender/cvfOverlayItem.cpp @@ -36,45 +36,113 @@ #include "cvfBase.h" -#include "cvfOverlayTextBox.h" -#include "cvfDrawableText.h" -#include "cvfMatrixState.h" -#include "cvfCamera.h" -#include "cvfShaderProgram.h" -#include "cvfOpenGL.h" -#include "cvfViewport.h" -#include "cvfOpenGLResourceManager.h" -#include "cvfUniform.h" - -#ifndef CVF_OPENGL_ES -#include "cvfRenderState_FF.h" -#endif +#include "cvfOverlayItem.h" +#include "cvfRect.h" namespace cvf { + + //================================================================================================== /// /// \class cvf::OverlayItem /// \ingroup Render /// /// A base class for all overlay items +/// +/// The default layout scheme is OverlayItem::HORIZONTAL and the default anchor corner is +/// OverlayItem::BOTTOM_LEFT. Note that when the items are laid out by a Rendering, items with +/// the OverlayItem::HORIZONTAL layout scheme will be placed first. /// //================================================================================================== //-------------------------------------------------------------------------------------------------- -/// Do hit test on the overlay item. Base class only does a check +/// //-------------------------------------------------------------------------------------------------- -bool OverlayItem::pick(int x, int y, const Vec2i& position, const Vec2ui& size) +OverlayItem::OverlayItem() +: m_layoutScheme(HORIZONTAL), + m_anchorCorner(BOTTOM_LEFT), + m_fixedPosition(0, 0) +{ +} + + +//-------------------------------------------------------------------------------------------------- +/// Specify how this overlay item should be laid out +/// +/// The default value for \a layoutScheme is OverlayItem::HORIZONTAL, and the default value +/// for \a anchorCorner is OverlayItem::BOTTOM_LEFT. +//-------------------------------------------------------------------------------------------------- +void OverlayItem::setLayout(LayoutScheme layoutScheme, AnchorCorner anchorCorner) +{ + CVF_ASSERT(layoutScheme == HORIZONTAL || layoutScheme == VERTICAL); + m_layoutScheme = layoutScheme; + m_anchorCorner = anchorCorner; + m_fixedPosition.set(0, 0); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void OverlayItem::setLayoutFixedPosition(const Vec2i& fixedPosition) +{ + m_layoutScheme = FIXED_POSITION; + m_anchorCorner = BOTTOM_LEFT; + m_fixedPosition = fixedPosition; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +OverlayItem::LayoutScheme OverlayItem::layoutScheme() const +{ + return m_layoutScheme; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +OverlayItem::AnchorCorner OverlayItem::anchorCorner() const +{ + return m_anchorCorner; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec2i OverlayItem::fixedPosition() const +{ + return m_fixedPosition; +} + + +//-------------------------------------------------------------------------------------------------- +/// \fn virtual Vec2ui OverlayItem::sizeHint() = 0; +/// +/// Returns the the size hint of this overlay item. +/// +/// The returned size should be in pixels. Derived classes must implement this function. +/// The size returned by this function is currently the exact same size that will be passed in as +/// the \a size parameter to the render() or pick() member functions. +//-------------------------------------------------------------------------------------------------- + + +//-------------------------------------------------------------------------------------------------- +/// Do hit test on the overlay item. +/// +/// Base class only does a check against the bounding box represented by \position and \size. +//-------------------------------------------------------------------------------------------------- +bool OverlayItem::pick(int x, int y, const Vec2i& position, const Vec2ui& size) { Recti oglRect(position, static_cast(size.x()), static_cast(size.y())); - if ((x > oglRect.min().x()) && (x < oglRect.max().x()) && - (y > oglRect.min().y()) && (y < oglRect.max().y())) - { - return true; - } - - return false; + return oglRect.contains(Vec2i(x, y)); } + + } // namespace cvf diff --git a/Fwk/VizFwk/LibRender/cvfOverlayItem.h b/Fwk/VizFwk/LibRender/cvfOverlayItem.h index 910433a20c..7bb0f56879 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayItem.h +++ b/Fwk/VizFwk/LibRender/cvfOverlayItem.h @@ -39,15 +39,13 @@ #include "cvfObject.h" #include "cvfVector2.h" -#include "cvfRect.h" namespace cvf { - - class OpenGLContext; + //================================================================================================== // // Interface for overlay items @@ -56,36 +54,39 @@ class OpenGLContext; class OverlayItem : public Object { public: - enum LayoutCorner + enum LayoutScheme + { + HORIZONTAL, + VERTICAL, + FIXED_POSITION + }; + + enum AnchorCorner { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, - BOTTOM_RIGHT, - UNMANAGED - }; - - enum LayoutDirection - { - HORIZONTAL, - VERTICAL + BOTTOM_RIGHT }; public: - virtual Vec2ui sizeHint() = 0; // In Pixels - virtual Vec2ui maximumSize() = 0; // In Pixels - virtual Vec2ui minimumSize() = 0; // In Pixels - - cvf::Vec2i unmanagedPosition() const { return m_unmanagedPosition; } - void setUnmanagedPosition(cvf::Vec2i val) { m_unmanagedPosition = val; } + OverlayItem(); + void setLayout(LayoutScheme layoutScheme, AnchorCorner anchorCorner); + void setLayoutFixedPosition(const Vec2i& fixedPosition); + LayoutScheme layoutScheme() const; + AnchorCorner anchorCorner() const; + Vec2i fixedPosition() const; + + virtual Vec2ui sizeHint() = 0; virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) = 0; virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) = 0; virtual bool pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size); private: - Vec2i m_unmanagedPosition; - + LayoutScheme m_layoutScheme; + AnchorCorner m_anchorCorner; + Vec2i m_fixedPosition; }; } diff --git a/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.cpp b/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.cpp index 58f1f8170b..ca12d0553a 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.cpp +++ b/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.cpp @@ -63,6 +63,7 @@ #include "cvfTexture.h" #include "cvfSampler.h" #include "cvfRenderStateTextureBindings.h" +#include "cvfRect.h" #ifndef CVF_OPENGL_ES #include "cvfRenderState_FF.h" @@ -148,24 +149,6 @@ cvf::Vec2ui OverlayNavigationCube::sizeHint() } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayNavigationCube::maximumSize() -{ - return sizeHint(); -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayNavigationCube::minimumSize() -{ - return sizeHint(); -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1214,7 +1197,7 @@ bool OverlayNavigationCube::processSelection(int winCoordX, int winCoordY, const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -size_t OverlayNavigationCube::pickItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size) +size_t OverlayNavigationCube::pickItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size) const { Camera cam; configureLocalCamera(&cam, position, size); @@ -1247,7 +1230,7 @@ size_t OverlayNavigationCube::pickItem(int winCoordX, int winCoordY, const Vec2i //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -OverlayNavigationCube::NavCubeItem OverlayNavigationCube::pick2dItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size) +OverlayNavigationCube::NavCubeItem OverlayNavigationCube::pick2dItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size) const { Vec2f vpOrigin; vpOrigin.x() = static_cast(position.x()) + static_cast(size.x())*0.5f; @@ -1289,7 +1272,7 @@ OverlayNavigationCube::NavCubeItem OverlayNavigationCube::pick2dItem(int winCoor //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void OverlayNavigationCube::configureLocalCamera(Camera* camera, const Vec2i& position, const Vec2ui& size) +void OverlayNavigationCube::configureLocalCamera(Camera* camera, const Vec2i& position, const Vec2ui& size) const { // Position the camera far enough away to make the axis and the text fit within the viewport Mat4d axisMatrix = m_camera->viewMatrix(); diff --git a/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.h b/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.h index 674a35bd46..bbbd064641 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.h +++ b/Fwk/VizFwk/LibRender/cvfOverlayNavigationCube.h @@ -80,8 +80,6 @@ public: ~OverlayNavigationCube(); virtual Vec2ui sizeHint(); - virtual Vec2ui maximumSize(); - virtual Vec2ui minimumSize(); virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); @@ -172,13 +170,13 @@ private: NavCubeItem navCubeItem(NavCubeFace face, NavCubeFaceItem item) const; - void configureLocalCamera(Camera* camera, const Vec2i& position, const Vec2ui& size); + void configureLocalCamera(Camera* camera, const Vec2i& position, const Vec2ui& size) const; void viewConfigurationFromNavCubeItem(NavCubeItem item, Vec3d* viewDir, Vec3d* up); Vec3d computeNewUpVector(const Vec3d& viewFrom, const Vec3d currentUp) const; - size_t pickItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size); - NavCubeItem pick2dItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size); + size_t pickItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size) const; + NavCubeItem pick2dItem(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size) const; void updateTextureBindings(OpenGLContext* oglContext, bool software); bool isFaceAlignedViewPoint() const; diff --git a/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.cpp b/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.cpp index 6d24a75628..aeec596c62 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.cpp +++ b/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.cpp @@ -114,24 +114,6 @@ cvf::Vec2ui OverlayScalarMapperLegend::sizeHint() } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayScalarMapperLegend::maximumSize() -{ - return m_sizeHint; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayScalarMapperLegend::minimumSize() -{ - return Vec2ui(100,100); -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.h b/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.h index ac2be99352..7e46bed797 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.h +++ b/Fwk/VizFwk/LibRender/cvfOverlayScalarMapperLegend.h @@ -64,8 +64,6 @@ public: virtual ~OverlayScalarMapperLegend(); virtual Vec2ui sizeHint(); - virtual Vec2ui maximumSize(); - virtual Vec2ui minimumSize(); void setScalarMapper(const ScalarMapper* scalarMapper); virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); diff --git a/Fwk/VizFwk/LibRender/cvfOverlayTextBox.cpp b/Fwk/VizFwk/LibRender/cvfOverlayTextBox.cpp index e7f452216b..f615501b97 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayTextBox.cpp +++ b/Fwk/VizFwk/LibRender/cvfOverlayTextBox.cpp @@ -101,24 +101,6 @@ cvf::Vec2ui OverlayTextBox::sizeHint() } -//-------------------------------------------------------------------------------------------------- -/// Returns the maximum size of the text box in pixels -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayTextBox::maximumSize() -{ - return sizeHint(); -} - - -//-------------------------------------------------------------------------------------------------- -/// Returns the minimum size of the text box in pixels -//-------------------------------------------------------------------------------------------------- -cvf::Vec2ui OverlayTextBox::minimumSize() -{ - return sizeHint(); -} - - //-------------------------------------------------------------------------------------------------- /// Render using Shaders //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibRender/cvfOverlayTextBox.h b/Fwk/VizFwk/LibRender/cvfOverlayTextBox.h index 08529566fe..20da397507 100644 --- a/Fwk/VizFwk/LibRender/cvfOverlayTextBox.h +++ b/Fwk/VizFwk/LibRender/cvfOverlayTextBox.h @@ -59,8 +59,6 @@ public: ~OverlayTextBox(); virtual Vec2ui sizeHint(); - virtual Vec2ui maximumSize(); - virtual Vec2ui minimumSize(); virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size); diff --git a/Fwk/VizFwk/LibRender/cvfScalarMapperUniformLevels.h b/Fwk/VizFwk/LibRender/cvfScalarMapperUniformLevels.h index 62af26473a..44462d1545 100644 --- a/Fwk/VizFwk/LibRender/cvfScalarMapperUniformLevels.h +++ b/Fwk/VizFwk/LibRender/cvfScalarMapperUniformLevels.h @@ -70,6 +70,11 @@ public: virtual bool updateTexture(TextureImage* image) const; bool updateColorLegend(OverlayColorLegend* legend) const; + // HACK to compile until we reconcile new and old scheme for scalar mappers + virtual void majorTickValues(std::vector*) const { CVF_FAIL_MSG("Not implemented"); } + virtual double normalizedValue(double) const { CVF_FAIL_MSG("Not implemented"); return 0; } + virtual double domainValue(double) const { CVF_FAIL_MSG("Not implemented"); return 0; } + private: void recomputeMaxTexCoord(); diff --git a/Fwk/VizFwk/LibRender/cvfTextureImage.cpp b/Fwk/VizFwk/LibRender/cvfTextureImage.cpp index 46e081c0bc..bb2e7d4716 100644 --- a/Fwk/VizFwk/LibRender/cvfTextureImage.cpp +++ b/Fwk/VizFwk/LibRender/cvfTextureImage.cpp @@ -154,6 +154,26 @@ void TextureImage::setFromRgb(const ubyte* rgbData, uint width, uint height) } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void TextureImage::clear() +{ + m_width = 0; + m_height = 0; + m_dataRgba.clear(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +ubyte* TextureImage::ptr() +{ + return m_dataRgba.ptr(); +} + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -216,13 +236,11 @@ void TextureImage::setPixel(uint x, uint y, const Color4ub& clr) CVF_TIGHT_ASSERT(x < m_width); CVF_TIGHT_ASSERT(y < m_height); - const uint idx = 4*(y*m_width + x); - const ubyte* data = clr.ptr(); - - m_dataRgba[idx] = data[0]; - m_dataRgba[idx + 1] = data[1]; - m_dataRgba[idx + 2] = data[2]; - m_dataRgba[idx + 3] = data[3]; + ubyte* rgbaThisPixel = &m_dataRgba[4*(y*m_width + x)]; + rgbaThisPixel[0] = clr.r(); + rgbaThisPixel[1] = clr.g(); + rgbaThisPixel[2] = clr.b(); + rgbaThisPixel[3] = clr.a(); } diff --git a/Fwk/VizFwk/LibRender/cvfTextureImage.h b/Fwk/VizFwk/LibRender/cvfTextureImage.h index 1d20933997..8082b36240 100644 --- a/Fwk/VizFwk/LibRender/cvfTextureImage.h +++ b/Fwk/VizFwk/LibRender/cvfTextureImage.h @@ -63,8 +63,10 @@ public: void setData(const ubyte* rgbaData, uint width, uint height); void setFromRgb(const UByteArray& rgbData, uint width, uint height); void setFromRgb(const ubyte* rgbData, uint width, uint height); + void clear(); ref toRgb() const; + ubyte* ptr(); const ubyte* ptr() const; void setPixel(uint x, uint y, const Color4ub& clr); diff --git a/Fwk/VizFwk/LibViewing/cvfRendering.cpp b/Fwk/VizFwk/LibViewing/cvfRendering.cpp index bf931824d1..52035a3707 100644 --- a/Fwk/VizFwk/LibViewing/cvfRendering.cpp +++ b/Fwk/VizFwk/LibViewing/cvfRendering.cpp @@ -60,13 +60,6 @@ namespace cvf { -// Internal -struct OverlayItemLayout -{ - ref overlayItem; - OverlayItem::LayoutCorner corner; - OverlayItem::LayoutDirection direction; -}; //================================================================================================== @@ -313,41 +306,46 @@ void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRe glScissor(static_cast(m_camera->viewport()->x()), static_cast(m_camera->viewport()->y()), static_cast(m_camera->viewport()->width()), static_cast(m_camera->viewport()->height())); glEnable(GL_SCISSOR_TEST); - OverlayItemRectMap::iterator it; - for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it) - { - OverlayItem* item = it->first; - Recti rect = it->second; - if (useSoftwareRendering) + const size_t numOverlayItems = m_overlayItems.size(); + for (size_t i = 0; i < numOverlayItems; i++) + { + OverlayItem* item = m_overlayItems.at(i); + + Vec2i pos(0, 0); + Vec2ui size(0, 0); + + if (item->layoutScheme() == OverlayItem::FIXED_POSITION) { - item->renderSoftware(oglContext, rect.min(), Vec2ui(static_cast(rect.width()), static_cast(rect.height()))); + pos = item->fixedPosition(); + size = item->sizeHint(); } else { - item->render(oglContext, rect.min(), Vec2ui(static_cast(rect.width()), static_cast(rect.height()))); + // Item should be laid out already - grab its pos/size from the layout map + OverlayItemRectMap::iterator it = itemRectMap.find(item); + if (it != itemRectMap.end()) + { + Recti rect = it->second; + pos = rect.min(); + size.set(static_cast(rect.width()), static_cast(rect.height())); + } } - } - for (size_t i = 0; i < m_overlayItems.size(); i++) - { - OverlayItemLayout item = m_overlayItems.at(i); - if ((item.corner == OverlayItem::UNMANAGED) ) + if (!size.isZero()) { - Vec2ui size = item.overlayItem->sizeHint(); - Vec2i pos = item.overlayItem->unmanagedPosition(); - if (useSoftwareRendering) { - item.overlayItem->renderSoftware(oglContext, pos, size); + item->renderSoftware(oglContext, pos, size); } else { - item.overlayItem->render(oglContext, pos, size); + item->render(oglContext, pos, size); } } } + // Restore scissor settings if (!scissorWasOn) glDisable(GL_SCISSOR_TEST); glScissor(scissorBox[0], scissorBox[1], scissorBox[2], scissorBox[3]); @@ -359,28 +357,32 @@ void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRe //-------------------------------------------------------------------------------------------------- void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap) { - calculateOverlayItemLayout(itemRectMap, OverlayItem::TOP_LEFT, OverlayItem::HORIZONTAL); - calculateOverlayItemLayout(itemRectMap, OverlayItem::TOP_LEFT, OverlayItem::VERTICAL); - calculateOverlayItemLayout(itemRectMap, OverlayItem::TOP_RIGHT, OverlayItem::HORIZONTAL); - calculateOverlayItemLayout(itemRectMap, OverlayItem::TOP_RIGHT, OverlayItem::VERTICAL); - calculateOverlayItemLayout(itemRectMap, OverlayItem::BOTTOM_LEFT, OverlayItem::HORIZONTAL); - calculateOverlayItemLayout(itemRectMap, OverlayItem::BOTTOM_LEFT, OverlayItem::VERTICAL); - calculateOverlayItemLayout(itemRectMap, OverlayItem::BOTTOM_RIGHT, OverlayItem::HORIZONTAL); - calculateOverlayItemLayout(itemRectMap, OverlayItem::BOTTOM_RIGHT, OverlayItem::VERTICAL); + // Must calculate horizontals first since starting position for vertical layout + // will be offset if corner is already populated + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::HORIZONTAL, OverlayItem::TOP_LEFT); + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::VERTICAL, OverlayItem::TOP_LEFT); + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::HORIZONTAL, OverlayItem::TOP_RIGHT); + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::VERTICAL, OverlayItem::TOP_RIGHT); + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::HORIZONTAL, OverlayItem::BOTTOM_LEFT); + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::VERTICAL, OverlayItem::BOTTOM_LEFT); + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::HORIZONTAL, OverlayItem::BOTTOM_RIGHT); + calculateOverlayItemLayoutForSchemeAndCorner(itemRectMap, OverlayItem::VERTICAL, OverlayItem::BOTTOM_RIGHT); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, OverlayItem::LayoutCorner corner, OverlayItem::LayoutDirection direction) +void Rendering::calculateOverlayItemLayoutForSchemeAndCorner(OverlayItemRectMap* itemRectMap, OverlayItem::LayoutScheme layoutScheme, OverlayItem::AnchorCorner anchorCorner) { + CVF_ASSERT(layoutScheme == OverlayItem::HORIZONTAL || layoutScheme == OverlayItem::VERTICAL); + const int border = 3; const Vec2i vpSize = Vec2i(static_cast(m_camera->viewport()->width()), static_cast(m_camera->viewport()->height())); const Vec2i vpPos = Vec2i(m_camera->viewport()->x(), m_camera->viewport()->y()); Vec2i cursor(0,0); - switch (corner) + switch (anchorCorner) { case OverlayItem::TOP_LEFT: cursor.set(border, vpSize.y() - border); break; case OverlayItem::TOP_RIGHT: cursor.set(vpSize.x() - border, vpSize.y() - border); break; @@ -391,55 +393,56 @@ void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, Over cursor += vpPos; - // Adjust based on other already placed items - OverlayItemRectMap::iterator it; - for (it = itemRectMap->begin(); it != itemRectMap->end(); ++it) + // Adjust starting cursor position based on other already placed items in this anchor corner + // The assumption here is that for each corner, the horizontal layout has already been added to the map + if (layoutScheme == OverlayItem::VERTICAL) { - Recti rect = it->second; - - if (rect.contains(cursor) && (direction == OverlayItem::VERTICAL)) + OverlayItemRectMap::iterator it; + for (it = itemRectMap->begin(); it != itemRectMap->end(); ++it) { - if (corner == OverlayItem::BOTTOM_LEFT || corner == OverlayItem::BOTTOM_RIGHT) + const OverlayItem* placedItem = it->first; + const Recti placedItemRect = it->second; + if (placedItem->anchorCorner() == anchorCorner && placedItemRect.contains(cursor)) { - cursor.y() += rect.height() + border; - } - else - { - cursor.y() -= rect.height() + border; + if (anchorCorner == OverlayItem::BOTTOM_LEFT || anchorCorner == OverlayItem::BOTTOM_RIGHT) + { + cursor.y() += placedItemRect.height() + border; + } + else + { + cursor.y() -= placedItemRect.height() + border; + } } } } - size_t numOverlayItems = m_overlayItems.size(); - size_t i; - for (i = 0; i < numOverlayItems; i++) + const size_t numOverlayItems = m_overlayItems.size(); + for (size_t i = 0; i < numOverlayItems; i++) { - OverlayItemLayout item = m_overlayItems.at(i); - if ((item.corner == corner) && (item.direction == direction)) + OverlayItem* item = m_overlayItems.at(i); + if ((item->anchorCorner() == anchorCorner) && (item->layoutScheme() == layoutScheme)) { - CVF_ASSERT(item.overlayItem.notNull()); - // Find this position and size Vec2i position = cursor; - Vec2ui size = item.overlayItem->sizeHint(); - if ((corner == OverlayItem::TOP_RIGHT) || (corner == OverlayItem::BOTTOM_RIGHT)) + Vec2ui size = item->sizeHint(); + if ((anchorCorner == OverlayItem::TOP_RIGHT) || (anchorCorner == OverlayItem::BOTTOM_RIGHT)) { position.x() -= size.x(); } - if ((corner == OverlayItem::TOP_LEFT) || (corner == OverlayItem::TOP_RIGHT)) + if ((anchorCorner == OverlayItem::TOP_LEFT) || (anchorCorner == OverlayItem::TOP_RIGHT)) { position.y() -= size.y(); } // Store the position in the map Recti rect(position.x(), position.y(), static_cast(size.x()), static_cast(size.y())); - (*itemRectMap)[item.overlayItem.p()] = rect; + (*itemRectMap)[item] = rect; // Find next position, moving the cursor - if (direction == OverlayItem::HORIZONTAL) + if (layoutScheme == OverlayItem::HORIZONTAL) { - if ((corner == OverlayItem::TOP_LEFT) || (corner == OverlayItem::BOTTOM_LEFT)) + if ((anchorCorner == OverlayItem::TOP_LEFT) || (anchorCorner == OverlayItem::BOTTOM_LEFT)) { cursor.x() += (size.x() + border); } @@ -448,9 +451,9 @@ void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, Over cursor.x() -= (size.x() + border); } } - else if (direction == OverlayItem::VERTICAL) + else if (layoutScheme == OverlayItem::VERTICAL) { - if ((corner == OverlayItem::BOTTOM_LEFT) || (corner == OverlayItem::BOTTOM_RIGHT)) + if ((anchorCorner == OverlayItem::BOTTOM_LEFT) || (anchorCorner == OverlayItem::BOTTOM_RIGHT)) { cursor.y() += (size.y() + border); } @@ -864,62 +867,30 @@ size_t Rendering::overlayItemCount() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void Rendering::addOverlayItem(OverlayItem* overlayItem, OverlayItem::LayoutCorner corner, OverlayItem::LayoutDirection direction) +void Rendering::addOverlayItem(OverlayItem* overlayItem) { CVF_ASSERT(overlayItem); - - OverlayItemLayout item; - item.corner = corner; - item.direction = direction; - item.overlayItem = overlayItem; - - m_overlayItems.push_back(item); + m_overlayItems.push_back(overlayItem); } //-------------------------------------------------------------------------------------------------- /// Returns the overlay item at the given index. -/// -/// corner and direction are optional parameters to receive the layout attachment of the overlay item //-------------------------------------------------------------------------------------------------- -OverlayItem* Rendering::overlayItem(size_t index, OverlayItem::LayoutCorner* corner, OverlayItem::LayoutDirection* direction) +OverlayItem* Rendering::overlayItem(size_t index) { CVF_ASSERT(index < overlayItemCount()); - - if (corner) - { - *corner = m_overlayItems[index].corner; - } - - if (direction) - { - *direction = m_overlayItems[index].direction; - } - - return m_overlayItems[index].overlayItem.p(); + return m_overlayItems.at(index); } //-------------------------------------------------------------------------------------------------- /// Returns the overlay item at the given index. -/// -/// corner and direction are optional parameters to receive the layout attachment of the overlay item //-------------------------------------------------------------------------------------------------- -const OverlayItem* Rendering::overlayItem(size_t index, OverlayItem::LayoutCorner* corner, OverlayItem::LayoutDirection* direction) const +const OverlayItem* Rendering::overlayItem(size_t index) const { CVF_ASSERT(index < overlayItemCount()); - - if (corner) - { - *corner = m_overlayItems[index].corner; - } - - if (direction) - { - *direction = m_overlayItems[index].direction; - } - - return m_overlayItems[index].overlayItem.p(); + return m_overlayItems.at(index); } @@ -931,15 +902,18 @@ OverlayItem* Rendering::overlayItemFromWindowCoordinates(int x, int y) OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); - OverlayItemRectMap::iterator it; - for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it) + const size_t numOverlayItems = m_overlayItems.size(); + for (size_t i = 0; i < numOverlayItems; i++) { - OverlayItem* item = it->first; - Recti rect = it->second; - - if (item->pick(x, y, rect.min(), Vec2ui(static_cast(rect.width()), static_cast(rect.height())))) + OverlayItem* item = m_overlayItems.at(i); + OverlayItemRectMap::iterator it = itemRectMap.find(item); + if (it != itemRectMap.end()) { - return item; + Recti rect = it->second; + if (item->pick(x, y, rect.min(), Vec2ui(static_cast(rect.width()), static_cast(rect.height())))) + { + return item; + } } } @@ -947,40 +921,12 @@ OverlayItem* Rendering::overlayItemFromWindowCoordinates(int x, int y) } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Recti Rendering::overlayItemRect(OverlayItem* item) -{ - OverlayItemRectMap itemRectMap; - calculateOverlayItemLayout(&itemRectMap); - - OverlayItemRectMap::iterator it = itemRectMap.find(item); - if (it != itemRectMap.end()) - { - return it->second; - } - - return cvf::Recti(); -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Rendering::removeOverlayItem(const OverlayItem* overlayItem) { - CVF_UNUSED(overlayItem); - - std::vector::iterator it; - for (it = m_overlayItems.begin(); it != m_overlayItems.end(); it++) - { - if (it->overlayItem == overlayItem) - { - m_overlayItems.erase(it); - break; - } - } + m_overlayItems.erase(overlayItem); } diff --git a/Fwk/VizFwk/LibViewing/cvfRendering.h b/Fwk/VizFwk/LibViewing/cvfRendering.h index f70a3f1cab..e8d8fc6825 100644 --- a/Fwk/VizFwk/LibViewing/cvfRendering.h +++ b/Fwk/VizFwk/LibViewing/cvfRendering.h @@ -61,7 +61,6 @@ class UniformSet; class RayIntersectSpec; class HitItemCollection; class OpenGLContext; -struct OverlayItemLayout; @@ -127,11 +126,10 @@ public: void clearMaxNumPartsToDraw(); size_t overlayItemCount() const; - void addOverlayItem(OverlayItem* overlayItem, OverlayItem::LayoutCorner corner, OverlayItem::LayoutDirection direction); - OverlayItem* overlayItem(size_t index, OverlayItem::LayoutCorner* corner, OverlayItem::LayoutDirection* direction); - const OverlayItem* overlayItem(size_t index, OverlayItem::LayoutCorner* corner, OverlayItem::LayoutDirection* direction) const; + void addOverlayItem(OverlayItem* overlayItem); + OverlayItem* overlayItem(size_t index); + const OverlayItem* overlayItem(size_t index) const; OverlayItem* overlayItemFromWindowCoordinates(int x, int y); - Recti overlayItemRect(OverlayItem* item); void removeOverlayItem(const OverlayItem* overlayItem); void removeAllOverlayItems(); @@ -140,10 +138,9 @@ public: private: void renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRendering); - typedef std::map OverlayItemRectMap; + typedef std::map OverlayItemRectMap; void calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap); - void calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, OverlayItem::LayoutCorner corner, OverlayItem::LayoutDirection direction); - + void calculateOverlayItemLayoutForSchemeAndCorner(OverlayItemRectMap* itemRectMap, OverlayItem::LayoutScheme layoutScheme, OverlayItem::AnchorCorner anchorCorner); void updateDynamicUniformSets(); void updateAndCombineGlobalDynamicUniformSets(); @@ -154,7 +151,7 @@ private: ref m_camera; ref m_targetFramebuffer; // The target framebuffer for the rendering. NULL means the default window framebuffer. - std::vector m_overlayItems; + Collection m_overlayItems; ref m_visibleParts; // The collection of visible parts for one pass. The collection class is reused between passes ref m_renderQueueSorter; // Render queue sorter, initialized to a basic sorter with minimal sorting strategy