diff --git a/Code/Common/otbDrawLineSpatialObjectListFilter.txx b/Code/Common/otbDrawLineSpatialObjectListFilter.txx index c94b211cfeaf05d77911f08d3879424298e97aa9..f171477f71f7b932a360a5c3c474df1465694b36 100644 --- a/Code/Common/otbDrawLineSpatialObjectListFilter.txx +++ b/Code/Common/otbDrawLineSpatialObjectListFilter.txx @@ -168,7 +168,6 @@ DrawLineSpatialObjectListFilter<TInputImage, TOutput> ::CropRightSegment(OutputIndexType *indexToCrop,OutputIndexType *otherIndex, const OutputImageRegionType *outputRegionForThread ) const { - OutputIndexType tempIndex; /** Dimensions of the buffered region*/ typename OutputImageRegionType::SizeType size = outputRegionForThread->GetSize(); @@ -271,7 +270,8 @@ DrawLineSpatialObjectListFilter<TInputImage, TOutput> { OutputIndexType tempIndex; - + tempIndex = *indexToCrop; + /** Dimensions of the buffered region*/ typename OutputImageRegionType::SizeType size = outputRegionForThread->GetSize(); typename OutputImageRegionType::IndexType start = outputRegionForThread->GetIndex(); diff --git a/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx b/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx index 263567b5978fd0c8b228095821ffeb1115f23ea2..ac9a423ed5dfae397aef09156bb5aaa6daf055b1 100644 --- a/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx +++ b/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx @@ -159,7 +159,7 @@ UnaryFunctorNeighborhoodWithOffsetImageFilter<TInputImage, TOutputImage, TFuncti while ( ! outputIt.IsAtEnd() ) { - outputIt.Set( m_FunctorList[threadId]( neighInputOffIt ) ); + outputIt.Set( m_FunctorList[threadId]( neighInputOffIt.GetNeighborhood() ) ); ++neighInputOffIt; ++outputIt; diff --git a/Code/Common/otbVectorDataExtractROI.h b/Code/Common/otbVectorDataExtractROI.h index 4e544f5892cab5070157ea267b3f50f28ad4c976..bbeeef948bdacf87997e460132c4ce0b65376500 100644 --- a/Code/Common/otbVectorDataExtractROI.h +++ b/Code/Common/otbVectorDataExtractROI.h @@ -49,6 +49,7 @@ public: /** Image type information. */ typedef TVectorData VectorDataType; + typedef typename VectorDataType::DataTreeType DataTreeType; /** Get/Set Macro for ROI Column size */ itkGetMacro(SizeX, unsigned int); diff --git a/Code/Common/otbVectorDataExtractROI.txx b/Code/Common/otbVectorDataExtractROI.txx index 66457b8254a31a65cb80ecf33c57cc7f2faa34ed..f545a6c08dc41dbaae1cbbf2a95b11cb0f047b1a 100644 --- a/Code/Common/otbVectorDataExtractROI.txx +++ b/Code/Common/otbVectorDataExtractROI.txx @@ -20,6 +20,7 @@ #include "otbVectorDataExtractROI.h" #include "itkImageRegion.h" +#include "itkPreOrderTreeIterator.h" #include "itkIndex.h" #include "itkSize.h" @@ -77,18 +78,20 @@ VectorDataExtractROI<TVectorData> ::GenerateData(void) { /** Get The input and the outptut*/ - - + typename VectorDataType::ConstPointer input = this->GetInput(); + if(!input) + std::cout << " Probleme avec la recuperation du input"<<std::endl; /** Create a region with the right size*/ - const unsigned int Dimension = 2; + const unsigned int Dimension = 2; typedef itk::ImageRegion<Dimension> ImageRegionType; typedef itk::Index<Dimension> IndexType; typedef itk::Size<Dimension> SizeType; - - ImageRegionType roi; - IndexType index; - SizeType size; + + /** */ + ImageRegionType roi; + IndexType index; + SizeType size; /** Update the region information*/ index[0] = m_StartX; @@ -99,13 +102,31 @@ VectorDataExtractROI<TVectorData> /** Create the region*/ roi.SetSize(size); roi.SetIndex(index); - - std::cout << "ROI " << roi<<std::endl; - - /***/ - - + /** Loop in the vectorData file*/ + typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType; + TreeIteratorType it(input->GetDataTree()); + + it.GoToBegin(); + while (!it.IsAtEnd()) + { + + itk::PreOrderTreeIterator<DataTreeType> itParent = it; + bool goesOn = true; + + if (it.Get()->IsPolygonFeature()) + std::cout << " C'est un polygone et les coordonnees " << it.Get()->GetPolygonExteriorRing()->GetVertexList()->GetElement(0) << std::endl; + + if (it.Get()->IsLineFeature()) + std::cout << "Vertex List Size " << it.Get()->GetLine()->GetVertexList()->Size() <<std::endl; + + if (it.Get()->IsPointFeature()) + std::cout << " C'est un point" << std::endl; + + + ++it; + } + } diff --git a/Code/FeatureExtraction/otbAngularSecondMomentumTextureFunctor.h b/Code/FeatureExtraction/otbAngularSecondMomentumTextureFunctor.h index c59fdaff8bbe16c54c10cfb8a5dccd51eace2ad0..0abf087341b3581d3edcd46cad278922380dbfd3 100755 --- a/Code/FeatureExtraction/otbAngularSecondMomentumTextureFunctor.h +++ b/Code/FeatureExtraction/otbAngularSecondMomentumTextureFunctor.h @@ -36,19 +36,16 @@ namespace Functor * \ingroup Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT AngularSecondMomentumTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: AngularSecondMomentumTextureFunctor(){}; virtual ~AngularSecondMomentumTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) diff --git a/Code/FeatureExtraction/otbClusterProminenceTextureFunctor.h b/Code/FeatureExtraction/otbClusterProminenceTextureFunctor.h index 8266779c0ea745f4bd1e76c94597364d713f4c83..7ab3e3ae04fc43739dd33a056f792ee9f71ebadf 100755 --- a/Code/FeatureExtraction/otbClusterProminenceTextureFunctor.h +++ b/Code/FeatureExtraction/otbClusterProminenceTextureFunctor.h @@ -39,21 +39,16 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT ClusterProminenceTextureFunctor : -public MeanTextureFunctor<TIterInput, TOutput> +public MeanTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> { public: ClusterProminenceTextureFunctor(){}; virtual ~ClusterProminenceTextureFunctor(){}; - - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - typedef MeanTextureFunctor<TIterInput, TOutput> Superclass; - + + typedef MeanTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbClusterShadeTextureFunctor.h b/Code/FeatureExtraction/otbClusterShadeTextureFunctor.h index 85057f3242594d9c0b36bb89077466b0f746be16..a7150427f51bcf56541badca5c704259ccd6e922 100755 --- a/Code/FeatureExtraction/otbClusterShadeTextureFunctor.h +++ b/Code/FeatureExtraction/otbClusterShadeTextureFunctor.h @@ -39,20 +39,16 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT ClusterShadeTextureFunctor : -public MeanTextureFunctor<TIterInput, TOutput> +public MeanTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> { public: ClusterShadeTextureFunctor(){}; virtual ~ClusterShadeTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - typedef MeanTextureFunctor<TIterInput, TOutput> Superclass; + typedef MeanTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbContrastTextureFunctor.h b/Code/FeatureExtraction/otbContrastTextureFunctor.h index 379d340055b74d9bddd7b2722366fcd96da4fb95..95e191636065607137edace79732b0785273e237 100755 --- a/Code/FeatureExtraction/otbContrastTextureFunctor.h +++ b/Code/FeatureExtraction/otbContrastTextureFunctor.h @@ -37,20 +37,16 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT ContrastTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: ContrastTextureFunctor(){}; virtual ~ContrastTextureFunctor(){}; - - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbCorrelationTextureFunctor.h b/Code/FeatureExtraction/otbCorrelationTextureFunctor.h index 314949868f6ec6c93ff7dfaf7f1870f0ecdf0e78..9e7c7e469fc2476886b2235d48f058104d555a4b 100755 --- a/Code/FeatureExtraction/otbCorrelationTextureFunctor.h +++ b/Code/FeatureExtraction/otbCorrelationTextureFunctor.h @@ -41,20 +41,16 @@ namespace Functor */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT CorrelationTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: CorrelationTextureFunctor(){}; virtual ~CorrelationTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbDifferenceEntropyTextureFunctor.h b/Code/FeatureExtraction/otbDifferenceEntropyTextureFunctor.h index 0e2d29ff84910d5a11e724b989a13bd92a5359dc..712f9c80114f7fedefed4a6aafa81028d3d8aadc 100755 --- a/Code/FeatureExtraction/otbDifferenceEntropyTextureFunctor.h +++ b/Code/FeatureExtraction/otbDifferenceEntropyTextureFunctor.h @@ -38,20 +38,16 @@ namespace Functor */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT DifferenceEntropyTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: DifferenceEntropyTextureFunctor(){}; virtual ~DifferenceEntropyTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbDifferenceVarianceTextureFunctor.h b/Code/FeatureExtraction/otbDifferenceVarianceTextureFunctor.h index 8cf916a29b80de646c51d431bad9b9e99039359f..e8aa1ae3485b364ec7c31e8b82cbc4bb27368a7e 100755 --- a/Code/FeatureExtraction/otbDifferenceVarianceTextureFunctor.h +++ b/Code/FeatureExtraction/otbDifferenceVarianceTextureFunctor.h @@ -37,20 +37,16 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT DifferenceVarianceTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: DifferenceVarianceTextureFunctor(){}; virtual ~DifferenceVarianceTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbEnergyTextureFunctor.h b/Code/FeatureExtraction/otbEnergyTextureFunctor.h index 6086c9c5ab874e4f72ddc092097842e817a9f0bb..31467044b469953152e018e16220865c3934cfd6 100755 --- a/Code/FeatureExtraction/otbEnergyTextureFunctor.h +++ b/Code/FeatureExtraction/otbEnergyTextureFunctor.h @@ -37,21 +37,21 @@ namespace Functor * \ingroup Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT EnergyTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: EnergyTextureFunctor(){}; virtual ~EnergyTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::OffsetType OffsetType; - typedef typename IterType::RadiusType RadiusType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; + typedef TScalarInputPixelType InputScalarType; + typedef TScalarOutputPixelType OutputScalarType; + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::OffsetType OffsetType; + typedef typename Superclass::RadiusType RadiusType; + typedef typename Superclass::NeighborhoodType NeighborhoodType; + double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbEntropyTextureFunctor.h b/Code/FeatureExtraction/otbEntropyTextureFunctor.h index 1f8175abd654c2ab6eaae15ba7bf5d6cedf69bff..b4163202025f2737194b29b7fc153e7badb910ba 100755 --- a/Code/FeatureExtraction/otbEntropyTextureFunctor.h +++ b/Code/FeatureExtraction/otbEntropyTextureFunctor.h @@ -37,20 +37,27 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT EntropyTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: EntropyTextureFunctor(){}; virtual ~EntropyTextureFunctor(){}; + typedef TScalarInputPixelType InputScalarType; + typedef TScalarOutputPixelType OutputScalarType; + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::OffsetType OffsetType; + typedef typename Superclass::RadiusType RadiusType; + typedef typename Superclass::NeighborhoodType NeighborhoodType; + /* typedef TIterInput IterType; typedef TOutput OutputType; typedef typename IterType::InternalPixelType InternalPixelType; typedef typename IterType::ImageType ImageType; typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + */ virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbInformationMeasureOfCorrelation1TextureFunctor.h b/Code/FeatureExtraction/otbInformationMeasureOfCorrelation1TextureFunctor.h index a0cd7105d499b3626573efd086dd11692fb15359..2c7a350a44db6a63c0259057f386776577d56e42 100755 --- a/Code/FeatureExtraction/otbInformationMeasureOfCorrelation1TextureFunctor.h +++ b/Code/FeatureExtraction/otbInformationMeasureOfCorrelation1TextureFunctor.h @@ -40,20 +40,16 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT InformationMeasureOfCorrelation1TextureFunctor : -public EntropyTextureFunctor<TIterInput, TOutput> +public EntropyTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> { public: InformationMeasureOfCorrelation1TextureFunctor(){}; virtual ~InformationMeasureOfCorrelation1TextureFunctor(){}; - - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - typedef EntropyTextureFunctor<TIterInput, TOutput> Superclass; + + typedef EntropyTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbInformationMeasureOfCorrelation2TextureFunctor.h b/Code/FeatureExtraction/otbInformationMeasureOfCorrelation2TextureFunctor.h index 79cced544052e2086f3d3e8b0981c1ed79ec9bdf..df64f8bedd4fc9ccbea5d5c26a0c47c7c1a59efa 100755 --- a/Code/FeatureExtraction/otbInformationMeasureOfCorrelation2TextureFunctor.h +++ b/Code/FeatureExtraction/otbInformationMeasureOfCorrelation2TextureFunctor.h @@ -40,20 +40,16 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT InformationMeasureOfCorrelation2TextureFunctor : -public EntropyTextureFunctor<TIterInput, TOutput> +public EntropyTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> { public: InformationMeasureOfCorrelation2TextureFunctor(){}; virtual ~InformationMeasureOfCorrelation2TextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - typedef EntropyTextureFunctor<TIterInput, TOutput> Superclass; + typedef EntropyTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbInverseDifferenceMomentTextureFunctor.h b/Code/FeatureExtraction/otbInverseDifferenceMomentTextureFunctor.h index 0c7acd44d90960216f43c4670642cec833403e27..910c52c72d2892d817da4543346fa3fdfdaffd66 100755 --- a/Code/FeatureExtraction/otbInverseDifferenceMomentTextureFunctor.h +++ b/Code/FeatureExtraction/otbInverseDifferenceMomentTextureFunctor.h @@ -37,21 +37,18 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT InverseDifferenceMomentTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: InverseDifferenceMomentTextureFunctor(){}; virtual ~InverseDifferenceMomentTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - - virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; + + virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { this->ComputeJointHistogram(neigh, neighOff); double area = static_cast<double>(neigh.GetSize()[0]*neigh.GetSize()[1]); diff --git a/Code/FeatureExtraction/otbLineDirectionFunctor.h b/Code/FeatureExtraction/otbLineDirectionFunctor.h index 218aba1459a19e4ba847b0c941b94bd30c1c9496..3714ca558825b0d56e24942fe58160d7dcdbcdae 100644 --- a/Code/FeatureExtraction/otbLineDirectionFunctor.h +++ b/Code/FeatureExtraction/otbLineDirectionFunctor.h @@ -26,10 +26,28 @@ namespace otb { /** \class LineDirectionFunctor - * \brief This functor first computes the spectral angle according to a reference pixel. - * \brief Then multiplies the result by a gaussian coefficient - * \brief And reverse the pixel values. + * \brief This functor computes textures based on line direction analysis through the central pixel. + * + * Directions are computed using NumberOfDirection, used to compute a constant step angle. + * A direction is defined as : $\mathit{d_{i} = \sqrt{(m^{e1}-m{e2})^{2}+(n^{e1}-n{e2})^{2}}}$ + * From $\mathit{d_{i}}, histograms are defined : + * $\mathit{H(c) : \{c \in I \mid \lbrack d_{1}(c), \ldots , d_{i}(c), \ldots , d_{D}(c)\rbrack \}}$ + * Thus, 6 textures are defined : + * $\mathit{length = \max_{i \in \lbrack1;D\rbrack}(d_{i}(c)}$ + * $\mathit{width = \min_{i \in \lbrack1;D\rbrack}(d_{i}(c)}$ + * $\mathit{PSI = \frac{1}{D}\sum_{1=1}^{D}d_{i}(c)}$ + * $\mathit{\omega-mean = \frac{1}{D}\sum_{1=1}^{D}\frac{\alpha.(k_{i}-1)}{st_{i}}d_{i}(c)}$ + * $\mathit{ratio = \arctan{\frac{\sum_{j=1}^{n}{sort_{min}^{j}(H(c))}}{\sum_{j=1}^{n}{sort_{max}^{j}(H(c))}}}}$ + * $\mathit{SD = \frac{1}{D-1}\sqrt{\sum_{1=1}^{D}(d_{i}(c)-PSI)^{2}}}$ + * + * For more details, please refer to refer to Xin Huang, Liangpei Zhang and Pingxiang Li publication, + * Classification and Extraction of Spatial Features in Urban Areas + * Using High-Resolution Multispectral Imagery. + * IEEE Geoscience and Remote Sensing Letters, + * vol. 4, n. 2, 2007, pp 260-264 */ + + namespace Functor { template<class TIter,class TOutputValue> @@ -53,7 +71,6 @@ public: typedef typename TIter::OffsetType OffsetType; typedef TOutputValue OutputValueType; typedef std::vector<OutputValueType> OutputType; - //typedef typename TOutputValue::ValueType InternalOutputPixelType; void SetSpatialThreshold( unsigned int thresh ){ m_SpatialThreshold=thresh; }; void SetSpectralThreshold( InternalPixelType thresh ){ m_SpectralThreshold=thresh; }; @@ -98,9 +115,6 @@ public: std::vector<double>::iterator itVector; OutputType out(6, 0); - //TOutputValue out; - //out.SetSize(6); - //out.Fill(0); OffsetType off; off.Fill(0); @@ -112,8 +126,8 @@ public: angle = m_Alpha*static_cast<double>(d); // last offset in the diraction respecting spatial threshold - off[0] = vcl_floor(SpatialThresholdDouble*vcl_cos( angle ) + 0.5); - off[1] = vcl_floor(SpatialThresholdDouble*vcl_sin( angle ) + 0.5); + off[0] = static_cast<unsigned int>(vcl_floor(SpatialThresholdDouble*vcl_cos( angle ) + 0.5)); + off[1] = static_cast<unsigned int>(vcl_floor(SpatialThresholdDouble*vcl_sin( angle ) + 0.5)); // last indices in the diration respecting spectral threshold OffsetType offEnd = this->FindLastOffset( it, off ); // computes distance = dist between the 2 segment point. One of them is the center pixel -> (0,0) @@ -169,7 +183,7 @@ public: di[d] = dist; if( m_SelectedTextures[3] == true ) { - lengthLine[d] = dist;//static_cast<unsigned int>( vcl_sqrt(vcl_pow(static_cast<double>(offEnd[0]), 2) + vcl_pow(static_cast<double>(offEnd[1]), 2)) ); + lengthLine[d] = static_cast<unsigned int>(dist);//static_cast<unsigned int>( vcl_sqrt(vcl_pow(static_cast<double>(offEnd[0]), 2) + vcl_pow(static_cast<double>(offEnd[1]), 2)) ); sti[d] = sdiVal; if(sdiVal!=0.) sumWMean += (m_Alpha*(dist-1)*dist/*lengthLine[n]*di[n]*/)/sdiVal; diff --git a/Code/FeatureExtraction/otbLineDirectionImageFilter.h b/Code/FeatureExtraction/otbLineDirectionImageFilter.h index 49708f4a806cbbfea10e863a10211eef541039d4..bbdf04230011aaaedef542e26872d17ea3ad541c 100644 --- a/Code/FeatureExtraction/otbLineDirectionImageFilter.h +++ b/Code/FeatureExtraction/otbLineDirectionImageFilter.h @@ -26,17 +26,31 @@ PURPOSE. See the above copyright notices for more information. namespace otb { - /** \class LineDirectionImageFilter - * \brief This functor computes water, ndvi and spectral index of an image - */ +/** \class LineDirectionImageFilter + * \brief This functor computes the texture describes in the following publication + * It is based on line direction estimation. + * + * Please refer to Xin Huang, Liangpei Zhang and Pingxiang Li publication, + * Classification and Extraction of Spatial Features in Urban Areas + * Using High-Resolution Multispectral Imagery. + * IEEE Geoscience and Remote Sensing Letters, + * vol. 4, n. 2, 2007, pp 260-264 + * + * The texture is computaed for each pixel using its neighborhood. + * User can set the spatial threshold taht is the max line length, the spectral threshold + * that is the max difference authorized between a pixel of the line and the center pixel + * of the current neighborhood. Alpha and RationMaxConsideration are used to compute + * the \omega -mean value. Finally, The number of direction can be precised with + * NumberOfDirections. + * You can choose the computed textures using SetTextureStatus method (1:length, 2:width, + * 3:PSI, 4:w-mean, 5:ratio, 6:SD). + * + * \sa LineDirectionFunctor +*/ template <class TInputImage, class TOutputImage> class ITK_EXPORT LineDirectionImageFilter : public itk::ImageToImageFilter<TInputImage,TOutputImage> - /*UnaryFunctorNeighborhoodImageFilter< TInputImage, - TOutputImage, - Functor::LineDirectionFunctor< ITK_TYPENAME itk::ConstNeighborhoodIterator<TInputImage>, - ITK_TYPENAME TOutputImage::InternalPixelType> >*/ { public: /** Standard class typedefs. */ @@ -54,22 +68,18 @@ public: itkTypeMacro(UnaryFunctorNeighborhoodImageFilter,ImageToImageFilter); /** Some convenient typedefs. */ - typedef typename InputImageType::ConstPointer InputImagePointerType; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::SizeType InputImageSizeType; - typedef typename OutputImageType::Pointer OutputImagePointerType; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - //typedef typename OutputImageType::InternalPixelType OutputInternalImagePixelType; - typedef itk::ConstNeighborhoodIterator<TInputImage> NeighborhoodIteratorType; - typedef typename NeighborhoodIteratorType::RadiusType RadiusType; - //////////////////////////////////////////// - // CHANGE THE OUTPUTINTERNAZL INTO OUTPUTPIXE///////////// - /////////////////////////////////////////// + typedef typename InputImageType::ConstPointer InputImagePointerType; + typedef typename InputImageType::RegionType InputImageRegionType; + typedef typename InputImageType::PixelType InputImagePixelType; + typedef typename InputImageType::SizeType InputImageSizeType; + typedef typename OutputImageType::Pointer OutputImagePointerType; + typedef typename OutputImageType::RegionType OutputImageRegionType; + typedef typename OutputImageType::PixelType OutputImagePixelType; + typedef itk::ConstNeighborhoodIterator<TInputImage> NeighborhoodIteratorType; + typedef typename NeighborhoodIteratorType::RadiusType RadiusType; typedef Functor::LineDirectionFunctor< NeighborhoodIteratorType,OutputImagePixelType > FunctorType; - typedef typename FunctorType::OutputType FunctorOutputType; - typedef itk::ProcessObject ProcessObjectType; + typedef typename FunctorType::OutputType FunctorOutputType; + typedef itk::ProcessObject ProcessObjectType; /**Set/Get the radius of neighborhood.*/ itkGetMacro(Radius,unsigned int); diff --git a/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx b/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx index a4c68254d0a1c77cb94bb90d513b63ffd50c568b..6e78364cc11ce7929c4067de93a86059c4371ff6 100644 --- a/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx +++ b/Code/FeatureExtraction/otbLineSpatialObjectListToRightAnglePointSetFilter.txx @@ -159,8 +159,8 @@ LineSpatialObjectListToRightAnglePointSetFilter<TImage,TLinesList ,TPointSet> /** Verify if the indexes of the line are inside the region*/ typename InputImageType::SizeType size = this->GetInputImage()->GetRequestedRegion().GetSize(); - unsigned int width = size[0]; - unsigned int length = size[1]; + //unsigned int width = size[0]; + //unsigned int length = size[1]; // if(IndexBeginSrc[0] > width) IndexBeginSrc[0] = width-1; // if(IndexBeginSrc[1] > length) IndexBeginSrc[1] = length-1; diff --git a/Code/FeatureExtraction/otbMeanTextureFunctor.h b/Code/FeatureExtraction/otbMeanTextureFunctor.h index 90ad9e003e0a2438a115dc034abb46973b3cdfb0..bccc370fb128a44bd70834898969f3ba3c24a892 100755 --- a/Code/FeatureExtraction/otbMeanTextureFunctor.h +++ b/Code/FeatureExtraction/otbMeanTextureFunctor.h @@ -37,20 +37,16 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT MeanTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: MeanTextureFunctor(){}; virtual ~MeanTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbPanTexTextureFunctor.h b/Code/FeatureExtraction/otbPanTexTextureFunctor.h index f7ea5da4047219b0fa7d3da5e4f97cf1e381373e..0a6e5469087088e8bb10a5b7ab07b40008ac16cd 100644 --- a/Code/FeatureExtraction/otbPanTexTextureFunctor.h +++ b/Code/FeatureExtraction/otbPanTexTextureFunctor.h @@ -37,9 +37,9 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT PanTexTextureFunctor : -public ContrastTextureFunctor<TIterInput, TOutput> +public ContrastTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> { public: PanTexTextureFunctor() @@ -72,6 +72,7 @@ public: virtual ~PanTexTextureFunctor(){}; + /* typedef TIterInput IterType; typedef TOutput OutputType; typedef typename IterType::InternalPixelType InternalPixelType; @@ -79,8 +80,13 @@ public: typedef typename IterType::OffsetType OffsetType; typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; typedef ContrastTextureFunctor<IterType, OutputType> Superclass; - - + */ + typedef TScalarInputPixelType InputScalarType; + typedef TScalarOutputPixelType OutputScalarType; + typedef ContrastTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::OffsetType OffsetType; + typedef typename Superclass::RadiusType RadiusType; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { // Loop over each offset diff --git a/Code/FeatureExtraction/otbPanTexTextureImageFilter.h b/Code/FeatureExtraction/otbPanTexTextureImageFilter.h index f0c257b228597b5004dcfdceeb5f7913ffe4e610..6737142cdb32165f0f999521d3e553c1e3b4ec9d 100644 --- a/Code/FeatureExtraction/otbPanTexTextureImageFilter.h +++ b/Code/FeatureExtraction/otbPanTexTextureImageFilter.h @@ -36,15 +36,15 @@ namespace otb template <class TInputImage, class TOutputImage> class ITK_EXPORT PanTexTextureImageFilter : -public UnaryFunctorNeighborhoodWithOffsetImageFilter< TInputImage, TOutputImage, ITK_TYPENAME Functor::PanTexTextureFunctor< ITK_TYPENAME itk::ConstNeighborhoodIterator<TInputImage>, ITK_TYPENAME TOutputImage::PixelType> > +public UnaryFunctorNeighborhoodWithOffsetImageFilter< TInputImage, TOutputImage, ITK_TYPENAME Functor::PanTexTextureFunctor< ITK_TYPENAME TInputImage::InternalPixelType, ITK_TYPENAME TOutputImage::InternalPixelType> > { public: /** Standard class typedefs. */ typedef PanTexTextureImageFilter Self; typedef UnaryFunctorNeighborhoodWithOffsetImageFilter<TInputImage, TOutputImage, - typename Functor::PanTexTextureFunctor<typename itk::ConstNeighborhoodIterator<TInputImage>, - typename TOutputImage::PixelType> > Superclass; + typename Functor::PanTexTextureFunctor<typename TInputImage::InternalPixelType, + typename TOutputImage::InternalPixelType> > Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; diff --git a/Code/FeatureExtraction/otbPanTexTextureImageFilter.txx b/Code/FeatureExtraction/otbPanTexTextureImageFilter.txx index 774d7e7ef4268416009008ff840510adcebb0bc6..b8e4467d536dbaecb7f25051b89747ec5ded639f 100644 --- a/Code/FeatureExtraction/otbPanTexTextureImageFilter.txx +++ b/Code/FeatureExtraction/otbPanTexTextureImageFilter.txx @@ -85,7 +85,7 @@ PanTexTextureImageFilter<TInputImage, TOutputImage> while ( ! outputIt.IsAtEnd() ) { - outputIt.Set( this->m_FunctorList[threadId]( neighInputOffIt ) ); + outputIt.Set( this->m_FunctorList[threadId]( neighInputOffIt.GetNeighborhood() ) ); ++neighInputOffIt; ++outputIt; diff --git a/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.h b/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.h index 70f8a1271e307a734286d7b41192cdb954dfd17c..8c326a1461b01124c34a426fa9d368678d5bfc31 100644 --- a/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.h +++ b/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.h @@ -41,14 +41,14 @@ namespace otb template <class TInputImage, class TOutputImage, class TCoordRep = float > class ITK_EXPORT PanTexTextureImageFunctionFilter : public FunctionWithNeighborhoodToImageFilter< TInputImage, TOutputImage, - TextureImageFunction<TInputImage, ITK_TYPENAME Functor::PanTexTextureFunctor< ITK_TYPENAME itk::ConstNeighborhoodIterator<TInputImage>, itk::VariableLengthVector<double> >, TCoordRep > > + TextureImageFunction<TInputImage, ITK_TYPENAME Functor::PanTexTextureFunctor< ITK_TYPENAME TInputImage::PixelType, ITK_TYPENAME TOutputImage::PixelType>, TCoordRep > > { public: /** Standard class typedefs. */ typedef PanTexTextureImageFunctionFilter Self; typedef FunctionWithNeighborhoodToImageFilter< TInputImage, TOutputImage, - TextureImageFunction<TInputImage, typename Functor::PanTexTextureFunctor< typename itk::ConstNeighborhoodIterator<TInputImage>, itk::VariableLengthVector<double> >, TCoordRep > > Superclass; + TextureImageFunction<TInputImage, typename Functor::PanTexTextureFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType >, TCoordRep > > Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; diff --git a/Code/FeatureExtraction/otbSumAverageTextureFunctor.h b/Code/FeatureExtraction/otbSumAverageTextureFunctor.h index 9cc71dd690ce5fbae64ab1951cddbb8ec8b6fd5b..ae80a6421183f4c31a11df3f29c7129b1fe1987a 100755 --- a/Code/FeatureExtraction/otbSumAverageTextureFunctor.h +++ b/Code/FeatureExtraction/otbSumAverageTextureFunctor.h @@ -36,20 +36,16 @@ namespace Functor * \ingroup Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT SumAverageTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: SumAverageTextureFunctor(){}; virtual ~SumAverageTextureFunctor(){}; - - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbSumEntropyTextureFunctor.h b/Code/FeatureExtraction/otbSumEntropyTextureFunctor.h index 44d3a89ea7b6a3baa71d6b19fda6c4dc3e2f8de8..92e835f13b1543deb7ad974e84b064a70f6a226b 100755 --- a/Code/FeatureExtraction/otbSumEntropyTextureFunctor.h +++ b/Code/FeatureExtraction/otbSumEntropyTextureFunctor.h @@ -36,20 +36,16 @@ namespace Functor * \ingroup Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT SumEntropyTextureFunctor : -public TextureFunctorBase<TIterInput, TOutput> +public TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> { public: SumEntropyTextureFunctor(){}; virtual ~SumEntropyTextureFunctor(){}; - - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + + typedef TextureFunctorBase<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/FeatureExtraction/otbSumVarianceTextureFunctor.h b/Code/FeatureExtraction/otbSumVarianceTextureFunctor.h index 6c3532f001feabc4bab847f9741a785a86df8b56..be391e6dc8fabc7aba8c91398fdad7180b939b27 100755 --- a/Code/FeatureExtraction/otbSumVarianceTextureFunctor.h +++ b/Code/FeatureExtraction/otbSumVarianceTextureFunctor.h @@ -38,24 +38,20 @@ namespace Functor * \ingroup Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT SumVarianceTextureFunctor : -public SumAverageTextureFunctor<TIterInput, TOutput> +public SumAverageTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> { public: SumVarianceTextureFunctor(){}; virtual ~SumVarianceTextureFunctor(){}; - - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - typedef SumAverageTextureFunctor<TIterInput, TOutput> SuperClass; + + typedef SumAverageTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { - double f6 = SuperClass::ComputeOverSingleChannel(neigh, neighOff); + double f6 = Superclass::ComputeOverSingleChannel(neigh, neighOff); double area = static_cast<double>(neigh.GetSize()[0]*neigh.GetSize()[1]); double areaInv = 1/area; diff --git a/Code/FeatureExtraction/otbTextureFunctorBase.h b/Code/FeatureExtraction/otbTextureFunctorBase.h index 35b037e9dc800a6727d32e60bb794caf901d1edc..50152c7ecba4367b6c80481bf417c291724e15d9 100755 --- a/Code/FeatureExtraction/otbTextureFunctorBase.h +++ b/Code/FeatureExtraction/otbTextureFunctorBase.h @@ -22,6 +22,9 @@ #include "itkMacro.h" #include "itkNumericTraits.h" #include "itkNeighborhood.h" +#include "itkOffset.h" +#include "itkSize.h" +#include "itkVariableLengthVector.h" namespace otb @@ -41,7 +44,7 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class TextureFunctorBase { public: @@ -62,17 +65,17 @@ public: }; virtual ~TextureFunctorBase() {}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::OffsetType OffsetType; - typedef typename IterType::RadiusType RadiusType; - typedef typename OutputType::ValueType OutputPixelType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType, ::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - typedef std::vector<double> DoubleVectorType; - typedef std::vector<int> IntVectorType; - typedef std::vector<IntVectorType> IntVectorVectorType; + typedef TScalarInputPixelType InputScalarType; + typedef TScalarOutputPixelType OutputScalarType; + typedef itk::VariableLengthVector<InputScalarType> InputVectorType; + typedef itk::VariableLengthVector<OutputScalarType> OutputVectorType; + typedef itk::Offset<> OffsetType; + typedef itk::Size<> RadiusType; + typedef itk::Neighborhood<InputScalarType, 2> NeighborhoodType; + typedef itk::Neighborhood<InputVectorType, 2> NeighborhoodVectorType; + typedef std::vector<double> DoubleVectorType; + typedef std::vector<int> IntVectorType; + typedef std::vector<IntVectorType> IntVectorVectorType; void SetOffset(OffsetType off){ m_Offset=off; }; @@ -164,21 +167,64 @@ public: m_OffsetBinLength = scottCoef*binLengthOff; } - inline TOutput operator()(const IterType &itOff) +inline OutputScalarType operator()(const NeighborhoodType &neigh) + { + RadiusType radiusOff = neigh.GetRadius(); + //OutputScalarType outPix; + //outPix.SetSize( neigh.GetCenterPixel().GetSize() ); + //outPix.Fill(0); + OffsetType offset; + offset.Fill(0); + // Compute the neighborhood radius from the neigh+offset iterator to extract the neighborhood area from the iterator + RadiusType radius; + radius[0] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[0] - 1) ) - static_cast<double>( vcl_abs(m_Offset[0])) ); + radius[1] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[1] - 1) ) - static_cast<double>( vcl_abs(m_Offset[1])) ); + + NeighborhoodType inNeigh; + inNeigh.SetRadius(radius); + NeighborhoodType offNeigh; + offNeigh.SetRadius(radiusOff); + // Extract the neighborhood area + for ( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ ) + { + offset[0] = l; + for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++) + { + offset[1] = k; + inNeigh[offset] = neigh[offset];//neigh.GetPixel(offset); + } + } + // Extract the offset area + offset.Fill(0); + for ( int l = -static_cast<int>(radiusOff[0]); l <= static_cast<int>(radiusOff[0]); l++ ) + { + offset[0] = l; + for ( int k = -static_cast<int>(radiusOff[1]); k <= static_cast<int>(radiusOff[1]); k++) + { + offset[1] = k; + offNeigh[offset] = neigh[offset];//neigh.GetPixel(offset); + } + } + OutputScalarType outPix = static_cast<OutputScalarType>( this->ComputeOverSingleChannel(inNeigh, offNeigh) ); + + return outPix; + } + + inline OutputVectorType operator()(const NeighborhoodVectorType &neigh) { - RadiusType radiusOff = itOff.GetRadius(); - OutputType outPix; - outPix.SetSize( itOff.GetCenterPixel().GetSize() ); + RadiusType radiusOff = neigh.GetRadius(); + OutputVectorType outPix; + outPix.SetSize( neigh.GetCenterValue/*Pixel*/().GetSize() ); outPix.Fill(0); OffsetType offset; offset.Fill(0); // Compute the neighborhood radius from the neigh+offset iterator to extract the neighborhood area from the iterator RadiusType radius; - radius[0] = static_cast<unsigned int>( 0.5*( static_cast<double>(itOff.GetSize()[0] - 1) ) - static_cast<double>( vcl_abs(m_Offset[0])) ); - radius[1] = static_cast<unsigned int>( 0.5*( static_cast<double>(itOff.GetSize()[1] - 1) ) - static_cast<double>( vcl_abs(m_Offset[1])) ); + radius[0] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[0] - 1) ) - static_cast<double>( vcl_abs(m_Offset[0])) ); + radius[1] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[1] - 1) ) - static_cast<double>( vcl_abs(m_Offset[1])) ); // For each channel - for ( unsigned int i=0; i<itOff.GetCenterPixel().GetSize(); i++ ) + for ( unsigned int i=0; i<neigh.GetCenterValue/*Pixel*/().GetSize(); i++ ) { NeighborhoodType inNeigh; inNeigh.SetRadius(radius); @@ -191,7 +237,7 @@ public: for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++) { offset[1] = k; - inNeigh[offset] = itOff.GetPixel(offset)[i]; + inNeigh[offset] = neigh[offset][i];//neigh.GetPixel(offset)[i]; } } // Extract the offset area @@ -202,10 +248,10 @@ public: for ( int k = -static_cast<int>(radiusOff[1]); k <= static_cast<int>(radiusOff[1]); k++) { offset[1] = k; - offNeigh[offset] = itOff.GetPixel(offset)[i]; + offNeigh[offset] = neigh[offset][i]; } } - outPix[i] = static_cast<OutputPixelType>( this->ComputeOverSingleChannel(inNeigh, offNeigh) ); + outPix[i] = static_cast<OutputScalarType>( this->ComputeOverSingleChannel(inNeigh, offNeigh) ); } return outPix; } diff --git a/Code/FeatureExtraction/otbTextureImageFunction.txx b/Code/FeatureExtraction/otbTextureImageFunction.txx index b8c6a6364890ec7cf94cdd48f19ea42a896f0c75..e80d82e3c1735e7e7fef022dab4deac124ccfdeb 100644 --- a/Code/FeatureExtraction/otbTextureImageFunction.txx +++ b/Code/FeatureExtraction/otbTextureImageFunction.txx @@ -69,8 +69,6 @@ TextureImageFunction<TInputImage, TFunctor, TCoordRep> return ( itk::NumericTraits<RealType>::max() ); } - IteratorType it(m_Radius, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion()); - it.SetLocation(index); SizeType radiusOff; radiusOff[0] = (m_Radius[0]) + vcl_abs(m_Offset[0]); radiusOff[1] = (m_Radius[1]) + vcl_abs(m_Offset[1]); @@ -80,7 +78,7 @@ TextureImageFunction<TInputImage, TFunctor, TCoordRep> FunctorType funct; funct.SetOffset(m_Offset); - return static_cast<RealType>(funct.ComputeOverSingleChannel( it.GetNeighborhood(), itOff.GetNeighborhood()) ); + return static_cast<RealType>(funct( itOff.GetNeighborhood() )); } diff --git a/Code/FeatureExtraction/otbVarianceTextureFunctor.h b/Code/FeatureExtraction/otbVarianceTextureFunctor.h index 492eab5b0bfa790cc176f60ea2c1989ab31b2545..55f0d3016c7ef74ab81834838b75fb1e4eb53883 100755 --- a/Code/FeatureExtraction/otbVarianceTextureFunctor.h +++ b/Code/FeatureExtraction/otbVarianceTextureFunctor.h @@ -39,20 +39,17 @@ namespace Functor * \ingroup Statistics */ -template <class TIterInput, class TOutput> +template <class TScalarInputPixelType, class TScalarOutputPixelType> class ITK_EXPORT VarianceTextureFunctor : -public MeanTextureFunctor<TIterInput, TOutput> +public MeanTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> { public: VarianceTextureFunctor(){}; virtual ~VarianceTextureFunctor(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - typedef MeanTextureFunctor<TIterInput, TOutput> Superclass; + typedef MeanTextureFunctor<TScalarInputPixelType, TScalarOutputPixelType> Superclass; + typedef typename Superclass::NeighborhoodType NeighborhoodType; + virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { diff --git a/Code/Radiometry/otbBuiltUpIndicesFunctor.h b/Code/Radiometry/otbBuiltUpIndicesFunctor.h index 47cc88b0829d54ad1414007976ab9f0884e1bb59..b5036042e5a9e6d543baa6eede6fc5b44ab32dea 100644 --- a/Code/Radiometry/otbBuiltUpIndicesFunctor.h +++ b/Code/Radiometry/otbBuiltUpIndicesFunctor.h @@ -63,22 +63,22 @@ public: virtual ~TM4AndTM5IndexBase() {}; /// Set TM4 Index - void SetTM4Index(unsigned int channel) + void SetIndex1(unsigned int channel) { m_TM4Index = channel; } /// Get TM4 Index - unsigned int GetTM4Index() + unsigned int GetIndex1() { return m_TM4Index; } /// Set TM5 Index - void SetTM5Index(unsigned int channel) + void SetIndex2(unsigned int channel) { m_TM5Index = channel; } /// Get TM5 Index - unsigned int GetTM5Index() + unsigned int GetIndex2() { return m_TM5Index; } diff --git a/Code/VisuRefac/otbBlendingImageFilter.h b/Code/VisuRefac/otbBlendingImageFilter.h index 0842adad13a225964ef2dca8db71b4bab05ee629..d1a458ae7f283e948ed831683a49901c98c05b20 100644 --- a/Code/VisuRefac/otbBlendingImageFilter.h +++ b/Code/VisuRefac/otbBlendingImageFilter.h @@ -133,6 +133,7 @@ public: void SetBlendingFunction(BlendingFunctionType * function) { this->GetFunctor().SetFunction(function); + this->Modified(); } /** diff --git a/Code/VisuRefac/otbChangeScaledExtractRegionActionHandler.h b/Code/VisuRefac/otbChangeScaledExtractRegionActionHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..853a24bbafa092c601fa822cf3e0cc64a3d25192 --- /dev/null +++ b/Code/VisuRefac/otbChangeScaledExtractRegionActionHandler.h @@ -0,0 +1,122 @@ +/*========================================================================= + + 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 __otbChangeScaledExtractRegionActionHandler_h +#define __otbChangeScaledExtractRegionActionHandler_h + +#include "otbImageWidgetActionHandler.h" + +namespace otb +{ +/** \class ChangeScaledExtractRegionActionHandler +* \brief Implements basic Scroll, Full and Zoom widgets resizing. +* +* \sa ImageWidgetController +* \sa ImageWidgetActionHandler +*/ + +template <class TModel, class TView> +class ChangeScaledExtractRegionActionHandler + : public ImageWidgetActionHandler +{ +public: + /** Standard class typedefs */ + typedef ChangeScaledExtractRegionActionHandler 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(ChangeScaledExtractRegionActionHandler,ImageWidgetActionHandler); + + /** Model typedefs */ + typedef TModel ModelType; + typedef typename ModelType::Pointer ModelPointerType; + typedef typename ModelType::RegionType RegionType; + + /** View typedefs */ + typedef TView ViewType; + typedef typename ViewType::Pointer ViewPointerType; + + + /** Handle widget event + * \param widgetId The id of the moved widget + * \param event The event + * \return The handling return code + */ + virtual bool HandleWidgetEvent(std::string widgetId, int event) + { + if( m_View.IsNotNull() && m_Model.IsNotNull() ) + { + if(widgetId == m_View->GetFullWidget()->GetIdentifier() + && event == FL_PUSH) + { + // Get the clicked index + typename ViewType::IndexType index; + index[0] = Fl::event_x(); + index[1] = m_View->GetFullWidget()->h()-Fl::event_y(); + // Convert to image index + index = m_View->GetFullWidget()->ScreenIndexToRegionIndex(index); + // Change scaled extract region center + m_Model->SetScaledExtractRegionCenter(m_View->GetFullWidget()->ScreenIndexToRegionIndex(index)); + // Update model + m_Model->Update(); + return true; + } + } + return false; + } + + /** Set/Get the pointer to the view */ + itkSetObjectMacro(View,ViewType); + itkGetObjectMacro(View,ViewType); + + /** Set/Get the pointer to the model */ + itkSetObjectMacro(Model,ModelType); + itkGetObjectMacro(Model,ModelType); + +protected: + /** Constructor */ + ChangeScaledExtractRegionActionHandler() : m_View(), m_Model() + {} + + /** Destructor */ + virtual ~ChangeScaledExtractRegionActionHandler(){} + /** Printself method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + } + +private: + ChangeScaledExtractRegionActionHandler(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/otbImageLayer.h b/Code/VisuRefac/otbImageLayer.h index 4629d237e009088bfcd399dc64302fc156c08744..8f442ea24dfdcc8fbdc4af3f7cb74037446991a5 100644 --- a/Code/VisuRefac/otbImageLayer.h +++ b/Code/VisuRefac/otbImageLayer.h @@ -55,40 +55,59 @@ public: itkTypeMacro(ImageLayer,Layer); /** Image typedef */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointerType; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::InternalPixelType InternalPixelType; + typedef TImage ImageType; + typedef typename ImageType::Pointer ImagePointerType; + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::InternalPixelType InternalPixelType; + typedef typename ImageType::RegionType RegionType; /** Output image typedef */ - typedef TOutputImage OutputImageType; + typedef TOutputImage OutputImageType; /** Histogram typedef */ - typedef itk::Statistics::DenseFrequencyContainer DFContainerType; + typedef itk::Statistics::DenseFrequencyContainer DFContainerType; - typedef itk::VariableLengthVector<InternalPixelType> SampleType; - typedef itk::Statistics::ListSample<SampleType> ListSampleType; + typedef itk::VariableLengthVector<InternalPixelType> SampleType; + typedef itk::Statistics::ListSample<SampleType> ListSampleType; typedef otb::ListSampleToVariableDimensionHistogramGenerator - <ListSampleType,InternalPixelType,DFContainerType> HistogramFilterType; - typedef typename HistogramFilterType::HistogramType HistogramType; - typedef typename HistogramType::Pointer HistogramPointerType; + <ListSampleType,InternalPixelType,DFContainerType> HistogramFilterType; + typedef typename HistogramFilterType::HistogramType HistogramType; + typedef typename HistogramType::Pointer HistogramPointerType; /** Rendering part */ - typedef RenderingImageFilter<TImage,TOutputImage> RenderingFilterType; - typedef typename RenderingFilterType::RenderingFunctionType RenderingFunctionType; - typedef typename RenderingFunctionType::Pointer RenderingFunctionPointerType; + typedef RenderingImageFilter<TImage,TOutputImage> RenderingFilterType; + typedef typename RenderingFilterType::Pointer RenderingFilterPointerType; + typedef typename RenderingFilterType::RenderingFunctionType RenderingFunctionType; + typedef typename RenderingFunctionType::Pointer RenderingFunctionPointerType; typedef Function::StandardRenderingFunction<InternalPixelType, - typename TOutputImage::PixelType> DefaultRenderingFunctionType; - typedef itk::ExtractImageFilter<ImageType,ImageType> ExtractFilterType; + typename TOutputImage::PixelType> DefaultRenderingFunctionType; + typedef itk::ExtractImageFilter<ImageType,ImageType> ExtractFilterType; + typedef typename ExtractFilterType::Pointer ExtractFilterPointerType; /** Set/Get the image */ - itkSetObjectMacro(Image,ImageType); + void SetImage(ImageType * img) + { + if(m_Image != img) + { + m_Image = img; + m_ExtractFilter->SetInput(m_Image); + m_ScaledExtractFilter->SetInput(m_Image); + } + } itkGetObjectMacro(Image,ImageType); /** Set/Get the quicklook */ - itkSetObjectMacro(Quicklook,ImageType); + void SetQuicklook(ImageType * ql) + { + if(m_Quicklook != ql) + { + m_Quicklook = ql; + m_QuicklookRenderingFilter->SetInput(m_Quicklook); + } + + } itkGetObjectMacro(Quicklook,ImageType); /** Set/Get the histogram list */ @@ -96,7 +115,16 @@ public: itkGetObjectMacro(Histogram,HistogramType); /** Set/Get the rendering function */ - itkSetObjectMacro(RenderingFunction,RenderingFunctionType); + void SetRenderingFunction(RenderingFunctionType * function) + { + if(m_RenderingFunction != function) + { + m_RenderingFunction = function; + m_QuicklookRenderingFilter->SetRenderingFunction(m_RenderingFunction); + m_ExtractRenderingFilter->SetRenderingFunction(m_RenderingFunction); + m_ScaledExtractRenderingFilter->SetRenderingFunction(m_RenderingFunction); + } + } itkGetObjectMacro(RenderingFunction,RenderingFunctionType); /** Set/Get the number of bins for histogram generation */ @@ -109,9 +137,47 @@ public: itkBooleanMacro(AutoMinMax); /** Set/Get the auto min/max quantile */ - itkSetClampMacro(AutoMinMaxQuantile,double,0.,1.); + void SetAutoMinMaxQuantile(double value) + { + if(value < 0. || value > 1.) + { + itkExceptionMacro(<<"MinMax quantile should be in the range [0,1]"); + } + m_AutoMinMaxQuantile = value; + m_AutoMinMaxUpToDate = false; + } itkGetMacro(AutoMinMaxQuantile,double); + /** Reimplemented to pass the parameter to the extract filter */ + virtual void SetExtractRegion(const RegionType & region) + { + // This check should be done in the itk::ExtractImageFilter + if(this->GetExtractRegion() != region) + { + Superclass::SetExtractRegion(region); + // SetExtractionRegion throws an exception in case of empty region + if(region.GetNumberOfPixels() > 0) + { + m_ExtractFilter->SetExtractionRegion(region); + } + } + } + + /** Reimplemented to pass the parameter to the extract filter */ + virtual void SetScaledExtractRegion(const RegionType & region) + { + // This check should be done in the itk::ExtractImageFilter + if(this->GetScaledExtractRegion() != region) + { + Superclass::SetScaledExtractRegion(region); + // SetExtractionRegion throws an exception in case of empty region + if(region.GetNumberOfPixels() > 0) + { + m_ScaledExtractFilter->SetExtractionRegion(region); + } + } + } + /** Actually render the image */ virtual void Render(); @@ -153,10 +219,20 @@ private: /** Use histogram quantiles for min/max */ bool m_AutoMinMax; + bool m_AutoMinMaxUpToDate; /** Quantile used with AutoMinMax */ double m_AutoMinMaxQuantile; + /** Rendering filters */ + RenderingFilterPointerType m_QuicklookRenderingFilter; + RenderingFilterPointerType m_ExtractRenderingFilter; + RenderingFilterPointerType m_ScaledExtractRenderingFilter; + + /** Extract filters */ + ExtractFilterPointerType m_ExtractFilter; + ExtractFilterPointerType m_ScaledExtractFilter; + }; // end class } // end namespace otb diff --git a/Code/VisuRefac/otbImageLayer.txx b/Code/VisuRefac/otbImageLayer.txx index 9c25d7ff1a7b7877cfd7be93d9106e3a6b6b7462..bb89af48410cbbf8a376e02802783d612098dafd 100644 --- a/Code/VisuRefac/otbImageLayer.txx +++ b/Code/VisuRefac/otbImageLayer.txx @@ -25,9 +25,29 @@ namespace otb template <class TImage, class TOutputImage> ImageLayer<TImage,TOutputImage> -::ImageLayer() : m_NumberOfHistogramBins(255), m_AutoMinMax(true), m_AutoMinMaxQuantile(0.02) +::ImageLayer() : m_Quicklook(), m_Image(), m_Histogram(), m_RenderingFunction(), + m_NumberOfHistogramBins(255), m_AutoMinMax(true), m_AutoMinMaxUpToDate(false), m_AutoMinMaxQuantile(0.02), + m_QuicklookRenderingFilter(), m_ExtractRenderingFilter(), m_ScaledExtractRenderingFilter(), + m_ExtractFilter(), m_ScaledExtractFilter() { + // Rendering filters + m_QuicklookRenderingFilter = RenderingFilterType::New(); + m_ExtractRenderingFilter = RenderingFilterType::New(); + m_ScaledExtractRenderingFilter = RenderingFilterType::New(); + + // Default rendering function m_RenderingFunction = DefaultRenderingFunctionType::New(); + m_QuicklookRenderingFilter->SetRenderingFunction(m_RenderingFunction); + m_ExtractRenderingFilter->SetRenderingFunction(m_RenderingFunction); + m_ScaledExtractRenderingFilter->SetRenderingFunction(m_RenderingFunction); + + // Extract filters + m_ExtractFilter = ExtractFilterType::New(); + m_ScaledExtractFilter = ExtractFilterType::New(); + + // Wiring + m_ExtractRenderingFilter->SetInput(m_ExtractFilter->GetOutput()); + m_ScaledExtractRenderingFilter->SetInput(m_ScaledExtractFilter->GetOutput()); } template <class TImage, class TOutputImage> @@ -70,39 +90,31 @@ ImageLayer<TImage,TOutputImage> // Render quicklook if(this->GetHasQuicklook()) { - typename RenderingFilterType::Pointer renderer = RenderingFilterType::New(); - renderer->SetRenderingFunction(m_RenderingFunction); - renderer->SetInput(m_Quicklook); - renderer->Update(); - this->SetRenderedQuicklook(renderer->GetOutput()); + m_QuicklookRenderingFilter->Update(); + this->SetRenderedQuicklook(m_QuicklookRenderingFilter->GetOutput()); + } + // If there are pixels to render + if(this->GetExtractRegion().GetNumberOfPixels() > 0) + { + + m_ExtractRenderingFilter->Update(); + this->SetRenderedExtract(m_ExtractRenderingFilter->GetOutput()); } - // Render extract - if(this->GetHasExtract()) + else { - // Extracting region - typename ExtractFilterType::Pointer extract = ExtractFilterType::New(); - extract->SetInput(m_Image); - extract->SetExtractionRegion(this->GetExtractRegion()); - // Rendering - typename RenderingFilterType::Pointer renderer = RenderingFilterType::New(); - renderer->SetRenderingFunction(m_RenderingFunction); - renderer->SetInput(extract->GetOutput()); - renderer->Update(); - this->SetRenderedExtract(renderer->GetOutput()); + this->SetHasExtract(false); } // Render scaled extract - if(this->GetHasScaledExtract()) + // If there are pixels to render + if(this->GetScaledExtractRegion().GetNumberOfPixels() > 0) + { + m_ScaledExtractRenderingFilter->Update(); + this->SetRenderedScaledExtract(m_ScaledExtractRenderingFilter->GetOutput()); + this->SetHasScaledExtract(true); + } + else { - // Extracting region - typename ExtractFilterType::Pointer extract = ExtractFilterType::New(); - extract->SetInput(m_Image); - extract->SetExtractionRegion(this->GetScaledExtractRegion()); - // Rendering - typename RenderingFilterType::Pointer renderer = RenderingFilterType::New(); - renderer->SetRenderingFunction(m_RenderingFunction); - renderer->SetInput(extract->GetOutput()); - renderer->Update(); - this->SetRenderedScaledExtract(renderer->GetOutput()); + this->SetHasScaledExtract(false); } } @@ -124,40 +136,47 @@ ImageLayer<TImage,TOutputImage> // Else use the full image (update the data) histogramSource = m_Image; } - // Update the histogram source - histogramSource->Update(); - - // Iterate on the image - itk::ImageRegionConstIterator<ImageType> it(histogramSource,histogramSource->GetLargestPossibleRegion()); - - // declare a list to store the samples - typename ListSampleType::Pointer listSample = ListSampleType::New(); - - // Set the measurement vector size - listSample->SetMeasurementVectorSize(histogramSource->GetNumberOfComponentsPerPixel()); - // Fill the samples list - it.GoToBegin(); - while(!it.IsAtEnd()) + // Check if we need to generate the histogram again + if( !m_Histogram || (histogramSource->GetUpdateMTime() < histogramSource->GetPipelineMTime()) ) { - listSample->PushBack(it.Get()); - ++it; + m_AutoMinMaxUpToDate = false; + + // Update the histogram source + histogramSource->Update(); + + // Iterate on the image + itk::ImageRegionConstIterator<ImageType> it(histogramSource,histogramSource->GetLargestPossibleRegion()); + + // declare a list to store the samples + typename ListSampleType::Pointer listSample = ListSampleType::New(); + + // Set the measurement vector size + listSample->SetMeasurementVectorSize(histogramSource->GetNumberOfComponentsPerPixel()); + + // Fill the samples list + it.GoToBegin(); + while(!it.IsAtEnd()) + { + listSample->PushBack(it.Get()); + ++it; + } + + // Create the histogram generation filter + typename HistogramFilterType::Pointer histogramFilter = HistogramFilterType::New(); + histogramFilter->SetListSample(listSample); + + typename HistogramFilterType::HistogramSizeType binSizes(histogramSource->GetNumberOfComponentsPerPixel()); + binSizes.Fill(m_NumberOfHistogramBins); + + histogramFilter->SetNumberOfBins(binSizes); + + // Generate + histogramFilter->Update(); + + // Retrieve the histogram + m_Histogram = histogramFilter->GetOutput(); } - - // Create the histogram generation filter - typename HistogramFilterType::Pointer histogramFilter = HistogramFilterType::New(); - histogramFilter->SetListSample(listSample); - - typename HistogramFilterType::HistogramSizeType binSizes(histogramSource->GetNumberOfComponentsPerPixel()); - binSizes.Fill(m_NumberOfHistogramBins); - - histogramFilter->SetNumberOfBins(binSizes); - - // Generate - histogramFilter->Update(); - - // Retrieve the histogram - m_Histogram = histogramFilter->GetOutput(); } template <class TImage, class TOutputImage> @@ -185,6 +204,11 @@ ImageLayer<TImage,TOutputImage> // Setup rendering function m_RenderingFunction->SetMinimum(min); m_RenderingFunction->SetMaximum(max); + + m_QuicklookRenderingFilter->Modified(); + m_ExtractRenderingFilter->Modified(); + m_ScaledExtractRenderingFilter->Modified(); + m_AutoMinMaxUpToDate = true; } } #endif diff --git a/Code/VisuRefac/otbImageView.h b/Code/VisuRefac/otbImageView.h new file mode 100644 index 0000000000000000000000000000000000000000..41186a84b72cec68f00c355ce7c7e4f92dacb159 --- /dev/null +++ b/Code/VisuRefac/otbImageView.h @@ -0,0 +1,136 @@ +/*========================================================================= + + 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 __otbImageView_h +#define __otbImageView_h + +#include "otbImageWidget.h" +#include "otbImageViewerModelListener.h" +#include "otbImageViewerModel.h" +#include "otbImageWidgetController.h" + +namespace otb +{ + +/** \class ImageView +* \brief +* \Todo: Rename ImageViewer when refactoring will be completed. +*/ + +template <class TViewerModel > +class ImageView + : public ImageViewerModelListener, public itk::Object +{ +public: + /** Standard class typedefs */ + typedef ImageView 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(ImageView,itk::Object); + + /** Model typedef */ + typedef TViewerModel ModelType; + typedef typename ModelType::Pointer ModelPointerType; + typedef typename ModelType::OutputImageType ImageType; + + /** Controller typedef */ + typedef ImageWidgetController ControllerType; + typedef typename ControllerType::Pointer ControllerPointerType; + + /** Image region typedef */ + typedef typename ImageType::RegionType RegionType; + + /** Region size & index typedef */ + typedef typename RegionType::SizeType SizeType; + typedef typename RegionType::IndexType IndexType; + + /** Image widget */ + typedef otb::ImageWidget<ImageType> ImageWidgetType; + typedef typename ImageWidgetType::Pointer ImageWidgetPointerType; + + /** + * This method unregister with previous model if any, and + * register with the new one. + */ + void SetModel(ModelType * model); + + /** + * This method sets the controller and passes it to the widgets. + */ + void SetController(ControllerType * controller); + + /** + * Manually trigger a refresh + */ + void Update(); + + /** Get pointers the widgets */ + itkGetObjectMacro(ScrollWidget,ImageWidgetType); + itkGetObjectMacro(FullWidget,ImageWidgetType); + itkGetObjectMacro(ZoomWidget,ImageWidgetType); + + protected: + /** Constructor */ + ImageView(); + /** Destructor */ + ~ImageView(); + /** Printself method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + /** Update Scroll widget */ + void UpdateScrollWidget(); + + /** Update Full widget */ + void UpdateFullWidget(); + + /** Update Zoom widget */ + void UpdateZoomWidget(); + + /** Handle notification from the viewer */ + virtual void ImageViewerNotify(); + +private: + ImageView(const Self&); // purposely not implemented + void operator=(const Self&); // purposely not implemented + + /** The three classical widgets */ + ImageWidgetPointerType m_ScrollWidget; + ImageWidgetPointerType m_FullWidget; + ImageWidgetPointerType m_ZoomWidget; + + /** Model pointer */ + ModelPointerType m_Model; + + /** Controller pointer */ + ControllerPointerType m_Controller; + +}; // end class +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageView.txx" +#endif + +#endif + + diff --git a/Code/VisuRefac/otbImageView.txx b/Code/VisuRefac/otbImageView.txx new file mode 100644 index 0000000000000000000000000000000000000000..60033ca1f6012c986f9a3eb692f80589a360ca0b --- /dev/null +++ b/Code/VisuRefac/otbImageView.txx @@ -0,0 +1,198 @@ +/*========================================================================= + +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 __otbImageView_txx +#define __otbImageView_txx + +#include "otbImageView.h" + +namespace otb +{ +template < class TInputImage > +ImageView<TInputImage> +::ImageView() : m_ScrollWidget(), m_FullWidget(), m_ZoomWidget(), + m_Model(), m_Controller() +{ + // Initializing the widgets + m_ScrollWidget = ImageWidgetType::New(); + m_FullWidget = ImageWidgetType::New(); + m_ZoomWidget = ImageWidgetType::New(); + + // Set the widget identifiers + m_ScrollWidget->SetIdentifier("Scroll"); + m_FullWidget->SetIdentifier("Full"); + m_ZoomWidget->SetIdentifier("Zoom"); +} + +template < class TInputImage > +ImageView<TInputImage> +::~ImageView() +{ + +} + +template < class TInputImage > +void +ImageView<TInputImage> +::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 TInputImage > +void +ImageView<TInputImage> +::SetController(ControllerType * controller) +{ + m_Controller = controller; + m_ScrollWidget->SetController(m_Controller); + m_FullWidget->SetController(m_Controller); + m_ZoomWidget->SetController(m_Controller); +} + +template < class TInputImage> +void +ImageView<TInputImage> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + // Call the superclass implementation + Superclass::PrintSelf(os,indent); +} + + +template < class TInputImage > +void +ImageView<TInputImage> +::ImageViewerNotify() +{ + this->Update(); +} + +template < class TInputImage > +void +ImageView<TInputImage> +::Update() +{ + this->UpdateScrollWidget(); + this->UpdateFullWidget(); + this->UpdateZoomWidget(); +} + +template < class TInputImage > +void +ImageView<TInputImage> +::UpdateScrollWidget() +{ + // If the model has a quicklook + if(m_Model->GetHasQuicklook()) + { + // Read the buffer + const RegionType qlRegion = m_Model->GetRasterizedQuicklook() + ->GetLargestPossibleRegion(); + m_ScrollWidget->ReadBuffer(m_Model->GetRasterizedQuicklook(),qlRegion); + + // Compute the appropriate scale + const double wratio = static_cast<double>(m_ScrollWidget->w())/static_cast<double>(qlRegion.GetSize()[0]); + 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); + + // Setting widget label + std::string label = m_ScrollWidget->GetIdentifier(); + label+=(" - "); + label+=m_Model->GetName(); + m_ScrollWidget->label(label.c_str()); + + // display the zoom rectangle if necessary + if(m_Model->GetHasExtract()) + { + m_ScrollWidget->SetDisplayRectangle(true); + m_ScrollWidget->SetRectangle(m_Model->GetSubsampledExtractRegion()); + } + else + { + m_ScrollWidget->SetDisplayRectangle(false); + } + } + + // Redraw + m_ScrollWidget->redraw(); +} + + +template < class TInputImage > +void +ImageView<TInputImage> +::UpdateFullWidget() +{ + if(m_Model->GetHasExtract()) + { + m_FullWidget->ReadBuffer(m_Model->GetRasterizedExtract(),m_Model->GetRasterizedExtract() + ->GetLargestPossibleRegion()); + + // Setting widget label + std::string label = m_FullWidget->GetIdentifier(); + label+=(" - "); + label+=m_Model->GetName(); + m_FullWidget->label(label.c_str()); + + // display the zoom rectangle if necessary + if(m_Model->GetHasScaledExtract()) + { + m_FullWidget->SetDisplayRectangle(true); + m_FullWidget->SetRectangle(m_Model->GetScaledExtractRegion()); + } + else + { + m_FullWidget->SetDisplayRectangle(false); + } + // redraw the widget + m_FullWidget->redraw(); + } + } + +template < class TInputImage > +void +ImageView<TInputImage> +::UpdateZoomWidget() +{ + if(m_Model->GetHasScaledExtract()) + { + m_ZoomWidget->ReadBuffer(m_Model->GetRasterizedScaledExtract(),m_Model->GetRasterizedScaledExtract() + ->GetLargestPossibleRegion()); + + // Setting widget label + std::string label = m_ZoomWidget->GetIdentifier(); + label+=(" - "); + label+=m_Model->GetName(); + m_ZoomWidget->label(label.c_str()); + + m_ZoomWidget->redraw(); + } +} + + +} +#endif diff --git a/Code/VisuRefac/otbImageViewerModel.h b/Code/VisuRefac/otbImageViewerModel.h index bbcf8e3dfbd4a0f9b906305846960df2ae9d9e8c..54e0472f86e23ac56ed61ed71470b5ff44dd197f 100644 --- a/Code/VisuRefac/otbImageViewerModel.h +++ b/Code/VisuRefac/otbImageViewerModel.h @@ -62,6 +62,7 @@ public: /** Layer typedef */ typedef otb::Layer<OutputImageType> LayerType; typedef typename LayerType::RegionType RegionType; + typedef typename RegionType::IndexType IndexType; /** Layer list typedef */ typedef otb::ObjectList<LayerType> LayerListType; @@ -122,17 +123,34 @@ public: itkGetObjectMacro(RasterizedExtract,OutputImageType); itkGetObjectMacro(RasterizedScaledExtract,OutputImageType); + /** 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); itkGetConstReferenceMacro(ScaledExtractRegion,RegionType); + /** Get the state of each view */ + itkGetMacro(HasQuicklook,bool); + itkGetMacro(HasExtract,bool); + itkGetMacro(HasScaledExtract,bool); + /** Update will render all visible layers, rasterize all visible * layers and notify all listeners. */ - virtual void Update(void); + void Update(void); + + /** Change the Scaled extract region by giving the center of the + * region */ + void SetScaledExtractRegionCenter(const IndexType & index); + + /** Change the extract region by giving the center of the + * region */ + void SetExtractRegionCenter(const IndexType & index); + protected: /** Constructor */ @@ -141,16 +159,19 @@ protected: ~ImageViewerModel(); /** Printself method */ - void PrintSelf(std::ostream& os, itk::Indent indent) const; + void PrintSelf(std::ostream& os, itk::Indent indent) const; /** Renders all visible layers */ - virtual void RenderVisibleLayers(void); + void RenderVisibleLayers(void); /** Rasterize visible layers */ - virtual void RasterizeVisibleLayers(void); + void RasterizeVisibleLayers(void); /** Notify a registered listener */ - virtual void Notify(ListenerType * listener); + void Notify(ListenerType * listener); + + /** Constrains the given region to the largest possible one. */ + RegionType ConstrainRegion(const RegionType & region, const RegionType & largest); private: ImageViewerModel(const Self&); // purposely not implemented @@ -170,11 +191,15 @@ private: OutputImagePointerType m_RasterizedExtract; bool m_HasExtract; RegionType m_ExtractRegion; + RegionType m_SubsampledExtractRegion; /** Rendered scaled extract */ OutputImagePointerType m_RasterizedScaledExtract; bool m_HasScaledExtract; RegionType m_ScaledExtractRegion; + + /** Wether the model is currently updating or not */ + bool m_Updating; }; // end class } // end namespace otb diff --git a/Code/VisuRefac/otbImageViewerModel.txx b/Code/VisuRefac/otbImageViewerModel.txx index 76731f427c88789c5002d721453d4628178b2952..7d2d0f019dc61bbb38aaf57c8a6e652aef241e83 100644 --- a/Code/VisuRefac/otbImageViewerModel.txx +++ b/Code/VisuRefac/otbImageViewerModel.txx @@ -25,17 +25,16 @@ namespace otb template <class TOutputImage> ImageViewerModel<TOutputImage> -::ImageViewerModel() +::ImageViewerModel() : m_Name("Default"), m_Layers(), m_RasterizedQuicklook(), + m_HasQuicklook(false),m_RasterizedExtract(),m_HasExtract(false), + m_ExtractRegion(), m_SubsampledExtractRegion(), m_RasterizedScaledExtract(), m_HasScaledExtract(false), + m_ScaledExtractRegion() + { // Intializing the layer list m_Layers = LayerListType::New(); - // Viewer name - m_Name = "Default"; + - // Default: nothing is available - m_HasQuicklook = false; - m_HasExtract = false; - m_HasScaledExtract = false; } template <class TOutputImage> @@ -160,12 +159,18 @@ void ImageViewerModel<TOutputImage> ::Update() { - // Render all visible layers - this->RenderVisibleLayers(); - // Rasterize all visible layers - this->RasterizeVisibleLayers(); - // Notify all listeners - this->NotifyAll(); + // Multiple concurrent update guards + if(!m_Updating) + { + m_Updating = true; + // Render all visible layers + this->RenderVisibleLayers(); + // Rasterize all visible layers + this->RasterizeVisibleLayers(); + // Notify all listeners + this->NotifyAll(); + m_Updating = false; + } } template <class TOutputImage> @@ -217,6 +222,17 @@ ImageViewerModel<TOutputImage> { 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()) @@ -230,6 +246,9 @@ ImageViewerModel<TOutputImage> m_HasScaledExtract = true; m_RasterizedScaledExtract = baseLayer->GetRenderedScaledExtract(); } + + // Move to the next layer + ++it; // Walk the remaining layers while(it!=m_Layers->End()) @@ -288,9 +307,82 @@ void ImageViewerModel<TOutputImage> ::Notify(ListenerType * listener) { + // Notify the listener listener->ImageViewerNotify(); } + +template <class TOutputImage> +void +ImageViewerModel<TOutputImage> +::SetScaledExtractRegionCenter(const IndexType & index) +{ + // Set the center of the scaled extract region + IndexType newIndex = index; + newIndex[0]-=m_ScaledExtractRegion.GetSize()[0]/2; + newIndex[1]-=m_ScaledExtractRegion.GetSize()[1]/2; + m_ScaledExtractRegion.SetIndex(newIndex); +} + +template <class TOutputImage> +void +ImageViewerModel<TOutputImage> +::SetExtractRegionCenter(const IndexType & index) +{ + // Set the center of the extract region + IndexType newIndex = index; + newIndex[0]-=m_ExtractRegion.GetSize()[0]/2; + newIndex[1]-=m_ExtractRegion.GetSize()[1]/2; + m_ExtractRegion.SetIndex(newIndex); +} + +template <class TOutputImage> +typename ImageViewerModel<TOutputImage> +::RegionType +ImageViewerModel<TOutputImage> +::ConstrainRegion(const RegionType & region, const RegionType & largest) +{ + // First check if the case is trivial + if(region.GetNumberOfPixels() == 0 || largest.IsInside(region)) + { + return region; + } + + RegionType resp = region; + typename RegionType::IndexType index = resp.GetIndex(); + typename RegionType::SizeType size = resp.GetSize(); + + for(unsigned int dim = 0; dim<RegionType::ImageDimension;++dim) + { + const int offset = index[dim]+size[dim] - largest.GetIndex()[dim] + largest.GetSize()[dim]; + // If the region is not larger than the largest, wen can constrain + if(largest.GetSize()[dim] > size[dim]) + { + // If the region is to the left, push left + if(index[dim] < largest.GetIndex()[dim]) + { + index[dim] = largest.GetIndex()[dim]; + } + // If the region is to the right, push right + else if(offset > 0) + { + index[dim]-=offset; + } + } + else + { + // else crop + index[dim] = largest.GetIndex()[dim]; + size[dim] = largest.GetSize()[dim]; + } + } + resp.SetIndex(index); + resp.SetSize(size); + + return resp; +} + + template <class TOutputImage> void ImageViewerModel<TOutputImage> diff --git a/Code/VisuRefac/otbImageWidget.h b/Code/VisuRefac/otbImageWidget.h index ece541616b5d8dd560dc43ce5f7b489e83e7c80d..931b690fc5337f1a6b31cd01bbafb993a4bbee10 100644 --- a/Code/VisuRefac/otbImageWidget.h +++ b/Code/VisuRefac/otbImageWidget.h @@ -25,6 +25,7 @@ // This is included for the default template #include "otbImage.h" #include "itkRGBPixel.h" +#include "itkFixedArray.h" // This include is needed to get the OTB_GL_USE_ACCEL definition #include "otbConfigure.h" @@ -43,6 +44,8 @@ namespace otb * will generate an exception. * Using Gl acceleration allows you to have a better rendering when * zooming. +* +* It is also able to display a rectangle on the displayed image. */ template <class TInputImage=otb::Image<itk::RGBPixel<unsigned char>,2 > > @@ -69,8 +72,11 @@ public: typedef typename RegionType::SizeType SizeType; typedef typename RegionType::IndexType IndexType; /** Controller typedef */ - typedef otb::ImageWidgetController ControllerType; - typedef typename ControllerType::Pointer ControllerPointerType; + typedef otb::ImageWidgetController ControllerType; + typedef typename ControllerType::Pointer ControllerPointerType; + + /** Color typedef (used to draw the rectangle, 4th channel is alpha) */ + typedef itk::FixedArray<float,4> ColorType; /** Reads the OpenGl buffer from an image pointer * \param image The image pointer, @@ -80,7 +86,7 @@ public: * This method fills the m_OpenGl buffer according to the region * size. Buffer in flipped over X axis if OTB_USE_GL_ACCEL is OFF. */ - virtual void ReadBuffer(InputImageType * image, RegionType & region); + virtual void ReadBuffer(const InputImageType * image, const RegionType & region); /** Set/Get the Controller */ itkSetObjectMacro(Controller,ControllerType); @@ -100,10 +106,29 @@ public: itkGetMacro(UseGlAcceleration,bool); itkBooleanMacro(UseGlAcceleration); + /** Enable/disable rectangle drawing */ + itkSetMacro(DisplayRectangle,bool); + itkGetMacro(DisplayRectangle,bool); + itkBooleanMacro(DisplayRectangle); + + /** Set/Get the rectangle to display */ + itkSetMacro(Rectangle,RegionType); + itkGetConstReferenceMacro(Rectangle,RegionType); + /** Set/Get the identifier */ itkSetStringMacro(Identifier); itkGetStringMacro(Identifier); + /** Set/Get the color of the rectangle */ + itkSetMacro(RectangleColor,ColorType); + itkGetConstReferenceMacro(RectangleColor,ColorType); + + /** 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); + protected: /** Constructor */ ImageWidget(); @@ -141,7 +166,6 @@ protected: return (region.GetSize()[1]-1+region.GetIndex()[1]-index[1])*3*region.GetSize()[0]+3*(index[0]-region.GetIndex()[0]); } - private: ImageWidget(const Self&); // purposely not implemented void operator=(const Self&); // purposely not implemented @@ -152,8 +176,8 @@ private: /** OpenGl buffer */ unsigned char * m_OpenGlBuffer; - /** OpenGl buffer size */ - SizeType m_OpenGlBufferSize; + /** OpenGl buffered region */ + RegionType m_OpenGlBufferedRegion; /** Widget identifier */ std::string m_Identifier; @@ -164,6 +188,17 @@ private: /** Flag for GlAcceleration */ bool m_UseGlAcceleration; + /** Rectangle region */ + RegionType m_Rectangle; + bool m_DisplayRectangle; + ColorType m_RectangleColor; + + /** Image extent coordinates in the display axis system */ + double m_ImageExtentWidth; + double m_ImageExtentHeight; + double m_ImageExtentX; + double m_ImageExtentY; + }; // end class } // end namespace otb diff --git a/Code/VisuRefac/otbImageWidget.txx b/Code/VisuRefac/otbImageWidget.txx index 57b2d606bf6f119349b0750b24c7ed256b8ecf89..5ef296ff33eaf074d0b78658d3b1d3108dfb6f1e 100644 --- a/Code/VisuRefac/otbImageWidget.txx +++ b/Code/VisuRefac/otbImageWidget.txx @@ -25,19 +25,18 @@ namespace otb { template <class TInputImage> ImageWidget<TInputImage> -::ImageWidget() : Fl_Gl_Window(0,0,0,0) +::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() { - // Setting up default values - m_IsotropicZoom = 1.0; - m_OpenGlBuffer = NULL; - m_OpenGlBufferSize.Fill(0); - m_Identifier = "Default"; - #ifdef OTB_GL_USE_ACCEL m_UseGlAcceleration = true; - #else - m_UseGlAcceleration = false; #endif + + // Default color for rectangle + m_RectangleColor.Fill(0.); + m_RectangleColor[0]=1.0; + m_RectangleColor[3]=1.0; } template <class TInputImage> @@ -79,7 +78,7 @@ ImageWidget<TInputImage> } else { - os<<indent<<indent<<"OpenGl buffer is allocated with size "<<m_OpenGlBufferSize<<"."<<std::endl; + os<<indent<<indent<<"OpenGl buffer is allocated with size "<<m_OpenGlBufferedRegion.GetSize()<<"."<<std::endl; } os<<indent<<indent<<"OpenGl isotropic zoom is "<<m_IsotropicZoom<<"."<<std::endl; } @@ -89,7 +88,7 @@ ImageWidget<TInputImage> template <class TInputImage> void ImageWidget<TInputImage> -::ReadBuffer(InputImageType * image, RegionType & region) +::ReadBuffer(const InputImageType * image, const RegionType & region) { // Before doing anything, check if region is inside the buffered // region of image @@ -143,7 +142,7 @@ ImageWidget<TInputImage> ++it; } // Last, updating buffer size - m_OpenGlBufferSize = region.GetSize(); + m_OpenGlBufferedRegion = region; } template <class TInputImage> @@ -177,7 +176,6 @@ ImageWidget<TInputImage> glMatrixMode(GL_PROJECTION); this->ortho(); glDisable(GL_BLEND); - // Check if there is somthing to draw if(m_OpenGlBuffer == NULL) { @@ -185,20 +183,20 @@ ImageWidget<TInputImage> } // Image extent - double sizex = m_IsotropicZoom*static_cast<double>(m_OpenGlBufferSize[0]); - double sizey = m_IsotropicZoom*static_cast<double>(m_OpenGlBufferSize[1]); - double startx = (static_cast<double>(this->w())-sizex)/2; - double starty = (static_cast<double>(this->h())-sizey)/2; + m_ImageExtentWidth = m_IsotropicZoom*static_cast<double>(m_OpenGlBufferedRegion.GetSize()[0]); + m_ImageExtentHeight = m_IsotropicZoom*static_cast<double>(m_OpenGlBufferedRegion.GetSize()[1]); + m_ImageExtentX = (static_cast<double>(this->w())-m_ImageExtentWidth)/2; + m_ImageExtentY = (static_cast<double>(this->h())-m_ImageExtentHeight)/2; if(!m_UseGlAcceleration) { // Set the pixel Zoom - glRasterPos2f(startx,starty); + glRasterPos2f(m_ImageExtentX,m_ImageExtentY); glPixelZoom(m_IsotropicZoom,m_IsotropicZoom); // display the image - glDrawPixels(m_OpenGlBufferSize[0], - m_OpenGlBufferSize[1], + glDrawPixels(m_OpenGlBufferedRegion.GetSize()[0], + m_OpenGlBufferedRegion.GetSize()[1], GL_RGB, GL_UNSIGNED_BYTE, m_OpenGlBuffer); @@ -210,22 +208,45 @@ ImageWidget<TInputImage> GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, 3, m_OpenGlBufferSize[0], m_OpenGlBufferSize[1], 0, GL_RGB, GL_UNSIGNED_BYTE, m_OpenGlBuffer); + glTexImage2D(GL_TEXTURE_2D, 0, 3, m_OpenGlBufferedRegion.GetSize()[0], m_OpenGlBufferedRegion.GetSize()[1], 0, GL_RGB, GL_UNSIGNED_BYTE, m_OpenGlBuffer); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering glBindTexture (GL_TEXTURE_2D, texture); glBegin (GL_QUADS); glTexCoord2f (0.0, 1.0); - glVertex3f (startx,starty, 0.0); + glVertex3f (m_ImageExtentX,m_ImageExtentY, 0.0); glTexCoord2f (1.0, 1.0); - glVertex3f (startx+sizex, starty, 0.0); + glVertex3f (m_ImageExtentX+m_ImageExtentWidth, m_ImageExtentY, 0.0); glTexCoord2f (1.0, 0.0); - glVertex3f (startx+sizex,starty+sizey, 0.0); + glVertex3f (m_ImageExtentX+m_ImageExtentWidth,m_ImageExtentY+m_ImageExtentHeight, 0.0); glTexCoord2f (0.0, 0.0); - glVertex3f (startx,starty+sizey, 0.0); + glVertex3f (m_ImageExtentX,m_ImageExtentY+m_ImageExtentHeight, 0.0); glEnd (); glDisable(GL_TEXTURE_2D); } + + // Draw the rectangle if necessary + if(m_DisplayRectangle) + { + typename RegionType::IndexType index; + typename RegionType::SizeType size; + + index = m_Rectangle.GetIndex(); + index[1]+=m_Rectangle.GetSize()[1]; + index = RegionIndexToScreenIndex(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); + + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(m_RectangleColor[0],m_RectangleColor[1],m_RectangleColor[2],m_RectangleColor[3]); + glBegin(GL_LINE_LOOP); + gl_rect(index[0],index[1],size[0],size[1]); + glEnd(); + glDisable(GL_BLEND); + } } template <class TInputImage> @@ -233,12 +254,34 @@ void ImageWidget<TInputImage> ::resize(int x, int y, int w, int h) { + // Distinguish between resize, move and not changed events + // (The system window manager may generate multiple resizing events, + // so we'd rather avoid event flooding here) + bool reportMove = false; + bool reportResize = false; + if(this->x() != x || this->y() != y) + { + reportMove = true; + } + + if(this->w() != w || this->h() != h) + { + reportResize = true; + } + // First call the superclass implementation Fl_Gl_Window::resize(x,y,w,h); // If There is a controller if(m_Controller.IsNotNull()) { - m_Controller->HandleWidgetResize(m_Identifier,x,y,w,h); + if(reportMove) + { + m_Controller->HandleWidgetMove(m_Identifier,x,y); + } + if(reportResize) + { + m_Controller->HandleWidgetResize(m_Identifier,w,h); + } } } @@ -257,5 +300,32 @@ ImageWidget<TInputImage> return 0; } } + +template <class TInputImage> +typename ImageWidget<TInputImage> +::IndexType +ImageWidget<TInputImage> +::ScreenIndexToRegionIndex(const IndexType & index) +{ + IndexType resp; + resp[0] = static_cast<int>(m_OpenGlBufferedRegion.GetIndex()[0]+static_cast<double>(index[0]-m_ImageExtentX)/m_IsotropicZoom); + resp[1] = static_cast<int>(m_OpenGlBufferedRegion.GetIndex()[1]+static_cast<double>(m_ImageExtentY+m_ImageExtentHeight-index[1])/m_IsotropicZoom); + return resp; +} + +template <class TInputImage> +typename ImageWidget<TInputImage> +::IndexType +ImageWidget<TInputImage> +::RegionIndexToScreenIndex(const IndexType & index) +{ + IndexType resp; + resp[0] = static_cast<int>(m_ImageExtentX + (static_cast<double>(index[0]) + -static_cast<double>(m_OpenGlBufferedRegion.GetIndex()[0]))*m_IsotropicZoom); + resp[1] = static_cast<int>(m_ImageExtentHeight + m_ImageExtentY - ((static_cast<double>(index[1]) + -static_cast<double>(m_OpenGlBufferedRegion.GetIndex()[1]))*m_IsotropicZoom)); + return resp; +} + } #endif diff --git a/Code/VisuRefac/otbImageWidgetActionHandler.h b/Code/VisuRefac/otbImageWidgetActionHandler.h index cb002db2f18fc20005ba2340401f8d615be367d9..94cc8c048781509f21b7e734f788b457edee4004 100644 --- a/Code/VisuRefac/otbImageWidgetActionHandler.h +++ b/Code/VisuRefac/otbImageWidgetActionHandler.h @@ -50,39 +50,38 @@ public: /** Runtime information */ itkTypeMacro(ImageWidgetActionHandler,Object); - virtual int HandleWidgetEvent(std::string widgetId, int event) + /** Handle widget event + * \param widgetId The id of the moved widget + * \param event The event + * \return true if the event is handled + */ + virtual bool HandleWidgetEvent(std::string widgetId, int event) { - return 0; + return false; } - /** Handle widget resizing - * \param widgetId The id of the resized widget + /** Handle widget move + * \param widgetId The id of the moved widget * \param x new x location * \param y new y location + * \return true if the event is handled + */ + virtual bool HandleWidgetMove(std::string widgetId,int x,int y) + { + return false; + } + + /** Handle widget resize + * \param widgetId The id of the resized widget * \param w new width * \param h new height + * \return true if the event is handled */ - virtual void HandleWidgetResize(std::string widgetId,int x,int y, int w, int h){} - - /** Returns true if the given event from the given widget is - * handled. - * \param widgetId The id of the widget the event comes from - * \param event The event - * \return True if the event is handled - */ - virtual bool ListenToEvent(std::string widgetId,int event) - { - return false; - } - /** Returns true if the resizing of the given widget is handled - * \param widgetId The id of the widget the event comes from - * \return True if the resizing is handled - */ - virtual bool ListenToResize(std::string widgetId) + virtual bool HandleWidgetResize(std::string widgetId,int w, int h) { return false; } - + protected: /** Constructor */ ImageWidgetActionHandler(){} diff --git a/Code/VisuRefac/otbImageWidgetController.cxx b/Code/VisuRefac/otbImageWidgetController.cxx index 4a88861ccc7e9ae898413c1b1fb3d677002d93e8..5955226562faec5ec1d114859c7dca6d2a44fb8e 100644 --- a/Code/VisuRefac/otbImageWidgetController.cxx +++ b/Code/VisuRefac/otbImageWidgetController.cxx @@ -65,13 +65,13 @@ int ImageWidgetController::HandleWidgetEvent(std::string widgetId, int event) // Get the current handler handler = it.Get(); // Check if it listens to (widget,event) - found = handler->ListenToEvent(widgetId,event); + found = handler->HandleWidgetEvent(widgetId,event); ++it; } // If an handler was found, use it if(found) { - return handler->HandleWidgetEvent(widgetId,event); + return 1; } else { @@ -79,7 +79,7 @@ int ImageWidgetController::HandleWidgetEvent(std::string widgetId, int event) } } -void ImageWidgetController::HandleWidgetResize(std::string widgetId, int x, int y, int w, int h) +void ImageWidgetController::HandleWidgetResize(std::string widgetId, int w, int h) { // Define an iterator on the action handlers list ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin(); @@ -94,17 +94,34 @@ void ImageWidgetController::HandleWidgetResize(std::string widgetId, int x, int { // Get the current handler handler = it.Get(); - // Check if it listens to (widget,event) - found = handler->ListenToResize(widgetId); + // try to handle the event with the current handler + found = handler->HandleWidgetResize(widgetId,w,h); ++it; - } - // If an handler was found, use it - if(found) + } +} + +void ImageWidgetController::HandleWidgetMove(std::string widgetId, int x, int y) +{ + // Define an iterator on the action handlers list + ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin(); + + // Found indicates if a handler was found to respond to this event + bool found = false; + + // The action handler found + ActionHandlerType * handler; + + while(!found && it!=m_ActionHandlersList->End()) { - handler->HandleWidgetResize(widgetId,x,y,w,h); + // Get the current handler + handler = it.Get(); + // Check if it listens to (widget,event) + found = handler->HandleWidgetMove(widgetId,x,y); + ++it; } } + void ImageWidgetController::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os,indent); diff --git a/Code/VisuRefac/otbImageWidgetController.h b/Code/VisuRefac/otbImageWidgetController.h index 0bfde167c563f924dd64c18da7fc6c8467763a40..1767a5623ac70510561901c7a097f465303478b8 100644 --- a/Code/VisuRefac/otbImageWidgetController.h +++ b/Code/VisuRefac/otbImageWidgetController.h @@ -74,14 +74,19 @@ public: */ int HandleWidgetEvent(std::string widgetId, int event); - /** Handle widget resizing + /** Handle widget resize * \param widgetId The id of the resized widget - * \param x new x location - * \param y new y location * \param w new width * \param h new height */ - void HandleWidgetResize(std::string widgetId,int x,int y, int w, int h); + void HandleWidgetResize(std::string widgetId, int w, int h); + + /** Handle widget move + * \param widgetId The id of the resized widget + * \param x new x location + * \param y new y location + */ + void HandleWidgetMove(std::string widgetId, int x, int y); protected: /** Constructor */ diff --git a/Code/VisuRefac/otbLayer.h b/Code/VisuRefac/otbLayer.h index ec8ec7b8062ee7be1557ff45648f13264f773cec..5c24e1c827e0f0bc7e79b8827d8afe8c73a6c634 100644 --- a/Code/VisuRefac/otbLayer.h +++ b/Code/VisuRefac/otbLayer.h @@ -90,10 +90,20 @@ public: itkSetMacro(Extent,RegionType); itkGetConstReferenceMacro(Extent,RegionType); - itkSetMacro(ExtractRegion,RegionType); + /** This parameters should be reported to the appropriate filters in + implementations. Therefore this method is marked as virtual. */ + virtual void SetExtractRegion(const RegionType & region) + { + m_ExtractRegion = region; + } itkGetConstReferenceMacro(ExtractRegion,RegionType); - itkSetMacro(ScaledExtractRegion,RegionType); + /** This parameters should be reported to the appropriate filters in + implementations. Therefore this method is marked as virtual. */ + virtual void SetScaledExtractRegion(const RegionType & region) + { + m_ScaledExtractRegion = region; + } itkGetConstReferenceMacro(ScaledExtractRegion,RegionType); itkSetMacro(QuicklookSubsamplingRate,unsigned int); diff --git a/Code/VisuRefac/otbRenderingImageFilter.h b/Code/VisuRefac/otbRenderingImageFilter.h index 188755361e96b84681609c10ff216cbafb9e238a..d57b5e5ace404f720cde3c70f2c0f8b9c86c22bf 100644 --- a/Code/VisuRefac/otbRenderingImageFilter.h +++ b/Code/VisuRefac/otbRenderingImageFilter.h @@ -154,6 +154,7 @@ public: void SetRenderingFunction(RenderingFunctionType * function) { this->GetFunctor().SetFunction(function); + this->Modified(); } /** diff --git a/Code/VisuRefac/otbWidgetResizingActionHandler.h b/Code/VisuRefac/otbWidgetResizingActionHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..e01125749dc6a0c7ae9e463c2533d44e0d6c4a3e --- /dev/null +++ b/Code/VisuRefac/otbWidgetResizingActionHandler.h @@ -0,0 +1,141 @@ +/*========================================================================= + + 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 __otbWidgetResizingActionHandler_h +#define __otbWidgetResizingActionHandler_h + +#include "otbImageWidgetActionHandler.h" + +namespace otb +{ +/** \class WidgetResizingActionHandler +* \brief Implements basic Scroll, Full and Zoom widgets resizing. +* +* \sa ImageWidgetController +* \sa ImageWidgetActionHandler +*/ + +template <class TModel, class TView> +class WidgetResizingActionHandler + : public ImageWidgetActionHandler +{ +public: + /** Standard class typedefs */ + typedef WidgetResizingActionHandler 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(WidgetResizingActionHandler,ImageWidgetActionHandler); + + /** Model typedefs */ + typedef TModel ModelType; + typedef typename ModelType::Pointer ModelPointerType; + typedef typename ModelType::RegionType RegionType; + + /** View typedefs */ + typedef TView ViewType; + typedef typename ViewType::Pointer ViewPointerType; + + /** Handle widget resizing + * \param widgetId The id of the resized widget + * \param x new x location + * \param y new y location + * \param w new width + * \param h new height + */ + virtual bool HandleWidgetResize(std::string widgetId, int w, int h) + { + if(m_Model.IsNotNull() && m_View.IsNotNull()) + { + // If resizing the scroll widget, nothing has to be done. + if(widgetId == m_View->GetScrollWidget()->GetIdentifier() ) + { + // Nothing has to be acted to the model, juste update the view + m_View->Update(); + return true; + } + else if(widgetId == m_View->GetFullWidget()->GetIdentifier() ) + { + // Enlarge the model extract region + RegionType region = m_Model->GetExtractRegion(); + typename RegionType::SizeType size = region.GetSize(); + size[0] = static_cast<unsigned int>(w); + size[1] = static_cast<unsigned int>(h); + region.SetSize(size); + m_Model->SetExtractRegion(region); + // Update the model + m_Model->Update(); + return true; + } + else if(widgetId ==m_View->GetZoomWidget()->GetIdentifier() ) + { + // Enlarge the model scaled extract region + RegionType region = m_Model->GetScaledExtractRegion(); + typename RegionType::SizeType size = region.GetSize(); + size[0] = static_cast<unsigned int>(static_cast<double>(w)/m_View->GetZoomWidget()->GetIsotropicZoom()); + size[1] = static_cast<unsigned int>(static_cast<double>(h)/m_View->GetZoomWidget()->GetIsotropicZoom()); + region.SetSize(size); + m_Model->SetScaledExtractRegion(region); + // Update the model + m_Model->Update(); + return true; + } + } + return false; + } + + /** Set/Get the pointer to the view */ + itkSetObjectMacro(View,ViewType); + itkGetObjectMacro(View,ViewType); + + /** Set/Get the pointer to the model */ + itkSetObjectMacro(Model,ModelType); + itkGetObjectMacro(Model,ModelType); + +protected: + /** Constructor */ + WidgetResizingActionHandler() : m_View(), m_Model() + {} + + /** Destructor */ + virtual ~WidgetResizingActionHandler(){} + /** Printself method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + } + +private: + WidgetResizingActionHandler(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/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx b/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx index 328f1219e81a243d91c8de39ad3ec3c8bcf6f902..67fb52c99ff000f8433165a0c5e14d2d63a64548 100644 --- a/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx +++ b/Examples/FeatureExtraction/LineSegmentDetectorExample.cxx @@ -48,7 +48,7 @@ int main( int argc, char * argv[] ) const char * outfname = argv[2]; typedef unsigned char InputPixelType; - typedef unsigned char PrecisionType; + typedef double PrecisionType; const unsigned int Dimension = 2; diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index 9e50512b6c60317544a82ca231cf101c18be2356..cbb5b9a68c1251d81a2df8fd12dad9fe8f58a4e6 100644 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -1025,7 +1025,7 @@ ADD_TEST(bfTvEdgeDensityImageFilter ${BASICFILTERS_TESTS9} otbEdgeDensityImageFilter ${INPUTDATA}/scene.png ${TEMP}/bfTvEdgeDensityImageFilterOutputImage.tif - 2 # radius + 1 # radius 15 3 1. 0.01 #Canny Parameters ) diff --git a/Testing/Code/BasicFilters/otbEdgeDensityImageFilter.cxx b/Testing/Code/BasicFilters/otbEdgeDensityImageFilter.cxx index c2e6d56323279901d0a1a8284afc32fcb763b2ef..05189e887ed4c7e5dfc6c1f827e43467d0e85270 100644 --- a/Testing/Code/BasicFilters/otbEdgeDensityImageFilter.cxx +++ b/Testing/Code/BasicFilters/otbEdgeDensityImageFilter.cxx @@ -68,6 +68,7 @@ int otbEdgeDensityImageFilter(int argc, char* argv[] ) CannyFilter->SetMaximumError(maximumError); ///0.01f filter->SetDetector(CannyFilter); + filter->SetNeighborhoodRadius(radius); /** Write the output*/ WriterType::Pointer writer = WriterType::New(); diff --git a/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilterNew.cxx b/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilterNew.cxx index a08cc620f5e2df02dc9c6e643a1b9b8b68130c5c..c59bf4b968aa5e75a536ea725c9784b990435a71 100644 --- a/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilterNew.cxx +++ b/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilterNew.cxx @@ -18,13 +18,14 @@ #include "itkExceptionObject.h" #include "itkNeighborhood.h" #include "otbImage.h" -#include "itkVariableLengthVector.h" -#include "itkConstNeighborhoodIterator.h" +//#include "itkVariableLengthVector.h" +//#include "itkConstNeighborhoodIterator.h" #include "otbTextureImageFunction.h" #include "otbFunctionWithNeighborhoodToImageFilter.h" -#include "otbTextureFunctorBase.h" +#include "itkOffset.h" +//#include "otbTextureFunctorBase.h" -template <class TIterInput1, class TIterInput2, class TOutput> +template <class TInputScalarType, class TOutputScalarType>//IterInput1, class TIterInput2, class TOutput> class TextureFunctorTest { public: @@ -34,26 +35,16 @@ public: }; ~TextureFunctorTest() {}; - typedef TIterInput1 IterType1; - typedef TIterInput2 IterType2; - typedef TOutput OutputType; - typedef typename IterType1::OffsetType OffsetType; - typedef typename IterType1::InternalPixelType InternalPixelType; - typedef typename IterType1::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType, ::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; - + typedef itk::Offset<> OffsetType; + typedef itk::Neighborhood<TInputScalarType, 2> NeighborhoodType; + void SetOffset(OffsetType off){ m_Offset=off; }; - inline TOutput operator()(const IterType1 &it, const IterType2 &itOff) + inline TOutputScalarType operator()(const NeighborhoodType &neigh) { - return static_cast<OutputType>(it.GetCenterPixel()[0]); + return static_cast<TOutputScalarType>(neigh.GetCenterValue()); } - double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) - { - return 0.; - } - private: OffsetType m_Offset; }; @@ -67,7 +58,7 @@ int otbFunctionWithNeighborhoodToImageFilterNew(int argc, char * argv[]) typedef itk::VariableLengthVector<double> VectorType; typedef itk::ConstNeighborhoodIterator<ImageType> IteratorType; - typedef TextureFunctorTest<IteratorType, IteratorType, VectorType> FunctorType; + typedef TextureFunctorTest<PixelType, PixelType> FunctorType; typedef otb::TextureImageFunction<ImageType, FunctorType> FunctionType; typedef otb::FunctionWithNeighborhoodToImageFilter<ImageType, ImageType, FunctionType> FilterType; diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index bf9ff241b308599735f8558fe311533b5b457418..5ba7d3fd9ded9d551235b5d1d1f3d4745d638fc4 100644 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -5,6 +5,11 @@ SET(BASELINE_FILES ${OTB_DATA_ROOT}/Baseline/OTB/Files) SET(INPUTDATA ${OTB_DATA_ROOT}/Input) SET(TEMP ${OTBTesting_BINARY_DIR}/Temporary) +#Remote sensing images (large images ) +IF(OTB_DATA_USE_LARGEINPUT) + SET(LARGEDATA ${OTB_DATA_LARGEINPUT_ROOT} ) +ENDIF(OTB_DATA_USE_LARGEINPUT) + #Tolerance sur diff pixel image SET(TOL 0.0) @@ -126,6 +131,21 @@ ADD_TEST(coTvExtractROI_RGB2 ${COMMON_TESTS2} ADD_TEST(coTuVectorDataExtractROINew ${COMMON_TESTS2} otbVectorDataExtractROINew) +IF(OTB_DATA_USE_LARGEINPUT) + +ADD_TEST(coTvVectorDataExtractROI ${COMMON_TESTS2} +# --compare-image ${TOL} +# ${BASELINE}/coVectorDataExtractROIOutput.shp +# ${TEMP}/coVectorDataExtractROIOutput.shp + otbVectorDataExtractROI + ${LARGEDATA}/TOULOUSE/QuickBird/GIS_FILES/000000128955_01_ORDER_SHAPE.shp + ${TEMP}/coVectorDataExtractROIOutput.shp + 10 10 50 50 + ) + +ENDIF(OTB_DATA_USE_LARGEINPUT) + + # ------- otb::MultiChannelExtractROI ------------------------------ @@ -587,6 +607,7 @@ otbMultiChannelExtractROI.cxx otbMultiChannelExtractROINew.cxx otbTestMultiExtractMultiUpdate.cxx otbVectorDataExtractROINew.cxx +otbVectorDataExtractROI.cxx ) SET(BasicCommon_SRCS3 otbMultiToMonoChannelExtractROI.cxx diff --git a/Testing/Code/Common/otbCommonTests2.cxx b/Testing/Code/Common/otbCommonTests2.cxx index 40c9d401861ee733c81a7a98e78205de117d2cf2..808364dae8bf8a0c2613ab4aef4ef14ce0ae5b01 100644 --- a/Testing/Code/Common/otbCommonTests2.cxx +++ b/Testing/Code/Common/otbCommonTests2.cxx @@ -35,4 +35,5 @@ void RegisterTests() REGISTER_TEST(otbMultiChannelExtractROINew ); REGISTER_TEST(otbTestMultiExtractMultiUpdate); REGISTER_TEST(otbVectorDataExtractROINew); + REGISTER_TEST(otbVectorDataExtractROI); } diff --git a/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.cxx b/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.cxx index ab7bc454c8a3a76b3c488984abb11f80afb24b9a..2f811e0cba52b89a179b576dedb5c0fe9720ce9f 100644 --- a/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.cxx +++ b/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.cxx @@ -25,15 +25,20 @@ namespace Functor { -template <class TIter, class TOutput> +template <class TInput, class TOutput> class UnaryFunctorNeighborhoodWithOffseImageFilterTest { public: UnaryFunctorNeighborhoodWithOffseImageFilterTest() {}; ~UnaryFunctorNeighborhoodWithOffseImageFilterTest() {}; - typedef TIter IterType; - typedef typename IterType::OffsetType OffsetType; + typedef TInput InputScalarType; + typedef TOutput OutputScalarType; + typedef itk::VariableLengthVector<InputScalarType> InputVectorType; + typedef itk::VariableLengthVector<OutputScalarType> OutputVectorType; + typedef itk::Offset<> OffsetType; + typedef itk::Neighborhood<InputScalarType, 2> NeighborhoodType; + typedef itk::Neighborhood<InputVectorType, 2> NeighborhoodVectorType; void SetOffset(OffsetType off) { @@ -44,9 +49,13 @@ public: return m_Offset; }; - inline TOutput operator() (const TIter & it) + inline OutputScalarType operator() (const NeighborhoodType & neigh) { - return(static_cast<TOutput>(it.GetCenterPixel())); + return(static_cast<OutputScalarType>(neigh.GetCenterValue())); + } + inline OutputVectorType operator() (const NeighborhoodVectorType & neigh) + { + return(static_cast<OutputVectorType>(neigh.GetCenterValue())); } private: @@ -68,7 +77,7 @@ int otbUnaryFunctorNeighborhoodWithOffsetImageFilter(int argc, char * argv[]) typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; - typedef Functor::UnaryFunctorNeighborhoodWithOffseImageFilterTest<IterType, PixelType> FunctorType; + typedef Functor::UnaryFunctorNeighborhoodWithOffseImageFilterTest<InputPixelType, InputPixelType> FunctorType; typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodImageFilterType; // Instantiating object diff --git a/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilterNew.cxx b/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilterNew.cxx index 930bd2cf0ef7203a91ea880bced15aedea1b2288..52e3a337dcaefc602d58dc65a5a9af623a283214 100644 --- a/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilterNew.cxx +++ b/Testing/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilterNew.cxx @@ -20,18 +20,24 @@ #include "otbUnaryFunctorNeighborhoodWithOffsetImageFilter.h" #include "otbVectorImage.h" #include "itkConstNeighborhoodIterator.h" +#include "itkOffset.h" namespace Functor { -template <class TIter, class TOutput> +template <class TInput, class TOutput> class UnaryFunctorNeighborhoodWithOffsetImageFilterFunctorNewTest { public: UnaryFunctorNeighborhoodWithOffsetImageFilterFunctorNewTest() {}; ~UnaryFunctorNeighborhoodWithOffsetImageFilterFunctorNewTest() {}; - typedef TIter IterType; - typedef typename IterType::OffsetType OffsetType; + typedef TInput InputScalarType; + typedef TOutput OutputScalarType; + typedef itk::VariableLengthVector<InputScalarType> InputVectorType; + typedef itk::VariableLengthVector<OutputScalarType> OutputVectorType; + typedef itk::Offset<> OffsetType; + typedef itk::Neighborhood<InputScalarType, 2> NeighborhoodType; + typedef itk::Neighborhood<InputVectorType, 2> NeighborhoodVectorType; void SetOffset(OffsetType off) { @@ -42,11 +48,16 @@ public: return m_Offset; }; - inline TOutput operator() (const TIter & it) + inline OutputScalarType operator() (const NeighborhoodType & neigh) { - return(static_cast<TOutput>(it.GetCenterPixel())); + return(static_cast<OutputScalarType>(neigh.GetCenterValue())); + } + inline OutputVectorType operator() (const NeighborhoodVectorType & neigh) + { + return(static_cast<OutputVectorType>(neigh.GetCenterValue())); } + private: OffsetType m_Offset; }; @@ -60,7 +71,7 @@ int otbUnaryFunctorNeighborhoodWithOffsetImageFilterNew(int argc, char * argv[]) typedef otb::VectorImage<InputPixelType,Dimension> ImageType; typedef ImageType::PixelType PixelType; typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; - typedef Functor::UnaryFunctorNeighborhoodWithOffsetImageFilterFunctorNewTest<IterType, PixelType> FunctorType; + typedef Functor::UnaryFunctorNeighborhoodWithOffsetImageFilterFunctorNewTest<InputPixelType, InputPixelType> FunctorType; typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodWithOffsetImageFilterType; // Instantiating object diff --git a/Testing/Code/Common/otbVectorDataExtractROI.cxx b/Testing/Code/Common/otbVectorDataExtractROI.cxx index 431cb4494ffbe209e1ec2e6365597c28a7e20bf5..b646a04193745d163ac1f3192ca49a8539ed760e 100644 --- a/Testing/Code/Common/otbVectorDataExtractROI.cxx +++ b/Testing/Code/Common/otbVectorDataExtractROI.cxx @@ -20,15 +20,34 @@ #include "otbVectorDataFileReader.h" -int otbVectorDataExtractROINew( int argc, char * argv[] ) +int otbVectorDataExtractROI( int argc, char * argv[] ) { + const char * infname = argv[1]; + + const unsigned int startX = atoi(argv[3]); + const unsigned int startY = atoi(argv[4]); + const unsigned int sizeX = atoi(argv[5]); + const unsigned int sizeY = atoi(argv[6]); + typedef otb::VectorData<> VectorDataType; typedef otb::VectorDataExtractROI< VectorDataType > FilterType; typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; - + /** */ FilterType::Pointer filter = FilterType::New(); + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + + /** */ + reader->SetFileName(infname); + + filter->SetInput(reader->GetOutput()); + filter->SetSizeX(sizeX); + filter->SetSizeY(sizeY); + filter->SetStartX(startX); + filter->SetStartY(startY); + filter->Update(); + return EXIT_SUCCESS; } diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx index 50b5c649c0151e8b171ad2a8a0cd57e29935d592..6d01df7f1ee9bc478b5135c59d026e8d7eeb2ecc 100644 --- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx +++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx @@ -43,6 +43,6 @@ int otbPanTexTextureImageFilter(int argc, char * argv[]) writer->SetInput( panTex->GetOutput() ); writer->Update(); - + return EXIT_SUCCESS; } diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx index 9511c798fa2713bba8607dc183afa278d5e13574..46389035a5ba5aff7cef5387b648a3266fc89a33 100644 --- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx +++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx @@ -29,7 +29,6 @@ int otbPanTexTextureImageFilterNew(int argc, char * argv[]) // Instantiating object PanTexType::Pointer object = PanTexType::New(); - - + return EXIT_SUCCESS; } diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx index 78e1bf5f6e35992c678dda0040ed837b6861890d..a732b61dedbb7d506027cef8509df0106c7dbe30 100644 --- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx +++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx @@ -43,6 +43,6 @@ int otbPanTexTextureImageFunctionFilter(int argc, char * argv[]) writer->SetInput( panTex->GetOutput() ); writer->Update(); - + return EXIT_SUCCESS; } diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx index 0a99f2d9039acd0e693d2a7b36b0e339939afee8..1fe47450eb9fb1d3b83adcd610aef4b2e7dab807 100644 --- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx +++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx @@ -29,7 +29,6 @@ int otbPanTexTextureImageFunctionFilterNew(int argc, char * argv[]) // Instantiating object PanTexType::Pointer object = PanTexType::New(); - - + return EXIT_SUCCESS; } diff --git a/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx b/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx index 9fe9feeed77776db9995a906675f17a37ca26980..acb29fac2cbdf8e9e947d0bafe108554d62109fe 100644 --- a/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx +++ b/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx @@ -70,90 +70,90 @@ int otbTextureFunctor(int argc, char * argv[]) typedef otb::VectorImage<InputPixelType,Dimension> ImageType; typedef ImageType::PixelType PixelType; typedef itk::ConstNeighborhoodIterator<ImageType> IteratorType; - + if(strArgv == "ENJ") { - typedef otb::Functor::EnergyTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::EnergyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "ENT" ) { - typedef otb::Functor::EntropyTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::EntropyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "IMD" ) { - typedef otb::Functor::InverseDifferenceMomentTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::InverseDifferenceMomentTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } - else if ( strArgv == "ASM" ) + else if ( strArgv == "ASM" ) { - typedef otb::Functor::AngularSecondMomentumTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::AngularSecondMomentumTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } - else if ( strArgv == "VAR" ) + else if ( strArgv == "VAR" ) { - typedef otb::Functor::VarianceTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::VarianceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "COR" ) { - typedef otb::Functor::CorrelationTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::CorrelationTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "CON" ) { - typedef otb::Functor::ContrastTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::ContrastTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "SAV" ) { - typedef otb::Functor::SumAverageTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::SumAverageTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "DEN" ) { - typedef otb::Functor::DifferenceEntropyTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::DifferenceEntropyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "SEN" ) { - typedef otb::Functor::SumEntropyTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::SumEntropyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "SVA" ) { - typedef otb::Functor::SumVarianceTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::SumVarianceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "DVA" ) { - typedef otb::Functor::DifferenceVarianceTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::DifferenceVarianceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "IC1" ) { - typedef otb::Functor::InformationMeasureOfCorrelation1TextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::InformationMeasureOfCorrelation1TextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "IC2" ) { - typedef otb::Functor::InformationMeasureOfCorrelation2TextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::InformationMeasureOfCorrelation2TextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "CSH" ) { - typedef otb::Functor::ClusterShadeTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::ClusterShadeTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "CPR" ) { - typedef otb::Functor::ClusterProminenceTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::ClusterProminenceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "MEA" ) { - typedef otb::Functor::MeanTextureFunctor<IteratorType, PixelType> FunctorType; + typedef otb::Functor::MeanTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); } else @@ -161,5 +161,6 @@ int otbTextureFunctor(int argc, char * argv[]) return EXIT_FAILURE; } + return EXIT_SUCCESS; } diff --git a/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx b/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx index 44e139e3da2c63fa9c27b5131e5c7f8edfd7c642..ff6e103ff4851d6f73dc268741e2e9b0c0fa6422 100644 --- a/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx +++ b/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx @@ -25,28 +25,22 @@ #include "otbTextureFunctorBase.h" -template <class TIterInput, class TOutput> +template <class TScalarInput, class TScalarOutput> class ITK_EXPORT TextureFunctorTest : -public otb::Functor::TextureFunctorBase<TIterInput, TOutput> +public otb::Functor::TextureFunctorBase<TScalarInput, TScalarOutput> { public: TextureFunctorTest() {}; ~TextureFunctorTest(){}; - typedef TIterInput IterType; - typedef TOutput OutputType; - typedef typename IterType::OffsetType OffsetType; - typedef typename IterType::RadiusType RadiusType; - typedef typename IterType::InternalPixelType InternalPixelType; - typedef typename IterType::ImageType ImageType; - typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; + typedef itk::Neighborhood<TScalarInput, 2> NeighborhoodType; virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { double out = neigh.GetCenterValue(); - return out; + return out; } }; @@ -65,7 +59,7 @@ int otbTextureFunctorBase(int argc, char * argv[]) typedef otb::ImageFileWriter<ImageType> WriterType; typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; - typedef TextureFunctorTest<IterType, PixelType> FunctorType; + typedef TextureFunctorTest<InputPixelType, InputPixelType> FunctorType; typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodImageFilterType; // Instantiating object diff --git a/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx b/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx index 3525d085f80b4d74f571256b7ad0bd812d823d0c..0540c5eb7cff4814b7000672387624f91a928dc9 100644 --- a/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx +++ b/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx @@ -41,8 +41,6 @@ int generic_TextureImageFunction(int argc, char * argv[]) typedef otb::TextureImageFunction<TInputImage, TFunctor> FunctionType; typedef otb::FunctionWithNeighborhoodToImageFilter<TInputImage, TOutputImage, FunctionType> FilterType; - //typename FunctionType::Pointer energyFunction = FunctionType::New(); - //typename FunctionType energyFunction; typename FilterType::Pointer filter = FilterType::New(); // Instantiating object @@ -52,7 +50,6 @@ int generic_TextureImageFunction(int argc, char * argv[]) writer->SetFileName(outputFileName); filter->SetInput(reader->GetOutput()); - //filter->SetFunction(energyFunction); SizeType radius; radius[0] = atoi(argv[3]); radius[1] = atoi(argv[4]); @@ -83,90 +80,90 @@ int otbTextureImageFunction(int argc, char * argv[]) typedef itk::VariableLengthVector<double> VectorType; typedef itk::ConstNeighborhoodIterator<ImageType> IteratorType; - + if(strArgv == "ENJ") { - typedef otb::Functor::EnergyTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::EnergyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "ENT" ) { - typedef otb::Functor::EntropyTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::EntropyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "IMD" ) { - typedef otb::Functor::InverseDifferenceMomentTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::InverseDifferenceMomentTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } - else if ( strArgv == "ASM" ) + else if ( strArgv == "ASM" ) { - typedef otb::Functor::AngularSecondMomentumTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::AngularSecondMomentumTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } - else if ( strArgv == "VAR" ) + else if ( strArgv == "VAR" ) { - typedef otb::Functor::VarianceTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::VarianceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "COR" ) { - typedef otb::Functor::CorrelationTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::CorrelationTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "CON" ) { - typedef otb::Functor::ContrastTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::ContrastTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "SAV" ) { - typedef otb::Functor::SumAverageTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::SumAverageTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "DEN" ) { - typedef otb::Functor::DifferenceEntropyTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::DifferenceEntropyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "SEN" ) { - typedef otb::Functor::SumEntropyTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::SumEntropyTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "SVA" ) { - typedef otb::Functor::SumVarianceTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::SumVarianceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "DVA" ) { - typedef otb::Functor::DifferenceVarianceTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::DifferenceVarianceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "IC1" ) { - typedef otb::Functor::InformationMeasureOfCorrelation1TextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::InformationMeasureOfCorrelation1TextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "IC2" ) { - typedef otb::Functor::InformationMeasureOfCorrelation2TextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::InformationMeasureOfCorrelation2TextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "CSH" ) { - typedef otb::Functor::ClusterShadeTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::ClusterShadeTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "CPR" ) { - typedef otb::Functor::ClusterProminenceTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::ClusterProminenceTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else if ( strArgv == "MEA" ) { - typedef otb::Functor::MeanTextureFunctor<IteratorType, VectorType> FunctorType; + typedef otb::Functor::MeanTextureFunctor<InputPixelType, InputPixelType> FunctorType; return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); } else diff --git a/Testing/Code/VisuRefac/CMakeLists.txt b/Testing/Code/VisuRefac/CMakeLists.txt index fe3c6a3509c8247b55609ff38d0cbcac7fb18a8a..9726e97846e340857018575c8704751ed746274a 100644 --- a/Testing/Code/VisuRefac/CMakeLists.txt +++ b/Testing/Code/VisuRefac/CMakeLists.txt @@ -194,6 +194,17 @@ otbImageLayerGeneratorVector ${INPUTDATA}/couleurs.tif 1 ) +#------------ otb::ImageView ------------ +ADD_TEST(vrTuImageViewNew ${VISUREFAC_TESTS1} +otbImageViewNew +) + +ADD_TEST(vrTvImageViewerEndToEndSingleLayer ${VISUREFAC_TESTS1} +otbImageViewerEndToEndSingleLayer +${INPUTDATA}/couleurs.tif +200 500 200 +) + # Testing srcs SET(VisuRefac_SRCS1 @@ -219,6 +230,8 @@ otbImageLayerGeneratorScalar.cxx otbImageLayerGeneratorVector.cxx otbMultiplyBlendingFunctionNew.cxx otbRenderingImageFilterVectorWithExpNegativeTransfer.cxx +otbImageViewNew.cxx +otbImageViewerEndToEndSingleLayer.cxx ) # Building testing executables diff --git a/Testing/Code/VisuRefac/otbImageViewNew.cxx b/Testing/Code/VisuRefac/otbImageViewNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f3a0374f4eeefb9b3b3e263360f9794ad00e5971 --- /dev/null +++ b/Testing/Code/VisuRefac/otbImageViewNew.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 "otbImageViewerModel.h" +#include "otbImage.h" +#include "itkRGBPixel.h" +#include "otbImageView.h" + +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::ImageView<ModelType> ViewType; + + // Instantiation + ViewType::Pointer model = ViewType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/VisuRefac/otbImageViewerEndToEndSingleLayer.cxx b/Testing/Code/VisuRefac/otbImageViewerEndToEndSingleLayer.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b5e29ec5592869c85069ad26eadaf0d42a5fad92 --- /dev/null +++ b/Testing/Code/VisuRefac/otbImageViewerEndToEndSingleLayer.cxx @@ -0,0 +1,105 @@ +/*========================================================================= + +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 "otbImageViewerModel.h" +#include "otbVectorImage.h" +#include "itkRGBPixel.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbImageLayerGenerator.h" +#include "otbImageLayer.h" +#include "otbImageView.h" +#include <FL/Fl.H> +#include "otbImageWidgetController.h" +#include "otbWidgetResizingActionHandler.h" +#include "otbChangeScaledExtractRegionActionHandler.h" + +int otbImageViewerEndToEndSingleLayer( int argc, char * argv[] ) +{ + // params + const char * infname = argv[1]; + const unsigned int scrollSize = atoi(argv[2]); + const unsigned int fullSize = atoi(argv[3]); + const unsigned int zoomSize = atoi(argv[4]); + + + // typedefs + typedef itk::RGBPixel<unsigned char> RGBPixelType; + typedef otb::Image<RGBPixelType,2> OutputImageType; + typedef otb::VectorImage<double,2> ImageType; + typedef otb::ImageLayer<ImageType> LayerType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::ImageLayerGenerator<LayerType> LayerGeneratorType; + typedef otb::ImageViewerModel<OutputImageType> ModelType; + typedef otb::ImageView<ModelType> ViewType; + typedef otb::ImageWidgetController ControllerType; + typedef otb::WidgetResizingActionHandler + <ModelType,ViewType> ResizingHandlerType; + typedef otb::ChangeScaledExtractRegionActionHandler + <ModelType,ViewType> ChangeScaledRegionHandlerType; + + // 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()); + + // Build a view + ViewType::Pointer view = ViewType::New(); + view->SetModel(model); + + // Build a controller + ControllerType::Pointer controller = ControllerType::New(); + view->SetController(controller); + + // Add the resizing handler + ResizingHandlerType::Pointer resizingHandler = ResizingHandlerType::New(); + resizingHandler->SetModel(model); + resizingHandler->SetView(view); + controller->AddActionHandler(resizingHandler); + +// Add the change scaled region handler + ChangeScaledRegionHandlerType::Pointer changeScaledHandler =ChangeScaledRegionHandlerType::New(); + changeScaledHandler->SetModel(model); + changeScaledHandler->SetView(view); + controller->AddActionHandler(changeScaledHandler); + + view->GetScrollWidget()->show(); + view->GetScrollWidget()->resize(fullSize,0,scrollSize,scrollSize); + Fl::check(); + + view->GetFullWidget()->show(); + view->GetFullWidget()->resize(0,0,fullSize,fullSize); + + Fl::check(); + + view->GetZoomWidget()->show(); + view->GetZoomWidget()->resize(fullSize,scrollSize,zoomSize,zoomSize); + + Fl::check(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/VisuRefac/otbImageWidgetController.cxx b/Testing/Code/VisuRefac/otbImageWidgetController.cxx index 7d33fcc1773d5c1f0acfe79f232b5e688b5638b2..02b8e50269e231500660aae917e070d3f1992525 100644 --- a/Testing/Code/VisuRefac/otbImageWidgetController.cxx +++ b/Testing/Code/VisuRefac/otbImageWidgetController.cxx @@ -47,7 +47,10 @@ int otbImageWidgetController( int argc, char * argv[] ) controller->HandleWidgetEvent("default",10); // Simulate a resize from a widget - controller->HandleWidgetResize("default",0,0,0,0); + controller->HandleWidgetResize("default",0,0); + + // Simulate a move from a widget + controller->HandleWidgetMove("default",0,0); return EXIT_SUCCESS; } diff --git a/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx b/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx index f7173bcf410c6d2a739bf3d97a08a6193ef76a5c..67dffe0996c97309cdecd05f0e9ea9eeb296d298 100644 --- a/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx +++ b/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx @@ -48,4 +48,6 @@ void RegisterTests() REGISTER_TEST(otbImageLayerGeneratorScalar); REGISTER_TEST(otbImageLayerGeneratorVector); REGISTER_TEST(otbMultiplyBlendingFunctionNew); + REGISTER_TEST(otbImageViewNew); + REGISTER_TEST(otbImageViewerEndToEndSingleLayer); } diff --git a/Testing/Fa/CMakeLists.txt b/Testing/Fa/CMakeLists.txt index 22f384169a350c8d4ca7958d8c0a2b18dd4a4287..7ebeeda088b510129f2fe7999c8f2f1516bf20d3 100644 --- a/Testing/Fa/CMakeLists.txt +++ b/Testing/Fa/CMakeLists.txt @@ -216,7 +216,7 @@ ADD_TEST(FA-0000041-mean_shift2 ${CXX_TEST_PATH}/0000041-mean_shift ) # ------- Vectorization issue ----------------------------------- -ADD_TEST(PolygonsVectorization ${CXX_TEST_PATH}/PolygonsVectorization +ADD_TEST(FA-0000094-fe-PolygonsVectorization ${CXX_TEST_PATH}/PolygonsVectorization -in ${INPUTDATA}/objtest2.tif -ot ${TEMP}/output.txt -out ${TEMP}/objtest2-result.tif