|
|
Line 1: |
Line 1: |
| How do you resize a matrix at runtime? How do you compute the inverse and get back an itkMatrix instead of a vnl_matrix?
| | {{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions. |
| | }} |
|
| |
|
| ==Matrix.cxx==
| | [https://itk.org/ITKExamples[ITK Sphinx Examples]] |
| <source lang="cpp">
| |
| #include <itkMatrix.h>
| |
| #include <itkVector.h>
| |
| | |
| #include <iostream>
| |
| | |
| static void Construct();
| |
| //static void ConstructRunTimeDims();
| |
| static void Multiply();
| |
| //static void Inverse();
| |
| | |
| int main(int, char *[])
| |
| {
| |
| Construct();
| |
| Multiply();
| |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| void Construct()
| |
| {
| |
| typedef itk::Matrix<double, 3, 3> MatrixType;
| |
| MatrixType M;
| |
| M(0,0) = 1.0;
| |
| M(0,1) = 2.0;
| |
| M(0,2) = 3.0;
| |
| M(1,0) = 4.0;
| |
| M(1,1) = 5.0;
| |
| M(1,2) = 6.0;
| |
| M(2,0) = 7.0;
| |
| M(2,1) = 8.0;
| |
| M(2,2) = 9.0;
| |
| | |
| std::cout << "M: " << M << std::endl;
| |
| }
| |
| | |
| /* | |
| void ConstructRunTimeDims()
| |
| {
| |
| int matrixSize = 3;
| |
| typedef itk::Matrix<double, matrixSize, matrixSize> MatrixType;
| |
| MatrixType M;
| |
| M(0,0) = 1.0;
| |
| M(0,1) = 2.0;
| |
| M(0,2) = 3.0;
| |
| M(1,0) = 4.0;
| |
| M(1,1) = 5.0;
| |
| M(1,2) = 6.0;
| |
| M(2,0) = 7.0;
| |
| M(2,1) = 8.0;
| |
| M(2,2) = 9.0;
| |
| | |
| std::cout << "M: " << M << std::endl;
| |
| }
| |
| */
| |
| | |
| void Multiply()
| |
| {
| |
| typedef itk::Matrix<double, 3, 3> MatrixType;
| |
| MatrixType M;
| |
| M(0,0) = 1.0;
| |
| M(0,1) = 2.0;
| |
| M(0,2) = 3.0;
| |
| M(1,0) = 4.0;
| |
| M(1,1) = 5.0;
| |
| M(1,2) = 6.0;
| |
| M(2,0) = 7.0;
| |
| M(2,1) = 8.0;
| |
| M(2,2) = 9.0;
| |
| | |
| std::cout << "M: " << M << std::endl;
| |
| | |
| typedef itk::Vector<double, 3> VectorType;
| |
| VectorType V;
| |
| V[0] = 1.0;
| |
| V[1] = 2.0;
| |
| V[2] = 3.0;
| |
| | |
| std::cout << "V: " << V << std::endl;
| |
| | |
| std::cout << "MV: " << M*V << std::endl;
| |
| }
| |
| | |
| /*
| |
| void Inverse()
| |
| {
| |
| | |
| }
| |
| */
| |
| </source>
| |
| | |
| | |
| {{ITKCMakeLists|{{SUBPAGENAME}}}}
| |