• No results found

Waveform Visualisation And Plot Optimization

N/A
N/A
Protected

Academic year: 2021

Share "Waveform Visualisation And Plot Optimization"

Copied!
32
0
0

Loading.... (view fulltext now)

Full text

(1)

Institutionen för datavetenskap

Department of Computer and Information Science

Final thesis

Waveform Visualisation And Plot Optimization

by

Emil Hammarstedt

LIU-IDA/LITH-EX-G--09/009-SE

2009-09-28

(2)

Linköping University

Department of Computer and Information Science

Final Thesis

Waveform Visualisation And Plot

Optimization

by

Emil Hammarstedt

LIU-IDA/LITH-EX-G--09/009-SE

2009-09-28

Supervisor: Per Nilsson

(3)

Abstract

This thesis is focused on the improvement of an existing implemen-tation of a waveform visualizer. The problem area handled in this work has its focus on how to reduce the number of points to be plotted. The given waveform visualizer was extended by the use of two additional algorithms. First, a Level Of Detail (LOD) algorithm that gives the subset of points that are necessary to plot the waveform in the current zoom level. Second, a straight line identification algorithm to find a series of points aligned in a straight line, only leaving the end points and then drawing a line between them. These two optimizations are the main focus of this work. Additionally, an exporting functionality was implemented to export the plot data into several different data formats. Also some improvements of zooming, panning, some GUI design, and a new drag and drop functionality was constructed.

(4)
(5)

Contents

1 Introduction 1

1.1 Goal . . . 1

1.2 Demarcation and Specification . . . 1

1.3 Method . . . 2

2 Analysis 3 2.1 Level Of Detail (LOD) . . . 3

2.2 Straight Line Optimization . . . 5

2.3 GUI Design . . . 8

3 Design and Implementation 9 3.1 Tools and Environment . . . 9

3.2 Design Choices . . . 9

3.3 Implementation . . . 11

3.3.1 Point Reduction Implementation . . . 12

3.3.2 Straight Line Identification . . . 12

3.3.3 Level Of Detail . . . 13

3.3.4 Zooming And Panning . . . 13

3.3.5 Selection and Drag and Drop . . . 14

3.4 Testing . . . 14

3.5 Further Testing . . . 14

4 Results 16 4.1 Level Of Detail . . . 16

4.2 Straight Line Identification . . . 16

4.3 Combining the LOD and Straight Line Identification . 16 4.4 Zoom and Pan . . . 17

4.5 Exporting of Different File Formats . . . 17

4.6 GUI Requirements . . . 17

4.6.1 GUI Evaluation . . . 17

4.7 Generalized Use of the Plot Component . . . 18

4.8 Overall User Experience . . . 18

5 Discussion 19 5.1 Future Work . . . 20

References 21

(6)

1

Introduction

The software Analog Dimensions by AnSyn AB is used to optimize and simulate analog electrical components. In this software there is a need to visualize different properties of the circuits and components. This is done with a graphical plot of the properties over time. This plot has some drawbacks, missing functionality and functionality which is slow. It is also sought to make the waveform visualizer component more dynamically deployable in the system.

1.1

Goal

The goal of this thesis is to investigate how to improve, and then re-implement the plotting function in Analog Dimension.

1.2

Demarcation and Specification

The work was divided into different goals based on the attributes of the features asked to be implemented.

• Break down the existing code and analyze what is useful and what is not.

• Build a new class structure and integrate old code.

• Optimize plotting of data by removing points in straight lines. • Make use of the Level Of Detail (LOD) concept to reduce the

number of points in a plot.

• Re-implement zooming and panning of the plot.

• Implement drag and drop functionality of different plots into dif-ferent charts.

• Make plots exportable in different data formats.

• Make the waveform visualization component reusable in any other window or panel in the Analog Dimensions program.

The given representation of a waveform is as follows:

• A waveform consists of a set of pairs containing x and y values sorted from minimum to maximum by the x-axis.

• Between any two neighboring points in a waveform a straight line will be drawn constructing a polygonal chain illustrating a waveform. Every waveform is discrete in this manner.

(7)

The use of the LOD-algorithm was an explicit requirement by AnSyn and due to the nature of the data that was to be plotted as a graph. Since the data collections that are to be plotted can hold from a few hundred points to even a million points the LOD -algorithm would allow a seamless user experience when applied since it would reduce the number of points that are to be plotted to the number of screen pixels in width used to display the graph. This is based on the principle that plotting is expensive and should not be done if not necessary[9].

1.3

Method

The work has been divided as mentioned above into problem domains. The foundation of the project is a preexisting code base which has been evaluated and reused when possible. A literature study was done to help understand and solve some of the problem areas, such as the optimization of the plots. The existing system is implemented using Java and therefore all further implementation was also done using Java. The existing waveform visualization component makes use of a third-party library, JFreeChart, which is also used in the this work. The library allows for a automatically correct illustration of data and easy handling of different plots and charts[2]. The library, JFreeChart, allowed the work to focus on what data to plot rather than how to plot it.

(8)

2

Analysis

2.1

Level Of Detail (LOD)

To construct an algorithm that could optimize a plot to contain a minimal number of necessary points, a deeper knowledge of different principles of computer graphics was needed as well as a study of nu-merical computation.

Since it was suggested by AnSyn that a certain algorithm was to be used, LOD (Level Of Detail), the work began with looking into the idea and principles of the Level Of Detail concept.

The principle of LOD is basically that the number of pixels of a screen area should be larger than the plotted amount of detail (or points) that are to be shown in that screen area[5][6]. This is shown in the illustrated figure 1.

Every sub part of an object that has a size smaller than one pixel, or a chosen threshold, is not to be plotted.

Figure 1: Explanation of the LOD concept.

This principle is a sound idea in 3D rendering where many objects are to be considered and as it is expensive to plot them. This principle of detail can also be used within 2D environments to save resources, since it is expensive to plot in a such an environment. [6][7][9].

Since the objects that are to be plotted are continuous lines based on generated data points, and because certain aspects of the graph are more interesting for the user than others, some calculations on the

(9)

data set are needed to determine which points in the set are important and which are not.

The data points determined by AnSyn to be of greater importance are the local maximum and minimum points. These are points that have both their left and right neighbor-points at a lower y-value or correspondingly a higher y-value. Also points in rounded shapes are seen as important. These points should be left alone by the LOD algorithm.

What could be concluded about the waveform and how to construct a specialized LOD was as follows:

• LOD only needs to consider two dimensions of space.

• A local maximum or minimum point should always be included in the set of points that is plotted.

• A rounded shape of a waveform must be kept and distorted as little as possible.

• The distribution of points in the x-axis are fairly even distributed, that is, the resolution of sample points does not change in a dramatic way over the x-axis.

The requirement of rounded shapes will automatically be solved since the highest possible detail that can be viewed is the number of points left in the set by the LOD algorithm. A pseudo code solution of how to select the necessary points can be seen below. It exemplifies how the Level of Detail algorithm can be used in this problem domain.

As shown below, the given data to the algorithm consists of a tuple data-set of points representing the waveform and a specified width given in pixels of the screen area that is to be used. When a point is deemed as necessary it is selected by the select method.

(10)

begin selectLOD(DataSet[][], W idth)

comment: Steplength is the number of points that are in the same screen pixel. steplength := DataSet.length/W idth

comment: Starts at 0 and steps a steplength until the end of the set for i := 0 to DataSet.length step steplength do

if i 6= 0 ∧ i + 1 6= DataSet.length then

comment: Selecting every steplenght:nth element in DataSet[][]. callselect(DataSet[i])

comment: Checks if the points between steplength comment: are local max- or min-points

for j := i + 1 to i + steplength − 1 step 1 do preY := DataSet[j − 1][2]

curY := DataSet[j][2] nexY := DataSet[j + 1][2] ifpreY ≤ curY ∧ nexY ≤ curY

then

call select(cur) fi if preY ≥ curY ∧ nexY ≥ curY

then call select(cur) fi od fi od end

The code above makes use of nested for-statements but it is not neces-sary. It is described as this because the nature of the algorithm. Since there is a need to check for minimum and maximum points in between every modulo "steplenght" point in the set, it is symbolic to show this with a for-statement. A more optimal solution would make use of only one for-statement iterating over every element in the set checking for minimum and maximum points and modulo "steplenght" points.

2.2

Straight Line Optimization

When plotting a waveform, a sequence of points is unnecessary to plot if they are on a straight line, since a straight line consisting of more than two points would actually consist of several straight lines in a

(11)

row. In a sense it could be described that every point actually is a vector pointing to the next point in the set when plotted. The only points necessary to plot would be the end-points of this hypothetical straight line. To identify a straight line, a method of determining the derivative of a certain point is needed.

If this derivative does not change between a series of points then there is a straight line. To calculate the derivative of a single point the following formula could be used. The below described formula of the geometric interpretation of the forward directional derivative make use of the next point to estimate the current derivative [8].

f0(x) ≈ f (x + h) − f (x)

h = D+(h) Here h is the distance in the x-axis to the next point.

This calculation is then done for each point in a plot to estimate the derivative. When this formula is applied iteratively over a whole series of points in a plot it is possible to ignore points when the derivative does not change. A new set of points is created, consisting of end-points creating straight lines, illustrated in figure 2.

Figure 2: Illustration of which points are necessary to keep

This above described algorithm will not take into account any points that are approximated to be on a straight line. To solve this approxi-mation of points to a line, some user input can be requested about the accuracy of the plot. This input is a number representing the relevant error of comparison known as ε. The ε-value from the user is then used as a parameter in the formula below describing the conditions for comparing two approximately equal numbers [8].

Dn Dn+1 < 1 −  ∨ Dn+1 Dn < 1 − 

(12)

This formula will need a special case in the fraction where the denom-inator is zero, but since it will be expressed as a true or false condition the result in this case will then be the true- or false-value of comparing the numerator to zero. This reduction of accuracy will normalize the points to a "thick line", shown in figure 3.

Figure 3: Intolerance example

