<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="post-text" itemprop="text">
<p>Hello,<br>
</p>
<p>my task is to visualize a grayscale pointcloud which I can
found in a DICOM series. I found this tutorial <a
href="https://pyscience.wordpress.com/2014/09/11/surface-extraction-creating-a-mesh-from-pixel-data-using-python-and-vtk/"
rel="nofollow noreferrer">https://pyscience.wordpress.com/2014/09/11/surface-extraction-creating-a-mesh-from-pixel-data-using-python-and-vtk/</a>
which shows how to visualize bones in 3D by meching them. I
could transfer it to c# and it work, but I need just a 3D point
cloud where I can define the object by thresholding the
grayscale. Hope u understand what I mean. So I tried this:</p>
<blockquote>
<pre class="lang-cs prettyprint prettyprinted" style=""><font face="Courier New, Courier, monospace"><code><span class="com">// read file</span><span class="pln">
</span><span class="kwd">string</span><span class="pln"> pathDicom </span><span class="pun">=</span><span class="pln"> </span><span class="str">@"...\dicomDirectory"</span><span class="pun">;</span><span class="pln">
vtkDICOMImageReader reader </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Kitware</span><span class="pun">.</span><span class="pln">VTK</span><span class="pun">.</span><span class="pln">vtkDICOMImageReader</span><span class="pun">();</span><span class="pln">
reader</span><span class="pun">.</span><span class="typ">SetDirectoryName</span><span class="pun">(</span><span class="pln">pathDicom</span><span class="pun">);</span><span class="pln">
reader</span><span class="pun">.</span><span class="typ">Update</span><span class="pun">();</span><span class="pln">
</span><span class="com">// convert HU value</span><span class="pln">
vtkImageShiftScale shiftScale </span><span class="pun">=</span><span class="pln"> vtkImageShiftScale</span><span class="pun">.</span><span class="typ">New</span><span class="pun">();</span><span class="pln">
shiftScale</span><span class="pun">.</span><span class="typ">SetScale</span><span class="pun">(</span><span class="pln">reader</span><span class="pun">.</span><span class="typ">GetRescaleSlope</span><span class="pun">());</span><span class="pln">
shiftScale</span><span class="pun">.</span><span class="typ">SetShift</span><span class="pun">(</span><span class="pln">reader</span><span class="pun">.</span><span class="typ">GetRescaleOffset</span><span class="pun">());</span><span class="pln">
shiftScale</span><span class="pun">.</span><span class="typ">SetInputConnection</span><span class="pun">(</span><span class="pln">reader</span><span class="pun">.</span><span class="typ">GetOutputPort</span><span class="pun">());</span><span class="pln">
shiftScale</span><span class="pun">.</span><span class="typ">Update</span><span class="pun">();</span><span class="pln">
</span><span class="com">// Visualize</span><span class="pln">
vtkPolyDataMapper mapper </span><span class="pun">=</span><span class="pln"> vtkPolyDataMapper</span><span class="pun">.</span><span class="typ">New</span><span class="pun">();</span><span class="pln">
mapper</span><span class="pun">.</span><span class="typ">SetInputConnection</span><span class="pun">(</span><span class="pln">shiftScale</span><span class="pun">.</span><span class="typ">GetOutputPort</span><span class="pun">());</span><span class="pln">
vtkActor actor </span><span class="pun">=</span><span class="pln"> vtkActor</span><span class="pun">.</span><span class="typ">New</span><span class="pun">();</span><span class="pln">
actor</span><span class="pun">.</span><span class="typ">SetMapper</span><span class="pun">(</span><span class="pln">mapper</span><span class="pun">);</span><span class="pln">
actor</span><span class="pun">.</span><span class="typ">GetProperty</span><span class="pun">().</span><span class="typ">SetPointSize</span><span class="pun">(</span><span class="lit">4</span><span class="pun">);</span><span class="pln">
vtkRenderWindow renderWindow </span><span class="pun">=</span><span class="pln"> renderWindowControl1</span><span class="pun">.</span><span class="typ">RenderWindow</span><span class="pun">;</span><span class="pln">
vtkRenderer renderer </span><span class="pun">=</span><span class="pln"> renderWindow</span><span class="pun">.</span><span class="typ">GetRenderers</span><span class="pun">().</span><span class="typ">GetFirstRenderer</span><span class="pun">();</span><span class="pln">
renderer</span><span class="pun">.</span><span class="typ">SetBackground</span><span class="pun">(</span><span class="lit">0.2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.3</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0.4</span><span class="pun">);</span><span class="pln">
renderer</span><span class="pun">.</span><span class="typ">AddActor</span><span class="pun">(</span><span class="pln">actor</span><span class="pun">);</span></code></font></pre>
</blockquote>
<p>When I start this I alwas get the same error</p>
<pre class="lang-cs prettyprint prettyprinted" style=""><code><span class="pln"> vtkStreamingDemandDrivenPipline </span><span class="pun">(</span><span class="lit">09366B85</span><span class="pun">)</span></code></pre>
<p>and Visual Studio tell me </p>
<pre class="lang-cs prettyprint prettyprinted" style=""><code><span class="typ"> System</span><span class="pun">.</span><span class="typ">AccessViolationException</span></code></pre>
<p>It's kind of memory error. </p>
<p>So my question is where is my mistake? During debugging I found
out that the error begun when I set the mapper for the actor.
But I now that this code is the normal way to display everything
in vtk. I think the problem is that I don't really get the
points out of the array but the imageData should contain all
pixels of the series. </p>
<p>Hope u can help me.</p>
<p>Beste Regards</p>
<p>Alexander<br>
</p>
</div>
</body>
</html>