]> Creatis software - bbtk.git/blobdiff - packages/vtk/src/bbvtkTransform.cxx
#3482 Transform box Rotation from Normal
[bbtk.git] / packages / vtk / src / bbvtkTransform.cxx
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);