Commit 2c2d0451 authored by saubatn's avatar saubatn
Browse files

UPDATED Remove ImageComponent methods prepareForSavin() and postSaving(), uses...

UPDATED Remove ImageComponent methods prepareForSavin() and postSaving(), uses instead a getImageDataWithFrameTransform() used to request the image data with its frame applied (for saving purpose for instance).

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@2180 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 92b6da1d
......@@ -90,7 +90,7 @@ bool VtkImageComponentExtension::save(Component* component) const {
else {
QFileInfo fileInfo(component->getFileName());
vtkSmartPointer<vtkImageData> image = img->getImageData();
vtkSmartPointer<vtkImageData> image = img->getImageDataWithFrameTransform();
if (fileInfo.completeSuffix() == "raw") {
//-- save as raw
......
......@@ -574,16 +574,7 @@ bool Application::save(Component * component) {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
if (ImageComponent * imgComp = dynamic_cast<ImageComponent *>(component)) {
// If we deal with an ImageComponent, prepare it for saving
imgComp->prepareForSaving();
}
if (cp->save(component)) {
if (ImageComponent * imgComp = dynamic_cast<ImageComponent *>(component)) {
// If we deal with an ImageComponent, revert changes made for saving it
imgComp->postSaving();
}
// update the last used dir
setLastUsedDirectory(QFileInfo(component->getFileName()).absoluteDir());
......
......@@ -311,19 +311,21 @@ void ImageComponent::setImageData(vtkSmartPointer<vtkImageData> anImageData,
updateImageProperties();
}
// -------------------- prepareForSaving --------------------
void ImageComponent::prepareForSaving() {
// -------------------- getImageDataWithFrameTransform --------------------
vtkSmartPointer<vtkImageData> ImageComponent::getImageDataWithFrameTransform() {
vtkSmartPointer<vtkImageData> imageDataFramed = vtkSmartPointer<vtkImageData>::New();
imageDataFramed->DeepCopy(originalImageData);
// 1. Put back image data to its original state
vtkSmartPointer<vtkMatrix4x4> backToOriginalImageDataMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
backToOriginalImageDataMatrix->DeepCopy(initialImageDataTransform->GetMatrix());
backToOriginalImageDataMatrix->Invert();
vtkSmartPointer<vtkImageReslice> backToOrigingImageDataFilter = vtkSmartPointer<vtkImageReslice>::New();
backToOrigingImageDataFilter->SetInput(originalImageData);
backToOrigingImageDataFilter->SetInput(imageDataFramed);
backToOrigingImageDataFilter->SetOutputDimensionality(3);
backToOrigingImageDataFilter->SetResliceAxes(backToOriginalImageDataMatrix);
originalImageData = backToOrigingImageDataFilter->GetOutput();
originalImageData->Update();
imageDataFramed = backToOrigingImageDataFilter->GetOutput();
imageDataFramed->Update();
// 2. Retrieve the matrice of the user Muser which has been applied to the initial frame
// Assuming Mframe = MinitFrame * Muser
......@@ -347,11 +349,11 @@ void ImageComponent::prepareForSaving() {
translationTransform->Translate(pos[0], pos[1], pos[2]);
translationTransform->Update();
vtkSmartPointer<vtkImageReslice> translationFilter = vtkSmartPointer<vtkImageReslice>::New();
translationFilter->SetInput(originalImageData);
translationFilter->SetInput(imageDataFramed);
translationFilter->SetOutputDimensionality(3);
translationFilter->SetResliceAxes(translationTransform->GetMatrix());
originalImageData = translationFilter->GetOutput();
originalImageData->Update();
imageDataFramed = translationFilter->GetOutput();
imageDataFramed->Update();
// 4. Retrieve the rotation matrix from the user matrix to manually save it
// only if user has modify it
......@@ -365,17 +367,8 @@ void ImageComponent::prepareForSaving() {
rotationMatrix->SetElement(1, 3, 0.0);
rotationMatrix->SetElement(2, 3, 0.0);
}
}
// -------------------- postSaving --------------------
void ImageComponent::postSaving(){
// Revert changes made on image data
vtkSmartPointer<vtkImageReslice> revertImageDataFilter = vtkSmartPointer<vtkImageReslice>::New();
revertImageDataFilter->SetInput(originalImageData);
revertImageDataFilter->SetOutputDimensionality(3);
revertImageDataFilter->SetResliceAxes(initialImageDataTransform->GetMatrix());
originalImageData = revertImageDataFilter->GetOutput();
originalImageData->Update();
return imageDataFramed;
}
// -------------------- initLookupTable --------------------
......
......@@ -102,22 +102,19 @@ public:
vtkSmartPointer<vtkImageData> getImageData() const {
return originalImageData;
}
/**
* Compute a copy of the original image data on which the frame transform has been applied.
* This allows to keep all the frame transform information on the file when saving it.
* @return a vtkImageData deep copied from the original image data on which the frame transform has been applied.
*/
vtkSmartPointer<vtkImageData> getImageDataWithFrameTransform();
/// 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();
/// Revert all changes made to the image (data and its frame) to save it correctly
/// This allows to correctly manipulate the image again.
void postSaving();
/** 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.
* The arguments are the ccordinates of the 3D point.
......
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