1 /*=========================================================================
4 Module: $RCSfile: wxMaracasEmptyPanel_3.cxx,v $
6 Date: $Date: 2008/10/31 16:32:10 $
7 Version: $Revision: 1.1 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
20 #include "wxMaracasEmptyPanel_3.h"
24 #include "vtkGdcmReader.h"
25 #include <vtkTransform.h>
26 #include "marGdcmDicom.h"
27 #include <vtkMatrix4x4.h>
29 #define PI 3.14159265358979323846
31 wxMaracasEmptyPanel_3::wxMaracasEmptyPanel_3( wxWindow* parent )
32 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
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 );
39 szTop->SetSizeHints( this );
40 this->SetAutoLayout( true );
41 this->SetSizer( szTop );
44 //----------------------------------------------------------------------------
45 wxMaracasEmptyPanel_3::~wxMaracasEmptyPanel_3( )
49 //----------------------------------------------------------------------------
50 void wxMaracasEmptyPanel_3::ConfigureVTK( marImageData *marimagedata )
52 _emptyPanel_3_Widget->ConfigureVTK(marimagedata);
59 //----------------------------------------------------------------------------
60 //----------------------------------------------------------------------------
61 //----------------------------------------------------------------------------
67 void GetAng(double &angX,double &angY,double &angZ,double positionVec[])
69 // double PI=3.14159265358979323846;
75 angZ = -atan2( y , x )*180/PI;
76 angY = -atan2( z , sqrt( x*x + y*y ) )*180/PI;
79 vtkTransform *transform = vtkTransform::New();
80 transform->Identity();
81 transform->RotateY( angY );
82 transform->RotateZ( angZ );
85 in[0] = positionVec[3];
86 in[1] = positionVec[4];
87 in[2] = positionVec[5];
90 transform->MultiplyPoint(in,out);
98 angX = -atan2(z,y)*180/PI;
101 FILE *ff=fopen("c:/Temp/PIXEL_EED.txt","a+");
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];;
112 transform2->MultiplyPoint(in,out);
113 fprintf(ff,">>>> vx=( %f , %f , %f ) ",out[0],out[1],out[2]);
115 in[0] = (double)positionVec[3];
116 in[1] = (double)positionVec[4];
117 in[2] = (double)positionVec[5];
119 transform2->MultiplyPoint(in,out);
120 fprintf(ff,"vy=( %f , %f , %f )\n",out[0],out[1],out[2]);
121 transform2->Delete();
129 //----------------------------------------------------------------------------
130 //----------------------------------------------------------------------------
131 //----------------------------------------------------------------------------
134 BEGIN_EVENT_TABLE( wxMaracasEmptyPanel_4, wxPanel )
135 EVT_MENU( 12121, wxMaracasEmptyPanel_4::OnRefreshView )
136 EVT_MENU( 12122, wxMaracasEmptyPanel_4::OnDClickLeft )
140 wxMaracasEmptyPanel_4::wxMaracasEmptyPanel_4( wxWindow* parent )
141 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
144 _vtkbasedata1 = NULL;
145 _vtkbasedata2 = NULL;
146 _wxvtk2Dbaseview1 = NULL;
147 _wxvtk2Dbaseview2 = NULL;
149 wxSplitterWindow * splitPanel = new wxSplitterWindow(this,-1);
150 wxPanel *imagePanel = CreateImagePanel(splitPanel);
151 wxPanel *panelControl = CreateControlPanel_Algo(splitPanel);
153 splitPanel->SplitVertically( imagePanel , panelControl , 2 );
154 // splitPanel->FitInside();
157 // Create the main frame window
158 wxBoxSizer* szTop = new wxBoxSizer( wxHORIZONTAL );
159 szTop->Add( splitPanel , 1 , wxEXPAND | wxALL , 0 );
161 szTop->SetSizeHints( this );
162 this->SetAutoLayout( true );
163 this->SetSizer( szTop );
167 //----------------------------------------------------------------------------
169 wxMaracasEmptyPanel_4::~wxMaracasEmptyPanel_4()
171 delete _wxvtk2Dbaseview1;
172 delete _wxvtk2Dbaseview2;
173 // delete _vtkbasedata1;
174 // delete _vtkbasedata2;
179 //----------------------------------------------------------------------------
181 wxPanel* wxMaracasEmptyPanel_4::CreateImagePanel(wxWindow *parent)
183 wxPanel *panel = new wxPanel(parent,-1);
185 _panelImage1 = new wxPanel(panel,-1);
186 _panelImage2 = new wxPanel(panel,-1);
188 wxBoxSizer *topsizer1 = new wxBoxSizer(wxVERTICAL );
189 _panelImage1->SetSizer(topsizer1);
191 wxBoxSizer *topsizer2 = new wxBoxSizer(wxVERTICAL );
192 _panelImage2->SetSizer(topsizer2);
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 );
199 szTop->SetSizeHints( panel );
200 panel->SetAutoLayout( true );
201 panel->SetSizer( szTop );
208 //----------------------------------------------------------------------------
210 wxPanel* wxMaracasEmptyPanel_4::CreateControlPanel_Algo(wxWindow *parent)
212 wxPanel *panel = new wxPanel(parent,-1);
214 wxBoxSizer *szTop = new wxBoxSizer(wxVERTICAL );
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"));
220 _rb1->SetValue(true);
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 );
234 //----------------------------------------------------------------------------
236 void wxMaracasEmptyPanel_4::OnRefreshView(wxCommandEvent & event) // virtual
240 pIn[0] = (int)(_vtkbasedata1->GetX());
241 pIn[1] = (int)(_vtkbasedata1->GetY());
242 pIn[2] = (int)(_vtkbasedata1->GetZ());
246 if (_rb1->GetValue()==true)
248 TranformPixel1(pIn,pOut, &_infoImg1,&_infoImg2);
250 if (_rb2->GetValue()==true)
252 TranformPixel2(pIn,pOut, &_infoImg1,&_infoImg2);
254 if (_rb3->GetValue()==true)
256 TranformPixel3(pIn,pOut, &_infoImg1,&_infoImg2);
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] );
267 _vtkbasedata2->SetX( pOut[0] );
268 _vtkbasedata2->SetY( pOut[1] );
269 _vtkbasedata2->SetZ( 0 );
273 if (_wxvtk2Dbaseview1!=NULL)
275 _wxvtk2Dbaseview1->RefreshView();
277 if (_wxvtk2Dbaseview2!=NULL)
279 _wxvtk2Dbaseview2->Refresh();
280 _wxvtk2Dbaseview2->RefreshView();
283 //----------------------------------------------------------------------------
284 void wxMaracasEmptyPanel_4::OnDClickLeft(wxCommandEvent & event) // virtual
287 //----------------------------------------------------------------------------
288 void wxMaracasEmptyPanel_4::ConfigureVTK( )
292 FILE *ff=fopen("c:/temp/filename.txt","r");
293 fscanf(ff, "%s ",filename1);
294 fscanf(ff, "%s ",filename2);
297 ConfigureImage(filename1,_panelImage1,1);
298 ConfigureImage(filename2,_panelImage2,2);
300 //----------------------------------------------------------------------------
301 void wxMaracasEmptyPanel_4::ConfigureImage( char *fileName,wxPanel *panelImage, int ventana)
303 vtkMPRBaseData *vtkbasedata;
304 wxVtkMPR2DView *wxvtk2Dbaseview;
306 struct InfoImag * infoImage;
310 vtkbasedata = _vtkbasedata1;
311 wxvtk2Dbaseview = _wxvtk2Dbaseview1;
312 infoImage=&_infoImg1;
314 vtkbasedata = _vtkbasedata2;
315 wxvtk2Dbaseview = _wxvtk2Dbaseview2;
316 infoImage=&_infoImg2;
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();
327 dim[0]=gdcmFile->GetXSize();
328 dim[1]=gdcmFile->GetYSize();
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();
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];
350 vtkImageData *imageData = vtkImageData::New();
351 imageData->SetDimensions ( dim );
352 imageData->SetScalarTypeToUnsignedShort();
353 imageData->AllocateScalars();
355 marImageData *marimagedata = new marImageData(imageData);
358 marGdcmDicom margdcmdicom;
359 void *p_vol = imageData->GetScalarPointer(0,0,0);
360 margdcmdicom.loadFileDicom( p_vol , dim , fileName );
362 if (vtkbasedata) { delete vtkbasedata; }
363 if (wxvtk2Dbaseview) { delete wxvtk2Dbaseview; }
365 vtkbasedata = new vtkMPRBaseData();
367 wxWidgetMesure2D *widgetMesure = new wxWidgetMesure2D(panelImage);
368 wxvtk2Dbaseview = new wxVtkMPR2DView( widgetMesure,2 );
370 // wxvtk2Dbaseview = new wxVtkMPR2DView( panelImage,2 );
373 vtkbasedata->SetMarImageData( marimagedata );
374 wxvtk2Dbaseview->SetVtkBaseData(vtkbasedata);
375 wxvtk2Dbaseview->Configure();
377 widgetMesure -> ConfigureA(wxvtk2Dbaseview);
378 widgetMesure -> SetMesureScale( infoImage->Spacing[0] );
381 wxVTKRenderWindowInteractor *imagePanel = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
383 vtkbasedata->SetX( dim[0]/2 );
384 vtkbasedata->SetY( dim[1]/2 );
385 vtkbasedata->SetZ( 0 );
387 wxSizer *sizer=panelImage->GetSizer();
388 // sizer-> Add( imagePanel ,1,wxGROW ,0);
389 sizer-> Add( widgetMesure ,1,wxGROW ,0);
391 panelImage->SetAutoLayout(true);
392 panelImage->Layout();
394 wxvtk2Dbaseview->Refresh();
398 _vtkbasedata1 = vtkbasedata;
399 _wxvtk2Dbaseview1 = wxvtk2Dbaseview;
400 _widgetMesure1 = widgetMesure;
402 _vtkbasedata2 = vtkbasedata;
403 _wxvtk2Dbaseview2 = wxvtk2Dbaseview;
404 _widgetMesure2 = widgetMesure;
410 //-----------------------------------------------------------------------------
413 void wxMaracasEmptyPanel_4::TranformPixel1(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
415 vtkTransform *transform = vtkTransform::New();
416 transform->Identity();
418 double ang1X,ang1Y,ang1Z;
419 double ang2X,ang2Y,ang2Z;
422 GetAng(ang1X,ang1Y,ang1Z,infoImg1->ImOrPa);
423 GetAng(ang2X,ang2Y,ang2Z,infoImg2->ImOrPa);
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 );
437 in[0] = (double)pIn[0];
438 in[1] = (double)pIn[1];
442 transform->MultiplyPoint(in,out);
446 pOut[0] = (int)(out[0] + 0.5);
447 pOut[1] = (int)(out[1] + 0.5);
448 pOut[2] = (int)(out[2] + 0.5);
453 //-----------------------------------------------------------------------------
455 void wxMaracasEmptyPanel_4::TranformPixel2(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
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;
467 double dst_nrm_dircos_x;
468 double dst_nrm_dircos_y;
469 double dst_nrm_dircos_z;
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];
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];
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;
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;
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;
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;
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];
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];
512 dst_row_dircos_x = infoImg2->ImOrPa[0];
513 dst_row_dircos_y = infoImg2->ImOrPa[1];
514 dst_row_dircos_z = infoImg2->ImOrPa[2];
516 dst_col_dircos_x = infoImg2->ImOrPa[3];
517 dst_col_dircos_y = infoImg2->ImOrPa[4];
518 dst_col_dircos_z = infoImg2->ImOrPa[5];
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;
529 vtkMatrix4x4 *mat=vtkMatrix4x4::New();
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);
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);
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);
548 mat->SetElement(3,0,0);
549 mat->SetElement(3,1,0);
550 mat->SetElement(3,2,0);
551 mat->SetElement(3,3,1);
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);
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);
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);
570 mat->SetElement(0,3,0);
571 mat->SetElement(1,3,0);
572 mat->SetElement(2,3,0);
573 mat->SetElement(3,3,1);
579 vtkTransform *transform2 = vtkTransform::New();
580 transform2->Identity();
581 transform2->SetMatrix(mat);
582 transform2->Update();
586 vtkMatrix4x4 *matB = vtkMatrix4x4::New();
587 vtkTransform *transform3 = vtkTransform::New();
589 mat->Invert(mat,matB);
590 //transform2->GetInverse(matB);
591 transform3->SetMatrix(matB);
592 transform3->Update();
595 FILE *hh=fopen("c:/Temp/Matrix.txt","w");
596 for (int i=0; i<4; i++)
598 for (int j=0; j<4; j++)
601 for (int ii=0;ii<4;ii++)
603 res = res + mat->GetElement(ii,j) * matB->GetElement(i,ii);
605 fprintf(hh,"%f ",res);
610 transform3->MultiplyPoint(in,out);
611 transform3->Delete();
616 out[0] = out[0] / infoImg2->Spacing[0];
617 out[1] = out[1] / infoImg2->Spacing[1];
618 out[2] = out[2] / 1.0;
622 pOut[0] = (int)(out[0] + 0.5);
623 pOut[1] = (int)(out[1] + 0.5);
624 pOut[2] = (int)(out[2] + 0.5);
629 //-----------------------------------------------------------------------------
631 void wxMaracasEmptyPanel_4::TranformPixel2a(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
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;
643 double dst_nrm_dircos_x;
644 double dst_nrm_dircos_y;
645 double dst_nrm_dircos_z;
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];
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];
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;
667 vtkMatrix4x4 *mat=vtkMatrix4x4::New();
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);
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);
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);
684 mat->SetElement(3,0,0);
685 mat->SetElement(3,1,0);
686 mat->SetElement(3,2,0);
687 mat->SetElement(3,3,1);
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);
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);
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);
706 mat->SetElement(0,3,0);
707 mat->SetElement(1,3,0);
708 mat->SetElement(2,3,0);
709 mat->SetElement(3,3,1);
712 vtkMatrix4x4 *matB = vtkMatrix4x4::New();
713 vtkTransform *transform3 = vtkTransform::New();
714 mat->Invert(mat,matB);
715 transform3->SetMatrix(matB);
716 transform3->Update();
719 FILE *hh=fopen("c:/Temp/Matrix.txt","w");
720 for (int i=0; i<4; i++)
722 for (int j=0; j<4; j++)
725 for (int ii=0;ii<4;ii++)
727 res = res + mat->GetElement(ii,j) * matB->GetElement(i,ii);
729 fprintf(hh,"%f ",res);
734 transform3->MultiplyPoint(in,out);
735 transform3->Delete();
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];
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];
754 dst_row_dircos_x = infoImg2->ImOrPa[0];
755 dst_row_dircos_y = infoImg2->ImOrPa[1];
756 dst_row_dircos_z = infoImg2->ImOrPa[2];
758 dst_col_dircos_x = infoImg2->ImOrPa[3];
759 dst_col_dircos_y = infoImg2->ImOrPa[4];
760 dst_col_dircos_z = infoImg2->ImOrPa[5];
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;
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;
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;
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;
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;
788 pOut[0] = (int)(out[0] + 0.5);
789 pOut[1] = (int)(out[1] + 0.5);
790 pOut[2] = (int)(out[2] + 0.5);
794 //----------------------------------------------------------------------------
797 void wxMaracasEmptyPanel_4::TranformPixel3(int pIn[], int pOut[], struct InfoImag *infoImg1, struct InfoImag *infoImg2)
800 manualPoint *p1a = _widgetMesure1->GetManualContourModel()->GetManualPoint(0);
801 manualPoint *p1b = _widgetMesure1->GetManualContourModel()->GetManualPoint(1);
803 manualPoint *p2a = _widgetMesure2->GetManualContourModel()->GetManualPoint(0);
804 manualPoint *p2b = _widgetMesure2->GetManualContourModel()->GetManualPoint(1);
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];
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];
816 double ang1= atan2( pp1bY-pp1aY , pp1bX-pp1aX )*180/PI;
817 double ang2= atan2( pp2bY-pp2aY , pp2bX-pp2aX )*180/PI;
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];
828 vtkTransform *transform;
829 transform = vtkTransform::New();
830 transform->Identity();
831 // transform->RotateZ( ang2 );
832 transform->RotateZ( -ang1 );
833 transform->MultiplyPoint(in,out);
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();
848 out[0] = out[0] + pp2aX;
849 out[1] = out[1] + pp2aY;
851 out[0] = out[0] / infoImg2->Spacing[0];
852 out[1] = out[1] / infoImg2->Spacing[1];
854 pOut[0]= (int)(out[0] + 0.5);
855 pOut[1]= (int)(out[1] + 0.5);
863 // EOF - wxMaracasEmptyPanel_3.cxx