From 0232d611c4bff743a627724fcf998b2d029d4c03 Mon Sep 17 00:00:00 2001 From: Julien Malik <julien.malik@c-s.fr> Date: Wed, 2 Jun 2010 17:45:01 +0200 Subject: [PATCH] BUG: Corrected the segfault when specifying wrong channel number in viewer --- .../View/otbImageViewerManagerViewGUI.cxx | 87 ++++++++----------- .../View/otbImageViewerManagerViewGroup.fl | 70 +++++++-------- 2 files changed, 71 insertions(+), 86 deletions(-) diff --git a/ViewerManager/View/otbImageViewerManagerViewGUI.cxx b/ViewerManager/View/otbImageViewerManagerViewGUI.cxx index a397d4563e..816725d7cb 100644 --- a/ViewerManager/View/otbImageViewerManagerViewGUI.cxx +++ b/ViewerManager/View/otbImageViewerManagerViewGUI.cxx @@ -759,36 +759,20 @@ ImageViewerManagerViewGUI ImageViewerManagerViewGUI ::UpdateViewerSetupWindow(unsigned int selectedItem) { - ImageViewerManagerModelType::ReaderPointerType reader = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pReader; unsigned int nbComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel(); - itk::OStringStream oss; - oss.str(""); + // Constrain min and max + guiGrayscaleChannelChoice->range(1, nbComponent); - //Clear all the choices - guiGrayscaleChannelChoice->clear(); - guiRedChannelChoice->clear(); - guiGreenChannelChoice->clear(); - guiBlueChannelChoice->clear(); - //guiGrayscaleChannelChoice->clear(); - guiRealChannelChoice->clear(); - guiImaginaryChannelChoice->clear(); + guiRedChannelChoice->range(1, nbComponent); + guiGreenChannelChoice->range(1, nbComponent); + guiBlueChannelChoice->range(1, nbComponent); + + guiRealChannelChoice->range(1, nbComponent); + guiImaginaryChannelChoice->range(1, nbComponent); - for (unsigned int i = 0;i<nbComponent;++i) - { - oss.str(""); - oss<<i+1; - guiGrayscaleChannelChoice->add(oss.str().c_str()); - guiRedChannelChoice->add(oss.str().c_str()); - guiGreenChannelChoice->add(oss.str().c_str()); - guiBlueChannelChoice->add(oss.str().c_str()); - guiGrayscaleChannelChoice->add(oss.str().c_str()); - guiRealChannelChoice->add(oss.str().c_str()); - guiImaginaryChannelChoice->add(oss.str().c_str()); - } guiViewerSetupWindow->redraw(); - //guiGrayscaleChannelChoice->redraw(); switch(nbComponent){ case 1 : @@ -818,6 +802,8 @@ ImageViewerManagerViewGUI ImageViewerManagerViewGUI ::RGBSet() { + std::cout << "RGBSet" << std::endl; + unsigned int selectedItem = guiImageList->value(); if (selectedItem == 0) { @@ -845,18 +831,19 @@ ImageViewerManagerViewGUI RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFunction; + // Get the current channel list (may have been already set by the user in case of a re-opening of the viewer) ChannelListType channels = renderingFunction->GetChannelList(); - unsigned int i=0; + + unsigned int i = 0; while (channels.size() < 3) { channels.push_back(i); ++i; } - - guiRedChannelChoice->value(std::min(channels[0],nbComponent-1)); - guiGreenChannelChoice->value(std::min(channels[1],nbComponent-1)); - guiBlueChannelChoice->value(std::min(channels[2],nbComponent-1)); + guiRedChannelChoice->value(std::min(channels[0] + 1,nbComponent)); + guiGreenChannelChoice->value(std::min(channels[1] + 1,nbComponent)); + guiBlueChannelChoice->value(std::min(channels[2] + 1,nbComponent)); } @@ -900,7 +887,7 @@ ImageViewerManagerViewGUI channels.push_back(0); } - guiGrayscaleChannelChoice->value(std::min(channels[0],nbComponent-1)); + guiGrayscaleChannelChoice->value(std::min(channels[0] + 1,nbComponent)); } @@ -941,8 +928,8 @@ ImageViewerManagerViewGUI ++i; } - guiRealChannelChoice->value(std::min(channels[0],nbComponent-1)); - guiImaginaryChannelChoice->value(std::min(channels[1],nbComponent-1)); + guiRealChannelChoice->value(std::min(channels[0] + 1,nbComponent)); + guiImaginaryChannelChoice->value(std::min(channels[1] + 1,nbComponent)); } @@ -968,37 +955,35 @@ ImageViewerManagerViewGUI { unsigned int selectedItem = guiImageList->value(); if (selectedItem == 0) - { + { // no image selected, return return; - } + } if (guiViewerSetupColorMode->value()) { - m_ImageViewerManagerController->UpdateRGBChannelOrder(atoi(guiRedChannelChoice->value())-1, - atoi(guiGreenChannelChoice->value())-1, - atoi(guiBlueChannelChoice->value())-1, - selectedItem); + int redChoice = static_cast<int>(guiRedChannelChoice->value() - 1); + int greenChoice = static_cast<int>(guiGreenChannelChoice->value() - 1); + int blueChoice = static_cast<int>(guiBlueChannelChoice->value() - 1); + m_ImageViewerManagerController->UpdateRGBChannelOrder(redChoice, greenChoice, blueChoice, selectedItem); } else if (guiViewerSetupGrayscaleMode->value()) { - m_ImageViewerManagerController->UpdateGrayScaleChannelOrder(atoi(guiGrayscaleChannelChoice->value())-1, - selectedItem); + int choice = static_cast<int>(guiGrayscaleChannelChoice->value() - 1); + m_ImageViewerManagerController->UpdateGrayScaleChannelOrder(choice, selectedItem); } else if (guiViewerSetupComplexMode->value()) { - if (bAmplitude->value()) - { - m_ImageViewerManagerController->UpdateAmplitudeChannelOrder(atoi(guiRealChannelChoice->value())-1, - atoi(guiImaginaryChannelChoice->value())-1, - selectedItem); - } + int realChoice = static_cast<int>(guiRealChannelChoice->value() - 1); + int imagChoice = static_cast<int>(guiImaginaryChannelChoice->value() - 1); + if (bAmplitude->value()) + { + m_ImageViewerManagerController->UpdateAmplitudeChannelOrder(realChoice, imagChoice, selectedItem); + } else - { - m_ImageViewerManagerController->UpdatePhaseChannelOrder(atoi(guiRealChannelChoice->value())-1, - atoi(guiImaginaryChannelChoice->value())-1, - selectedItem); - } + { + m_ImageViewerManagerController->UpdatePhaseChannelOrder(realChoice, imagChoice, selectedItem); + } } } diff --git a/ViewerManager/View/otbImageViewerManagerViewGroup.fl b/ViewerManager/View/otbImageViewerManagerViewGroup.fl index 8473cc2e2d..1456990099 100644 --- a/ViewerManager/View/otbImageViewerManagerViewGroup.fl +++ b/ViewerManager/View/otbImageViewerManagerViewGroup.fl @@ -1,9 +1,9 @@ # data file for the Fltk User Interface Designer (fluid) -version 1.0107 -i18n_type 1 -i18n_include "otbI18n.h" -i18n_function otbGetTextMacro -header_name {.h} +version 1.0109 +i18n_type 1 +i18n_include "otbI18n.h" +i18n_function otbGetTextMacro +header_name {.h} code_name {.cxx} class ImageViewerManagerViewGroup {open } { @@ -11,8 +11,8 @@ class ImageViewerManagerViewGroup {open } { Fl_Window guiMainWindow { label otbImageViewerManagerView - callback {this->Quit()} open selected - xywh {160 106 610 460} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 resizable visible + callback {this->Quit()} open + xywh {366 65 610 460} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 resizable visible } { Fl_Text_Display guiViewerInformation { label Information @@ -102,8 +102,8 @@ class ImageViewerManagerViewGroup {open } } Fl_Window guiViewerSetupWindow { - label {Viewer setup} - xywh {885 215 705 230} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 hide + label {Viewer setup} open + xywh {885 215 705 230} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 visible } { Fl_Round_Button guiViewerSetupGrayscaleMode { label {Grayscale mode} @@ -115,22 +115,22 @@ class ImageViewerManagerViewGroup {open callback {RGBSet();} tooltip {Switch the image viewer mode to RGB composition} xywh {460 17 184 24} box ROUND_UP_BOX down_box ROUND_DOWN_BOX color 23 selection_color 22 labelcolor 186 } - Fl_Input_Choice guiGrayscaleChannelChoice { - label {Channel index} open - tooltip {Select the band to view in grayscale mode} xywh {118 73 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 - } {} - Fl_Input_Choice guiRedChannelChoice { - label {Red channel} open - tooltip {Select band for red channel in RGB composition} xywh {602 51 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 deactivate - } {} - Fl_Input_Choice guiGreenChannelChoice { - label {Green channel} open - tooltip {Select band for green channel in RGB composition} xywh {602 73 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 deactivate - } {} - Fl_Input_Choice guiBlueChannelChoice { - label {Blue channel} open - tooltip {Select band for blue channel in RGB composition} xywh {602 95 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 deactivate - } {} + Fl_Spinner guiGrayscaleChannelChoice { + label {Channel index} + tooltip {Select the band to view in grayscale mode} xywh {118 73 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 value 1 + } + Fl_Spinner guiRedChannelChoice { + label {Red channel} + tooltip {Select band for red channel in RGB composition} xywh {602 51 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 value 1 deactivate + } + Fl_Spinner guiGreenChannelChoice { + label {Green channel} + tooltip {Select band for green channel in RGB composition} xywh {602 73 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 value 1 deactivate + } + Fl_Spinner guiBlueChannelChoice { + label {Blue channel} + tooltip {Select band for blue channel in RGB composition} xywh {602 95 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 value 1 deactivate + } Fl_Return_Button guiViewerSetupOk { label Ok callback {ViewerSetupOk();} @@ -150,14 +150,14 @@ class ImageViewerManagerViewGroup {open callback {ComplexSet();} tooltip {Switch the image viewer mode to complex composition} xywh {215 17 210 26} box ROUND_UP_BOX down_box ROUND_DOWN_BOX color 23 selection_color 22 labelcolor 186 } - Fl_Input_Choice guiRealChannelChoice { - label {Real channel index} open - tooltip {Select band for real channel in complex composition} xywh {375 74 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 deactivate - } {} - Fl_Input_Choice guiImaginaryChannelChoice { - label {Imaginary channel index} open - tooltip {Select band for imaginary channel in complex composition} xywh {375 96 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 deactivate - } {} + Fl_Spinner guiRealChannelChoice { + label {Real channel index} + tooltip {Select band for real channel in complex composition} xywh {375 74 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 value 1 deactivate + } + Fl_Spinner guiImaginaryChannelChoice { + label {Imaginary channel index} + tooltip {Select band for imaginary channel in complex composition} xywh {375 96 57 24} box EMBOSSED_BOX color 7 selection_color 55 labelcolor 187 value 1 deactivate + } Fl_Round_Button bAmplitude { label Amplitude callback {bPhase->clear();} @@ -229,7 +229,7 @@ class ImageViewerManagerViewGroup {open tooltip {Next image in diaporama} xywh {140 55 105 25} box ROUND_UP_BOX down_box ROUND_DOWN_BOX shortcut 0xff56 color 23 selection_color 23 labelcolor 186 } Fl_Return_Button {} { - label {Quit} + label Quit callback {DiaporamaQuit();} tooltip {Leave diaporama mode} xywh {262 55 105 25} box ROUND_UP_BOX down_box ROUND_DOWN_BOX shortcut 0xff1b color 23 selection_color 23 labelcolor 186 } @@ -286,4 +286,4 @@ class ImageViewerManagerViewGroup {open } {} Function {PackedViewMode()} {open return_type {virtual void} } {} -} +} -- GitLab