Figure 3 describes a hypothetical accuracy level accepted by the algorithm. Even though figure 3 shows an extreme value of intolerance, every point that is within the red-marked area between two green points will be removed. The waveform described in figure 3 is not an actual true representation but just an illustration. The green points are the last points that are deemed to be on a straight line and hence kept.

When accepting an error in comparison there is a risk of an accu-mulated error over the complete straight line which could be greater than the accepted ε. This accumulated error could be handled by a recursive back checking of all the previous derivatives on the line. This back checking will create a quadratic complexity and therefore a middle way would be suitable i.e. checking only a fixed number of derivatives back.

(13)

approach of solving the selection of end-points of lines.

begin selectStraightLine(DataSet[][], epsilon) f irst := DataSet[0]

last := DataSet[2]

comment: first point in a line must always be selected select(f irst)

for i := 1 to DataSet.length − 1 step 1 do mid := DataSet[i]

last := DataSet[i + 1]

comment: Calculating the distance of ’mid’ comment: from the line between ’first’ and ’last’. dist := distanceF romLine(f irst, last, mid) if absolute(dist) > epsilon select(mid) f irst := mid fi od select(last) end (Kessler, 2009)

As seen in the pseudo code above, a distance function is needed (not described here) that calculates the distance between a point and a line. This solution allows for a linear complexity and therefore a faster calculation.

2.3

GUI Design

Features and functions described as a GUI component or partly as a GUI component have been evaluated. The main GUI features where already implemented. Because of the drag and drop requirement de-scribed in the introduction and a need to have some virtual artifact to drag and drop, it was decided that the legends in the plot describing the plot should be used as objects to be dragged. These legends were to be put on the up most right corner of the plot, the background was set to a semitransparent black and white semitransperent back-ground if selected. The color of the legend text was to be the same as the color of its corresponding waveform. This solution was decided together with AnSyn to be a satisfactory one.

(14)

3

Design and Implementation

The legacy code consisted mostly of two classes. Because of the legacy code base of the waveform visualizer and its limitation, it was necessary that this code had to be re-factored and rewritten before any new functionality could be added.

3.1

Tools and Environment

The design and implementation of the functionality was to be done in Java 6 using NetBeans 6.7 and with use of the JFreeChart library. Java is a object oriented, platform independent and modern language commonly used by developers. Java was developed by Sun Microsys-tems in the 90s [1]. The developing environment, NetBeans 6.7, was also developed by Sun Microsystems as a Java IDE (Integrated Devel-oping Environment) [3]. Both Java and NetBeans are today developed as open source and maintained by the open source community. Also the chosen chart generating library, JfreeChart 1.0.13, is developed as a open source project[2]. While writing, all of these tools are freely available to download and use.

3.2

Design Choices

To implement the new functions into the preexisting code base and to make the code easier to manage a design plan had to be done. This was decided to be based upon standard design patterns. To select the right design patterns the functionality had to be analyzed so it could be matched.

As hinted in figure 4 the main part of the solution makes use of the Model View Controller or MVC design pattern. MVC was chosen as it is a nice and well proven design pattern when building user interfaces. It is also almost auto implemented when using Java Swing. Swing is the incorporated library in Java for constructing GUIs[4].

The Model View Controller design pattern has a releative long his-tory and the concept of separating the data model (Model) away from the user interface (view) and the functionality (controller) is effective if it is desired to create a maintainable GUI [11].

Since one of the goals was to make the waveform visualization com-ponent portable, a facade design pattern was chosen, as it allows any other developer to interact with the whole component using a single

(15)

class. That is, the complete class hierarchy will be hidden behind one single class [10].

Figure 4: Planned class solution diagram. (export classes not included)

The configuration of the MVC tends to be a complex and a lengthy procedure, therefore it was thought that a builder pattern could ease this and make it less complicated, hence it would remove a lot of nonfunctional code from the central code. [10]

To solve the file exporting function a static form of the factory pattern was chosen as it could separate the definition of any file format from the actual generation of the file. This solution will allow for an easy expansion of additional file formats in a general and easy way [10].

(16)

3.3

Implementation

Implementation of the different goals was done goal by goal. Highest priority first and so on. Every task was individually broken down into sub-tasks. By doing this every sub-task could then be evaluated into the amount of time to finish and difficulty. Some tasks depended on others which led to an obvious order of implementation.

Figure 5: Auto generated class solution diagram after implementation.

As shown in figure 5 the end class hierarchy was implemented as de-scribed in figure 4 with an exception. The abstract builder was not seen as a necessary feature since it would be put behind the facade, and not to be changed by any other developer in the sense it was first thought.

In figure 5 the class hierarchy of the export-factory classes is not shown. Also the JFreeChart component XYSeriesCollection-class is removed in figure 5, which is representing the model in the MVC.

Exporting the plots into different external data-formats, containing the sample-points as data-values, was done by a function in AnsynChartPanelBuilder-class. From here the function will get a list of

(17)

