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

#ifndef First_StudyH
#define First_StudyH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ExtCtrls.hpp>
#include "CSPIN.h"
#include <ComCtrls.hpp>

#include "CPB_Module.h"
#include <Chart.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
#include "TntButtons.hpp"
#include "TntComCtrls.hpp"
#include "TntExtCtrls.hpp"
#include "TntStdCtrls.hpp"
#include "TntForms.hpp"

#define NOT_THREED 1
#define THREED 2

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define GRID_SIZE 20

#define YSPACE 35                
#define FIRST_STUDY_N 100
#define EXPAND_PRINT_PROBABLITY 20

//---------------------------------------------------------------------------
class TFirstStudy : public TTntForm
{
__published:	// IDE-managed Components
	TTntLabel *Label3;
    TTntGroupBox *GroupBox1;
    TTntImage *Image1;
    TTntGroupBox *GroupBox2;
    TTntLabel *Label10;
    TTntLabel *Label11;
    TTntLabel *Label12;
    TTntLabel *Label13;
    TTntLabel *Label18;
    TTntLabel *Label19;
    TTntLabel *Label20;
    TTntLabel *Label21;
    TTntBitBtn *BitBtn1;
    TTntBitBtn *BitBtn2;
    TTntGroupBox *GroupBox11;
    TTntImage *ResultImage1;
    TTntImage *ResultImage2;
    TTntImage *ResultImage3;
    TTntImage *ResultImage4;
    TTntPanel *Panel1;
  TTntStaticText *CameraStatic1;
  TTntStaticText *CameraStatic2;
  TTntStaticText *CameraStatic3;
  TTntStaticText *CameraStatic4;
  TTntStaticText *CameraStatic5;
  TTntStaticText *CameraStatic6;
  TTntStaticText *CameraStatic7;
  TTntStaticText *CameraStatic8;
  TTntStaticText *CameraStatic9;
  TTntStaticText *CameraStatic10;
  TTntStaticText *StudyProcessingLabel1;
  TTntStaticText *StudyProcessingLabel2;
  TTntStaticText *StudyProcessingLabel3;
  TTntStaticText *StudyProcessingLabel4;
  TTntStaticText *StudyProcessingLabel5;
  TTntStaticText *StudyProcessingLabel6;
  TTntStaticText *StudyProcessingLabel7;
  TTntStaticText *StudyProcessingLabel8;
  TTntStaticText *StudyProcessingLabel9;
  TTntStaticText *StudyProcessingLabel10;
  TTntProgressBar *StudyProcessingBar1;
  TTntProgressBar *StudyProcessingBar2;
  TTntProgressBar *StudyProcessingBar3;
  TTntProgressBar *StudyProcessingBar4;
  TTntProgressBar *StudyProcessingBar5;
  TTntProgressBar *StudyProcessingBar6;
  TTntProgressBar *StudyProcessingBar7;
  TTntProgressBar *StudyProcessingBar8;
  TTntProgressBar *StudyProcessingBar9;
  TTntProgressBar *StudyProcessingBar10;
    TTntGroupBox *GroupBox12;
    TTntImage *Image56;
    TTntImage *Image57;
    TTntImage *Image58;
    TTntImage *Image59;
    TTntLabel *Label1;
    TTntLabel *Label2;
    TTntLabel *Label5;
    TTntLabel *Label6;
  TTntGroupBox *GroupBox5;
  TTntImage *BoundarySetResultImage1;
  TTntImage *BoundarySetResultImage2;
  TTntImage *BoundarySetResultImage5;
  TTntImage *subBoundarySetResultImage1;
  TTntImage *subBoundarySetResultImage5;
  TTntStaticText *StaticText5;
  TTntStaticText *TntStaticText1;
  TTntStaticText *TntStaticText2;
  TTntStaticText *TntStaticText3;
  TTntStaticText *TntStaticText4;
  TTntStaticText *TntStaticText5;
  TTntImage *BoundarySetResultImage3;
  TTntStaticText *TntStaticText6;
  TTntImage *BoundarySetResultImage4;
  TTntImage *BoundarySetResultImage6;
  TTntStaticText *TntStaticText7;
  TTntImage *BoundarySetResultImage7;
  TTntStaticText *TntStaticText8;
  TTntImage *BoundarySetResultImage8;
  TTntStaticText *TntStaticText9;
  TTntGroupBox *TntGroupBox1;
  TTntImage *BoundarySetResultImage9;
  TTntImage *BoundarySetResultImage10;
  TTntImage *BoundarySetResultImage13;
  TTntImage *subBoundarySetResultImage9;
  TTntImage *subBoundarySetResultImage13;
  TTntImage *BoundarySetResultImage11;
  TTntImage *BoundarySetResultImage12;
  TTntImage *BoundarySetResultImage14;
  TTntImage *BoundarySetResultImage15;
  TTntImage *BoundarySetResultImage16;
  TTntStaticText *TntStaticText10;
  TTntStaticText *TntStaticText11;
  TTntStaticText *TntStaticText12;
  TTntStaticText *TntStaticText13;
  TTntStaticText *TntStaticText14;
  TTntStaticText *TntStaticText15;
  TTntStaticText *TntStaticText16;
  TTntStaticText *TntStaticText17;
  TTntStaticText *TntStaticText18;
  TTntStaticText *TntStaticText19;
  TTntProgressBar *StudyProcessingBar11;
  TTntStaticText *StudyProcessingLabel11;
  TTntStaticText *CameraStatic11;
  TTntProgressBar *StudyProcessingBar12;
  TTntStaticText *StudyProcessingLabel12;
  TTntStaticText *CameraStatic12;
  TTntProgressBar *StudyProcessingBar13;
  TTntStaticText *StudyProcessingLabel13;
  TTntStaticText *CameraStatic13;
  TTntProgressBar *StudyProcessingBar14;
  TTntStaticText *StudyProcessingLabel14;
  TTntStaticText *CameraStatic14;
  TTntProgressBar *StudyProcessingBar15;
  TTntStaticText *StudyProcessingLabel15;
  TTntStaticText *CameraStatic15;
  TTntStaticText *CameraStatic16;
  TTntStaticText *StudyProcessingLabel16;
  TTntProgressBar *StudyProcessingBar16;
  TTntImage *ResultImage5;
  TTntImage *ResultImage6;
  TTntImage *ResultImage7;
  TTntImage *ResultImage8;
  TTntImage *ResultImage9;
  TTntImage *ResultImage13;
  TTntImage *ResultImage10;
  TTntImage *ResultImage11;
  TTntImage *ResultImage14;
  TTntImage *ResultImage15;
  TTntImage *ResultImage12;
  TTntImage *ResultImage16;
  TTntGroupBox *TntGroupBox2;
  TTntImage *TestImage1;
  TTntImage *TestImage2;
  TScrollBox *DebugPanel;
  TImage *SideImage6;
  TImage *SideImage5;
  TImage *SideImage4;
  TImage *SideImage3;
  TImage *SideImage2;
  TGroupBox *DataGroupBox1;
  TLabel *AngleXMatchingResultLabel1;
  TLabel *AngleYMatchingResultLabel1;
  TLabel *AngleZMatchingResultLabel1;
  TLabel *ResMatchingResultLabel1;
  TImage *SideImage1;
  TGroupBox *GroupBox20;
  TRadioButton *CamRadioBtn2;
  TRadioButton *CamRadioBtn3;
  TRadioButton *CamRadioBtn4;
  TRadioButton *CamRadioBtn6;
  TRadioButton *CamRadioBtn7;
  TRadioButton *CamRadioBtn8;
  TRadioButton *CamRadioBtn14;
  TRadioButton *CamRadioBtn15;
  TRadioButton *CamRadioBtn16;
  TRadioButton *CamRadioBtn12;
  TRadioButton *CamRadioBtn11;
  TRadioButton *CamRadioBtn10;
  TButton *testStartBtn;
  TButton *Button2;
  TGroupBox *DataGroupBox2;
  TLabel *AngleXMatchingResultLabel2;
  TLabel *AngleYMatchingResultLabel2;
  TLabel *AngleZMatchingResultLabel2;
  TLabel *ResMatchingResultLabel2;
  TGroupBox *DataGroupBox3;
  TLabel *AngleXMatchingResultLabel3;
  TLabel *AngleYMatchingResultLabel3;
  TLabel *AngleZMatchingResultLabel3;
  TLabel *ResMatchingResultLabel3;
  TGroupBox *DataGroupBox4;
  TLabel *AngleXMatchingResultLabel4;
  TLabel *AngleYMatchingResultLabel4;
  TLabel *AngleZMatchingResultLabel4;
  TLabel *ResMatchingResultLabel4;
  TGroupBox *DataGroupBox5;
  TLabel *AngleXMatchingResultLabel5;
  TLabel *AngleYMatchingResultLabel5;
  TLabel *AngleZMatchingResultLabel5;
  TLabel *ResMatchingResultLabel5;
  TGroupBox *DataGroupBox6;
  TLabel *AngleXMatchingResultLabel6;
  TLabel *AngleYMatchingResultLabel6;
  TLabel *AngleZMatchingResultLabel6;
  TLabel *ResMatchingResultLabel6;
  TButton *Button3;
  TChart *TestYAngleMatchingResultChart;
  TBarSeries *BarSeries1;
  TBarSeries *BarSeries2;
  TChart *TestZAngleMatchingResultChart;
  TBarSeries *BarSeries3;
  TBarSeries *BarSeries4;
  TChart *TestXAngleMatchingResultChart;
  TBarSeries *BarSeries5;
  TBarSeries *BarSeries6;
  TScrollBox *SideFaceProcessingResultPanel;
  TChart *YAngleMatchingResultChart;
  TBarSeries *BarSeries7;
  TBarSeries *BarSeries8;
  TChart *ZAngleMatchingResultChart;
  TBarSeries *BarSeries9;
  TBarSeries *BarSeries10;
  TChart *XAngleMatchingResultChart;
  TBarSeries *BarSeries11;
  TBarSeries *BarSeries12;
  TPanel *Panel3;
  TPanel *Panel4;
  TPanel *Panel5;
  TImage *SideFaceGradientImage1;
  TGroupBox *GroupBox23;
  TLabel *SideFaceXAngleMatchingResult1;
  TLabel *SideFaceImageIndexLabel1;
  TImage *SideFaceBinaryImage1;
  TLabel *SideFaceYAngleMatchingResult1;
  TLabel *SideFaceZAngleMatchingResult1;
  TLabel *SideFaceShiftXMatchingResult1;
  TLabel *SideFaceShiftYMatchingResult1;
  TLabel *SideFaceResolution1;
  TLabel *SideFaceImageIndexLabel2;
  TImage *SideFaceGradientImage2;
  TImage *SideFaceBinaryImage2;
  TGroupBox *GroupBox21;
  TLabel *SideFaceXAngleMatchingResult2;
  TLabel *SideFaceYAngleMatchingResult2;
  TLabel *SideFaceZAngleMatchingResult2;
  TLabel *SideFaceShiftXMatchingResult2;
  TLabel *SideFaceShiftYMatchingResult2;
  TLabel *SideFaceResolution2;
  TLabel *SideFaceImageIndexLabel3;
  TImage *SideFaceGradientImage3;
  TImage *SideFaceBinaryImage3;
  TGroupBox *GroupBox22;
  TLabel *SideFaceXAngleMatchingResult3;
  TLabel *SideFaceYAngleMatchingResult3;
  TLabel *SideFaceZAngleMatchingResult3;
  TLabel *SideFaceShiftXMatchingResult3;
  TLabel *SideFaceShiftYMatchingResult3;
  TLabel *SideFaceResolution3;
  TProgressBar *CurrentProgressBar;
    void __fastcall BitBtn1Click(TObject *Sender);
    void __fastcall BitBtn2Click(TObject *Sender);
    void __fastcall rmActivate(TObject *Sender);
    void __fastcall FormCreate(TObject *Sender);
  void __fastcall ResultImageClick(TObject *Sender);
  void __fastcall Result3DImageClick(TObject *Sender);
  void __fastcall CameraResEdit9Click(TObject *Sender);
  void __fastcall Button2Click(TObject *Sender);
  void __fastcall SideImage1DblClick(TObject *Sender);
  void __fastcall TntFormClose(TObject *Sender, TCloseAction &Action);
private:	// User declarations
  int Side_XSPACE;
  int Front_XSPACE;
	int ImageHeight;
	int ImageWidth;
  int BoundaryLeft[SYSTEM_TOTAL_CAMERA_COUNT];
  int BoundaryRight[SYSTEM_TOTAL_CAMERA_COUNT];
  int BoundaryTop[SYSTEM_TOTAL_CAMERA_COUNT];
  int BoundaryBottom[SYSTEM_TOTAL_CAMERA_COUNT];
  int BaseAdjustValue[SYSTEM_TOTAL_CAMERA_COUNT];
  int PrintShiftValue[SYSTEM_TOTAL_CAMERA_COUNT][4][2];
  unsigned char AccumualteImage1[MAX_IMAGE_WIDTH*MAX_IMAGE_HEIGHT][THREED_PRINT_MAX_LABEL_COUNT];
  unsigned char AccumualteImage2[MAX_IMAGE_WIDTH*MAX_IMAGE_HEIGHT][THREED_PRINT_MAX_LABEL_COUNT];
  int Disk1Print1ImageCount;
  int Disk1Print2ImageCount;
  int Disk2Print1ImageCount;
  int Disk2Print2ImageCount;
	int FirstStudyExcuteSW;

