From a7a4faf8fc3a02c189f6867c05e81a4e6ef610b4 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Fri, 26 Jun 2009 16:57:23 +0800 Subject: [PATCH] ENH: remove the static_cast on the rendering function --- .../Model/otbImageViewerManagerModel.cxx | 49 ++++++++------- .../View/otbImageViewerManagerViewGUI.cxx | 62 +++++++++++++------ .../View/otbImageViewerManagerViewGUI.h | 2 +- 3 files changed, 72 insertions(+), 41 deletions(-) diff --git a/ViewerManager/Model/otbImageViewerManagerModel.cxx b/ViewerManager/Model/otbImageViewerManagerModel.cxx index 00969a210f..49c4fb74cc 100644 --- a/ViewerManager/Model/otbImageViewerManagerModel.cxx +++ b/ViewerManager/Model/otbImageViewerManagerModel.cxx @@ -208,20 +208,23 @@ void ImageViewerManagerModel ::UpdateRGBChannelOrder(int redChoice , int greenChoice, int blueChoice, unsigned int selectedItem) { -// RenderingFunctionType::Pointer renderFunction = m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion; - //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType -// StandardRenderingFunctionType::Pointer renderFunction = static_cast<StandardRenderingFunctionType*>(m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion.GetPointer()); + + StandardRenderingFunctionType::ChannelListType channels; + channels.resize(3); + channels[0]=redChoice; + channels[1]=greenChoice; + channels[2]=blueChoice; + StandardRenderingFunctionType::Pointer renderFunction; renderFunction = StandardRenderingFunctionType::New(); - renderFunction->GetPixelRepresentationFunction().SetChannelIndex(0,redChoice); - renderFunction->GetPixelRepresentationFunction().SetChannelIndex(1,greenChoice); - renderFunction->GetPixelRepresentationFunction().SetChannelIndex(2,blueChoice); + renderFunction->SetChannelList(channels); + //Update the layer m_ObjectTrackedList.at(selectedItem-1).pLayer->SetRenderingFunction(renderFunction); m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion = renderFunction; - renderFunction->Initialize();//FIXME Initialize() should disappear from the renderinFunction + renderFunction->Initialize();//FIXME Initialize() should disappear from the renderingFunction m_ObjectTrackedList.at(selectedItem-1).pRendering->Update(); //Notify @@ -234,18 +237,19 @@ void ImageViewerManagerModel ::UpdateGrayScaleChannelOrder(int choice, unsigned int selectedItem) { -// RenderingFunctionType::Pointer renderFunction = m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion; - //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType -// StandardRenderingFunctionType::Pointer renderFunction = static_cast<StandardRenderingFunctionType*>(m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion.GetPointer()); + StandardRenderingFunctionType::ChannelListType channels; + channels.resize(3); + channels[0]=choice; + StandardRenderingFunctionType::Pointer renderFunction; renderFunction = StandardRenderingFunctionType::New(); - renderFunction->GetPixelRepresentationFunction().SetAllChannels(choice); + renderFunction->SetChannelList(channels); //Update the layer m_ObjectTrackedList.at(selectedItem-1).pLayer->SetRenderingFunction(renderFunction); m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion = renderFunction; - renderFunction->Initialize();//FIXME Initialize() should disappear from the renderinFunction + renderFunction->Initialize();//FIXME Initialize() should disappear from the renderingFunction m_ObjectTrackedList.at(selectedItem-1).pRendering->Update(); //Notify @@ -258,14 +262,14 @@ void ImageViewerManagerModel ::UpdateModulusChannelOrder(int realChoice , int imChoice, unsigned int selectedItem ) { - ModulusRenderingFunction::Pointer modulusFunction; - modulusFunction = ModulusRenderingFunction::New(); - - ModulusRenderingFunction::PixelRepresentationFunctionType::ChannelListType channels; channels.push_back(realChoice); channels.push_back(imChoice); - modulusFunction->GetPixelRepresentationFunction().SetChannelList(channels); + + ModulusRenderingFunction::Pointer modulusFunction; + modulusFunction = ModulusRenderingFunction::New(); + + modulusFunction->SetChannelList(channels); //Update the layer @@ -285,13 +289,16 @@ void ImageViewerManagerModel ::UpdatePhaseChannelOrder(int realChoice , int imChoice, unsigned int selectedItem ) { - PhaseRenderingFunction::Pointer phaseFunction; - phaseFunction = PhaseRenderingFunction::New(); - PhaseRenderingFunction::PixelRepresentationFunctionType::ChannelListType channels; channels.push_back(realChoice); channels.push_back(imChoice); - phaseFunction->GetPixelRepresentationFunction().SetChannelList(channels); + + PhaseRenderingFunction::Pointer phaseFunction; + phaseFunction = PhaseRenderingFunction::New(); + + phaseFunction->SetChannelList(channels); + + //Update the layer m_ObjectTrackedList.at(selectedItem-1).pLayer->SetRenderingFunction(phaseFunction); diff --git a/ViewerManager/View/otbImageViewerManagerViewGUI.cxx b/ViewerManager/View/otbImageViewerManagerViewGUI.cxx index 274cf672a1..66a5dcd259 100644 --- a/ViewerManager/View/otbImageViewerManagerViewGUI.cxx +++ b/ViewerManager/View/otbImageViewerManagerViewGUI.cxx @@ -824,10 +824,6 @@ ImageViewerManagerViewGUI ImageViewerManagerModelType::ReaderPointerType reader = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pReader; unsigned int nbComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel(); - //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType - assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); - StandardRenderingFunctionType::Pointer renderingFunction = static_cast<StandardRenderingFunctionType*>(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); - guiViewerSetupColorMode->set(); guiViewerSetupComplexMode->clear(); guiViewerSetupGrayscaleMode->clear(); @@ -841,10 +837,22 @@ ImageViewerManagerViewGUI guiGreenChannelChoice->activate(); guiBlueChannelChoice->activate(); - assert(renderingFunction); - guiRedChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetRedChannelIndex(),nbComponent-1)); - guiGreenChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetGreenChannelIndex(),nbComponent-1)); - guiBlueChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetBlueChannelIndex(),nbComponent-1)); + assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); + + RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion; + + ChannelListType channels = renderingFunction->GetChannelList(); + 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)); } @@ -864,10 +872,6 @@ ImageViewerManagerViewGUI ImageViewerManagerModelType::ReaderPointerType reader = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pReader; unsigned int nbComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel(); -// RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion; - //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType - StandardRenderingFunctionType::Pointer renderingFunction = static_cast<StandardRenderingFunctionType*>(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); - guiViewerSetupGrayscaleMode->set(); guiViewerSetupComplexMode->clear(); guiViewerSetupColorMode->clear(); @@ -881,7 +885,18 @@ ImageViewerManagerViewGUI guiBlueChannelChoice->deactivate(); guiGrayscaleChannelChoice->activate(); - guiGrayscaleChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetRedChannelIndex(),nbComponent-1)); + + assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); + + RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion; + + ChannelListType channels = renderingFunction->GetChannelList(); + if (channels.size() < 1) + { + channels.push_back(0); + } + + guiGrayscaleChannelChoice->value(std::min(channels[0],nbComponent-1)); } @@ -898,10 +913,6 @@ ImageViewerManagerViewGUI ImageViewerManagerModelType::ReaderPointerType reader = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pReader; unsigned int nbComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel(); -// RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion; - //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType - StandardRenderingFunctionType::Pointer renderingFunction = static_cast<StandardRenderingFunctionType*>(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); //FIXME should be the Modulus/Phase rendering function - guiViewerSetupComplexMode->set(); guiViewerSetupColorMode->clear(); guiViewerSetupGrayscaleMode->clear(); @@ -913,8 +924,21 @@ ImageViewerManagerViewGUI guiImaginaryChannelChoice->activate(); bModulus->activate(); bPhase->activate(); - guiRealChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetChannelIndex(0),nbComponent-1)); - guiImaginaryChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetChannelIndex(1),nbComponent-1)); + + + assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); + RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion; + + ChannelListType channels = renderingFunction->GetChannelList(); + unsigned int i=0; + while (channels.size() < 2) + { + channels.push_back(i); + ++i; + } + + guiRealChannelChoice->value(std::min(channels[0],nbComponent-1)); + guiImaginaryChannelChoice->value(std::min(channels[1],nbComponent-1)); } diff --git a/ViewerManager/View/otbImageViewerManagerViewGUI.h b/ViewerManager/View/otbImageViewerManagerViewGUI.h index 64e493e739..03bcc5d6f3 100644 --- a/ViewerManager/View/otbImageViewerManagerViewGUI.h +++ b/ViewerManager/View/otbImageViewerManagerViewGUI.h @@ -83,7 +83,7 @@ public: typedef ImageViewerManagerModelType::OffsetType OffsetType; typedef ImageViewerManagerModelType::RenderingFunctionType RenderingFunctionType; typedef ImageViewerManagerModelType::StandardRenderingFunctionType StandardRenderingFunctionType; - + typedef StandardRenderingFunctionType::ChannelListType ChannelListType; typedef ImageView<VisuModelType> VisuViewType; typedef VisuViewType::Pointer VisuViewPointerType; -- GitLab