Skip to content

Commit

Permalink
Merge pull request #115 from PauloCarvalhoRJ/FFT_polar_form
Browse files Browse the repository at this point in the history
FFT Polar Form
  • Loading branch information
PauloCarvalhoRJ authored Sep 17, 2017
2 parents df59811 + 248433b commit 7444077
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion GammaRay.pro
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ LIBS += -lvtkGUISupportQt$$_VTK_VERSION_SUFFIX \
# The application version
# Don't forget to update the Util::importSettingsFromPreviousVersion() method to
# enable the import of registry/user settings of previous versions.
VERSION = 2.7
VERSION = 2.7.1

# Define a preprocessor macro so we can get the application version in application code.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
Expand Down
Binary file modified docs/GammaRayManual.docx
Binary file not shown.
7 changes: 5 additions & 2 deletions imagejockey/imagejockeydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ ImageJockeyDialog::ImageJockeyDialog(QWidget *parent) :
this->setAttribute(Qt::WA_DeleteOnClose);

//maximizes the dialog
this->setWindowFlag( Qt::WindowMaximizeButtonHint );
Qt::WindowFlags flags = this->windowFlags();
flags |= Qt::WindowMaximizeButtonHint;
this->setWindowFlags( flags );

//the grid plot widget (displayed in the left pane)
m_gridPlot = new ImageJockeyGridPlot();
Expand Down Expand Up @@ -300,7 +302,8 @@ void ImageJockeyDialog::preview()
);

//reverse FFT the edited data (result is written back to the input data array).
Util::fft3D( cg->getNX(), cg->getNY(), cg->getNZ(), data, FFTComputationMode::REVERSE );
Util::fft3D( cg->getNX(), cg->getNY(), cg->getNZ(), data,
FFTComputationMode::REVERSE, FFTImageType::POLAR_FORM );

//add the in-memory data (now in real space) to the new Cartesian grid object
cgFFTtmp->addDataColumns( data, "real part of rFFT", "imaginary part of rFFT" );
Expand Down
4 changes: 2 additions & 2 deletions imagejockey/imagejockeydialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Variable with real part:</string>
<string>Variable with magnitude part:</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -518,7 +518,7 @@
<item row="2" column="1">
<widget class="QLabel" name="lbl33">
<property name="text">
<string>Variable with imaginary part:</string>
<string>Variable with angle part:</string>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion imagejockey/spectrogram1dplotpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Spectrogram1DPlotPicker::draw( const QPoint &pos )

//get the current geometry points
QVector<QPointF> drawnPointsSoFar;
for( int i = 0; i < m_drawingCurve->data()->size(); ++i){
for( uint i = 0; i < m_drawingCurve->data()->size(); ++i){
drawnPointsSoFar.push_back( m_drawingCurve->data()->sample( i ) );
}

Expand Down
16 changes: 9 additions & 7 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ void MainWindow::onProjectContextMenu(const QPoint &mouse_location)
_right_clicked_attribute2 = static_cast<Attribute*>( index2.internalPointer() );
if( _right_clicked_attribute->getContainingFile()->getFileType() == "CARTESIANGRID" ){
QString menu_caption_rfft = "rev. FFT: ";
menu_caption_rfft += "real = " + _right_clicked_attribute->getName();
menu_caption_rfft += "; imag = " + _right_clicked_attribute2->getName();
menu_caption_rfft += "mag. = " + _right_clicked_attribute->getName();
menu_caption_rfft += "; phase = " + _right_clicked_attribute2->getName();
_projectContextMenu->addAction(menu_caption_rfft, this, SLOT(onRFFT()));
}
}
Expand Down Expand Up @@ -1373,7 +1373,8 @@ void MainWindow::onFFT()
cg->getNY(),
cg->getNZ(),
array,
FFTComputationMode::DIRECT);
FFTComputationMode::DIRECT,
FFTImageType::POLAR_FORM );

//make a tmp file path
QString tmp_file_path = Application::instance()->getProject()->generateUniqueTmpFilePath("dat");
Expand All @@ -1385,7 +1386,7 @@ void MainWindow::onFFT()
new_cg->setInfoFromOtherCG( cg, false );

//save the results in the project's tmp directory
Util::createGEOEASGrid( "Real part", "Imaginary part", array, tmp_file_path);
Util::createGEOEASGrid( "Magnitude", "Angle", array, tmp_file_path);

//import the saved file to the project
Application::instance()->getProject()->importCartesianGrid( new_cg, new_cg_name );
Expand Down Expand Up @@ -1609,8 +1610,8 @@ void MainWindow::onRFFT()
//the parent file is surely a CartesianGrid.
CartesianGrid *cg = (CartesianGrid*)_right_clicked_attribute->getContainingFile();

//get the array containing the data (first variable is real part (amplitude spectrum) and
//the second is the imaginary part (phase spectrum)
//get the array containing the data (first variable is magnitude part (amplitude spectrum) and
//the second is the angle part (phase spectrum)
std::vector< std::complex<double> > array = cg->getArray( _right_clicked_attribute->getAttributeGEOEASgivenIndex()-1,
_right_clicked_attribute2->getAttributeGEOEASgivenIndex()-1);

