<DIV>
<DIV>
<DIV>Dear users,</DIV>
<DIV> </DIV>
<DIV>I have to build an user interface by using MS VC++ for medical image processing. Instead of having to compute reading of image files, I am using ITK-VTK but I am quite new in this.</DIV>
<DIV> </DIV>
<DIV>- I read a raw 3D image using ITK and, as you suggested in "http://public.kitware.com/pipermail/insight-users/2003-April/003345.html", I use itkExtractImageFilter to create a 2D image from the 3D volume and get the pixel data in a buffer with: </DIV>
<DIV>extractFilter->GetOutput()->GetBufferPointer().</DIV>
<DIV> </DIV>
<DIV>
<DIV>- I would like to create a bitmap from this data using MFC classes to show the image in a frame of my user interface already built. To do so, I use HBitmap and CreateDIBitmap, but HBITMAP returned is NULL and nothing happens. </DIV></DIV>
<DIV> </DIV>
<DIV>- Can you suggest me a way to use VTK to display my image not in a modal window apart as implemented in vtkImageViewer, but in a frame of my interface?</DIV>
<DIV> </DIV>
<DIV>I joined a part of my code below. Please help me.</DIV>
<DIV> </DIV>
<DIV>Thanks in advance,</DIV>
<DIV> </DIV>
<DIV>Isabelle Renaud</DIV>
<DIV> </DIV>
<DIV>//-------code----------------------</DIV>
<DIV> if(extension == "raw")<BR> {<BR> //declarations<BR> typedef itk::Image< short, 3> ImageType;<BR> typedef itk::ImageFileReader< ImageType > ReaderType;<BR> <BR> //initialisations<BR> ReaderType::Pointer reader = ReaderType::New();<BR> <BR> //provide minimum info<BR> reader->SetFileName("myImage.mhd");<BR> <BR> try<BR> {<BR> reader->Update();</DIV>
<DIV> }</DIV>
<DIV> catch(itk::ExceptionObject &exception)<BR> {<BR> CString msg;<BR> msg.Format("Erreur: %s", exception.GetDescription());<BR> AfxMessageBox(msg, MB_ICONERROR);<BR> }</DIV>
<DIV> </DIV>
<DIV> //Create a device context to load the bitmap into<BR> CPaintDC dc(this); <BR> dcMem.CreateCompatibleDC(&dc);</DIV>
<DIV> if(GrabRAWFrame(1) != NULL) Invalidate();<BR> else AfxMessageBox("erreur a creation de image BMP\n");</DIV>
<DIV> }</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>HBITMAP CSequenceAvi::GrabRAWFrame(int frame)<BR>{<BR> //declarations<BR> typedef short PixelType;</DIV>
<DIV> typedef itk::Image< PixelType, 2 > ImageType2D;<BR> typedef itk::Image< PixelType, 3 > ImageType3D;<BR> <BR> typedef itk::ImageFileReader< ImageType3D > ReaderType;<BR> typedef itk::ExtractImageFilter< ImageType3D, ImageType2D > ExtractType;</DIV>
<DIV> </DIV>
<DIV> //initialisations<BR> ReaderType::Pointer reader = ReaderType::New();<BR> ExtractType::Pointer extractFilter = ExtractType::New();</DIV>
<DIV> reader->SetFileName("myImage.mhd");<BR> reader->Update();</DIV>
<DIV> ImageType3D::RegionType inputRegion = <BR> reader->GetOutput()->GetLargestPossibleRegion();</DIV>
<DIV> ImageType3D::SizeType size = inputRegion.GetSize();<BR> size[2] = 0;</DIV>
<DIV> ImageType3D::IndexType start = inputRegion.GetIndex();<BR> start[2] = frame;</DIV>
<DIV> //creation of an image region<BR> ImageType3D::RegionType desiredRegion;<BR> desiredRegion.SetSize(size);<BR> desiredRegion.SetIndex(start);</DIV>
<DIV> //region passed to filter to extract<BR> extractFilter->SetExtractionRegion(desiredRegion);</DIV>
<DIV> //connect an d execute<BR> extractFilter->SetInput(reader->GetOutput());<BR> try{<BR> extractFilter->Update();<BR> }<BR> catch(itk::ExceptionObject &exception)<BR> {<BR> CString msg;<BR> msg.Format("Erreur: %s", exception.GetDescription());<BR> AfxMessageBox(msg, MB_ICONERROR);<BR> }</DIV>
<DIV> </DIV>
<DIV> //get the data<BR> ImageType2D::Pointer image = extractFilter->GetOutput();<BR> short* pData = extractFilter->GetOutput()->GetBufferPointer();</DIV>
<DIV> </DIV>
<DIV> BITMAPINFOHEADER bih;<BR> memset(&bih, 0, sizeof(BITMAPINFOHEADER));</DIV>
<DIV> bih.biBitCount=24; //16 bits per pixel<BR> bih.biClrImportant=0;<BR> bih.biClrUsed=0;<BR> bih.biCompression=BI_RGB;//uncompressed format<BR> bih.biPlanes=1;//always<BR> bih.biSize= 40; //nb of bytes required by the structure BITMAPINFOHEADER<BR> bih.biWidth=width;<BR> bih.biHeight=height;<BR> bih.biXPelsPerMeter=0;<BR> bih.biYPelsPerMeter=0;<BR> bih.biSizeImage=((((bih.biWidth * bih.biBitCount)+31)& ~31) >>3)*bih.biHeight;<BR> //0 for uncompressed images</DIV>
<DIV> </DIV>
<DIV> //on cree l image<BR> CPaintDC dc(this);<BR> HBITMAP hBitmap = CreateDIBitmap(dc,//handle of device context<BR> (BITMAPINFOHEADER*)&bih,//address of bitmap size and format data<BR> CBM_INIT,//initialization flag<BR> pData,//address of initialization data<BR> (BITMAPINFO*)&bih,//address of bitmap color format data<BR> DIB_RGB_COLORS);//color data usage</DIV>
<DIV> return hBitmap;<BR>}</DIV>
<DIV><BR>void CSequenceAvi::OnPaint() <BR>{<BR> CPaintDC dc(this); // device context for painting<BR> <BR> // TODO: Add your message handler code here<BR> ShowBitmap(&dc);</DIV>
<DIV> //Draw rectangle<BR> SetPenBrush(&dc);<BR> dc.Rectangle(rect_roi);<BR> ResetPenBrush(&dc);<BR>}</DIV>
<DIV><BR>void CSequenceAvi::ShowBitmap(CPaintDC *pDC)<BR>{<BR> //Sélectionner 1 nouvel objet en memoire, détruire l’ancien <BR> HGDIOBJ pOldObj = SelectObject(dcMem,hBitmap);<BR> if(pOldObj) DeleteObject(pOldObj);<BR> <BR> //draw avi file in a fixed rectangle<BR> CRect rect;<BR> GetDlgItem(IDC_RECT)->GetWindowRect(rect);<BR> ScreenToClient(rect);//convert coord of rect on screen to client area coord<BR> <BR> //move the bitmap from the memory to the screen<BR> pDC->StretchBlt(0,0,rect.Width(),rect.Height(),<BR> &dcMem, 0,0,<BR> width, height,SRCCOPY);<BR>}</DIV></DIV></DIV><p>
                <hr size=1>
Découvrez le nouveau Yahoo! Mail : <font color="red">1 Go d'espace</font> de stockage pour vos mails, photos et vidéos !<br><a href="http://us.rd.yahoo.com/mail_fr/mail_campaigns/splash/taglines_1go/default/*http://fr.promotions.yahoo.com/mail/creer28.html" target="_blank">Créez votre Yahoo! Mail</a>