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

Ashish Singh mrasingh at gmail.com
Wed Sep 13 13:23:43 EDT 2006


Hi Amy,

I don't remember if VTK_USE_RENDERING variable was ON or not. Is there a way
to confirm that? However I am able to compile and run other programs from
the examples/tutorials directory such as cones etc. as well as read and
display single dicom image and interact with it using
renderwindowinteractor.

Here is my cmakelists.txt file for cone example:
---
PROJECT (Step1)

FIND_PACKAGE(VTK REQUIRED)
IF(NOT VTK_USE_RENDERING)
  MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")
ENDIF(NOT VTK_USE_RENDERING)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(Cone Cone.cxx)
TARGET_LINK_LIBRARIES(Cone vtkRendering)
----
This works fine.

The cmakelists.txt file that I use for dicom volume problem is :
----
PROJECT (multiimagereader)

INCLUDE (${CMAKE_ROOT}/Modules/FindVTK.cmake)
IF (USE_VTK_FILE)
  INCLUDE(${USE_VTK_FILE})
ENDIF (USE_VTK_FILE)

ADD_EXECUTABLE(multiimagereader multiimagereader.cxx)
TARGET_LINK_LIBRARIES(multiimagereader vtkRendering)
----
Is there anything that I need to modify in this file?

Thanks,
Ashish


