⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printingdata.cpp

📁 颜色预测模型评估,印刷品质量检测技术,实现光谱分析
💻 CPP
字号:
// PrintingData.cpp : implementation file
//

#include "stdafx.h"
#include "Printing.h"
#include "PrintingData.h"
#include <math.h>

#include "evaluation.h"
#include "conio.h"
#ifdef _DEBUG
#include "stdlib.h"
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CString string1="false",string2="false",string3="false",string4="false",string5="false",string6="false";
/////////////////////////////////////////////////////////////////////////////
// PrintingData dialog


PrintingData::PrintingData(CWnd* pParent /*=NULL*/)
	: CDialog(PrintingData::IDD, pParent)
{
	//{{AFX_DATA_INIT(PrintingData)
		// NOTE: the ClassWizard will add member initialization 

	//}}AFX_DATA_INIT
}


void PrintingData::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(PrintingData)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(PrintingData, CDialog)
	//{{AFX_MSG_MAP(PrintingData)
	ON_BN_CLICKED(IDC_CELIANG, OnCeliang)
	ON_BN_CLICKED(IDC_BIAOZHUN, OnBiaozhun)
	ON_BN_CLICKED(IDC_PINGJIA, OnPingjia)
	ON_BN_CLICKED(IDC_JIAOZHENGSHUJV, OnJiaozhengshujv)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// PrintingData message handlers

//初始化主对话框

BOOL PrintingData::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	FILE* fp;
	char temp[20];
	char TempChar;
	int Int;
	float TempFloat;
	float Data;
	int i,j;
	p = (CMSFlexGrid *)GetDlgItem(IDC_MSFLEXGRID1);
	p->SetRow(0);
	p->SetColWidth(0,700);
	for(i=1;i<39;i++)
		p->SetColWidth(i,1600);
	for(i=1;i<39;i++)
	{
		p->SetCol(i);
		switch(i)
		{
		case 1: p->SetText(CString("    R(λ)_400nm"));break;
		case 2: p->SetText(CString("    R(λ)_410nm"));break;
		case 3: p->SetText(CString("    R(λ)_420nm"));break;
		case 4: p->SetText(CString("    R(λ)_430nm"));break;
		case 5: p->SetText(CString("    R(λ)_440nm"));break;
		case 6: p->SetText(CString("    R(λ)_450nm"));break;
		case 7: p->SetText(CString("    R(λ)_460nm"));break;
		case 8: p->SetText(CString("    R(λ)_470nm"));break;
		case 9: p->SetText(CString("    R(λ)_480nm"));break;
		case 10: p->SetText(CString("   R(λ)_490nm"));break;
		case 11: p->SetText(CString("   R(λ)_500nm"));break;
		case 12: p->SetText(CString("   R(λ)_510nm"));break;
		case 13: p->SetText(CString("   R(λ)_520nm"));break;
		case 14: p->SetText(CString("   R(λ)_530nm"));break;
		case 15: p->SetText(CString("   R(λ)_540nm"));break;
		case 16: p->SetText(CString("   R(λ)_550nm"));break;
		case 17: p->SetText(CString("   R(λ)_560nm"));break;
		case 18: p->SetText(CString("   R(λ)_570nm"));break;
		case 19: p->SetText(CString("   R(λ)_580nm"));break;
		case 20: p->SetText(CString("   R(λ)_590nm"));break;
		case 21: p->SetText(CString("   R(λ)_600nm"));break;
		case 22: p->SetText(CString("   R(λ)_610nm"));break;
		case 23: p->SetText(CString("   R(λ)_620nm"));break;
		case 24: p->SetText(CString("   R(λ)_630nm"));break;
		case 25: p->SetText(CString("   R(λ)_640nm"));break;
		case 26: p->SetText(CString("   R(λ)_650nm"));break;
		case 27: p->SetText(CString("   R(λ)_660nm"));break;
		case 28: p->SetText(CString("   R(λ)_670nm"));break;
		case 29: p->SetText(CString("   R(λ)_680nm"));break;
		case 30: p->SetText(CString("   R(λ)_690nm"));break;
		case 31: p->SetText(CString("   R(λ)_700nm"));break;
		case 32: p->SetText(CString("    L1"));break;
		case 33: p->SetText(CString("    A1"));break;
		case 34: p->SetText(CString("    B1"));break;
		case 35: p->SetText(CString("    L2"));break;
		case 36: p->SetText(CString("    A2"));break;
		case 37: p->SetText(CString("    B2"));break;
		case 38: p->SetText(CString("    △E"));break;
		default: p->SetText(CString("    △E"));
		}
	}
	if((fp=fopen("Commsp2.txt","r"))==NULL)
		MessageBox("Can't open IT8.7/3 standard data file!","Error",MB_ICONWARNING);
	fseek(fp,672,0);
	for(i=1;i<929;i++)
    {	
		p->SetRow(i);
        fscanf(fp,"%d",&Int);
   		fscanf(fp,"%s",&temp);
		p->SetCol(0);		
		p->SetText(CString(" ")+temp);
		for(j=1;j<5;j++)
		{
		fscanf(fp,"%d",&Int);
		}
	    fscanf(fp,"%f",&TempFloat);
        fscanf(fp,"%f",&TempFloat);
	    fscanf(fp,"%f",&TempFloat);
		for(j=1;j<4;j++)
		{
			fscanf(fp,"%f",&Data);
		}
       fscanf(fp,"%c",&TempChar);
    }
    fclose(fp);
	string1="false";
	string2="false";
	return TRUE;  
}

