Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine Belvire
otb
Commits
6b6ddfcb
Commit
6b6ddfcb
authored
12 years ago
by
Otmane Lahlou
Browse files
Options
Downloads
Patches
Plain Diff
ENH: trial to focus the zoom on the position under cursor + key event handling
parent
97db447b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Common/mvdImageViewManipulator.cxx
+79
-7
79 additions, 7 deletions
Code/Common/mvdImageViewManipulator.cxx
Code/Common/mvdImageViewManipulator.h
+2
-0
2 additions, 0 deletions
Code/Common/mvdImageViewManipulator.h
with
81 additions
and
7 deletions
Code/Common/mvdImageViewManipulator.cxx
+
79
−
7
View file @
6b6ddfcb
...
...
@@ -99,13 +99,27 @@ ImageViewManipulator
m_MouseContext
.
dx
=
-
event
->
x
()
+
m_MouseContext
.
xMove
;
m_MouseContext
.
dy
=
-
event
->
y
()
+
m_MouseContext
.
yMove
;
// moveRegion
this
->
moveRegion
(
m_MouseContext
.
dx
,
m_MouseContext
.
dy
);
// Update the position of the first press to take into account the
// last drag
m_MouseContext
.
xMove
-=
m_MouseContext
.
dx
;
m_MouseContext
.
yMove
-=
m_MouseContext
.
dy
;
}
/******************************************************************************/
void
ImageViewManipulator
::
moveRegion
(
double
dx
,
double
dy
)
{
// Update the navigation context
ImageRegionType
&
currentRegion
=
m_NavigationContext
.
m_ViewportImageRegion
;
// Apply the offset to the (start) index of the stored region
ImageRegionType
::
OffsetType
offset
;
offset
[
0
]
=
m_MouseContext
.
dx
/
m_IsotropicZoom
;
offset
[
1
]
=
m_MouseContext
.
dy
/
m_IsotropicZoom
;
offset
[
0
]
=
dx
/
m_IsotropicZoom
;
offset
[
1
]
=
dy
/
m_IsotropicZoom
;
// Apply the offset to the (start) index of the stored region
IndexType
index
=
currentRegion
.
GetIndex
()
+
offset
;
...
...
@@ -113,11 +127,6 @@ ImageViewManipulator
// Constraint the region to the largestPossibleRegion
this
->
ConstrainRegion
(
currentRegion
,
m_NavigationContext
.
m_ModelImageRegion
);
// Update the position of the first press to take into account the
// last drag
m_MouseContext
.
xMove
-=
m_MouseContext
.
dx
;
m_MouseContext
.
yMove
-=
m_MouseContext
.
dy
;
}
/******************************************************************************/
...
...
@@ -167,10 +176,42 @@ ImageViewManipulator
double
scale
=
vcl_pow
(
scaleRatio
,
nbSteps
);
// store the position under the mouse cursor
m_MouseContext
.
x
=
event
->
x
();
m_MouseContext
.
y
=
event
->
y
();
// The viewPort Region must be adapted to this zoom ratio
ImageRegionType
&
currentRegion
=
m_NavigationContext
.
m_ViewportImageRegion
;
// center the region on the position under the cursor
IndexType
origin
=
currentRegion
.
GetIndex
();
double
centerX
=
origin
[
0
]
+
currentRegion
.
GetSize
()[
0
]
/
2
;
double
centerY
=
origin
[
1
]
+
currentRegion
.
GetSize
()[
1
]
/
2
;
// new center
double
newCenterX
=
m_MouseContext
.
x
*
scale
+
(
(
centerX
-
m_MouseContext
.
x
)
);
double
newCenterY
=
m_MouseContext
.
y
*
scale
+
(
(
centerY
-
m_MouseContext
.
y
)
);
// new index
IndexType
newIndex
;
newIndex
[
0
]
=
newCenterX
-
(
m_NavigationContext
.
m_ViewportImageRegion
.
GetSize
()[
0
]
/
2
)
;
newIndex
[
1
]
=
newCenterY
-
(
m_NavigationContext
.
m_ViewportImageRegion
.
GetSize
()[
1
]
/
2
)
;
currentRegion
.
SetIndex
(
newIndex
);
// Constraint this region to the LargestPossibleRegion
this
->
ConstrainRegion
(
currentRegion
,
m_NavigationContext
.
m_ModelImageRegion
);
// rescale the viewport region
this
->
Zoom
(
scale
);
}
// void
// ImageViewManipulator
// ::CenterRegion()
// {
// }
/******************************************************************************/
void
ImageViewManipulator
...
...
@@ -254,6 +295,37 @@ ImageViewManipulator
}
}
/******************************************************************************/
void
ImageViewManipulator
::
keyPressEvent
(
QKeyEvent
*
event
)
{
switch
(
event
->
key
())
{
case
Qt
::
Key_Minus
:
Zoom
(
0.8
);
break
;
case
Qt
::
Key_Plus
:
Zoom
(
1.25
);
break
;
case
Qt
::
Key_Left
:
moveRegion
(
-
10
,
0
);
break
;
case
Qt
::
Key_Right
:
moveRegion
(
10
,
0
);
break
;
case
Qt
::
Key_Up
:
moveRegion
(
0
,
10
);
break
;
case
Qt
::
Key_Down
:
moveRegion
(
0
,
-
10
);
break
;
default:
break
;
}
}
/*****************************************************************************/
/* SLOTS */
/*****************************************************************************/
...
...
This diff is collapsed.
Click to expand it.
Code/Common/mvdImageViewManipulator.h
+
2
−
0
View file @
6b6ddfcb
...
...
@@ -86,6 +86,7 @@ public:
void
mouseReleaseEvent
(
QMouseEvent
*
event
);
void
wheelEvent
(
QWheelEvent
*
event
);
void
resizeEvent
(
QResizeEvent
*
event
);
void
keyPressEvent
(
QKeyEvent
*
event
);
/** Methods to access to the context */
/**
...
...
@@ -195,6 +196,7 @@ private:
private
:
void
Zoom
(
const
double
scale
);
void
moveRegion
(
double
dx
,
double
dy
);
//
// Private attributes.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment