-
Notifications
You must be signed in to change notification settings - Fork 511
Open
Description
int ctkVTKSliceViewTest2(int argc, char* argv[])
{
ctk::vtkSetSurfaceDefaultFormat();
QApplication app(argc, argv);
// Test arguments
QString filename = "Case9_US_resampled.nrrd";
// Command line parser
ctkCommandLineParser parser;
parser.addArgument("", "-I", QVariant::Bool);
parser.addArgument("", "-D", QVariant::String);
bool ok = false;
QHash<QString, QVariant> parsedArgs = parser.parseArguments(app.arguments(), &ok);
if (!ok)
{
std::cerr << qPrintable(parser.errorString()) << std::endl;
return EXIT_FAILURE;
}
bool interactive = parsedArgs["-I"].toBool();
QString data_directory = parsedArgs["-D"].toString();
QString imageFilename = data_directory + "/" + filename;
vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
reader->SetFileName("F:/Projects/ProSegProject/img/Case9_US_resampled.mhd");
//reader->Update();
if (!reader->GetOutput())
{
std::cerr << "Failed to read NRRD file" << std::endl;
return EXIT_FAILURE;
}
// Use reader->GetOutput() as vtkImageData
vtkAlgorithmOutput* imagePort = reader->GetOutputPort();
vtkNew<vtkImageReslice> reslice;
reslice->SetInputConnection(reader->GetOutputPort());
reslice->SetOutputSpacing(0.3, 0.3, 3); // shrink spacing
reslice->Update();
int extent[6];
double spacing[3], origin[3];
vtkImageData* image = reslice->GetOutput();
image->GetExtent(extent);
image->GetSpacing(spacing);
image->GetOrigin(origin);
std::cout << "Extent: ";
for (int i = 0; i < 6; ++i)
{
std::cout << extent[i] << " ";
}
std::cout << std::endl;
// Print spacing
std::cout << "Spacing: ";
for (int i = 0; i < 3; ++i)
{
std::cout << spacing[i] << " ";
}
std::cout << std::endl;
// Print origin
std::cout << "Origin: ";
for (int i = 0; i < 3; ++i)
{
std::cout << origin[i] << " ";
}
std::cout << std::endl;
// Top level widget
QWidget widget;
// .. and its associated layout
QVBoxLayout* topLevelLayout = new QVBoxLayout(&widget);
topLevelLayout->setContentsMargins(0, 0, 0, 0);
// Horizontal layout to contain the spinboxes
QHBoxLayout* spinBoxLayout = new QHBoxLayout;
topLevelLayout->addLayout(spinBoxLayout);
int defaultRowCount = 1;
int defaultColumnCount = 1;
// SpinBox to change number of row in lightBox
QSpinBox* rowSpinBox = new QSpinBox;
rowSpinBox->setRange(1, 10);
rowSpinBox->setSingleStep(1);
rowSpinBox->setValue(defaultRowCount);
spinBoxLayout->addWidget(rowSpinBox);
// SpinBox to change number of column in lightBox
QSpinBox* columnSpinBox = new QSpinBox;
columnSpinBox->setRange(1, 10);
columnSpinBox->setSingleStep(1);
columnSpinBox->setValue(defaultColumnCount);
spinBoxLayout->addWidget(columnSpinBox);
ctkVTKSliceView* sliceView = new ctkVTKSliceView(&widget);
sliceView->setRenderEnabled(true);
sliceView->setMinimumSize(200, 200);
sliceView->setImageDataConnection(reslice->GetOutputPort());
sliceView->setHighlightedBoxColor(QColor(Qt::yellow));
sliceView->lightBoxRendererManager()->SetRenderWindowLayout(defaultRowCount, defaultColumnCount);
//sliceView->resize(1800, 1000);
sliceView->lightBoxRendererManager()->SetHighlighted(0, 0, true);
vtkLightBoxRendererManager* manager = sliceView->lightBoxRendererManager();
// Add annotation text
sliceView->setCornerAnnotationText("CTK");
sliceView->scheduleRender();
topLevelLayout->addWidget(sliceView);
vtkRenderer* testren = manager->GetRenderer(0, 0);
vtkCamera* cam = testren->GetActiveCamera();
double scale = cam->GetParallelScale();
std::cout << "ParallelScale = " << scale << std::endl;
// Set connection
QObject::connect(rowSpinBox, SIGNAL(valueChanged(int)),
sliceView, SLOT(setLightBoxRendererManagerRowCount(int)));
QObject::connect(columnSpinBox, SIGNAL(valueChanged(int)),
sliceView, SLOT(setLightBoxRendererManagerColumnCount(int)));
ctkVTKObjectEventsObserver vtkObserver;
vtkObserver.addConnection(sliceView->lightBoxRendererManager(), vtkCommand::ModifiedEvent,
sliceView, SLOT(scheduleRender()));
widget.show();
// TODO Add image regression test
interactive = true;
if (!interactive)
{
QTimer::singleShot(1000, &app, SLOT(quit()));
}
return app.exec();
}
this is official ctkvtksliceview code , but the grid cell cannot fit the slice when the window initialized.
Metadata
Metadata
Assignees
Labels
No labels