Bresenham’s Line Drawing Algorithm

Write a program to implement Bresanham’s line drawing algorithm.


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void Bline(int,int,int,int);
void main()
{
	int x1,y1,x2,y2;
	int gd=DETECT,gm;
	initgraph(&gd,&gm,"c:\\tc\\bgi");
	printf("\n Enter the coordinates: ");
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	Bline(x1,y1,x2,y2);
	getch();
	closegraph();
}
void Bline(int x1,int y1,int x2,int y2)
{
	int dx,dy,tdy,tdydx,x,y,xend,flag=0,yend;
	long p;
	dy=abs(y1-y2);
	dx=abs(x1-x2);
	p=2*dy-dx;
	tdy=2*dy;
	tdydx=2*(dy-dx);
	if(x1>x2)
	{
		x=x2;
		y=y2;
		xend=x1;
		if(y2>y1)
			flag=1;
	}
	else
	{
		x=x1;
		y=y1;
		xend=x2;
		if(y1>y2)
			flag=1;
	}
	putpixel(x,y,WHITE);
	if(x1==x2)
	{
		if(y1<y2)
		{
			y=y1;
			yend=y2;
		}
		else
		{
			y=y2;
			yend=y1;
		}
		while(y<yend)
		{
			y++;
			putpixel(x,y,WHITE);
		}
	}
	else
	{
		while(x<xend)
		{
			x++;
			if(p<0)
				p+=tdy;
			else
			{
				if(flag==1)
					y--;
				else
					y++;
				p+=tdydx;
			}
			putpixel(x,y,WHITE);
		}
	}
	putpixel(0,0,WHITE);
	putpixel(639,479,WHITE);
}

Output
1

DDA Line Drawing Algorithm

Write a program to implement DDA line drawing algorithm.

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#define ROUND(a) ((int)(a+.5))

void dda(int,int,int,int);
void main()
{
	int gd=DETECT,gm,x1,x2,y1,y2;
	initgraph(&gd,&gm,"c:\\tc\\bgi");
	printf("\nEnter the coordinates: ");
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	dda(x1,y1,x2,y2);
	getch();
	closegraph();
}

void dda(int x1,int y1,int x2,int y2)
{
	int dx,dy,steps,k;
	float xin,yin,x,y;
	dx=x2-x1;
	dy=y2-y1;
	x=x1;
	y=y1;
	if(abs(dx)>abs(dy))
		steps=abs(dx);
	else
		steps=abs(dy);
	xin=dx/(float)steps;
	yin=dy/(float)steps;
	putpixel(ROUND(x),ROUND(y),WHITE);
	for(k=0;k<steps;k++)
	{
		x+=(xin);
		y+=(yin);
		putpixel(ROUND(x),ROUND(y),WHITE);
	}
}

Output
1

Basic Graph Functions

 

1) INITGRAPH

  • Initializes the graphics system.
  • Initgraph initializes the graphic system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode.
  • Initgraph also resets all graphics settings (color, palette, current position, viewport, etc) to their defaults.

Declaration

void far initgraph(int far *graphdriver)

 

2) GETPIXEL, PUTPIXEL

  • Getpixel gets the color of a specified pixel.
  • Putpixel places a pixel at a specified point.

Declaration

unsigned far getpixel(int x, int y)

void far putpixel(int x, int y, int color)

 

3) CLOSE GRAPH

  • Shuts down the graphic system.
  • Close graph deallocates all memory allocated by the graphic system.
  • It then restores the screen to the mode it was in before you called initgraph.

Declaration

void far closegraph(void);

 

4) ARC, CIRCLE

  • Arc draws a circular arc in the current drawing color
  • Circle draws a circle in the current drawing color

Declaration

void far arc(int x, int y, int stangle, int endangle, int radius);

void far circle(int x, int y, int radius);

void far pieslice(int x, int y, int stangle, int endangle, int radius);

 

