Commit 1d6d8b1a authored by saubatn's avatar saubatn
Browse files

FEATURE 592 Save the initial image orientation when saving in MHA / MHD file format.

NEW Wait cursor when saving a component (saving can be a little bit long).

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1844 ec899d31-69d1-42ba-9299-647d76f65fb3
parent d54c2fe0
......@@ -87,6 +87,7 @@ bool VtkImageComponentExtension::save(Component* component) const {
if (!img)
return false;
else {
QFileInfo fileInfo(component->getFileName());
vtkSmartPointer<vtkImageData> image = img->getImageData();
......@@ -108,7 +109,7 @@ bool VtkImageComponentExtension::save(Component* component) const {
return false;
}
// Write info in a separted file
// Write info in a separated file
QFile infoFile(fileInfo.absoluteDir().absolutePath() + fileInfo.baseName() + ".info");
infoFile.open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream out(&infoFile);
......@@ -170,6 +171,7 @@ bool VtkImageComponentExtension::save(Component* component) const {
if ((QString::compare(fileExt, "mhd", Qt::CaseInsensitive) == 0) ||
(QString::compare(fileExt, "mha", Qt::CaseInsensitive) == 0)) {
writer = vtkSmartPointer<vtkMetaImageWriter>::New();
vtkSmartPointer<vtkMetaImageWriter> metaImgWriter = vtkSmartPointer<vtkMetaImageWriter>::New();
writer->SetFileDimensionality(3);
}
else {
......@@ -188,6 +190,24 @@ bool VtkImageComponentExtension::save(Component* component) const {
writer->SetInput(image);
writer->Write();
// Save image orientation for compatible header (as it is not possible to store it either in
// vtkImageData or vtkMetaImageWriter classes
// we are obliged to open the whole image, as a text, replace the anatomical orientation string
// store it back in ASCII (to preserve data format)
if ((QString::compare(fileExt, "mhd", Qt::CaseInsensitive) == 0) ||
(QString::compare(fileExt, "mha", Qt::CaseInsensitive) == 0)) {
QByteArray fileData;
QFile file(component->getFileName());
file.open(QIODevice::ReadWrite);
fileData = file.readAll();
QString text(fileData);
text.replace(QString("AnatomicalOrientation = ???"), QString("AnatomicalOrientation = ") + ImageOrientationHelper::getOrientationAsQString(img->getInitialOrientation()));
file.seek(0); // go to the beginning of the file
file.write(text.toAscii()); // write back the file, in ASCII to preserve data format
file.close(); // close the file handle.
}
}
return true;
......
......@@ -511,7 +511,9 @@ bool Application::save(Component* component) {
}
else { // ready to save
if(ImageComponent* imgComp = dynamic_cast<ImageComponent*>(component)){
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
if(ImageComponent* imgComp = dynamic_cast<ImageComponent*>(component)){
// If we deal with an ImageComponent, we apply the frame transform to the image data, to save it
imgComp->prepareForSaving();
}
......@@ -520,9 +522,12 @@ bool Application::save(Component* component) {
// update the last used dir
setLastUsedDirectory(QFileInfo(component->getFileName()).absoluteDir());
showStatusBarMessage( component->getName() + tr ( " successfully saved..." ));
QApplication::restoreOverrideCursor();
return true;
}
else {
QApplication::restoreOverrideCursor();
return false;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment