[vtkusers] Re: Re: Re: Creating a Volume from 2D BMP files.

Yixun Liu yxliu at fudan.edu.cn
Sun Sep 3 20:56:33 EDT 2006


Hi,
If you read color bmp files you should update vtk to 5.0 version and use vtkFixedPointVolumeRayCastMapper(see last mail). Otherwise, you should not call
br->SetNumberOfScalarComponents(3);

1. You can decide the physical spacing accroding to the image extent(pixel unit) and its physical size(mm): spacing = size/(extent-1); If no physical size you have to give a estimation for the spacing.

2.The point1 and point2 will define a linear opacity function, which can be interpolated from the two points. For example, define two points (intensity1, opacity1)and (intensity2, opacity2) you can get the opacity3 at intensity3 by opacity3 = (intensity3-intensity1)/(intensity2-intensity1)*(opacity2-opacity1) + opacity1

Hope it help.

Cheers,

Yixun Liu


  ----- Original Message ----- 
  From: Sharwari Mavalankar 
  To: Yixun Liu 
  Cc: VTK 
  Sent: Monday, September 04, 2006 6:50 AM
  Subject: Re: Re: Creating a Volume from 2D BMP files.


  hi Yixun,
  I implemented the suggestions that you had made.
  Now I am getting a 3D volume but it doesnt look anything like the original 2D slices.
  It is much darker in appearance and it's got lines all over it ( it looks as though it's some kind of aliasing).

  I have the following questions to ask you 
  1.While using the function SetDataSpacing(x,y,z) how do I decide the values of the parameters x,y and z.

  2.While using the Addpoint()  function of class vtkPiecewiseFunction what do the two parameters in the Addpoint function mean?
  How do they affect the output?


  This is code I have used. Do let me know if you can make any more sugestions.


  //This program reads a single BMP file and plots it as an image.
  //The same program will be extended to read multiple images and create a 3D volume out of 2D slices.


  #include "vtkRenderer.h"
  #include "vtkRenderWindow.h"
  #include "vtkRenderWindowInteractor.h"
  #include "vtkBMPReader.h"
  #include "vtkPolyDataMapper.h"
  #include "vtkActor.h"
  #include "vtkActor2D.h"
  #include "vtkImageActor.h"
  #include "vtkOutlineFilter.h"
  #include "vtkCamera.h"
  #include "vtkProperty.h" 
  #include "vtkPolyDataNormals.h"
  #include "vtkContourFilter.h"
  #include "vtkDataSetMapper.h"
  #include "vtkImageMapper.h"
  #include "vtkVolumeMapper.h"
  #include " vtkVolumeRayCastMapper.h"
  #include "vtkVolumeRayCastCompositeFunction.h"
  #include "vtkPiecewiseFunction.h"
  #include "vtkVolumeProperty.h"


  void main (void)
  {
   
   vtkRenderer *aRenderer = vtkRenderer::New();
      vtkRenderWindow *renWin = vtkRenderWindow::New();
      
   renWin->AddRenderer(aRenderer);
      vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); 
      iren->SetRenderWindow(renWin);


   //create an instance of the class vtkBMPReader
   vtkBMPReader *br = vtkBMPReader::New();
   
   br->SetFilePrefix("C:\\Images\\conductivities\\slice"); 
   br->SetFilePattern("%s%d.bmp"); 
   br->SetFileNameSliceOffset(1);
   br->SetFileNameSliceSpacing(1);
   br->SetNumberOfScalarComponents(3);
   br->SetDataSpacing(0.4,0.4,10);
   br->SetDataOrigin(0,0,0);
   br->SetDataExtent(0,255,0,255,0,7); 
   br->Update();
    
      vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
   opacityTransferFunction->AddPoint(20,0.2);
   opacityTransferFunction->AddPoint(255,1.0);

   vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
   volumeProperty->SetScalarOpacity(opacityTransferFunction);
   


   
   vtkVolumeRayCastMapper *VolumeMapper = vtkVolumeRayCastMapper::New();
      vtkVolumeRayCastCompositeFunction *RayCastFunction = vtkVolumeRayCastCompositeFunction::New();
      VolumeMapper->SetVolumeRayCastFunction(RayCastFunction); 
      VolumeMapper->SetInput(br->GetOutput());

      
   vtkVolume *volume = vtkVolume::New();
     
      VolumeMapper->SetInput(br->GetOutput());
     volume->SetMapper(VolumeMapper);

      vtkCamera *aCamera = vtkCamera::New();
      aCamera->SetViewUp (0, 0,-1);
      aCamera->SetPosition (0, 1, 0);
      aCamera->SetFocalPoint (0, 0, 0);
      aCamera->ComputeViewPlaneNormal();


    aRenderer->AddActor(volume);
   aRenderer->SetActiveCamera(aCamera);
      aRenderer->ResetCamera ();
   aRenderer->SetBackground(1,1,1);
   renWin->Render();
   
      iren->Initialize(); 
      iren->Start(); 
   
  }


  Thanks again for all your help.
  Sharwari

   
  On 8/31/06, Yixun Liu <yxliu at fudan.edu.cn> wrote: 
    Hi,
    Assuming image is 256x256x100. The first file name is image1 and the last file name is image100. So, SetDataExtent(0, 255, 0, 255, 1, 100); The access violation may be caused by wrong extent setting. 

    If you use vtkVolume, use vtkVolumeRayCastMapper(vtk4.2.2) or use vtkFixedPointVolumeRayCastMapper(vtk5.0). Note that if you use vtkFixedPointVolumeRayCastMapper you no need to call SetVolumeRayCastFunction(); 

    Hope it help.

    Yixun Liu
      ----- Original Message ----- 
      From: Sharwari Mavalankar 
      To: Yixun Liu 
      Cc: VTK 
      Sent: Thursday, August 31, 2006 6:37 PM
      Subject: Re: Creating a Volume from 2D BMP files.

       
      hi Yixun,
      Thanks for your email.I had a couple of more questions though.
      1.I do not want to visualize colour slices.They are grey level images.

      2.Also if I put SetDataExtent() before the Update() then I am getting an access violation error.What does the Update function do exactly?
      Also can you tell me what the five parameters in SetDataExtent() mean?

      3.If I use vtkVolume what mapper should I use to visualize the slices?


      Thanks again for all your help.
      Sharwari


       
      On 8/23/06, Yixun Liu <yxliu at fudan.edu.cn> wrote: 
        Hi,

        If you want to visualize color slices, you need to 
        1. read these slices. You need to put the SetDataExtent(0, 111, 0, 127, 1, 300);
        before Update();

         vtkTIFFReader *v16 = vtkTIFFReader::New();
         v16->SetFilePrefix("D:\\MyVC\\VTKtest\\Raycasting\\Data\\BrainColor\\brain");
         v16->SetFilePattern("%s%d.TIF"); 
         v16->SetDataExtent(0, 111, 0, 127, 1, 300);
         v16->SetDataSpacing(1.2,1.2,0.5);
         v16->SetDataOrigin(0.0, 0.0, 0.0);
         v16->SetNumberOfScalarComponents(3);
         v16->Update();

        2. Add the 4th component. The first three components are color and the 4th is used to map to opacity. I compute the luminancy according to the firft three components and take it as the 4th component. 

        3. Opacity map using vtkPiecewiseFunction

        4. no need color map function

        5. you need vtk5.0

        Regads,

        Yixun Liu

         




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060904/11c58401/attachment.htm>


More information about the vtkusers mailing list