itaRavenProject.m 286 KB
Newer Older
1
classdef itaRavenProject < handle
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    %RavenProject - The class for working with RAVEN.
    % This class allows you to create configurations of settings, to
    % run simulations and to retrieve the results.
    %
    % Using:
    %   rpf = itaRavenProject(raven_project_file)
    %
    % Public Properties:
    %   Enter this command to get the properties:
    %   >> properties itaRavenProject
    %
    % Public Methods:
    %   Enter this command to get the methods:
    %   >> methods itaRavenProject
    %
    %   Enter this command to get more info of method:
    %   >> help itaRavenProject/methodname
    %
    %
    %
22
    % Examples:
23
    %   rpf = itaRavenProject();
24
25
26
27
28
    %   rpf.SetModel('cave.ac');
    %   rpf.getEquationBasedReverbTime(); returns reverb time based on
    %                                     sabine equation
    %   rpf.run();                        run simulation
    %   rpf.getT30();                     get T30 based on simulation
29
    %   rpf.plotMaterialsAbsorption();    plots absorption coefficients
30
    %
31
32
    % Author:           Soenke Pelzer (spe@akustik.rwth-aachen.de)
    %                   Lukas Aspck (las@akustik.rwth-aachen.de)
33
    %
34
    % Version:        0.2
35
    % First release:  01.11.10
36
    % Last revision:  11.07.18
37
38
    % Copyright:      Institute of Technical Acoustics, RWTH Aachen University
    %
39
40
41
42
43
44
    
    % <ITA-Toolbox>
    % This file is part of the application Raven for the ITA-Toolbox. All rights reserved.
    % You can find the license for this m-file in the application folder.
    % </ITA-Toolbox>
    
45
46
47
48
49
    
    properties(Constant)
        
        % CONSTANTS
        freqLabel3rd = { '   20 Hz', '   25 Hz', '   31 Hz', '   40 Hz', '   50 Hz', '   63 Hz', '   80 Hz', '  100 Hz', '  125 Hz', '  160 Hz', '  200 Hz', ...
50
51
52
            '  250 Hz', '  315 Hz', '  400 Hz', '  500 Hz', '  630 Hz', '  800 Hz', '   1 kHz', '1.25 kHz', ' 1.6 kHz', '   2 kHz', ...
            ' 2.5 kHz', '3.15 kHz', '   4 kHz', '   5 kHz', ' 6.3 kHz', '   8 kHz', '  10 kHz', '12.5 kHz', '  16 kHz', '  20 kHz'};
        freqLabelOct = { '   31 Hz', '   63 Hz', '  125 Hz', '  250 Hz', '  500 Hz', '   1 kHz', '   2 kHz', '   4 kHz', '   8 kHz', '  16 kHz'};
53
54
55
56
57
58
59
        freqVector3rd = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
        freqVectorOct = [31.5 63 125 250 500 1000 2000 4000 8000 16000];
        MODE_BSP   = 0;
        MODE_HASH  = 1;
        MODE_BRUTE = 2;
        COORD_TRAFO_SKETCHUP2RAVEN = [1 3 -2];
        COORD_TRAFO_RAVEN2SKETCHUP = [1 -3 2];
60
    end
61
62
63
    
    properties (GetAccess = 'public', SetAccess = 'private')
        % raven
64
        
65
66
67
        ravenExe
        ravenLogFile = 'RavenLog.txt'
        ravenProjectFile
68
        ravenIniFile
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        projectName
        
        % general
        sampleRate = 44100
        
        % paths
        pathResults
        pathDirectivities
        pathMaterials
        fileHRTF
        fileSpeakers
        
        % model
        modelFileList = []
        model = []
        
        % [Global]
        simulationTypeIS
        simulationTypeRT
        generateRIR
        generateBRIR
        generateISHOA
        generateRTHOA
        generateISVBAP
        generateRTVBAP
        exportFilter
        exportHistogram
        exportWallHitLog
        exportPlaneWaveList
        accelerationType
        logPerformance
        
        % [PrimarySources] %
        sourceNames
        sourceDirectivity
        sourcePositions
        sourceViewVectors
        sourceUpVectors
        sourceSoundStates
        sourceSoundLevels
        
        % [Receiver] %
        receiverNames
        receiverPositions
        receiverViewVectors
        receiverUpVectors
        receiverStates
        
        % [ImageSources] %
        ISOrder_PS
        ISOrder_SS
        ISSkipDirectSound
        
        % [RayTracing] %
        numParticles_Sphere
        numParticles_Portal
        energyLoss_Sphere
        energyLoss_Portal
127
128
        detectionSphereAziResolution
        detectionSphereEleResolution
129
130
131
132
133
134
135
136
137
        filterLength
        timeSlotLength
        radiusSphere
        fixReflectionPattern
        
        % [Filter] %
        fixPoissonSequence
        poissonSequenceNumber
        filterResolution
138
        maxReflectionDensity
139
140
141
142
        ambisonicsOrder
        numberSpreadedSources
        spreadingStdDeviation
        fftDegreeForWallFilterInterpolation
143
        
144
145
146
        % [PlaneWaveLists] %
        planeWaveList_IS = []
        planeWaveList_RT = []
147
        
148
149
150
151
152
        % [Performance]
        performance = struct('ISFilterMonaural',[],'ISFilterBinaural',[],'RTFilterMonaural',[],'RTFilterBinaural',[],'ISGenerateImageSources',[],'ISTransformationMatrix',[],'ISAudibilityTest',[],'RTTotal',[],'RTBands',[]);
        
    end
    
153
    properties (GetAccess = 'public', SetAccess = 'public')
154
155
156
157
158
        % [WallHitLogs] %
        wallHitLog_IS = []
        wallHitLog_RT = []
        initialParticleEnergy = []
    end
159
    
160
    properties (GetAccess = 'private', SetAccess = 'private')
161
162
163
164
        
        ravenExe64 = '..\bin64\RavenConsole64.exe'
        ravenExe32 = '..\bin32\RavenConsole.exe'
        
165
        rpf_ini
166
        raven_ini
167
168
169
170
171
172
173
        projectID
        projectTag
        
        projectLoaded = false
        simulationDone = false
        
        keepOutputFiles
174
        plotModelHandle = [];
175
176
177
178
179
180
181
182
183
184
185
186
        
        % [PrimarySources] %
        sourceNameString
        sourceDirectivityString
        
        % [Receiver] %
        receiverNameString
        uniformReceiverGridX = []
        uniformReceiverGridY = []
        uniformReceiverGridZ = []
        
        % RESULTS %
187
188
189
        monoIR = []
        monoIR_IS = []
        monoIR_RT = []
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
        binauralIR = []
        binauralIR_IS = []
        binauralIR_RT = []
        ambisonicsIR = []
        ambisonicsIR_IS = []
        ambisonicsIR_RT = []
        vbapIR = []
        vbapIR_IS = []
        vbapIR_RT = []
        histogram = []
        histogramRT = []
    end
    
    
    %---------------------- PUBLIC METHODS -------------------------------%
    methods
        %------------------------------------------------------------------
207
        function obj = itaRavenProject(raven_project_file)
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
            %RavenProject - constructor
            % To Create a new project with empty default configuration.
            %
            % Using:
            %   rpf = RavenProject(raven_project_file)
            %
            % Input:
            %   [optional] existing raven project file
            %
            % Output:
            %   obj - an instance of class RavenProject
            %
            
            if strcmp(computer('arch'), 'win32')
                obj.ravenExe = obj.ravenExe32;
            elseif strcmp(computer('arch'), 'win64')
                obj.ravenExe = obj.ravenExe64;
            else
                error('Only Windows OS are supported.');
            end
            
229
230
231
232
233
234
            itaRavenProjectPath = which('itaRavenProject.m');
            obj.ravenIniFile = [ itaRavenProjectPath(1:end-9) '.ini'];
            
            ravenIniExists = exist(obj.ravenIniFile,'file');
            
            if (ravenIniExists)
235
236
237
238
                % load path from itaRaven.ini
                obj.raven_ini = IniConfig();
                obj.raven_ini.ReadFile(obj.ravenIniFile);
                obj.ravenExe         = obj.raven_ini.GetValues('Global', 'PathRavenExe', obj.ravenExe);
239
                if (ischar(obj.ravenExe) && exist(obj.ravenExe,'file'))
240
241
                    obj.raven_ini.WriteFile(obj.ravenIniFile);
                end
242
243
            end
            
244
            if (~exist(obj.ravenExe,'file'))
245
246
                % neither the default relative raven console path nor the path in
                % itaRaven.ini was found, try to locate RavenConsole
247
248
                locatedRavenExe = which(obj.ravenExe(10:end));
                
249
250
251
252
253
254
255
256
257
258
259
260
                % try default raven exe path after instalation
                if isempty(locatedRavenExe)
                    if strcmp(computer('arch'), 'win32')
                        defaultInstallationPathRavenExe = 'C:\ITASoftware\Raven\bin32\RavenConsole.exe';
                    elseif strcmp(computer('arch'), 'win64')
                        defaultInstallationPathRavenExe = 'C:\ITASoftware\Raven\bin64\RavenConsole64.exe';
                    else
                        error('Only Windows OS are supported.');
                    end
                    
                    if exist(defaultInstallationPathRavenExe,'file')
                        locatedRavenExe = defaultInstallationPathRavenExe;
261
                        obj.ravenExe = defaultInstallationPathRavenExe;
262
263
264
                    end
                end
                
265
                if isempty(locatedRavenExe)
