#include #include #include #include #include #include #include #include #include "wxMPRBaseData.h" #include "pPlotter/HistogramDialog.h" //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- vtkBaseData::vtkBaseData() { _z = 0; _t = 0; _marImageData = NULL; } //------------------------------------------------------------------- vtkBaseData::~vtkBaseData() { } //------------------------------------------------------------------- void vtkBaseData::SetMarImageData(marImageData *marimagedata) { _marImageData = marimagedata; //Configure(); } //------------------------------------------------------------------- vtkImageData* vtkBaseData::GetImageData() { return _marImageData->GetImageDataT(_t); } //------------------------------------------------------------------- marImageData* vtkBaseData::GetMarImageData() { return _marImageData; } //------------------------------------------------------------------- void vtkBaseData::Configure() // virtual { } //------------------------------------------------------------------- void vtkBaseData::SetZ(double z){ //int maxZ; // int dim[3]; // _marImageData->GetDimensions(dim); // maxZ=dim[2]; int ext[6]; vtkImageData* img = _marImageData->GetImageData(); if(img!=NULL){ /*img->GetWholeExtent(ext); maxZ=ext[5]-ext[4]+1; if (z>=maxZ) { //z=maxZ-1; } if (z<=0) { z=0; } _z=z;*/ img->GetExtent(ext); if (z > ext[5]) { z = ext[5]; } if (z < ext[4]) { z = ext[4]; } _z=z; } } //------------------------------------------------------------------- double vtkBaseData::GetZ() { return _z; } //------------------------------------------------------------------- int vtkBaseData::GetT() { return _t; } //------------------------------------------------------------------- void vtkBaseData::SetT(double t) { int maxT = _marImageData->GetMaxT(); if (t>=maxT) { t=maxT-1; } if (t<=0) { t=0; } _t=(int)t; } //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- vtkMPRBaseData::vtkMPRBaseData() { _x=0; _y=0; _z=0; _transformOrientation = NULL; _marImageData = NULL; } //------------------------------------------------------------------- vtkMPRBaseData::~vtkMPRBaseData() { if (_marImageData) delete _marImageData; if (_transformOrientation) _transformOrientation ->Delete(); } //------------------------------------------------------------------- void vtkMPRBaseData::Configure() { vtkImageData* img = _marImageData->GetImageData(); if(img !=NULL){ img->GetExtent (_x1,_x2,_y1,_y2,_z1,_z2); //std::cout<<"vtkMPRBaseData::Configure() _x1= "<<_x1<<" _x2= "<<_x2<<" _y1= "<<_y1<<" _y2= "<<_y2<<" _z1= "<<_z1<<" _z2= "<<_z2<Identity(); } } //------------------------------------------------------------------- void vtkMPRBaseData::GetDimensionExtention(int *x1,int *x2,int *y1,int *y2,int *z1,int *z2) { *x1=_x1; *x2=_x2; *y1=_y1; *y2=_y2; *z1=_z1; *z2=_z2; } //------------------------------------------------------------------------ int vtkMPRBaseData::GetMaxPositionX( ) { return _x2; } //------------------------------------------------------------------------ int vtkMPRBaseData::GetMaxPositionY( ) { return _y2; } //------------------------------------------------------------------------ int vtkMPRBaseData::GetMaxPositionZ( ) { return _z2; } //------------------------------------------------------------------- double vtkMPRBaseData::GetX() { return _x; } //------------------------------------------------------------------- double vtkMPRBaseData::GetY() { return _y; } //------------------------------------------------------------------- /** ** Calculates the value of the slider and the layer in the image that is spouse to show **/ void vtkMPRBaseData::SetX(double x) { //int dim[3]; int ext[6]; vtkImageData* img = _marImageData->GetImageData(); if(img!=NULL){ /*img->GetDimensions(dim); if (x<0) { x=0; } if (x>=dim[0]) { x=dim[0]-1; } _x=x;*/ img->GetExtent(ext); if (x < ext[0]) { x=ext[0]; } if (x > ext[1]) { x=ext[1]; } _x=x; } } //------------------------------------------------------------------- /** ** Calculates the value of the slider and the layer in the image that is spouse to show **/ void vtkMPRBaseData::SetY(double y) { //int dim[3]; int ext[6]; vtkImageData* img = _marImageData->GetImageData(); if(img!=NULL){ /*img->GetDimensions(dim); if (y<0) { y=0; } if (y>=dim[1]) { y=dim[1]-1; } _y=y;*/ img->GetExtent(ext); if (y ext[3]) { y=ext[3]; } _y=y; } } //------------------------------------------------------------------- vtkTransform *vtkMPRBaseData::GetTransformOrientation() { return _transformOrientation; } //------------------------------------------------------------------- void vtkMPRBaseData::SetNormal(double nx, double ny, double nz) { double alfa = atan2(ny,nx) * 180.0 / 3.1416; double beta = atan2( nz, sqrt( nx*nx + ny*ny ) ) * 180.0 / 3.1416; _transformOrientation->Identity(); _transformOrientation->RotateWXYZ(alfa,0,0,1); _transformOrientation->RotateWXYZ(-beta,0,1,0); } //------------------------------------------------------------------- void vtkMPRBaseData::InitTransformOrientation(vtkTransform *trans) { _transformOrientation->SetMatrix( trans->GetMatrix() ); } //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- vtkMPR3DDataViewer::vtkMPR3DDataViewer() { _visiblePosition[0]=false; _visiblePosition[1]=false; _visiblePosition[2]=false; _ctfun = NULL; _vtkmprbasedata=NULL; _ctfun=NULL; _saggitalColors=NULL; _saggital=NULL; _axialColors=NULL; _axial=NULL; _coronalColors=NULL; _coronal=NULL; _mapOutline=NULL; _outline=NULL; _outlineData=NULL; } //------------------------------------------------------------------- vtkMPR3DDataViewer::~vtkMPR3DDataViewer() { _outlineData -> Delete(); _mapOutline -> Delete(); _outline -> Delete(); // if (_bwLut) _bwLut -> Delete(); // if (_hueLut) _hueLut -> Delete(); // if (_satLut) _satLut -> Delete(); if (_ctfun) _ctfun -> Delete(); if (_saggitalColors) _saggitalColors -> Delete(); if (_saggital) _saggital -> Delete(); if (_axialColors) _axialColors -> Delete(); if (_axial) _axial -> Delete(); if (_coronalColors) _coronalColors -> Delete(); if (_coronal) _coronal -> Delete(); } //------------------------------------------------------------------- vtkActor* vtkMPR3DDataViewer::GetOutlineActor() { return _outline; } //------------------------------------------------------------------- vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id) { vtkImageActor *tmpVtkActor=NULL; if (id==0){ tmpVtkActor = GetvtkActor_saggital(); } if (id==1){ tmpVtkActor = GetvtkActor_coronal(); } if (id==2){ tmpVtkActor = GetvtkActor_axial(); } return tmpVtkActor; } //------------------------------------------------------------------- void vtkMPR3DDataViewer::Refresh() { int x = (int)(_vtkmprbasedata->GetX()); int y = (int)(_vtkmprbasedata->GetY()); int z = (int)(_vtkmprbasedata->GetZ()); std::cout<<" vtkMPR3DDataViewer::Refresh() x="<greyValuesTransferenceFVector.size(); if(tfSize>0) { int i=0,y; hDlg->erasePointsTransferenceFunction(); while(iaddPointToTransferenceFunction(g,in*100); i++; } } int ctfSize=this->redColorsOfColorTransferenceFVector.size(); if(ctfSize>0) { int i=0,y; while(iaddColorPoint(gr,r*255,g*255,b*255); i++; } } //If it is smooth activate next line //hDlg->updatePlotter(); //setting variables if the user wants to do refresh hDlg->setCTF(_ctfun); hDlg->setTF(_tfun); // // when the user had changed the transference Function // if(hDlg->ShowModal()== wxID_OK ) { // -- vtkPiecewiseFunction -- this->_tfun->RemoveAllPoints(); greyValuesTransferenceFVector.clear(); intensityValuesTransferenceFVector.clear(); int nTFPoints=hDlg->getSizeTransferenceFunction(); i=0; while(igetTransferenceFunctionPoint(i,xi,yi); this->_tfun->AddPoint( xi , yi/100.0 ); greyValuesTransferenceFVector.push_back(xi); intensityValuesTransferenceFVector.push_back(yi/100.0); i++; } // -- vtkColorTransferFunction -- this->_ctfun->RemoveAllPoints (); //clean colors redColorsOfColorTransferenceFVector.clear(); greenColorsOfColorTransferenceFVector.clear(); blueColorsOfColorTransferenceFVector.clear(); greyValueColorsOfColorTransferenceFVector.clear(); int nCTFpoints=hDlg->getSizeBarColor(); i=0; while(igetDataBarColorPoint(i,xi,r,g,b); this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 ); redColorsOfColorTransferenceFVector.push_back(r/255.0); greenColorsOfColorTransferenceFVector.push_back(g/255.0); blueColorsOfColorTransferenceFVector.push_back(b/255.0); greyValueColorsOfColorTransferenceFVector.push_back(xi); i++; } this->_volumeMapper->Update(); this->_newvol->Update(); } else { if(hDlg->getRefreshed()) { int i=0,size; //--Transference Function---- this->_tfun->RemoveAllPoints(); i=0; size=greyValuesTransferenceFVector.size(); for(i=0;i_tfun->AddPoint( grey1 , in2 ); } // -- vtkColorTransferFunction -- _ctfun->RemoveAllPoints (); i=0; size=greyValueColorsOfColorTransferenceFVector.size(); for(i=0;iAddRGBPoint(grey2,red,green,blue); } this->_volumeMapper->Update(); this->_newvol->Update(); } } hDlg->Destroy(); */ } /* void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile) { char tmp[256]; short int max; double range[2]; double x,val,r,g,b; FILE *ff = fopen ( namefile ,"r"); // -- MAX -- fscanf(ff,"%s",tmp); if (strcmp(tmp,"MAX")==0) { vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData(); vtkimagedata->GetScalarRange(range); max = (int) (range[1]); } else { max = atoi(tmp); } fscanf(ff,"%s",tmp); // -- // -- vtkPiecewiseFunction -- this->_tfun->RemoveAllPoints(); fscanf(ff,"%s",tmp); while ( strcmp(tmp,"--")!=0 ) { x=atof(tmp); fscanf(ff,"%s",tmp); val=atof(tmp); this->_tfun->AddPoint( x*max , val ); fscanf(ff,"%s",tmp); } this->_ctfun->RemoveAllPoints (); // -- vtkColorTransferFunction -- while ( !feof(ff)) { fscanf(ff,"%s",tmp); x=atof(tmp); fscanf(ff,"%s",tmp); r=atof(tmp); fscanf(ff,"%s",tmp); g=atof(tmp); fscanf(ff,"%s",tmp); b=atof(tmp); this->_ctfun->AddRGBPoint( x*max , r,g,b ); } this->_volumeMapper->Update(); this->_newvol->Update(); fclose(ff); } */ //------------------------------------------------------------------- // EED 23 Mai 2007 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile) { vtkDataSetReader *reader = vtkDataSetReader::New(); reader->SetFileName(namefile); reader->Update(); _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() ); }