tp@0: function [edgepointcoords,weightvec,edgenumberlist] = EDB1getedgepoints(edgestartcoords,edgeendcoords,edgelengths,nedgesubs,returnedgenumbers) tp@0: % EDB1getedgepoints - Calculates a number of edge coordinates. tp@0: % tp@0: % Input parameters: tp@0: % edgestartcoords Matrix, [nedges,3], of the startpoint coordinates of nedges edges. tp@0: % edgeendcoords Matrix, [nedges,3], of the endpoint coordinates of nedges edges. tp@0: % edgelengths List, [nedges,1], of edge lengths. tp@0: % nedgesubs The desired number of subdivisions per edge. tp@0: % returnedgenumbers (optional) If this optional parameter is given the tp@0: % value 1, the output parameter edgenumberlist will be non-empty. tp@0: % tp@0: % NB! The input parameters edgestartcoords, edgeendcoords and edgelengths tp@0: % should have been passed on directly from the eddata file. tp@0: % The parameter nedgesubs should have been taken from the setup file. tp@0: % tp@0: % Output parameters: tp@0: % edgepointcoords Matrix, [nedges*nedgesubs,3], of the midpoints tp@0: % of the edge subdivision segments. tp@0: % weightvec List, [nedges*nedgesubs,3], with the weights tp@0: % (1,2,4,8,...) per edge subdivision segment. tp@0: % edgenumberlist List, [nedges*nedgesubs,1], of which edge tp@0: % number each subdivision segment originated from. tp@0: % See also the input parameter returnedgenumbers. tp@0: % tp@0: % ---------------------------------------------------------------------------------------------- tp@0: % This file is part of the Edge Diffraction Toolbox by Peter Svensson. tp@0: % tp@0: % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify tp@0: % it under the terms of the GNU General Public License as published by the Free Software tp@0: % Foundation, either version 3 of the License, or (at your option) any later version. tp@0: % tp@0: % The Edge Diffraction Toolbox is distributed in the hope that it will be useful, tp@0: % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS tp@0: % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. tp@0: % tp@0: % You should have received a copy of the GNU General Public License along with the tp@0: % Edge Diffraction Toolbox. If not, see . tp@0: % ---------------------------------------------------------------------------------------------- tp@0: % Peter Svensson (svensson@iet.ntnu.no) 20030503 tp@0: % tp@0: % [edgepointcoords,weightvec,edgenumberlist] = EDB1getedgepoints(edgestartcoords,edgeendcoords,edgelengths,nedgesubs,returnedgenumbers); tp@0: tp@0: if nargin < 5 tp@0: returnedgenumbers = 0; tp@0: end tp@0: tp@0: [nedges,slask] = size(edgestartcoords); tp@0: tp@0: if nedgesubs == 1 tp@0: edgepointcoords = (edgestartcoords+edgeendcoords)/2; tp@0: weightvec = uint8(ones(nedges,1)); tp@0: if returnedgenumbers == 1 tp@0: if nedges < 256 tp@0: edgenumberlist = uint8([1:nedges]); tp@0: elseif nedges < 65536 tp@0: edgenumberlist = uint16([1:nedges]); tp@0: else tp@0: edgenumberlist = uint32([1:nedges]); tp@0: end tp@0: else tp@0: edgenumberlist = []; tp@0: end tp@0: return tp@0: end tp@0: tp@0: ntot = nedges*nedgesubs; tp@0: tp@0: edgestart = zeros(ntot,3); tp@0: edgeend = zeros(ntot,3); tp@0: tp@0: onesvec1 = ones(nedgesubs,1); tp@0: onesvec2 = ones(1,3); tp@0: onesvec3 = ones(1,nedges); tp@0: tp@0: %------------------------------------------------- tp@0: % Start points tp@0: tp@0: A = edgestartcoords(:,1).'; tp@0: edgestart(:,1) = reshape(A(onesvec1,:),ntot,1); tp@0: tp@0: A = edgestartcoords(:,2).'; tp@0: edgestart(:,2) = reshape(A(onesvec1,:),ntot,1); tp@0: tp@0: A = edgestartcoords(:,3).'; tp@0: edgestart(:,3) = reshape(A(onesvec1,:),ntot,1); tp@0: tp@0: %------------------------------------------------- tp@0: % End points tp@0: tp@0: A = edgeendcoords(:,1).'; tp@0: edgeend(:,1) = reshape(A(onesvec1,:),ntot,1); tp@0: tp@0: A = edgeendcoords(:,2).'; tp@0: edgeend(:,2) = reshape(A(onesvec1,:),ntot,1); tp@0: tp@0: A = edgeendcoords(:,3).'; tp@0: edgeend(:,3) = reshape(A(onesvec1,:),ntot,1); tp@0: tp@0: %------------------------------------------------------------ tp@0: % Spread the edge points along the edge, including the end tp@0: % points, but nudge them in a bit. tp@0: tp@0: displacement = 1e-1; tp@0: tp@0: edgedividervec = [displacement 1:nedgesubs-2 nedgesubs-1-displacement].'/(nedgesubs-1); tp@0: edgedividervec = reshape(edgedividervec(:,onesvec3),ntot,1); tp@0: tp@0: edgepointcoords = edgestart + (edgeend - edgestart).*edgedividervec(:,onesvec2); tp@0: tp@0: %------------------------------------------------------------ tp@0: % Extra output data tp@0: tp@0: if nedgesubs < 8 tp@0: weightvec = uint8(2.^[0:nedgesubs-1].'); tp@0: elseif nedgesubs < 16 tp@0: weightvec = uint16(2.^[0:nedgesubs-1].'); tp@0: else tp@0: weightvec = uint32(2.^[0:nedgesubs-1].'); tp@0: end tp@0: tp@0: weightvec = reshape(weightvec(:,onesvec3),ntot,1); tp@0: tp@0: if returnedgenumbers == 1 tp@0: if nedges < 256 tp@0: edgenumberlist = uint8([1:nedges]); tp@0: elseif nedges < 65536 tp@0: edgenumberlist = uint16([1:nedges]); tp@0: else tp@0: edgenumberlist = uint32([1:nedges]); tp@0: end tp@0: edgenumberlist = reshape(edgenumberlist(onesvec1,:),ntot,1); tp@0: else tp@0: edgenumberlist = []; tp@0: end