5) ELLIPSE, FILLELIPSE, SECTOR

  • ellipse draws an elliptical arc in the current drawing color.
  • fillellipse draws an elliptical arc in the current drawing color and then fills it with fill color and fill pattern.
  • sector draws an elliptical pie slice in the current drawing color and then fills it using the pattern and color defined by setfillstyle or setfillpattern.

Declaration

void far ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius)

void far fillellipse(int x, int y, int xradius, int yradius)

void farsectoe(int x, int y, int stangle, int endangle, int xradius, int yradius)

 

6) FLOODFILL

  • Floodfills an enclosed area on bitmap device.
  • The area bounded by the color border is flooded with the current fill pattern and fill color.

Declaration

void far floodfill(int x, int y, int border)

 

7) GETCOLOR, SETCOLOR

  • Getcolor returns the current drawing color.
  • Setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor.
  • To set a drawing color with setcolor , you can pass either the color number or the
  • equivalent color name.

Declaration

int far getcolor(void);

void far setcolor(int color)

 

8) LINE,LINETO

  • Line draws a line from (x1, y1) to (x2, y2) using the current color, line style and thickness.
  • It does not update the current position (CP).
  • Lineto draws a line from the CP to (x, y), then moves the CP to (x,y).

 

Declaration

void far lineto(int x, int y)

 

9) RECTANGLE

  • It draws a rectangle in the current line style, thickness and drawing color.
  • (left, top) is the upper left corner of the rectangle, and (right, bottom) is its lower right corner.

Declaration

void far rectangle(int left, int top, int right, int bottom)

 

JAX RS 2.0 on Weblogic 12.1.3

Java API for RESTful Web Services (JAX-RS) is a Java programming language API that provides support in creating web services according to the REST architecture. JAX-RS uses annotations, introduced in Java SE 5, to simplify the development and deployment of web service clients and endpoints.

Support for JAX-RS 2.0 in WebLogic Server 12.1.3 is provided through the integration of the Jersey 2.5.1 library. The Jersey 2.5.1 library provides the Reference Implementation (RI) of JSR-399 (JAX-RS 2.0: Java API for RESTful Web Services) and is delivered as a shared library. So the first step is to register the Jersey 2.5.1 shared library.

Registering the Jersey 2.5.1 (JAX-RS 2.0 RI) Shared Library With Your WebLogic Server Instances

Using the administrative console, we can register the library by following these steps:

  1. Log into the WebLogic Server Administration : http://host:port/console
  2. Select Deployments.
  3. Click Install to install the shared library.
  4. In the Path field, enter or navigate to the following directory: MW_HOME\wlserver\common\deployable-libraries.
  5. Select the jax-rs-2.0.war file.
  6. Click Next.
  7. Select Install this deployment as a library.
  8. Click Next.
  9. Click Finish.

Create a sample Web Application

For creating the web application I prefer to use Eclipse for Java EE. I created a new Dynamic Web Project. For the demo purpose, I am going to create a simple web application and not an Enterprise web application, which is recommended by Oracle.

1jax

Create a package

2jax

Create class

Created an Example class and scripted a simple Hello world Application.(Note the folder structure to the right of the image)

3jax

Export as a WAR file

5jax

Deploy the application on the weblogic server

4jax

Test

Access the rest url via a browser to test. http://<host>:<port>/<contextPath>/resources/helloworld

6jax

 

 

Oracle Database In-Memory

The In-Memory database has been a buzz word in the industry for quite some time as major companies like SAP, IBM, and Microsoft has released their products which packs breakthrough performance than the regular databases. Database pioneers Oracle, is now joining the league with the ‘Oracle Database In-Memory’ capability to their flagship database product “Oracle Database 12c”.

Larry Ellison, CEO, Oracle Corporation announced “Oracle Database In-Memory” in a special event held at the Oracle Headquarters on June 10th 2014.

Oracle Database In-Memory will pack extreme performance, availability and lucid simplicity. I have a brief summary of his release keynote:

The main goals of developing the Oracle In-Memory database are to provide:

  1. 100X faster query processing
  2. 2X speed for processing OLTP
  3. Provide Transparency

