aboutsummaryrefslogtreecommitdiff
path: root/beam_trace.m
blob: 0896975235d6063eccded27c8a9c50e9ae1f404a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function img = beam_trace(beams, faces, borders, border_limits, img)
	%% trace beam and all it reflections and refractions on faces
	% for beams and faces structure description see face_beam_interaction.m
	% border similar to faces cell array which enclose the beam
	% i.e. it does not leave the polygon consisting of border faces

	intensity_threshold = 1e-3; % intensity of the weakest beam which we still trace

	Nbeams=size(beams)(2);
	if ( Nbeams == 0 )
		% no more beam to trace
		return;
	end

	% trace each beam in beams cell array
	for i=1:Nbeams
		beam=beams{i};
		[is_face_hit, hit_position, hit_distance, new_beams] =  face_beam_interaction(beam, faces);
		if (is_face_hit)
			%% remove beams which are to weak to trace
			N_new_beams=size(new_beams)(2);
			intense_enough_beams={};
			intense_beams_counter=0;
			for k=1:N_new_beams
				if ( new_beams{k}.intensity >= intensity_threshold )
					intense_beams_counter=intense_beams_counter + 1;
					intense_enough_beams{intense_beams_counter}=new_beams{k};
				end
			end
			img = beam_trace(intense_enough_beams, faces, borders, border_limits, img);
		else
			% beam does not hit face but it should stop and borders
			beam.face=NA;
			[is_face_hit, hit_position, hit_distance, new_beams] =  face_beam_interaction(beam, borders);
			if (!is_face_hit)
				error('borders are badly defined, the beam misses them');
			end
		end
		img=make_beam_trace(beam, hit_position, border_limits, img);
	end
end