On 9/13/06, Amy Squillacote <amy.squillacote at kitware.com> wrote:
>
>  Hi Ashish,
>
> When you built VTK, was the VTK_USE_RENDERING CMake variable set to ON? If
> it was, are you linking against the vtkVolumeRendering library?
>
> - Amy
>
> Ashish Singh wrote:
>
> Hi Yixun and Sharwari,
>
> I am trying to solve exactly similar problem but using DICOM images rather
> than bmp. But I am getting errors and I can't figure out why. My code is
> based on your previous conversation so far. The error that I get is:
> (1)error LNK2019: unresolved external symbol "public: static class
> vtkVolumeRayCastCompositeFunction * __cdecl
> vtkVolumeRayCastCompositeFunction::New(void)"
> (?New at vtkVolumeRayCastCompositeFunction@@SAPAV1 at XZ ) referenced in
> function _main
>  (2)error LNK2019: unresolved external symbol "public: static class
> vtkVolumeRayCastMapper * __cdecl vtkVolumeRayCastMapper::New(void)"
> (?New at vtkVolumeRayCastMapper@@SAPAV1 at XZ) referenced in function _main
> (3)fatal error LNK1120: 2 unresolved externals
>
> Can you please help me figure out what's going wrong here?
>
> My code is as follows:
> -----
> #include "vtkConeSource.h"
> #include "vtkPolyDataMapper.h "
> #include "vtkRenderWindow.h"
> #include "vtkCamera.h"
> #include "vtkActor.h"
> #include "vtkImageActor.h"
> #include "vtkOutlineFilter.h"
> #include " vtkProperty.h"
> #include "vtkPolyDataNormals.h"
> #include "vtkContourFilter.h"
> #include "vtkDataSetMapper.h"
> #include "vtkImageMapper.h"
> #include "vtkPiecewiseFunction.h "
> #include "vtkVolumeProperty.h"
> #include "vtkRenderer.h"
> #include "conio.h"
> #include "vtkDICOMImageReader.h"
> #include "vtkImageViewer2.h"
> #include " vtkJPEGReader.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkVolumeMapper.h"
> #include "vtkActor2D.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkVolumeRayCastCompositeFunction.h "
> #include "vtkVolumeRayCastMapper.h"
>
> void main()
> {
>
>   vtkRenderer *arenderer = vtkRenderer::New();
>   vtkRenderWindow *renwin = vtkRenderWindow::New();
>   vtkDICOMImageReader *img1=vtkDICOMImageReader::New();
>
>   img1->SetFilePrefix("D:\\testimages\\dicomset\\IM");
>   img1->SetFilePattern("%s%d.dcm");
>   img1->SetFileNameSliceOffset(1);
>   img1->SetFileNameSliceSpacing(1);
>   img1->SetDataExtent(0,511,0,511,1,10);//512x512 images and 10 slices
>   img1->SetDataSpacing(360.0/512,360.0/512,1.0); //my image is 36cm x 36cm
> and 512x512
>   img1->SetDataOrigin(0.0,0.0,0.0);
>   img1->Update();
>
>   vtkVolume *vol=vtkVolume::New();
>   vtkVolumeRayCastMapper *volumemapper = vtkVolumeRayCastMapper::New();
>   vtkVolumeRayCastCompositeFunction
> *rcf=vtkVolumeRayCastCompositeFunction::New();
>   volumemapper->SetVolumeRayCastFunction(rcf);
>   volumemapper->SetInput(img1->GetOutput());
>   vol->SetMapper(volumemapper);
>
>   vtkCamera *cam=vtkCamera::New();
>   cam->SetViewUp(0,0,-1);
>   cam->SetPosition(0,1,0);
>   cam->SetFocalPoint(0,0,0);
>   cam->ComputeViewPlaneNormal();
>
>   arenderer->AddActor(vol);
>   arenderer->SetActiveCamera(cam);
>   arenderer->ResetCamera();
>   arenderer->SetBackground(1,1,1);
>
>   renwin->AddRenderer(arenderer);
>   vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
>   iren->SetRenderWindow(renwin);
>   renwin->Render();
>   iren->Initialize();
>   iren->Start();
>
>   img1->Delete();
>   iren->Delete();
> }
> --------
> I would really appreciate if anyone can help me.
>
> Regards,
> Ashish
>
> On 9/7/06, Sharwari Mavalankar < sharwari at gmail.com> wrote:
> >
> >  hi Yixun,
> > I'll try and look into why the volume appears darker.
> >
> > However I'll there are many lines that are appearing on the volume (they
> > look like striations).
> > Do you know what the reason for that could be?
> >
> >
> > Also if I have to visualize color bmp slices (24 bit ) I need vtkFixedPointVolumeRayCastMapper
> > right?
> > Thanks
> >  Sharwari
> >
> >
> >  On 9/6/06, Yixun Liu <yxliu at fudan.edu.cn> wrote:
> > >
> > >  Hi,
> > > You are right and alwayse taking mm as the unit.
> > > SpacingX = 5.12*10/256;
> > > SpacingY = 5.12*10/256;
> > >
> > > Many reason can make the volume look darker.
> > > You can change the opacity and color interpolation function to adjust
> > > the appearance of the volume. If you use shade you can also change ambient
> > > or diffusion coefficient to make the volume look more lighter. Another
> > > method is to change the vtkLight in the renderer. vtkLight is a
> > > virtual light for 3D rendering. It provides methods to locate and point the
> > > light, turn it on and off, and set its brightness and color.
> > >
> > > Cheers,
> > >
> > > Yixun Liu
> > >   ----- Original Message -----
> > > *From:* Sharwari Mavalankar <sharwari at gmail.com>
> > > *To:* Yixun Liu <yxliu at fudan.edu.cn>
> > > *Cc:* VTK <vtkusers at vtk.org>
> > >  *Sent:* Thursday, September 07, 2006 1:43 AM
> > > *Subject:* Re: Re: Re: Creating a Volume from 2D BMP files.
> > >
> > >
> > > hi Yixun,
> > > Thank you very much for your email.
> > > What exactly do you mean by the physical size of the image?
> > > Does it mean the size of the image in cm or mm?
> > >
> > > For example if my original images are 5.12 cm * 5.12 cm and are 256 *
> > > 256 images.
> > > What will the data spacing be?
> > >
> > >
> > > Also can you tell me the reason why the 3D volume seems darker than
> > > the original images?
> > > Is there any way I can scale the intensity of the images?
> > > Thanks again,
> > > Sharwari
> > >
> > >
> > > On 9/3/06, Yixun Liu <yxliu at fudan.edu.cn> wrote:
> > > >
> > > >  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 <sharwari at gmail.com>
> > > > *To:* Yixun Liu <yxliu at fudan.edu.cn>
> > > > *Cc:* VTK <vtkusers at vtk.org>
> > > >  *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 <sharwari at gmail.com>
> > > > > *To:* Yixun Liu <yxliu at fudan.edu.cn>
> > > > > *Cc:* VTK <vtkusers at vtk.org>
> > > > > *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
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
> >
> ------------------------------
>
> _______________________________________________ This is the private VTK
> discussion list. Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060913/3852c122/attachment.htm>


More information about the vtkusers mailing list