Graphics Hit-testing. Shape Models Selecting Lines and Shapes. 2.7 Graphics Hit-testing 1

Similar documents
2D Graphics. Shape Models, Drawing, Selection. CS d Graphics 1

2D Graphics. Shape Models, Drawing, Selection. CS d Graphics 1

Java 2D Graphics. Drawing Primitives, Affine Transformations, Scene Graphs, Hit Tests. Drawing Primitives 2/9/2014. Using it is simple.

Affine Transformations. Transforming shape models Combining affine transformations Scene graphs, interactor trees Hit tests on transformed shapes

Graphics Transformations

Affine Transformation. Edith Law & Mike Terry

(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci

Graphics (Output) Primitives. Chapters 3 & 4

Principles of Computer Game Design and Implementation. Lecture 6

Lecture 5 2D Transformation

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Applications of Integration. Copyright Cengage Learning. All rights reserved.

Tutorial 14b: Advanced polygonal modeling

REVIT ARCHITECTURE 2016

1 Preview. Dr. Scott Gordon Computer Science Dept. CSUS. Virtual Cameras, Viewing Transformations: CSc-155 Advanced Computer Graphics

Image Warping, Linear Algebra CIS581

Vector Algebra Transformations. Lecture 4

3ds Max Cottage Step 1. Always start out by setting up units: We re going with this setup as we will round everything off to one inch.

CS559 Computer Graphics Fall 2015

Building Java Programs

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Ray Tracing Part 1. CSC418/2504 Introduction to Computer Graphics. TA: Muhammed Anwar & Kevin Gibson

Overview. Java2D. Graphics in Java2D: Colour Images Fonts. The bigger picture of Java Graphics: Java Advanced Imaging (JAI) API Java3D

Building Java Programs

Illustrator Domains 1-4: Getting to Know Your Workspace. Dreamweaver Domain 3

Topic 9 More Graphics. Based on slides bu Marty Stepp and Stuart Reges from

Rasterization, or What is glbegin(gl_lines) really doing?

Data Representation in Visualisation

EXAMINATIONS 2016 TRIMESTER 2

create 2 new grid lines

Graphics and Interaction Rendering pipeline & object modelling

Computer Graphics Fundamentals. Jon Macey

Solution Notes. COMP 151: Terms Test

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Transforms. COMP 575/770 Spring 2013

3D Viewing. CS 4620 Lecture 8

Captain America Shield

03 Vector Graphics. Multimedia Systems. 2D and 3D Graphics, Transformations

Software System Components 1 Graphics

Using Graphics. Building Java Programs Supplement 3G

EXAMINATIONS 2017 TRIMESTER 2

Garfield AP CS. Graphics

Programming Fundamentals

3D Rendering and Ray Casting

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Overview. Affine Transformations (2D and 3D) Coordinate System Transformations Vectors Rays and Intersections

Adobe Illustrator CS Design Professional GETTING STARTED WITH ILLUSTRATOR

Lecture 11. More Ray Casting/Tracing

SHORTCUTS DRAW PERSONA

Building Java Programs

Constraint Based Modeling Geometric and Dimensional. ENGR 1182 SolidWorks 03

Visual C# Program: Simple Game 3

The Department of Construction Management and Civil Engineering Technology CMCE-1110 Construction Drawings 1 Lecture Introduction to AutoCAD What is

Objective Utilize appropriate tools and methods to produce digital graphics.

creating files and saving for web

CHAPTER V IMPLEMENTATION AND TESTING

Linear Algebra Simplified

Experimental Design and Graphical Analysis of Data

COMP3421. Vector geometry, Clipping

Rational Numbers: Graphing: The Coordinate Plane

Week 4 Part 2. Introduction to 2D Graphics & Java 2D

Java Programming. Computer Science 112

INKSCAPE BASICS. 125 S. Prospect Avenue, Elmhurst, IL (630) elmhurstpubliclibrary.org. Create, Make, and Build

Chapter 1. Getting to Know Illustrator

1. Complete these exercises to practice creating user functions in small sketches.

Education and Training CUFMEM14A. Exercise 2. Create, Manipulate and Incorporate 2D Graphics

Assignment 6: Ray Tracing

Create Text Inside a Shape with Photoshop CS6

Pipeline and Rasterization. COMP770 Fall 2011

Building Java Programs

Einführung in Visual Computing

EDITING SHAPES. Lesson overview

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

GraphWorX64 Productivity Tips

User Interaction. User Interaction. Input devices. Input devices. Input devices GUIs and GUI design Event-driven programming 3D interaction

2D Design. Window. 3D Window. Toolpat h Operati ons. Navigation Homepage. Layer Managemen t. Component Manager. Modeling Tools

Warping & Blending AP

CS418 OpenGL & GLUT Programming Tutorial (IV) MP2 Bonus/Object Picking. Presented by : Wei-Wen Feng 2/20/2008

Loops. Variable Scope Remapping Nested Loops. Donald Judd. CS Loops 1. CS Loops 2

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

MET 107 Drawing Tool (Shapes) Notes Day 3

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Graphic Design & Digital Photography. Photoshop Basics: Working With Selection.

Module 5: Creating Sheet Metal Transition Piece Between a Square Tube and a Rectangular Tube with Triangulation

Hidden surface removal. Computer Graphics

public void paintcomponent(graphics g) { Graphics2D g2 = (Graphics2D)g;... }

Generating Vectors Overview

OpenGL: A Practical Introduction. (thanks, Mark Livingston!)

Overview: The Map Window

Computer Graphics and Linear Algebra Rebecca Weber, 2007

3DS Max Tutorial Surface, Shell, Editable Mesh and Mesh Smooth.

Paint by Numbers and Comprehensible Rendering of 3D Shapes

When dragging out a marquee: Shift toggles the corner selection

CS452/552; EE465/505. Geometry Transformations

Project report Augmented reality with ARToolKit

Open GL Framework For A Computer Graphics Course

CoderDojo Athenry Code and notes by Martha Fahy, 2017

VANSTEENKISTE LEO DAE GD ENG UNFOLD SHADER. Introduction

Topic 8 graphics. -mgrimes, Graphics problem report 134

Transcription:

Graphics Hit-testing Shape Models Selecting Lines and Shapes 2.7 Graphics Hit-testing 1

Recap - Graphic Models and Images Computer Graphics is the creation, storage, and manipulation of images and their models Model: a mathematical representation of an image containing the important properties of an object (location, size, orientation, color, texture, etc.) in data structures Rendering: Using the properties of the model to create an image to display on the screen Image: the rendered model Model Rendering Image 2.7 Graphics Hit-testing 2

Recap - Shape Model an array of points: {P 1, P 2,, P n } isclosed flag (shape is polyline or polygon) isfilled flag (polygon is filled or not) (and stroke thickness, colours, etc.) 2.7 Graphics Hit-testing 3

Implementing Direct Manipulation Objective: test when a rendered shape is selected - could be a filled or outlined polygon or a polyline - selections that just miss the shape should snap to shape Tasks: - create a model of the shape - draw it - choose a selection paradigm - implement shape hit tests - respond to events 2.7 Graphics Hit-testing 4

Selection Paradigms Hit-test selection - open shapes like lines and polyline use edge hit-test - closed shapes like rectangles, and polygons use inside hit-test Alternate approaches we won t cover: - Rubberband rectangle - Lasso 2.7 Graphics Hit-testing 5

Linear Algebra: Affine Space s v P a scalar: a single value (real number) a vector: directed line segment (direction and magnitude) a point: a fixed location in space (represents a position) Legal operations: vector + vector: v 1 + v 2 = v 3 vector multiplied by scalar: v 1 x s 1 = v 4 point minus point: P 1 P 2 = v 5 point + vector: P 2 + v 5 = P 1 Two ways to multiply vector by vector, dot (inner) product: v 1 v 2 = s 2 cross (outer) product: v 1 x v 2 = v 6 2.7 Graphics Hit-testing 6

Line Segment Hit-test a line model has no thickness pick a threshold distance from mouse position to line point to line distance can be computed using vector projection (blackboard ) 2.7 Graphics Hit-testing 7

ClosestPoint.java // find closest point using projection method static Point2d closestpoint(point2d M, Point2d P0, Point2d P1) { Vector2d v = new Vector2d(); v.sub(p1,p0); // v = P2 - P1 // early out if line is less than 1 pixel long if (v.lengthsquared() < 0.5) return P0; Vector2d u = new Vector2d(); u.sub(m,p0); // u = M - P1 } // scalar of vector projection... double s = u.dot(v) / v.dot(v); // find point for constrained line segment if (s < 0) return P0; else if (s > 1) return P1; else { Point2d I = P0; Vector2d w = new Vector2d(); w.scale(s, v); // w = s * v I.add(w); // I = P1 + w return I; } 2.7 Graphics Hit-testing 8

ClosestPointDemo.java // get distance using Java2D method double d2 = Line2D.ptSegDist(P0.x, P0.y, P1.x, P1.y, M.x, M.y); 2.7 Graphics Hit-testing 9

Polyline and Multiple Polyline Hit-testing a polyline is just many line segments check distance from every every polyline to mouse position - how can this be optimized? (blackboard ) 2.7 Graphics Hit-testing 10

Rectangle Shape Hit-Test assume axis-aligned rectangle shape useful as a bounding box (blackboard ) 2.7 Graphics Hit-testing 11

Mouse Inside Polygon Test is a point inside or outside a polygon? approach: find intersection points of horizontal line with polygon (can be optimized ) need special case test when horizontal line passes through end of line segments need a line-line intersection routine (blackboard ) 2.7 Graphics Hit-testing 12

PolygonHittest.java public void paintcomponent(graphics g) { super.paintcomponent(g); Graphics2D g2 = (Graphics2D) g; if (poly.contains(m.x, M.y)) g2.setcolor(color.blue); else g2.setcolor(color.red); g2.fillpolygon(poly); } g2.setcolor(color.black); g.drawpolyline(poly.xpoints, poly.ypoints, poly.npoints); 2.7 Graphics Hit-testing 13

Hit-testing with Transformed Shapes Mouse and shape model are in different coordinate systems Two options for hit testing: 1. Transform shape model to mouse coordinates 2. Transform mouse to shape model coordinates p (0,0) x shape model coordinates p mouse coordinates y A p m m 2.7 Graphics Transformations 14

Transform Shape Model to Mouse Coordinates Have to transform every point and/or parameter in shape model before running each hit-test algorithm - extra memory, lots of extra calculation p (0,0) x shape model coordinates mouse coordinates y p = A p m 2.7 Graphics Transformations 15

Transform Mouse to Shape Model Coordinates Only one point to transform Need to adjust hit-test threshold - e.g. 3 pixels in mouse coords. is how far in model coords? - what if non-uniform scale? Computing inverse can be costly p (0,0) x shape model coordinates mouse coordinates y m = A -1 m A p m 2.7 Graphics Transformations 16

TransformHittest.java Canvas () { // create transformation matrix for shape1 AT1 = new AffineTransform(); AT1.translate(350, 100); AT1.rotate(Math.toRadians(30)); // create another transformation matrix for shape2 AT2 = new AffineTransform(); AT2.translate(200, 300); AT2.rotate(Math.toRadians(30)); AT2.scale(2, 2); } public void paintcomponent(graphics g) { // Shape1 g2.settransform(at1); // Use matrix AT1 g2.setcolor(color.red); g2.drawpolygon(shape.xpoints, shape.ypoints, shape.npoints); // Shape2 g2.settransform(at2); // Use matrix AT2 g2.setcolor(color.blue); g2.drawpolygon(shape.xpoints, shape.ypoints, shape.npoints); } 2.7 Graphics Hit-testing 17

TransformHittest.java public void paintcomponent(graphics g) { // hit testing Point MT = new Point(); // create an inverse matrix of AT1 AffineTransform IAT1 = AT1.createInverse(); // apply the inverse transformation to the mouse position IAT1.transform(M, MT); } // Hit test with transformed mouse position if (shape.contains(mt.x, MT.y)) g2.setcolor(color.red); else g2.setcolor(color.white); g2.fillpolygon(shape); 2.7 Graphics Hit-testing 18