//读入色靶标准数据并写入主对话框

void PrintingData::OnBiaozhun() 
{
	// TODO: Add your control notification handler code here
	CString szFile1;
	FILE* fp;

	CFileDialog fileDialog1(TRUE, "CUR",NULL,
		OFN_HIDEREADONLY,"Agfa color Data Files(*.txt)|*.txt||");

	if(fileDialog1.DoModal()!= IDOK) 
	return;
	szFile1 = fileDialog1.GetPathName();

	if((fp=fopen(szFile1,"r"))==NULL)//Open IS12642.dat.
	{
	::MessageBox(NULL ,"Can not open IS12642 data file!","ERROR",MB_OK);
    return;
	}
  		

	char temp[20];
	char TempChar;

	int i,j;
    for(i=0;i<928;i++)
    {	
		p->SetRow(i+1);
        
		for(j=1;j<32;j++)
	{
		fscanf(fp,"%f",&LAB0[i][j-1]);
			p->SetCol(j);
			_gcvt(LAB0[i][j-1],5,temp);
			p->SetText(CString("  ")+temp);
			
		}
       fscanf(fp,"%c",&TempChar);
    }
    string1="true";
	fclose(fp);	
	
}

//读入计算数据并写入主对话框 

void PrintingData::OnCeliang()
{
	// TODO: Add your control notification handler code here

	X0[0]=0.0143;
	X0[1]=0.0435;
	X0[2]=0.1344;
	X0[3]=0.2839;
	X0[4]=0.3483;
	X0[5]=0.3362;
	X0[6]=0.2908;
	X0[7]=0.1954;
	X0[8]=0.0956;
	X0[9]=0.0320;
	X0[10]=0.0049;
	X0[11]=0.0093;
	X0[12]=0.0633;
	X0[13]=0.1655;
	X0[14]=0.2904;
	X0[15]=0.4334;
	X0[16]=0.5945;
	X0[17]=0.7621;
	X0[18]=0.9163;
	X0[19]=1.0263;
	X0[20]=1.0622;
	X0[21]=1.0026;
	X0[22]=0.8544;
	X0[23]=0.6424;
	X0[24]=0.4479;
	X0[25]=0.2835;
	X0[26]=0.1649;
	X0[27]=0.0874;
	X0[28]=0.0468;
	X0[29]=0.0227;
	X0[30]=0.0114;
	Y0[0]=0.0004;
	Y0[1]=0.0012;
	Y0[2]=0.0040;
	Y0[3]=0.0116;
	Y0[4]=0.0230;
	Y0[5]=0.0380;
	Y0[6]=0.0600;
	Y0[7]=0.0910;
	Y0[8]=0.1390;
	Y0[9]=0.2080;
	Y0[10]=0.3230;
	Y0[11]=0.5030;
	Y0[12]=0.7100;
	Y0[13]=0.8620;
	Y0[14]=0.9540;
	Y0[15]=0.9950;
	Y0[16]=0.995;
	Y0[17]=0.9520;
	Y0[18]=0.8700;
	Y0[19]=0.7570;
	Y0[20]=0.6310;
	Y0[21]=0.5030;
	Y0[22]=0.3810;
	Y0[23]=0.2650;
	Y0[24]=0.1750;
	Y0[25]=0.1070;
	Y0[26]=0.0610;
	Y0[27]=0.0320;
	Y0[28]=0.0170;
	Y0[29]=0.0082;
	Y0[30]=0.0041;
	Z0[0]=0.0679;
	Z0[1]=0.2047;
	Z0[2]=0.6456;
	Z0[3]=1.3856;
	Z0[4]=1.7471;
	Z0[5]=1.7721;
	Z0[6]=1.6692;
	Z0[7]=1.8276;
	Z0[8]=0.8130;
	Z0[9]=0.4562;
	Z0[10]=0.2720;
	Z0[11]=0.1582;
	Z0[12]=0.0782;
	Z0[13]=0.0422;
	Z0[14]=0.0203;
	Z0[15]=0.0087;
	Z0[16]=0.0039;
	Z0[17]=0.0021;
	Z0[18]=0.0017;
	Z0[19]=0.0011;
	Z0[20]=0.0008;
	Z0[21]=0.0003;
	Z0[22]=0.0002;
	Z0[23]=0;
	Z0[24]=0;
	Z0[25]=0;
	Z0[26]=0;
	Z0[27]=0;
	Z0[28]=0;
	Z0[29]=0;
	Z0[30]=0;
	S[0]=49.31;
	S[1]=56.51;
	S[2]=60.03;
	S[3]=57.82;
	S[4]=74.82;
	S[5]=87.25;
	S[6]=90.61;
	S[7]=91.37;
	S[8]=65.11;
	S[9]=91.96;
	S[10]=95.72;
	S[13]=96.61;
	S[11]=97.13;
	S[12]=102.10;
	S[14]=100.75;
	S[15]=102.32;
	S[16]=100.00;
	S[17]=97.74;
	S[18]=98.92;
	S[19]=93.50;
	S[20]=97.69;
	S[21]=99.27;
	S[22]=99.04;
	S[23]=95.72;
	S[24]=98.86;
	S[25]=95.67;
	S[26]=98.19;
	S[27]=103.00;
	S[28]=9.13;
	S[29]=87.38;
	S[30]=91.60;
	int i,j;
	
	for(i=0;i<928;i++)
	{
		X[i]=0;
		Y[i]=0;
		Z[i]=0;
		for(j=0;j<32;j++)
		{
		X1[j]=LAB0[i][j]*S[j]*X0[j]*0.09;
		Y1[j]=LAB0[i][j]*S[j]*Y0[j]*0.09;
		Z1[j]=LAB0[i][j]*S[j]*Z0[j]*0.09;
		X[i]=X[i]+X1[j];
		Y[i]=Y[i]+Y1[j];
		Z[i]=Z[i]+Z1[j];
		}
	
	
	}
		x=95.045,y=100,z=108.255;
		for(i=0;i<928;i++)
		{

			LAB1[i][0]=(float)(pow((double)(Y[i]/y),0.3333)*116-16);
			LAB1[i][1]=(float)(500*(pow((double)(X[i]/x),0.3333)-pow((double)(Y[i]/y),0.3333)));
			LAB1[i][2]=(float)(200*(pow((double)(Y[i]/y),0.3333)-pow((double)(Z[i]/z),0.3333)));
		}
	char temp[20],temp1[20],temp2[20];
	for(i=0;i<928;i++)
	{
			p->SetRow(i+1);	
			p->SetCol(32);
			_gcvt(LAB1[i][0],4,temp);
			p->SetText(CString("  ")+temp);
	}
	for(i=0;i<928;i++)
	{
			p->SetRow(i+1);	
			p->SetCol(33);
			_gcvt(LAB1[i][1],4,temp1);
			p->SetText(CString("  ")+temp1);
	}
		for(i=0;i<928;i++)
	{
			p->SetRow(i+1);	
			p->SetCol(34);
			_gcvt(LAB1[i][2],4,temp2);
			p->SetText(CString("  ")+temp2);
	}
		string2="true";
}


