Difference between revisions of "ITK/Examples/Math/MatrixInverse"

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==MatrixInverse.cxx== <source lang="cpp"> #include <itkMatrix.h> #include <iostream> int main() { typedef itk::Matrix<double, 2, 2> MatrixType; MatrixType M; M(0,0) = 1.0...")
 
Line 24: Line 24:
 
</source>
 
</source>
  
{{ITKCMakeLists|MatrixInverse}}
+
{{VTKCMakeLists|{{SUBPAGENAME}}}}

Revision as of 12:06, 11 December 2012

MatrixInverse.cxx

#include <itkMatrix.h>

#include <iostream>

int main()
{
  typedef itk::Matrix<double, 2, 2> MatrixType;
  MatrixType M;
  M(0,0) = 1.0;
  M(0,1) = 2.0;
  M(1,0) = 3.0;
  M(1,1) = 5.0;

  std::cout << "M: " << M << std::endl;

  MatrixType Minv( M.GetInverse() );

  std::cout << "Inverse: " << Minv << std::endl;

}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(MatrixInverse)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(MatrixInverse MACOSX_BUNDLE MatrixInverse.cxx)

if(VTK_LIBRARIES)
  target_link_libraries(MatrixInverse ${VTK_LIBRARIES})
else()
  target_link_libraries(MatrixInverse vtkHybrid vtkWidgets)
endif()

Download and Build MatrixInverse

Click here to download MatrixInverse. and its CMakeLists.txt file.

Once the tarball MatrixInverse.tar has been downloaded and extracted,

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

./MatrixInverse

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