[vtkusers] Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Ali Habib ali.mahmoud.habib at gmail.com
Wed Oct 21 11:09:46 EDT 2009


My code use to render 3D volume of human face as attached  I want to create
a mesh for this volume I used the following code but it always through error
wich is

Attempted to read or write protected memory. This is often an indication
that other memory is corrupt.

the code is :


//Variables

double[] metaScalarRange = new double[2] { 0, 0 };

vtk.vtkRenderWindow renwM = new vtk.vtkRenderWindow();

vtk.vtkRenderer ren1= new vtkRenderer();

vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();

vtk.vtkVolume volume = new vtk.vtkVolume();

renwM.AddRenderer(ren1);

iren.SetRenderWindow(renwM);

// Read a DICOM series path:

vtk.vtkDICOMImageReader VDR = new vtk.vtkDICOMImageReader();

VDR.SetDirectoryName("D:\\Programming and tutorials\\Master source\\CT
test\\DICOM\\PA1\\ST1\\SE1\\");

VDR.SetDataOrigin(0, 0, 0);

VDR.Update();

/////

vtk.vtkImageChangeInformation VIC = new vtk.vtkImageChangeInformation();

VIC.SetInput(VDR.GetOutput());

VIC.CenterImageOn();

VIC.Update();

///////// Applying the mesh

vtkDataSetTriangleFilter VDST = new vtkDataSetTriangleFilter();

VDST.SetInputConnection(VDR.GetOutputPort());

/*

vtkDelaunay3D VDST = new vtkDelaunay3D();

VDST.SetInputConnection(VDR.GetOutputPort()); */

// Load the data on vtkimagedata.

vtk.vtkImageData VoxelData = VIC.GetOutput();

// Start adjust the rendering

 vtkVolumeProperty volumeProperty = new vtkVolumeProperty();

metaScalarRange = VoxelData.GetScalarRange();

int isovalue =Convert.ToInt32( 0.8 * (metaScalarRange[1] +
metaScalarRange[0]));

/////////////////////////////////////////////

double[] inputRange = VoxelData.GetScalarRange();

vtk.vtkPiecewiseFunction opacityIsoTransferFunction = new vtk.
vtkPiecewiseFunction();

double per = ((inputRange[1] - inputRange[0]) / 100);

if (isovalue > (inputRange[0] + per))

{

opacityIsoTransferFunction.AddPoint(inputRange[0], 0);

opacityIsoTransferFunction.AddPoint(isovalue - (per), 0);

}

opacityIsoTransferFunction.AddPoint(isovalue, 1);

opacityIsoTransferFunction.AddPoint(inputRange[1], 1);

vtk.vtkColorTransferFunction colorTransferFunction = new vtk.
vtkColorTransferFunction();

colorTransferFunction.AddRGBPoint(inputRange[0], 1.0, 1.0, 1.0);

colorTransferFunction.AddRGBPoint(inputRange[1], 1.0, 1.0, 1.0);

volumeProperty.SetColor(colorTransferFunction);

volumeProperty.SetScalarOpacity(opacityIsoTransferFunction);

volumeProperty.ShadeOn();

volumeProperty.SetInterpolationTypeToLinear();

volume.SetProperty(volumeProperty);

///////////////////////////

vtk.vtkFixedPointVolumeRayCastMapper volumeMapper = new vtk.
vtkFixedPointVolumeRayCastMapper();

volumeMapper.SetInputConnection(VDST.GetOutputPort());

volumeMapper.AutoAdjustSampleDistancesOn();

volumeMapper.Update();

volume.SetMapper(volumeMapper);

volume.Update();

//////////////////////////////////

vtkActor actor = new vtkActor();

actor.GetProperty().SetRepresentationToWireframe();

ren1.AddVolume(volume);

ren1.AddActor(actor);

ren1.ResetCamera();

/*ren1.GetActiveCamera().Azimuth(0);

ren1.GetActiveCamera().Roll(0);*/

ren1.GetActiveCamera().Elevation(90);

renwM.Render();

iren.Initialize(); iren.Enable();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091021/9ab78630/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output.jpg
Type: image/jpeg
Size: 42443 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091021/9ab78630/attachment.jpg>


More information about the vtkusers mailing list