void DrImage::Cut(){ char cImage[160]; sprintf(cImage,"Small.png"); double pixel[4]; double xBound[2] = {.5,.75}; double yBound[2] = {.2,.45}; int xNBound[2]; int yNBound[2]; for(int d=0;d<2;d++){ xNBound[d] = (int)(xBound[d]*NWidth); yNBound[d] = (int)(yBound[d]*NHeight); printf("%d %d %d %d\n",xNBound[d],NWidth,yNBound[d],NHeight); } int Dx = xNBound[1]-xNBound[0]; int Dy = yNBound[1]-yNBound[0]; double *Plot = new double[Dx*Dy]; Matematica *Mat = new Matematica; //VarData *Var = new VarData; Matrice *ImIn = new Matrice(Dx,Dy); pngwriter ImageOut(xNBound[1]-xNBound[0],yNBound[1]-yNBound[0],1.0,cImage); double Average = 0.; double Count = 0.; for(int h=yNBound[0];h<yNBound[1];h++){ for(int w=xNBound[0];w<xNBound[1];w++){ int hh = h -yNBound[0]; int ww = w -xNBound[0]; double Sum = data[0][h*NWidth+w]+data[1][h*NWidth+w]+data[2][h*NWidth+w]; //Sum *= .5; // ImageOut.plot(ww,hh,data[0][h*NWidth+w],data[1][h*NWidth+w],data[2][h*NWidth+w]); ImIn->Set(ww,hh,Sum); Plot[hh*Dx+ww] = Sum; } } for(int h=0;h<Dy;h++){ for(int w=0;w<Dx;w++){ //if(ImIn->Val(w,h) >= 0.) ImageOut.plot(w,h,10.*ImIn->Val(w,h),ImIn->Val(w,h),ImIn->Val(w,h)); } } ImageOut.close(); delete [] Plot; }
void Forces::FillMatrix(){ if(!IfFillMatrix) return; IntMatrix->Clear(); double Inter = pEdge(CLat1)/(double)NEdge;//fabs(pPos(1,0) - pPos(0,0)); SPLINE Weight; Weight.a0 = Kf.El[2]; Weight.a1 = 0./Inter; Weight.a2 = Kf.Lap/SQR(Inter); Weight.a3 = 0./(Inter*SQR(Inter)); Weight.a4 = Kf.SLap/(SQR(Inter)*SQR(Inter)); if(VAR_IF_TYPE(SysShape,SYS_ROD)){ int NDim = 1; Matrice *CoeffMatrix = new Matrice(Weight,NDim); CoeffMatrix->Print(); for(int r=0;r<pNPart();r++){ if(Pm[r].Typ != 0){ IntMatrix->Set(r,r,1.);continue;} if(r >= 2) IntMatrix->Set(r,r-2,CoeffMatrix->Val(2,0)); if(r >= 1) IntMatrix->Set(r,r-1,CoeffMatrix->Val(2,1)); if(r < pNPart()-1) IntMatrix->Set(r,r+1,CoeffMatrix->Val(2,3)); if(r < pNPart()-2) IntMatrix->Set(r,r+2,CoeffMatrix->Val(2,4)); IntMatrix->Set(r,r,CoeffMatrix->Val(2,2)); } IntMatrix->Invert(); //IntMatrix->Print(); delete CoeffMatrix; } else if(VAR_IF_TYPE(SysShape,SYS_LEAVES)){ int NDim = 1; Matrice *CoeffMatrix = new Matrice(Weight,NDim); CoeffMatrix->Print(); for(int r=0;r<pNPCh();r++){ if(Pm[r].Typ != 0){ IntMatrix->Set(r,r,1.);continue;} if(r >= 2) IntMatrix->Set(r,r-2,CoeffMatrix->Val(2,0)); if(r >= 1) IntMatrix->Set(r,r-1,CoeffMatrix->Val(2,1)); if(r < pNPart()-1) IntMatrix->Set(r,r+1,CoeffMatrix->Val(2,3)); if(r < pNPart()-2) IntMatrix->Set(r,r+2,CoeffMatrix->Val(2,4)); IntMatrix->Set(r,r,CoeffMatrix->Val(2,2)); } //IntMatrix->Invert(); IntMatrix->Print(); delete CoeffMatrix; } else if(VAR_IF_TYPE(SysShape,SYS_2D)){ int NDim = 2; Matrice *CoeffMatrix = new Matrice(Weight,NDim); CoeffMatrix->Print(); for(int p=0;p<pNPart();p++){ if(Pm[p].Typ != 0){ IntMatrix->Set(p,p,1.); continue; } int pym1 = Ln[p].Link[0]; int pyp1 = Ln[p].Link[1]; int pym2 = Ln[pym1].Link[0]; int pyp2 = Ln[pyp1].Link[1]; int pxm1 = Ln[p].Link[2]; int pxp1 = Ln[p].Link[3]; int pxm2 = Ln[pxm1].Link[2]; int pxp2 = Ln[pxp1].Link[3]; // printf("%d)\n",p); //printf("%d %d %d %d\n",pym2,pym1,pyp1,pyp2); // printf("%d %d %d %d\n",pxm2,pxm1,pxp1,pxp2); if(PeriodicImage[0]){ IntMatrix->Set(p,pxm2,CoeffMatrix->Val(2,0)); IntMatrix->Set(p,pxm1,CoeffMatrix->Val(2,1)); IntMatrix->Set(p,pxp1,CoeffMatrix->Val(2,3)); IntMatrix->Set(p,pxp2,CoeffMatrix->Val(2,4)); } else{ if(pxm2 == p-2*nEdge[1]) IntMatrix->Set(p,pxm2,CoeffMatrix->Val(2,0)); if(pxm1 == p-nEdge[1]) IntMatrix->Set(p,pxm1,CoeffMatrix->Val(2,1)); if(pxp1 == p+nEdge[1]) IntMatrix->Set(p,pxp1,CoeffMatrix->Val(2,3)); if(pxp2 == p+2*nEdge[1]) IntMatrix->Set(p,pxp2,CoeffMatrix->Val(2,4)); } IntMatrix->Add(p,p,CoeffMatrix->Val(2,2)); if(PeriodicImage[1]){ IntMatrix->Set(p,pym2,CoeffMatrix->Val(2,0)); IntMatrix->Set(p,pym1,CoeffMatrix->Val(2,1)); IntMatrix->Set(p,pyp1,CoeffMatrix->Val(2,3)); IntMatrix->Set(p,pyp2,CoeffMatrix->Val(2,4)); } else{ if(pym2 == p-2) IntMatrix->Set(p,pym2,CoeffMatrix->Val(2,0)); if(pym1 == p-1) IntMatrix->Set(p,pym1,CoeffMatrix->Val(2,1)); if(pyp1 == p+1) IntMatrix->Set(p,pyp1,CoeffMatrix->Val(2,3)); if(pyp2 == p+2) IntMatrix->Set(p,pyp2,CoeffMatrix->Val(2,4)); } } IntMatrix->Invert(); //IntMatrix->Print(); delete CoeffMatrix; } IfFillMatrix = 0; }