36 #include "QGoGUILibConfigure.h"
38 #include "vtkSmartPointer.h"
39 #include "vtkImageData.h"
44 #include "vtkMatrix4x4.h"
45 #include "vtkImageReslice.h"
48 #include "vtkContourFilter.h"
49 #include "vtkMarchingSquares.h"
50 #include "vtkCellArray.h"
52 #include "vtkStripper.h"
53 #include "vtkFeatureEdges.h"
56 #include "vtkMarchingCubes.h"
58 #include "vtkPolyDataConnectivityFilter.h"
60 #include "vtkFillHolesFilter.h"
62 #include "vtkWindowedSincPolyDataFilter.h"
63 #include "vtkPolyDataWriter.h"
67 #include "vtkCutter.h"
69 #include "vtkImageExport.h"
79 m_OriginalImageMC(NULL),
140 vtkSmartPointer< vtkImageData >
352 static double elements[3][16] = { {
372 vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();
374 resliceAxes->DeepCopy(elements[iDirection]);
376 resliceAxes->SetElement(0, 3, iOrigin[0]);
377 resliceAxes->SetElement(1, 3, iOrigin[1]);
378 resliceAxes->SetElement(2, 3, iOrigin[2]);
380 vtkImageReslice *reslicer = vtkImageReslice::New();
381 reslicer->SetOutputDimensionality(2);
382 reslicer->SetInformationInput(iOriginalImage);
383 reslicer->SetInterpolationModeToLinear();
384 reslicer->SetInput(iOriginalImage);
385 reslicer->SetResliceAxes(resliceAxes);
388 vtkImageData *output = vtkImageData::New();
389 output->DeepCopy( reslicer->GetOutput() );
392 resliceAxes->Delete();
404 vtkMarchingSquares *contours = vtkMarchingSquares::New();
406 contours->SetInput(iInputImage);
407 contours->GenerateValues (1, iThreshold, iThreshold);
410 vtkPolyData *outputToOrganize = vtkPolyData::New();
411 outputToOrganize->DeepCopy( contours->GetOutput() );
416 outputToOrganize->Delete();
428 vtkStripper *stripper = vtkStripper::New();
430 stripper->SetInput(iInputImage);
432 stripper->SetMaximumLength(999);
436 stripper->GetOutput()->GetLines()->InitTraversal();
441 vtkIdType *pts = NULL;
443 stripper->GetOutput()->GetLines()->GetNextCell(npts, pts);
444 vtkPoints *points = vtkPoints::New();
446 vtkCellArray *lines = vtkCellArray::New();
447 vtkIdType * lineIndices =
new vtkIdType[
static_cast< int >( npts + 1 )];
449 for (
int k = 0; k < static_cast< int >( npts ); k++ )
451 points->InsertPoint( k, stripper->GetOutput()->GetPoints()->GetPoint(pts[k]) );
455 lineIndices[
static_cast< int >( npts )] = 0;
456 lines->InsertNextCell(npts + 1, lineIndices);
457 delete[] lineIndices;
459 vtkPolyData *testPolyD = vtkPolyData::New();
460 testPolyD->SetPoints(points);
461 testPolyD->SetLines(lines);
467 decimator->SetInput(testPolyD);
469 double ratio = 1. - 20. /
static_cast< double >( npts );
471 decimator->SetTargetReduction(ratio);
474 vtkPolyData *output = vtkPolyData::New();
475 output->DeepCopy( decimator->GetOutput() );
513 vtkSmartPointer< vtkContourFilter > contours = vtkSmartPointer< vtkContourFilter >::New();
514 contours->SetInput(iInputImage);
515 contours->SetComputeGradients(0);
516 contours->SetComputeNormals(0);
517 contours->SetComputeScalars(0);
518 contours->SetNumberOfContours(1);
519 contours->SetValue(0, iThreshold);
522 vtkSmartPointer< vtkFeatureEdges > feature =
523 vtkSmartPointer< vtkFeatureEdges >::New();
524 feature->SetInputConnection( contours->GetOutputPort() );
525 feature->BoundaryEdgesOn();
526 feature->FeatureEdgesOff();
527 feature->NonManifoldEdgesOn();
528 feature->ManifoldEdgesOff();
531 vtkSmartPointer< vtkFillHolesFilter > fillFilter =
532 vtkSmartPointer< vtkFillHolesFilter >::New();
534 vtkSmartPointer< vtkPolyDataConnectivityFilter > connectivityFilter =
535 vtkSmartPointer< vtkPolyDataConnectivityFilter >::New();
536 connectivityFilter->SetExtractionModeToLargestRegion();
539 if ( feature->GetOutput()->GetNumberOfCells() > 0 )
542 fillFilter->SetInputConnection( contours->GetOutputPort() );
543 fillFilter->Update();
545 connectivityFilter->SetInputConnection( fillFilter->GetOutputPort() );
549 connectivityFilter->SetInputConnection( contours->GetOutputPort() );
553 connectivityFilter->Update();
555 unsigned int smoothingIterations = 15;
556 double passBand = 0.001;
557 double featureAngle = 120.0;
560 vtkSmartPointer< vtkWindowedSincPolyDataFilter > smoother =
561 vtkSmartPointer< vtkWindowedSincPolyDataFilter >::New();
562 smoother->SetInputConnection( connectivityFilter->GetOutputPort() );
563 smoother->SetNumberOfIterations( smoothingIterations );
564 smoother->BoundarySmoothingOff();
565 smoother->FeatureEdgeSmoothingOff();
566 smoother->SetFeatureAngle(featureAngle);
567 smoother->SetPassBand(passBand);
568 smoother->NonManifoldSmoothingOn();
569 smoother->NormalizeCoordinatesOn();
572 vtkPolyData *output = vtkPolyData::New();
573 output->DeepCopy( connectivityFilter->GetOutput() );
void UpdateAdvancedMode(bool)
void setOriginalImageMC(std::vector< vtkSmartPointer< vtkImageData > > *iOriginalImage)
double * getCenter()
Get the center of the area to be segmented.
void setName(QString iName)
Set Name of the filter in the combo box.
QGoFilterSemiAutoBase(QObject *iParent=NULL)
Constructor.
vtkSmartPointer< vtkImageData > getInput()
void setOutput(vtkImageData *iOutput)
int getChannel()
Get the channel to be segmented.
vtkPolyData * ReorganizeContour(vtkPolyData *iInputImage=NULL, bool iDecimate=true)
void UpdateVisibility(int iFilter)
virtual void ConnectSignals(int iFilterNumber)
void setChannel(int iChannel=0)
void setWidget(QWidget *iWidget)
Set the widget associated to the filter.
vtkPolyData * ReconstructMesh(vtkImageData *iInputImage, const double &iThreshold)
void setSampling(int iSampling)
static vtkPolylineDecimation * New()
Instantiate this object with a target reduction of 0.90.
QWidget * getWidget()
Get the widget associated to the filter.
void setCenter(double *iCenter)
vtkPolyData * ReconstructContour(vtkImageData *iInputImage, const double &iThreshold)
QString getName()
Get Name of the filter in the combo box.
std::vector< vtkSmartPointer< vtkImageData > > * m_OriginalImageMC
virtual ~QGoFilterSemiAutoBase()
Destructor.
vtkImageExport * m_vtk2itkImage
vtkImageData * extractOneSlice(vtkImageData *iOriginalImage, double *iOrigin, int iDirection)
double getRadius()
Get the radius of the area to be segmented.
vtkImageData * getOutput()
void setPoints(vtkPoints *iPoints)
void setRadius(double iRadius)