36 #include <QFileDialog>
37 #include <QPushButton>
38 #include <QVBoxLayout>
43 #include <vtkImageData.h>
68 mPatientModelService(patientModelService)
70 this->setAttribute(Qt::WA_DeleteOnClose);
72 QVBoxLayout* layout =
new QVBoxLayout(
this);
73 this->setWindowTitle(
"Set properties for imported data");
75 mUidLabel =
new QLabel(
"Data uid: ");
76 mNameLabel =
new QLabel(
"Data name: ");
78 layout->addWidget(mUidLabel);
79 layout->addWidget(mNameLabel);
83 layout->addWidget(mModalityCombo);
87 layout->addWidget(mImageTypeCombo);
91 layout->addWidget(mParentFrameCombo);
93 mNiftiFormatCheckBox =
new QCheckBox(
"Use NIfTI-1/ITK-Snap axis definition",
this);
94 mNiftiFormatCheckBox->setToolTip(
""
95 "Use X=Left->Right Y=Posterior->Anterior Z=Inferior->Superior, as in ITK-Snap.\n"
96 "This is different from normal DICOM.");
97 mNiftiFormatCheckBox->setChecked(
false);
98 mNiftiFormatCheckBox->setEnabled(
false);
99 mTransformFromParentFrameCheckBox =
new QCheckBox(
"Import transform from Parent",
this);
100 mTransformFromParentFrameCheckBox->setToolTip(
"Replace data transform with that of the parent data.");
101 mTransformFromParentFrameCheckBox->setChecked(
false);
103 mConvertToUnsignedCheckBox =
new QCheckBox(
"Convert to unsigned",
this);
104 mConvertToUnsignedCheckBox->setToolTip(
""
105 "Convert imported data set to unsigned values.\n"
106 "This is recommended on Linux because the 2D overlay\n"
107 "renderer only handles unsigned.");
108 mConvertToUnsignedCheckBox->setChecked(
false);
110 layout->addWidget(mNiftiFormatCheckBox);
111 layout->addWidget(mTransformFromParentFrameCheckBox);
112 layout->addWidget(mConvertToUnsignedCheckBox);
114 connect(mParentFrameAdapter.get(), SIGNAL(changed()),
this, SLOT(updateImportTransformButton()));
115 this->updateImportTransformButton();
117 mErrorLabel =
new QLabel();
118 layout->addWidget(mErrorLabel);
120 QHBoxLayout* buttons =
new QHBoxLayout;
121 layout->addLayout(buttons);
122 mOkButton =
new QPushButton(
"OK",
this);
123 buttons->addStretch();
124 buttons->addWidget(mOkButton);
125 connect(mOkButton, SIGNAL(clicked()),
this, SLOT(accept()));
126 connect(
this, SIGNAL(accepted()),
this, SLOT(acceptedSlot()));
127 mOkButton->setDefault(
true);
128 mOkButton->setFocus();
130 report(
"Importing data...");
141 QTimer::singleShot(0,
this, SLOT(importDataSlot()));
144 void ImportDataDialog::importDataSlot()
147 mData = mPatientModelService->importData(mFilename, infoText);
148 if (!infoText.isEmpty())
150 infoText +=
"<font color=red><br>If these warnings are not expected the import have probably failed.</font>";
151 if(infoText.contains(
"File already exists", Qt::CaseInsensitive))
152 infoText +=
"<font color=red><br>Importing two different volumes with the same name will lead to undesired effects.</font>";
153 mErrorLabel->setText(infoText);
158 mUidLabel->setText(mFilename);
159 mNameLabel->setText(
"Import failed");
160 mOkButton->setText(
"Exit");
164 mUidLabel->setText(
"Data uid: " +
qstring_cast(mData->getUid()));
165 mNameLabel->setText(
"Data name: " +
qstring_cast(mData->getName()));
167 ImagePtr image = boost::dynamic_pointer_cast<Image>(mData);
168 mModalityAdapter->setData(image);
169 mModalityCombo->setEnabled(image!=0);
170 mImageTypeAdapter->setData(image);
171 mImageTypeCombo->setEnabled(image!=0);
173 this->setInitialGuessForParentFrame();
174 mParentFrameAdapter->setData(mData);
175 mParentFrameCombo->setEnabled(mPatientModelService->getData().size()>1);
178 mNiftiFormatCheckBox->setEnabled(mPatientModelService->getData<Mesh>(mData->getUid())!=0);
180 mConvertToUnsignedCheckBox->setEnabled(
false);
182 if (image && image->getBaseVtkImageData())
187 mConvertToUnsignedCheckBox->setEnabled( (image!=0) && (image->getBaseVtkImageData()->GetScalarTypeMin()<0) );
191 if (mConvertToUnsignedCheckBox->isEnabled())
192 mConvertToUnsignedCheckBox->setChecked(
true);
202 void ImportDataDialog::setInitialGuessForParentFrame()
207 QString base =
qstring_cast(mData->getName()).split(
".")[0];
209 std::map<QString, DataPtr> all = mPatientModelService->getData();
210 for (std::map<QString, DataPtr>::iterator iter=all.begin(); iter!=all.end(); ++iter)
212 if (iter->second==mData)
214 QString current =
qstring_cast(iter->second->getName()).split(
".")[0];
215 if (base.indexOf(current)>=0)
217 mData->get_rMd_History()->setParentSpace(iter->first);
224 void ImportDataDialog::updateImportTransformButton()
226 DataPtr parent = mPatientModelService->getData(mParentFrameAdapter->getValue());
227 bool enabled = bool(parent);
228 mTransformFromParentFrameCheckBox->setEnabled(enabled);
231 void ImportDataDialog::acceptedSlot()
233 this->importParentTransform();
234 this->convertFromNifti1Coordinates();
235 this->convertToUnsigned();
237 mPatientModelService->autoSave();
248 void ImportDataDialog::convertFromNifti1Coordinates()
250 if (!mNiftiFormatCheckBox->isChecked())
256 mData->get_rMd_History()->setRegistration(rMd);
257 report(
"Nifti import: rotated input data " + mData->getName() +
" 180* around Z-axis.");
263 void ImportDataDialog::importParentTransform()
265 if (!mTransformFromParentFrameCheckBox->isChecked())
269 DataPtr parent = mPatientModelService->getData(mData->getParentSpace());
272 mData->get_rMd_History()->setRegistration(parent->get_rMd());
273 report(
"Assigned rMd from data [" + parent->getName() +
"] to data [" + mData->getName() +
"]");
276 void ImportDataDialog::convertToUnsigned()
278 if (!mConvertToUnsignedCheckBox->isChecked())
281 ImagePtr image = boost::dynamic_pointer_cast<Image>(mData);
287 image->setVtkImageData(converted->getBaseVtkImageData());
289 ImageTF3DPtr TF3D = converted->getTransferFunctions3D()->createCopy();
290 ImageLUT2DPtr LUT2D = converted->getLookupTable2D()->createCopy();
291 image->setLookupTable2D(LUT2D);
292 image->setTransferFunctions3D(TF3D);
QString qstring_cast(const T &val)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
static StringPropertyDataModalityPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class Image > ImagePtr
virtual ~ImportDataDialog()
ImagePtr convertImageToUnsigned(PatientModelServicePtr dataManager, ImagePtr image, vtkImageDataPtr suggestedConvertedVolume, bool verbose)
boost::shared_ptr< class Data > DataPtr
static StringPropertyImageTypePtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ImageLUT2D > ImageLUT2DPtr
void showEvent(QShowEvent *event)
ImportDataDialog(PatientModelServicePtr patientModelService, QString filename, QWidget *parent=NULL)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static StringPropertySetParentFramePtr New(PatientModelServicePtr patientModelService)
cxLogicManager_EXPORT ViewServicePtr viewService()
cxLogicManager_EXPORT PatientModelServicePtr patientService()
Transform3D createTransformRotateZ(const double angle)
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr