[vtkusers] How read the scalar data in a vtkvolume16reader object? (the scalar data associated with some specified voxel)
Amy Henderson
amy.henderson at kitware.com
Mon May 3 08:42:14 EDT 2004
The problem is that the data isn't actually read from your file until
Update is called on the reader. Try adding the line v16->Update(); before
you try to get its output.
- Amy
At 06:41 AM 4/30/2004, Dumont Nicolas wrote:
>Hello !!! I am using vtkvolume16reader to read the CT data quarter.1-93
>I wish to modify the scalar data at some voxel. So first I try to copy
>volume16reader->GetOutput() (which is a vtkImageData object ?) in a new
>vtkImageData object.
>
>Here is the c++ code i tried:
>
>vtkVolume16Reader *v16 = vtkVolume16Reader::New();
> v16->SetDataDimensions(64,64);
> v16->SetDataByteOrderToLittleEndian();
> v16->SetFilePrefix (argv[1]);
> v16->SetImageRange(1, 93);
> v16->SetDataSpacing (3.2, 3.2, 1.5);
>
>vtkImageData *imageData = vtkImageData::New();
> imageData->SetDimensions(64,64,93);
> imageData->SetSpacing(3.2,3.2,1.5);
> imageData->SetOrigin(0.0,0.0,0.0);
> imageData->SetScalarTypeToUnsignedChar();
> imageData->SetNumberOfScalarComponents(1);
> imageData->AllocateScalars();
> imageData->GetPointData()->CopyAllOn();
> imageData->GetPointData()->CopyScalarsOn();
>
>for (int i=0; i<64*64*93; i++)
>{
> imageData->GetPointData()->CopyData( v16->GetOutput()->GetPointData(),
>i, i );
>} //this give me a all black volume, only the outline of the data is visible
>
>
>/* unsigned char *ptr2 =(unsigned char *)
>v16->GetOutput()->GetScalarPointer();
>unsigned char *ptr =(unsigned char *) imageData->GetScalarPointer();
>
>for (int i=0; i<64*64*93; i++)
>{
> *ptr = *ptr2;
> ptr++;
> ptr2++;
>}*/
>// this returns the error that ptr2 points to memory adress 0x00000000 and
>cant be read.
>
>so .... How can I read the scalar data at some specified voxel in a
>vtkvolume16reader object?
>thanks in advance,
>Nicolas D.
>Belgium, ulg.
>
>Here my hole code :
>
>#include <iostream>
>#include <vector>
>#include <string>
>#include <stdio.h>
>
>#include "vtkRenderer.h"
>#include "vtkRenderWindow.h"
>#include "vtkRenderWindowInteractor.h"
>#include "vtkVolume16Reader.h"
>#include "vtkVolumeRayCastCompositeFunction.h"
>#include "vtkVolumeRayCastMapper.h"
>#include "vtkVolumeRayCastCompositeFunction.h"
>#include "vtkPiecewiseFunction.h"
>#include "vtkColorTransferFunction.h"
>#include "vtkVolumeProperty.h"
>#include "vtkVolume.h"
>#include "vtkOutlineFilter.h"
>#include "vtkPolyDataMapper.h"
>#include "vtkActor.h"
>#include "vtkCamera.h"
>#include "vtkProperty.h"
>#include "vtkInteractorStyleTrackballCamera.h"
>#include "vtkImageData.h"
>#include "vtkPointData.h"
>#include "vtkCellData.h"
>#include "vtkDataSetAttributes.h"
>
>
>
>
>
>int main (int argc, char **argv)
>{
> if (argc < 2)
> {
> cout << "Usage: " << argv[0] << " DATADIR/headsq/quarter " << endl;
> return 1;
> }
>
>
>vtkVolume16Reader *v16 = vtkVolume16Reader::New();
> v16->SetDataDimensions(64,64);
> v16->SetDataByteOrderToLittleEndian();
> v16->SetFilePrefix (argv[1]);
> v16->SetImageRange(1, 93);
> v16->SetDataSpacing (3.2, 3.2, 1.5);
>
>
>
>vtkImageData *imageData = vtkImageData::New();
> imageData->SetDimensions(64,64,93);
> imageData->SetSpacing(3.2,3.2,1.5);
> imageData->SetOrigin(0.0,0.0,0.0);
> imageData->SetScalarTypeToUnsignedChar();
> imageData->SetNumberOfScalarComponents(1);
> imageData->AllocateScalars();
> imageData->GetPointData()->CopyAllOn();
> imageData->GetPointData()->CopyScalarsOn();
>
>/*for (int i=0; i<64*64*93; i++)
>{
> imageData->GetPointData()->CopyData(
> v16->GetOutput()->GetPointData(), i,
>i );
>}*/
>
>unsigned char *ptr2 =(unsigned char *) v16->GetOutput()->GetScalarPointer();
>unsigned char *ptr =(unsigned char *) imageData->GetScalarPointer();
>
>for (int i=0; i<64*64*93; i++)
>{
> *ptr = *ptr2;
> ptr++;
> ptr2++;
>}
>
>vtkVolumeRayCastCompositeFunction *compositeFunction =
>vtkVolumeRayCastCompositeFunction::New();
>
>
>vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
> volumeMapper->SetInput(imageData);
> volumeMapper->SetVolumeRayCastFunction(compositeFunction);
> //volumeMapper->CroppingOn();
> //volumeMapper->SetCroppingRegionPlanes(60,100,60,100,60,100);
> //volumeMapper->SetCroppingRegionFlags(0x7ffffdf);
>
>
>vtkPiecewiseFunction *tfun = vtkPiecewiseFunction::New();
> tfun->AddPoint(399.0,0.0);
> tfun->AddPoint(400.0,0.2);
> tfun->AddPoint(700.0,0.2);
> tfun->AddPoint(701.0,0.05);
> tfun->AddPoint(1199,0.05);
> tfun->AddPoint(1200,0.2);
> tfun->AddPoint(2649,0.2);
> tfun->AddPoint(2650,0.2);
>
>vtkColorTransferFunction *ctfun = vtkColorTransferFunction::New();
> ctfun->AddRGBPoint(350, 1.0, 1.0, 1.0);
> ctfun->AddRGBPoint(500, 1.0, 0.5, 0.5);
> ctfun->AddRGBPoint(650, 1.0, 0.5, 0.5);
> ctfun->AddRGBPoint(800, 0.6, 0.5, 0.3);
> ctfun->AddRGBPoint(1000, 0.6, 0.5, 0.3);
> ctfun->AddRGBPoint(1500, 1.0, 1.0, 1.0);
> ctfun->AddRGBPoint(2000, 1.0, 0.1, 0.1);
> ctfun->AddRGBPoint(2700, 0.0, 1.0, 0.0);
>
>
>
>vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
> volumeProperty->SetColor(ctfun);
> volumeProperty->SetScalarOpacity(tfun);
> volumeProperty->SetInterpolationTypeToLinear();
> volumeProperty->ShadeOn();
>
>
>vtkVolume *newvol = vtkVolume::New();
> newvol->SetMapper(volumeMapper);
> newvol->SetProperty(volumeProperty);
>
>
>
>vtkOutlineFilter *outline = vtkOutlineFilter::New();
> outline->SetInput((vtkDataSet *) v16->GetOutput());
>
>
>vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
> outlineMapper->SetInput(outline->GetOutput());
>
>vtkActor *outlineActor = vtkActor::New();
> outlineActor->SetMapper(outlineMapper);
> outlineActor->GetProperty()->SetColor(1,1,1);
>
>
>
>vtkCamera *Camera = vtkCamera::New();
> Camera->SetViewUp (0, 0, -1);
> Camera->SetPosition (140, 600, -100);
> Camera->SetFocalPoint (100, 100, 75);
> Camera->ComputeViewPlaneNormal();
>
>
>vtkRenderer *ren = vtkRenderer::New();
> ren->AddActor(outlineActor);
> ren->AddVolume(newvol);
> ren->SetBackground(0,0,0);
> ren->SetActiveCamera(Camera);
>
>
>vtkRenderWindow *renWin = vtkRenderWindow::New();
> renWin->AddRenderer(ren);
> renWin->SetSize(640,480);
>
>
>vtkInteractorStyleTrackballCamera *style =
>vtkInteractorStyleTrackballCamera::New();
>
>vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
> iren->SetInteractorStyle(style);
> iren->Initialize();
> iren->Start();
>
>
>
>
> v16->Delete();
> compositeFunction->Delete();
> volumeMapper->Delete();
> tfun->Delete();
> ctfun->Delete();
> volumeProperty->Delete();
> newvol->Delete();
> outline->Delete();
> outlineMapper->Delete();
> outlineActor->Delete();
> Camera->Delete();
> ren->Delete();
> renWin->Delete();
> iren->Delete();
> style->Delete();
>
> return 0;
>}
>
>
>
>
>
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at:
><http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list