1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
EdgeMiner
=========
.. module:: ezdxf.edgeminer
.. versionadded:: 1.4
Purpose of this Module
----------------------
This is a helper tool to:
- build polylines from DXF primitives like LINE, ARC, ELLIPSE, SPLINE
- build hatch boundary paths from DXF primitives
- find open chains or closed loops in an unordered heap of DXF primitives (edges)
- in general: find connections between edges
What are Edges?
---------------
An edge is a linear structure with an start- and end point and an optional length.
This module is not limited to DXF primitives. Anything that can be represented by an
start- and end point can be processed. This makes this module to a versatile tool with
the disadvantage that intersections between edges are not known and cannot be calculated.
e.g. When each arc is represented by an edge, the HATCH boundary path on the left can be
found because the arcs are connected by their end points. Finding the HATCH boundary
path on the right is not possible because the intersections points of the arcs (edges)
are not known:
.. image:: gfx/em-intersections.png
How to Create Edges?
--------------------
The process of creating edges is separated from this module and is done in the
companion module :mod:`ezdxf.edgesmith`. The :mod:`edgeminer` module doesn't really
know what an edge represents or what it looks like.
Terminology
-----------
I try to use the terminology of `Graph Theory`_ but there are differences where I think
a different term is better suited for this module like loop for cycle.
Edge
A linear connection between two points. The shape of an edge is not known.
Intersection points between edges are not known and cannot be calculated.
.. image:: gfx/em-edges.png
Vertex
A connection point of two or more edges.
Degree
The degree of a vertex is the number of connected edges.
.. image:: gfx/em-degree.png
Leaf
A leaf is a vertex of degree 1.
A leaf is a loose end of an edge, which is not connected to other edges.
Junction
A junction is a vertex of degree greater 2.
A junction has more than two adjacent edges.
A junction is an ambiguity when searching for open chains or closed loops.
Graph Theory: multiple adjacency
Chain
A chain has sequential connected edges.
The end point of an edge is connected to the start point of the following edge.
A chain has unique edges, each edge appears only once in the chain.
A chain can contain vertices of degree greater 2.
A solitary edge is also a chain.
Graph Theory: Trail - no edge is repeated, vertex is repeated
.. image:: gfx/em-chain.png
Simple Chain (special to this module)
A simple chain contains only vertices of degree 2, except the start- and end vertex.
The start- and end vertices are leafs (degree of 1) or junctions (degree greater 2).
The following image shows 3 simple chains: [1-2-3], [4-5-6] and [7-8-9].
Simple chains are easy to detect and can be replaced by a single edge and reduces so
the search space.
.. image:: gfx/em-simple-chains.png
Open Chain
An open chain is a chain which starts and ends with a leaf.
A solitary edge is also an open chain.
Graph Theory: Path - no edge is repeated, no vertex is repeated, endings not connected
Loop
A loop is a simple chain with connected start- and end vertices.
A loop has two or more edges.
A loop contains only vertices of degree 2.
Graph Theory: Cycle - no edge is repeated, no vertex is repeated, endings connected;
a loop in Graph Theory is something different!
Network
A network has two or more edges that are directly and indirectly connected.
The edges in a network have no order.
A network can contain vertices of degree greater 2 (junctions).
A solitary edge is not a network.
A chain with two or more edges is a network.
Graph Theory: multigraph; a network in Graph Theory is something different!
Gap Tolerance
Maximum vertex distance to consider two edges as connected
Forward Connection
An edge is forward connected when the end point of the edge is connected to the
start point of the following edge.
.. seealso::
- :ref:`tut_edges`
- :mod:`ezdxf.edgesmith` module
.. important::
This is the reference documentation and not a tutorial how to use this module.
High Level Functions
--------------------
.. autofunction:: find_sequential_chain
.. autofunction:: find_all_sequential_chains
.. autofunction:: find_simple_chain
.. autofunction:: find_all_simple_chains
.. autofunction:: find_all_open_chains
.. autofunction:: find_loop
.. autofunction:: find_loop_by_edge
.. autofunction:: find_all_loops
Low Level Functions
-------------------
.. autofunction:: filter_coincident_edges
.. autofunction:: flatten
.. autofunction:: is_chain
.. autofunction:: is_forward_connected
.. autofunction:: is_loop
.. autofunction:: is_wrapped_chain
.. autofunction:: isclose
.. autofunction:: length
.. autofunction:: longest_chain
.. autofunction:: make_edge
.. autofunction:: reverse_chain
.. autofunction:: shortest_chain
.. autofunction:: subtract_edges
.. autofunction:: unwrap_simple_chain
.. autofunction:: wrap_simple_chain
Classes
-------
.. autoclass:: Edge
.. automethod:: __eq__
.. automethod:: __hash__
.. automethod:: reversed
.. autoclass:: Deposit
.. autoproperty:: edges
.. autoproperty:: max_degree
.. automethod:: degree_counter
.. automethod:: degree
.. automethod:: degrees
.. automethod:: edges_linked_to
.. automethod:: find_all_networks
.. automethod:: find_leafs
.. automethod:: find_nearest_edge
.. automethod:: find_network
.. automethod:: unique_vertices
.. autoclass:: TimeoutError
Global Constants
----------------
.. code-block:: Python
GAP_TOL = 1e-9
ABS_TOL = 1e-9
TIMEOUT = 60.0 # in seconds
.. _Graph Theory: https://en.wikipedia.org/wiki/Glossary_of_graph_theory
.. _GeeksForGeeks: https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/?ref=shm
|