<div dir="ltr"><div>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 </div>
<div> </div>
<div>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</div>
<div> </div>
<div>the code is :</div>
<div> </div>
<div><font size="2">
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">//Variables</font></font><font size="2">
<p></p></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">double</font></font><font size="2">[] metaScalarRange = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">double</font></font><font size="2">[2] { 0, 0 };
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkRenderWindow</font></font><font size="2"> renwM = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkRenderWindow</font></font><font size="2">();
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkRenderer</font></font><font size="2"> ren1= </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">vtkRenderer</font></font><font size="2">();
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkRenderWindowInteractor</font></font><font size="2"> iren = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkRenderWindowInteractor</font></font><font size="2">();
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkVolume</font></font><font size="2"> volume = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkVolume</font></font><font size="2">();
<p>renwM.AddRenderer(ren1);</p>
<p>iren.SetRenderWindow(renwM);</p>
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">// Read a DICOM series path: </font></font><font size="2">
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkDICOMImageReader</font></font><font size="2"> VDR = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkDICOMImageReader</font></font><font size="2">();
<p>VDR.SetDirectoryName(</p></font><font color="#800000" size="2"><font color="#800000" size="2">&quot;D:\\Programming and tutorials\\Master source\\CT test\\DICOM\\PA1\\ST1\\SE1\\&quot;</font></font><font size="2">);
<p>VDR.SetDataOrigin(0, 0, 0);</p>
<p>VDR.Update();</p>
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">/////</font></font><font size="2">
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkImageChangeInformation</font></font><font size="2"> VIC = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkImageChangeInformation</font></font><font size="2">();
<p>VIC.SetInput(VDR.GetOutput());</p>
<p>VIC.CenterImageOn();</p>
<p>VIC.Update();</p>
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">///////// Applying the mesh </font></font><font size="2">
<p></p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkDataSetTriangleFilter</font></font><font size="2"> VDST = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">vtkDataSetTriangleFilter</font></font><font size="2">();
<p>VDST.SetInputConnection(VDR.GetOutputPort());</p>
<p></p>
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">/*
<p>vtkDelaunay3D VDST = new vtkDelaunay3D();</p>
<p>VDST.SetInputConnection(VDR.GetOutputPort()); */</p></font></font><font size="2">
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">// Load the data on vtkimagedata.</font></font><font size="2">
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkImageData</font></font><font size="2"> VoxelData = VIC.GetOutput();
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">// Start adjust the rendering </font></font><font size="2">
<p></p>
<p></p>
<p></p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkVolumeProperty</font></font><font size="2"> volumeProperty = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">vtkVolumeProperty</font></font><font size="2">();
<p>metaScalarRange = VoxelData.GetScalarRange();</p>
<p></p></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font size="2"> isovalue =</font><font color="#008080" size="2"><font color="#008080" size="2">Convert</font></font><font size="2">.ToInt32( 0.8 * (metaScalarRange[1] + metaScalarRange[0]));
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">/////////////////////////////////////////////</font></font><font size="2">
<p></p></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">double</font></font><font size="2">[] inputRange = VoxelData.GetScalarRange();
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkPiecewiseFunction</font></font><font size="2"> opacityIsoTransferFunction = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkPiecewiseFunction</font></font><font size="2">();
<p></p></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">double</font></font><font size="2"> per = ((inputRange[1] - inputRange[0]) / 100);
<p></p></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">if</font></font><font size="2"> (isovalue &gt; (inputRange[0] + per))
<p>{</p>
<p>opacityIsoTransferFunction.AddPoint(inputRange[0], 0);</p>
<p>opacityIsoTransferFunction.AddPoint(isovalue - (per), 0);</p>
<p>}</p>
<p>opacityIsoTransferFunction.AddPoint(isovalue, 1);</p>
<p>opacityIsoTransferFunction.AddPoint(inputRange[1], 1);</p>
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkColorTransferFunction</font></font><font size="2"> colorTransferFunction = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkColorTransferFunction</font></font><font size="2">();
<p>colorTransferFunction.AddRGBPoint(inputRange[0], 1.0, 1.0, 1.0);</p>
<p>colorTransferFunction.AddRGBPoint(inputRange[1], 1.0, 1.0, 1.0);</p>
<p>volumeProperty.SetColor(colorTransferFunction);</p>
<p>volumeProperty.SetScalarOpacity(opacityIsoTransferFunction);</p>
<p>volumeProperty.ShadeOn();</p>
<p>volumeProperty.SetInterpolationTypeToLinear();</p>
<p>volume.SetProperty(volumeProperty);</p>
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">///////////////////////////</font></font><font size="2">
<p>vtk.</p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkFixedPointVolumeRayCastMapper</font></font><font size="2"> volumeMapper = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> vtk.</font><font color="#008080" size="2"><font color="#008080" size="2">vtkFixedPointVolumeRayCastMapper</font></font><font size="2">();
<p>volumeMapper.SetInputConnection(VDST.GetOutputPort());</p>
<p>volumeMapper.AutoAdjustSampleDistancesOn();</p>
<p>volumeMapper.Update();</p>
<p>volume.SetMapper(volumeMapper);</p>
<p>volume.Update();</p>
<p></p>
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">//////////////////////////////////</font></font><font size="2">
<p></p></font><font color="#008080" size="2"><font color="#008080" size="2">vtkActor</font></font><font size="2"> actor = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">vtkActor</font></font><font size="2">();
<p>actor.GetProperty().SetRepresentationToWireframe(); </p>
<p>ren1.AddVolume(volume);</p>
<p>ren1.AddActor(actor);</p>
<p>ren1.ResetCamera();</p>
<p></p></font><font color="#008000" size="2"><font color="#008000" size="2">/*ren1.GetActiveCamera().Azimuth(0); 
<p>ren1.GetActiveCamera().Roll(0);*/</p></font></font><font size="2">
<p>ren1.GetActiveCamera().Elevation(90);</p>
<p>renwM.Render();</p>
<p>iren.Initialize(); iren.Enable();</p></font></div></div>