Skip to content
Snippets Groups Projects
Commit a6415036 authored by Julien Michel's avatar Julien Michel
Browse files

ENH: (Visu Refactoring) Several enhancements in the Model part

parent 4a98e3fb
Branches
Tags
No related merge requests found
...@@ -62,6 +62,7 @@ public: ...@@ -62,6 +62,7 @@ public:
/** Layer typedef */ /** Layer typedef */
typedef otb::Layer<OutputImageType> LayerType; typedef otb::Layer<OutputImageType> LayerType;
typedef typename LayerType::RegionType RegionType; typedef typename LayerType::RegionType RegionType;
typedef typename RegionType::IndexType IndexType;
/** Layer list typedef */ /** Layer list typedef */
typedef otb::ObjectList<LayerType> LayerListType; typedef otb::ObjectList<LayerType> LayerListType;
...@@ -122,9 +123,12 @@ public: ...@@ -122,9 +123,12 @@ public:
itkGetObjectMacro(RasterizedExtract,OutputImageType); itkGetObjectMacro(RasterizedExtract,OutputImageType);
itkGetObjectMacro(RasterizedScaledExtract,OutputImageType); itkGetObjectMacro(RasterizedScaledExtract,OutputImageType);
/** Set/Get the Extract Region */ /** Set/Get the Extract Region */
itkSetMacro(ExtractRegion,RegionType); itkSetMacro(ExtractRegion,RegionType);
itkGetConstReferenceMacro(ExtractRegion,RegionType); itkGetConstReferenceMacro(ExtractRegion,RegionType);
/** Get the extract region in the quicklook space */
itkGetConstReferenceMacro(SubsampledExtractRegion,RegionType);
/** Set/Get the Scaled Extract Region */ /** Set/Get the Scaled Extract Region */
itkSetMacro(ScaledExtractRegion,RegionType); itkSetMacro(ScaledExtractRegion,RegionType);
...@@ -137,7 +141,16 @@ public: ...@@ -137,7 +141,16 @@ public:
/** Update will render all visible layers, rasterize all visible /** Update will render all visible layers, rasterize all visible
* layers and notify all listeners. */ * 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: protected:
/** Constructor */ /** Constructor */
...@@ -146,16 +159,19 @@ protected: ...@@ -146,16 +159,19 @@ protected:
~ImageViewerModel(); ~ImageViewerModel();
/** Printself method */ /** Printself method */
void PrintSelf(std::ostream& os, itk::Indent indent) const; void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** Renders all visible layers */ /** Renders all visible layers */
virtual void RenderVisibleLayers(void); void RenderVisibleLayers(void);
/** Rasterize visible layers */ /** Rasterize visible layers */
virtual void RasterizeVisibleLayers(void); void RasterizeVisibleLayers(void);
/** Notify a registered listener */ /** 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: private:
ImageViewerModel(const Self&); // purposely not implemented ImageViewerModel(const Self&); // purposely not implemented
...@@ -175,11 +191,15 @@ private: ...@@ -175,11 +191,15 @@ private:
OutputImagePointerType m_RasterizedExtract; OutputImagePointerType m_RasterizedExtract;
bool m_HasExtract; bool m_HasExtract;
RegionType m_ExtractRegion; RegionType m_ExtractRegion;
RegionType m_SubsampledExtractRegion;
/** Rendered scaled extract */ /** Rendered scaled extract */
OutputImagePointerType m_RasterizedScaledExtract; OutputImagePointerType m_RasterizedScaledExtract;
bool m_HasScaledExtract; bool m_HasScaledExtract;
RegionType m_ScaledExtractRegion; RegionType m_ScaledExtractRegion;
/** Wether the model is currently updating or not */
bool m_Updating;
}; // end class }; // end class
} // end namespace otb } // end namespace otb
......
...@@ -27,7 +27,7 @@ template <class TOutputImage> ...@@ -27,7 +27,7 @@ template <class TOutputImage>
ImageViewerModel<TOutputImage> ImageViewerModel<TOutputImage>
::ImageViewerModel() : m_Name("Default"), m_Layers(), m_RasterizedQuicklook(), ::ImageViewerModel() : m_Name("Default"), m_Layers(), m_RasterizedQuicklook(),
m_HasQuicklook(false),m_RasterizedExtract(),m_HasExtract(false), m_HasQuicklook(false),m_RasterizedExtract(),m_HasExtract(false),
m_ExtractRegion(), m_RasterizedScaledExtract(), m_HasScaledExtract(false), m_ExtractRegion(), m_SubsampledExtractRegion(), m_RasterizedScaledExtract(), m_HasScaledExtract(false),
m_ScaledExtractRegion() m_ScaledExtractRegion()
{ {
...@@ -159,12 +159,18 @@ void ...@@ -159,12 +159,18 @@ void
ImageViewerModel<TOutputImage> ImageViewerModel<TOutputImage>
::Update() ::Update()
{ {
// Render all visible layers // Multiple concurrent update guards
this->RenderVisibleLayers(); if(!m_Updating)
// Rasterize all visible layers {
this->RasterizeVisibleLayers(); m_Updating = true;
// Notify all listeners // Render all visible layers
this->NotifyAll(); this->RenderVisibleLayers();
// Rasterize all visible layers
this->RasterizeVisibleLayers();
// Notify all listeners
this->NotifyAll();
m_Updating = false;
}
} }
template <class TOutputImage> template <class TOutputImage>
...@@ -216,6 +222,17 @@ ImageViewerModel<TOutputImage> ...@@ -216,6 +222,17 @@ ImageViewerModel<TOutputImage>
{ {
m_HasQuicklook = true; m_HasQuicklook = true;
m_RasterizedQuicklook = baseLayer->GetRenderedQuicklook(); 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()) if(baseLayer->GetHasExtract())
...@@ -229,6 +246,9 @@ ImageViewerModel<TOutputImage> ...@@ -229,6 +246,9 @@ ImageViewerModel<TOutputImage>
m_HasScaledExtract = true; m_HasScaledExtract = true;
m_RasterizedScaledExtract = baseLayer->GetRenderedScaledExtract(); m_RasterizedScaledExtract = baseLayer->GetRenderedScaledExtract();
} }
// Move to the next layer
++it;
// Walk the remaining layers // Walk the remaining layers
while(it!=m_Layers->End()) while(it!=m_Layers->End())
...@@ -287,9 +307,82 @@ void ...@@ -287,9 +307,82 @@ void
ImageViewerModel<TOutputImage> ImageViewerModel<TOutputImage>
::Notify(ListenerType * listener) ::Notify(ListenerType * listener)
{ {
// Notify the listener
listener->ImageViewerNotify(); 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> template <class TOutputImage>
void void
ImageViewerModel<TOutputImage> ImageViewerModel<TOutputImage>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment