From aabf8efd83baca91f3ef0603db6e859db6f60c9f Mon Sep 17 00:00:00 2001 From: davila Date: Thu, 29 Jan 2015 16:09:30 +0100 Subject: [PATCH] #2520 creaMaracasVisu - Bug New Normal - Color Layer with double images --- .../bbcreaMaracasVisuColorLayerImageView.cxx | 2 +- .../ColorLayerImageView.cxx | 67 +++++++++---------- .../ThresholdImageView/ColorLayerImageView.h | 6 +- .../ColorLayerImageViewPanel.cxx | 27 -------- 4 files changed, 37 insertions(+), 65 deletions(-) diff --git a/bbtk/src/bbcreaMaracasVisuColorLayerImageView.cxx b/bbtk/src/bbcreaMaracasVisuColorLayerImageView.cxx index de5de6e..160795d 100644 --- a/bbtk/src/bbcreaMaracasVisuColorLayerImageView.cxx +++ b/bbtk/src/bbcreaMaracasVisuColorLayerImageView.cxx @@ -41,7 +41,7 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ColorLayerImageView,bbtk::WxBlackBox); //===== void ColorLayerImageView::Process() { - + ColorLayerImageViewPanel *clivp = (ColorLayerImageViewPanel*)bbGetOutputWidget(); clivp->SetActive( bbGetInputActive() ); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx index 50cafdd..6a6e3ad 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx @@ -82,8 +82,6 @@ void ColorLayerImageView::SetZ2(int z2) _z2 = z2; } - - //---------------------------------------------------------------------------- int ColorLayerImageView::GetX() // virtual { @@ -280,7 +278,7 @@ void ColorLayerImageView::ConfigLookupTable() // virtual SetDefaultBaseColorAndGreyLevelBoundary(); } else { // If at least one color has been set, set the grey level boundaries to build an equipartition of the image grey levels, keeping the base colors defined. - if (GetBaseColorNb() != (_grey_level_boundary.size() - 1) ) + if (GetBaseColorNb() != ((int)_grey_level_boundary.size() - 1) ) { std::cout << "CM ColorLayerImageView::ConfigLookupTable : ERROR!!! Inconsistency between the sizes of vectors _base_color and _grey_level_boundary. _base_color.size()/3 (=" <<_base_color.size()/3 << ") should be equal to _grey_level_boundary.size() - 1 (=" << _grey_level_boundary.size() - 1 << ")." << std::endl; std::cout << "CM The default values for the base colors and the grey level boundaries will be set." << std::endl; @@ -306,7 +304,8 @@ void ColorLayerImageView::ConfigLookupTable() // virtual thresholdTable->SetSaturationRange(0, 0); thresholdTable->SetRampToLinear( ); - thresholdTable->SetNumberOfTableValues(1000); + maxColorsThresholdTable = 1000; + thresholdTable->SetNumberOfTableValues( maxColorsThresholdTable ); // Defines the lookup table. @@ -317,47 +316,29 @@ void ColorLayerImageView::ConfigLookupTable() // virtual // Sets the plain color for each grey level interval. if (_color_type) { -// thresholdTable->SetNumberOfTableValues(thresholdTable_range[1] - thresholdTable_range[0] + 1); if ( minRangeGetGreyLevelBoundaries( _grey_level_boundary.size()-1 ) ) { - start = 1000*(GetGreyLevelBoundaries( _grey_level_boundary.size()-1 )-minRange) / (maxRange-minRange);; - end = 1000*(maxRange-minRange) / (maxRange-minRange); + start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries( _grey_level_boundary.size()-1 ) ); + end = GrayLevel_TO_colorTableIndex( maxRange ); FillColorTable(start,end, 0,0,0, 0,0,0); } - int delta; for (int iColor = 0; iColor < GetBaseColorNb(); iColor++) { - - start = 1000*(GetGreyLevelBoundaries(iColor)-minRange) / (maxRange-minRange); - end = 1000*(GetGreyLevelBoundaries(iColor+1)-minRange) / (maxRange-minRange); - r1 = GetBaseColors(iColor*3+0); g1 = GetBaseColors(iColor*3+1); b1 = GetBaseColors(iColor*3+2); - + start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) ); + end = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor+1) ); FillColorTable(start,end, r1,g1,b1,r1,g1,b1); - -/* - delta = GetGreyLevelBoundaries(i+1) - GetGreyLevelBoundaries(i); - for (int ii = 1; ii <= delta; ii++) - { - thresholdTable->SetTableValue(GetGreyLevelBoundaries(i) + ii, - GetBaseColors(i*3), - GetBaseColors(i*3 + 1), - GetBaseColors(i*3 + 2), - 1); - } // for ii -*/ - } // for i } // End Of if (_color_type) @@ -365,7 +346,6 @@ void ColorLayerImageView::ConfigLookupTable() // virtual else { //EED 28/01/2015 - thresholdTable->SetNumberOfTableValues(1000); if (GetBaseColorNb() > 1) { for (int iColor = 0; iColor < GetBaseColorNb(); iColor++) @@ -384,31 +364,46 @@ void ColorLayerImageView::ConfigLookupTable() // virtual r2 = GetBaseColors(iColor*3+0); g2 = GetBaseColors(iColor*3+1); b2 = GetBaseColors(iColor*3+2); - start = 1000*(GetGreyLevelBoundaries(iColor)-minRange) / (maxRange-minRange); - end = 1000*(GetGreyLevelBoundaries(iColor+1)-minRange) / (maxRange-minRange); - FillColorTable(start,end, r1,g1,b1,r2,g2,b2); + start = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor) ); + end = GrayLevel_TO_colorTableIndex( GetGreyLevelBoundaries(iColor+1) ); + FillColorTable( start,end, r1,g1,b1, r2,g2,b2 ); }// for } //if } // End Of if (!_color_type) + thresholdTable->SetRange( minRange, maxRange ); + thresholdTable->SetValueRange( 0.0, 1.0 ); + thresholdTable->Build( ); //EO CM EED } +//---------------------------------------------------------------------------- +int ColorLayerImageView::GrayLevel_TO_colorTableIndex( double VALUE ) +{ + GetImage()->GetScalarRange(_range); + double minRange = _range[0]; + double maxRange = _range[1]; + return maxColorsThresholdTable * (VALUE-minRange) / (maxRange-minRange); +} +//---------------------------------------------------------------------------- void ColorLayerImageView::FillColorTable(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2) { vtkLookupTable* thresholdTable = GetThresholdTable(); - int iTable; - double delta = end-start; - double dr = (r2-r1)/delta; - double dg = (g2-g1)/delta; - double db = (b2-b1)/delta; + int iTable; + double delta = end-start; + double dr = (r2-r1)/delta; + double dg = (g2-g1)/delta; + double db = (b2-b1)/delta; for (iTable=0; iTable<=delta; iTable++) { thresholdTable->SetTableValue( iTable+start , r1+dr*iTable, g1+dg*iTable, b1+db*iTable,1); } // for iTable + + if (start==0) thresholdTable->SetTableValue( start , r1, g1, b1,0); // The first color in the table is transparent + } // EOF diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h index 6d18f93..75c6e1a 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h @@ -92,7 +92,9 @@ class ColorLayerImageView : public LayerImageBase int GetBaseColorNb(); - void FillColorTable(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2); + void FillColorTable(int start, int end, double r1, double g1, double b1, double r2, double g2, double b2); + + int GrayLevel_TO_colorTableIndex( double VALUE ); private: @@ -102,6 +104,8 @@ class ColorLayerImageView : public LayerImageBase void SetDefaultGreyLevelBoundary(); void SetDefaultBaseColorAndGreyLevelBoundary(); virtual void ConfigLookupTable(); + int maxColorsThresholdTable; + //! Range values in the colored image. double _range[2]; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx index 1477a0c..d6efc91 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx @@ -59,7 +59,6 @@ void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *paren wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 3 , lstOptOperation, 3, wxRA_SPECIFY_COLS); dialSizer->Add( new wxStaticText(dial,-1,message) , 0, wxGROW ); - // dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW ); dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW ); dialSizer->Add(radioOpts,0,wxGROW); dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW ); @@ -90,12 +89,10 @@ void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *paren ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type) : wxPanel(parent, -1, wxDefaultPosition, wxSize(600,100), wxBORDER_SUNKEN) { - printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel start \n"); _spcBase[0] = _spcBase[1] = _spcBase[2] = 0; _dimBase[0] = _dimBase[1] = _dimBase[2] = 0; -//EED01 _colorLayerImageView = new ColorLayerImageView(); _colorLayerImageViewManager = new ColorLayerImageViewManager(); _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") ); @@ -268,9 +265,6 @@ void ColorLayerImageViewPanel::SetImage(vtkImageData *img) else typeOfTransformation = _fitting_mode; //EO CM - - printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n"); - if (typeOfTransformation==1) // make dimensions equals { printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n"); @@ -296,15 +290,11 @@ void ColorLayerImageViewPanel::SetImage(vtkImageData *img) img->SetSpacing(spc); } // spc !_spcBase dim!__dimBase -//EED01 if (_colorLayerImageView!=NULL) -//EED01 { -//EED01 _colorLayerImageView->onThreshold(); if (_active==true) { _colorLayerImageViewManager->onThreshold(); RefreshView(); } -//EED01 } } @@ -352,59 +342,42 @@ void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event) //---------------------------------------------------------------------------- void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event) { -//EED01 if (_colorLayerImageView!=NULL) -//EED01 { if (_thresholdGo) { -//EED01 _colorLayerImageView->onThresholdChange(); _colorLayerImageViewManager->onThresholdChange(); RefreshView(); //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl; } // _thresholdGo -//EED01 }//_colorLayerImageView } //---------------------------------------------------------------------------- void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event) { -//EED01 if (_colorLayerImageView!=NULL) -//EED01 { _thresholdGo = _cb_ShowHide->GetValue(); if (_thresholdGo) { -//EED01 _colorLayerImageView->onThreshold(); _colorLayerImageViewManager->onThreshold(); }else{ -//EED01 _colorLayerImageView->onThresholdRemove( ); _colorLayerImageViewManager->onThresholdRemove( ); } RefreshView(); -//EED01 }//_colorLayerImageView } //---------------------------------------------------------------------------- void ColorLayerImageViewPanel::onThresholdStop() { -//EED01 if (_colorLayerImageView!=NULL) -//EED01 { if (_thresholdGo) { -//EED01 _colorLayerImageView->onThresholdRemove( ); _colorLayerImageViewManager->onThresholdRemove( ); _thresholdGo=false; } -//EED01 }//_colorLayerImageView } //---------------------------------------------------------------------------- void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event) { -//EED01 if (_colorLayerImageView!=NULL) -//EED01 { -//EED01 _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue()); _colorLayerImageViewManager->onThresholdInterpolation(_interpolationCheckBox->GetValue()); RefreshView(); -//EED01 }//_colorLayerImageView } //---------------------------------------------------------------------------- -- 2.45.0