VTK/Examples/Cxx/Utilities/ArrayLookup

From KitwarePublic

Jump to: navigation, search

ArrayLookup.cxx

#include <vtkSmartPointer.h>
#include <vtkFloatArray.h>
#include <vtkIdList.h>
 
int main(int, char *[])
{
  vtkSmartPointer<vtkFloatArray> distances =
    vtkSmartPointer<vtkFloatArray>::New();
  distances->SetNumberOfComponents(1);
  distances->SetName("Distances");
 
  distances->InsertNextValue(5);
  distances->InsertNextValue(15);
  distances->InsertNextValue(15);
  distances->InsertNextValue(25);
  distances->InsertNextValue(15);
 
  // Get first location
  vtkIdType result = distances->LookupValue(15);
  std::cout << "result: " << result << std::endl;
 
  // Get all locations
  vtkSmartPointer<vtkIdList> idList =
    vtkSmartPointer<vtkIdList>::New();
  distances->LookupValue(15, idList);
  std::cout << "found at: " << std::endl;
  for(vtkIdType i = 0; i < idList->GetNumberOfIds(); i++)
    {
    std::cout << idList->GetId(i) << " ";
    }
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
PROJECT(ArrayLookup)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
if (APPLE)
  add_executable(ArrayLookup MACOSX_BUNDLE ArrayLookup.cxx)
else()
  add_executable(ArrayLookup ArrayLookup.cxx)
endif()
 
if(VTK_LIBRARIES)
  target_link_libraries(ArrayLookup ${VTK_LIBRARIES})
else()
  target_link_libraries(ArrayLookup vtkHybrid )
endif()
Personal tools