SET(
App_QT_SOURCES
- ImageMPR.cxx
+ ImageMPR.cxx
)
SET(
App_SOURCES
- main.cxx
+ MementoState.cxx
+ main.cxx
)
SET(
App_QT_HEADERS
)
SET(
App_HEADERS
+ MementoState.h
)
FILE(GLOB App_QT_UI "${App_SOURCE_DIR}/*.ui")
FILE(GLOB App_QT_RES "${App_SOURCE_DIR}/*.qrc")
#include "ImageMPR.h"
+#include "MementoState.h"
#include "ui_ImageMPR.h"
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
+#include <vtkMetaImageReader.h>
#include <QFileDialog>
#include <QMessageBox>
m_MeshReaderClass( "" ),
m_MeshWriterClass( "" ),
m_MeshCutterClass( "" ),
- m_Image( NULL )
+ m_Image( NULL ),
+ m_state(1)
{
this->m_UI->setupUi( this );
this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
this, SLOT( _triggered_actionOpenInputPolyData( ) )
);
+ QObject::connect(
+ this->m_UI->actionUndo, SIGNAL(triggered()),
+ this, SLOT(_triggered_actionUndo())
+ );
+ QObject::connect(
+ this->m_UI->actionRedo, SIGNAL(triggered()),
+ this, SLOT(_triggered_actionRedo())
+ );
// Start: load all disponible plugins
this->_LoadPlugins(
this->m_MPRObjects->ActivateInteractors( );
this->m_MPRObjects->ResetCameras( );
this->m_MPRObjects->RenderAll( );
+
+ MementoState(m_state, this->m_Image);
}
else
QMessageBox::critical(
if( this->m_Image.IsNotNull( ) )
this->m_MPRObjects->SetImage(
this->m_Image->GetVTK< vtkImageData >( )
- );
+
+ );
+ m_state++;
+ MementoState(m_state, this->m_Image);
}
else
QMessageBox::critical(
);
}
+// -------------------------------------------------------------------------
+void ImageMPR::
+_triggered_actionUndo()
+{
+ MementoState memento = MementoState();
+
+ if (this->m_state>1)
+ {
+ this->m_state--;
+ this->m_MPRObjects->SetImage(
+ memento.getMemento(this->m_state)->GetOutput()
+ );
+ } else
+ {
+ QMessageBox::critical(
+ this,
+ tr("Error message"),
+ tr("No history to undo")
+ );
+ }
+
+}
+
+// -------------------------------------------------------------------------
+void ImageMPR::
+_triggered_actionRedo()
+{
+ MementoState memento = MementoState();
+ try
+ {
+ this->m_state++;
+ this->m_MPRObjects->SetImage(
+ memento.getMemento(this->m_state)->GetOutput()
+ );
+ }
+ catch (int err)
+ {
+ QMessageBox::critical(
+ this,
+ tr("Error message"),
+ tr("No history to redo")
+ );
+ }
+}
+
+
// eof - $RCSfile$
#include <cpPlugins/Interface/Image.h>
#include <cpPlugins/Interface/ImplicitFunction.h>
#include <cpPlugins/Interface/Mesh.h>
+#include <vtkMetaImageWriter.h>
+#include <vtkMetaImageReader.h>
+
// -------------------------------------------------------------------------
namespace Ui
class ImageMPR;
}
+//==========================================================================
+// Plugins types
+//typedef cpPlugins::Interface::Interface TPluginsInterface;
+//typedef cpPlugins::Interface::Object TPluginObject;
+//typedef cpPlugins::Interface::DataObject TPluginData;
+//typedef cpPlugins::Interface::Image TPluginImage;
+//typedef cpPlugins::Interface::ImplicitFunction TPluginImplicitFunction;
+//typedef cpPlugins::Interface::Mesh TPluginMesh;
+//typedef cpPlugins::Interface::ProcessObject TPluginFilter;
+//typedef cpPlugins::Interface::Parameters TParameters;
+//
+//typedef cpExtensions::Visualization::MPRObjects TMPRObjects;
+
+
+
+
+//class MementoState
+//{
+//private:
+// long m_Id;
+//
+//public:
+//
+// MementoState()
+// {
+// m_Id = 0;
+// };
+//
+// MementoState(long id, TPluginImage* _img)
+// {
+// char * base = "state";
+// std::ostringstream oss;
+// oss << id;
+// std::string str = oss.str();
+// auto complement = str.c_str();
+//
+// std::string fileName(base);
+// fileName.append(complement);
+// fileName.append(".mhd");
+//
+// std::string fileNameRaw(base);
+// fileNameRaw.append(complement);
+// fileNameRaw.append(".raw");
+// save(fileName, fileNameRaw, _img);
+// }
+//
+// vtkSmartPointer<vtkMetaImageReader> getMemento(long id)
+// {
+// char * base = "state";
+// std::ostringstream oss;
+// oss << id;
+// std::string str = oss.str();
+// auto complement = str.c_str();
+//
+// std::string fileName(base);
+// fileName.append(complement);
+// fileName.append(".mhd");
+// return load(fileName);
+// }
+//
+// void save(const std::string& filename, const std::string& filenameRaw, TPluginImage* img) {
+// vtkSmartPointer<vtkMetaImageWriter> writer =
+// vtkSmartPointer<vtkMetaImageWriter>::New();
+// writer->SetInputData(img->GetVTK< vtkImageData >());
+// writer->SetFileName(filename.c_str());
+// writer->SetRAWFileName(filenameRaw.c_str());
+// writer->Write();
+// }
+//
+// vtkSmartPointer<vtkMetaImageReader> load(const std::string& filename) {
+// vtkSmartPointer<vtkMetaImageReader> reader =
+// vtkSmartPointer<vtkMetaImageReader>::New();
+// reader->SetFileName(filename.c_str());
+// reader->Update();
+// return reader;
+// }
+//
+//};
+
+//==========================================================================
+
// -------------------------------------------------------------------------
/**
*/
+
+
+
class ImageMPR
: public QMainWindow
{
void _triggered_actionOpenInputPolyData( );
void _triggered_actionImageToImage( );
void _triggered_actionImageToMesh( );
-
+ void _triggered_actionUndo();
+ void _triggered_actionRedo();
private:
Ui::ImageMPR* m_UI;
// Visualization stuff
vtkSmartPointer< TMPRObjects > m_MPRObjects;
+ // Memento stuff
+ unsigned long m_state;
+
/* TODO
vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget;
*/
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <widget class="QVTKWidget" name="m_YPlaneVTK">
+ <widget class="QVTKWidget" name="m_YPlaneVTK" native="true">
<property name="enabled">
<bool>true</bool>
</property>
</size>
</property>
</widget>
- <widget class="QVTKWidget" name="m_XPlaneVTK">
+ <widget class="QVTKWidget" name="m_XPlaneVTK" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <widget class="QVTKWidget" name="m_ZPlaneVTK">
+ <widget class="QVTKWidget" name="m_ZPlaneVTK" native="true">
<property name="enabled">
<bool>true</bool>
</property>
</size>
</property>
</widget>
- <widget class="QVTKWidget" name="m_3DVTK">
+ <widget class="QVTKWidget" name="m_3DVTK" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<x>0</x>
<y>0</y>
<width>718</width>
- <height>27</height>
+ <height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<string>Image to mesh</string>
</property>
</widget>
+ <widget class="QMenu" name="menuEdit">
+ <property name="title">
+ <string>Edit</string>
+ </property>
+ <addaction name="actionUndo"/>
+ <addaction name="actionRedo"/>
+ </widget>
<addaction name="menuFile"/>
+ <addaction name="menuEdit"/>
<addaction name="MenuImageToImage"/>
<addaction name="MenuImageToMesh"/>
</widget>
<string>Open segmentation</string>
</property>
</action>
+ <action name="actionUndo">
+ <property name="text">
+ <string>Undo</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Z</string>
+ </property>
+ </action>
+ <action name="actionRedo">
+ <property name="text">
+ <string>Redo</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Y</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
--- /dev/null
+#include "MementoState.h"
+
+#include <vtkMetaImageReader.h>
+#include <vtkMetaImageWriter.h>
+
+
+// -------------------------------------------------------------------------
+MementoState::MementoState()
+{
+ m_Id = 0;
+};
+
+// -------------------------------------------------------------------------
+MementoState::MementoState(long id, TPluginImage* _img)
+{
+ char * base = "state";
+ std::ostringstream oss;
+ oss << id;
+ std::string str = oss.str();
+ auto complement = str.c_str();
+
+ std::string fileName(base);
+ fileName.append(complement);
+ fileName.append(".mhd");
+
+ std::string fileNameRaw(base);
+ fileNameRaw.append(complement);
+ fileNameRaw.append(".raw");
+ save(fileName, fileNameRaw, _img);
+}
+
+// -------------------------------------------------------------------------
+vtkSmartPointer<vtkMetaImageReader>
+MementoState::getMemento(long id)
+{
+ char * base = "state";
+ std::ostringstream oss;
+ oss << id;
+ std::string str = oss.str();
+ auto complement = str.c_str();
+
+ std::string fileName(base);
+ fileName.append(complement);
+ fileName.append(".mhd");
+ return load(fileName);
+}
+
+// -------------------------------------------------------------------------
+void MementoState::
+save(const std::string& filename, const std::string& filenameRaw, TPluginImage* img) {
+ vtkSmartPointer<vtkMetaImageWriter> writer =
+ vtkSmartPointer<vtkMetaImageWriter>::New();
+ writer->SetInputData(img->GetVTK< vtkImageData >());
+ writer->SetFileName(filename.c_str());
+ writer->SetRAWFileName(filenameRaw.c_str());
+ writer->Write();
+}
+
+// -------------------------------------------------------------------------
+vtkSmartPointer<vtkMetaImageReader>
+MementoState::load(const std::string& filename) {
+ vtkSmartPointer<vtkMetaImageReader> reader =
+ vtkSmartPointer<vtkMetaImageReader>::New();
+ reader->SetFileName(filename.c_str());
+ reader->Update();
+ return reader;
+}
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __MEMENTOSTATE__H__
+#define __MEMENTOSTATE__H__
+
+#include <vector>
+
+
+// vtk stuff
+#include <vtkSmartPointer.h>
+#include <cpExtensions/Visualization/MPRObjects.h>
+
+// Plugins interface
+#include <cpPlugins/Interface/Interface.h>
+#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/ImplicitFunction.h>
+#include <cpPlugins/Interface/Mesh.h>
+
+#include <vtkMetaImageReader.h>
+
+// -------------------------------------------------------------------------
+namespace Ui
+{
+ class ImageMPR;
+}
+
+//==========================================================================
+// Plugins types
+typedef cpPlugins::Interface::Interface TPluginsInterface;
+typedef cpPlugins::Interface::Object TPluginObject;
+typedef cpPlugins::Interface::DataObject TPluginData;
+typedef cpPlugins::Interface::Image TPluginImage;
+typedef cpPlugins::Interface::ImplicitFunction TPluginImplicitFunction;
+typedef cpPlugins::Interface::Mesh TPluginMesh;
+typedef cpPlugins::Interface::ProcessObject TPluginFilter;
+typedef cpPlugins::Interface::Parameters TParameters;
+
+typedef cpExtensions::Visualization::MPRObjects TMPRObjects;
+
+class MementoState
+{
+private:
+ long m_Id;
+
+public:
+
+ MementoState();
+ MementoState(long id, TPluginImage* _img);
+ vtkSmartPointer<vtkMetaImageReader> getMemento(long id);
+private:
+ void save(const std::string& filename, const std::string& filenameRaw, TPluginImage* img);
+ vtkSmartPointer<vtkMetaImageReader> load(const std::string& filename);
+
+};
+
+//==========================================================================
+
+// -------------------------------------------------------------------------
+/**
+ */
+
+
+
+
+
+#endif // __MEMENTOSTATE__H__
+
+// eof - $RCSfile$