supported file-formats from the ExportFormatTemplateFactory-class, this list is then presented as a save-window where the user saves the file. The selected file-format is then used as a parameter again in a call to the factory-method of the ExportFormatTemplateFactory -class which then produces a template for the selected format. This template is then later used to put together from the displayed data the file to be exported. This solution will allow for an easy extension of further formats in an fairly simple and dynamic way.

3.3.1 Point Reduction Implementation

As discussed in the analysis the reduction of points in the data set that represents the waveform was the main focus and the main problem. To implement the point reduction feature it was divided into two separate problems, as follows.

• Straight line identification - If a series of points can be said to be on a straight line then draw a line between the first and the last points of the line.

• Level of detail - The number of pixels dedicated to show the plot is the maximum number of points to be plotted, a higher number would be unnecessary since they would be between the screen pixels.

The order of applying the algorithms was the one of applying the LOD-algorithm and later the straight line identification algorithm. This is, of not having to apply the straight line identification on every point in the set and then reduce the amount with LOD. Since LOD decides which points can be shown, it is unnecessary to calculate the derivative on a point that will be excluded.

3.3.2 Straight Line Identification

The straight line identification had some sub problems that needed to be implemented such as a function for comparing two floating point numbers and a derivative function.

The comparison function was done by modifying a preexisting solu-tion. As discussed in the analysis the formula of approximative com-parison was implemented as shown in Listing 1. In this solution a magnitude value is used and set to be 0.000000001 allowing for a high level of resolution.

(18)

The approximation of the derivative at a point in a plot was im-plemented as discussed in the analysis. The solution can be seen in listing 2. Some special cases had to be taken into account as the plot supports logarithmic scales. The truncating and derivative methods were then in turn called by a main point-reducing method which it-erated over all the data series and selected the points to be plotted, shown in listing 3.

As shown in listing 3 the summary of all the relevant points is done. As discussed in the analysis the derivatives are compared with the approximative equal-function and a number of ten derivatives back was compared. The second last else statement in listing 3 is unneces-sary but symbolically there to show that a point will be ‘removed‘ or ignored.

3.3.3 Level Of Detail

The solution shown in listing 4 of the LOD principle was done in mostly the manner described in the analysis. Since this function came down to selecting every n:th point in the plot series where n is the number of points divided by the plot screen-width, represented by the variable "step" in listing 4, the local maximum and minimum points was as well identified. This came to be a fairly straight forward solution.

Also the level of detail method was called by the point-reducing method before any straight line reduction was done.

3.3.4 Zooming And Panning

Zooming was one of the main problematic implementations due to a number of reasons. There was already an implemented solution for zooming which was reused and reconfigured. It consisted of five zoom-ing functions which will zoom in and out by a specified factor and zoom to fit a rectangle drawn with the mouse. These functions had to be redesigned to take into account the LOD and straight line opti-mization. When changing the zoom level a recalculation was needed of mainly the LOD, but since the straight line optimization is done on the LOD-reduced set of points both had to be redone.

Panning was implemented by using the zooming functions and was done by changing the zoomed in area relative to the mouse while pan-ning.

(19)

3.3.5 Selection and Drag and Drop

Implementing the selection of a waveform was done by plotting the selected waveform with a thicker line and also making the legend of the waveform into a white background rather than black. The coloring of the different waveforms had to be an automated process and was solved by constructing a singleton class holding 18 different colors and a counter holding the number of the latest color used. A singleton class was chosen as it would allow for an easy access of a good color choice at any time and that it would remember which color was last used, eliminating the risk of having the same color chosen twice in a row[10]. The coloring function is used by requesting a new color and the singleton will then return the next color in line. When the 19:th color is requested the series is reset and the first color will again be returned. The drag and drop functionality was implemented by the standard drag and drop functions in Java, which allows for a standard way of dragging and dropping objects.

3.4

Testing

Testing was done in an informal way by testing the specified goals in their separate part and together as a complete solution.

For every part of the specification functional testing was done to ensure that the specified features were functioning.

By using all the functions together with old functionality every new feature was tested. Testing was also done by trying to test as many functions as possible at the same time to provoke detection of errors.

Several problems or bugs did occur and led to a bug list in the form of a bug tracing and handling system. The bug list was extended every time a new bug occurred. Mostly the bugs were fixed at discovery but some needed to be fixed after additional implementation of additional functionality.

3.5

Further Testing

To verify the functionality of the implementation only the output data could be used. The data used as reference was the output of the old implementation of the plot. Since the output was in the form of a graphical interface some special measures were needed.

The practical testing was done by comparing some random points in the reference output to the corresponding point in the new

(20)

im-plementation. This procedure was then done over a set of different waveforms with different shapes and as well with different functions active both so to verify that all functionality did work together.

The practical method of the testing procedures was done both in a quantitative and a qualitative manner as both the actual values were compared as well as the graphical plot layout.

(21)

4

Results

This part will provide the results of testing the implemented function-ality against the specified criteria mentioned in the introduction. The measured data comes from a printout of the number of points in the original set and the reduced set of points.

4.1

Level Of Detail

The resulting implementation of the level of detail-functionality worked and resulted in a circa 90% reduction of points in a sinusoid-like wave-form displayed over 1060 screen pixels in width and circa 14000 sample-points.

