CSS 455 Scientific Programming



CSS 455 Scientific ProgrammingMachine Problem #3 MP3Reproducing Line Drawings with piecewise cubic spline and cubic Hermite interpolants. Take in part from Data fitting/ Computer Aided DesignDeadline: for full credit - 11:59 PM, Thursday, March 8.for 75% credit - up to 24 hrs latefor 50% credit – up to 48 hrs late (Changes made in this document after first posting are in blue.)Specification. The overall problem is to take a digitized picture provided to you and then use spline or pchip piecewise interpolation of it to : 1) reproduce it as a line drawing; 2) create a composite of four drawings in a square; 3) generate an animated short “movie” showing the rotation of the square; and 4) create a space filling pattern of 16 squares in a 4 x 4 grid. Finally, parallel approaches will be taken to increase the complexity of 3 and 4 above.The test picture chosen is the right hand wine glass in the figure of three. This wine glass has already been digitized by a student. In the archive directory you will find a set of digitized segments that are components of the wine glass. Each file in this directory is a csv-file that contains an array of the (xdata,,ydata) coordinates of a particular segment of the glass. Each *.csv file is read into an (N x 2) array with the xcoordinates in the first column and the y coordinates in the 2nd column. If there are N-points in this digitization, the following statement reads the coordinates into info, which is (N x 2): files = dir('ShortWG*.csv');info = csvread(files(segment).name)(The data structure files had been filled by a dir statement that listed all *.csv files in the directory. Each element of that structure has the file name in the .name field. If there are M such files in the directory, then there will be M such entries in the files structure. You would create M arrays such as info.)Info is (N x 2), with N xdata values in column 1 and N ydata values on column 2.Each of these (xdata,ydata) data arrays (for one of the segments) is to be fit with either piecewise Hermite or cubic spline interpolants. Those composite interpolants (one for each segment) are then evaluated to provide dense (x,y) data sets to be smoothly plotted. Once the spline or cubic Hermite interpolants have been determined, those fits (perhaps saved as PP’s) are used repeatedly each time the image is needed for one of the “products” described below. In other words, the cubic fits to determine the interpolants are only done once, and then evaluated repeatedly. You might consider storing the set of cubit interpolants as structures in a cell array with an entry for each segment. The user will have the choice whether to use cubic Hermite polynomials (pchip) or cubic splines (spline). The spline function provides a range of spline options, such as natural, not-a-knot, etc. The figure is then rendered by evaluating each of the segment interpolants and plotting the (x,y) data points. Some of the segments may need to meet each other smoothly and may demand that you treat the end points of the spline fits carefully to avoid unwanted artifacts.. For some segments, (horizontal curves), the usual y = f(x) approach will work just fine. In others (those oriented vertically), you will need to fit them as x = f(y), but then remembering to plot them as plot (x,y) as usual.It may be convenient to treat the digitized x and y values as parameterized curves x(t) and y(t), where t is just an index stepping from 1 to the number of points in the digitization segment. You then would fit each of the x(t) and y(t) curves to an interpolant as a function of t. The resulting interpolated values x(t) and y(t) would be the x,y input to plot. This involves two interpolations for each segment, but the process can yield superior results. Now, you would choose a dense enough set of t values to give a smooth final curve.You should be able to save the interpolants in PP form. You could do this by saving the entire Matlab workspace. Alternatively, you could define a cell array in Matlab with dimensions (1,N) if there are N interpolants, and then place one of the PP structures in each of the cell structure locations. Your program should be able to load in this structure of PP’s and plot the figure without further input from the user.You may need to make choices as to type of interpolants, density of points, etc, that are specific to the figure you are using. If that is the case, the code should be designed so that it would run on any general figure digitization provided. I will test it with at least one case that is not the one provided.Specific Program RequirementsThe user is asked to find a directory that contains a set of *.csv files, one digitized data set for each segment of the figure. It can be assumed that the directory contains no other *.csv files and that it contains all that are necessary.The program will read the full set of segment data arrays and fit each of them to either a pchip or spline interpolant, allowing the user to make this choice for the entire figure.The full set of interpolants is to be stored in a cell array that can be saved for future use.The program renders the figure in a smooth high quality rendition. The user should be able to choose whether or not to display the raw data points (xdata,ydata) along with the interpolant fit to them. This is the first deliverable for the project. The user should be able to save this figure. See the example.The program will then generate a square drawing with four renditions of the figure oriented about the center of the square at the four directions 0, 90, 180, 270 degrees. You will want to do this rotation with a rotation matrix operating on the (x,y) data vectors. Prior to this rotation, you need to translate the coordinate system from the original, somewhat arbitrary one to the center of this square. This just involves translation of the (xdata, ydata) vectors prior to rotation.The user should be able to save this square of four renditions. See exampleThe program will create an animation of the above square rotating about its center. You may use the movie and getframe functions in order to do this. If possible, you should be able to generate this rotation in real time and play it back for several rotations over a period of at least a few seconds. There need to be enough frames to make the rotation appear smooth. (real movie frames run at 24 s-1 ; the default in movie as 1/2 of that.) You can also create such animation by using data updating in real time. But, the movie option is probably better because it is easy to save. The user should be able to save this movie matrix to be run again with movie. The program is to render the figure for each frame and not simply rotate an existing frame.The program will create a M x M array of copies of the square figure. The program should render each of the squares for this figure and not just reproduce a saved copy of the image object from above. One of the goals here is to make sure it can be rendered in real time. The user should be able to save this image. See (4 x 4) example.All of the above is to be done in serial mode with a single processor. The code is then to be parallelized. The goal of the distributed processing to allow the movie in #5 to be done more rapidly and create a longer movie rapidly. It is also meant to allow generation of much larger array for #7 above. You should test the parallel version with those extensions. Your report should assess how well the parallelization worked and how the times might be dependent on problem size, movie length, etc. In the real use, the user will provide much more complex figures with very involved interpolations. It is expected that these runs will take considerable real time, so that these parallel speedups may be very practical. Programming detailsAfter importing the digitizing data for a curve, it is to be spline or pchip fit with the resulting piecewise polynomial coefficients saved in the data structure such as PPA below. These interpolant structures can then be combined in a cell array, such as PPSET below. You can address the interpolants one at a time this way, as done for PPAdup below.. x = 1 2 3 4 5 6 7y = 1 4 9 16 25 36 49>> PPA = spline(x,y)>> PPSET = cell (1,5)PPSET = [] [] [] [] []>> PPSET {3} = PPA (note curly brackets)PPSET = [] [] [1x1 struct] [] []>> PPAdup = PPSET{3}>> Y = ppval(PPAdup,X);>> plot (X,Y)Digitization Instructions and links to digitization routines are found at this link. You are not being required to carry out digitization here. But, if you choose to do so, you can use one of these three digitizers and save the result as appropriate *.csv files to be used by your program.To maintain the shape of the figure, you will need to issue the axis equal command when drawing the figure. This maintains the aspect ratio (metric) of the graph at its initial value. There are a number of other useful axis commands as well.The user should have control over the density of points in the final plot. A reasonable default should be provided, of course. But, the user should be able to vary the number of points obtained from the interpolants to get a smooth curve, but not waste undue resources.The user should be provided with a dialog (e.g. uigetdir) to find the appropriate directory with the digitized segments in it. The program should report elapsed times for each major task.Good coding practices are to be followed:Adequate and informative commenting throughout, including the use of and purpose of each function.Appropriate indentation in code and use of white space to clearly delineate logic ments should explain each functionUse of white space around operators to make the lines of code more readableSensible variable and function names that make code easy to understandEfficiency: especially regarding vector operationsAppropriate modularization based on task componentsSparing use of global variables – in most cases only as constantsNumbers should generally not appear in code if variables or constants would be appropriate. (Is their origin obvious, and are they likely to be ever changed?)Efficiency countsSaved data (interpolants and other data needed to reproduce them) should be in a well-organized and labeled format.Preliminary submission. By 11:59 PM, Friday, February 24, you are to turn in a deliverable to the “MP3PreliminarySubmission” drop box. This file is to report on the design (including modularization), author responsibilities for different components and phases of code development, and a detailed timeline. It should also include rough drafts ( not yet debugged) of any modules that have been started.Report. Report should include:Specify the source of the original picture.Should contain an example of the rendering produced by your program with your file of PP interpolants.Should contain an example of the “square” rendering produced by your program.Should contain an example of the N x N composite of squares (perhaps N=4).Directory containing: the *.csv files containing the digitization, a copy of the images and movie produced by your program, and the Matlab data set containing the interpolant. This latter could be organized as a workspace file, with the PP’s in an indexed cellular array.Summary of number of segments, number of digitization points on each, number of evaluation points for each to get a smooth plot, etc.Timings for each of the major sectionsDiscussion about strategy for solving the problem and determining the number and placement of points.Discussion of the parallelization strategy and the results obtained. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download