1 / 25

Windows and clipping

Windows and clipping. Dr Nicolas Holzschuch University of Cape Town e-mail: holzschu@cs.uct.ac.za Modified by Longin Jan Latecki latecki@temple.edu Sep. 11, 2002. Map of the lecture. Views, windows, buttons: the need for clipping Clipping simple points Clipping line segments

vinsonk
Download Presentation

Windows and clipping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Windows and clipping Dr Nicolas Holzschuch University of Cape Town e-mail: holzschu@cs.uct.ac.za Modified by Longin Jan Latecki latecki@temple.edu Sep. 11, 2002

  2. Map of the lecture • Views, windows, buttons: • the need for clipping • Clipping simple points • Clipping line segments • against one edge of the window • against the whole window

  3. Views and windows • The application models contains the objects adressed by the application • The window is the part of the screen reserved for the application • Of that window, a part is reserved for drawing (the pane) • A part of the application model is mapped onto the pane: it’s a view

  4. Views and windows Window Pane Application Model

  5. Menus and buttons • Apart from the pane, other parts of the window are used by the application: • title bar • menu bar • buttons • text areas

  6. Clipping: the basic problem • The view is smaller than the application model • Need to select the part of the application model to display • Ensure that there is no overlap • Graphics have to be clipped

  7. Clipping for window systems • No drawing outside the window: • Ensures visual impression of “window” Window

  8. Requirements • For window systems: draw only: • the primitives that are inside the window • the parts of the primitive that are inside the window • For menus, buttons, text areas: • parts of the application that must stay untouched • An essential part of all GUI libraries

  9. The difficulties of clipping • Parts of the primitives are outside the window: • I must find the new shape • implies new vertices, new edges, etc. • Will be done quite often: • must be a simple, non-costly, algorithm • preferably, clipping before rasterizing

  10. Clipping in the application model • Rasterizing: • low level algorithm • done by the graphics library • Clipping: • higher level algorithm • sometimes done by the window system • sometimes you have to do it • do it in the application model

  11. Clipping simple points Draw the point iff: ((xmin < x < xmax) && (ymin < y < ymax)) ymax (x,y) ymin xmin xmax

  12. Clipping line segments • Start by clipping against one edge of the window • Several definition for line segments: • ax+by+c = 0 • y = mx+d • M(t) = P + tu… • same for the edge • Which one is best for clipping?

  13. Use parametric representation • Line defined as M(t) = P + tu • Find t P Begin point Window boundary t=0 Q t=? End Point t=1

  14. Define the boundary • Boundary defined by point and normal • A point is inside: EP•n  0 Window boundary n P outside inside E

  15. Finding the new vertex n P Window boundary t=0 Q t=? t=1 E

  16. Where is the new line segment? • Should I draw from 0 to t, or from t to 1? • Depends if the line was entering, or leaving: P n n P Q Q Leaving Entering

  17. Entering or leaving? • From the sign of PQ•n: • positive: • the line is entering, • draw from t to 1 • negative: • the line is leaving, • draw from 0 to t

  18. Clipping a line against a window • Clip the line against each boundary: top bottom left right

  19. Clipping against a window • Clip against each boundary in turn • For each boundary: • compute t • status: entering/leaving • Keep greater t_entering and smaller t_leaving • If t_entering  t_leaving, nothing to draw • Else, draw from t_entering to t_leaving

  20. Clipping a line against a window tE top bottom left right

  21. Clipping a line against a window tE top t’E <tE bottom left right

  22. Clipping a line against a window tE top t’E <tE tL>1 bottom left right

  23. Clipping a line against a window tE top t’E <tE t’L<1 tL>1 bottom left right

  24. Clipping a line against a window tE top t’E <tE t’L<1 tL>1 bottom left right

  25. Clipping a line: conclusion • A simple algorithm • Requires only standard operations • dot products, divisions • even faster if you use horizontal/vertical boundaries • Easy to implement using standard libraries

More Related