Iterator Class¶
This is the Class for the iterator which is the main part of the module. It initializes every important variable and array. After or while that process the flow can be processed and animated. As a remark only the so far saved curve flow can be animated but the animation can be restarted a any point. The figure and axis are always returned and need to be saved in a local variable for the plot to show up. Otherwise they are destroyed and can not be displayed by the matplotlib. Also only the backends qt5agg and qt4agg has been tested so far.
Todo
Write the animation in a way that the user can provide an update method. By this it is more easy to personalize to animation.
-
class
curve_shortening_flow.iterator.iterator(vertices)[source]¶ Class for the iterator
The iterator initializes all necessary variables and sets the initial vertices. After the initialization a step or multiple steps can be performed. It will only iterate until there are only 5 or less vertices left. After or while doing single steps, an animation can be loaded and played.
Flags are
- remesh: Remeshing the curve, default is True.
- remove: Removing vertices that are to close, default is False.
- save: Save the vertices and some helpful variables at every step, default is True.
- move_cm: Move the CM back to starting position, default is True.
- cubic: Set the spline interpolation to cubic on or off. Off means linear. Default is True.
- rescale_length: Rescale the length of the curve ons it reaches the minimal length, default is True.
Some parameters are
- method: Set the time stepping Method, default is “euler_forward”.
- tolerance: The tolerance for the check whether the curvature is still changing. Default is 1e-10.
- min_length: Set the minimal length for the curve (if rescale_length is True). Default is 1/4 of the bounding box.
The initial set of vertices is once remeshed into equal distribution for smoothness.
Parameters: vertices: numpy array
Numpy array of initial vertices to use. Shape needs to be (n,2).
-
animate(FPS=50, name='', with_markers=False, direct_plot=False)[source]¶ Animation of the vertices
If an animation is performed this method initializes a figure and an animator of the matplotlib library. The initial vertices are painted in blue as well as the CM. The last vertices are painted in green. The momentary vertices are painted in red and the CM in black. It returns the figure and axes objects in order to be displayed.
Parameters: FPS: int, optional
Number of Frames per second for the animation, default is 50.
name: str, optional
Name of the file without prefix. It will be saved as a MP4 file. If “” then no file is saved.
with_markers: bool, optional
If True + markers are placed at the position of a vertex. Default is False
direct_plot: bool, optional
If True the plot is started right away without returning figure and axes objects. Default is False
Returns: f: figure-object
ax: axes-object
line_anim: animation-object
-
classmethod
example(name='spiral')[source]¶ Initialization of the iterator with a example.
Parameters: name: str, optional
Name if the example file. Options are spiral (default), bohne, some_form and ellipse
Returns: iterator:
Instance of iterator class with example vertices.
-
step()[source]¶ Stepping function for a single step.
This method only does one step and only if the number of vertices is larger than 5. If wished it also saves the step into a dictionary and lists for length and CM. It is possible to turn off the remeshing, which is default. Also the removing of points can be turned of. The time step method is a euler forward for now.
-
steps(stps=inf)[source]¶ Stepping function for multiple steps.
If the vertices are supposed to be iterated over more steps, this function will run until the maximum number of step specified are reached or until the number of vertices is lower or equal to 5.
Parameters: stps: int, optional
Number of steps to perform, default is inf, which means iteration until number of vertices is lower or equal 5