Page MenuHomePhabricator

Implement mitkIOUtil and QmitkIOUtil
Closed, ResolvedPublic

Description

Many tests have lots of methods in common. E.g. SaveImage(std::string), LoadImage(std::string) are frequently used in various tests.

Currently, everybody writes his own implementation or copies the code from somewhere else.

This bug is used to collect the most important methods and decide where to implement them (e.g. mitkTestingCommon).

We can also discuss whether the DataNodeFactory could be used in the final implementation. However, the interfaces should be designed for the test developer.

Brainstorming for methods:
-LoadImage(std::string)
-SaveImage(std::string)
-LoadSurface(std::string)
...

@Marco: could we work on this during the bugsquashing?

Related Objects

Event Timeline

We need this to improve the tests of image readers and writers.

The interface I propose looks like this:

Generic Method for any node:
mitk::DateNode::Point LoadDataNode(std::string path)

These methods make use of LoadDataNode(), but add a cast to the corresponding basic data tpye:
mitk::Image::Pointer LoadImage(std::string path)
mitk::Surface::Pointer LoadSurface(std::string path)
mitk::PointSet::Pointer LoadPointSet(std::string path)

Specialized saving methods:
(there is no generic save for a node, is there?)
bool SaveImage(std::string path)
bool SaveSurface(std::string path)
bool SavePointSet(std::string path)

In order to keep the methods similar, the path should contain also the file-extension and corresponding writer should be called accordingly.

I propose to name this mitkIOCommon and place it in Core/Code/IO.

We discussed this today in the MITK meeting:
*The class/file should be located in IO => The GUI OpenFile methods can re-use this code
*Sascha and I searched for already existing code:
-There is a class mitkIOUtil which offers already means to read multiple files. Furthermore, the class QmitkCommonFunctionality implements some IO methods, but is Qt dependent. QmitkCommonFunctionality should also use the new methods in mitkIOUtil
*Nice to have feature for mitkIOUtil would also be "GetThreadSaveTmpDirectory()" which should return a path to a temporary thread save directory. This often causes issues in tests.

I wrote a feature request for the core.

Eric and I finished the work today at mitkIOUtil and wrote a very basic test.

Still todo:
refactor the code in QmitkCommonFunctionality

[73fbae]: Merge branch 'bug-11901-IOUtilIntegration'

Merged commits:

2012-09-26 14:02:45 Thomas Kilgus [f8a412]
Reverted changes to QmitkCommonFunctionality in order to push mitkIOUtil without any modifications to that.


2012-09-26 14:01:01 Thomas Kilgus [8abc5b]
Temporarily removed savebasedata method. Not important for now.


2012-09-26 10:57:32 Thomas Kilgus [343df5]
Merge branch 'bug-11901-mitkIOUtil' into bug-11901-IOUtilIntegration


2012-08-29 17:06:10 Thomas Kilgus [08bc96]
Started to refactor QmitkCommonFunctionality. SaveImage is not working, yet.


2012-08-29 16:53:55 Thomas Kilgus [6f07a2]
Added exceptions and docu. Adapted the test to use the Testing directory and removed the files after the test is done.


2012-08-22 16:39:01 Thomas Kilgus [2a4a63]
Implemtented simple test.


2012-08-22 16:38:02 Thomas Kilgus [27a3a3]
Added test to cmake.


2012-08-22 16:34:12 Thomas Kilgus [1cb87e]
Minor Bugfixes.


2012-08-22 15:31:29 Thomas Kilgus [4cc43b]
Implemented methods described in the bug.

We merged mitkIOUtil including the test into the master. It should be used now for all I/O purposes. Next, we will replace QmitkCommonFunctionality.

We started implementing QmitkIOUtil and already used it inside the DataManagerView. Everything is pushed to: bug-11901-ReplaceCommonFunctionality

Still todo:
-Check wether we can write a method SaveBaseData inside mitkIOUtil and use this inside QmitkIOUitl
-Check wether saving of extentions like TensorImage etc. is still possible
-More exhaustive testing of GUI
-Get the possible suffixes of files somewhere from the Core

