[vtkusers] Problems in accessing point data

rahul indoria rahulindoria5 at gmail.com
Mon Jul 22 11:04:12 EDT 2013


Hi,
     I have an example (
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/CurvedReformation ),
and i am modifying this example, i am trying to find the point data on the
data, i have modified this code, in that way which i am showing, but i am
getting some unexpected pointdata values which are nearly zero and which is
not possible. could you please suggest me some solution regarding this?

static vtkSmartPointer<vtkPolyData> SweepLine (vtkPolyData *line,
                                               double direction[3],
                                               double distance,
                                               unsigned int cols);
int main (int argc, char *argv[])
{
  // Verify arguments
  if (argc < 4)
    {
      std::cout << "Usage: " << argv[0]
                << " InputVolume PolyDataInput"
                << " Resolution"
                << std::endl;
      return EXIT_FAILURE;
    }

  // Parse arguments
  std::string volumeFileName = argv[1];
  std::string polyDataFileName = argv[2];
  std::stringstream ssResolution;
  ssResolution << argv[3];
  unsigned int resolution;
  ssResolution >> resolution;

  // Output arguments
  std::cout << "InputVolume: " << volumeFileName << std::endl
            << "PolyDataInput: " << polyDataFileName << std::endl
            << "Resolution: " << resolution << std::endl;

  // Read the volume data
  vtkSmartPointer< vtkImageReader2Factory > imageFactory =
    vtkSmartPointer< vtkImageReader2Factory >::New();
  vtkImageReader2 *imageReader =
  imageFactory->CreateImageReader2(volumeFileName.c_str());
  imageReader->SetFileName(volumeFileName.c_str());
  imageReader->Update();

  // Read the Polyline
  vtkSmartPointer<vtkPolyDataReader> polyLineReader =
    vtkSmartPointer<vtkPolyDataReader>::New();
  polyLineReader->SetFileName(polyDataFileName.c_str());
  polyLineReader->Update();

  vtkSmartPointer<vtkSplineFilter> spline =
    vtkSmartPointer<vtkSplineFilter>::New();
  spline->SetInputConnection(polyLineReader->GetOutputPort());
  spline->SetSubdivideToSpecified();
  spline->SetNumberOfSubdivisions(resolution);

  // Sweep the line to form a surface
  double direction[3];
  direction[0] = 0.0;
  direction[1] = 0.0;
  direction[2] = 1.0;
  double distance = 164;
  spline->Update();
  vtkSmartPointer<vtkPolyData> surface =
    SweepLine(spline->GetOutput(),
              direction,
              distance,
              atoi(argv[3]));

  // Probe the volume with the extruded surface
  vtkSmartPointer<vtkProbeFilter> sampleVolume =
    vtkSmartPointer<vtkProbeFilter>::New();
  sampleVolume->SetInputConnection(1, imageReader->GetOutputPort());
#if VTK_MAJOR_VERSION <= 5
  sampleVolume->SetInput(0, surface);
 #else
  sampleVolume->SetInputData(0, surface);
#endif
  // Compute a simple window/level based on scalar range
  vtkSmartPointer<vtkWindowLevelLookupTable> wlLut =
    vtkSmartPointer<vtkWindowLevelLookupTable>::New();
  double range = imageReader->GetOutput()->GetScalarRange()[1] -
                 imageReader->GetOutput()->GetScalarRange()[0];
  double level = (imageReader->GetOutput()->GetScalarRange()[1] +
                  imageReader->GetOutput()->GetScalarRange()[0]) / 2.0;
  wlLut->SetWindow(range);
  wlLut->SetLevel(level);
  sampleVolume->Update();


*// From Here i have done modification in my code.*

// To find out the Pointdata of a surface

  // Extract the polydata
   vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData> :: New();
   polydata = vtkPolyData::SafeDownCast(sampleVolume->GetOutput());

  // Get the number of points in the polydata
  vtkIdType idNumPointsInFile = polydata->GetNumberOfPoints();

  vtkSmartPointer<vtkDoubleArray> array = vtkSmartPointer<vtkDoubleArray>
:: New();
 //  array->SetName("Double");
   array->SetNumberOfTuples(idNumPointsInFile);

  polydata->GetPointData()->AddArray(array);

  // array =
vtkDoubleArray::SafeDownCast(polydata->GetPointData()->GetArray("Double"));
  if(array)
    {
    for(int i = 0; i < idNumPointsInFile; i++)
      {
      std::cout << "Got array.= " << i << std::endl;
      double dist;
      dist = array->GetValue(i);

      // if the array held arrays instead of scalars, you would use this:
      // double location[3];
      // array->GetTupleValue(i, location);
      // std::cout << "Location: " << Location[0] << ","  << Location[1] <<
"," << Location[2] << std::endl;

  std::cout << "Distance: " << dist << std::endl;
      }
    } //end if(array)
  else
    {
    std::cout << "no array." << std::endl;
    }

  system("PAUSE");

  return EXIT_SUCCESS;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130722/719a42d4/attachment.htm>


More information about the vtkusers mailing list