<commit_before>﻿using ArucoUnity.Plugin;
using ArucoUnity.Plugin.cv;
using System;
using UnityEngine;

namespace ArucoUnity
{
  /// \addtogroup aruco_unity_package
  /// \{

  namespace Utility
  {
    /// <summary>
    /// Manages to retrieve and display every frame the images of any system with a fixed number of cameras to use with ArucoUnity.
    /// </summary>
    public abstract class ArucoCamera : MonoBehaviour
    {
      // Editor fields

      [SerializeField]
      [Tooltip("Start the cameras automatically after configured it.")]
      private bool autoStart = true;

      [SerializeField]
      [Tooltip("Display automatically or not the camera images on screen.")]
      private bool displayImages = true;

      // Events

      public delegate void CameraEventHandler();

      /// <summary>
      /// Executed when the camera system is configured.
      /// </summary>
      public event CameraEventHandler Configured = delegate { };

      /// <summary>
      /// Executed when the camera system starts.
      /// </summary>
      public event CameraEventHandler Started = delegate { };

      /// <summary>
      /// Executed when the camera system stops.
      /// </summary>
      public event CameraEventHandler Stopped = delegate { };

      /// <summary>
      /// Executed when the images has been updated.
      /// </summary>
      public event CameraEventHandler ImagesUpdated = delegate { };

      // Properties

      /// <summary>
      /// Start the camera system automatically after configured it.
      /// </summary>
      public bool AutoStart { get { return autoStart; } set { autoStart = value; } }

      /// <summary>
      /// Display automatically or not the camera images on screen.
      /// </summary>
      public bool DisplayImages { get { return displayImages; } set { displayImages = value; } }

      /// <summary>
      /// The number of cameras in the system.
      /// </summary>
      public abstract int CamerasNumber { get; }

      /// <summary>
      /// True when the camera system has started.
      /// </summary>
      public bool IsStarted { get; protected set; }

      /// <summary>
      /// True when the camera system is configured.
      /// </summary>
      public bool IsConfigured { get; protected set; }

      /// <summary>
      /// True when the images has been updated this frame.
      /// </summary>
      public bool ImagesUpdatedThisFrame { get; protected set; }

      /// <summary>
      /// The images in a OpenCV format. When getting the property, a new Mat is created for each image from the corresponding 
      /// <see cref="ImageTextures"/> content. When setting, the <see cref="ImageTextures"/> content is updated for each image from the Mat array.
      /// </summary>
      public virtual Mat[] Images 
      {
        get
        {
          // Initialize
          if (images == null)
          {
            images = new Mat[ImageTextures.Length];
            imageDataSizes = new int[ImageTextures.Length];

            for (int i = 0; i < ImageTextures.Length; i++)
            {
              byte[] imageData = ImageTextures[i].GetRawTextureData();
              images[i] = new Mat(ImageTextures[i].height, ImageTextures[i].width, ImageType(ImageTextures[i]), imageData);
              imageDataSizes[i] = (int)(images[i].ElemSize() * images[i].Total());
            }
            imagesGetThisFrame = true;
          }
          else if (!imagesGetThisFrame)
          {
            for (int i = 0; i < ImageTextures.Length; i++)
            {
              images[i].dataByte = ImageTextures[i].GetRawTextureData();
            }
            imagesGetThisFrame = true;
          }

          return images;
        }
        set
        {
          if (value.Length == images.Length)
          {
            for (int i = 0; i < images.Length; i++)
            {
              images[i] = value[i];
            }
            imagesHasBeenSetThisFrame = true;
          }
        }
      }

      /// <summary>
      /// Image textures, updated each frame.
      /// </summary>
      public Texture2D[] ImageTextures { get; protected set; }

      /// <summary>
      /// The parameters of each camera.
      /// </summary>
      public CameraParameters[] CameraParameters { get; protected set; }

      /// <summary>
      /// The Unity camera components that will capture the <see cref="ImageTextures"/>.
      /// </summary>
      public Camera[] ImageCameras { get; protected set; }

      /// <summary>
      /// The correct image orientations.
      /// </summary>
      public virtual Quaternion[] ImageRotations { get; protected set; }

      /// <summary>
      /// The image ratios.
      /// </summary><commit_msg>style(ArucoCamera.cs): use CamerasNumber instead of the length of an images array property.<commit_after>﻿using ArucoUnity.Plugin;
using ArucoUnity.Plugin.cv;
using System;
using UnityEngine;

namespace ArucoUnity
{
  /// \addtogroup aruco_unity_package
  /// \{

