gen_polygons_xld (Intersection, Polygons, 'ramer', 2)
split_contours_xld (Polygons, ContoursSplit, 'polygon', 1, 5)
* Select the segments that have approximately the expected orientation
select_shape_xld (ContoursSplit, SelectedXLD, ['orientation_points','orientation_points'], 'or', rad([OrientationRef,OrientationRef - 180]) - rad(OrientationTolerance), rad([OrientationRef,OrientationRef - 180]) + rad(OrientationTolerance))
union_adjacent_contours_xld (SelectedXLD, UnionContours, 10, 1, 'attr_keep')
* Select the three longest segments
length_xld (UnionContours, Length)
*给边排序,第0号就是最长的
SelectedId := sort_index(-Length)[0:2] + 1
select_obj (UnionContours, ObjectSelected1, SelectedId[0])
select_obj (UnionContours, ObjectSelected2, SelectedId[1])
select_obj (UnionContours, ObjectSelected3, SelectedId[2])
上面代码中,第0号就是最长的边
或者直接用下面的代码也可以,下面的方法更简单
SelectedId := sort_index(-Length) + 1
select_obj (UnionContours, ObjectSelected1, SelectedId[0])
算法升级,筛选最短的和最长的
*最长最短长度及其索引初始化
Max_Length :=0
Max_Index :=0
Min_Length :=9999999
Min_Index:=0
*遍历每个轮廓长度
for i:=1 to Number2 by 1
select_obj (Polygons, SelectedPolygon, i)
get_polygon_xld (SelectedPolygon, Rowlg, Collg, Length, Phi)
*保留最长轮廓及绑住索引
if(Max_Length<Length)
Max_Length := Length
Max_Index := i
endif
*保留最短轮廓及其索引
if(Min_Length>Length)
Min_Length :=Length
Min_Index := i
endif
endfor
*从众多轮廓中选择出最长,最短轮廓
select_obj (Polygons,MaxLengthContour , Max_Index)
select_obj (Polygons,MinLengthContour , Min_Index)
dev_set_color('yellow')
dev_display(MaxLengthContour)
dev_set_color('red')
dev_display(MinLengthContour)