error LNK2001 when using complex pow(),log(),exp() in VC++6 - c++

I work with VC++6 and I want to use complex power function (pow()) in one of my self-made function.
I wrote my necessary functions in a header file (.h).
Here is my function in the header file:
#include "MrServers/MrVista/Ice/IceIdeaFunctors/DllInterface.h"
// Base class:
#include "MrServers/MrVista/Include/Ice/IceUtils/IceImageReconFunctors.h"
#include "MrServers/MrVista/Include/Ice/IceUtils/IceUtils.h"
#include "MrServers/MrVista/Include/Ice/IceAlgos/IceWrapper.h"
// C++ class:
#include <vector>
#include <iostream>
#include <math.h>
#include <cmath>
#include <numeric>
#include <complex>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
// #define ACC 40.0 //Make larger to increase accuracy.
// #define BIGNO 1.0e10
// #define BIGNI 1.0e-10
// #define PI 3.14159265
typedef std::vector <float> array_1d;
typedef std::vector <array_1d> array_2d;
typedef std::vector <array_2d> array_3d;
using namespace std;
IceWrapper myice;
...other function...
void Hankel_Transform(IceAs& dstAs, IceAs& srcAs, int M, int N, int nCha, int nPHS, float delta_r, float delta_rho, int r_range)
{
//parameters for Hankel Transform
//M: Number of samples on a spoke
//N: total number of orders
//rho: a 1D vector contains rho values (in source image)
//r: a 1D vector contains r values (for final image)
//r_range: length of vector r
double res = 0.005;
int z_ord = (int) N/2;
float pii = 3.14159265f; // f means float. to avoid error
array_3d bessel_table(N, array_2d(M, array_1d(r_range)));
// load "bessel_table" from PDS// (will be added later)
// load bessel_table
//array_2d bessel_table;
//bessel_table = read_bessel_txt();
// create pointer in order to access srcAs and dstAs
CMPLX *p_srcAs = (CMPLX*) srcAs.calcSplObjStartAddr();
CMPLX *p_dstAs = (CMPLX*) dstAs.calcSplObjStartAddr();
// Hankel Formula //
//int my_ind;
float my_j;
float r;
float rho;
complex<float> temp (0.0 , 0.0);
complex<float> fn_r (0.0 , 0.0);
complex<float> immm(0, 1);
float ipow =0.0f;
//CMPLX *temp;
//CMPLX *fn_r;
for (int phase = 0; phase < nPHS; phase++)
{ for(int ord = -(N/2); ord < (N/2); ord++) //lines
{ for(int nc = 0; nc < nCha; nc++) //channels
{ for(int rr = 0; rr < r_range; rr++) //columns
{
r=(float)(rr+1)*delta_r;
fn_r=complex<float>(0.0 , 0.0);
//fn_r -> re = 0;
//fn_r -> im = 0;
for(int rhoo = 0; rhoo < M; rhoo++)
{
rho = delta_rho/2 + (float)rhoo*delta_rho;
// to avoid redunduncy in calculation of besselj in cha and phase
if ( nc == 0 && phase == 0 )
{
my_j = bessj(ord , (float)(pii*rho*r));
bessel_table[ord+z_ord][rhoo][rr] = my_j;
}
else
{
my_j = bessel_table[ord+z_ord][rhoo][rr];
}
//my_ind = (int)floor((float)(pii*rho*r/res)); // should be "round" :(
//if(my_ind==0){my_ind=1;}
//my_j = bessel_table[ord+z_ord][my_ind-1]; // dar c++ andis ha az 0 shoru mishe!!
// bayad esme jadval "bessel_table" bashad!
temp = complex<float>(rho*my_j*p_srcAs->re , rho*my_j*p_srcAs->im);
fn_r += temp;
p_srcAs++;
}
ipow = (float)ord;
//ICE_OUT(std::pow<complex>(fn_r,2));
fn_r *= std::pow(immm,ipow); //exp(ipow*log(immm));//pow(immm,ipow);
p_dstAs->re = real(fn_r);
p_dstAs->im = imag(fn_r);
p_dstAs++;
if(rr != (r_range-1) )
{
p_srcAs -= M;
}
}
}
}
}
}
Without putting this line: fn_r *= std::pow(immm,ipow) , everything works fine and the project correctly compiles. But when i try to put this line, or using exp() or log() function compiling fails with this errors:
IcePFTd_HankelFunctor.obj : error LNK2001: unresolved external symbol "struct _STL::complex<float> __cdecl _STL::pow(str
uct _STL::complex<float> const &,float const &)" (?pow#_STL##YA?AU?$complex#M#1#ABU21#ABM#Z)
/n4/x86/prod/bin/IcePFTd.dll : fatal error LNK1120: 1 unresolved externals
make: *** [\n4\x86\prod/bin/IcePFTd.dll] Error 96
I also tried to use the expression exp(ipow*log(immm)) instead of power function, but it also fails with the same error.
I tried to use this function (pow()) in a simple code in visual studio 2016,it works fine and it's just okay to consider #include <complex> in the first lines of the header.
Do you have any idea?
Any help will be appreciated.

