[vtkusers] I have tried different ways, But... I cannot get a contour

qin zeng qin_in_usa at hotmail.com
Tue Nov 25 21:23:05 EST 2003


Hi, all,

I am a new user of VTK. I want to contour with some points and I have tried some ways. But no way out. who can help me?
The first part is all the same : I create a polydata without cells
////////////////////////////////////////////////////////////////////////////////////////////
 vtkPoints* _points = vtkPoints::New();
 vtkFloatArray* _pcoords =vtkFloatArray::New();
 vtkFloatArray* _iso_data =vtkFloatArray::New();
 vtkPolyData* _polydata = vtkPolyData::New();
 vtkCellArray*  _cells =  vtkCellArray::New();

 float grids[9800][3];       //  9800=70*140
 _pcoords->SetNumberOfComponents(3); // for x,y,z
 _pcoords->SetNumberOfTuples(70*140);  // for data (num)

/*
 Here I retrieve data from a file and store in a array temdata[70*140]
 process omitted here....

*/    
 int indexs=0;
 float ii,jj;
 for (ii =0;ii<70 ;ii ++)
 {
      for (jj = 0 ;jj< 140;jj =jj ++)
      {
          indexs =ii * 140 + jj);
          _iso_data->InsertNextValue(temdata[indexs]);
   
           grids[indexs][0] = jj; grids[indexs][1] = ii; grids[indexs][2] = 100;
           _pcoords->SetTuple(indexs, grids[indexs]);

      }
 }
 _points->SetData(_pcoords);
 _polydata->SetPoints(_points);
 _polydata->GetPointData()->SetScalars(_iso_data);

////////////////////////////////////////////////////////////////////////////////////////////

//<1>  Method 1: Manually create Cell.  Actually It is a grid so I create Pixel as a cell
// for the grid 70 * 140 the cell of pixels should be 69 * 139
  for (ii =0;ii<70-1 ;ii ++)
 {
      for (jj = 0 ;jj< 140 -1 ;jj =jj ++)
      {

           _cells->InsertNextCell(4);
           _cells->InsertCellPoint( (ii+1)*140 + j );
           _cells->InsertCellPoint((ii+1)*140 + j+1 );
           _cells->InsertCellPoint(  ii*140 + j );
           _cells->InsertCellPoint(  ii*140 + j +1 );
          // Here establish a cell of pixel
      }
 }
_polydata->SetPolys(_cells);
//<1> ...............And then I use  vtkContourFilter to process the _polydata  and then render it.



//<2> Method 2: Use vtkDelaunay2D as a filter to transfer the vtkPoints to vtkPolydata

    vtkDelaunay2D *  _d_2d =vtkDelaunay2D::New();
    _d_2d->SetInput(_polydata);
    _d_2d->SetTolerance(1);
 _polydata =_d_2d->GetOutput();

// <2>...............And then I use  vtkContourFilter to process the _polydata  and then render it.



//<3> I also use vtkSurfaceReconstructionFilter to do so.



But I failed to get any contour data!!!!!  
I know that if I create a polydata without cell I will surely fail. But I tried different way to create cell and fail too. why??

Is there anything important I am missing? 


Thanks!!!!

qzgrmc




More information about the vtkusers mailing list