ENH: remove the static_cast on the rendering function
authorEmmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Fri Jun 26 16:57:23 2009 +0800 (14 months ago)
changeset 14931f5c57f8535f
parent 1492 7061e2cbda26
child 1494 2146acd4e899
ENH: remove the static_cast on the rendering function
ViewerManager/Model/otbImageViewerManagerModel.cxx
ViewerManager/View/otbImageViewerManagerViewGUI.cxx
ViewerManager/View/otbImageViewerManagerViewGUI.h
     1.1 --- a/ViewerManager/Model/otbImageViewerManagerModel.cxx	Fri Jun 26 11:09:51 2009 +0800
     1.2 +++ b/ViewerManager/Model/otbImageViewerManagerModel.cxx	Fri Jun 26 16:57:23 2009 +0800
     1.3 @@ -208,20 +208,23 @@
     1.4  ImageViewerManagerModel
     1.5  ::UpdateRGBChannelOrder(int redChoice , int greenChoice, int blueChoice, unsigned int selectedItem)
     1.6  {
     1.7 -//   RenderingFunctionType::Pointer renderFunction = m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion;
     1.8 -   //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType
     1.9 -//    StandardRenderingFunctionType::Pointer renderFunction = static_cast<StandardRenderingFunctionType*>(m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion.GetPointer());
    1.10 +
    1.11 +  StandardRenderingFunctionType::ChannelListType channels;
    1.12 +  channels.resize(3);
    1.13 +  channels[0]=redChoice;
    1.14 +  channels[1]=greenChoice;
    1.15 +  channels[2]=blueChoice;
    1.16 +
    1.17     StandardRenderingFunctionType::Pointer renderFunction;
    1.18     renderFunction = StandardRenderingFunctionType::New();
    1.19  
    1.20 -  renderFunction->GetPixelRepresentationFunction().SetChannelIndex(0,redChoice);
    1.21 -  renderFunction->GetPixelRepresentationFunction().SetChannelIndex(1,greenChoice);
    1.22 -  renderFunction->GetPixelRepresentationFunction().SetChannelIndex(2,blueChoice);
    1.23 +   renderFunction->SetChannelList(channels);
    1.24 +
    1.25  
    1.26    //Update the layer
    1.27    m_ObjectTrackedList.at(selectedItem-1).pLayer->SetRenderingFunction(renderFunction);
    1.28    m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion = renderFunction;
    1.29 -  renderFunction->Initialize();//FIXME Initialize() should disappear from the renderinFunction
    1.30 +  renderFunction->Initialize();//FIXME Initialize() should disappear from the renderingFunction
    1.31    m_ObjectTrackedList.at(selectedItem-1).pRendering->Update();
    1.32  
    1.33    //Notify
    1.34 @@ -234,18 +237,19 @@
    1.35  ImageViewerManagerModel
    1.36  ::UpdateGrayScaleChannelOrder(int choice, unsigned int selectedItem)
    1.37  {
    1.38 -//   RenderingFunctionType::Pointer renderFunction = m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion;
    1.39 -   //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType
    1.40 -//    StandardRenderingFunctionType::Pointer renderFunction = static_cast<StandardRenderingFunctionType*>(m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion.GetPointer());
    1.41 +  StandardRenderingFunctionType::ChannelListType channels;
    1.42 +  channels.resize(3);
    1.43 +  channels[0]=choice;
    1.44 +
    1.45    StandardRenderingFunctionType::Pointer renderFunction;
    1.46    renderFunction = StandardRenderingFunctionType::New();
    1.47  
    1.48 -  renderFunction->GetPixelRepresentationFunction().SetAllChannels(choice);
    1.49 +  renderFunction->SetChannelList(channels);
    1.50  
    1.51    //Update the layer
    1.52    m_ObjectTrackedList.at(selectedItem-1).pLayer->SetRenderingFunction(renderFunction);
    1.53    m_ObjectTrackedList.at(selectedItem-1).pRenderFuntion = renderFunction;
    1.54 -  renderFunction->Initialize();//FIXME Initialize() should disappear from the renderinFunction
    1.55 +  renderFunction->Initialize();//FIXME Initialize() should disappear from the renderingFunction
    1.56    m_ObjectTrackedList.at(selectedItem-1).pRendering->Update();
    1.57  
    1.58    //Notify
    1.59 @@ -258,14 +262,14 @@
    1.60  ImageViewerManagerModel
    1.61  ::UpdateModulusChannelOrder(int realChoice , int imChoice, unsigned int selectedItem )
    1.62  {
    1.63 -  ModulusRenderingFunction::Pointer modulusFunction;
    1.64 -  modulusFunction = ModulusRenderingFunction::New();
    1.65 -
    1.66 -
    1.67    ModulusRenderingFunction::PixelRepresentationFunctionType::ChannelListType channels;
    1.68    channels.push_back(realChoice);
    1.69    channels.push_back(imChoice);
    1.70 -  modulusFunction->GetPixelRepresentationFunction().SetChannelList(channels);
    1.71 +
    1.72 +   ModulusRenderingFunction::Pointer modulusFunction;
    1.73 +  modulusFunction = ModulusRenderingFunction::New();
    1.74 +
    1.75 +  modulusFunction->SetChannelList(channels);
    1.76  
    1.77  
    1.78    //Update the layer
    1.79 @@ -285,13 +289,16 @@
    1.80  ImageViewerManagerModel
    1.81  ::UpdatePhaseChannelOrder(int realChoice , int imChoice, unsigned int selectedItem )
    1.82  {
    1.83 +  PhaseRenderingFunction::PixelRepresentationFunctionType::ChannelListType channels;
    1.84 +  channels.push_back(realChoice);
    1.85 +  channels.push_back(imChoice);
    1.86 +
    1.87    PhaseRenderingFunction::Pointer phaseFunction;
    1.88    phaseFunction = PhaseRenderingFunction::New();
    1.89  
    1.90 -  PhaseRenderingFunction::PixelRepresentationFunctionType::ChannelListType channels;
    1.91 -  channels.push_back(realChoice);
    1.92 -  channels.push_back(imChoice);
    1.93 -  phaseFunction->GetPixelRepresentationFunction().SetChannelList(channels);
    1.94 +  phaseFunction->SetChannelList(channels);
    1.95 +
    1.96 +
    1.97  
    1.98    //Update the layer
    1.99    m_ObjectTrackedList.at(selectedItem-1).pLayer->SetRenderingFunction(phaseFunction);
     2.1 --- a/ViewerManager/View/otbImageViewerManagerViewGUI.cxx	Fri Jun 26 11:09:51 2009 +0800
     2.2 +++ b/ViewerManager/View/otbImageViewerManagerViewGUI.cxx	Fri Jun 26 16:57:23 2009 +0800
     2.3 @@ -824,10 +824,6 @@
     2.4     ImageViewerManagerModelType::ReaderPointerType reader = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pReader;
     2.5     unsigned int nbComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel();
     2.6  
     2.7 -   //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType
     2.8 -   assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer());
     2.9 -   StandardRenderingFunctionType::Pointer renderingFunction = static_cast<StandardRenderingFunctionType*>(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer());
    2.10 -
    2.11     guiViewerSetupColorMode->set();
    2.12     guiViewerSetupComplexMode->clear();
    2.13     guiViewerSetupGrayscaleMode->clear();
    2.14 @@ -841,10 +837,22 @@
    2.15     guiGreenChannelChoice->activate();
    2.16     guiBlueChannelChoice->activate();
    2.17  
    2.18 -   assert(renderingFunction);
    2.19 -   guiRedChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetRedChannelIndex(),nbComponent-1));
    2.20 -   guiGreenChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetGreenChannelIndex(),nbComponent-1));
    2.21 -   guiBlueChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetBlueChannelIndex(),nbComponent-1));
    2.22 +   assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer());
    2.23 +
    2.24 +   RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion;
    2.25 +
    2.26 +   ChannelListType channels = renderingFunction->GetChannelList();
    2.27 +   unsigned int i=0;
    2.28 +   while (channels.size() < 3)
    2.29 +   {
    2.30 +     channels.push_back(i);
    2.31 +     ++i;
    2.32 +   }
    2.33 +
    2.34 +
    2.35 +   guiRedChannelChoice->value(std::min(channels[0],nbComponent-1));
    2.36 +   guiGreenChannelChoice->value(std::min(channels[1],nbComponent-1));
    2.37 +   guiBlueChannelChoice->value(std::min(channels[2],nbComponent-1));
    2.38  
    2.39   }
    2.40  
    2.41 @@ -864,10 +872,6 @@
    2.42     ImageViewerManagerModelType::ReaderPointerType reader = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pReader;
    2.43     unsigned int nbComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel();
    2.44  
    2.45 -//    RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion;
    2.46 -   //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType
    2.47 -   StandardRenderingFunctionType::Pointer renderingFunction = static_cast<StandardRenderingFunctionType*>(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer());
    2.48 -
    2.49     guiViewerSetupGrayscaleMode->set();
    2.50     guiViewerSetupComplexMode->clear();
    2.51     guiViewerSetupColorMode->clear();
    2.52 @@ -881,7 +885,18 @@
    2.53     guiBlueChannelChoice->deactivate();
    2.54  
    2.55     guiGrayscaleChannelChoice->activate();
    2.56 -   guiGrayscaleChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetRedChannelIndex(),nbComponent-1));
    2.57 +
    2.58 +   assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer());
    2.59 +
    2.60 +   RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion;
    2.61 +
    2.62 +   ChannelListType channels = renderingFunction->GetChannelList();
    2.63 +   if (channels.size() < 1)
    2.64 +   {
    2.65 +     channels.push_back(0);
    2.66 +   }
    2.67 +
    2.68 +   guiGrayscaleChannelChoice->value(std::min(channels[0],nbComponent-1));
    2.69   }
    2.70  
    2.71  
    2.72 @@ -898,10 +913,6 @@
    2.73     ImageViewerManagerModelType::ReaderPointerType reader = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pReader;
    2.74     unsigned int nbComponent = reader->GetOutput()->GetNumberOfComponentsPerPixel();
    2.75  
    2.76 -//    RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion;
    2.77 -    //FIXME make sure this is called only when the renderingFunction is a StandardRenderingFunctionType
    2.78 -   StandardRenderingFunctionType::Pointer renderingFunction = static_cast<StandardRenderingFunctionType*>(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer()); //FIXME should be the Modulus/Phase rendering function
    2.79 -
    2.80     guiViewerSetupComplexMode->set();
    2.81     guiViewerSetupColorMode->clear();
    2.82     guiViewerSetupGrayscaleMode->clear();
    2.83 @@ -913,8 +924,21 @@
    2.84     guiImaginaryChannelChoice->activate();
    2.85     bModulus->activate();
    2.86     bPhase->activate();
    2.87 -   guiRealChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetChannelIndex(0),nbComponent-1));
    2.88 -   guiImaginaryChannelChoice->value(std::min(renderingFunction->GetPixelRepresentationFunction().GetChannelIndex(1),nbComponent-1));
    2.89 +
    2.90 +
    2.91 +   assert(m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion.GetPointer());
    2.92 +   RenderingFunctionType::Pointer renderingFunction = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pRenderFuntion;
    2.93 +
    2.94 +   ChannelListType channels = renderingFunction->GetChannelList();
    2.95 +   unsigned int i=0;
    2.96 +   while (channels.size() < 2)
    2.97 +   {
    2.98 +     channels.push_back(i);
    2.99 +     ++i;
   2.100 +   }
   2.101 +
   2.102 +   guiRealChannelChoice->value(std::min(channels[0],nbComponent-1));
   2.103 +   guiImaginaryChannelChoice->value(std::min(channels[1],nbComponent-1));
   2.104   }
   2.105  
   2.106  
     3.1 --- a/ViewerManager/View/otbImageViewerManagerViewGUI.h	Fri Jun 26 11:09:51 2009 +0800
     3.2 +++ b/ViewerManager/View/otbImageViewerManagerViewGUI.h	Fri Jun 26 16:57:23 2009 +0800
     3.3 @@ -83,7 +83,7 @@
     3.4    typedef ImageViewerManagerModelType::OffsetType                 OffsetType;
     3.5    typedef ImageViewerManagerModelType::RenderingFunctionType      RenderingFunctionType;
     3.6    typedef ImageViewerManagerModelType::StandardRenderingFunctionType StandardRenderingFunctionType;
     3.7 -
     3.8 +  typedef StandardRenderingFunctionType::ChannelListType          ChannelListType;
     3.9    typedef ImageView<VisuModelType>                                VisuViewType;
    3.10    typedef VisuViewType::Pointer                                   VisuViewPointerType;
    3.11