Commit 6619c23c authored by saubatn's avatar saubatn
Browse files

FEATURE 592 Add ImageComponent::prepareForSaving() method to store back the...

FEATURE 592 Add ImageComponent::prepareForSaving() method to store back the frame transform (from world) into the imageData in order to save them.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1842 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 4db65e9f
......@@ -31,6 +31,7 @@
#include "ExtensionManager.h"
#include "Action.h"
#include "HistoryComponent.h"
#include "ImageComponent.h"
// -- QT stuff
#include <QSettings>
......@@ -69,7 +70,7 @@ Application::Application(QString name, int & theArgc, char ** theArgv, bool auto
initIcons(); // sometimes needed to get the icon when compiled in static mode
// recommended (see exec() comment in QApplication)
// recommended (see exec() comment in QApplication)
connect(this, SIGNAL(aboutToQuit()), SLOT(quitting()));
connect(this, SIGNAL(lastWindowClosed()), SLOT(quitting()));
......@@ -143,10 +144,10 @@ Application::Application(QString name, int & theArgc, char ** theArgv, bool auto
}
#endif
}
settings.endGroup();
settings.endGroup();
// Load the resources of the application (mainly its translation file)
initResources();
// Load the resources of the application (mainly its translation file)
initResources();
}
// ----------------- destructor --------------------
......@@ -508,7 +509,13 @@ bool Application::save(Component* component) {
+" <li>Or your correctly registered your component in the CamiTK settings</li></ul>");
return false;
}
else {
else { // ready to save
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();
}
if (cp->save(component)) {
// update the last used dir
setLastUsedDirectory(QFileInfo(component->getFileName()).absoluteDir());
......@@ -1022,31 +1029,31 @@ void Application::saveHistoryAsSXML()
// -------------------- getSelectedLanguage --------------------
QString Application::getSelectedLanguage(){
// Get the path of the Language File in the setting file
QSettings & settings(Application::getSettings());
settings.beginGroup(Application::getName() + ".Application");
// Get the language an d flag for the current Application instance
QString language = settings.value("language").toString();
QString languageAbreviation = settings.value("languageAbreviation").toString();
QString flagFile = settings.value("flagFilename").toString();
settings.endGroup();
return languageAbreviation;
// Get the path of the Language File in the setting file
QSettings & settings(Application::getSettings());
settings.beginGroup(Application::getName() + ".Application");
// Get the language an d flag for the current Application instance
QString language = settings.value("language").toString();
QString languageAbreviation = settings.value("languageAbreviation").toString();
QString flagFile = settings.value("flagFilename").toString();
settings.endGroup();
return languageAbreviation;
}
// -------------------- initResources --------------------
void Application::initResources(){
// Get the selected language
QString selectedLanguage = Application::getSelectedLanguage();
// Get the selected language
QString selectedLanguage = Application::getSelectedLanguage();
// Load the application translation
QTranslator* translator = new QTranslator();
QString languageFile = ":/translate_" + getName().remove("camitk-") +"/translate/translate_" + selectedLanguage + ".qm";
if (!translator->load(languageFile))
CAMITK_WARNING("Application", "initResources", "Cannot load file: " + languageFile.toStdString());
else
QCoreApplication::installTranslator(translator);
// Load the application translation
QTranslator* translator = new QTranslator();
QString languageFile = ":/translate_" + getName().remove("camitk-") +"/translate/translate_" + selectedLanguage + ".qm";
if (!translator->load(languageFile))
CAMITK_WARNING("Application", "initResources", "Cannot load file: " + languageFile.toStdString());
else
QCoreApplication::installTranslator(translator);
}
}
......
......@@ -216,6 +216,8 @@ void ImageComponent::updateProperty(QString name, QVariant value) {
// -------------------- setImageData --------------------
void ImageComponent::setImageData(vtkSmartPointer<vtkImageData> anImageData, bool copy, ImageOrientationHelper::PossibleImageOrientations initialOrientation) {
this->initialOrientation = initialOrientation;
originalImageData = NULL;
if (copy) {
......@@ -301,6 +303,19 @@ void ImageComponent::setImageData(vtkSmartPointer<vtkImageData> anImageData, boo
updateImageProperties();
}
// -------------------- prepareForSaving --------------------
void ImageComponent::prepareForSaving(){
// 3rd Apply the frame transformation to the original image date in order to save it
vtkSmartPointer<vtkImageReslice> imageResliceFilter = vtkSmartPointer<vtkImageReslice>::New();
imageResliceFilter->SetInput(originalImageData);
imageResliceFilter->SetOutputDimensionality(3);
// imageResliceFilter->SetOutputOrigin(0, 0, 0);
vtkSmartPointer<vtkMatrix4x4> frameMatrix = getFrame()->getTransformFromWorld()->GetMatrix();
imageResliceFilter->SetResliceAxes(frameMatrix);
originalImageData = imageResliceFilter->GetOutput();
originalImageData->Update();
}
// -------------------- initLookupTable --------------------
void ImageComponent::initLookupTable() {
......
......@@ -98,7 +98,19 @@ public:
void setImageName( const QString& );
/// get the image volume managed by this Component
vtkSmartPointer<vtkImageData> getImageData();
vtkSmartPointer<vtkImageData> getImageData() const{
return originalImageData;
}
/// Get the initial image orientation
ImageOrientationHelper::PossibleImageOrientations getInitialOrientation() const{
return initialOrientation;
}
/// Prepare the ImageComponent for saving
/// Apply its frame transform to its imageData. This way, original translation and image orientation are saved
/// Also, the frame modification on the image are saved
void prepareForSaving();
/** Method called when a pixel has been picked in the 3D view.
* This method tells all the scene3D to display the slice containing the picked pixel.
......@@ -276,12 +288,10 @@ private:
/// Model to display data
QStandardItemModel *model;
};
/// Initial image orientation
ImageOrientationHelper::PossibleImageOrientations initialOrientation;
// -------------------- getImageData --------------------
inline vtkSmartPointer<vtkImageData> ImageComponent::getImageData() {
return originalImageData;
}
};
}
......
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