mercredi 20 janvier 2021

New to C++/Objective C, unclear which file to call and/or compile

Right now I have 3 main files I'm getting from a research paper:

AntennaPatternGenAppDelegate.m
PatternGenAndSave.cpp
PaternView.m

Along with their 3 respective header files.

The files are as follow:

AntennaPatternGenAppDelegate.h

    #import <Cocoa/Cocoa.h>
    @interface AntennaPatternGenAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
    }
    @property (assign) IBOutlet NSWindow *window;

AntennaPatternGenAppDelegate.m


    #import "AntennaPatternGenAppDelegate.h"
    @implementation AntennaPatternGenAppDelegate
    @synthesize window;
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
        // write code here to initialize your application
    }
    @end
  • PatternGenAndSave.h
#ifndef PATTERNGENANDSAVE_H
#define PATTERNGENANDSAVE_H

#ifdef __cplusplus
#include <OpenEXR/ImfRgbaFile.h>
#include <openexr/ImfChannelList.h>
#include <openexr/ImfHeader.h>
#include <openexr/ImfOutputFile.h>
#include <openexr/ImfInputFile.h>
#include <openexr/ImfStandardAttributes.h>
#include <openexr/ImfArray.h>
using namespace Imf;
using namespace Imath;
#endif

#ifdef __cplusplus
extern "C" {
#endif
void GenPattern(float *data, float *rangeMod, int width, int height,
float pixelSpacing,
float antLength, float waveLength, float
rangeScale, float rangeCenter);
void saveEXR(const char* filename, int width, int height, const float*
data,
const float* rangeMod, float pixelSpacing, float
frequency, float antLen,
float rangeScale, float rangeCenter);
#ifdef __cplusplus
}
#endif
#endif //PATTERNGENANDSAVE_H

PatternGenAndSave.cpp

#include "PatternGenAndSave.h"
#include <cmath>
using namespace std;
#define PI 3.14159265358979323846
#define PLANE_DIST 20000.0
#define PLANE_PIXEL 0.33333333
double sinc(double th){
    if(th == 0)
        return 1.0;
    return sin(th)/th;
}

void GenPattern(float *data, float *rangeMod, int width, int height, float
                pixelSpacing,
                float antLenth, float waveLength, float rangeScale,
                float rangeCenter){
    // Calculation code
}
void saveEXR(const char* filename, int width, int height, const float* data,
             const float* rangeMod,
             float pixelSpacing, float frequency, float antLen, float
             rangeScale, float rangeCenter){
    Header header (width, height);
    header.insert("pixel spacing", FloatAttribute (pixelSpacing));
    header.channels().insert ("G", Channel (FLOAT));
    header.channels().insert ("Z", Channel (FLOAT));
    OutputFile file (filename, header);
    FrameBuffer frameBuffer;
    frameBuffer.insert ("G", Slice(FLOAT, (char *)data, sizeof(*data),
                                   sizeof(*data)*width));
    frameBuffer.insert ("Z", Slice(FLOAT, (char *)rangeMod,
                                   sizeof(*rangeMod),
                                   sizeof(*rangeMod)*width));
    file.setFrameBuffer(frameBuffer);
    file.writePixels(height);
}

PatternView.h

// PatternView.h
// AntennaPatternGen
//
//
#import <Cocoa/Cocoa.h>
@interface PatternView : NSView {
    int imgwidth, imgheight;
    float imgSeparation;
etc.
}

-(void)awakeFromNib;
-(void) SettingChange: (id)Sender;
-(void) SizeChange: (id)Sender;
-(void) ExposureChange: (id)Sender;
- (void) drawRect:(NSRect)dirtyRect;
- (void) SaveImage: (id)Sender ;

PatternView.m

// PatternView.m
// AntennaPatternGen
//
//
#import "PatternGenAndSave.h"
@implementation PatternView
- (void)awakeFromNib
{
    imgexposure = 1.f;
    imgwidth = 6000;

etc.
}
- (void) SettingChange: (id)Sender {
    // Calculation code
    GenPattern(data, rangeMod, imgwidth, imgheight, imgSeparation, antLength,
               waveLength,
               rangeScale, rangeCenter);
    [self setNeedsDisplay:YES];
}
- (void) SizeChange: (id)Sender {
    // Calculation Code
    GenPattern(data, rangeMod, imgwidth, imgheight, imgSeparation,
               antLength,waveLength,
               rangeScale, rangeCenter);
    [self setNeedsDisplay:YES];
}
- (void) ExposureChange: (id)Sender {
    imgexposure = pow(2,[ExposureSetting floatValue]);
    [self setNeedsDisplay:YES];
}
- (void) drawRect:(NSRect)dirtyRect {
    NSRect bds = dirtyRect;
    // Some code
    }
    [myImageCache draw];
}
- (void) SaveImage: (id)Sender {
    // Code
    saveEXR([tvarFilename UTF8String], imgwidth, imgheight, data, rangeMod,
            imgSeparation, frequency, antLength, rangeScale,
            rangeCenter);
}
@end

The program should open up a GUI, but I don't know which file to run to do so. I thought I'd have to run the cpp file with g++ -std=c++11 PatternGenAndSave.cpp but it returns this error

  "Iex_2_5::TypeExc::TypeExc(char const*)", referenced from:
      Imf_2_5::TypedAttribute<float>::cast(Imf_2_5::Attribute const*) in PatternGenAndSave-266f7a.o
  "Iex_2_5::TypeExc::~TypeExc()", referenced from:
      Imf_2_5::TypedAttribute<float>::cast(Imf_2_5::Attribute const*) in PatternGenAndSave-266f7a.o
  "Imf_2_5::OutputFile::writePixels(int)", referenced from:
      _saveEXR in PatternGenAndSave-266f7a.o

.
.
.
  "typeinfo for Imf_2_5::Attribute", referenced from:
      Imf_2_5::TypedAttribute<float>::cast(Imf_2_5::Attribute const*) in PatternGenAndSave-266f7a.o
      typeinfo for Imf_2_5::TypedAttribute<float> in PatternGenAndSave-266f7a.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64

If anyone could give me a pointer on how these files run together, it'd be much appreciated!

Thank you!

Aucun commentaire:

Enregistrer un commentaire