Tested branch bug-11901-ReplaceCommonFunctionality :

Loading was always done by drag'N'drop.

Loading:

  • .dwi images (diffusion weighted) work fine, they are recognized as multi gradient images and treated accordingly
  • can load .qbi images
  • can load .dti images
  • can load .cnf Networks

Renaming an empty .txt to various extensions produced the following results:

  • .nrrd : Nothing (usual cryptic Console message*)
  • .nii : Nothing (usual cryptic Console message)
  • .nii.gz : Nothing (usual cryptic Console message)
  • .qbi : Console Warning
  • .dti : Console Warning
  • .dwi : Console Message Containing an Error
  • .fib : Console Error and possible program corruption messagte box
  • .cnf : Console Error

Renaming a .txt filled with "ßäöasdfäpaorgäipnoi²€€@µ" (without quotes):

  • .nrrd : Nothing (usual cryptic Console message)
  • .nii : Nothing (usual cryptic Console message)
  • .nii.gz : Nothing (usual cryptic Console message)
  • .qbi : Freeze (crash)
  • .dti : Freeze (crash)
  • .dwi : Freeze (crash)
  • .fib : Console Error and possible program corruption message box (file is blocked by MITK afterwards)
  • .cnf : Console Error

Saving:
Right Click in datamanager->Save in Context Menu (Works fine on current master)

  • Diffusion weighted image: Application freezes for a short while, then nothing happens
  • fiber images: Nothing happens (Log windows informs about the fiber bundle being written, but neither a window for save location selection opens nor can the file be found afterwards)
  • Diffusion Tensor images: Nothing happens
  • Qball Images: Nothing happens
  • Connectomics Networks: Nothing happens (Writer does log the network being written, but again no window)

Debuging reveals a debug assertion failure (sequence not ordered) from the
allWriters.merge(list2);
call in mitkCoreObjectFactory.cpp. This seems to prevent the dialogue from opening. The (correct) Writer will then continue using the node name as filename (no path, no extension).

  • Usual Cryptic Console message:

("application/x-qt-windows-mime;value="Shell IDList Array"", "application/x-qt-windows-mime;value="UsingDefaultDragImage"", "application/x-qt-windows-mime;value="DragImageBits"", "application/x-qt-windows-mime;value="DragContext"", "application/x-qt-windows-mime;value="DragSourceHelperFlags"", "application/x-qt-windows-mime;value="InShellDragLoop"", "text/uri-list","application/x-qt-windows-mime;value="FileName"", "application/x-qt-windows-mime;value="FileNameW"")""

I just tried merging with the current master and problems persist.

Regarding my last todo's:
-Check wether we can write a method SaveBaseData inside mitkIOUtil and use this inside QmitkIOUitl -> Not possible
-Check wether saving of extentions like TensorImage etc. is still possible -> Done by Caspar
-More exhaustive testing of GUI -> Done by Caspar

Still todo:
-Get the possible suffixes of files somewhere from the Core
-Fix saving of extensions like TensorImage etc.
-Make a new bug for loading empty files

Still todo:
-Get the possible suffixes of files somewhere from the Core -> New T13525
-Fix saving of extensions like TensorImage etc. -> Done and tested
-Make a new bug for loading empty files -> New T13524

TODO:
Merge!

[8811de]: Merge branch 'bug-11901-ReplaceCommonFunctionality'

Merged commits:

2012-10-31 16:21:31 Thomas Kilgus [d14f97]
Fixed warnings and a bug in SaveToFileWriter which would not show any dialog.


2012-10-10 17:50:42 Thomas Kilgus [285c74]
Adapted QmitkIOUtil to use a QWidget as parent.


2012-10-10 16:54:39 Thomas Kilgus [2f6644]
Declared CommonFunctionality deprecated


2012-10-10 16:54:16 Thomas Kilgus [b7bf1f]
Removed saveBaseData from IOUtil


2012-09-26 18:06:36 Thomas Kilgus [d71073]
Implemtend QmitkIOUtil and used it inside DataManagerView.


2012-09-26 14:18:02 Thomas Kilgus [aa15a9]
Added new QmitkIOUtil and SaveBaseData