Skip to content
Snippets Groups Projects
Commit 4bc1f7e8 authored by Sacha Percot-Tétu's avatar Sacha Percot-Tétu
Browse files

Added circular sinus synthesis

parent e9e32eba
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,10 @@
#include <QDialogButtonBox>
#include <QApplication>
#include <GrayscaleImage.h>
#include <QGroupBox>
#include <QRadioButton>
#include <QHBoxLayout>
#include <QLabel>
using namespace std;
using namespace imagein;
......@@ -47,6 +51,14 @@ void SinusSynthesisOp::operator()(const imagein::Image*, const std::map<const im
QFormLayout* layout = new QFormLayout();
dialog->setLayout(layout);
QGroupBox* radioGroup = new QGroupBox("Direction", dialog);
QRadioButton* linearButton = new QRadioButton(dialog->tr("Linear"));
QRadioButton* circularButton = new QRadioButton(dialog->tr("Circular"));
QHBoxLayout* radioLayout = new QHBoxLayout(radioGroup);
radioLayout->addWidget(linearButton);
radioLayout->addWidget(circularButton);
linearButton->setChecked(true);
QSpinBox* sizeBox = new QSpinBox();
sizeBox->setRange(0, 65536);
QSpinBox* periodBox = new QSpinBox();
......@@ -57,16 +69,21 @@ void SinusSynthesisOp::operator()(const imagein::Image*, const std::map<const im
QComboBox* colorBox = new QComboBox();
colorBox->addItem(dialog->tr("256"));
colorBox->addItem(dialog->tr("2 (Black and white)"));
layout->insertRow(0, dialog->tr("Image size (width=height) : "), sizeBox);
layout->insertRow(1, dialog->tr("Signal period (pixel) : "), periodBox);
layout->insertRow(2, dialog->tr("Orientation : "), angleBox);
layout->insertRow(3, dialog->tr("Niveaux de gris : "), colorBox);
layout->insertRow(0, radioGroup);
layout->insertRow(1, dialog->tr("Image size (width=height) : "), sizeBox);
layout->insertRow(2, dialog->tr("Signal period (pixel) : "), periodBox);
QLabel* orientationLabel = new QLabel(dialog->tr("Orientation (°): "));
layout->insertRow(3, orientationLabel, angleBox);
layout->insertRow(4, dialog->tr("Niveaux de gris : "), colorBox);
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
layout->insertRow(4, buttonBox);
layout->insertRow(5, buttonBox);
QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
QObject::connect(circularButton, SIGNAL(toggled(bool)), orientationLabel, SLOT(setHidden(bool)));
QObject::connect(circularButton, SIGNAL(toggled(bool)), angleBox, SLOT(setHidden(bool)));
QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec());
if(code!=QDialog::Accepted) return;
......@@ -76,23 +93,51 @@ void SinusSynthesisOp::operator()(const imagein::Image*, const std::map<const im
double angle = angleBox->value();
double period = periodBox->value();
double pi=3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117;
if(colorBox->currentIndex() == 0) {
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
double arg = i * sin(angle / 180. * pi) + j * cos(angle / 180. * pi);
double value = cos(2 * pi * arg / period);
value = (value + 1.) * 128;
if(value > 255.) value = 255.;
resImg->setPixel(i, j, value + 0.5);
if(linearButton->isChecked()) {
if(colorBox->currentIndex() == 0) {
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
double arg = i * sin(angle * pi / 180.) + j * cos(angle * pi / 180.);
double value = cos(2 * pi * arg / period);
value = (value + 1.) * 128;
if(value > 255.) value = 255.;
resImg->setPixel(i, j, value + 0.5);
}
}
}
else{
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
double arg = i * sin(angle / 180. * pi) + j * cos(angle / 180. * pi);
double value = cos(2 * pi * arg / period);
resImg->setPixel(i, j, value < 0. ? 0 : 255);
}
}
}
}
else{
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
double arg = i * sin(angle / 180. * pi) + j * cos(angle / 180. * pi);
double value = cos(2 * pi * arg / period);
resImg->setPixel(i, j, value < 0. ? 0 : 255);
else {
if(colorBox->currentIndex() == 0) {
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
double dx = i - resImg->getWidth()/2.;
double dy = j - resImg->getHeight()/2.;
double arg = std::sqrt(dx*dx + dy*dy);
double value = cos(2 * pi * arg / period);
value = (value + 1.) * 128;
if(value > 255.) value = 255.;
resImg->setPixel(i, j, value + 0.5);
}
}
}
else{
for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
double dx = i - resImg->getWidth()/2.;
double dy = j - resImg->getHeight()/2.;
double arg = std::sqrt(dx*dx + dy*dy);
double value = cos(2 * pi * arg / period);
resImg->setPixel(i, j, value < 0. ? 0 : 255);
}
}
}
}
......
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