Related

Using a pointer to a structure in a function that is declared in a header file

I have been searching all morning how to do this and I can't quite find what I am looking for. I should mention that I am fairly new to C.
I am trying to modulise my code (that is working until I try and do this)
Presently in the main code I have :
#include<stdio.h>
#include<rfftw.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <fstream>
#include <iomanip>
#include<complex>
#include<omp.h>
struct basic_gal {
double ra,dec,z,dist,fkp,nbar;
double cp[3];
double RSD[3];
};
struct basic_gal *gal;
int NGAL_MAX =200000;
main() {
if(!(gal = (struct basic_gal*)malloc(NGAL_MAX*sizeof(struct basic_gal))-1))
printf("memory allocation problem for galaxies\n");
etc etc..
}
I then go on to read in a file and allocate the various attributes to the structure.
What I would like to do is pass the empty structure (or a pointer to it) to a function, fill in the elements of the structure in the function and then return it to use in my main program again.
This requires 3 files, the main.c, the header file, header.h and the file that contains the function actions bin_gals.c
In the header file I have
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
void bin_NGP(int,int*,struct basic_gal*,int);
In the bin_gals.c file I have
#include "header.h"
#include <all_the_others>
void bin_NGP(int NGAL_MAX, int *NGAL, basic_gal *gal, int flag) {
/*read in files and add data etc*/
}
And in the main.c file I have
#include "header.h"
#include <all_the_others>
struct basic_gal {
double ra,dec,z,dist,fkp,nbar;
double cp[3];
double RSD[3];
};
struct basic_gal *gal;
int NGAL_MAX = 200000;
main() {
if(!(gal = (struct basic_gal*)malloc(NGAL_MAX*sizeof(struct basic_gal))-1))
printf("memory allocation problem for galaxies\n");
int NGAL =0;
int *ipNGAL =&NGAL;
bin_NGP(NRAN_MAX,ipNGAL,gal,1);
}
The problem is that I think I am not passing the structure properly but cannot figure out how to do this.
My error messages look like
bin_gals.c: In function ‘void bin_NGP(int, int*, basic_gal*, int)’:
bin_gals.c:150: error: ISO C++ forbids comparison between pointer and integer
bin_gals.c:151: error: invalid types ‘basic_gal*[int*]’ for array subscript
and I am not sure how to fix this.
Any help would be much appreciated!
EDIT: The actual content of the bin_NGP part of bin_gals.c is:
void bin_NGP(const char *data, int NGAL_MAX, int *NGAL, double *min_x, double *min_y ,double *min_z, double *max_x, double *max_y ,double *max_z ,struct basic_gal *gal, int flag) {
FILE *fp_rand;
if((fp_rand=fopen(data,"r"))==NULL) printf("data file %d not opened\n", flag);
const int bsz=100; char buf[bsz];
fgets(buf, bsz, fp_rand); //header line
while((fgets(buf, bsz, fp_rand))!=NULL) {
double ra, dec, cz;
sscanf(buf,"%lf %lf %lf\n",&ra,&dec,&cz);
if(++NGAL>NGAL_MAX) { NGAL--; break; }
gal[NGAL].ra = ra*pi/180.;
gal[NGAL].dec = dec*pi/180.;
gal[NGAL].z = cz;
gal[NGAL].dist = calc_dp(gal[NGAL].z);
gal[NGAL].cp[0] = (gal[NGAL].dist*cos(gal[NGAL].dec)*cos(gal[NGAL].ra));
gal[NGAL].cp[1] = (gal[NGAL].dist*cos(gal[NGAL].dec)*sin(gal[NGAL].ra));
gal[NGAL].cp[2] = (gal[NGAL].dist*sin(gal[NGAL].dec));
if (flag ==1) {
if (gal[NGAL].cp[0] > max_x) max_x = gal[NGAL].cp[0];
if (gal[NGAL].cp[1] > max_y) max_y = gal[NGAL].cp[1];
if (gal[NGAL].cp[2] > max_z) max_z = gal[NGAL].cp[2];
if (gal[NGAL].cp[0] < min_x) min_x = gal[NGAL].cp[0];
if (gal[NGAL].cp[1] < min_y) min_y = gal[NGAL].cp[1];
if (gal[NGAL].cp[2] < min_z) min_z = gal[NGAL].cp[2];
}
}
fclose(fp_rand);
}
I tried to simplify the question by removing some of the input parameters.. maybe I was disguising a mistake.
EDIT: fixed. For clarity I have included the fixed code incase anyone has the same problem.
void bin_NGP(const char *data, int NGAL_MAX, int *NGAL, double *min_x, double *min_y ,double *min_z, double *max_x, double *max_y ,double *max_z ,struct basic_gal *gal, int flag) {
FILE *fp_rand;
if((fp_rand=fopen(data,"r"))==NULL) printf("data file %d not opened\n", flag);
const int bsz=100; char buf[bsz];
fgets(buf, bsz, fp_rand); //header line
while((fgets(buf, bsz, fp_rand))!=NULL) {
double ra, dec, cz;
sscanf(buf,"%lf %lf %lf\n",&ra,&dec,&cz);
if(++(*NGAL) > NGAL_MAX) { *NGAL--; break; }
gal[*NGAL].ra = ra*pi/180.;
gal[*NGAL].dec = dec*pi/180.;
gal[*NGAL].z = cz;
gal[*NGAL].dist = calc_dp(gal[*NGAL].z);
gal[*NGAL].cp[0] = (gal[*NGAL].dist*cos(gal[*NGAL].dec)*cos(gal[*NGAL].ra));
gal[*NGAL].cp[1] = (gal[*NGAL].dist*cos(gal[*NGAL].dec)*sin(gal[*NGAL].ra));
gal[*NGAL].cp[2] = (gal[*NGAL].dist*sin(gal[*NGAL].dec));
if (flag ==1) {
if (gal[*NGAL].cp[0] > *max_x) *max_x = gal[*NGAL].cp[0];
if (gal[*NGAL].cp[1] > *max_y) *max_y = gal[*NGAL].cp[1];
if (gal[*NGAL].cp[2] > *max_z) *max_z = gal[*NGAL].cp[2];
if (gal[*NGAL].cp[0] < *min_x) *min_x = gal[*NGAL].cp[0];
if (gal[*NGAL].cp[1] < *min_y) *min_y = gal[*NGAL].cp[1];
if (gal[*NGAL].cp[2] < *min_z) *min_z = gal[*NGAL].cp[2];
}
}
fclose(fp_rand);
}
You need to forward declare struct basic_gal* for the declaration of bin_NGP() as struct basic_gal is defined in main.c. However, the definition of struct basic_gal will need to be available to the definition of bin_NGP() so you should move its definition out of main.c into a separate module:
/* basic_gal.h */
#ifndef BASIC_GAL_DEFINITION
#define BASIC_GAL_DEFINITION
struct basic_gal {
double ra,dec,z,dist,fkp,nbar;
double cp[3];
double RSD[3];
};
#endif
Note, if this is C you need to use struct basic_gal.
After edit, this is the offending line:
if(++NGAL>NGAL_MAX) { NGAL--; break; }
as NGAL is an int* and NGAL_MAX is an int. Dereference NGAL:
if(++*NGAL > NGAL_MAX) { (*NGAL)--; break; }
Dereference NGAL when using as array index:
gal[*NGAL].ra = ra*pi/180.;
You need to make your structure visible to both main.c and bin_gals.c. Modify your header bin_gals.h to something like:
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
struct basic_gal {
double ra,dec,z,dist,fkp,nbar;
double cp[3];
double RSD[3];
};
void bin_NGP(int,int*,struct basic_gal*,int);
bin_gals.c then would look like
#include "bin_gals.h"
#include <all_the_others>
void bin_NGP(int NGAL_MAX, int *NGAL, basic_gal *gal, int flag) {
/*read in files and add data etc*/
}
And your main file would be like the following:
#include "bin_gals.h"
#include <all_the_others>
struct basic_gal *gal;
int NGAL_MAX = 200000;
main() {
if(!(gal = (struct basic_gal*)malloc(NGAL_MAX*sizeof(struct basic_gal))-1))
printf("memory allocation problem for galaxies\n");
int NGAL =0;
int *ipNGAL =&NGAL;
bin_NGP(NRAN_MAX,ipNGAL,gal,1);
}

