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
No related branches found
No related tags found
No related merge requests found
......@@ -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,9 +123,12 @@ 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);
......@@ -137,7 +141,16 @@ public:
/** 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 */
......@@ -146,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
......@@ -175,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
......
......@@ -27,7 +27,7 @@ template <class TOutputImage>
ImageViewerModel<TOutputImage>
::ImageViewerModel() : m_Name("Default"), m_Layers(), m_RasterizedQuicklook(),
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()
{
......@@ -159,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>
......@@ -216,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())
......@@ -229,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())
......@@ -287,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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment