diff --git a/Code/BasicFilters/otbListSampleToHistogramListGenerator.txx b/Code/BasicFilters/otbListSampleToHistogramListGenerator.txx index df8a5c47e4194174f7a0104d1e5f6922349ef5e1..34616debcc55bcc6d87e3756e5266119b77363da 100755 --- a/Code/BasicFilters/otbListSampleToHistogramListGenerator.txx +++ b/Code/BasicFilters/otbListSampleToHistogramListGenerator.txx @@ -23,6 +23,7 @@ #include <exception> #include "otbMacro.h" +#include "itkArray.h" namespace otb { @@ -62,7 +63,6 @@ ListSampleToHistogramListGenerator< TListSample, itkExceptionMacro("Sample list measurement vectors and histogram max have different dimensions !"); } } - typename TListSample::MeasurementVectorType lower(m_List->GetMeasurementVectorSize()); typename TListSample::MeasurementVectorType upper(m_List->GetMeasurementVectorSize()); @@ -78,8 +78,6 @@ ListSampleToHistogramListGenerator< TListSample, { FindSampleBound(m_List, m_List->Begin(), m_List->End(), lower, upper) ; - std::cout<<"lower = "<<lower<<std::endl; - std::cout<<"upper = "<<upper<<std::endl; float margin ; for ( unsigned int i = 0 ; i < m_List->GetMeasurementVectorSize() ; i++ ) @@ -125,9 +123,6 @@ ListSampleToHistogramListGenerator< TListSample, h_lower = m_HistogramMin; h_upper = m_HistogramMax; } - std::cout<<"hlower = "<<h_lower<<std::endl; - std::cout<<"hupper = "<<h_upper<<std::endl; - // Clearing previous histograms m_HistogramList->Clear(); diff --git a/Code/BasicFilters/otbListSampleToVariableDimensionHistogramGenerator.txx b/Code/BasicFilters/otbListSampleToVariableDimensionHistogramGenerator.txx index 627a93a1459cee5eb4718cf58ef84fef32372b86..e0a17087f6f49592e5e1fdd9c3488c7af9875c02 100755 --- a/Code/BasicFilters/otbListSampleToVariableDimensionHistogramGenerator.txx +++ b/Code/BasicFilters/otbListSampleToVariableDimensionHistogramGenerator.txx @@ -82,7 +82,6 @@ ListSampleToVariableDimensionHistogramGenerator< TListSample, { FindSampleBound(m_List, m_List->Begin(), m_List->End(), lower, upper) ; - float margin ; for ( unsigned int i = 0 ; i < m_List->GetMeasurementVectorSize() ; i++ ) diff --git a/Code/Common/otbVectorDataExtractROI.txx b/Code/Common/otbVectorDataExtractROI.txx index d7ec133c361818dbd5dc7ed4ab67328f98bd844a..70e0895e04a2cb02bd7610683e87b048f1d7404a 100644 --- a/Code/Common/otbVectorDataExtractROI.txx +++ b/Code/Common/otbVectorDataExtractROI.txx @@ -67,7 +67,7 @@ VectorDataExtractROI<TVectorData> output->SetProjectionRef(input->GetProjectionRef()); if(!input) - std::cout << " Probleme avec la recuperation du input"<<std::endl; + return; /** Need to check if it is necessary to project the roi*/ this->CompareInputAndRegionProjection(); @@ -76,6 +76,8 @@ VectorDataExtractROI<TVectorData> /** If Projection of the region is needed, we project on the vectorData coordinate axis*/ if(m_ProjectionNeeded) this->ProjectRegionToInputVectorProjection(); + else + m_GeoROI = m_ROI; /** Loop in the vectorData file @@ -87,49 +89,87 @@ VectorDataExtractROI<TVectorData> typename DataNodeType::Pointer root = input->GetDataTree()->GetRoot()->Get(); typename VectorDataType::DataTreeType::Pointer tree = output->GetDataTree(); - DataNodePointerType currentContainer; + DataNodePointerType currentContainer; + DataNodePointerType newDataNodeFolder = DataNodeType::New(); + DataNodePointerType newDataNodeMultiPolygon = DataNodeType::New(); + DataNodePointerType newDataNodeMultiLine = DataNodeType::New(); /** Walking trough the input vector data */ typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType; TreeIteratorType it(input->GetDataTree()); it.GoToBegin(); + bool newFolder = false ; + bool newMultiFeature = false; + + while (!it.IsAtEnd()) { - DataNodePointerType dataNode = it.Get(); - DataNodePointerType newDataNode = DataNodeType::New(); - newDataNode->SetNodeType(dataNode->GetNodeType()); - newDataNode->SetNodeId(dataNode->GetNodeId()); + DataNodePointerType dataNode = it.Get(); + DataNodePointerType newDataNode = DataNodeType::New(); + + switch (dataNode->GetNodeType()) { case ROOT: { + newDataNode->SetNodeType(dataNode->GetNodeType()); + newDataNode->SetNodeId(dataNode->GetNodeId()); tree->SetRoot(newDataNode); currentContainer = newDataNode; break; } case DOCUMENT: { + newDataNode->SetNodeType(dataNode->GetNodeType()); + newDataNode->SetNodeId(dataNode->GetNodeId()); tree->Add(newDataNode,currentContainer); currentContainer = newDataNode; break; } case FOLDER: { - tree->Add(newDataNode,currentContainer); - currentContainer = newDataNode; + newDataNodeFolder->SetNodeType(dataNode->GetNodeType()); + newDataNodeFolder->SetNodeId(dataNode->GetNodeId()); + newFolder = true; break; } case FEATURE_POINT: { - newDataNode->SetPoint(dataNode->GetPoint()); - tree->Add(newDataNode,currentContainer); + if(m_GeoROI.IsInside(this->PointToContinuousIndex(dataNode->GetPoint()))) + { + if(newFolder) + { + tree->Add(newDataNodeFolder,currentContainer); + currentContainer = newDataNodeFolder; + newFolder = false; + } + newDataNode->SetNodeType(dataNode->GetNodeType()); + newDataNode->SetNodeId(dataNode->GetNodeId()); + newDataNode->SetPoint(dataNode->GetPoint()); + tree->Add(newDataNode,currentContainer); + } + break; } case FEATURE_LINE: { if(this->IsLineIntersectionNotNull(dataNode->GetLine())) { + if(newFolder) + { + tree->Add(newDataNodeFolder,currentContainer); + currentContainer = newDataNodeFolder; + newFolder = false; + } + if(newMultiFeature) + { + tree->Add(newDataNodeMultiLine,currentContainer); + currentContainer = newDataNodeMultiLine; + newMultiFeature = false; + } + newDataNode->SetNodeType(dataNode->GetNodeType()); + newDataNode->SetNodeId(dataNode->GetNodeId()); newDataNode->SetLine(dataNode->GetLine()); tree->Add(newDataNode,currentContainer); } @@ -139,35 +179,53 @@ VectorDataExtractROI<TVectorData> { if(this->IsPolygonIntersectionNotNull(dataNode->GetPolygonExteriorRing())) { + if(newFolder) + { + tree->Add(newDataNodeFolder,currentContainer); + currentContainer = newDataNodeFolder; + newFolder = false; + } + if(newMultiFeature) + { + tree->Add(newDataNodeMultiPolygon,currentContainer); + currentContainer = newDataNodeMultiPolygon; + newMultiFeature = false; + } + + newDataNode->SetNodeType(dataNode->GetNodeType()); + newDataNode->SetNodeId(dataNode->GetNodeId()); newDataNode->SetPolygonExteriorRing(dataNode->GetPolygonExteriorRing()); newDataNode->SetPolygonInteriorRings(dataNode->GetPolygonInteriorRings()); tree->Add(newDataNode,currentContainer); } - else - std::cout << " OUTSIDE The region" <<std::endl; - break; } case FEATURE_MULTIPOINT: { + newDataNode->SetNodeType(dataNode->GetNodeType()); + newDataNode->SetNodeId(dataNode->GetNodeId()); tree->Add(newDataNode,currentContainer); currentContainer = newDataNode; break; } case FEATURE_MULTILINE: { - tree->Add(newDataNode,currentContainer); - currentContainer = newDataNode; + newDataNodeMultiLine->SetNodeType(dataNode->GetNodeType()); + newDataNodeMultiLine->SetNodeId(dataNode->GetNodeId()); + newMultiFeature = true; break; } case FEATURE_MULTIPOLYGON: { - tree->Add(newDataNode,currentContainer); - currentContainer = newDataNode; + newDataNodeMultiPolygon->SetNodeType(dataNode->GetNodeType()); + newDataNodeMultiPolygon->SetNodeId(dataNode->GetNodeId()); + newMultiFeature = true; break; } case FEATURE_COLLECTION: { + newDataNode->SetNodeType(dataNode->GetNodeType()); + newDataNode->SetNodeId(dataNode->GetNodeId()); tree->Add(newDataNode,currentContainer); currentContainer = newDataNode; break; @@ -211,10 +269,9 @@ void VectorDataExtractROI<TVectorData> ::CompareInputAndRegionProjection() { - /**Traces*/ std::string regionProjection = m_ROI.GetRegionProjection(); std::string inputVectorProjection = this->GetInput()->GetProjectionRef(); - + if(regionProjection == inputVectorProjection) m_ProjectionNeeded = false; else @@ -229,7 +286,7 @@ void VectorDataExtractROI<TVectorData> ::ProjectRegionToInputVectorProjection() { - typedef otb::GenericMapProjection<otb::FORWARD> ForwardMapProjectionType; + typedef otb::GenericMapProjection<otb::INVERSE> ForwardMapProjectionType; ForwardMapProjectionType::Pointer mapTransform = ForwardMapProjectionType::New(); mapTransform->SetWkt(m_ROI.GetRegionProjection()); @@ -256,8 +313,8 @@ VectorDataExtractROI<TVectorData> ProjPointType pGeo3 = mapTransform->TransformPoint(point3); ProjPointType pGeo4 = mapTransform->TransformPoint(point4); - /** Inverse : From long/lat to InputVectorData projection*/ - typedef otb::GenericMapProjection<otb::INVERSE> InverseMapProjectionType; + /** INVERSE : From long/lat to InputVectorData projection*/ + typedef otb::GenericMapProjection<otb::FORWARD> InverseMapProjectionType; InverseMapProjectionType::Pointer mapInverseTransform = InverseMapProjectionType::New(); if(this->GetInput()->GetProjectionRef().empty()) { @@ -272,13 +329,13 @@ VectorDataExtractROI<TVectorData> ProjPointType pCarto2 = mapInverseTransform->TransformPoint(pGeo2); ProjPointType pCarto3 = mapInverseTransform->TransformPoint(pGeo3); ProjPointType pCarto4 = mapInverseTransform->TransformPoint(pGeo4); - + /** Fill the vertex List : First Convert Point To*/ regionCorners->InsertElement(regionCorners->Size(),this->PointToContinuousIndex(pCarto1)); regionCorners->InsertElement(regionCorners->Size(),this->PointToContinuousIndex(pCarto2)); regionCorners->InsertElement(regionCorners->Size(),this->PointToContinuousIndex(pCarto3)); regionCorners->InsertElement(regionCorners->Size(),this->PointToContinuousIndex(pCarto4)); - + /** Due to The projection : the Projected ROI can be rotated */ m_GeoROI = this->ComputeVertexListBoudingRegion(regionCorners.GetPointer()); @@ -292,11 +349,12 @@ typename VectorDataExtractROI<TVectorData> VectorDataExtractROI<TVectorData> ::PointToContinuousIndex(ProjPointType point) { + VertexType vertex; vertex[0] = point[0]; vertex[1] = point[1]; - + return vertex; } @@ -326,13 +384,13 @@ VectorDataExtractROI<TVectorData> y = static_cast<double>(it.Value()[1]); index[0] = x; index[1] = y; - + ++it; while (it != vertexlist->End()) { x = static_cast<double>(it.Value()[0]); y = static_cast<double>(it.Value()[1]); - + // Index search if ( x < index[0] ) { diff --git a/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx b/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx index 6e78364cc11ce7929c4067de93a86059c4371ff6..79d3e3988b7cdaf04b0c06c416459311fde141d7 100644 --- a/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx +++ b/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx @@ -189,7 +189,7 @@ LineSpatialObjectListToRightAnglePointSetFilter<TImage,TLinesList ,TPointSet> * d(P,[Q1Q2]) = |PQ1^PQ2|/|Q1Q2| */ - float SegmentLength = (Xq1-Xq2)* (Xq1-Xq2) + (Yq1-Yq2) *(Yq1-Yq2); + float SegmentLength = vcl_sqrt((Xq1-Xq2)* (Xq1-Xq2) + (Yq1-Yq2) *(Yq1-Yq2)); float CrossProduct = Xq1*Yq2 - Xq2*Yq1 ; /** Define a line iterator */ diff --git a/Code/VisuRefac/otbChangeExtractRegionActionHandler.h b/Code/VisuRefac/otbChangeExtractRegionActionHandler.h index e217038239807fb4ff504e9dcf3b6c004905a3ab..eb3ed7adc88dc1705a7a9a79c48462d7db025493 100644 --- a/Code/VisuRefac/otbChangeExtractRegionActionHandler.h +++ b/Code/VisuRefac/otbChangeExtractRegionActionHandler.h @@ -74,7 +74,7 @@ public: index[0] = Fl::event_x(); index[1] = Fl::event_y(); // Change scaled extract region center - m_Model->SetExtractRegionSubsampledCenter(m_View->GetScrollWidget()->ScreenIndexToRegionIndex(index)); + m_Model->SetExtractRegionCenter(m_View->GetScrollWidget()->ScreenIndexToImageIndex(index)); // Update model m_Model->Update(); return true; diff --git a/Code/VisuRefac/otbImageLayer.h b/Code/VisuRefac/otbImageLayer.h index b7bc736780a3aa1094c25d856dd214384db2e77d..445b7a22b3e494444dbf2d006e50701ebdaa1085 100644 --- a/Code/VisuRefac/otbImageLayer.h +++ b/Code/VisuRefac/otbImageLayer.h @@ -18,7 +18,7 @@ #ifndef __otbImageLayer_h #define __otbImageLayer_h -#include "otbLayer.h" +#include "otbImageLayerBase.h" #include "itkVariableLengthVector.h" #include "itkDenseFrequencyContainer.h" #include "otbRenderingImageFilter.h" @@ -39,12 +39,12 @@ namespace otb template <class TImage, class TOutputImage = otb::Image<itk::RGBPixel<unsigned char>, 2 > > class ImageLayer - : public Layer<TOutputImage> + : public ImageLayerBase<TOutputImage> { public: /** Standard class typedefs */ typedef ImageLayer Self; - typedef Layer<TOutputImage> Superclass; + typedef ImageLayerBase<TOutputImage> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; @@ -60,6 +60,7 @@ public: typedef typename ImageType::PixelType PixelType; typedef typename ImageType::InternalPixelType InternalPixelType; typedef typename ImageType::RegionType RegionType; + typedef typename ImageType::IndexType IndexType; /** Output image typedef */ typedef TOutputImage OutputImageType; @@ -181,6 +182,9 @@ public: /** Actually render the image */ virtual void Render(); + /** Get the pixel description */ + virtual std::string GetPixelDescription(const IndexType & index); + protected: /** Constructor */ ImageLayer(); diff --git a/Code/VisuRefac/otbImageLayer.txx b/Code/VisuRefac/otbImageLayer.txx index cd112ceb19668212695d7fc6a3e7863bbcc53d08..34caade42f33d8f0402b649a968db90e823b46e8 100644 --- a/Code/VisuRefac/otbImageLayer.txx +++ b/Code/VisuRefac/otbImageLayer.txx @@ -174,7 +174,11 @@ ImageLayer<TImage,TOutputImage> it.GoToBegin(); while(!it.IsAtEnd()) { - listSample->PushBack(it.Get()); + SampleType sample(histogramSource->GetNumberOfComponentsPerPixel()); + // workaround to handle both scalar and vector pixels the same way + sample.Fill(itk::NumericTraits<InternalPixelType>::Zero); + sample += it.Get(); + listSample->PushBack(sample); ++it; } otbMsgDevMacro(<<"ImageLayer::RenderHistogram()"<<" ("<<this->GetName()<<")"<< " Sample list generated ("<<listSample->Size()<<" samples, "<<histogramSource->GetNumberOfComponentsPerPixel()<<" bands)"); @@ -232,5 +236,42 @@ ImageLayer<TImage,TOutputImage> m_AutoMinMaxUpToDate = true; } } + +template <class TImage, class TOutputImage> +std::string +ImageLayer<TImage,TOutputImage> +::GetPixelDescription(const IndexType & index) +{ + // If required, use histogram for auto min/max + if(m_AutoMinMax) + { + this->RenderHistogram(); + this->AutoMinMaxRenderingFunctionSetup(); + } + // Ensure rendering function intialization + m_RenderingFunction->Initialize(); + // The ouptut stringstream + itk::OStringStream oss; + oss<<this->GetName(); + // If we are inside the buffered region + if(m_Image->GetBufferedRegion().IsInside(index)) + { + oss<<" "<<m_RenderingFunction->Describe(m_Image->GetPixel(index)); + } + else if(m_Quicklook.IsNotNull()) + // Else we extrapolate the value from the quicklook + { + IndexType ssindex = index; + ssindex[0]/=this->GetQuicklookSubsamplingRate(); + ssindex[1]/=this->GetQuicklookSubsamplingRate(); + + if(m_Quicklook->GetBufferedRegion().IsInside(ssindex)) + { + oss<<" (ql) "<<m_RenderingFunction->Describe(m_Quicklook->GetPixel(ssindex)); + } + } + return oss.str(); +} + } #endif diff --git a/Code/VisuRefac/otbLayer.h b/Code/VisuRefac/otbImageLayerBase.h similarity index 90% rename from Code/VisuRefac/otbLayer.h rename to Code/VisuRefac/otbImageLayerBase.h index 5c24e1c827e0f0bc7e79b8827d8afe8c73a6c634..c7a77699d3cb80c94270bae19973dc357dbdd940 100644 --- a/Code/VisuRefac/otbLayer.h +++ b/Code/VisuRefac/otbImageLayerBase.h @@ -15,8 +15,8 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __otbLayer_h -#define __otbLayer_h +#ifndef __otbImageLayerBase_h +#define __otbImageLayerBase_h #include "itkObject.h" #include "otbImage.h" @@ -26,7 +26,7 @@ namespace otb { -/** \class Layer +/** \class ImageLayerBase * \brief Base class for all layers objects * A layer is something that can be rendered to the screen. * @@ -34,24 +34,25 @@ namespace otb */ template <class TOutputImage = Image<itk::RGBPixel<unsigned char>, 2 > > -class Layer +class ImageLayerBase : public itk::Object { public: /** Standard class typedefs */ - typedef Layer Self; + typedef ImageLayerBase Self; typedef itk::Object Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; /** Runtime information */ - itkTypeMacro(Layer,Object); + itkTypeMacro(ImageLayerBase,Object); /** Output image typedef */ typedef TOutputImage OutputImageType; typedef typename OutputImageType::Pointer OutputImagePointerType; typedef typename OutputImageType::RegionType RegionType; typedef typename RegionType::SizeType SizeType; + typedef typename RegionType::IndexType IndexType; typedef typename OutputImageType::PixelType PixelType; /** Blending function typedef */ @@ -61,6 +62,9 @@ public: /** Actually render the layer */ virtual void Render() = 0; + /** Get the pixel description */ + virtual std::string GetPixelDescription(const IndexType & index) = 0; + itkGetObjectMacro(RenderedQuicklook, OutputImageType); itkGetObjectMacro(RenderedExtract, OutputImageType); itkGetObjectMacro(RenderedScaledExtract, OutputImageType); @@ -114,7 +118,7 @@ public: protected: /** Constructor */ - Layer() : m_Name("Default"), m_Visible(false), m_Extent(), + ImageLayerBase() : m_Name("Default"), m_Visible(false), m_Extent(), m_RenderedQuicklook(), m_HasQuicklook(false), m_QuicklookSize(), m_QuicklookSubsamplingRate(1), m_RenderedExtract(), m_HasExtract(false), m_ExtractRegion(), m_RenderedScaledExtract(), m_HasScaledExtract(false), m_ScaledExtractRegion(), @@ -124,12 +128,12 @@ protected: m_BlendingFunction = Function::UniformAlphaBlendingFunction<PixelType>::New(); } /** Destructor */ - virtual ~Layer(){} + virtual ~ImageLayerBase(){} /** Printself method */ void PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os,indent); - os<<indent<<"Layer "<<m_Name<<":"<<std::endl; + os<<indent<<"ImageLayerBase "<<m_Name<<":"<<std::endl; os<<indent<<indent<<"Has a quicklook: " <<(m_HasQuicklook ? "true" : "false") << std::endl; os<<indent<<indent<<"Has an extract: " <<(m_HasExtract ? "true" : "false") << std::endl; os<<indent<<indent<<"Has a scaled extract: "<<(m_HasScaledExtract ? "true" : "false") << std::endl; @@ -141,7 +145,7 @@ protected: itkSetObjectMacro(RenderedScaledExtract, OutputImageType); private: - Layer(const Self&); // purposely not implemented + ImageLayerBase(const Self&); // purposely not implemented void operator=(const Self&); // purposely not implemented /** The layer name */ diff --git a/Code/VisuRefac/otbImageViewerModel.h b/Code/VisuRefac/otbImageLayerRenderingModel.h similarity index 63% rename from Code/VisuRefac/otbImageViewerModel.h rename to Code/VisuRefac/otbImageLayerRenderingModel.h index c705e793921ab2d971aef3f09596861b8cfdd296..3c19370e8d80bc07bc003c547bce045facff265a 100644 --- a/Code/VisuRefac/otbImageViewerModel.h +++ b/Code/VisuRefac/otbImageLayerRenderingModel.h @@ -15,18 +15,19 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __otbImageViewerModel_h -#define __otbImageViewerModel_h +#ifndef __otbImageLayerRenderingModel_h +#define __otbImageLayerRenderingModel_h -#include "otbMVCModel.h" -#include "otbLayer.h" +#include "otbMVCModelBase.h" +#include "otbLayerBasedModel.h" +#include "otbImageLayerBase.h" #include "otbObjectList.h" -#include "otbImageViewerModelListener.h" +#include "otbImageLayerRenderingModelListener.h" #include "otbBlendingImageFilter.h" namespace otb { -/** \class ImageViewerModel +/** \class ImageLayerRenderingModel * \brief This class is the model for ImageViewer. * It is in charge of rendering to the screen a set of Layer. * Each visible layer is rendered separately, and the resulting @@ -39,18 +40,18 @@ namespace otb */ template <class TOutputImage = otb::Image<itk::RGBPixel<unsigned char>,2 > > -class ImageViewerModel - : public MVCModel<ImageViewerModelListener> +class ImageLayerRenderingModel + : public MVCModelBase<ImageLayerRenderingModelListener>, public LayerBasedModel< ImageLayerBase<TOutputImage> > { public: /** Standard class typedefs */ - typedef ImageViewerModel Self; - typedef MVCModel<ImageViewerModelListener> Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; + typedef ImageLayerRenderingModel Self; + typedef LayerBasedModel< ImageLayerBase <TOutputImage> > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; /** Runtime information */ - itkTypeMacro(ImageViewerModel,MVCModel); + itkTypeMacro(ImageLayerRenderingModel,LayerBasedModel); /** New macro */ itkNewMacro(Self); @@ -60,17 +61,17 @@ public: typedef typename OutputImageType::Pointer OutputImagePointerType; /** Layer typedef */ - typedef otb::Layer<OutputImageType> LayerType; + typedef typename Superclass::LayerType LayerType; typedef typename LayerType::RegionType RegionType; typedef typename RegionType::IndexType IndexType; /** Layer list typedef */ - typedef otb::ObjectList<LayerType> LayerListType; - typedef typename LayerListType::Pointer LayerListPointerType; - typedef typename LayerListType::Iterator LayerIteratorType; + typedef typename Superclass::LayerListType LayerListType; + typedef typename LayerListType::Pointer LayerListPointerType; + typedef typename LayerListType::ConstIterator LayerIteratorType; /** Listener typedef */ - typedef ImageViewerModelListener ListenerType; + typedef ImageLayerRenderingModelListener ListenerType; /** Blending filter typedef */ typedef otb::BlendingImageFilter<OutputImageType> BlendingFilterType; @@ -80,46 +81,6 @@ public: typedef typename BlendingFilterListType::Pointer BlendingFilterListPointerType; typedef typename BlendingFilterListType::Iterator BlendingFilterIteratorType; - - /** Add a new layer - * \param layer The layer to add. - * \return The location of the added layer. - */ - virtual unsigned int AddLayer(LayerType * layer); - - /** Get the layer at the current index - * \param index The index of the layer to get. - * \return a pointer to the layer or NULL if no layer was found at - * this location. - */ - virtual LayerType * GetLayer(unsigned int index); - - /** Remove the layer at the current index - * \param index The index of the layer to remove. - * \return true if a layer was actually deleted, false otherwise. - * this location. - */ - virtual bool DeleteLayer(unsigned int index); - - /** Returns the first layer whose name matches the given name. - * \param name The name of the layer. - * \return a pointer to the layer or NULL if no layer was found. - */ - virtual LayerType * GetLayerByName(std::string name); - - /** Delete the first layer whose name matches the given name. - * \param name The name of the layer. - * \return true if a layer was actually deleted, false otherwise. - * this location. - */ - virtual bool DeleteLayerByName(std::string name); - - /** Clear all layers */ - virtual void ClearLayers(void); - - /** \return The number of layers */ - virtual unsigned int GetNumberOfLayers(void); - /** Get/Set the viewer name */ itkGetStringMacro(Name); itkSetStringMacro(Name); @@ -133,8 +94,6 @@ public: /** Set/Get the Extract Region */ itkSetMacro(ExtractRegion,RegionType); itkGetConstReferenceMacro(ExtractRegion,RegionType); - /** Get the extract region in the quicklook space */ - itkGetConstReferenceMacro(SubsampledExtractRegion,RegionType); /** Set/Get the Scaled Extract Region */ itkSetMacro(ScaledExtractRegion,RegionType); @@ -156,16 +115,15 @@ public: /** Change the extract region by giving the center of the * region */ void SetExtractRegionCenter(const IndexType & index); - - /** Change the extract region by giving the subsamppled center - * of the region */ - void SetExtractRegionSubsampledCenter(const IndexType & index); + + /** Get the sumbsampling rate */ + unsigned int GetSubsamplingRate(); protected: /** Constructor */ - ImageViewerModel(); + ImageLayerRenderingModel(); /** Destructor */ - ~ImageViewerModel(); + ~ImageLayerRenderingModel(); /** Printself method */ void PrintSelf(std::ostream& os, itk::Indent indent) const; @@ -183,15 +141,12 @@ protected: RegionType ConstrainRegion(const RegionType & region, const RegionType & largest); private: - ImageViewerModel(const Self&); // purposely not implemented + ImageLayerRenderingModel(const Self&); // purposely not implemented void operator=(const Self&); // purposely not implemented /** Viewer name */ std::string m_Name; - /** Layer list */ - LayerListPointerType m_Layers; - /** Rasterized quicklook */ OutputImagePointerType m_RasterizedQuicklook; bool m_HasQuicklook; @@ -200,8 +155,7 @@ private: OutputImagePointerType m_RasterizedExtract; bool m_HasExtract; RegionType m_ExtractRegion; - RegionType m_SubsampledExtractRegion; - + /** Rendered scaled extract */ OutputImagePointerType m_RasterizedScaledExtract; bool m_HasScaledExtract; @@ -219,7 +173,7 @@ private: } // end namespace otb #ifndef OTB_MANUAL_INSTANTIATION -#include "otbImageViewerModel.txx" +#include "otbImageLayerRenderingModel.txx" #endif #endif diff --git a/Code/VisuRefac/otbImageViewerModel.txx b/Code/VisuRefac/otbImageLayerRenderingModel.txx similarity index 51% rename from Code/VisuRefac/otbImageViewerModel.txx rename to Code/VisuRefac/otbImageLayerRenderingModel.txx index 946f94e02dc4bdf4db1f5c92dd48ed91a7f6a0e7..5088326d545c2c26ec7a62427eeeea51f082564b 100644 --- a/Code/VisuRefac/otbImageViewerModel.txx +++ b/Code/VisuRefac/otbImageLayerRenderingModel.txx @@ -15,10 +15,10 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __otbImageViewerModel_txx -#define __otbImageViewerModel_txx +#ifndef __otbImageLayerRenderingModel_txx +#define __otbImageLayerRenderingModel_txx -#include "otbImageViewerModel.h" +#include "otbImageLayerRenderingModel.h" #include "otbMacro.h" #include "itkTimeProbe.h" @@ -26,16 +26,14 @@ namespace otb { template <class TOutputImage> -ImageViewerModel<TOutputImage> -::ImageViewerModel() : m_Name("Default"), m_Layers(), m_RasterizedQuicklook(), +ImageLayerRenderingModel<TOutputImage> +::ImageLayerRenderingModel() : m_Name("Default"), m_RasterizedQuicklook(), m_HasQuicklook(false),m_RasterizedExtract(),m_HasExtract(false), - m_ExtractRegion(), m_SubsampledExtractRegion(), m_RasterizedScaledExtract(), m_HasScaledExtract(false), - m_ScaledExtractRegion(), m_QuicklookBlendingFilterList(), m_ExtractBlendingFilterList(), m_ScaledExtractBlendingFilterList() + m_ExtractRegion(), m_RasterizedScaledExtract(), m_HasScaledExtract(false), + m_ScaledExtractRegion(), m_QuicklookBlendingFilterList(), m_ExtractBlendingFilterList(), + m_ScaledExtractBlendingFilterList() { - // Intializing the layer list - m_Layers = LayerListType::New(); - // Initalize the blending filter list m_QuicklookBlendingFilterList = BlendingFilterListType::New(); m_ExtractBlendingFilterList = BlendingFilterListType::New(); @@ -43,140 +41,13 @@ ImageViewerModel<TOutputImage> } template <class TOutputImage> -ImageViewerModel<TOutputImage> -::~ImageViewerModel() -{ - -} - -template <class TOutputImage> -unsigned int -ImageViewerModel<TOutputImage> -::AddLayer(LayerType * layer) -{ - // Push back and return the size-1 - m_Layers->PushBack(layer); - - // Add new blending filters - m_QuicklookBlendingFilterList->PushBack(BlendingFilterType::New()); - m_ExtractBlendingFilterList->PushBack(BlendingFilterType::New()); - m_ScaledExtractBlendingFilterList->PushBack(BlendingFilterType::New()); - - return (m_Layers->Size()-1); -} - -template <class TOutputImage> -typename ImageViewerModel<TOutputImage> -::LayerType * -ImageViewerModel<TOutputImage> -::GetLayer(unsigned int index) -{ - // Check if not out of bound and return the ith element - if(index >= m_Layers->Size()) - { - return NULL; - } - else - { - return m_Layers->GetNthElement(index); - } -} -template <class TOutputImage> -bool -ImageViewerModel<TOutputImage> -::DeleteLayer(unsigned int index) -{ -// Check if not out of bound and delete the ith element - if(index >= m_Layers->Size()) - { - return false; - } - else - { - m_Layers->Erase(index); - m_QuicklookBlendingFilterList->Erase(index); - m_ExtractBlendingFilterList->Erase(index); - m_ScaledExtractBlendingFilterList->Erase(index); - return true; - } -} - -template <class TOutputImage> -typename ImageViewerModel<TOutputImage> -::LayerType * -ImageViewerModel<TOutputImage> -::GetLayerByName(std::string name) -{ - LayerType * resp = NULL; - LayerIteratorType it = m_Layers->Begin(); - bool found = false; - - // Look for the layer named after name - while(it!=m_Layers->End() && !found) - { - if(it.Get()->GetName() == name) - { - resp = it.Get(); - found = true; - } - } - return resp; -} - -template <class TOutputImage> -bool -ImageViewerModel<TOutputImage> -::DeleteLayerByName(std::string name) -{ - LayerIteratorType it = m_Layers->Begin(); - bool found = false; - unsigned int index = 0; - - // Look for the layer named after name - while(it!=m_Layers->End() && !found) - { - if(it.Get()->GetName() == name) - { - found = true; - } - ++index; - } - - if(found) - { - m_Layers->Erase(index-1); - m_QuicklookBlendingFilterList->Erase(index-1); - m_ExtractBlendingFilterList->Erase(index-1); - m_ScaledExtractBlendingFilterList->Erase(index-1); - } - - return found; -} - -template <class TOutputImage> -void -ImageViewerModel<TOutputImage> -::ClearLayers() -{ - // Clear layers list - m_Layers->Clear(); - m_QuicklookBlendingFilterList->Clear(); - m_ExtractBlendingFilterList->Clear(); - m_ScaledExtractBlendingFilterList->Clear(); -} - -template <class TOutputImage> -unsigned int -ImageViewerModel<TOutputImage> -::GetNumberOfLayers(void) -{ - // return layer list size - return m_Layers->Size(); -} +ImageLayerRenderingModel<TOutputImage> +::~ImageLayerRenderingModel() +{} template <class TOutputImage> void -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::Update() { // Multiple concurrent update guards @@ -195,12 +66,12 @@ ImageViewerModel<TOutputImage> template <class TOutputImage> void -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::RenderVisibleLayers() { // Render all visible layers - for(LayerIteratorType it = m_Layers->Begin(); - it != m_Layers->End(); ++it) + for(LayerIteratorType it = this->GetLayers()->Begin(); + it != this->GetLayers()->End(); ++it) { // If the layer is visible if(it.Get()->GetVisible()) @@ -212,7 +83,7 @@ ImageViewerModel<TOutputImage> m_ScaledExtractRegion = this->ConstrainRegion(m_ScaledExtractRegion,m_ExtractRegion); it.Get()->SetScaledExtractRegion(m_ScaledExtractRegion); // Render it - otbMsgDevMacro(<<"ImageViewerModel::RenderVisibleLayers(): Rendering layer "<<it.Get()->GetName()<<" with regions ("<<m_ExtractRegion.GetIndex()<<" "<<m_ExtractRegion.GetSize()<<") ("<<m_ScaledExtractRegion.GetIndex()<<" "<<m_ScaledExtractRegion.GetSize()<<")"); + otbMsgDevMacro(<<"ImageLayerRenderingModel::RenderVisibleLayers(): Rendering layer "<<it.Get()->GetName()<<" with regions ("<<m_ExtractRegion.GetIndex()<<" "<<m_ExtractRegion.GetSize()<<") ("<<m_ScaledExtractRegion.GetIndex()<<" "<<m_ScaledExtractRegion.GetSize()<<")"); it.Get()->Render(); } } @@ -220,7 +91,7 @@ ImageViewerModel<TOutputImage> template <class TOutputImage> void -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::RasterizeVisibleLayers() { // If there are no layer to render @@ -235,25 +106,14 @@ ImageViewerModel<TOutputImage> } // Get the lowest layer - LayerIteratorType it = m_Layers->Begin(); - - BlendingFilterIteratorType qlBlenderIt = m_QuicklookBlendingFilterList->Begin(); - BlendingFilterIteratorType extBlenderIt = m_ExtractBlendingFilterList->Begin(); - BlendingFilterIteratorType scalBlenderIt = m_ScaledExtractBlendingFilterList->Begin(); - + LayerIteratorType it = this->GetLayers()->Begin(); bool visible = false; - while(!visible && it != m_Layers->End() - && qlBlenderIt != m_QuicklookBlendingFilterList->End() - && extBlenderIt != m_ExtractBlendingFilterList->End() - && scalBlenderIt != m_ScaledExtractBlendingFilterList->End()) + while(!visible && it != this->GetLayers()->End()) { visible = it.Get()->GetVisible(); ++it; - ++qlBlenderIt; - ++extBlenderIt; - ++scalBlenderIt; } if(!visible) @@ -262,31 +122,17 @@ ImageViewerModel<TOutputImage> return; } --it; - --qlBlenderIt; - --extBlenderIt; - --scalBlenderIt; // base layer typename LayerType::Pointer baseLayer = it.Get(); - otbMsgDevMacro(<<"ImageViewerModel::RasterizeVisibleLayers(): Found base layer named "<<it.Get()->GetName()); + otbMsgDevMacro(<<"ImageLayerRenderingModel::RasterizeVisibleLayers(): Found base layer named "<<it.Get()->GetName()); // Configure base layer rasterization if(baseLayer->GetHasQuicklook()) { m_HasQuicklook = true; m_RasterizedQuicklook = baseLayer->GetRenderedQuicklook(); - - // Update the subsampled extract region - m_SubsampledExtractRegion = m_ExtractRegion; - typename RegionType::SizeType size = m_SubsampledExtractRegion.GetSize(); - typename RegionType::IndexType index = m_SubsampledExtractRegion.GetIndex(); - size[0]/=baseLayer->GetQuicklookSubsamplingRate(); - size[1]/=baseLayer->GetQuicklookSubsamplingRate(); - index[0]/=baseLayer->GetQuicklookSubsamplingRate(); - index[1]/=baseLayer->GetQuicklookSubsamplingRate(); - m_SubsampledExtractRegion.SetIndex(index); - m_SubsampledExtractRegion.SetSize(size); } if(baseLayer->GetHasExtract()) @@ -303,16 +149,25 @@ ImageViewerModel<TOutputImage> // Move to the next layer ++it; - ++qlBlenderIt; - ++extBlenderIt; - ++scalBlenderIt; - + // Walk the remaining layers - while(it!=m_Layers->End() - && qlBlenderIt != m_QuicklookBlendingFilterList->End() - && extBlenderIt != m_ExtractBlendingFilterList->End() - && scalBlenderIt != m_ScaledExtractBlendingFilterList->End()) + unsigned int count = 0; + while(it!=this->GetLayers()->End()) { + // Populate Blending filter list if needed + if(count >= m_QuicklookBlendingFilterList->Size()) + { + m_QuicklookBlendingFilterList->PushBack(BlendingFilterType::New()); + } + if(count >= m_ExtractBlendingFilterList->Size()) + { + m_ExtractBlendingFilterList->PushBack(BlendingFilterType::New()); + } + if(count >= m_ScaledExtractBlendingFilterList->Size()) + { + m_ScaledExtractBlendingFilterList->PushBack(BlendingFilterType::New()); + } + // If a layer is visible if(it.Get()->GetVisible()) { @@ -322,7 +177,7 @@ ImageViewerModel<TOutputImage> if(m_HasQuicklook && it.Get()->GetHasQuicklook()) { // Blend it with the current rasterized quicklook - typename BlendingFilterType::Pointer blender =/** BlendingFilterType::New();*/qlBlenderIt.Get(); + typename BlendingFilterType::Pointer blender = m_QuicklookBlendingFilterList->GetNthElement(count); // Using the blending function of the layer blender->SetBlendingFunction(it.Get()->GetBlendingFunction()); blender->SetInput1(m_RasterizedQuicklook); @@ -336,7 +191,7 @@ ImageViewerModel<TOutputImage> if(m_HasExtract && it.Get()->GetHasExtract()) { // Blend it with the current rasterized extract - typename BlendingFilterType::Pointer blender =/** BlendingFilterType::New();*/extBlenderIt.Get(); + typename BlendingFilterType::Pointer blender = m_ExtractBlendingFilterList->GetNthElement(count); // Using the blending function of the layer blender->SetBlendingFunction(it.Get()->GetBlendingFunction()); blender->SetInput1(m_RasterizedExtract); @@ -351,7 +206,7 @@ ImageViewerModel<TOutputImage> if(m_HasScaledExtract && it.Get()->GetHasScaledExtract()) { // Blend it with the current rasterized scaledExtract - typename BlendingFilterType::Pointer blender = /**BlendingFilterType::New();*/ scalBlenderIt.Get(); + typename BlendingFilterType::Pointer blender = m_ScaledExtractBlendingFilterList->GetNthElement(count); // Using the blending function of the layer blender->SetBlendingFunction(it.Get()->GetBlendingFunction()); blender->SetInput1(m_RasterizedScaledExtract); @@ -362,30 +217,28 @@ ImageViewerModel<TOutputImage> m_RasterizedScaledExtract = blender->GetOutput(); } probe.Stop(); - otbMsgDevMacro("ImageViewerModel::RasterizeVisibleLayers(): Previous layer rasterized with layer "<<it.Get()->GetName()<<" ( "<<probe.GetMeanTime()<<" s.)"); + otbMsgDevMacro("ImageLayerRenderingModel::RasterizeVisibleLayers(): Previous layer rasterized with layer "<<it.Get()->GetName()<<" ( "<<probe.GetMeanTime()<<" s.)"); } ++it; - ++qlBlenderIt; - ++extBlenderIt; - ++scalBlenderIt; + ++count; } } template <class TOutputImage> void -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::Notify(ListenerType * listener) { // Notify the listener - otbMsgDevMacro(<<"ImageViewerModel::Notify(): Notifying listener"); - listener->ImageViewerNotify(); + otbMsgDevMacro(<<"ImageLayerRenderingModel::Notify(): Notifying listener"); + listener->ImageLayerRenderingModelNotify(); } template <class TOutputImage> void -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::SetScaledExtractRegionCenter(const IndexType & index) { // Set the center of the scaled extract region @@ -397,7 +250,7 @@ ImageViewerModel<TOutputImage> template <class TOutputImage> void -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::SetExtractRegionCenter(const IndexType & index) { // Set the center of the extract region @@ -413,44 +266,37 @@ ImageViewerModel<TOutputImage> } template <class TOutputImage> -void -ImageViewerModel<TOutputImage> -::SetExtractRegionSubsampledCenter(const IndexType & index) +unsigned int +ImageLayerRenderingModel<TOutputImage> +::GetSubsamplingRate() { -// Get the lowest layer - LayerIteratorType it = m_Layers->Begin(); + if(this->GetNumberOfLayers() < 1) + { + return 1; + } + // Get the lowest layer + LayerIteratorType it = this->GetLayers()->Begin(); // Base layer typename LayerType::Pointer baseLayer = it.Get(); - // Set compute the upsampled center of the extract region - IndexType newIndex = index; - newIndex[0]*= baseLayer->GetQuicklookSubsamplingRate(); - newIndex[1]*= baseLayer->GetQuicklookSubsamplingRate(); - - // Update Scaled extract center as well - this->SetScaledExtractRegionCenter(newIndex); - - // Update extract region - newIndex[0]-=m_ExtractRegion.GetSize()[0]/2; - newIndex[1]-=m_ExtractRegion.GetSize()[1]/2; - m_ExtractRegion.SetIndex(newIndex); + return baseLayer->GetQuicklookSubsamplingRate(); } template <class TOutputImage> -typename ImageViewerModel<TOutputImage> +typename ImageLayerRenderingModel<TOutputImage> ::RegionType -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::ConstrainRegion(const RegionType & small, const RegionType & big) { RegionType resp = small; // If not small is larger than big, then crop if (small.GetSize()[0]>big.GetSize()[0] ||small.GetSize()[1]>big.GetSize()[1]) - { - resp.Crop(big); - } + { + resp.Crop(big); + } else - { - // Else we can constrain it + { + // Else we can constrain it IndexType index = resp.GetIndex(); typename RegionType::SizeType size = resp.GetSize(); @@ -470,20 +316,20 @@ ImageViewerModel<TOutputImage> } resp.SetSize(size); resp.SetIndex(index); - } + } return resp; } template <class TOutputImage> void -ImageViewerModel<TOutputImage> +ImageLayerRenderingModel<TOutputImage> ::PrintSelf(std::ostream& os, itk::Indent indent) const { // Call superclass implementation Superclass::PrintSelf(os,indent); os<<indent<<"Viewer "<<m_Name<<": "<<std::endl; - for(LayerIteratorType it = m_Layers->Begin(); - it != m_Layers->End(); ++it) + for(LayerIteratorType it = this->GetLayers()->Begin(); + it != this->GetLayers()->End(); ++it) { os<<indent<<it.Get()<<std::endl; } diff --git a/Code/VisuRefac/otbImageViewerModelListener.h b/Code/VisuRefac/otbImageLayerRenderingModelListener.h similarity index 65% rename from Code/VisuRefac/otbImageViewerModelListener.h rename to Code/VisuRefac/otbImageLayerRenderingModelListener.h index 361a80d8bd1b198299fa332ba6a8427d8ab36190..fdcbeeefec93d8825ed51f729718870cd65de476 100644 --- a/Code/VisuRefac/otbImageViewerModelListener.h +++ b/Code/VisuRefac/otbImageLayerRenderingModelListener.h @@ -15,35 +15,35 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __otbImageViewerModelListener_h -#define __otbImageViewerModelListener_h +#ifndef __otbImageLayerRenderingModelListener_h +#define __otbImageLayerRenderingModelListener_h namespace otb { /** - * \class ImageViewerModelListener + * \class ImageLayerRenderingModelListener * * Vectorization view interface specification for the model * */ -class ImageViewerModelListener +class ImageLayerRenderingModelListener { public: /** Standard class typedefs */ - typedef ImageViewerModelListener Self; + typedef ImageLayerRenderingModelListener Self; // Update the display - virtual void ImageViewerNotify() = 0; + virtual void ImageLayerRenderingModelNotify() = 0; protected: /** Constructor */ - ImageViewerModelListener() {}; + ImageLayerRenderingModelListener() {}; /** Destructor */ - virtual ~ImageViewerModelListener() {}; + virtual ~ImageLayerRenderingModelListener() {}; private: - ImageViewerModelListener(const Self&); //purposely not implemented + ImageLayerRenderingModelListener(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented }; diff --git a/Code/VisuRefac/otbImageView.h b/Code/VisuRefac/otbImageView.h index 41186a84b72cec68f00c355ce7c7e4f92dacb159..2149c9b0f84f85c243b4f59d47b4c91c980d33c7 100644 --- a/Code/VisuRefac/otbImageView.h +++ b/Code/VisuRefac/otbImageView.h @@ -19,8 +19,7 @@ #define __otbImageView_h #include "otbImageWidget.h" -#include "otbImageViewerModelListener.h" -#include "otbImageViewerModel.h" +#include "otbImageLayerRenderingModelListener.h" #include "otbImageWidgetController.h" namespace otb @@ -33,7 +32,7 @@ namespace otb template <class TViewerModel > class ImageView - : public ImageViewerModelListener, public itk::Object + : public ImageLayerRenderingModelListener, public itk::Object { public: /** Standard class typedefs */ @@ -107,7 +106,7 @@ public: void UpdateZoomWidget(); /** Handle notification from the viewer */ - virtual void ImageViewerNotify(); + virtual void ImageLayerRenderingModelNotify(); private: ImageView(const Self&); // purposely not implemented diff --git a/Code/VisuRefac/otbImageView.txx b/Code/VisuRefac/otbImageView.txx index 1677c5102a289a664b4702607b5a59d64153f956..cd0352d35dd7dc4c8ad5e5ab13a89ef6445911b7 100644 --- a/Code/VisuRefac/otbImageView.txx +++ b/Code/VisuRefac/otbImageView.txx @@ -85,7 +85,7 @@ ImageView<TInputImage> template < class TInputImage > void ImageView<TInputImage> -::ImageViewerNotify() +::ImageLayerRenderingModelNotify() { this->Update(); } @@ -120,6 +120,7 @@ ImageView<TInputImage> const double hratio = static_cast<double>(m_ScrollWidget->h())/static_cast<double>(qlRegion.GetSize()[1]); const double scale = std::min(wratio,hratio); m_ScrollWidget->SetIsotropicZoom(scale); + m_ScrollWidget->SetSubsamplingRate(m_Model->GetSubsamplingRate()); // Setting widget label std::string label = m_ScrollWidget->GetIdentifier(); @@ -131,7 +132,7 @@ ImageView<TInputImage> if(m_Model->GetHasExtract()) { m_ScrollWidget->SetDisplayRectangle(true); - m_ScrollWidget->SetRectangle(m_Model->GetSubsampledExtractRegion()); + m_ScrollWidget->SetRectangle(m_Model->GetExtractRegion()); } else { diff --git a/Code/VisuRefac/otbImageWidget.h b/Code/VisuRefac/otbImageWidget.h index 931b690fc5337f1a6b31cd01bbafb993a4bbee10..952bf3b59fac466531150fc7d52f720df1c539f1 100644 --- a/Code/VisuRefac/otbImageWidget.h +++ b/Code/VisuRefac/otbImageWidget.h @@ -123,12 +123,24 @@ public: itkSetMacro(RectangleColor,ColorType); itkGetConstReferenceMacro(RectangleColor,ColorType); + /** Set/Get the subsampling rate */ + itkSetMacro(SubsamplingRate,unsigned int); + itkGetMacro(SubsamplingRate,unsigned int); + /** Convert a screen index to a buffered region index */ IndexType ScreenIndexToRegionIndex(const IndexType& index ); /** Convert a buffered region index to a screen index */ IndexType RegionIndexToScreenIndex(const IndexType& index); + /** Convert a screen index to an image index (taking into account + * subsampling rate) */ + IndexType ScreenIndexToImageIndex(const IndexType& index ); + + /** Convert an image index to a screen index (taking into account + * subsamplinh rate) */ + IndexType ImageIndexToScreenIndex(const IndexType& index); + protected: /** Constructor */ ImageWidget(); @@ -199,6 +211,11 @@ private: double m_ImageExtentX; double m_ImageExtentY; + /** If the image is subsampled with respect to the original image, + * this indicates the subsampling rate */ + unsigned int m_SubsamplingRate; + + }; // end class } // end namespace otb diff --git a/Code/VisuRefac/otbImageWidget.txx b/Code/VisuRefac/otbImageWidget.txx index 71f605a92e0ded99e6fc47832bb8811bf76e583d..01015eef8b25ac2118311ae559a77500077fa26c 100644 --- a/Code/VisuRefac/otbImageWidget.txx +++ b/Code/VisuRefac/otbImageWidget.txx @@ -27,7 +27,8 @@ template <class TInputImage> ImageWidget<TInputImage> ::ImageWidget() : Fl_Gl_Window(0,0,0,0), m_IsotropicZoom(1.0), m_OpenGlBuffer(NULL), m_OpenGlBufferedRegion(), m_Identifier("Default"), m_UseGlAcceleration(false), m_Rectangle(),m_DisplayRectangle(false), - m_RectangleColor(), m_ImageExtentWidth(0), m_ImageExtentHeight(0), m_ImageExtentX(), m_ImageExtentY() + m_RectangleColor(), m_ImageExtentWidth(0), m_ImageExtentHeight(0), m_ImageExtentX(), m_ImageExtentY(), + m_SubsamplingRate(1) { #ifdef OTB_GL_USE_ACCEL m_UseGlAcceleration = true; @@ -235,10 +236,10 @@ ImageWidget<TInputImage> // UL left in image space is LR in opengl space, so we need to get // the real upper left index[1]+=m_Rectangle.GetSize()[1]; - index = RegionIndexToScreenIndex(index); + index = ImageIndexToScreenIndex(index); - size[0]= static_cast<unsigned int>(static_cast<double>(m_Rectangle.GetSize()[0])*m_IsotropicZoom); - size[1] = static_cast<unsigned int>(static_cast<double>(m_Rectangle.GetSize()[1])*m_IsotropicZoom); + size[0]= static_cast<unsigned int>(static_cast<double>(m_Rectangle.GetSize()[0]/m_SubsamplingRate)*m_IsotropicZoom); + size[1] = static_cast<unsigned int>(static_cast<double>(m_Rectangle.GetSize()[1]/m_SubsamplingRate)*m_IsotropicZoom); glEnable(GL_BLEND); @@ -315,6 +316,18 @@ ImageWidget<TInputImage> return resp; } +template <class TInputImage> +typename ImageWidget<TInputImage> +::IndexType +ImageWidget<TInputImage> +::ScreenIndexToImageIndex(const IndexType & index) +{ + IndexType resp = ScreenIndexToRegionIndex(index); + resp[0]*=m_SubsamplingRate; + resp[1]*=m_SubsamplingRate; + return resp; +} + template <class TInputImage> typename ImageWidget<TInputImage> ::IndexType @@ -327,5 +340,17 @@ ImageWidget<TInputImage> return resp; } +template <class TInputImage> +typename ImageWidget<TInputImage> +::IndexType +ImageWidget<TInputImage> +::ImageIndexToScreenIndex(const IndexType & index) +{ + IndexType resp; + resp[0]=static_cast<int>(m_ImageExtentX+(index[0]/m_SubsamplingRate-m_OpenGlBufferedRegion.GetIndex()[0])*m_IsotropicZoom); + resp[1]=static_cast<int>(m_ImageExtentY+m_ImageExtentHeight-(index[1]/m_SubsamplingRate-m_OpenGlBufferedRegion.GetIndex()[1])*m_IsotropicZoom); + return resp; +} + } #endif diff --git a/Code/VisuRefac/otbLayerBasedModel.h b/Code/VisuRefac/otbLayerBasedModel.h new file mode 100644 index 0000000000000000000000000000000000000000..cef48ddd41c30fb9dc9e048c979c00af8204f5b3 --- /dev/null +++ b/Code/VisuRefac/otbLayerBasedModel.h @@ -0,0 +1,131 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbLayerBasedModel_h +#define __otbLayerBasedModel_h + +#include "itkObject.h" +#include "otbObjectList.h" + +namespace otb +{ +/** \class LayerBasedModel +* \brief Base class providing layer stack model +* +* \sa Layer, ImageLayer +* \sa BlendingFunction +* +*/ + +template <class TLayer > +class LayerBasedModel + : public itk::Object +{ +public: + /** Standard class typedefs */ + typedef LayerBasedModel Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Runtime information */ + itkTypeMacro(LayerBasedModel,Object); + + /** New macro */ + itkNewMacro(Self); + + /** Layer typedef */ + typedef TLayer LayerType; + + /** Layer list typedef */ + typedef otb::ObjectList<LayerType> LayerListType; + typedef typename LayerListType::Pointer LayerListPointerType; + typedef typename LayerListType::ConstIterator LayerIteratorType; + + /** Add a new layer + * \param layer The layer to add. + * \return The location of the added layer. + */ + virtual unsigned int AddLayer(LayerType * layer); + + /** Get the layer at the current index + * \param index The index of the layer to get. + * \return a pointer to the layer or NULL if no layer was found at + * this location. + */ + virtual LayerType * GetLayer(unsigned int index); + + /** Remove the layer at the current index + * \param index The index of the layer to remove. + * \return true if a layer was actually deleted, false otherwise. + * this location. + */ + virtual bool DeleteLayer(unsigned int index); + + /** Returns the first layer whose name matches the given name. + * \param name The name of the layer. + * \return a pointer to the layer or NULL if no layer was found. + */ + virtual LayerType * GetLayerByName(std::string name); + + /** Delete the first layer whose name matches the given name. + * \param name The name of the layer. + * \return true if a layer was actually deleted, false otherwise. + * this location. + */ + virtual bool DeleteLayerByName(std::string name); + + /** Clear all layers */ + virtual void ClearLayers(void); + + /** \return The number of layers */ + virtual unsigned int GetNumberOfLayers(void); + + /** Set/Get the layers stack */ + itkSetObjectMacro(Layers,LayerListType); + itkGetObjectMacro(Layers,LayerListType); + + +protected: + /** Constructor */ + LayerBasedModel(); + /** Destructor */ + ~LayerBasedModel(); + + /** Printself method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +/** Get the layer list (Convenience for subclasses) */ + itkGetConstObjectMacro(Layers,LayerListType); + +private: + LayerBasedModel(const Self&); // purposely not implemented + void operator=(const Self&); // purposely not implemented + + /** Layer list */ + LayerListPointerType m_Layers; + +}; // end class +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbLayerBasedModel.txx" +#endif + +#endif + + diff --git a/Code/VisuRefac/otbLayerBasedModel.txx b/Code/VisuRefac/otbLayerBasedModel.txx new file mode 100644 index 0000000000000000000000000000000000000000..641ddbf7ec5b31988d5135c54a4f35da560738fc --- /dev/null +++ b/Code/VisuRefac/otbLayerBasedModel.txx @@ -0,0 +1,164 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbLayerBasedModel_txx +#define __otbLayerBasedModel_txx + +#include "otbLayerBasedModel.h" +#include "otbMacro.h" +#include "itkTimeProbe.h" + +namespace otb +{ + +template <class TLayer> +LayerBasedModel<TLayer> +::LayerBasedModel() : m_Layers() + +{ + // Intializing the layer list + m_Layers = LayerListType::New(); +} + +template <class TLayer> +LayerBasedModel<TLayer> +::~LayerBasedModel() +{} + +template <class TLayer> +unsigned int +LayerBasedModel<TLayer> +::AddLayer(LayerType * layer) +{ + // Push back and return the size-1 + m_Layers->PushBack(layer); + + // Return the layer index + return m_Layers->Size()-1; +} + +template <class TLayer> +typename LayerBasedModel<TLayer> +::LayerType * +LayerBasedModel<TLayer> +::GetLayer(unsigned int index) +{ + // Check if not out of bound and return the ith element + if(index >= m_Layers->Size()) + { + return NULL; + } + else + { + return m_Layers->GetNthElement(index); + } +} +template <class TLayer> +bool +LayerBasedModel<TLayer> +::DeleteLayer(unsigned int index) +{ +// Check if not out of bound and delete the ith element + if(index >= m_Layers->Size()) + { + return false; + } + else + { + m_Layers->Erase(index); + return true; + } +} + +template <class TLayer> +typename LayerBasedModel<TLayer> +::LayerType * +LayerBasedModel<TLayer> +::GetLayerByName(std::string name) +{ + LayerType * resp = NULL; + LayerIteratorType it = m_Layers->Begin(); + bool found = false; + + // Look for the layer named after name + while(it!=m_Layers->End() && !found) + { + if(it.Get()->GetName() == name) + { + resp = it.Get(); + found = true; + } + } + return resp; +} + +template <class TLayer> +bool +LayerBasedModel<TLayer> +::DeleteLayerByName(std::string name) +{ + LayerIteratorType it = m_Layers->Begin(); + bool found = false; + unsigned int index = 0; + + // Look for the layer named after name + while(it!=m_Layers->End() && !found) + { + if(it.Get()->GetName() == name) + { + found = true; + } + ++index; + } + + if(found) + { + m_Layers->Erase(index-1); + } + return found; +} + +template <class TLayer> +void +LayerBasedModel<TLayer> +::ClearLayers() +{ + // Clear layers list + m_Layers->Clear(); +} + +template <class TLayer> +unsigned int +LayerBasedModel<TLayer> +::GetNumberOfLayers(void) +{ + // return layer list size + return m_Layers->Size(); +} + +template <class TLayer> +void +LayerBasedModel<TLayer> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + // Call superclass implementation + Superclass::PrintSelf(os,indent); +} + +} // end namespace otb + +#endif diff --git a/Code/VisuRefac/otbMVCModel.h b/Code/VisuRefac/otbMVCModelBase.h similarity index 76% rename from Code/VisuRefac/otbMVCModel.h rename to Code/VisuRefac/otbMVCModelBase.h index a44b556a07d66482ced88775df6a247bc170bf21..c4a699398f40eaca7a57fe1d0a83c69fef983aeb 100644 --- a/Code/VisuRefac/otbMVCModel.h +++ b/Code/VisuRefac/otbMVCModelBase.h @@ -15,36 +15,23 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __otbMVCModel_h -#define __otbMVCModel_h +#ifndef __otbMVCModelBase_h +#define __otbMVCModelBase_h #include <set> -#include "itkObject.h" -#include "itkObjectFactory.h" namespace otb { -/** \class MVCModel +/** \class MVCModelBase * - * Base class for MVC based modelling. Implements the registration and + * Interface class for MVC based modelling. Implements the registration and * Unregistration of listeners, as well as the NotifyAll method. A valid listener must * implement a Notify() method. */ template <class TListener> -class MVCModel - : public itk::Object +class MVCModelBase { public: - /** Standard class typedefs */ - typedef MVCModel Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Standard macros */ - itkTypeMacro(MVCModel,Object); - itkNewMacro(Self); - // Define the listener type typedef TListener ListenerType; @@ -84,9 +71,9 @@ public: protected: /** Constructor */ - MVCModel() {} + MVCModelBase() {} /** Destructor */ - ~MVCModel() {} + ~MVCModelBase() {} private: /** Registered liteners */ diff --git a/Code/VisuRefac/otbPixelDescriptionActionHandler.h b/Code/VisuRefac/otbPixelDescriptionActionHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..527b153b4400ef969600ef39d847522fd4e20075 --- /dev/null +++ b/Code/VisuRefac/otbPixelDescriptionActionHandler.h @@ -0,0 +1,155 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbPixelDescriptionActionHandler_h +#define __otbPixelDescriptionActionHandler_h + +#include "otbImageWidgetActionHandler.h" + +namespace otb +{ +/** \class PixelDescriptionActionHandler +* \brief Implements pixel reporting capabilities. +* +* \sa ImageWidgetController +* \sa ImageWidgetActionHandler +*/ + +template <class TModel, class TView> +class PixelDescriptionActionHandler + : public ImageWidgetActionHandler +{ +public: + /** Standard class typedefs */ + typedef PixelDescriptionActionHandler Self; + typedef ImageWidgetActionHandler Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory */ + itkNewMacro(Self); + + /** Runtime information */ + itkTypeMacro(PixelDescriptionActionHandler,ImageWidgetActionHandler); + + /** Model typedefs */ + typedef TModel ModelType; + typedef typename ModelType::Pointer ModelPointerType; + typedef typename ModelType::IndexType IndexType; + + /** View typedef */ + typedef TView ViewType; + typedef typename ViewType::Pointer ViewPointerType; + typedef typename ViewType::ImageWidgetPointerType WidgetPointerType; + + /** Handle widget event + */ + virtual bool HandleWidgetEvent(std::string widgetId, int event) + { + if(m_Model.IsNotNull() && m_View.IsNotNull()) + { + // Find the source widget + WidgetPointerType sourceWidget; + bool handle = false; + if(widgetId == m_View->GetScrollWidget()->GetIdentifier() ) + { + sourceWidget = m_View->GetScrollWidget(); + handle = true; + } + else if(widgetId == m_View->GetFullWidget()->GetIdentifier() ) + { + sourceWidget = m_View->GetFullWidget(); + handle = true; + } + else if(widgetId == m_View->GetZoomWidget()->GetIdentifier() ) + { + sourceWidget = m_View->GetZoomWidget(); + handle = true; + } + if(handle) + { + switch(event) + { + case FL_ENTER: + { + return true; + break; + } + case FL_LEAVE: + { + return true; + break; + } + case FL_MOVE: + { + // Get the hovered index + IndexType index; + index[0]=Fl::event_x(); + index[1]=Fl::event_y(); + // Convert to image index + index = sourceWidget->ScreenIndexToImageIndex(index); + // Communicate new index to model + m_Model->UpdatePixelDescription(index); + return true; + break; + } + default: + { + break; + } + } + } + } + return false; + } + + /** Set/Get the pointer to the model */ + itkSetObjectMacro(Model,ModelType); + itkGetObjectMacro(Model,ModelType); + + /** Set/Get the pointer to the view */ + itkSetObjectMacro(View,ViewType); + itkGetObjectMacro(View,ViewType); + +protected: + /** Constructor */ + PixelDescriptionActionHandler() : m_View(), m_Model() + {} + + /** Destructor */ + virtual ~PixelDescriptionActionHandler(){} + /** Printself method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + } + +private: + PixelDescriptionActionHandler(const Self&); // purposely not implemented + void operator=(const Self&); // purposely not implemented + + // Pointer to the view + ViewPointerType m_View; + + // Pointer to the model + ModelPointerType m_Model; + +}; // end class +} // end namespace otb +#endif + + diff --git a/Code/VisuRefac/otbPixelDescriptionModel.h b/Code/VisuRefac/otbPixelDescriptionModel.h new file mode 100644 index 0000000000000000000000000000000000000000..9412109a3968350770982f24312fdabc7dd9bcd4 --- /dev/null +++ b/Code/VisuRefac/otbPixelDescriptionModel.h @@ -0,0 +1,98 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbPixelDescriptionModel_h +#define __otbPixelDescriptionModel_h + +#include "otbMVCModelBase.h" +#include "otbLayerBasedModel.h" +#include "otbPixelDescriptionModelListener.h" +#include "otbImageLayerBase.h" + +namespace otb +{ +/** \class PixelDescriptionModel +* \brief This class is a layer based model reporting pixel information +* +* \sa ImageLayer +* +*/ + +template <class TOutputImage > +class PixelDescriptionModel + : public MVCModelBase<PixelDescriptionModelListener>, public LayerBasedModel< ImageLayerBase< TOutputImage > > +{ +public: + /** Standard class typedefs */ + typedef PixelDescriptionModel Self; + typedef LayerBasedModel< ImageLayerBase<TOutputImage > > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Runtime information */ + itkTypeMacro(PixelDescriptionModel,LayerBasedModel); + + /** New macro */ + itkNewMacro(Self); + + /** Layer typedef */ + typedef typename Superclass::LayerType LayerType; + + /** We assume that TLayer is has an IndexType definition */ + typedef typename LayerType::IndexType IndexType; + + /** Listener typedef */ + typedef PixelDescriptionModelListener ListenerType; + + /** Get/Set the viewer name */ + itkGetStringMacro(PixelDescription); + + /** Clear the pixel description */ + void ClearPixelDescription(); + + /** Update the pixel description */ + void UpdatePixelDescription(const IndexType & index); + +protected: + /** Constructor */ + PixelDescriptionModel(); + /** Destructor */ + ~PixelDescriptionModel(); + + /** Printself method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + /** Notify a registered listener */ + void Notify(ListenerType * listener); + +private: + PixelDescriptionModel(const Self&); // purposely not implemented + void operator=(const Self&); // purposely not implemented + + /** The pixel description */ + std::string m_PixelDescription; + +}; // end class +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbPixelDescriptionModel.txx" +#endif + +#endif + + diff --git a/Code/VisuRefac/otbPixelDescriptionModel.txx b/Code/VisuRefac/otbPixelDescriptionModel.txx new file mode 100644 index 0000000000000000000000000000000000000000..ac20aecec746c8050d428582fc897fd288bca124 --- /dev/null +++ b/Code/VisuRefac/otbPixelDescriptionModel.txx @@ -0,0 +1,89 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbPixelDescriptionModel_txx +#define __otbPixelDescriptionModel_txx + +#include "otbPixelDescriptionModel.h" +#include "otbMacro.h" +#include "itkTimeProbe.h" + +namespace otb +{ + +template <class TOutputImage> +PixelDescriptionModel<TOutputImage> +::PixelDescriptionModel() : m_PixelDescription("") +{ +} + +template <class TOutputImage> +PixelDescriptionModel<TOutputImage> +::~PixelDescriptionModel() +{} +template <class TOutputImage> +void +PixelDescriptionModel<TOutputImage> +::ClearPixelDescription() +{ + m_PixelDescription = ""; +} + +template <class TOutputImage> +void +PixelDescriptionModel<TOutputImage> +::UpdatePixelDescription(const IndexType & index) +{ + // The output stringstream + itk::OStringStream oss; + oss<<"Index: "<<index<<std::endl; + // Report pixel info for each visible layer + for(typename Superclass::LayerIteratorType it = this->GetLayers()->Begin(); + it != this->GetLayers()->End(); ++it) + { + // If the layer is visible + if(it.Get()->GetVisible()) + { + // Get the pixel description + oss<<it.Get()->GetPixelDescription(index)<<std::endl; + } + } + m_PixelDescription = oss.str(); + + // Notify all listeners + this->NotifyAll(); +} + +template <class TOutputImage> +void +PixelDescriptionModel<TOutputImage> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os,indent); +} + +template <class TOutputImage> +void +PixelDescriptionModel<TOutputImage> +::Notify(ListenerType * listener) +{ + listener->PixelDescriptionModelNotify(); +} + +} // end namespace otb + +#endif diff --git a/Code/VisuRefac/otbPixelDescriptionModelListener.h b/Code/VisuRefac/otbPixelDescriptionModelListener.h new file mode 100644 index 0000000000000000000000000000000000000000..bc5e080340da98e9e9ad0d0adc953a15d8fc137b --- /dev/null +++ b/Code/VisuRefac/otbPixelDescriptionModelListener.h @@ -0,0 +1,49 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbPixelDescriptionModelListener_h +#define __otbPixelDescriptionModelListener_h + +namespace otb +{ +/** + * \class PixelDescriptionModelListener + * + */ + +class PixelDescriptionModelListener +{ +public: + /** Standard class typedefs */ + typedef PixelDescriptionModelListener Self; + + // Update the display + virtual void PixelDescriptionModelNotify() = 0; + +protected: + /** Constructor */ + PixelDescriptionModelListener() {}; + /** Destructor */ + virtual ~PixelDescriptionModelListener() {}; + +private: + PixelDescriptionModelListener(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + +} // end namespace otb +#endif diff --git a/Code/VisuRefac/otbPixelDescriptionView.h b/Code/VisuRefac/otbPixelDescriptionView.h new file mode 100644 index 0000000000000000000000000000000000000000..01fd9186fbcdf775c140c970cb162a311e13b0dc --- /dev/null +++ b/Code/VisuRefac/otbPixelDescriptionView.h @@ -0,0 +1,104 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbPixelDescription_h +#define __otbPixelDescription_h + +#include "otbImageWidget.h" +#include "otbImageLayerRenderingModelListener.h" +#include "otbImageWidgetController.h" + +#include <FL/Fl_Multiline_Output.H> + +namespace otb +{ + +/** \class PixelDescriptionView +* \brief +* \Todo: Rename PixelDescriptioner when refactoring will be completed. +*/ + +template <class TModel > +class PixelDescriptionView + : public PixelDescriptionModelListener, public itk::Object +{ +public: + /** Standard class typedefs */ + typedef PixelDescriptionView Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory */ + itkNewMacro(Self); + + /** Runtime information */ + itkTypeMacro(PixelDescriptionView,itk::Object); + + /** Model typedef */ + typedef TModel ModelType; + typedef typename ModelType::Pointer ModelPointerType; + + /** Pixel description widget typedef */ + typedef Fl_Multiline_Output PixelDescriptionWidgetType; + + /** + * This method unregister with previous model if any, and + * register with the new one. + */ + void SetModel(ModelType * model); + + /** + * Manually trigger a refresh + */ + void Update(); + + /** Get the pixel description widget */ + PixelDescriptionWidgetType * GetPixelDescriptionWidget() + { + return m_PixelDescriptionWidget; + } + + protected: + /** Constructor */ + PixelDescriptionView(); + /** Destructor */ + ~PixelDescriptionView(); + + /** Handle notification from the viewer */ + virtual void PixelDescriptionModelNotify(); + +private: + PixelDescriptionView(const Self&); // purposely not implemented + void operator=(const Self&); // purposely not implemented + + /** The description widget */ + Fl_Multiline_Output * m_PixelDescriptionWidget; + + /** Model pointer */ + ModelPointerType m_Model; + +}; // end class +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbPixelDescriptionView.txx" +#endif + +#endif + + diff --git a/Code/VisuRefac/otbPixelDescriptionView.txx b/Code/VisuRefac/otbPixelDescriptionView.txx new file mode 100644 index 0000000000000000000000000000000000000000..b7ff95286ec4124c86dda2a4f5fa1cb4adf1cbfd --- /dev/null +++ b/Code/VisuRefac/otbPixelDescriptionView.txx @@ -0,0 +1,78 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbPixelDescriptionView_txx +#define __otbPixelDescriptionView_txx + +#include "otbPixelDescriptionView.h" + +namespace otb +{ +template < class TInputPixelDescription > +PixelDescriptionView<TInputPixelDescription> +::PixelDescriptionView() : m_PixelDescriptionWidget(NULL), m_Model() +{ + // build a widget with a default size + m_PixelDescriptionWidget = new Fl_Multiline_Output(0,0,200,40); +} + +template < class TInputPixelDescription > +PixelDescriptionView<TInputPixelDescription> +::~PixelDescriptionView() +{ + if(m_PixelDescriptionWidget != NULL) + { + delete m_PixelDescriptionWidget; + } +} + +template < class TInputPixelDescription > +void +PixelDescriptionView<TInputPixelDescription> +::SetModel(ModelType * model) +{ + // Unregister from previous model if nay + if(m_Model.IsNotNull()) + { + m_Model->UnRegisterListener(this); + } + + // Set and register with new model + m_Model = model; + m_Model->RegisterListener(this); +} + + + +template < class TInputPixelDescription > +void +PixelDescriptionView<TInputPixelDescription> +::PixelDescriptionModelNotify() +{ + this->Update(); +} + +template < class TInputPixelDescription > +void +PixelDescriptionView<TInputPixelDescription> +::Update() +{ + m_PixelDescriptionWidget->value(m_Model->GetPixelDescription()); + m_PixelDescriptionWidget->redraw(); +} +} +#endif diff --git a/Code/VisuRefac/otbRenderingFunction.h b/Code/VisuRefac/otbRenderingFunction.h index dc34d91279f2231c66e498b0fa843e1847ede2d2..18fc5ad8ba68f6ef8c4df295ca8d19aa485fa19e 100644 --- a/Code/VisuRefac/otbRenderingFunction.h +++ b/Code/VisuRefac/otbRenderingFunction.h @@ -57,7 +57,13 @@ public: /** Evaluate method (vector version) */ virtual const OutputPixelType Evaluate(const VectorPixelType & vpixel) const = 0; - + + /** Get a string description of a pixel (scalar version) */ + virtual const std::string Describe(ScalarPixelType spixel) const = 0; + + /** Get a string description of a pixel (vector version) */ + virtual const std::string Describe(const VectorPixelType& vpixel) const = 0; + /** This method is available to allow implementation of * preprocessing. */ diff --git a/Code/VisuRefac/otbStandardRenderingFunction.h b/Code/VisuRefac/otbStandardRenderingFunction.h index b2a00c4d803d9a41b356c914bb892adc3f53e889..8ab02b3c6469ac78e8da9970dee672c42a30844f 100644 --- a/Code/VisuRefac/otbStandardRenderingFunction.h +++ b/Code/VisuRefac/otbStandardRenderingFunction.h @@ -19,6 +19,7 @@ #define __otbStandardRenderingFunction_h #include "otbRenderingFunction.h" +#include "otbMacro.h" #include <assert.h> namespace otb @@ -99,6 +100,26 @@ public: return resp; } + + inline const std::string Describe(ScalarPixelType spixel) const + { + itk::OStringStream oss; + OutputPixelType output = this->Evaluate(spixel); + oss<<"Grayscale[value: "<<spixel<<", displayed: "<<output[0]<<"]"; + return oss.str(); + } + + inline const std::string Describe(const VectorPixelType & vpixel) const + { + itk::OStringStream oss; + OutputPixelType output = this->Evaluate(vpixel); + oss<<"R[chan=" <<m_RedChannelIndex <<" val="<< vpixel[m_RedChannelIndex] <<" disp="<<static_cast<unsigned int>(output[0])<<"], "; + oss<<"G[chan="<<m_GreenChannelIndex <<" val="<< vpixel[m_GreenChannelIndex] <<" disp="<<static_cast<unsigned int>(output[1])<<"], "; + oss<<"B[chan=" <<m_BlueChannelIndex <<" val="<< vpixel[m_BlueChannelIndex] <<" disp="<<static_cast<unsigned int>(output[2])<<"]"; + return oss.str(); + + } + /** Get the transfer function for tuning */ TransferFunctionType & GetTransferFunction() { diff --git a/Testing/Code/VisuRefac/CMakeLists.txt b/Testing/Code/VisuRefac/CMakeLists.txt index c61746a1aad425a17aae0329c5a4fce5df90541e..ef15e18ec38524676e1a0d5c5755a20efb33a4da 100644 --- a/Testing/Code/VisuRefac/CMakeLists.txt +++ b/Testing/Code/VisuRefac/CMakeLists.txt @@ -156,25 +156,31 @@ ${EXAMPLESDATA}/SpotAfter.png ${TEMP}/vrTvBlendingImageFilterOutput.png ) -#------------ otb::ImageViewerModel ------------ +#------------ otb::LayerBasedModel ------------ -ADD_TEST(vrTuImageViewerModelNew ${VISUREFAC_TESTS1} -otbImageViewerModelNew +ADD_TEST(vrTuLayerBasedModelNew ${VISUREFAC_TESTS1} +otbLayerBasedModelNew ) -ADD_TEST(vrTvImageViewerModelSingleLayer ${VISUREFAC_TESTS1} +#------------ otb::ImageLayerRenderingModel ------------ + +ADD_TEST(vrTuImageLayerRenderingModelNew ${VISUREFAC_TESTS1} +otbImageLayerRenderingModelNew +) + +ADD_TEST(vrTvImageLayerRenderingModelSingleLayer ${VISUREFAC_TESTS1} --compare-n-images ${TOL} 3 -${BASELINE}/vrTvImageViewerModelSingleLayerQuicklookOutput.png -${TEMP}/vrTvImageViewerModelSingleLayerQuicklookOutput.png -${BASELINE}/vrTvImageViewerModelSingleLayerExtractOutput.png -${TEMP}/vrTvImageViewerModelSingleLayerExtractOutput.png -${BASELINE}/vrTvImageViewerModelSingleLayerScaledExtractOutput.png -${TEMP}/vrTvImageViewerModelSingleLayerScaledExtractOutput.png -otbImageViewerModelSingleLayer +${BASELINE}/vrTvImageLayerRenderingModelSingleLayerQuicklookOutput.png +${TEMP}/vrTvImageLayerRenderingModelSingleLayerQuicklookOutput.png +${BASELINE}/vrTvImageLayerRenderingModelSingleLayerExtractOutput.png +${TEMP}/vrTvImageLayerRenderingModelSingleLayerExtractOutput.png +${BASELINE}/vrTvImageLayerRenderingModelSingleLayerScaledExtractOutput.png +${TEMP}/vrTvImageLayerRenderingModelSingleLayerScaledExtractOutput.png +otbImageLayerRenderingModelSingleLayer ${INPUTDATA}/couleurs.tif -${TEMP}/vrTvImageViewerModelSingleLayerQuicklookOutput.png -${TEMP}/vrTvImageViewerModelSingleLayerExtractOutput.png -${TEMP}/vrTvImageViewerModelSingleLayerScaledExtractOutput.png +${TEMP}/vrTvImageLayerRenderingModelSingleLayerQuicklookOutput.png +${TEMP}/vrTvImageLayerRenderingModelSingleLayerExtractOutput.png +${TEMP}/vrTvImageLayerRenderingModelSingleLayerScaledExtractOutput.png ) #------------ otb::ImageLayerGenerator ------------ @@ -211,6 +217,18 @@ ${INPUTDATA}/couleurs.tif 200 500 200 0 ) +#------------ otb::PixelDescriptionModel ------------ + +ADD_TEST(vrTuPixelDescriptionModelNew ${VISUREFAC_TESTS1} +otbPixelDescriptionModelNew +) + +ADD_TEST(vrTvPixelDescriptionModelSingleLayer ${VISUREFAC_TESTS1} +otbPixelDescriptionModelSingleLayer +${INPUTDATA}/couleurs.tif +) + + # Testing srcs SET(VisuRefac_SRCS1 otbImageWidgetNew.cxx @@ -228,8 +246,9 @@ otbImageLayerVector.cxx otbUniformAlphaBlendingFunctionNew.cxx otbBlendingImageFilterNew.cxx otbBlendingImageFilter.cxx -otbImageViewerModelNew.cxx -otbImageViewerModelSingleLayer.cxx +otbLayerBasedModelNew.cxx +otbImageLayerRenderingModelNew.cxx +otbImageLayerRenderingModelSingleLayer.cxx otbImageLayerGeneratorNew.cxx otbImageLayerGeneratorScalar.cxx otbImageLayerGeneratorVector.cxx @@ -238,6 +257,8 @@ otbRenderingImageFilterVectorWithExpNegativeTransfer.cxx otbImageViewNew.cxx otbImageViewerEndToEndSingleLayer.cxx otbImageViewerEndToEndTwoLayers.cxx +otbPixelDescriptionModelNew.cxx +otbPixelDescriptionModelSingleLayer.cxx ) # Building testing executables diff --git a/Testing/Code/VisuRefac/otbImageViewerModelNew.cxx b/Testing/Code/VisuRefac/otbImageLayerRenderingModelNew.cxx similarity index 82% rename from Testing/Code/VisuRefac/otbImageViewerModelNew.cxx rename to Testing/Code/VisuRefac/otbImageLayerRenderingModelNew.cxx index 7caba88b6e147850f120972f37ff97269d6fd6aa..8cb359f4185c5bb0b420064a11302e98e3dab338 100644 --- a/Testing/Code/VisuRefac/otbImageViewerModelNew.cxx +++ b/Testing/Code/VisuRefac/otbImageLayerRenderingModelNew.cxx @@ -15,15 +15,15 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbImageViewerModel.h" +#include "otbImageLayerRenderingModel.h" #include "otbImage.h" #include "itkRGBPixel.h" -int otbImageViewerModelNew( int argc, char * argv[] ) +int otbImageLayerRenderingModelNew( int argc, char * argv[] ) { typedef itk::RGBPixel<unsigned char> RGBPixelType; typedef otb::Image<RGBPixelType,2> ImageType; - typedef otb::ImageViewerModel<ImageType> ModelType; + typedef otb::ImageLayerRenderingModel<ImageType> ModelType; // Instantiation ModelType::Pointer model = ModelType::New(); diff --git a/Testing/Code/VisuRefac/otbImageViewerModelSingleLayer.cxx b/Testing/Code/VisuRefac/otbImageLayerRenderingModelSingleLayer.cxx similarity index 94% rename from Testing/Code/VisuRefac/otbImageViewerModelSingleLayer.cxx rename to Testing/Code/VisuRefac/otbImageLayerRenderingModelSingleLayer.cxx index b2c53620b4bd822c4aacc040799c92ea57cd2c8b..293bf834da82fe17cc017b96aa9ec2772969e86a 100644 --- a/Testing/Code/VisuRefac/otbImageViewerModelSingleLayer.cxx +++ b/Testing/Code/VisuRefac/otbImageLayerRenderingModelSingleLayer.cxx @@ -15,7 +15,7 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbImageViewerModel.h" +#include "otbImageLayerRenderingModel.h" #include "otbVectorImage.h" #include "itkRGBPixel.h" #include "otbImageFileReader.h" @@ -24,7 +24,7 @@ PURPOSE. See the above copyright notices for more information. #include "otbImageFileWriter.h" #include "otbImageLayer.h" -int otbImageViewerModelSingleLayer( int argc, char * argv[] ) +int otbImageLayerRenderingModelSingleLayer( int argc, char * argv[] ) { // params const char * infname = argv[1]; @@ -39,7 +39,7 @@ int otbImageViewerModelSingleLayer( int argc, char * argv[] ) typedef otb::ImageLayer<ImageType> LayerType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageLayerGenerator<LayerType> LayerGeneratorType; - typedef otb::ImageViewerModel<OutputImageType> ModelType; + typedef otb::ImageLayerRenderingModel<OutputImageType> ModelType; typedef otb::ImageFileWriter<OutputImageType> WriterType; // Instantiation diff --git a/Testing/Code/VisuRefac/otbImageLayerScalar.cxx b/Testing/Code/VisuRefac/otbImageLayerScalar.cxx index 65fbf567a669018ac41154e3ed825b4dac5ef084..0b40a833bc23b8c974563d5b4478ee62a440abe4 100644 --- a/Testing/Code/VisuRefac/otbImageLayerScalar.cxx +++ b/Testing/Code/VisuRefac/otbImageLayerScalar.cxx @@ -103,6 +103,9 @@ int otbImageLayerScalar( int argc, char * argv[] ) // Render the layer layer->Render(); + // Report a pixel + std::cout<<"Reporting index: "<<index<<" -> "<<layer->GetPixelDescription(index)<<std::endl; + // Write the image views WriterType::Pointer writer = WriterType::New(); writer->SetInput(layer->GetRenderedQuicklook()); diff --git a/Testing/Code/VisuRefac/otbImageLayerVector.cxx b/Testing/Code/VisuRefac/otbImageLayerVector.cxx index 20b8ae1424a2a5fc4d1c3d8ac377bc450a257a77..dd906904b73458dc2ba43d2439dc8299f3c25a93 100644 --- a/Testing/Code/VisuRefac/otbImageLayerVector.cxx +++ b/Testing/Code/VisuRefac/otbImageLayerVector.cxx @@ -115,6 +115,9 @@ int otbImageLayerVector( int argc, char * argv[] ) // Render the layer layer->Render(); + // Report a pixel + std::cout<<"Reporting index: "<<index<<" -> "<<layer->GetPixelDescription(index)<<std::endl; + // Write the image views WriterType::Pointer writer = WriterType::New(); writer->SetInput(layer->GetRenderedQuicklook()); diff --git a/Testing/Code/VisuRefac/otbImageViewNew.cxx b/Testing/Code/VisuRefac/otbImageViewNew.cxx index f3a0374f4eeefb9b3b3e263360f9794ad00e5971..9f5b41e254b0074a37d77cc2c775dc972fedeaee 100644 --- a/Testing/Code/VisuRefac/otbImageViewNew.cxx +++ b/Testing/Code/VisuRefac/otbImageViewNew.cxx @@ -15,7 +15,7 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbImageViewerModel.h" +#include "otbImageLayerRenderingModel.h" #include "otbImage.h" #include "itkRGBPixel.h" #include "otbImageView.h" @@ -24,7 +24,7 @@ int otbImageViewNew( int argc, char * argv[] ) { typedef itk::RGBPixel<unsigned char> RGBPixelType; typedef otb::Image<RGBPixelType,2> ImageType; - typedef otb::ImageViewerModel<ImageType> ModelType; + typedef otb::ImageLayerRenderingModel<ImageType> ModelType; typedef otb::ImageView<ModelType> ViewType; // Instantiation diff --git a/Testing/Code/VisuRefac/otbImageViewerEndToEndSingleLayer.cxx b/Testing/Code/VisuRefac/otbImageViewerEndToEndSingleLayer.cxx index c2b49928660e78feb1fb3ce5ebadd9c6cf0cf362..c2c7a18b6d3bf3fe846ad6ae35100552def444c9 100644 --- a/Testing/Code/VisuRefac/otbImageViewerEndToEndSingleLayer.cxx +++ b/Testing/Code/VisuRefac/otbImageViewerEndToEndSingleLayer.cxx @@ -15,7 +15,7 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbImageViewerModel.h" +#include "otbImageLayerRenderingModel.h" #include "otbVectorImage.h" #include "itkRGBPixel.h" #include "otbImageFileReader.h" @@ -29,7 +29,9 @@ PURPOSE. See the above copyright notices for more information. #include "otbChangeScaledExtractRegionActionHandler.h" #include "otbChangeExtractRegionActionHandler.h" #include "otbChangeScaleActionHandler.h" - +#include "otbPixelDescriptionModel.h" +#include "otbPixelDescriptionActionHandler.h" +#include "otbPixelDescriptionView.h" int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) { @@ -49,7 +51,7 @@ int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) typedef otb::ImageLayer<ImageType> LayerType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageLayerGenerator<LayerType> LayerGeneratorType; - typedef otb::ImageViewerModel<OutputImageType> ModelType; + typedef otb::ImageLayerRenderingModel<OutputImageType> ModelType; typedef otb::ImageView<ModelType> ViewType; typedef otb::ImageWidgetController ControllerType; typedef otb::WidgetResizingActionHandler @@ -60,9 +62,17 @@ int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) <ModelType,ViewType> ChangeRegionHandlerType; typedef otb::ChangeScaleActionHandler <ModelType,ViewType> ChangeScaleHandlerType; + typedef otb::PixelDescriptionModel<OutputImageType> PixelDescriptionModelType; + typedef otb::PixelDescriptionActionHandler + < PixelDescriptionModelType, ViewType> PixelDescriptionActionHandlerType; + typedef otb::PixelDescriptionView + < PixelDescriptionModelType > PixelDescriptionViewType; + // Instantiation ModelType::Pointer model = ModelType::New(); + PixelDescriptionModelType::Pointer pixelModel = PixelDescriptionModelType::New(); + pixelModel->SetLayers(model->GetLayers()); // Reading input image ReaderType::Pointer reader = ReaderType::New(); @@ -76,6 +86,7 @@ int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) // Add the layer to the model model->AddLayer(generator->GetLayer()); + // Build a view ViewType::Pointer view = ViewType::New(); view->SetModel(model); @@ -90,7 +101,7 @@ int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) resizingHandler->SetView(view); controller->AddActionHandler(resizingHandler); -// Add the change scaled region handler + // Add the change scaled region handler ChangeScaledRegionHandlerType::Pointer changeScaledHandler =ChangeScaledRegionHandlerType::New(); changeScaledHandler->SetModel(model); changeScaledHandler->SetView(view); @@ -102,12 +113,32 @@ int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) changeHandler->SetView(view); controller->AddActionHandler(changeHandler); -// Add the change scaled handler + // Add the change scaled handler ChangeScaleHandlerType::Pointer changeScaleHandler =ChangeScaleHandlerType::New(); changeScaleHandler->SetModel(model); changeScaleHandler->SetView(view); controller->AddActionHandler(changeScaleHandler); + // Add the pixel description action handler + PixelDescriptionActionHandlerType::Pointer pixelActionHandler = PixelDescriptionActionHandlerType::New(); + pixelActionHandler->SetView(view); + pixelActionHandler->SetModel(pixelModel); + controller->AddActionHandler(pixelActionHandler); + + // Build a pixel description view + PixelDescriptionViewType::Pointer pixelView = PixelDescriptionViewType::New(); + pixelView->SetModel(pixelModel); + + Fl_Window pixelWindow(fullSize,50); + if(fullSize > 0) + { + pixelWindow.add(pixelView->GetPixelDescriptionWidget()); + pixelWindow.resizable(pixelView->GetPixelDescriptionWidget()); + pixelWindow.show(); + pixelView->GetPixelDescriptionWidget()->show(); + pixelView->GetPixelDescriptionWidget()->resize(0,0,fullSize,50); + } + Fl_Window scrollWindow(scrollSize,scrollSize); if(scrollSize > 0) { @@ -150,6 +181,7 @@ int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) zoomWindow.remove(view->GetZoomWidget()); scrollWindow.remove(view->GetScrollWidget()); fullWindow.remove(view->GetFullWidget()); + pixelWindow.remove(pixelView->GetPixelDescriptionWidget()); return EXIT_SUCCESS; } diff --git a/Testing/Code/VisuRefac/otbImageViewerEndToEndTwoLayers.cxx b/Testing/Code/VisuRefac/otbImageViewerEndToEndTwoLayers.cxx index bec2115d9d1c90c23dbf8197a02d86100b1598d0..6f70b725f7194707ccf073ae13e1a47d7abe48f2 100644 --- a/Testing/Code/VisuRefac/otbImageViewerEndToEndTwoLayers.cxx +++ b/Testing/Code/VisuRefac/otbImageViewerEndToEndTwoLayers.cxx @@ -15,7 +15,7 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbImageViewerModel.h" +#include "otbImageLayerRenderingModel.h" #include "otbVectorImage.h" #include "itkRGBPixel.h" #include "otbImageFileReader.h" @@ -31,6 +31,9 @@ PURPOSE. See the above copyright notices for more information. #include "otbChangeScaleActionHandler.h" #include "itkSobelEdgeDetectionImageFilter.h" #include "otbPerBandVectorImageFilter.h" +#include "otbPixelDescriptionModel.h" +#include "otbPixelDescriptionActionHandler.h" +#include "otbPixelDescriptionView.h" int otbImageViewerEndToEndTwoLayers( int argc, char * argv[] ) { @@ -51,7 +54,7 @@ int otbImageViewerEndToEndTwoLayers( int argc, char * argv[] ) typedef otb::ImageLayer<ImageType> LayerType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageLayerGenerator<LayerType> LayerGeneratorType; - typedef otb::ImageViewerModel<OutputImageType> ModelType; + typedef otb::ImageLayerRenderingModel<OutputImageType> ModelType; typedef otb::ImageView<ModelType> ViewType; typedef otb::ImageWidgetController ControllerType; typedef otb::WidgetResizingActionHandler @@ -62,15 +65,21 @@ int otbImageViewerEndToEndTwoLayers( int argc, char * argv[] ) <ModelType,ViewType> ChangeRegionHandlerType; typedef otb::ChangeScaleActionHandler <ModelType,ViewType> ChangeScaleHandlerType; + typedef otb::PixelDescriptionModel<OutputImageType> PixelDescriptionModelType; + typedef otb::PixelDescriptionActionHandler + < PixelDescriptionModelType, ViewType> PixelDescriptionActionHandlerType; + typedef otb::PixelDescriptionView + < PixelDescriptionModelType > PixelDescriptionViewType; // Filters for the second layer typedef itk::SobelEdgeDetectionImageFilter<ScalarImageType,ScalarImageType> FilterType; typedef otb::PerBandVectorImageFilter<ImageType,ImageType,FilterType> PerBandFilterType; - // Instantiation ModelType::Pointer model = ModelType::New(); + PixelDescriptionModelType::Pointer pixelModel = PixelDescriptionModelType::New(); + pixelModel->SetLayers(model->GetLayers()); // Reading input image ReaderType::Pointer reader = ReaderType::New(); @@ -109,7 +118,7 @@ int otbImageViewerEndToEndTwoLayers( int argc, char * argv[] ) resizingHandler->SetView(view); controller->AddActionHandler(resizingHandler); -// Add the change scaled region handler + // Add the change scaled region handler ChangeScaledRegionHandlerType::Pointer changeScaledHandler =ChangeScaledRegionHandlerType::New(); changeScaledHandler->SetModel(model); changeScaledHandler->SetView(view); @@ -121,13 +130,33 @@ int otbImageViewerEndToEndTwoLayers( int argc, char * argv[] ) changeHandler->SetView(view); controller->AddActionHandler(changeHandler); -// Add the change scaled handler + // Add the change scaled handler ChangeScaleHandlerType::Pointer changeScaleHandler =ChangeScaleHandlerType::New(); changeScaleHandler->SetModel(model); changeScaleHandler->SetView(view); controller->AddActionHandler(changeScaleHandler); - Fl_Window scrollWindow(scrollSize,scrollSize); + // Add the pixel description action handler + PixelDescriptionActionHandlerType::Pointer pixelActionHandler = PixelDescriptionActionHandlerType::New(); + pixelActionHandler->SetView(view); + pixelActionHandler->SetModel(pixelModel); + controller->AddActionHandler(pixelActionHandler); + + // Build a pixel description view + PixelDescriptionViewType::Pointer pixelView = PixelDescriptionViewType::New(); + pixelView->SetModel(pixelModel); + + Fl_Window pixelWindow(fullSize,50); + if(fullSize > 0) + { + pixelWindow.add(pixelView->GetPixelDescriptionWidget()); + pixelWindow.resizable(pixelView->GetPixelDescriptionWidget()); + pixelWindow.show(); + pixelView->GetPixelDescriptionWidget()->show(); + pixelView->GetPixelDescriptionWidget()->resize(0,0,fullSize,50); + } + + Fl_Window scrollWindow(scrollSize,scrollSize); if(scrollSize > 0) { scrollWindow.add(view->GetScrollWidget()); @@ -169,6 +198,7 @@ int otbImageViewerEndToEndTwoLayers( int argc, char * argv[] ) zoomWindow.remove(view->GetZoomWidget()); scrollWindow.remove(view->GetScrollWidget()); fullWindow.remove(view->GetFullWidget()); - + pixelWindow.remove(pixelView->GetPixelDescriptionWidget()); + return EXIT_SUCCESS; } diff --git a/Testing/Code/VisuRefac/otbLayerBasedModelNew.cxx b/Testing/Code/VisuRefac/otbLayerBasedModelNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e642eb48e8226f464e00f1610f9144c63b82730e --- /dev/null +++ b/Testing/Code/VisuRefac/otbLayerBasedModelNew.cxx @@ -0,0 +1,34 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbImageLayerBase.h" +#include "otbLayerBasedModel.h" +#include "otbImage.h" +#include "itkRGBPixel.h" + +int otbLayerBasedModelNew( int argc, char * argv[] ) +{ + typedef itk::RGBPixel<unsigned char> RGBPixelType; + typedef otb::Image<RGBPixelType,2> ImageType; + typedef otb::ImageLayerBase<ImageType> LayerType; + typedef otb::LayerBasedModel<LayerType> ModelType; + + // Instantiation + ModelType::Pointer model = ModelType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/VisuRefac/otbPixelDescriptionModelNew.cxx b/Testing/Code/VisuRefac/otbPixelDescriptionModelNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..bda26f04f8b4b94c87ec27f45be301182833a0b0 --- /dev/null +++ b/Testing/Code/VisuRefac/otbPixelDescriptionModelNew.cxx @@ -0,0 +1,31 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbPixelDescriptionModel.h" +#include "otbImage.h" +#include "otbImageLayer.h" + +int otbPixelDescriptionModelNew( int argc, char * argv[] ) +{ + typedef otb::Image<double,2> ImageType; + typedef otb::PixelDescriptionModel<ImageType> ModelType; + + // Instantiation + ModelType::Pointer model = ModelType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/VisuRefac/otbPixelDescriptionModelSingleLayer.cxx b/Testing/Code/VisuRefac/otbPixelDescriptionModelSingleLayer.cxx new file mode 100644 index 0000000000000000000000000000000000000000..75b91fd87ea5d992a15be56c24ae0054d52bbe4f --- /dev/null +++ b/Testing/Code/VisuRefac/otbPixelDescriptionModelSingleLayer.cxx @@ -0,0 +1,63 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbPixelDescriptionModel.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageLayerGenerator.h" +#include "otbImageLayer.h" + +int otbPixelDescriptionModelSingleLayer( int argc, char * argv[] ) +{ + // params + const char * infname = argv[1]; + + typedef otb::VectorImage<double,2> ImageType; + typedef otb::ImageLayer<ImageType> LayerType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageLayerGenerator<LayerType> LayerGeneratorType; + typedef otb::PixelDescriptionModel<LayerType::OutputImageType> ModelType; + + // Instantiation + ModelType::Pointer model = ModelType::New(); + + // Reading input image + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(infname); + + // Generate the layer + LayerGeneratorType::Pointer generator = LayerGeneratorType::New(); + generator->SetImage(reader->GetOutput()); + generator->GenerateLayer(); + + // Add the layer to the model + model->AddLayer(generator->GetLayer()); + + // Compute extract and scaled extract region + ImageType::RegionType lregion = reader->GetOutput()->GetLargestPossibleRegion(); + ImageType::RegionType::IndexType index; + + index[0] = lregion.GetSize()[0]/4; + index[1] = lregion.GetSize()[1]/4; + + model->UpdatePixelDescription(index); + + std::cout<<"Pixel description: "<<std::endl; + std::cout<<model->GetPixelDescription()<<std::endl; + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx b/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx index 59f08b750008a2221341ef2d7fdb43101c48764b..60062db6f5fb90f5fdc2a6849ec3bf1a7fe99147 100644 --- a/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx +++ b/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx @@ -42,8 +42,9 @@ void RegisterTests() REGISTER_TEST(otbUniformAlphaBlendingFunctionNew); REGISTER_TEST(otbBlendingImageFilterNew); REGISTER_TEST(otbBlendingImageFilter); - REGISTER_TEST(otbImageViewerModelNew); - REGISTER_TEST(otbImageViewerModelSingleLayer); + REGISTER_TEST(otbLayerBasedModelNew); + REGISTER_TEST(otbImageLayerRenderingModelNew); + REGISTER_TEST(otbImageLayerRenderingModelSingleLayer); REGISTER_TEST(otbImageLayerGeneratorNew); REGISTER_TEST(otbImageLayerGeneratorScalar); REGISTER_TEST(otbImageLayerGeneratorVector); @@ -51,4 +52,6 @@ void RegisterTests() REGISTER_TEST(otbImageViewNew); REGISTER_TEST(otbImageViewerEndToEndSingleLayer); REGISTER_TEST(otbImageViewerEndToEndTwoLayers); + REGISTER_TEST(otbPixelDescriptionModelNew); + REGISTER_TEST(otbPixelDescriptionModelSingleLayer); }