C++ Time Library and Octave .oct files

I am trying to write an Octave C++ .oct function that uses the linasm-1.13 library but I cannot seem to get even basic loading of tzdata from /usr/share/zoneinfo/ to work. My simple test function so far is
#include <octave/oct.h>
#include <Time.h> // the linasm-1.13 library
DEFUN_DLD ( tz, args, nargout,
"-*- texinfo -*-\n\
#deftypefn {Function File} {} tz (#var{YYYYMMDDHHMMSS})\n\
\n\
#end deftypefn" )
{
octave_value_list retval_list ;
unsigned int tz ;
const char *ny_time = "/usr/share/zoneinfo/America/New_York" ;
tz = Time::LoadTimeZone( ny_time ) ;
return retval_list ;
which, on compiling with mkoctfile, gives this error
>> mkoctfile tz.cc
tz.cc: In function ‘octave_value_list Ftz(const octave_value_list&, int)’:
tz.cc:24:34: error: cannot call member function ‘unsigned int Time::LoadTimeZone(const char*)’ without object
tz = Time::LoadTimeZone( ny_time ) ;
^
warning: mkoctfile: building exited with failure status
My understanding of this is that ny_time is not an object that is recognised, but I have tried casting ny_time as a string literal as detailed in this accepted SO answer.
I am doing things this way because the input for LoadTimeZone according to the linasm page should be a "path to tzfile, which describes required time zone." Where am I going wrong?
I think you have to #include "source.cc" files also, not just the #include "header.h" files. In your case, I guess you should add: #include "Time.cc" or something like that. I don't know why but this worked for me when working with Rafat's Hussain wavemin library, but I had only 4 files, it must be incredibly tedious with lots of files.
This is what I did (it's a modified version of the test code provided by Rafat with his library).
#include "wavemin.h"
#include "waveaux.h"
#include "wavemin.cc"
#include "waveaux.cc"
#include <octave/oct.h>
double ensayo();
double absmax(double *array, int N);
DEFUN_DLD(helloctave2, argv, , "Usage: hello()"){
wave_object obj;
wt_object wt;
double *inp, *out, *diff;
int N, i, J;
char *name = "db4";
obj = wave_init(name);// Initialize the wavelet
N = 14; //Length of Signal
inp = (double*)malloc(sizeof(double)* N); //Input signal
out = (double*)malloc(sizeof(double)* N);
diff = (double*)malloc(sizeof(double)* N);
//wmean = mean(temp, N);
for (i = 0; i < N; ++i) {
inp[i] = i;
}
J = 1; //Decomposition Levels
wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object
setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
setWTConv(wt, "direct");
dwt(wt, inp);// Perform DWT
//DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
for (i = 0; i < wt->outlength; ++i) {
octave_stdout << wt->output[i];
octave_stdout << "\n";
}
idwt(wt, out);// Perform IDWT (if needed)
// Test Reconstruction
for (i = 0; i < wt->siglength; ++i) {
diff[i] = out[i] - inp[i];
}
octave_stdout << absmax(diff, wt->siglength);
octave_stdout << "\n";
octave_value_list retval;
return retval;
}
double
absmax(double *array, int N) {
double max;
int i;
max = 0.0;
for (i = 0; i < N; ++i) {
if (fabs(array[i]) >= max) {
max = fabs(array[i]);
}
}
return max;
}

Calling a function from a library in C++ [closed]

I am new to using library's in C++, and would appreciate some help to learn. I have a main.cpp file and a library called maths with maths.cpp and maths.h
I have the following function, in my maths.cpp file, which I want to call from main.cpp :
void maths::Readings_to_Temperature (int temperature [5]) {
for (int n = 0 ; n < no_readings ; n++ ){
temperature[n] = ((R2*temperature[n])/Vin)-R2;
}
}
I have moved it from main.cpp, where it worked fine, as I want to clean up the code and make it more shareable. So how do I reference it in main.cpp? I have read a few tutorials, but the led.flash(5) style example doesn't really work, as I don't have any hardware parameters to pass to it, the only data which needs passing is the variable going into temperature.
My current main call is:
Readings_to_Temperature (readings);
I thought maybe:
maths.Readings_to_Temperature (readings);
or
maths::Readings_to_Temperature (readings);
I have the #include <maths.h> directive at the top of main.cpp
Thanks
Where R2 and Vin come from ?
Did you write a class ?
Use STL as much as you can, forget C array, use std::vector or std::array.
maths.h
#include <vector>
namespace maths
{
void Readings_to_Temperature (std::vector<int>& v);
}
maths.cpp
#include "maths.h"
namespace maths
{
void Readings_to_Temperature(std::vector<int>& v)
{
const size_t size = v.size();
for (size_t i = 0; size < size ; ++i)
{
temperature[i] = ((R2 * temperature[i]) / Vin) - R2;
}
}
}
main.cpp
#include <vector>
#include "maths.h"
int main()
{
std::vector<int> v(5, 0); // 5 integers set to 0
maths::Readings_to_Temperature(v);
}

C++ ~ call to function in client gives error: “identifier ____ is undefined”

I'm coming to you with a problem that has several different files involved. I'm not sure why I'm getting the error specified in the title. Let me put the files below and go from there.
DummyClient.cpp
#include "Gameboard.h" //for Gameboard
#include "Location.h" //for function prototypes
#include "zList.h" //for Zombies
#include <iostream> //for input/output stream
using namespace std;
void main()
{
srand(123456789);
Gameboard myGB;
myGB = Gameboard();
ZombieListClass();
ZombieRec zombieList[MAX_ZOMBIES];
PopulateZombies(zombieList[MAX_ZOMBIES]); // this throws the error here of "Error: identifier "PopulateZombies" is undefined"
}
zList.h
#ifndef ZLIST_H
#define ZLIST_H
#include "Location.h" // for list record
#include "ZombieRec.h"
#include "Gameboard.h"
class ZombieListClass
{
public:
ZombieListClass(); //default constructor
void PopulateZombies(ZombieRec zombieList[]);
bool IsInBounds(int row, int col);
private:
ZombieRec list[MAX_ZOMBIES]; //stores the items in the list
int length; //# of values currently in the list
int currPos; //position of current element
int strength; // health and attack units of a zombie
};
#endif
zList.cpp
#include "zList.h"
ZombieListClass::ZombieListClass() //default constructor
{
length = 0;
currPos = 0;
strength = 5;
LocationRec zombieLoc;
}
void ZombieListClass::PopulateZombies(ZombieRec zombieList[])
{
int row, col;
for (int i = 0; i < MAX_ZOMBIES; i++)
{
row = rand() % MAX_ROW + 1;
col = rand() % MAX_COL + 1;
while (!IsInBounds(row, col))
{
row = rand() % MAX_ROW + 1;
col = rand() % MAX_COL + 1;
}
zombieList[i].currLoc.row = row;
zombieList[i].currLoc.col = col;
}
}
bool ZombieListClass::IsInBounds(int row, int col)
{
if (row == 0 || row == MAX_ROW + 1 || col == 0 || col == MAX_COL + 1)
{
return false;
}
else
{
return true;
}
}
Gameboard.h
#ifndef GAMEBOARD_H
#define GAMEBOARD_H
#include "Location.h"
#include "ZombieRec.h"
#include "zList.h"
const int MAX_ROW = 3; // total number of rows in the board
const int MAX_COL = 3; // total number of cols in the board
class Gameboard
{
public:
Gameboard();
private:
int boardSizeArr[MAX_ROW + 2][MAX_COL + 2];
}; // end Gameboard
#endif
and finally, Gameboard.cpp
#include "Gameboard.h"
Gameboard::Gameboard()
{
// Declares a board with a boundary along the outside
boardSizeArr[MAX_ROW + 2][MAX_COL + 2];
}
I'm not looking to be spoonfed and for somebody to solve my problem for me, I'm trying to figure out what I'm doing wrong so that the remainder of my project isn't as bumpy as it has been this whole time.
Looking back on my error, "identifer "PopulateZombies" is undefined", I can't imagine why it is. Could this have something to do with the scope of how I'm doing things? If I've left any code out (I didn't put everything in there but I think I have everything relevant) just let me know, I'm able to converse back and forth as long as this takes.
Thank you to everybody in advance that tries to help :)
-Anthony
In general, you call the function using a variable, instead of calling it directly if defined in a class:
ZombieListClass zombieList=new ZombieListClass(); // add a variable here
ZombieRec zombieList[MAX_ZOMBIES];
zombieList.PopulateZombies(zombieList[MAX_ZOMBIES]); // See the difference?
I am not sure whether the error you posted is the only error. Here is what I see in your main.cpp
#include "Gameboard.h" //for Gameboard
#include "Location.h" //for function prototypes
#include "zList.h" //for Zombies
#include <iostream> //for input/output stream
using namespace std;
void main()
{
srand(123456789);
Gameboard myGB;
myGB = Gameboard();//The constructor"Gameboard()" is automatically called when you defined
//myGB in the previous line,
ZombieListClass();//see Hai Bi's great answer on this one
ZombieRec zombieList[MAX_ZOMBIES];//ZombieRec is a member of ZombieListClass, use . to access it
PopulateZombies(zombieList[MAX_ZOMBIES]); //Also see Hai Bi's answer
}
My advice is to revisit the concept of constructor and class definition before put your hands on s a problem like this.

