//---------------------------------------------------------------------------

#ifndef SecStudy_FormH
#define SecStudy_FormH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include "CPB_Module.h"
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TSecondStudyFom : public TForm
{
__published:	// IDE-managed Components
  TEdit *Edit1;
  TLabel *Label1;
  TLabel *Label2;
  TEdit *ImgPath;
  TButton *Button1;
  TButton *StudyStart;
  TImage *Image1;
  TGroupBox *TwoColor;
  TStaticText *TabletTwoColorFrontLabel_Disk1_R;
  TStaticText *TabletTwoColorFrontLabel_Disk1_G;
  TStaticText *TabletTwoColorFrontLabel_Disk1_B;
  TStaticText *TabletTwoColorRearLabel_Disk1_B;
  TStaticText *TabletTwoColorRearLabel_Disk1_G;
  TStaticText *TabletTwoColorRearLabel_Disk1_R;
  TStaticText *TabletTwoColorFrontLabel_Disk2_B;
  TStaticText *TabletTwoColorFrontLabel_Disk2_G;
  TStaticText *TabletTwoColorFrontLabel_Disk2_R;
  TStaticText *TabletTwoColorRearLabel_Disk2_B;
  TStaticText *TabletTwoColorRearLabel_Disk2_G;
  TStaticText *TabletTwoColorRearLabel_Disk2_R;
  TShape *TabletTwoColorFrontShape1;
  TShape *TabletTwoColorRearShape1;
  TShape *TabletTwoColorFrontShape2;
  TShape *TabletTwoColorRearShape2;
  TGroupBox *OneColor;
  TShape *TabletOneColorShape1;
  TShape *TabletOneColorShape2;
  TStaticText *TabletOneColorLabel_Disk1_R;
  TStaticText *TabletOneColorLabel_Disk1_G;
  TStaticText *TabletOneColorLabel_Disk1_B;
  TStaticText *TabletOneColorLabel_Disk2_B;
  TStaticText *TabletOneColorLabel_Disk2_G;
  TStaticText *TabletOneColorLabel_Disk2_R;
  TGroupBox *PrintIsOrNotThresholdV;
  TStaticText *StaticText1;
  TStaticText *StaticText2;
  TStaticText *StaticText3;
  TStaticText *StaticText4;
  TStaticText *ThresholdLabel_ForCam1_A;
  TStaticText *ThresholdLabel_ForCam1_B;
  TStaticText *ThresholdLabel_ForCam2_B;
  TStaticText *ThresholdLabel_ForCam2_A;
  TStaticText *ThresholdLabel_ForCam6_B;
  TStaticText *ThresholdLabel_ForCam6_A;
  TStaticText *ThresholdLabel_ForCam7_B;
  TStaticText *ThresholdLabel_ForCam7_A;
  TGroupBox *Thickness;
  TStaticText *StaticText5;
  TStaticText *HeightThresholdLabel_Disc1;
  TStaticText *StaticText7;
  TStaticText *HeightThresholdLabel_Disc2;
  TGroupBox *EmptyRemaining;
  TStaticText *StaticText6;
  TStaticText *Cam1Empty;
  TStaticText *StaticText9;
  TStaticText *Cam1Remaining;
  TStaticText *StaticText11;
  TStaticText *StaticText12;
  TStaticText *Cam6Empty;
  TStaticText *Cam6Remaining;
  TProgressBar *ProgressBar1;
  TGroupBox *GroupBox1;
  TShape *SideCameraColorShape2;
  TStaticText *SideCameraBColorLabel2;
  TStaticText *SideCameraGColorLabel2;
  TStaticText *SideCameraRColorLabel2;
  TStaticText *SideCameraRColorLabel3;
  TStaticText *SideCameraGColorLabel3;
  TStaticText *SideCameraBColorLabel3;
  TShape *SideCameraColorShape3;
  TStaticText *SideCameraRColorLabel4;
  TStaticText *SideCameraGColorLabel4;
  TStaticText *SideCameraBColorLabel4;
  TShape *SideCameraColorShape4;
  TStaticText *SideCameraRColorLabel8;
  TStaticText *SideCameraGColorLabel8;
  TStaticText *SideCameraBColorLabel8;
  TShape *SideCameraColorShape8;
  TStaticText *SideCameraRColorLabel7;
  TStaticText *SideCameraGColorLabel7;
  TStaticText *SideCameraBColorLabel7;
  TShape *SideCameraColorShape7;
  TStaticText *SideCameraRColorLabel6;
  TStaticText *SideCameraGColorLabel6;
  TShape *SideCameraColorShape6;
  TStaticText *SideCameraBColorLabel6;
  TStaticText *SideCameraRColorLabel12;
  TStaticText *SideCameraGColorLabel12;
  TStaticText *SideCameraBColorLabel12;
  TShape *SideCameraColorShape12;
  TStaticText *SideCameraRColorLabel11;
  TStaticText *SideCameraGColorLabel11;
  TStaticText *SideCameraBColorLabel11;
  TShape *SideCameraColorShape11;
  TStaticText *SideCameraRColorLabel10;
  TStaticText *SideCameraGColorLabel10;
  TShape *SideCameraColorShape10;
  TStaticText *SideCameraBColorLabel10;
  TStaticText *SideCameraRColorLabel16;
  TStaticText *SideCameraGColorLabel16;
  TStaticText *SideCameraBColorLabel16;
  TShape *SideCameraColorShape16;
  TStaticText *SideCameraRColorLabel15;
  TStaticText *SideCameraGColorLabel15;
  TStaticText *SideCameraBColorLabel15;
  TShape *SideCameraColorShape15;
  TStaticText *SideCameraRColorLabel14;
  TStaticText *SideCameraGColorLabel14;
  TShape *SideCameraColorShape14;
  TStaticText *SideCameraBColorLabel14;
  TGroupBox *GroupBox2;
  TShape *TabletEngraveOneColorShape1;
  TShape *TabletEngraveOneColorShape2;
  TStaticText *TabletEngraveOneColorLabel_Disk1_R;
  TStaticText *TabletEngraveOneColorLabel_Disk1_G;
  TStaticText *TabletEngraveOneColorLabel_Disk1_B;
  TStaticText *TabletEngraveOneColorLabel_Disk2_B;
  TStaticText *TabletEngraveOneColorLabel_Disk2_G;
  TStaticText *TabletEngraveOneColorLabel_Disk2_R;
  void __fastcall Button1Click(TObject *Sender);
  void __fastcall StudyStartClick(TObject *Sender);
  void __fastcall FormCreate(TObject *Sender);
  void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private:	// User declarations
  void __fastcall DoProcessing(int imageCount, int cameraIndex);
  bool __fastcall ReadSetupData(TTabletSetupData *tabletSetupData);
  bool __fastcall Read3DSetupData(TTablet3DSetupData *tablet3DSetupData);
  void __fastcall ImageLoad(int imageIndex, int cameraIndex);
  void __fastcall SaveImageFilePath();
  void __fastcall LoadImageFilePath();
  void __fastcall ProcessingResultAccumulation(int globalCamIndex);
  void __fastcall StudyResultDisplay();
  int __fastcall Optimal_Threshold(unsigned short *histo, int st_gray, int end_gray, int *grayMean, int option);
  int __fastcall Mean(unsigned short *data, int st_index, int end_index);
  bool __fastcall SaveStudyData(AnsiString studyFileName, TTabletStudyData &StudyData);
  void __fastcall Setup(int cameraIndex);

  TSideData tempSideData[SYSTEM_TOTAL_CAMERA_COUNT - 4];

  unsigned char PCBackgroundImageBuffer[MAX_INBOARD_PROCESSING_CAMERA_COUNT][MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * 3];
  short PCColorRateImageBuffer[MAX_INBOARD_PROCESSING_CAMERA_COUNT][MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * 3];
  unsigned char PCRGBFactorArrayBuffer[MAX_INBOARD_PROCESSING_CAMERA_COUNT][MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT];

  TStudyResultData_SPB AccStudyData[SYSTEM_TOTAL_CAMERA_COUNT];
public:		// User declarations
  __fastcall TSecondStudyFom(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TSecondStudyFom *SecondStudyFom;
//---------------------------------------------------------------------------
#endif
