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 03699c77 authored by sarrazij's avatar sarrazij
Browse files
parent 3719def1
......@@ -16,4 +16,5 @@ add_subdirectory(itksegmentation)
add_subdirectory(itkfilters)
add_subdirectory(arbitraryslice)
add_subdirectory(showin3d)
add_subdirectory(cropvolume)
/*****************************************************************************
* $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 "BoxVOI.h"
// includes from Qt
#include <QMessageBox>
#include <QString>
#include <QTextStream>
// includes from CamiTK
#include <Application.h>
#include <vtkExtractVOI.h>
#include <InteractiveViewer.h>
// local includes
#include "BoxVOIWidget.h"
//std includes
#include <algorithm>
#include <complex>
using namespace camitk;
// --------------- constructor -------------------
BoxVOI::BoxVOI ( ActionExtension * extension ) : Action ( extension )
{
// Setting name, description and input component
setName ( "Box Volume Of Interest" );
setDescription ( "<p>This filter helps you to crop a volume to keep only an interesting subsample. To use it, select respectively the min and the max of each axe (i,j,k), i.e 6 points. It is possible to use only 2 points (the origin of parallelepiped and its opposite diagonal point)." );
setComponent ( "ImageComponent" );
setEmbedded ( true );
// Setting classification family and tags
this->setFamily ( "Image Processing" );
this->addTag ( "Crop Volume" );
this->addTag ( "Box" );
this->addTag ( "Volume Of Interest" );
this->addTag ( "Seed Point" );
// Setting the widget containing the parameters
theWidget = NULL;
}
// --------------- destructor -------------------
BoxVOI::~BoxVOI()
{
// 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)
}
// --------------- getWidget --------------
QWidget * BoxVOI::getWidget()
{
BoxVOIWidget * rgWidget = dynamic_cast<BoxVOIWidget *> ( theWidget );
//-- create the widget if needed
if ( !rgWidget ) {
theWidget = new BoxVOIWidget ( this );
rgWidget = dynamic_cast<BoxVOIWidget *> ( theWidget );
}
//-- update the widget with a PickedPixelMap param
rgWidget->updateComponent ( dynamic_cast<ImageComponent *> ( getTargets().last() ) );
return theWidget;
}
// --------------- apply -------------------
Action::ApplyStatus BoxVOI::apply()
{
// check the widget
BoxVOIWidget * rgWidget = dynamic_cast<BoxVOIWidget *> ( theWidget );
// Get the image
ImageComponent * input = dynamic_cast<ImageComponent *> ( getTargets().last() );
// this call works only with a GUI (i.e. if theWidget exists)
if ( ( input == NULL ) || ( rgWidget == NULL ) )
return ABORTED;
// Get the parameters
seedPoints = rgWidget->getSeedPoints ( input );
// check if number of seeds is coherent
if ( seedPoints->count() == 2 || seedPoints->count() == 6 ) {
process ( input );
} else {
QMessageBox::warning ( NULL, "Warning", "Please select 2 or 6 seeds to apply this method", QMessageBox::Abort );
return ABORTED;
}
return SUCCESS;
}
// --------------- apply -------------------
Action::ApplyStatus BoxVOI::apply ( QList<QVector3D> * seedPoints )
{
// Get the image
ImageComponent * input = dynamic_cast<ImageComponent *> ( getTargets().last() );
// Get the parameters
this->seedPoints = seedPoints;
// check if number of seeds is coherent
if ( seedPoints->count() == 2 || seedPoints->count() == 6 ) {
process ( input );
} else {
std::cerr <<"Warning: Please select 2 or 6 seeds to apply this method"<< std::endl;
return ABORTED;
}
return SUCCESS;
}
// --------------- process -------------------
void BoxVOI::process ( ImageComponent * comp )
{
vtkSmartPointer<vtkImageData> inputImage = comp->getImageData();
vtkSmartPointer<vtkImageData> result = vtkSmartPointer<vtkImageData>::New();
vtkSmartPointer<vtkExtractVOI> extractVOI = vtkSmartPointer<vtkExtractVOI>::New();
//construction of new img
extractVOI->SetInput ( inputImage );
//get seeds values
int x1,x2,y1,y2,z1,z2=0;
if ( seedPoints->count() ==6 ) {
x1 = ( seedPoints->at ( 0 ).x() );
x2 = ( seedPoints->at ( 1 ).x() );
y1 = ( seedPoints->at ( 2 ).y() );
y2 = ( seedPoints->at ( 3 ).y() );
z1 = ( seedPoints->at ( 4 ).z() );
z2 = ( seedPoints->at ( 5 ).z() );
} else {
x1 = ( seedPoints->at ( 0 ).x() );
x2 = ( seedPoints->at ( 1 ).x() );
y1 = ( seedPoints->at ( 0 ).y() );
y2 = ( seedPoints->at ( 1 ).y() );
z1 = ( seedPoints->at ( 0 ).z() );
z2 = ( seedPoints->at ( 1 ).z() );
}
// constructs volume of interest
extractVOI->SetVOI ( std::min ( x1,x2 ),std::max ( x1,x2 ),std::min ( y1,y2 ),std::max ( y1,y2 ),std::min ( z1,z2 ),std::max ( z1,z2 ) );
extractVOI->Update();
// --------------------- Create and return a copy (the filters will be deleted)--
vtkImageData * resultImage = extractVOI->GetOutput();
// Adapt properties of the new volume
double *inputO = inputImage->GetOrigin();
// value - origin in case of origin of an image is not (0,0,0)
resultImage->SetOrigin (std::min ( x1,x2 )*comp->getVoxelSize().x()+inputO[0],
std::min ( y1,y2 )*comp->getVoxelSize().y()+inputO[1],
std::min ( z1,z2 )*comp->getVoxelSize().z()+inputO[2]);
// adapt extent to the new volume
int* dims = resultImage->GetDimensions();
int extent[6]={0,
dims[0]-1,
0,
dims[1]-1,
0,
dims[2]-1};
resultImage->SetExtent ( extent );
//Update values computed
result->SetExtent ( extent );
result->DeepCopy ( resultImage );
result->Update();
// creation of the image component
QString newName;
QTextStream ( &newName ) << comp->getName() << "_cropped";
new ImageComponent ( result, newName );
Application::refresh();
}
\ 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 BOXROI_H
#define BOXROI_H
#include <QObject>
#include <QMap>
#include <Action.h>
#include <ImageComponent.h>
#include <QFrame>
class BoxVOI : public camitk::Action {
public:
/// Default Constructor
BoxVOI(camitk::ActionExtension *);
/// Default Destructor
virtual ~BoxVOI();
/// Returns the widget that allows to modify the action parameters
virtual QWidget * getWidget();
public slots:
/** this method is automatically called when the action is triggered.
* !!! This method works only if theWidget has been instantiated
* (i.e. if getWidget has been called at least once, this is the case when there is a GUI)
* if not, please use the apply method with the parameters...
*/
virtual ApplyStatus apply();
/// Same method to be called manually with the parameters
virtual ApplyStatus apply(QList<QVector3D> * seedPoints);
private:
/// helper method to simplify the target component processing
virtual void process(camitk::ImageComponent * comp);
protected:
/// The widget will be filled with parameters
QWidget * theWidget;
/// list of seed points
QList<QVector3D> * seedPoints;
};
#endif // BOXROI_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 "BoxVOIExtension.h"
// include generated actions headers
#include "BoxVOI.h"
// --------------- declare the extension -------------------
Q_EXPORT_PLUGIN2 (boxvoiextension, BoxVOIExtension)
// --------------- getActions -------------------
void BoxVOIExtension::init() {
registerNewAction (BoxVOI);
}
/*****************************************************************************
* $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 BOXVOIEXTENSION_H
#define BOXVOIEXTENSION_H
#include <ActionExtension.h>
/** Simple action that allows to crop a subsample of a volume
*/
class BoxVOIExtension : public camitk::ActionExtension {
Q_OBJECT
Q_INTERFACES (camitk::ActionExtension)
public:
/// the constructor
BoxVOIExtension() : ActionExtension() {};
/// the destructor
virtual ~BoxVOIExtension() {};
/// Method that return the action extension name
virtual QString getName() {
return "BoxVOIExtension";
};
/// Method that return the action extension descrption
virtual QString getDescription() {
return "Allows to crop a subsample of a volume.";
};
/// initialize all the actions
virtual void init();
};
#endif // BOXVOIEXTENSION_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 <QList>
#include <QVector3D>
#include <PickedPixelMap.h>
#include <Application.h>
#include "BoxVOIWidget.h"
using namespace camitk;
BoxVOIWidget::BoxVOIWidget(Action * action)
: QWidget()
{
this->myAction = action;
ui.setupUi(this);
pickingW = new MultiPickingWidget(this);
ui.boxPointsGroupBox->layout()->addWidget(pickingW);
ui.descriptionBoxVOI->viewport()->setAutoFillBackground(false);
QObject::connect(ui.applyButton, SIGNAL(clicked()), myAction, SLOT(apply()));
}
BoxVOIWidget::~BoxVOIWidget() {
}
QList<QVector3D> * BoxVOIWidget::getSeedPoints(ImageComponent * image) {
return pickingW->getPickedPixelMap(image)->getPixelIndexList();
}
void BoxVOIWidget::updateComponent (ImageComponent * image) {
ui.componentName->setText(image->getName());
pickingW->updateComponent(image);
}
/*****************************************************************************
* $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 BOXVOIWIDGET_H
#define BOXVOIWIDGET_H
#include <QWidget>
#include <ImageComponent.h>
#include <MultiPickingWidget.h>
#include <Action.h>
#include "ui_BoxVOIWidget.h"
class BoxVOIWidget : public QWidget {
Q_OBJECT
public:
/// Default construtor
BoxVOIWidget(camitk::Action* action);
/// destructor
~BoxVOIWidget();
/// Update the widget with the correct PickedPixelMap (ImageComponent + Qlist of the selected points)
void updateComponent(camitk::ImageComponent * image);
/// List of seed points
QList<QVector3D> * getSeedPoints(camitk::ImageComponent * image);
protected:
Ui::BoxVOIWidget ui;
/// Multiple picking widget
MultiPickingWidget * pickingW;
/// Connected Action
camitk::Action * myAction;
};
#endif // BOXVOIWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BoxVOIWidget</class>
<widget class="QWidget" name="BoxVOIWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>359</width>
<height>619</height>
</rect>
</property>
<property name="windowTitle">
<string>Crop Region of Interest</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="imageComponentgroupBox">
<property name="title">
<string>Image Component</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Original Image Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="componentName">
<property name="text">
<string>None</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="boxPointsGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Box Points</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>ROI properties</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QTextEdit" name="descriptionBoxVOI">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Description:&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;This filter helps you to crop a volume with a parallelepiped. To use it, select respectively the min and the max of each axe (i,j,k), i.e 6 points.&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;It is possible to choose only 2 points to construct the parallelepiped. In this case, given points must be the origin and opposite diagonal point of the parallelepiped. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="groupBoxVSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>