Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ImageINSA_Tanguy
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Tanguy.Raufflet
ImageINSA_Tanguy
Commits
caba9c9d
Commit
caba9c9d
authored
12 years ago
by
Sacha Percot-Tétu
Browse files
Options
Downloads
Patches
Plain Diff
Added the Rotation operation
parent
e5a0f652
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/Operations/RotateOp.cpp
+154
-0
154 additions, 0 deletions
app/Operations/RotateOp.cpp
app/Operations/RotateOp.h
+48
-0
48 additions, 0 deletions
app/Operations/RotateOp.h
with
202 additions
and
0 deletions
app/Operations/RotateOp.cpp
0 → 100644
+
154
−
0
View file @
caba9c9d
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EIImage is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<QDialogButtonBox>
#include
<QFormLayout>
#include
<QDialog>
#include
<QSpinBox>
#include
<QCheckBox>
#include
"ImgWidget.h"
#include
"RotateOp.h"
using
namespace
std
;
using
namespace
imagein
;
RotateOp
::
RotateOp
()
:
Operation
(
"Rotation"
)
{
}
bool
RotateOp
::
needCurrentImg
()
{
return
true
;
}
struct
Point
{
int
x
;
int
y
;
Point
(
int
x_
=
0
,
int
y_
=
0
)
:
x
(
x_
),
y
(
y_
)
{}
};
inline
Point
rotatePoint
(
Point
toRotate
,
double
sin
,
double
cos
)
{
Point
returnval
;
returnval
.
x
=
((
double
)
toRotate
.
x
)
*
cos
+
((
double
)
toRotate
.
y
)
*
sin
;
returnval
.
y
=
((
double
)
toRotate
.
y
)
*
cos
-
((
double
)
toRotate
.
x
)
*
sin
;
return
returnval
;
}
std
::
vector
<
QWidget
*>
RotateOp
::
operator
()(
const
Image
*
img
,
const
map
<
const
Image
*
,
string
>&
imgList
)
{
vector
<
QWidget
*>
result
;
QString
imgName
(
imgList
.
find
(
img
)
->
second
.
c_str
());
QDialog
*
dialog
=
new
QDialog
();
dialog
->
setWindowTitle
(
QString
(
dialog
->
tr
(
"Rotating %1"
)).
arg
(
imgName
));
dialog
->
setMinimumWidth
(
180
);
QFormLayout
*
layout
=
new
QFormLayout
();
dialog
->
setLayout
(
layout
);
layout
->
setSizeConstraint
(
QLayout
::
SetFixedSize
);
QDoubleSpinBox
*
angleSpinBox
=
new
QDoubleSpinBox
(
dialog
);
QCheckBox
*
expandBox
=
new
QCheckBox
(
"Expand image"
,
dialog
);
QSpinBox
*
valueSpinBox
=
new
QSpinBox
(
dialog
);
angleSpinBox
->
setRange
(
-
180
,
180
);
angleSpinBox
->
setWrapping
(
true
);
angleSpinBox
->
setSingleStep
(
45
);
valueSpinBox
->
setRange
(
0
,
255
);
valueSpinBox
->
setValue
(
0
);
layout
->
insertRow
(
0
,
"Rotation angle : "
,
angleSpinBox
);
layout
->
insertRow
(
1
,
expandBox
);
layout
->
insertRow
(
2
,
"Fill value : "
,
valueSpinBox
);
QDialogButtonBox
*
buttonBox
=
new
QDialogButtonBox
(
QDialogButtonBox
::
Ok
|
QDialogButtonBox
::
Cancel
,
Qt
::
Horizontal
,
dialog
);
layout
->
insertRow
(
3
,
buttonBox
);
QObject
::
connect
(
buttonBox
,
SIGNAL
(
accepted
()),
dialog
,
SLOT
(
accept
()));
QObject
::
connect
(
buttonBox
,
SIGNAL
(
rejected
()),
dialog
,
SLOT
(
reject
()));
QDialog
::
DialogCode
code
=
static_cast
<
QDialog
::
DialogCode
>
(
dialog
->
exec
());
if
(
code
!=
QDialog
::
Accepted
)
return
result
;
double
angle
=
angleSpinBox
->
value
()
*
acos
(
0
)
/
90
;
Image
::
depth_t
fillValue
=
valueSpinBox
->
value
();
int
Width
=
img
->
getWidth
();
int
Height
=
img
->
getHeight
();
int
nWidth
=
Width
,
nHeight
=
Height
;
double
cos_angle
=
cos
(
angle
);
if
(
fabs
(
cos_angle
)
<
1e-10
)
cos_angle
=
0
;
double
cos_neg_ang
=
cos
(
-
angle
);
if
(
fabs
(
cos_neg_ang
)
<
1e-10
)
cos_neg_ang
=
0
;
double
sin_angle
=
sin
(
angle
);
if
(
fabs
(
sin_angle
)
<
1e-10
)
sin_angle
=
0
;
double
sin_neg_ang
=
sin
(
-
angle
);
if
(
fabs
(
sin_neg_ang
)
<
1e-10
)
sin_neg_ang
=
0
;
// Calculate the size of the new bitmap
Point
rotation_point
;
rotation_point
.
x
=
0
;
rotation_point
.
y
=
0
;
Point
p1
=
rotatePoint
(
Point
(
0
,
0
),
sin_angle
,
cos_angle
);
Point
p2
=
rotatePoint
(
Point
(
img
->
getWidth
()
-
1
,
0
),
sin_angle
,
cos_angle
);
Point
p3
=
rotatePoint
(
Point
(
0
,
img
->
getHeight
()
-
1
),
sin_angle
,
cos_angle
);
Point
p4
=
rotatePoint
(
Point
(
img
->
getWidth
()
-
1
,
img
->
getHeight
()
-
1
),
sin_angle
,
cos_angle
);
int
min_x
=
min
(
min
(
p1
.
x
,
p2
.
x
),
min
(
p3
.
x
,
p4
.
x
));
int
max_x
=
max
(
max
(
p1
.
x
,
p2
.
x
),
max
(
p3
.
x
,
p4
.
x
));
int
min_y
=
min
(
min
(
p1
.
y
,
p2
.
y
),
min
(
p3
.
y
,
p4
.
y
));
int
max_y
=
max
(
max
(
p1
.
y
,
p2
.
y
),
max
(
p3
.
y
,
p4
.
y
));
if
(
expandBox
->
isChecked
())
{
nWidth
=
abs
(
max_x
-
min_x
)
+
1
;
nHeight
=
abs
(
max_y
-
min_y
)
+
1
;
}
Image
*
resImg
=
new
Image
(
nWidth
,
nHeight
,
img
->
getNbChannels
(),
fillValue
);
Point
source_point
;
for
(
unsigned
int
c
=
0
;
c
<
resImg
->
getNbChannels
();
++
c
)
{
for
(
unsigned
int
hcounter
=
0
;
hcounter
<
nHeight
;
hcounter
++
)
{
for
(
unsigned
int
wcounter
=
0
;
wcounter
<
nWidth
;
wcounter
++
)
{
source_point
.
x
=
wcounter
+
min_x
;
source_point
.
y
=
hcounter
+
min_y
;
source_point
=
rotatePoint
(
source_point
,
sin_neg_ang
,
cos_neg_ang
);
source_point
.
x
=
source_point
.
x
+
rotation_point
.
x
;
source_point
.
y
=
source_point
.
y
+
rotation_point
.
y
;
if
(
(
source_point
.
x
>=
0
)
&&
(
source_point
.
x
<
Width
)
&&
(
source_point
.
y
>=
0
)
&&
(
source_point
.
y
<
Height
))
{
resImg
->
setPixel
(
wcounter
,
hcounter
,
c
,
img
->
getPixel
(
source_point
.
x
,
source_point
.
y
,
c
));
}
}
}
}
result
.
push_back
(
new
ImgWidget
(
resImg
,
QString
(
" rotated %1"
).
arg
(
angleSpinBox
->
value
()).
toStdString
()));
return
result
;
}
This diff is collapsed.
Click to expand it.
app/Operations/RotateOp.h
0 → 100644
+
48
−
0
View file @
caba9c9d
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EIImage is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ROTATEOP_H
#define ROTATEOP_H
#include
<QCoreApplication>
#include
<vector>
#include
<QDialog>
#include
<QSpinBox>
#include
<QLabel>
#include
<QCheckBox>
#include
<QRadioButton>
#include
"Operation.h"
#include
"Image.h"
class
QWidget
;
class
RotateOp
:
public
Operation
{
public:
RotateOp
();
std
::
vector
<
QWidget
*>
operator
()(
const
imagein
::
Image
*
,
const
std
::
map
<
const
imagein
::
Image
*
,
std
::
string
>&
);
bool
needCurrentImg
();
};
#endif // ROTATEOP_H
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