//--------------------------------------------------------------------------- #include #pragma hdrstop #include "treatment.h" #include "Simulation_F.h" #include "common.h" #include #include "Main_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzPanel" #pragma link "RzRadGrp" #pragma link "RzButton" #pragma link "RzEdit" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_TREATMENT_SET StringTable[0] #define IDS_TREATMENT_METHOD StringTable[1] #define IDS_NONE StringTable[2] #define IDS_HAIR StringTable[3] #define IDS_RAISE StringTable[4] #define IDS_COURSE StringTable[5] #define IDS_TREATMENT StringTable[6] #define IDS_CHECK_ALL StringTable[7] //--------------------------------------------------------------------------- TTreatment_F *Treatment_F; //--------------------------------------------------------------------------- typedef struct tagCOURSE_TREATMENT { bool layer[MAX_LAYER_COUNT]; } COURSE_TREATMENT; //--------------------------------------------------------------------------- typedef struct tag_RAISE3D { bool used; bool special; // Ư¼öÇÑ ¼ºÁúÀ» ÁöÁ¤ POINT pos[4]; // ½Ã°è¹æÇâÀ¸·Î µ¹¾Æ°£´Ù double z; double brt; double glx, gly; double sqr[4]; double a[4], b[4], c[4]; void _fastcall set_constant(){ repro_dis(0, 0, 1); repro_dis(1, 2, 3); repro_dis(2, 3, 0); repro_dis(3, 1, 2); } void __fastcall repro_dis(int i, int j, int k){ a[i] = pos[j].y - pos[k].y; b[i] = pos[k].x - pos[j].x; c[i] = pos[j].x * pos[k].y - pos[k].x * pos[j].y; sqr[i] = sqrt(a[i] * a[i] + b[i] * b[i]); } void _fastcall find_point(int &ix, int &iy, int &ox, int &oy){ double lx1, lx2, ly1, ly2; ly1 = fabs(a[0] * ix + b[0] * iy + c[0]) / sqr[0]; ly2 = fabs(a[1] * ix + b[1] * iy + c[1]) / sqr[1]; lx1 = fabs(a[2] * ix + b[2] * iy + c[2]) / sqr[2]; lx2 = fabs(a[3] * ix + b[3] * iy + c[3]) / sqr[3]; if (lx1 + lx2 && ly1 + ly2) { ox = lx1 * glx / (lx1 + lx2); oy = ly1 * gly / (ly1 + ly2); } else { ox = 0; oy = 0; } } } RAISE3D; //--------------------------------------------------------------------------- typedef struct tagHAIR { bool used; bool hasPile; Yarn *yarn[MAX_LAYER_COUNT];//MAX_LAYER_COUNT°³ÀÇ ½Ç POINT pos[4];//½Ã°è¹æÇâÀ¸·Î µ¹¾Æ°£´Ù double glx, gly; double sqr[4]; double a[4], b[4], c[4]; void _fastcall set_constant(){ repro_dis(0, 0, 1); repro_dis(1, 2, 3); repro_dis(2, 3, 0); repro_dis(3, 1, 2); } void __fastcall repro_dis(int i, int j, int k){ a[i] = pos[j].y - pos[k].y; b[i] = pos[k].x - pos[j].x; c[i] = pos[j].x * pos[k].y - pos[k].x * pos[j].y; sqr[i] = sqrt(a[i] * a[i] + b[i] * b[i]); } void _fastcall find_point(int &ix, int &iy, int &ox, int &oy){ double lx1, lx2, ly1, ly2; ly1 = fabs(a[0] * ix + b[0] * iy + c[0]) / sqr[0]; ly2 = fabs(a[1] * ix + b[1] * iy + c[1]) / sqr[1]; lx1 = fabs(a[2] * ix + b[2] * iy + c[2]) / sqr[2]; lx2 = fabs(a[3] * ix + b[3] * iy + c[3]) / sqr[3]; if (lx1 + lx2 && ly1 + ly2) { ox = lx1 * glx / (lx1 + lx2); oy = ly1 * gly / (ly1 + ly2); } else { ox = 0; oy = 0; } } } HAIR; //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- __fastcall TTreatment_F::TTreatment_F(TComponent* Owner) : TForm(Owner) { treatmentMap1=NULL; treatmentMap2=NULL; sgCourse->DoubleBuffered = true; } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::PreTreat(Tricot *tricot){ Back=SimulationForm->sd.back; this->tricot=tricot; if(Back==true)return; if(rgTreatmentMethod->ItemIndex==0) return; Tex *tex = (Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; if(tex->Curve->Count!=CourseTreat->Count)SetHeight(tex->Curve->Count); LEG *Leg; HEAD *Head; if(rgTreatmentMethod->ItemIndex==1){ if(CourseTreat->Count){ for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ Octopus *octo = tricot->GetOctopus(i,j); if(octo->used!=true)continue; COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[j%CourseTreat->Count]; bool treat=false; int maxl=0; for(int k=0;kListOfLeg->Count;k++){//ÃÖ°íÃþÀÌ °¡°øµÇ´Â °¡¸¦ °Ë»ç Leg = (LEG *)octo->ListOfLeg->Items[k]; if(Leg->Layer>maxl){ treat=ct->layer[Leg->Layer]; maxl=Leg->Layer; } } for(int k=0;kListOfLeg->Count;k++){ Leg = (LEG *)octo->ListOfLeg->Items[k]; if(ct->layer[Leg->Layer]&&treat) Leg->ls=NO_LEG; } } } } } else if(rgTreatmentMethod->ItemIndex==2){ } } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::FinalTreat(TTexpiaBitmap *bmDst, int width, int height, ProgressPercentage *percent){ percent->Percentage(0); if(Back==true)return;//Èİ¡°øÇÒ¶§¿¡´Â µÞ¸éÀ» ½Å°æ¾²Áö ¾Ê°Ú´Ù if(tricot->Width<2||tricot->Height<2) return;//ÀÌ·¸°Ô ÀÛÀº°Ç Èİ¡°ø ÇØºÁ¾ß ¼Ò¿ë¾ø´Ù if(rgTreatmentMethod->ItemIndex==0) return; HDC dcSrc=NULL, dcDst=NULL; TTexpiaBitmap *bmSrc= new TTexpiaBitmap; bmSrc->Create(width,height, 24); bmSrc->CopyFromRect(bmDst,0,0,SRCCOPY); if(rgTreatmentMethod->ItemIndex==1){ treatmentMap1 = VirtualAlloc(NULL,tricot->Width*tricot->Height*sizeof(HAIR),MEM_COMMIT,PAGE_READWRITE); if(treatmentMap1) VirtualLock(treatmentMap1,tricot->Width*tricot->Height*sizeof(HAIR)); ////////////////////////////HAIR µ¥ÀÌŸ ÃʱâÈ­ 1 LEG *Leg; if(CourseTreat->Count){ for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[j%CourseTreat->Count]; Octopus *octo = tricot->GetOctopus(i,j); if(octo->used!=true)continue; bool treat=false; int maxl=0; for(int k=0;kListOfLeg->Count;k++){//ÃÖ°íÃþÀÌ °¡°øµÇ´Â °¡¸¦ °Ë»ç Leg = (LEG *)octo->ListOfLeg->Items[k]; if(Leg->Layer>maxl){ treat=ct->layer[Leg->Layer]; maxl=Leg->Layer; } } HAIR *hair = ((HAIR *)treatmentMap1+j*tricot->Width+i); hair->used=true; hair->pos[0].x = tricot->FindRealPosX(octo,i,j); hair->pos[0].y = tricot->FindRealPosY(octo,i,j); for(int k=0;kListOfLeg->Count;k++){ Leg = (LEG *)octo->ListOfLeg->Items[k]; if(ct->layer[Leg->Layer]&&treat) { hair->hasPile=true; hair->yarn[Leg->Layer]=Leg->yarn;//¿ø·¡´Â LegÀÇ link¿¡ ÀÇÇØ ÇϳªÀÇ ÄÚ¿¡ µÎ°³ÀÇ ÆÄÀÏÀÌ »ý±âÁö¸¸ ±×³É ³ª°¡´Â ÄÚ¿¡¼­¸¸ ¼¼°í °öÇϱâ 2¸¦ ÇÑ´Ù°í »ý°¢ÇÏÀÚ } else { hair->yarn[Leg->Layer]=NULL; } } } } } ////////////////////////////HAIR µ¥ÀÌŸ ÃʱâÈ­ 2 for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ HAIR *hair = ((HAIR *)treatmentMap1+j*tricot->Width+i); if(hair->used==false){ double x = tricot->RDistX*i; double y = tricot->RDistY*j; for(int j2=0;j2Height;j2++){ HAIR *hair2 = ((HAIR *)treatmentMap1+((j+j2)%tricot->Height)*tricot->Width+i); if(hair2->used){ x=hair2->pos[0].x; break; } } for(int i2=0;i2Width;i2++){ HAIR *hair2 = ((HAIR *)treatmentMap1+j*tricot->Width+(i+i2)%tricot->Width); if(hair2->used){ y=hair2->pos[0].y; break; } } hair->pos[0].x=x; hair->pos[0].y=y; } } } ////////////////////////////HAIR µ¥ÀÌŸ ÃʱâÈ­ 3 for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ HAIR *hair11 = ((HAIR *)treatmentMap1+j*tricot->Width+i); HAIR *hair12 = ((HAIR *)treatmentMap1+j*tricot->Width+(i+1)%tricot->Width); HAIR *hair21 = ((HAIR *)treatmentMap1+((j+1)%tricot->Height)*tricot->Width+i); HAIR *hair22 = ((HAIR *)treatmentMap1+((j+1)%tricot->Height)*tricot->Width+(i+1)%tricot->Width); hair11->pos[1]=hair12->pos[0]; hair11->pos[2]=hair22->pos[0]; hair11->pos[3]=hair21->pos[0]; } } ////////////////////////////HAIR µ¥ÀÌŸ ÃʱâÈ­ 3-1 for(int j=0;jHeight;j++){ HAIR *hair = ((HAIR *)treatmentMap1+j*tricot->Width+tricot->Width-1); hair->pos[1].x+=width; hair->pos[2].x+=width; } for(int i=0;iWidth;i++){ HAIR *hair = ((HAIR *)treatmentMap1+(tricot->Height-1)*tricot->Width+i); hair->pos[2].y+=height; hair->pos[3].y+=height; } ////////////////////////////HAIR µ¥ÀÌŸ ÃʱâÈ­ 4 for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ HAIR *hair = ((HAIR *)treatmentMap1+j*tricot->Width+i); hair->glx=tricot->RDistX; hair->gly=tricot->RDistY; hair->set_constant(); } } //////////////////////½ÇÁ¦ÀûÀÎ Àû¿ë Byte *p; if (!bmSrc->StartScanLine()) { goto fail; } for(int i=0;iWidth;i++){ percent->Percentage(i*100/tricot->Width); for(int j=0;jHeight;j++){ HAIR *hair = ((HAIR *)treatmentMap1+j*tricot->Width+i); TPlaneVertex pv; pv.Create(hair->pos[0], hair->pos[1], hair->pos[2], hair->pos[3]); if (hair->sqr[0]>0.0 && hair->sqr[1]>0.0 && hair->sqr[2]>0.0 && hair->sqr[3]>0.0) { for (int y = pv.start.y; y <= pv.end.y; y++) { int y2=y; while(y2<0){y2+=height;} y2%=height; p = bmSrc->GetScanLine(height-1-y2); for (int x = pv.start.x; x <= pv.end.x; x++) { int x2=x; while(x2<0){x2+=width;} x2%=width; int nx, ny; int bright; int x1, px1; if(Back) { x1 = 3 * x2; } else { x1 = 3 * (width-1-x2); } if (pv.Check(x, y)) { hair->find_point(x, y, nx, ny); HAIR *hair11 = ((HAIR *)treatmentMap1+j*tricot->Width+i); HAIR *hair21 = ((HAIR *)treatmentMap1+j*tricot->Width+(i+1)%tricot->Width); HAIR *hair12 = ((HAIR *)treatmentMap1+((j+1)%tricot->Height)*tricot->Width+i); HAIR *hair22 = ((HAIR *)treatmentMap1+((j+1)%tricot->Height)*tricot->Width+(i+1)%tricot->Width); double p11=(hair11->glx-nx)*(hair11->gly-ny); double p21=nx*(hair11->gly-ny); double p12=(hair11->glx-nx)*ny; double p22=nx*ny; p11=p11*p11; p12=p12*p12; p21=p21*p21; p22=p22*p22; double area=p11+p12+p21+p22; int cnt=4; if(!hair11->hasPile) { area-=p11; p11=0; cnt--;} if(!hair21->hasPile) { area-=p21; p21=0; cnt--;} if(!hair12->hasPile) { area-=p12; p12=0; cnt--;} if(!hair22->hasPile) { area-=p22; p22=0; cnt--;} if(cnt==0||area<=0) continue; double density=(0.55+cnt*0.1);//5%Á¤µµ´Â ¹éÁ¶Á÷À» º¸ÀÌ°Ô ÇÑ´Ù p11/=area; p21/=area; p12/=area; p22/=area; double seed=(rand()%100)/100.0; seed/=density; HAIR *hairp=NULL; if(seedhasPile==false) continue; int l=0; do{ l=rand()%MAX_LAYER_COUNT; } while(!hairp->yarn[l]); RGBQUAD rgb=TColorToRGB(hairp->yarn[l]->color); int v=(rand()%64-32); int b=rgb.rgbBlue+v; int g=rgb.rgbGreen+v; int r=rgb.rgbRed+v; if(b<0)b=0;if(b>255)b=255; if(g<0)g=0;if(g>255)g=255; if(r<0)r=0;if(r>255)r=255; p[x1]=(Byte)b; p[x1+1]=(Byte)g; p[x1+2]=(Byte)r; } } bmSrc->PutScanLine(height-1-y2); } } } } bmSrc->StopScanLine(); if(treatmentMap1) VirtualUnlock(treatmentMap1,tricot->Width*tricot->Height*sizeof(HAIR)); if(treatmentMap1) VirtualFree(treatmentMap1,tricot->Width*tricot->Height*sizeof(HAIR),MEM_DECOMMIT); treatmentMap1 = NULL; } else if(rgTreatmentMethod->ItemIndex==2){ treatmentMap2 = VirtualAlloc(NULL,tricot->Width*tricot->Height*sizeof(RAISE3D),MEM_COMMIT,PAGE_READWRITE); if(treatmentMap2) VirtualLock(treatmentMap2,tricot->Width*tricot->Height*sizeof(RAISE3D)); ////////////////////////////RAISE3D µ¥ÀÌŸ ÃʱâÈ­ 1 LEG *Leg; SLEG *SLeg; if(CourseTreat->Count){ for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ Octopus *octo = tricot->GetOctopus(i,j); if(octo->used!=true)continue; bool hasTreat=false; COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[j%CourseTreat->Count]; bool treat=false; int maxl=0; for(int k=0;kListOfLeg->Count;k++){//ÃÖ°íÃþÀÌ °¡°øµÇ´Â °¡¸¦ °Ë»ç Leg = (LEG *)octo->ListOfLeg->Items[k]; if(Leg->Layer>maxl){ treat=ct->layer[Leg->Layer]; maxl=Leg->Layer; } } if(treat){ for(int k=0;klayer[k]){ hasTreat=true; break; } } } RAISE3D *r3d = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); r3d->pos[0].x = tricot->FindRealPosX(octo,i,j); r3d->pos[0].y = tricot->FindRealPosY(octo,i,j); r3d->special=hasTreat; r3d->used=true; } } } for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ Octopus *octo = tricot->GetOctopus(i,j); if(octo->used!=true)continue; for(int k=0;kListOfLeg->Count;k++){ Leg = (LEG *)octo->ListOfLeg->Items[k]; if(Leg->ls==TOP_LEG||Leg->ls==TOP_LEG_FORCE) { for(int l=j;llink.y;l++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+(l%tricot->Height)*tricot->Width+i); r3d->special=false; } } } for(int k=0;kListOfSLeg->Count;k++){ SLeg = (SLEG *)octo->ListOfSLeg->Items[k]; if(SLeg->ls==TOP_LEG||SLeg->ls==TOP_LEG_FORCE) { for(int l=j;llink.y;l++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+(l%tricot->Height)*tricot->Width+i); r3d->special=false; } } } } } ////////////////////////////RAISE3D µ¥ÀÌŸ ÃʱâÈ­ 2 for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); if(r3d->used==false){ double x = tricot->RDistX*i; double y = tricot->RDistY*j; for(int j2=0;j2Height;j2++){ RAISE3D *r3d2 = ((RAISE3D *)treatmentMap2+((j+j2)%tricot->Height)*tricot->Width+i); if(r3d2->used){ x=r3d2->pos[0].x; break; } } for(int i2=0;i2Width;i2++){ RAISE3D *r3d2 = ((RAISE3D *)treatmentMap2+j*tricot->Width+(i+i2)%tricot->Width); if(r3d2->used){ y=r3d2->pos[0].y; break; } } r3d->pos[0].x=x; r3d->pos[0].y=y; } } } ////////////////////////////RAISE3D µ¥ÀÌŸ ÃʱâÈ­ 3 for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ RAISE3D *r3d11 = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); RAISE3D *r3d12 = ((RAISE3D *)treatmentMap2+j*tricot->Width+(i+1)%tricot->Width); RAISE3D *r3d21 = ((RAISE3D *)treatmentMap2+((j+1)%tricot->Height)*tricot->Width+i); RAISE3D *r3d22 = ((RAISE3D *)treatmentMap2+((j+1)%tricot->Height)*tricot->Width+(i+1)%tricot->Width); r3d11->pos[1]=r3d12->pos[0]; r3d11->pos[2]=r3d22->pos[0]; r3d11->pos[3]=r3d21->pos[0]; } } ////////////////////////////RAISE3D µ¥ÀÌŸ ÃʱâÈ­ 3-1 for(int j=0;jHeight;j++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+j*tricot->Width+tricot->Width-1); r3d->pos[1].x+=width; r3d->pos[2].x+=width; } for(int i=0;iWidth;i++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+(tricot->Height-1)*tricot->Width+i); r3d->pos[2].y+=height; r3d->pos[3].y+=height; } ////////////////////////////RAISE3D µ¥ÀÌŸ ÃʱâÈ­ 4 for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); r3d->glx=tricot->RDistX; r3d->gly=tricot->RDistY; r3d->set_constant(); } } ////////////////////////////·£´ýÇÔ¼ö ÀÌ¿ëÇÏ¿© Èİ¡°ø Àû¿ë for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); if(r3d->used){ if(r3d->special){ r3d->z=2.0; } else { r3d->z=0; } } else { r3d->z=0; } r3d->z+=0.1-(rand()%10)/50.0; } } ////////////Àû´çÈ÷ ¸Þµð¾È ¿¬»êÀ» ÅëÇØ z¸¦ ºÎµå·´°Ô Æîħ double MoveFactor=0.05; int TERM = 16; for(int n=0;nWidth*tricot->Height*TERM;n++){ int i=rand()%tricot->Width; int j=rand()%tricot->Height; int im1=(i-1+tricot->Width)%tricot->Width; int ip1=(i+1)%tricot->Width; int jm1=(j-1+tricot->Height)%tricot->Height; int jp1=(j+1)%tricot->Height; double v = ( ((RAISE3D *)treatmentMap2+jm1*tricot->Width+im1)->z+((RAISE3D *)treatmentMap2+jm1*tricot->Width+i)->z +((RAISE3D *)treatmentMap2+jm1*tricot->Width+ip1)->z+ ((RAISE3D *)treatmentMap2+j*tricot->Width+im1)->z +((RAISE3D *)treatmentMap2+j*tricot->Width+i)->z +((RAISE3D *)treatmentMap2+j*tricot->Width+ip1)->z+ ((RAISE3D *)treatmentMap2+jp1*tricot->Width+im1)->z+((RAISE3D *)treatmentMap2+jp1*tricot->Width+i)->z +((RAISE3D *)treatmentMap2+jp1*tricot->Width+ip1)->z )/9.0; ((RAISE3D *)treatmentMap2+j*tricot->Width+i)->z=v*MoveFactor+((RAISE3D *)treatmentMap2+j*tricot->Width+i)->z*(1.0-MoveFactor); } ////////////////////////////////¸í¾ÏÀ» Á¤ÇÑ´Ù Vector stand, light; stand.init3(0,0,1); light.init3(-5,10,30); // ±¤¿øÀÇ ¹æÇâÀ¸·Î ÀÓÀÇ·Î Á¤ÇÑ´Ù light.normal(); double increasefactor = 1.5; for(int i=0;iWidth;i++){ for(int j=0;jHeight;j++){ Vector v1,v2,v3; RAISE3D *r3d11 = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); RAISE3D *r3d21 = ((RAISE3D *)treatmentMap2+j*tricot->Width+(i+1)%tricot->Width); RAISE3D *r3d12 = ((RAISE3D *)treatmentMap2+((j+1)%tricot->Height)*tricot->Width+i); RAISE3D *r3d22 = ((RAISE3D *)treatmentMap2+((j+1)%tricot->Height)*tricot->Width+(i+1)%tricot->Width); v1.init3(0,1,r3d12->z-r3d11->z); v2.init3(1,0,r3d21->z-r3d11->z); v3.init(3); v3.cross(v2,v1); if(v3.length()<=0){ r3d11->brt=0.5; } else { v3.normal(); double angle = light.dot(v3); // -1 <= angle <= 1 if(angle<=0){ r3d11->brt=0; } else { r3d11->brt = -0.4+r3d11->z/5.0+angle*increasefactor; } } } } //////////////////////½ÇÁ¦ÀûÀÎ Àû¿ë Byte *p; if (!bmSrc->StartScanLine()) { goto fail; } for(int i=0;iWidth;i++){ percent->Percentage(i*100/tricot->Width); for(int j=0;jHeight;j++){ RAISE3D *r3d = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); TPlaneVertex pv; pv.Create(r3d->pos[0], r3d->pos[1], r3d->pos[2], r3d->pos[3]); if (r3d->sqr[0]>0.0 && r3d->sqr[1]>0.0 && r3d->sqr[2]>0.0 && r3d->sqr[3]>0.0) { for (int y = pv.start.y; y <= pv.end.y; y++) { int y2=y; while(y2<0){y2+=height;} y2%=height; p = bmSrc->GetScanLine(height-1-y2); for (int x = pv.start.x; x <= pv.end.x; x++) { int x2=x; while(x2<0){x2+=width;} x2%=width; int nx, ny; int bright; int x1, px1; if(Back) { x1 = 3 * x2; } else { x1 = 3 * (width-1-x2); } if (pv.Check(x, y)) { r3d->find_point(x, y, nx, ny); RAISE3D *r3d11 = ((RAISE3D *)treatmentMap2+j*tricot->Width+i); RAISE3D *r3d21 = ((RAISE3D *)treatmentMap2+j*tricot->Width+(i+1)%tricot->Width); RAISE3D *r3d12 = ((RAISE3D *)treatmentMap2+((j+1)%tricot->Height)*tricot->Width+i); RAISE3D *r3d22 = ((RAISE3D *)treatmentMap2+((j+1)%tricot->Height)*tricot->Width+(i+1)%tricot->Width); double v = (r3d11->brt*(1.0-nx/r3d11->glx)+r3d21->brt*(nx/r3d11->glx))*(1.0-ny/r3d11->gly) + (r3d12->brt*(1.0-nx/r3d11->glx)+r3d22->brt*(nx/r3d11->glx))*(ny/r3d11->gly); int c1,c2,c3; c1 = p[x1]*v; c2 = p[x1+1]*v; c3 = p[x1+2]*v; if(c1<0)c1=0; if(c2<0)c2=0; if(c3<0)c3=0; if(c1>255)c1=255; if(c2>255)c2=255; if(c3>255)c3=255; p[x1]=c1; p[x1+1]=c2; p[x1+2]=c3; } } bmSrc->PutScanLine(height-1-y2); } } } } bmSrc->StopScanLine(); if(treatmentMap2) VirtualUnlock(treatmentMap2,tricot->Width*tricot->Height*sizeof(RAISE3D)); if(treatmentMap2) VirtualFree(treatmentMap2,tricot->Width*tricot->Height*sizeof(RAISE3D),MEM_DECOMMIT); treatmentMap2 = NULL; } dcDst = bmDst->CreateDC(); if(dcDst==NULL){ goto fail; } dcSrc = bmSrc->CreateDC(); for(int i=0;i<=bmDst->Width/width;i++){ for(int j=0;j<=bmDst->Height/height;j++){ BitBlt(dcDst, i*width, j*height, width, height, dcSrc, 0, 0, SRCCOPY); } } bmDst->DeleteDC(dcDst); bmSrc->DeleteDC(dcSrc); if(bmSrc) delete bmSrc; percent->Percentage(100); return; fail: if(dcSrc) bmSrc->DeleteDC(dcSrc); if(bmSrc) delete bmSrc; percent->Percentage(100); ShowMessage(IDS_MESSAGE_TOO_LARGE_BITMAP_ZOOM_REPEAT); } //--------------------------------------------------------------------------- bool __fastcall TTreatment_F::ReadFromFile(HANDLE hFile, int main_ver){ DWORD dwRead; int index=0; int courseCnt; bool check1=false; bool check2=false; bool check3=false; bool check4=false; Reset(); try{ if(main_ver>=100){ int ver; ReadFile(hFile, &ver, sizeof(int), &dwRead, NULL); if(ver>=1){ ReadFile(hFile, &index, sizeof(int), &dwRead, NULL); if(ver<2){ ReadFile(hFile, &check1, sizeof(bool), &dwRead, NULL); ReadFile(hFile, &check2, sizeof(bool), &dwRead, NULL); ReadFile(hFile, &check3, sizeof(bool), &dwRead, NULL); ReadFile(hFile, &check4, sizeof(bool), &dwRead, NULL); } else { int maxLayerCnt; if(ver < 3) maxLayerCnt = 4; else if(ver < 4) maxLayerCnt = 5; else maxLayerCnt = MAX_LAYER_COUNT; ReadFile(hFile, &courseCnt, sizeof(int), &dwRead, NULL); SetHeight(courseCnt); for(int i=0;iItems[i]; ReadFile(hFile, ct, maxLayerCnt, &dwRead, NULL); } } /* if(ver>=2 && ver<3){ ReadFile(hFile, &courseCnt, sizeof(int), &dwRead, NULL); SetHeight(courseCnt); for(int i=0;iItems[i]; ReadFile(hFile, ct, 4/ * = sizeof(COURSE_TREATMENT)* /, &dwRead, NULL); } } else if(ver>=3) {//gabriel ReadFile(hFile, &courseCnt, sizeof(int), &dwRead, NULL); SetHeight(courseCnt); for(int i=0;iItems[i]; ReadFile(hFile, ct, MAX_LAYER_COUNT/ * = sizeof(COURSE_TREATMENT)* /, &dwRead, NULL); } } */ } } else if(main_ver>=1){ ReadFile(hFile, &index, sizeof(int), &dwRead, NULL); ReadFile(hFile, &check1, sizeof(bool), &dwRead, NULL); ReadFile(hFile, &check2, sizeof(bool), &dwRead, NULL); ReadFile(hFile, &check3, sizeof(bool), &dwRead, NULL); ReadFile(hFile, &check4, sizeof(bool), &dwRead, NULL); } rgTreatmentMethod->ItemIndex=index; } catch(...){ ShowMessage(IDS_MESSAGE_LOAD_FAIL); return false; } Tex *tex = (Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; if(tex->Curve->Count!=CourseTreat->Count)SetHeight(tex->Curve->Count); return true; } //--------------------------------------------------------------------------- bool __fastcall TTreatment_F::SaveToFile(HANDLE hFile){ Tex *tex = (Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; if(tex->Curve->Count!=CourseTreat->Count)SetHeight(tex->Curve->Count); DWORD dwWrite; int index=rgTreatmentMethod->ItemIndex; if(index>=rgTreatmentMethod->Items->Count||index<0)index=0; try{ int ver=4;//gabriel. ver=2: 4bar , ver=3: 5bar, ver=4: 6bar WriteFile(hFile, &ver, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &index, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &(CourseTreat->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[i]; WriteFile(hFile, ct, sizeof(COURSE_TREATMENT), &dwWrite, NULL); } }catch(...){ ShowMessage(IDS_MESSAGE_SAVE_FAIL); return false; } return true; } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::FormCreate(TObject *Sender) { CourseTreat = new TList; sgCourse->ColCount = 2; sgCourse->RowCount = 20; sgCourse->DefaultRowHeight = 25; sgCourse->ColWidths[0] = 77; sgCourse->ColWidths[1] = 200; sgCourse->FixedCols=1; SetFont(); StringTable.Create(BaseDir, Language, "Treatment"); Caption=IDS_TREATMENT_SET; sbAll->Caption=IDS_CHECK_ALL; rgTreatmentMethod->Caption=IDS_TREATMENT_METHOD; rgTreatmentMethod->Items->Clear(); rgTreatmentMethod->Items->Add(IDS_NONE); rgTreatmentMethod->Items->Add(IDS_HAIR); rgTreatmentMethod->Items->Add(IDS_RAISE); rgTreatmentMethod->ItemIndex=0; } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::SetFont(){ SetSmallFont(Font); SetSmallFont(lbLayer->Font); } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::FormDestroy(TObject *Sender) { if(CourseTreat){ while(CourseTreat->Count){ delete (COURSE_TREATMENT *)CourseTreat->Last(); CourseTreat->Remove(CourseTreat->Last()); } delete CourseTreat; } CourseTreat = NULL; } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::FormPaint(TObject *Sender) { lbLayer->Caption="Layer "+IntToStr(Main->LayerNum+1); sgCourse->RowCount = CourseTreat->Count>20 ? CourseTreat->Count+10 : 30; sgCourse->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::sgCourseDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { Tex *tex = (Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; if(tex->Curve->Count!=CourseTreat->Count)SetHeight(tex->Curve->Count); AnsiString str; sgCourse->Canvas->Font->Size=10; switch(ACol){ case 0: { if(ARow==0){ str = IDS_COURSE; sgCourse->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1Count){ sgCourse->Canvas->Font->Color = clWhite; str=IntToStr(ARow); } } break; } case 1: { if(ARow==0){ str = IDS_TREATMENT; sgCourse->Canvas->Font->Color = clWhite; } else { if(ARow-1Count){ COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[ARow-1]; if(ct->layer[Main->LayerNum]){ str="O"; } else { str="X"; } } } break; } default: break; } if(sgCourse->Cells[ACol][ARow]!="")sgCourse->Cells[ACol][ARow]=""; int x = ((Rect.right-Rect.left) - sgCourse->Canvas->TextWidth(str)) / 2; int y = ((Rect.bottom-Rect.top) - sgCourse->Canvas->TextHeight(str)) / 2; sgCourse->Canvas->TextOut(Rect.Left + x, Rect.Top + y, str); } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::edCourseInputKeyPress(TObject *Sender, char &Key) { Tex *tex = (Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; if(tex->Curve->Count!=CourseTreat->Count)SetHeight(tex->Curve->Count); switch(sgCourse->Col){ case 0: break; case 1: { if(Key==VK_RETURN){ if(edCourseInput->Text=="")return; bool v=true; if(edCourseInput->Text=="0"||edCourseInput->Text=="O"||edCourseInput->Text=="o"){ v=true; } else { v=false; } for(int j=sgCourse->Selection.Top;j<=sgCourse->Selection.Bottom;j++){ if(j-1Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ//Curve´Â 0ºÎÅͽÃÀÛ//Row-1==Curve COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[j-1]; ct->layer[Main->LayerNum]=v; } } edCourseInput->Text=""; sgCourse->Repaint(); //sgCourse->Row++; } break; } default: break; } } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::sgCourseClick(TObject *Sender) { edCourseInput->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::edCourseInputKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { switch(Key){ case VK_LEFT: { if(sgCourse->Col>sgCourse->FixedCols) sgCourse->Col--; break; } case VK_RIGHT: { if(sgCourse->ColColCount-1) sgCourse->Col++; break; } case VK_UP: { if(sgCourse->Row>sgCourse->FixedRows) sgCourse->Row--; break; } case VK_DOWN: { if(sgCourse->RowRowCount-1) sgCourse->Row++; break; } } } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::sgCourseMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { int ACol,ARow; sgCourse->MouseToCell(X, Y, ACol, ARow); Tex *tex = (Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; if(tex->Curve->Count!=CourseTreat->Count)SetHeight(tex->Curve->Count); switch(ACol){ case 1: { if(!Shift.Contains(ssLeft))break; if(ARow!=0&&ARow-1Count){ COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[ARow-1]; ct->layer[Main->LayerNum]=!ct->layer[Main->LayerNum]; } break; } default: break; } sgCourse->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::SetHeight(int h){ if(CourseTreat->Count>h){ while(CourseTreat->Count>h){ delete (COURSE_TREATMENT *)CourseTreat->Last(); CourseTreat->Remove(CourseTreat->Last()); } } else { while(CourseTreat->Countlayer[i]=false; CourseTreat->Add(ct); } } } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::Reset(){ rgTreatmentMethod->ItemIndex=0; if(CourseTreat){ while(CourseTreat->Count){ delete (COURSE_TREATMENT *)CourseTreat->Last(); CourseTreat->Remove(CourseTreat->Last()); } //delete CourseTreat; } } //--------------------------------------------------------------------------- void __fastcall TTreatment_F::sbAllClick(TObject *Sender) { bool check=false; if(CourseTreat->Count){ COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[0]; check=ct->layer[Main->LayerNum]; } for(int j=0;jCount;j++){ COURSE_TREATMENT *ct = (COURSE_TREATMENT *)CourseTreat->Items[j]; ct->layer[Main->LayerNum]=!check; } sgCourse->Repaint(); } //---------------------------------------------------------------------------