Skip to content

Commit

Permalink
Refactored - renamed all the temporary NewRenderer classes to Renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
pyushkevich committed Jan 13, 2025
1 parent 055f480 commit 37346bc
Show file tree
Hide file tree
Showing 45 changed files with 875 additions and 4,359 deletions.
8 changes: 2 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,6 @@ SET(UI_GENERIC_CXX
GUI/Renderer/CrosshairsRenderer.cxx
GUI/Renderer/DeformationGridRenderer.cxx
GUI/Renderer/EdgePreprocessingSettingsRenderer.cxx
GUI/Renderer/GenericSliceContextItem.cxx
GUI/Renderer/GenericSliceNewRenderer.cxx
GUI/Renderer/GenericSliceRenderer.cxx
GUI/Renderer/Generic3DRenderer.cxx
GUI/Renderer/GMMRenderer.cxx
Expand Down Expand Up @@ -621,7 +619,7 @@ SET(UI_GENERIC_HEADERS
GUI/Model/UIState.h
GUI/Model/VoxelChangeReportModel.h
GUI/Renderer/AbstractRenderer.h
GUI/Renderer/AbstractNewRenderer.h
GUI/Renderer/AbstractContextBasedRenderer.h
GUI/Renderer/AbstractVTKRenderer.h
GUI/Renderer/AbstractVTKSceneRenderer.h
GUI/Renderer/AnnotationRenderer.h
Expand All @@ -630,8 +628,6 @@ SET(UI_GENERIC_HEADERS
GUI/Renderer/DeformationGridRenderer.h
GUI/Renderer/EdgePreprocessingSettingsRenderer.h
GUI/Renderer/Generic3DRenderer.h
GUI/Renderer/GenericSliceNewRenderer.h
GUI/Renderer/GenericSliceContextItem.h
GUI/Renderer/GenericSliceRenderer.h
GUI/Renderer/GMMRenderer.h
GUI/Renderer/IntensityCurveVTKRenderer.h
Expand Down Expand Up @@ -790,7 +786,7 @@ SET(UI_MOC_HEADERS
GUI/Qt/Components/QtFlowLayout.h
GUI/Qt/Components/QtHideOnDeactivateContainer.h
GUI/Qt/Components/QtIPCManager.h
GUI/Qt/Components/QPainterNewRenderContext.h
GUI/Qt/Components/QPainterRenderContext.h
GUI/Qt/Components/QtWarningDialog.h
GUI/Qt/Components/QtWidgetActivator.h
GUI/Qt/Components/RecentHistoryItemsView.h
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#ifndef QPAINTERNEWRENDERCONTEXT_H
#define QPAINTERNEWRENDERCONTEXT_H

#include "AbstractNewRenderer.h"
#include "AbstractContextBasedRenderer.h"
#include "SNAPCommon.h"
#include <QImage>
#include <QPainterPath>
#include <QPainter>
#include <QDebug>
#include <QFontDatabase>

class QPainterNewRenderContextTexture : public AbstractNewRenderContext::Texture
class QPainterRenderContextTexture : public AbstractRenderContext::Texture
{
public:
irisITKObjectMacro(QPainterNewRenderContextTexture, AbstractNewRenderContext::Texture)
irisITKObjectMacro(QPainterRenderContextTexture, AbstractRenderContext::Texture)

protected:
QPixmap qpixmap;
QBrush qbrush;

QPainterNewRenderContextTexture() {}
virtual ~QPainterNewRenderContextTexture() override {}
friend class QPainterNewRenderContext;
QPainterRenderContextTexture() {}
virtual ~QPainterRenderContextTexture() override {}
friend class QPainterRenderContext;
};

class QPainterNewRenderContextPath2D : public AbstractNewRenderContext::Path2D
class QPainterRenderContextPath2D : public AbstractRenderContext::Path2D
{
public:
irisITKObjectMacro(QPainterNewRenderContextPath2D, AbstractNewRenderContext::Texture)
irisITKObjectMacro(QPainterRenderContextPath2D, AbstractRenderContext::Texture)

protected:
QPainterPath *path = nullptr;

QPainterNewRenderContextPath2D() {}
virtual ~QPainterNewRenderContextPath2D() override { if(path) delete(path); }
friend class QPainterNewRenderContext;
QPainterRenderContextPath2D() {}
virtual ~QPainterRenderContextPath2D() override { if(path) delete(path); }
friend class QPainterRenderContext;
};

// Template class that takes a member function pointer as a template parameter
Expand Down Expand Up @@ -94,23 +94,23 @@ using QPainterCompositionModeRestorer =
&QPainter::setCompositionMode>;


class QPainterNewRenderContext : public AbstractNewRenderContext
class QPainterRenderContext : public AbstractRenderContext
{
public:
using RGBAPixel = AbstractNewRenderContext::RGBAPixel;
using RGBAImage = AbstractNewRenderContext::RGBAImage;
using Texture = AbstractNewRenderContext::Texture;
using TexturePtr = AbstractNewRenderContext::TexturePtr;
using Path2D = AbstractNewRenderContext::Path2D;
using Path2DPtr = AbstractNewRenderContext::Path2DPtr;
using VertexVector = AbstractNewRenderContext::VertexVector;
using RGBAPixel = AbstractRenderContext::RGBAPixel;
using RGBAImage = AbstractRenderContext::RGBAImage;
using Texture = AbstractRenderContext::Texture;
using TexturePtr = AbstractRenderContext::TexturePtr;
using Path2D = AbstractRenderContext::Path2D;
using Path2DPtr = AbstractRenderContext::Path2DPtr;
using VertexVector = AbstractRenderContext::VertexVector;

QPainterNewRenderContext(QPainter &painter) : painter(painter) {}
QPainterRenderContext(QPainter &painter) : painter(painter) {}

virtual Path2DPtr CreatePath() override
{
// Create the object that will store the path data
auto wrapper = QPainterNewRenderContextPath2D::New();
auto wrapper = QPainterRenderContextPath2D::New();
wrapper->path = new QPainterPath();
wrapper->Modified();
return Path2DPtr(wrapper.GetPointer());
Expand All @@ -119,7 +119,7 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
virtual void AddPolygonSegmentToPath(Path2D *path, const VertexVector &segment, bool closed) override
{
// Get the QPainterPath from the passed in pointer
auto *wrapper = static_cast<QPainterNewRenderContextPath2D *>(path);
auto *wrapper = static_cast<QPainterRenderContextPath2D *>(path);
auto *p = wrapper->path;

// Add the segment
Expand All @@ -137,7 +137,7 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
virtual TexturePtr CreateTexture(RGBAImage *image) override
{
// Create the object that will store the texture data
auto texture = QPainterNewRenderContextTexture::New();
auto texture = QPainterRenderContextTexture::New();

// Load the texture from ITK
auto size = image->GetBufferedRegion().GetSize();
Expand All @@ -160,7 +160,7 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
virtual TexturePtr ColorizeTexture(Texture *texture, const Vector3d &color) override
{
// Get the original texture
auto *q_texture = static_cast<QPainterNewRenderContextTexture *>(texture);
auto *q_texture = static_cast<QPainterRenderContextTexture *>(texture);

QPixmap result(q_texture->qpixmap.size());
result.fill(Qt::transparent); // Fill with transparency initially
Expand All @@ -172,15 +172,15 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
rpainter.fillRect(result.rect(), QColor::fromRgbF(color[0], color[1], color[2]));
rpainter.end(); // End painting

auto new_texture = QPainterNewRenderContextTexture::New();
auto new_texture = QPainterRenderContextTexture::New();
new_texture->qpixmap = result;
new_texture->Modified();
return TexturePtr(new_texture.GetPointer());
}

virtual void DrawPath(Path2D *path) override
{
auto *wrapper = static_cast<QPainterNewRenderContextPath2D *>(path);
auto *wrapper = static_cast<QPainterRenderContextPath2D *>(path);
QPainterPath *p = wrapper->path;
painter.drawPath(*p);
}
Expand Down Expand Up @@ -315,22 +315,22 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
painter.setBrush(brush);
}

using CompositionMode = AbstractNewRenderContext::CompositionMode;
using CompositionMode = AbstractRenderContext::CompositionMode;

virtual void SetCompositionMode(CompositionMode mode) override
{
switch(mode)
{
case AbstractNewRenderContext::SOURCE_OVER:
case AbstractRenderContext::SOURCE_OVER:
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
break;
case AbstractNewRenderContext::DESTINATION_OVER:
case AbstractRenderContext::DESTINATION_OVER:
painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
break;
case AbstractNewRenderContext::MULTIPLY:
case AbstractRenderContext::MULTIPLY:
painter.setCompositionMode(QPainter::CompositionMode_Xor);
break;
case AbstractNewRenderContext::UNKNOWN:
case AbstractRenderContext::UNKNOWN:
break;
}
}
Expand All @@ -340,13 +340,13 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
switch(painter.compositionMode())
{
case QPainter::CompositionMode_SourceOver:
return AbstractNewRenderContext::SOURCE_OVER;
return AbstractRenderContext::SOURCE_OVER;
case QPainter::CompositionMode_DestinationOver:
return AbstractNewRenderContext::DESTINATION_OVER;
return AbstractRenderContext::DESTINATION_OVER;
case QPainter::CompositionMode_Multiply:
return AbstractNewRenderContext::MULTIPLY;
return AbstractRenderContext::MULTIPLY;
default:
return AbstractNewRenderContext::UNKNOWN;
return AbstractRenderContext::UNKNOWN;
}
}

Expand Down Expand Up @@ -437,7 +437,7 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
bool bilinear,
double opacity) override
{
auto *q_texture = static_cast<QPainterNewRenderContextTexture *>(texture);
auto *q_texture = static_cast<QPainterRenderContextTexture *>(texture);
QPainterOpacityRestorer op(painter, opacity);
QPainterCompositionModeRestorer comp(painter, QPainter::CompositionMode_SourceOver);
QPainterRenderHintsRestorer hints(painter, QPainter::SmoothPixmapTransform, bilinear);
Expand All @@ -457,7 +457,7 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
double opacity,
Vector3d &color) override
{
auto *q_texture = static_cast<QPainterNewRenderContextTexture *>(texture);
auto *q_texture = static_cast<QPainterRenderContextTexture *>(texture);
this->DrawImage(x,y,width,height,texture,bilinear,opacity);
QRectF target(x, y, width, height);
QPainterCompositionModeRestorer comp(painter, QPainter::CompositionMode_Multiply);
Expand All @@ -476,7 +476,7 @@ class QPainterNewRenderContext : public AbstractNewRenderContext
bool bilinear,
double opacity) override
{
auto *q_texture = static_cast<QPainterNewRenderContextTexture *>(texture);
auto *q_texture = static_cast<QPainterRenderContextTexture *>(texture);
QPainterOpacityRestorer op(painter, opacity);
QPainterCompositionModeRestorer comp(painter, QPainter::CompositionMode_SourceOver);
QPainterRenderHintsRestorer hints(painter, QPainter::SmoothPixmapTransform, bilinear);
Expand Down
12 changes: 6 additions & 6 deletions GUI/Qt/Components/QtFrameBufferOpenGLWidget.cxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "QtFrameBufferOpenGLWidget.h"
#include "AbstractNewRenderer.h"
#include "AbstractContextBasedRenderer.h"
#include <QOpenGLFramebufferObject>
#include <QOpenGLPaintDevice>
#include "QPainterNewRenderContext.h"
#include "QPainterRenderContext.h"
#include <chrono>
#include <cstdio>

Expand All @@ -17,7 +17,7 @@ QtFrameBufferOpenGLWidget::~QtFrameBufferOpenGLWidget()
}

void
QtFrameBufferOpenGLWidget::SetRenderer(AbstractNewRenderer *r)
QtFrameBufferOpenGLWidget::SetRenderer(AbstractContextBasedRenderer *r)
{
this->m_Renderer = r;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ QtFrameBufferOpenGLWidget::paintGL()
auto t0 = std::chrono::system_clock::now();
QPainter painter(&device);
painter.setRenderHint(QPainter::Antialiasing, true);
QPainterNewRenderContext context(painter);
QPainterRenderContext context(painter);
m_Renderer->Render(&context);

auto t1 = std::chrono::system_clock::now();
Expand Down Expand Up @@ -133,7 +133,7 @@ QtDirectRenderOpenGLWidget::QtDirectRenderOpenGLWidget(QWidget *parent)
}

void
QtDirectRenderOpenGLWidget::SetRenderer(AbstractNewRenderer *r)
QtDirectRenderOpenGLWidget::SetRenderer(AbstractContextBasedRenderer *r)
{
this->renderer = r;
}
Expand Down Expand Up @@ -161,7 +161,7 @@ QtDirectRenderOpenGLWidget::paintGL()
auto t0 = std::chrono::system_clock::now();
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
QPainterNewRenderContext context(painter);
QPainterRenderContext context(painter);

renderer->Render(&context);
auto t1 = std::chrono::system_clock::now();
Expand Down
14 changes: 7 additions & 7 deletions GUI/Qt/Components/QtFrameBufferOpenGLWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <QOpenGLWidget>
#include <QOpenGLFunctions>

class AbstractNewRenderer;
class AbstractContextBasedRenderer;
class QOpenGLFramebufferObject;

/**
* A simple OpenGL widget with a framebuffer to use with AbstractNewRenderer,
* A simple OpenGL widget with a framebuffer to use with AbstractRenderer,
* supports multisampling
*/
class QtFrameBufferOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
Expand All @@ -18,7 +18,7 @@ class QtFrameBufferOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctio

~QtFrameBufferOpenGLWidget();

void SetRenderer(AbstractNewRenderer *r);
void SetRenderer(AbstractContextBasedRenderer *r);

void updateFBO();

Expand All @@ -31,30 +31,30 @@ class QtFrameBufferOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctio
void setScreenshotRequest(const std::string &filename);

private:
AbstractNewRenderer *m_Renderer;
AbstractContextBasedRenderer *m_Renderer;
std::string m_ScreenshotRequest;

QOpenGLFramebufferObject* m_FrameBufferObject = nullptr;
};


/**
* An OpenGL widget connected to an AbstractNewRenderer, does not use internal frame
* An OpenGL widget connected to an AbstractRenderer, does not use internal frame
* buffer and might not support multisampling. Provided as a backup.
*/
class QtDirectRenderOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
public:
QtDirectRenderOpenGLWidget(QWidget *parent);

void SetRenderer(AbstractNewRenderer *r);
void SetRenderer(AbstractContextBasedRenderer *r);

void initializeGL() override;

void paintGL() override;

private:
AbstractNewRenderer *renderer;
AbstractContextBasedRenderer *renderer;
};


Expand Down
Loading

0 comments on commit 37346bc

Please # to comment.