Expand All @@ -1619,7 +1620,8 @@ void MainWindow::onRFFT()
cg->getNY(),
cg->getNZ(),
array,
FFTComputationMode::REVERSE);
FFTComputationMode::REVERSE,
FFTImageType::POLAR_FORM);

//make a tmp file path
QString tmp_file_path = Application::instance()->getProject()->generateUniqueTmpFilePath("dat");
Expand Down
22 changes: 16 additions & 6 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ void Util::importSettingsFromPreviousVersion()
QSettings currentSettings;
//The list of previous versions (order from latest to oldest version is advised)
QStringList previousVersions;
previousVersions << "2.5.1" << "2.5" << "2.4" << "2.3" << "2.2" << "2.1" << "2.0" << "1.7.1" << "1.7" << "1.6"
previousVersions << "2.7" << "2.5.1" << "2.5" << "2.4" << "2.3" << "2.2" << "2.1" << "2.0" << "1.7.1" << "1.7" << "1.6"
<< "1.5" << "1.4" << "1.3.1" << "1.3" << "1.2.1" << "1.2" << "1.1.0" << "1.0.1" << "1.0";
//Iterate through the list of previous versions
QList<QString>::iterator itVersion = previousVersions.begin();
Expand Down Expand Up @@ -1448,9 +1448,11 @@ QStringList Util::fastSplit(const QString lineGEOEAS)
return result;
}

void Util::fft3D(int nI, int nJ, int nK, std::vector<std::complex<double> > &values, FFTComputationMode isig)
void Util::fft3D(int nI, int nJ, int nK, std::vector<std::complex<double> > &values,
FFTComputationMode isig,
FFTImageType itype )
{
//create a vtk image from the value array
//create a vtk image from the input value array
////// index_shift = ( index + nINDEX/2) % nINDEX), if in reverse FFT mode,
////// shifts the lower frequencies components to the corners of the image for compatibility with RFFT algorithm/////
vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
Expand All @@ -1467,6 +1469,8 @@ void Util::fft3D(int nI, int nJ, int nK, std::vector<std::complex<double> > &val
if( isig == FFTComputationMode::DIRECT ) i_shift = i;
std::complex<double> value = values[i_shift + j_shift*nI + k_shift*nJ*nI];
double* cell = static_cast<double*>(image->GetScalarPointer(i,j,k));
if( isig == FFTComputationMode::REVERSE && itype == FFTImageType::POLAR_FORM )
value = std::polar( value.real(), value.imag() );
cell[0] = value.real();
cell[1] = value.imag();
}
Expand All @@ -1485,7 +1489,7 @@ void Util::fft3D(int nI, int nJ, int nK, std::vector<std::complex<double> > &val
fftFilter->SetInputData( image );
fftFilter->Update();

//get the image in frequency/real domain
//return the result image in frequency/real domain (polar/rectangular form)
////// index_shift = ( index + nINDEX/2) % nINDEX), if in forward FFT mode,
////// shifts the lower frequencies components to the center of the image for ease of interpretation/////
vtkSmartPointer<vtkImageData> imageOutput = fftFilter->GetOutput();
Expand All @@ -1500,8 +1504,14 @@ void Util::fft3D(int nI, int nJ, int nK, std::vector<std::complex<double> > &val
if( isig == FFTComputationMode::REVERSE ) i_shift = i;
std::complex<double> value;
double* cell = static_cast<double*>(imageOutput->GetScalarPointer(i,j,k));
value.real( cell[0] );
value.imag( cell[1] );
if( isig == FFTComputationMode::DIRECT && itype == FFTImageType::POLAR_FORM ){
std::complex<double> tmp( cell[0], cell[1] );
value.real( std::abs( tmp ) );
value.imag( std::arg( tmp ) );
} else {
value.real( cell[0] );
value.imag( cell[1] );
}
values[i_shift + j_shift*nI + k_shift*nJ*nI] = value;
}
}
Expand Down
12 changes: 11 additions & 1 deletion util.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ enum class FFTComputationMode : int {
REVERSE /*!< Functions fft*() take an input in frequency space and result is in real space. */
};

/*! FFT image type for functions fft*(). */
enum class FFTImageType : int {
RECTANGULAR_FORM = 0, /*!< Functions fft*() complex numbers are directly their real and imaginary components. */
POLAR_FORM /*!< Functions fft*() complex numbers are in their polar form (magnitude == real part, angle == imaginary part). */
};

/*! Computation direction for fft1d() when taking a 3D array. */
enum class FFT1DDirection : int {
DIR_I = 0, /*!< Computes along I (inlines). */
Expand Down Expand Up @@ -440,8 +446,12 @@ class Util
* @param nK Number of elements in Z/K direction.
* @param values Input/output array of values (complex numbers).
* @param isig 0 or 1 to transform or back-transform respectively.
* @param itype Image type. Either direct real and imaginary components or the complex numbers are in polar form (magnitude and angle).
*/
static void fft3D(int nI, int nJ, int nK, std::vector<std::complex<double> > &values, FFTComputationMode isig );
static void fft3D(int nI, int nJ, int nK,
std::vector<std::complex<double> > &values,
FFTComputationMode isig,
FFTImageType itype = FFTImageType::RECTANGULAR_FORM );

/** Compute the dip angle corresponding to grid steps.
* the d* parameters are the grid cell sizes.
Expand Down

0 comments on commit 7444077

Please sign in to comment.