mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-03 13:11:25 +08:00
Installed a few hooks to allow more flexibility in subclasses, refactored traceback() to allow obtaining tracebacks fast during front evolution, and moved some initializations to reset(). Full list: * integer division in calculating indices * traceback_offsets use -2 for uninitialized, -1 for seed point. In that we we can distinguish between these two cases in traceback() * Clearing of traceback_offset, cumulative_costs, pushing start positions into the heap, are now all done in reset() * Reset is called every time that find_cost is called. * Add hook _goal_reached() * Add hook _examine_neighbor() * Add hook _update_node() * Replace while loop with a for-loop to prevent infinite looping in case of a bug. * Split traceback() in two functions to allow getting a flat traceback fast. traceback() calles these two private functions and behaves as just before.
46 lines
1.5 KiB
Cython
46 lines
1.5 KiB
Cython
""" This is the definition file for mcp.pyx.
|
|
It contains the definitions of the mcp class, such that
|
|
other cython modules can "cimport mcp" and subclass it.
|
|
"""
|
|
|
|
cimport heap
|
|
cimport numpy as cnp
|
|
|
|
ctypedef heap.BOOL_T BOOL_T
|
|
ctypedef unsigned char DIM_T
|
|
ctypedef cnp.float64_t FLOAT_T
|
|
ctypedef cnp.intp_t INDEX_T
|
|
ctypedef cnp.int8_t EDGE_T
|
|
ctypedef cnp.int8_t OFFSET_T
|
|
ctypedef cnp.int16_t OFFSETS_INDEX_T
|
|
|
|
|
|
cdef class MCP:
|
|
cdef heap.FastUpdateBinaryHeap costs_heap
|
|
cdef object costs_shape
|
|
cdef DIM_T dim
|
|
cdef BOOL_T dirty
|
|
cdef BOOL_T use_start_cost
|
|
# if use_start_cost is true, the cost of the starting element is added to
|
|
# the cost of the path. Set to true by default in the base class...
|
|
|
|
# Arrays used during front propagation
|
|
cdef FLOAT_T [:] flat_costs
|
|
cdef FLOAT_T [:] flat_cumulative_costs
|
|
cdef OFFSETS_INDEX_T [:] traceback_offsets
|
|
cdef EDGE_T [:,:] flat_pos_edge_map
|
|
cdef EDGE_T [:,:] flat_neg_edge_map
|
|
cdef OFFSET_T [:,:] offsets
|
|
cdef INDEX_T [:] flat_offsets
|
|
cdef FLOAT_T [:] offset_lengths
|
|
|
|
# Methods
|
|
cpdef int goal_reached(self, INDEX_T index, FLOAT_T cumcost)
|
|
cdef FLOAT_T _travel_cost(self, FLOAT_T old_cost, FLOAT_T new_cost, FLOAT_T offset_length)
|
|
cdef void _examine_neighbor(self, INDEX_T index, INDEX_T new_index, FLOAT_T offset_length)
|
|
cdef void _update_node(self, INDEX_T index, INDEX_T new_index, FLOAT_T offset_length)
|
|
|
|
cdef object _flat_traceback(self, INDEX_T end)
|
|
cdef object _unravel_traceback(self, object flat_traceback)
|
|
|