4.2

Straight Line Identification

The results from only using the implementation of the Straight line identification algorithm produced a reduction of circa 80% of points in the above mentioned sinusoid and without any visible loss of detail on any local max- and min-points. The setting of ε to 0.5 was used to produce this result. It should be noted that the value of 0.5 for ε is a large value. Results from applying the algorithm on a exponentially like curve of 88 sampling points a reduction to 37 points was achieved with some small amount of detail lost at a ε of 0.5

A second sinusoid resulted in a circa 83% reduction of points with ε set to 0.5 and a circa 90% reduction at ε 0.75. When incrementing ε to the level of visible loss of data without any zoom the value of ε is around 0.9 and a circa 90% reduction was achieved.

On any completely straight-line waveform all but 3 points were removed with any setting of ε. The first 2 points were left and the last point, this is because of the used algorithm that needs two points to calculate the derivative, that is, the forward approximative derivative.

4.3

Combining the LOD and Straight Line

Iden-tification

The resulting reduction of points when these two optimization algo-rithms were used together and ε was set to 0.5 was circa 93% when applied to the above first mentioned sinusoid. When ε was set to the more extreme value of 0.9 the reduction resulted in a circa 97% both

(22)

without any clear loss of data. Both results were at standard zoom with the screen pixel width of 995 and circa 14000 sample-points.

When plotting a number of 23 waveforms with the combined num-ber of 326324 points the two algorithms reduce the numnum-ber of points in the plot to 8288 points, this is at no zoom and 995 screen pixels width and an ε at 0.995. This leaves basically only local max- and min-points as the ε is at an extreamley high value.

4.4

Zoom and Pan

The zooming functionality was already implemented, but was needed to be redesigned to work with the optimization/reduction algorithms. The zoom was done by use of the scroll-wheel, mouse selection and by push-buttons. The default zoom-step was set to 80% inwards zoom and 125% outward zoom. When the zoom changes, recalculation of the set of points was done.

Panning was implemented by using the zooming functions but only changing the zoomed-in area, not the zoom-level.

4.5

Exporting of Different File Formats

The exporting function was implemented and verified by exporting a file in all the formats and then importing the files into other programs, all successfully.

4.6

GUI Requirements

The requirements involving the graphical nature of the program were all implemented as they were described in the introduction. Some artistic freedom had to be applied and can be seen in figure 6. The labels of the plotted waveforms are used as dragable objects between different plots and in that way enabling the drag and drop functional-ity.

4.6.1 GUI Evaluation

The GUI was evaluated by a few users and was in large deemed as acceptable and usable. Some concerns were made about the zooming control and the placement of the legends. The drag and drop func-tionality was not seen as obvious but as intuitive when the knowledge of it existed. Overall the GUI was granted as satisfactory.

(23)

Figure 6: Example of the GUI design

4.7

Generalized Use of the Plot Component

The component was built as described in earlier chapters as a facade-class and can therefore be handled as one single object in any other window-component.

4.8

Overall User Experience

By interviewing a few users about the overall user experience between the old and the new implementation, the resulting response was that of an intuitive and responsive feeling. Responses to the zooming and panning was that of an increased flow.

(24)

5

Discussion

The purpose with this work has been to re-implement a waveform visualizer that can handle a large plot in a fast and seamless way. The work has been divided into two major parts. The first part was to optimize the plotting by reducing the number of necessary points in the plot. The second one has been more on the focus of the user experience, such as panning and other GUI interactions. These two parts have of course been necessary to be combined in the work process. In the second part of the project we have not relied on the theoretical work as much as we have done on the first part but on suggesting solutions and trying them out on users. We decided to use this approach because it is cheap, fast and easy, and as it is difficult to find precise and "correct ways" of building a GUIs, and the author believes that the trial by error approach is a good enough way to find interactions that work. If there had been more time and resources, a field study could have been done where a larger group of potential users could have been interviewed and tested on the interactions.

The first part or main part, the optimization, was the work which took the most planning and field-studying to implement. This part of the project was, on the other hand, the fastest to implement due to the work done in the theoretical study of the problem domain to make it work correctly.

The results described earlier can be viewed in some different per-spectives. In an efficiency perspective, where the number of points re-duced is concerned, the solution clearly has made some improvements. In some cases this reduction can be a little too aggressive. When a set of points already has a small number of points the reduction tends to be unnecessary and details can be visibly lost.

When taking the perspective of correctness, removing a point that is not on a straight line is wrong, so both the LOD and the straight line identification is removing points that have a defining attribute to a waveform. As these algorithms will recalculate the plot when zooming, the finer details of a plot will be shown and then, if the ε is not set too a far to aggressive mode, it will not remove too much detail. But to get a high-performing plot the accuracy has most likely to be set a little aside. If preferred, a comparison to lossy compression could possibly be made.

It should be noted that an extensive verification of how much dis-tortion the straight line identification algorithm and the LOD

(25)

