From 4d6822024afbbe783cdd620e248184b37d84c540 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Wed, 8 May 2024 09:27:21 +0200 Subject: [PATCH] #3517 Transform box with manual matrix --- packages/std/src/bbstdMagicBox.h | 2 +- packages/vtk/src/bbvtkTransform.cxx | 39 +++++++++++++++++++++++++++-- packages/vtk/src/bbvtkTransform.h | 4 +++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/packages/std/src/bbstdMagicBox.h b/packages/std/src/bbstdMagicBox.h index 99d27e8..20c964f 100644 --- a/packages/std/src/bbstdMagicBox.h +++ b/packages/std/src/bbstdMagicBox.h @@ -117,7 +117,7 @@ namespace bbstd (&MagicBox::bbGetInputIn), new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) ); - BBTK_INPUT(MagicBox, Active, "Active True/False (default True)",bool,""); + BBTK_INPUT(MagicBox, Active, "(default True) Active True/False",bool,""); AddOutputDescriptor diff --git a/packages/vtk/src/bbvtkTransform.cxx b/packages/vtk/src/bbvtkTransform.cxx index 8b71e00..1b29f8b 100644 --- a/packages/vtk/src/bbvtkTransform.cxx +++ b/packages/vtk/src/bbvtkTransform.cxx @@ -27,7 +27,10 @@ #include "bbvtkTransform.h" #include "bbvtkPackage.h" + #include "vtkMath.h" +#include "vtkMatrix4x4.h" + namespace bbvtk { BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Transform); @@ -130,16 +133,48 @@ namespace bbvtk result->RotateWXYZ( ang , v3[0], v3[1], v3[2] ); } // if rotation size >=4 + if (bbGetInputManualMatrixIn().size()==16) + { + std::vector manaulMatrixIn = bbGetInputManualMatrixIn(); + vtkMatrix4x4* m = result->GetMatrix(); + int i,j,ii=0; + for (j=0;j<4;j++) + { + for (i=0;i<4;i++) + { + m->SetElement(i,j,manaulMatrixIn[ii]); + ii++; + }// for i + } // for j + m->Modified(); + result->Update(); + } // ManualMatrix + + vtkTransform * finalTransform; if (bbGetInputInverse()==false) { - bbSetOutputOut(result); + finalTransform = result; } else { vtkMatrix4x4 *matrix; matrix=vtkMatrix4x4::New(); result->GetInverse(matrix); resultInverse->SetMatrix( matrix ); - bbSetOutputOut(resultInverse); + finalTransform = resultInverse; } // if Inverse + + bbSetOutputOut(finalTransform); + + std::vector manualMatrixOut; + vtkMatrix4x4* m = finalTransform->GetMatrix(); + int i,j,ii=0; + for (j=0;j<4;j++) + { + for (i=0;i<4;i++) + { + manualMatrixOut.push_back( m->GetElement(i,j) ); + }// for i + } // for j + bbSetOutputManualMatrixOut( manualMatrixOut ); } }// EO namespace bbvtk diff --git a/packages/vtk/src/bbvtkTransform.h b/packages/vtk/src/bbvtkTransform.h index 46e1c76..2a8d0cd 100644 --- a/packages/vtk/src/bbvtkTransform.h +++ b/packages/vtk/src/bbvtkTransform.h @@ -48,7 +48,9 @@ namespace bbvtk BBTK_DECLARE_INPUT(Translate,std::vector); BBTK_DECLARE_INPUT(Spacing,std::vector); BBTK_DECLARE_INPUT(RotateToNormal,std::vector); + BBTK_DECLARE_INPUT(ManualMatrixIn,std::vector); BBTK_DECLARE_OUTPUT(Out,vtkLinearTransform *); + BBTK_DECLARE_OUTPUT(ManualMatrixOut,std::vector); BBTK_PROCESS(Process); void Process(); @@ -73,8 +75,10 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(Transform,bbtk::AtomicBlackBox); BBTK_INPUT(Transform,Spacing,"vector with spacingX spacingY spacingZ",std::vector,""); BBTK_INPUT(Transform,RotateWXYZ,"vector with Angle Vx Vy Vz",std::vector,""); BBTK_INPUT(Transform,RotateToNormal,"(default is EMPTY) Normal vector [nx,ny,nz]",std::vector,""); + BBTK_INPUT(Transform,ManualMatrixIn,"(default EMPTY) The 16 elements of a 4x4 matrix",std::vector,""); BBTK_OUTPUT(Transform,Out,"vtkTransform result",vtkLinearTransform *,""); + BBTK_OUTPUT(Transform,ManualMatrixOut,"The 16 elements of the 4x4 matrix",std::vector,""); BBTK_END_DESCRIBE_BLACK_BOX(Transform); } -- 2.47.1