]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
authorRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Thu, 19 Apr 2012 14:20:38 +0000 (16:20 +0200)
committerRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Thu, 19 Apr 2012 14:20:38 +0000 (16:20 +0200)
common/clitkTransformUtilities.cxx
common/clitkTransformUtilities.h
tools/clitkAffineTransform.ggo
tools/clitkAffineTransformGenericFilter.txx
vv/vvAnimatedGIFWriter.cxx

index 069fc70554022422781eb7bdabad1b454d1f9f01..ef210d70ae3318c5dbb778557787d9d86b51677e 100644 (file)
 namespace clitk
 {
 
+//--------------------------------------------------------------------
+template < >
+itk::Matrix<double, 3, 3>
+GetForwardAffineMatrix<2>(itk::Array<double> transformParameters)
+{
+  return GetForwardAffineMatrix2D(transformParameters);
+}
+
+//--------------------------------------------------------------------
+template < >
+itk::Matrix<double, 4, 4>
+GetForwardAffineMatrix<3>(itk::Array<double> transformParameters)
+{
+  return GetForwardAffineMatrix3D(transformParameters);
+}
+
 //--------------------------------------------------------------------
 template < >
 itk::Matrix<double, 3, 3>
@@ -37,4 +53,18 @@ GetBackwardAffineMatrix<3>(itk::Array<double> transformParameters)
   return GetBackwardAffineMatrix3D(transformParameters);
 }
 
+//--------------------------------------------------------------------
+template <>
+itk::Matrix<double, 2, 2> GetRotationMatrix<2>(itk::Array<double> rotationParameters)
+{
+  return GetRotationMatrix2D(rotationParameters);
+}
+
+//--------------------------------------------------------------------
+template <>
+itk::Matrix<double, 3, 3> GetRotationMatrix<3>(itk::Array<double> rotationParameters)
+{
+  return GetRotationMatrix3D(rotationParameters);
+}
+
 }
index a6fdd8c6a33f2670d9d665896d458f9cb1c7462c..3bdf22026ee0ab969a5fe8f6274db3a0fd4fa2e3 100644 (file)
@@ -32,12 +32,15 @@ namespace clitk
   //============================================================================
   itk::Matrix<double, 3, 3> GetForwardAffineMatrix2D(itk::Array<double> transformParameters);
   itk::Matrix<double, 4, 4> GetForwardAffineMatrix3D(itk::Array<double> transformParameters);
+  template <unsigned int Dimension > itk::Matrix<double, Dimension+1, Dimension+1> GetForwardAffineMatrix(itk::Array<double> transformParameters);
 
   itk::Matrix<double, 3, 3> GetBackwardAffineMatrix2D(itk::Array<double> transformParameters);
   itk::Matrix<double, 4, 4> GetBackwardAffineMatrix3D(itk::Array<double> transformParameters);
   template <unsigned int Dimension > itk::Matrix<double, Dimension+1, Dimension+1> GetBackwardAffineMatrix(itk::Array<double> transformParameters);
 
   itk::Matrix<double, 3, 3> GetRotationMatrix3D(itk::Array<double> rotationParameters);
+  itk::Matrix<double, 2, 2> GetRotationMatrix2D(itk::Array<double> rotationParameters);
+  template <unsigned int Dimension> itk::Matrix<double, Dimension, Dimension> GetRotationMatrix(itk::Array<double> rotationParameters);
   itk::Point<double, 3> GetRotatedPoint3D(itk::Array<double> rotationParameters, itk::Point<double, 3> input);
   itk::Matrix<double, 4, 4> GetCenteredRotationMatrix3D(itk::Array<double> rotationParameters,itk::Point<double,3> centerOfRotation);
   //   itk::Matrix<double, 4, 4> GetComposedMatrix3D(itk::Matrix<double, 4, 4> firstTransform, itk::Matrix<double, 4, 4> secondTransform);
@@ -166,9 +169,17 @@ namespace clitk
     matrix[2][2]= cos(rotationParameters[0])*cos(rotationParameters[1]);
     return matrix;
   }
