| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
MainWindow has some number of QitkSliceViewFull widgets. QitkSliceViewFull widgets paint a QinfoImages and QinfoImage inherits QImage. QinfoImage call QPainter in its method that paints some texts and drawings on itself. Result screen capture is attached as jpg.. You can see the MainWindow (it' is shaded by text console) and error messages. The error messages occurred in QinfoImage when QPainter is initiated. First 22 QinfoImage did well without error messages. From 23rd QinfoImage, it makes the error. And the time of error message starting, differed among the machines. Same code works well in Linux. Do you guys have any idea? Samuel B. Park (byeongjun.park@xxxxxxxx) - Research Associate of Sohn Laboratory. Case Western Reserve University. School of Medicine. Dept. Rad. Oncology http://rophys.meds.case.edu
Attachment:
Attachment:
result_N206142.jpg
Description: JPEG image#include <QApplication>
#include "MainWindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWin;
mainWin.setMinimumWidth(1024);
mainWin.setMinimumHeight(768);
// std::cout << "5" << std::endl;
mainWin.show();
// mainWin.show();
return app.exec();
}
PROJECT(test_N206142)
PROJECT(test_N206142)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0)
#
# Find QT
#
INCLUDE (${CMAKE_ROOT}/Modules/FindQt4.cmake)
#FIND_PACKAGE(QT4 REQUIRED)
INCLUDE (${QT_USE_FILE})
INCLUDE_DIRECTORIES(
${QT_QTOPENGL_INCLUDE_DIR}
)
LINK_LIBRARIES (
${QT_LIBRARIES}
)
IF(WIN32)
ADD_DEFINITIONS(-DQT_DLL)
ENDIF(WIN32)
SET(TEST_SRCS
MainWindow.cpp
app.cpp
QitkSliceViewFull.cpp
QinfoImage.cpp
)
SET(TEST_MOC_HDRS
MainWindow.h
QitkSliceViewFull.h
)
QT4_WRAP_CPP(TEST_MOC_SRCS ${TEST_MOC_HDRS})
ADD_EXECUTABLE(TEST ${TEST_SRCS} ${TEST_MOC_SRCS} ${TEST_RSC_SRCS})
INSTALL(TARGETS TEST
RUNTIME DESTINATION bin
)
#include <QtGui>
#include <QtGui>
#include "MainWindow.h"
#include <QGridLayout>
#include <iostream>
MainWindow::MainWindow()
{
QWidget *cWidget = new QWidget(this);
this->setCentralWidget(cWidget);
QGridLayout *layout = new QGridLayout(cWidget);
for(int i=0; i<5; ++i)
{
for(int j=0; j<5; j++)
{
std::cout << "i=" << i << ", j=" << j << std::endl;
QitkSliceViewFull *view = new QitkSliceViewFull(cWidget);
view->setFixedWidth(250);
view->setFixedHeight(180);
layout->addWidget(view, i, j);
}
}
}
#ifndef MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <vector>
#include <string>
#include "QitkSliceViewFull.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
};
#endif
#include <QtGui>
#include <QtGui>
#include <QColor>
#include "QinfoImage.h"
#include <QImage>
#include <cmath>
#include <iostream>
QinfoImage::QinfoImage( int sx, int sy) :
QImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, QImage::Format_ARGB32_Premultiplied)
{
m_bNeedRedraw = true;
m_iSX = sx;
m_iSY = sy;
m_iNslice = 0;
m_iDim = 2;
setColors();
m_fSpacing = 100.0;
m_pOriImage = new QImage(48, 48, QImage::Format_ARGB32_Premultiplied);
eraseAll();
setDim(m_iDim);
setImagesetName(QObject::tr("test"));
drawRuler(1.0);
drawOrientPad(m_iDim, 0.0, 1.0, 1.0, 0.0);
redrawOrientPad();
}
void QinfoImage::setColors()
{
// theses color concept is derived from Pinnacle3
m_colorRuler = QColor(Qt::yellow);
m_colorOrientBox = QColor(Qt::cyan);
m_colorSliceInfo = QColor(Qt::yellow);
m_colorAxis[0] = QColor(Qt::yellow); // X axis
m_colorAxis[1] = QColor(Qt::green); // Y axis
m_colorAxis[2] = QColor(Qt::cyan); // Z axis
}
QinfoImage::~QinfoImage()
{
}
void QinfoImage::drawRuler(double fSpacing)
{
QPainter painter(this);
painter.setCompositionMode(QPainter::CompositionMode_Source);
int ix, iy;
ix = m_iSX - 10;
iy = m_iSY - 65;
double fcount = 0.0;
int old_height = int(50.0/m_fSpacing) + 3;
painter.fillRect(ix - 16, iy - old_height, 25, old_height + 1, Qt::transparent );
painter.setPen(m_colorRuler);
painter.drawLine(ix-15, iy, ix, iy);
while(fcount < 10.0)
{
fcount +=fSpacing;
iy--;
painter.drawPoint(ix,iy);
}
painter.drawLine(ix-15, iy, ix, iy);
while(fcount < 20.0)
{
fcount +=fSpacing;
iy--;
painter.drawPoint(ix,iy);
}
painter.drawLine(ix-15, iy, ix, iy);
while(fcount < 30.0)
{
fcount +=fSpacing;
iy--;
painter.drawPoint(ix,iy);
}
painter.drawLine(ix-15, iy, ix, iy);
while(fcount < 40.0)
{
fcount +=fSpacing;
iy--;
painter.drawPoint(ix,iy);
}
painter.drawLine(ix-15, iy, ix, iy);
while(fcount < 50.0)
{
fcount +=fSpacing;
iy--;
painter.drawPoint(ix,iy);
}
painter.drawLine(ix-15, iy, ix, iy);
m_fSpacing = fSpacing;
}
void QinfoImage::drawSliceInfo(int numSlice, double fPosSlice)
{
QPainter painter(this);
QRect rect(5, m_iSY - 25, m_iSX - 64, 16);
painter.setCompositionMode(QPainter::CompositionMode_Source);
// Erase the text area
painter.fillRect(rect, Qt::transparent );
painter.setPen(m_colorSliceInfo);
// painter.setFont(QFont("Arial", 12));
// Draw Text
QString str;
str = QObject::tr("Slice ") + QString::number(numSlice)
+ QObject::tr(": ") + m_axisName
+ QString::number(fPosSlice,'f',3)
// + m_imgName +
// QObject::tr("(") + m_planName + QObject::tr(")")
;
painter.drawText(rect, str);
m_iNslice = numSlice;
painter.end();
}
/**
* This is not the funcition called automatically.
* when loading new image set and changing patient orientation setup
* this drawOrientPad() must be called once before IsPixmapReady()
*/
void QinfoImage::drawOrientPad(int dimSlice, double phyX0, double phyX1, double phyY0, double phyY1)
{
bool bFlipX, bFlipY;
QPainter painter(m_pOriImage);
int xStart, xAs, xAe, yAs, yAe;
int xDim, yDim;
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(0,0,48,48,Qt::transparent);
// draw box
painter.setPen(m_colorOrientBox);
painter.drawRect(0,0, 47, 47);
if(dimSlice == 0)
{ // sagital
xDim = 1;
yDim = 2;
if(phyX0 < phyX1)
{ // Y axis is reverse
bFlipX = true;
xStart = 0;
xAs = 32;
xAe = 45;
}
else
{ // Y axis is not reverse
bFlipX = false;
xStart = 16;
xAs = 15;
xAe = 2;
}
if(phyY0 > phyY1)
{ // Y axis is not reverse
bFlipY = false;
yAs = 15;
yAe = 2;
}
else
{ // Y axis is reverse
bFlipY = true;
yAs = 32;
yAe = 45;
}
painter.setPen(m_colorAxis[dimSlice]);
if( bFlipX == bFlipY )
{ // this view from "Left"
// Draw "L"
painter.drawLine(xStart + 5, 10, xStart + 5, 38);
painter.drawLine(xStart + 5, 38, xStart+27, 38);
}
else
{ // this view from "Right"
// Draw "R"
painter.drawLine(xStart+5, 10, xStart+27, 10);
painter.drawLine(xStart+5, 10, xStart+5, 38);
painter.drawLine(xStart+5, 24, xStart+27, 24);
painter.drawLine(xStart+27, 10, xStart+27, 24);
painter.drawLine(xStart+20, 24, xStart+27, 38);
}
}
else if (dimSlice == 1)
{ // coronal
xDim = 0;
yDim = 2;
if(phyX0 < phyX1)
{ // X axis is not reverse
bFlipX = false;
xStart = 0;
xAs = 32;
xAe = 45;
}
else
{ // X axis is reverse
bFlipX = true;
xStart = 16;
xAs = 15;
xAe = 2;
}
if(phyY0 > phyY1)
{ // Y axis is not reverse
bFlipY = false;
yAs = 15;
yAe = 2;
}
else
{ // Y axis is reverse
bFlipY = true;
yAs = 32;
yAe = 45;
}
painter.setPen(m_colorAxis[dimSlice]);
if( bFlipX == bFlipY )
{ // this view from "Anterior"
// Draw "A"
painter.drawLine(xStart + 6, 38, xStart + 16, 10);
painter.drawLine(xStart + 11, 23, xStart + 21, 23);
painter.drawLine(xStart + 27, 38, xStart+16, 10);
}
else
{ // this view from "Posterior"
// Draw "P"
painter.drawLine(xStart+5, 10, xStart+27, 10);
painter.drawLine(xStart+5, 10, xStart+5, 38);
painter.drawLine(xStart+5, 24, xStart+27, 24);
painter.drawLine(xStart+27, 10, xStart+27, 24);
}
}
else if (dimSlice == 2)
{ // axial
xDim = 0;
yDim = 1;
if(phyX0 < phyX1)
{ // X axis is not reverse
bFlipX = false;
xStart = 0;
xAs = 32;
xAe = 45;
}
else
{ // X axis is reverse
bFlipX = true;
xStart = 16;
xAs = 15;
xAe = 2;
}
if(phyY0 > phyY1)
{ // Y axis is not reverse
bFlipY = false;
yAs = 15;
yAe = 2;
}
else
{ // Y axis is reverse
bFlipY = true;
yAs = 32;
yAe = 45;
}
painter.setPen(m_colorAxis[dimSlice]);
if( bFlipX == bFlipY )
{ // this view from "Inferior"
// Draw "I"
painter.drawLine(xStart + 6, 10, xStart + 26, 10);
painter.drawLine(xStart + 16, 10, xStart + 16, 38);
painter.drawLine(xStart + 5, 38, xStart+27, 38);
}
else
{ // this view from "Superior"
// Draw "S"
painter.drawLine(xStart+5, 10, xStart + 27, 10);
painter.drawLine(xStart+5, 10, xStart+5, 24);
painter.drawLine(xStart+5, 24, xStart+27, 24);
painter.drawLine(xStart+27, 24, xStart+27, 38);
painter.drawLine(xStart+5, 38, xStart+27, 38);
}
}
else
{
// ERROR
std::cout << "drawOrientPad() get the wrong dimSlice:" << dimSlice
<< std::endl;
return;
}
// Draw X axis arrow
painter.setPen(m_colorAxis[xDim]);
painter.drawLine(xAs, yAs, xAe, yAs);
painter.drawLine( xAe - (xAe - xAs)/3 , yAs + 3, xAe, yAs);
painter.drawLine( xAe - (xAe - xAs)/3 , yAs - 3, xAe, yAs);
// Draw Y axis arrow
painter.setPen(m_colorAxis[yDim]);
painter.drawLine(xAs, yAs, xAs, yAe);
painter.drawLine( xAs + 3, yAe - (yAe-yAs)/3, xAs, yAe);
painter.drawLine( xAs - 3, yAe - (yAe-yAs)/3, xAs, yAe);
painter.end();
}
void QinfoImage::redrawOrientPad()
{
QPainter painter(this);
int ix, iy;
ix = m_iSX - 57;
iy = m_iSY - 57;
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect( ix, iy, ix+48, iy+48, Qt::transparent);
painter.drawImage( ix, iy, *m_pOriImage);
painter.end();
}
void QinfoImage::eraseAll()
{
QPainter painter(this);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(0,0, m_iSX, m_iSY,Qt::transparent);
painter.end();
}
#ifndef __QINFOIMAGE_H_INCLUDE_392038dks093820390__
#ifndef __QINFOIMAGE_H_INCLUDE_392038dks093820390__
#define __QINFOIMAGE_H_INCLUDE_392038dks093820390__
#include <QImage>
class QColor;
#define DEFAULT_WIDTH (3000)
#define DEFAULT_HEIGHT (2000)
class QinfoImage : public QImage
{
public:
QinfoImage(int sx, int sy);
virtual ~QinfoImage();
void setDirt(bool bf=true)
{
m_bNeedRedraw = bf;
}
void setWidgetArea(int sx, int sy);
void drawRuler(double fSpacing);
void setImagesetName(QString str)
{
m_imgName = QObject::tr(" ") + str;
};
void setPlanName(QString str)
{
m_planName = str;
};
void setDim(int nDim)
{
m_iDim = nDim;
switch(m_iDim)
{
case 0:
m_viewName = QObject::tr("Sag: ");
m_axisName = QObject::tr("X=");
break;
case 1:
m_viewName = QObject::tr("Cor: ");
m_axisName = QObject::tr("Y=");
break;
case 2:
m_viewName = QObject::tr("Axi: ");
m_axisName = QObject::tr("Z=");
break;
default:
m_viewName = QObject::tr("Err: ");
m_axisName = QObject::tr("U=");
break;
}
};
bool isPixmapReady(int numSlice, double fPosSlice, double fSpacing);
void drawSliceInfo(int numSlice, double fPosSlice);
void drawOrientPad(int dimSlice, double phyX0, double phyX1, double phyY0, double phyY1);
protected:
void redrawOrientPad();
void eraseAll();
void setColors();
protected:
bool m_bNeedRedraw;
int m_iSX; // viewable width of the image
int m_iSY; // viewable height of the image
int m_iNslice; // Slice Number for current
int m_iDim; // Dim number of the slice
double m_fSpacing; // spacing value for the ruler
QColor m_colorRuler;
QColor m_colorOrientBox;
QColor m_colorSliceInfo;
QColor m_colorAxis[3];
QString m_imgName;
QString m_planName;
QString m_viewName;
QString m_axisName;
QString m_directionString;
QImage *m_pOriImage;
};
#endif //__QINFOIMAGE_H_INCLUDE_392038dks093820390__
#include <QtGui>
#include <QtGui>
#include "QitkSliceViewFull.h"
QitkSliceViewFull::QitkSliceViewFull(QWidget *parent)
:QWidget(parent)
{
m_pImage = new QImage( DEFAULT_BUFFER_WIDTH, DEFAULT_BUFFER_HEIGHT,QImage::Format_ARGB32_Premultiplied );
m_pImageROI = new QImage( DEFAULT_BUFFER_WIDTH, DEFAULT_BUFFER_HEIGHT,QImage::Format_ARGB32_Premultiplied );
m_pImageBuffer = new QImage(DEFAULT_BUFFER_WIDTH, DEFAULT_BUFFER_HEIGHT, QImage::Format_ARGB32_Premultiplied);
m_pRulerImage = new QImage(DEFAULT_BUFFER_WIDTH, DEFAULT_BUFFER_HEIGHT, QImage::Format_ARGB32_Premultiplied);
m_pInfoImage = new QinfoImage(250, 180);
m_pTraceInfoImage = new QImage(320,40, QImage::Format_ARGB32_Premultiplied);
}
void QitkSliceViewFull::paintEvent(QPaintEvent *event)
{
QPainter painter(m_pImageBuffer);
painter.fillRect(0,0,width(),height(), Qt::black);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.drawImage(0, 0, *m_pImage, 0,0, 250, 180);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(0, 0, *m_pImageROI, 0,0, 250, 180);
painter.setPen(Qt::red);
painter.drawLine(0,80,100,80);
// draw Image information matte
painter.drawImage(0,0, *m_pInfoImage, 0,0, 250, 180);
painter.drawImage(0,0, *m_pRulerImage, 0,0, 250,180);
painter.drawImage(10,10, *m_pTraceInfoImage);
painter.end();
QPainter widgetPainter(this);
widgetPainter.fillRect(0,0,width(),height(), Qt::black);
widgetPainter.drawImage(0,0, *m_pImageBuffer, 0, 0, width(), height());
widgetPainter.end();
} // virtual painting handler
#ifndef QITKSLICEVIEWFULL_H_INCLUDED_2983029
#ifndef QITKSLICEVIEWFULL_H_INCLUDED_2983029
#define QITKSLICEVIEWFULL_H_INCLUDED_2983029
#include <QWidget>
#include <QImage>
#include "QinfoImage.h"
#define DEFAULT_BUFFER_WIDTH (2048)
#define DEFAULT_BUFFER_HEIGHT (2048)
class QitkSliceViewFull : public QWidget
{
Q_OBJECT
public:
QitkSliceViewFull( QWidget *parent);
protected:
void paintEvent(QPaintEvent *pevent);
QImage *m_pImage;
QImage *m_pImageROI;
QImage *m_pImageBuffer;
QImage *m_pRulerImage;
QImage *m_pTraceInfoImage;
QinfoImage *m_pInfoImage;
};
#endif // QITKSLICEVIEWFULL_H_INCLUDED_2983029