13 #include <vtkImageData.h> 14 #include <vtkUnsignedCharArray.h> 15 #include <vtkPointData.h> 29 data->SetSpacing(1, 1, 1);
30 data->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
35 int scalarSize = dim[0]*dim[1]*dim[2]*numComp;
37 unsigned char *rawchars = (
unsigned char*)malloc(scalarSize+1);
39 std::fill(rawchars,rawchars+scalarSize, initValue);
42 array->SetNumberOfComponents(1);
44 array->SetArray(rawchars, scalarSize+1, 0);
45 data->GetPointData()->SetScalars(array);
50 data->GetScalarRange();
60 std::vector<vtkImageDataPtr> storage;
61 for (
unsigned i=0; i<N; ++i)
64 storage.push_back(data);
66 std::cout <<
"generated leak for images=" << N << std::endl;
116 for (
unsigned i=0; i<N; ++i)
118 block.
mData.push_back(generateVtkImageData());
122 std::cout << QString(
"generated memory: %1 Mb, %2 blocks").arg(
double(block.
mData.front()->GetActualMemorySize() * N) / 1000.0).arg(
mBlocks.size()).toStdString() << std::endl;
129 std::cout << QString(
"removed one block, %1 left").arg(
mBlocks.size()).toStdString() << std::endl;
141 this->setWindowTitle(
"QtSandbox");
145 this->setCentralWidget(
new QPlainTextEdit);
159 void MemoryTester::addActions()
161 mAction1 =
new QAction(
"Action1",
this);
162 mAction1->setIcon(QIcon(
":/images/go-home.png"));
165 mAddMemAction =
new QAction(
"AddMem",
this);
166 mRemoveMemAction =
new QAction(
"RemMem",
this);
167 mLeakAction =
new QAction(
"Leak",
this);
169 connect(mAddMemAction, SIGNAL(triggered()), mMemory.get(), SLOT(addBlock()));
170 connect(mRemoveMemAction, SIGNAL(triggered()), mMemory.get(), SLOT(removeBlock()));
171 connect(mLeakAction, SIGNAL(triggered()), mMemory.get(), SLOT(generateLeak()));
183 mAboutQtAct =
new QAction(tr(
"About &Qt"),
this);
184 mAboutQtAct->setStatusTip(tr(
"Show the Qt library's About box"));
185 connect(mAboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
187 mAboutAct =
new QAction(tr(
"About QtSandbox"),
this);
188 mAboutAct->setStatusTip(tr(
"Show the Application's About box"));
189 connect(mAboutAct, SIGNAL(triggered()),
this, SLOT(about()));
191 mCrashAct =
new QAction(tr(
"Color crash"),
this);
192 connect(mCrashAct, SIGNAL(triggered()),
this, SLOT(colorCrash()));
195 void MemoryTester::addToolbar()
197 mToolbar = this->addToolBar(
"Mytoolbar");
201 mToolbar->addAction(mRemoveMemAction);
205 void MemoryTester::addMenu()
207 QMenu* fileMenu = menuBar()->addMenu(tr(
"&File"));
208 fileMenu->addAction(mAction1);
209 fileMenu->addAction(mCrashAct);
211 QMenu* helpMenu = menuBar()->addMenu(tr(
"&Help"));
212 helpMenu->addAction(mAboutQtAct);
213 helpMenu->addAction(mAboutAct);
217 void MemoryTester::about()
219 QMessageBox::about(
this, tr(
"About QtSandbox"),
220 tr(
"The <b>QtSandbox</b> is a place where you can " 221 "test out nifty Qt features in a small app. Enjoy!"));
224 void MemoryTester::createStatusBar()
226 statusBar()->showMessage(tr(
"Ready"));
229 void MemoryTester::colorCrash()
231 #if QT_VERSION >= 0x040500 232 QColorDialog dialog(QColor(
"white"),
this);
235 QColor result = QColorDialog::getColor(QColor(
"white"),
this);
std::vector< Block > mBlocks
vtkSmartPointer< class vtkUnsignedCharArray > vtkUnsignedCharArrayPtr
MemoryTester(QWidget *parent=0)
std::vector< vtkImageDataPtr > mData
Namespace for all CustusX production code.