PlanesIntersection

VTKExamples/Cxx/GeometricObjects/PlanesIntersection

Other Languages

See (Python), (Java), (CSharp)

Code

PlanesIntersection.cxx

#include <vtkPlanesIntersection.h>
#include <vtkPoints.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>

int main(int, char *[])
{
  vtkSmartPointer<vtkSphereSource> sphereSource =
    vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();

  double bounds[6];
  sphereSource->GetOutput()->GetBounds(bounds);

  vtkSmartPointer<vtkPoints> box =
    vtkSmartPointer<vtkPoints>::New();

  box->SetNumberOfPoints(8);

  double xMin, xMax, yMin, yMax, zMin, zMax;
  xMin = bounds[0]; xMax = bounds[1];
  yMin = bounds[2]; yMax = bounds[3];
  zMin = bounds[4]; zMax = bounds[5];

  box->SetPoint(0, xMax, yMin, zMax);
  box->SetPoint(1, xMax, yMin, zMin);
  box->SetPoint(2, xMax, yMax, zMin);
  box->SetPoint(3, xMax, yMax, zMax);
  box->SetPoint(4, xMin, yMin, zMax);
  box->SetPoint(5, xMin, yMin, zMin);
  box->SetPoint(6, xMin, yMax, zMin);
  box->SetPoint(7, xMin, yMax, zMax);

  vtkSmartPointer<vtkPlanesIntersection> planesIntersection =
      vtkSmartPointer<vtkPlanesIntersection>::New();
  planesIntersection->SetBounds(bounds);

  int intersects = planesIntersection->IntersectsRegion(box);

  std::cout << "Intersects? " << intersects << std::endl;

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(PlanesIntersection)

find_package(VTK COMPONENTS 
  vtkCommonCore
  vtkCommonDataModel
  vtkFiltersSources QUIET)
if (NOT VTK_FOUND)
  message("Skipping PlanesIntersection: ${VTK_NOT_FOUND_MESSAGE}")
  return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
  # old system
  include(${VTK_USE_FILE})
  add_executable(PlanesIntersection MACOSX_BUNDLE PlanesIntersection.cxx )
  target_link_libraries(PlanesIntersection PRIVATE ${VTK_LIBRARIES})
else ()
  # include all components
  add_executable(PlanesIntersection MACOSX_BUNDLE PlanesIntersection.cxx )
  target_link_libraries(PlanesIntersection PRIVATE ${VTK_LIBRARIES})
  # vtk_module_autoinit is needed
  vtk_module_autoinit(
    TARGETS PlanesIntersection
    MODULES ${VTK_LIBRARIES}
    )
endif () 

Download and Build PlanesIntersection

Click here to download PlanesIntersection and its CMakeLists.txt file. Once the tarball PlanesIntersection.tar has been downloaded and extracted,

cd PlanesIntersection/build 

If VTK is installed:

cmake ..

If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:

cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

make

and run it:

./PlanesIntersection

WINDOWS USERS

Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.