<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="initial_rectangles">
<interface>
<io>
<par name="Region" base_type="iconic" dimension="0"/>
</io>
<oo>
<par name="Rectangles" base_type="iconic" dimension="0"/>
</oo>
<ic>
<par name="rectangle_type" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="overlaps" base_type="ctrl" dimension="0"/>
<par name="initial_box_coordinates" base_type="ctrl" dimension="0"/>
</oc>
</interface>
<body>
<c> * Copyright (c) MVTec Software GmbH.  All rights reserved.</c>
<c> *</c>
<c> * All use of this software is subject to the terms of the revised BSD</c>
<c> * license.  You should have received a copy of this license along</c>
<c> * with this source code in a file named "license.txt."</c>
<c> </c>
<c> * Border treatment: do not clip regions!</c>
<l>get_system ('clip_region',ClipRegion)</l>
<l>set_system ('clip_region','false')</l>
<c></c>
<l>gen_empty_obj (Rectangles)</l>
<l>overlaps := []</l>
<l>initial_box_coordinates := []</l>
<c>*</c>
<c>* b = [row, column, height, width, phi]</c>
<c>*</c>
<l>for Index := 0 to |rectangle_type|-1 by 1</l>
<l>    if (rectangle_type[Index] == 'rectangle1')</l>
<c>        ***********************</c>
<c>        * Bounding Rectangle1</c>
<c>        ***********************</c>
<l>        smallest_rectangle1 (Region, Row1, Column1, Row2, Column2)</l>
<l>        gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)</l>
<l>        bb_overlap (Region, Rectangle, overlap)</l>
<l>        convert_rectangle1_params_to_box_coordinates (Row1, Column1, Row2, Column2, \
                                                      box_coordinates)</l>
<c>        </c>
<l>    elseif (rectangle_type[Index] == 'rectangle2')</l>
<c>        ***********************</c>
<c>        * Bounding Rectangle2</c>
<c>        ***********************</c>
<l>        smallest_rectangle2 (Region, Row, Column, Phi, Length1, Length2)</l>
<l>        gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)</l>
<l>        bb_overlap (Region, Rectangle, overlap)</l>
<l>        convert_rectangle2_params_to_box_coordinates (Row, Column, Phi, \
                                                      Length1, Length2, \
                                                      box_coordinates)</l>
<l>    elseif (rectangle_type[Index] == 'rectangularity')</l>
<c>        ***********************</c>
<c>        * Rectangularity</c>
<c>        ***********************</c>
<l>        area_center (Region, _, Row, Column)</l>
<l>        elliptic_axis (Region, Ra, Rb, Phi)</l>
<l>        RectA := max2(0.866 * Ra - 0.5,0)</l>
<l>        RectB := max2(0.866 * Rb - 0.5,0)</l>
<l>        RectPhi := Phi</l>
<l>        gen_rectangle2 (Rectangle, Row, Column, RectPhi, RectA, RectB)</l>
<l>        bb_overlap (Region, Rectangle, overlap)</l>
<l>        convert_rectangle2_params_to_box_coordinates (Row, Column, RectPhi, \
                                                      RectA, RectB, \
                                                      box_coordinates)</l>
<l>    elseif (rectangle_type[Index] == 'inner_circle')</l>
<c>        * As a true inner bound we use the inner square of the inner circle</c>
<l>        inner_circle (Region, Row, Column, Radius)</l>
<l>        box_coordinates := [Row, Column, sqrt(2.0)*Radius, sqrt(2.0)*Radius, 0.0]</l>
<l>        gen_rectangle_b (Rectangle, box_coordinates)</l>
<l>        bb_overlap (Region, Rectangle, overlap)</l>
<l>    elseif (rectangle_type[Index] == 'inner_rectangle1')</l>
<c>        ****************************</c>
<c>        * Largest inner Rectangle1</c>
<c>        ****************************</c>
<l>        inner_rectangle1 (Region, Row1, Column1, Row2, Column2)</l>
<l>        gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)</l>
<l>        bb_overlap (Region, Rectangle, overlap)</l>
<l>        convert_rectangle1_params_to_box_coordinates (Row1, Column1, Row2, Column2, \
                                                      box_coordinates)</l>
<l>    else</l>
<c>        * ..........</c>
<c>        * We can add different initial regions here</c>
<c>        * ..........</c>
<c></c>
<l>        throw (['invalid rectangle type'])</l>
<l>    endif</l>
<l>    concat_obj (Rectangles, Rectangle, Rectangles)</l>
<l>    overlaps := [overlaps, overlap]</l>
<l>    initial_box_coordinates := [initial_box_coordinates,box_coordinates]</l>
<l>endfor</l>
<c></c>
<l>set_system ('clip_region',ClipRegion)</l>
<c></c>
<l>return ()</l>
</body>
<docu id="initial_rectangles">
<parameters>
<parameter id="Rectangles"/>
<parameter id="Region"/>
<parameter id="initial_box_coordinates"/>
<parameter id="overlaps"/>
<parameter id="rectangle_type"/>
</parameters>
</docu>
</procedure>
</hdevelop>
