[vtkusers] UGrid volume ray cast Bug?

Juan José Aja Fernández juan.aja at gmail.com
Wed Apr 5 20:29:44 EDT 2006


Hi, Everyone:

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: http://public.kitware.com/pipermail/vtkusers/2006-February/083786.htmlwho
pointed me in the direction of this fixed bug:
http://www.vtk.org/Bug/bug.php?op=show&bugid=2546&pos=3 but the problem
persists.

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:

(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).


#include "vtkVoxel.h"
#include "vtkCellData.h"
#include "vtkRenderer.h"
#include "vtkPoints.h"
#include "vtkUnstructuredGrid.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkColorTransferFunction.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkUnstructuredGridWriter.h"
#include "vtkDoubleArray.h"
#include "vtkDataSetTriangleFilter.h"
#include "vtkUnstructuredGridVolumeRayCastMapper.h"
#include "vtkUnstructuredGridVolumeRayCastFunction.h"
#include "vtkImageData.h"
#include "vtkDataSetToImageFilter.h"
#include "stdio.h"
#include "iostream.h"
#include "fstream.h"
#include "string.h"
#include "vtkOpenGLRenderer.h"
#include "vtkXOpenGLRenderWindow.h"
#include "vtkXRenderWindowInteractor.h"


int main(int argc, char *dim[])
{

  int dim_x =  atoi(dim[1]);
  int dim_y =  atoi(dim[1]);
  int dim_z =  atoi(dim[1]);
  int i, j, k;
  int no_points = dim_x * dim_x * dim_x;
  int no_voxels = (dim_x-1) * (dim_x-1) * (dim_x-1);

  vtkPoints *points = vtkPoints::New();
  points->SetNumberOfPoints(no_points);
  points->SetDataTypeToDouble();

  for(k=0; k< dim_z; k++)
    for(j=0; j< dim_y; j++)
      for(i=0; i< dim_x; i++)
        points->InsertNextPoint(i, j, k);

  vtkDoubleArray *pts = vtkDoubleArray::New();
  pts->SetName("pts");

  for(i=0; i < no_voxels; i++)
    pts->InsertNextValue(i);

  vtkUnstructuredGrid *grid = vtkUnstructuredGrid::New();

  vtkColorTransferFunction *funtrans = vtkColorTransferFunction::New();

  //To create the grid we need to know if we are in any of the
  //cube limits (height, width, depth), to prevent from adding
  //inexistant cells
  j=0;
  k=0;
  int w = 0;
  int count = 0;
  vtkVoxel *v = vtkVoxel::New();

  for(i=0; i< (no_points - ((dim_x * dim_x) + (dim_x + 1))); i++) {
    if(j != dim_x - 1 && k!= dim_x - 1) {
      (v->GetPointIds())->SetId(0, i);
      (v->GetPointIds())->SetId(1, i+1);
      (v->GetPointIds())->SetId(2, i+dim_x);
      (v->GetPointIds())->SetId(3, i+dim_x+1);
      (v->GetPointIds())->SetId(4, i + (dim_x * dim_y));
      (v->GetPointIds())->SetId(5, i + (dim_x * dim_y) + 1);
      (v->GetPointIds())->SetId(6, i + (dim_x * dim_y) + dim_x);
      (v->GetPointIds())->SetId(7, i + (dim_x * dim_y) + dim_x + 1);
      grid->InsertNextCell(v->GetCellType(), v->GetPointIds());

      j++;
      count++;
    }
    else {
      if(j == dim_x-1) {
        j=0;
        k++;
        if(k == dim_x-1) {
          j=0;
          k=0;
          i = i+dim_x;
          w++;
        }
      }
    }
  }
  grid->SetPoints(points);

  vtkCellData *cd = grid->GetCellData();
  cd->SetNumberOfTuples(no_voxels);
  cd->SetScalars(pts);

  int idx = 0;
  while (idx < no_voxels) {
    if (idx%2 == 0 )

      funtrans->AddRGBPoint(pts->GetValue(idx), 1, 0, 0);
    else funtrans->AddRGBPoint(pts->GetValue(idx), 0, 1,0);

    idx++;
  }
  vtkOpenGLRenderer *renderer = vtkOpenGLRenderer::New();
  vtkXOpenGLRenderWindow *renwin =  vtkXOpenGLRenderWindow::New();
  vtkXRenderWindowInteractor *iren = vtkXRenderWindowInteractor::New();

  renwin->AddRenderer(renderer);
  iren->SetRenderWindow(renwin);

  vtkPiecewiseFunction *funop = vtkPiecewiseFunction::New();
  funop->AddPoint(0, 1);
  funop->AddPoint(no_voxels, 1);

  vtkVolumeProperty *vp = vtkVolumeProperty::New();
  vp->SetColor(funtrans);
  vp->SetScalarOpacity(funop);

  vtkUnstructuredGridVolumeRayCastMapper *vrcm =
vtkUnstructuredGridVolumeRayCastMapper::New();

  vtkDataSetTriangleFilter *filter = vtkDataSetTriangleFilter::New();
  filter->SetInput(grid);

  vrcm->SetInput(filter->GetOutput());

  vtkVolume *volume = vtkVolume::New();
  volume->SetMapper(vrcm);
  volume->SetProperty(vp);

  renderer->AddActor(volume);

  renwin->Render();
  iren->Start();
}


This will attempt to create a cube with dimensions arg[1] coloring odd and
even cells with green and red.
Try it with argv[1] = 6, then argv[1] = 20, see the results.

Is this a bug, or I'm doing things the wrong way?


Thanks in advance,

Juan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060405/b381fa20/attachment.htm>


More information about the vtkusers mailing list