pro-duced was not done in a quantitative manner, this meaning that no results are presented about the amount of how much distortion from the original waveform the left out points produced. But since there is no recalculation of the plotted points compared to the corresponding points in the original set, it is in between the plotted points, where points have been removed, an error might be found characterized as sharp edges on the waveform. Sharp edges can also be the result of a low resolution of samples or a high zoom-level.

5.1

Future Work

Suggested extending features to the plotting component, has been a calculating feature that can operate on a waveform e.g. a derivative, integration, addition, subtraction etc.

The LOD possibly needs to be more adaptive to the fact that some waveforms needs a smaller degree of point reduction. Both over the whole set, as well as a need to adapt the reduction over subsets of a waveform where the sample points are fewer.

The implementation of straight line identification in this work is the first step into a wider possibility of pattern matching of graphs. A further study of how to match other forms than straight lines can produce yet smoother and even faster plotting waveforms. Identifying sinusoids and replace them with parts of the sinus-function as well as identifying parts of circles and other geometric functions are prospects that should be considered as they could improve performance.

Another prospect of further work is an aspect of the applied straight line algorithm and the possibility of an increased error over the length of the “straight” line. This meaning that if a series of points has a close to ±ε in a row, an error could accumulate over the series, resulting in a possibly incorrect result. This is in part reduced by the comparison over three points done when determining if a point is on a straight line in listing 3.

At this point the plot has extensive possibilities of configuration which can make it hard to configure in other parts of the application as well as in other applications. Some of the configuration attributes could possibly be implicit. A further overview of configuration at-tributes that could be abstracted away from the facade of the plot would allow for an easier interface which could improve the usability of the plot component.

(26)

References

[1] Java history timeline. Referenced on 2009-08-20, URL:http://www.java.com/en/javahistory/timeline.jsp.

[2] Jfree chart library. Referenced on 2009-08-20, URL:http://www.jfree.org/jfreechart/.

[3] Netbeans IDE. Referenced on 2009-08-20, URL:http://www.netbeans.org/.

[4] Swing and MVC. Referenced on 2009-08-20, URL:http://java.sun.com/products/jfc/tsc/articles/architecture/. [5] Edwin Earl Catmull. A subdivision algorithm for computer display

of curved surfaces. PhD thesis, 1974. The University of Utah. [6] James H. Clark. Hierarchical geometric models for visible-surface

algorithms. SIGGRAPH Comput. Graph., 10(2):267–267, 1976. [7] Willem H. de Boer. Fast terrain rendering using

geometri-cal mipmapping. E-mersion Project, October 2000, avialable at http://www.flipcode.com/, 2000.

[8] Lars Eldén and Linde Wittmeyer-Koch. Numeriska Beräkningar. Studentlitteratur, Studentliteratur, Lund, fourth edition, 2001. [9] Carl Martin Erikson. Hierarchical levels of detail to accelerate

the rendering of large static and dynamic polygonal environments. PhD thesis, 2000. The University of North Carolina at Chapel Hill.

[10] Erich Gamma et al. Design Patterns - Elements of Resuable Object-Oriented Software. ADDISON-WESLEY, 1995.

[11] Ian Sommerville. Software Engineering. ADDISON-WESLEY, 2007.

(27)

Avdelning, Institution Division, Department Datum Date Språk Language Svenska/Swedish Engelska/English Rapporttyp Report category Licentiatavhandling Examensarbete C-uppsats D-uppsats övrig rapport URL för elektronisk version

ISBN ISRN

Serietitel och serienummer Title of series, numbering

ISSN Linköping Studies in Science and Technology Thesis No. Titel Title Författare Author Sammanfattning Abstract

This thesis is focused on the improvement of an existing implementation of a waveform visualizer. The problem area handled in this work has its focus on how to reduce the number of points to be plotted. The given waveform visualizer was extended by the use of two additional algorithms. First, a Level Of Detail (LOD) algorithm that gives the subset of points that are necessary to plot the waveform in the current zoom level. Second, a straight line identification algorithm to find a series of points aligned in a straight line, only leaving the end points and then drawing a line between them. These two optimizations are the main focus of this work. Additionally, an exporting functionality was implemented to export the plot data into several different data formats. Also some improvements of zooming, panning, some GUI design, and a new drag and drop functionality was constructed.

Institutionen för datavetenskap

Dept. of Computer and Information Science 581 83 Linköping 2009-09-21 91-LIU-IDA/LITH-EX-G–09/009–SE http://www-und.ida.liu.se/~emiha480/ exjobb/report/report.pdf 2009-09-21

Waveform Visualisation And Plot Optimization

Emil Hammarstedt

× ×

(28)

Appendices

Listing 1: Approximated equality comparison

p r i v a t e b o o l e a n a p p r o x i m a t e l y E q u a l (d o u b l e answer , d o u b l e c o r r e c t , i n t s i g n i f i c a n c e ) { f i n a l f l o a t magnitude = 0 . 0 0 0 0 0 0 0 0 1 f ; f i n a l d o u b l e d i f f T o l e r a n c e F a c t o r = ( s i g n i f i c a n c e ∗ magnitude ) ; r e t u r n ( ( a n s w e r == 0 ) && ( c o r r e c t == 0 ) ) | | ( ! ( a n s w e r / c o r r e c t < 1 . 0 − d i f f T o l e r a n c e F a c t o r ) && ! ( c o r r e c t / a n s w e r < 1 . 0 − d i f f T o l e r a n c e F a c t o r ) ) ; }

