Skip to content

Commit

Permalink
Re #178: Add option to switch between end-capping methods
Browse files Browse the repository at this point in the history
By setting the "End capping" parameter, the method used to generate end caps can be changed:
- 0 = leave contours open on surface exterior.
- 1 (default) = close surface by generating smooth end caps.
- 2 = close surface by generating straight end caps.
  • Loading branch information
Sunderlandkyl committed Jan 29, 2021
1 parent 21f2321 commit 3d69277
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ vtkPlanarContourToClosedSurfaceConversionRule::vtkPlanarContourToClosedSurfaceCo
this->ConversionParameters[this->GetDefaultSliceThicknessParameterName()] = std::make_pair("0.0",
"Default thickness for contours if slice spacing cannot be calculated.");
this->ConversionParameters[this->GetEndCappingParameterName()] = std::make_pair("1",
"Create end cap to close surface inside contours on the top and bottom of the structure. 1 (default) = close surface by generating end caps. 0 = leave contours open on surface exterior.");
"Create end cap to close surface inside contours on the top and bottom of the structure.\n"
"0 = leave contours open on surface exterior.\n"
"1 (default) = close surface by generating smooth end caps.\n"
"2 = close surface by generating straight end caps."
);
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -313,7 +317,7 @@ bool vtkPlanarContourToClosedSurfaceConversionRule::Convert(vtkDataObject* sourc
}

// Triangulate all contours which are exposed.
if (vtkVariant(this->GetConversionParameter(this->GetEndCappingParameterName())).ToInt() == true)
if (vtkVariant(this->GetConversionParameter(this->GetEndCappingParameterName())).ToInt() != EndCappingModes::None)
{
this->EndCapping(inputContoursCopy, outputPolygons, lineTriganulatedToAbove, lineTriganulatedToBelow);
}
Expand Down Expand Up @@ -1280,6 +1284,68 @@ void vtkPlanarContourToClosedSurfaceConversionRule::CreateEndCapContour(vtkPolyD
vtkErrorMacro("CreateEndCapContour: invalid vtkCellArray");
}

if (vtkVariant(this->GetConversionParameter(this->GetEndCappingParameterName())).ToInt() == EndCappingModes::Smooth)
{
this->CreateSmoothEndCapContour(inputROIPoints, inputLine, outputLines, lineSpacing);
}
else if (vtkVariant(this->GetConversionParameter(this->GetEndCappingParameterName())).ToInt() == EndCappingModes::Straight)
{
this->CreateStraightEndCapContour(inputROIPoints, inputLine, outputLines, lineSpacing);
}
}

//----------------------------------------------------------------------------
void vtkPlanarContourToClosedSurfaceConversionRule::CreateStraightEndCapContour(vtkPolyData* inputROIPoints, vtkLine* inputLine, vtkCellArray* outputLines, double lineSpacing)
{
if (!inputROIPoints)
{
vtkErrorMacro("CreateEndCapContour: invalid vtkPolyData");
return;
}

if (!inputLine)
{
vtkErrorMacro("CreateEndCapContour: invalid vtkLine");
return;
}

if (!outputLines)
{
vtkErrorMacro("CreateEndCapContour: invalid vtkCellArray");
}

vtkSmartPointer<vtkPoints> inputPoints = inputROIPoints->GetPoints();
vtkNew<vtkIdList> endCapLine;
for (int i = 0; i < inputLine->GetNumberOfPoints(); ++i)
{
double endCapPoint[3] = { 0.0, 0.0, 0.0 };
inputPoints->GetPoint(inputLine->GetPointId(i), endCapPoint);
endCapPoint[2] += lineSpacing / 2.0;
endCapLine->InsertNextId(inputPoints->InsertNextPoint(endCapPoint));
}
outputLines->InsertNextCell(endCapLine);
}

//----------------------------------------------------------------------------
void vtkPlanarContourToClosedSurfaceConversionRule::CreateSmoothEndCapContour(vtkPolyData* inputROIPoints, vtkLine* inputLine, vtkCellArray* outputLines, double lineSpacing)
{
if (!inputROIPoints)
{
vtkErrorMacro("CreateEndCapContour: invalid vtkPolyData");
return;
}

if (!inputLine)
{
vtkErrorMacro("CreateEndCapContour: invalid vtkLine");
return;
}

if (!outputLines)
{
vtkErrorMacro("CreateEndCapContour: invalid vtkCellArray");
}

vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
lines->Initialize();
lines->InsertNextCell(inputLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class VTK_SLICER_DICOMRTIMPORTEXPORT_CONVERSIONRULES_EXPORT vtkPlanarContourToCl

static const std::string GetDefaultSliceThicknessParameterName() { return "Default slice thickness"; };
static const std::string GetEndCappingParameterName() { return "End capping"; };
enum EndCappingModes
{
None = 0,
Smooth = 1,
Straight = 2
};

/// Constructs representation object from representation name for the supported representation classes
/// (typically source and target representation VTK classes, subclasses of vtkDataObject)
Expand Down Expand Up @@ -189,6 +195,22 @@ class VTK_SLICER_DICOMRTIMPORTEXPORT_CONVERSIONRULES_EXPORT vtkPlanarContourToCl
/// \param The size of the spacing between the contours. Contours created by this function will be offset by 1/2 of this amount
void CreateEndCapContour(vtkPolyData* inputROIPoints, vtkLine* inputLine, vtkCellArray* outputLines, double lineSpacing);

/// Create smoothly interpolated end cap contours on the exterior of the surface.
/// Called by CreateEndCapContour based on the "End capping" conversion parameter.
/// \param inputROIPoints Polydata containing all of the points and contours
/// \param inputLine The original line that needs to be extended
/// \param outputLines Cell array containing all of the lines that are created by the algorithm
/// \param The size of the spacing between the contours. Contours created by this function will be offset by 1/2 of this amount
void CreateSmoothEndCapContour(vtkPolyData* inputROIPoints, vtkLine* inputLine, vtkCellArray* outputLines, double lineSpacing);

/// Create straight extruded end cap contours on the exterior of the surface.
/// Called by CreateEndCapContour based on the "End capping" conversion parameter.
/// \param inputROIPoints Polydata containing all of the points and contours
/// \param inputLine The original line that needs to be extended
/// \param outputLines Cell array containing all of the lines that are created by the algorithm
/// \param The size of the spacing between the contours. Contours created by this function will be offset by 1/2 of this amount
void CreateStraightEndCapContour(vtkPolyData* inputROIPoints, vtkLine* inputLine, vtkCellArray* outputLines, double lineSpacing);

/// Triangulate the interior of a contour on the xy plane.
/// \param Contour that is being triangulated
/// \param Cell array that the polygons are added to
Expand Down

0 comments on commit 3d69277

Please sign in to comment.