]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/wxMaracasEmptyPanel_3.cxx
compila
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / wxMaracasEmptyPanel_3.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracasEmptyPanel_3.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/10/31 16:32:10 $
7   Version:   $Revision: 1.1 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
12      This software is distributed WITHOUT ANY WARRANTY; without even
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18
19
20 #include "wxMaracasEmptyPanel_3.h"
21
22 #include <gdcm.h> 
23 #include <gdcmFile.h> 
24 #include "vtkGdcmReader.h"
25 #include <vtkTransform.h>
26 #include "marGdcmDicom.h"
27 #include <vtkMatrix4x4.h>
28
29 #define PI 3.14159265358979323846
30
31 wxMaracasEmptyPanel_3::wxMaracasEmptyPanel_3( wxWindow* parent  )
32 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
33 {
34   // Create the main frame window
35   _emptyPanel_3_Widget = new wxEmptyPanel_3_Widget( this);
36   wxBoxSizer* szTop = new wxBoxSizer( wxVERTICAL );
37   szTop->Add( _emptyPanel_3_Widget, 1  , wxEXPAND |  wxALL , 0 );
38   szTop->Fit( this );
39   szTop->SetSizeHints( this );
40   this->SetAutoLayout( true );
41   this->SetSizer( szTop );
42   this->Layout();
43 }
44 //----------------------------------------------------------------------------
45 wxMaracasEmptyPanel_3::~wxMaracasEmptyPanel_3( )
46 {
47   // Nothing
48 }
49 //----------------------------------------------------------------------------
50 void wxMaracasEmptyPanel_3::ConfigureVTK( marImageData *marimagedata )
51 {
52   _emptyPanel_3_Widget->ConfigureVTK(marimagedata);
53 }
54
55
56
57
58
59 //----------------------------------------------------------------------------
60 //----------------------------------------------------------------------------
61 //----------------------------------------------------------------------------
62
63
64
65
66
67 void GetAng(double &angX,double &angY,double &angZ,double positionVec[])
68 {
69 //      double PI=3.14159265358979323846;
70         double x,y,z;
71         x = positionVec[0];
72         y = positionVec[1];
73         z = positionVec[2];
74
75         angZ = -atan2( y , x )*180/PI;
76         angY = -atan2( z , sqrt( x*x + y*y ) )*180/PI;
77
78
79         vtkTransform *transform = vtkTransform::New();
80         transform->Identity();
81         transform->RotateY( angY );
82         transform->RotateZ( angZ );
83
84         double in[4],out[4];
85         in[0] = positionVec[3];
86         in[1] = positionVec[4];
87         in[2] = positionVec[5];
88         in[3] = 1;
89
90         transform->MultiplyPoint(in,out);
91
92         transform->Delete();
93
94         x = out[0] ;
95         y = out[1] ;
96         z = out[2] ;
97         
98         angX =  -atan2(z,y)*180/PI;
99
100 //--
101 FILE *ff=fopen("c:/Temp/PIXEL_EED.txt","a+");
102
103         vtkTransform *transform2 = vtkTransform::New();
104         transform2->Identity();
105         transform2->RotateX( angX );
106         transform2->RotateY( -angY );
107         transform2->RotateZ( angZ );
108         in[0] = (double)positionVec[0];
109         in[1] = (double)positionVec[1];
110         in[2] = (double)positionVec[2];;
111         in[3] = 1;
112         transform2->MultiplyPoint(in,out);
113 fprintf(ff,">>>> vx=( %f , %f , %f )  ",out[0],out[1],out[2]);
114
115         in[0] = (double)positionVec[3];
116         in[1] = (double)positionVec[4];
117         in[2] = (double)positionVec[5];
118         in[3] = 1;
119         transform2->MultiplyPoint(in,out);
120 fprintf(ff,"vy=( %f , %f , %f )\n",out[0],out[1],out[2]);
121         transform2->Delete();
122 fclose(ff);
123
124 }
125
126
127
128
129 //----------------------------------------------------------------------------
130 //----------------------------------------------------------------------------
131 //----------------------------------------------------------------------------
132
133
134 BEGIN_EVENT_TABLE( wxMaracasEmptyPanel_4, wxPanel )
135         EVT_MENU( 12121, wxMaracasEmptyPanel_4::OnRefreshView )
136         EVT_MENU( 12122, wxMaracasEmptyPanel_4::OnDClickLeft  )
137 END_EVENT_TABLE( );
138
139
140 wxMaracasEmptyPanel_4::wxMaracasEmptyPanel_4( wxWindow* parent )
141 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
142 {
143
144         _vtkbasedata1                                           = NULL;
145         _vtkbasedata2                                           = NULL;
146         _wxvtk2Dbaseview1                                       = NULL;
147         _wxvtk2Dbaseview2                                       = NULL;
148
149         wxSplitterWindow * splitPanel = new wxSplitterWindow(this,-1);
150         wxPanel *imagePanel             = CreateImagePanel(splitPanel);
151         wxPanel *panelControl   = CreateControlPanel_Algo(splitPanel);
152
153         splitPanel->SplitVertically( imagePanel ,  panelControl , 2 );
154 //      splitPanel->FitInside();
155
156
157           // Create the main frame window
158         wxBoxSizer* szTop = new wxBoxSizer( wxHORIZONTAL );
159         szTop->Add( splitPanel  , 1  , wxEXPAND |  wxALL , 0 );
160         szTop->Fit( this );
161         szTop->SetSizeHints( this );
162         this->SetAutoLayout( true );
163         this->SetSizer( szTop );
164         this->Layout();
165 }
166
167 //----------------------------------------------------------------------------
168
169 wxMaracasEmptyPanel_4::~wxMaracasEmptyPanel_4()
170 {
171         delete  _wxvtk2Dbaseview1;       
172         delete  _wxvtk2Dbaseview2;       
173 //      delete  _vtkbasedata1;           
174 //      delete  _vtkbasedata2;  
175 }
176
177
178
179 //----------------------------------------------------------------------------
180
181 wxPanel* wxMaracasEmptyPanel_4::CreateImagePanel(wxWindow *parent)
182 {
183         wxPanel *panel = new wxPanel(parent,-1);
184
185         _panelImage1                                            = new wxPanel(panel,-1);
186         _panelImage2                                            = new wxPanel(panel,-1);
187
188         wxBoxSizer                      *topsizer1              = new wxBoxSizer(wxVERTICAL  );
189         _panelImage1->SetSizer(topsizer1);
190
191         wxBoxSizer                      *topsizer2              = new wxBoxSizer(wxVERTICAL  );
192         _panelImage2->SetSizer(topsizer2);
193
194           // Create the main frame window
195         wxBoxSizer* szTop = new wxBoxSizer( wxHORIZONTAL );
196         szTop->Add( _panelImage1  , 1  , wxEXPAND |  wxALL , 0 );
197         szTop->Add( _panelImage2  , 1  , wxEXPAND |  wxALL , 0 );
198         szTop->Fit( panel );
199         szTop->SetSizeHints( panel );
200         panel->SetAutoLayout( true );
201         panel->SetSizer( szTop );
202         panel->Layout();
203         return panel;
204
205 }
206
207
208 //----------------------------------------------------------------------------
209
210 wxPanel* wxMaracasEmptyPanel_4::CreateControlPanel_Algo(wxWindow *parent)
211 {
212         wxPanel *panel = new wxPanel(parent,-1);
213
214         wxBoxSizer                      *szTop          = new wxBoxSizer(wxVERTICAL  );
215
216         _rb1 = new wxRadioButton(panel,-1,_T("Algo. 1"));
217         _rb2 = new wxRadioButton(panel,-1,_T("Algo. 2"));
218         _rb3 = new wxRadioButton(panel,-1,_T("Algo. 3"));
219
220         _rb1->SetValue(true);
221
222         szTop->Add( _rb1  , 1  , wxEXPAND |  wxALL , 0 );
223         szTop->Add( _rb2  , 1  , wxEXPAND |  wxALL , 0 );
224         szTop->Add( _rb3  , 1  , wxEXPAND |  wxALL , 0 );
225         szTop->Fit( parent );
226         szTop->SetSizeHints( parent );
227         panel->SetAutoLayout( true );
228         panel->SetSizer( szTop );
229         panel->Layout();
230
231         return panel;
232 }
233
234 //----------------------------------------------------------------------------
235
236 void wxMaracasEmptyPanel_4::OnRefreshView(wxCommandEvent & event) // virtual
237 {
238
239         int pIn[4],pOut[4]; 
240         pIn[0] = (int)(_vtkbasedata1->GetX());
241         pIn[1] = (int)(_vtkbasedata1->GetY());
242         pIn[2] = (int)(_vtkbasedata1->GetZ());
243         pIn[2] = 0;
244         pIn[3] = 1;
245
246         if (_rb1->GetValue()==true)
247         {
248                 TranformPixel1(pIn,pOut, &_infoImg1,&_infoImg2);
249         }
250         if (_rb2->GetValue()==true)
251         {
252                 TranformPixel2(pIn,pOut, &_infoImg1,&_infoImg2);
253         }
254         if (_rb3->GetValue()==true)
255         {
256                 TranformPixel3(pIn,pOut, &_infoImg1,&_infoImg2);
257         }
258
259
260 FILE *ff=fopen("c:/Temp/PIXEL_EED.txt","a+");
261 fprintf(ff,"-) %d %d %d \n"     ,pIn[0] ,pIn[1] ,pIn[2]         );
262 fprintf(ff,"1) %d %d %d \n"     ,pOut[0],pOut[1],pOut[2]        );
263 //TranformPixel2(pIn,pOut, &_infoImg1,&_infoImg2);
264 //fprintf(ff,"2) %d %d %d \n\n" ,pOut[0],pOut[1],pOut[2]        );
265 fclose(ff);
266
267         _vtkbasedata2->SetX( pOut[0] );
268         _vtkbasedata2->SetY( pOut[1] );
269         _vtkbasedata2->SetZ( 0 );
270
271
272
273         if (_wxvtk2Dbaseview1!=NULL) 
274         {
275                 _wxvtk2Dbaseview1->RefreshView();
276         }
277         if (_wxvtk2Dbaseview2!=NULL) 
278         {
279                 _wxvtk2Dbaseview2->Refresh();
280                 _wxvtk2Dbaseview2->RefreshView();
281         }
282 }
283 //----------------------------------------------------------------------------
284 void wxMaracasEmptyPanel_4::OnDClickLeft(wxCommandEvent & event) // virtual
285 {
286 }
287 //----------------------------------------------------------------------------
288 void wxMaracasEmptyPanel_4::ConfigureVTK( )
289 {
290         char filename1[255];
291         char filename2[255];
292         FILE *ff=fopen("c:/temp/filename.txt","r");
293         fscanf(ff, "%s ",filename1);
294         fscanf(ff, "%s ",filename2);
295         fclose(ff);
296
297         ConfigureImage(filename1,_panelImage1,1);
298         ConfigureImage(filename2,_panelImage2,2);
299 }
300 //----------------------------------------------------------------------------
301 void wxMaracasEmptyPanel_4::ConfigureImage( char *fileName,wxPanel *panelImage, int ventana)
302 {
303         vtkMPRBaseData *vtkbasedata;
304         wxVtkMPR2DView *wxvtk2Dbaseview;
305
306         struct InfoImag * infoImage;
307
308         if (ventana==1)
309         {
310                 vtkbasedata             = _vtkbasedata1;
311                 wxvtk2Dbaseview = _wxvtk2Dbaseview1;
312                 infoImage=&_infoImg1;
313         } else {
314                 vtkbasedata             = _vtkbasedata2;
315                 wxvtk2Dbaseview = _wxvtk2Dbaseview2;
316                 infoImage=&_infoImg2;
317         }
318  
319
320         // Read header file
321         GDCM_NAME_SPACE::File *gdcmFile = GDCM_NAME_SPACE::File::New();
322         gdcmFile->SetLoadMode( GDCM_NAME_SPACE::LD_NOSHADOW );
323         gdcmFile->SetFileName( fileName );
324         bool ok = gdcmFile->Load();
325         long int offset = gdcmFile->GetPixelOffset(); 
326         int dim[3];
327         dim[0]=gdcmFile->GetXSize();
328         dim[1]=gdcmFile->GetYSize();
329         dim[2]=1; 
330
331         infoImage->Spacing[0]=gdcmFile->GetXSpacing();
332         infoImage->Spacing[1]=gdcmFile->GetYSpacing();
333         infoImage->ImPoPa[0]=gdcmFile->GetXOrigin();
334         infoImage->ImPoPa[1]=gdcmFile->GetYOrigin();
335         infoImage->ImPoPa[2]=gdcmFile->GetZOrigin();
336
337         float iop[6];
338         gdcmFile->GetImageOrientationPatient(iop);
339         infoImage->ImOrPa[0]=iop[0];
340         infoImage->ImOrPa[1]=iop[1];
341         infoImage->ImOrPa[2]=iop[2];
342         infoImage->ImOrPa[3]=iop[3];
343         infoImage->ImOrPa[4]=iop[4];
344         infoImage->ImOrPa[5]=iop[5];
345         
346
347         gdcmFile->Delete();
348
349         // Memory allocation
350         vtkImageData *imageData =       vtkImageData::New();
351         imageData->SetDimensions ( dim );
352         imageData->SetScalarTypeToUnsignedShort();
353         imageData->AllocateScalars();    
354         imageData->Update();  
355         marImageData *marimagedata = new marImageData(imageData);
356
357         // Read Image
358         marGdcmDicom margdcmdicom;
359         void *p_vol = imageData->GetScalarPointer(0,0,0);
360         margdcmdicom.loadFileDicom( p_vol , dim , fileName );
361         
362         if (vtkbasedata)                { delete vtkbasedata;     } 
363         if (wxvtk2Dbaseview)    { delete wxvtk2Dbaseview; } 
364
365         vtkbasedata             = new vtkMPRBaseData(); 
366
367 wxWidgetMesure2D *widgetMesure  = new wxWidgetMesure2D(panelImage);
368 wxvtk2Dbaseview = new wxVtkMPR2DView( widgetMesure,2 );
369
370 //      wxvtk2Dbaseview = new wxVtkMPR2DView( panelImage,2 );
371
372
373         vtkbasedata->SetMarImageData( marimagedata );
374         wxvtk2Dbaseview->SetVtkBaseData(vtkbasedata);
375         wxvtk2Dbaseview->Configure();
376
377         widgetMesure                                    ->      ConfigureA(wxvtk2Dbaseview);
378         widgetMesure                                    ->      SetMesureScale( infoImage->Spacing[0] );
379
380
381         wxVTKRenderWindowInteractor *imagePanel = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();       
382
383         vtkbasedata->SetX( dim[0]/2 );
384         vtkbasedata->SetY( dim[1]/2 );
385         vtkbasedata->SetZ( 0 );
386
387         wxSizer *sizer=panelImage->GetSizer();
388 //      sizer-> Add( imagePanel ,1,wxGROW  ,0);
389         sizer-> Add( widgetMesure ,1,wxGROW  ,0);
390
391         panelImage->SetAutoLayout(true);
392         panelImage->Layout();  
393
394         wxvtk2Dbaseview->Refresh();
395
396         if (ventana==1)
397         {
398                 _vtkbasedata1           = vtkbasedata;
399                 _wxvtk2Dbaseview1       = wxvtk2Dbaseview;
400                 _widgetMesure1          = widgetMesure;
401         } else {
402                 _vtkbasedata2           = vtkbasedata;
403                 _wxvtk2Dbaseview2       = wxvtk2Dbaseview;
404                 _widgetMesure2          = widgetMesure;
405         }
406 }
407
408
409
410 //-----------------------------------------------------------------------------
411
412
413 void wxMaracasEmptyPanel_4::TranformPixel1(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
414 {
415         vtkTransform *transform = vtkTransform::New();
416         transform->Identity();
417
418         double ang1X,ang1Y,ang1Z;
419         double ang2X,ang2Y,ang2Z;
420         double in[4],out[4];
421         
422         GetAng(ang1X,ang1Y,ang1Z,infoImg1->ImOrPa);
423         GetAng(ang2X,ang2Y,ang2Z,infoImg2->ImOrPa);
424
425         // Transformation
426         transform->Scale( 1/infoImg2->Spacing[0] , 1/infoImg2->Spacing[1] , 1 );
427         transform->RotateX( ang2X );
428         transform->RotateY( -ang2Y );
429         transform->RotateZ( ang2Z );
430         transform->Translate( -infoImg2->ImPoPa[0] ,  -infoImg2->ImPoPa[1] ,  -infoImg2->ImPoPa[2] );
431         transform->Translate( infoImg1->ImPoPa[0] ,  infoImg1->ImPoPa[1] ,  infoImg1->ImPoPa[2] );
432         transform->RotateZ( -ang1Z );
433         transform->RotateY( ang1Y );
434         transform->RotateX( -ang1X );
435         transform->Scale(       infoImg1->Spacing[0]    ,       infoImg1->Spacing[1]    ,       1       );
436
437         in[0] = (double)pIn[0];
438         in[1] = (double)pIn[1];
439         in[2] = 0;
440         in[3] = 1;
441
442         transform->MultiplyPoint(in,out);
443
444         transform->Delete();
445
446         pOut[0] = (int)(out[0] + 0.5);
447         pOut[1] = (int)(out[1] + 0.5);
448         pOut[2] = (int)(out[2] + 0.5);
449 }
450
451
452
453 //-----------------------------------------------------------------------------
454
455 void wxMaracasEmptyPanel_4::TranformPixel2(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
456 {
457         double in[4],out[4];
458
459         //Scale 1
460         double src_pos_x = (double)pIn[0] * infoImg1->Spacing[0];
461         double src_pos_y = (double)pIn[1] * infoImg1->Spacing[1];
462         double src_pos_z = (double)pIn[2] * 1;
463
464
465
466 //Rotation 1
467 double dst_nrm_dircos_x;
468 double dst_nrm_dircos_y;
469 double dst_nrm_dircos_z;
470
471 double dst_pos_x;
472 double dst_pos_y;
473 double dst_pos_z;
474
475 double dst_row_dircos_x = infoImg1->ImOrPa[0];
476 double dst_row_dircos_y = infoImg1->ImOrPa[1];
477 double dst_row_dircos_z = infoImg1->ImOrPa[2];
478
479 double dst_col_dircos_x = infoImg1->ImOrPa[3];
480 double dst_col_dircos_y = infoImg1->ImOrPa[4];
481 double dst_col_dircos_z = infoImg1->ImOrPa[5];
482
483 dst_nrm_dircos_x = dst_row_dircos_y * dst_col_dircos_z - dst_row_dircos_z * dst_col_dircos_y; 
484 dst_nrm_dircos_y = dst_row_dircos_z * dst_col_dircos_x - dst_row_dircos_x * dst_col_dircos_z; 
485 dst_nrm_dircos_z = dst_row_dircos_x * dst_col_dircos_y - dst_row_dircos_y * dst_col_dircos_x; 
486
487
488 dst_pos_x = dst_row_dircos_x * src_pos_x
489           + dst_row_dircos_y * src_pos_y
490           + dst_row_dircos_z * src_pos_z;
491
492 dst_pos_y = dst_col_dircos_x * src_pos_x
493           + dst_col_dircos_y * src_pos_y
494           + dst_col_dircos_z * src_pos_z;
495
496 dst_pos_z = dst_nrm_dircos_x * src_pos_x
497           + dst_nrm_dircos_y * src_pos_y
498           + dst_nrm_dircos_z * src_pos_z;
499
500 //Translation 1
501 dst_pos_x = dst_pos_x + infoImg1->ImPoPa[0];
502 dst_pos_y = dst_pos_y + infoImg1->ImPoPa[1];
503 dst_pos_z = dst_pos_z + infoImg1->ImPoPa[2];
504
505 //Tranalacion  - 2
506 dst_pos_x = dst_pos_x - infoImg2->ImPoPa[0];
507 dst_pos_y = dst_pos_y - infoImg2->ImPoPa[1];
508 dst_pos_z = dst_pos_z - infoImg2->ImPoPa[2];
509
510
511 //Rotation - 2
512 dst_row_dircos_x = infoImg2->ImOrPa[0];
513 dst_row_dircos_y = infoImg2->ImOrPa[1];
514 dst_row_dircos_z = infoImg2->ImOrPa[2];
515
516 dst_col_dircos_x = infoImg2->ImOrPa[3];
517 dst_col_dircos_y = infoImg2->ImOrPa[4];
518 dst_col_dircos_z = infoImg2->ImOrPa[5];
519
520 dst_nrm_dircos_x = dst_row_dircos_y * dst_col_dircos_z - dst_row_dircos_z * dst_col_dircos_y; 
521 dst_nrm_dircos_y = dst_row_dircos_z * dst_col_dircos_x - dst_row_dircos_x * dst_col_dircos_z; 
522 dst_nrm_dircos_z = dst_row_dircos_x * dst_col_dircos_y - dst_row_dircos_y * dst_col_dircos_x; 
523
524
525 in[0] = dst_pos_x;
526 in[1] = dst_pos_y;
527 in[2] = dst_pos_z;
528 in[3] = 1;
529 vtkMatrix4x4 *mat=vtkMatrix4x4::New();
530 mat->Identity ();
531
532 /*
533 mat->SetElement(0,0,dst_row_dircos_x);
534 mat->SetElement(0,1,dst_row_dircos_y);
535 mat->SetElement(0,2,dst_row_dircos_z);
536 mat->SetElement(0,3,0);
537
538 mat->SetElement(1,0,dst_col_dircos_x);
539 mat->SetElement(1,1,dst_col_dircos_y);
540 mat->SetElement(1,2,dst_col_dircos_z);
541 mat->SetElement(1,3,0);
542
543 mat->SetElement(2,0,dst_nrm_dircos_x);
544 mat->SetElement(2,1,dst_nrm_dircos_y);
545 mat->SetElement(2,2,dst_nrm_dircos_z);
546 mat->SetElement(2,3,0);
547
548 mat->SetElement(3,0,0);
549 mat->SetElement(3,1,0);
550 mat->SetElement(3,2,0);
551 mat->SetElement(3,3,1);
552
553 */
554
555 mat->SetElement(0,0,dst_row_dircos_x);
556 mat->SetElement(1,0,dst_row_dircos_y);
557 mat->SetElement(2,0,dst_row_dircos_z);
558 mat->SetElement(3,0,0);
559
560 mat->SetElement(0,1,dst_col_dircos_x);
561 mat->SetElement(1,1,dst_col_dircos_y);
562 mat->SetElement(2,1,dst_col_dircos_z);
563 mat->SetElement(3,1,0);
564
565 mat->SetElement(0,2,dst_nrm_dircos_x);
566 mat->SetElement(1,2,dst_nrm_dircos_y);
567 mat->SetElement(2,2,dst_nrm_dircos_z);
568 mat->SetElement(3,2,0);
569
570 mat->SetElement(0,3,0);
571 mat->SetElement(1,3,0);
572 mat->SetElement(2,3,0);
573 mat->SetElement(3,3,1);
574
575
576
577
578 /*
579 vtkTransform *transform2 = vtkTransform::New();
580 transform2->Identity();
581 transform2->SetMatrix(mat);
582 transform2->Update();
583 */
584
585
586 vtkMatrix4x4 *matB                      = vtkMatrix4x4::New();
587 vtkTransform *transform3        = vtkTransform::New();
588 matB->Identity ();
589 mat->Invert(mat,matB);
590 //transform2->GetInverse(matB);
591 transform3->SetMatrix(matB);
592 transform3->Update();
593
594 double res=0;
595 FILE *hh=fopen("c:/Temp/Matrix.txt","w");
596 for (int i=0; i<4; i++)
597 {
598         for (int j=0; j<4; j++)
599         {
600                 res=0;
601                 for (int ii=0;ii<4;ii++)
602                 {
603                         res = res + mat->GetElement(ii,j) * matB->GetElement(i,ii);
604                 }
605         fprintf(hh,"%f ",res);
606         }
607 }
608 fclose(hh);
609
610 transform3->MultiplyPoint(in,out);
611 transform3->Delete();
612 mat->Delete();
613 matB->Delete();
614
615         //Scale 1/2
616 out[0] = out[0] / infoImg2->Spacing[0];
617 out[1] = out[1] / infoImg2->Spacing[1];
618 out[2] = out[2] / 1.0;
619
620 //--
621
622 pOut[0] = (int)(out[0] + 0.5);
623 pOut[1] = (int)(out[1] + 0.5);
624 pOut[2] = (int)(out[2] + 0.5);
625 }
626
627
628
629 //-----------------------------------------------------------------------------
630
631 void wxMaracasEmptyPanel_4::TranformPixel2a(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
632 {
633         double in[4],out[4];
634
635         //Scale 1
636         double src_pos_x = (double)pIn[0] * infoImg1->Spacing[0];
637         double src_pos_y = (double)pIn[1] * infoImg1->Spacing[1];
638         double src_pos_z = (double)pIn[2] * 1;
639
640
641
642 //Rotation 1
643 double dst_nrm_dircos_x;
644 double dst_nrm_dircos_y;
645 double dst_nrm_dircos_z;
646
647 double dst_pos_x;
648 double dst_pos_y;
649 double dst_pos_z;
650
651 double dst_row_dircos_x = infoImg1->ImOrPa[0];
652 double dst_row_dircos_y = infoImg1->ImOrPa[1];
653 double dst_row_dircos_z = infoImg1->ImOrPa[2];
654
655 double dst_col_dircos_x = infoImg1->ImOrPa[3];
656 double dst_col_dircos_y = infoImg1->ImOrPa[4];
657 double dst_col_dircos_z = infoImg1->ImOrPa[5];
658
659 dst_nrm_dircos_x = dst_row_dircos_y * dst_col_dircos_z - dst_row_dircos_z * dst_col_dircos_y; 
660 dst_nrm_dircos_y = dst_row_dircos_z * dst_col_dircos_x - dst_row_dircos_x * dst_col_dircos_z; 
661 dst_nrm_dircos_z = dst_row_dircos_x * dst_col_dircos_y - dst_row_dircos_y * dst_col_dircos_x; 
662
663 in[0] = src_pos_x;
664 in[1] = src_pos_y;
665 in[2] = src_pos_z;
666 in[3] = 0;
667 vtkMatrix4x4 *mat=vtkMatrix4x4::New();
668
669 mat->SetElement(0,0,dst_row_dircos_x);
670 mat->SetElement(0,1,dst_row_dircos_y);
671 mat->SetElement(0,2,dst_row_dircos_z);
672 mat->SetElement(0,3,0);
673
674 mat->SetElement(1,0,dst_col_dircos_x);
675 mat->SetElement(1,1,dst_col_dircos_y);
676 mat->SetElement(1,2,dst_col_dircos_z);
677 mat->SetElement(1,3,0);
678
679 mat->SetElement(2,0,dst_nrm_dircos_x);
680 mat->SetElement(2,1,dst_nrm_dircos_y);
681 mat->SetElement(2,2,dst_nrm_dircos_z);
682 mat->SetElement(2,3,0);
683
684 mat->SetElement(3,0,0);
685 mat->SetElement(3,1,0);
686 mat->SetElement(3,2,0);
687 mat->SetElement(3,3,1);
688
689 /*
690
691 mat->SetElement(0,0,dst_row_dircos_x);
692 mat->SetElement(1,0,dst_row_dircos_y);
693 mat->SetElement(2,0,dst_row_dircos_z);
694 mat->SetElement(3,0,0);
695
696 mat->SetElement(0,1,dst_col_dircos_x);
697 mat->SetElement(1,1,dst_col_dircos_y);
698 mat->SetElement(2,1,dst_col_dircos_z);
699 mat->SetElement(3,1,0);
700
701 mat->SetElement(0,2,dst_nrm_dircos_x);
702 mat->SetElement(1,2,dst_nrm_dircos_y);
703 mat->SetElement(2,2,dst_nrm_dircos_z);
704 mat->SetElement(3,2,0);
705
706 mat->SetElement(0,3,0);
707 mat->SetElement(1,3,0);
708 mat->SetElement(2,3,0);
709 mat->SetElement(3,3,1);
710 */
711
712 vtkMatrix4x4 *matB                      = vtkMatrix4x4::New();
713 vtkTransform *transform3        = vtkTransform::New();
714 mat->Invert(mat,matB);
715 transform3->SetMatrix(matB);
716 transform3->Update();
717
718 double res=0;
719 FILE *hh=fopen("c:/Temp/Matrix.txt","w");
720 for (int i=0; i<4; i++)
721 {
722         for (int j=0; j<4; j++)
723         {
724                 res=0;
725                 for (int ii=0;ii<4;ii++)
726                 {
727                         res = res + mat->GetElement(ii,j) * matB->GetElement(i,ii);
728                 }
729         fprintf(hh,"%f ",res);
730         }
731 }
732 fclose(hh);
733
734 transform3->MultiplyPoint(in,out);
735 transform3->Delete();
736 mat->Delete();
737 matB->Delete();
738
739
740 //Translation 1
741 dst_pos_x = out[0] + infoImg1->ImPoPa[0];
742 dst_pos_y = out[0] + infoImg1->ImPoPa[1];
743 dst_pos_z = out[0] + infoImg1->ImPoPa[2];
744
745 //Tranalacion  - 2
746 src_pos_x = dst_pos_x - infoImg2->ImPoPa[0];
747 src_pos_y = dst_pos_y - infoImg2->ImPoPa[1];
748 src_pos_z = dst_pos_z - infoImg2->ImPoPa[2];
749
750
751
752
753 //Rotation - 2
754 dst_row_dircos_x = infoImg2->ImOrPa[0];
755 dst_row_dircos_y = infoImg2->ImOrPa[1];
756 dst_row_dircos_z = infoImg2->ImOrPa[2];
757
758 dst_col_dircos_x = infoImg2->ImOrPa[3];
759 dst_col_dircos_y = infoImg2->ImOrPa[4];
760 dst_col_dircos_z = infoImg2->ImOrPa[5];
761
762 dst_nrm_dircos_x = dst_row_dircos_y * dst_col_dircos_z - dst_row_dircos_z * dst_col_dircos_y; 
763 dst_nrm_dircos_y = dst_row_dircos_z * dst_col_dircos_x - dst_row_dircos_x * dst_col_dircos_z; 
764 dst_nrm_dircos_z = dst_row_dircos_x * dst_col_dircos_y - dst_row_dircos_y * dst_col_dircos_x; 
765
766
767 dst_pos_x = dst_row_dircos_x * src_pos_x
768           + dst_row_dircos_y * src_pos_y
769           + dst_row_dircos_z * src_pos_z;
770
771 dst_pos_y = dst_col_dircos_x * src_pos_x
772           + dst_col_dircos_y * src_pos_y
773           + dst_col_dircos_z * src_pos_z;
774
775 dst_pos_z = dst_nrm_dircos_x * src_pos_x
776           + dst_nrm_dircos_y * src_pos_y
777           + dst_nrm_dircos_z * src_pos_z;
778
779
780
781         //Scale 1/2
782 out[0]=dst_pos_x / infoImg2->Spacing[0];
783 out[1]=dst_pos_y / infoImg2->Spacing[1];
784 out[2]=dst_pos_z / 1.0;
785
786 //--
787
788 pOut[0] = (int)(out[0] + 0.5);
789 pOut[1] = (int)(out[1] + 0.5);
790 pOut[2] = (int)(out[2] + 0.5);
791 }
792
793
794 //----------------------------------------------------------------------------
795
796
797 void wxMaracasEmptyPanel_4::TranformPixel3(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
798 {
799
800         manualPoint *p1a = _widgetMesure1->GetManualContourModel()->GetManualPoint(0);  
801         manualPoint *p1b = _widgetMesure1->GetManualContourModel()->GetManualPoint(1);  
802
803         manualPoint *p2a = _widgetMesure2->GetManualContourModel()->GetManualPoint(0);  
804         manualPoint *p2b = _widgetMesure2->GetManualContourModel()->GetManualPoint(1);  
805
806     double pp1aX = p1a->GetX() * infoImg1->Spacing[0];
807     double pp1aY = p1a->GetY() * infoImg1->Spacing[1];
808     double pp1bX = p1b->GetX() * infoImg1->Spacing[0];
809     double pp1bY = p1b->GetY() * infoImg1->Spacing[1];
810
811     double pp2aX = p2a->GetX() * infoImg2->Spacing[0];
812     double pp2aY = p2a->GetY() * infoImg2->Spacing[1];
813     double pp2bX = p2b->GetX() * infoImg2->Spacing[0];
814     double pp2bY = p2b->GetY() * infoImg2->Spacing[1];
815
816         double ang1= atan2( pp1bY-pp1aY , pp1bX-pp1aX )*180/PI;
817         double ang2= atan2( pp2bY-pp2aY , pp2bX-pp2aX )*180/PI;
818
819         double in[4],inB[4],out[4];
820         in[0] = (double)pIn[0] * infoImg1->Spacing[0];
821         in[1] = (double)pIn[1] * infoImg1->Spacing[1];
822         in[2] = 0;
823         in[3] = 1;
824
825         in[0]=in[0]-pp1aX;
826         in[1]=in[1]-pp1aY;
827
828         vtkTransform *transform; 
829         transform = vtkTransform::New();
830         transform->Identity();
831 //      transform->RotateZ( ang2 );
832         transform->RotateZ( -ang1 );
833         transform->MultiplyPoint(in,out);
834         transform->Delete();
835
836         inB[0] = out[0];
837         inB[1] = out[1];
838         inB[2] = out[2];
839         inB[3] = out[3];
840         vtkTransform *transform2; 
841         transform2 = vtkTransform::New();
842         transform2->Identity();
843         transform2->RotateZ( ang2 );
844 //      transform2->RotateZ( ang1 );
845         transform2->MultiplyPoint(inB,out);
846         transform2->Delete();
847
848         out[0] = out[0] + pp2aX;
849         out[1] = out[1] + pp2aY;
850
851         out[0] = out[0] / infoImg2->Spacing[0];
852         out[1] = out[1] / infoImg2->Spacing[1];
853
854         pOut[0]= (int)(out[0] + 0.5);   
855         pOut[1]= (int)(out[1] + 0.5);   
856         pOut[2]= 0;     
857
858
859
860 }
861
862
863 // EOF - wxMaracasEmptyPanel_3.cxx
864
865
866
867