Proposals:New Mesh Class: Difference between revisions
Agouaillard (talk | contribs) |
Agouaillard (talk | contribs) |
||
Line 77: | Line 77: | ||
! ITK/Code/Review Names !! Coverage !! # of Lines not covered !! Analyze - Comments | ! ITK/Code/Review Names !! Coverage !! # of Lines not covered !! Analyze - Comments | ||
|- | |- | ||
| itkGeometricalQuadEdge.h || | | itkGeometricalQuadEdge.h || 72.22% || 10 || iterators, SetRight( ). | ||
|- | |- | ||
| itkGeometricalQuadEdge.txx || | | itkGeometricalQuadEdge.txx || 82.11% || 22 || Degenerated cases (Disconnect). | ||
|- | |- | ||
| itkQuadEdge.h | | ''itkQuadEdge.h'' || 100.0% || 00 || | ||
|- | |- | ||
| itkQuadEdge.cxx || | | itkQuadEdge.cxx || 85.94% || 36 || Degenerated Cases not tested. | ||
|- | |- | ||
| itkQuadEdgeMesh.h || 75.00% || 03 || Requestedregion...( ), CopyInformation( ). | | itkQuadEdgeMesh.h || 75.00% || 03 || Requestedregion...( ), CopyInformation( ). | ||
|- | |- | ||
| itkQuadEdgeMesh.txx || | | itkQuadEdgeMesh.txx || 84.78% || 63*|| GetEdge( cellId ), SetCell with a native itkCell. | ||
|- | |- | ||
| itkQuadEdgeMeshBaseIterator.h || 65. | | itkQuadEdgeMeshBaseIterator.h || 65.67% || 23 || Iterators not used. | ||
|- | |- | ||
| itkQuadEdgeMeshBoundaryEdgesMeshFunction.h || | | itkQuadEdgeMeshBoundaryEdgesMeshFunction.h || 66.67% || 01 || ----- | ||
|- | |- | ||
| itkQuadEdgeMeshBoundaryEdgesMeshFunction.txx|| 88.46% || 03 || ----- | | itkQuadEdgeMeshBoundaryEdgesMeshFunction.txx|| 88.46% || 03 || ----- | ||
|- | |- | ||
| itkQuadEdgeMeshFrontIterator.h || | | itkQuadEdgeMeshFrontIterator.h || 87.50% || 02 || Const flavor of Constructor, Destructor. | ||
|- | |- | ||
| itkQuadEdgeMeshFrontIterator.txx || | | itkQuadEdgeMeshFrontIterator.txx || 79.07% || 09 || Bad init fall cases, FindDefaultSeed( ). | ||
|- | |- | ||
| itkQuadEdgeMeshLineCell.h || 72.73% || 03 || const versions of Get/Set Id API. | | itkQuadEdgeMeshLineCell.h || 72.73% || 03 || const versions of Get/Set Id API. | ||
Line 111: | Line 111: | ||
| itkQuadEdgeMeshPolygonCell.h || 83.33% || 03*|| MakeCopy( ) | | itkQuadEdgeMeshPolygonCell.h || 83.33% || 03*|| MakeCopy( ) | ||
|- | |- | ||
| itkQuadEdgeMeshPolygonCell.txx || | | itkQuadEdgeMeshPolygonCell.txx || 77.06% || 25*|| Accept( ), BoundaryFeat., PointsIds, | ||
|- | |- | ||
| ''itkQuadEdgeMeshTopologyChecker.h'' || 100.0% || 00 || | | ''itkQuadEdgeMeshTopologyChecker.h'' || 100.0% || 00 || | ||
|- | |- | ||
| | | itkQuadEdgeMeshTopologyChecker.txx || 86.84% || 05 || | ||
|- | |- | ||
| ''itkQuadEdgeMeshToQuadEdgeMeshFilter.h'' || ------ || -- || Not Covered - Not Used - '''OK''' tested in creatis | | ''itkQuadEdgeMeshToQuadEdgeMeshFilter.h'' || ------ || -- || Not Covered - Not Used - '''OK''' tested in creatis |
Revision as of 22:03, 3 August 2007
This document derives the motivation and implementation of a new Mesh Class and associated Filters and IO classes for ITK
Overview
itkQuadEdgeMesh (itkQEMesh) is a new data structure for surface meshes. It is more efficient than the current itkMesh for surface processing. However it cannot handle N-dimensional meshes. Hence itkMesh and itkQEMesh will coexist in future releases of ITK. This documents describes how itkQuadEdgeMesh will be integrated into ITK 3.2.
CORE: First Implementation Subtleties
1: function vs filters
Some operations on the QuadEdgeMesh are implemented in Function classes
QuadEdgeMeshFunctionBase is the base class for function objects specialised in Mesh "small" (reduced in range) modification. Subclasses of itk::QuadEdgeFunctionBase cannot modify their InputType since the signature of their Evaluate( const InputType& ) method guarantees it. Consider a method that modifies (the geometry, the connectivity or both) a mesh. For large modifications of this mesh we follow the classical itk Filter schema (*), which implies duplicating the mesh which can be space consuming. But for small modifications (think of the Euler operators) that an algorithm needs to apply many times, this systematic duplication can be daunting. QuadEdgeMeshFunctionBase thus offers a leightweight alternative to itk Filter. Subclasses of QuadEdgeMeshFunctionBase, which should override Evaluate(), are function objects that apply reduced and localised modifications (geometry, or connectivity) on the InputType mesh.
The main example is Euler Operators.
(*)It's up to filter's devellopers to use those functions inside the filter and enforce const-correctness.
2: QuadEdgeMeshCells
an itkQuadEdgeMesh uses two types f cells: a QELineCell and a QEPolygonCell.
Building QE layer
Both cell types have a constructor that creates the good underlying QE structure. In fact the LineCell always creates it, and is the core cell as far as QE layer is concerned. The polygon cell has several constructors, one of which constructs the underlying QE layer. The destructor check how the cell was created and clean the QE layer if needed. It is needed when one creates a single polygon cell and want to iterate over the PointIds. The creation of the QE layer of a mesh is done elsewhere.
The cells are not, by definition, aware of the Mesh. It's thus the mesh that is in charge of creating the overall structure. It is done through the SetCell method. Each cell must be passed over to the mesh, and thus, with a QEMesh, only the dynamic way of creating cells is allowed/possible.
The SetCell method actually build the cell and its boundaries. In the case of the Polygon, it mean that the edges of the polygon are also created (as Line Cells) and added to the QEMesh. In this case, the Line Cells create the QE layer, and a polygonal face is "put" on top of it and linked with it (see the PolygonCell constructor that takes a QEType * as argument).
You can see SetCell as the conductor and AddEdge() and AddFace() as the main musicians. SetCell is going to check if containers are set, if points are valids, if edges already exist (or it creates them using AddEdge() ), if there is still space to add a face and then creates the face (using AddFace() ), wrap it in an autopointer and put it in the cell container.
SetCell( ) accept any type of itkCell / itkQEMeshCell in input. Cells whose dimension is superior to 2 are simply dropped (QEMesh is dedicated to surface meshes). Other cells are imported. Actually, only the points of the cell are used, and a new face is created. It's different from the behavior of an itkMesh where the cells are passed over and directly stored in the container. To be backward compatible, and to avoid memory leaks caused by reusing the autopointer when passing over several cells in a row, itkQuadEdgeMesh::SetCell( ) actually releases the memory of the cell after it created its own copy of it. One should be carefull then: after a SetCell( ) the pointer to the cell is valid with an itkMesh and invalid with an itkQuadEdgeMesh.
Cell API
Most of the Cell API (see itkCellInterface.h) has been implemented
Note that for the QECells, the underlying GeometricalQuadEdge is the pointIdContainer. Each QEGeom contains one PointId (it's origin), and all the QEGeom of a given face are linked. An iterator (given by GetGeomLnext( )) allows you to go around. In native QuadEdgeMesh code, this is used in place of the usual unsigned long* as definition of the PointIdsIterator.
Unfortunatly, this is not backward compatible with the usual Cell API. If you try to create a cell using the celltraits defined in the itkQuadEdgeMeshTraits, this would fail as the PointIdsIterator would be defined as an iterator on QuadEdges, whereas usual itk Cells do not have a QuadEdge Layer. This case happen everytime you want to use an existing filter that produce a Mesh (let's say, itkVTKPolyDataReader) and use an itkQuadEdgeMesh as OutputType.
We then splitted the PointIds API into 2 versions: the usual version, which basically returns null pointers, or pointers to something empty (check with the itkQuadEdgeMeshCellInterfaceTest.cxx code), and the QuadEdgeIterator based one, which is prefixed by "Internal" and used an additional type defined in the default QuadEdgeMesh traits as PointIdsInternal Iterator. The first one is used by default and enforce total backward compatibility with existing filters. The later is used within itkQuadEdgeMesh, and should be used by default by any code using only QuadEdgeMesh.
To be fully compliant with the cell API, as far as Points Id iterator are concerned, would mean implementing a local (in the cell) point container, and thus duplicate the information. It would also require building an Edge container in the polygoncell. That can be done, but would duplicate information and take more memory. We supposed that nobody would try to use a QuadEdgeCell without a QuadEdgeMesh, and made the minimum implementation for the API to be complete. If there was a need for a complete API, we could easily implement the complete solution.
Right now, the polygon cell Boundary features, type and dimension API are implemented but could be made better. Specifically, the GetType could return different values depending on the number of point, as in a QuadEdgeMesh, all cells but edges are polygons. For the time being, it returns POLYGON_CELL. Get Boundary features returns the number of points, and the number of edges deduced from ... the number of points :). The other Boundary feature interface is not yet implemented.
CORE: Review code monitoring
1: Code Coverage and Memory Leaks
Reports : http://www.itk.org/Testing/Dashboard/MostRecentResults-Nightly/Dashboard.html
ITK/Code/Review Names | Coverage | # of Lines not covered | Analyze - Comments |
---|---|---|---|
itkGeometricalQuadEdge.h | 72.22% | 10 | iterators, SetRight( ). |
itkGeometricalQuadEdge.txx | 82.11% | 22 | Degenerated cases (Disconnect). |
itkQuadEdge.h | 100.0% | 00 | |
itkQuadEdge.cxx | 85.94% | 36 | Degenerated Cases not tested. |
itkQuadEdgeMesh.h | 75.00% | 03 | Requestedregion...( ), CopyInformation( ). |
itkQuadEdgeMesh.txx | 84.78% | 63* | GetEdge( cellId ), SetCell with a native itkCell. |
itkQuadEdgeMeshBaseIterator.h | 65.67% | 23 | Iterators not used. |
itkQuadEdgeMeshBoundaryEdgesMeshFunction.h | 66.67% | 01 | ----- |
itkQuadEdgeMeshBoundaryEdgesMeshFunction.txx | 88.46% | 03 | ----- |
itkQuadEdgeMeshFrontIterator.h | 87.50% | 02 | Const flavor of Constructor, Destructor. |
itkQuadEdgeMeshFrontIterator.txx | 79.07% | 09 | Bad init fall cases, FindDefaultSeed( ). |
itkQuadEdgeMeshLineCell.h | 72.73% | 03 | const versions of Get/Set Id API. |
itkQuadEdgeMeshLineCell.txx | 67.82% | 28* | Accept( ), "Internal" versions of PointIds( 8 fct. ) |
itkQuadEdgeMeshMacro.h | ------ | -- | Not Covered - Macros |
itkQuadEdgeMeshPoint.h | 100.0% | 00 | ----- |
itkQuadEdgeMeshPoint.txx | 100.0% | 00 | ----- |
itkQuadEdgeMeshPolygonCell.h | 83.33% | 03* | MakeCopy( ) |
itkQuadEdgeMeshPolygonCell.txx | 77.06% | 25* | Accept( ), BoundaryFeat., PointsIds, |
itkQuadEdgeMeshTopologyChecker.h | 100.0% | 00 | |
itkQuadEdgeMeshTopologyChecker.txx | 86.84% | 05 | |
itkQuadEdgeMeshToQuadEdgeMeshFilter.h | ------ | -- | Not Covered - Not Used - OK tested in creatis |
itkQuadEdgeMeshToQuadEdgeMeshFilter.txx | ------ | -- | Not Covered - Not Used - OK tested in creatis |
itkQuadEdgeMeshTraits.h | ------ | -- | Not Covered - Implicit + only types |
Euler Operators
1: Introduction and implementation choices
The advantage of the QE datastructure is to have only two operators to modify itself. Unfortunatly, the splice operator is not very intuitive (to say the less). Moreover a lot of topology/connectivity/geometry processing filters in the publications are based on the so-called euler operators (operators that do not modify the Euler number of the mesh). Smooth is one example of a geometry filter that does NOT require those operators as it does not modify the connectivity of the mesh, but subdivision, remeshing, simplifying (decimate => with a metric, reversible = Progressive Mesh, ...) and many other filters can be moe easily written above Euler Ops.
We mimic'ed the API on C-GAL's even though the underlying code is completly different:
http://www.cgal.org/Manual/3.3/doc_html/cgal_manual/Polyhedron/Chapter_main.html
Only combinatorial operateors are coded. Genus modifying method or hole/facet handling are not.
as for the implementation, we choosed factorization over performance: when an euler operator can be written using other(s), we did it this way, even if we knew it would lead to suboptimal performances (like creating a face to remove it just after). We prefered to keep the code easy to maintain. Good example of this is the SplitEdge function that uses the SPlitVertex function, or the JoinVertex function that uses the (non-trivial) ZipMesh function.
2: list of files
ITK/Code/Review Names | Coverage | # of Lines not covered | Analyze - Comments |
---|---|---|---|
*./itkQuadEdgeMeshEulerOperatorCreateCenterVertexFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorCreateCenterVertexFunction.txx | |||
*./itkQuadEdgeMeshEulerOperatorDeleteCenterVertexFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorDeleteCenterVertexFunction.txx | |||
*./itkQuadEdgeMeshEulerOperatorFlipEdgeFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorFlipEdgeFunction.txx | |||
*./itkQuadEdgeMeshEulerOperatorJoinFacetFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorJoinFacetFunction.txx | |||
*./itkQuadEdgeMeshEulerOperatorJoinVertexFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorJoinVertexFunction.txx | |||
*./itkQuadEdgeMeshEulerOperatorSplitEdgeFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorSplitFacetFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorSplitFacetFunction.txx | |||
*./itkQuadEdgeMeshEulerOperatorSplitVertexFunction.h | |||
*./itkQuadEdgeMeshEulerOperatorSplitVertexFunction.txx | |||
*./itkQuadEdgeMeshZipMeshFunction.txx | |||
*./itkQuadEdgeMeshFunctionBase.h | |||
*./itkQuadEdgeMeshEulerOperatorsTest.cxx |
3: Synchronize ITK/Code/Review with Original rep
KWStyle
- Matrix
Coverage
Subtest | Percentage | Lines covered | Lines not covered | Files covered | Files not covered | Coverage metric |
---|---|---|---|---|---|---|
. | 78.68 | 1709 | 463 | 56 | 0 | 0.79 |
Examples | 66.67 | 22 | 11 | 1 | 0 | 0.74 |
Testing | 76.80 | 1112 | 336 | 17 | 0 | 0.77 |
Code | 83.21 | 575 | 116 | 38 | 0 | 0.83 |
Mem. Leaks
Names | Whatever | Memory Leak | Potential Memory Leak | Uninitialized Memory Read |
---|---|---|---|---|
EulerOperatorsTest | Report | 0 | 2 | 0 |
vtkUnstructuredGridImportTest | Report | 0 | 1 | 0 |
Backward Compatibility and Benchmarks
IN PROGRESS
One should be able to use an itkQuadEdgeMesh anywhere an itkMesh was used for a surface mesh. We wanted the transition to be as easy as just modifying the MeshType. It had two goals: not rewriting existing code (even if it could/should be rewritten to beneficiate of the full power of QuadEdgeMesh) and (we hopped) fasten the filters as buildlinks where not required anymore.
It required the implementation of the (almost) complete Mesh and cell API and thus had an impact on the memory footprint and on the speed. Some features could not and should not be implemented though, like the buildlinks() method (which now does nothing) and the CellLinks / PointCellLinks feature that has no longer reason to exist. Thi slast part is not fully implemented right now (august 3rd, 2007).
To test the implementation, and also to benchmark the eventual gains in speed, the best way is to try every itkMeshSourceFilter that is expected a mesh of dimension equal or inferior to 2 (surface). To help this in progress work, we are going to list here all the filters that are involved and notify everyone when they are included in the test suite / benchmark and successfully using QuadEdgeMesh.
Backward compatibility
itkMeshSource | -> itkAutomaticTopologyMeshSource | |||
-> itkImageToMeshFilter | -> itkBinaryMask3DMeshSource | |||
-> itkBinaryMaskToNarrowBandPointSetFilter | ||||
-> itkImageToParametricSpaceFilter | ||||
-> itkMeshToMeshFilter | -> itkBalloonForceFilter | |||
-> itkConnectedRegionsMeshFilter | ||||
-> itkDeformableMesh3DFilter | ||||
-> itkDeformableSimplexMesh3DFilter | ||||
-> itkInteriorExteriorMeshFilter | ||||
-> itkParametricSpaceToImageSpaceMeshFilter | ||||
-> itkQuadEdgeMeshToQuadEdgeMeshFilter | OK | |||
-> itkSimplexMeshAdaptTopologyFilter | ||||
-> itkSimplexMeshToTriangleMeshFilter | ||||
-> itkTransformMeshFilter | ||||
-> itkTriangleMeshToSimplexMeshFilter | ||||
-> itkWarpMeshFilter | ||||
-> itkRegularSphereMeshSource | ||||
-> itkSphereMeshSource | ||||
-> itkVTKPolyDataReader |