diff options
Diffstat (limited to 'calibration.e')
-rw-r--r-- | calibration.e | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/calibration.e b/calibration.e new file mode 100644 index 0000000..e1b2d6a --- /dev/null +++ b/calibration.e @@ -0,0 +1,106 @@ +class CALIBRATION +-- This class is able to +-- - build some calibration grid with user assistance, +-- - save calibration grid, +-- - reload calibration grid, +-- - use calibration grid for coordinates conversion. + +create {ANY} + make + +feature {} + make is + do + create reference_points.make + end + +feature {ANY} + ready: BOOLEAN + + build (display_width_, display_height_: INTEGER) is + local + uncalibrated: FAST_ARRAY[INTEGER] + do + display_width := display_width_ + display_height := display_height_ + from + uncalibrated := {FAST_ARRAY[INTEGER] <<0, 0, display_width, display_height>>} + until + uncalibrated.is_empty + loop + + end + ensure + ready + end + + write_to (os: OUTPUT_STREAM) is + require + os.is_connected + do + ensure + os.is_connected + end + + load_from (data: INPUT_STREAM) is + require + data.is_connected + do + end + + set_offset(x_display, y_display: INTEGER) is + do + x_offset := x_display + y_offset := y_display + end + + convert (x_device, y_device: INTEGER) is + -- Result is available in last_x, last_y + require + x_device.in_range(0, device_width) + y_device.in_range(0, device_height) + local + i, j: INTEGER + x_rest, y_rest: INTEGER + + do + i := x_device // horizontal_step + j := y_device // vertical_step + x_rest := x_device - i * horizontal_step + y_rest := y_device - j * vertical_step + if y_rest * 2 < vertical_step then + last_x := ((x_table.item(i, j) * x_rest + x_table.item(i + 1, j) * (horizontal_step - x_rest)) / horizontal_step).force_to_integer_32 + else + last_x := ((x_table.item(i, j + 1) * x_rest + x_table.item(i + 1, j + 1) * (horizontal_step - x_rest)) / horizontal_step).force_to_integer_32 + end + if x_rest * 2 < horizontal_step then + last_y := ((y_table.item(i, j) * y_rest + y_table.item(i, j + 1) * (vertical_step - y_rest)) / vertical_step).force_to_integer_32 + else + last_y := ((y_table.item(i + 1, j) * y_rest + y_table.item(i + 1, j + 1) * (vertical_step - y_rest)) / vertical_step).force_to_integer_32 + end + ensure + last_x.in_range(x_offset, x_offset + display_width -1) + last_y.in_range(y_offset, y_offset + display_height - 1) + end + + last_x, last_y: INTEGER + -- Last conversion result (in display coordinates) + +feature {} + x_offset, y_offset, display_width, display_height: INTEGER + -- coordinates and size of the displayed area in pixels + + x_table, y_table: FAST_ARRAY2[REAL] + -- Store display coordinates for device coordinate. Use + -- `horizontal_step' and `vertical_step' for table indexes values. + + horizontal_step, vertical_step: INTEGER + -- Indexes steps for tables + + device_width, device_height: INTEGER + -- Digitizer size + + reference_points: REFERENCE_POINTS + -- 4 values per reference point x_device +end + |