<P>Hey guys,I have got a trouble problem,hope that you can help me</P>
<P> </P>
<P>Recently my work has related to displaying a raw data(512x512x331,short array),I am succeed in doing that by using vtkImageData,my code is as follows:</P>
<P>(platform : vs 2008.net language:C# )</P>
<P> </P>
<P> private void volumeRendering(String filePath, int[] dims, int []shrinkFactor,vtkRenderWindow renWin)<BR> {</P>
<P> //Read dat data<BR> FileStream fs = null;<BR> byte[] point = new byte[2];</P>
<P> if (!File.Exists(filePath))<BR> {<BR> MessageBox.Show("Raw Data doesn't exist!");<BR> return;<BR> }<BR> fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);</P>
<P><BR> int i, j, k;<BR> short[,,]rawData = new short[dims[0], dims[1], dims[2]];<BR> for (i = 0; i < dims[0]; i++)<BR> {<BR> for (j = 0; j < dims[1]; j++)<BR> {<BR> for (k = 0; k < dims[2]; k++)<BR> {<BR> point[0] = (byte)fs.ReadByte();<BR> point[1] = (byte)fs.ReadByte();</P>
<P> rawData[i, j, k] = BitConverter.ToInt16(point, 0);<BR> }<BR> }<BR> }</P>
<P> //Volume Rendeing<BR> vtkImageData id = new vtkImageData();<BR> id.SetDimensions(dims[0], dims[1], dims[2]);<BR> id.SetScalarTypeToShort();<BR> id.SetNumberOfScalarComponents(1);<BR> id.AllocateScalars();</P>
<P> vtkImageShrink3D mask = new vtkImageShrink3D();<BR> mask.SetInput(id);<BR> mask.SetShrinkFactors(shrinkFactor[0], shrinkFactor[1], shrinkFactor[2]);<BR> <BR> unsafe<BR> {<BR> short* a = (short*)(id.GetScalarPointer().ToPointer());</P>
<P> for (i = 0; i < dims[0]; i++)<BR> {<BR> for (j = 0; j < dims[1]; j++)<BR> {<BR> for (k = 0; k < dims[2]; k++)<BR> {<BR> *a++ = rawData[i, j, k];<BR> }<BR> }<BR> }<BR> }</P>
<P> vtkContourFilter cf = new vtkContourFilter();<BR> cf.SetInputConnection(mask.GetOutputPort());</P>
<P> vtkPolyDataMapper mapper = new vtkPolyDataMapper();<BR> mapper.SetInputConnection(cf.GetOutputPort());<BR> mapper.ScalarVisibilityOff();<BR> mapper.SetScalarRange(-2048, 2047);</P>
<P> actor = new vtkLODActor();<BR> actor.SetMapper(mapper);</P>
<P> .....</P>
<P> </P>
<P>as you see, I simply read the data from a .dat file,and associate it with the vtkImageData by the code written in the unsafe period.</P>
<P>However,what we are intergrating the system,my classmate just pass a array(which is 3D reconstructed data) to me(He didn't read it from file).And I got nothing displayed!I feel puzzled,because I pass the data from .dat file to an array ,and then pass this array to the function I write,it indeed could display!And it seems that a random array could,'t be displayed!</P>
<P>Do anybody know this?This is the first part of my trouble</P>
<P> </P>
<P>So I modified my strategy,I randomly produce the data by simulating the .dat file I have mentioned above.And use another version of code:</P>
<P> </P>
<P> vtkShortArray arr = new vtkShortArray();<BR> arr.Allocate(dims[0] * dims[1] * dims[2], 1);<BR> arr.SetArray(array, dims[0] * dims[1] * dims[2], 1);</P>
<P> //Volume Rendeing<BR> vtkImageData id = new vtkImageData();<BR> id.GetPointData().SetScalars(arr);<BR> id.SetDimensions(dims[0], dims[1], dims[2]);<BR> id.SetScalarTypeToShort();<BR> id.SetNumberOfScalarComponents(3);</P>
<P> id.AllocateScalars();</P>
<P> </P>
<P>And then I got another problem,if the data is too large(My is 512x512x331),then I got the exception:</P>
<P> </P>
<P>ERROR:In m:\dev\cur\vtkdotnet\branch\50\common\vtkDataArrayTemplate\vtkFloatArray[06CDAE30]:unable to allocate 21577254</P>
<P>elements of size 4</P>
<P> </P>
<P>But 50x50x50 could be displayed!</P>
<P> </P>
<P>I don't why,I have encountered this kind of error lots of time,could anyone tell me something about this?</P>
<P> </P>
<P>Thank you very much!</P>