function [h, order] = order_pts(pts)
h = [];
if size(pts,2)~=3
    return;
end
h = [];
for i=1:max(pts(:,3))
    ind = find(pts(:,3)==i);
    rpts = pts(ind,1:2);
    if ~isempty(rpts)
        rpts = order_xy_pts(rpts);
        h = [h; [rpts ones(size(rpts,1),1)*i]];
    end
end
return;