]> Creatis software - clitk.git/blob - vv/vvToolRigidReg.cxx
Return 0.0 if libstatgrab is not used
[clitk.git] / vv / vvToolRigidReg.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18
19 // vv
20 #include "vvToolRigidReg.h"
21 #include "vvImageReader.h"
22 #include "vvSlicer.h"
23
24 // vtk
25 #include <vtkImageData.h>
26 #include <vtkSmartPointer.h>
27 #include <vtkTransform.h>
28
29 // clitk
30 #include "clitkTransformUtilities.h"
31 #include "clitkAffineRegistrationGenericFilter.h"       
32 // qt
33 #include <QMessageBox>
34 #include <QFileDialog>
35 #include <QTextStream>
36 #include <QComboBox>
37 #include <QCursor>
38
39
40 //------------------------------------------------------------------------------
41 // Create the tool and automagically (I like this word) insert it in
42 // the main window menu.
43 ADD_TOOL(vvToolRigidReg);
44 //------------------------------------------------------------------------------
45
46 //------------------------------------------------------------------------------
47 vvToolRigidReg::vvToolRigidReg(vvMainWindowBase * parent, Qt::WindowFlags f):
48     vvToolWidgetBase(parent, f),
49     vvToolBase<vvToolRigidReg>(parent),
50     Ui::vvToolRigidReg()
51 {
52   // GUI Initialization
53   Ui_vvToolRigidReg::setupUi(mToolWidget);
54    // QSize qsize;
55 //    qsize.setHeight(470);
56 //    qsize.setWidth(850);
57 //    mToolWidget->setFixedSize(qsize);
58   // Set how many inputs are needed for this tool
59   cb_transform->hide();
60   cb_interpolator->hide();
61   cb_optimizer->hide();
62   cb_metric->hide();
63   cb_selectoutput->hide();
64   cb_presets->hide();
65   translabel->hide();
66   metriclabel->hide();
67   outputlabel->hide();
68   optimlabel->hide();
69   interpollabel->hide();
70   presetlabel->hide();
71   
72   
73   // Set how many inputs are needed for this tool
74   AddInputSelector("Select moving image");
75   AddInputSelector("Select fixed image");
76 }
77 //------------------------------------------------------------------------------
78
79 //------------------------------------------------------------------------------
80 vvToolRigidReg::~vvToolRigidReg()
81 {
82 }
83 //------------------------------------------------------------------------------
84
85 //------------------------------------------------------------------------------
86 bool vvToolRigidReg::close()
87 {
88   ResetTransform();
89   RemoveOverlay();
90   return vvToolWidgetBase::close();
91 }
92 //------------------------------------------------------------------------------
93
94 //------------------------------------------------------------------------------
95 void vvToolRigidReg::reject()
96 {
97
98   return vvToolWidgetBase::reject();
99 }
100 //------------------------------------------------------------------------------
101
102 //------------------------------------------------------------------------------
103 void vvToolRigidReg::GetArgsInfoFromGUI()
104 {   
105   QFont font=QFont("Courier",10);
106   tab2textedit->setTextColor(QColor(255,0,0));
107   tab2textedit->setCurrentFont(font);
108   tab2textedit->update();
109    
110   QString file = QFileDialog::getOpenFileName(
111                     this,
112                     "Locate the Config File",
113                     mMainWindow->GetInputPathName(),
114                     "Text (*.conf *.txt *.rtf *.doc)");
115   
116   if (file.isEmpty())
117   return;
118   
119   QFile Qfile1(file);
120   mConfigFile= file.toStdString();
121   CmdlineParser(1, 1);//1,1 - override, initialize
122   cb_transform->setCurrentIndex(mArgsInfo.transform_arg);
123   cb_interpolator->setCurrentIndex(mArgsInfo.interp_arg);
124   cb_optimizer->setCurrentIndex(mArgsInfo.optimizer_arg);
125   cb_metric->setCurrentIndex(mArgsInfo.metric_arg);
126 }
127 //------------------------------------------------------------------------------
128
129 //------------------------------------------------------------------------------
130 void vvToolRigidReg::Presets()
131 {
132   mConfigFile="Presets";
133   std::string matrixfilename;
134 if(cb_presets->currentIndex()==0)
135 {
136     mArgsInfo.reference_arg=new char;   
137     mArgsInfo.reference_given=0;
138     mArgsInfo.target_arg=new char;       
139     mArgsInfo.target_given=0;
140     mArgsInfo.output_arg=new char;       
141     mArgsInfo.referenceMask_arg=new char;        
142     mArgsInfo.targetMask_arg=new char;   
143     mArgsInfo.initMatrix_arg=new char;   
144     mArgsInfo.matrix_arg=new char;
145     mArgsInfo.referenceMask_given=0;     
146     mArgsInfo.reference_given=0;         
147     mArgsInfo.reference_arg=new char;    
148     mArgsInfo.target_given=0;    
149     mArgsInfo.target_arg=new char;       
150     mArgsInfo.output_given=0;    
151     mArgsInfo.output_arg=new char;       
152     mArgsInfo.checker_after_given=0;     
153     mArgsInfo.checker_before_given=0;    
154     mArgsInfo.after_given=0;     
155     mArgsInfo.before_given=0;    
156     mArgsInfo.threads_given=1;   
157     mArgsInfo.threads_arg=3;     
158     mArgsInfo.normalize_flag=0;          
159     mArgsInfo.blur_arg=0.0;      
160     mArgsInfo.referenceMask_arg=new char;        
161     mArgsInfo.targetMask_arg=new char;   
162     mArgsInfo.targetMask_given=0;        
163     mArgsInfo.levels_given=1;    
164     mArgsInfo.levels_arg=2;      
165     mArgsInfo.moment_flag=1;     
166     mArgsInfo.intThreshold_given=0;      
167     mArgsInfo.intThreshold_arg=0.0;      
168     mArgsInfo.transX_arg=0.0;    
169     mArgsInfo.transY_arg=0.0;    
170     mArgsInfo.transZ_arg=0.0;    
171     mArgsInfo.transform_arg=2;   
172     mArgsInfo.gradient_flag=1;   
173     mArgsInfo.interp_given=1;    
174     mArgsInfo.interp_arg=1;      
175     mArgsInfo.interpOrder_given=1;       
176     mArgsInfo.interpOrder_arg=3;         
177     mArgsInfo.interpSF_given=1;          
178     mArgsInfo.interpSF_arg=20;//default          
179     mArgsInfo.metric_given=1;    
180     mArgsInfo.metric_arg=0;      
181     mArgsInfo.samples_arg=1;//default    
182     mArgsInfo.stdDev_arg=0.4;    
183     mArgsInfo.step_arg=2.0;      
184     mArgsInfo.relax_arg=0.7;     
185     mArgsInfo.valueTol_arg=0.01;         
186     mArgsInfo.stepTol_arg=0.1;   
187     mArgsInfo.gradTol_arg=1e-5;          
188     mArgsInfo.lineAcc_arg=0.9;   
189     mArgsInfo.convFactor_arg=1e+12;      
190     mArgsInfo.maxIt_arg=500;     
191     mArgsInfo.maxLineIt_arg=50;          
192     mArgsInfo.maxEval_arg=500;   
193     mArgsInfo.maxCorr_arg=5;     
194     mArgsInfo.selectBound_arg=0;         
195     mArgsInfo.inc_arg=1.2;       
196     mArgsInfo.dec_arg=4;         
197     mArgsInfo.optimizer_arg=1;   
198     mArgsInfo.initMatrix_given=0;        
199     mArgsInfo.initMatrix_arg=new char;   
200     mArgsInfo.tWeight_given=1;   
201     mArgsInfo.tWeight_arg=1.0;   
202     mArgsInfo.rWeight_given=1.0;         
203     mArgsInfo.rWeight_arg=50.0;          
204     mArgsInfo.matrix_given=1;
205     matrixfilename="/home/bharath/bin/writematrix.txt";//put ur path here for retreiving your matrix
206     mArgsInfo.matrix_arg=const_cast<char*>(matrixfilename.c_str()); 
207     UpdateTextEditor2();
208 }
209 else {
210   QMessageBox::information(this,"Sorry", "Other Presets are not available for the moment!");
211   return;
212  }
213 }
214 //------------------------------------------------------------------------------
215
216 //------------------------------------------------------------------------------
217 void vvToolRigidReg::UpdateTextEditor2()
218 {
219   
220     QString str1,str2,str3;
221     QColor color;
222     tab2textedit->clear();
223     tab2textedit->setAcceptRichText(true);
224     str2=tab2textedit->toPlainText();
225     tab2textedit->setTextColor(QColor(255,0,0));
226     str2.append(str3.append("threads="+str1.setNum(mArgsInfo.threads_arg)));
227     tab2textedit->setText(str2);
228     str3.clear();
229     str1.clear();
230
231     str2=tab2textedit->toPlainText();
232     str2.append("\n");
233     tab2textedit->setText(str2);
234
235     str2=tab2textedit->toPlainText();
236     str2.append(str3.append("reference="+str1.append(mArgsInfo.reference_arg)));
237     tab2textedit->setText(str2);
238     str3.clear();
239     str1.clear();
240
241     str2=tab2textedit->toPlainText();
242     str2.append("\n");
243     tab2textedit->setText(str2);
244     
245     str2=tab2textedit->toPlainText();
246     str2.append(str3.append("target="+str1.append(mArgsInfo.target_arg)));
247     tab2textedit->setText(str2);
248     str3.clear();
249     str1.clear();
250
251     str2=tab2textedit->toPlainText();
252     str2.append("\n");
253     tab2textedit->setText(str2);
254     
255     str2=tab2textedit->toPlainText();
256     str2.append(str3.append("matrix="+str1.append(mArgsInfo.matrix_arg)));
257     tab2textedit->setText(str2);
258     str3.clear();
259     str1.clear();
260
261     str2=tab2textedit->toPlainText();
262     str2.append("\n");
263     tab2textedit->setText(str2);
264     
265     str2=tab2textedit->toPlainText();
266     str2.append(str3.append("interp="+str1.setNum(mArgsInfo.interp_arg)));
267     tab2textedit->setText(str2);
268     str3.clear();
269     str1.clear();
270
271     str2=tab2textedit->toPlainText();
272     str2.append("\n");
273     tab2textedit->setText(str2);
274     
275     str2=tab2textedit->toPlainText();
276     str2.append(str3.append("transform="+str1.setNum(mArgsInfo.transform_arg)));
277     tab2textedit->setText(str2);
278     str3.clear();
279     str1.clear();
280
281     str2=tab2textedit->toPlainText();
282     str2.append("\n");
283     tab2textedit->setText(str2);
284     
285     str2=tab2textedit->toPlainText();
286     str2.append(str3.append("transX="+str1.setNum(mArgsInfo.transX_arg)));
287     tab2textedit->setText(str2);
288     str3.clear();
289     str1.clear();
290
291     str2=tab2textedit->toPlainText();
292     str2.append("\n");
293     tab2textedit->setText(str2);
294     
295     str2=tab2textedit->toPlainText();
296     str2.append(str3.append("transY="+str1.setNum(mArgsInfo.transY_arg)));
297     tab2textedit->setText(str2);
298     str3.clear();
299     str1.clear();
300
301     str2=tab2textedit->toPlainText();
302     str2.append("\n");
303     tab2textedit->setText(str2);
304     
305     str2=tab2textedit->toPlainText();
306     str2.append(str3.append("transZ="+str1.setNum(mArgsInfo.transZ_arg)));
307     tab2textedit->setText(str2);
308     str3.clear();
309     str1.clear();
310
311     str2=tab2textedit->toPlainText();
312     str2.append("\n");
313     tab2textedit->setText(str2);
314     
315     str2=tab2textedit->toPlainText();
316     str2.append(str3.append("metric="+str1.setNum(mArgsInfo.metric_arg)));
317     tab2textedit->setText(str2);
318     str3.clear();
319     str1.clear();
320
321     str2=tab2textedit->toPlainText();
322     str2.append("\n");
323     tab2textedit->setText(str2);
324     
325     str2=tab2textedit->toPlainText();
326     str2.append(str3.append("samples="+str1.setNum(mArgsInfo.samples_arg)));
327     tab2textedit->setText(str2);
328     str3.clear();
329     str1.clear();
330
331     str2=tab2textedit->toPlainText();
332     str2.append("\n");
333     tab2textedit->setText(str2);
334     
335     str2=tab2textedit->toPlainText();
336     str2.append(str3.append("intThreshold="+str1.setNum(mArgsInfo.intThreshold_arg)));
337     tab2textedit->setText(str2);
338     str3.clear();
339     str1.clear();
340
341     str2=tab2textedit->toPlainText();
342     str2.append("\n");
343     tab2textedit->setText(str2);
344     
345     str2=tab2textedit->toPlainText();
346     str2.append(str3.append("stdDev="+str1.setNum(mArgsInfo.stdDev_arg)));
347     tab2textedit->setText(str2);
348     str3.clear();
349     str1.clear();
350
351     str2=tab2textedit->toPlainText();
352     str2.append("\n");
353     tab2textedit->setText(str2);
354     
355     
356     str2=tab2textedit->toPlainText();
357     str2.append(str3.append("blur="+str1.setNum(mArgsInfo.blur_arg)));
358     tab2textedit->setText(str2);
359     str3.clear();
360     str1.clear();
361
362     str2=tab2textedit->toPlainText();
363     str2.append("\n");
364     tab2textedit->setText(str2);
365     
366     
367     str2=tab2textedit->toPlainText();
368     str2.append(str3.append("optimizer="+str1.setNum(mArgsInfo.optimizer_arg)));
369     tab2textedit->setText(str2);
370     str3.clear();
371     str1.clear();
372
373     str2=tab2textedit->toPlainText();
374     str2.append("\n");
375     tab2textedit->setText(str2);
376     
377     
378     str2=tab2textedit->toPlainText();
379     str2.append(str3.append("step="+str1.setNum(mArgsInfo.step_arg)));
380     tab2textedit->setText(str2);
381     str3.clear();
382     str1.clear();
383
384     str2=tab2textedit->toPlainText();
385     str2.append("\n");
386     tab2textedit->setText(str2);
387     
388     
389     str2=tab2textedit->toPlainText();
390     str2.append(str3.append("relax="+str1.setNum(mArgsInfo.relax_arg)));
391     tab2textedit->setText(str2);
392     str3.clear();
393     str1.clear();
394
395     str2=tab2textedit->toPlainText();
396     str2.append("\n");
397     tab2textedit->setText(str2);
398     
399     str2=tab2textedit->toPlainText();
400     str2.append(str3.append("valueTol="+str1.setNum(mArgsInfo.valueTol_arg)));
401     tab2textedit->setText(str2);
402     str3.clear();
403     str1.clear();
404     
405     str2=tab2textedit->toPlainText();
406     str2.append("\n");
407     tab2textedit->setText(str2);
408     
409     str2=tab2textedit->toPlainText();
410     str2.append(str3.append("stepTol="+str1.setNum(mArgsInfo.stepTol_arg)));
411     tab2textedit->setText(str2);
412     str3.clear();
413     str1.clear();
414
415     str2=tab2textedit->toPlainText();
416     str2.append("\n");
417     tab2textedit->setText(str2);
418     
419     
420     str2=tab2textedit->toPlainText();
421     str2.append(str3.append("gradTol="+str1.setNum(mArgsInfo.gradTol_arg)));
422     tab2textedit->setText(str2);
423     str3.clear();
424     str1.clear();
425
426     str2=tab2textedit->toPlainText();
427     str2.append("\n");
428     tab2textedit->setText(str2);
429     
430     str2=tab2textedit->toPlainText();
431     str2.append(str3.append("lineAcc="+str1.setNum(mArgsInfo.lineAcc_arg)));
432     tab2textedit->setText(str2);
433     str3.clear();
434     str1.clear();
435
436     str2=tab2textedit->toPlainText();
437     str2.append("\n");
438     tab2textedit->setText(str2);
439     str2=tab2textedit->toPlainText();
440     str2.append(str3.append("convFactor="+str1.setNum(mArgsInfo.convFactor_arg)));
441     tab2textedit->setText(str2);
442     str3.clear();
443     str1.clear();
444
445     str2=tab2textedit->toPlainText();
446     str2.append("\n");
447     tab2textedit->setText(str2);
448     
449     str2=tab2textedit->toPlainText();
450     str2.append(str3.append("maxIt="+str1.setNum(mArgsInfo.maxIt_arg)));
451     tab2textedit->setText(str2);
452     str3.clear();
453     str1.clear();
454  
455     str2=tab2textedit->toPlainText();
456     str2.append("\n");
457     tab2textedit->setText(str2);
458     
459     str2=tab2textedit->toPlainText();
460     str2.append(str3.append("maxLineIt="+str1.setNum(mArgsInfo.maxLineIt_arg)));
461     tab2textedit->setText(str2);
462     str3.clear();
463     str1.clear();
464
465     str2=tab2textedit->toPlainText();
466     str2.append("\n");
467     tab2textedit->setText(str2);
468     
469     str2=tab2textedit->toPlainText();
470     str2.append(str3.append("maxEval="+str1.setNum(mArgsInfo.maxEval_arg)));
471     tab2textedit->setText(str2);
472     str3.clear();
473     str1.clear();
474
475     str2=tab2textedit->toPlainText();
476     str2.append("\n");
477     tab2textedit->setText(str2);
478     
479       str2=tab2textedit->toPlainText();
480     str2.append(str3.append("maxCorr="+str1.setNum(mArgsInfo.maxCorr_arg)));
481     tab2textedit->setText(str2);
482     str3.clear();
483     str1.clear();
484
485     str2=tab2textedit->toPlainText();
486     str2.append("\n");
487     tab2textedit->setText(str2);
488     
489       str2=tab2textedit->toPlainText();
490     str2.append(str3.append("selectBound="+str1.setNum(mArgsInfo.selectBound_arg)));
491     tab2textedit->setText(str2);
492     str3.clear();
493     str1.clear();
494
495     str2=tab2textedit->toPlainText();
496     str2.append("\n");
497     tab2textedit->setText(str2);
498     
499       str2=tab2textedit->toPlainText();
500     str2.append(str3.append("rWeight="+str1.setNum(mArgsInfo.rWeight_arg)));
501     tab2textedit->setText(str2);
502     str3.clear();
503     str1.clear();
504
505     str2=tab2textedit->toPlainText();
506     str2.append("\n");
507     tab2textedit->setText(str2);
508     
509       str2=tab2textedit->toPlainText();
510     str2.append(str3.append("tWeight="+str1.setNum(mArgsInfo.tWeight_arg)));
511     tab2textedit->setText(str2);
512     str3.clear();
513     str1.clear();
514
515     str2=tab2textedit->toPlainText();
516     str2.append("\n");
517     tab2textedit->setText(str2);
518     
519       str2=tab2textedit->toPlainText();
520     str2.append(str3.append("levels="+str1.setNum(mArgsInfo.levels_arg)));
521     tab2textedit->setText(str2);
522     str3.clear();
523     str1.clear();
524
525     str2=tab2textedit->toPlainText();
526     str2.append("\n");
527     tab2textedit->setText(str2);
528     
529       str2=tab2textedit->toPlainText();
530     str2.append(str3.append("inc="+str1.setNum(mArgsInfo.inc_arg)));
531     tab2textedit->setText(str2);
532     str3.clear();
533     str1.clear();
534
535     str2=tab2textedit->toPlainText();
536     str2.append("\n");
537     tab2textedit->setText(str2);
538     
539       str2=tab2textedit->toPlainText();
540     str2.append(str3.append("dec="+str1.setNum(mArgsInfo.dec_arg)));
541     tab2textedit->setText(str2);
542     str3.clear();
543     str1.clear();
544
545     str2=tab2textedit->toPlainText();
546     str2.append("\n");
547     tab2textedit->setText(str2);
548 }
549 //------------------------------------------------------------------------------
550
551 //------------------------------------------------------------------------------
552 void vvToolRigidReg::TransformSelect()
553 {
554   if(!mConfigFile.empty()){
555    mArgsInfo.transform_arg=cb_transform->currentIndex();
556    UpdateTextEditor2();
557   }
558   else{
559     QMessageBox::information(this,"Warning","Load the Config File First!..");
560   }
561 }
562 //------------------------------------------------------------------------------
563   
564 //------------------------------------------------------------------------------
565 void vvToolRigidReg::CmdlineParser(int override, int initialize)
566 {
567    //0 opened, 1 not opened fine
568    int opened=cmdline_parser_clitkAffineRegistration_configfile(const_cast<char*>(mConfigFile.c_str()),&mArgsInfo,override,initialize,1);
569    DD(opened);
570    mArgsInfo.gradient_flag=1;
571    QString str;
572    //Read the transformation parameters from the  path in the config file(mArgsInfo.matrix_arg) and display it on the TextBox 2
573    ifstream readfile;
574    std::vector<QString> Qstr;
575    
576    if(!opened){
577    readfile.open(mConfigFile.c_str());
578    }
579    else{
580    QMessageBox::information(this,"Warning","Load the Config File First..");
581    }
582    if (readfile.is_open()) 
583    { 
584     while (!readfile.eof())
585       {
586       readfile >> mConfigFile;
587       Qstr.push_back(QString(mConfigFile.c_str()));
588       }
589       readfile.close();
590    }
591     else {
592       QMessageBox::information(this,"Warning","Cannot Open File!");
593       return;
594     }
595      for(unsigned int i=0;i<Qstr.size()-1;i++)
596       {
597     str=tab2textedit->toPlainText();
598     str.append(Qstr.at(i));
599     tab2textedit->setText(str);
600     str.append("\n");
601     tab2textedit->setText(str);
602       }
603 }
604 //------------------------------------------------------------------------------
605
606 //------------------------------------------------------------------------------
607 void vvToolRigidReg::OptimizerSelect()
608 {
609   if(!mConfigFile.empty()){
610   mArgsInfo.optimizer_arg=cb_optimizer->currentIndex();
611   UpdateTextEditor2();
612    }
613   else{
614     QMessageBox::information(this,"Warning","Load the Config File First!..");
615   }
616 }
617 //------------------------------------------------------------------------------
618
619 //------------------------------------------------------------------------------
620 void vvToolRigidReg::InterpolatorSelect()
621 {
622   if(!mConfigFile.empty()){
623   mArgsInfo.interp_arg=cb_interpolator->currentIndex();
624   UpdateTextEditor2();
625    }
626   else{
627     QMessageBox::information(this,"Warning","Load the Config File First!..");
628   }
629 }
630 //------------------------------------------------------------------------------
631
632 //------------------------------------------------------------------------------
633 void vvToolRigidReg::MetricSelect()
634 {
635   if(!mConfigFile.empty()){
636  mArgsInfo.metric_arg=cb_metric->currentIndex();
637  UpdateTextEditor2();
638    }
639   else{
640     QMessageBox::information(this,"Warning","Load the Config File First!..");
641   }
642 }
643 //------------------------------------------------------------------------------
644
645 //------------------------------------------------------------------------------
646 void vvToolRigidReg::OutputSelect()
647 {
648   std::ostringstream osstream;
649   if(!mConfigFile.empty()){
650     if(cb_selectoutput->currentIndex()==0){
651       mArgsInfo.output_given=0;
652       mArgsInfo.checker_after_given=0;
653       mArgsInfo.checker_before_given=0;
654       mArgsInfo.after_given=0;
655       mArgsInfo.before_given=0;
656     }//get transformed output image
657     if(cb_selectoutput->currentIndex()==1){ 
658       mArgsInfo.output_given=0;
659       mArgsInfo.checker_after_given=1;
660       mArgsInfo.checker_before_given=0;
661       mArgsInfo.after_given=0;
662       mArgsInfo.before_given=0;
663     }//get checkered image after reg
664     if(cb_selectoutput->currentIndex()==2){  
665       mArgsInfo.output_given=0;
666       mArgsInfo.checker_after_given=0;
667       mArgsInfo.checker_before_given=1;
668       mArgsInfo.after_given=0;
669       mArgsInfo.before_given=0;
670     }//get checkered  image before reg
671     if(cb_selectoutput->currentIndex()==3){
672       mArgsInfo.output_given=0;
673       mArgsInfo.checker_after_given=0;
674       mArgsInfo.checker_before_given=0;
675       mArgsInfo.after_given=1;
676       mArgsInfo.before_given=0;
677     }//get difference image after reg
678     if(cb_selectoutput->currentIndex()==4){  
679       mArgsInfo.output_given=0;
680       mArgsInfo.checker_after_given=0;
681       mArgsInfo.checker_before_given=0;
682       mArgsInfo.after_given=0;
683       mArgsInfo.before_given=1;
684     }//get difference image before reg
685   }
686   else{
687     QMessageBox::information(this,"Warning","Load the Config File First!..");
688   }
689 }
690 //------------------------------------------------------------------------------
691
692 //------------------------------------------------------------------------------
693 void vvToolRigidReg::SaveTextEdit()
694 {
695      DD(mArgsInfo.transform_arg);
696    QString f1 = QFileDialog::getSaveFileName(this, tr("Save Config File"),
697                                               mMainWindow->GetInputPathName(),
698                                               tr("Text (*.mat *.txt *.doc *.rtf)"));
699    QFile file(f1);                                    
700    if(file.open(QFile::WriteOnly | QFile::Truncate) & !mConfigFile.empty() ){
701    QTextStream stream( &file );
702    stream << tab2textedit->toPlainText();
703      }
704     else
705      {
706       QMessageBox::information(this,"Warning","Nothing to Save!");
707       return;
708      }
709    tab2textedit->clear();
710    DD(mArgsInfo.transform_arg);
711 }
712 //------------------------------------------------------------------------------
713
714 //------------------------------------------------------------------------------
715 void vvToolRigidReg::InputIsSelected(std::vector<vvSlicerManager *> & l)
716 {
717   //inputs
718   mInput1 = l[0];
719   mInput2 = l[1];
720   UpdateTextEditor(mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix(),textEdit_2);
721
722   for(int i =0;i<4;i++)
723   {
724     for(int j=0;j<4;j++)
725     {
726       mInitialMatrix[i*4+j]=mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()->GetElement(i,j);
727     }
728   }
729
730   if(mInput1->GetFileName()==mInput2->GetFileName())
731   {
732     QMessageBox::information(this, "Warning","Your Reference and Target Images are the same");
733   }
734   mTwoInputs = true;
735   SetOverlay(mInput2->GetImage());
736   mImageSize=mInput1->GetImage()->GetSize();
737   SetRotationCenter();
738   SetSliderRanges();
739
740     //connect all sigs to slots
741    connect(resetbutton, SIGNAL(pressed()), this, SLOT(ResetTransform()));
742    connect(tab2loadbutton, SIGNAL(pressed()), this, SLOT(GetArgsInfoFromGUI()));
743    connect(tab2applybutton, SIGNAL(pressed()), this, SLOT(AutoRegister()));
744
745
746    connect(Xval, SIGNAL(editingFinished()), this, SLOT(SetXvalue()));
747    connect(Yval, SIGNAL(editingFinished()), this, SLOT(SetYvalue()));
748    connect(Zval, SIGNAL(editingFinished()), this, SLOT(SetZvalue()));
749
750    connect(xtrans_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateTransform_sliders()));
751    connect(ytrans_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateTransform_sliders()));
752    connect(ztrans_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateTransform_sliders()));
753
754
755    connect(xrot_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateTransform_sliders()));
756    connect(yrot_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateTransform_sliders()));
757    connect(zrot_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateTransform_sliders()));
758
759    connect(xtrans_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
760    connect(ytrans_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
761    connect(ztrans_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
762    connect(xrot_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
763    connect(yrot_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
764    connect(zrot_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
765    
766    connect(loadbutton, SIGNAL(pressed()), this, SLOT(LoadFile()));
767    connect(savebutton, SIGNAL(pressed()), this, SLOT(SaveFile()));
768    
769    connect(checkBox_rigid, SIGNAL(clicked(bool)), this, SLOT(CheckRigidReg()));
770    connect(checkBox_deformable, SIGNAL(clicked(bool)), this, SLOT(CheckDeformableReg()));
771    
772    connect(cb_presets, SIGNAL(activated(int)), this, SLOT(Presets()));
773    connect(cb_transform, SIGNAL(activated(int)), this, SLOT(TransformSelect()));
774    connect(cb_optimizer, SIGNAL(activated(int)), this, SLOT(OptimizerSelect()));
775    connect(cb_interpolator, SIGNAL(activated(int)), this, SLOT(InterpolatorSelect()));
776    connect(cb_metric, SIGNAL(activated(int)), this, SLOT(MetricSelect()));
777    connect(cb_selectoutput, SIGNAL(activated(int)), this, SLOT(OutputSelect()));
778    connect(tab2savebutton, SIGNAL(pressed()), this, SLOT(SaveTextEdit()));
779    
780 }
781 //------------------------------------------------------------------------------
782
783 //------------------------------------------------------------------------------
784 void vvToolRigidReg::apply()
785 {
786   RemoveOverlay();
787 }
788 //------------------------------------------------------------------------------
789
790 //------------------------------------------------------------------------------
791 void vvToolRigidReg::CheckRigidReg()
792 {
793   checkBox_deformable->setChecked(false);
794   cb_transform->show();
795   cb_presets->show();
796   cb_metric->show();
797   cb_interpolator->show();
798   cb_optimizer->show();
799   cb_selectoutput->show();
800   translabel->show();
801   metriclabel->show();
802   outputlabel->show();
803   optimlabel->show();
804   interpollabel->show();
805   presetlabel->show();
806   
807 }
808 //------------------------------------------------------------------------------
809
810 //------------------------------------------------------------------------------
811 void vvToolRigidReg::CheckDeformableReg()
812 {
813   checkBox_rigid->setChecked(false);
814   presetlabel->hide();
815   cb_transform->show();
816   cb_metric->show();
817   cb_interpolator->show();
818   cb_optimizer->show();
819   cb_selectoutput->show();
820   cb_presets->hide();
821   translabel->show();
822   metriclabel->show();
823   outputlabel->show();
824   optimlabel->show();
825   interpollabel->show();
826 }
827 //------------------------------------------------------------------------------
828
829 //------------------------------------------------------------------------------
830 void vvToolRigidReg::SetOverlay(vvImage::Pointer Image)
831 {
832     for (int i =0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
833    mCurrentSlicerManager->GetSlicer(i)->SetOverlay(Image);
834    mCurrentSlicerManager->GetSlicer(i)->SetActorVisibility("overlay",0,true);
835    mCurrentSlicerManager->SetColorMap();
836    mCurrentSlicerManager->Render();
837    }
838   }
839 //------------------------------------------------------------------------------
840
841 //------------------------------------------------------------------------------
842 void vvToolRigidReg::RemoveOverlay()
843 {
844    for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers();i++)
845   {
846      mInput1->RemoveActor("overlay",0);
847      mInput1->SetColorMap(0);
848      mInput1->Render();
849      hide();
850   }
851 }
852 //------------------------------------------------------------------------------
853
854 //------------------------------------------------------------------------------
855 void vvToolRigidReg::SetXvalue()
856 {
857   QString xstr = Xval->text();
858 }
859 //------------------------------------------------------------------------------
860
861 //------------------------------------------------------------------------------
862 void vvToolRigidReg::SetYvalue()
863 {
864   QString ystr = Yval->text();
865 }
866 //------------------------------------------------------------------------------
867
868 //------------------------------------------------------------------------------
869 void vvToolRigidReg::SetZvalue()
870 {
871   QString zstr = Zval->text();
872 }
873 //------------------------------------------------------------------------------
874
875 //------------------------------------------------------------------------------
876 void vvToolRigidReg::SetTransform(double tX, double tY, double tZ, double aX, double aY, double aZ,bool update)
877 {
878   vtkSmartPointer<vtkTransform> transform = mInput1->GetImage()->GetTransform();
879   transform->PostMultiply();
880   //Rotations
881   if (aX!=0 || aY!=0 || aZ!=0) {
882     double x, y ,z;
883     x= Xval->text().toDouble();
884     y= Yval->text().toDouble();
885     z= Zval->text().toDouble();
886     transform->Translate(-x,-y,-z);
887     if (aX!=0) transform->RotateX(aX);
888     if (aY!=0) transform->RotateY(aY);
889     if (aZ!=0) transform->RotateZ(aZ);
890     transform->Translate(x,y,z);
891   }
892   //Translations
893   if (tX!=0||tY!=0||tZ!=0)
894     transform->Translate(tX*mInput1->GetImage()->GetSpacing()[0],
895                          tY*mInput1->GetImage()->GetSpacing()[1],
896                          tZ*mInput1->GetImage()->GetSpacing()[2]);
897 }
898 //------------------------------------------------------------------------------
899
900 //------------------------------------------------------------------------------
901 void vvToolRigidReg::SetTransform(vtkMatrix4x4 *matrix)
902 {
903    vtkSmartPointer<vtkTransform> transform=vtkSmartPointer<vtkTransform>::New();
904     for(int i=0; i<4;i++)
905       for(int j=0;j<4;j++)
906     mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()->SetElement(i,j,matrix->GetElement(i,j));
907     
908     Render();
909 }
910 //------------------------------------------------------------------------------
911
912 //------------------------------------------------------------------------------
913 void vvToolRigidReg::LoadFile()
914 {
915   ReadFile(false);
916 }
917 //------------------------------------------------------------------------------
918   
919 //------------------------------------------------------------------------------
920 void vvToolRigidReg::Render()
921 {
922   for (int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
923        mCurrentSlicerManager->GetSlicer(i)->ForceUpdateDisplayExtent();
924        mCurrentSlicerManager->GetSlicer(i)->Render();
925       }
926 }
927 //------------------------------------------------------------------------------
928
929 //------------------------------------------------------------------------------
930   void vvToolRigidReg::UpdateTextEditor(vtkMatrix4x4 *matrix,QTextEdit* textEdit)
931 {
932     QFont font=QFont("Courier",11);
933     textEdit->setCurrentFont(font);
934     textEdit->update();
935
936     QString str1,str2,str3;
937     QColor color;
938     textEdit->clear();
939     textEdit->setAcceptRichText(true);
940     str2=textEdit->toPlainText();
941     str2.append("#Rotation Center(mm): \n#");
942     textEdit->setText(str2);
943
944     str2=textEdit->toPlainText();
945     textEdit->setTextColor(QColor(255,0,0));
946     str2.append(str3.append(Xval->text()));
947     textEdit->setText(str2);
948     str3.clear();
949
950     str2=textEdit->toPlainText();
951     str2.append("\t");
952     textEdit->setText(str2);
953
954     str2=textEdit->toPlainText();
955     str2.append(str3.append(Yval->text()));
956     textEdit->setText(str2);
957     str3.clear();
958
959     str2=textEdit->toPlainText();
960     str2.append("\t");
961     textEdit->setText(str2);
962
963
964     str2=textEdit->toPlainText();
965     str2.append(str3.append(Zval->text()));
966     textEdit->setText(str2);
967
968
969     str2=textEdit->toPlainText();
970     str2.append("\n");
971     textEdit->setText(str2);
972
973
974     str2=textEdit->toPlainText();
975     str2.append("#Transformation Matrix(mm):\n");
976     textEdit->setText(str2);
977     for(int i=0;i<4;i++)
978     {
979     for(int j=0;j<4;j++)
980       {
981     str2=textEdit->toPlainText();
982    // str2.append("\t"+str1.setNum(matrix->Element[i][j]));
983     str2.append(QString("%1\t").arg(str1.setNum(matrix->Element[i][j]),2));
984     textEdit->setText(str2);
985       }
986     str2=textEdit->toPlainText();
987     str2.append("\n");
988     textEdit->setText(str2);
989     }
990     //QString str = QFileDialog::getOpenFileName();
991     textEdit->setTextColor(QColor(255,0,0));
992     textEdit->setFont(QFont("courrier new",12,4,true));
993     textEdit->toPlainText().toAscii();
994
995     str2=textEdit->toPlainText();
996     textEdit->setText(str2);
997 }
998 //------------------------------------------------------------------------------
999
1000 //------------------------------------------------------------------------------
1001 void vvToolRigidReg::UpdateTransform_sliders()
1002 {
1003        InitializeSliders(xtrans_slider->value()*mInput1->GetImage()->GetSpacing()[0],
1004                          ytrans_slider->value()*mInput1->GetImage()->GetSpacing()[1],
1005                          ztrans_slider->value()*mInput1->GetImage()->GetSpacing()[2],
1006                         xrot_slider->value(),yrot_slider->value(),zrot_slider->value(),false);
1007         UpdateTransform(true);
1008         Render();
1009 }
1010 //------------------------------------------------------------------------------
1011
1012 //------------------------------------------------------------------------------
1013 void vvToolRigidReg::UpdateTransform_sb()
1014 {
1015    InitializeSliders(xtrans_sb->value(),
1016       ytrans_sb->value(),
1017       ztrans_sb->value(),
1018                         xrot_sb->value(),yrot_sb->value(),zrot_sb->value(),false);
1019       UpdateTransform(false);
1020       Render();
1021 }
1022 //------------------------------------------------------------------------------
1023
1024 //------------------------------------------------------------------------------
1025 void vvToolRigidReg::AutoRegister()
1026
1027     if (!mCurrentSlicerManager) close();
1028     
1029     if(!mConfigFile.empty()){
1030     std::vector<vvImage::Pointer> inputs;
1031     // Input
1032     inputs.push_back(mInput1->GetImage());
1033     inputs.push_back(mInput2->GetImage());
1034     // Check input type
1035     // Main filter
1036     clitk::AffineRegistrationGenericFilter::Pointer filter =
1037     clitk::AffineRegistrationGenericFilter::New();
1038     filter->SetInputVVImages(inputs);
1039     filter->SetArgsInfo(mArgsInfo);
1040     filter->EnableReadOnDisk(false);
1041     filter->Update();
1042     std::ostringstream osstream;
1043     vvImage::Pointer output;
1044     output = filter->GetOutputVVImage();
1045     SetOverlay(output);
1046     
1047     if(!cb_selectoutput->currentIndex()==0){
1048      std::string outputstring;
1049      output = filter->GetOutputVVImages()[1];
1050      if(cb_selectoutput->currentIndex()==1){outputstring="Checkered_after_reg";}
1051      if(cb_selectoutput->currentIndex()==2){outputstring="Checkered_before_reg";}
1052      if(cb_selectoutput->currentIndex()==3){outputstring="Diff_after_reg";}
1053      if(cb_selectoutput->currentIndex()==4){outputstring="Diff_before_reg";}
1054     osstream << outputstring << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
1055     AddImage(output,osstream.str());
1056     filter->DeleteLastOutputImage();
1057     }
1058     DD(filter->GetOutputVVImages().capacity());
1059     QApplication::restoreOverrideCursor();
1060     ReadFile(true);
1061     }
1062     else
1063     {
1064       QMessageBox::information(this, "Warning","Load the Config File First!...");
1065       return;
1066     }
1067 }
1068 //------------------------------------------------------------------------------
1069
1070 //------------------------------------------------------------------------------
1071 void vvToolRigidReg::UpdateTransform(bool slider_enabled)
1072 {
1073      vtkSmartPointer<vtkTransform> transform_final=mInput1->GetImage()->GetTransform();
1074      transform_final->SetMatrix(mInitialMatrix);
1075      transform_final->PostMultiply();
1076   //Rotations
1077     double x=0, y=0 ,z=0;
1078     x= Xval->text().toDouble();
1079     y= Yval->text().toDouble();
1080     z= Zval->text().toDouble();
1081     transform_final->Translate(-x,-y,-z);
1082     if(slider_enabled){
1083     transform_final->RotateY(yrot_slider->value());
1084     transform_final->RotateX(xrot_slider->value());
1085     transform_final->RotateZ(zrot_slider->value());
1086     }
1087     else{
1088     transform_final->RotateY(yrot_sb->value());
1089     transform_final->RotateX(xrot_sb->value());
1090     transform_final->RotateZ(zrot_sb->value());
1091     }
1092     transform_final->Translate(x,y,z);
1093     transform_final->PreMultiply();
1094     if(slider_enabled){
1095     transform_final->Translate(xtrans_slider->value()*mInput1->GetImage()->GetSpacing()[0],0,0);
1096     transform_final->Translate(0,ytrans_slider->value()*mInput1->GetImage()->GetSpacing()[1],0);
1097     transform_final->Translate(0,0,ztrans_slider->value()*mInput1->GetImage()->GetSpacing()[2]);
1098     }
1099     else{
1100     transform_final->Translate(xtrans_sb->value(),0,0);
1101     transform_final->Translate(0,ytrans_sb->value(),0);
1102     transform_final->Translate(0,0,ztrans_sb->value());
1103     }
1104     transform_final->Update();
1105     Render();
1106     UpdateTextEditor(transform_final->GetMatrix(),textEdit);
1107 }
1108 //------------------------------------------------------------------------------
1109
1110
1111 //------------------------------------------------------------------------------
1112 void vvToolRigidReg::SaveFile()
1113 {
1114   //Write the Transformation Matrix
1115     QString f1 = QFileDialog::getSaveFileName(this, tr("Save Transformation Matrix File"),
1116                                               mMainWindow->GetInputPathName(),
1117                                               tr("Text (*.mat *.txt *.doc *.rtf)"));
1118     QFile file1(f1);
1119     std::vector<QString> transparameters;
1120     QString line1;
1121
1122     for(int i =0;i<4;i++)
1123       for(int j=0;j<4;j++)
1124     transparameters.push_back(line1.setNum(mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()->Element[i][j]));
1125
1126     if (file1.open(QFile::WriteOnly | QFile::Truncate)) {
1127     QTextStream out1(&file1);
1128      for(int i =0;i<4;i++){
1129       for(int j=0;j<4;j++) {
1130       out1<<transparameters[i*4+j]+"\t";
1131       }
1132       out1<<"\n";
1133      }
1134     }
1135      else
1136      {
1137       QMessageBox::information(this,"Warning","Error Reading Parameters");
1138      }
1139 }
1140 //------------------------------------------------------------------------------
1141
1142 //------------------------------------------------------------------------------
1143 void vvToolRigidReg::ReadFile(bool matrix_given)
1144 {
1145    std::string x;
1146    QString center;
1147    double * orientations=new double[3];
1148    double * translations=new double[3];
1149    vtkMatrix4x4 *matrix=vtkMatrix4x4::New();
1150    std::string transfile;
1151    vtkSmartPointer<vtkTransform> transform = mCurrentSlicerManager->GetImage()->GetTransform();
1152    if(!matrix_given)
1153    {
1154    //Open File to read the transformation parameters
1155    QString file1 = QFileDialog::getOpenFileName(
1156                     this,
1157                     "Choose the Transformation Parameters file",
1158                     mMainWindow->GetInputPathName(),
1159                     "Text (*.mat *.txt *.rtf *.doc)");
1160     if (file1.isEmpty())
1161     return;
1162    QFile Qfile1(file1);
1163   // ifstream readfile;
1164    transfile= file1.toStdString();
1165    }
1166    else
1167    {
1168     transfile=mArgsInfo.matrix_arg;
1169     DD(transfile);
1170    }
1171    std::string filename1(transfile);
1172    std::ifstream f1(filename1.c_str());
1173    if(f1.is_open())
1174    {
1175    f1.close();
1176    itk::Matrix<double, 4, 4> itkMat = clitk::ReadMatrix3D(transfile);
1177    for(int j=0; j<4; j++)
1178       for(int i=0; i<4; i++)
1179     matrix->SetElement(i,j,rint(itkMat[i][j]));
1180    }
1181     UpdateTextEditor(matrix,textEdit);
1182     transform->SetMatrix(matrix);
1183     transform->GetOrientation(orientations);
1184     transform->PostMultiply();
1185
1186      //Obtain the Rotation Center , set it to origin
1187     Xval->setText(center.setNum(0));
1188     Yval->setText(center.setNum(0));
1189     Zval->setText(center.setNum(0));
1190
1191     //In the Order or Y X Z //
1192     //now  postmultiply for the rotations
1193     SetTransform(0,0,0,0,0,-rint(orientations[2]),false);
1194     SetTransform(0,0,0,-rint(orientations[0]),0,0,false);
1195     SetTransform(0,0,0,0,-rint(orientations[1]),0,false);
1196
1197     transform->GetPosition(translations);
1198     transform->Identity();
1199
1200     DD(translations[0]/mInput1->GetImage()->GetSpacing()[0]);
1201     DD(translations[1]/mInput1->GetImage()->GetSpacing()[1]);
1202     DD(translations[2]/mInput1->GetImage()->GetSpacing()[2]);
1203     DD(mInput1->GetImage()->GetSpacing()[0]);
1204     DD(mInput1->GetImage()->GetSpacing()[1]);
1205     DD(mInput1->GetImage()->GetSpacing()[2]);
1206     DD(orientations[0]);
1207     DD(orientations[1]);
1208     DD(orientations[2]);
1209       //set the sliders  and spin box values
1210     InitializeSliders(rint(translations[0]),rint(translations[1])
1211     ,rint(translations[2]),rint(orientations[0]),rint(orientations[1]),rint(orientations[2]),true);
1212     SetTransform(matrix);
1213 }
1214 //------------------------------------------------------------------------------
1215
1216 //------------------------------------------------------------------------------
1217 void vvToolRigidReg::ResetTransform()
1218 {
1219   vtkSmartPointer<vtkTransform> transform = mCurrentSlicerManager->GetImage()->GetTransform();
1220   transform->SetMatrix(mInitialMatrix);
1221   transform->Update();
1222   
1223    Render();
1224    SetRotationCenter();
1225    SetSliderRanges();
1226    UpdateTextEditor(transform->GetMatrix(),textEdit);
1227 }
1228 //------------------------------------------------------------------------------
1229
1230 //------------------------------------------------------------------------------
1231 void vvToolRigidReg::SetRotationCenter()
1232 {
1233     //default image rotation center is the center of the image
1234     QString xcord,ycord,zcord;
1235     std::vector<double> imageorigin;
1236     imageorigin=mInput1->GetImage()->GetOrigin();
1237     DD("before bug");
1238     xcord=xcord.setNum(imageorigin[0]+mImageSize[0]*mInput1->GetImage()->GetSpacing()[0]/2, 'g', 3);
1239     ycord=ycord.setNum(imageorigin[1]+mImageSize[1]*mInput1->GetImage()->GetSpacing()[1]/2, 'g', 3);
1240     zcord=zcord.setNum(imageorigin[2]+mImageSize[2]*mInput1->GetImage()->GetSpacing()[2]/2, 'g', 3);
1241
1242     Xval->setText(xcord);
1243     Yval->setText(ycord);
1244     Zval->setText(zcord);
1245     InitializeSliders(0,0,0,0,0,0,true);
1246 }
1247 //------------------------------------------------------------------------------
1248
1249 //------------------------------------------------------------------------------
1250 void vvToolRigidReg::InitializeSliders(double xtrans,double ytrans, double ztrans, double xrot, double yrot, double zrot,bool sliders)
1251 {
1252
1253     xtrans_sb->blockSignals(true);
1254     xtrans_sb->setSingleStep(mInput1->GetImage()->GetSpacing()[0]);
1255     xtrans_sb->setValue(xtrans);
1256     xtrans_sb->blockSignals(false);
1257     ytrans_sb->blockSignals(true);
1258     ytrans_sb->setSingleStep(mInput1->GetImage()->GetSpacing()[1]);
1259     ytrans_sb->setValue(ytrans);
1260     ytrans_sb->blockSignals(false);
1261     ztrans_sb->blockSignals(true);
1262     ztrans_sb->setSingleStep(mInput1->GetImage()->GetSpacing()[2]);
1263     ztrans_sb->setValue(ztrans);
1264     ztrans_sb->blockSignals(false);
1265
1266     if(sliders){
1267     xtrans_slider->blockSignals(true);
1268     xtrans_slider->setValue(rint(xtrans/mInput1->GetImage()->GetSpacing()[0]));
1269     xtrans_slider->blockSignals(false);
1270     ytrans_slider->blockSignals(true);
1271     ytrans_slider->setValue(rint(ytrans/mInput1->GetImage()->GetSpacing()[1]));
1272     ytrans_slider->blockSignals(false);
1273     ztrans_slider->blockSignals(true);
1274     ztrans_slider->setValue(rint(ztrans/mInput1->GetImage()->GetSpacing()[2]));
1275     ztrans_slider->blockSignals(false);
1276     }
1277     xrot_sb->blockSignals(true);
1278     xrot_sb->setValue(xrot);                                                                    
1279     xrot_sb->blockSignals(false);
1280     yrot_sb->blockSignals(true);
1281     yrot_sb->setValue(yrot);
1282     yrot_sb->blockSignals(false);
1283     zrot_sb->blockSignals(true);
1284     zrot_sb->setValue(zrot);
1285     zrot_sb->blockSignals(false);
1286     xrot_slider->blockSignals(true);
1287     xrot_slider->setValue(xrot);
1288     xrot_slider->blockSignals(false);
1289     yrot_slider->blockSignals(true);
1290     yrot_slider->setValue(yrot);
1291     yrot_slider->blockSignals(false);
1292     zrot_slider->blockSignals(true);
1293     zrot_slider->setValue(zrot);
1294     zrot_slider->blockSignals(false);
1295 }
1296 //------------------------------------------------------------------------------
1297
1298 //------------------------------------------------------------------------------
1299 void vvToolRigidReg::SetSliderRanges()
1300 {
1301   xtrans_slider->blockSignals(true);
1302   xtrans_slider->setRange(-2000,2000);
1303   xtrans_slider->blockSignals(false);
1304
1305   ytrans_slider->blockSignals(true);
1306   ytrans_slider->setRange(-2000,2000);
1307   ytrans_slider->blockSignals(false);
1308
1309   ztrans_slider->blockSignals(true);
1310   ztrans_slider->setRange(-2000,2000);
1311   ztrans_slider->blockSignals(false);
1312
1313   xtrans_sb->blockSignals(true);
1314   xtrans_sb->setRange(-2000,2000);
1315   xtrans_sb->setDecimals(3);
1316   xtrans_sb->blockSignals(false);
1317
1318   ytrans_sb->blockSignals(true);
1319   ytrans_sb->setRange(-2000,2000);
1320   ytrans_sb->setDecimals(3);
1321   ytrans_sb->blockSignals(false);
1322
1323   ztrans_sb->blockSignals(true);
1324   ztrans_sb->setRange(-2000,2000);
1325   ztrans_sb->setDecimals(3);
1326   ztrans_sb->blockSignals(false);
1327
1328   xrot_slider->blockSignals(true);
1329   xrot_slider->setRange(-360,360);
1330   xrot_slider->blockSignals(false);
1331
1332   yrot_slider->blockSignals(true);
1333   yrot_slider->setRange(-360,360);
1334   yrot_slider->blockSignals(false);
1335
1336   zrot_slider->blockSignals(true);
1337   zrot_slider->setRange(-360,360);
1338   zrot_slider->blockSignals(false);
1339
1340   xrot_sb->blockSignals(true);
1341   xrot_sb->setRange(-360,360);
1342   xrot_sb->blockSignals(false);
1343
1344   yrot_sb->blockSignals(true);
1345   yrot_sb->setRange(-360,360);
1346   yrot_sb->blockSignals(false);
1347
1348   zrot_sb->blockSignals(true);
1349   zrot_sb->setRange(-360,360);
1350   zrot_sb->blockSignals(false);
1351 }