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() );