Syntax
[corr,cio,ccw]=CPLisccwinout(CPL)
Input Parameter
CPL : | | Contour polygon list |
Output Parameter
corr : | | true if correct |
cio : | | level of contour (0=most outwards) |
ccw : | | ccw direction |
Examples
FCPL=replaceNaN(CPLsample(12),3,flipud(separateNaN(CPLsample(12),3)));
CPLisccwinout(FCPL)
CPLisccwinout(CPLsample(13))
Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, CPLisccwinout
, determines the orientation of contours in a contour polygon list (CPL) and checks if they are correctly oriented with respect to their level of nesting.
Input Parameters
- CPL: Contour polygon list, which is a data structure containing the coordinates of the contours.
- varargin: Optional parameter to change behavior, default is
false
.
Output Results
- corr: Boolean array indicating if each contour is correctly oriented.
- cio: Array indicating the level of each contour (0 = most outwards).
- ccw: Boolean array indicating if each contour is counter-clockwise (ccw).
Algorithm Steps
- Initialize
chng
to false
. If an additional argument is provided and is not empty, set chng
to that argument.
- Call
CPLsortinout
to determine the nesting level of each contour, storing the result in cio
.
- Call
CPLisccw
to determine the orientation of each contour, storing the result in ccw
.
- Calculate
corr
using the XOR operation between the oddness of cio
and ccw
. This checks if the contour orientation matches the expected orientation based on its nesting level.
- If no output arguments are specified, plot the contours using different colors to indicate their orientation and correctness:
- Green for counter-clockwise (ccw) contours.
- Blue for clockwise (cw) contours.
- Red dashed lines for incorrectly oriented contours.
Example Usage
Example code snippets demonstrate how to use the function with sample data:
FCPL = replaceNaN(CPLsample(12), 3, flipud(separateNaN(CPLsample(12), 3)));
CPLisccwinout(FCPL);
CPLisccwinout(CPLsample(13));
Algorithm explaination created using ChatGPT on 2025-08-19 08:22. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21