diff --git a/src/matlab/LRNURBSSurface.m b/src/matlab/LRNURBSSurface.m index f35621c..f4b7175 100644 --- a/src/matlab/LRNURBSSurface.m +++ b/src/matlab/LRNURBSSurface.m @@ -32,7 +32,10 @@ % contourf - Plot a contour mesh of a given scalar field % plot - Plot the mesh structure % print - Prints raw c++ lr data structure +<<<<<<< HEAD % tikz - Output vector graphics tikz figure +======= +>>>>>>> parent of 7f55efc... Added functionality to output lrspline to a vector graphics tikz figure. % save - Saves the backend c++ lr data to file % load - Loads the backend c++ lr data from file @@ -115,19 +118,8 @@ function delete(this) newHandle = lrsplinesurface_interface('copy', this.objectHandle); copyObject = LRNURBSSurface(); copyObject.setHandle(newHandle) - end - - function tikz(this, filename) - % export_to_tikz saves the LR-spline object to to a tex-tikz file - % - % parameters: - % filename - the name of the file - if ~strcmp(class(filename), 'char') - throw(MException('LRSplineSurface:export_to_tikz', 'Error: Invalid file name')); - end - lrsplinesurface_tikz(this, filename); end - + function save(this, filename) % SAVE Dumps the backend c++ representation of this LR-spline object to file % LRNURBSSurface.save(filename) diff --git a/src/matlab/LRSplineSurface.m b/src/matlab/LRSplineSurface.m index e930252..f19a5e1 100644 --- a/src/matlab/LRSplineSurface.m +++ b/src/matlab/LRSplineSurface.m @@ -37,7 +37,10 @@ % contourf - Plot a contour mesh of a given scalar field % plot - Plot the mesh structure % print - Prints raw c++ lr data structure +<<<<<<< HEAD % tikz - Output vector graphics tikz figure +======= +>>>>>>> parent of 7f55efc... Added functionality to output lrspline to a vector graphics tikz figure. % save - Saves the backend c++ lr data to file % load - Load the backend c++ lr data from file % loadG2 - Load the backend c++ lr data from file @@ -123,17 +126,6 @@ function delete(this) newHandle = lrsplinesurface_interface('copy', this.objectHandle); copyObject = LRSplineSurface(); copyObject.setHandle(newHandle); - end - - function tikz(this, filename) - % export_to_tikz saves the LR-spline object to to a tex-tikz file - % - % parameters: - % filename - the name of the file - if ~strcmp(class(filename), 'char') - throw(MException('LRSplineSurface:export_to_tikz', 'Error: Invalid file name')); - end - lrsplinesurface_tikz(this, filename); end function save(this, filename) diff --git a/src/matlab/lrgui.m b/src/matlab/lrgui.m index 28073fd..dbedce1 100644 --- a/src/matlab/lrgui.m +++ b/src/matlab/lrgui.m @@ -8,36 +8,35 @@ % Create and then hide the GUI as it is being constructed. f = figure('Visible','off','Position',[360,500,450,325]); - % Construct the components. + % Construct the components. hnew = uicontrol('Style','pushbutton','String','New',... - 'Position',[315,250,70,20],... + 'Position',[315,240,70,25],... 'Callback',@newbutton_Callback); hrefine = uicontrol('Style','pushbutton',... 'String','Refine',... - 'Position',[315,220,70,20],... - 'Callback',@refinebutton_Callback); - hraise = uicontrol('Style','pushbutton',... - 'String','Raise Order',... - 'Position',[315,190,70,20],... - 'Callback',@raisebutton_Callback); + 'Position',[315,200,70,25],... + 'Callback',@refinebutton_Callback); hload = uicontrol('Style','pushbutton','String','Load',... - 'Position',[315,160,70,20],... + 'Position',[315,160,70,25],... 'Callback',@loadbutton_Callback); hsave = uicontrol('Style','pushbutton','String','Save',... - 'Position',[315,130,70,20],... + 'Position',[315,120,70,25],... 'Callback',@savebutton_Callback); - htikz = uicontrol('Style','pushbutton','String','Tikz',... - 'Position',[315,100,70,20],... - 'Callback',@tikzbutton_Callback); htext = uicontrol('Style','text','String','Refinement strategy',... - 'Position',[300,40,80,35]); + 'Position',[300,60,80,35]); hpopup = uicontrol('Style','popupmenu',... 'String',{'Elements','Functions'},... 'Position',[300,30,100,25],... 'Callback',@popup_menu_Callback); +<<<<<<< HEAD ha = axes('Units','Pixels','Position',[50,60,200,185]); align([hnew,hrefine,hraise,hload,hsave,htikz,htext,hpopup],'Center','None'); +======= + ha = axes('Units','Pixels','Position',[50,60,200,185]); + align([hnew,hrefine,hload,hsave,htext,hpopup],'Center','None'); + +>>>>>>> parent of 7f55efc... Added functionality to output lrspline to a vector graphics tikz figure. % Create the data to plot. current_mesh = LRSplineSurface([3,3], [10,10]); @@ -48,7 +47,6 @@ ha.Units = 'normalized'; hnew.Units = 'normalized'; hload.Units = 'normalized'; - htikz.Units = 'normalized'; hsave.Units = 'normalized'; hrefine.Units = 'normalized'; hraise.Units = 'normalized'; @@ -140,14 +138,6 @@ function savebutton_Callback(source,eventdata) end end - function tikzbutton_Callback(source,eventdata) - % Display mesh plot of the currently selected data. - [file path] = uiputfile('out.tex'); - if file ~= 0 - current_mesh.tikz([path,file]); - end - end - % Keyboard callbacks (hotkeys) function keypress(src, e) switch e.Key @@ -165,8 +155,6 @@ function keypress(src, e) loadbutton_Callback(src, e); case 's' savebutton_Callback(src, e); - case 't' - tikzbutton_Callback(src, e); case 'n' newbutton_Callback(src, e); end diff --git a/src/matlab/lrsplinesurface_tikz.m b/src/matlab/lrsplinesurface_tikz.m deleted file mode 100644 index 26dd686..0000000 --- a/src/matlab/lrsplinesurface_tikz.m +++ /dev/null @@ -1,476 +0,0 @@ -function lrsplinesurface_tikz(lrsplinesurface, filename) - -% initialize -check_filename_extension(filename); % check that input is a .tex file -write_preamble(); % write the new commands to a file: preamble.tex - -% write data to .dat file -datafile = strcat(filename(1:end-4),'.dat'); -fileID = fopen(datafile,'w'); -write_data_to_texfile(fileID, lrsplinesurface); -fclose(fileID); - -% write main \tikz file -fileID = fopen(filename,'w'); - -% create document, load preamble and data -fprintf(fileID,'%s\n\n','\documentclass[crop=true,a4paper]{standalone}'); -fprintf(fileID,'%s\n\n','\input{preamble.tex}'); % include preamble -fprintf(fileID,'%s%s%s\n\n','\input{',datafile,'}'); % add data to file - -fprintf(fileID,'%s\n %s\n %s\n\n','\def\tkzscale{10.0}',... - '\def\dirdata{../data}',... - '\tikzexternaldisable'); - -% write main user-defined parameters -write_userinput_to_tikzfile(fileID); - -% begin new document -fprintf(fileID,'%s\n\n','\begin{document}'); - -% initialize tikz picture settings -fprintf(fileID,'%s\n %s\n %s\n %s\n\n\n',... - '\begin{tikzpicture}[scale=\tkzscale, ',... - 'every node/.style={font=\tikzfontsize},',... - 'nonactive/.style={loosely dotted},',... - 'x=\sizeX,y=\sizeY]'); - -fprintf(fileID,'%s\n%s\n\n',... - '% define active area',... - '\clip (\aX-0.05*\bX+0.05*\aX, \aY-0.05*\bY+0.05*\aY) rectangle ( \bX+0.05*\bX-0.05*\aX, \bY+0.05*\bY-0.05*\aY);'); - -write_drawing_to_tikzfile(fileID, lrsplinesurface); - -% close file -fprintf(fileID,'%s\n','\end{tikzpicture}'); -fprintf(fileID,'%s\n','\end{document}'); -fclose(fileID); - -end - -% check filename extension -function check_filename_extension(filename) - if strcmp(filename(end-3:end),'.tex') - % continue - else - error('Filename should have the extension .tex'); - end -end - -% write new commands to newcommands.tex -function write_preamble() - - filename = 'preamble.tex'; - if isfile(filename) - % do nothing - % if file does not exist create new file with commands - else - % open file - fileID = fopen(filename,'w'); - - % load packages - fprintf(fileID,'%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n',... - '%%%%%%%%%%%%%%%%%% load packages %%%%%%%%%%%%%%%%%%%%',... - '\usepackage{tikz}',... - '\usepackage{tikzscale}',... - '\usepackage{standalone} % for standalone compilation of tikz graphics',... - '\usepackage{listofitems}',... - '\usepackage[utf8]{inputenc} % for UTF-8 encoding',... - '\usepackage[german,english]{babel}',... - '\usepackage{lmodern} % latin modern fonts - added to resolve visualization issues with fontenc',... - '\usepackage[intlimits]{amsmath}',... - '\usepackage{amssymb} ',... - '\usepackage{amsthm}',... - '\usepackage{amsfonts,mathrsfs}',... - '\usepackage{xcolor}'); - - % load tikz functionality - fprintf(fileID,'%s\n%s\n%s\n%s\n\n',... - '%%%%%%%%%%%%%%%%%% tikz %%%%%%%%%%%%%%%%%%%%',... - '\usetikzlibrary{external,calc,math,shapes,spy,fit}',... - '\tikzexternalize[optimize command away=\includepdf]',... - '\tikzsetexternalprefix{tmp/}'); - - fprintf(fileID,'%s\n%s\n%s\n%s\n%s\n%s\n\n',... - '%%% Font size in plots and graphics',... - '\def\pgfplotfontsizetitle{\small}',... - '\def\pgfplotfontsize{\footnotesize}',... - '\def\tikzfontsize{\small}',... - '\def\tikzfontsizesmall{\footnotesize}',... - '\def\tikzfontsizetiny{\scriptsize}'); - - fprintf(fileID,'%s\n%s\n\n',... - '% create a new list by indexing an existing multidimensional list.',... - '\newcommand{\itemtolist}[2]{\itemtomacro#1\tmp; \readlist#2\tmp;}'); - - fprintf(fileID,'%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n',... - '% sum a list of integers',... - '\newcommand{\listsumtruncatemacro}[2]{',... - '\def\s{0}',... - '\foreachitem \MyLocalMu \in #1{',... - ' \pgfmathtruncatemacro{\s}{\s+\MyLocalMu}',... - '}',... - '\pgfmathsetmacro{#2}{\s}',... - '}'); - - fprintf(fileID,'%s\n%s\n%s\n%s\n%s\n%s\n\n',... - '% difference between two list entries',... - '\newcommand{\listdiffmacro}[3]{',... - '\itemtomacro#1\ua',... - '\itemtomacro#2\ub',... - '\pgfmathsetmacro{#3}{\ub - \ua}',... - '}'); - - % Command that draws u-knots of a lr-spline - fprintf(fileID,'%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n',... - '\newcommand{\plotuknot}[5]{',... - '\draw [knotline=#5] (#1,#2) -- (#1-#4*\mudistance+\mudistance,#2);',... - '\foreach \i in {1,...,#4}',... - '{',... - ' \pgfmathparse{#1-(\i-1)*\mudistance} \let\uu\pgfmathresult;',... - ' \draw [knotline=#5] (\uu,#2) -- (\uu,#3);',... - '}',... - '\draw [knotline=#5] (#1,#3) -- (#1-#4*\mudistance+\mudistance,#3);',... - '}'); - - % Command that draws v-knots of a lr-spline - fprintf(fileID,'%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n',... - '\newcommand{\plotvknot}[5]{',... - '\draw [knotline=#5] (#2,#1) -- (#2,#1-#4*\mudistance+\mudistance);',... - '\foreach \i in {1,...,#4}',... - '{',... - ' \pgfmathparse{#1-(\i-1)*\mudistance} \let\vv\pgfmathresult;',... - ' \draw [knotline=#5] (#2,\vv) -- (#3,\vv);',... - '}',... - '\draw [knotline=#5] (#3,#1) -- (#3,#1-#4*\mudistance+\mudistance);',... - '}'); - - % draw all u and v knot lines with multiplicity distance s - fprintf(fileID,'%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n',... - '\newcommand{\plotknotlines}[4]{',... - '\listsumtruncatemacro{#2}{\p}',... - '\listsumtruncatemacro{#4}{\q}',... - '\pgfmathsetmacro{\m}{\listlen#1[]}',... - '\pgfmathsetmacro{\n}{\listlen#3[]}',... - '\pgfmathsetmacro{\vstart}{#3[1]-\mudistance*#4[1]+\mudistance};',... - '\pgfmathsetmacro{\vstop}{#3[\n]};',... - '\pgfmathsetmacro{\ustart}{#1[1]-\mudistance*#2[1]+\mudistance};',... - '\pgfmathsetmacro{\ustop}{#1[\m]};',... - '\foreach \i in {1,...,\m}{',... - ' \pgfmathsetmacro{\uu}{#1[\i]};',... - ' \pgfmathsetmacro{\mm}{#2[\i]};',... - ' \plotuknot{\uu}{\vstart}{\vstop}{\mm}{\p-2};',... - '}',... - '\foreach \i in {1,...,\n}{',... - ' \pgfmathsetmacro{\vv}{#3[\i]};',... - ' \pgfmathsetmacro{\nn}{#4[\i]};',... - ' \plotvknot{\vv}{\ustart}{\ustop}{\nn}{\q-2};',... - '}',... - '}'); - fclose(fileID); - end -end - -% write data to .dat file -function write_data_to_texfile(fileID, lrsplinesurface) - - % initialize - p = lrsplinesurface.p; - kts = lrsplinesurface.knots; - cp = lrsplinesurface.cp'; - elements = lrsplinesurface.elements; - support = lrsplinesurface.support; - - m = size(p,1); % number of elements - n = size(cp,1); % number of basis functions - - % determine size of the supports - d = zeros(n,1); - for k=1:n - s = kts{k,1}(end)-kts{k,1}(1); - t = kts{k,2}(end)-kts{k,2}(1); - d(k) = s * t; - end - [~,I] = sort(d,'descend'); [~,J] = sort(I); - - % print list of degrees - fprintf(fileID,'%s\n%s\n',... - '\setsepchar{,}',... - '\readlist\degree{'); - for k=1:m - fprintf(fileID,'%d,',p(k,1)); - end - fprintf(fileID,'}\n\n'); - - % print list of elements - A = elements(1,1:2); B = elements(1,1:2); - fprintf(fileID,'%s\n%s\n',... - '\setsepchar[ ]{/ ;}',... - '\readlist\element{'); - for k=1:m - a = elements(k,1:2); % lower-left corner - b = elements(k,3:4); % upper-right corner - - if (a(1)