VTK/Examples/Cxx/Utilities/Box

From KitwarePublic

Jump to: navigation, search

Box.cxx

#include <vtkSmartPointer.h>
#include <vtkBox.h>
 
int main(int, char *[])
{
  // Define a box
  double bounds[6] = {-1,1,-1,1,-1,1};
 
  // Define a ray
  double rayOrigin[3] = {-5.0, 0, 0};
  double rayDirection[3] = {1.0, 0, 0};
 
  double intersection[3];
  double t;
 
  char hit = vtkBox::IntersectBox(bounds, rayOrigin, rayDirection, intersection, t);
 
  if(!hit)
    {
    std::cout << "Not hit!" << std::endl;
    }
  else
    {
    // Intersection should be (-1.0, 0, 0)
    std::cout << "Intersection is " << intersection[0] << " " << intersection[1] << " " << intersection[2] << std::endl;
    std::cout << "t is " << t << std::endl;
    }
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
PROJECT(Box)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(Box Box.cxx)
TARGET_LINK_LIBRARIES(Box vtkHybrid)
Personal tools