Commit fd6a7d3f authored by Jean-Loup Haberbusch's avatar Jean-Loup Haberbusch

Initial commit

parents
File added
File added
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<cep xmlns="http://camitk.imag.fr/cepcoreschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://camitk.imag.fr/cepcoreschema Cep.xsd">
<name>Tutorial: Albert's example</name>
<contact>
<email>Celine.Fouard@imag.fr</email>
</contact>
<description>This CEP provides all necessary Components and Actions for Albert's example (scenario 1) in the tutorial. It helps Albert to make statistics on pig's snouts.</description>
<actionExtensions>
<actionExtension>
<name>Albert's Actions</name>
<description>This extension provides all actions needed by the scenario 1 of the tutorial.</description>
<actions>
<action>
<name>Albert's Region Growing</name>
<description>This Action allows to apply a region growing algorithm on a 2D, unsigned char gray levels images.</description>
<component>ImageComponent</component>
<classification>
<family>ExcellenceLab</family>
</classification>
<parameters>
<parameter defaultValue="0" description="Value below which the region does not grow any more" editable="true" name="Low Threshold" type="int" unit="gray level"/>
<parameter defaultValue="255" description="Value above which the region does not grow any more" editable="true" name="High Threshold" type="int" unit="gray level"/>
</parameters>
</action>
<action>
<name>PigSnoutSurface</name>
<description>This action allows to count white voxel from a 2D image.</description>
<component>ImageComponent</component>
<classification>
<family>ExcellenceLab</family>
</classification>
</action>
</actions>
<dependencies>
<dependency name="albertscomponents" type="component"/>
<dependency name="itk" type="library"/>
</dependencies>
</actionExtension>
</actionExtensions>
<componentExtensions>
<componentExtension>
<name>Albert's Components</name>
<description>This extension provides necessary components for scenarion 1 of the tutorial</description>
<components>
<component>
<name>PigSnoutStatistics</name>
<description>This component allows to store a pig snout 2D surface.</description>
<representation>None</representation>
<properties>
<parameter defaultValue="0" description="Number of pixels of the pig's snout " editable="true" name="Nb Pixels" type="int" unit=""/>
<parameter defaultValue="0.0" description="Surface of the pig's snout" editable="true" name="Surface" type="double" unit="mm^2"/>
</properties>
<fileSuffix>pig</fileSuffix>
</component>
</components>
</componentExtension>
</componentExtensions>
</cep>
#--------------------------------------------
# CamiTK Extension Project
#--------------------------------------------
cmake_minimum_required(VERSION 2.6)
# Find CamiTK SDK
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
find_package(CamiTK REQUIRED)
include(${CAMITK_USE_FILE})
# define the CEP
camitk_extension_project(NAME "Tutorial-Alberts-example"
CONTACT "Celine.Fouard@imag.fr"
DESCRIPTION "This CEP provides all necessary Components and Actions for Albert's example (scenario 1) in the tutorial. It helps Albert to make statistics on pig's snouts."
ENABLED
)
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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$
****************************************************************************/
This diff is collapsed.
TODO write this README file
#
# DO NOT EDIT THIS FILE (unless you REALLY know what you are doing)
#
# To add a component, just add a subdirectory (the component name is the
# directory name). Add all your code there and a text file called
# CMakeLists.txt
# In your CMakeLists.txt, use the camitk_extension(ACTION_EXTENSION ...) macro apropriately
# find components
get_subdirectories(ACTIONS_LIST)
# Add subdirectories in CMake project
foreach(ACTION_NAME ${ACTIONS_LIST})
add_subdirectory(${ACTION_NAME})
endforeach()
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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 "AlbertsActions.h"
// include generated actions headers
#include "AlbertsRegionGrowing.h"
#include "PigSnoutSurface.h"
// --------------- getActions -------------------
void AlbertsActions::init() {
// Creating and registering the instance of AlbertsRegionGrowing
// Creating and registering the instance of PigSnoutSurface
registerNewAction(AlbertsRegionGrowing);
registerNewAction(PigSnoutSurface);
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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 ALBERTSACTIONS_H
#define ALBERTSACTIONS_H
#include <ActionExtension.h>
class AlbertsActions : public camitk::ActionExtension {
Q_OBJECT
Q_INTERFACES(camitk::ActionExtension)
Q_PLUGIN_METADATA(IID "fr.imag.camitk.albert.action.albertsactions")
public:
/// Constructor
AlbertsActions() : ActionExtension() {};
/// Destructor
virtual ~AlbertsActions() {};
/// Method returning the action extension name
virtual QString getName() {
return "Albert's Actions";
};
/// Method returning the action extension descrption
virtual QString getDescription() {
return "This extension provides all actions needed by the scenario 1 of the tutorial.";
};
/// initialize all the actions
virtual void init();
};
#endif // ALBERTSACTIONS_H
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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$
****************************************************************************/
// CamiTK includes
#include "AlbertsRegionGrowing.h"
#include <Property.h>
#include <Application.h>
#include <ActionWidget.h>
#include <MultiPickingWidget.h>
// Qt includes
#include <QString>
#include <QMessageBox>
#include <QTextStream>
// Itk includes
#include <itkImage.h>
#include <itkConnectedThresholdImageFilter.h>
#include <itkImageToVTKImageFilter.h>
using namespace camitk;
// --------------- Constructor -------------------
AlbertsRegionGrowing::AlbertsRegionGrowing(ActionExtension * extension) : Action(extension) {
// Setting name, description and input component
setName("Albert's Region Growing");
setDescription("This Action allows to apply a region growing algorithm on a 2D, unsigned char gray levels images.");
setComponent("ImageComponent");
// Setting classification family and tags
setFamily("ExcellenceLab");
// Tags allow the user to search the actions trhough themes
// You can add tags here with the method addTag("tagName");
// Setting the action's parameters
addParameter(new Property(tr("Low Threshold"), 0, tr("Value below which the region does not grow any more"), "gray level"));
addParameter(new Property(tr("High Threshold"), 255, tr("Value above which the region does not grow any more"), "gray level"));
seedPoints = NULL;
}
// --------------- destructor -------------------
AlbertsRegionGrowing::~AlbertsRegionGrowing() {
// Do not do anything yet.
// Delete stuff if you create stuff
// (except if you use smart pointers of course !!)
}
QWidget * AlbertsRegionGrowing::getWidget() {
// build or update the widget
if ( !actionWidget ) {
// Setting the widget containing the parameters, using the default widget
actionWidget = new ActionWidget ( this );
pickingW = new MultiPickingWidget(actionWidget);
QLayout * widgetLayout = actionWidget->layout();
QBoxLayout * boxWidgetLayout = dynamic_cast<QBoxLayout *>(widgetLayout);
if (boxWidgetLayout != NULL) {
boxWidgetLayout->insertWidget(2, pickingW);
}
else {
actionWidget->layout()->addWidget(pickingW);
}
}
// make sure the widget has updated targets
dynamic_cast<ActionWidget*> ( actionWidget )->updateTargets();
pickingW->updateComponent(dynamic_cast<ImageComponent *> (getTargets().last()));
return actionWidget;
}
void AlbertsRegionGrowing::setSeedPoints(QList<QVector3D> * seedPoints) {
this->seedPoints = seedPoints;
}
// --------------- apply -------------------
Action::ApplyStatus AlbertsRegionGrowing::apply() {
ImageComponent * input = dynamic_cast<ImageComponent *> ( dynamic_cast<ImageComponent *> (getTargets().last()));
return process(input);
}
Action::ApplyStatus AlbertsRegionGrowing::process(ImageComponent * comp) {
// Get Parameters
int lowThreshold = property("Low Threshold").toInt();
int highThreshold = property("High Threshold").toInt();
if (seedPoints == NULL) {
seedPoints = pickingW->getPickedPixelMap(comp)->getPixelIndexList();
}
// Getting the input image
vtkSmartPointer<vtkImageData> inputImage = comp->getImageData();
// Check that the type is unsigned char and 2D image
if (inputImage->GetScalarType() != VTK_UNSIGNED_CHAR) {
QMessageBox::warning(NULL, "Warning", "This action is designed only for unsigned char type images\n sorry...\n");
return ABORTED;
}
int * dims = inputImage->GetDimensions();
if (dims[2] > 1) {
QMessageBox::warning(NULL, "Warning", "This action is designed only for 2D images\n sorry...\n");
return ABORTED;
}
if (seedPoints->empty()) {
QMessageBox::warning(NULL, "Warning", "You did not pick any point. Your action may not work...\n");
return ABORTED;
}
// Check parameters
// QString msg = "parameters: low threshold " + QString::number(lowThreshold) + " high threshold " + QString::number(highThreshold);
// QMessageBox::warning(NULL, "Method Region Growint", msg);
typedef itk::Image< unsigned char, 2 > ImageType;
ImageType::Pointer image = ImageType::New();
// Copy pixels values
ImageType::RegionType region;
ImageType::IndexType start;
typename ImageType::IndexType pixelIndex;
start[0] = 0;
start[1] = 0;
ImageType::SizeType size;
size[0] = dims[0];
size[1] = dims[1];
region.SetSize( size);
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
// Make a square
for(unsigned int j = 0; j < dims[1]; j++)
{
for(unsigned int i = 0; i < dims[0]; i++)
{
pixelIndex[0] = i;
pixelIndex[1] = j;
unsigned char val = (unsigned char) (inputImage->GetScalarComponentAsDouble(i, j, 0, 0));
image->SetPixel(pixelIndex, val);
}
}
typedef itk::ConnectedThresholdImageFilter<ImageType, ImageType> ConnectedFilterType;
typename ConnectedFilterType::Pointer regionGrow = ConnectedFilterType::New();
regionGrow->SetInput(image);
regionGrow->SetLower(lowThreshold);
regionGrow->SetUpper(highThreshold);
regionGrow->SetReplaceValue(255);
// set the initial seeds
for (int i = 0; i < seedPoints->size(); i++) {
pixelIndex[0] = seedPoints->at(i).x();
pixelIndex[1] = seedPoints->at(i).y();
regionGrow->AddSeed(pixelIndex);
}
regionGrow->Update();
// Visualize
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
ConnectorType::Pointer backToVtk = ConnectorType::New();
backToVtk->SetInput(regionGrow->GetOutput());
backToVtk->Update();
vtkSmartPointer<vtkImageData> outputImage = backToVtk->GetOutput();
// Create The output Component
QString newName;
QTextStream(&newName) << comp->getName() << "_processed";
QString newFileName;
newFileName = QFileInfo(comp->getFileName()).path() + "/" + newName + ".mhd";
ImageComponent * newComp = new ImageComponent(outputImage, newName);
newComp->setFileName(newFileName);
Application::refresh();
return SUCCESS;
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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 ALBERTSREGIONGROWING_H
#define ALBERTSREGIONGROWING_H
#include <Action.h>
#include <ImageComponent.h>
class MultiPickingWidget;
class AlbertsRegionGrowing : public camitk::Action {
public:
/// Default Constructor
AlbertsRegionGrowing(camitk::ActionExtension *);
/// Default Destructor
virtual ~AlbertsRegionGrowing();
virtual QWidget * getWidget();
virtual void setSeedPoints(QList<QVector3D> * seedPoints);
public slots:
/** this method is automatically called when the action is triggered.
* Call getTargets() method to get the list of components to use.
* \note getTargets() is automatically filtered so that it only contains compatible components,
* i.e., instances of AlbertsRegionGrowing (or a subclass).
*/
virtual ApplyStatus apply();
private:
/// helper method to simplify the target component processing
virtual Action::ApplyStatus process(camitk::ImageComponent *);
/// Multi-picking widget to get the seed points
MultiPickingWidget * pickingW;
QList<QVector3D> * seedPoints;
};
#endif // ALBERTSREGIONGROWING_H
# Call CamiTK CMake Macro to define the action
camitk_extension( ACTION_EXTENSION
DEFAULT
INSTALL_ALL_HEADERS
DESCRIPTION "This extension provides all actions needed by the scenario 1 of the tutorial."
NEEDS_ITK
NEEDS_COMPONENT_EXTENSION albertscomponents
NEEDS_ACTION_EXTENSION multipicking
)
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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$
****************************************************************************/
// CamiTK includes
#include "PigSnoutSurface.h"
#include <Property.h>
#include <Application.h>
// Qt includes
#include <QString>
#include <QMessageBox>
#include <QTextStream>
#include <QVector3D>
#include "PigSnoutStatistics.h"
using namespace camitk;
// --------------- Constructor -------------------
PigSnoutSurface::PigSnoutSurface(ActionExtension * extension) : Action(extension) {
// Setting name, description and input component
setName("PigSnoutSurface");
setDescription("This action allows to count white voxel from a 2D image.");
setComponent("ImageComponent");
// Setting classification family and tags
setFamily("ExcellenceLab");
// Tags allow the user to search the actions trhough themes
// You can add tags here with the method addTag("tagName");
// Setting the action's parameters
// If you want to add parameters to your action, you can add them
// using properties
Property * propImageName = new Property("Image Name", "No Image", tr("Input image name"), "");
propImageName->setReadOnly(true);
Property * propNbPixels = new Property(tr("Nb Pixels"), 0, tr("Number of pixels of the pig's snout "), "");
propNbPixels->setReadOnly(true);
Property * propSurface = new Property(tr("Surface"), 0.0, tr("Surface of the pig's snout"), "mm^2");
propSurface->setReadOnly(true);
addParameter(propImageName);
addParameter(propNbPixels);
addParameter(propSurface);
}
// --------------- destructor -------------------
PigSnoutSurface::~PigSnoutSurface() {
// Do not do anything yet.
// Delete stuff if you create stuff
// (except if you use smart pointers of course !!)
}
// --------------- apply -------------------
Action::ApplyStatus PigSnoutSurface::apply() {
ImageComponent * input = dynamic_cast<ImageComponent *> ( dynamic_cast<ImageComponent *> (getTargets().last()));
return process(input);
}
Action::ApplyStatus PigSnoutSurface::process(ImageComponent * comp) {
// Getting the input image
vtkSmartPointer<vtkImageData> inputImage = comp->getImageData();
// Check that the type is unsigned char and 2D image
if (inputImage->GetScalarType() != VTK_UNSIGNED_CHAR) {
QMessageBox::warning(NULL, "Warning", "This action is designed only for unsigned char type images\n sorry...\n");
return ABORTED;
}
int * dims = inputImage->GetDimensions();
if (dims[2] > 1) {
QMessageBox::warning(NULL, "Warning", "This action is designed only for 2D images\n sorry...\n");
return ABORTED;
}
// count the number of non-zero pixels:
int nbNonZeroPixels = 0;
for (int y = 0; y < dims[1]; y++)
{
for (int x = 0; x < dims[0]; x++)
{
unsigned char * pixel = static_cast<unsigned char *>(inputImage->GetScalarPointer(x,y,0));
if (pixel[0] > 0) {
nbNonZeroPixels += 1;
}
}
}
double surface = nbNonZeroPixels * comp->getVoxelSize().x() * comp->getVoxelSize().y();
this->setProperty("Image Name", comp->getName());
this->setProperty("Nb Pixels", nbNonZeroPixels);
this->setProperty("Surface", surface);
QString pigSnoutName = comp->getName() + "_stats";
QString pigSnoutFileName = QFileInfo(comp->getFileName()).path() + "/" + pigSnoutName + ".pig";
PigSnoutStatistics * pig = new PigSnoutStatistics(pigSnoutName, comp->getName(), nbNonZeroPixels, surface);
pig->setFileName(pigSnoutFileName);
Application::refresh();
return SUCCESS;
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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 PIGSNOUTSURFACE_H
#define PIGSNOUTSURFACE_H
#include <Action.h>
#include <ImageComponent.h>
class PigSnoutSurface : public camitk::Action {
public:
/// Default Constructor
PigSnoutSurface(camitk::ActionExtension *);
/// Default Destructor
virtual ~PigSnoutSurface();
public slots:
/** this method is automatically called when the action is triggered.