36 #include <QFileDialog> 37 #include <QPushButton> 38 #include <QVBoxLayout> 43 #include <vtkImageData.h> 64 mPatientModelService(patientModelService),
65 mViewService(viewService)
67 this->setAttribute(Qt::WA_DeleteOnClose);
69 QVBoxLayout* layout =
new QVBoxLayout(
this);
70 this->setWindowTitle(
"Set properties for imported data");
72 mUidLabel =
new QLabel(
"Data uid: ");
73 mNameLabel =
new QLabel(
"Data name: ");
75 layout->addWidget(mUidLabel);
76 layout->addWidget(mNameLabel);
80 layout->addWidget(mModalityCombo);
84 layout->addWidget(mImageTypeCombo);
88 layout->addWidget(mParentFrameCombo);
90 mNiftiFormatCheckBox =
new QCheckBox(
"Convert from RAS to LPS coordinates",
this);
91 mNiftiFormatCheckBox->setToolTip(
"" 92 "Use RAS (X=Left->Right Y=Posterior->Anterior Z=Inferior->Superior), as in ITK-Snap.\n" 93 "This is different from DICOM/CustusX, which uses LPS (left-posterior-superior).");
94 mNiftiFormatCheckBox->setChecked(
false);
95 mNiftiFormatCheckBox->setEnabled(
true);
96 mTransformFromParentFrameCheckBox =
new QCheckBox(
"Import transform from Parent",
this);
97 mTransformFromParentFrameCheckBox->setToolTip(
"Replace data transform with that of the parent data.");
98 mTransformFromParentFrameCheckBox->setChecked(
false);
100 mConvertToUnsignedCheckBox =
new QCheckBox(
"Convert to unsigned",
this);
101 mConvertToUnsignedCheckBox->setToolTip(
"Convert imported data set to unsigned values.");
102 mConvertToUnsignedCheckBox->setChecked(
false);
104 layout->addWidget(mNiftiFormatCheckBox);
105 layout->addWidget(mTransformFromParentFrameCheckBox);
106 layout->addWidget(mConvertToUnsignedCheckBox);
108 connect(mParentFrameAdapter.get(), &
Property::changed,
this, &ImportDataDialog::updateImportTransformButton);
109 this->updateImportTransformButton();
111 mErrorLabel =
new QLabel();
112 layout->addWidget(mErrorLabel);
114 QHBoxLayout* buttons =
new QHBoxLayout;
115 layout->addLayout(buttons);
116 mOkButton =
new QPushButton(
"OK",
this);
117 buttons->addStretch();
118 buttons->addWidget(mOkButton);
119 connect(mOkButton, &QPushButton::clicked,
this, &QDialog::accept);
120 connect(
this, &QDialog::accepted,
this, &ImportDataDialog::acceptedSlot);
121 connect(
this, &QDialog::rejected,
this, &ImportDataDialog::finishedSlot);
122 mOkButton->setDefault(
true);
123 mOkButton->setFocus();
125 report(
"Importing data...");
136 QTimer::singleShot(0,
this, SLOT(importDataSlot()));
139 void ImportDataDialog::importDataSlot()
142 mData = mPatientModelService->importData(mFilename, infoText);
143 if (!infoText.isEmpty())
145 infoText +=
"<font color=red><br>If these warnings are not expected the import have probably failed.</font>";
146 if(infoText.contains(
"File already exists", Qt::CaseInsensitive))
147 infoText +=
"<font color=red><br>Importing two different volumes with the same name will lead to undesired effects.</font>";
148 mErrorLabel->setText(infoText);
153 mUidLabel->setText(mFilename);
154 mNameLabel->setText(
"Import failed");
155 mOkButton->setText(
"Exit");
159 mUidLabel->setText(
"Data uid: " +
qstring_cast(mData->getUid()));
160 mNameLabel->setText(
"Data name: " +
qstring_cast(mData->getName()));
163 mModalityAdapter->setData(image);
164 mModalityCombo->setEnabled(image!=0);
165 mImageTypeAdapter->setData(image);
166 mImageTypeCombo->setEnabled(image!=0);
168 this->setInitialGuessForParentFrame();
169 mParentFrameAdapter->setData(mData);
170 mParentFrameCombo->setEnabled(mPatientModelService->getDatas().size()>1);
174 if(mFilename.endsWith(
".nii", Qt::CaseInsensitive))
175 mNiftiFormatCheckBox->setChecked(
true);
177 mConvertToUnsignedCheckBox->setEnabled(
false);
178 if (image && image->getBaseVtkImageData())
180 mConvertToUnsignedCheckBox->setEnabled( (image!=0) && (image->getBaseVtkImageData()->GetScalarTypeMin()<0) );
188 void ImportDataDialog::setInitialGuessForParentFrame()
193 QString base =
qstring_cast(mData->getName()).split(
".")[0];
195 std::map<QString, DataPtr> all = mPatientModelService->getDatas();
196 for (std::map<QString, DataPtr>::iterator iter=all.begin(); iter!=all.end(); ++iter)
198 if (iter->second==mData)
200 QString current =
qstring_cast(iter->second->getName()).split(
".")[0];
201 if (base.indexOf(current)>=0)
203 mData->get_rMd_History()->setParentSpace(iter->first);
210 void ImportDataDialog::updateImportTransformButton()
212 DataPtr parent = mPatientModelService->getData(mParentFrameAdapter->getValue());
213 bool enabled = bool(parent);
214 mTransformFromParentFrameCheckBox->setEnabled(enabled);
217 void ImportDataDialog::acceptedSlot()
219 this->importParentTransform();
220 this->convertFromNifti1Coordinates();
221 this->convertToUnsigned();
223 mPatientModelService->autoSave();
224 mViewService->autoShowData(mData);
225 this->finishedSlot();
228 void ImportDataDialog::finishedSlot()
239 void ImportDataDialog::convertFromNifti1Coordinates()
241 if (!mNiftiFormatCheckBox->isChecked())
249 mData->get_rMd_History()->setRegistration(rMd);
250 report(
"Nifti import: Converted data " + mData->getName() +
" from LPS to RAS coordinates.");
256 void ImportDataDialog::importParentTransform()
258 if (!mTransformFromParentFrameCheckBox->isChecked())
262 DataPtr parent = mPatientModelService->getData(mData->getParentSpace());
265 mData->get_rMd_History()->setRegistration(parent->get_rMd());
266 report(
"Assigned rMd from data [" + parent->getName() +
"] to data [" + mData->getName() +
"]");
269 void ImportDataDialog::convertToUnsigned()
271 if (!mConvertToUnsignedCheckBox->isChecked())
280 image->setVtkImageData(converted->getBaseVtkImageData());
282 ImageTF3DPtr TF3D = converted->getTransferFunctions3D()->createCopy();
283 ImageLUT2DPtr LUT2D = converted->getLookupTable2D()->createCopy();
284 image->setLookupTable2D(LUT2D);
285 image->setTransferFunctions3D(TF3D);
286 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.