<DIV>Hi,</DIV>
<DIV> </DIV>
<DIV>I tried <STRONG>SetParentId()</STRONG> from <STRONG>vtkImageViewer </STRONG>to make my 2D image displayed in the window I pass. It works well. </DIV>
<DIV> </DIV>
<DIV>However, my image is still displayed with its own dimensions, not the window's one. Could someone suggest me a way to stretch my image to the window size like I used to do with StretchBlt(for HBITMAP).</DIV>
<DIV> </DIV>
<DIV>By the way, what's the difference between vtkImageViewer and vtkImageViewer2?</DIV>
<DIV> </DIV>
<DIV>Thanks a lot,</DIV>
<DIV> </DIV>
<DIV>ISabelle <BR><BR><I><STRONG>Mark Wyszomierski <markww@gmail.com></STRONG></I> a écrit :</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Renaud,<BR><BR>If you call SetParentId() from vtkImageViewer, or vtkImageViewer2, the<BR>render context will be 'framed' within the window you passed as its<BR>parent, it works really well, and you don't need to deal with HBITMAPs<BR>etc.<BR><BR>If you don't want to do that, you are already using MFC, so look at<BR>the MFC class CImage. It really simplifies working with bitmaps at<BR>getting them painted to your dc.<BR><BR>Mark<BR><BR>On 5/20/05, Renaud Isabelle <RENAUISA@YAHOO.FR>wrote:<BR>> <BR>> Dear users,<BR>> <BR>> I have to build an user interface by using MS VC++ for medical image<BR>> processing. Instead of having to compute reading of image files, I am using<BR>> ITK-VTK but I am quite new in this.<BR>> <BR>> - I read a raw 3D image using ITK and, as you suggested in<BR>>
"http://public.kitware.com/pipermail/insight-users/2003-April/003345.html",<BR>> I use itkExtractImageFilter to create a 2D image from the 3D volume and get<BR>> the pixel data in a buffer with: <BR>> extractFilter->GetOutput()->GetBufferPointer().<BR>> <BR>> - I would like to create a bitmap from this data using MFC classes to show<BR>> the image in a frame of my user interface already built. To do so, I use<BR>> HBitmap and CreateDIBitmap, but HBITMAP returned is NULL and nothing<BR>> happens. <BR>> <BR>> - Can you suggest me a way to use VTK to display my image not in a modal<BR>> window apart as implemented in vtkImageViewer, but in a frame of my<BR>> interface?<BR>> <BR>> I joined a part of my code below. Please help me.<BR>> <BR>> Thanks in advance,<BR>> <BR>> Isabelle Renaud<BR>> <BR>> //-------code----------------------<BR>> 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();<BR>> }<BR>> catch(itk::ExceptionObject &exception)<BR>> {<BR>> CString msg;<BR>> msg.Format("Erreur: %s", exception.GetDescription());<BR>> AfxMessageBox(msg, MB_ICONERROR);<BR>> }<BR>> <BR>> //Create a device context to load the bitmap into<BR>> CPaintDC dc(this); <BR>> dcMem.CreateCompatibleDC(&dc);<BR>> if(GrabRAWFrame(1) != NULL) Invalidate();<BR>> else AfxMessageBox("erreur a creation de image BMP\n");<BR>> }<BR>> }<BR>> <BR>> HBITMAP CSequenceAvi::GrabRAWFrame(int frame)<BR>> {<BR>> //declarations<BR>> typedef short PixelType;<BR>> 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;<BR>> <BR>> //initialisations<BR>> ReaderType::Pointer reader = ReaderType::New();<BR>> ExtractType::Pointer extractFilter = ExtractType::New();<BR>> reader->SetFileName("myImage.mhd");<BR>> reader->Update();<BR>> ImageType3D::RegionType inputRegion = <BR>> reader->GetOutput()->GetLargestPossibleRegion();<BR>> ImageType3D::SizeType size = inputRegion.GetSize();<BR>> size[2] = 0;<BR>> ImageType3D::IndexType start = inputRegion.GetIndex();<BR>> start[2] = frame;<BR>> //creation of an image region<BR>> ImageType3D::RegionType desiredRegion;<BR>> desiredRegion.SetSize(size);<BR>> desiredRegion.SetIndex(start);<BR>> //region passed to filter to extract<BR>>
extractFilter->SetExtractionRegion(desiredRegion);<BR>> //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>> }<BR>> <BR>> //get the data<BR>> ImageType2D::Pointer image = extractFilter->GetOutput();<BR>> short* pData =<BR>> extractFilter->GetOutput()->GetBufferPointer();<BR>> <BR>> BITMAPINFOHEADER bih;<BR>> memset(&bih, 0, sizeof(BITMAPINFOHEADER));<BR>> 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)<BR>> >>3)*bih.biHeight;<BR>> //0 for uncompressed images<BR>> <BR>> //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<BR>> 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<BR>> return hBitmap;<BR>> }<BR>> <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);<BR>> //Draw rectangle<BR>> SetPenBrush(&dc);<BR>> dc.Rectangle(rect_roi);<BR>>
ResetPenBrush(&dc);<BR>> }<BR>> <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>> }<BR>> <BR>> ________________________________<BR>> Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails,<BR>> photos et vidéos !<BR>> Créez votre Yahoo! Mail <BR>> <BR>> <BR>> _______________________________________________<BR>> Insight-users mailing list<BR>>
Insight-users@itk.org<BR>> http://www.itk.org/mailman/listinfo/insight-users<BR>> <BR>> <BR>><BR></BLOCKQUOTE><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>