<br>Yep, that did the trick.<br>
This deserves a bug report?<br>
<br>
Thanks a lot Randall, you've been most helpful.<br>
<br>
<br>
Juan<br><div><span class="gmail_quote">On 4/6/06, <b class="gmail_sendername">Randall Hand</b> <<a href="mailto:randall.hand@gmail.com">randall.hand@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="direction: ltr;">OK, I'm seeing the same glitch here on my
end.. That is an odd one.. The only thing I know to attribute it to is
some type of interpolation within the colormap. If you switch
from vtkUnstructuredGridVolumeRayCastMapper to
vtkProjectedTetrahedraMapper then it works perfectly. Also, if
you switch from the colormap approach to the 4-component approach I
mentioned last night, then it works just fine. At this point, it
does seem to be some kind of issue in the RayCastMapper.
<br><br>I'm gonna dig a little deeper, I'll let you know what I find,
if anything. Also, just fyi, you don't need to declare the OpenGL
objects directly, the object factories know when to create the OpenGL
ones vs the Mesa ones just fine :)
<br><br>As promised, code for the 4-component scalar shown below:<br><br><div style="margin-left: 40px; font-family: courier new,monospace;"></div><div style="direction: ltr;"><span class="e" id="q_10a6f8f39c1f383d_1">#include "
vtkVoxel.h"<br>#include "vtkCellData.h"<br>#include "
vtkRenderer.h"<br>#include "vtkPoints.h"<br>#include "vtkUnstructuredGrid.h"<br>#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include "vtkColorTransferFunction.h
"<br>#include "vtkPiecewiseFunction.h"<br>#include "vtkVolume.h"<br>#include "vtkVolumeProperty.h"<br>#include "vtkUnstructuredGridWriter.h"<br>#include "vtkDoubleArray.h
"
<br>#include "vtkDataSetTriangleFilter.h"<br>#include "vtkUnstructuredGridVolumeRayCastMapper.h"<br>#include "vtkUnstructuredGridVolumeRayCastFunction.h"<br>#include "vtkImageData.h"
<br>#include "vtkDataSetToImageFilter.h"<br>#include "stdio.h"<br>#include "iostream.h"<br>#include "fstream.h"<br>#include "string.h"<br>#include "vtkOpenGLRenderer.h
"<br>#include "vtkXOpenGLRenderWindow.h"<br>#include "vtkXRenderWindowInteractor.h"<br><br><br>int main(int argc, char *dim[])<br>{<br><br> int dim_x = atoi(dim[1]);<br> int dim_y = atoi(dim[1]);
<br> int dim_z = atoi(dim[1]);<br> int i, j, k;<br> int no_points = dim_x * dim_x * dim_x;<br> int no_voxels = (dim_x-1) * (dim_x-1) * (dim_x-1);<br><br> vtkPoints *points = vtkPoints::New();<br> points->SetNumberOfPoints(no_points);
<br> points->SetDataTypeToDouble();<br><br> for(k=0; k< dim_z; k++)<br> for(j=0; j< dim_y; j++)<br> for(i=0; i< dim_x; i++)<br> points->InsertNextPoint(i, j, k);<br><br> vtkDoubleArray *pts = vtkDoubleArray::New();
<br></span></div><div style="direction: ltr;"> pts->SetNumberOfComponents(4);<br> pts->SetName("pts");<br><br> for(i=0; i < no_voxels; i++) {<br> if (i & 0x01)<br> pts->InsertNextTuple4(1,0,0,
0.9);<br> else<br> pts->InsertNextTuple4(0,1,0,
0.9);<br> }<br><br> vtkUnstructuredGrid *grid = vtkUnstructuredGrid::New();</div><div style="direction: ltr;"><span class="e" id="q_10a6f8f39c1f383d_3"><br><br> //To create the grid we need to know if we are in any of the
<br> //cube limits (height, width, depth), to prevent from adding<br> //inexistant cells
<br> j=0;<br> k=0;<br> int w = 0;<br> int count = 0;<br> vtkVoxel *v = vtkVoxel::New();<br><br> for(i=0; i< (no_points - ((dim_x * dim_x) + (dim_x + 1))); i++) {<br> if(j != dim_x - 1 && k!= dim_x - 1) {
<br> (v->GetPointIds())->SetId(0, i);<br> (v->GetPointIds())->SetId(1, i+1);<br> (v->GetPointIds())->SetId(2, i+dim_x);<br> (v->GetPointIds())->SetId(3, i+dim_x+1);<br> (v->GetPointIds())->SetId(4, i + (dim_x * dim_y));
<br> (v->GetPointIds())->SetId(5, i + (dim_x * dim_y) + 1);<br> (v->GetPointIds())->SetId(6, i + (dim_x * dim_y) + dim_x);<br> (v->GetPointIds())->SetId(7, i + (dim_x * dim_y) + dim_x + 1);
<br> grid->InsertNextCell(v->GetCellType(), v->GetPointIds());<br><br> j++;<br> count++;<br> }<br> else {<br> if(j == dim_x-1) {<br> j=0;<br> k++;<br> if(k == dim_x-1) {
<br> j=0;<br> k=0;<br> i = i+dim_x;<br> w++;<br> }<br> }<br> }<br> }<br> grid->SetPoints(points);<br><br> vtkCellData *cd = grid->GetCellData();<br> cd->SetNumberOfTuples(no_voxels);
<br> cd->SetScalars(pts);<br><br></span></div><div style="direction: ltr;"> vtkRenderer *renderer = vtkRenderer::New();<br> vtkRenderWindow *renwin = vtkRenderWindow::New();<br> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
</div><div style="direction: ltr;"><span class="q"><br><br> renwin->AddRenderer(renderer);
<br> iren->SetRenderWindow(renwin);<br><br></span></div><div style="direction: ltr;"><span class="q"> vtkVolumeProperty *vp = vtkVolumeProperty::New();<br> // vp->SetColor(funtrans);<br> // vp->SetScalarOpacity(funop);
<br></span></div><div style="direction: ltr;"> vp->IndependentComponentsOff();</div><div style="direction: ltr;"><span class="q"><br><br>
vtkUnstructuredGridVolumeRayCastMapper *vrcm =<br> vtkUnstructuredGridVolumeRayCastMapper::New();<br><br> vtkDataSetTriangleFilter *filter = vtkDataSetTriangleFilter::New();<br> filter->SetInput(grid);<br>
<br> vrcm->SetInput(filter->GetOutput());<br><br> vtkVolume *volume = vtkVolume::New();<br> volume->SetMapper(vrcm);<br> volume->SetProperty(vp);<br><br> renderer->AddActor(volume);<br><br> renwin->Render();
<br> iren->Start();<br>}<br></span></div><div style="direction: ltr;"></div><br><br><br><br></div><div style="direction: ltr;"><span class="e" id="q_10a6f8f39c1f383d_10"><div><span class="gmail_quote">On 4/5/06, <b class="gmail_sendername">
Randall Hand</b> <<a href="mailto:randall.hand@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">randall.hand@gmail.com</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="direction: ltr;">If you look at the documentation for vtkVolumeProperty around the SetIndependantComponents stuff :
<a href="http://www.vtk.org/doc/release/5.0/html/a02182.html#z4350_1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.vtk.org/doc/release/5.0/html/a02182.html#z4350_1
</a><br><br>I'll play around with it tomorrow morning.. if I can get a
working version of your test driver, I'll send it to you for you to
check out :)</div><div style="direction: ltr;"><span>
<br><br><div><span class="gmail_quote">On 4/5/06, <b class="gmail_sendername">
Juan José Aja Fernández</b> <<a href="mailto:juan.aja@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">juan.aja@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="direction: ltr;">Hi, Randall:<br><br>Thanks again for the swift response.<br><br>I haven't tried using point data, first thing tomorrow I will rewrite the code.<br><br>Your
second suggestion was exactly what I was looking for, until now I
didn't know if there was a way to color whithout using a transfer
function (that explains my horrible hack of using the voxel index as a
"scalar"). I skimmed through the docs trying to find something related,
and I looked at vtkScalarsToColors as a possible candidate, but I have
my doubts: ¿How can I create a RGBA scalar field and how can this be
used as the color function in the mapper?
<br><br><br>Thanks a lot,<br></div><div style="direction: ltr;"><span><br>Juan.</span></div><div style="direction: ltr;"><span><br><br><br><div><span class="gmail_quote">On 4/5/06,
<b class="gmail_sendername">Randall Hand</b> <<a href="mailto:randall.hand@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">randall.hand@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="direction: ltr;">I'll try this out on my end tomorrow, since I'm already neck-deep in the Volume Rendering code anyway :)
<br><br>Just a thought tho, I believe most of the Volume Renderers
expect Point Data, not Cell Data.. Have you tried using Per-point data?
<br><br>Also, if you really want to define colors per-point and not
via a colormap, then if you use a 4-component scalar field you can have
it directly contain R/G/B/A for volume rendering.<br><br><div></div><div style="direction: ltr;">
<span><span class="gmail_quote">
On 4/5/06, <b class="gmail_sendername">Juan José Aja Fernández</b> <<a href="mailto:juan.aja@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">juan.aja@gmail.com</a>> wrote:</span></span>
</div><div style="direction: ltr;"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"></blockquote></div><div style="direction: ltr;"><span>
<div style="direction: ltr;"><span class="gmail_quote">(Sorry for the double post, The first url was broken)<br><br></span><div style="direction: ltr;">Hi, Everyone:<br>
<br>
This is the third time I'm posting about this issue, of the previous
two one remained unanswered and the last one I've got a kind response
by Randall Hand:
<a href="http://public.kitware.com/pipermail/vtkusers/2006-February/083786.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://public.kitware.com/pipermail/vtkusers/2006-February/083786.html
</a><br>
<br>
who pointed me in the direction of this fixed bug:
<br>
<br>
<a href="http://www.vtk.org/Bug/bug.php?op=show&bugid=2546&pos=3" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.vtk.org/Bug/bug.php?op=show&bugid=2546&pos=3</a> but the
problem persists.<br>
<br>
I think the vtkUnstructuredGridVolumeRayCastMapper has some serious bug
(look at the screenshots posted in the thread that Randall answered),
and to prove It I think I need to post my entire example code: <br>
<br>
(Really, I think I'm on to something, specially If you consider that
the mapper for unstructured grids is fairly new, but I didn't want to
litter the bug report with false positives).<br>
<br>
<br>
#include "vtkVoxel.h"<br>
#include "vtkCellData.h"<br>
#include "vtkRenderer.h"<br>
#include "vtkPoints.h"<br>
#include "vtkUnstructuredGrid.h"<br>
#include "vtkRenderWindow.h"<br>
#include "vtkRenderWindowInteractor.h"<br>
#include "vtkColorTransferFunction.h"<br>
#include "vtkPiecewiseFunction.h"<br>
#include "vtkVolume.h"<br>
#include "vtkVolumeProperty.h"<br>
#include "vtkUnstructuredGridWriter.h"<br>
#include "vtkDoubleArray.h"<br>
#include "vtkDataSetTriangleFilter.h"<br>
#include "vtkUnstructuredGridVolumeRayCastMapper.h"<br>
#include "vtkUnstructuredGridVolumeRayCastFunction.h"<br>
#include "vtkImageData.h"<br>
#include "vtkDataSetToImageFilter.h"<br>
#include "stdio.h"<br>
#include "iostream.h"<br>
#include "fstream.h"<br>
#include "string.h"<br>
#include "vtkOpenGLRenderer.h"<br>
#include "vtkXOpenGLRenderWindow.h"<br>
#include "vtkXRenderWindowInteractor.h"<br>
<br>
<br>
int main(int argc, char *dim[]) <br>
{ <br>
<br>
int dim_x = atoi(dim[1]);<br>
int dim_y = atoi(dim[1]);<br>
int dim_z = atoi(dim[1]);<br>
int i, j, k;<br>
int no_points = dim_x * dim_x * dim_x;<br>
int no_voxels = (dim_x-1) * (dim_x-1) * (dim_x-1);<br>
<br>
vtkPoints *points = vtkPoints::New();<br>
points->SetNumberOfPoints(no_points);<br>
points->SetDataTypeToDouble();<br>
<br>
for(k=0; k< dim_z; k++)<br>
for(j=0; j< dim_y; j++)<br>
for(i=0; i< dim_x; i++) <br>
points->InsertNextPoint(i, j, k);<br>
<br>
vtkDoubleArray *pts = vtkDoubleArray::New();<br>
pts->SetName("pts");<br>
<br>
for(i=0; i < no_voxels; i++)<br>
pts->InsertNextValue(i);<br>
<br>
vtkUnstructuredGrid *grid = vtkUnstructuredGrid::New();<br>
<br>
vtkColorTransferFunction *funtrans = vtkColorTransferFunction::New();<br>
<br>
//To create the grid we need to know if we are in any of the<br>
//cube limits (height, width, depth), to prevent from adding<br>
//inexistant cells<br>
j=0;<br>
k=0;<br>
int w = 0;<br>
int count = 0;<br>
vtkVoxel *v = vtkVoxel::New();<br>
<br>
for(i=0; i< (no_points - ((dim_x * dim_x) + (dim_x + 1))); i++) {<br>
if(j != dim_x - 1 && k!= dim_x - 1) { <br>
(v->GetPointIds())->SetId(0, i);<br>
(v->GetPointIds())->SetId(1, i+1);<br>
(v->GetPointIds())->SetId(2, i+dim_x);<br>
(v->GetPointIds())->SetId(3, i+dim_x+1);<br>
(v->GetPointIds())->SetId(4, i + (dim_x * dim_y));<br>
(v->GetPointIds())->SetId(5, i + (dim_x * dim_y) + 1);<br>
(v->GetPointIds())->SetId(6, i + (dim_x * dim_y) + dim_x);<br>
(v->GetPointIds())->SetId(7, i + (dim_x * dim_y) + dim_x + 1);<br>
grid->InsertNextCell(v->GetCellType(), v->GetPointIds());<br>
<br>
j++;<br>
count++;<br>
}<br>
else { <br>
if(j == dim_x-1) {<br>
j=0;<br>
k++;<br>
if(k == dim_x-1) {<br>
j=0;<br>
k=0;<br>
i = i+dim_x;<br>
w++;<br>
}<br>
}<br>
}<br>
}<br>
grid->SetPoints(points);<br>
<br>
vtkCellData *cd = grid->GetCellData();<br>
cd->SetNumberOfTuples(no_voxels);<br>
cd->SetScalars(pts);<br>
<br>
int idx = 0;<br>
while (idx < no_voxels) {<br>
if (idx%2 == 0 )<br>
<br>
funtrans->AddRGBPoint(pts->GetValue(idx), 1, 0, 0);<br>
else funtrans->AddRGBPoint(pts->GetValue(idx), 0, 1,0);<br>
<br>
idx++;<br>
}<br>
vtkOpenGLRenderer *renderer = vtkOpenGLRenderer::New();<br>
vtkXOpenGLRenderWindow *renwin = vtkXOpenGLRenderWindow::New();<br>
vtkXRenderWindowInteractor *iren = vtkXRenderWindowInteractor::New();<br>
<br>
renwin->AddRenderer(renderer);<br>
iren->SetRenderWindow(renwin);<br>
<br>
vtkPiecewiseFunction *funop = vtkPiecewiseFunction::New();<br>
funop->AddPoint(0, 1);<br>
funop->AddPoint(no_voxels, 1);<br>
<br>
vtkVolumeProperty *vp = vtkVolumeProperty::New();<br>
vp->SetColor(funtrans);<br>
vp->SetScalarOpacity(funop);<br>
<br>
vtkUnstructuredGridVolumeRayCastMapper *vrcm = vtkUnstructuredGridVolumeRayCastMapper::New();<br>
<br>
vtkDataSetTriangleFilter *filter = vtkDataSetTriangleFilter::New();<br>
filter->SetInput(grid);<br>
<br>
vrcm->SetInput(filter->GetOutput()); <br>
<br>
vtkVolume *volume = vtkVolume::New();<br>
volume->SetMapper(vrcm);<br>
volume->SetProperty(vp);<br>
<br>
renderer->AddActor(volume);<br>
<br>
renwin->Render();<br>
iren->Start();<br>
}<br>
<br>
<br>
This will attempt to create a cube with dimensions arg[1] coloring odd and even cells with green and red.<br>
Try it with argv[1] = 6, then argv[1] = 20, see the results.<br>
<br>
Is this a bug, or I'm doing things the wrong way?<br>
<br>
<br>
Thanks in advance,<br></div></div></span></div><div style="direction: ltr;"><div style="direction: ltr;"><span><div style="direction: ltr;"><span>
<br>
Juan.<br>
<br>
</span></div>
</span></div><br>_______________________________________________<br>This is the private VTK discussion list.<br>Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.vtk.org/mailman/listinfo/vtkusers
</a><br><br><br></div><br><br clear="all"><br>-- <br>Randall Hand<br>Visualization Scientist, <br>ERDC-MSRC Vicksburg, MS<br>Homepage: <a href="http://www.yeraze.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.yeraze.com</a>
</div></blockquote></div><br>
</span></div></blockquote></div><br><br clear="all"><br>-- <br>Randall Hand<br>Visualization Scientist, <br>ERDC-MSRC Vicksburg, MS<br>Homepage: <a href="http://www.yeraze.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.yeraze.com</a>
</span></div></blockquote></div><br><br clear="all"><br>-- <br>Randall Hand<br>Visualization Scientist, <br>ERDC-MSRC Vicksburg, MS<br>Homepage: <a href="http://www.yeraze.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.yeraze.com</a>
</span></div></blockquote></div><br>