VTK/Closed Surface Clipping: Difference between revisions

From KitwarePublic
< VTK
Jump to navigationJump to search
Line 62: Line 62:


=== Reducing the number of triangles produced ===
=== Reducing the number of triangles produced ===
This class uses the clipping/contouring methods in the vtkCell subclasses, which triangulate polys before clipping or contouring them.  This produces many more points and cells than are actually needed to describe the geometry.  Also, when multiple cut planes are used, these cells can be clipped multiple times, causing a proliferation of small, sharp triangles.
This class uses the clipping/contouring methods in the vtkCell subclasses, which triangulate polys while clipping or contouring them.  This produces many more points and cells than are actually needed to describe the geometry.  Also, when multiple cut planes are used, these cells can be clipped multiple times, causing a proliferation of small, sharp triangles.


The solution to this would be to write new clipping/contouring code specific to this class, that will not triangulate polys before clipping/contouring them.  As a corollary to this, the final step in creating new polygons can be to just create convex polygons, instead of creating triangles.  People who require triangles could follow-up with vtkTriangleFilter, or the triangulation could just be deferred until the very end.
The solution to this would be to write new clipping/contouring code specific to this class, that will not triangulate polys while clipping/contouring them.  As a corollary to this, the final step in creating new polygons can be to just create convex polygons, instead of creating triangles.  People who require triangles could follow-up with vtkTriangleFilter, or the triangulation could just be deferred until the very end.


=== Handling non-closed inputs ===
=== Handling non-closed inputs ===

Revision as of 16:15, 31 March 2010

ClipClosedSurface regression test.

The main goal of this project is to make it possible to clip a surface, and then create a "cap" polygon (or polygons) that fill in the area that is enclosed by all the new edges that were created by the clipping. In other words, the goal is to close the surface after the clipping has been performed. For this purpose, a new filter called vtkClipClosedSurface has been created.

This class was contributed to VTK by David Gobbi on March 30, 2010.

Features

The vtkClipClosedSurface filter has the following features:

  • A vtkPlaneCollection is used to set the clip region (arbitrary implicit functions are not allowed).
  • If given a closed surface as input, it will produce a closed surface as output.
  • If given an open surface as input, it will create a closed surface if supplied with a clipping plane that clips away all open edges.
  • The input surface can be concave, and can even be composed of multiple closed surfaces, as long as there is no intersection between the surfaces. If the surfaces share an edge or a face, then the surfaces will be considered to be intersecting.

Caveats

The newly-created clip surfaces have the following limitations:

  • If the contours at the clip plane are not closed, or if they don't have simple topology, then an incorrect surface will be generated.
  • The triangles that are generated are often very narrow. The code does not attempt to generate high-quality triangles.
  • This filter ignores vtkVertex cells, and the output will contain no verts.
  • Similarly, input lines will be discarded unless the GenerateOutline option is on.

Options

ClippedVolumeOutline
  • GenerateFaces - On by default. If turned off, the output will have no polygons, which useful if only the outlines are desired.
  • GenerateOutline - Off by default. If turned on, contours will be generated where the planes intersect the surface.
  • GenerateColorScalars - Off by default. Generate color scalars for the output, see below for more.

The GenerateColorScalars option creates color cell scalars so that the cut surfaces are displayed with a different color than the rest of the surface. Cell scalars are used instead of point scalars because the use of point scalars would require point duplication where the cut surfaces meet the rest of the surface. The lines cannot be colored differently from polys. If you need the lines to be a different color, then you could use two instances of vtkClipClosedSurface: one to generates faces, and another to generates outlines.

If GenerateColorScalars is on, then three colors can be set:

  • ClipColor for the clip surfaces
  • BaseColor for the rest of the surface
  • ActivePlaneColor to color one clip surface in a different color

The purpose of ActivePlaneColor is to color one cut plane differently, e.g. the plane that the user is interacting with. The ActivePlaneId can be set to specify which of the cut planes is the active plane.

The BaseColor will be ignored if the input already has 3-component color cell scalars. If this is the case, the original scalars will be used instead of BaseColor. This is useful if you want to chain two vtkClipClosedSurface filters together, or if you want to use vtkClipClosedSurface on the output of vtkOutlineSource or vtkVolumeOutlineSource.

Note that many VTK filters that create new cells (e.g. vtkStripper) will erase the cell scalars. So if you use GenerateCellScalars, you should avoid using vtkStripper to post-process the data.

Algorithm

ClipClosedSurface wireframe.

This filter uses many of the functions that are built into vtkCell and its subclasses, but it also has several internal functions for polygon manipulation. The tolerance for merging points etc. is set at d*1e-5 where "d" is the maximum dimension of the input bounds. An overall description of what is done for each of the clipping planes is as follows:

  1. Clip scalars are generated for all points.
  2. The data is clipped and contoured, using the clip scalars.
  3. The contours are used to generate the cut faces.
  4. The process is repeated for the next cut plane

Generation of the cut faces from the cut contours is a multi-step process:

  1. The contour lines are joined end-to-end to form polygons.
  2. If the polygons self-intersect, they are split at the intersection points.
  3. Any polygon points that aren't at a corner of the polygon are removed.
  4. The sense of the polygons is set according to the cut plane normal.
  5. If any polygons are within other polygons, cuts are made between the outer and inner polygons.
  6. The ear-cut triangulation method of vtkPolygon is used to triangulate the polygons.
  7. Some of the new triangles are subdivided in order to add back the points that were removed in step 3.

Future Work

Reducing the number of triangles produced

This class uses the clipping/contouring methods in the vtkCell subclasses, which triangulate polys while clipping or contouring them. This produces many more points and cells than are actually needed to describe the geometry. Also, when multiple cut planes are used, these cells can be clipped multiple times, causing a proliferation of small, sharp triangles.

The solution to this would be to write new clipping/contouring code specific to this class, that will not triangulate polys while clipping/contouring them. As a corollary to this, the final step in creating new polygons can be to just create convex polygons, instead of creating triangles. People who require triangles could follow-up with vtkTriangleFilter, or the triangulation could just be deferred until the very end.

Handling non-closed inputs

The algorithm for creating new polygons assumes that all contours are closed. Currently, when a non-closed contour is found, it's two ends are connected in order to close it. This produces some odd results when the filter is given non-closed inputs. There are three possible solutions:

  1. Generate an error when non-closed contours are found, but otherwise continue with the current behaviour.
  2. Throw out these non-closed contours. Probably not a good idea.
  3. Add heuristics for optimally joining non-closed contours.