<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Bookman Old Style">Hi,</FONT></DIV>
<DIV><FONT face="Bookman Old Style">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</FONT></DIV>
<DIV><FONT 
face="Bookman Old Style">br-&gt;SetNumberOfScalarComponents(3);</FONT></DIV>
<DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
<DIV><FONT face="Bookman Old Style">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.</FONT></DIV>
<DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
<DIV><FONT face="Bookman Old Style">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</FONT></DIV>
<DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
<DIV><FONT face="Bookman Old Style">Hope it help.</FONT></DIV>
<DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
<DIV><FONT face="Bookman Old Style">Cheers,</FONT></DIV>
<DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
<DIV><FONT face="Bookman Old Style">Yixun Liu</FONT></DIV>
<DIV><FONT face="Bookman Old Style"><BR></FONT></DIV>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 9pt &#23435;&#20307;">----- Original Message ----- </DIV>
  <DIV style="BACKGROUND: #e4e4e4; FONT: 9pt &#23435;&#20307;; font-color: black"><B>From:</B> 
  <A title=sharwari@gmail.com href="mailto:sharwari@gmail.com">Sharwari 
  Mavalankar</A> </DIV>
  <DIV style="FONT: 9pt &#23435;&#20307;"><B>To:</B> <A title=yxliu@fudan.edu.cn 
  href="mailto:yxliu@fudan.edu.cn">Yixun Liu</A> </DIV>
  <DIV style="FONT: 9pt &#23435;&#20307;"><B>Cc:</B> <A title=vtkusers@vtk.org 
  href="mailto:vtkusers@vtk.org">VTK</A> </DIV>
  <DIV style="FONT: 9pt &#23435;&#20307;"><B>Sent:</B> Monday, September 04, 2006 6:50 
