Commit 65572eb5 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

Merge branch 'meshprojection' into 'develop'

Meshprojection

See merge request !170
parents 45108ed0 22abaf3e
......@@ -95,6 +95,8 @@ AnglesAndTranslationAction::~AnglesAndTranslationAction() {
QWidget* AnglesAndTranslationAction::getWidget() {
if (!actionWidget) {
actionWidget = new AnglesAndTranslationWidget(this);
// update the translation and corresponding UI wheever the arbitrary viewer slider changes
QObject::connect(Application::getViewer("Arbitrary Viewer"), SIGNAL(selectionChanged()), this, SLOT(updateTranslation()));
}
// update the pointer
......@@ -182,3 +184,17 @@ bool AnglesAndTranslationAction::event(QEvent* e) {
// this is important to continue the process if the event is a different one
return QObject::event(e);
}
// ---------------------- updateTranslationSlider ----------------------------
void AnglesAndTranslationAction::updateTranslation() {
// update the translation properties safely (i.e. without event(..) to be doing anything on the component)
blockEvent = true;
// current translation along the z axis of the arbitrary slice
setProperty("Translation", currentImageComp->getTranslationInVolume() * 100.0);
// update widget
dynamic_cast<AnglesAndTranslationWidget*>(actionWidget)->updateGUI();
blockEvent = false;
}
......@@ -68,6 +68,9 @@ public slots:
return SUCCESS;
}
// Update the translation and the corresponding slider whenever the arbitrary slice viewer slider has changed
void updateTranslation();
private:
/// update action's parameter using the current image state + update widget GUI
/// + update the central viewer depending on the current value of the "Visible Viewer" property
......
# Call CamiTK CMake Macro to define the action
camitk_extension(ACTION_EXTENSION
DEFAULT
INSTALL_ALL_HEADERS
DESCRIPTION "Show the contour of the mesh in a given orientation slice"
NEEDS_VIEWER interactivegeometryviewer interactivesliceviewer
AUTO_TEST
# all files but .frame
TEST_FILES sinus_skin_decimated.obj
)
This diff is collapsed.
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2021 Univ. Grenoble Alpes, 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 MESHPROJECTION_H
#define MESHPROJECTION_H
#include <Action.h>
#include <MeshComponent.h>
#include <ImageComponent.h>
#include <Slice.h>
#include <InteractiveViewer.h>
//--vtk
#include <vtkPlane.h>
#include <vtkPolyDataMapper.h>
/** Show the mesh contour in the slice viewers.
*
* This action needs two input components: a mesh component and an image component.
*
* The projection of a mesh is displayed as contour onto an image on each slice viewer (sagittal, coronal and axial)
* in respectively red, green and blue color.
*
*/
class MeshProjection : public camitk::Action {
Q_OBJECT
public:
/// Default Constructor
MeshProjection(camitk::ActionExtension *);
/// Default Destructor
virtual ~MeshProjection();
/// manage property modification immediatly
virtual bool event(QEvent* e);
/// 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.
* 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 MeshProjection (or a subclass).
*/
virtual ApplyStatus apply();
/// this slots is called when the user changes the selected slice to update the contour
void updateCuttingPlane();
private slots:
/// remove the contour from the viewers if the mesh is closed / destroyed
void hide();
private:
/// current mesh component
camitk::MeshComponent *meshToProject;
/// current image component to project onto
camitk::ImageComponent *targetImage;
/// update the managed mesh and check the change in the image component using the corresponding property
void updateComponents(camitk::MeshComponent *);
// used to map item id with component for the "Component List" property
QList<camitk::ImageComponent*> imageComponentList;
/// show/hide the contour in a viewer
void updateVisibility();
/// the contour mappers (input for both 3D and 2D actors)
QMap<camitk::Slice::SliceOrientation, vtkSmartPointer<vtkPolyDataMapper>> cutterMapperMap;
/// the mesh contours in the 3D view (where the mesh actually is), one for each orientation
QMap<camitk::Slice::SliceOrientation, vtkSmartPointer<vtkActor>> contourActorMap;
/// the mesh contours in the 2D views (with the proper transform that makes it appear in the slice viewer)
QMap<camitk::Slice::SliceOrientation, vtkSmartPointer<vtkActor>> contourActorIn2DViewerMap;
/// the cutting planes: the contour is the intersection between these planes and the mesh
QMap<camitk::Slice::SliceOrientation, vtkSmartPointer<vtkPlane>> cuttingPlaneMap;
/// get the dimension index corresponding to the current orientation
/// 0 is the index for sagittal dimension, 1 for the coronal orientation and 2 is for the axial orientation
int getOrientationIndex(camitk::Slice::SliceOrientation);
/// get the voxel slice in the correct orientation
double getVoxelSize(camitk::Slice::SliceOrientation);
/// get the slice viewer corresponding to the orientation
camitk::InteractiveViewer* getViewer(camitk::Slice::SliceOrientation);
/// create an actor for the contour. The color of the new actor depends on the current orientation
vtkSmartPointer<vtkActor> getNewActor(camitk::Slice::SliceOrientation);
/// create a plane for a given orientation
vtkSmartPointer<vtkPlane> getNewPlane(camitk::Slice::SliceOrientation);
/// update the cutting plane position depending on the current slice and the given orientation
void updateCuttingPlane(camitk::Slice::SliceOrientation);
/// update the contour line width using the corresponding property value
void updateContourLineWidth();
};
#endif // MESHPROJECTION_H
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2021 Univ. Grenoble Alpes, 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 "MeshProjectionExtension.h"
// include generated actions headers
#include "MeshProjection.h"
// --------------- getActions -------------------
void MeshProjectionExtension::init() {
// Creating and registering the instance of MeshProjection
registerNewAction(MeshProjection);
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2021 Univ. Grenoble Alpes, 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 MESHPROJECTIONEXTENSION_H
#define MESHPROJECTIONEXTENSION_H
#include <ActionExtension.h>
class MeshProjectionExtension : public camitk::ActionExtension {
Q_OBJECT
Q_INTERFACES(camitk::ActionExtension);
Q_PLUGIN_METADATA(IID "fr.imag.camitk.wizardgenerated.action.MeshProjectionExtension")
public:
/// Constructor
MeshProjectionExtension() : ActionExtension() {};
/// Destructor
virtual ~MeshProjectionExtension() {};
/// Method returning the action extension name
virtual QString getName() {
return "Mesh Projection Extension";
};
/// Method returning the action extension descrption
virtual QString getDescription() {
return "Show the contour of the mesh in 2D slices";
};
/// initialize all the actions
virtual void init();
};
#endif // MESHPROJECTIONEXTENSION_H
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/translate_meshcontour">
</qresource>
</RCC>
......@@ -25,28 +25,28 @@ initTestData() {
# Number of component, action and viewer extensions
componentExtensionCount=( [5.0]=14 [4.1]=14 [4.0]=14 )
actionExtensionCount=( [5.0]=32 [4.1]=27 [4.0]=27 )
actionExtensionCount=( [5.0]=33 [4.1]=27 [4.0]=27 )
viewerExtensionCount=( [5.0]=10 )
# Number of different file format/extension manages by the component extensions
fileExtensionCount=( [5.0]=37 [4.1]=37 [4.0]=37 )
# Number of actions provided by the action extensions
actionCount=( [5.0]=110 [4.1]=105 [4.0]=105 )
actionCount=( [5.0]=111 [4.1]=105 [4.0]=105 )
# Number of viewers managed by the viewer extensions
viewerCount=( [5.0]=13 )
#-- Release date
releaseDate=( [5.0]="not yet released, current development version" \
[4.1]="15 July 2018" \
[4.0]="22 July 2016" \
[3.5]="29 January 2016"
[3.4]="31 October 2014" \
[3.3]="4 March 2014" \
[3.2]="26 June 2013" \
[3.1]="1 March 2013" \
[3.0]="7 July 2012" )
releaseDate=( [5.0]="not yet released, current development version" \
[4.1]="15 July 2018" \
[4.0]="22 July 2016" \
[3.5]="29 January 2016"
[3.4]="31 October 2014" \
[3.3]="4 March 2014" \
[3.2]="26 June 2013" \
[3.1]="1 March 2013" \
[3.0]="7 July 2012" )
#-- extensionCount is just the sum of all three extension counts
extensionCount=( [5.0]=$((componentExtensionCount[5.0] + actionExtensionCount[5.0] + viewerExtensionCount[5.0]))
......
......@@ -94,6 +94,27 @@ extern double rint(double x);
#define CAMITK_API_DEPRECATED(X)
#endif
// -----------------------------------------------------------------------
// warning when using deprecated methods
//
// prefix each deprecated method by the CAMITK_API_DEPRECATED keyword
// CAMITK_API_NOT_IMPLEMENTED mymethod(...)
//
// This is silent during CamiTK Core compilation
#if !defined(COMPILE_CAMITK_API)
#if defined(__GNUC__) || defined(__clang__)
#define CAMITK_API_UNIMPLEMENTED __attribute__((deprecated("Unimplemeted method. Do not hesitate to contribute to CamiTK API!")))
#elif defined(_MSC_VER)
#define CAMITK_API_UNIMPLEMENTED __declspec(deprecated("Unimplemeted method. Do not hesitate to contribute to CamiTK API!"))
#endif // elif
#else
// inside CamiTK Core compilation
#define CAMITK_API_UNIMPLEMENTED
#if !defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)
#pragma message("WARNING: You need to implement CAMITK_API_UNIMPLEMENTED() for this compiler")
#endif
#endif // COMPILE_CAMITK_API
// -----------------------------------------------------------------------
// -- Definition of some useful CamiTK container types
namespace camitk {
......
......@@ -357,7 +357,7 @@ void ArbitrarySingleImageComponent::translate(double x, double y, double z) {
// -------------------- setSlice --------------------
void ArbitrarySingleImageComponent::setSlice(int s) {
// do nothing!
setTransformTranslation(0.0, 0.0, double(s)/100.0);
}
void ArbitrarySingleImageComponent::setSlice(double x, double y, double z) {
......@@ -391,12 +391,21 @@ void ArbitrarySingleImageComponent::setSlice(double x, double y, double z) {
// -------------------- getSlice --------------------
int ArbitrarySingleImageComponent::getSlice() const {
return 0;
double C_L[4] = {dimensions[0]* spacing[0] / 2.0 - spacing[0] / 2.0,
dimensions[1]* spacing[1] / 2.0 - spacing[1] / 2.0,
0.0,
1.0
};
double C_P[4];
getTransform()->GetMatrix()->MultiplyPoint(C_L, C_P);
QVector3D currentCenter(C_P[0], C_P[1], C_P[2]);
double k = QVector3D(currentCenter - cMinus_P).length() / QVector3D(cPlus_P - cMinus_P).length();
return k*100.0;
}
// -------------------- getNumberOfSlices --------------------
int ArbitrarySingleImageComponent::getNumberOfSlices() const {
return 0;
return 100;
}
......
......@@ -88,31 +88,34 @@ public:
/// rotate of the given angles around the center of the frame/arbitrary slice
virtual void setTransformRotation(double, double, double) override;
/// translation along the z axis (TODO Not yet implemented)
virtual void translate(double, double, double) override;
/// translation along the z axis (TODO implement this method)
CAMITK_API_UNIMPLEMENTED virtual void translate(double, double, double) override;
/// rotate on the slide center (TODO Not yet implemented)
virtual void rotate(double, double, double) override;
/// rotate on the slide center (TODO implement this method)
CAMITK_API_UNIMPLEMENTED virtual void rotate(double, double, double) override;
/// rotate on the slide center using the VTK way (TODO Not yet implemented)
virtual void rotateVTK(double, double, double) override;
/// rotate on the slide center using the VTK way (TODO implement this method)
CAMITK_API_UNIMPLEMENTED virtual void rotateVTK(double, double, double) override;
/// set translation the VTK way (TODO Not yet implemented)
virtual void setTransformTranslationVTK(double, double, double) override;
/// set translation the VTK way (TODO implement this method)
CAMITK_API_UNIMPLEMENTED virtual void setTransformTranslationVTK(double, double, double) override;
/// set rotation the VTK way (TODO Not yet implemented)
virtual void setTransformRotationVTK(double, double, double) override;
/// set rotation the VTK way (TODO implement this method)
CAMITK_API_UNIMPLEMENTED virtual void setTransformRotationVTK(double, double, double) override;
/// rewritten to do nothing. For arbitrary slice use setTransformTranslation and getTranslationInVolume instead
/// set slice as a percentage on the z axis translation
/// \note To set the slice using absolute value, please use setTransformTranslation and getTranslationInVolume instead
virtual void setSlice(int) override;
/// rewritten because the setSlice(int) method is overriden (compiler needs this)
virtual void setSlice(double, double, double) override;
/// rewritten: always return 0. For arbitrary slice use setTransformTranslation and getTranslationInVolume instead
/// return the slice as the percentage of translation (between 0 and 100)
/// \note To set the slice using absolute value, please use setTransformTranslation and getTranslationInVolume instead
virtual int getSlice() const override;
/// rewritten: always return 0. For arbitrary slice use setTransformTranslation and getTranslationInVolume instead
/// always return 100 (as getSlice() gives a percentage value, the max number of slices is 100.
/// \note To set the slice using absolute value, please use setTransformTranslation and getTranslationInVolume instead
virtual int getNumberOfSlices() const override;
/** This method is called when the arbitrary image has been picked in the arbitrary InteractiveViewer,
......@@ -122,16 +125,28 @@ public:
virtual void pixelPicked(double, double, double) override;
///@}
/// @name Specific helper methods to manage arbitrary orientation and its representation
///
/// @{
/// Get the current translation relatively to the volume
/// 0.0 means that the center of the slice is at the first border of the image volume
/// 1.0 means that the center of the slice is
///
/// \note: the center of the slice is the center of rotation
/// @see
virtual double getTranslationInVolume();
/// Compute the current position of the image center
/// and the z direction vector in the parent coordinate system (i.e. image frame)
void getImageCenterAndTranslationVectorInParent(double C_P[4], double Z_P[4]);
/// get the current position of the image center in the parent coordinate system
/// i.e the image frame (given as homogeneous point, hence 4D)
void getImageCenterInParent(double[4]);
///@}
private:
/// check if the center of the frame transformed usin the given matrix stays inside the initial image volume
bool checkCenter(vtkSmartPointer<vtkMatrix4x4>);
......@@ -142,14 +157,6 @@ private:
/// update cPlus and cMinus
void updateTranslationExtremity();
/// get the current position of the image center in the parent coordinate system
/// i.e the image frame (given as homogeneous point, hence 4D)
void getImageCenterInParent(double[4]);
/// Compute the current position of the image center
/// and the z direction vector in the parent coordinate system (i.e. image frame)
void getImageCenterAndTranslationVectorInParent(double C_P[4], double Z_P[4]);
/// dimension of the whole image (kept here for simplifying code)
int* dimensions;
......
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