34 #include <vtkImageData.h>
35 #include <vtkUnsignedCharArray.h>
36 #include <vtkPointData.h>
50 data->SetSpacing(1, 1, 1);
51 data->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
56 int scalarSize = dim[0]*dim[1]*dim[2]*numComp;
58 unsigned char *rawchars = (
unsigned char*)malloc(scalarSize+1);
60 std::fill(rawchars,rawchars+scalarSize, initValue);
63 array->SetNumberOfComponents(1);
65 array->SetArray(rawchars, scalarSize+1, 0);
66 data->GetPointData()->SetScalars(array);
71 data->GetScalarRange();
81 std::vector<vtkImageDataPtr> storage;
82 for (
unsigned i=0; i<N; ++i)
85 storage.push_back(data);
87 std::cout <<
"generated leak for images=" << N << std::endl;
137 for (
unsigned i=0; i<N; ++i)
139 block.
mData.push_back(generateVtkImageData());
143 std::cout << QString(
"generated memory: %1 Mb, %2 blocks").arg(
double(block.
mData.front()->GetActualMemorySize() * N) / 1000.0).arg(
mBlocks.size()).toStdString() << std::endl;
150 std::cout << QString(
"removed one block, %1 left").arg(
mBlocks.size()).toStdString() << std::endl;
162 this->setWindowTitle(
"QtSandbox");
166 this->setCentralWidget(
new QPlainTextEdit);
180 void MemoryTester::addActions()
182 mAction1 =
new QAction(
"Action1",
this);
183 mAction1->setIcon(QIcon(
":/images/go-home.png"));
186 mAddMemAction =
new QAction(
"AddMem",
this);
187 mRemoveMemAction =
new QAction(
"RemMem",
this);
188 mLeakAction =
new QAction(
"Leak",
this);
190 connect(mAddMemAction, SIGNAL(triggered()), mMemory.get(), SLOT(addBlock()));
191 connect(mRemoveMemAction, SIGNAL(triggered()), mMemory.get(), SLOT(removeBlock()));
192 connect(mLeakAction, SIGNAL(triggered()), mMemory.get(), SLOT(generateLeak()));
204 mAboutQtAct =
new QAction(tr(
"About &Qt"),
this);
205 mAboutQtAct->setStatusTip(tr(
"Show the Qt library's About box"));
206 connect(mAboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
208 mAboutAct =
new QAction(tr(
"About QtSandbox"),
this);
209 mAboutAct->setStatusTip(tr(
"Show the Application's About box"));
210 connect(mAboutAct, SIGNAL(triggered()),
this, SLOT(about()));
212 mCrashAct =
new QAction(tr(
"Color crash"),
this);
213 connect(mCrashAct, SIGNAL(triggered()),
this, SLOT(colorCrash()));
216 void MemoryTester::addToolbar()
218 mToolbar = this->addToolBar(
"Mytoolbar");
222 mToolbar->addAction(mRemoveMemAction);
226 void MemoryTester::addMenu()
228 QMenu* fileMenu = menuBar()->addMenu(tr(
"&File"));
229 fileMenu->addAction(mAction1);
230 fileMenu->addAction(mCrashAct);
232 QMenu* helpMenu = menuBar()->addMenu(tr(
"&Help"));
233 helpMenu->addAction(mAboutQtAct);
234 helpMenu->addAction(mAboutAct);
238 void MemoryTester::about()
240 QMessageBox::about(
this, tr(
"About QtSandbox"),
241 tr(
"The <b>QtSandbox</b> is a place where you can "
242 "test out nifty Qt features in a small app. Enjoy!"));
245 void MemoryTester::createStatusBar()
247 statusBar()->showMessage(tr(
"Ready"));
250 void MemoryTester::colorCrash()
252 #if QT_VERSION >= 0x040500
253 QColorDialog dialog(QColor(
"white"),
this);
256 QColor result = QColorDialog::getColor(QColor(
"white"),
this);
std::vector< Block > mBlocks
vtkSmartPointer< class vtkUnsignedCharArray > vtkUnsignedCharArrayPtr
MemoryTester(QWidget *parent=0)
std::vector< vtkImageDataPtr > mData