//读入验证数据并写入主对话框

void PrintingData::OnJiaozhengshujv() 
{
	// TODO: Add your control notification handler code here
	CString szFile1;
	FILE* fp;

	CFileDialog fileDialog1(TRUE, "CUR",NULL,
		OFN_HIDEREADONLY,"Agfa color Data Files(*.txt)|*.txt||");

	if(fileDialog1.DoModal()!= IDOK) 
	return;
	szFile1 = fileDialog1.GetPathName();

	if((fp=fopen(szFile1,"r"))==NULL)
	{
	::MessageBox(NULL ,"Can not open IS12642 data file!","ERROR",MB_OK);
    return;
	}
	
	
	char temp[20];
	char TempChar;
//	int Int;
	int i,j;
    for(i=0;i<928;i++)
    {	
		p->SetRow(i+1);
        
		for(j=35;j<38;j++)
		{
			fscanf(fp,"%f",&LAB2[i][j-35]);
			p->SetCol(j);
			_gcvt(LAB2[i][j-35],4,temp);
			p->SetText(CString("   ")+temp);
		}
       fscanf(fp,"%c",&TempChar);
    }
   	fclose(fp);

	string4="true";
}

//对系统色彩传递质量进行评价

void PrintingData::OnPingjia() 
{
	// TODO: Add your control notification handler code here
	double D=0;
	float g=0;

	for(int i=0;i<928;i++)
	{

		for(int j=0;j<3;j++)
		{
		
		AB[i][j]=LAB1[i][j]-LAB2[i][j];
		}
		E[i]=(float) sqrt(AB[i][0]*AB[i][0]+AB[i][1]*AB[i][1]+AB[i][2]*AB[i][2]);
		
		D=D+E[i];
		if (E[i]>=6)
			g=g+1;
	}

	AVERAGEERROR=float(D/928.00);//平均色差
	PERCENT=float((float)(g)/928.00);//色差大于6所占的百分比
	MAXERROR=E[0];

	for(i=1; i<928; i++)//求最大色差
		if (E[i]>MAXERROR)
		{
			MAXERROR=E[i];

		}
	Cevaluation dialog;
	
  	LPCTSTR temp1,temp2;
	temp1="传递质量不佳,须进行校正。";
	temp2="传递质量尚可,不需要校正。";
	if (string2=="true")
		if(string4=="true")
		{
			if(PERCENT>0.6)
			{
				dialog.m_Result=temp1;
				string3="true";
			}
			else
				dialog.m_Result=temp2;
			dialog.m_Averageerror=AVERAGEERROR;
			dialog.m_Maxerror=MAXERROR;
			dialog.m_Percent=PERCENT*100;
			dialog.DoModal();
			temp2=(LPCTSTR)(dialog.m_Result);
			UpdateData(FALSE);		
			
		}
		else
			MessageBox("请选择标准数据文件!  ","警告:",MB_ICONWARNING);
	else
		MessageBox("请先计算数据!  ","警告:",MB_ICONWARNING);
	
	char temp[20];	
	for(i=0;i<928;i++)//向主对话框中写入色差值
	{
			p->SetRow(i+1);	
			p->SetCol(38);
			_gcvt(E[i],4,temp);
			p->SetText(CString("  ")+temp);
			
	}
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -