Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

I3333: Image synthesis

2D algorithm

Mohamad Saade
2D algorithms
• Pixel and Image
• 2D Drawing of Base Objects
– Drawing segments and curves
– Traceof segmentcircle
– Trace of a curve
• Clippingwindowing (Cutting)
– Clippingrectangular
– Clippingparametric
– 3D windowing
• Filling
3D windowing
• Setting the viewing volume
– windowrectangular belonging to the projection
plane
– projectionparallel :parallelepiped whose edgesare
parallelto the direction of projection
– projectionperspective :infinite pyramid whose
summitis theprojection center
Window volume shapes
• parallelepiped
Window volume shapes
• Pyramidal
Window volumes
• Generally:
– Volumesfinished windows
– Datain the observer frame
Cohen-Sutherland algorithm
1. Affecta 6-bit code at each end of the segment
– bit 1 = 1: the end is to the left of the volume
– bit 2 = 1: the end is to the right of the volume
– bit 3 = 1: the end is below the volume
– bit 4 = 1: the end is above the volume
– bit 5 = 1: the end is in front of the volume
– bit 6 = 1: the end is behind the volume
2. To classifythe segment
– ifcode1=000000and code2=000000 the segment is completely visible
– else if(code1 and code2)≠ 000000 he is invisible
– otherwise the segment is (potentially) partially visible
3. Examinethe remaining segments:
– calculationof the intersection of the segment with the plane of the volume
concerned
– calculateits end code
Calculation of intersections: plane
equations
• For a parallelepiped volume:
equationsplanstrivial
• Forun pyramidal volume:
• projections on the planOXobsZobs
– left plane: x = -w/dz
– right plane: x =w/dz
• projections on the planOZobsYobs
– upper plane: y =h/dz
– lower plane: y = -h/dz
• Z values
– front plane: z =ZBefore
– rear plane: z =Zarrière
Windowing volumes with OpenGL
• Perspective projection
– glFrustum(left,right,bottom,top,zNear,zFar);
– gluPerspective(angleFovy, ratio,zNear,zFar);

• Orthogonal projection
– glOrtho(left,right,bottom,top,zNear,zFar)
2D algorithms

• Pixel and Image


• 2D Drawing of Base Objects
– Drawing segments and curves
– Traceof segmentcircle
– Trace of a curve
• Clippingwindowing (Cutting)
– Clippingrectangular
– Clippingparametric
• Filling
2D filling
• Definition
– 2D broken line: 2D polygonal curve defined by a non-circular series of
points connected by segments.
– 2D polygon: 2D surface bordered by a circular series of points
connected by segments.
2D filling
• Filling a convex
polygon
– Filling frame by frame
starting from the lower
vertex and going up the
frames while managing
the path of the right and
left face sequences.
– Left continuation: B, A,
F, E
– Right continuation: B, C,
D, E
2D filling
• Polygon characteristics influence algorithm complexity
Area defined by color
• Definition
– By area defined by a color we mean:
1. a maximum connected set of pixels of the
same color,
2. a maximum connected set of pixels whose
color is not a defined color (area edge color)
– Case (1): Each of gray, black and white areas.
– Case (2): The union of the gray and black
zones with respect to the white zone.
– The filling is carried out from a seed pixel.
Area defined by a border

• Area defined by a border


– Set of related pixels whose border
consists of pixels of a color different
from that of the area
Area defined by vertices
• Area defined by the vertices of a polygon
Seed algorithm
• For an area defined by a border
– THEFilling is done by horizontal pixel scanning starting from
an initial pixel calledgerm
– We are looking for new germs (those who are furthest to the
right of a maximum horizontal sequence to fill) on the lines
above and below the processed line

Germ
Seed algorithm
• Recursive algorithm:

• Issue :battery capacity exceeded if the filled


areas are too large
Seed algorithm
• Principle:Filling is carried out, maximum horizontal sequence
of pixels after a horizontal sequence, from an initial seed pixel.

• At each iteration:
– We fill all the pixelsPiup to the color limit to the right and left of the
current seed
– We search among the pixels above and below thePithose who
arerightmostof a maximum horizontal sequence to fill
– These pixels are stacked as seeds for subsequent iterations.
Seed algorithm
Seed algorithm
Seed algorithm
Seed algorithm
• In the following example:
– It will be noted in particular in the last figure that the seed 3 is stacked.
We then stacked our scanning line. No other sprouts will be added
because the lines above and below are full.
– We then unstack germ 2 and fill its scanning line which again does not
give any other germ.
– We finally unstack germ 1 whose line is already filled (We could test it)
– The algorithm is then completed, the stack being empty. The maximum
stack size will have been 4, which is very economical compared to the
previous algorithm.
Seed algorithm
Scanline algorithm
• Process of filling an area defined by a set of points
• Line by line, frame by frame scanning
Algorithm ofscanline
• Consists of calculating horizontal segments
included in the polygon
Algorithm ofscanline
• Idea of ​the algorithm:
• Foreach horizontal line
– Determinedthe pixels havethe interiorof the polygon
– Pixels marked/displayedwith the correct value /color
• Principle of the algorithm:
• Foreach horizontal line
1. DeterminedTHEendshorizontal segments includedin thepolygon
• Ends = intersection between horizontal line withedgesof the polygon
2. Sort themendsin ascending order ofcontact detailsin x
3. Posterthe pixels havethe interiorof the polygon betweenend pairs
– Rulerof theparityto know if pixel hasthe interioror not
Active Edge Table (AET)
• For each horizontal line of a polygon we need to consider that
certain edges
• Keeps a table of active edges =ActiveEdgeTable
– Updating this table each time a row changes
• We extract from this table the intervals to be colored
Initialization:EdgeTable (AND)
• Order of description of an edge
– Be sure thaty1<y2for each edge(x1,y1) (x2,y2)
• Building an edge tableEdgeTable (AND)
– Sorting edges according to their minimum Y
– Edges starting with the same Y are placed in the
same “box”
– Each element contains(Ymax,Xmin,incrementX)
Maintain AET
• Transition to the following horizontal line:
– Remove each edge including2= current line
– Update the value of x for each remaining edge
– Add each edge whose y1 is equal to the current
line
Drawing from AET
• Sort active edges by x
• The pairs of edges give the segments to draw
• Attention
– Maximum vertices are not drawn
– Special case when a polygon shares edges with a
neighboring polygon
• See example.
Example
Example
Example

You might also like