#include "wxVtkMPR2DView.h" #include "vtkInteractorStyleBaseView.h" #include "vtkCellArray.h" wxVtkMPR2DView::wxVtkMPR2DView( wxWindow *parent, int direction) :wxVtk2DBaseView(parent) { _backX = -99999; _backY = -99999; _backZ = -99999; _direction = direction; _ptsA = NULL; _lineAActor = NULL; _lineAMapper = NULL; _pdA = NULL; _ptsB = NULL; _lineBActor = NULL; _lineBMapper = NULL; _pdB = NULL; } //------------------------------------------------------------------- wxVtkMPR2DView::~wxVtkMPR2DView() { if (_ptsA!=NULL) { _ptsA -> Delete(); } if (_lineAActor!=NULL) { _lineAActor -> Delete(); } if (_lineAMapper!=NULL) { _lineAMapper -> Delete(); } if (_pdA!=NULL) { _pdA -> Delete(); } if (_ptsB!=NULL) { _ptsB -> Delete(); } if (_lineBActor!=NULL) { _lineBActor -> Delete(); } if (_lineBMapper!=NULL) { _lineBMapper -> Delete(); } if (_pdB!=NULL) { _pdB -> Delete(); } } //------------------------------------------------------------------- vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata() { return (vtkMPRBaseData*)GetVtkBaseData(); } //------------------------------------------------------------------- void wxVtkMPR2DView::Configure(){ wxVtk2DBaseView::Configure(); _interactorstylemprview = new vtkInteractorStyleMPRView(); ((vtkInteractorStyleBaseView*)GetInteractorStyleBaseView())->AddInteractorStyleMaracas( _interactorstylemprview ); int x1,x2,y1,y2,z1,z2; GetVtkmprbasedata() -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2); double spc[3]; vtkImageData* img = GetVtkmprbasedata()->GetImageData(); if(img!=NULL){ img->GetSpacing(spc); x1 = (int)(x1*spc[0]); y1 = (int)(y1*spc[1]); z1 = (int)(z1*spc[2]); x2 = (int)(x2*spc[0]); y2 = (int)(y2*spc[1]); z2 = (int)(z2*spc[2]); _visibleAxis = true; // Axe A _ptsA = vtkPoints::New(); _ptsA->SetNumberOfPoints(2); _ptsA->SetPoint(0, -1000 , -1000 , -1000 ); _ptsA->SetPoint(1, 1000 , 1000 , 1000 ); vtkCellArray *linesA; linesA = vtkCellArray::New(); linesA->InsertNextCell(2); linesA->InsertCellPoint(0); linesA->InsertCellPoint(1); _pdA = vtkPolyData::New(); _pdA->SetPoints( _ptsA ); _pdA->SetLines( linesA ); linesA->Delete(); //do not delete lines ?? _lineAActor = vtkActor::New(); _lineAMapper = vtkPolyDataMapper::New(); _lineAMapper->SetInput(_pdA); _lineAMapper->ImmediateModeRenderingOn(); _lineAActor->SetMapper(_lineAMapper); // _lineAActor->GetProperty()->BackfaceCullingOn(); _lineAActor->GetProperty()->SetDiffuseColor(1,0,0); _lineAActor->GetProperty()->SetLineWidth(2); _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor ); // Axe B _ptsB = vtkPoints::New(); _ptsB->SetNumberOfPoints(2); _ptsB->SetPoint(0, -1000 , -1000 , -1000 ); _ptsB->SetPoint(1, 1000 , 1000 , 1000 ); vtkCellArray *linesB; linesB = vtkCellArray::New(); linesB->InsertNextCell(2); linesB->InsertCellPoint(0); linesB->InsertCellPoint(1); _pdB = vtkPolyData::New(); _pdB->SetPoints( _ptsB ); _pdB->SetLines( linesB ); linesB->Delete(); //do not delete lines ?? _lineBActor = vtkActor::New(); _lineBMapper = vtkPolyDataMapper::New(); _lineBMapper->SetInput(_pdB); _lineBMapper->ImmediateModeRenderingOn(); _lineBActor->SetMapper(_lineBMapper); // _lineBActor->GetProperty()->BackfaceCullingOn(); _lineBActor->GetProperty()->SetDiffuseColor(1,0,0); _lineBActor->GetProperty()->SetLineWidth(2); _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor ); vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera(); //EED 17Avril2009 /* if (_direction==0) { camera->SetViewUp ( 0 , -1 , 0 ); camera->SetPosition ( -10000,(y1+y2)/2 , (z1+z2)/2 ); camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 ); camera->SetParallelScale( (z2-z1)/3.0 ); } if (_direction==1) { camera->SetViewUp ( 0 , 0 , -1 ); camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 ); camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 ); camera->SetParallelScale( (x2-x1)/3.0 ); } if (_direction==2) { camera->SetViewUp ( 0 , -1 , 0 ); camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , -10000); camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 ); camera->SetParallelScale( (x2-x1)/3.0 ); } */ if (_direction==0) { camera->SetViewUp ( 0 , 1 , 0 ); camera->SetPosition ( 10000,(y1+y2)/2 , (z1+z2)/2 ); camera->SetFocalPoint ( 0 , (y1+y2)/2 , (z1+z2)/2 ); camera->SetParallelScale( (z2-z1)/3.0 ); } if (_direction==1) { camera->SetViewUp ( 0 , 0 , -1 ); camera->SetPosition ((x1+x2)/2 , 10000 , (z1+z2)/2 ); camera->SetFocalPoint ((x1+x2)/2 , 0 , (z1+z2)/2 ); camera->SetParallelScale( (x2-x1)/3.0 ); } if (_direction==2) { camera->SetViewUp ( 0 , 1 , 0 ); camera->SetPosition ((x1+x2)/2 , (y1+y2)/2 , 10000); camera->SetFocalPoint ((x1+x2)/2 , (y1+y2)/2 , 0 ); camera->SetParallelScale( (x2-x1)/3.0 ); } } // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160); // _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800); } void wxVtkMPR2DView::SetVisibleAxis(bool ok) { if (ok!=_visibleAxis) { _visibleAxis=ok; if (_visibleAxis==true) { _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor ); _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor ); } if (_visibleAxis==false) { _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor ); _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor ); } } } //------------------------------------------------------------------- void wxVtkMPR2DView::Refresh() { //wxVtk2DBaseView::Refresh(); //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx int x1,x2,y1,y2,z1,z2; GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2); double spc[3]; vtkImageData* img = GetVtkmprbasedata()->GetImageData(); if(img!=NULL){ img->GetSpacing(spc); x1 = (int)(x1*spc[0]); y1 = (int)(y1*spc[1]); z1 = (int)(z1*spc[2]); x2 = (int)(x2*spc[0]); y2 = (int)(y2*spc[1]); z2 = (int)(z2*spc[2]); int x = (int)(GetVtkmprbasedata()->GetX()); int y = (int)(GetVtkmprbasedata()->GetY()); int z = (int)(GetVtkmprbasedata()->GetZ()); x = (int)(x*spc[0]); y = (int)(y*spc[1]); z = (int)(z*spc[2]); if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) { if (_direction==0) { _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) ); _ptsA->SetPoint(0, -x2, y1 , z ); _ptsA->SetPoint(1, -x2, y2 , z ); _ptsB->SetPoint(0, -x2, y , z1); _ptsB->SetPoint(1, -x2, y , z2); } if (_direction==1) { _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) ); _ptsA->SetPoint(0, x1 , y2 , z ); _ptsA->SetPoint(1, x2 , y2 , z ); _ptsB->SetPoint(0, x , y2 , z1); _ptsB->SetPoint(1, x , y2 , z2); } if (_direction==2) { _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) ); _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) ); // _ptsA->SetPoint(0, x1 , y , -z2 ); // _ptsA->SetPoint(1, x2 , y , -z2 ); // _ptsB->SetPoint(0, x , y1, -z2 ); // _ptsB->SetPoint(1, x , y2, -z2 ); _ptsA->SetPoint(0, x1 , y , z2 ); _ptsA->SetPoint(1, x2 , y , z2 ); _ptsB->SetPoint(0, x , y1, z2 ); _ptsB->SetPoint(1, x , y2, z2 ); } _backX=x; _backY=y; _backZ=z; } wxVtkBaseView::Refresh(); } } //------------------------------------------------------------------- int wxVtkMPR2DView::GetActualSlice() // virtual { int result; if (_direction==0) { result = (int)(GetVtkmprbasedata()->GetX()); } if (_direction==1) { result = (int)(GetVtkmprbasedata()->GetY()); } if (_direction==2) { result = (int)(GetVtkmprbasedata()->GetZ()); } return result; } //------------------------------------------------------------------- void wxVtkMPR2DView::SetActualSlice(int slice) // virtual { if (_direction==0) { GetVtkmprbasedata()->SetX(slice); } if (_direction==1) { GetVtkmprbasedata()->SetY(slice); } if (_direction==2) { GetVtkmprbasedata()->SetZ(slice); } } //------------------------------------------------------------------- bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z) { double delta=5; bool result=false; if (_direction==0) { } if (_direction==1) { if (( xGetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta )) { result = true; } } if (_direction==2) { if (( xGetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta )) { result = true; } } return result; } //------------------------------------------------------------------- bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z) { double delta=5; bool result=false; if (_direction==0) { if (( yGetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta )) { result = true; } } if (_direction==1) { } if (_direction==2) { if (( yGetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta )) { result = true; } } return result; } //------------------------------------------------------------------- bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z) { double delta=5; bool result=false; if (_direction==0) { if (( zGetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta )) { result = true; } } if (_direction==1) { if (( zGetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta )) { result = true; } } if (_direction==2) { } return result; } //------------------------------------------------------------------- void wxVtkMPR2DView::MoveX(double x, double y, double z) { if (_direction==0) { } if (_direction==1) { GetVtkmprbasedata()->SetX(x); } if (_direction==2) { GetVtkmprbasedata()->SetX(x); } } //------------------------------------------------------------------- void wxVtkMPR2DView::MoveY(double x, double y, double z) { if (_direction==0) { GetVtkmprbasedata()->SetY(y); } if (_direction==1) { } if (_direction==2) { GetVtkmprbasedata()->SetY(y); } } //------------------------------------------------------------------- void wxVtkMPR2DView::MoveZ(double x, double y, double z) { if (_direction==0) { GetVtkmprbasedata()->SetZ(z); } if (_direction==1) { GetVtkmprbasedata()->SetZ(z); } if (_direction==2) { } } //------------------------------------------------------------------- void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z) { double c1r=1,c1g=1,c1b=0; double c2r=1,c2g=0,c2b=0; if (_direction==0) { if (IfMouseTouchY(x,y,z)==true) { _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b); } else { _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b); } if (IfMouseTouchZ(x,y,z)==true) { _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b); } else { _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b); } } if (_direction==1) { if (IfMouseTouchX(x,y,z)==true) { _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b); } else { _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b); } if (IfMouseTouchZ(x,y,z)==true) { _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b); } else { _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b); } } if (_direction==2) { if (IfMouseTouchX(x,y,z)==true) { _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b); } else { _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b); } if (IfMouseTouchY(x,y,z)==true) { _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b); } else { _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b); } } Refresh(); } //------------------------------------------------------------------- void wxVtkMPR2DView::TransfromeCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual { wxVtkBaseView::TransfromeCoordScreenToWorld(X,Y,Z,_direction); if (_direction==0) { X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX(); } if (_direction==1) { Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY(); } if (_direction==2) { Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ(); } } //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual // if (eventId==vtkCommand::StartInteractionEvent){ // _renWin->SetDesiredUpdateRate(10); // } // if (eventId==vtkCommand::InteractionEvent){ // _renWin->SetDesiredUpdateRate(0.001); // } // if (eventId==vtkCommand::EndInteractionEvent){ // vtkPlanes *planes = vtkPlanes::New(); // vtkBoxWidget *boxwidget = reinterpret_cast(wdg); // boxwidget->GetPlanes(planes); // _volumeMapper->SetClippingPlanes(planes); // planes -> Delete(); // } //} //------------------------------------------------------------------- //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){ // _renWin = renWin; //} //------------------------------------------------------------------- //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){ // _volumeMapper = volumeMapper; //}