You are on page 1of 24

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELAGAVI-590014, KARNATAKA

A Mini Project Report


On

“PRIM’S ALGORITHM”
Submitted in Partial Fulfillment of the Requirement for
“Computer Graphics Laboratory with Mini Project-VI Semester”

For the Award of Degree

BACHELOR OF ENGINEERING

IN

COMPUTER SCIENCE & ENGINEERING


Submitted By:

FOUZIA ANJUM.S (1SG18CS030)

MEGHANA G (1SG18CS054)

Under the Guidance of:


Mrs. CHAITHRA
Associate Professor

Department of Computer Science and Engineering


SAPTHAGIRI COLLEGE OF ENGINEERING
(Affiliated to Visvesvaraya Technological University, Belagavi& Approved by AICTE, New Delhi.)
ISO 9001-2015 & 14001-2015 Certified, Accredited by NAAC with ‘A’ Grade
#14/5, Chikkasandra, Hesaraghatta Main Road,
Bengaluru-560057
2020-2021
SAPTHAGIRI COLLEGE OF ENGINEERING
(Affiliated to Visvesvaraya Technological University, Belagavi& Approved by AICTE, New Delhi.)
ISO 9001-2015 & 14001-2015 Certified, Accredited by NAAC with ‘A’ Grade
#14/5, Chikkasandra, Hesaraghatta Main Road, Bengaluru-560057

Department of Computer Science and Engineering

Certificate
This is to certify that the Mini Project Work entitled “PRIM’S ALGORITHM” carried
out by FOUZIA ANJUM. S (1SG18CS030) & MEGHANA G (1SG18CS054), bonafide
students of Sapthagiri College of Engineering, in partial fulfillment for the award of
Bachelor of Engineering degree in Computer Science and Engineering of
Visvesvaraya Technological University, Belagavi during the academic year 2020-21. It
is certified that all corrections/suggestions indicated for Internal Assessment have been
incorporated in the report deposited in the department library. The mini-project report has
been approved as it satisfies the academic requirements in respect of Computer Graphics
Laboratory with Mini Project (18CSL67) prescribed for the said Degree.

Signature of the Guide Signature of the HOD


Prof. Chaithra Dr. Kamalakshi Naganna
Associate Professor Professor & Head

EXTERNAL EXAMINATION

Name of the Examiners Signature with Date

1. _____________________ _____________________

2. _____________________ _____________________
ACKNOWLEDGEMENT

The satisfaction and euphoria that accompany the completion of any task would be
incomplete without the mention of the people who made it possible, whose constant guidance
and encouragement ground my efforts with success.

I consider it is a privilege to express my gratitude and respect to all those who guided me in
completion of technical seminar.

I am, grateful to thank our Principal Dr. H Ramakrishna, Sapthagiri College of Engineering,
who patronized throughout my career and for the facilities provided to carry out this work
successfully.

It’s a great privilege to place on record my deep sense of gratitude to our beloved HOD Dr.
Kamalakshi Naganna of Computer Science and Engineering, who patronized throughout my
career and for the facilities provided to carry out this work successfully.

I am also grateful to thank our mini project Guides Prof. Chaithra , Associate Professor and
Mrs. Manasa K N, Assistant Professor of CSE department for her invaluable support and
guidance.

I would also like to thank the teaching and non-teaching staff members who have helped me
directly or indirectly during the technical seminar.

Lastly but most importantly I would like thank my family and friends for their co- operation
and motivation to complete this seminar successfully.

FOUZIA ANJUM.S (1SG18CS030)

MEGHANA G (1SG18CS054)
ABSTRACT

This project demonstrates a simple illustration of Prim’s Algorithm. Here the arrays of
elements are represented in the form of circles with different radii. Minimum Spanning Tree
is generated with the help of given costs.

Here we use the keyboard as an input device. Keyboard events are generated when the mouse
is in the window and one of the keys is pressed or released.

