]> Creatis software - bbtk.git/commitdiff
#3482 Transform box Rotation from Normal
authorEduardo DAVILA <davila@creatis.insa-lyon.fr>
Mon, 27 Dec 2021 10:58:48 +0000 (11:58 +0100)
committerEduardo DAVILA <davila@creatis.insa-lyon.fr>
Mon, 27 Dec 2021 10:58:48 +0000 (11:58 +0100)
packages/vtk/src/bbvtkTransform.cxx
packages/vtk/src/bbvtkTransform.h

index 1c6b3357f01ee34bf315f3193352c9aaaafdf533..c935a0dd9b1aa6f3860e3066252f8bc7b098f9d2 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "bbvtkTransform.h"
 #include "bbvtkPackage.h"
+#include "vtkMath.h"
 namespace bbvtk
 {
   BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Transform);
@@ -58,8 +59,8 @@ namespace bbvtk
                vecSpacing.push_back(1);  //spacing y
                vecSpacing.push_back(1);  //spacing z
                bbSetInputSpacing(vecSpacing);
-
-               result = NULL;  
+        
+               result = NULL;
        }
 
        // --------------------------------------------------------------       
@@ -107,6 +108,23 @@ namespace bbvtk
                  result->RotateWXYZ(bbGetInputRotateWXYZ()[0],bbGetInputRotateWXYZ()[1], bbGetInputRotateWXYZ()[2], bbGetInputRotateWXYZ()[3]);
       } // if rotation size >=4
  
+      if (bbGetInputRotateToNormal().size()>=3)
+      {
+          double v1[3],v2[3],v3[3];
+          v1[0]             = 0;
+          v1[1]             = 0;
+          v1[2]             = 1;
+          v2[0]             = bbGetInputRotateToNormal()[0];
+          v2[1]             = bbGetInputRotateToNormal()[1];
+          v2[2]             = bbGetInputRotateToNormal()[2];
+          vtkMath *vtkmath  = vtkMath::New();
+          double ang        = acos ( vtkmath->Dot(v1,v2)  );
+          ang               = vtkmath->DegreesFromRadians( ang );
+          vtkmath->Cross( v1,v2,v3 );
+          vtkmath->Delete();
+          result->RotateWXYZ( ang  , v3[0], v3[1], v3[2] );
+      } // if rotation size >=4
+
          if (bbGetInputInverse()==false)
          {
                bbSetOutputOut(result);
index 618b0d357235667f39c22af6316027a15aa3ca14..ebe2e7515864b0f07ab637320515940a15e702d9 100644 (file)
@@ -47,6 +47,7 @@ namespace bbvtk
     BBTK_DECLARE_INPUT(RotateWXYZ,std::vector<double>);
     BBTK_DECLARE_INPUT(Translate,std::vector<double>);
     BBTK_DECLARE_INPUT(Spacing,std::vector<double>);
+    BBTK_DECLARE_INPUT(RotateToNormal,std::vector<double>);
     BBTK_DECLARE_OUTPUT(Out,vtkLinearTransform *);
     BBTK_PROCESS(Process);
     void Process();
@@ -71,6 +72,7 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(Transform,bbtk::AtomicBlackBox);
   BBTK_INPUT(Transform,Translate,"vector with x y z",std::vector<double>,"");
   BBTK_INPUT(Transform,Spacing,"vector with spacingX spacingY spacingZ",std::vector<double>,"");
   BBTK_INPUT(Transform,RotateWXYZ,"vector with Angle Vx Vy Vz",std::vector<double>,"");
+  BBTK_INPUT(Transform,RotateToNormal,"(default is EMPTY) Normal vector [nx,ny,nz]",std::vector<double>,"");
 
   BBTK_OUTPUT(Transform,Out,"vtkTransform result",vtkLinearTransform *,"");