Build an OpenGL mesh viewer with glut(2)-Load M file into half-edge data structure


In this project, we focus on triangle mesh model which its data is stored into M file.  The format of M file is very simple, it contains two parts, one is for “vertex”, another part is for “face”.


Every “Vertex” has its index number and 3 float-point numbers as its vector value, each “Face” has its index number and 3 int numbers which are vertex index number.

Our task is how to load those data into memory for preparing rending in OpenGL. First, we have to read those data line by line and store them into a special data structure. The best solution for storing those data is using half-edge which is very popular, to understand the concept can refer

 Define half-edge data structure in our project

Create new file and name it as MeshModel.cpp in the project, define half-edge data structure in it.

Create another file name as “Main.cpp”  which contain main() function. In this file we need to load M file and push its data into half-edge structure we defined above.



Posted in CG

Build an OpenGL mesh viewer with glut(1)-Setup development environment


For this project development, we use Glut to build the interface which provide the UI such as window, menu and mouse/key interaction, as a beginner, Glut is good choice, because it is easy to use and do not need spend much time on learning it.

We choose MS Visual studio 2012 express for desktop as the IDE, it can be downloaded from Microsoft. , and the most important is get OpenGL library.

 Install Visual C++ Express 2012

1. Download Visual C++ Express from:

2. Run setup and follow instructions to install Visual C++.

 Install FreeGLUT

1. Download “freeglut 2.8.1 MSVC Package” from
2. Extract the compressed file to a folder freeglut
3. Inside freeglut folder:
On 32bit versions of windows
copy all files in include/GL folder to C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl
copy all files in lib folder to C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib
copy freeglut.dll to C:\windows\system32
On 64bit versions of windows:
copy all files in include/GL folder to C:\Program Files(x86)\Microsoft SDKs\Windows\v7.0A\Include\gl
copy all files in lib folder to C:\Program Files(x86)\Microsoft SDKs\Windows\v7.0A\Lib
copy freeglut.dll to C:\windows\SysWOW64

Create Visual C++ project using sample code

1. Download sample code: Glut_demo
2. Click on create new project in Visual Studio
3. Select Win32 Console Application, type name of your project and click on OK
4. On wizard window that shows up, click Application Settings and check Empty Project, click Finish.
5. Select Add Existing Item from Project menu
6. Select all source files in sample code and click add
7. Select Properties from Project menu
8. At the top of the window, change Configuration to All Configuraitons.
9. Select Linker->Input from tree on your left.
10. In Addititonal Dependencies on right pane, add “;freeglut.lib” to the end, if you use glew, also add “;glew32.lib”.
11. Click OK and select Build Solution from Debug menu
12. Run the program by hitting Ctrl+F5, right click on the black window, select “teapot”, a white wireframe teapot will be shown in the black stage like blow


Posted in CG

for-each of XSLT


There is a request that show some information on the page if the special products included in an xml file, and this need to be done by xslt.

Usually, we use for-each to look through all nodes and detect by if test=”condition” to check the result, but there is a problem that how to exit loop when we get correct result, so that don’t display multiple times?

XML data:

If the special products are more than one, the information will be repeat shown.

The solution is:

first, we need to change for-each code to only select the nodes which includes special product, the code is:

select=”node[condition1 or condition2 or …]

then we use xsl:if test=”position()<2″ in for-each loop, to show the information only one time.

XSL code:


Posted in Uncategorized Tagged with:

Comparison of SSIM and PSNR for Image Quality Evaluation


Wang Weiqiang

SCE, Nanyang Technological University


I developed a software for comparing SSIM and PSNR the two methods of image quality evaluation, and compare the two algorithms by experimental data. The experimental results show that the SSIM algorithm is more suitable for the human visual system characteristics than the PSNR and it can get better image quality evaluation results.


1 Introduction 

SSIM and PSNR are two kinds of image quality assessment, PSNR is one of traditional objective methods, it has simple calculation method and wide range of applications in practice. Because it does not consider the human visual perception and image characteristics, in some case it is out of touch with people’s subjective evaluation, but SSIM(Structural Similarity) is easy to implement and has a strong applicability. Experiment shows that it has a better correlation with subjective. SSIM algorithm is excellent for image quality evaluation. In this report  I try to give out the compare result between this two algorithms.

2 PSNR algorithm

PSNR(Peak Signal-to-Noise Ratio) is the ratio between the maximum power of signal and power of noise which affects the fidelity of the signal’s representation. Usually PSNR is used to measure the quality of compressed images, the signal is from original image and the noise is the error created by compression codecs. PSNR is defined via MSE(Mean Squared Error) and MSE is defined as follow.

Figure 1


x is signal image with MxN dimension, x^ is noisy approximation of x, m and n define the position of the pixel which need to be calculated in two images. x(m,n) and x^(m,n) is the luminance value of the 2 pixels at (m,n).

Figure 2


From the definition of PSNR in figure 2, we can know if the quality of noisy image is very closed to original image, the value of MSE will be very small even close to zero, the value of 2552/MSE will be very large, that’s why use logarithmic decibel scale in the formula.


3 SSIM algorithm


SSIM(Structural SIMilarity) consists of three parts, brightness measurement compare, contrast measurement compare and structure information measurement. The formula is defined as figure 3.

Figure 3

the average of

the average of

the variance of

the variance of

the covariance of  and

Figure 4

wherein: x and y are the original image block and the distorted block; and  denote the mean value of the x and y; δx and δy are respectively standard deviation of x and y; δxy represents the covariance of x and y; parameters α, β, γ are greater than zero, so that can adjust the proportion of three parts. C1, C2 and C3 are small constants and in order to avoid zero denominator, wherein C1=(K1L)2, C2=(K2L)2, C3=C2/2,K1,K2<<1; L is the dynamic range of the pixel.


4 Experimental and results

I) Constants initial

During experiment, the constants of SSIM are set as below:

K1=0.01, K2=0.03, L=255 for 8-bit grayscale image, so C1=5.06,C2=45.56 and C3=22.78, set  α, β, γ  as 1.

II) Database

I choose LIVE Multiply Distorted Image Quality Database for experiment in this report, the version is release 2 which contains 175 Jpeg200 compression images, 169 Jpeg compression images, 145 gaussian blur images, 145 white noise images and 145 images which are with bit errors in JPEG2000 bit stream. It can be downloaded from The image library also gives Difference Mean Opinion Scores (DMOS). The bigger is the DMOS value, the lower is the image quality. I used MOS(100-DMOS) values in the  experiment to make scatter plots are more visualized. That means bigger is MOS value, the higher is the image quality. In this database, all image name, distorted image list and their DMOS values are in Matlab file, but it’s not easy to read them from .net programme, so I decided to copy them out manually and hard-code them as constants in my software, that mean the software can not be commonly used, but it’s enough just for this report.


In order to understand SSIM and PSNR well, I developed a simple software base on .NET platform, programing language is C#.

Because all data information of the image library is in Matlab file, and it’s troublesome to read them from my programer, so I have to copy them from Matlab file and re-organize them in C# code. First of all, I defined images list, reference images and distorted images DMOS values in three arrays instead of reading them from Matlab file.

When the software is running, I can locate the image library folder by clicking “Browse” button, and then select distortion category from 5 radio buttons, follow by clicking “Compute” button to tell the software to scan the folder to find out all distorted images according the category selected, the software will load original image and distorted image one by one and calculate out the PSNR and SSIM values. These values will be shown at window form with MOS value, and also will be marked as points in two charts.

Finally I can get regression line for each chart by clicking “Trendline” button. The UI of the software is shown at figure 5.

Figure 5


In the charts of the software, abscissa is PSNR/SSIM value, ordinate is the MOS(Mean Opinion Scores) value, the core code of this software is attached in appendix A.

In this report all scatter plots are the screenshot of this software, in order to make the charts more clear, I removed table lines and added legend to flag data meaning.

IV) Experiment Results

 Here list out some example data of single image and all distortion category scatter plots.

Figure 6:  image “bikes.bmp” and it’s JPEG2000 compression distorted images.

Figure 7 :image “bikes.bmp” and it’s fast fading distorted images.

Figure 8: Image “bikes” and it’s JPEG compression distorted image

i) Scatter plots of subjective mean opinion score(MOS) versus PSNR and SSIM for Jpeg2000 compression.


ii) Scatter plots of subjective mean opinion score(MOS) versus PSNR and SSIM for Jpeg compression.

iii) Scatter plots of subjective mean opinion score(MOS) versus PSNR and SSIM for gaussian blur.

iv) Scatter plots of subjective mean opinion score(MOS) versus PSNR and SSIM for white noise.

v) Scatter plots of subjective mean opinion score(MOS) versus PSNR and SSIM for fading fast.

5 Conclusion, analyzing and discussion

Compare above scatter plots, we can find that in some case PSNR does not do well, for example, the values in fast fading and jpeg compression are very discreted, and for gaussian blur it’s values are agminated to middle range, actually we can get the answer from it’s definition which is only focus on the measure of difference of pixel. In another case, if we try to compute the MSE between two identical images, the value will be zero and hence the PSNR will be undefined (division by zero).  The main limitation of this metric is that it relies strictly on numeric comparison and does not actually take into account any level of biological factors of the human vision system.

SSIM does better than PSNR from all testing, especially for fast fading, gaussian blur and Jpeg2000 compression, it can evaluate the image from three parts and this method accord with expect of human visual system, but in Jpeg compression and white noise testing it’s result is not good enough to match to MOS. Anyway the results show that the SSIM algorithm can better fit the human visual characteristics than PSNR.

The structural similarity (SSIM) index measures the similarity between two images in a manner that is more consistent with human perception than traditional techniques like mean square error (MSE).  For example, blurred images are perceived as bad quality by the human eye, and this is consistent with results from the SSIM metric, unlike the MSE method, which claims a blurred image is similar to its focused original.

Because of its correlation to human perception, SSIM has become an accepted part of image quality and video analysis practices for analyzing compressed video data.

In conclusion, PSNR is more efficient than SSIM in algorithm. SSIM has strong ability on image quality assessment, but in some case it can not do well, in some paper SSIM was improved to contains more and more image feature, such as contourlet, gradient etc. From those experiment conclusion more image feature included in algorithm the result is more close to mean opinion scores.

Although PSNR has some limit in image quality assessment, but it still is an efficient method, in some situation that request is not very rigorous, PSNR is economic choice. SSIM is much better than PSNR, but the main issue for SSIM is efficiency, so the optimization of the SSIM index for various image processing algorithms needs to be studied.



  1. Zhou Wang, Member, IEEE, Alan Conrad Bovik, Fellow, IEEE, Hamid Rahim Sheikh, Student Member, IEEE, and Eero P. Simoncelli “Image Quality Assessment: From Error Visibility to Structural Similarity” in IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 13, NO. 4, APRIL 2004

  2. Peak signal-to-noise ratio in Wikimedia

  3. Structural similarity in Wikimedia

  4. Similarity check (PSNR and SSIM) on the GPU

Posted in Digital Multiple Media Tagged with: ,

SCI sentences


1. In this paper, we focus on the need for
2. This paper proceeds as follow.
3. The structure of the paper is as follows.
4. In this paper, we shall first briefly introduce fuzzy sets and related concepts
5. To begin with we will provide a brief background on the

1. This will be followed by a description of the fuzzy nature of the problem and a detailed presentation of how the required membership functions are defined.
2. Details on xx and xx are discussed in later sections.
3. In the next section, after a statement of the basic problem, various situations involving possibility knowledge are investigated: first, an entirely possibility model is proposed; then the cases of a fuzzy service time with stochastic arrivals and non fuzzy service rule is studied; lastly, fuzzy service rule are considered.

1. This review is followed by an introduction.
2. A brief summary of some of the relevant concepts in xxx and xxx is presented in Section 2.
3. In the next section, a brief review of the …. is given.
4. In the next section, a short review of … is given with special regard to …
5. Section 2 reviews relevant research related to xx.
6. Section 1.1 briefly surveys the motivation for a methodology of action, while 1.2 looks at the difficulties posed by the complexity of systems and outlines the need for development of possibility methods.

1. Section 1 defines the notion of robustness, and argues for its importance.
2. Section 1 devoted to the basic aspects of the FLC decision making logic.
3. Section 2 gives the background of the problem which includes xxx
4. Section 2 discusses some problems with and approaches to, natural language understanding.
5. Section 2 explains how flexibility which often … can be expressed in terms of fuzzy time window
6. Section 3 discusses the aspects of fuzzy set theory that are used in the …
7. Section 3 describes the system itself in a general way, including the ….. and also discusses how to evaluate system performance.
8. Section 3 describes a new measure of xx.
9. Section 3 demonstrates the use of fuzzy possibility theory in the analysis of xx.
10. Section 3 is a fine description of fuzzy formulation of human decision.
11. Section 3, is developed to the modeling and processing of fuzzy decision rules
12. The main idea of the FLC is described in Section 3 while Section 4 describes the xx strategies.
13. Section 3 and 4 show experimental studies for verifying the proposed model.
14. Section 4 discusses a previous fuzzy set based approach to cost variance investigation.
15. Section 4 gives a specific example of xxx.
16. Section 4 is the experimental study to make a fuzzy model of memory process.
17. Section 4 contains a discussion of the implication of the results of Section 2 and 3.
18. Section 4 applies this fuzzy measure to the analysis of xx and illustrate its use on experimental data.
19. Section 5 presents the primary results of the paper: a fuzzy set model ..
20. Section 5 contains some conclusions plus some ideas for further work.
21. Section 6 illustrates the model with an example.
22. Various ways of justification and the reasons for their choice are discussed very briefly in Section 2.
23. In Section 2 are presented the block diagram expression of a whole model of human DM system
24. In Section 2 we shall list a collection of basic assumptions which a … scheme must satisfy.
25. In Section 2 of this paper, we present representation and uniqueness theorems for the fundamental measurement of fuzziness when the domain of discourse is order dense.
26. In Section 3, we describe the preliminary results of an empirical study currently in progress to verify the measurement model and to construct membership functions.
27. In Section 5 is analyzed the inference process through the two kinds of inference experiments…
This Section
1. In this section, the characteristics and environment under which MRP is designed are described.
2. We will provide in this section basic terminologies and notations which are necessary for the understanding of subsequent results.Next Section
2. The next section describes the mathematics that goes into the computer implementation of such fuzzy logic statements.
3. However, it is cumbersome for this purpose and in practical applications the formulae were rearranged and simplified as discussed in the next section.
4. The three components will be described in the next two section, and an example of xx analysis of a computer information system will then illustrate their use.
5. We can interpret the results of Experiments I and II as in the following sections.
6. The next section summarizes the method in a from that is useful for arguments based on xx

1. This paper concludes with a discussion of future research consideration in section 5.
2. Section 5 summarizes the results of this investigation.
3. Section 5 gives the conclusions and future directions of research.
4. Section 7 provides a summary and a discussion of some extensions of the paper.
5. Finally, conclusions and future work are summarized
6. The basic questions posed above are then discussed and conclusions are drawn.
7. Section 7 is the conclusion of the paper.