  int PrintPixelCntCam1;
  int PrintPixelCntCam9;
  int addCount1;
  int addCount2;

  int Acc_ProtoEngraveDistinguishV_Cam1;
  int Acc_ProtoEngraveDistinguishV_Cam9;
  int EngraveMatchingCount1;
  int EngraveMatchingCount2;

	bool Setup3DNeeded;

  AnsiString CameraInfo[SYSTEM_TOTAL_CAMERA_COUNT];

  int AccInspectionAreaStX[SYSTEM_TOTAL_CAMERA_COUNT];
  int AccInspectionAreaEdX[SYSTEM_TOTAL_CAMERA_COUNT];
  int InspectionAreaMinY[SYSTEM_TOTAL_CAMERA_COUNT];
  int InspectionAreaMaxY[SYSTEM_TOTAL_CAMERA_COUNT];
  int SideFaceMatchingCount;

  int XAngleMatchingResultData[MAX_ANGLE1_RANGE * 2 + 1];
  int YAngleMatchingResultData[MAX_ANGLE2_RANGE * 2 + 1];
  int ZAngleMatchingResultData[MAX_ANGLE3_RANGE * 2 + 1];

  TSideData tempSideData[SYSTEM_TOTAL_CAMERA_COUNT - 4];

  int TiltingTabletHeight[SYSTEM_TOTAL_CAMERA_COUNT];

