CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics1
Polygon Meshes and other modeling tools• Object representation• Polygon meshes• Normals• Scene graphs• Level of detail• Space partitioning
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics2
How can we represent objects/scenes• Polygon meshes• Scene graphs• Parametric representations• Equations• Bunch o points
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics3
Why?• Rendering• Manipulate
– User– System
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics4
Point Clouds
• Unstructured set of 3D point samples– Why– What for?
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics5
Polygon/Triangle Soup
• Unstructured set up polygons/triangles– Just a list of vertices for each polygon/triangle– Why?– What for? class Triangle
{ public: Triangle() {m_material = NULL;}
CGrPoint3F m_vertices[3]; CGrPoint3F m_normals[3]; CGrPoint2F m_tvertices[3]; const void *m_material; };
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics6
What is tessellation?
• Representing a surface with flat approximating polygons– A sampled representation
• Geometric Aliasing– Error in the representation due to the sampling with
polygons
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics7
Polygon/Triangle mesh
• Common method for describing geometry
• Set of vertices– Coordinates– Normal– Texture coordinates– Etc.
• Set of surfaces– Pointers to vertices– Material properties
Common: Triangle mesh
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics8
class CTriangleMesh{public: CTriangleMesh(void); ~CTriangleMesh(void);
// This structure defines a triangle struct Triangle { int m[3]; const CMaterial *material; };
int VertexCnt() const {return (int)m_vertices.size();} int TriangleCnt() const {return (int)m_triangles.size();}
const std::vector<CGrPoint3F> &Vertices() const {return m_vertices;} const std::vector<CGrPoint3F> &Normals() const {return m_normals;} const std::vector<CGrPoint2F> &TVertices() const {return m_tvertices;}
const std::vector<Triangle> &Triangles() const {return m_triangles;} const CMaterials &Materials() const {return m_materials;}
private: CMaterials m_materials; // The materials collection
// The vertices, normals, and texture vertices. // These three all correspond with each other. std::vector<CGrPoint3F> m_vertices; std::vector<CGrPoint3F> m_normals; std::vector<CGrPoint2F> m_tvertices;
std::vector<Triangle> m_triangles;};
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics9
Polygon Mesh
• Retains shared-vertex relationships
Vertex a,b,c,d;
Polygon P1(a, b, c);Polygon P2(c, b, d);
b,c shared by two polygons
a
b
c
d
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics10
Computing a surface normal
• Assume the following polygon:
p1
p2
p3
p4
)()(
)()(
1412
1412
pppp
ppppN
N
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics11
The Method of Projected Areas
• Assume this 2D example line:
p1
p2
x
y
xy
xyN
,
,
Projection of lengthto one axis
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics12
Method of Projected Areas
• The projection of the area onto the x/y plane is the z part of the normal
zyx
zyx
nii
n
iniiz
nii
n
iniiy
nii
n
iniix
NNN
NNNN
yyxxN
xxzzN
zzyyN
,,
,,
))((
))((
))((
)1%(1
)1%(
)1%(1
)1%(
)1%(1
)1%(
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics13
Where does this come from?
zyx
zyx
nii
n
iniiz
nii
n
iniiy
nii
n
iniix
NNN
NNNN
yyxxN
xxzzN
zzyyN
,,
,,
))((
))((
))((
)1%(1
)1%(
)1%(1
)1%(
)1%(1
)1%(
x
y
Why would we want to use this?
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics14
Vertex normals
• Add normals for surfaces incident on vertex:
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics15
The Winged-Edge Data Structure
• Maintains– List of vertices– List of edges– List of faces
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics16
Winged-Edge Data Structure
Vertex Incident Edge
A a
B b
C e
D a
Face Incident Edge
1 a
2 c
3 e
4 b
Vertex table:
Face table:
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics17
Edge Table
a
c
e
b d
1 2
B
D
Edge Vertices Faces Left Traverse Right Traverse
Name Start End Left Right Pred Succ Prec Succ
c B D 1 2 b a e d
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics18
Voxels
• Grid of volumetric samples– CAT, MRI, etc.
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics19
Scene Graphs
PolygonPolygon PolygonPolygon…
CompositeComposite
TranslateTranslate
ColorColor
PolygonPolygon PolygonPolygon…
CompositeComposite
ColorColor
TranslateTranslateTranslateTranslate
CompositeComposite
BarbellEnds
BarbellBar
SeparatorSeparator SeparatorSeparator SeparatorSeparator
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics20
Scene Graphs
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics21
Collapsing a Scene Graph
• It’s often possible to apply transformations in a scene graph once to the underlying vertices, collapsing some nodes. Example:
TranslationTranslation
RotationRotation
PolygonPolygon
PolygonPolygonCollapse to
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics22
Cloning
• If part of a scene graph has two edges to it, it will be necessary to clone before collapsing
TranslationTranslation
RotationRotation
PolygonPolygon
TranslationTranslation
RotationRotation
PolygonPolygon
TranslationTranslation
RotationRotation
Polygon’Polygon’
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics23
Integration of mesheswith scene graphs
PolygonPolygon PolygonPolygon…
CompositeComposite
TranslateTranslate
ColorColor
Polygon MeshPolygon Mesh
ColorColor
TranslateTranslateTranslateTranslate
CompositeComposite
BarbellEnds
BarbellBar
SeparatorSeparator SeparatorSeparator SeparatorSeparator
Other possibilities?
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics24
Bounding Boxes
• Bounding boxes describe the X,Y,Z extents (minimum and maximum values).– If we know everything below a certain point in the scene
graph is in a box, we can avoid traversal if the box is not on-screen
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics25
class CBBoxF{ public: class CBBoxF() {}; class CBBoxF(const CGrPoint3F &p) : m_min(p), m_max(p) {}
void Set(const CGrPoint3F &p) {m_min = p; m_max = p;} void Set(const CBBoxF &b) {m_min = b.m_min; m_max=b.m_max;} void Include(const CGrPoint3F &p); void Include(const CBBoxF &b) {Include(b.m_min); Include(b.m_max);}
const CGrPoint3F &Max() const {return m_max;} const CGrPoint3F &Min() const {return m_min;} const float MinForD(int d) const {return m_min[d];} double Extent(int d) const {return m_max[d] - m_min[d];}
private: CGrPoint3F m_min; CGrPoint3F m_max;};
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics26
Levels of Detail (lod)
• Alternative scene graphs with different resolutions– Varying tessellation– Which we use depends on how far away the camera is.– Significant performance enhancement
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics27
BSP Trees
• Binary Space Partitioning– Divides space into half-spaces– We can then use this method to
• limit how much scene graph we examine• examine the scene graph in certain orders
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics28
k-d Trees
• k is dimensions• Node
– Info– x, y– lt-link– ge-link
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics29
Levels
• Level 0 – Index X– Level 1 – Index Y
• Level 2 – Index X
• level = 0 if root, level(parent)+1 otherwise• For each level, index: level mod k
• 3D: Index X, Index Y, Index Z, Index X, etc…
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics30
Example
• Banja Luca (19, 45)• Derventa (40, 50)• Teslic (38, 38)• Tuzla (54, 40)• Sinj (4, 4)
Banja Luca (19, 45)Banja Luca (19, 45)
Derventa (40, 50)Derventa (40, 50)
Teslic (38, 38)Teslic (38, 38)
Tuzla (54, 40)Tuzla (54, 40)
Sinj (4, 4)Sinj (4, 4)
X
Y
X
Y
Insert: East Broko (21, 57)Search for exact?Search for nearest?Range searches?
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics31
k-d Trees
• Search for exact– Okay, but may be o(k)
• Search for nearest– In a moment
• Range search?
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics32
Range Search
• Consider each tree level to be region• Recursively search all regions that overlap search
range
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics33
Example Regions
Banja Luca (19, 45)Banja Luca (19, 45)
Derventa (40, 50)Derventa (40, 50)
Teslic (38, 38)Teslic (38, 38)
Tuzla (54, 40)Tuzla (54, 40)
Sinj (4, 4)Sinj (4, 4)
(-,+) (-,+)
(-,19) (-,+) [19,+) (-,+)
[19,+) (-,50)
[38,+) (-,50)
East Broko (21, 57)East Broko (21, 57)
[19,+) [50,+)
Range: (10,20) (20, 45)
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics34
k-d Trees
• Fast and easy• Tend to be rather tall (unbalanced)• How could we extend to disk structure?• What if k=1?
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics35
Quadtrees
• 2-d only• Split data 4 ways• Node:
– info– x,y– nw,sw,ne,se
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics36
Example
• Banja Luca (19, 45)
• Derventa (40, 50)
• Teslic (38, 38)
• Tuzla (54, 40)
• Sinj (4, 4)
Banja Luca (19, 45)Banja Luca (19, 45)
Derventa (40, 50)Derventa (40, 50)
Teslic (38, 38)Teslic (38, 38)
Tuzla (54, 40)Tuzla (54, 40)
Sinj (4, 4)Sinj (4, 4)
ne senw
se
Insert: East Broko (21, 57)Search for exact?Search for nearest?Range searches?
CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics37
Octtrees
• 3-d• Split data 8 ways• Node:
– info– x,y,z– up nw,sw,ne,se, down nw,sw,ne,se