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(
"Convert from RAS to LPS coordinates",
this);
94 mNiftiFormatCheckBox->setToolTip(
""
95 "Use RAS (X=Left->Right Y=Posterior->Anterior Z=Inferior->Superior), as in ITK-Snap.\n"
96 "This is different from DICOM/CustusX, which uses LPS (left-posterior-superior).");
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(
"Convert imported data set to unsigned values.");
105 mConvertToUnsignedCheckBox->setChecked(
false);
107 layout->addWidget(mNiftiFormatCheckBox);
108 layout->addWidget(mTransformFromParentFrameCheckBox);
109 layout->addWidget(mConvertToUnsignedCheckBox);
111 connect(mParentFrameAdapter.get(), &
Property::changed,
this, &ImportDataDialog::updateImportTransformButton);
112 this->updateImportTransformButton();
114 mErrorLabel =
new QLabel();
115 layout->addWidget(mErrorLabel);
117 QHBoxLayout* buttons =
new QHBoxLayout;
118 layout->addLayout(buttons);
119 mOkButton =
new QPushButton(
"OK",
this);
120 buttons->addStretch();
121 buttons->addWidget(mOkButton);
122 connect(mOkButton, &QPushButton::clicked,
this, &QDialog::accept);
123 connect(
this, &QDialog::accepted,
this, &ImportDataDialog::acceptedSlot);
124 connect(
this, &QDialog::rejected,
this, &ImportDataDialog::finishedSlot);
125 mOkButton->setDefault(
true);
126 mOkButton->setFocus();
128 report(
"Importing data...");
139 QTimer::singleShot(0,
this, SLOT(importDataSlot()));
142 void ImportDataDialog::importDataSlot()
145 mData = mPatientModelService->importData(mFilename, infoText);
146 if (!infoText.isEmpty())
148 infoText +=
"<font color=red><br>If these warnings are not expected the import have probably failed.</font>";
149 if(infoText.contains(
"File already exists", Qt::CaseInsensitive))
150 infoText +=
"<font color=red><br>Importing two different volumes with the same name will lead to undesired effects.</font>";
151 mErrorLabel->setText(infoText);
156 mUidLabel->setText(mFilename);
157 mNameLabel->setText(
"Import failed");
158 mOkButton->setText(
"Exit");
162 mUidLabel->setText(
"Data uid: " +
qstring_cast(mData->getUid()));
163 mNameLabel->setText(
"Data name: " +
qstring_cast(mData->getName()));
165 ImagePtr image = boost::dynamic_pointer_cast<Image>(mData);
166 mModalityAdapter->setData(image);
167 mModalityCombo->setEnabled(image!=0);
168 mImageTypeAdapter->setData(image);
169 mImageTypeCombo->setEnabled(image!=0);
171 this->setInitialGuessForParentFrame();
172 mParentFrameAdapter->setData(mData);
173 mParentFrameCombo->setEnabled(mPatientModelService->getData().size()>1);
176 mNiftiFormatCheckBox->setEnabled(mPatientModelService->getData<Mesh>(mData->getUid())!=0);
178 mConvertToUnsignedCheckBox->setEnabled(
false);
179 if (image && image->getBaseVtkImageData())
184 mConvertToUnsignedCheckBox->setEnabled( (image!=0) && (image->getBaseVtkImageData()->GetScalarTypeMin()<0) );
192 void ImportDataDialog::setInitialGuessForParentFrame()
197 QString base =
qstring_cast(mData->getName()).split(
".")[0];
199 std::map<QString, DataPtr> all = mPatientModelService->getData();
200 for (std::map<QString, DataPtr>::iterator iter=all.begin(); iter!=all.end(); ++iter)
202 if (iter->second==mData)
204 QString current =
qstring_cast(iter->second->getName()).split(
".")[0];
205 if (base.indexOf(current)>=0)
207 mData->get_rMd_History()->setParentSpace(iter->first);
214 void ImportDataDialog::updateImportTransformButton()
216 DataPtr parent = mPatientModelService->getData(mParentFrameAdapter->getValue());
217 bool enabled = bool(parent);
218 mTransformFromParentFrameCheckBox->setEnabled(enabled);
221 void ImportDataDialog::acceptedSlot()
223 this->importParentTransform();
224 this->convertFromNifti1Coordinates();
225 this->convertToUnsigned();
227 mPatientModelService->autoSave();
229 this->finishedSlot();
232 void ImportDataDialog::finishedSlot()
243 void ImportDataDialog::convertFromNifti1Coordinates()
245 if (!mNiftiFormatCheckBox->isChecked())
253 mData->get_rMd_History()->setRegistration(rMd);
254 report(
"Nifti import: Converted data " + mData->getName() +
" from LPS to RAS coordinates.");
260 void ImportDataDialog::importParentTransform()
262 if (!mTransformFromParentFrameCheckBox->isChecked())
266 DataPtr parent = mPatientModelService->getData(mData->getParentSpace());
269 mData->get_rMd_History()->setRegistration(parent->get_rMd());
270 report(
"Assigned rMd from data [" + parent->getName() +
"] to data [" + mData->getName() +
"]");
273 void ImportDataDialog::convertToUnsigned()
275 if (!mConvertToUnsignedCheckBox->isChecked())
278 ImagePtr image = boost::dynamic_pointer_cast<Image>(mData);
284 image->setVtkImageData(converted->getBaseVtkImageData());
286 ImageTF3DPtr TF3D = converted->getTransferFunctions3D()->createCopy();
287 ImageLUT2DPtr LUT2D = converted->getLookupTable2D()->createCopy();
288 image->setLookupTable2D(LUT2D);
289 image->setTransferFunctions3D(TF3D);
QString qstring_cast(const T &val)
pcsRAS
Right-Anterior-Superior, used by Slicer3D, ITK-Snap, nifti.
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
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)
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cxLogicManager_EXPORT ViewServicePtr viewService()
cxLogicManager_EXPORT PatientModelServicePtr patientService()
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr