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">http://public.kitware.com/pipermail/vtkusers/2006-February/083786.html</a>
who pointed me in the direction of this fixed bug:
<a href="http://www.vtk.org/Bug/bug.php?op=show&bugid=2546&pos=3">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>
<br>
Juan.<br>
<br>