Difference between revisions of "VTK/Examples/Cxx/PolyData/CopyAllArrays"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to navigationJump to search
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CopyAllArrays CopyAllArrays] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples websit...")
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==CopyAllArrays.cxx==
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CopyAllArrays CopyAllArrays] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkSphereSource.h>
 
#include <vtkPolyData.h>
 
#include <vtkPointData.h>
 
#include <vtkFloatArray.h>
 
#include <vtkDoubleArray.h>
 
#include <vtkIntArray.h>
 
 
 
int main(int argc, char *argv[])
 
{
 
  vtkSmartPointer<vtkSphereSource> sphereSource =
 
      vtkSmartPointer<vtkSphereSource>::New();
 
  sphereSource->Update();
 
 
 
  vtkPolyData* polydata = sphereSource->GetOutput();
 
 
 
  vtkSmartPointer<vtkDoubleArray> doubles =
 
      vtkSmartPointer<vtkDoubleArray>::New();
 
  doubles->SetName("Doubles");
 
  doubles->SetNumberOfTuples(polydata->GetNumberOfPoints());
 
 
 
  polydata->GetPointData()->AddArray(doubles);
 
 
 
  vtkSmartPointer<vtkIntArray> ints =
 
      vtkSmartPointer<vtkIntArray>::New();
 
  ints->SetName("Ints");
 
  ints->SetNumberOfTuples(polydata->GetNumberOfPoints());
 
 
 
  polydata->GetPointData()->AddArray(ints);
 
 
 
  unsigned int numberOfArrays = polydata->GetPointData()->GetNumberOfArrays();
 
  cout << "There are " << numberOfArrays << " arrays." << endl;
 
 
 
  vtkSmartPointer<vtkPolyData> newPolyData =
 
      vtkSmartPointer<vtkPolyData>::New();
 
 
 
  for(unsigned int i = 0; i < numberOfArrays; i++)
 
    {
 
    cout << "array " << i << ":" << endl;
 
    cout << "name: " << polydata->GetPointData()->GetArrayName(i) << endl;
 
    cout << "type: " << polydata->GetPointData()->GetArray(i)->GetDataType() << endl;
 
    cout << endl;
 
   
 
    newPolyData->GetPointData()->AddArray(polydata->GetPointData()->GetArray(i));
 
    }
 
   
 
  cout << "new polydata: " << endl;
 
 
 
  for(unsigned int i = 0; i < numberOfArrays; i++)
 
    {
 
    cout << "array " << i << ":" << endl;
 
    cout << "name: " << newPolyData->GetPointData()->GetArrayName(i) << endl;
 
    cout << "type: " << newPolyData->GetPointData()->GetArray(i)->GetDataType() << endl;
 
    cout << endl;
 
    }
 
 
 
  return EXIT_SUCCESS;
 
}
 
 
 
</source>
 
 
 
==CMakeLists.txt==
 
<source lang="cmake">
 
cmake_minimum_required(VERSION 2.6)
 
 
 
PROJECT(CopyAllArrays)
 
 
 
FIND_PACKAGE(VTK REQUIRED)
 
INCLUDE(${VTK_USE_FILE})
 
 
 
ADD_EXECUTABLE(CopyAllArrays CopyAllArrays.cxx)
 
TARGET_LINK_LIBRARIES(CopyAllArrays vtkHybrid)
 
 
 
 
 
</source>
 

Latest revision as of 15:35, 9 September 2019