+
+  inline itk::Matrix<double, 2, 2> GetRotationMatrix2D(itk::Array<double> rotationParameters)
+  {
+    itk::Matrix<double, 2, 2> matrix;
+    matrix[0][0] = cos(rotationParameters[0]);
+    matrix[1][0] = sin(rotationParameters[0]);
+    matrix[0][1] = -matrix[1][0];
+    matrix[1][1] = matrix[0][0];
+    return matrix;
+  }
+
   //========================================================================================
   inline  itk::Point<double, 3> GetRotatedPoint3D(itk::Array<double> rotationParameters, itk::Point<double, 3> input)
   {
index 8eeb3fc3b8b6365fb1bf348905d2514b241e33e4..131ff8e25bd101b351ea6c49a284bbeb06ee842a 100644 (file)
@@ -17,6 +17,8 @@ option "size"         -       "New output size if different from input"       int     no      multiple
 option "spacing"       -       "New output spacing if different from input"    double  no      multiple
 option "origin"                -       "New output origin if different from input"     double  no      multiple
 option "matrix"                m       "Affine matrix (homogene) filename"             string  no
+option "rotate"                r       "Rotation to apply (radians)"                   double  no      multiple
+option "translate"     t       "Translation to apply (mm)"                     double  no      multiple
 option "pad"           -       "Edge padding value"                            double  no      default="0.0"
 
 section "Interpolation"
index ef81fe2d464bc7082ed42a8f2d9ae1d5856ea3dc..ec9db098493cb873f1f0d4478696b48da1e5b0f6 100644 (file)
@@ -135,16 +135,50 @@ AffineTransformGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
 
   // Matrix
   typename itk::Matrix<double, Dimension+1, Dimension+1> matrix;
-  if (m_ArgsInfo.matrix_given) {
-    matrix= clitk::ReadMatrix<Dimension>(m_ArgsInfo.matrix_arg);
-    if (m_Verbose) std::cout<<"Reading the matrix..."<<std::endl;
-  } else {
-    matrix.SetIdentity();
+  if (m_ArgsInfo.rotate_given || m_ArgsInfo.translate_given)
+  {
+    if (m_ArgsInfo.matrix_given)
+    {
+      std::cerr << "You must use either rotate/translate or matrix options" << std::cout;
+      return;
+    }
+    itk::Array<double> transformParameters(2 * Dimension);
+    int pos = 0;
+    if (Dimension == 2)
+      transformParameters[pos++] = m_ArgsInfo.rotate_arg[0];
+    else
+      for (unsigned int i = 0; i < 3; i++)
+        transformParameters[pos++] = m_ArgsInfo.rotate_arg[i];
+    for (unsigned int i = 0; i < Dimension && i < 3; i++)
+      transformParameters[pos++] = m_ArgsInfo.translate_arg[i];
+    if (Dimension == 4)
+    {
+      matrix.SetIdentity();
+      itk::Matrix<double, 4, 4> tmp = GetForwardAffineMatrix3D(transformParameters);
+      for (unsigned int i = 0; i < 3; ++i)
+        for (unsigned int j = 0; j < 3; ++j)
+          matrix[i][j] = tmp[i][j];
+      for (unsigned int i = 0; i < 3; ++i)
+        matrix[i][4] = tmp[i][3];
+    }
+    else
+      matrix = GetForwardAffineMatrix<Dimension>(transformParameters);
+  }
+  else
+  {
+    if (m_ArgsInfo.matrix_given)
+    {
+      matrix= clitk::ReadMatrix<Dimension>(m_ArgsInfo.matrix_arg);
+      if (m_Verbose) std::cout << "Reading the matrix..." << std::endl;
+    }
+    else
+      matrix.SetIdentity();
   }
-  if (m_Verbose) std::cout<<"Using the following matrix:"<<std::endl;
-  if (m_Verbose) std::cout<<matrix<<std::endl;
-  typename itk::Matrix<double, Dimension, Dimension> rotationMatrix=clitk::GetRotationalPartMatrix(matrix);
-  typename itk::Vector<double,Dimension> translationPart= clitk::GetTranslationPartMatrix(matrix);
+  if (m_Verbose)
+    std::cout << "Using the following matrix:" << std::endl
+              << matrix << std::endl;
+  typename itk::Matrix<double, Dimension, Dimension> rotationMatrix = clitk::GetRotationalPartMatrix(matrix);
+  typename itk::Vector<double, Dimension> translationPart = clitk::GetTranslationPartMatrix(matrix);
 
   // Transform
   typedef itk::AffineTransform<double, Dimension> AffineTransformType;
@@ -284,14 +318,50 @@ void AffineTransformGenericFilter<args_info_type>::UpdateWithDimAndVectorType()
 
   // Matrix
   typename itk::Matrix<double, Dimension+1, Dimension+1> matrix;
-  if (m_ArgsInfo.matrix_given)
-    matrix= clitk::ReadMatrix<Dimension>(m_ArgsInfo.matrix_arg);
+  if (m_ArgsInfo.rotate_given || m_ArgsInfo.translate_given)
+  {
+    if (m_ArgsInfo.matrix_given)
+    {
+      std::cerr << "You must use either rotate/translate or matrix options" << std::cout;
+      return;
+    }
+    itk::Array<double> transformParameters(2 * Dimension);
+    int pos = 0;
+    if (Dimension == 2)
+      transformParameters[pos++] = m_ArgsInfo.rotate_arg[0];
+    else
+      for (unsigned int i = 0; i < 3; i++)
+        transformParameters[pos++] = m_ArgsInfo.rotate_arg[i];
+    for (unsigned int i = 0; i < Dimension && i < 3; i++)
+      transformParameters[pos++] = m_ArgsInfo.translate_arg[i];
+    if (Dimension == 4)
+    {
+      matrix.SetIdentity();
+      itk::Matrix<double, 4, 4> tmp = GetForwardAffineMatrix3D(transformParameters);
+      for (unsigned int i = 0; i < 3; ++i)
+        for (unsigned int j = 0; j < 3; ++j)
+          matrix[i][j] = tmp[i][j];
+      for (unsigned int i = 0; i < 3; ++i)
+        matrix[i][4] = tmp[i][3];
+    }
+    else
+      matrix = GetForwardAffineMatrix<Dimension>(transformParameters);
+  }
   else
-    matrix.SetIdentity();
-  if (m_Verbose) std::cout<<"Using the following matrix:"<<std::endl;
-  if (m_Verbose) std::cout<<matrix<<std::endl;
-  typename itk::Matrix<double, Dimension, Dimension> rotationMatrix=clitk::GetRotationalPartMatrix(matrix);
-  typename itk::Vector<double, Dimension> translationPart= clitk::GetTranslationPartMatrix(matrix);
+  {
+    if (m_ArgsInfo.matrix_given)
+    {
+      matrix= clitk::ReadMatrix<Dimension>(m_ArgsInfo.matrix_arg);
+      if (m_Verbose) std::cout << "Reading the matrix..." << std::endl;
+    }
+    else
+      matrix.SetIdentity();
+  }
+  if (m_Verbose)
+    std::cout << "Using the following matrix:" << std::endl
+              << matrix << std::endl;
+  typename itk::Matrix<double, Dimension, Dimension> rotationMatrix = clitk::GetRotationalPartMatrix(matrix);
+  typename itk::Vector<double, Dimension> translationPart = clitk::GetTranslationPartMatrix(matrix);
 
   // Transform
   typedef itk::AffineTransform<double, Dimension> AffineTransformType;
index 75352acacc0f05b33f48540b97b9ad52649fddaa..7af2ca4ab26466a2e7f401c3f9837a86cb4aa3ca 100644 (file)
@@ -75,11 +75,19 @@ void vvAnimatedGIFWriter::End()
                                  width, height, 8, width, false);
     cximages[i]->SetFrameDelay(100/Rate);
     cximages[i]->SetPalette((RGBQUAD*)(quant->GetLookupTable()->GetPointer(0)));
+    // Swap r and b in LUT before setting it
+    RGBQUAD *pal = cximages[i]->GetPalette();
+    for(unsigned int j=0; j<256; j++)
+      std::swap(pal[j].rgbBlue, pal[j].rgbRed);
   }
 
   // Create gif
   FILE * pFile;
   pFile = fopen (this->FileName, "wb");
+  if(pFile==NULL) {
+    vtkErrorMacro("Error in vvAnimatedGIFWriter::End: could not open " << this->FileName );
+    return;
+  }
   CxImageGIF cximagegif;
   cximagegif.SetLoops(Loops);
   bool result = cximagegif.Encode(pFile,&(cximages[0]), (int)RGBslices.size(), true);