266
267
268
269
270
271
272
                    
                    disp('[itaRaven]:');
                    disp('No RAVEN binary was found! Please select path to the RAVEN console application (RavenConsole.exe/RavenConsole64.exe)!');
                    disp('To run RAVEN simulations, an installation of the RAVEN software is required. ');
                    disp('Individual licenses for academic purposes are available on request.');
                    disp('Please contact: las@akustik.rwth-aachen.de');
                    
273
274
275
276
277
278
279
280
                    [ selectedRavenExe, selectedRavenPath] = uigetfile('*.exe',' No RAVEN binary was found! Please select path to RavenConsole.exe');
                    
                    if (ischar(selectedRavenExe)&& ischar(selectedRavenPath))
                        obj.ravenExe = [ selectedRavenPath selectedRavenExe];
                    else
                        warning('WARNING: RAVEN binary path was set to default, but binary was not found. Please specify the correct path in itaRaven.ini');
                        obj.ravenExe = defaultInstallationPathRavenExe;
                    end
281
                    
282
283
284
285
286
287
                end
                
                if (~ravenIniExists)
                    obj.raven_ini = IniConfig();
                    obj.raven_ini.AddSections({'Global'});
                    obj.raven_ini.AddKeys('Global', {'PathRavenExe'}, {obj.ravenExe});
288
289
                    obj.raven_ini.WriteFile(obj.ravenIniFile);
                    
290
291
                else
                    obj.raven_ini.SetValues('Global', {'PathRavenExe'}, {obj.ravenExe});
292
                    obj.raven_ini.WriteFile(obj.ravenIniFile);
293
294
                end
                
295
            end
296
            
297
            % check if raven project file exists
298
299
300
301
302
303
304
            if (nargin > 0) && exist(raven_project_file, 'file')
                obj.loadRavenConfig(raven_project_file);
            else
                error('No raven project file given or file not found.');
            end
        end
        
305
306
307
308
        function delete(obj)
            obj.deleteResultsInRavenFolder();
        end
        
309
        %------------------------------------------------------------------
310
        function setRavenIniPath(obj, newPath)
311
312
            obj.ravenIniFile = newPath;
        end
313
314
        
        %------------------------------------------------------------------
315
        function copyProjectToNewRPFFile(obj, newPath)
316
317
318
319
320
321
322
323
324
            if (exist(fileparts(newPath),'dir'))
                obj.ravenProjectFile = newPath;
                obj.rpf_ini.WriteFile(obj.ravenProjectFile);
            else
                error('itaRavenProject/copyProjectToNewRPFFile: invalid path');
            end
        end
        
        
325
326
        %------------------------------------------------------------------
        function setRavenExe(obj, newRavenExe)
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
            
            
            if (exist(newRavenExe,'file'))
                
                obj.ravenExe = newRavenExe;
                
                if (exist(obj.ravenIniFile,'file'))
                    obj.raven_ini.SetValues('Global', {'PathRavenExe'}, {obj.ravenExe});
                    obj.raven_ini.WriteFile(obj.ravenIniFile);
                else
                    obj.raven_ini = IniConfig();
                    obj.raven_ini.AddSections({'Global'});
                    obj.raven_ini.AddKeys('Global', {'PathRavenExe'}, {obj.ravenExe});
                end
                
342
            else
343
344
                error('[itaRaven]: Error: Path to new Raven binary not found!');
                
345
            end
346
            
347
348
349
350
351
352
353
        end
        
        %------------------------------------------------------------------
        function loadRavenConfig(obj, filename)
            %loadRavenConfig - Reads an existing raven project file
            %
            
354
355
356
357
358
359
            % change relative to absolute path
            if (~strcmp(filename(2),':'))
                obj.ravenProjectFile = [pwd '\' filename];
            else
                obj.ravenProjectFile = filename;
            end
360
361
362
363
364
365
            
            obj.rpf_ini = IniConfig();
            obj.rpf_ini.ReadFile(filename);
            
            % [Global] %
            obj.projectName         = obj.rpf_ini.GetValues('Global', 'ProjectName', 'Matlab');
366
            obj.projectTag          = obj.projectName;
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
            obj.pathResults         = obj.rpf_ini.GetValues('Global', 'ProjectPath_Output', '..\RavenOutput');
            obj.pathDirectivities   = obj.rpf_ini.GetValues('Global', 'ProjectPath_DirectivityDB', '..\RavenDatabase\DirectivityDatabase');
            obj.pathMaterials       = obj.rpf_ini.GetValues('Global', 'ProjectPath_MaterialDB', '..\RavenDatabase\MaterialDatabase');
            obj.fileHRTF            = obj.rpf_ini.GetValues('Global', 'ProjectPath_HRTFDB', '..\RavenDatabase\HRTF\ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.daff');
            obj.fileSpeakers        = obj.rpf_ini.GetValues('Global', 'SpeakerConfigFile', 'Speakers.ini');
            obj.simulationTypeIS    = obj.rpf_ini.GetValues('Global', 'simulationTypeIS', 1);
            obj.simulationTypeRT    = obj.rpf_ini.GetValues('Global', 'simulationTypeRT', 1);
            obj.generateRIR         = obj.rpf_ini.GetValues('Global', 'generateRIR', 1);
            obj.generateBRIR        = obj.rpf_ini.GetValues('Global', 'generateBRIR', 1);
            obj.generateISHOA       = obj.rpf_ini.GetValues('Global', 'generateISHOA', 0);
            obj.generateRTHOA       = obj.rpf_ini.GetValues('Global', 'generateRTHOA', 0);
            obj.generateISVBAP      = obj.rpf_ini.GetValues('Global', 'generateISVBAP', 0);
            obj.generateRTVBAP      = obj.rpf_ini.GetValues('Global', 'generateRTVBAP', 0);
            obj.exportFilter        = obj.rpf_ini.GetValues('Global', 'exportFilter', 1);
            obj.exportHistogram     = obj.rpf_ini.GetValues('Global', 'exportHistogram', 1);
            obj.exportWallHitLog    = obj.rpf_ini.GetValues('Global', 'exportWallHitList', 0);
            obj.exportPlaneWaveList = obj.rpf_ini.GetValues('Global', 'exportPlaneWaveList', 0);
            obj.accelerationType    = obj.rpf_ini.GetValues('Global', 'accelerationType', 0);   % default 0 = MODE_BSP
            obj.logPerformance      = obj.rpf_ini.GetValues('Global', 'logPerformance', 0);
            obj.keepOutputFiles     = obj.rpf_ini.GetValues('Global', 'keepOutputFiles', 0);
            
388
            
389
390
391
392
393
394
395
            % change relative to absolute paths
            if obj.ravenExe(2) == ':' % absolute path
                ravenBasePath = fileparts(fileparts(obj.ravenExe)); % base path of raven
                
                if (strcmp(obj.pathResults(1:2),'..')), obj.pathResults = [ ravenBasePath obj.pathResults(3:end) ]; end
                if (strcmp(obj.pathDirectivities(1:2),'..')), obj.pathDirectivities = [ ravenBasePath obj.pathDirectivities(3:end) ]; end
                if (strcmp(obj.pathMaterials(1:2),'..')), obj.pathMaterials = [ ravenBasePath obj.pathMaterials(3:end) ]; end
396
397
                if (strcmp(obj.fileHRTF(1:2),'..')), obj.fileHRTF = [ ravenBasePath obj.fileHRTF(3:end) ]; end
                
398
                
399
400
            end
            
401
402
403
404
405
406
            % [Rooms] %
            model_string            = obj.rpf_ini.GetValues('Rooms',  'Model');
            obj.modelFileList       = textscan(model_string, '%s', 'Delimiter' , ',');
            obj.modelFileList       = obj.modelFileList{1}; % textscan implementation issue
            if numel(obj.modelFileList) == 1
                obj.modelFileList = obj.modelFileList{1};   % de-cell if only 1 room given
407
408
                
                if obj.ravenExe(2) == ':' % convert to absolute path
409
                    if (strcmp(obj.modelFileList(1:2),'..')), obj.modelFileList = [ ravenBasePath obj.modelFileList(3:end) ]; end
410
                end
411
412
            end
            
413
414
            
            
415
            
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
            % [PrimarySources] %
            obj.sourceNameString    = obj.rpf_ini.GetValues('PrimarySources', 'sourceNames', 'Sender');
            obj.sourceNames         = textscan(obj.sourceNameString, '%s', 'Delimiter', ',');
            obj.sourceNames         = obj.sourceNames{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            obj.sourceDirectivityString = obj.rpf_ini.GetValues('PrimarySources', 'sourceDirectivity', '');
            if ~isempty(obj.sourceDirectivityString)
                obj.sourceDirectivity   = textscan(obj.sourceDirectivityString, '%s', 'Delimiter', ',');
                obj.sourceDirectivity   = obj.sourceDirectivity{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            else
                obj.sourceDirectivity   = {};
            end
            obj.sourcePositions     = obj.rpf_ini.GetValues('PrimarySources', 'sourcePositions');
            obj.sourcePositions     = reshape(obj.sourcePositions, 3, numel(obj.sourcePositions)/3)';
            obj.sourceViewVectors   = obj.rpf_ini.GetValues('PrimarySources', 'sourceViewVectors', '0, 0, 1');
            obj.sourceViewVectors   = reshape(obj.sourceViewVectors, 3, numel(obj.sourceViewVectors)/3)';
            obj.sourceUpVectors     = obj.rpf_ini.GetValues('PrimarySources', 'sourceUpVectors', '0, 1, 0');
            obj.sourceUpVectors     = reshape(obj.sourceUpVectors, 3, numel(obj.sourceUpVectors)/3)';
            obj.sourceSoundStates   = obj.rpf_ini.GetValues('PrimarySources', 'sourceSoundStates', '1');
            obj.sourceSoundLevels   = obj.rpf_ini.GetValues('PrimarySources', 'sourceSoundLevels', '100');
            
            % [Receiver] %
            obj.receiverNameString  = obj.rpf_ini.GetValues('Receiver', 'receiverNames', 'Receiver');
            obj.receiverNames       = textscan(obj.receiverNameString, '%s', 'Delimiter', ',');
            obj.receiverNames       = obj.receiverNames{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            obj.receiverPositions   = obj.rpf_ini.GetValues('Receiver', 'receiverPositions');
            obj.receiverPositions   = reshape(obj.receiverPositions, 3, numel(obj.receiverPositions)/3)';
            obj.receiverViewVectors = obj.rpf_ini.GetValues('Receiver', 'receiverViewVectors', '1, 0 ,0');
            obj.receiverViewVectors = reshape(obj.receiverViewVectors, 3, numel(obj.receiverViewVectors)/3)';
            obj.receiverUpVectors   = obj.rpf_ini.GetValues('Receiver', 'receiverUpVectors', '0, 1, 0');
            obj.receiverUpVectors   = reshape(obj.receiverUpVectors, 3, numel(obj.receiverUpVectors)/3)';
            
            % [ImageSources] %
            obj.ISOrder_PS          = obj.rpf_ini.GetValues('ImageSources', 'ISOrder_PS', 2);
            obj.ISOrder_SS          = obj.rpf_ini.GetValues('ImageSources', 'ISOrder_SS', 2);
            obj.ISSkipDirectSound   = obj.rpf_ini.GetValues('ImageSources', 'ISSkipDirectSound', 0);
            
            % [RayTracing] %
            obj.numParticles_Sphere = obj.rpf_ini.GetValues('RayTracing', 'numberOfParticles_DetectionSphere', 10000);
            obj.numParticles_Portal = obj.rpf_ini.GetValues('RayTracing', 'numberOfParticles_Portal', 10000);
            obj.energyLoss_Sphere   = obj.rpf_ini.GetValues('RayTracing', 'energyLoss_DetectionSphere', 63);
            obj.energyLoss_Portal   = obj.rpf_ini.GetValues('RayTracing', 'energyLoss_Portal', 63);
            obj.filterLength        = obj.rpf_ini.GetValues('RayTracing', 'filterLength_DetectionSphere', 2000);
            obj.timeSlotLength      = obj.rpf_ini.GetValues('RayTracing', 'timeResolution_DetectionSphere', 6);
            obj.radiusSphere        = obj.rpf_ini.GetValues('RayTracing', 'radius_DetectionSphere', 0.5);
            obj.fixReflectionPattern= obj.rpf_ini.GetValues('RayTracing', 'fixReflectionPattern', 0);
            
            % [Filter] %
            obj.fixPoissonSequence  = obj.rpf_ini.GetValues('Filter', 'setFixPoissonSequence', 0);
            obj.poissonSequenceNumber = obj.rpf_ini.GetValues('Filter', 'poissonSequenceNumber', 9876);
            obj.filterResolution    = obj.rpf_ini.GetValues('Filter', 'filterResolution', 1);   % 1 = Octave, 0 = 3rd Octave
            obj.ambisonicsOrder     = obj.rpf_ini.GetValues('Filter', 'ambisonicsOrder', -1);
            obj.numberSpreadedSources             = obj.rpf_ini.GetValues('Filter', 'numberSpreadedSources', 0);
            obj.spreadingStdDeviation             = obj.rpf_ini.GetValues('Filter', 'spreadingStdDeviation', 0.2);
            obj.fftDegreeForWallFilterInterpolation = obj.rpf_ini.GetValues('Filter', 'fftDegreeForWallFilterInterpolation', 8);
            
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
            
            %% check input data files (HRTF, source directivity, room model)
            % HRTF (also shows if DAFF file is v15 or v17)
            if (exist(obj.fileHRTF,'file') == 0) 
                warning('HRTF file not found at the specified location.');
            else
                if (contains(obj.fileHRTF,'.v17.daff'))
                   disp('itaRavenProject: Loaded DAFFv17 HRTF file'); 
                end
                if (contains(obj.fileHRTF,'.v15.daff'))
                   disp('itaRavenProject: Loaded DAFFv15 HRTF file'); 
                end                
            end

            % Source directivity (only checks first directivity file)
            if (~isempty(obj.sourceDirectivity)) % first check if any directivity was defined
                if (exist([ obj.pathDirectivities '\' obj.sourceDirectivity{1}],'file') == 0) 
                    warning('Source directivity file not found at the specified location.');
                else
                    if (contains(obj.sourceDirectivity{1},'.v17.daff'))
                       disp('itaRavenProject: Loaded DAFFv17 source directivity file'); 
                    end
                    if (contains(obj.sourceDirectivity{1},'.v15.daff'))
                       disp('itaRavenProject: Loaded DAFFv15 source directivity file'); 
                    end                  
                end
            end
            
             % room model
            if (numel(obj.modelFileList) == 0 ) 
                warning('No room model file (*.ac) specified in project file.');
            end
            
            if (numel(obj.modelFileList) == 1 && exist(obj.modelFileList,'file') == 0) 
                warning('Room model file (*.ac) not found at the specified location.');
            end
            
508
509
510
511
512
513
514
515
516
517
518
519
            obj.projectLoaded = true;
        end
        
        %------------------------------------------------------------------
        function reloadRavenConfig(obj, filename)
            if nargin < 2
                filename = obj.ravenProjectFile;
            end
            
            obj.loadRavenConfig(filename);
        end
        
520
        %------------------------------------------------------------------
521
522
523
524
525
526
        function saveRavenConfig(obj, filename)
            %saveRavenConfig - Saves the current object in a (different)
            %raven project file. Can be used as a log if various
            %simulations are run with multiple configurations
            %
            obj.rpf_ini.WriteFile(filename);
527
            
528
529
        end
        
530
531
        %------------------------------------------------------------------
        function run(obj)
Philipp Schäfer's avatar
Philipp Schäfer committed
532
533
534
            if numel(obj.projectName) > 70
                warning('Long project name. This might cause an error while writing output files. Consider resetting your project name!')
            end
535
536
537
538
539
540
541
542
543
544
545
            
            obj.simulationDone = false;
            
            if obj.projectLoaded
                savedProjectName = obj.projectName;
                
                obj.projectID = datestr(now, 30);
                obj.projectTag = [obj.projectName obj.projectID];
                
                % give the project name a date and time string to help to identify the results
                obj.setProjectName(obj.projectTag);
546
                
547
548
549
550
551
552
                % run the simulation
                disp(['Running simulation... (' obj.ravenExe ')']);
                if exist(obj.ravenLogFile, 'file')
                    delete(obj.ravenLogFile);
                end
                %                 system([obj.ravenExe ' "' obj.ravenProjectFile '" >> ' obj.ravenLogFile]);
553
554
                
                if (~exist(obj.ravenExe,'file'))
555
                    error('[itaRaven]: Error: Cannot find Raven binary file! Please check itaRaven.ini file!');
556
557
                end
                
558
559
                prevPath = pwd;
                cd(fileparts(obj.ravenExe));
560
                dos(['"' obj.ravenExe '"' ' "' obj.ravenProjectFile '"'],'-echo');
561
                cd(prevPath);
562
563
564
565
566
                
                % restore the initial project name
                obj.setProjectName(savedProjectName);
                
                % gather results
567
                disp('[R] Simulation seems to be finished. Getting results...');
568
                obj.gatherResults();
569
                disp('[R] Done.');
570
571
572
573
574
575
576
577
578
579
580
581
582
                
                obj.simulationDone = true;
                
                % delete results in raven folder structure -> they are copied now into this class
                if (obj.keepOutputFiles == 0)
                    obj.deleteResultsInRavenFolder();
                end
            else
                disp('No projected defined yet.');
            end
            
        end
        
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
        %------------------------------------------------------------------
        function runNoGathering(obj)
            % basicly the same as the run method, but without the call of
            % obj.gatherResults();
            
            obj.simulationDone = false;
            
            if obj.projectLoaded
                savedProjectName = obj.projectName;
                
                obj.projectID = datestr(now, 30);
                obj.projectTag = [obj.projectName obj.projectID];
                
                % give the project name a date and time string to help to identify the results
                obj.setProjectName(obj.projectTag);
                
                % set filter length to the length of the reverberation
                %                 obj.setFilterLengthToReverbTime();
                
                % run the simulation
                disp(['Running simulation... (' obj.ravenExe ')']);
                if exist(obj.ravenLogFile, 'file')
                    delete(obj.ravenLogFile);
                end
                %                 system([obj.ravenExe ' "' obj.ravenProjectFile '" >> ' obj.ravenLogFile]);
608
609
610
                prevPath = pwd;
                cd(fileparts(obj.ravenExe));
                dos(['"' obj.ravenExe '"' ' "' obj.ravenProjectFile '"'],'-echo');
611
                disp('Done.');
612
613
                cd(prevPath);
                
614
615
616
617
618
619
                
                % restore the initial project name
                obj.setProjectName(savedProjectName);
                
                % gather results
                disp('This function does _not_ gather the results. Please provide arguments to getWallHitLogBand(band)');
620
621
                %                 obj.gatherResults();
                %                 disp('Done.');
622
623
624
625
                
                obj.simulationDone = true;
                
                % delete results in raven folder structure -> they are copied now into this class
626
627
628
                %                 if (obj.keepOutputFiles == 0)
                %                     obj.deleteResultsInRavenFolder();
                %                 end
629
630
631
632
633
634
            else
                disp('No projected defined yet.');
            end
            
        end
        
635
636
637
638
        %------------------------------------------------------------------
        function keepImpulseResponseFiles(obj, keepFiles)
            % keepImpulseResponseFiles
            %
639
            %   By default, RAVEN Impulse Responses are deleted from the hard disk
640
641
642
643
644
645
646
647
            %   after simulation and are only available in your rpf project
            %
            %   By setting keepOutFiles to 1 / true, results are kept in
            %   the Output-Folder (obj.pathResults)
            
            obj.keepOutputFiles     = keepFiles;
            obj.rpf_ini.SetValues('Global', 'keepOutputFiles', keepFiles);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
648
        end
649
        
650
        %------------------------------------------------------------------
651
652
        function openOutputFolder(obj)
            % opens the output folder in windows explorer
653
            
654
655
656
657
658
659
660
661
662
            if (exist(obj.pathResults,'dir'))
                dos(['C:\Windows\Explorer.exe ' obj.pathResults]);
            else
                disp('Output Folder does not exist!');
            end
            
        end
        
        
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
        %------------------------------------------------------------------
        function numReceivers = createReceiverArray(obj, xpositions, zpositions, yheight)
            numReceivers = numel(xpositions) * numel(zpositions);
            [obj.uniformReceiverGridX, obj.uniformReceiverGridZ] = meshgrid(xpositions, zpositions);
            obj.uniformReceiverGridY = ones(size(obj.uniformReceiverGridX,1), size(obj.uniformReceiverGridX,2)) * yheight;
            
            rec_names = obj.makeNumberedNames('Array', numReceivers);
            rec_states = str2num(obj.writeXtimes_num(1, numReceivers));
            rec_view = str2num(obj.writeXtimes('1,0,0', numReceivers));
            rec_up = str2num(obj.writeXtimes('0,1,0', numReceivers));
            
            positions = zeros(numReceivers * 3, 1);
            positions(1:3:end) = obj.uniformReceiverGridX(:);
            positions(2:3:end) = obj.uniformReceiverGridY(:);
            positions(3:3:end) = obj.uniformReceiverGridZ(:);
            
            obj.setReceiverNames(rec_names);
            obj.setReceiverPositions(positions);
            obj.setReceiverViewVectors(rec_view);
            obj.setReceiverUpVectors(rec_up);
            obj.setReceiverStates(rec_states);
            
            disp(['Receiver grid created successfully. ' num2str(numReceivers) ' receivers placed.']);
        end
        
        %------------------------------------------------------------------
        function createReceiverArrayAuto(obj, yheight, distance, roomID)
            
            if nargin < 4
                roomID = 0;   % default = first room (ID = 0)
            end
            
            if isempty(obj.model)
                if iscell(obj.modelFileList)
                    for iRoom = 1 : numel(obj.modelFileList)
698
                        obj.model{iRoom} = itaAc3dModel(obj.modelFileList{iRoom});
699
700
701
                    end
                    roommodel = obj.model{roomID + 1};
                else
702
                    obj.model = itaAc3dModel(obj.modelFileList);
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
                    roommodel = obj.model;
                end
            else
                if iscell(obj.model)
                    roommodel = obj.model{roomID + 1};
                else
                    roommodel = obj.model;
                end
            end
            
            if nargin < 3
                distance = 1;   % default = 1 meter
            end
            
            if nargin < 2
                yheight = min(roommodel.nodes(:,2)) + 1.2;  % default listener 1.2 meters above ground
                if yheight > max(roommodel.nodes(:,2))
                    yheight = mean(roommodel.nodes(:,2));   % if 1.2 meters is out of ceiling, try putting receivers in the middle between floor and ceiling
                end
            end
            
            xpositions = min(roommodel.nodes(:,1)) + distance/2 : distance : max(roommodel.nodes(:,1)) - distance/2;
            zpositions = min(roommodel.nodes(:,3)) + distance/2 : distance : max(roommodel.nodes(:,3)) - distance/2;
            
            obj.createReceiverArray(xpositions, zpositions, yheight);
        end
        
        %------------------------------------------------------------------
        function rebuildReceiverGrid(obj)
            numReceivers = numel(obj.receiverPositions) / 3;    %xyz
            if numReceivers < 1
                error('No receiver position data present.');
            end
            x = obj.receiverPositions(:,1);
            y = obj.receiverPositions(:,2);
            z = obj.receiverPositions(:,3);
            averageDistance = sqrt((max(x)-min(x))*(max(z)-min(z)) / numReceivers);
            obj.createReceiverArray(min(x) : averageDistance : max(x), min(z) : averageDistance : max(z), mean(y));
        end
        
        %------------------------------------------------------------------
        function setModel(obj, filename)
            
            if (nargin < 2)
                error('Not enough input arguments.')
            end
            
            if ~ischar(filename)
                error('Requires string input.')
            else
                if iscell(filename)
                    obj.modelFileList = obj.cat_cell_of_strings(filename);
                else
                    obj.modelFileList = filename;
                end
                obj.rpf_ini.SetValues('Rooms', 'Model', obj.modelFileList);
            end
            
            obj.model = [];
            
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
        %------------------------------------------------------------------
        function [outputFilePath] = setModelToShoebox(obj, length,width,height)
            % setModelToShoebox
            % creates a shoebox room model and automatically sets the model
            % of the current project to the defined shoebox room.
            % The shoebox room has 6 materials assigned (matShoebox1 ..
            % matShoebox6), which can be set using
            %       rpf.setMaterial(matShoebox1,abs,scat)
            %
            % surface order:
            % (1) floor, (2) ceiling,
            % (3) larger wall (length x height; left, view from origin)
            % (4) smaller wall (width x height; front)
            % (5) larger wall (length x height; right)
            % (6) smaller wall (width x height; back)
781
            %
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
            % Using:
            %   outputFileName = rpf.setModelToShoebox(myLength,myWidth,myHeight);
            %
            %   see ita_raven_demo_shoebox for more details on usage
            %
            % Input:
            %   length, width, height (all in meters)
            %
            % Output:
            %   outputFilePath: full path of save ac3d model
            %
            
            outputFileName = ['Shoebox_' num2str(length) 'x' num2str(width) 'x' num2str(height) '.ac' ];
            
            if strfind(obj.modelFileList,'RavenModels')
                outputFilePath = [ obj.modelFileList(1:strfind(obj.modelFileList,'RavenModels')+10) '\' outputFileName ];
                
            else
                % if model wasn't stored in RavenModels folder, save it in
                % the folder of the current rpf file.
                outputFilePath = [ fileparts(obj.ravenProjectFile) '\' outputFileName ];
            end
            
            fid = fopen(outputFilePath,'w');
            fprintf(fid,'AC3Db\n');
            for iMat=1:6
                fprintf(fid,['MATERIAL "matShoebox' num2str(iMat) '" rgb ' num2str(0.0) ' ' num2str(0.0) ' ' num2str(0.1*iMat) ' amb 0.2 0.2 0.2  emis 0 0 0  spec 0.2 0.2 0.2  shi 128  trans 0 \n']);
            end
            
            fprintf(fid,'OBJECT world\n');
            fprintf(fid,'kids 6\n');
            
            lS=sprintf('%1.4f',length);
            wS=sprintf('%1.4f',-width);
            hS=sprintf('%1.4f',height);
            
            for iWall=1:6
                fprintf(fid,'OBJECT poly\n');
                fprintf(fid,'name "polygon_object"\n');
                fprintf(fid,'numvert 4\n');
                
                if iWall==1
                    fprintf(fid,'0 0 0\n');
                    fprintf(fid,[lS ' 0 0\n']);
                    fprintf(fid,[lS ' 0 ' wS '\n']);
                    fprintf(fid,['0 0 ' wS '\n']);
                end
                
                if iWall==2
                    fprintf(fid,[lS ' ' hS ' 0\n']);
                    fprintf(fid,['0 ' hS ' 0\n']);
                    fprintf(fid,['0 ' hS ' '  wS '\n']);
                    fprintf(fid,[lS ' ' hS ' '  wS '\n']);
                end
                
                if iWall==3
                    fprintf(fid,[lS ' 0 0\n']);
                    fprintf(fid,'0 0 0\n');
                    fprintf(fid,['0 ' hS ' 0\n']);
                    fprintf(fid,[lS ' ' hS ' 0\n']);
                end
                
                if iWall==4
                    fprintf(fid,'0 0 0\n');
                    fprintf(fid,['0 0 ' wS '\n']);
                    fprintf(fid,['0 ' hS ' '  wS '\n']);
                    fprintf(fid,['0 ' hS ' 0\n']);
                end
                
                if iWall==5
                    fprintf(fid,['0 0 ' wS '\n']);
                    fprintf(fid,[lS ' 0 ' wS '\n']);
                    fprintf(fid,[lS ' ' hS ' '  wS '\n']);
                    fprintf(fid,['0 ' hS ' '  wS '\n']);
                end
                
                if iWall==6
                    fprintf(fid,[lS ' 0 ' wS '\n']);
                    fprintf(fid,[lS ' 0 0\n']);
                    fprintf(fid,[lS ' ' hS ' 0\n']);
                    fprintf(fid,[lS ' ' hS ' '  wS '\n']);
                end
                
                fprintf(fid,'numsurf 1\n');
                fprintf(fid,'SURF 0x10\n');
                fprintf(fid,['mat ' num2str(iWall-1) '\n']);
                fprintf(fid,'refs 4\n');
                fprintf(fid,'3 0 0\n');
                fprintf(fid,'2 0 0\n');
                fprintf(fid,'1 0 0\n');
                fprintf(fid,'0 0 0\n');
                fprintf(fid,'kids 0\n');
                
                
            end
            
            fclose(fid);
            obj.setModel(outputFilePath);
            
        end
882
        
883
884
        %------------------------------------------------------------------
        function [outputFilePath] = setModelToFaces(obj,points,faces,materials)
885
            % setModelToFaces
886
            % creates a room model using points and faces and automatically
887
888
889
890
891
892
893
894
895
896
897
898
            % sets the model of the current project to the so defined room.
            % The room has one material assigned to each face (mat1 ..
            % mat6), which can be set using
            %       rpf.setMaterial(mat1,abs,scat)
            %
            % Using:
            %   outputFileName = rpf.setModelToFaces(points,faces,materials);
            %
            %   see ita_raven_demo_faces_room for more details on usage
            %
            % Input:
            %   points (matrix Nx3 in meters, columns represnt x, y, and z)
899
            %   faces (cell array, faces are defined pointing to the rows
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
            % of matrix points) the first element points the material
            %   materials (cell array) This array does not necesarlly match
            % the number of surfaces
            % Output:
            %   FilePath: full path of save ac3d model
            %
            
            nW=length(faces);
            
            outputFileName = ['room_' num2str(nW) '_faces'];
            
            if strfind(obj.modelFileList,'RavenModels')
                outputFilePath = [ obj.modelFileList(1:strfind(obj.modelFileList,'RavenModels')+10) '\' outputFileName ];
                
            else
                % if model wasn't stored in RavenModels folder, save it in
                % the folder of the current rpf file.
                outputFilePath = [ fileparts(obj.ravenProjectFile) '\' outputFileName ];
918
919
920
921
922
923
924
925
926
            end
            
            fn = floor(size(points,2)/4); % first element of a three elements point
            
            if size(points,2)>3
                idx = (points(:,1));
            else
                idx=1:size(points,1);
            end
927
            
928
            
929
930
931
            fid = fopen(outputFilePath,'w');
            fprintf(fid,'AC3Db\n');
            
932
            for iW=1:nW
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
                fprintf(fid,['MATERIAL "' materials{faces{iW}(1)} '" rgb ' num2str(0.0) ' ' num2str(0.0) ' ' num2str(0.9/nW*iW) ' amb 0.2 0.2 0.2  emis 0 0 0  spec 0.2 0.2 0.2  shi 128  trans 0 \n']);
            end
            
            fprintf(fid,'OBJECT world\n');
            fprintf(fid,['kids ' num2str(nW) '\n']);
            
            for iW=1:nW
                nP=length(faces{iW})-1;
                
                fprintf(fid,'OBJECT poly\n');
                fprintf(fid,'name "polygon_object"\n');
                
                fprintf(fid,['numvert ' num2str(nP) '\n']);
                
                for iP=1:nP
948
                    fprintf(fid,[sprintf('%1.4f %1.4f %1.4f',points(faces{iW}(iP+1)==idx,fn+(1:3))) '\n']);
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
                end
                
                fprintf(fid,'numsurf 1\n');
                fprintf(fid,'SURF 0x10\n');
                fprintf(fid,['mat ' num2str(iW-1) '\n']);
                fprintf(fid,'refs 4\n');
                fprintf(fid,'3 0 0\n');
                fprintf(fid,'2 0 0\n');
                fprintf(fid,'1 0 0\n');
                fprintf(fid,'0 0 0\n');
                fprintf(fid,'kids 0\n');
                
                
            end
            
            fclose(fid);
            obj.setModel(outputFilePath);
            
        end
968
        
969
        %------------------------------------------------------------------
Lukas Aspöck's avatar
Lukas Aspöck committed
970
        function figureHandle=plotModel(obj, tgtAxes, comp2axesMapping, wireframe)
971
972
973
974
975
976
977
978
979
980
981
982
            if isempty(obj.modelFileList)
                return;
            end
            
            if nargin < 4
                wireframe = 0;
            else
                if ischar(wireframe)
                    wireframe = isequal(wireframe, 'wireframe');
                end
            end
            if nargin < 3
Philipp Schäfer's avatar
Philipp Schäfer committed
983
                comp2axesMapping = [1 -3 2];
984
985
            end
            if nargin < 2
986
987
988
989
990
991
992
                if (ishandle(obj.plotModelHandle))
                    tgtAxes = obj.plotModelHandle;
                else
                    figure;
                    tgtAxes = gca;
                end
                
993
994
            end
            
995
996
            obj.plotModelHandle = tgtAxes;
            
997
998
999
            if isempty(obj.model)
                if iscell(obj.modelFileList)
                    for iRoom = 1 : numel(obj.modelFileList)
1000
                        obj.model{iRoom} = itaAc3dModel(obj.modelFileList{iRoom});
1001
1002
1003
1004
                        obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
                        hold on;
                    end
                else
1005
                    obj.model = itaAc3dModel(obj.modelFileList);
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
                    obj.model.plotModel(tgtAxes, comp2axesMapping, wireframe);
                end
            else
                if iscell(obj.model)
                    for iRoom = 1 : numel(obj.model)
                        obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
                        hold on;
                    end
                else
                    obj.model.plotModel(tgtAxes, comp2axesMapping, wireframe);
                end
            end
Philipp Schäfer's avatar
Philipp Schäfer committed
1018
1019
1020
1021
1022
            
            % get and transform source and receiver data
            invertAxes = sign(comp2axesMapping);
            comp2axesMapping = abs(comp2axesMapping);
            
1023
            spos = obj.getSourcePosition;
1024
            spos = spos(:, comp2axesMapping).*repmat(invertAxes,size(spos,1),1);
Philipp Schäfer's avatar
Philipp Schäfer committed
1025
            sview = obj.getSourceViewVectors;
1026
            sview = sview(:, comp2axesMapping).*repmat(invertAxes,size(sview,1),1);
Lukas Aspöck's avatar
Lukas Aspöck committed
1027
1028
            sup = obj.getSourceUpVectors;
            sup = sup(:, comp2axesMapping).*repmat(invertAxes,size(sup,1),1);
1029
            
1030
1031
1032
            snames = obj.getSourceNames;
            
            rpos = obj.getReceiverPosition;
1033
            rpos = rpos(:, comp2axesMapping).*repmat(invertAxes,size(rpos,1),1);
Philipp Schäfer's avatar
Philipp Schäfer committed
1034
            rview = obj.getReceiverViewVectors;
1035
            rview = rview(:, comp2axesMapping).*repmat(invertAxes,size(rview,1),1);
Lukas Aspöck's avatar
Lukas Aspöck committed
1036
1037
            rup = obj.getReceiverUpVectors;
            rup = rup(:, comp2axesMapping).*repmat(invertAxes,size(rup,1),1);
1038
1039
            rnames = obj.getReceiverNames;
            
Philipp Schäfer's avatar
Philipp Schäfer committed
1040
1041
            % plot source and receivers
            plot3(spos(:,1),spos(:,2),spos(:,3),'marker','o','markersize',9,'linestyle','none','linewidth',1.5)
1042
            %             hold on; view(0,90);
Philipp Schäfer's avatar
Philipp Schäfer committed
1043
            plot3(rpos(:,1),rpos(:,2),rpos(:,3),'marker','x','markersize',9,'linestyle','none','linewidth',1.5)
1044
            
1045
            % plot view vectors (red) of sources
Philipp Schäfer's avatar
Philipp Schäfer committed
1046
            quiver3(spos(:,1),spos(:,2),spos(:,3),sview(:,1),sview(:,2),sview(:,3),0,'color','r','maxheadsize',1.5,'linewidth',1.5);
1047
            
1048
            % plot view/up vectors (red) of receivers
1049
            quiver3(rpos(:,1),rpos(:,2),rpos(:,3),rview(:,1),rview(:,2),rview(:,3),0,'color','r','maxheadsize',1.5,'linewidth',1.5);
1050
1051
            
            
Lukas Aspöck's avatar
Lukas Aspöck committed
1052
            % plot up vectors (green) of sources and receivers )
1053
            quiver3(spos(:,1),spos(:,2),spos(:,3),0.5*sup(:,1),0.5*sup(:,2),0.5*sup(:,3),0,'color','g','maxheadsize',1.5,'linewidth',1.5);
Lukas Aspöck's avatar
Lukas Aspöck committed
1054
            
1055
            quiver3(rpos(:,1),rpos(:,2),rpos(:,3),0.5*rup(:,1),0.5*rup(:,2),0.5*rup(:,3),0,'color','g','maxheadsize',1.5,'linewidth',1.5);
1056
            
1057
1058
            
            % plot names
Lukas Aspöck's avatar
Lukas Aspöck committed
1059
1060
1061
1062
            text(spos(:,1)-0.2,spos(:,2),spos(:,3),snames,'FontName','Times','FontSize',20,'HorizontalAlignment','right')
            text(rpos(:,1)+0.2,rpos(:,2),rpos(:,3),rnames,'FontName','Times','FontSize',20)
            
            figureHandle=gca;
1063
        end
1064
1065
        
        %------------------------------------------------------------------
1066
        function tgtAxes = plotModelRoom(obj, tgtAxes, comp2axesMapping, wireframe)
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
            % identical to plotModel, without sound sources and receivers
            if isempty(obj.modelFileList)
                return;
            end
            
            if nargin < 4
                wireframe = 0;
            else
                if ischar(wireframe)
                    wireframe = isequal(wireframe, 'wireframe');
                end
            end
            if nargin < 3
1080
                comp2axesMapping = [1 -3 2];
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
            end
            if nargin < 2
                if (ishandle(obj.plotModelHandle))
                    tgtAxes = obj.plotModelHandle;
                else
                    figure;
                    tgtAxes = gca;
                end
                
            end
            
            obj.plotModelHandle = tgtAxes;
            
            if isempty(obj.model)
                if iscell(obj.modelFileList)
                    for iRoom = 1 : numel(obj.modelFileList)
1097
                        obj.model{iRoom} = itaAc3dModel(obj.modelFileList{iRoom});
1098
1099
1100
1101
                        obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
                        hold on;
                    end
                else
1102
                    obj.model = itaAc3dModel(obj.modelFileList);
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
                    obj.model.plotModel(tgtAxes, comp2axesMapping, wireframe);
                end
            else
                if iscell(obj.model)
                    for iRoom = 1 : numel(obj.model)
                        obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
                        hold on;
                    end
                else
                    obj.model.plotModel(tgtAxes, comp2axesMapping, wireframe);
                end
            end
1115
            
1116
        end
1117
        
1118
        %------------------------------------------------------------------
1119
        function plotMaterialsAbsorption(obj, exportPlot, fileType, outputPath)
1120
1121
            
            if nargin < 2
1122
                exportPlot = false;
1123
1124
            end
            
1125
1126
1127
1128
            if nargin < 3
                fileType='png';
            end
            
1129
1130
1131
1132
1133
1134
1135
1136
            if nargin < 4
                outputPath= obj.pathResults;
            end
            
            % strip final slash or backslash
            if ( strcmp(outputPath(end),'\') ||  strcmp(outputPath(end),'/') )
                outputPath = outputPath(1:end-1);
            end
1137
1138
            
            
1139
1140
1141
1142
            freqVector = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
            freqLabel3rdVisual = { '', '', '31.5 Hz', '', '', '' '', '  ', '  125 Hz', ' ', ' ', ...
                '', ' ', ' ', '  500 Hz', ' ', '  ', '', '', ' ', '   2 kHz', ...
                ' ', '', '', '', '', '   8 kHz', '  ', '', '', '20 kHz'};
1143
            
1144
            yticks = { '0.0','', '0.20','','0.40','','0.60','','0.80','','1.0'};
1145
            
1146
1147
            allMaterials = obj.getRoomMaterialNames;
            numberMaterials = length(allMaterials);
1148
            
1149
1150
1151
            currentMaterial = itaResult;
            currentMaterial.freqVector = freqVector;
            currentMaterial.freqData = [];
1152
            
1153
1154
            for iMat=1:numberMaterials
                [absorp scatter ] = obj.getMaterial(allMaterials{iMat});
1155
                currentMaterial.freqData = [ currentMaterial.freqData absorp' ];
1156
1157
1158
                currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{iMat});
                allMaterials{iMat} = strrep(allMaterials{iMat},'_',' ');
                allMaterials{iMat} = [ allMaterials{iMat} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m ;'];
1159
                allMaterials{iMat} = [ allMaterials{iMat} ' A (Eyring, f=1000 Hz) = ' num2str(-currentSurfaceArea*log(1-currentMaterial.freqData(18,iMat)),'%5.2f') ' m )'];
1160
            end
1161
            
1162
1163
            currentMaterial.channelNames = allMaterials;
            currentMaterial.allowDBPlot = false;
1164
            currentPlot = ita_plot_freq(currentMaterial,'LineWidth',2);
1165
            
1166
1167
1168
1169
1170
            myAxes = gca;
            for iMat=1:numberMaterials
                myAxes.Children(iMat+2).Marker = 's';
            end
            
1171
            % change format of plot
1172
1173
1174
            title('');
            ylabel('Absorption coefficient');
            xlabel('Frequency in Hz');
1175
1176
            set(myAxes,'XLim',[20 20000]);
            set(myAxes,'YLim',[0 1.05]);
1177
1178
            leg = findobj(gcf,'Tag','legend');
            set(leg,'Location','NorthWest');
1179
            set(leg,'FontSize',12);
1180
1181
1182
1183
            
            % remove [1] in legend entry
            for iMat=1:numberMaterials
                leg.String{iMat} = leg.String{iMat}(1:end-4);
1184
            end
1185
            
1186
            % export plot to raven output
1187
            if (exportPlot)
1188
1189
1190
                [pathstr,name,ext] = fileparts(obj.ravenProjectFile);
                dateTimeStr = datestr(now,30);
                dateTimeStr = strrep(dateTimeStr,'T','_');
1191
1192
                fileNamePNG = [ outputPath '\Absorption_' name '_' dateTimeStr '.png'];
                fileNamePDF = [ outputPath '\Absorption_' name '_' dateTimeStr '.pdf'];
1193
1194
                set(gcf,'units','normalized','outerposition',[0 0 1 1]);
                set(gcf,'PaperUnits','inches','PaperPosition',1.34*[0 0 8 5]);
1195
1196
                
                if strcmpi(fileType,'pdf')
1197
                    set(gcf,'PaperUnits','centimeters','PaperSize',[25.7, 16.5]);
1198
1199
1200
1201
1202
1203
1204
1205
                    print('-dpdf','-r200', fileNamePDF);
                    close(currentPlot);
                else
                    if ~strcmpi(fileType,'png')
                        warning('plotMaterialsAbsorption: Specified fileType not supported. Using PNG.');
                    end
                    print('-dpng','-r200', fileNamePNG);
                end
1206
1207
1208
1209
            end
        end
        
        %------------------------------------------------------------------
1210
        function averageRoomScattering = plotMaterialsScattering(obj, exportPlot, fileType, outputPath)
1211
            
1212
            if nargin < 2
1213
                exportPlot = false;
1214
1215
            end
            
1216
1217
1218
1219
            if nargin < 3
                fileType='png';
            end
            
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
            if nargin < 4
                outputPath= obj.pathResults;
            end
            
            % strip final slash or backslash
            if ( strcmp(outputPath(end),'\') ||  strcmp(outputPath(end),'/') )
                outputPath = outputPath(1:end-1);
            end
            
            
1230
1231
1232
1233
            freqVector = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
            freqLabel3rdVisual = { '', '', '31.5 Hz', '', '', '' '', '  ', '  125 Hz', ' ', ' ', ...
                '', ' ', ' ', '  500 Hz', ' ', '  ', '', '', ' ', '   2 kHz', ...
                ' ', '', '', '', '', '   8 kHz', '  ', '', '', '20 kHz'};
1234
            
1235
            yticks = { '0.0','', '0.20','','0.40','','0.60','','0.80','','1.0'};
1236
            
1237
1238
            allMaterials = obj.getRoomMaterialNames;
            numberMaterials = length(allMaterials);
1239
            
1240
1241
1242
            currentMaterial = itaResult;
            currentMaterial.freqVector = freqVector;
            currentMaterial.freqData = [];
1243
            
Lukas Aspöck's avatar
Lukas Aspöck committed
1244
1245
            averageRoomScattering = zeros(1,31);
            
1246
1247
1248
            for i=1:numberMaterials
                [absorp scatter ] = obj.getMaterial(allMaterials{i});
                currentMaterial.freqData = [ currentMaterial.freqData scatter' ];
1249
                currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{i});
1250
1251
                allMaterials{i} = strrep(allMaterials{i},'_',' ');
                allMaterials{i} = [ allMaterials{i} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m )'];
Lukas Aspöck's avatar
Lukas Aspöck committed
1252
                averageRoomScattering = averageRoomScattering + (scatter)*currentSurfaceArea;
1253
            end
1254
            
Lukas Aspöck's avatar
Lukas Aspöck committed
1255
1256
            averageRoomScattering = averageRoomScattering / obj.getRoomSurfaceArea;
            
1257
1258
            currentMaterial.channelNames = allMaterials;
            currentMaterial.allowDBPlot = false;
1259
            currentPlot=ita_plot_freq(currentMaterial,'LineWidth',2);
1260
1261
1262
1263
1264
1265
            
            myAxes = gca;
            for iMat=1:numberMaterials
                myAxes.Children(iMat+2).Marker = 's';
            end
            
1266
1267
            
            % change format of plot
1268
1269
1270
            title('');
            ylabel('Scattering coefficient');
            xlabel('Frequency in Hz');
1271
1272
            set(myAxes,'XLim',[20 20000]);
            set(myAxes,'YLim',[0 1.05]);
1273
1274
            leg = findobj(gcf,'Tag','legend');
            set(leg,'Location','NorthWest');
1275
            set(leg,'FontSize',12);
1276
1277
1278
1279
1280
            
            % remove [1] in legend entry
            for iMat=1:numberMaterials
                leg.String{iMat} = leg.String{iMat}(1:end-4);
            end
1281
            
1282
            % export plot to raven output
1283
            if (exportPlot)
1284
1285
1286
                [pathstr,name,ext] = fileparts(obj.ravenProjectFile);
                dateTimeStr = datestr(now,30);
                dateTimeStr = strrep(dateTimeStr,'T','_');
1287
1288
                fileNamePNG = [ outputPath '\Scattering_' name '_' dateTimeStr '.png'];
                fileNamePDF = [ outputPath '\Scattering_' name '_' dateTimeStr '.pdf'];
1289
1290
                set(gcf,'units','normalized','outerposition',[0 0 1 1]);
                set(gcf,'PaperUnits','inches','PaperPosition',1.34*[0 0 8 5]);
1291
1292
                
                if strcmpi(fileType,'pdf')
1293
                    set(gcf,'PaperUnits','centimeters','PaperSize',[25.7, 16.5]);
1294
1295
1296
1297
1298
1299
1300
1301
1302
                    print('-dpdf','-r200', fileNamePDF);
                    close(currentPlot);
                else
                    if ~strcmpi(fileType,'png')
                        warning('plotMaterialsScattering: Specified fileType not supported. Using PNG.');
                    end
                    print('-dpng','-r200', fileNamePNG);
                end
                
1303
1304
1305
1306
1307
            end
        end
        
        
        
1308
1309
1310
1311
1312
1313
1314
1315
        % [Global] %
        %------------------------------------------------------------------
        function setProjectName(obj, projectName)
            obj.projectName = projectName;
            obj.rpf_ini.SetValues('Global', 'ProjectName', projectName);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
Philipp Schäfer's avatar
Philipp Schäfer committed
1316
1317
1318
1319
1320
1321
        function setPathMaterials(obj, pathMaterials)
            obj.pathMaterials = pathMaterials;
            obj.rpf_ini.SetValues('Global', 'ProjectPath_MaterialDB', pathMaterials);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
        %------------------------------------------------------------------
        function setSimulationTypeIS(obj, typeIS)
            obj.simulationTypeIS = typeIS;
            obj.rpf_ini.SetValues('Global', 'simulationTypeIS', typeIS);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSimulationTypeRT(obj, typeRT)
            obj.simulationTypeRT = typeRT;
            obj.rpf_ini.SetValues('Global', 'simulationTypeRT', typeRT);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateRIR(obj, genRIR)
            obj.generateRIR = genRIR;
            obj.rpf_ini.SetValues('Global', 'generateRIR', genRIR);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateBRIR(obj, genBRIR)
            obj.generateBRIR = genBRIR;
            obj.rpf_ini.SetValues('Global', 'generateBRIR', genBRIR);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateISHOA(obj, genISHOA)
            obj.generateISHOA = genISHOA;
            obj.rpf_ini.SetValues('Global', 'generateISHOA', genISHOA);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateRTHOA(obj, genRTHOA)
            obj.generateRTHOA = genRTHOA;
            obj.rpf_ini.SetValues('Global', 'generateRTHOA', genRTHOA);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateISVBAP(obj, genISVBAP)
            obj.generateISVBAP = genISVBAP;
            obj.rpf_ini.SetValues('Global', 'generateISVBAP', genISVBAP);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateRTVBAP(obj, genRTVBAP)
            obj.generateRTVBAP = genRTVBAP;
            obj.rpf_ini.SetValues('Global', 'generateRTVBAP', genRTVBAP);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportFilter(obj, exportFilter)
            obj.exportFilter = exportFilter;
            obj.rpf_ini.SetValues('Global', 'exportFilter', exportFilter);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportHistogram(obj, exportHisto)
            obj.exportHistogram = exportHisto;
            obj.rpf_ini.SetValues('Global', 'exportHistogram', exportHisto);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportWallHitLog(obj, exportWallHitLog)
            obj.exportWallHitLog = exportWallHitLog;
            obj.rpf_ini.SetValues('Global', 'exportWallHitList', exportWallHitLog);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportPlaneWaveList(obj, exportPlaneWaveList)
            obj.exportPlaneWaveList = exportPlaneWaveList;
            obj.rpf_ini.SetValues('Global', 'exportPlaneWaveList', exportPlaneWaveList);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setAccelerationType(obj, accelerationType)
            obj.accelerationType = accelerationType;
Lukas Aspöck's avatar
Lukas Aspöck committed
1409
            obj.rpf_ini.SetValues('Global', 'AccelerationType', accelerationType);
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setLogPerformance(obj, logPerformance)
            obj.logPerformance = logPerformance;
            obj.rpf_ini.SetValues('Global', 'logPerformance', logPerformance);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setPortals(obj, portalTypes, portalStatus)
            if nargin < 3
                % if only 1 parameter is given (portalTypes), interprete
                % them as portal states! (more likely to be used like this)
                obj.rpf_ini.SetValues('Portals', 'portalStatus', obj.make_proper_string(portalTypes));     % 1 = open, 0 = closed
            else
                obj.rpf_ini.SetValues('Portals', 'portalType', portalTypes);
                obj.rpf_ini.SetValues('Portals', 'portalStatus', obj.make_proper_string(portalStatus));     % 1 = open, 0 = closed
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setTemperature(obj, temp)
            obj.rpf_ini.SetValues('Rooms', 'Temperature', num2str(temp));
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function temp = getTemperature(obj)
            temp = obj.rpf_ini.GetValues('Rooms', 'Temperature', -1);
        end
        
        %------------------------------------------------------------------
        function setHumidity(obj, humid)
            obj.rpf_ini.SetValues('Rooms', 'Humidity', num2str(humid));
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function humid = getHumidity(obj)
            humid = obj.rpf_ini.GetValues('Rooms', 'Humidity', -1);
        end
        
        %------------------------------------------------------------------
        function setPressure(obj, press)
            obj.rpf_ini.SetValues('Rooms', 'Pressure', num2str(press));
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function press = getPressure(obj)
            press = obj.rpf_ini.GetValues('Rooms', 'Pressure', -1);
        end
        
        %------------------------------------------------------------------
        function enableAirAbsorption(obj)
            obj.rpf_ini.SetValues('Rooms', 'noAirAbsorption', 0);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function disableAirAbsorption(obj)
            obj.rpf_ini.SetValues('Rooms', 'noAirAbsorption', 1);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
1478
1479
1480
        %------------------------------------------------------------------
        function airAbsEnabled = getAirAbsorptionEnabled(obj)
            airAbsEnabled = ~obj.rpf_ini.GetValues('Rooms', 'noAirAbsorption', 0);
1481
        end
1482
        
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
        % [PrimarySources] %
        %------------------------------------------------------------------
        function setSourceNames(obj, sourceNames)
            if iscell(sourceNames)
                obj.sourceNameString = obj.cat_cell_of_strings(sourceNames);
                obj.sourceNames      = sourceNames;
            else
                obj.sourceNameString = sourceNames;
                obj.sourceNames      = textscan(obj.sourceNameString, '%s', 'Delimiter', ',');
                obj.sourceNames      = obj.sourceNames{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            end
            obj.rpf_ini.SetValues('PrimarySources', 'sourceNames', obj.sourceNameString);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function directivityName = getSourceDirectivity(obj, srcID)
            
            readstring = obj.rpf_ini.GetValues('PrimarySources', 'sourceDirectivity', '');
            if ~isempty(readstring)
                
                readstring   = textscan(readstring, '%s', 'Delimiter', ',');
                readstring   = readstring{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
                if nargin<2
                    directivityName=readstring;
                else
                    directivityName=readstring(srcID);
                end
                
            else
                obj.sourceDirectivity   = {};
            end
            
            % %            Original
            %             if iscell(obj.sourceDirectivity)
            %                 directivityName = obj.sourceDirectivity{sourceID + 1};
            %             else
            %                 obj.sourceDirectivity   = textscan(obj.sourceDirectivityString, '%s', 'Delimiter', ',');
            %                 obj.sourceDirectivity   = obj.sourceDirectivity{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            %                 directivityName = obj.sourceDirectivity{sourceID + 1};
            %             end
        end
        
        %------------------------------------------------------------------
        function setSourceDirectivity(obj, directivity)
            if iscell(directivity)
                obj.sourceDirectivityString = obj.cat_cell_of_strings(directivity);
                obj.sourceDirectivity   = directivity;
            else
                obj.sourceDirectivityString = directivity;
1533
1534
1535
1536
                if ~isempty(directivity)
                    obj.sourceDirectivity   = textscan(obj.sourceDirectivityString, '%s', 'Delimiter', ',');
                    obj.sourceDirectivity   = obj.sourceDirectivity{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
                end
1537
1538
1539
1540
1541
            end
            obj.rpf_ini.SetValues('PrimarySources', 'sourceDirectivity', obj.sourceDirectivityString);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
1542
1543
1544
1545
1546
1547
1548
1549
1550
        
        %------------------------------------------------------------------
        function setSourceDirectivityPath(obj, myPath)
            %
            %   setSourceDirectivityPath(path)
            %
            %      Set the RAVEN source directivity database path. Here all
            %      directivities (.daff files) should be located
            %
1551
            %      To generate new files, check out opendaff in the
1552
1553
1554
1555
            %      \applications\VirtualAcoustics\openDAFF\
            %
            %      RAVEN currently only supports OpenDAFFv1.5 files
            %
1556
            obj.pathDirectivities = myPath;
1557
            obj.rpf_ini.SetValues('Global', 'ProjectPath_DirectivityDB', myPath);
1558
1559
1560
1561
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        
1562
1563
        %------------------------------------------------------------------
        function pos = getSourcePosition(obj, srcID)
1564
            
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
            all_pos = obj.rpf_ini.GetValues('PrimarySources', 'sourcePositions');
            if (nargin < 2)
                pos = reshape(all_pos',3,length(all_pos)/3)';
            else
                pos = all_pos((srcID*3 + 1) : (srcID*3 + 3));
            end
        end
        %------------------------------------------------------------------
        function setSourcePositions(obj, pos, coord_trafo)
            %setSourcePositions(pos, [coord_trafo])
            %   coord_trafo: 3-element vector
            %                1. element: which of the given axis to use as x-coordinates
            %                2. element: which of the given axis to use as y-coordinates
            %                3. element: which of the given axis to use as z-coordinates
            
            % if input is string convert to matrix
            if ischar(pos)
                pos = reshape(sscanf(pos, '%f,'), 3, numel(pos)/3)';
            end
            
            % if input is itaCoordinates convert to matrix
            if isa(pos, 'itaCoordinates')
                pos = pos.cart;
            end
            
            % check dimensions
            if size(pos, 2) ~= 3
                error('Positions must be given in vector (1x3) or matrix (Nx3) format.');
            end
            
            % store matrix in RavenProject object
            obj.sourcePositions = pos;
            
            % store positions in .rpf file on disk
            if nargin > 2
                obj.rpf_ini.SetValues('PrimarySources', 'sourcePositions', obj.make_proper_string( ...
                    [sign(coord_trafo(1)) .* pos(:, abs(coord_trafo(1))), ...
                    sign(coord_trafo(2)) .* pos(:, abs(coord_trafo(2))), ...
                    sign(coord_trafo(3)) .* pos(:, abs(coord_trafo(3)))] ));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourcePositions', obj.make_proper_string(pos));
            end
            
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceViewVectors(obj, view)
            obj.sourceViewVectors = view;
            if isnumeric(view) || iscell(view)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceViewVectors', obj.make_proper_string(view));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceViewVectors', view);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceUpVectors(obj, up)
            obj.sourceUpVectors = up;
            if isnumeric(up) || iscell(up)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceUpVectors', obj.make_proper_string(up));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceUpVectors', up);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceSoundStates(obj, state)
            obj.sourceSoundStates   = state;
            if isnumeric(state) || iscell(state)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundStates', obj.make_proper_string(state));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundStates', state);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceLevels(obj, levels)
            obj.sourceSoundLevels   = levels;
            if isnumeric(levels) || iscell(levels)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundLevels', obj.make_proper_string(levels));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundLevels', levels);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        % [Receiver] %
        %------------------------------------------------------------------
        function setReceiverNames(obj, rec_names)
            if iscell(rec_names)
                obj.receiverNameString = obj.cat_cell_of_strings(rec_names);
                obj.receiverNames      = rec_names;
            else
                obj.receiverNameString = rec_names;
                obj.receiverNames      = textscan(obj.receiverNameString, '%s', 'Delimiter', ',');
                obj.receiverNames      = obj.receiverNames{1}; % textscan liefer cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            end
            obj.rpf_ini.SetValues('Receiver', 'receiverNames', obj.receiverNameString);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function pos = getReceiverPosition(obj, recID)
            all_pos = obj.rpf_ini.GetValues('Receiver', 'receiverPositions');
            if (nargin < 2)
                pos = reshape(all_pos',3,length(all_pos)/3)';
            else
                pos = all_pos((recID*3 + 1) : (recID*3 + 3));
            end
        end
        
        %------------------------------------------------------------------
        function rvv = getReceiverViewVectors(obj, recID)
1682
            
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
            all_pos = obj.rpf_ini.GetValues('Receiver', 'receiverViewVectors');
            if (nargin < 2)
                rvv=reshape(all_pos',3,length(all_pos)/3)';
            else
                rvv = all_pos((recID*3 + 1) : (recID*3 + 3));
            end
        end
        
        %------------------------------------------------------------------
        function ruv = getReceiverUpVectors(obj, recID)
1693
            
1694
1695
1696
1697
1698
1699
1700
1701
1702
            all_pos = obj.rpf_ini.GetValues('Receiver', 'receiverUpVectors');
            if (nargin < 2)
                ruv = reshape(all_pos',3,length(all_pos)/3)';
            else
                ruv = all_pos((recID*3 + 1) : (recID*3 + 3));
            end
        end
        
        %------------------------------------------------------------------
1703
        function rss = getReceiverStates(obj,recID)
1704
1705
1706
1707
            rss = obj.rpf_ini.GetValues('Receiver', 'receiverStates', -1);
            if nargin==2
                rss=rss(recID);
            end
1708
        end
1709
        
1710
        %------------------------------------------------------------------
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
        function rn = getReceiverNames(obj,recID)
            rn = obj.rpf_ini.GetValues('Receiver', 'receiverNames', -1);
            rn = textscan(rn, '%s', 'Delimiter', ',');
            rn = rn{1};
            if nargin==2
                rn=rn{1}{recID};
            end
        end
        
        %------------------------------------------------------------------
        function setReceiverPositions(obj, pos, coord_trafo)
            %setReceiverPositions(pos, coord_trafo)
            %   coord_trafo: 3-element vector
            %                1. element: which of the given axis to use as x-coordinates
            %                2. element: which of the given axis to use as y-coordinates
            %                3. element: which of the given axis to use as z-coordinates
            
            % if input is string convert to matrix
            if ischar(pos)
                pos = reshape(sscanf(pos, '%f,'), 3, numel(pos)/3)';
            end
            
            % if input is itaCoordinates convert to matrix
            if isa(pos, 'itaCoordinates')
                pos = pos.cart;
            end
            
            % check dimensions
            if size(pos, 2) ~= 3
                error('Positions must be given in vector (1x3) or matrix (Nx3) format.');
            end
            
            % store matrix in RavenProject object
            obj.receiverPositions = pos;
            
            % store positions in .rpf file on disk
            if nargin > 2
                obj.rpf_ini.SetValues('Receiver', 'receiverPositions', obj.make_proper_string( ...
                    [sign(coord_trafo(1)) .* pos(:, abs(coord_trafo(1))), ...
                    sign(coord_trafo(2)) .* pos(:, abs(coord_trafo(2))), ...
                    sign(coord_trafo(3)) .* pos(:, abs(coord_trafo(3)))] ));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverPositions', obj.make_proper_string(pos));
            end
            
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setReceiverViewVectors(obj, view)
            obj.receiverViewVectors = view;
            if isnumeric(view) || iscell(view)
                obj.rpf_ini.SetValues('Receiver', 'receiverViewVectors', obj.make_proper_string(view));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverViewVectors', view);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setReceiverUpVectors(obj, up)
            obj.receiverUpVectors   = up;
            if isnumeric(up) || iscell(up)
                obj.rpf_ini.SetValues('Receiver', 'receiverUpVectors', obj.make_proper_string(up));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverUpVectors', up);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setReceiverStates(obj, states)
            obj.receiverStates = states;
            if isnumeric(states) || iscell(states)
                obj.rpf_ini.SetValues('Receiver', 'receiverStates', obj.make_proper_string(states));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverStates', states);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function directivityName = getReceiverHRTF(obj)
            directivityName = obj.rpf_ini.GetValues('Global', 'ProjectPath_HRTFDB');
        end
        
        %------------------------------------------------------------------
        function setReceiverHRTF(obj, HRTF)
            [pathHRTF,~,~] = fileparts(obj.fileHRTF);
            newFile = fullfile(pathHRTF, HRTF);
            
1802
            % check if file path is absolute or relative path
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
            % (if ':" is in path, path is absolute)
            if ~isempty(strfind(HRTF, ':'))
                newFile = HRTF;
            else
                newFile = fullfile(pathHRTF, HRTF);
            end
            
            if exist(newFile, 'file')
                obj.fileHRTF = newFile;
                obj.rpf_ini.SetValues('Global', 'ProjectPath_HRTFDB', obj.fileHRTF);
                obj.rpf_ini.WriteFile(obj.ravenProjectFile);
            else
                error(['File not found: ' newFile]);
            end
        end
        
        % [ImageSources] %
        %------------------------------------------------------------------
        function setISOrder_PS(obj, is_order)
1822
1823
1824
1825
1826
1827
            % setISOrder_PS
            % sets image source order
            % -1  = disabled
            %  0  = direct sound only
            %  N  = for N>1 : image source calculation up to order N
            % Do not set above 4, especially for complex models
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
            obj.ISOrder_PS          = is_order;
            obj.rpf_ini.SetValues('ImageSources', 'ISOrder_PS', is_order);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setISOrder_SS(obj, is_order)
            obj.ISOrder_SS          = is_order;
            obj.rpf_ini.SetValues('ImageSources', 'ISOrder_SS', is_order);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSkipDirectSound(obj, skipit)
            obj.ISSkipDirectSound   = skipit;
            obj.rpf_ini.SetValues('ImageSources', 'ISSkipDirectSound', skipit);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        % [RayTracing] %
        %------------------------------------------------------------------
        function setNumParticles(obj, num_particles)
            obj.numParticles_Sphere = num_particles;
            obj.rpf_ini.SetValues('RayTracing', 'numberOfParticles_DetectionSphere', num_particles);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setNumParticles_Portal(obj, num_particles)
            obj.numParticles_Portal = num_particles;
            obj.rpf_ini.SetValues('RayTracing', 'numberOfParticles_Portal', num_particles);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
Philipp Schäfer's avatar
Philipp Schäfer committed
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
        %------------------------------------------------------------------
        function setFixReflectionPattern(obj, fixit)
            obj.fixReflectionPattern = fixit;
            obj.rpf_ini.SetValues('RayTracing', 'fixReflectionPattern', fixit);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %--------------