Skip to content

ProjectPointPlane

Repository source: ProjectPointPlane

Description

This example projects a point onto a plane. To use this example, you must have the CVSHEAD version of VTK (as of 2/2/2010).

Other languages

See (Java), (CSharp)

Question

If you have a question about this example, please use the VTK Discourse Forum

Code

ProjectPointPlane.cxx

#include <vtkNew.h>
#include <vtkPlane.h>

int main(int, char*[])
{
  vtkNew<vtkPlane> plane;
  plane->SetOrigin(0.0, 0.0, 0.0);
  plane->SetNormal(0.0, 0.0, 1.0);

  double p[3] = {23.1, 54.6, 9.2};
  double origin[3] = {0.0, 0.0, 0.0};
  double normal[3] = {0.0, 0.0, 1.0};
  double projected[3];

  plane->ProjectPoint(p, origin, normal, projected);

  std::cout << "Projected: " << projected[0] << " " << projected[1] << " "
            << projected[2] << std::endl;

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(ProjectPointPlane)

find_package(VTK COMPONENTS 
  CommonCore
  CommonDataModel
)

if (NOT VTK_FOUND)
  message(FATAL_ERROR "ProjectPointPlane: Unable to find the VTK build folder.")
endif()

# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(ProjectPointPlane MACOSX_BUNDLE ProjectPointPlane.cxx )
  target_link_libraries(ProjectPointPlane PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
  TARGETS ProjectPointPlane
  MODULES ${VTK_LIBRARIES}
)

Download and Build ProjectPointPlane

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

cd ProjectPointPlane/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:

./ProjectPointPlane

WINDOWS USERS

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