Difference between revisions of "VTK/Examples/Cxx/InfoVis/ArrayToTable"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(VTK 5/6 compatible)
 
Line 1: Line 1:
==ArrayToTable.cxx==
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/InfoVis/ArrayToTable ArrayToTable] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
<source lang="cpp">
 
#include <vtkVersion.h>
 
#include <vtkSmartPointer.h>
 
#include <vtkDenseArray.h>
 
#include <vtkArrayToTable.h>
 
#include <vtkTable.h>
 
#include <vtkArrayData.h>
 
 
 
int main(int, char *[])
 
{
 
  vtkSmartPointer<vtkDenseArray<int> > array =
 
      vtkSmartPointer<vtkDenseArray<int> >::New();
 
  array->Resize(2,4);
 
 
 
  //set values
 
  std::cout << "There are " << array->GetExtents()[0].GetEnd() << std::endl;
 
  std::cout << "There are " << array->GetExtents()[1].GetEnd() << std::endl;
 
 
 
  for(vtkIdType i = 0; i < array->GetExtents()[0].GetEnd(); i++)
 
    {
 
    for(vtkIdType j = 0; j < array->GetExtents()[1].GetEnd(); j++)
 
      {
 
      array->SetValue(i, j, i+j);
 
      }
 
    }
 
   
 
  vtkSmartPointer<vtkArrayData> arrayData =
 
    vtkSmartPointer<vtkArrayData>::New();
 
  arrayData->AddArray(array);
 
 
 
  vtkSmartPointer<vtkArrayToTable> arrayToTable =
 
    vtkSmartPointer<vtkArrayToTable>::New();
 
#if VTK_MAJOR_VERSION <= 5
 
  arrayToTable->SetInputConnection(arrayData->GetProducerPort());
 
#else
 
  arrayToTable->SetInputData(arrayData);
 
#endif
 
  arrayToTable->Update();
 
 
 
  vtkSmartPointer<vtkTable> table = arrayToTable->GetOutput();
 
  table->Dump();
 
 
 
  return EXIT_SUCCESS;
 
}
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 
 
 
[[Category:VTKNoVizRequired]]
 

Latest revision as of 16:49, 20 February 2019

See ArrayToTable on the new VTKExamples website.