He said that all the In-Memory databases in the marker right now, start and end in achieving only the first goal of faster query processing. But Oracle has been very strong on sticking to all three of these goals which, made it enter into the market bit late. OLTP processing and the query processing has a complimentary behavior when it comes to performance. So, to have both of them work with little trade-off was the biggest challenge. But now Oracle has come up with a smart solution which will make the product stand out in the industry.

Migrating your existing application utilize the In-Memory option would actually be a cake walk. Larry says, “You have got to install the In-Memory option, throw a switch, and then all your applications run faster”. There would absolutely be no code changes at all.

There are two different database formats:

  1. Traditional relational databases, in which the data is organizes as rows
  2. Analytic databases, in which the data is organized as columns.

The relational databases are great for transactional processing, in which you have all the columns of a limited number of rows, and the analytic databases are excellent for doing analytic calculations and report generation. We need to have best of both these database formats to push the performance limits further. And here is where, the innovation from Oracle comes.

It stores the data in two formats in memory. The old row format, which has been the de-facto standard till now has been kept as it is but by the introduction of the column format, in In-Memory option will scale up the performance limits.

Some data in the column format is brought In-Memory. Highly compressed data in the column format is brought into the column cache (In-Memory) from the flash or disk as and when needed. The column data is not persistent and hence is not logged. The real data still remain in the row format.

Using the SIMD processing which is right now used for hardware acceleration, is put to use, which would enable a single core of the CPU to scan billions of rows per second. The join operation in database can be converted into fast scans in the In-Memory option. This will ensure at least 10X performance improvement. Dropping the analytical indexed for the OLTP processing can improve performance many fold. They can be replaced with the column store.

The main features of Oracle Database In-Memory are:

  1. Scale out

The In-Memory feature simply scales out from a multi-socket server, to an Exadata machine or even to SPARC M6-32 Server. There is an inherent memory hierarchy in the system. All the data need not be in the memory at an instance. Suppose we have 200 TB data of which only 10 TB is on active use, then then 10 TB can be accommodated in the memory and the rest can be spread out between the flash storage and the disks.

  1.   Fault Tolerance

“If one of your Exadata nodes fail, then what? The application simply runs.” That’s what Larry says. The column cache is mirrored across at-least 2 nodes, which makes it a fault tolerant system. Larry claims that the Oracle Database In-Memory, is the only product in the market to be fault tolerant.

  1. Availability

By maintain the time tested, row oriented database structure in place, Oracle claims high reliability and availability. The data that is stored in the disk is row oriented. The whole system is protected against node failure, site failure, corruption or human error.

  1. Transparent

Setting up the Oracle Database In-Memory option involves only these three tasks:

  1. Configure the main memory capacity that the In-Memory tool can use to setup the column cache.
  2. Configure the tables or partition to be kept in memory.
  3. *Drop the analytic indexes to speed up the OLTP. (*optional)

“You are done, that’s it, nothing else”, says Larry.

 

The Oracle Database In-Memory is cloud ready. All the applications can run faster by utilizing this feature. Larry showcased the Oracle E-Business Suite, Oracle PeopleSoft, Fusion Applications and Oracle Siebel in his presentation. The ability to run legacy applications like PeopleSoft and the latest Fusion Applications with no code change at all proves the mettle of Oracle Database In-Memory.

An analytic program in Oracle E-Business Suite, which took 58 hours before now takes just 13 minutes. A financial analyzer based on PeopleSoft performs 1300X faster from 4.3 hours to 11.5 seconds. All these statistics are from real application running on real database in real companies.

The companies are going to benefit a lot when this kind of performance overhaul comes in. Information comes in faster than what they get today. So they will ask questions more frequently, and those questions will be more complicated. The whole business process will have a boost by utilizing this technology.

Juan Loaiza, Senior Vice President, Systems Technology, Oracle Corporation, demonstrated the high availability, improved performance and the scaling feature on a 2 socket server, an Exadata and a M6-32 Server. Trillions of rows were processed in mere seconds.

Oracle Database In-Memory is scheduled for general availability in July and can be used with all hardware platforms on which Oracle Database 12c is supported.