Commit afc8bfb5 authored by Otmane Lahlou's avatar Otmane Lahlou

ENH: resolve zoom bug for j2k images

parent 10d6d7a5
......@@ -220,7 +220,7 @@ GLImageWidget
ImageModelRenderer::RenderingContext context(
datasetModel->GetSelectedImageModel(),
region, isotropicZoom,
width(), height()
width(), height(), m_ImageViewManipulator->HasZoomChanged()
);
// use the model renderer to paint the requested region of the image.
......
......@@ -101,7 +101,9 @@ void ImageModelRenderer::paintGL( const RenderingContext& context )
if (!m_IsMoving)
{
// request the data for the current region
m_Buffer = viModel->RasterizeRegion(scaledRegion, context.m_IsotropicZoom);
m_Buffer = viModel->RasterizeRegion(scaledRegion,
context.m_IsotropicZoom,
context.m_ForceRefresh);
}
// current resolution
......
......@@ -75,12 +75,14 @@ public:
unsigned int width = 0,
unsigned int height = 0,
int dx = 0,
int dy = 0) :
int dy = 0,
bool refresh = true) :
m_AbstractImageModel( model ),
m_ImageRegion( region ),
m_IsotropicZoom( zoom ),
m_WidgetWidth(width),
m_WidgetHeight(height)
m_WidgetHeight(height),
m_ForceRefresh(refresh)
{
}
......@@ -89,6 +91,7 @@ public:
double m_IsotropicZoom;
unsigned int m_WidgetWidth;
unsigned int m_WidgetHeight;
bool m_ForceRefresh;
};
//
......
......@@ -51,7 +51,8 @@ ImageViewManipulator
QObject( parent ),
m_NavigationContext(),
m_MouseContext(),
m_IsotropicZoom(1)
m_IsotropicZoom(1),
m_PreviousIsotropicZoom(1.)
{
// TODO: Remove later because initialized in struct's default constructor and resizeEvent().
this->InitializeContext(1,1);
......@@ -95,6 +96,8 @@ void
ImageViewManipulator
::mouseMoveEvent( QMouseEvent * event)
{
m_PreviousIsotropicZoom = m_IsotropicZoom;
// Update the mouse context
m_MouseContext.dx = -event->x() + m_MouseContext.xMove;
m_MouseContext.dy = -event->y() + m_MouseContext.yMove;
......@@ -196,6 +199,8 @@ void
ImageViewManipulator
::Zoom(const double scale)
{
m_PreviousIsotropicZoom = m_IsotropicZoom;
// compute the new size
double sizeX = m_NavigationContext.m_SizeXBeforeConstrain / scale;
double sizeY = m_NavigationContext.m_SizeYBeforeConstrain / scale;
......
......@@ -108,6 +108,19 @@ public:
return m_IsotropicZoom;
}
inline
bool HasZoomChanged() const
{
bool res = false;
if (vcl_abs(m_IsotropicZoom - m_PreviousIsotropicZoom) > 0.00000001 )
{
res = true;
}
return res;
}
/*
const MouseContextType& GetMouseContextType() const
{
......@@ -121,6 +134,8 @@ public:
// set back the zoom to 1
m_IsotropicZoom = 1.;
m_PreviousIsotropicZoom = 1.;
// store the image largest region
m_NavigationContext.m_ModelImageRegion = largestRegion;
......@@ -217,6 +232,7 @@ private:
MouseContextType m_MouseContext;
double m_IsotropicZoom;
double m_PreviousIsotropicZoom;
//
// SLOTS.
......
......@@ -256,7 +256,7 @@ VectorImageModel
/*******************************************************************************/
unsigned char *
VectorImageModel
::RasterizeRegion( const ImageRegionType& region, const double zoomFactor)
::RasterizeRegion( const ImageRegionType& region, const double zoomFactor, bool refresh)
{
m_Region = region;
......@@ -271,7 +271,8 @@ VectorImageModel
// Don't do anything if the region did not changed
if ( m_PreviousRegion!=region ||
m_Settings.IsDirty() )
m_Settings.IsDirty() ||
refresh )
{
// check that the current and the previous region have some pixels in
// common
......@@ -281,7 +282,8 @@ VectorImageModel
// if the first time or no pixels in common , reload all
if ( res &&
m_PreviousRegion!=ImageRegionType() &&
!m_Settings.IsDirty() )
!m_Settings.IsDirty() &&
!refresh )
{
// Compute loaded region, and the four regions not loaded yet
// within the new requested region
......@@ -348,10 +350,11 @@ VectorImageModel
// rasterize the region
this->DumpImagePixelsWithinRegionIntoBuffer(region);
}
m_Settings.ClearDirty();
}
// settings changes have been taken into account, clean the dirty flag
m_Settings.ClearDirty();
// Store the region
m_PreviousRegion = region;
......
......@@ -282,7 +282,9 @@ public:
void LoadFile( const QString& filename, int w, int h );
/** Rasterize the buffered region in a buffer */
unsigned char * RasterizeRegion(const ImageRegionType& region, const double zoomFactor);
unsigned char * RasterizeRegion(const ImageRegionType& region,
const double zoomFactor,
bool refresh);
/**
* Following the zoom factor, get the best level of detail knowing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment