8 #include "iDeformationRigid.hh" 86 cout <<
"-- Rigid transformation algorithm based on trilinear interpolation --" << endl;
87 cout <<
"Each transformation requires 3 translation (x,y,z) and 3 rotation parameters, provided by command-line option or in a text file" << endl;
88 cout <<
"The transformation parameters can be either defined between: " << endl;
89 cout <<
"- A position n and the following position n+1 " << endl;
90 cout <<
"- A reference position and the actual position n (default) " << endl;
91 cout <<
" (Check the 'Transformation mode' keyword below for more information) " << endl;
93 cout <<
"--------------------------------------------------------" << endl;
94 cout <<
"Command-line options:" <<endl;
95 cout <<
"Parameters for each transformation must be provided sequentially and separated by commas" << endl;
96 cout <<
"Example for a dataset containing 3 transformations:" << endl;
97 cout <<
"-rm deformationRigid:trX1,trY1,trZ1,rotX1,rotY1,rotZ1,trX2,trY2,trZ2,rotX2,rotY2,rotZ2,trX3,trY3,trZ3,rotX3,rotY3,rotZ3" << endl;
98 cout <<
"--------------------------------------------------------" << endl;
99 cout <<
"Text file:" <<endl;
100 cout <<
"Parameters for each transformation must be provided after a 'Transformation parameters' key, on a separate line, and separated by commas" << endl;
101 cout <<
"Translations must be provided in mm, for each axis." << endl;
102 cout <<
"Rotations must be provided in degree. Use the Rotation convention optional parameter in order to set up the rotation orientation." << endl;
103 cout <<
"Example for a dataset containing 3 transformations:" << endl;
104 cout <<
"Transformation_parameters:" << endl;
105 cout <<
"trX1,trY1,trZ1,rotA1,rotB1,rotC1" << endl;
106 cout <<
"trX2,trY2,trZ2,rotA2,rotB2,rotC2" << endl;
107 cout <<
"trX3,trY3,trZ3,rotA3,rotB3,rotC3" << endl;
108 cout <<
"etc..." << endl;
110 cout <<
"--------------------------------------------------------" << endl;
111 cout <<
"Optional parameters (configuration file only):" << endl;
113 cout <<
"Rotation_convention: Any combinations of 'x', 'y', and 'z'" << endl;
114 cout <<
"Define the axe on which the rotation will be performed using rotA, rotB and rotC angle in 1 (default): XYZ" << endl;
116 cout <<
"Transformation_mode: (1 or 0)" << endl;
117 cout <<
"0 (default): Transformation between the reference position to the n position." << endl;
118 cout <<
"1 : Transformation between the n-1 position to the n position." << endl;
119 cout <<
" They will be recomputed to represent transformations from a reference position to i as required by CASToR" << endl;
143 Cerr(
"***** iDeformationRigid::ReadAndCheckConfigurationFile() -> Number of transformations in the deformation has not been initialized !" << endl);
148 ifstream in_file(a_fileOptions.c_str(), ios::in);
158 Cerr(
"***** iDeformationRigid::ReadAndCheckConfigurationFile -> A problem occurred while trying to recover transformation parameters from file !" << endl);
165 Cerr(
"***** iDeformationRigid::ReadAndCheckConfigurationFile -> A problem occurred while trying to read 'compute_transformations' flag (must be 1 (true) or 0 (false))!" << endl);
172 Cerr(
"***** iDeformationRigid::ReadAndCheckConfigurationFile -> A problem occurred while trying to read rotation convention (string) !" << endl);
187 mp_tX[t] = p_coeffs[t*6];
188 mp_tY[t] = p_coeffs[t*6+1];
189 mp_tZ[t] = p_coeffs[t*6+2];
190 mp_rA[t] = p_coeffs[t*6+3];
191 mp_rB[t] = p_coeffs[t*6+4];
192 mp_rC[t] = p_coeffs[t*6+5];
197 Cerr(
"***** iDeformationRigid::ReadAndCheckOptionsList() -> An error occurred while building Transformation matrices !" << endl);
206 Cerr(
"***** iDeformationRigid::ReadAndCheckConfigurationFile -> Error while trying to read configuration file : " << a_fileOptions << endl);
231 Cerr(
"***** iDeformationRigid::ReadAndCheckOptionsList() -> Number of transformations in the deformation has not been initialized !" << endl);
242 "Rigid deformation configuration"))
244 Cerr(
"***** iDeformationRigid::ReadAndCheckOptionsList() -> Failed to correctly read the list of parameters in command-line options !" << endl);
245 Cerr(
"***** "<<
m_nbTransformations*6<<
" parameters were expected (6 parameters for each transformation)" << endl);
261 mp_tX[t] = p_coeffs[t*6];
262 mp_tY[t] = p_coeffs[t*6+1];
263 mp_tZ[t] = p_coeffs[t*6+2];
264 mp_rA[t] = p_coeffs[t*6+3];
265 mp_rB[t] = p_coeffs[t*6+4];
266 mp_rC[t] = p_coeffs[t*6+5];
271 Cerr(
"***** iDeformationRigid::ReadAndCheckOptionsList() -> An error occurred while building Transformation matrices !" << endl);
299 Cerr(
"***** iDeformationRigid::ComputeTransformationMatrices() -> Parameters not initialized !" << endl);
327 for(
int d=0 ; d<2 ; d++)
334 x_rad = -
mp_rA[t] * M_PI/180.;
335 y_rad = -
mp_rB[t] * M_PI/180.;
336 z_rad = -
mp_rC[t] * M_PI/180.;
360 Cerr(
"***** iDeformationRigid::ComputeTransformationMatrices() -> Error occurred when initializing rotation matrices !" << endl);
377 for(
int l=0 ; l<4 ; l++)
378 for(
int c=0 ; c<4 ; c++)
384 for(
int l=0 ; l<4 ; l++)
385 for(
int c=0 ; c<4 ; c++)
422 Cerr(
"***** iDeformationRigid::CheckSpecificParameters() -> Transformation parameters not initialized !" << endl);
448 Cerr(
"***** iDeformationRigid::Initialize() -> Parameters should be checked before Initialize() !" << endl);
483 Cerr(
"***** iDeformationRigid::ApplyDeformations() -> Called while not initialized !" << endl);
489 << (
string)((a_direction==
FORWARD_DEFORMATION)?
"forward":
"backward") <<
"), with parameters " 490 <<
mp_tX[a_defIdx] <<
";" <<
mp_tY[a_defIdx] <<
";" <<
mp_tZ[a_defIdx] <<
";" 491 <<
mp_rA[a_defIdx] <<
";" <<
mp_rB[a_defIdx] <<
";" <<
mp_rC[a_defIdx] <<
";" << endl);
532 #ifdef CASTOR_VERBOSE 571 Cerr(
"*****iDeformationRigid::ApplyDeformationToForwardImage()->Error, unknown direction type( must be 'forward' or 'backward' # " << endl);
579 uint32_t iv = ivZ*dXY + ivY*dX + ivX;
583 dvZ = (oVect->
GetMatriceElt(2,0) - (ivZ*sZ - dZ*sZ/2 + sZ*0.5) ) / sZ;
584 dvY = (oVect->
GetMatriceElt(1,0) - (ivY*sY - dY*sY/2 + sY*0.5) ) / sY;
585 dvX = (oVect->
GetMatriceElt(0,0) - (ivX*sX - dX*sX/2 + sX*0.5) ) / sX;
596 Tlerp(ap_inputImage, ap_outputImage, v, iv, dvX, dvY, dvZ);
629 string a = a_cvt.substr(0, 1);
630 string b = a_cvt.substr(1, 1);
631 string c = a_cvt.substr(2, 1);
634 if (a ==
"X" || a ==
"x")
636 else if(a ==
"Y" || a ==
"y")
638 else if(a ==
"Z" || a ==
"z")
642 Cerr(
"*****iDeformationRigid::SetRotationMatrix()-> Symbol'"<< a <<
"' unknown for rotation convention! " << endl);
647 if (b ==
"X" || b ==
"x")
649 else if(b ==
"Y" || b ==
"y")
651 else if(b ==
"Z" || b ==
"z")
655 Cerr(
"*****iDeformationRigid::SetRotationMatrix()-> Symbol'"<< b <<
"' unknown for rotation convention! " << endl);
660 if (c ==
"X" || c ==
"x")
662 else if(c ==
"Y" || c ==
"y")
664 else if(c ==
"Z" || c ==
"z")
668 Cerr(
"*****iDeformationRigid::SetRotationMatrix()-> Symbol'"<< c <<
"' unknown for rotation convention! " << endl);
int ReadStringOption(const string &a_input, T *ap_return, int a_nbElts, const string &sep, const string &a_option)
Parse the 'a_input' string corresponding to the 'a_option' into 'a_nbElts' elements, using the 'sep' separator. The results are returned in the templated 'ap_return' dynamic templated array. Call "ConvertFromString()" to perform the correct conversion depending on the type of the data to convert.
FLTNB GetVoxSizeX()
Get the voxel's size along the X axis, in mm.
FLTNB GetVoxSizeZ()
Get the voxel's size along the Z axis, in mm.
FLTNB GetVoxSizeY()
Get the voxel's size along the Y axis, in mm.
INTNB GetNbVoxXY()
Get the number of voxels in a slice.
HPFLTNB GetMatriceElt(uint16_t l, uint16_t c)
#define KEYWORD_MANDATORY
INTNB GetNbVoxXYZ()
Get the total number of voxels.
Structure designed for basic matrices operations.
INTNB GetNbVoxX()
Get the number of voxels along the X axis.
int SetXRotMtx(HPFLTNB ang)
INTNB GetNbVoxZ()
Get the number of voxels along the Z axis.
int Multiplication(oMatrix *ap_Mtx, oMatrix *ap_MtxResult)
int ReadDataASCIIFile(const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter a...
int SetMatriceElt(uint16_t l, uint16_t c, HPFLTNB a_val)
int SetZRotMtx(HPFLTNB ang)
int SetYRotMtx(HPFLTNB ang)
INTNB GetNbVoxY()
Get the number of voxels along the Y axis.
#define KEYWORD_OPTIONAL_ERROR