From 4c3453f28629bee30f19a06fdc32c9d0d0f7c69e Mon Sep 17 00:00:00 2001 From: Janick Martinez Esturo Date: Wed, 14 May 2014 23:22:59 +0200 Subject: [PATCH] Code cleanup --- Deform2DConformal.m | 2 - Deform2DFinite.m | 2 - TriSystemTikhonovGradientEnergy.m | 4 +- util/CholConstrSolver.m | 2 +- util/LagrConstrSolver.m | 6 +-- util/readMesh.m | 62 +++++++++++++-------------- util/readOBJ.m | 70 ++++++++++++++++--------------- util/readOFF.m | 2 + 8 files changed, 75 insertions(+), 75 deletions(-) diff --git a/Deform2DConformal.m b/Deform2DConformal.m index 85802b7..75f1190 100644 --- a/Deform2DConformal.m +++ b/Deform2DConformal.m @@ -62,7 +62,5 @@ function init(obj, hidxs) mesh.p = reshape(u,2,[]); end - end - end diff --git a/Deform2DFinite.m b/Deform2DFinite.m index 5f8d691..04aa09d 100644 --- a/Deform2DFinite.m +++ b/Deform2DFinite.m @@ -90,7 +90,5 @@ function init(obj, hidxs) obj.mesh.p = reshape(u,2,[]); end - end - end diff --git a/TriSystemTikhonovGradientEnergy.m b/TriSystemTikhonovGradientEnergy.m index f2203d0..0f23ec6 100644 --- a/TriSystemTikhonovGradientEnergy.m +++ b/TriSystemTikhonovGradientEnergy.m @@ -43,8 +43,8 @@ % beta - smoothing factor in [0,1] % en - number of quadratic error components per triangle % d - dimension of unknown coefficients at vertices - % c - number of independent functions to setup system rhs for in - % pure quadratic case (defaults to 1) + % c - number of independent functions to setup system rhs + % (defaults to 1) if nargin < 6, c = 1; end diff --git a/util/CholConstrSolver.m b/util/CholConstrSolver.m index b35be56..0bca23e 100644 --- a/util/CholConstrSolver.m +++ b/util/CholConstrSolver.m @@ -59,7 +59,7 @@ b=obj.b; end - b(obj.cidxs,:)=[]; %correct? + b(obj.cidxs,:)=[]; b=b-obj.A01*constr; y=obj.L00'\(obj.L00\b(obj.cholPerm,:)); diff --git a/util/LagrConstrSolver.m b/util/LagrConstrSolver.m index d590bc8..2e23d52 100644 --- a/util/LagrConstrSolver.m +++ b/util/LagrConstrSolver.m @@ -26,9 +26,9 @@ methods function obj = LagrConstrSolver(E,A_or_cidxs,b) %% Constructor - % minimizes f(x) = 1/2*x'*E*x - x'*b + d s.t. A*x=c using - % lagrange multipliers. - % If cidxs are given A is a corresponding identity matrix. + % Minimizes f(x) = 1/2*x'*E*x - x'*b + d s.t. A*x=c using + % Lagrange multipliers. + % If cidxs are given A is a corresponding identity matrix. if nargin > 2 && ~isempty(b), obj.b=b; diff --git a/util/readMesh.m b/util/readMesh.m index 4543d7c..897308b 100644 --- a/util/readMesh.m +++ b/util/readMesh.m @@ -1,37 +1,37 @@ function [p,t,uv] = readMesh(filename) -% read in vertices and faces from a .off or .obj file -% Input: -% filename file holding mesh -% Output: -% p (vertex list) -% t (face list) -% uv (texture coordinates list) -% -% Copyright 2011, Alec Jacobson (jacobson@inf.ethz.ch) -% -% See also: readOBJ, readOBJfast, readOFF -% -uv = []; + % read in vertices and faces from a .off or .obj file + % Input: + % filename file holding mesh + % Output: + % p (vertex list) + % t (face list) + % uv (texture coordinates list) + % + % Copyright 2011, Alec Jacobson (jacobson@inf.ethz.ch) + % + % See also: readOBJ, readOBJfast, readOFF + % + uv = []; -if ~isempty(regexp(filename,'\.off$')) - [V,F] = readOFF(filename); -elseif ~isempty(regexp(filename,'\.obj$')) - if nargout > 2, - [V,F,UV] = readOBJ(filename); - uv = UV'; - else - try - [V,F] = readOBJfast(filename); - catch exception - fprintf('Fast reader failed, retrying with more robust, slower reader\n'); - [V,F] = readOBJ(filename); + if ~isempty(regexp(filename,'\.off$')) + [V,F] = readOFF(filename); + elseif ~isempty(regexp(filename,'\.obj$')) + if nargout > 2, + [V,F,UV] = readOBJ(filename); + uv = UV'; + else + try + [V,F] = readOBJfast(filename); + catch exception + fprintf('Fast reader failed, retrying with more robust, slower reader\n'); + [V,F] = readOBJ(filename); + end end + else + error('Input file must be .off or .obj file.'); end -else - error('Input file must be .off or .obj file.'); -end -% adapt to our convention -p = V'; -t = F'; + % adapt to our convention + p = V'; + t = F'; end diff --git a/util/readOBJ.m b/util/readOBJ.m index acb0000..6a3fa19 100644 --- a/util/readOBJ.m +++ b/util/readOBJ.m @@ -14,42 +14,44 @@ % WARNING: This is at least 40 times slower than readOFF but probably much much % slower... % + % Copyright 2011, Alec Jacobson (jacobson@inf.ethz.ch) + % % See also: load_mesh, readOBJfast, readOFF -V = []; -UV = []; -F = []; -fp = fopen( filename, 'r' ); -type = fscanf( fp, '%s', 1 ); -while strcmp( type, '' ) == 0 - if strcmp( type, 'v' ) == 1 - v = fscanf( fp, '%g %g %g\n' ); - V = [V; v']; - elseif strcmp( type, 'vt') - v = fscanf( fp, '%g %g %g\n' ); - UV = [UV; v']; - elseif strcmp( type, 'f' ) == 1 - line = fgets(fp); - [t, count] = sscanf(line, '%d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d'); + V = []; + UV = []; + F = []; + fp = fopen( filename, 'r' ); + type = fscanf( fp, '%s', 1 ); + while strcmp( type, '' ) == 0 + if strcmp( type, 'v' ) == 1 + v = fscanf( fp, '%g %g %g\n' ); + V = [V; v']; + elseif strcmp( type, 'vt') + v = fscanf( fp, '%g %g %g\n' ); + UV = [UV; v']; + elseif strcmp( type, 'f' ) == 1 + line = fgets(fp); + [t, count] = sscanf(line, '%d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d'); - if (count>2) - t = t(1:3:end); - else - [t, count] = sscanf(line, '%d/%d %d/%d %d/%d %d/%d %d/%d'); - if (count>2) - t = t(1:2:end); - else - [t, count] = sscanf( line, '%d %d %d %d %d %d %d %d %d %d %d\n' ); - end - end - F = [F; t']; - elseif strcmp( type, '#' ) == 1 - fscanf( fp, '%s\n', 1 ); - end - type = fscanf( fp, '%s', 1 ); -end -fclose( fp ); + if (count>2) + t = t(1:3:end); + else + [t, count] = sscanf(line, '%d/%d %d/%d %d/%d %d/%d %d/%d'); + if (count>2) + t = t(1:2:end); + else + [t, count] = sscanf( line, '%d %d %d %d %d %d %d %d %d %d %d\n' ); + end + end + F = [F; t']; + elseif strcmp( type, '#' ) == 1 + fscanf( fp, '%s\n', 1 ); + end + type = fscanf( fp, '%s', 1 ); + end + fclose( fp ); -%% transform into array if all faces have the same number of vertices -if (size(UV,1)>0) UV = UV; end + %% transform into array if all faces have the same number of vertices + if (size(UV,1)>0) UV = UV; end end diff --git a/util/readOFF.m b/util/readOFF.m index a6a0ecf..0bcedbf 100644 --- a/util/readOFF.m +++ b/util/readOFF.m @@ -21,6 +21,8 @@ % C #V by 3 list of colors % N #V by 3 list of normals % + % Copyright 2011, Alec Jacobson (jacobson@inf.ethz.ch) + % % See also: load_mesh, readOBJfast, readOBJ V = [];