Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 8c0413db authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

Merge branch 'fix/various-small-bugs' into 'develop'

Fix/various small bugs + Slice simplification

See merge request !137
parents b5f9f671 42343ce0
......@@ -57,7 +57,16 @@ QWidget* QuitAction::getWidget() {
// --------------- apply -------------------
Action::ApplyStatus QuitAction::apply() {
Application::getMainWindow()->close();
return SUCCESS;
// close all components (and therefore ask the user to savet the modified ones)
ApplyStatus closeAllStatus = Application::getAction("Close All")->apply();
if (closeAllStatus == SUCCESS) {
// Quit the app (will call Application::quitting() and therefore unload all action extensions and delete all actions)
Application::quit();
return SUCCESS;
}
else {
// or abort the operation
return ABORTED;
}
}
......@@ -25,14 +25,8 @@
#include "SaveAllAction.h"
#include <Application.h>
#include <ImageComponent.h>
#include <ImageComponentExtension.h>
#include <MeshComponent.h>
#include <MeshComponentExtension.h>
#include <Log.h>
#include <QFileDialog>
using namespace camitk;
......
......@@ -36,11 +36,11 @@ using namespace camitk;
// --------------- constructor -------------------
ImageLutAction::ImageLutAction(ActionExtension* extension) : Action(extension) {
setName("Lut");
setName("Image Look Up Table");
setDescription("Modify the LUT of an image components");
setComponent("ImageComponent");
setFamily("ImageLut");
addTag("Lut");
setFamily("Image LUT");
addTag("LUT");
}
// --------------- getWidget -------------------
......
......@@ -47,7 +47,7 @@ using namespace camitk;
// ---------------------- Constructor ----------------------------
ImageLutWidget::ImageLutWidget(QWidget* parent) : QWidget(parent) {
myComponent = NULL;
myComponent = nullptr;
lutMin = 0;
lutMax = 255;
......@@ -92,7 +92,7 @@ void ImageLutWidget::updateComponent(ImageComponent* comp) {
myComponent = comp;
// if there is no lookup table, just don't display this widget!
if (myComponent->getLut() == NULL) {
if (myComponent->getLut() == nullptr) {
setEnabled(false);
return;
}
......
......@@ -51,10 +51,8 @@ public:
/// Default Destructor
virtual ~VolumeRenderingAction() = default;
void createVolumeRendering(camitk::ImageComponent* comp);
public slots:
/** this method is automatically called when the action is triggered.
* Call getTargets() method to get the list of components to use.
......
......@@ -189,7 +189,7 @@ Action::ApplyStatus WarpOut::apply() {
for (vtkIdType i = 0; i < connectivityFilter->GetOutput()->GetNumberOfPoints(); i++) {
// get the id of the point in the original point set
#if VTK_MAJOR_VERSION == 8
#if VTK_MAJOR_VERSION >= 7
pointId->GetTypedTuple(i, &id);
#else
pointId->GetTupleValue(i, &id);
......
......@@ -473,7 +473,7 @@ void ImpMainWindow::updateViewMenu() {
// change the central viewer if there is more than one viewer in the central area
if (qobject_cast<QStackedWidget*>(centralWidget())->count() > 1) {
viewMenu->addSeparator()->setText(tr("Toggle Central Viewers"));
// add a toggle action for each widget stacked inside the central widget
for (int i = 0; i < qobject_cast<QStackedWidget*>(centralWidget())->count(); i++) {
QWidget* cWidget = qobject_cast<QStackedWidget*>(centralWidget())->widget(i);
......@@ -488,15 +488,15 @@ void ImpMainWindow::updateViewMenu() {
});
Viewer* cViewer = (*it);
// viewerAction is own by viewMenu, viewMenu->clear() will delete it
QAction *viewerAction = viewMenu->addAction(cViewer->objectName());
QAction* viewerAction = viewMenu->addAction(cViewer->objectName());
viewerAction->setCheckable(true);
viewerAction->setChecked(cViewer == centralViewer);
QString tipString = "Hide/show the " + cViewer->objectName() + " central viewer";
viewerAction->setStatusTip(tr(tipString.toStdString().c_str()));
viewerAction->setWhatsThis(tr(tipString.toStdString().c_str()));
// add the toggle action slot using C++11 lambda so that everything is contained inside viewMenu
connect(viewerAction, &QAction::toggled, [=](bool) {
setCentralViewer(cViewer);
connect(viewerAction, &QAction::toggled, [ = ](bool) {
setCentralViewer(cViewer);
});
}
}
......@@ -600,63 +600,65 @@ void ImpMainWindow::saveHistoryAsSCXML() {
// ------------------------- openDataDirectoryMenuBuilder ---------------------------
void ImpMainWindow::openDataDirectoryMenuBuilder() {
QStringList dirExt = ExtensionManager::getDataDirectoryExtNames();
QString dirExtName;
if (dirExt.size() > 1) {
if (fileOpenDataDirectoryMenu == nullptr){
if (fileOpenDataDirectoryMenu == nullptr) {
fileOpenDataDirectoryMenu = new QMenu("Open Data Directory");
fileMenu->addMenu(fileOpenDataDirectoryMenu);
} else {
disconnect(fileOpenDataDirectoryMenu,0,0,0);
}
else {
disconnect(fileOpenDataDirectoryMenu, 0, 0, 0);
fileOpenDataDirectoryMenu->clear();
}
fileOpenDataDirectoryMenu->setIcon(QPixmap(":/fileOpen"));
foreach (dirExtName, dirExt) {
for (QString dirExtName : dirExt) {
QAction* openDirectory = new QAction(dirExtName, this);
openDirectory->setStatusTip(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectory->setWhatsThis(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
connect(openDirectory, &QAction::triggered, this, [=]() {this->openDataDirectory(dirExtName);});
connect(openDirectory, &QAction::triggered, this, [ = ]() {
this->openDataDirectory(dirExtName);
});
fileOpenDataDirectoryMenu->addAction(openDirectory);
}
} else if (dirExt.size() == 1) {
QAction* openDirectoryAct;
dirExtName = dirExt.at(0);
int indexAction = 0;
bool updateAction = false;
bool IDidntFindWhatImLookingFor = true;
QList<QAction *> actions = fileMenu->actions();
int size = actions.size();
while (IDidntFindWhatImLookingFor && indexAction < actions.size() ) {
if (actions.at(indexAction)->text().contains(" Directory")) {
actions.at(indexAction)->destroyed();
updateAction = true;
IDidntFindWhatImLookingFor = false;
}
else
if (dirExt.size() == 1) {
// if it exists, remove the default directory extension menu (that has only one submenu)
// from the file "open" action list
bool updateAction = false;
QList<QAction*> menuActions = fileMenu->actions();
int indexAction = 0;
while (indexAction < menuActions.size() && !updateAction) {
if (menuActions.at(indexAction)->text().contains(" Directory")) {
menuActions.at(indexAction)->destroyed();
updateAction = true;
}
indexAction++;
}
// create the single open directory action
QString dirExtName = dirExt.at(0);
QAction* openDirectoryAction = new QAction("Open " + dirExtName + " Directory", this);
if (!updateAction) {
// there was no specific menu, just add the single "open directory" action in the file menu
fileMenu->addAction(openDirectoryAction);
}
indexAction++;
};
if (!updateAction) {
openDirectoryAct = new QAction("Open " + dirExtName + " Directory", this);
fileMenu->addAction(openDirectoryAct);
} else {
openDirectoryAct = new QAction("Open " + dirExtName + " Directory", this);
}
openDirectoryAct->setStatusTip(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectoryAct->setWhatsThis(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectoryAction->setStatusTip(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
openDirectoryAction->setWhatsThis(tr(QString("Opens data directory for " + dirExtName).toStdString().c_str()));
connect(openDirectoryAct, &QAction::triggered, this, [=]() {this->openDataDirectory(dirExtName);});
connect(openDirectoryAction, &QAction::triggered, this, [ = ]() {
this->openDataDirectory(dirExtName);
});
openDirectoryAct->setIcon(QPixmap(":/fileOpen"));
} else {
fileOpenDataDirectoryMenu = new QMenu("No plugins loaded to Open Data Directory");
fileOpenDataDirectoryMenu->setIcon(QPixmap(":/fileOpen"));
fileOpenDataDirectoryMenu->setEnabled(false);
fileMenu->addMenu(fileOpenDataDirectoryMenu);
}
openDirectoryAction->setIcon(QPixmap(":/fileOpen"));
}
else {
fileOpenDataDirectoryMenu = new QMenu("No plugins loaded to Open Data Directory");
fileOpenDataDirectoryMenu->setIcon(QPixmap(":/fileOpen"));
fileOpenDataDirectoryMenu->setEnabled(false);
fileMenu->addMenu(fileOpenDataDirectoryMenu);
}
}
......@@ -572,7 +572,7 @@ private:
}
// -------------------- declare the interface for QPluginLoader --------------------
Q_DECLARE_INTERFACE(camitk::Action, "TIMC-IMAG.Action/2.1") //TODO use svn version?
Q_DECLARE_INTERFACE(camitk::Action, "TIMC-IMAG.Action/2.1")
#endif // ACTION_H
......
......@@ -58,6 +58,7 @@ void ActionExtension::initResources() {
// -------------------- destructor --------------------
ActionExtension::~ActionExtension() {
// delete all actions one by one
while (!actions.empty()) {
Action* toDelete = actions.takeFirst();
// do not delete the "Quit" action: it is the action that triggers this delete!
......@@ -66,7 +67,7 @@ ActionExtension::~ActionExtension() {
}
}
//delete internationalization instance
// delete internationalization instance
if (translator) {
delete translator;
}
......
......@@ -108,7 +108,7 @@ private:
}
// -------------------- declare the interface for QPluginLoader --------------------
Q_DECLARE_INTERFACE(camitk::ActionExtension, "TIMC-IMAG. Action Extension/2.1") //TODO use variable from CMake?
Q_DECLARE_INTERFACE(camitk::ActionExtension, "TIMC-IMAG. Action Extension/2.1")
#endif //ACTION_EXTENSION_H
......@@ -204,7 +204,7 @@ QString Application::getName() {
// ----------------- quitting --------------------
void Application::quitting() {
// this is connect to the aboutToQuit signal from QApplication
// this is connected to the aboutToQuit signal from QApplication
// it should contain all the code that frees the resources
// delete all actions (they are instantiated when the extension is loaded)
......
......@@ -186,6 +186,27 @@ public:
*/
vtkSmartPointer<vtkActor> getActor(const RenderingModes) override;
/** Set a texture to this object. */
void setTexture(vtkSmartPointer<vtkTexture> texture) override;
/// a vtkPoint of the structured was picked (to be reimplemented in a Component inherited class if needed)
void pointPicked(vtkIdType, bool) {};
/// a vtkCell of the structured was picked (to be reimplemented in a Component inherited class if needed)
void cellPicked(vtkIdType, bool) {};
///@}
/// @name manage extra prop associated with a Geometry
/// @{
/// TODO
/// - put all this management into a dedicated interface
/// - remove it from InterfaceBitMap and InterfaceGeometry
/// - remove it from Slice and Geometry helper classes
/// - create a new associated helper class
/// - update Component class and all other code using it (if needed)
/// Note : beware that Geometry requires this to manage to at least "label" and "glyph" extra actors
/// Return the vtkProp (actors, volumes and annotations) corresponding to the given name
vtkSmartPointer<vtkProp> getProp(const QString&) override;
......@@ -204,18 +225,8 @@ public:
* @return true if effictively done
*/
bool removeProp(const QString&) override;
/** Set a texture to this object. */
void setTexture(vtkSmartPointer<vtkTexture> texture) override;
/// a vtkPoint of the structured was picked (to be reimplemented in a Component inherited class if needed)
void pointPicked(vtkIdType, bool) {};
/// a vtkCell of the structured was picked (to be reimplemented in a Component inherited class if needed)
void cellPicked(vtkIdType, bool) {};
///@}
/// @}
/// @name InterfaceGeometry Helpers inherited methods
/// @{
......@@ -307,10 +318,7 @@ private:
/// the VTK mapper
vtkSmartPointer<vtkDataSetMapper> mapper;
/// The additional map for prop (include at least "label" and "glyph"
QMap<QString, vtkSmartPointer<vtkProp> > extraProp;
/// the mapper to create the text
vtkSmartPointer<vtkTextMapper> labelActorMapper;
......@@ -386,8 +394,15 @@ private:
double oldAlphaPoints;
double oldPointsColor[4];
///@}
protected:
vtkSmartPointer< vtkPointSet > New();
/// @name manage extra prop associated with a Geometry
/// @{
/// TODO see extra prop management method section
/// The additional map for prop (include at least "label" and "glyph")
QMap<QString, vtkSmartPointer<vtkProp> > extraProp;
///@}
};
......
......@@ -85,15 +85,12 @@ public:
/** Return the vtkActor used to pick pixels in the slices. */
virtual vtkSmartPointer<vtkActor> getPixelActor() = 0;
/** Return 2D Axes at the proper slice origin */
// virtual vtkSmartPointer<vtkAxesActor> get2DAxesActor() = 0;
/** This method is called when the associated plane has been picked in the InteractiveViewer,
* the given coordinates is position where the plane was picked.
*/
virtual void pixelPicked(double, double, double) = 0;
/// update the position of the plane surrounding the currently selected slice
virtual void updatePickPlane() = 0;
/** Return the number of slices in the image data set. */
......@@ -122,10 +119,18 @@ public:
/** Returns the encapsultaed data structure: the image as a vtkImageData. */
virtual vtkSmartPointer<vtkImageData> getImageData() const = 0;
// TODO : put all of this into a dedicated interface
/// The additional map for prop (include at least "label" and "glyph"
QMap<QString, vtkSmartPointer<vtkProp> > extraProp;
/// @name manage extra prop associated with an InterfaceBitMap
/// @{
/// TODO
/// - put all this management into a dedicated interface
/// - remove it from InterfaceBitMap and InterfaceGeometry
/// - remove it from Slice and Geometry helper classes
/// - create a new associated helper class
/// - update Component class and all other code using it (if needed)
/// Note : beware that Geometry requires this to manage to at least "label" and "glyph" extra actors
/// Return the vtkProp (actors, volumes and annotations) corresponding to the given name
virtual vtkSmartPointer<vtkProp> getProp(const QString&) = 0;
......@@ -144,7 +149,7 @@ public:
* @return true if effictively done
*/
virtual bool removeProp(const QString&) = 0;
// END TODO
/// @}
};
......
......@@ -152,29 +152,7 @@ public:
* @see Geometry
*/
virtual void setDataConnection(vtkSmartPointer<vtkAlgorithmOutput>) = 0;
/// Return the actor for the representation mode, NULL if the actor doesn't exist.
virtual vtkSmartPointer<vtkActor> getActor(const RenderingModes) = 0;
/// Return the vtkProp (actors, volumes and annotations) corresponding to the given name
virtual vtkSmartPointer<vtkProp> getProp(const QString&) = 0;
/// return the number of additional prop
virtual unsigned int getNumberOfProp() const = 0;
/// return an additional prop by its index
virtual vtkSmartPointer<vtkProp> getProp(unsigned int) = 0;
/** remove a given additional prop.
* @return true if effictively done
*/
virtual bool removeProp(const QString&) = 0;
/** insert an additional prop, defining it by its name (default visibility = false).
* @return true if the additional prop was added (i.e. another additional prop of the same name does not exist)
*/
virtual bool addProp(const QString&, vtkSmartPointer<vtkProp>) = 0;
/// Set a texture to this object.
virtual void setTexture(vtkSmartPointer<vtkTexture>) = 0;
......@@ -204,6 +182,40 @@ public:
* @see InteractiveViewer
*/
virtual void cellPicked(vtkIdType cellId, bool pickingIsSelecting) = 0;
/// Return the actor for the representation mode, NULL if the actor doesn't exist.
virtual vtkSmartPointer<vtkActor> getActor(const RenderingModes) = 0;
///@}
/// @name manage extra prop associated with an InterfaceGeometry
/// @{
/// TODO
/// - put all this management into a dedicated interface
/// - remove it from InterfaceBitMap and InterfaceGeometry
/// - remove it from Slice and Geometry helper classes
/// - create a new associated helper class
/// - update Component class and all other code using it (if needed)
/// Note : beware that Geometry requires this to manage to at least "label" and "glyph" extra actors
/// Return the vtkProp (actors, volumes and annotations) corresponding to the given name
virtual vtkSmartPointer<vtkProp> getProp(const QString&) = 0;
/// return the number of additional prop
virtual unsigned int getNumberOfProp() const = 0;
/// return an additional prop by its index
virtual vtkSmartPointer<vtkProp> getProp(unsigned int) = 0;
/** remove a given additional prop.
* @return true if effictively done
*/
virtual bool removeProp(const QString&) = 0;
/** insert an additional prop, defining it by its name (default visibility = false).
* @return true if the additional prop was added (i.e. another additional prop of the same name does not exist)
*/
virtual bool addProp(const QString&, vtkSmartPointer<vtkProp>) = 0;
///@}
/// @name Helpers methods
......
......@@ -30,14 +30,12 @@
#include "Slice.h"
// -- vtk stuff
#include <vtkImageData.h>
#include <vtkProperty.h>
#include <vtkViewport.h>
#include <vtkCaptionActor2D.h>
#include <vtkTextActor.h>
#include <vtkProperty2D.h>
#include <vtkImageFlip.h>
#include <vtkImageMapper3D.h>
#include <vtkQuad.h>
#include <vtkDataSetMapper.h>
#include <vtkImageMapToColors.h>
using namespace std;
......@@ -45,8 +43,8 @@ using namespace std;
namespace camitk {
// -------------------- constructor --------------------
Slice::Slice(vtkSmartPointer<vtkImageData> volume, SliceOrientation orientation, vtkSmartPointer<vtkWindowLevelLookupTable> lookupTable) {
this->sliceOrientation = orientation;
this->lut = lookupTable;
sliceOrientation = orientation;
lut = lookupTable;
init();
setOriginalVolume(volume);
setSlice(getNumberOfSlices() / 2);
......@@ -56,56 +54,24 @@ Slice::Slice(vtkSmartPointer<vtkImageData> volume, SliceOrientation orientation,
// -------------------- Destructor --------------------
Slice::~Slice() {
// Let's unreference vtkSmartPointers
originalVolume = nullptr;
lut = nullptr;
imgToMapFilter = nullptr;
image3DActor = nullptr;
image2DActor = nullptr;
pickPlane = nullptr;
pickPlaneActor = nullptr;
pickPlaneMapper = nullptr;
pixelActor = nullptr;
init();
}
// -------------------- init --------------------
void Slice::init() {
currentSliceIndex = 0;
extent[0] = 0;
extent[1] = 0;
extent[2] = 0;
extent[3] = 0;
extent[4] = 0;
extent[5] = 0;
originalDimensions[0] = -1;
originalDimensions[1] = -1;
originalDimensions[2] = -1;
originalSpacing[0] = -1.0;
originalSpacing[1] = -1.0;
originalSpacing[2] = -1.0;
originalVolume = nullptr;
imgToMapFilter = nullptr;
image3DActor = nullptr;
image2DActor = nullptr;
pickPlane = nullptr;
pickPlaneMapper = nullptr;
pickPlaneActor = nullptr;
pixelActor = nullptr;
imgToMapFilter = vtkSmartPointer<vtkImageMapToColors>::New();
image3DActor = vtkSmartPointer<vtkImageActor>::New();
image2DActor = vtkSmartPointer<vtkImageActor>::New();
for (int i=0; i<3; i++) {
originalSpacing[i] = 1.0;
}
pickPlane = vtkSmartPointer<vtkPlaneSource>::New();
pickPlaneMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
pickPlaneActor = vtkSmartPointer<vtkActor>::New();
originalVolume = nullptr;
image3DActor = nullptr;
image2DActor = nullptr;
pickPlaneActor = nullptr;
pickPlaneActorPointSet = nullptr;
pixelActor = nullptr;
pixelActorPointSet = nullptr;
}
......@@ -120,106 +86,32 @@ void Slice::setOriginalVolume(vtkSmartPointer<vtkImageData> volume) {
// de-reference the smart pointer.
originalVolume = volume;
// Get volume information
// Get the original volume information
// Original volume dimensions in number of voxels (x, y and z)
int originalDimensions[3];
originalVolume->GetDimensions(originalDimensions);
originalVolume->GetSpacing(originalSpacing);
originalVolume->GetExtent(extent);
originalSize[0] = originalDimensions[0] * originalSpacing[0];
originalSize[1] = originalDimensions[1] * originalSpacing[1];
originalSize[2] = originalDimensions[2] * originalSpacing[2];
// In other methods, there will be divisions by originalSpacing[k]
// so let's avoid division by 0
if (originalSpacing[0] == 0.0) {
originalSpacing[0] = -1.0;
}
if (originalSpacing[1] == 0.0) {
originalSpacing[1] = -1.0;
}
if (originalSpacing[2] == 0.0) {
originalSpacing[2] = -1.0;
for (int i=0; i<3; i++) {
// compute original size (nb of slice * spacing)
originalSize[i] = originalDimensions[i] * originalSpacing[i];