(29)

Listing 2: Approximated derivative of a point in a plot p r i v a t e Number d e r i v a t i v e (XYDataItem n e x t P o i n t , XYDataItem c u r r e n t P o i n t , Number fPrimeX ) { Number nextFPrimeX ; // a p p r o x i m a t i n g t h e d e r i v a t i v e // f ( x+h ) − f ( x ) o r d e l t a y Number n u m e r a t o r = n e x t P o i n t . getY ( ) . d o u b l e V a l u e ( ) − c u r r e n t P o i n t . getY ( ) . d o u b l e V a l u e ( ) ; // h o r d e l t a x Number d e n o m i n a t o r = n e x t P o i n t . getX ( ) . d o u b l e V a l u e ( ) − c u r r e n t P o i n t . getX ( ) . d o u b l e V a l u e ( ) ; // c o m p e n s a t e s t h e d e r i v a t i v e f o r l o g a r i t h m i c s c a l e s i f ( l o g S c a l e X A x i s && ! l o g S c a l e Y A x i s && d e n o m i n a t o r . d o u b l e V a l u e ( ) != 1 . 0 && d e n o m i n a t o r . d o u b l e V a l u e ( ) != 0 ) { d e n o m i n a t o r = Math . l o g 1 0 ( d e n o m i n a t o r . d o u b l e V a l u e ( ) ) ; } e l s e i f ( l o g S c a l e Y A x i s && ! l o g S c a l e X A x i s && n u m e r a t o r . d o u b l e V a l u e ( ) != 0 ) { n u m e r a t o r = Math . l o g 1 0 ( n u m e r a t o r . d o u b l e V a l u e ( ) ) ; } e l s e i f ( l o g S c a l e X A x i s && l o g S c a l e Y A x i s && d e n o m i n a t o r . d o u b l e V a l u e ( ) != 1 . 0 && d e n o m i n a t o r . d o u b l e V a l u e ( ) != 0 && n u m e r a t o r . d o u b l e V a l u e ( ) != 0 ) { n u m e r a t o r = Math . l o g 1 0 ( n u m e r a t o r . d o u b l e V a l u e ( ) ) ; d e n o m i n a t o r = Math . l o g 1 0 ( d e n o m i n a t o r . d o u b l e V a l u e ( ) ) ; } i f ( d e n o m i n a t o r . d o u b l e V a l u e ( ) != 0 . 0 ) { nextFPrimeX = ( n u m e r a t o r . d o u b l e V a l u e ( ) / d e n o m i n a t o r . d o u b l e V a l u e ( ) ) ; } e l s e { // assumes p r e v i o u s v a l u e i f h = 0 , s h o u l d n o t happen . nextFPrimeX = fPrimeX ; } r e t u r n nextFPrimeX ; }

(30)

Listing 3: The Straight line matching method

p r i v a t e X Y S e r i e s m a t c h S t r a i g h t L i n e ( X Y S e r i e s d s ) {

f i n a l i n t b a c k c h e c k l e n g h t = 1 0 ; //How many p o i n t s b a c k t o c h e c k f o r c h a n g e s

X Y S e r i e s newds = new X Y S e r i e s ( ds . getKey ( ) ) ;

Number oldFPrimeX = n u l l; Number fPrimeX = n u l l; Number nextFPrimeX = n u l l; f o r (i n t i = 0 ; i < d s . g e t I t e m C o u n t ( ) ; i ++) { // f o r e v e r y p o i n t i n waveform XYDataItem c u r r e n t P o i n t = (XYDataItem) d s . g e t I t e m s ( ) . g e t ( i ) ; L i n k e d L i s t <Number> d e r i v a t i e s = new L i n k e d L i s t < Number>() ; i f ( ds . g e t I t e m C o u n t ( ) == i + 1 ) { // a d d s t h e l a s t p o i n t b e i n d a t a s e t newds . add ( c u r r e n t P o i n t ) ; } e l s e { // c a l c u l a t e t h e n e x t d e r i v a t i v e nextFPrimeX = d e r i v a t i v e ( (XYDataItem) d s . g e t I t e m s ( ) . g e t ( i +1) , c u r r e n t P o i n t , fPrimeX ) ; i f ( fPrimeX == n u l l) { // Catch t h e f i r s t p o i n t fPrimeX = nextFPrimeX ; newds . add ( c u r r e n t P o i n t ) ; } e l s e { i f ( oldFPrimeX == n u l l) { oldFPrimeX = fPrimeX ; fPrimeX = nextFPrimeX ; newds . add ( c u r r e n t P o i n t ) ; } e l s e i f( I s S t r a i g h t ( fPrimeX , nextFPrimeX , ( L i n k e d L i s t <Number>) d e r i v a t i e s . c l o n e ( ) ) ) { d e r i v a t i e s . add ( fPrimeX ) ; i f( d e r i v a t i e s . s i z e ( ) > b a c k c h e c k l e n g h t ) d e r i v a t i e s . r e m o v e L a s t ( ) ; } e l s e { d e r i v a t i e s . c l e a r ( ) ; // add a l l p o i n t s i f i t i s n o t on a s t r a i g h t l i n e oldFPrimeX = fPrimeX ; fPrimeX = nextFPrimeX ; newds . add ( c u r r e n t P o i n t ) ; } } } } r e t u r n newds ; }

(31)

Listing 4: Level of detail implementation

p r i v a t e X Y S e r i e s l e v e l O f D e t a i l ( X Y S e r i e s d a t a S e r i e s ,i n t wi dt h ) { X Y S e r i e s newDS = new X Y S e r i e s ( d a t a S e r i e s . getKey ( ) ) ;

i n t d S S i z e = d a t a S e r i e s . g e t I t e m C o u n t ( ) ;

i n t s t e p = 0 ;

i f( w id th != 0 )

s t e p = d S S i z e / w id th ;

i f( s t e p > 1 ) {

// up t o s t e p −1 p o i n t s can b e removed from t h e // end o f t h e s e r i e s . f o r(i n t i = 0 ; i+s t e p < d S S i z e ; i=i+s t e p ) { // i f t h e i n t e r v a l c o n t a i n s peak −/bottom− v a l u e , // i t must b e p l o t e d . f o r(i n t j = i ; j <i+s t e p ; j ++){ i f( j >0 && j +1 != d S S i z e ) { XYDataItem p r e v = d a t a S e r i e s . g e t D a t a I t e m ( j −1) ; XYDataItem c u r r = d a t a S e r i e s . g e t D a t a I t e m ( j ) ; XYDataItem n e x t = d a t a S e r i e s . g e t D a t a I t e m ( j +1) ; i f( p r e v . getYValue ( ) < c u r r . getYValue ( ) && n e x t . getYValue ( ) <= c u r r . getYValue ( ) ) { newDS . add ( c u r r ) ; } i f( p r e v . getYValue ( ) > c u r r . getYValue ( ) && n e x t . getYValue ( ) >= c u r r . getYValue ( ) ) { newDS . add ( c u r r ) ; } } } newDS . add ( d a t a S e r i e s . g e t D a t a I t e m ( i ) ) ; } r e t u r n newDS ; }e l s e r e t u r n d a t a S e r i e s ; }

(32)

På svenska

Detta dokument hålls tillgängligt på Internet – eller dess framtida ersättare –

under en längre tid från publiceringsdatum under förutsättning att inga

extra-ordinära omständigheter uppstår.

Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner,

skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat för

ickekommersiell forskning och för undervisning. Överföring av upphovsrätten

vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av

dokumentet kräver upphovsmannens medgivande. För att garantera äktheten,

säkerheten och tillgängligheten finns det lösningar av teknisk och administrativ

art.

Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i

den omfattning som god sed kräver vid användning av dokumentet på ovan

beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan

form eller i sådant sammanhang som är kränkande för upphovsmannens litterära

eller konstnärliga anseende eller egenart.

För ytterligare information om Linköping University Electronic Press se

förlagets hemsida

http://www.ep.liu.se/

In English

The publishers will keep this document online on the Internet - or its possible

replacement - for a considerable time from the date of publication barring

exceptional circumstances.

The online availability of the document implies a permanent permission for

anyone to read, to download, to print out single copies for your own use and to

use it unchanged for any non-commercial research and educational purpose.

Subsequent transfers of copyright cannot revoke this permission. All other uses

of the document are conditional on the consent of the copyright owner. The

publisher has taken technical and administrative measures to assure authenticity,

security and accessibility.

According to intellectual property law the author has the right to be

mentioned when his/her work is accessed as described above and to be protected

against infringement.

For additional information about the Linköping University Electronic Press

and its procedures for publication and for assurance of document integrity,

please refer to its WWW home page:

http://www.ep.liu.se/

References

Related documents

This is investigated through three research questions focusing on what journalistic and marketing discourses that are apparent in advertorials and click-based material; what blend

[ 18 ] Radiances for the AMSU-B sounding channels were simulated by ARTS and RTTOV using the interpolated profiles as input, that means that the radiative transfer equation

The Gauss-Newton method with and without line-search was applied to a least squares template matching problem where the template was a 11  11 pixels white square with a 4 pixel

Based on the external changes that affected Stena Line and especially the Danish route, the authors found Stena Line as a well-suitable case company to apply to the thesis..

Three different types of damping control devices were introduced in this report, the fluid viscous damper (FVD), the magnetorheological (MR) damper and the tuned mass damper

This chapter describes the simulation models’ structure, how they were built along with limitations and simplifications for the models. The chapter is divided into two main

En undersökning har utförts på frekvensomriktare av typen E och F, där felrapporter för år 2007 har granskats. Felen som har upptäckts har delats in efter typ och storlek.

With reference to the prisoners of war detained at Guantanamo Bay in Cuba as a consequence of the War on Terror, I am going to research within the framework of this essay the