From 6e940f8b87d85a90438f01d56c3c6c92da2bc14a Mon Sep 17 00:00:00 2001 From: Juan Prieto Date: Mon, 27 Jul 2009 07:58:19 +0000 Subject: [PATCH] ViewerNV 2D with color Transfer Function --- bbtk/src/bbmaracasvisuShowNPoints.cxx | 12 ++- .../src/bbmaracasvisuTransferFunctionView.cxx | 3 + bbtk/src/bbmaracasvisuViewerNV.cxx | 9 +- bbtk/src/bbmaracasvisuViewerNV.h | 2 + .../wxWindows/widgets/vtkImageViewer2_XYZ.cxx | 12 ++- .../wxWindows/widgets/vtkImageViewer2_XYZ.h | 4 + .../widgets/wxMaracas_N_ViewersWidget.cxx | 18 +++- .../widgets/wxMaracas_N_ViewersWidget.h | 6 +- .../widgets/wxMaracas_ViewerWidget.cxx | 15 ++- .../widgets/wxMaracas_ViewerWidget.h | 5 +- .../wxWindows/widgets/wxVtk2DBaseView.cxx | 5 + .../wxWindows/widgets/wxVtk2DBaseView.h | 1 + .../wxWindows/widgets/wxVtkMPR2DView.cxx | 96 ++++++++++--------- 13 files changed, 132 insertions(+), 56 deletions(-) diff --git a/bbtk/src/bbmaracasvisuShowNPoints.cxx b/bbtk/src/bbmaracasvisuShowNPoints.cxx index 1a1b2c6..6b35fe3 100644 --- a/bbtk/src/bbmaracasvisuShowNPoints.cxx +++ b/bbtk/src/bbmaracasvisuShowNPoints.cxx @@ -161,12 +161,22 @@ void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label) sphereActor->SetMapper(sphereMapper); sphereActor->SetOrigin(0, 0, 0); double spc[3]; + if(mimage==NULL){ + wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR); + dialog.ShowModal(); + return; + } mimage->GetSpacing(spc); sphereActor->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z ); sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] ); sphereActor->GetProperty()->SetOpacity( mopacity ); lstActorsSphere.push_back(sphereActor); + if(renderer==NULL){ + wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR); + dialog.ShowModal(); + return; + } renderer->AddActor( sphereActor ); // Actor @@ -432,7 +442,7 @@ void ShowNPoints::bbUserSetDefaultValues() { mwxwidget = NULL; - bbSetInputRadio(0.5); + bbSetInputRadio(1); bbSetInputOpacity(1); std::vector colour; diff --git a/bbtk/src/bbmaracasvisuTransferFunctionView.cxx b/bbtk/src/bbmaracasvisuTransferFunctionView.cxx index 137f82b..fb08960 100644 --- a/bbtk/src/bbmaracasvisuTransferFunctionView.cxx +++ b/bbtk/src/bbmaracasvisuTransferFunctionView.cxx @@ -80,6 +80,9 @@ void TransferFunctionView::bbUserSetDefaultValues() _tfun = NULL; _ctfun = NULL; + bbSetOutputOpacityFunction(0); + bbSetOutputColorFunction(0); + } diff --git a/bbtk/src/bbmaracasvisuViewerNV.cxx b/bbtk/src/bbmaracasvisuViewerNV.cxx index 4dfa24f..ae65750 100644 --- a/bbtk/src/bbmaracasvisuViewerNV.cxx +++ b/bbtk/src/bbmaracasvisuViewerNV.cxx @@ -72,11 +72,11 @@ void ViewerNV::Process() if(!compareVectors(type, currenttype)){ mwxwidget->SetType(&type); - mwxwidget->UpdateLayout(img); + mwxwidget->UpdateLayout(img); }else if (img != currentimg){ mwxwidget->SetImage(img); //mwxwidget->UpdateLayout(img); - } + } currenttype = type; currentimg = img; @@ -104,6 +104,10 @@ void ViewerNV::Process() if (wvbv2!=NULL) { bbSetOutputRenderer2( wvbv2->GetRenderer() ); } if (wvbv3!=NULL) { bbSetOutputRenderer3( wvbv3->GetRenderer() ); } if (wvbv4!=NULL) { bbSetOutputRenderer4( wvbv4->GetRenderer() ); } + + if(bbGetInputColorFunction()!=NULL){ + mwxwidget->setColorTransferFunction(bbGetInputColorFunction()); + } } } @@ -144,6 +148,7 @@ void ViewerNV::bbUserSetDefaultValues() bbSetOutputRenderer2( NULL ); bbSetOutputRenderer3( NULL ); bbSetOutputRenderer4( NULL ); + bbSetInputColorFunction(NULL); } //----------------------------------------------------------------- diff --git a/bbtk/src/bbmaracasvisuViewerNV.h b/bbtk/src/bbmaracasvisuViewerNV.h index e92aa73..51d24a3 100644 --- a/bbtk/src/bbmaracasvisuViewerNV.h +++ b/bbtk/src/bbmaracasvisuViewerNV.h @@ -46,6 +46,7 @@ class /*BBTK_EXPORT*/ ViewerNV BBTK_DECLARE_INPUT(Title,std::string); BBTK_DECLARE_INPUT(In, vtkImageData *); BBTK_DECLARE_INPUT(nTypeView, std::vector ); + BBTK_DECLARE_INPUT(ColorFunction, vtkColorTransferFunction* ); BBTK_DECLARE_OUTPUT(wxVtkBaseView1,wxVtkBaseView*); BBTK_DECLARE_OUTPUT(wxVtkBaseView2,wxVtkBaseView*); BBTK_DECLARE_OUTPUT(wxVtkBaseView3,wxVtkBaseView*); @@ -79,6 +80,7 @@ BBTK_DESCRIPTION("Viewer : N view configuration 2D and 3D"); BBTK_INPUT(ViewerNV,Title,"Title prepended to the text",std::string,""); BBTK_INPUT(ViewerNV,In,"Input image",vtkImageData*,""); BBTK_INPUT(ViewerNV,nTypeView,"vector of viewer types (default 5 0 1 3 ): -1=Z_2DwithOutAxis 0=Z_2D 1=X_2D 2=Y_2D 3=Plane 4=Sphere 5=3D 6=3Dplane",std::vector,""); + BBTK_INPUT(ViewerNV,ColorFunction,"Optional: set a different color for the viewers 2D",vtkColorTransferFunction*,""); BBTK_OUTPUT(ViewerNV,wxVtkBaseView1,"wxVtkBaseView 1",wxVtkBaseView *,""); BBTK_OUTPUT(ViewerNV,wxVtkBaseView2,"wxVtkBaseView 2",wxVtkBaseView *,""); BBTK_OUTPUT(ViewerNV,wxVtkBaseView3,"wxVtkBaseView 3",wxVtkBaseView *,""); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.cxx index dc98f55..c692f96 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.cxx @@ -9,7 +9,7 @@ vtkImageViewer2_XYZ::vtkImageViewer2_XYZ() _vtkimageviewer2= vtkImageViewer2::New(); _vtkimageviewer2->GetRenderer()->GradientBackgroundOn(); _vtkimageviewer2->GetRenderer()->SetBackground( 0.33 , 0.33 , 0.33 ); - _vtkimageviewer2->GetRenderer()->SetBackground2( 0.66 , 0.66 , 0.66 ); + _vtkimageviewer2->GetRenderer()->SetBackground2( 0.66 , 0.66 , 0.66 ); } //------------------------------------------------------------------- vtkImageViewer2_XYZ::~vtkImageViewer2_XYZ() @@ -84,3 +84,13 @@ vtkImageViewer2 *vtkImageViewer2_XYZ::GetVtkImageViewer2() { return _vtkimageviewer2; } + +void vtkImageViewer2_XYZ::setColorTransferFunction(vtkColorTransferFunction* colortable){ + + vtkImageMapToWindowLevelColors* imagemaptowindowlevel = _vtkimageviewer2->GetWindowLevel(); + + if(colortable!=NULL&&colortable->GetSize()>0){ + imagemaptowindowlevel->SetLookupTable(colortable); + } + +} diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.h index ebac223..472ac9b 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.h @@ -7,6 +7,8 @@ //------------------------------------------------------------------ #include "marTypes.h" #include "vtkImageViewer2.h" +#include "vtkImageMapToWindowLevelColors.h" +#include "vtkColorTransferFunction.h" class creaMaracasVisu_EXPORT vtkImageViewer2_XYZ{ public: @@ -22,6 +24,8 @@ public: int GetZSlice(); vtkImageViewer2 *GetVtkImageViewer2(); + void setColorTransferFunction(vtkColorTransferFunction* colortable); + private: int _x1,_x2,_y1,_y2,_z1,_z2; vtkImageViewer2 *_vtkimageviewer2; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx index 4ad8c77..3cfdc1a 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $ Language: C++ - Date: $Date: 2009/06/05 06:07:39 $ - Version: $Revision: 1.10 $ + Date: $Date: 2009/07/27 07:58:20 $ + Version: $Revision: 1.11 $ Copyright: (c) 2002, 2003 License: @@ -282,4 +282,18 @@ double wxMaracas_N_ViewersWidget :: GetZ() // return wxwindow1->GetZ(); } +void wxMaracas_N_ViewersWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){ + if (wxwindow1!=NULL) { + wxwindow1->setColorTransferFunction(colortable); + } + if (wxwindow2!=NULL) { + wxwindow2->setColorTransferFunction(colortable); + } + if (wxwindow3!=NULL) { + wxwindow3->setColorTransferFunction(colortable); + } + if (wxwindow4!=NULL) { + wxwindow4->setColorTransferFunction(colortable); + } +} diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h index 2efb923..67a0e0c 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracas_N_ViewersWidget.h,v $ Language: C++ - Date: $Date: 2009/06/05 06:07:39 $ - Version: $Revision: 1.6 $ + Date: $Date: 2009/07/27 07:58:20 $ + Version: $Revision: 1.7 $ Copyright: (c) 2002, 2003 License: @@ -78,6 +78,8 @@ class creaMaracasVisu_EXPORT wxMaracas_N_ViewersWidget : public wxPanel double GetY(); double GetZ(); + void setColorTransferFunction(vtkColorTransferFunction* colortable); + //------------------------------------------------------------------------------------------------------------ // Attributes //------------------------------------------------------------------------------------------------------------ diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.cxx index c6d2e89..7e68a75 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.cxx @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracas_ViewerWidget.cxx,v $ Language: C++ - Date: $Date: 2009/06/22 10:31:44 $ - Version: $Revision: 1.14 $ + Date: $Date: 2009/07/27 07:58:20 $ + Version: $Revision: 1.15 $ Copyright: (c) 2002, 2003 License: @@ -387,3 +387,14 @@ // return mvtk2Dbaseview->GetVtkBaseData()->GetZ(); } + void wxMaracas_ViewerWidget::setColorTransferFunction(vtkColorTransferFunction* colortable){ + if(mvtkmpr2Dview_X!=NULL){ + mvtkmpr2Dview_X->setColorTransferFunction(colortable); + } + if(mvtkmpr2Dview_Y!=NULL){ + mvtkmpr2Dview_Y->setColorTransferFunction(colortable); + } + if(mvtkmpr2Dview_Z!=NULL){ + mvtkmpr2Dview_Z->setColorTransferFunction(colortable); + } + } \ No newline at end of file diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.h index caa733e..77a37ed 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_ViewerWidget.h @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracas_ViewerWidget.h,v $ Language: C++ - Date: $Date: 2009/06/05 06:07:39 $ - Version: $Revision: 1.6 $ + Date: $Date: 2009/07/27 07:58:20 $ + Version: $Revision: 1.7 $ Copyright: (c) 2002, 2003 License: @@ -76,6 +76,7 @@ // Attributes //------------------------------------------------------------------------------------------------------------ + void setColorTransferFunction(vtkColorTransferFunction* colortable); private: int mType; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx index 45a387a..a7a406b 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx @@ -241,3 +241,8 @@ void wxVtk2DBaseView::GetSpacing(double spc[3]) // virtual imageData->GetSpacing(spc); } +void wxVtk2DBaseView::setColorTransferFunction(vtkColorTransferFunction* colortable){ + if(_imageViewer2XYZ!=NULL){ + _imageViewer2XYZ->setColorTransferFunction(colortable); + } +} diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.h index 7494012..7ceccfb 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.h @@ -34,6 +34,7 @@ public: virtual void TransformCoordinate_spacing_ModelToView(double &X,double &Y, double &Z); virtual void GetSpacing(double spc[3]); + void setColorTransferFunction(vtkColorTransferFunction* colortable); private: vtkBaseData *_vtkbasedata; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx index 0ec8f0d..2163d69 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx @@ -63,52 +63,60 @@ void wxVtkMPR2DView::Configure(){ _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 ); + if(_lineAActor==NULL){ + _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 ); + if(_lineBActor==NULL){ + _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(); -- 2.46.0