[vtkusers] vtkClipPolyData and vtkTubeFilter runtime error

Julien Jomier jjomier at cs.unc.edu
Thu Apr 29 13:02:58 EDT 2004


Hi,

I'm trying to use vtkClipPolyData to clip some tubes produced by a
vtkTubeFilter. Everything is working well if I don't set scalars to my
vtkPolyData (the input of the vtkTubeFilter). However, I need to set the
scalars to use the SetVaryRadiusToVaryRadiusByScalar().

---------- Code Begin ----------
  
  unsigned int nPoints = 5;
  vtkPoints* vPoints = vtkPoints::New();
  vPoints->SetNumberOfPoints(nPoints);

  vtkFloatArray* vScalars = vtkFloatArray::New();
  vScalars->SetNumberOfTuples(nPoints);
      
  for(unsigned int i=0; i<nPoints;i++)
    {
    vPoints->SetPoint(i, i, i, i);
    vScalars->SetTuple1(i,1+i);  // setting this line to ->SetTuple1(i,1);
works
    } 

  //Step 1: create a point id list (for a polyline this is just linear
  int* pntIds = new int[nPoints];
  for (unsigned int i = 0; i < (int)nPoints; i++)
    {
    pntIds[i] = i;
    }

  //Step 2: create a polyline from the points and pt id list
  vtkPolyLine* vPLine = vtkPolyLine::New();
  vPLine->Initialize(nPoints, pntIds, vPoints);

  //Step 3: convert this to a cellarray
  vtkCellArray* vCA = vtkCellArray::New();
  vCA->InsertNextCell(vPLine); 

  //Step 4: convert to polydata
  vtkPolyData* vPData = vtkPolyData::New();
  vPData->SetLines(vCA);
  vPData->SetPoints(vPoints);
  vtkFloatingPointType range[2];
  bool use_scalars = false;
  float min_scalar, max_scalar;
  vScalars->GetRange(range);
  min_scalar = range[0];
  max_scalar = range[1];
  if (min_scalar <= 0.0001) 
    {
    min_scalar = 0.0001;
    }
  if(max_scalar < min_scalar) 
    {
    max_scalar = min_scalar;
    }
  if (min_scalar != max_scalar) 
    {
    use_scalars = true;
    vPData->GetPointData()->SetScalars(vScalars);
    }

  //Step 5: remove any duplicate points from polydata. The tube filter
  //fails if any duplicates are present
  vtkCleanPolyData* vClean = vtkCleanPolyData::New();
  vClean->SetInput(vPData);

  //Step 6: make tubes.
  vtkTubeFilter* vTFilter = vtkTubeFilter::New();
  vTFilter->SetNumberOfSides(3);
  vTFilter->SetInput(vClean->GetOutput());
  vTFilter->CappingOff();

  if(use_scalars)
    {
    vTFilter->SetVaryRadiusToVaryRadiusByScalar();
    vTFilter->SetRadius(min_scalar);  
    vTFilter->SetRadiusFactor(max_scalar/min_scalar);
    }
  else
    {
    vTFilter->SetRadius(min_scalar);
    vTFilter->SetVaryRadiusToVaryRadiusOff();
    }

  //Step 7: Create the clipper
  vtkSphere* sphere = vtkSphere::New();
  sphere->SetRadius(1);
  sphere->SetCenter(0,0,0);

  vTFilter->Update();
    
  vtkClipPolyData*  clipper = vtkClipPolyData::New();
  clipper->SetInput(vTFilter->GetOutput());
  clipper->SetClipFunction(sphere);
  clipper->GenerateClipScalarsOn();
  clipper->GenerateClippedOutputOn();
  clipper->InsideOutOn();
  clipper->SetValue(0.5);
  clipper->Update();

---------- Code End  ----------

The debugger returns a runtime error in the function
vtkDataSetAttributes::InterpolateTuple() of the vtkDataSetAttributes.cxx
class (ln 1079).

I'm using VTK from CVS updated this morning on a Win2K platform with MSVC
6.0
Am I doing something wrong?

Thanks for the help,

Julien




More information about the vtkusers mailing list