[vtkusers] Re: Creating a Volume from 2D BMP files.
Sharwari Mavalankar
sharwari at gmail.com
Tue Aug 22 17:30:22 EDT 2006
hi all,
This is with reference to my earlier mail about creating a volume out of 2D
BMP slices.
As suggested I included SetDataExtent( ) and vtkVolume in my program.
However now the output cannot be seen at all.
The program just exits giving me an access violation error at runtime.
Why does this error come?
Here is my code :
//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"
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->SetDataSpacing(1,1,1);
br->SetDataOrigin(0,0,0);
br->Update();
br->SetDataExtent(0,255,0,255,0,7);
vtkVolumeRayCastMapper *VolumeMapper = vtkVolumeRayCastMapper::New();
vtkVolumeRayCastCompositeFunction *RayCastFunction =
vtkVolumeRayCastCompositeFunction::New();
VolumeMapper->SetVolumeRayCastFunction(RayCastFunction);
VolumeMapper->SetInput(br->GetOutput());
vtkVolume *volume = vtkVolume::New();
volume->SetMapper(VolumeMapper);
aRenderer->AddActor(volume);
aRenderer->SetBackground(1,1,1);
renWin->Render();
iren->Initialize();
iren->Start();
}
Hoping someone can help me out.
Thanks
Sharwari
On 8/15/06, Sharwari Mavalankar <sharwari at gmail.com> wrote:
>
> hi all,
> I am trying to create a 3D volume out of 2D Bmp slices.
> I believe that the BMP files are being read because the outputis a 2D
> image which I cannot render.
> The output does not look like a volume but just a 2D image.
> Here is my code.
>
>
> #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"
>
>
> 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->SetDataSpacing(1,1,0.1);
> br->SetDataOrigin(0,0,0);
> br->Update();
>
>
> vtkActor2D *Actor2D=vtkActor2D::New();
> vtkImageMapper *ImageMapper = vtkImageMapper::New();
>
> ImageMapper->SetInput(br->GetOutput());
> Actor2D->SetMapper(ImageMapper);
>
>
> aRenderer->AddActor(Actor2D);
> aRenderer->SetBackground(1,1,1);
> iren->Initialize();
> iren->Start();
>
>
>
>
> }
>
> Hope to get some help here!
>
> Thanks
>
> Sharwari
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060822/b9562fa7/attachment.htm>
More information about the vtkusers
mailing list