Chapter 0. Abstract
1. A basic problem in the design of xx is presented by the choice of a xx rate for the measurement of experimental variables.
2. This paper examines a new measure of xx in xx based on fuzzy mathematics which overcomes the difficulties found in other xx measures.
3. This paper describes a system for the analysis of the xx.
4. The method involves the construction of xx from fuzzy relations.
5. The procedure is useful in analyzing how groups reach a decision.
6. The technique used is to employ a newly developed and versatile xx algorithm.
7. The usefulness of xx is also considered.
8. A brief methodology used in xx is discussed.
9. The analysis is useful in xx and xx problem.
10. A model is developed for a xx analysis using fuzzy matrices.
11. Algorithms to combine these estimates and produce a xx are presented and justified.
12. The use of the method is discussed and an example is given.
13. Results of an experimental applications of this xx analysis procedure are given to illustrate the proposed technique.
14. This paper analyses problems in
15. This paper outlines the functions carried out by …
16. This paper includes an illustration of the …
17. This paper provides an overview and information useful for approaching
18. Emphasis is placed on the construction of a criterion function by which the xx in achieving a hierarchical system of objectives are evaluated.
19. The main emphasis is placed on the problem of xx
20. Our proposed model is verified through experimental study.
21. The experimental results reveal interesting examples of fuzzy phases of: xx, xx
22. The compatibility of a project in terms of cost, and xx are likewise represented by linguistic variables.
23. A didactic example is included to illustrate the computational procedure

Chapter 1. Introduction
1. Over the course of the past 30 years, .. has emerged form intuitive
2. Technological revolutions have recently hit the industrial world
3. The advent of … systems for has had a significant impact on the
4. The development of … is explored
5. During the past decade, the theory of fuzzy sets has developed in a variety of directions
6.The concept of xx was investigated quite intensively in recent years
7. There has been a turning point in … methodology in accordance with the advent of …
8. A major concern in … today is to continue to improve…
9. A xx is a latecomer in the part representation arena.
10. At the time of this writing, there is still no standard way of xx
11. Although a lot of effort is being spent on improving these weaknesses, the efficient and effective method has yet to be developed.
12. The pioneer work can be traced to xx [1965].
13. To date, none of the methods developed is perfect and all are far from ready to be used in commercial systems.

Objective / Goal / Purpose
1. The purpose of the inference engine can be outlined as follows:
2. The ultimate goal of the xx system is to allow the non experts to utilize the existing knowledge in the area of manual handling of loads, and to provide intelligent, computer aided instruction for xxx.
3. The paper concerns the development of a xx
4. The scope of this research lies in
5. The main theme of the paper is the application of rule based decision making.
6. These objectives are to be met with such thoroughness and confidence as to permit …
7. The objectives of the … operations study are as follows:
8. The primary purpose/consideration/objective of
9. The ultimate goal of this concept is to provide
10. The main objective of such a … system is to
11. The aim of this paper is to provide methods to construct such probability distribution.
12. In order to achieve these objectives, an xx must meet the following requirements:
13. In order to take advantage of their similarity
14. more research is still required before final goal of … can be completed
15. In this trial, the objective is to generate…
16. for the sake of concentrating on … research issues
17. A major goal of this report is to extend the utilization of a recently developed procedure for the xx.
18. For an illustrative purpose, four well known OR problems are studied in presence of fuzzy data: xx.
19. A major thrust of the paper is to discuss approaches and strategies for structuring ..methods
20. This illustration points out the need to specify
21. The ultimate goal is both descriptive and prescriptive.
22. Chapter 2. Literature Review
23. A wealth of information is to be found in the statistics literature, for example, regarding xx
24. A considerable amount of research has been done .. during the last decade
25. A great number of studies report on the treatment of uncertainties associated with xx.
26. There is considerable amount of literature on planning
27. However, these studies do not provide much attention to uncertainty in xx.
28. Since then, the subject has been extensively explored and it is still under investigation as well in
methodological aspects as in concrete applications.
29. Many research studies have been carried out on this topic.
30. Problem of xx draws recently more and more attention of system analysis.
31. Attempts to resolve this dilemma have resulted in the development of
32. Many complex processes unfortunately, do not yield to this design procedure and have, therefore, not yet been automated.
33. Most of the methods developed so far are deterministic and /or probabilistic in nature.
34. The central issue in all these studies is to
35. The problem of xx has been studied by other investigators, however, these studies have been based upon classical statistical approaches.
36. Applied … techniques to
37. Characterized the … system as
38. Developed an algorithm to
39. Developed a system called … which
40. Uses an iterative algorithm to deduce
41. Emphasized the need to
42. Identifies six key issues surrounding high technology
43. A comprehensive study of the… has been undertaken
44. Much work has been reported recently in these filed
45. Proposed/Presented/State that/Described/Illustrated/
Indicated/Has shown / showed/Address/Highlights
46. Point out that the problem of
47. A study on …was done / developed by []
48. Previous work, such as [] and [], deal only with
49. The approach taken by [] is
50. The system developed by [] consists
51. A paper relevant to this research was published by []
52. []’s model requires consideration of…
53. []’ model draws attention to evolution in human development
54. []’s model focuses on…
55. Little research has been conducted in applying … to
56. The published information that is relevant to this research…
57. This study further shows that
58. Their work is based on the principle of
59. More history of … can be found in xx et al. [1979].
60. Studies have been completed to established
61. The …studies indicated that
62. Though application of xx in the filed of xx has proliferated in recent years, effort in analyzing xx, especially xx, is lacking.
Problem / Issue / Question
63. Unfortunately, real-world engineering problems such as manufacturing planning do not fit well with this narrowly defined model. They tend to span broad activities and require consideration of multiple aspects.
64. Remedy / solve / alleviate these problems
67. … is a difficult problem, yet to be adequately resolved
68. Two major problems have yet to be addressed
69. An unanswered question
70. This problem in essence involves using x to obtain a solution.
71. An additional research issue to be tackled is ….
72. Some important issues in developing a … system are discussed
73. The three prime issues can be summarized:
74. The situation leads to the problem of how to determine the …
75. There have been many attempts to
76. It is expected to be serious barrier to
77. It offers a simple solution in a limited domain for a complex

Posted in Uncategorized

Cursor list in Glut


There are a lot of cursors we can use in glut window for our OpenGL programming.

value name cursor style
Posted in Uncategorized Tagged with:

XOR operator in javascript


How to predicate every character  in a string is number (0-9)?

normal way 1: validate by regular express

normal way 2: use parseInt() function

normal way 3: use isNaN() function

There are some other method also can do such checking, for example, check every character by loop etc.

We also can use XOR operator to do such work:


Exchange the value of tow variable

In normal way, we have to declare third variable to help  do such exchange work like below:

XOR operator can do it easily without third variable:

 Predicate tow int variable are same


Posted in Javascript Tagged with:

How to make jQuery validation engine works well for select2()

How to make jQuery validation engine works well for select2()


When we use select2 to prettify selector , the jQuery validation engine will do not work well for it. A lot of people have to do custom validation function to hand over it.

It’s very troublesome, is there any way to solve this problem?

Select2 library make the original selector hidden, and validation engine can not work for hidden element, so first is make the <select> visible, then the validation engine can see it. The second is we need to make the selector element hidden for us, there are about 2 ways to do, such as set it’s opacity into “0”, or make it’s height/width as “0px”, actually we need both.

Below is the code example:



Posted in Javascript Tagged with: , ,

101 LINQ Samples


Learn how to use LINQ in your applications with these code samples, covering the entire range of LINQ functionality and demonstrating LINQ with SQL, DataSets, and XML.

Posted in ASP.NET Tagged with:

Warning! WP Super Cache caching broken! The script advanced-cache.php could not load wp-cache-phase1.php.


After upgraded WordPress into latest version, encounter a warning message show as:

Warning! WP Super Cache caching broken! The script advanced-cache.php could not load wp-cache-phase1.php.

fixed this problem by modifying wp-config.php, add below code



Posted in Uncategorized Tagged with: ,