The GLUT function glutKeyboardFunc is the callback for events generated by pressing the
key. When it occurs the ASCII code for the key that generated the event and the location of
the mouse are returned.

All the keyboard callbacks are registered in a single callback function, such as the following:
glutKeyboardFunc(keyboard);

The callback is specified in GLUT by the following function call:glutDisplayFunc(display);

It is invoked when GLUT determines that the window should be redisplayed.


TABLE OF CONTENTS
SL No. CHAPTERS PAGE No.
1 Introduction 7

1.1. Overview Of The Project 8

1.2. Aim Of The Project 9

2 Requirement Specification 10

2.1 Functional Requirements 10

2.2 Non Functional Requirements 11

2.2.1. Dependability
2.2.2. Availability

2.2.3. Reliability

2.2.4. Safety

2.2.5. Security

2.3. Details of the Software 11

2.3.1. Microsoft Visual C++

2.3.2. OpenGL and GLUT

2.4. Software Requirements 12

2.5. Hardware Requirements 12

3 Design 13

4 Implementation 14

4.1. Built-in Functions

4.2. User Defined Functions

5 Testing 18

6 Snapshots 19

7 Conclusion 22
23
Bibliography

LIST OF FIGURES
SL. No. Figure No. Title Of Figure Page No.

1 1.1 Library organization of 8


OpenGL

2 1.2 Flow chart for Representation 13


of Prim’s Algorithm

3 2.1 Main Page 19

4 2.2 Main Menu 19

5 2.3 Prim’s Algorithm Visualizer 20

6 2.4 Spanning Tree Representation 20

7 2.5 Matrix Representation 21

CHAPTER 1
INTRODUCTION
The Computer Graphics is one of the most effective and commonly used methods to
communicate the processed information to the user. It displays the information in the form of
graphics objects such as pictures, charts, graphs and diagram instead of simple text.
In computer graphics, pictures or graphics objects are presented as a collection of discrete
picture elements called pixels. The pixel is the smallest addressable screen element.
Computer graphics today is largely interactive: The user controls the contents structure, and
appearance of objects and their displayed images by using input devices, such as a keyboard,
mouse, or touch-sensitive panel on the screen.

The image processing can be classified as


 Image enhancement.
 Pattern detection and recognition
 Scene analysis and computer vision.

The image enhancement deals with the improvement in the image quality by eliminating
noise or by increasing image contrast. Pattern detection and recognition deals with the
detection and clarification of standard patterns and finding deviations from these
patterns .The optical character recognition (OCR) technology is an practical example for
pattern detection & recognition. Scene analysis deals with the recognition and reconstruction
of 3D model of scene from several 2D images.

The applications of computer graphics in some of the major areas are as


follows:-

1. Display of information.
2. Design.
3. Simulation and Animation.
4. User interfaces.
1.1 Overview of the project
Implementing certain technical concepts like transformation. To show that implementation of
bubble sort and selection sort graphically. Migration from text editor to OpenGL. Consists of
array of elements represented in the form of circles in random order. Sorting the randomized
elements.
Displaying the elements that are being swapped.

The various concepts used in this application are as follows:


Menus:
OpenGL supports simple cascading pop-up menus. In this application simple pop-up menus
along with the submenu are used to provide a simple user interface. The menu will pop up by
clicking the right mouse button.

Blending:
The project uses blending to make objects appear transparent.
Transformations:
A transformation is a function that takes a point or vector and maps that point or vector into
another point or vector. In this application the transformation is used to make the plane to
rotate in all 3 axis.

Bitmap Character:
OpenGL supports two kinds of texts: bitmap character and stroke character. Bitmap
characters are basically 2D font without thickness. In this application bitmap character is used
to display the texts.

The main features of the project are as follows:


 The application is user friendly, thereby it can be used by children and who do not
know computer in depth too.
 As provision for future development.
 It has many options of keyboard functions.
 It has a good visual effect.

2.5 Aim of the Project


Prims Algorithm
The algorithm may informally be described as performing the following steps:

1. Initialize a tree with a single vertex, chosen arbitrarily from the graph.
2. Grow the tree by one edge: of the edges that connect the tree to vertices not yet in the
tree, find the minimum-weight edge, and transfer it to the tree.
3. Repeat step 2 (until all vertices are in the tree).

The project has been implemented in modules so as to make it user friendly i.e. if a code
viewer is finding trouble with a particular function it can go to a particular module and make
corresponding changes in it instead of searching in the program. Also it is more advantageous
for future modifications as when modifications are to be made instead of searching the whole
program module search can be useful as it decreases the time consumption.
CHAPTER 2
REQUIREMENT SPECIFICATION
A software requirement definition is an abstract description of the services which the system
should provide, and the constraints under which the system must operate. It should only
specify the external behaviour of the system.

2.1 Functional requirements


In software engineering, a functional requirement defines a function of a software system or
its component. A function is described as a set of inputs, the behaviour, and outputs (see also
software). Functional requirements may be calculations, technical details, data manipulation
and processing and other specific functionality that define what a system is supposed to
accomplish.
Behavioral requirements describing all the cases where the system uses the functional
requirements are captured in use cases.

The various methods used in this project are as follows:


 Display
The module draws the output on the screen and the functions in it.
 Menu
This module specifies the action corresponding to menu entry.
 Keyboard
The module specifies the action corresponding to the keyboard.
 Idle
This module is used to display the object more times using some delay t.
Reading 10 random numbers between 1 and 20
Perform selection sort in descending order.

2.2Non-functional requirements:
These are constraints on the services or functions offered by the system. They include timing
constraints, constraints on the development process and standards. Non-functional
requirements often apply to the system as a whole.
Non-Functional Requirements are as follows:

2.2.1 Dependability:
The dependability of a computer system is a property of the system that equates to its
trustworthiness. Trustworthiness essentially means the degree of user confidence that the
system will operate as they expect and that the system will not ‘fail’ in normal use.

2.2.2 Availability:
The ability of the system to deliver services when requested. There is no error in the program
while executing the program.

2.2.3 Reliability:
The ability of the system to deliver services as specified. The program is compatible with all
types of operating system without any failure.

2.2.4 Safety:
The ability of the system to operate without catastrophic failure. This program is user friendly
and it will never effects the system.

2.5.2 Security:
The ability of the system to protect itself against accidental or deliberate intrusion.

2.3 Details of the software


Here, the coding of our project is done in Microsoft Visual C++ which is a commercial
integrated development environment (IDE) with OpenGL (Open Graphics Library) which is a
standard specification to produce 2D and 3D computer graphics. We use, the OpenGL Utility
Toolkit called GLUT which is a library of utilities for OpenGL programs.

2.3.1 Microsoft Visual C++


Microsoft Visual C++ is a commercial integrated development environment (IDE) product
engineered by Microsoft for the C, C++ and C++/CLI programming languages. It has tools
for developing and debugging C++ code, especially code written for the Microsoft Windows
API, OpenGL API, the DirectX API and the Microsoft .NET Framework.
2.3.2 OpenGL and GLUT
OpenGL (Open Graphics Library) is a standard specification defining a cross-
language, cross-platform API for writing applications that produce 2D and 3D computer
graphics, describing a set of functions and the precise behaviours that they must perform.
From this specification, hardware vendors create implementations – libraries of functions
created to match the functions stated in the OpenGL specification, making use of hardware
acceleration where possible. Hardware vendors have to meet specific tests to be able to
qualify their implementation as an OpenGL implementation. GLUT is the OpenGL Utility
Toolkit, a window system independent toolkit for writing OpenGL programs. It implements a
simple windowing application programming interface (API)for
OpenGL. GLUT makes it considerably easier to learn about and explore OpenGL
programming. GLUT provides a portable API so you can write a single OpenGL program
that works across all PC and workstation OS platforms.

2.4 Software requirements

 OPERATING SYSTEM: Windows 98, Windows XP, Windows Vista, Windows 7


 FRONT END: Microsoft Visual Studio 2010
 CODING LANGUAGE: C++

2.5 Hardware requirements

 SYSTEM: Pentium IV 2.4 GHz or above


 HARD DISK: 40 GB, 80 GB, 160 GB or above
 MONITOR: 15 VGA colour
 RAM: 256 MB, 512 MB, 1 GB or above
CHAPTER 3:
DESIGN

Data flow design is as shown below covering the flow of the data in the system. It describes
the relation between user input and the system behaviour.

START

Main

Initialize OpenGL Callback


Functions

Click
Enter
No

1.Create Nodes
List of Menus 2.Draw Edges
3.Draw
Spanning Tree

Yes

Run and print matrix

STOP

Figure 1.2
CHAPTER 4:
IMPLEMENTATION

To implement the Current System, we have used different functions of our project which are
as follows:

OpenGL built-in functions:


1. glutKeyboardFunc :-sets the keyboard callback for the current window.

2. GL_POLYGON:-Draws a single, convex polygon. Vertices 1 through N define this


polygon.
3.  glutBitmapCharacter :-renders a bitmap character using OpenGL.

4.  glutPostRedisplay:- marks the current window as needing to be redisplayed.

5. glMatrixMode:- sets the current matrix mode.

6. glClearColor :-specify clear values for the color buffers.

7. glLoadIdentity:- replace the current matrix with the identity matrix.

8. gluOrtho2D:- define a 2D orthographic projection matrix.

9. glFlush:- force execution of GL commands in finite time

10. glutInitDisplayMode :-sets the initial display mode.

11. glViewport :- set the viewport.

12.  glutInitWindowPosition and   glutInitWindowSize set the initial

window position and size respectively.
13.  glutCreateWindow:-creates a top-level window.

14.   glutMouseFunc:-sets the mouse callback for the current window.

15. glutReshapeFunc:- sets the reshape callback for the current window.

16. glutAddMenuEntry:- adds a menu entry to the bottom of the current

menu.
17. glutMainLoop:- enters the GLUT event processing loop.

18. glutAttachMenu:- attaches a mouse button for the current window to the identifier


of the current menu.
19. glutCreateMenu:- creates a new pop-up menu.
20. glPointSize:-specify the diameter of rasterized points.

OpenGL user defined functions:


1. int_str()
signature: void int_str(int rad,char r[])
Description: This function writes the integer into char array
2. push()
signature: void push(int n)
Description: whenever undo function is called the cost is pushed into the stack
3. pop()
signature: int pop()
Description: when redo function is called the cost is popped out
4. drawpoint()
signature: void drawpoint()
Description: this function creates nodes using location stored in oldx[][] array
5. bitmap_output()
signature: void bitmap_output(int x, int y, char *string, void *font)
Description: This function prints text in graphics window
6. delay()
signature: void delay()
Description: this delays out execution of next instruction
7. frontpage()
Signature: void frontpage()
Description: this function displays staring window
8. Instructions()
signature: void Instructions()
Description: this function displays text instructions in grpahics windwow
9. drawline()
signature: void drawline()
Description: this function draws edges using location stored in linex array
10. blinking_lines()
signature: void blinking_lines()
Description: this function does animation of lines connecting after calculating spanning tree
11. drawPointAt()
signature: void drawPointAt(float x,float y)
Description: this displays a point when mouse clicked for first time in draw edge mode
12. loadpage()
signature: void loadpage()
Description: this function mimics loading animation
13. output()
signature: void output()
Description: this function displays text output after calculating spanning tree
14. display()
signature: void display()
Description: this is callback function called by OpenGL
15. reshape()
signature: void reshape(int w, int h)
Description: this is reshape callback function called by OpenGL whenever window is resized
16. input()
signature: void input()
Description: this function takes cost input from user during edge drawing
17. mousefun()
signature: void mousefun(int button,int state,int x,int y)
Description: this is mouse callback function called by OpenGL whenever mouse event occurs
18. printmatrix()
signature: void printmatrix()
Description: this function will print matrix constructed
19. isconnected()
signature: bool isconnected()
Description: this checks if the graph is connected or not
20. undo()
signature: void undo()
Description: this undo the drawing in the order the graph was drawn
21. redo()
signature: void redo()
Description: this redo the drawing in the order the graph was drawn
22. find()
signature: void find()
Description: this will call find_spanning_tree function if graph is connected
23. selectedge()
signature: void selectedge()
Description: this will select edge draw mode
24. selectnode()
signature: void selectnode()
Description: this will select node draw mode
25. keyboardfun()
signature: void keyboardfun(unsigned char key,int x,int y)
Description: this is keyboard callback function called by OpenGL whenever keyboard event
occurs
26. menu()
signature: void menu(int id)
Description: this is menu callback function called by OpenGL as menu function
27. find_spanning_tree()
signature: void find_spanning_tree()
Description: this function calculates spanning tree using Prim's algorithm
28. main()
signature: int main(int argc,char** argv)
Description: Program execution starts from here
CHAPTER 5:
TESTING

Testing has been conducted as tabulated below.

SL.No. Functions with Expected result Actual result Comments


parameters
under test
1 All the output The object and The object and PASS
statement must be in particle drop should Particle appeared.
their position appear at the
mentioned window

2 Moving function The Object has to be The object has PASS


Moved from one to be Moved
location to desired
location

3 Key Function When enter is The keys has to PASS


pressed it has to work properly,
display the Prim’s has per menu.
Algorithm window.
When ‘N’ is pressed,
it has to create
nodes. When ‘E’ is
pressed, it has to
draw edges, and
when ‘D’ is pressed
it has to draw
spanning tree.

4 Run Option When run is pressed Spanning tree is PASS


it has to show the generated
working of Prim’s
algorithm

5 Print Matrix When Print matrix is Matrix is displayed PASS


selected it has to
display the matrix
CHAPTER 6:
SNAPSHOTS

6.1 Main Page:

Figure 2.1

6.2 Main Menu


Figure 2.2
6.3 Prim’s Algorithm Visualiser:

Figure 2.3

6.4 Spanning Tree Representation:


Figure 2.4
6.5 Matrix Representation:

Figure 2.5
CHAPTER 7:

CONCLUSION

We have attempted to design and implement “Prim’s Algorithm”. OpenGL supports


enormous flexibility in the design and the use of OpenGL graphics program.

The presence of many built-in functions take care of much functionality and reduce the job of
coding as well as make the implementation simpler. We have implemented the project
making it user friendly and error free as much as possible.

The development of the project is not an easy process as it involves lot of challenges in
different stages of software analysis, design, coding and testing.

Having understood the requirements properly and implementing the solutions as per the
expectation as brought to the closure of the project.

We have tried our best to make this project very realistic, so that the user does not face any
trouble when switching over from any real life graphics project to this highly useful one.
In this project the graphics used makes any user fascinating to look into the output sreen.In
future this program can be improved by using more advanced OpenGL functions.

BIBILOGRAPHY

Reference Books:

1. “Interactive Computer Graphics- A Top-Down Approach Using OpenGL” By Edward


Angel
2. “Computer Graphics under C” By Yeshwant Kanetkar
3. The OpenGL programming guide – The red book
4. Donald Hearn and Pauline Baker: Computer Graphics-OpenGL Version,2nd edition

Websites:

1. www.opengl.org
2. www.google.co.in(OpenGLprojects)
3. www.wikipedia.com
4. www.youtube.com
5. www.github.com

You might also like