15 #include <QFileDialog> 16 #include <QPushButton> 17 #include <QVBoxLayout> 22 #include <vtkImageData.h> 43 mPatientModelService(patientModelService),
44 mViewService(viewService)
46 this->setAttribute(Qt::WA_DeleteOnClose);
48 QVBoxLayout* layout =
new QVBoxLayout(
this);
49 this->setWindowTitle(
"Set properties for imported data");
51 mUidLabel =
new QLabel(
"Data uid: ");
52 mNameLabel =
new QLabel(
"Data name: ");
54 layout->addWidget(mUidLabel);
55 layout->addWidget(mNameLabel);
59 layout->addWidget(mModalityCombo);
63 layout->addWidget(mImageTypeCombo);
67 layout->addWidget(mParentFrameCombo);
69 mNiftiFormatCheckBox =
new QCheckBox(
"Convert from RAS to LPS coordinates",
this);
70 mNiftiFormatCheckBox->setToolTip(
"" 71 "Use RAS (X=Left->Right Y=Posterior->Anterior Z=Inferior->Superior), as in ITK-Snap.\n" 72 "This is different from DICOM/CustusX, which uses LPS (left-posterior-superior).");
73 mNiftiFormatCheckBox->setChecked(
false);
74 mNiftiFormatCheckBox->setEnabled(
true);
75 mTransformFromParentFrameCheckBox =
new QCheckBox(
"Import transform from Parent",
this);
76 mTransformFromParentFrameCheckBox->setToolTip(
"Replace data transform with that of the parent data.");
77 mTransformFromParentFrameCheckBox->setChecked(
false);
79 mConvertToUnsignedCheckBox =
new QCheckBox(
"Convert to unsigned",
this);
80 mConvertToUnsignedCheckBox->setToolTip(
"Convert imported data set to unsigned values.");
81 mConvertToUnsignedCheckBox->setChecked(
false);
83 layout->addWidget(mNiftiFormatCheckBox);
84 layout->addWidget(mTransformFromParentFrameCheckBox);
85 layout->addWidget(mConvertToUnsignedCheckBox);
87 connect(mParentFrameAdapter.get(), &
Property::changed,
this, &ImportDataDialog::updateImportTransformButton);
88 this->updateImportTransformButton();
90 mErrorLabel =
new QLabel();
91 layout->addWidget(mErrorLabel);
93 QHBoxLayout* buttons =
new QHBoxLayout;
94 layout->addLayout(buttons);
95 mOkButton =
new QPushButton(
"OK",
this);
96 buttons->addStretch();
97 buttons->addWidget(mOkButton);
98 connect(mOkButton, &QPushButton::clicked,
this, &QDialog::accept);
99 connect(
this, &QDialog::accepted,
this, &ImportDataDialog::acceptedSlot);
100 connect(
this, &QDialog::rejected,
this, &ImportDataDialog::finishedSlot);
101 mOkButton->setDefault(
true);
102 mOkButton->setFocus();
104 report(
"Importing data...");
115 QTimer::singleShot(0,
this, SLOT(importDataSlot()));
118 void ImportDataDialog::importDataSlot()
121 mData = mPatientModelService->importData(mFilename, infoText);
122 if (!infoText.isEmpty())
124 infoText +=
"<font color=red><br>If these warnings are not expected the import have probably failed.</font>";
125 if(infoText.contains(
"File already exists", Qt::CaseInsensitive))
126 infoText +=
"<font color=red><br>Importing two different volumes with the same name will lead to undesired effects.</font>";
127 mErrorLabel->setText(infoText);
132 mUidLabel->setText(mFilename);
133 mNameLabel->setText(
"Import failed");
134 mOkButton->setText(
"Exit");
138 mUidLabel->setText(
"Data uid: " +
qstring_cast(mData->getUid()));
139 mNameLabel->setText(
"Data name: " +
qstring_cast(mData->getName()));
142 mModalityAdapter->setData(image);
143 mModalityCombo->setEnabled(image!=0);
144 mImageTypeAdapter->setData(image);
145 mImageTypeCombo->setEnabled(image!=0);
147 this->setInitialGuessForParentFrame();
148 mParentFrameAdapter->setData(mData);
149 mParentFrameCombo->setEnabled(mPatientModelService->getDatas().size()>1);
153 if(mFilename.endsWith(
".nii", Qt::CaseInsensitive))
154 mNiftiFormatCheckBox->setChecked(
true);
156 mConvertToUnsignedCheckBox->setEnabled(
false);
157 if (image && image->getBaseVtkImageData())
159 mConvertToUnsignedCheckBox->setEnabled( (image!=0) && (image->getBaseVtkImageData()->GetScalarTypeMin()<0) );
167 void ImportDataDialog::setInitialGuessForParentFrame()
172 QString base =
qstring_cast(mData->getName()).split(
".")[0];
174 std::map<QString, DataPtr> all = mPatientModelService->getDatas();
175 for (std::map<QString, DataPtr>::iterator iter=all.begin(); iter!=all.end(); ++iter)
177 if (iter->second==mData)
179 QString current =
qstring_cast(iter->second->getName()).split(
".")[0];
180 if (base.indexOf(current)>=0)
182 mData->get_rMd_History()->setParentSpace(iter->first);
189 void ImportDataDialog::updateImportTransformButton()
191 DataPtr parent = mPatientModelService->getData(mParentFrameAdapter->getValue());
192 bool enabled = bool(parent);
193 mTransformFromParentFrameCheckBox->setEnabled(enabled);
196 void ImportDataDialog::acceptedSlot()
198 this->importParentTransform();
199 this->convertFromNifti1Coordinates();
200 this->convertToUnsigned();
202 mPatientModelService->autoSave();
203 mViewService->autoShowData(mData);
204 this->finishedSlot();
207 void ImportDataDialog::finishedSlot()
218 void ImportDataDialog::convertFromNifti1Coordinates()
220 if (!mNiftiFormatCheckBox->isChecked())
228 mData->get_rMd_History()->setRegistration(rMd);
229 report(
"Nifti import: Converted data " + mData->getName() +
" from LPS to RAS coordinates.");
235 void ImportDataDialog::importParentTransform()
237 if (!mTransformFromParentFrameCheckBox->isChecked())
241 DataPtr parent = mPatientModelService->getData(mData->getParentSpace());
244 mData->get_rMd_History()->setRegistration(parent->get_rMd());
245 report(
"Assigned rMd from data [" + parent->getName() +
"] to data [" + mData->getName() +
"]");
248 void ImportDataDialog::convertToUnsigned()
250 if (!mConvertToUnsignedCheckBox->isChecked())
259 image->setVtkImageData(converted->getBaseVtkImageData());
261 ImageTF3DPtr TF3D = converted->getTransferFunctions3D()->createCopy();
262 ImageLUT2DPtr LUT2D = converted->getLookupTable2D()->createCopy();
263 image->setLookupTable2D(LUT2D);
264 image->setTransferFunctions3D(TF3D);
265 mPatientModelService->insertData(image);
QString qstring_cast(const T &val)
pcsRAS
Right-Anterior-Superior, used by Slicer3D, ITK-Snap, nifti, MINC.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
cxResource_EXPORT Transform3D createTransformFromReferenceToExternal(PATIENT_COORDINATE_SYSTEM external)
static StringPropertyDataModalityPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class Image > ImagePtr
ImportDataDialog(PatientModelServicePtr patientModelService, ViewServicePtr viewService, QString filename, QWidget *parent=NULL)
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)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
static StringPropertySetParentFramePtr New(PatientModelServicePtr patientModelService)
void changed()
emit when the underlying data value is changed: The user interface will be updated.
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
Namespace for all CustusX production code.