<span id="result_box" class="medium_text"><span title="óÐÁÓÉÂÏ ÏÇÒÏÍÎÏÅ
ÚÁ ÉÄÅÀ!!!">Thank you very much for the idea! </span><span title="ôÏÞÎÅÅ
ÚÁ ÉÓÐÏÌØÚÏ×ÁÎÉÅ vtkImageActor.">Specifically for use vtkImageActor. </span><span title="ïÎ ÎÅ ×Ù×ÏÄÉÔØ Dicom-files, ÎÏ Ñ ÎÁÛÅÌ ×ÙÈÏÄ:))).">He did not
show Dicom-files, but I found out :))). </span><span title="é ×ÏÔ ÔÕÔ
ËÁË ÒÁÚ ÐÒÉÇÏÄÉÌÓÑ vtkImageViewer2.">And it was just a handy
vtkImageViewer2.<br>ššššššššššš //Create the RenderWindow, Renderer and RenderWindowInteractor<br>ššššššššššš vtkRenderer ren1 = new vtkRenderer();<br>ššššššššššš vtkRenderWindow renWin = new vtkRenderWindow();//reWin.GetRenderWindow();<br>
ššššššššššš renWin.AddRenderer(ren1);<br>ššššššššššš vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();<br>ššššššššššš iren.SetRenderWindow(renWin);<br><br>ššššššššššš vtkDICOMImageReader DicomReader = new vtkDICOMImageReader();<br>
ššššššššššš DicomReader.SetFileName(m_strFilePath);<br>ššššššššššš DicomReader.Update();<br><br>š ššššššššš vtkImageData vol = new vtkImageData();<br>ššššššššššš vol.SetDimensions(512, 512, 1);<br>ššššššššššš vol.SetSpacing(1, 1, 1);<br>
ššššššššššš vol.SetOrigin(0, 0, 0);<br>ššššššššššš vol.SetScalarTypeToFloat();<br>ššššššššššš vol.AllocateScalars();<br><br>ššššššššššš vtkFloatArray scalars = new vtkFloatArray();<br>ššššššššššš for (int i = 0; i < 512; i++)<br>
ššššššššššš {<br>ššššššššššššššš for (int j = 0; j < 512; j++)<br>ššššššššššššššš {<br>ššššššššššššššššššš scalars.InsertTuple1(i * 512 + j, m_DoseMap[i * 512 + j]);<br>ššššššššššššššš }<br>ššššššššššš }<br><br>ššššššššššš vol.GetPointData().SetScalars(scalars);<br>
ššššššššššš vol.Update();<br><br>ššššššššššš double[] DoseRange = vol.GetScalarRange();<br><br>ššššššššššš vtkLookupTable LUT = new vtkLookupTable();<br>ššššššššššš LUT.SetTableRange(DoseRange[0], DoseRange[1]);//min dose,max dose<br>
ššššššššššš LUT.SetNumberOfColors(1000);<br>ššššššššššš LUT.SetSaturationRange(1, 1);<br>ššššššššššš LUT.SetHueRange(0.67, 0);//blue to red<br>ššššššššššš LUT.SetAlphaRange(0, 0.3);//opacity<br>ššššššššššš LUT.Build();<br>
<br>ššššššššššš vtkImageMapToColors mapToRGBA = new vtkImageMapToColors();<br>ššššššššššš mapToRGBA.SetInput(vol);<br>ššššššššššš mapToRGBA.SetOutputFormatToRGBA();<br>ššššššššššš mapToRGBA.SetLookupTable(LUT);<br><br>ššššššššššš vtkImageActor ColorActor = new vtkImageActor();<br>
ššššššššššš ColorActor.SetInput(mapToRGBA.GetOutput());<br>ššššššššššš ColorActor.SetPosition(0, 0, 1);<br><br>ššššššššššš vtkContourFilter cf = new vtkContourFilter();<br>ššššššššššš cf.SetInput(vol);<br>ššššššššššš cf.SetValue(0, 100);<br>
ššššššššššš cf.Update();<br><br>ššššššššššš vtkPolyDataMapper mapper = new vtkPolyDataMapper();<br>ššššššššššš mapper.SetInputConnection(cf.GetOutputPort());<br>ššššššššššš mapper.ScalarVisibilityOff();<br><br>ššššššššššš vtkActor actor = new vtkActor();<br>
ššššššššššš actor.SetMapper(mapper);<br>ššššššššššš actor.GetProperty().SetColor(1, 0, 0);<br>ššššššššššš actor.SetPosition(0, 0, 2);<br><br>ššššššššššš vtkImageViewer2 viewer = new vtkImageViewer2();<br>ššššššššššš viewer.SetupInteractor(iren);<br>
ššššššššššš viewer.SetInputConnection(DicomReader.GetOutputPort());<br>ššššššššššš viewer.GetRenderer().AddActor(ColorActor);<br>ššššššššššš viewer.GetRenderer().AddActor(actor);<br>ššššššššššš viewer.GetRenderer().ResetCamera();<br>
ššššššššššš viewer.Render();<br></span></span><br><div class="gmail_quote">9 ÁÐÒÅÌÑ 2010 Ç. 0:42 ÐÏÌØÚÏ×ÁÔÅÌØ Eric E. Monson <span dir="ltr"><<a href="mailto:emonson@cs.duke.edu">emonson@cs.duke.edu</a>></span> ÎÁÐÉÓÁÌ:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;">Hello Andrej,<div><br></div><div>Well, maybe someone else can give their opinion, too, but personally I would just use a standard vtkRenderWindow, and add all three actors to the vtkRenderer that you add to that render window.š</div>
<div><br></div><div>Each of the images can be shown with a vtkImageActor, and those can be placed anywhere in 3D space with SetPosition(), and then you can just use a regular vtkActor for the contour filter output and place it "in front" of the image actors.</div>
<div><br></div><div>Here's a piece of Python code that does this, if you want to have a look. (Sorry the beginning is more complicated than it should be, I was already playing with VTK/Examples/ImageProcessing/Python/ImageSlicing.py and this was an easy way to get two grayscale images to superimpose...) It takes two images, gives one an orange and one a yellow color map with transparency, then overlays them. (I positioned them separately in space, but I think you can put these on the same Z plane.) Then, I place the contour output "over the top" of the images. (If you change the interactor style to TrackballCamera, you can roll them around and see the separation, which doesn't have to be this extreme.)</div>
<div><br></div><div>Again, maybe others have a better way to do this, but it works for keeping the spatial order as you want it, and they all move together in the window.</div><div><br></div><div>Good luck,</div><div>-Eric</div>
<div><br></div><div>===================</div><div><br></div><div><div>#!/usr/bin/env python</div><div><br></div><div>import vtk</div><div><br></div><div>VTK_DATA_ROOT = '/Users/emonson/Programming/VTK_cvs/VTKData'</div>
<div><br></div><div># Start by loading some data.</div><div>reader = vtk.vtkImageReader2()</div><div>reader.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter")</div><div>reader.SetDataExtent(0, 63, 0, 63, 1, 93)</div>
<div>reader.SetDataSpacing(1.0, 1.0, 1.0)</div><div>reader.SetDataOrigin(0.0, 0.0, 0.0)</div><div>reader.SetDataScalarTypeToUnsignedShort()</div><div>reader.UpdateWholeExtent()</div><div><br></div><div># Calculate the center of the volume</div>
<div>reader.GetOutput().UpdateInformation()</div><div>(xMin, xMax, yMin, yMax, zMin, zMax) = reader.GetOutput().GetWholeExtent()</div><div>(xSpacing, ySpacing, zSpacing) = reader.GetOutput().GetSpacing()</div><div>(x0, y0, z0) = reader.GetOutput().GetOrigin()</div>
<div><br></div><div>center = [x0 + xSpacing * 0.5 * (xMin + xMax),</div><div>šš š š š šy0 + ySpacing * 0.5 * (yMin + yMax),</div><div>šš š š š šz0 + zSpacing * 0.5 * (zMin + zMax)]</div><div><br></div><div>renderer = vtk.vtkRenderer()</div>
<div>renderer.SetBackground(1,1,1)</div><div><br></div><div>resliceList = []</div><div>tableList = []</div><div>colorList = []</div><div>actorList = []</div><div><br></div><div>imgOffset = 70</div><div><br></div><div>for ii in range(2):</div>
<div><span style="white-space: pre;">                </span></div><div><span style="white-space: pre;">        </span>zpos = z0 + zSpacing*(zMin+ii*imgOffset)</div><div><span style="white-space: pre;">        </span>axial = vtk.vtkMatrix4x4()</div><div>
<span style="white-space: pre;">        </span>axial.DeepCopy((1, 0, 0, center[0],</div><div><span style="white-space: pre;">                                        </span>0, 1, 0, center[1],</div><div><span style="white-space: pre;">                                        </span>0, 0, 1, zpos,</div>
<div><span style="white-space: pre;">                                        </span>0, 0, 0, 1))</div><div><span style="white-space: pre;">                                        </span></div><div><span style="white-space: pre;">        </span># Extract a slice in the desired orientation</div><div>
<span style="white-space: pre;">        </span>reslice = vtk.vtkImageReslice()</div><div><span style="white-space: pre;">        </span>reslice.SetInputConnection(reader.GetOutputPort())</div><div><span style="white-space: pre;">        </span>reslice.SetOutputDimensionality(2)</div>
<div><span style="white-space: pre;">        </span>reslice.SetResliceAxes(axial)</div><div><span style="white-space: pre;">        </span>reslice.SetInterpolationModeToNearestNeighbor()</div><div><span style="white-space: pre;">        </span>reslice.Update()</div>
<div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span>resliceList.append(reslice)</div><div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span># Create a greyscale lookup table</div>
<div><span style="white-space: pre;">        </span>table = vtk.vtkLookupTable()</div><div><span style="white-space: pre;">        </span>table.SetRange(0, 2000) # image intensity range</div><div><span style="white-space: pre;">        </span>table.SetHueRange(ii*0.1,0.1+ii*0.1)</div>
<div><span style="white-space: pre;">        </span>table.SetValueRange(0.0, 1.0) # from black to white</div><div><span style="white-space: pre;">        </span>table.SetSaturationRange(0.0, 0.8) # no color saturation</div><div><span style="white-space: pre;">        </span>table.SetAlphaRange(0,0.8)</div>
<div><span style="white-space: pre;">        </span>table.SetRampToLinear()</div><div><span style="white-space: pre;">        </span>table.Build()</div><div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span>tableList.append(table)</div>
<div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span># Map the image through the lookup table</div><div><span style="white-space: pre;">        </span>color = vtk.vtkImageMapToColors()</div>
<div><span style="white-space: pre;">        </span>color.SetLookupTable(tableList[ii])</div><div><span style="white-space: pre;">        </span>color.SetInputConnection(resliceList[ii].GetOutputPort())</div><div><span style="white-space: pre;">        </span></div>
<div><span style="white-space: pre;">        </span>colorList.append(color)</div><div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span># Display the image</div><div><span style="white-space: pre;">        </span>actor = vtk.vtkImageActor()</div>
<div><span style="white-space: pre;">        </span>actor.SetInput(colorList[ii].GetOutput())</div><div><span style="white-space: pre;">        </span>actor.SetPosition(0, 0, ii*1.0)</div><div><span style="white-space: pre;">        </span>actorList.append(actor)</div>
<div><span style="white-space: pre;">        </span></div><div><span style="white-space: pre;">        </span>renderer.AddActor(actorList[ii])</div><div><span style="white-space: pre;">        </span></div><div>contour = vtk.vtkContourFilter()</div>
<div>contour.SetInputConnection(resliceList[0].GetOutputPort(0))</div><div>contour.GenerateValues(5,0,2000)</div><div>contour.SetComputeScalars(True)</div><div><br></div><div>polyMapper = vtk.vtkPolyDataMapper()</div><div>
polyMapper.SetInputConnection(contour.GetOutputPort(0))</div><div># Uncomment next two to color contour lines</div><div># polyMapper.SetScalarModeToUsePointData()</div><div># polyMapper.SetScalarRange(0,2000)</div><div>polyMapper.SetScalarVisibility(False)</div>
<div>polyActor = vtk.vtkActor()</div><div>polyActor.SetMapper(polyMapper)</div><div>polyActor.GetProperty().SetColor(0,0,0)</div><div>polyActor.GetProperty().SetLineWidth(1)</div><div>polyActor.SetPosition(0,0,2.0)</div><div>
<br></div><div>renderer.AddActor(polyActor)</div><div><br></div><div># Set up the interaction</div><div>interactorStyle = vtk.vtkInteractorStyleImage()</div><div>interactor = vtk.vtkRenderWindowInteractor()</div><div>interactor.SetInteractorStyle(interactorStyle)</div>
<div><br></div><div>window = vtk.vtkRenderWindow()</div><div>window.AddRenderer(renderer)</div><div>window.SetInteractor(interactor)</div><div>window.Render()</div><div><br></div><div># Start interaction</div><div>interactor.Start()</div>
<div><br></div><div><br></div></div><div><div></div><div class="h5"><div><br><div><div>On Apr 8, 2010, at 9:49 AM, Andrej Gluhov wrote:</div><br><blockquote type="cite"><span><span style="background-color: rgb(255, 255, 255);" title="Hi, Eric.">Hi, Eric.<br>
<br></span><span style="background-color: rgb(255, 255, 255);" title="óÐÁÓÉÂÏ ÚÁ
ÏÔËÌÉË."Images from vtkActor2D gets under 2D images" ÜÔÏ
ÏÛÉÂËÁ.">Thanks for the response. "Images from vtkActor2D gets under 2D
images" is a mistake. </span><span style="background-color: rgb(255, 255, 255);" title="ñ ËÏÎÅÞÎÏ ÉÍÅÌ ××ÉÄÕ vtkActor.">Of course, I meant
vtkActor. </span><span style="background-color: rgb(255, 255, 255);" title="ðÒÏÂÌÅÍÁ × ÔÏÍ, ÞÔÏ ËÏÎÔÕÒ ÎÅ ×ÉÄÎÏ ÐÒÉ ÏÔÏÂÒÁÖÅÎÉÉ, ÎÏ ÅÓÌÉ
ÒÁÓÔÑÎÕÔØ ÏËÎÏ, ÔÏ vtkActor2D ÏÓÔÁÅÔÓÑ × ÌÅ×ÏÍ ÎÉÖÎÅÍ ÕÇÌÕ, Á Contours
×ÉÄÎÏ ÎÁ ÚÁÄÎÅÍ ÆÏÎÅ(ÐÏÄ vtkActor2D).">The problem is that the contour is
not visible when displaying, but if you stretch the window and then
vtkActor2D remains in the lower left corner, and the Contours can be
seen in the background (under vtkActor2D). </span><span style="background-color: rgb(255, 255, 255);" title="ñ ÐÒÏÂÏ×ÁÌ ÉÚÍÅÎÉÔØ
ÐÏÚÉÃÉÀ ÐÏ ËÏÏÒÄÉÎÁÔÅ Z, ÎÏ ÜÔÏ ÎÅ ÄÁÌÏ ÒÅÚÕÌØÔÁÔÁ.">I tried to change
the position of the coordinate Z, but it does not yield results. </span><span style="background-color: rgb(255, 255, 255);" title="vtkActor2D ÎÅ
ÉÍÅÅÔ ËÏÏÒÄÉÎÁÔÙ Z.">vtkActor2D has only x,y coordinates.<br></span><span style="background-color: rgb(255, 255, 255);" title="á ÏËÎÏ Ñ ÓÏÚÄÁÀ ÄÌÑ
ÔÏÇÏ, ÞÔÏÂÙ ÐÏÔÏÍ ÐÒÉËÒÅÐÉÔØ vtkImageViewer2 in WindowsForm.">And the
window I create in order to then attach vtkImageViewer2 in WindowsForm.</span></span><br><br><div class="gmail_quote">8 ÁÐÒÅÌÑ 2010 Ç. 17:16 ÐÏÌØÚÏ×ÁÔÅÌØ Eric E. Monson <span dir="ltr"><<a href="mailto:emonson@cs.duke.edu" target="_blank">emonson@cs.duke.edu</a>></span> ÎÁÐÉÓÁÌ:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hey Andrej,<br>
<br>
I'm trying to understand your problem, but I'm not sure exactly what you mean by "Images from vtkActor2D gets under 2D images". If the problem is that your images show up in front of your contour lines so that the contours are hidden, you can use something like:<br>
<br>
actor.SetPosition(0, 0, 0.01);<br>
<br>
to move the contours out in front of the image, and not have to change the polydata into imagedata.<br>
<br>
Also, you seem to be trying to create a vtkRenderWindow at the beginning of your code but you are using the vtkImageViewer2 later. If you want to view all of your objects in one window, you can use just one or the other (ImageViewer2 creates a render window for you).<br>
<br>
If this doesn't address your problem, be sure to try again to clarify the trouble you're having and I'm sure someone can help.<br>
<br>
Talk to you later,<br>
-Eric<br>
<br>
------------------------------------------------------<br>
Eric E Monson<br>
Duke Visualization Technology Group<br>
<div><div></div><div><br>
<br>
On Apr 8, 2010, at 3:17 AM, Andrej Gluhov wrote:<br>
<br>
> Hi.<br>
> I have this problem of combining vtkActor and vtkActor2D for vtkImageViewer2D. Images from vtkActor2D gets under 2D images. I understand that the problem is converting vtkPolyData to vtkImageData, I could use vtkImageData, but do not know how to create it on the contour points.<br>
><br>
> š š š š š š //Create the RenderWindow, Renderer and RenderWindowInteractor<br>
> š š š š š š vtkRenderer ren1 = new vtkRenderer();<br>
> š š š š š š vtkRenderWindow renWin = reWin.GetRenderWindow();<br>
> š š š š š š renWin.AddRenderer(ren1);<br>
> š š š š š š vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();<br>
> š š š š š š iren.SetRenderWindow(renWin);<br>
><br>
> š š š š š š vtkDICOMImageReader DicomReader = new vtkDICOMImageReader();<br>
> š š š š š š DicomReader.SetFileName(m_strFilePath);<br>
> š š š š š š DicomReader.Update();<br>
><br>
> š š š š š š vtkImageMapper DicomMapper = new vtkImageMapper();<br>
> š š š š š š DicomMapper.SetInputConnection(DicomReader.GetOutputPort());<br>
> š š š š š š DicomMapper.SetColorWindow(255.0);<br>
> š š š š š š DicomMapper.SetColorLevel(127.5);<br>
><br>
> š š š š š š vtkActor2D DicomActor = new vtkActor2D();<br>
> š š š š š š DicomActor.SetMapper(DicomMapper);<br>
><br>
> š š š š š š vtkImageData vol = new vtkImageData();<br>
> š š š š š š vol.SetDimensions(512, 512, 1);<br>
> š š š š š š vol.SetSpacing(1, 1, 1);<br>
> š š š š š š vol.SetOrigin(0, 0, 0);<br>
> š š š š š š vol.SetScalarTypeToFloat();<br>
> š š š š š š vol.AllocateScalars();<br>
><br>
> š š š š š š vtkFloatArray scalars = new vtkFloatArray();<br>
> š š š š š š for (int i = 0; i < 512; i++)<br>
> š š š š š š {<br>
> š š š š š š š š for (int j = 0; j < 512; j++)<br>
> š š š š š š š š {<br>
> š š š š š š š š š š scalars.InsertTuple1(i * 512 + j, m_DoseMap[i * 512 + j]);<br>
> š š š š š š š š }<br>
> š š š š š š }<br>
><br>
> š š š š š š vol.GetPointData().SetScalars(scalars);<br>
> š š š š š š vol.Update();<br>
><br>
> š š š š š š double[] DoseRange = vol.GetScalarRange();<br>
><br>
> š š š š š š vtkLookupTable LUT = new vtkLookupTable();<br>
> š š š š š š LUT.SetTableRange(DoseRange[0], DoseRange[1]);//min dose,max dose<br>
> š š š š š š LUT.SetNumberOfColors(1000);<br>
> š š š š š š LUT.SetSaturationRange(1, 1);<br>
> š š š š š š LUT.SetHueRange(0.67, 0);//blue to red<br>
> š š š š š š LUT.SetAlphaRange(0, 0.3);//opacity<br>
> š š š š š š LUT.Build();<br>
><br>
> š š š š š š vtkImageMapToColors mapToRGBA = new vtkImageMapToColors();<br>
> š š š š š š mapToRGBA.SetInput(vol);<br>
> š š š š š š mapToRGBA.SetOutputFormatToRGBA();<br>
> š š š š š š mapToRGBA.SetLookupTable(LUT);<br>
><br>
> š š š š š š vtkImageMapper ColorMapper = new vtkImageMapper();<br>
> š š š š š š ColorMapper.SetInputConnection(mapToRGBA.GetOutputPort());<br>
> š š š š š š ColorMapper.SetColorWindow(255.0);<br>
> š š š š š š ColorMapper.SetColorLevel(127.5);<br>
><br>
> š š š š š š vtkActor2D ColorActor = new vtkActor2D();<br>
> š š š š š š ColorActor.SetMapper(ColorMapper);<br>
><br>
> š š š š š š vtkContourFilter cf = new vtkContourFilter();<br>
> š š š š š š cf.SetInput(vol);<br>
> š š š š š š //cf.SetValue(0, Convert.ToDouble(dataGridViewIsodose.Rows[i].Cells[1].Value));<br>
> š š š š š š cf.SetValue(0, 100);<br>
> š š š š š š cf.Update();<br>
><br>
> š š š š š š vtkPolyDataMapper mapper = new vtkPolyDataMapper();<br>
> š š š š š š mapper.SetInputConnection(cf.GetOutputPort());<br>
> š š š š š š mapper.ScalarVisibilityOff();<br>
><br>
> š š š š š š vtkActor actor = new vtkActor();<br>
> š š š š š š actor.SetMapper(mapper);<br>
> š š š š š š actor.GetProperty().SetColor(1, 0, 0);<br>
><br>
> š š š š š š vtkImageViewer2 viewer = new vtkImageViewer2();<br>
> š š š š š š viewer.SetupInteractor(iren);<br>
> š š š š š š viewer.GetRenderer().AddActor(DicomActor);<br>
> š š š š š š viewer.GetRenderer().AddActor(ColorActor);<br>
> š š š š š š viewer.GetRenderer().AddActor(actor);<br>
> š š š š š š viewer.GetRenderer().ResetCamera();<br>
> š š š š š š viewer.Render();<br>
><br>
> Thanks in advance.<br>
><br>
> --<br>
> ó õ×ÁÖÅÎÉÅÍ,<br>
> áÎÄÒÅÊ.<br>
> Best regards, Andrew<br>
</div></div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>ó õ×ÁÖÅÎÉÅÍ,<br>áÎÄÒÅÊ.<br>Best regards, Andrew<br>
</blockquote></div><br></div></div></div></div></blockquote></div><br><br clear="all"><br>-- <br>ó õ×ÁÖÅÎÉÅÍ,<br>áÎÄÒÅÊ.<br>Best regards, Andrew<br>