<div> <div>//------------------------원본코드 함수<span style="font-size:9pt;">------------------------</span></div> <div>float<span style="white-space:pre;"> </span>TFractalDimension::Calculate(TStringGrid *S)</div> <div>{</div> <div>float<span style="white-space:pre;"> </span>MinD=10;</div> <div>float<span style="white-space:pre;"> </span>MaxD=50;</div> <div>float<span style="white-space:pre;"> </span>W=(float)Image->Width;</div> <div>float H=(float)Image->Height;</div> <div>int<span style="white-space:pre;"> </span>TH=128;</div> <div><br></div> <div>S->RowCount=(int)MaxD-(int)MinD+1;</div> <div><br></div> <div>int <span style="white-space:pre;"> </span>i,n,x,y,x1,y1,count;</div> <div>float<span style="white-space:pre;"> </span>size,xx,yy,xs,ys;</div> <div>bool<span style="white-space:pre;"> </span>found;</div> <div><br></div> <div>AnsiString<span style="white-space:pre;"> </span>N;</div> <div>for(i=0;i<S->RowCount;i++){</div> <div><span style="white-space:pre;"> </span>n=(int)MaxD-i;</div> <div><span style="white-space:pre;"> </span>S->Cells[0][i]=AnsiString(n*n);</div> <div><span style="white-space:pre;"> </span>size=W/(float)n;</div> <div><span style="white-space:pre;"> </span>count=0;</div> <div><span style="white-space:pre;"> </span>for(x=0;x<n;x++){</div> <div><span style="white-space:pre;"> </span>for(y=0;y<n;y++){</div> <div><span style="white-space:pre;"> </span>xs=(float)x*size;</div> <div><span style="white-space:pre;"> </span>ys=(float)y*size;</div> <div><span style="white-space:pre;"> </span>found=false;</div> <div><span style="white-space:pre;"> </span>xx=xs;</div> <div><span style="white-space:pre;"> </span>while(xx<xs+size && !found){</div> <div><span style="white-space:pre;"> </span>yy=ys;</div> <div><span style="white-space:pre;"> </span>while(yy<ys+size && !found){</div> <div><span style="white-space:pre;"> </span>x1=(int)xx;</div> <div><span style="white-space:pre;"> </span>y1=(int)yy;</div> <div><span style="white-space:pre;"> </span>if (x1>=0 && x1<(int)W && y1>=0 && y1<(int)H){</div> <div><span style="white-space:pre;"> </span>BYTE *L=(BYTE*)Image->ScanLine[y1];</div> <div><span style="white-space:pre;"> </span>int G=(L[x1*3]+L[x1*3+1]+L[x1*3+2])/3;</div> <div><span style="white-space:pre;"> </span>if (G<TH) found=true;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>yy+=1;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>xx+=1;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>if (found) count++;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>S->Cells[1][i]=AnsiString(count);</div> <div><span style="white-space:pre;"> </span>}</div> <div><br></div> <div>n=S->RowCount;</div> <div>float<span style="white-space:pre;"> </span>*X=new float[n];</div> <div>float<span style="white-space:pre;"> </span>*Y=new float[n];</div> <div><br></div> <div>for(i=0;i<n;i++){</div> <div><span style="white-space:pre;"> </span>X[i]=(float)log10(sqrt(S->Cells[0][i].ToDouble()));</div> <div><span style="white-space:pre;"> </span>Y[i]=(float)log10(S->Cells[1][i].ToDouble());</div> <div><span style="white-space:pre;"> </span>}</div> <div>float<span style="white-space:pre;"> </span>a,b;</div> <div>RegressionAnalysis(n,X,Y,a,b);</div> <div>delete[]X;</div> <div>delete[]Y;</div> <div>return fabs(a);</div> <div>}</div> <div><br></div> <div>void<span style="white-space:pre;"> </span>TFractalDimension::RegressionAnalysis(int n,float *x,float *y,float &a,float &b)</div> <div>{</div> <div>float<span style="white-space:pre;"> </span>xs,ys,xss,xys;</div> <div>xs=ys=xss=xys=0;</div> <div>int<span style="white-space:pre;"> </span>i;</div> <div>for(i=0;i<n;i++){</div> <div><span style="white-space:pre;"> </span>xs+=x[i];</div> <div><span style="white-space:pre;"> </span>ys+=y[i];</div> <div><span style="white-space:pre;"> </span>xss+=x[i]*x[i];</div> <div><span style="white-space:pre;"> </span>xys+=x[i]*y[i];</div> <div><span style="white-space:pre;"> </span>}</div> <div>a=((float)n*xys-xs*ys)/((float)n*xss-xs*xs);</div> <div>b=y[0]-a*x[0];</div> <div>}</div></div> <div><br></div> <div><br></div> <div>//------------------------수정중인 코드 함수<span style="font-size:9pt;">------------------------</span></div> <div>float TFractalDimension::Calculate(TStringGrid *StrGrid) {</div> <div><span style="white-space:pre;"> </span>float MinD = 10;</div> <div><span style="white-space:pre;"> </span>float MaxD = 50;</div> <div><span style="white-space:pre;"> </span>float Width = (float)Image->Width;</div> <div><span style="white-space:pre;"> </span>float Height = (float)Image->Height;</div> <div><span style="white-space:pre;"> </span>int threshold = 128;</div> <div><br></div> <div><span style="white-space:pre;"> </span>StrGrid->RowCount = (int)MaxD - (int)MinD + 1;</div> <div><br></div> <div><span style="white-space:pre;"> </span>int nowD, x1, y1, count;</div> <div><span style="white-space:pre;"> </span>float size, xx, yy, x2Size, y2Size;</div> <div><span style="white-space:pre;"> </span>bool found;</div> <div><br></div> <div><span style="white-space:pre;"> </span>for (int i = 0; i < StrGrid->RowCount; i++) {</div> <div><span style="white-space:pre;"> </span>nowD = (int)MaxD - i;</div> <div><span style="white-space:pre;"> </span>StrGrid->Cells[0][i] = IntToStr(nowD * nowD);</div> <div><span style="white-space:pre;"> </span>size = Width / (float)nowD;</div> <div><span style="white-space:pre;"> </span>count = 0;</div> <div><span style="white-space:pre;"> </span>for (int x = 0; x < nowD; x++) {</div> <div><span style="white-space:pre;"> </span>for (int y = 0; y < nowD; y++) {</div> <div><span style="white-space:pre;"> </span>x2Size = (float)x * size;</div> <div><span style="white-space:pre;"> </span>y2Size = (float)y * size;</div> <div><span style="white-space:pre;"> </span>found = false;</div> <div><span style="white-space:pre;"> </span>xx = x2Size;</div> <div><span style="white-space:pre;"> </span>while (xx < x2Size + size && !found) {</div> <div><span style="white-space:pre;"> </span>yy = y2Size;</div> <div><span style="white-space:pre;"> </span>while (yy < y2Size + size && !found) {</div> <div><span style="white-space:pre;"> </span>x1 = (int)xx;</div> <div><span style="white-space:pre;"> </span>y1 = (int)yy;</div> <div><span style="white-space:pre;"> </span>if (x1 >= 0 && x1 < (int)Width && y1 >= 0 && y1 < (int)Height) {</div> <div><span style="white-space:pre;"> </span>BYTE *L = (BYTE*)Image->ScanLine[y1];</div> <div><span style="white-space:pre;"> </span>int G = (L[x1 * 3] + L[x1 * 3 + 1] +</div> <div><span style="white-space:pre;"> </span>L[x1 * 3 + 2]) / 3;</div> <div><span style="white-space:pre;"> </span>if (G < threshold)</div> <div><span style="white-space:pre;"> </span>found = true;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>yy += 1;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>xx += 1;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>if (found)</div> <div><span style="white-space:pre;"> </span>count++;</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>StrGrid->Cells[1][i] = AnsiString(count);</div> <div><span style="white-space:pre;"> </span>}</div> <div><br></div> <div><span style="white-space:pre;"> </span>nowD = StrGrid->RowCount;</div> <div><span style="white-space:pre;"> </span>float *X = new float[nowD];</div> <div><span style="white-space:pre;"> </span>float *Y = new float[nowD];</div> <div><br></div> <div><span style="white-space:pre;"> </span>for (int i = 0; i < nowD; i++) {</div> <div><span style="white-space:pre;"> </span>X[i] = (float)log10(sqrt(StrGrid->Cells[0][i].ToDouble()));</div> <div><span style="white-space:pre;"> </span>Y[i] = (float)log10(StrGrid->Cells[1][i].ToDouble());</div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>float a, b;</div> <div><span style="white-space:pre;"> </span>RegressionAnalysis(nowD, X, Y, a, b);</div> <div><span style="white-space:pre;"> </span>delete[]X;</div> <div><span style="white-space:pre;"> </span>delete[]Y;</div> <div><span style="white-space:pre;"> </span>return fabs(a);</div> <div>}</div> <div><br></div> <div>/*</div> <div>이 긴 함수를 재멋대로인 변수명으로 괴롭히는 저자때문에 맨붕이 옵니다.</div> <div>그나마 조금씩 수정하긴 하는대 수정할때마다 드는 생각이 '이걸 왜 이따구로 썻지?' 라는 생각....</div> <div>2012년도에 발행된 '엔지니어를 위한 C++ 빌더 프로그래밍의 기초' 라는 책인대 진심 변수 네이밍 샌스가 바닥이고</div> <div>쓸대없이 코드를 늘리는 부분이 많아 공부하기가 난해합니다.</div> <div><br></div> <div>만약 <span style="font-size:9pt;">'엔지니어를 위한 C++ 빌더 프로그래밍의 기초'란 책을 보려하신 분이 있다면 보지 마세요</span></div> <div><span style="font-size:9pt;">쥐뢰입니다.</span></div> <div>*/</div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.