Commit f65f9b13 authored by lealv's avatar lealv
Browse files

BUG 27: attach the process of the action to the progress bar.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1827 ec899d31-69d1-42ba-9299-647d76f65fb3
parent ec3256e2
......@@ -8,6 +8,7 @@
// Vtk includes
#include <vtkDataSetAttributes.h>
#include <vtkPointData.h>
#include <vtkCallbackCommand.h>
using namespace camitk;
......@@ -35,18 +36,22 @@ Action::ApplyStatus ComputeCurvatures::apply() {
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
Application::showStatusBarMessage ( "Compute Curvatures..." );
Application::resetProgressBar();
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
// target must be a polydata
MeshComponent *mesh = dynamic_cast<MeshComponent*> ( getTargets().first() );
if (!mesh) {
CAMITK_DEBUG ( "ComputeCurvatures", "apply", "mesh " +
getTargets().first()->getName().toStdString() + " is not a MeshComponent" )
return ABORTED;
}
vtkPolyData* pData = vtkPolyData::SafeDownCast(mesh->getPointSet());
pData->AddObserver(vtkCommand::ProgressEvent, progressCallback);
pData->Update();
if (!pData) {
CAMITK_DEBUG ( "ComputeCurvatures", "apply", "the mesh point set of " +
getTargets().first()->getName().toStdString() + " is not a polydata" )
......@@ -60,26 +65,27 @@ Action::ApplyStatus ComputeCurvatures::apply() {
vtkSmartPointer<vtkCurvatures> curv = vtkSmartPointer<vtkCurvatures>::New();
curv->SetCurvatureType ( property("Curvature type").toInt() );
curv->SetInput(pData);
curv->AddObserver(vtkCommand::ProgressEvent, progressCallback);
curv->Update();
switch(property("Curvature type").toInt()) {
case MINIMUM :
mesh->addPointData("Minimum Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Minimum_Curvature"));
break;
mesh->addPointData("Minimum Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Minimum_Curvature"));
break;
case MAXIMUM :
mesh->addPointData("Maximum Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Maximum_Curvature"));
break;
mesh->addPointData("Maximum Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Maximum_Curvature"));
break;
case GAUSSIAN :
mesh->addPointData("Gauss Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Gauss_Curvature"));
break;
mesh->addPointData("Gauss Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Gauss_Curvature"));
break;
case MEAN:
mesh->addPointData("Mean Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Mean_Curvature"));
break;
mesh->addPointData("Mean Curvature", vtkDataSetAttributes::SCALARS, curv->GetOutput()->GetPointData()->GetScalars("Mean_Curvature"));
break;
default :
return ABORTED;
break;
return ABORTED;
break;
}
// refresh restore the normal cursor and progress bar
Application::refresh();
Application::resetProgressBar();
......
......@@ -31,6 +31,7 @@
#include <vtkGeometryFilter.h>
#include <vtkCleanPolyData.h>
#include <vtkExtractEdges.h>
#include <vtkCallbackCommand.h>
using namespace camitk;
......@@ -52,17 +53,20 @@ Action::ApplyStatus ExtractEdges::apply() {
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
Application::showStatusBarMessage("Extracting edges...");
Application::resetProgressBar();
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
// use the last target
MeshComponent *targetMesh = dynamic_cast<MeshComponent*>(getTargets().last());
vtkSmartPointer<vtkExtractEdges> extractEdgesFilter = vtkSmartPointer<vtkExtractEdges>::New();
extractEdgesFilter->SetInput(targetMesh->getPointSet());
extractEdgesFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback);
extractEdgesFilter->Update();
// create a new mesh Component
// create a new mesh Component
new MeshComponent(extractEdgesFilter->GetOutput(), targetMesh->getName() + " edges");
Application::refresh();
Application::refresh();
// restore the normal cursor and progress bar
Application::resetProgressBar();
......
......@@ -31,6 +31,7 @@ using namespace camitk;
#include <vtkUnstructuredGrid.h>
#include <vtkGeometryFilter.h>
#include <vtkCleanPolyData.h>
#include <vtkCallbackCommand.h>
#include "ExtractSurface.h"
......@@ -51,20 +52,23 @@ Action::ApplyStatus ExtractSurface::apply() {
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
Application::showStatusBarMessage("Extracting Surface...");
Application::resetProgressBar();
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
// use the last target
MeshComponent *targetMesh = dynamic_cast<MeshComponent*>(getTargets().last());
vtkSmartPointer<vtkGeometryFilter> geometryFilter = vtkSmartPointer<vtkGeometryFilter>::New();
vtkSmartPointer<vtkCleanPolyData> cleanFilter = vtkSmartPointer<vtkCleanPolyData>::New();
geometryFilter->SetInput(targetMesh->getPointSet());
cleanFilter->SetInputConnection(geometryFilter->GetOutputPort());
cleanFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback);
cleanFilter->Update();
// create a new mesh Component
// create a new mesh Component
new MeshComponent(cleanFilter->GetOutput(), targetMesh->getName() + " surface");
Application::refresh();
Application::refresh();
// restore the normal cursor and progress bar
Application::resetProgressBar();
......
......@@ -67,13 +67,15 @@ Action::ApplyStatus FillWithPoints::apply() {
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
Application::showStatusBarMessage("Filling With Nodes...");
Application::resetProgressBar();
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
// use the last target
MeshComponent *targetMesh = dynamic_cast<MeshComponent*>(getTargets().last());
//-- check if this is a polydata and if this is an unstructured grid, extract the surface
vtkSmartPointer<vtkPolyData> targetPolyData = VtkMeshUtil::vtkPointSetToVtkPolyData(targetMesh->getPointSet());
//-- computes the subdivision depending on the mesh resolution
vtkSmartPointer<vtkPointLocator> subdivisionLocator = vtkSmartPointer<vtkPointLocator>::New();
subdivisionLocator->SetDataSet ( targetPolyData );
......@@ -86,7 +88,7 @@ Action::ApplyStatus FillWithPoints::apply() {
// length of the divisions in the x-axis, y-axis and z-axis
double *bounds = targetPolyData->GetPoints()->GetBounds(); // [xmin,xmax, ymin,ymax, zmin,zmax]
double xDiv = ( bounds[1] - bounds[0] ) / nbDiv[0];
double xDiv = ( bounds[1] - bounds[0] ) / nbDiv[0];
double yDiv = ( bounds[3] - bounds[2] ) / nbDiv[1];
double zDiv = ( bounds[5] - bounds[4] ) / nbDiv[2];
......@@ -108,11 +110,11 @@ Action::ApplyStatus FillWithPoints::apply() {
z = bounds[4] + k * zDiv;
// randomize
if (property("Randomize?").toBool()) {
x += ( xDiv / 10.0 ) * ( 0.5 - double ( qrand() ) / ( double ( RAND_MAX ) + 1.0 ) );
y += ( yDiv / 10.0 ) * ( 0.5 - double ( qrand() ) / ( double ( RAND_MAX ) + 1.0 ) );
z += ( zDiv / 10.0 ) * ( 0.5 - double ( qrand() ) / ( double ( RAND_MAX ) + 1.0 ) );
}
points->InsertNextPoint ( x, y, z );
x += ( xDiv / 10.0 ) * ( 0.5 - double ( qrand() ) / ( double ( RAND_MAX ) + 1.0 ) );
y += ( yDiv / 10.0 ) * ( 0.5 - double ( qrand() ) / ( double ( RAND_MAX ) + 1.0 ) );
z += ( zDiv / 10.0 ) * ( 0.5 - double ( qrand() ) / ( double ( RAND_MAX ) + 1.0 ) );
}
points->InsertNextPoint ( x, y, z );
}
}
}
......@@ -123,6 +125,7 @@ Action::ApplyStatus FillWithPoints::apply() {
vtkSmartPointer<vtkSelectEnclosedPoints> select = vtkSmartPointer<vtkSelectEnclosedPoints>::New();
select->SetInput ( gridPoints );
select->SetSurface ( targetPolyData );
select->AddObserver(vtkCommand::ProgressEvent, progressCallback);
select->Update();
//-- create a new polydata that contains only the internal selected points
......@@ -132,26 +135,28 @@ Action::ApplyStatus FillWithPoints::apply() {
insidePointsPoints->InsertNextPoint ( gridPoints->GetPoints()->GetPoint ( i ) );
}
}
vtkSmartPointer<vtkPolyData> insidePoints = vtkSmartPointer<vtkPolyData>::New();
insidePoints->SetPoints ( insidePointsPoints );
insidePoints->Allocate ( 2 );
vtkIdType *vtkPointIndex = new vtkIdType [insidePointsPoints->GetNumberOfPoints()];
for (vtkIdType i=0; i<insidePointsPoints->GetNumberOfPoints(); i++)
vtkPointIndex[i] = i;
vtkPointIndex[i] = i;
insidePoints->InsertNextCell(VTK_POLY_VERTEX, insidePointsPoints->GetNumberOfPoints(),vtkPointIndex);
insidePoints->AddObserver(vtkCommand::ProgressEvent, progressCallback);
insidePoints->Update();
//-- Generates one structure with all the points (append targetPolyData and insidePoints)
vtkSmartPointer<vtkAppendPolyData> appender = vtkSmartPointer<vtkAppendPolyData>::New();
appender->AddInput ( targetPolyData );
appender->AddInput ( insidePoints );
appender->AddObserver(vtkCommand::ProgressEvent, progressCallback);
appender->Update();
//-- Create a new mesh Component using an unstructured grid (to show the isolated nodes)
vtkSmartPointer<vtkPointSet> resultPointSet = appender->GetOutput();
new MeshComponent(resultPointSet, targetMesh->getName() + " filled");
Application::refresh();
Application::refresh();
// restore the normal cursor and progress bar
Application::resetProgressBar();
......
......@@ -33,11 +33,12 @@
#include <vtkIterativeClosestPointTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkLandmarkTransform.h>
#include <vtkCallbackCommand.h>
using namespace camitk;
ICPRegistration::ICPRegistration ( camitk::ActionExtension* ext ) : Action ( ext ) {
this->setName ( "ICP Registration" );
this->setDescription ( QString ( "Iterative Closest Point algorithm bewteen two mesh.<br/>" ) +
QString ( "At least two mesh components must be selected :" ) +
......@@ -69,6 +70,8 @@ camitk::Action::ApplyStatus ICPRegistration::apply() {
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
Application::showStatusBarMessage ( "Registration..." );
Application::resetProgressBar();
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
// at least 2 targets must be selected
if ( getTargets().size() < 2 ) {
......@@ -101,15 +104,16 @@ camitk::Action::ApplyStatus ICPRegistration::apply() {
icp->SetMaximumNumberOfIterations ( property ( "Number of iterations" ).toInt() );
switch (property("Distance mesure type").toInt()) {
case RMS :
icp->SetMeanDistanceModeToRMS();
break;
icp->SetMeanDistanceModeToRMS();
break;
case ABS :
icp->SetMeanDistanceModeToAbsoluteValue();
break;
icp->SetMeanDistanceModeToAbsoluteValue();
break;
default:
icp->SetMeanDistanceModeToRMS();
break;
icp->SetMeanDistanceModeToRMS();
break;
}
icp->AddObserver( vtkCommand::ProgressEvent, progressCallback);
icp->Modified();
icp->Update();
......@@ -122,6 +126,7 @@ camitk::Action::ApplyStatus ICPRegistration::apply() {
icpTransformFilter->SetInputData ( sourceMesh->getPointSet() );
#endif
icpTransformFilter->SetTransform ( icp );
icpTransformFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback);
icpTransformFilter->Update();
// create a new MeshComponent for the result
......
......@@ -32,6 +32,7 @@
#include <vtkPolyDataNormals.h>
#include <vtkSmartPointer.h>
#include <vtkCallbackCommand.h>
using namespace camitk;
......@@ -71,14 +72,20 @@ void InvertMesh::process(MeshComponent * comp) {
vtkSmartPointer<vtkPolyDataNormals> polydataNormals = vtkSmartPointer<vtkPolyDataNormals>::New();
vtkSmartPointer<vtkPolyData> poly = vtkPolyData::SafeDownCast(comp->getPointSet());
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
polydataNormals->SetInput(poly);
polydataNormals->SetFlipNormals(1);
polydataNormals->AddObserver(vtkCommand::ProgressEvent, progressCallback);
polydataNormals->Update();
comp->setPointSet(vtkPointSet::SafeDownCast(polydataNormals->GetOutput()));
comp->refresh();
// restore the normal cursor and progress bar
Application::resetProgressBar();
QApplication::restoreOverrideCursor();
}
......@@ -35,6 +35,7 @@
// Vtk includes
#include <vtkSmoothPolyDataFilter.h>
#include <vtkSmartPointer.h>
#include <vtkCallbackCommand.h>
using namespace camitk;
......@@ -114,6 +115,9 @@ void SmoothFilter::process(MeshComponent * comp) {
int iteration = property("Number of iterations").toInt();
double relaxation = property("Relaxation factor").toDouble();
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
vtkSmartPointer<vtkPolyData> poly = vtkPolyData::SafeDownCast(comp->getPointSet());
// create the filter and set the polydata
......@@ -134,10 +138,15 @@ void SmoothFilter::process(MeshComponent * comp) {
// turn on/off smoothing along sharp interior edges.
if (edgeSmoothing)
smoothFilter->SetFeatureEdgeSmoothing(1);
smoothFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback);
smoothFilter->Update();
comp->setPointSet(vtkPointSet::SafeDownCast(smoothFilter->GetOutput()));
comp->refresh();
// restore the normal cursor and progress bar
Application::resetProgressBar();
QApplication::restoreOverrideCursor();
}
......@@ -45,6 +45,7 @@
#include <vtkCellLocator.h>
#include <vtkPolyDataConnectivityFilter.h>
#include <vtkUnstructuredGrid.h>
#include <vtkCallbackCommand.h>
using namespace camitk;
......@@ -78,6 +79,8 @@ Action::ApplyStatus WarpOut::apply() {
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
Application::showStatusBarMessage("Warping out...");
Application::resetProgressBar();
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
// use the last target
MeshComponent *targetMesh = dynamic_cast<MeshComponent*>(getTargets().last());
......@@ -91,12 +94,13 @@ Action::ApplyStatus WarpOut::apply() {
resultPointSet = vtkSmartPointer<vtkPolyData>::New();
}
else {
QMessageBox::warning(NULL, "Warp Out", "Invalid mesh: the selected component (\"" + targetMesh->getName() + "\") is not an unstructured grid nor a polydata.", QMessageBox::Abort);
QMessageBox::warning(NULL, "Warp Out", "Invalid mesh: the selected component (\"" + targetMesh->getName() + "\") is not an unstructured grid nor a polydata.", QMessageBox::Abort);
return ABORTED;
}
resultPointSet->DeepCopy(targetMesh->getPointSet());
}
resultPointSet->AddObserver(vtkCommand::ProgressEvent, progressCallback);
resultPointSet->DeepCopy(targetMesh->getPointSet());
resultPointSet->Update();
//-- add the id as point data in order to match normal to the points
vtkSmartPointer<vtkIdTypeArray> pointId = vtkSmartPointer<vtkIdTypeArray>::New();
pointId->SetNumberOfComponents(1);
......@@ -111,6 +115,7 @@ Action::ApplyStatus WarpOut::apply() {
//-- extract the surface
vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
surfaceFilter->SetInput(resultPointSet);
surfaceFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback);
surfaceFilter->Update();
//-- generate the normals
......@@ -119,6 +124,7 @@ Action::ApplyStatus WarpOut::apply() {
normalGenerator->ComputePointNormalsOn();
normalGenerator->ComputeCellNormalsOff();
normalGenerator->SplittingOff();
normalGenerator->AddObserver(vtkCommand::ProgressEvent, progressCallback);
normalGenerator->Update();
//-- Find the outer surface (see ExtractOutsideSurface Cxx example)
......@@ -151,6 +157,7 @@ Action::ApplyStatus WarpOut::apply() {
connectivityFilter->SetExtractionModeToCellSeededRegions();
connectivityFilter->InitializeSeedList();
connectivityFilter->AddSeed(cellId);
connectivityFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback);
connectivityFilter->Update();
/*
......
Supports Markdown
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