<div dir="ltr">Thanks a lot! <br>The solution from Andaharoo was what I was looking for. </div><br><div class="gmail_quote"><div dir="ltr">pon., 3 gru 2018 o 07:50 Andras Lasso <<a href="mailto:lasso@queensu.ca">lasso@queensu.ca</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You can copy voxel values from a volume to a polydata using vtkProbeFilter.<br>
<br>
However, this won't help you if you obtained your polydata using a vtkContourFilter, because the contour filter generates isosurface, which means all extracted points have the same intensity value in the input volume. No matter what transfer function you apply, you'll always end up with a solid colored surface.<br>
<br>
It is a common desire to replace volume rendering by displaying a colored surface, but this is not feasible (<a href="https://discourse.slicer.org/t/save-volume-rendering-as-stl-file/524/20" rel="noreferrer" target="_blank">https://discourse.slicer.org/t/save-volume-rendering-as-stl-file/524/20</a>).<br>
<br>
If your goal is 3D printing then you may use voxel printing technique, which allows printing directly from volume rendering, without segmenting any surfaces (<a href="https://discourse.slicer.org/t/printing-volume-renderings-in-plastic/3017" rel="noreferrer" target="_blank">https://discourse.slicer.org/t/printing-volume-renderings-in-plastic/3017</a>).<br>
<br>
If your goal is volume-rendering-like display (for example, you want to show "volume rendering" in Unity) then you need to use an actual volume renderer.<br>
<br>
Andras<br>
<br>
<br>
-----Original Message-----<br>
From: vtkusers <<a href="mailto:vtkusers-bounces@public.kitware.com" target="_blank">vtkusers-bounces@public.kitware.com</a>> On Behalf Of Andaharoo<br>
Sent: Sunday, December 2, 2018 11:27 PM<br>
To: <a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a><br>
Subject: Re: [vtkusers] Color PolyData based on VolumeData<br>
<br>
So, if I understand right, you want to color the scalar/whatever field onto the poly? Just provide vtkPolyData with scalars and set the polyData's mapper scalar visibility to on.<br>
<br>
If you give it 1 component scalars you can give the mapper a color function to map them. If you give it 3 component uchar it should just display them as color (as long as scalar visibility is on). Like so:<br>
<br>
<br>
// Create the scalars array<br>
vtkDoubleArray* scalars = vtkDoubleArray::New();<br>
scalars->SetName("Scalars");<br>
// For every point in the poly<br>
for (vtkIdType i = 0; i < outputPoly->GetNumberOfPoints(); i++) {<br>
double pt[3];<br>
outputPoly->GetPoint(i, pt);<br>
<br>
scalars->InsertTuple1(i, trilinearSamplePoint(inputImage, pt[0], pt[1], pt[2], 1, 0)); } // Add the scalar data to the poly data<br>
outputPoly->GetPointData()->AddArray(scalars);<br>
outputPoly->GetPointData()->SetActiveScalars("Scalars");<br>
<br>
<br>
This just goes through all the points in the polygon and gets the color from the image. Getting the color at a point in an image can be done by simply using the nearest color from the image (nearest neighbor) or better would be to use trilinear interpolation of the 8 nearest colors which I used in my example. Also note my code expects float image input:<br>
static const int calcIndex(int x, int y, int z, int width, int height) { return x + width * (y + height * z); }<br>
<br>
static float trilinearSamplePoint(vtkImageData* imageData, float x, float y, float z, int numComps, int comp) {<br>
float* imagePtr = static_cast<float*>(imageData->GetScalarPointer());<br>
double* spacing = imageData->GetSpacing();<br>
double* origin = imageData->GetOrigin();<br>
int* dim = imageData->GetDimensions();<br>
<br>
// We assume point x, y, z is in the image<br>
int xi = (x - origin[0]) / spacing[0];<br>
int yi = (y - origin[1]) / spacing[1];<br>
int zi = (z - origin[2]) / spacing[2];<br>
<br>
// Get the intensities at the 8 nearest neighbors<br>
float i000 = imagePtr[calcIndex(xi, yi, zi, dim[0], dim[1]) * numComps + comp];<br>
float i100 = imagePtr[calcIndex(xi + 1, yi, zi, dim[0], dim[1]) * numComps<br>
+ comp];<br>
float i110 = imagePtr[calcIndex(xi + 1, yi + 1, zi, dim[0], dim[1] * numComps + comp)];<br>
float i010 = imagePtr[calcIndex(xi, yi + 1, zi, dim[0], dim[1]) * numComps<br>
+ comp];<br>
<br>
float i001 = imagePtr[calcIndex(xi, yi, zi + 1, dim[0], dim[1]) * numComps<br>
+ comp];<br>
float i101 = imagePtr[calcIndex(xi + 1, yi, zi + 1, dim[0], dim[1]) * numComps + comp];<br>
float i111 = imagePtr[calcIndex(xi + 1, yi + 1, zi + 1, dim[0], dim[1]) * numComps + comp];<br>
float i011 = imagePtr[calcIndex(xi, yi + 1, zi + 1, dim[0], dim[1]) * numComps + comp];<br>
<br>
// Get the fractional/unit distance from nearest neighbor 000<br>
float rx = xi * spacing[0] + origin[0]; // Position of node<br>
rx = (x - rx) / spacing[0]; // (Node - actual point position) / voxel width<br>
float ry = yi * spacing[1] + origin[1];<br>
ry = (y - ry) / spacing[1];<br>
float rz = zi * spacing[2] + origin[2];<br>
rz = (z - rz) / spacing[2];<br>
<br>
// Now we do the trilinear interpolation<br>
float ax = i000 + (i100 - i000) * rx;<br>
float bx = i010 + (i110 - i010) * rx;<br>
float cy = ax + (bx - ax) * ry;<br>
<br>
float dx = i001 + (i101 - i001) * rx;<br>
float ex = i011 + (i111 - i011) * rx;<br>
float fy = dx + (ex - dx) * ry;<br>
<br>
float gz = cy + (fy - cy) * rz;<br>
return gz;<br>
}<br>
<br>
<br>
<br>
<br>
--<br>
Sent from: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvtk.1045678.n5.nabble.com%2FVTK-Users-f1224199.html&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091371821&sdata=iziee8ltwEAWna3RvM3dma7A3p94NWMHCfIwclRpR0I%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvtk.1045678.n5.nabble.com%2FVTK-Users-f1224199.html&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091371821&sdata=iziee8ltwEAWna3RvM3dma7A3p94NWMHCfIwclRpR0I%3D&reserved=0</a><br>
_______________________________________________<br>
Powered by <a href="https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091371821&sdata=6Nv%2FWdIIIaOq%2B3peZlXxuGdAwkOwzORn7AfWthXw5Xo%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091371821&sdata=6Nv%2FWdIIIaOq%2B3peZlXxuGdAwkOwzORn7AfWthXw5Xo%3D&reserved=0</a><br>
<br>
Visit other Kitware open-source projects at <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=oEIpua2iKsLpUdJaY%2BmQdOhCHfusGYUZDRd3Ru67Qoo%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=oEIpua2iKsLpUdJaY%2BmQdOhCHfusGYUZDRd3Ru67Qoo%3D&reserved=0</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.vtk.org%2FWiki%2FVTK_FAQ&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=7h18pSmCa3LapcNQJsqqxU7kyWVyaQzKbPYZPMCbDiw%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.vtk.org%2FWiki%2FVTK_FAQ&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=7h18pSmCa3LapcNQJsqqxU7kyWVyaQzKbPYZPMCbDiw%3D&reserved=0</a><br>
<br>
Search the list archives at: <a href="https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%2Fsearch%2F%3Fq%3Dvtkusers&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=luU4EgKZZ9nD1OOxN5EGfBpA5HnK%2FyuVoN6C7PE%2Bzhc%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%2Fsearch%2F%3Fq%3Dvtkusers&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=luU4EgKZZ9nD1OOxN5EGfBpA5HnK%2FyuVoN6C7PE%2Bzhc%3D&reserved=0</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fvtkusers&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=URr5vqvvkUuWmwaPIIGXXJzsmW2LFrYs7Z7jDcvt4ek%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fvtkusers&data=02%7C01%7Classo%40queensu.ca%7C34224811bdf846b9c4a808d658d7898f%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636794080091381830&sdata=URr5vqvvkUuWmwaPIIGXXJzsmW2LFrYs7Z7jDcvt4ek%3D&reserved=0</a><br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote></div>