Thursday, October 25, 2012

scaling program


//// scaling program////
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void matrixmulti(int translate[3][3],int vertex[3][5],int result[3][5]);
void main()
{
            int gd=DETECT,gm,errorcode;
            initgraph(&gd,&gm,"\\tc\\bgi");
            errorcode=graphresult();
            if(errorcode!=grOk)
            {
                        printf("Graphics ERROR!: %s",grapherrormsg(errorcode));
                        printf("\nPress any Key .......");
                        getch();
                        exit(1);
            }
            setbkcolor(2);
            int vertex[3][5]={{100,100,200,200,100},
            {100,200,200,100,100},
            {1,1,1,1,1}};
            for(int i=0;i<4;i++)
            {
                        setcolor(BLUE);
                        line(vertex[0][i],vertex[1][i],vertex[0][i+1],vertex[1][i+1]);

            }

            printf("SCALE X=");
            int sx,sy;
            scanf("%d",&sx);
            printf("SCALE Y:=");
            scanf("%d",&sy);
            int translate[3][3]={{2,0,0},{0,1,0},{0,0,1}};
            translate[0][0]=sx;
            translate[1][1]=sy;
            printf("Press any key for the translated line.....\n");
            getch();
            int result[3][5];
            matrixmulti(translate,vertex,result);
            for(i=0;i<4;i++)
            {
                        setcolor(YELLOW);
                        line(result[0][i],result[1][i],result[0][i+1],result[1][i+1]);

            }
            getch();
            closegraph();
}
void matrixmulti(int translate[3][3],int vertex[3][5],int result[3][5])
{
            for(int i=0;i<=3;i++)
            {
                        for(int j=0;j<=5;j++)
                        {
                                    result[i][j]=0;
                                    for(int k=0;k<=3;k++)
                                                result[i][j]+=translate[i][k]*vertex[k][j];
                        }
            }
}

Saturday, October 13, 2012

3D Object representations



                                                3D Object representations
Graphical scenes can contain many different kinds of objects like trees, flowers, rocks, waters...etc. There is no one method that we can use to describe objects that will include all features of those different materials. To produce realistic display of scenes, we need to use representations that accurately model object characteristics.
·         Simple Euclidean objects like polyhedrons and ellipsoids can be represented by polygon and quadric surfaces.
·         Spline surface are useful for designing aircraft wings, gears and other engineering objects.
·          Procedural methods and particle systems allow us to give accurate representation of clouds, clumps of grass, and other natural objects.
·         Octree encodings are used to represent internal features of objects. Such as medical CT images.

Representation schemes for solid objects are often divided into two broad categories:
1.      Boundary representations: describes a 3D object as a set of polygonal surfaces, separate the object interior from environment.

2.      Space-partitioning representation: used to describe interior properties, by partitioning the spatial region, containing an object into a set of small, non overlapping, contiguous solids. e.g. 3D object as Octree representation. 

Boundary Representation: Each 3D object is supposed to be formed its surface by collection of polygon facets and spline patches. Some of the boundary representation methods for 3D surface are:

1. Polygon Surfaces: It is he most common representation for 3D graphics object. In this representations, a 3D object is represented by a set of surfaces that enclose the object interior. Many graphics system use this method. Set of polygons are stored for object description. This simplifies and speeds up the surface rendering and display of object since all surfaces can be described with linear equations.




 



The polygon surface are common in design and solid-modeling applications, since wire frame display can be done quickly to give general indication of surface structure. Then realistic scenes are produced by interpolating shading patterns across polygon surface to illuminate. 

Hardware Concepts: Display devices(ii)



Raster-Scan Display
        Raster Scan Display  is based on television technology. In raster-scan the electron beam is swept across the screen, one row at a time from top to bottom. No of scan line per second is called horizontal scan rate.
        As electron beam moves across each row, the beam intensity is turned on and off to create a pattern of illuminated spots. Picture definition is stored in a memory called frame buffer or refresh buffer. Frame buffer holds all the intensity value for screen points. 


 
Figure: A raster-scan system displays an object as a set of points across each screen scan line
 
 
Figure: Raster Scan display system

        The stored intensity value is retrieved from frame buffer and painted on the scan line at a time. Home television are common examples using raster display
        Intensity range for pixel position depends on capability of raster system. For B/W system each point on screen are either on or off, so only one bit per pixel is needed to control the pixel intensity. To display color with varying intensity level, additional bits are needed. Up to 24 to 32 bit per pixel are included in high quality systems, which require more space of storage for the frame buffer, depending upon the resolution of the system.
        A system with 24 bit pixel and screen resolution 1024  1024 require 3 megabyte of storage in frame buffer.
1024*1024 pixel = 1024*1024*24 bits = 3 MB

        The frame butter in B/W system stores a pixel with one bit per pixel so it is termed as bitmap. The frame buffer in multi bit per pixel storage, is called pixmap.
        Refreshing on Raster-Scan display is carried out at the rate of 60 or higher frames per second. 60 frames per second is also termed as 60 cycle per second usually used unit Hertz (HZ)
        Returning of electron beam from right end to deft end after refreshing each scan line is horizontal retrace . At the end of each frame, the electron beam returns to the top left corner to begin next frame called vertical retrace.


Interlaced: Display in two pass with interlacing. 

Figure: Horizontal retrace and Vertical retrace
                                                             
Question: Consider a RGB raster system is to be designed using 8 inch by 10 inch screen with a resolution of 100 pixels per inch in each direction. If  we want to store 6 bits per pixel in the frame buffer, How much storage(in bytes) do we need for the frame buffer?

Solution: Size of screen = 8 inch ´ 10 inch.
Pixel per inch(Resolution)  = 100.
Then, Total no of pixels  =  8´100 ´ 10 ´ 100 pixels
Bit per pixel storage = 8

Therefore Total storage required in frame buffer = (800 ´1000´8) bits
                                                                                        = (800 ´1000´8)/8 Bytes
                                                                                        = 800000 Bytes.