Commit 738a7bf0 authored by Ernesto Accolti's avatar Ernesto Accolti Committed by Ernesto Accolti

Added method to create room models using a Points matrix and a Faces cell array

parent 16483a5e
......@@ -839,8 +839,85 @@ classdef itaRavenProject < handle
obj.setModel(outputFilePath);
end
%------------------------------------------------------------------
function [outputFilePath] = setModelToFaces(obj,points,faces,materials)
% setModelToSArbitrary
% creates a room model using points and faces and automatically
% 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)
% faces (cell array, faces are defined pointing to the rows
% 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 ];
end
fid = fopen(outputFilePath,'w');
fprintf(fid,'AC3Db\n');
for iW=1:nW
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
fprintf(fid,[sprintf('%1.4f %1.4f %1.4f',points(faces{iW}(iP+1),:)) '\n']);
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
%------------------------------------------------------------------
function plotModel(obj, tgtAxes, comp2axesMapping, wireframe)
if isempty(obj.modelFileList)
return;
......
%% RAVEN simulation: Example for creating a room model specifying points
% and planes
% Author: eac@akustik.rwth-aachen.de
% date: 2020/01/07
%
% <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>
%% project settings
projectName = 'my_6_faces';
h1=10; h2 = 4;
w1=14; w2 =24;
l = 30;
% Example shape: Fan shape
points=[-w1/2 0 h1-h2; w1/2 0 h1-h2; w2/2 l 0; -w2/2 l 0; -w2/2 l h1; ...
w2/2 l h1; w1/2 0 h1; -w1/2 0 h1];
faces={[5 4 3 2 1];[1 8 7 6 5];[2 1 2 7 8];[3 3 4 5 6];[4 2 3 6 7]; ...
[6 1 8 5 4]};
for i=1:length(faces)
faces{i}(2:end)=fliplr(faces{i}(2:end));
end
materials={'ceiling';'backwall';'frontwall';'sidewall1';'floor';'sidewall2';};
nM=length(materials);
%% Create project and set input data
rpf = itaRavenProject('C:\ITASoftware\Raven\RavenInput\Classroom\Classroom.rpf'); % modify path if not installed in default directory
rpf.copyProjectToNewRPFFile(['C:\ITASoftware\Raven\RavenInput\' projectName '.rpf' ]);
rpf.setProjectName(projectName);
rpf.setModelToFaces(points,faces,materials)
% source and receiver
hs=1.2; %source height
hr=1.2; %receiver height
rpf.setSourcePositions([0.1*w2 3 (h1-h2)-(h1-h2)/l*(3) + hs])
rpf.setReceiverPositions([0.1*w1 l-5 (h1-h2)-(h1-h2)/l*(l-5) + hr])
% Coefficients
for iMat=1:nM
myAbsorp = 0.1 * ones(1,31);
myScatter = 0.1 * ones(1,31);
rpf.setMaterial(rpf.getRoomMaterialNames{iMat},myAbsorp,myScatter);
end
%% set simulation parameters
rpf.setGenerateRIR(1);
rpf.setGenerateBRIR(1);
rpf.setSimulationTypeRT(1);
rpf.setSimulationTypeIS(1);
rpf.setNumParticles(50000);
rpf.setISOrder_PS(2);
%% run simulation
rpf.run
%% plot results
rpf.plotSphereEnergy();
RIR = rpf.getMonauralImpulseResponseItaAudio;
RIR.ptd;
T30 = rpf.getT30;
figure;
semilogx(rpf.freqVectorOct,T30','LineWidth',1.5,'Marker','x');
grid on;ylabel('T30 in s');xlabel('Frequency in Hz');
title('T30 of two shoebox rooms');xlim([20 20000]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment