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

MDIFrame.cpp

00001 //----------------------------------------------------------------------------
00002 //Borland C++Builder
00003 //Copyright (c) 1987, 1998-2002 Borland International Inc. All Rights Reserved.
00004 //----------------------------------------------------------------------------
00005 //---------------------------------------------------------------------------
00006 #include <vcl.h>
00007 #pragma hdrstop
00008 
00009 #include "MDIFrame.h"
00010 #include "MDIFirstHit.h"
00011 #include "MDIEdit.h"
00012 #include "MDISlice.h"
00013 #include "MDIGradient.h"
00014 
00015 #include "MDIMarchingCubes.h"
00016 #include "MDICuberille.h"
00017 #include "MDIIsovalue.h"
00018 #include "MDIRegionBoundary.h"
00019 #include "MDITransparent.h"
00020 #include "MDIAverage.h"
00021 #include "MDINPR.h"
00022 #include "MDIMIP.h"
00023 #include "about.h"
00024 #include "MDITransfer.h"
00025 #include "MDITwoLevel.h"
00026 #include <fastmath.h>
00027 #include <math.h>
00028 //---------------------------------------------------------------------------
00029 #pragma resource "*.dfm"
00030 
00031 #define MIN(x,y)        ((x<y) ? (x) : (y))
00032 #define MAX(x,y)        ((x>y) ? (x) : (y))
00033 
00034 TFrameForm *FrameForm;
00035 
00036 //---------------------------------------------------------------------------
00037 __fastcall TFrameForm::TFrameForm(TComponent* Owner)
00038     : TForm(Owner)
00039 {
00040 }
00041 //---------------------------------------------------------------------------
00042 void __fastcall TFrameForm::Exit1Click(TObject *Sender)
00043 {
00044   Close();
00045 }
00046 //---------------------------------------------------------------------
00047 void __fastcall TFrameForm::Tile1Click(TObject *Sender)
00048 {
00049   Tile();
00050 }
00051 //---------------------------------------------------------------------
00052 void __fastcall TFrameForm::Cascade1Click(TObject *Sender)
00053 {
00054   Cascade();
00055 }
00056 //---------------------------------------------------------------------
00057 void __fastcall TFrameForm::Arrangeicons1Click(TObject *Sender)
00058 {
00059   ArrangeIcons();
00060 }
00061 //---------------------------------------------------------------------
00062 void __fastcall TFrameForm::Open1Click(TObject *Sender)
00063 {
00064   if(OpenFileDialog->Execute()){ this->Repaint();
00065         if (loadFile(OpenFileDialog->FileName)){
00066                         filename->Caption = OpenFileDialog->FileName;
00067                         dimensions->Caption = IntToStr(sizeX) + " x " +IntToStr(sizeY) + " x " + IntToStr(sizeZ);
00068                         CoolBar->Visible = true;
00069                         Ansicht1->Enabled = true;
00070                         Window1->Enabled = true;
00071                         Close1->Enabled = true;
00072                 }
00073   }
00074 }
00075 //---------------------------------------------------------------------
00076 void __fastcall TFrameForm::SlicesClick(TObject *Sender)
00077 {
00078   if (Slices->Checked)
00079   {
00080         SliceForm->Close();
00081         Slices->Checked = false;
00082   }
00083   else
00084   {
00085         SliceForm = new TSliceForm(this);
00086         Slices->Checked = true;
00087   }
00088 }
00089 //---------------------------------------------------------------------------
00090 
00091 
00092 
00093 void __fastcall TFrameForm::GradientSlicesClick(TObject *Sender)
00094 {
00095   if (GradientSlices->Checked)
00096   {
00097         GradientForm->Close();
00098         GradientSlices->Checked = false;
00099   }
00100   else
00101   {
00102         GradientForm = new TGradientForm(this);
00103         GradientSlices->Checked = true;
00104   }
00105 
00106 }
00107 //---------------------------------------------------------------------------
00108 
00109 void __fastcall TFrameForm::AverageClick(TObject *Sender)
00110 {
00111   if (Average->Checked)
00112   {
00113         AverageForm->Close();
00114         Average->Checked = false;
00115   }
00116   else
00117   {
00118         AverageForm = new TAverageForm(this);
00119         Average->Checked = true;
00120   }
00121 
00122 }
00123 //---------------------------------------------------------------------------
00124 
00125 void __fastcall TFrameForm::FirstHitClick(TObject *Sender)
00126 {
00127   if (FirstHit->Checked)
00128   {
00129         FirstHitForm->Close();
00130         FirstHit->Checked = false;
00131   }
00132   else
00133   {
00134         FirstHitForm = new TFirstHitForm(this);
00135         FirstHit->Checked = true;
00136   }
00137 
00138 }
00139 //---------------------------------------------------------------------------
00140 
00141 void __fastcall TFrameForm::TransparentClick(TObject *Sender)
00142 {
00143  if (Transparent->Checked)
00144   {
00145         TransparentForm->Close();
00146         Transparent->Checked = false;
00147   }
00148   else
00149   {
00150         TransparentForm = new TTransparentForm(this);
00151         Transparent->Checked = true;
00152   }
00153 
00154 }
00155 //---------------------------------------------------------------------------
00156 
00157 void __fastcall TFrameForm::CuberilleClick(TObject *Sender)
00158 {
00159   if (Cuberille->Checked)
00160   {
00161         CuberilleForm->Close();
00162         Cuberille->Checked = false;
00163   }
00164   else
00165   {
00166         CuberilleForm = new TCuberilleForm(this);
00167         Cuberille->Checked = true;
00168   }
00169 
00170 }
00171 //---------------------------------------------------------------------------
00172 
00173 
00174 void __fastcall TFrameForm::MIPClick(TObject *Sender)
00175 {
00176   if (MIP->Checked)
00177   {
00178         MIPForm->Close();
00179         MIP->Checked = false;
00180   }
00181   else
00182   {
00183         MIPForm = new TMIPForm(this);
00184         MIP->Checked = true;
00185   }
00186 
00187 }
00188 //---------------------------------------------------------------------------
00189 
00190 void __fastcall TFrameForm::NPRClick(TObject *Sender)
00191 {
00192  if (NPR->Checked)
00193   {
00194         NPRForm->Close();
00195         NPR->Checked = false;
00196   }
00197   else
00198   {
00199         NPRForm = new TNPRForm(this);
00200         NPR->Checked = true;
00201   }
00202 
00203 }
00204 //---------------------------------------------------------------------------
00205 
00206 
00207 void __fastcall TFrameForm::Saveas1Click(TObject *Sender)
00208 {
00209   if(SaveFileDialog->Execute()){
00210 
00211   }
00212 }
00213 //---------------------------------------------------------------------------
00214 
00215 void __fastcall TFrameForm::Print1Click(TObject *Sender)
00216 {
00217   if(PrintDialog->Execute()){
00218 
00219   }
00220 }
00221 //---------------------------------------------------------------------------
00222 
00223 void __fastcall TFrameForm::Close1Click(TObject *Sender)
00224 {
00225         filename->Caption = "";
00226         dimensions->Caption = "0 x 0 x 0";
00227         CoolBar->Visible = false;
00228         Ansicht1->Enabled = false;
00229         Window1->Enabled = false;
00230         Close1->Enabled = false;
00231         Open1->Enabled = true;
00232         deallocate();
00233 
00234 }
00235 //---------------------------------------------------------------------------
00236 bool __fastcall TFrameForm::loadFile(AnsiString name)
00237 {
00238         int pagesize, i;
00239         double d;
00240 
00241         // Getting data set size:
00242         ifstream f(name.c_str(), ios::binary|ios::in);
00243 
00244         // read the 6 byte header:
00245         sizeX = _readInt16(f);
00246         sizeY = _readInt16(f);
00247         sizeZ = _readInt16(f);
00248 
00249         pagesize = sizeX*sizeY;
00250 
00251         // reading data:
00252         StatusProgress->Visible = true;
00253         size = sizeX*sizeY*sizeZ;
00254 
00255         deallocate();
00256 
00257         data = new __int16[size];
00258         histo = new THistogram(4096);
00259         histo->horizontal = false;
00260         contr = new TContrast(histo->size);
00261         transe = new TTransfer(histo);
00262         gradient = new vertex[size+pagesize];
00263 //        gradient2 = new vertex[size];
00264         absgrad = new __int16[size];
00265         color = new rgba[size];
00266 
00267         memusage = memusage + size*2;   //data
00268         memusage = memusage + sizeof(THistogram)+4096*sizeof(__int16);   //histo
00269         memusage = memusage + sizeof(TContrast); //contr
00270         memusage = memusage + sizeof(TTransfer); //transe
00271         memusage = memusage + size*4*3; //gradient
00272         memusage = memusage + size*2;   //absgrad
00273         memusage = memusage + size*4;   //color
00274         memupdate();
00275 
00276         StatusMain->Caption = "Reading File ...";
00277         StatusMain->Repaint();
00278         // Reading data in blocks of size "sizeX*__valsize":
00279         char * buff = (char *)data;
00280         int __valsize = sizeof(__int16);
00281         for(int i = 0; i<size*__valsize; i+=(sizeX*__valsize)) {
00282                 f.read(buff+i, sizeX*__valsize);
00283                 StatusProgress->Position = 10*(float(i)/float(size*__valsize))+1;
00284         }
00285         for (i=0; i<size; i++)
00286         { if (data[i]<0) data[i]=0;
00287           if (data[i]>4095) data[i]=4095; }
00288 
00289         // calculating colors:
00290 
00291         StatusMain->Caption = "Calculating Gradient ...";
00292         StatusMain->Repaint();
00293 
00294         __int16 dataMax = 0;
00295         //      step 1: get maximum intensity:
00296 
00297         for (i=0; i<size; i++)
00298         {
00299         //        get gradient, then normalize it and store length in absgrad
00300                 if (i<pagesize || i>size-pagesize) { gradient[i].x = gradient[i].y = gradient[i].z=0;absgrad[i]=0.0000001;}
00301                 else
00302                 {
00303                 gradient[i].x = (data[i+1]-data[i-1])/2;
00304                 gradient[i].y = (data[i+sizeX]-data[i-sizeX])/2;
00305                 gradient[i].z = (data[i+pagesize]-data[i-pagesize])/2;
00306                 absgrad[i] = _fm_sqrt(gradient[i].x*gradient[i].x + gradient[i].y*gradient[i].y + gradient[i].z * gradient[i].z);
00307                 d = (double)sqrt(gradient[i].x*gradient[i].x + gradient[i].y*gradient[i].y + gradient[i].z * gradient[i].z);
00308                 gradient[i].x = (float)(gradient[i].x / d);
00309                 gradient[i].y = (float)(gradient[i].y / d);
00310                 gradient[i].z = (float)(gradient[i].z / d);
00311                 }
00312                 if (!(i%(sizeX*sizeY)))
00313                         StatusProgress->Position = 10+70*(float(i)/float(size))+1;
00314         }
00315 
00316 /*        for (i=0; i<size; i++)
00317         {
00318 
00319                 if (i==0 || i==size-1)
00320                 {
00321                 if (i==0) { gradient[i].x = (data[i+1])/2;}
00322                 if (i==size-1) { gradient[i].x = (0-data[i-1])/2;  }
00323                 }
00324                 else
00325                 {
00326                 gradient[i].x = (data[i+1]-data[i-1])/2;
00327                 }
00328 
00329                 if (i<sizeX || i>size-sizeX-1)
00330                 {
00331                 if (i<sizeX) { gradient[i].y = (data[i+sizeX])/2; }
00332                 if (i>size-sizeX-1) { gradient[i].y = (0-data[i-sizeX])/2;   }
00333                 }
00334                 else
00335                 {
00336                 gradient[i].y = (data[i+sizeX]-data[i-sizeX])/2;
00337                 }
00338 
00339                 if (i<pagesize || i>size-pagesize-1)
00340                 {
00341                 if (i<pagesize) { gradient[i].z= (data[i+pagesize])/2;  }
00342                 if (i>size-pagesize-1) { gradient[i].z = (0-data[i-pagesize])/2;  }
00343                 }
00344                 else
00345                 {
00346                 gradient[i].z = (data[i+pagesize]-data[i-pagesize])/2;
00347                 }
00348 
00349                 absgrad[i] = _fm_sqrt(gradient[i].x*gradient[i].x + gradient[i].y*gradient[i].y + gradient[i].z * gradient[i].z);
00350                 gradient[i].x = (gradient[i].x / absgrad[i]);
00351                 gradient[i].y = (gradient[i].y / absgrad[i]);
00352                 gradient[i].z = (gradient[i].z / absgrad[i]);
00353 
00354 
00355             if (!(i%(sizeX*sizeY)))
00356                         StatusProgress->Position = 10+70*(float(i)/float(size))+1;
00357         }
00358 */
00359   /*      for (i=pagesize; i<size-pagesize; i++)
00360        {
00361                 gradient2[i].x = (gradient[i+1].x+gradient[i-1].x+gradient[i+sizeX].x+gradient[i-sizeX].x+gradient[i+pagesize].x+gradient[i-pagesize].x+gradient[i].x*2)/8;
00362                 gradient2[i].y = (gradient[i+1].y+gradient[i-1].y+gradient[i+sizeX].y+gradient[i-sizeX].y+gradient[i+pagesize].y+gradient[i-pagesize].y+gradient[i].y*2)/8;
00363                 gradient2[i].z = (gradient[i+1].z+gradient[i-1].z+gradient[i+sizeX].z+gradient[i-sizeX].z+gradient[i+pagesize].z+gradient[i-pagesize].z+gradient[i].z*2)/8;
00364                 StatusProgress->Position = 100*(float(i)/float(size));
00365         }
00366   */
00367         StatusMain->Caption = "Mapping Colors ...";
00368         StatusMain->Repaint();
00369         dataMax = 4095;
00370         //      step 2: fit intensity to color range:
00371         float ratio = (float)0xFF / (float)dataMax;
00372         for (int i=0; i<size; ++i)
00373         {
00374                 color[i].r = color[i].g = color[i].b =
00375                         (unsigned char)((float)data[i]*ratio);
00376                 if (data[i]>350) {
00377 
00378                         if (data[i]>1200) {
00379                                 color[i].a = 255;
00380                                 color[i].r = 255;
00381                                 color[i].g = 0;
00382                                 color[i].b = 0;
00383                         } else {
00384                                 color[i].a = 10;
00385                                 color[i].r = 0;
00386                                 color[i].g = 0;
00387                                 color[i].b = 255;
00388                         }
00389                 } else {
00390                         color[i].a = 0;
00391                 }
00392 
00393 //                color[i].a = 1;
00394                 ++((*histo)[data[i]]);
00395                 if (!(i%(sizeX*sizeY)))
00396                         StatusProgress->Position = 80+20*(float(i)/float(size))+1;
00397         }
00398 
00399         StatusMain->Caption = "";
00400         StatusProgress->Visible = false;
00401         return true;
00402 }
00403 //---------------------------------------------------------------------------
00404 __int16 __fastcall TFrameForm::_readInt16(ifstream & ifs)
00405 {
00406         char tmp[2];
00407         tmp[0] = ifs.get();
00408         tmp[1] = ifs.get();
00409         __int16 *res = (__int16 *)tmp;
00410         return *res;
00411 }
00412 
00413 void __fastcall TFrameForm::FormClose(TObject *Sender,
00414       TCloseAction &Action)
00415 {
00416         deallocate();
00417 }
00418 //---------------------------------------------------------------------------
00419 
00420 void __fastcall TFrameForm::About1Click(TObject *Sender)
00421 {
00422 AboutBox = new TAboutBox(this);
00423 AboutBox->ShowModal();
00424 
00425 }
00426 //---------------------------------------------------------------------------
00427 
00428 
00429 void __fastcall TFrameForm::deallocate()
00430 {
00431 
00432         if (color) {delete [] color;memusage = memusage - size*4;color = NULL;}
00433         if (gradient) {delete [] gradient; memusage = memusage - size*4*3;gradient = NULL;}
00434         if (absgrad) {delete [] absgrad; memusage = memusage - size*2;absgrad = NULL;}
00435         if (data) {delete [] data;memusage = memusage - size*2;data = NULL;}
00436         if (histo) {delete histo;memusage = memusage - sizeof(THistogram)-4096*sizeof(__int16);histo = NULL;}
00437         if (contr) {delete contr;memusage = memusage - sizeof(TContrast);contr = NULL;}
00438         if (transe) {delete transe;memusage = memusage - sizeof(TTransfer);transe = NULL;}
00439 memupdate();
00440 }
00441 
00442 
00443 void __fastcall TFrameForm::FormResize(TObject *Sender)
00444 {
00445 StatusMain->Width = (Width-168)/2;
00446 StatusMain2->Width = StatusMain->Width;
00447 StatusMain2->Left = StatusMain->Width + 7;
00448 StatusProgress->Width = StatusMain->Width-10;
00449 }
00450 //---------------------------------------------------------------------------
00451 
00452 void __fastcall TFrameForm::FormCreate(TObject *Sender)
00453 {
00454 StatusDate->Caption = DateToStr(Date());
00455 memusage = 0;
00456 memupdate();
00457 }
00458 //---------------------------------------------------------------------------
00459 void __fastcall TFrameForm::memupdate()
00460 {
00461 StatusMem->Caption = FloatToStrF(memusage/1000, ffNumber, 7,0) + " K";
00462 StatusMem->Repaint();
00463 }
00464 //---------------------------------------------------------------------------
00465 void __fastcall TFrameForm::METransferfunktionClick(TObject *Sender)
00466 {
00467   if (METransferfunktion->Checked)
00468   {
00469         TransferForm->Close();
00470         METransferfunktion->Checked = false;
00471   }
00472   else
00473   {
00474         TransferForm = new TTransferForm(this, transe);
00475         METransferfunktion->Checked = true;
00476   }
00477 }
00478 //---------------------------------------------------------------------------
00479 
00480 void __fastcall TFrameForm::TwoLevelClick(TObject *Sender)
00481 {
00482   if (TwoLevel->Checked)
00483   {
00484         TwoLevelForm->Close();
00485         TwoLevel->Checked = false;
00486   }
00487   else
00488   {
00489         TwoLevelForm = new TTwoLevelForm(this);
00490         TwoLevel->Checked = true;
00491   }
00492 }
00493 //---------------------------------------------------------------------------
00494 

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