AM</DIV>
  <DIV style="FONT: 9pt &#23435;&#20307;"><B>Subject:</B> Re: Re: Creating a Volume from 2D 
  BMP files.</DIV>
  <DIV><BR></DIV>
  <DIV>hi Yixun,</DIV>
  <DIV>I implemented the suggestions that you had made.</DIV>
  <DIV>Now I am getting a 3D volume but it doesnt look anything like the 
  original 2D slices.</DIV>
  <DIV>It is much darker in appearance and it's got lines all over it ( it looks 
  as though it's some kind of aliasing).</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>I have the following questions to ask you </DIV>
  <DIV>1.While using the function SetDataSpacing(x,y,z) how do I decide the 
  values of the parameters x,y and z.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>2.While using the Addpoint() &nbsp;function of class vtkPiecewiseFunction 
  what do the two parameters in the Addpoint function mean?</DIV>
  <DIV>How do they affect the output?</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>This is code I have used. Do let me know if you can make any more 
  sugestions.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>
  <P>//This program reads a single BMP file and plots it as an image.<BR>//The 
  same program will be extended to read multiple images and create a 3D volume 
  out of 2D slices.</P>
  <P><BR>#include "vtkRenderer.h"<BR>#include "vtkRenderWindow.h"<BR>#include 
  "vtkRenderWindowInteractor.h"<BR>#include "vtkBMPReader.h"<BR>#include 
  "vtkPolyDataMapper.h"<BR>#include "vtkActor.h"<BR>#include 
  "vtkActor2D.h"<BR>#include "vtkImageActor.h"<BR>#include 
  "vtkOutlineFilter.h"<BR>#include "vtkCamera.h"<BR>#include "vtkProperty.h" 
  <BR>#include "vtkPolyDataNormals.h"<BR>#include 
  "vtkContourFilter.h"<BR>#include "vtkDataSetMapper.h"<BR>#include 
  "vtkImageMapper.h"<BR>#include "vtkVolumeMapper.h"<BR>#include " 
  vtkVolumeRayCastMapper.h"<BR>#include 
  "vtkVolumeRayCastCompositeFunction.h"<BR>#include 
  "vtkPiecewiseFunction.h"<BR>#include "vtkVolumeProperty.h"</P>
  <P><BR>void main (void)<BR>{<BR>&nbsp;<BR>&nbsp;vtkRenderer *aRenderer = 
  vtkRenderer::New();<BR>&nbsp;&nbsp;&nbsp; vtkRenderWindow *renWin = 
  vtkRenderWindow::New();<BR>&nbsp;&nbsp;&nbsp; 
  <BR>&nbsp;renWin-&gt;AddRenderer(aRenderer);<BR>&nbsp;&nbsp;&nbsp; 
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); 
  <BR>&nbsp;&nbsp;&nbsp; iren-&gt;SetRenderWindow(renWin);</P>
  <P><BR>&nbsp;//create an instance of the class 
  vtkBMPReader<BR>&nbsp;vtkBMPReader *br = 
  vtkBMPReader::New();<BR>&nbsp;<BR>&nbsp;br-&gt;SetFilePrefix("C:\\Images\\conductivities\\slice"); 
  <BR>&nbsp;br-&gt;SetFilePattern("%s%d.bmp"); 
  <BR>&nbsp;br-&gt;SetFileNameSliceOffset(1);<BR>&nbsp;br-&gt;SetFileNameSliceSpacing(1);<BR>&nbsp;br-&gt;SetNumberOfScalarComponents(3);<BR>&nbsp;br-&gt;SetDataSpacing(0.4,0.4,10);<BR>&nbsp;br-&gt;SetDataOrigin(0,0,0);<BR>&nbsp;br-&gt;SetDataExtent(0,255,0,255,0,7); 
  <BR>&nbsp;br-&gt;Update();<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; 
  vtkPiecewiseFunction *opacityTransferFunction = 
  vtkPiecewiseFunction::New();<BR>&nbsp;opacityTransferFunction-&gt;AddPoint(20,0.2);<BR>&nbsp;opacityTransferFunction-&gt;AddPoint(255,1.0);</P>
  <P>&nbsp;vtkVolumeProperty *volumeProperty = 
  vtkVolumeProperty::New();<BR>&nbsp;volumeProperty-&gt;SetScalarOpacity(opacityTransferFunction);<BR>&nbsp;</P>
  <P><BR>&nbsp;<BR>&nbsp;vtkVolumeRayCastMapper *VolumeMapper = 
  vtkVolumeRayCastMapper::New();<BR>&nbsp;&nbsp;&nbsp; 
  vtkVolumeRayCastCompositeFunction *RayCastFunction = 
  vtkVolumeRayCastCompositeFunction::New();<BR>&nbsp;&nbsp;&nbsp; 
  VolumeMapper-&gt;SetVolumeRayCastFunction(RayCastFunction); 
  <BR>&nbsp;&nbsp;&nbsp; VolumeMapper-&gt;SetInput(br-&gt;GetOutput());</P>
  <P>&nbsp;&nbsp;&nbsp; <BR>&nbsp;vtkVolume *volume = 
  vtkVolume::New();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; 
  VolumeMapper-&gt;SetInput(br-&gt;GetOutput());<BR>&nbsp;&nbsp; 
  volume-&gt;SetMapper(VolumeMapper);</P>
  <P>&nbsp;&nbsp;&nbsp; vtkCamera *aCamera = 
  vtkCamera::New();<BR>&nbsp;&nbsp;&nbsp; aCamera-&gt;SetViewUp (0, 
  0,-1);<BR>&nbsp;&nbsp;&nbsp; aCamera-&gt;SetPosition (0, 1, 
  0);<BR>&nbsp;&nbsp;&nbsp; aCamera-&gt;SetFocalPoint (0, 0, 
  0);<BR>&nbsp;&nbsp;&nbsp; aCamera-&gt;ComputeViewPlaneNormal();</P>
  <P><BR>&nbsp;&nbsp;aRenderer-&gt;AddActor(volume);<BR>&nbsp;aRenderer-&gt;SetActiveCamera(aCamera);<BR>&nbsp;&nbsp;&nbsp; 
  aRenderer-&gt;ResetCamera 
  ();<BR>&nbsp;aRenderer-&gt;SetBackground(1,1,1);<BR>&nbsp;renWin-&gt;Render();<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 
  iren-&gt;Initialize(); <BR>&nbsp;&nbsp;&nbsp; iren-&gt;Start(); 
  <BR>&nbsp;<BR>}</P></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>Thanks again for all your help.</DIV>
  <DIV>Sharwari<BR><BR>&nbsp;</DIV>
  <DIV><SPAN class=gmail_quote>On 8/31/06, <B class=gmail_sendername>Yixun 
  Liu</B> &lt;<A href="mailto:yxliu@fudan.edu.cn">yxliu@fudan.edu.cn</A>&gt; 
  wrote:</SPAN> 
  <BLOCKQUOTE class=gmail_quote 
  style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
    <DIV>
    <DIV bgcolor="#ffffff">
    <DIV><FONT face="Bookman Old Style">Hi,</FONT></DIV>
    <DIV><FONT face="Bookman Old Style">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. </FONT></DIV>
    <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
    <DIV><FONT face="Bookman Old Style">If you use vtkVolume, use 
    vtkVolumeRayCastMapper(vtk4.2.2) or&nbsp;use 
    vtkFixedPointVolumeRayCastMapper(vtk5.0). Note that if you use 
    vtkFixedPointVolumeRayCastMapper you no need to call 
    SetVolumeRayCastFunction(); </FONT></DIV>
    <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
    <DIV><FONT face="Bookman Old Style">Hope it help.</FONT></DIV></DIV>
    <DIV><SPAN class=sg>
    <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
    <DIV><FONT face="Bookman Old Style"><SPAN class=st id=st 
    name="st">Yixun</SPAN> Liu</FONT></DIV></SPAN></DIV>
    <DIV><SPAN class=e id=q_10d66d8eca6b69f3_2>
    <BLOCKQUOTE 
    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
      <DIV>----- Original Message ----- </DIV>
      <DIV style="BACKGROUND: #e4e4e4"><B>From:</B> <A title=sharwari@gmail.com 
      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:sharwari@gmail.com" target=_blank>Sharwari Mavalankar</A> 
      </DIV>
      <DIV><B>To:</B> <A title=yxliu@fudan.edu.cn 
      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:yxliu@fudan.edu.cn" target=_blank>Yixun Liu</A> </DIV>
      <DIV><B>Cc:</B> <A title=vtkusers@vtk.org 
      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:vtkusers@vtk.org" target=_blank>VTK</A> </DIV>
      <DIV><B>Sent:</B> Thursday, August 31, 2006 6:37 PM</DIV>
      <DIV><B>Subject:</B> Re: Creating a Volume from 2D BMP files.</DIV>
      <DIV><BR>&nbsp;</DIV>
      <DIV>hi Yixun,</DIV>
      <DIV>Thanks for your email.I had a couple of more questions though.</DIV>
      <DIV>1.I do not want to visualize colour slices.They are grey level 
      images.</DIV>
      <DIV>&nbsp;</DIV>
      <DIV>2.Also if I put SetDataExtent() before the Update() then I am getting 
      an access violation error.What does the Update function do exactly?</DIV>
      <DIV>Also can you tell me what the five parameters in SetDataExtent() 
      mean?</DIV>
      <DIV>&nbsp;</DIV>
      <DIV>3.If I use vtkVolume what mapper should I use to visualize the 
      slices?</DIV>
      <DIV>&nbsp;</DIV>
      <DIV>&nbsp;</DIV>
      <DIV>Thanks again for all your help.</DIV>
      <DIV>Sharwari</DIV>
      <DIV><BR><BR>&nbsp;</DIV>
      <DIV><SPAN class=gmail_quote>On 8/23/06, <B class=gmail_sendername>Yixun 
      Liu</B> &lt;<A onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:yxliu@fudan.edu.cn" target=_blank>yxliu@fudan.edu.cn</A>&gt; 
      wrote: </SPAN>
      <BLOCKQUOTE class=gmail_quote 
      style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
        <DIV>
        <DIV bgcolor="#ffffff">
        <DIV><FONT face="Bookman Old Style">Hi,</FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style">If you want to visualize color 
        slices, you need to </FONT></DIV>
        <DIV><FONT face="Bookman Old Style">1. read these slices. You need to 
        put the SetDataExtent(0, 111, 0, 127, 1, 300);<BR>before 
        Update();</FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style">&nbsp;vtkTIFFReader *v16 = 
        vtkTIFFReader::New();<BR></FONT><FONT 
        face="Bookman Old Style">&nbsp;v16-&gt;SetFilePrefix("D:\\MyVC\\VTKtest\\Raycasting\\Data\\BrainColor\\brain");<BR>&nbsp;v16-&gt;SetFilePattern("%s%d.TIF"); 
        <BR>&nbsp;v16-&gt;SetDataExtent(0, 111, 0, 127, 1, 
        300);<BR>&nbsp;v16-&gt;SetDataSpacing(1.2,1.2,0.5);<BR>&nbsp;v16-&gt;SetDataOrigin(0.0, 
        0.0, 0.0);</FONT></DIV>
        <DIV><FONT 
        face="Bookman Old Style">&nbsp;v16-&gt;SetNumberOfScalarComponents(3);<BR></FONT><FONT 
        face="Bookman Old Style">&nbsp;v16-&gt;Update();</FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style">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. </FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style">3. Opacity map using 
        vtkPiecewiseFunction</FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style">4. no need color map 
        function</FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style">5. you need vtk5.0</FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style">Regads,</FONT></DIV>
        <DIV><FONT face="Bookman Old Style"></FONT>&nbsp;</DIV>
        <DIV><FONT face="Bookman Old Style"><SPAN name="st">Yixun</SPAN> 
        Liu</FONT></DIV>
        <DIV><BR>&nbsp;</DIV>
        <DIV><FONT 
      face="Bookman Old Style"></FONT>&nbsp;</DIV></DIV></DIV></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></SPAN></DIV>
    <DIV></DIV></DIV></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></BODY></HTML>