Main Page   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

MDINPR.cpp

00001 //---------------------------------------------------------------------------
00002 
00003 #include <vcl.h>
00004 #include <math.h>
00005 #pragma hdrstop
00006 
00007 #include "MDINPR.h"
00008 #include "MDIEdit.h"
00009 #include "MDIFrame.h"
00010 #define MIN(x,y)        ((x<y) ? (x) : (y))
00011 #define MAX(x,y)        ((x>y) ? (x) : (y))
00012 //---------------------------------------------------------------------------
00013 #pragma package(smart_init)
00014 #pragma resource "*.dfm"
00015 TNPRForm *NPRForm;
00016 rgb *NPRview;
00017 
00018 float ghisto[128];
00019 const float pi=3.141592;
00020 const float pid2=2*pi;
00021 const float pih=pi/2;
00022 const float pirad=pi/180;
00023 //---------------------------------------------------------------------------
00024 __fastcall TNPRForm::TNPRForm(TComponent* Owner)
00025         : TForm(Owner)
00026 {
00027 }
00028 //---------------------------------------------------------------------------
00029 void __fastcall TNPRForm::SetPixelFormatDescriptor()
00030 {
00031     PIXELFORMATDESCRIPTOR pfd = {
00032         sizeof(PIXELFORMATDESCRIPTOR),
00033         1,
00034         PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
00035         PFD_TYPE_RGBA,
00036         24,
00037         0,0,0,0,0,0,
00038         0,0,
00039         0,0,0,0,0,
00040         32,
00041         0,
00042         0,
00043         PFD_MAIN_PLANE,
00044         0,
00045         0,0,
00046     };
00047     PixelFormat = ChoosePixelFormat(hdc, &pfd);
00048     SetPixelFormat(hdc, PixelFormat, &pfd);
00049 }
00050 
00051 //---------------------------------------------------------------------
00052 void __fastcall TNPRForm::FormClose(TObject *Sender, TCloseAction &Action)
00053 {
00054 delete [] NPRview;
00055 Action=caFree;
00056 FrameForm->NPR->Checked = false;
00057 memusage = memusage - 3*1024*1024;
00058 FrameForm->memupdate();
00059 wglDeleteContext(hrc);
00060 ReleaseDC(Handle,hdc);
00061 }
00062 //---------------------------------------------------------------------
00063 void __fastcall TNPRForm::FormCreate(TObject *Sender)
00064 {
00065     int i,a;
00066 
00067     vr = SFGColor->Brush->Color & 255;
00068     vg = (SFGColor->Brush->Color >> 8) & 255;
00069     vb = (SFGColor->Brush->Color >> 16) & 255;
00070     lr = SBGColor->Brush->Color & 255;
00071     lg = (SBGColor->Brush->Color >> 8) & 255;
00072     lb = (SBGColor->Brush->Color >> 16) & 255;
00073 
00074     ghistomax = 0;
00075     for (i=0; i<128; i++) { ghisto[i]=0;}
00076     for (i=0; i<size; i++) { ghisto[absgrad[i]/32]++; }
00077     for (i=1; i<128; i++) {
00078         if (ghisto[i]>ghistomax) {ghistomax=ghisto[i];}
00079         }
00080     for (i=0; i<128; i++) { ghisto[i]=ghisto[i]*40/ghistomax; }
00081 
00082     if (ghisto[0]>40) ghisto[0]=40;
00083     gmin = 1; gmax = 127; gdragmin = false; gdragmax=false;
00084     garea->Canvas->Pen->Color = clBlack;
00085     garea->Canvas->Brush->Color = clWhite;
00086     NPRview = new rgb[1024*1024];
00087     memusage = memusage + 3*1024*1024;
00088     FrameForm->memupdate();
00089 
00090     mrotx=0; mroty=0;xres=128;yres=128;thresh = 400;
00091     hdc = GetDC(Handle);
00092     SetPixelFormatDescriptor();
00093     hrc = wglCreateContext(hdc);
00094     if(hrc == NULL) ShowMessage("Could not create DC!");
00095     wglMakeCurrent(hdc, hrc);
00096 
00097     w = ClientWidth;
00098     h = ClientHeight;
00099 
00100     glEnable(GL_DEPTH_TEST);
00101     glEnable(GL_CULL_FACE);
00102 
00103     glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
00104     glOrtho (-50.0,50.0,-50.0,50.0,-50.0,50.0);
00105 
00106     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00107     glFlush();
00108     SwapBuffers(hdc);
00109     FormResize(Sender);
00110     RayCast();
00111 }
00112 //---------------------------------------------------------------------
00113 void __fastcall TNPRForm::FormResize(TObject *Sender)
00114 {
00115         PrepareGLWindow();
00116         if (autores->Checked && arepaint->Checked) {RayCast();}
00117         PaintGL();
00118 }
00119 //---------------------------------------------------------------------------
00120 void __fastcall TNPRForm::FormPaint(TObject *Sender)
00121 {
00122         PaintGL();
00123 }
00124 //---------------------------------------------------------------------------
00125 void __fastcall TNPRForm::PaintGL()
00126 {
00127         float i;
00128 
00129         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00130         PrepareGLWindow();
00131         glColor3f(0.6f,0.6f,0.6f);
00132         glLineWidth(3.0f);
00133         glBegin(GL_LINE_STRIP);
00134         glVertex3f(-50,-50,0);
00135         glVertex3f(50,-50,0);
00136         glVertex3f(50,50,0);
00137         glVertex3f(-50,50,0);
00138         glVertex3f(-50,-50,0);
00139         glEnd();
00140 
00141         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
00142         glDrawPixels(xres, yres, GL_RGB, GL_UNSIGNED_BYTE,NPRview);
00143                         // we use unsigned byte (char) to meet speed issues.
00144                         // 16 bit data (__int16) slows down drawing to much.
00145 
00146         glFlush();
00147         SwapBuffers(hdc);
00148 }
00149 
00150 void __fastcall TNPRForm::PrepareGLWindow()
00151 {
00152         wglMakeCurrent(hdc, hrc);
00153 
00154         GLfloat nRange = 50.0;
00155         w = ClientWidth-200;
00156         h = ClientHeight;
00157 
00158         if(h == 0) h = 1;
00159         if(w == 0) w = 1;
00160 
00161         glViewport(200, 0, w, h);
00162         glLoadIdentity();
00163 
00164         if (w <= h)
00165         {        glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
00166                 glPixelZoom((float)w/(float)xres, (float)w/(float)yres);}
00167          else
00168         {        glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
00169                 glPixelZoom((float)h/(float)xres, (float)h/(float)yres);}
00170 
00171         glRasterPos2d(-50,-50);
00172 }
00173 //---------------------------------------------------------------------------
00174 
00175 void __fastcall TNPRForm::FormActivate(TObject *Sender)
00176 {
00177         PaintGL();        
00178 }
00179 //---------------------------------------------------------------------------
00180 
00181 void __fastcall TNPRForm::Button1Click(TObject *Sender)
00182 {
00183 RayCast();
00184 PaintGL();
00185 }
00186 //---------------------------------------------------------------------------
00187 
00188 
00189 
00190 void __fastcall TNPRForm::FormMouseDown(TObject *Sender,
00191       TMouseButton Button, TShiftState Shift, int X, int Y)
00192 {
00193 mdown=true;
00194 ox = X;
00195 oy = Y;
00196 }
00197 //---------------------------------------------------------------------------
00198 
00199 
00200 
00201 void __fastcall TNPRForm::FormMouseUp(TObject *Sender,
00202       TMouseButton Button, TShiftState Shift, int X, int Y)
00203 {
00204 mdown=false;
00205 RayCast();
00206 PaintGL();
00207 }
00208 //---------------------------------------------------------------------------
00209 
00210 void __fastcall TNPRForm::FormMouseMove(TObject *Sender,
00211       TShiftState Shift, int X, int Y)
00212 {
00213 if (mdown)
00214 {
00215 mrotx -= (Y-oy);
00216 mroty -= (X-ox);
00217 if (mrotx<0) mrotx += 360;
00218 if (mrotx>360) mrotx -= 360;
00219 if (mroty<0) mroty += 360;
00220 if (mroty>360) mroty -= 360;
00221 
00222 if (arepaint->Checked) {RayCast(); PaintGL(); }
00223 txrot->Text = IntToStr(mrotx);
00224 tzrot->Text = IntToStr(mroty);
00225 ox = X;
00226 oy = Y;
00227 }
00228 }
00229 //---------------------------------------------------------------------------
00230 void __fastcall TNPRForm::RayCast()
00231 {
00232         int a,i,k,maxres;
00233         __int16 value;
00234         int colx, coly, colz, aktpos, rowsize,pagesize, px, py, pz;
00235         int ita, ite;
00236         float t,ta,te,tx,ty,tz,xrcos,yrcos,zrcos,xrsin,yrsin,zrsin,xrot,yrot,zrot,ac;
00237         float value1,value2,value3, value4, value11, value22,pfx,pfy,pfz,sx,sy,sz,s1x,s1y;
00238         float gscale, jstep, lv, temp,j, tmax, lx, ly, lz, valgx, valgy, valgz, valsh;
00239         long averg, anzavg, aline;
00240         int tlmip, detval, maxdim, levlx, levly, levlz;
00241         bool endcast;
00242 
00243         gscale = 4096/(float)((gmax*32)-(gmin*32));
00244 
00245         jstep = StrToFloat(step->Caption);
00246         tlmip = StrToInt(lmipvalue->Caption);
00247 
00248         levlx = StrToInt(llx->Text);
00249         levly = StrToInt(lly->Text);
00250         levlz = StrToInt(llz->Text);
00251 
00252         if (levlx==0) levlx=9999;
00253         if (levly==0) levly=9999;
00254         if (levlz==0) levlz=9999;
00255 
00256         if (sizeX>sizeY) {maxdim=sizeX;} else {maxdim=sizeY;}
00257         if (maxdim<sizeZ) {maxdim=sizeZ;}
00258         maxdim *= 1.6;
00259 
00260         //detval = StrToInt(detail->Caption);
00261         vertex pppos;
00262         vertex dlookup[1024];
00263 
00264         if (autores->Checked)
00265         { if (w>h) {xres=h;yres=h;} else {xres=w;yres=w;} }
00266         else
00267         {
00268         xres = StrToInt(textx->Caption);
00269         yres = StrToInt(texty->Caption);
00270         }
00271 
00272         xrot = (float)StrToFloat(txrot->Text)*pirad;
00273 //        yrot = (float)StrToFloat(tyrot->Text)*pirad;
00274         zrot = (float)StrToFloat(tzrot->Text)*pirad;
00275 
00276         xrcos = _fm_cos(xrot);
00277 //        yrcos = _fm_cos(yrot);
00278         zrcos = _fm_cos(zrot);
00279         xrsin = _fm_sin(xrot);
00280 //        yrsin = _fm_sin(yrot);
00281         zrsin = _fm_sin(zrot);
00282 
00283         FrameForm->StatusProgress->Position = 0;
00284         FrameForm->StatusProgress->Visible = true;
00285         maxres = MAX(MAX(sizeX,sizeY),sizeZ);
00286 
00287         lx =0; ly=1; lz=0;
00288 
00289         temp = ly;
00290         ly = temp*xrcos - lz * xrsin;
00291         lz = temp*xrsin + lz * xrcos;
00292 
00293         temp = lx;
00294         lx = temp*zrcos - ly * zrsin;
00295         ly = temp*zrsin + ly * zrcos;
00296 
00297 
00298         dx.x = (float)maxres/(float)xres;
00299         dx.y = 0;
00300         dx.z = 0;
00301 
00302         temp = dx.y;
00303 
00304         dx.x = dx.x;
00305         dx.y = temp * xrcos - dx.z*xrsin;
00306         dx.z = temp * xrsin + dx.z*xrcos;
00307 
00308         temp = dx.x;
00309 
00310         dx.x = temp * zrcos - dx.y * zrsin;
00311         dx.y = temp * zrsin + dx.y * zrcos;
00312         dx.z = dx.z;
00313 
00314         dy.x = 0;
00315         dy.y = 0;
00316         dy.z = (float)maxres/(float)yres;
00317 
00318         temp = dy.y;
00319 
00320         dy.x = dy.x;
00321         dy.y = temp * xrcos - dy.z*xrsin;
00322         dy.z = temp * xrsin + dy.z*xrcos;
00323 
00324         temp = dy.x;
00325 
00326         dy.x = temp * zrcos - dy.y * zrsin;
00327         dy.y = temp * zrsin + dy.y * zrcos;
00328         dy.z = dy.z;
00329 
00330 
00331         dz.x = 0;
00332         dz.y = 1;
00333         dz.z = 0;
00334 
00335         temp = dz.y;
00336 
00337         dz.x = dz.x;
00338         dz.y = temp * xrcos - dz.z*xrsin;
00339         dz.z = temp * xrsin + dz.z*xrcos;
00340 
00341         temp = dz.x;
00342 
00343         dz.x = temp * zrcos - dz.y * zrsin;
00344         dz.y = temp * zrsin + dz.y * zrcos;
00345         dz.z = dz.z;
00346 
00347         o.x = -(maxres/2);
00348         o.y = -(sizeY/2);
00349         o.z = -(maxres/2);
00350 
00351         temp = o.y;
00352 
00353         o.x = o.x;
00354         o.y = temp * xrcos - o.z*xrsin;
00355         o.z = temp * xrsin + o.z*xrcos;
00356 
00357         temp = o.x;
00358 
00359         o.x = temp * zrcos - o.y * zrsin;
00360         o.y = temp * zrsin + o.y * zrcos;
00361         o.z = o.z;
00362 
00363         o.x = o.x + sizeX/2;
00364         o.y = o.y + sizeY/2;
00365         o.z = o.z + sizeZ/2;
00366 
00367         pagesize = sizeX*sizeY;
00368         rowsize = sizeX;
00369 
00370         for (i=0; i<1024; i++)
00371         {
00372         dlookup[i].x = (i-512) * dz.x;        //Lookup-Values für RayCast berechnen
00373         dlookup[i].y = (i-512) * dz.y;
00374         dlookup[i].z = (i-512) * dz.z;
00375         }
00376 
00377         k = 0;
00378         for (a=0; a<yres; a++)
00379         {
00380                 pppos.x = o.x + a * dy.x;
00381                 pppos.y = o.y + a * dy.y;
00382                 pppos.z = o.z + a * dy.z;
00383 
00384                 if (arepaint->Checked == false) {FrameForm->StatusProgress->Position = (int)(100 * ((float)a / (float)yres));}
00385                 for (i=0; i<xres; i++)
00386                 {
00387                         ppos.x = pppos.x + i * dx.x;     // Rotierten Startpunkt für parametrisierte
00388                         ppos.y = pppos.y + i * dx.y;     // Gerade berechnen ...
00389                         ppos.z = pppos.z + i * dx.z;
00390 
00391                         ta = 9999;
00392                         te = 9999;
00393 
00394                         if (dz.x!=0)
00395                         {
00396                           t = (1-ppos.x)/dz.x;                      // Schneide Ray mit x=0
00397                           ty = ppos.y + t*dz.y;
00398                           tz = ppos.z + t*dz.z;
00399                           if (ty>=1 && tz>=2 && ty<sizeY-2 && tz<sizeZ-3) { if (ta==9999) ta=t; else te=t; }
00400 
00401                           t = (sizeX-2-ppos.x)/dz.x;               // Schneide Ray mit x=sizeX
00402                           ty = ppos.y + t*dz.y;
00403                           tz = ppos.z + t*dz.z;
00404                           if (ty>=1 && tz>=2 && ty<sizeY-2 && tz<sizeZ-3) { if (ta==9999) ta=t; else te=t; }
00405                         }
00406 
00407                         if (dz.y!=0)
00408                         {
00409                           t = (1-ppos.y)/dz.y;                      // Schneide Ray mit y=0
00410                           tx = ppos.x + t*dz.x;
00411                           tz = ppos.z + t*dz.z;
00412                           if (tx>=1 && tz>=2 && tx<sizeX-2 && tz<sizeZ-3) { if (ta==9999) ta=t; else te=t; }
00413 
00414                           t = (sizeY-2-ppos.y)/dz.y;               // Schneide Ray mit y=sizeY
00415                           tx = ppos.x + t*dz.x;
00416                           tz = ppos.z + t*dz.z;
00417                           if (tx>=1 && tz>=2 && tx<sizeX-2 && tz<sizeZ-3) { if (ta==9999) ta=t; else te=t; }
00418                         }
00419 
00420                         if (dz.z!=0)
00421                         {
00422                           t = (2-ppos.z)/dz.z;                      // Schneide Ray mit z=0
00423                           tx = ppos.x + t*dz.x;
00424                           ty = ppos.y + t*dz.y;
00425                           if (tx>=1 && ty>=1 && tx<sizeX-2 && ty<sizeY-2) { if (ta==9999) ta=t; else te=t; }
00426 
00427                           t = (sizeZ-3-ppos.z)/dz.z;               // Schneide Ray mit z=sizeZ
00428                           tx = ppos.x + t*dz.x;
00429                           ty = ppos.y + t*dz.y;
00430                           if (tx>=1 && ty>=1 && tx<sizeX-2 && ty<sizeY-2) { if (ta==9999) ta=t; else te=t; }
00431                         }
00432 
00433                         if (ta>te) {t=ta; ta=te; te=t;}
00434 
00435                         averg = 0;
00436 
00437                         if (te==9999)
00438                         {
00439                         NPRview[k].r=NPRview[k].b=NPRview[k].g = 0;
00440                         }
00441                         else
00442                         {
00443                         value = 0;
00444                         aline = 0;
00445                         endcast=false;
00446                         for (j=ta; j<te && endcast==false; j += jstep)
00447                         {
00448                           pfx = (ppos.x) + j*dz.x;
00449                           pfy = (ppos.y) + j*dz.y;
00450                           pfz = (ppos.z) + j*dz.z;
00451 
00452                           px = (int)pfx;
00453                           py = (int)pfy;
00454                           pz = (int)pfz;
00455                           aktpos = pagesize*pz + rowsize*py + px;
00456                           if (trilinear->Checked)
00457                           {
00458                                 sx = pfx-px;
00459                                 sy = pfy-py;
00460                                 sz = pfz-pz;
00461                                 s1x = 1-sx;
00462                                 s1y = 1-sy;
00463                                 value1 = (float)absgrad[aktpos]*s1x                  + (float)absgrad[aktpos+1]*sx;
00464                                 value2 = (float)absgrad[aktpos+rowsize]*s1x          + (float)absgrad[aktpos+rowsize+1]*sx;
00465                                 value3 = (float)absgrad[aktpos+pagesize+rowsize]*s1x + (float)absgrad[aktpos+pagesize+rowsize+1]*sx;
00466                                 value4 = (float)absgrad[aktpos+pagesize]*s1x         + (float)absgrad[aktpos+pagesize+1]*sx;
00467                                 value11 = value1*(s1y) + value2*(sy);
00468                                 value22 = value4*(s1y) + value3*(sy);
00469                                 value = (int)(value11*(1-sz) + value22*(sz));
00470 
00471                                 if (value>(gmin*32))
00472                                 {
00473                                 value1 = (float)gradient[aktpos].y*s1x                  + (float)gradient[aktpos+1].y*sx;
00474                                 value2 = (float)gradient[aktpos+rowsize].y*s1x          + (float)gradient[aktpos+rowsize+1].y*sx;
00475                                 value3 = (float)gradient[aktpos+pagesize+rowsize].y*s1x + (float)gradient[aktpos+pagesize+rowsize+1].y*sx;
00476                                 value4 = (float)gradient[aktpos+pagesize].y*s1x         + (float)gradient[aktpos+pagesize+1].y*sx;
00477                                 value11 = value1*(1-sy) + value2*(sy);
00478                                 value22 = value4*(1-sy) + value3*(sy);
00479                                 valgy=((value11*(1-sz) + value22*(sz)));
00480 
00481                                 value1 = (float)gradient[aktpos].x*s1x                  + (float)gradient[aktpos+1].x*sx;
00482                                 value2 = (float)gradient[aktpos+rowsize].x*s1x          + (float)gradient[aktpos+rowsize+1].x*sx;
00483                                 value3 = (float)gradient[aktpos+pagesize+rowsize].x*s1x + (float)gradient[aktpos+pagesize+rowsize+1].x*sx;
00484                                 value4 = (float)gradient[aktpos+pagesize].x*s1x         + (float)gradient[aktpos+pagesize+1].x*sx;
00485                                 value11 = value1*(1-sy) + value2*(sy);
00486                                 value22 = value4*(1-sy) + value3*(sy);
00487                                 valgx=((value11*(1-sz) + value22*(sz)));
00488 
00489                                 value1 = (float)gradient[aktpos].z*s1x                  + (float)gradient[aktpos+1].z*sx;
00490                                 value2 = (float)gradient[aktpos+rowsize].z*s1x          + (float)gradient[aktpos+rowsize+1].z*sx;
00491                                 value3 = (float)gradient[aktpos+pagesize+rowsize].z*s1x + (float)gradient[aktpos+pagesize+rowsize+1].z*sx;
00492                                 value4 = (float)gradient[aktpos+pagesize].z*s1x         + (float)gradient[aktpos+pagesize+1].z*sx;
00493                                 value11 = value1*(1-sy) + value2*(sy);
00494                                 value22 = value4*(1-sy) + value3*(sy);
00495                                 valgz=((value11*(1-sz) + value22*(sz)));
00496 
00497                                 lv = sqrt(valgx*valgx + valgy*valgy + valgz*valgz);
00498                                 valgx /= lv;
00499                                 valgy /= lv;
00500                                 valgz /= lv;
00501 
00502                                 valsh = fabs(valgx*lx+valgy*ly+valgz*lz);
00503                                 if (valsh>0.999) {valsh=0.999;}
00504                                 if (valsh<0) {valsh=0;}
00505                                 valsh = 1-valsh;
00506                                 if (StrToFloat(apower->Caption)>1) valsh = exp(StrToFloat(apower->Caption)*log(valsh));
00507 
00508                                 if (px%levlx == 0 || py%levly == 0 || pz%levlz == 0)
00509                                 { if (px!=0 && py!=0 && pz!=0 && value>aline) {aline=value;} }
00510 
00511                                 value = value-gmin*32;
00512                                 value = int((float)value*(float)gscale);
00513                                 if (value>4095) value=4095;
00514                                 value = value*(valsh);
00515                                 }
00516                                 else
00517                                 {
00518                                 value = value-gmin*32;
00519                                 value = value*gscale;
00520                                 if (value>4095) value=4095;
00521                                 }
00522                                 if (depth->Checked){
00523                                         tmax = j;
00524                                         if (tmax<0) tmax=0;
00525                                         if (tmax>maxdim) tmax=maxdim;
00526                                         if (lmipcheck->Checked) {
00527                                                 if ((value*(maxdim-tmax))>averg)
00528                                                         {averg = (value*(maxdim-tmax));}
00529                                                         else
00530                                                         {
00531                                                         if (averg>(tlmip*(maxdim-tmax)) && (value*(maxdim-tmax))<averg)
00532                                                                 {
00533                                                                 endcast = true;
00534                                                                 }
00535                                                         }
00536                                                 } else {
00537                                                 if ((value*(maxdim-tmax))>averg) {averg = (value*(maxdim-tmax));}
00538                                                 }
00539                                        }
00540                                         else {
00541                                         if (lmipcheck->Checked) {
00542                                                 if (value>averg)
00543                                                         {averg = value;}
00544                                                         else
00545                                                         {
00546                                                         if (averg>tlmip && value<(averg))
00547                                                                 {
00548                                                                 endcast = true;
00549                                                                 }
00550                                                         }
00551                                                 } else {
00552                                                 if (value>averg) {averg = value;}
00553                                                 }
00554                                         }
00555                           }
00556                           else
00557                           {
00558                                 value = absgrad[pagesize*pz + rowsize*py + px];
00559 
00560                                 if (value>(gmin*32))
00561                                 {valsh = fabs(gradient[pagesize*pz + rowsize*py + px].x*lx+gradient[pagesize*pz + rowsize*py + px].y*ly+gradient[pagesize*pz + rowsize*py + px].z*lz);
00562                                 if (valsh>0.999) {valsh=0.999;}
00563                                 if (valsh<0) {valsh=0;}
00564                                 valsh = 1-valsh;
00565                                 value = value-gmin*32;
00566                                 value = int((float)value*(float)gscale);
00567                                 if (value>4095) value=4095;
00568 
00569                                 if (StrToFloat(apower->Caption)>1) valsh = exp(StrToFloat(apower->Caption)*log(valsh));
00570 
00571                                 if (px%levlx == 0 || py%levly == 0 || pz%levlz == 0)
00572                                 { if (px!=0 && py!=0 && pz!=0 && value>aline) {aline=value;} }
00573                                 value = value*(valsh);
00574                                 }
00575                                 else
00576                                 {
00577                                 value = value-gmin*32;
00578                                 value = int((float)value*(float)gscale);
00579                                 if (value>4095) value=4095;
00580                                 }
00581                             if (depth->Checked){
00582                                         tmax = j;
00583                                         if (tmax<0) tmax=0;
00584                                         if (tmax>(maxdim)) tmax=(maxdim);
00585 
00586                                         if (lmipcheck->Checked) {
00587                                                 if ((value*(maxdim-tmax))>averg)
00588                                                         {averg = (value*(maxdim-tmax));}
00589                                                         else
00590                                                         {
00591                                                         if (averg>(tlmip*(maxdim-tmax)) && (value*(maxdim-tmax))<averg)
00592                                                                 {
00593                                                                 endcast = true;
00594                                                                 }
00595                                                         }
00596                                                 } else {
00597                                                 if ((value*(maxdim-tmax))>averg) {averg = (value*(maxdim-tmax));}
00598                                                 }
00599 
00600                                         }
00601                                         else {
00602                                         if (lmipcheck->Checked) {
00603                                                 if (value>averg)
00604                                                         {averg = value;}
00605                                                         else
00606                                                         {
00607                                                         if (averg>tlmip && value<averg)
00608                                                                 {
00609                                                                 endcast = true;
00610                                                                 }
00611                                                         }
00612                                                 } else {
00613                                                 if (value>averg) {averg = value;}
00614                                                 }
00615                                         }
00616                           }
00617 
00618                          }
00619                          if (depth->Checked){
00620                                 colx = ((aline*lr)+(averg*vr)/maxdim)/4096;
00621                                 coly = ((aline*lg)+(averg*vg)/maxdim)/4096;
00622                                 colz = ((aline*lb)+(averg*vb)/maxdim)/4096;
00623                                 if (colx>255) colx=255;
00624                                 if (coly>255) coly=255;
00625                                 if (colz>255) colz=255;
00626                                 NPRview[k].r = colx;
00627                                 NPRview[k].g = coly;
00628                                 NPRview[k].b = colz;
00629                                 }
00630                                 else {
00631 
00632                                 colx = ((aline*lr)+(averg*vr))/4096;
00633                                 coly = ((aline*lg)+(averg*vg))/4096;
00634                                 colz = ((aline*lb)+(averg*vb))/4096;
00635 
00636                                 if (colx>255) colx=255;
00637                                 if (coly>255) coly=255;
00638                                 if (colz>255) colz=255;
00639                                 NPRview[k].r = colx;
00640                                 NPRview[k].g = coly;
00641                                 NPRview[k].b = colz;
00642                                 }
00643                          }
00644                 k++;
00645                 }
00646         }
00647         FrameForm->StatusProgress->Visible = false;
00648 }
00649 
00650 
00651 void __fastcall TNPRForm::ResTrackBarChange(TObject *Sender)
00652 {
00653 switch (ResTrackBar->Position)
00654         {
00655         case 1: textx->Caption = "32"; texty->Caption = "32"; break;
00656         case 2: textx->Caption = "64"; texty->Caption = "64"; break;
00657         case 3: textx->Caption = "128"; texty->Caption = "128"; break;
00658         case 4: textx->Caption = "256"; texty->Caption = "256"; break;
00659         case 5: textx->Caption = "512"; texty->Caption = "512"; break;
00660         case 6: textx->Caption = "1024"; texty->Caption = "1024";
00661         }
00662 if (arepaint->Checked) {RayCast();PaintGL();}
00663         
00664 }
00665 //---------------------------------------------------------------------------
00666 
00667 
00668 void __fastcall TNPRForm::autoresClick(TObject *Sender)
00669 {
00670 if (autores->Checked==true)
00671         {
00672         ResTrackBar->Enabled=false;
00673         textx->Enabled=false;
00674         Label2->Enabled=false;
00675         texty->Enabled=false;
00676         }
00677         else
00678         {
00679         ResTrackBar->Enabled=true;
00680         textx->Enabled=true;
00681         Label2->Enabled=true;
00682         texty->Enabled=true;
00683         }
00684 if (arepaint->Checked) {RayCast();PaintGL();}
00685 
00686 }
00687 //---------------------------------------------------------------------------
00688 
00689 void __fastcall TNPRForm::trilinearClick(TObject *Sender)
00690 {
00691 if (arepaint->Checked) {RayCast();PaintGL();}
00692         
00693 }
00694 //---------------------------------------------------------------------------
00695 
00696 
00697 void __fastcall TNPRForm::TrackBar1Change(TObject *Sender)
00698 {
00699 apower->Caption = FloatToStr(((float)TrackBar1->Position/10)+1);
00700 }
00701 //---------------------------------------------------------------------------
00702 
00703 
00704 void __fastcall TNPRForm::TrackBar2Change(TObject *Sender)
00705 {
00706 lmipvalue->Caption = IntToStr(TrackBar2->Position);
00707 }
00708 //---------------------------------------------------------------------------
00709 
00710 void __fastcall TNPRForm::lmipcheckClick(TObject *Sender)
00711 {
00712 lmipvalue->Enabled = lmipcheck->Checked;
00713 }
00714 //---------------------------------------------------------------------------
00715 
00716 void __fastcall TNPRForm::TrackBar3Change(TObject *Sender)
00717 {
00718 step->Caption = FloatToStr((float)TrackBar3->Position/10);
00719 }
00720 //---------------------------------------------------------------------------
00721 
00722 void __fastcall TNPRForm::gareaPaint(TObject *Sender)
00723 {
00724 int i;
00725 garea->Canvas->FillRect(Rect(0,0,128,39));
00726 garea->Canvas->Pen->Color = clSilver;
00727 for (i=0; i<128; i++) {
00728         garea->Canvas->MoveTo(i,39);
00729         garea->Canvas->LineTo(i,39-ghisto[i]);
00730         }
00731 garea->Canvas->Pen->Color = clGray;
00732 garea->Canvas->MoveTo(gmin,0);
00733 garea->Canvas->LineTo(gmin,39);
00734 garea->Canvas->MoveTo(gmax,0);
00735 garea->Canvas->LineTo(gmax,39);
00736 garea->Canvas->Pen->Color = clBlack;
00737 garea->Canvas->MoveTo(0,39);
00738 garea->Canvas->LineTo(gmin,39);
00739 garea->Canvas->LineTo(gmax,0);
00740 garea->Canvas->LineTo(128,0);
00741 }
00742 //---------------------------------------------------------------------------
00743 
00744 
00745 void __fastcall TNPRForm::gareaMouseMove(TObject *Sender,
00746       TShiftState Shift, int X, int Y)
00747 {
00748 if (gdragmin==false && gdragmax==false) {
00749         if (abs(X-gmin)<3 ||abs(X-gmax)<3)
00750         {garea->Cursor = crSizeWE; }
00751         else {garea->Cursor = crDefault; }
00752         } else {
00753         if (gdragmin) {
00754                 gmin = X;
00755                 if (gmin>gmax-3) {gmin=gmax-3;}
00756                 if (gmin<1) {gmin=1;}
00757                 lgmin->Caption = IntToStr(gmin*32);
00758                 garea->Repaint();}
00759         if (gdragmax) {
00760                 gmax = X;
00761                 if (gmax<gmin+3) {gmax=gmin+3;}
00762                 if (gmax>127) {gmax=127;}
00763                 lgmax->Caption = IntToStr(gmax*32);
00764                 garea->Repaint();}
00765         }
00766 }
00767 //---------------------------------------------------------------------------
00768 
00769 void __fastcall TNPRForm::gareaMouseUp(TObject *Sender,
00770       TMouseButton Button, TShiftState Shift, int X, int Y)
00771 {
00772 gdragmin = false; gdragmax=false;        
00773 }
00774 //---------------------------------------------------------------------------
00775 
00776 void __fastcall TNPRForm::gareaMouseDown(TObject *Sender,
00777       TMouseButton Button, TShiftState Shift, int X, int Y)
00778 {
00779 if (abs(X-gmin)<3) {gdragmin=true;}
00780 if (abs(X-gmax)<3) {gdragmax=true;}
00781 }
00782 //---------------------------------------------------------------------------
00783 
00784 
00785 void __fastcall TNPRForm::SFGColorMouseDown(TObject *Sender,
00786       TMouseButton Button, TShiftState Shift, int X, int Y)
00787 {
00788 if (ColorDialog1->Execute()) {
00789                         SFGColor->Brush->Color = ColorDialog1->Color;}
00790 vr = SFGColor->Brush->Color & 255;
00791 vg = (SFGColor->Brush->Color >> 8) & 255;
00792 vb = (SFGColor->Brush->Color >> 16) & 255;
00793 }
00794 //---------------------------------------------------------------------------
00795 
00796 void __fastcall TNPRForm::SBGColorMouseDown(TObject *Sender,
00797       TMouseButton Button, TShiftState Shift, int X, int Y)
00798 {
00799 if (ColorDialog1->Execute()) {
00800                         SBGColor->Brush->Color = ColorDialog1->Color;}
00801 lr = SBGColor->Brush->Color & 255;
00802 lg = (SBGColor->Brush->Color >> 8) & 255;
00803 lb = (SBGColor->Brush->Color >> 16) & 255;
00804 }
00805 //---------------------------------------------------------------------------
00806 
00807 
00808 

Generated on Thu Jan 23 06:17:38 2003 for Vol by doxygen1.2.18