ERROR LNK2019 ( Unresolved external symbol) IN VS2008 WITH ITK AND FFTW

I am performing a project with ITK for processing medical images. After a lot of work there is no further compilation errors, but in the linking process I am having the following info :
1>------Generation started: proyect: prueba_r01, configuration: Debug Win32 ------
1>Linking…
1>Creating library C:\Documents and Settings\GTTS\Mis documentos\Visual Studio 2008\Projects\prueba_r01\Debug\prueba_r01.lib and object C:\Documents and Settings\GTTS\Mis documentos\Visual Studio 2008\Projects\prueba_r01\Debug\prueba_r01.exp
1>prueba_r01.obj : error LNK2019: extern symbol "public: double (* __thiscall prueba_r01::multiply_matrix_2D(double ()[2],double ()[2],int,int))[2]" (?multiply_matrix_2D#prueba_r01##QAEPAY01NPAY01N0HH#Z) unresolved which is referenced in the function "private: void __thiscall prueba_r01::filtro(void)" (?filtro#prueba_r01##AAEXXZ)
1>C:\Documents and Settings\GTTS\Mis documentos\Visual Studio 2008\Projects\prueba_r01\Debug\prueba_r01.exe : fatal error LNK1120: 1 externos sin resolver
1>prueba_r01 - 2 errors, 0 warnings
========== Generar: 0 corrects, 1 incorrects, 0 actualized, 0 omited ==========
The method multiply_matrix_2D produces the error when is called inside the private slot “filtro()” (translated as filter)
The header of the file is :
#include <QtGui/QMainWindow>
#include "ui_prueba_r01.h"
#include "vicdef.h"
#include "itkImage.h"
#include "math.h"
#include <complex>
#include "fftw3.h"
using namespace std;
#define PI 3.14159265
class prueba_r01 : public QMainWindow
{
Q_OBJECT
public:
typedef double PixelType;
typedef itk::Image < PixelType, 2> ImageType;
ImageType::Pointer imagen;
double** H;
prueba_r01(QWidget *parent = 0, Qt::WFlags flags = 0);
~prueba_r01();
void matrix2D_H(int ancho, int alto, double eta, double sigma);
fftw_complex* multiply_matrix_2D(fftw_complex* out, fftw_complex* H,int a, int b);
private slots:
void openRGB();
void filtro();
private:
Ui::prueba_r01Class ui;
};
#endif // PRUEBA_R01_H
And the main part where the problem is located is in the .cpp file and is displayed here:
fftw_complex* res ;
res = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*a*b);
fftw_complex* H_casted= reinterpret_cast<fftw_complex*> (&H);
res = multiply_matrix_2D(out,H_casted, a, b);
The process of casting a **double pointer to *fftw_complex is done here, because I want to multiply a filter in frequency domain (H(w)) with the result of the fft transform of an image, that’s the reason. Is important to remark that fftw_complex is double[2], the first row for the real part, and the second for the imaginary
And the problematic method is shown below:
fftw_complex* multiply_matrix_2D(fftw_complex* out, fftw_complex* H, int a ,int b){
/* The matrix out[axb] or [n0x(n1/2)+1] is the image after the FFT , and the out_H[axb] is the filter in the frequency domain,
both are multiplied POINT TO POINT, it has to be called twice, one for the imaginary part and another for the normal part
*/
fftw_complex *res;
res = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*a*b);
for (int i0 = 0; i0<a ; i0++){
for (int i1 = 0; i1<b ; i1++){
res[i1+a*i0][0] = out[i1+a*i0][0]*(H[0][0]+H[0][1]); // real part
res[i1+a*i0][1] = out[i1+a*i0][1]*(H[0][0]+H[0][1]); // imaginary part
}
}
return res;
}
Any help will be really nice!! I’m quite lost now…
Thanks! Gracias!
Antonio
Change the function header in the cpp file to:
fftw_complex* prueba_r01::multiply_matrix_2D(fftw_complex* out, fftw_complex* H, int a, int b)
You forgot the class name (prueba_r01::) in the implementation, therefore it doesn't find the function body

Resources