  bool StudyFailInfo[SYSTEM_TOTAL_CAMERA_COUNT];

  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];
  
  void __fastcall LoadDebugResult(int cameraIndex);

  void __fastcall GetDefaultString();
  void __fastcall ImageLoad(int imageIndex, int cameraIndex);
  void __fastcall ResultDisplay(void);

  void __fastcall MakeTabletSetupData(TTabletCharacter *tabletCharacter);
  bool __fastcall ReadSetupData(TTabletSetupData *tabletSetupData);
  void __fastcall ProcessingResultDisplay(int cameraIndex, int option);
  void __fastcall ResultDataAccumulate(int cameraIndex, int option,int imageCount);
  void __fastcall FirstStudyDataCalculate(void);
  void __fastcall ProgressDisplay(int cameraIndex, int imageCount, int maxStudyCount);
  bool __fastcall Read3DSetupData(TTablet3DSetupData *tablet3DSetupData);
  void __fastcall Store3DSetupData(int cameraIndex);
  void __fastcall AccumulateAreaInformation(int cameraIndex);

  void __fastcall MakeDebugComponent();
  void __fastcall DeleteDebugComponent();
  void __fastcall ShowProcessingResult();
  void __fastcall InitialSideFaceProcessingDebugData();
  void __fastcall SetSideFaceProcessingDebugData(int ImageIndex, int cameraIndex);
  int __fastcall GetTabletAreaInfo(int cameraIndex);

  int Disk1ThreeDImageCenterXForLaser;
  int Disk1ThreeDImageCenterYForLaser;
  int Disk2ThreeDImageCenterXForLaser;
  int Disk2ThreeDImageCenterYForLaser;

  int Disk1ThreeDImageLengthForLaser;
  int Disk2ThreeDImageLengthForLaser;
  
public:		// User declarations
    __fastcall TFirstStudy(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFirstStudy *FirstStudy;
//---------------------------------------------------------------------------
#endif
