Commit 526a9176 authored by sarrazij's avatar sarrazij
Browse files

NEW Pixel Color Changer

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@690 ec899d31-69d1-42ba-9299-647d76f65fb3
parent a7b4b162
......@@ -17,4 +17,5 @@ add_subdirectory(itkfilters)
add_subdirectory(arbitraryslice)
add_subdirectory(showin3d)
add_subdirectory(cropvolume)
add_subdirectory(pixelcolorchanger)
# Call CamiTK CMake Macro to define the action
camitk_extension(ACTION_EXTENSION
DEFAULT
DEFINES COMPILE_PIXELCOLORCHANGER_ACTION_API
)
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2013 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#include "PixelColorChanger.h"
#include <Application.h>
#include <InteractiveViewer.h>
#include <QMessageBox>
#include <QString>
#include <QTextStream>
using namespace camitk;
// --------------- constructor -------------------
PixelColorChanger::PixelColorChanger(ActionExtension * extension) : Action(extension) {
// Setting name, description and input component
setName("Pixel Color Changer");
setDescription("<br>Sets clicked pixel (CTRL + Mouse Left) to a new defined color value.<p>Size 1 is equal to one pixel in the considered slice. Size 2 correspond to 3 pixels in the slice to always keep a center::the picked pixel (Size 3-> 5pix; 4->7pix...)");
setComponent("ImageComponent");
// Setting classification family and tags
this->setFamily("Image Processing");
this->addTag("Color Changer");
this->addTag("Picked Pixel");
setProperty("newColorValue", QVariant(0));
setProperty("size_i", QVariant(1));
setProperty("size_j", QVariant(1));
setProperty("size_k", QVariant(1));
setAutoUpdateProperties(true);
isConnected = false;
}
QWidget* PixelColorChanger::getWidget() {
if (!isConnected) {
//-- run the action every time a picking is done in the axial/sagittal or coronal planes
QObject::connect(InteractiveViewer::getAxialViewer(), SIGNAL(selectionChanged()), this, SLOT(apply()));
QObject::connect(InteractiveViewer::getCoronalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply()));
QObject::connect(InteractiveViewer::getSagittalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply()));
isConnected = true;
}
return Action::getWidget();
}
// --------------- destructor -------------------
PixelColorChanger::~PixelColorChanger() {
// do not delete the widget has it might have been used in the ActionViewer (i.e. the ownership might have been taken by the stacked widget)
}
// --------------- apply -------------------
Action::ApplyStatus PixelColorChanger::apply() {
// check if widget is still visible, otherwise disconnect action
if (this->getWidget()->isVisible()) {
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
// Get the image
ImageComponent * input = dynamic_cast<ImageComponent *> ( getTargets().last() );
// get the last picked pixel index
int i, j, k=-1;
input->getLastPixelPicked(&i, &j, &k);
// Get the parameters
sizei = property("size_i").toInt();
sizej = property("size_j").toInt();
sizek = property("size_k").toInt();
// check validity
if (i != -1 && j != -1 && k != -1 && sizei >0 && sizej>0 && sizek>0) {
// retrieve information
newColorValue = property("newColorValue").toInt();
//get dims of image
int* ext= input->getImageData()->GetExtent();
// Redraw all pixels around picked pixel according to given size i,j,k
for (int i1 = i-(sizei-1); i1<i+sizei; i1++) {
for (int j1 = j-(sizej-1); j1< j+sizej; j1++) {
for (int k1 = k-(sizek-1); k1< k+sizek; k1++) {
if (i1>ext[0] && i1<ext[1] && j1>ext[2] && j1<ext[3] && k1>ext[4] && k1<ext[5]) {
input->getImageData()->SetScalarComponentFromDouble(i1,j1,k1, 0, (double)newColorValue);
}
}
}
}
// Allows to refresh the input image (2 lines below)
input->getImageData()->Modified();
input->getImageData()->Update();
}
Application::refresh();
// restore the normal cursor
QApplication::restoreOverrideCursor();
}
else {
// disconnect
QObject::disconnect(InteractiveViewer::getAxialViewer(), SIGNAL(selectionChanged()), this, SLOT(apply()));
QObject::disconnect(InteractiveViewer::getCoronalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply()));
QObject::disconnect(InteractiveViewer::getSagittalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply()));
isConnected = false;
}
return SUCCESS;
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2013 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#ifndef PIXELCOLORCHANGER_H
#define PIXELCOLORCHANGER_H
#include <QObject>
#include <qframe.h>
#include <Action.h>
#include <ImageComponent.h>
class PixelColorChanger : public camitk::Action {
public:
/// Default Constructor
PixelColorChanger(camitk::ActionExtension *);
/// Default Destructor
virtual ~PixelColorChanger();
/// method called when the action when the action is triggered (i.e. started)
virtual QWidget * getWidget();
public slots:
/** this method is automatically called when the action is triggered.
* Use getTargets() QList to get the list of component to use.
* \note getTargets() is automatically filtered so that it only contains compatible components,
* i.e., instances of ImageComponent (or a subclass).
*/
virtual ApplyStatus apply();
private:
protected:
/// new color given to picked pixel
int newColorValue;
/// size to draw pixels on i axis
int sizei;
/// size to draw pixels on j axis
int sizej;
/// size to draw pixels on k axis
int sizek;
/// is the widget automatically connected to image picking
bool isConnected;
};
#endif // PIXELCOLORCHANGER_H
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2013 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#include "PixelColorChangerExtension.h"
#include "PixelColorChanger.h"
#include <Action.h>
#include <Application.h>
#include <ImageComponent.h>
using namespace camitk;
// --------------- declare the extension -------------------
Q_EXPORT_PLUGIN2(pixelcolorchanger, PixelColorChangerExtension);
// -------------------- init --------------------
void PixelColorChangerExtension::init() {
registerNewAction(PixelColorChanger);
}
\ No newline at end of file
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2013 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#ifndef PIXELCOLORCHANGEREXTENSION_H
#define PIXELCOLORCHANGEREXTENSION_H
#include <QObject>
#include <Action.h>
#include <ActionExtension.h>
class PixelColorChangerExtension : public camitk::ActionExtension {
Q_OBJECT
Q_INTERFACES(camitk::ActionExtension);
public:
/// the constructor
PixelColorChangerExtension() : ActionExtension() {};
/// the destructor
virtual ~PixelColorChangerExtension() {};
/// initialize all the actions
virtual void init();
/// Method that return the action extension name
virtual QString getName() {return "pixelcolorchanger";};
/// Method that return the action extension descrption
virtual QString getDescription() {return "extension that allows to change pixel color value";};
};
#endif // PIXELCOLORCHANGEREXTENSION_H
\ No newline at end of file
Markdown is supported
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