  namespace Utility
  {
    /// <summary>
    /// Manages to retrieve and display every frame the images of any system with a fixed number of cameras to use with ArucoUnity.
    /// </summary>
    public abstract class ArucoCamera : MonoBehaviour
    {
      // Editor fields

      [SerializeField]
      [Tooltip("Start the cameras automatically after configured it.")]
      private bool autoStart = true;

      [SerializeField]
      [Tooltip("Display automatically or not the camera images on screen.")]
      private bool displayImages = true;

      // Events

      public delegate void CameraEventHandler();

      /// <summary>
      /// Executed when the camera system is configured.
      /// </summary>
      public event CameraEventHandler Configured = delegate { };

      /// <summary>
      /// Executed when the camera system starts.
      /// </summary>
      public event CameraEventHandler Started = delegate { };

      /// <summary>
      /// Executed when the camera system stops.
      /// </summary>
      public event CameraEventHandler Stopped = delegate { };

      /// <summary>
      /// Executed when the images has been updated.
      /// </summary>
      public event CameraEventHandler ImagesUpdated = delegate { };

      // Properties

      /// <summary>
      /// Start the camera system automatically after configured it.
      /// </summary>
      public bool AutoStart { get { return autoStart; } set { autoStart = value; } }

      /// <summary>
      /// Display automatically or not the camera images on screen.
      /// </summary>
      public bool DisplayImages { get { return displayImages; } set { displayImages = value; } }

      /// <summary>
      /// The number of cameras in the system.
      /// </summary>
      public abstract int CamerasNumber { get; }

      /// <summary>
      /// True when the camera system has started.
      /// </summary>
      public bool IsStarted { get; protected set; }

      /// <summary>
      /// True when the camera system is configured.
      /// </summary>
      public bool IsConfigured { get; protected set; }

      /// <summary>
      /// True when the images has been updated this frame.
      /// </summary>
      public bool ImagesUpdatedThisFrame { get; protected set; }

      /// <summary>
      /// The images in a OpenCV format. When getting the property, a new Mat is created for each image from the corresponding 
      /// <see cref="ImageTextures"/> content. When setting, the <see cref="ImageTextures"/> content is updated for each image from the Mat array.
      /// </summary>
      public virtual Mat[] Images 
      {
        get
        {
          // Initialize
          if (images == null)
          {
            images = new Mat[CamerasNumber];
            imageDataSizes = new int[CamerasNumber];

            for (int i = 0; i < CamerasNumber; i++)
            {
              byte[] imageData = ImageTextures[i].GetRawTextureData();
              images[i] = new Mat(ImageTextures[i].height, ImageTextures[i].width, ImageType(ImageTextures[i]), imageData);
              imageDataSizes[i] = (int)(images[i].ElemSize() * images[i].Total());
            }
            imagesGetThisFrame = true;
          }
          else if (!imagesGetThisFrame)
          {
            for (int i = 0; i < CamerasNumber; i++)
            {
              images[i].dataByte = ImageTextures[i].GetRawTextureData();
            }
            imagesGetThisFrame = true;
          }

          return images;
        }
        set
        {
          if (value.Length == CamerasNumber)
          {
            for (int i = 0; i < CamerasNumber; i++)
            {
              images[i] = value[i];
            }
            imagesHasBeenSetThisFrame = true;
          }
        }
      }

      /// <summary>
      /// Image textures, updated each frame.
      /// </summary>
      public Texture2D[] ImageTextures { get; protected set; }

      /// <summary>
      /// The parameters of each camera.
      /// </summary>
      public CameraParameters[] CameraParameters { get; protected set; }

      /// <summary>
      /// The Unity camera components that will capture the <see cref="ImageTextures"/>.
      /// </summary>
      public Camera[] ImageCameras { get; protected set; }

      /// <summary>
      /// The correct image orientations.
      /// </summary>
      public virtual Quaternion[] ImageRotations { get; protected set; }

      /// <summary>
      /// The image ratios.
      /// </summary>
{'fraction_non_alphanumeric': 0.11572419592179946, 'fraction_numerical': 0.0008408660920748371, 'mean_word_length': 1.8234421364985163, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '680762', 'n_tokens_mistral': 2459, 'n_tokens_neox': 2400, 'n_words': 812}