Commit 5a7da759 authored by promayon's avatar promayon
Browse files

NEW Basic mesh picking action

NEW pixel value displayed in status bar when image picked
FIXED MeshComponent is automatically visible in the 3D viewer
FIXED FindCamiTK.cmake in case of install (linux)
FIXED starting size of MainWindow (should always be 1024x768)
FIXED Arbitrary slice layout in medical image viewer
FIXED Fancy has now a MedicalImageViewer and its own 3D viewer (new interactive viewer): simpler, correct layout,...
FIXED some (very few) code cleaning msh component and basictopology (btw thanks you Mat for your contribution!)
FIXED delete exporttomsh action (not needed any more thanks to msh component, which has a much better element/cell type coverage)

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@152 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 92630675
......@@ -24,6 +24,7 @@
#include <MeshComponent.h>
#include <InteractiveViewer.h>
#include <RendererWidget.h>
#include <Log.h>
using namespace camitk;
......@@ -69,7 +70,7 @@ VolumeRenderingAction::~VolumeRenderingAction() {
// --------------- apply -------------------
Action::ApplyStatus VolumeRenderingAction::apply() {
cout << "VolumeRenderingAction::apply()" << endl;
CAMITK_INFO("VolumeRenderingAction", "apply", "apply volume rendering");
foreach (Component *comp, getTargets()) {
ImageComponent * input = dynamic_cast<ImageComponent *> ( comp );
process(input);
......@@ -111,7 +112,7 @@ void VolumeRenderingAction::process(ImageComponent * comp) {
// FILTER
// Cast element type of the image of type unigned short for mapper to work on the image
vtkImageCast *imageCast = vtkImageCast::New();
vtkSmartPointer<vtkImageCast> imageCast = vtkImageCast::New();
imageCast->SetInput(comp->getImageData()); // reader->GetOutput());
imageCast->SetOutputScalarTypeToUnsignedShort();
......@@ -209,14 +210,16 @@ void VolumeRenderingAction::process(ImageComponent * comp) {
if (oldVolume) {
comp->removeProp(volumeName);
InteractiveViewer::get3DViewer()->getRendererWidget()->removeProp(oldVolume);
//InteractiveViewer::get3DViewer()->getRendererWidget()->removeProp(oldVolume);
}
// Add the new computed volume to the component and display it in the 3D viewer
comp->addProp(volumeName, volume);
InteractiveViewer::get3DViewer()->getRendererWidget()->addProp(volume);
InteractiveViewer::get3DViewer()->refresh();
comp->getProp(volumeName)->SetVisibility(true);
//InteractiveViewer::get3DViewer()->getRendererWidget()->addProp(volume);
//InteractiveViewer::get3DViewer()->refresh();
comp->refresh();
// Create new component
// new ImageComponent(volumeMapper->GetInput(), comp->getImageName() + "_vr");
// Application::refresh();
......
......@@ -24,7 +24,7 @@ $CAMITK_LICENCE_END$
*****************************************************************************/
#include "PickedPixelMap.h"
#include "ImageComponent.h"
#include <ImageComponent.h>
#include <QFileInfo>
......
......@@ -27,6 +27,7 @@ $CAMITK_LICENCE_END$
#include "RigidTransform.h"
#include "RenderingOption.h"
#include "ChangeColor.h"
#include "MeshPicking.h"
#include <Action.h>
......@@ -44,4 +45,5 @@ void BasicMeshExtension::init() {
registerNewAction(ChangeColor);
registerNewAction(RenderingOption);
registerNewAction(RigidTransform);
registerNewAction(MeshPicking);
}
\ No newline at end of file
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
// because of namespace problems with Component, put these include first
#include "MeshPicking.h"
#include <MeshComponent.h>
#include <Log.h>
#include <Application.h>
#include <InteractiveViewer.h>
//-- vtk stuff to compute some information from the picking
#include <vtkCell.h>
#include <vtkPoints.h>
// Qt
#include <QPushButton>
#include <QVBoxLayout>
// -------------------- MeshPicking --------------------
MeshPicking::MeshPicking(ActionExtension *extension) : Action(extension) {
setName("Basic Mesh Picking");
setDescription("Pick a mesh to retrieve point/cell information from the mesh");
setComponent("MeshComponent");
setFamily("Basic Mesh");
addTag("Picking");
addTag("Tutorial");
//-- widget lazy instanciation
informationFrame = NULL;
}
QWidget* MeshPicking::getWidget() {
if (!informationFrame) {
//-- the frame
informationFrame = new QFrame();
informationFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
informationFrame->setLineWidth(3);
//-- the information label
informationLabel = new QLabel();
//-- run the action every time a picking is done in the axial/sagittal or coronal planes
QObject::connect(InteractiveViewer::get3DViewer(), SIGNAL(selectionChanged()), this, SLOT(apply()));
//-- the vertical layout, put every GUI elements in it
QVBoxLayout * informationFrameLayout = new QVBoxLayout();
informationFrameLayout->addWidget(informationLabel);
//-- set the layout for the action widget
informationFrame->setLayout(informationFrameLayout);
}
return informationFrame;
}
// --------------- apply -------------------
Action::ApplyStatus MeshPicking::apply() {
// set waiting cursor (not really needed here as the action is very fast, but after all this is a demo)
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
// get the last selected image component
MeshComponent * meshComponent = dynamic_cast<MeshComponent *>(getTargets().last());
// NOTE it is not needed to check for NULL pointer after this dynamic_cast: this action
// has declared to be able to process MeshComponent (see the setComponent(..) in the constructor),
// therefore it is only called using getTargets() that are compatible with MeshComponent
// get the index in the respectively Points and Cells array
vtkIdType lastPickedPointId = meshComponent->getPickedPointId();
vtkIdType lastPickedCellId = meshComponent->getPickedCellId();
// the information message (in rich text, i.e., html)
QString message = "<b>Selected Component:</b> " + meshComponent->getName() + "<br/>";
// if the id is valid, get the corresponding information
if (lastPickedPointId >= 0) {
message += "<b>Point Id:</b> " + QString("%1").arg(lastPickedPointId, 6) + "<br/>";
// get the position
double *pointPosition = meshComponent->getPointSet()->GetPoint(lastPickedPointId);
message += "<b>Point Position:</b> "+ QString("(%1,%2,%3)").arg(pointPosition[0], 6).arg(pointPosition[1], 6).arg(pointPosition[2], 6) + "<br/>";
}
else {
message += "<b>No point picked</b><br/>";
}
if (lastPickedCellId >= 0) {
message += "<b>Cell Id:</b> " + QString("%1").arg(lastPickedCellId, 6) + "<br/>";
vtkCell *pickedCell = meshComponent->getPointSet()->GetCell(lastPickedCellId);
// for example here compute the barycenter of the cell
double cellBarycenter[3] = {0.0, 0.0, 0.0};
// loop on all the cell points
for (unsigned int i = 0; i < pickedCell->GetNumberOfPoints(); i++) {
// for each point accumulate the position
double *position = pickedCell->GetPoints()->GetPoint(i);
for (unsigned int j = 0; j < 3; j++) {
cellBarycenter[j] += position[j];
}
}
// divide by the number of accumulation
for (unsigned int i = 0; i < 3; i++) {
cellBarycenter[i] /= pickedCell->GetNumberOfPoints();
}
// add information
message += "<b>Barycenter:</b> " + QString("(%1,%2,%3)").arg(cellBarycenter[0], 6).arg(cellBarycenter[1], 6).arg(cellBarycenter[2], 6);
}
else {
message += "<b>No cell picked</b>";
}
// update the information label
informationLabel->setText(message);
CAMITK_INFO("MeshPicking", "apply", "Done...");
// NOTE this CAMITK_INFO is here just to show how to use CamiTK log facilities
// restore the normal cursor
QApplication::restoreOverrideCursor();
return SUCCESS;
}
......@@ -23,37 +23,41 @@ Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
#ifndef EXPORTTOMESH_H
#define EXPORTTOMESH_H
#ifndef MESH_PICKING_H
#define MESH_PICKING_H
#include <Action.h>
using namespace camitk;
#include <QFrame>
#include <QLabel>
/**
* Quick export to (a subset of) Msh format.
* see http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#File-formats for the msh format.
* This is a subset working in sofa.
*
* Only tetrahedron and hexahedron are implemented yet.
* Demonstrates how to get information from image picking.
* This is an embedded action (it is shown in the ActionViewer)
*/
class ExportToMsh : public Action {
class MeshPicking : public Action {
public:
/// the constructor
ExportToMsh(ActionExtension *);
MeshPicking(ActionExtension *);
/// the destructor
virtual ~ExportToMsh() {};
virtual ~MeshPicking() {};
/// no specific widget needed, the export filename is asked in appy
virtual QWidget * getWidget() {
return NULL;
}
/// method called when the action when the action is triggered (i.e. started)
virtual QWidget * getWidget();
public slots:
/// method called when the action is applied
virtual ApplyStatus apply();
private:
/// this action widget (to simplify, it is just a label that gives information + a button)
QFrame *informationFrame;
/// the information label (needed as an attributes to update the displayed text)
QLabel *informationLabel;
};
#endif // EXPORTTOMESH_H
#endif // MESH_PICKING_H
\ No newline at end of file
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
/**
* @file BasicTopologyExtension.cpp
* @brief Class for basic topology manipulationµ.
......
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
/**
* @file BasicTopologyExtension.h
* @brief Class for basic topology manipulation.
......
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
/**
* @file GridTopology.cpp
* @brief Class implementation for 3D grid mesh creation
......@@ -20,15 +44,11 @@
GridTopology::GridTopology(ActionExtension *extension) : Action(extension) {
setName("Grid Topology");
setEmbedded(true);
setDescription("Build a regular grid");
setComponent(""); // empty component: it does not need any data to be triggered
setFamily("Mesh Processing");
addTag("Build Grid");
//-- widget lazy instanciation
myWidget = NULL;
setProperty("Tetrahedralize", false);
setProperty("Dimension X", 1);
setProperty("Dimension Y", 1);
......@@ -42,8 +62,6 @@ GridTopology::GridTopology(ActionExtension *extension) : Action(extension) {
}
GridTopology::~GridTopology() {
if (myWidget)
delete myWidget;
}
Action::ApplyStatus GridTopology::apply() {
......@@ -100,8 +118,9 @@ Action::ApplyStatus GridTopology::apply() {
grid->Update();
MeshComponent* result = new MeshComponent(grid, "Grid_" + QString::number(dimX)+"x"+QString::number(dimY)+"x"+QString::number(dimZ));
Application::getMainWindow()->refresh();
Application::refresh();
Application::resetProgressBar();
Application::showStatusBarMessage("");
return SUCCESS;
}
\ No newline at end of file
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
/**
* @file GridTopology.h
* @brief Class for 3D grid mesh creation
......@@ -31,7 +55,6 @@ private:
/// method called when the action is applied
virtual ApplyStatus apply();
QWidget* myWidget;
};
#endif // GRID_TOPOLOGY_HPP_
\ No newline at end of file
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
/**
* @file SphereTopology.cpp
* @brief Class implementation for 3D sphere mesh creation
......@@ -27,9 +52,6 @@ SphereTopology::SphereTopology(ActionExtension *extension) : Action(extension) {
setFamily("Mesh Processing");
addTag("Build Sphere");
//-- widget lazy instanciation
myWidget = NULL;
setProperty("Center X", 0.);
setProperty("Center Y", 0.);
setProperty("Center Z", 0.);
......@@ -39,8 +61,6 @@ SphereTopology::SphereTopology(ActionExtension *extension) : Action(extension) {
}
SphereTopology::~SphereTopology() {
if (myWidget)
delete myWidget;
}
Action::ApplyStatus SphereTopology::apply() {
......@@ -61,9 +81,9 @@ Action::ApplyStatus SphereTopology::apply() {
vtkSmartPointer<vtkPolyData> pData = sphere->GetOutput();
MeshComponent* result = new MeshComponent(pData, "Sphere");
Application::getMainWindow()->refresh();
Application::refresh();
Application::resetProgressBar();
//Application::setStatusBarMsg("");
Application::showStatusBarMessage("");
return SUCCESS;
}
\ No newline at end of file
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
/**
* @file SphereTopology.h
* @brief Class for 3D sphere mesh creation
......
action_extension(DEFAULT
NEEDS_COMPONENT_EXTENSION vtkmesh
DEFINES COMPILE_EXPORTTOMESH_ACTION_API)
\ No newline at end of file
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
#include "ExportToMsh.h"
#include <Component.h>
#include <Log.h>
#include <Application.h>
//-- vtk stuff
#include <vtkTetra.h>
#include <vtkUnstructuredGrid.h>
#include <vtkCellArray.h>
//-- Qt Stuff
#include <QMessageBox>
#include <QFileInfo>
#include <QFileDialog>
// -------------------- ExportToMsh --------------------
ExportToMsh::ExportToMsh(ActionExtension *extension) : Action(extension) {
this->setName("Export To Msh");
setEmbedded(false);
this->setDescription("Export any mesh to MSH format (a subset of)");
this->setComponent("MeshComponent");
this->setFamily("Mesh Processing");
this->addTag("ExportToMsh");
this->addTag("Export");
this->addTag("MSH");
}
// --------------- apply -------------------
Action::ApplyStatus ExportToMsh::apply() {
bool warning = false;
CAMITK_INFO("ExportToMsh", "apply", "Exporting " << getTargets().last()->getName().toStdString());
// set waiting cursor
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
// get the last component
camitk::Component *myComponent = getTargets().last();
vtkSmartPointer<vtkPointSet> ps = myComponent->getPointSet();
//-- 6 Generate .msh and .scn
// see http://www.geuz.org/gmsh/doc/texinfo/gmsh.html#File-formats for the msh format
// this is a subset working in sofa
QString baseFilename = QFileInfo(myComponent->getFileName()).absolutePath() + "/" + QFileInfo(myComponent->getFileName()).completeBaseName();
QString mshFilename = baseFilename + ".msh";
mshFilename = QFileDialog::getSaveFileName(0, tr("Select MSH file name"), mshFilename, tr("MSH file (*.msh)"));
ofstream mshFile ( mshFilename.toUtf8() );
double xyz[3];
mshFile << "$NOD" << endl;
mshFile << ps->GetPoints()->GetNumberOfPoints() << endl;
for ( int i = 0; i < ps->GetPoints()->GetNumberOfPoints(); i++ ) {
ps->GetPoints()->GetPoint(i, xyz);
// write atom
mshFile << i + 1 << " " << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl;
}
mshFile << "$ENDNOD" << endl;
mshFile << "$ELM" << endl;
mshFile << ps->GetNumberOfCells() << endl;
for ( unsigned int i = 0; i < ps->GetNumberOfCells() ; i++ ) {