first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<html>
<head>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<pre>
<table width=100% bgcolor=#CFCFE5><tr> <td> <font face=arial size=+3>
Build Log
</font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>
<h3>------- Build started: Project: proj5, Configuration: Debug|Win32 -------
</h3>
</pre></table><table width=100% bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
Command Lines
</font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>Creating temporary file "d:\School Shit\06 - 2005 - Spring\Cs4451\proj5\Debug\RSP000007.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MLd /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /ZI /TP
".\Renderer.cpp"
]
Creating command line "cl.exe @"d:\School Shit\06 - 2005 - Spring\Cs4451\proj5\Debug\RSP000007.rsp" /nologo"
</pre></table><table width=100% bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
Output Window
</font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>Compiling...
Skipping... (no relevant changes detected)
Renderer.cpp
</pre></table><table width=100% bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
Results
</font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>
Build log was saved at "file://d:\School Shit\06 - 2005 - Spring\Cs4451\proj5\Debug\BuildLog.htm"
proj5 - 0 error(s), 0 warning(s)</pre></table><table width=100% height=20 bgcolor=#CFCFE5><tr><td><font face=arial size=+2>
</font></table></body></html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
CS4451/proj5/Debug/main.obj Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
CS4451/proj5/Debug/vc70.idb Normal file

Binary file not shown.

BIN
CS4451/proj5/Debug/vc70.pdb Normal file

Binary file not shown.

View File

@@ -0,0 +1,84 @@
#include "FileReader.h"
#include "Renderer.h"
#include <iostream>
#include <fstream>
//Initialize the FileReader instance
FileReader FileReader::m_instance;
void FileReader::readFile(char* fileName) {
char input[81], *inputPtr; //temp string space
std::fstream fs; //File Stream
int numTris, numPts; //Number of objects
//Open file
fs.open(fileName, std::fstream::in);
if (!fs.is_open()) {
std::cout << "The file failed to open.\n";
exit(-1);
}
//Get the # of vertices and # of triangles
fs.getline(input,81);
//Number of Triangles
numTris = strtol(input,&inputPtr,0);
//Renderer::getInstance()->triangles->reserve(numTris);
//Number of points
numPts = strtol(inputPtr,NULL,0);
//Renderer::getInstance()->points->reserve(numPts);
//skip over the first newline
fs.getline(input,81);
//Read all triangles
for (int i = 0; i < numTris; i++) {
readTriangle(&fs, i);
}
//skip over the second newline
fs.getline(input,81);
//Read all Points
for (int i = 0; i < numPts; i++) {
readPoint(&fs, i);
}
}
void FileReader::readTriangle(std::fstream *fs, int index) {
char input[81], *inputPtr; //temp string space
Triangle t;
//Read next line
fs->getline(input,81);
t.a1 = strtol(input,&inputPtr,0);
t.a2 = strtol(inputPtr,&inputPtr,0);
t.a3 = strtol(inputPtr,NULL,0);
t.normal.i = t.normal.j = t.normal.k = 0;
Renderer::getInstance()->triangles->push_back(t);
}
void FileReader::readPoint(std::fstream *fs, int index) {
char input[81], *inputPtr; //temp string space
Point p;
//Read next line
fs->getline(input,81);
p.x = (float)strtod(input,&inputPtr);
p.y = (float)strtod(inputPtr,&inputPtr);
p.z = (float)strtod(inputPtr,NULL);
Renderer::getInstance()->points->push_back(p);
}

26
CS4451/proj5/FileReader.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef _FILEREADER_H_
#define _FILEREADER_H_
#include <fstream>
class FileReader {
public:
static inline FileReader* getInstance() {
return & m_instance;
}
void readFile(char* fileName);
private:
static FileReader m_instance;
inline FileReader() {};
void readTriangle(std::fstream *fs, int index);
void readPoint(std::fstream *fs, int index);
};
#endif

207
CS4451/proj5/Input.cpp Normal file
View File

@@ -0,0 +1,207 @@
#include "Input.h"
#include "utils.h"
#include "Renderer.h"
#include <GL/glut.h>
#include <iostream>
Input Input::m_instance;
GLvoid Input::keyboard_event(GLubyte key, GLint x, GLint y)
{
switch ( key ) {
case 'w':
this->menu(ZOOM_IN_EVENT);
break;
case 's':
this->menu(ZOOM_OUT_EVENT);
break;
case 'a':
this->menu(ANIMATE_EVENT);
break;
case 'l':
this->menu(LINES_EVENT);
break;
case 'f':
this->menu(FULL_EVENT);
break;
default:
break;
}
}
GLvoid Input::menu( int value )
{
switch ( value ) {
case ZOOM_IN_EVENT:
Renderer::getInstance()->divViewDist(1.2);
break;
case ZOOM_OUT_EVENT:
Renderer::getInstance()->multViewDist(1.2);
break;
case LINES_EVENT:
glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Renderer::getInstance()->render();
break;
case FULL_EVENT:
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
Renderer::getInstance()->render();
break;
case ANIMATE_EVENT:
Renderer::getInstance()->animate =
Renderer::getInstance()->animate ? false : true;
Renderer::getInstance()->render();
break;
default:
break;
}
}
GLvoid Input::passive_motion(GLint mx, GLint my)
{
}
GLvoid Input::button_motion(GLint mx, GLint my)
{
/* First calculate P */
static Point v;
Point p, w, a;
//Give us the scaled p on the sphere
scalePoint(p,mx,my);
//get the unit vector of p
GLfloat length = p.magnitude();
if (length==0) {
return;
} else {
w.x = p.x / length;
w.y = p.y / length;
w.z = p.z / length;
}
//This is the first time the movement has been made
if (oldPoint.z == -1) {
scalePoint(oldPoint,(int)oldPoint.x,(int)oldPoint.y);
length = oldPoint.magnitude();
if (length==0) {
return;
} else {
v.x = oldPoint.x / length;
v.y = oldPoint.y / length;
v.z = oldPoint.z / length;
}
}
cross(a,oldPoint,p);
length = a.magnitude();
if (length==0) {
return;
} else {
a.x /= length;
a.y /= length;
a.z /= length;
}
GLfloat angle = dot(v,w);
if (angle > 1) {
angle = 1;
} else if (angle < -1) {
angle = -1;
}
angle = acos(angle);
/* Perform the rotation calculation */
GLfloat newMatrix[16];
calcAngle(newMatrix,angle,a);
/* Make OpenGL do our work */
glPushMatrix();
glLoadMatrixf(newMatrix);
glMultMatrixf(Renderer::getInstance()->currModelTransform);
glGetFloatv(GL_MODELVIEW_MATRIX,Renderer::getInstance()->currModelTransform);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
oldPoint = p;
v = w;
glutPostRedisplay();
return;
}
GLvoid Input::mouse_button(GLint btn, GLint state, GLint mx, GLint my)
{
switch( btn ) {
case GLUT_LEFT_BUTTON:
switch( state ) {
case GLUT_DOWN:
oldPoint.x = mx;
oldPoint.y = my;
oldPoint.z = -1;
break;
case GLUT_UP:
break;
}
break;
case GLUT_MIDDLE_BUTTON:
switch( state ) {
case GLUT_DOWN:
break;
case GLUT_UP:
break;
}
break;
case GLUT_RIGHT_BUTTON:
switch( state ) {
case GLUT_DOWN:
break;
case GLUT_UP:
break;
}
break;
}
}
void Input::calcAngle(GLfloat *newMatrix, GLfloat angle, Point& a) {
newMatrix[0] = 1.+(1.-cos(angle))*(pow(a.x,2)-1.);
newMatrix[1] = a.z*sin(angle) + (1.-cos(angle)) * a.x * a.y;
newMatrix[2] = -1. * a.y * sin(angle) + (1.-cos(angle))*a.x*a.z;
newMatrix[3] = 0;
newMatrix[4] = -1. * a.z * sin(angle) + (1.-cos(angle)) * a.x * a.y;
newMatrix[5] = 1. + (1. - cos(angle))*(pow(a.y,2)-1.);
newMatrix[6] = a.x * sin(angle) + (1.-cos(angle))*a.y*a.z;
newMatrix[7] = 0;
newMatrix[8] = a.y * sin(angle) + (1.-cos(angle))*a.x * a.z;
newMatrix[9] = -1. * a.x * sin(angle) + (1.-cos(angle))*a.y*a.z;
newMatrix[10] = 1. + (1.-cos(angle))*(pow(a.z,2)-1.);
newMatrix[11] = newMatrix[12] = newMatrix[13] = newMatrix[14] = 0;
newMatrix[15] = 1.;
}
void Input::scalePoint(Point& p, GLint mx, GLint my) {
//scale to -1 and 1
float scale = ceil(Renderer::getInstance()->getVPD()/2.);
p.x = (mx / scale) -1.;
p.y = (my / scale) -1.;
p.y*=-1.; //handle reversed y
p.z = 1.-pow(p.x,2)-pow(p.y,2);
if (p.z < 0) {
float under = sqrt((p.x*p.x)+(p.y*p.y));
p.x /= under;
p.y /= under;
p.z = 0;
} else {
p.z = sqrt(p.z);
}
}

43
CS4451/proj5/Input.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef _INPUT_H_
#define _INPUT_H_
#include <stdlib.h>
#include <GL/glut.h>
#include "structs.h"
class Input {
public:
static inline Input* getInstance() {
return & m_instance;
}
GLvoid keyboard_event(GLubyte key, GLint x, GLint y);
GLvoid menu( int value );
GLvoid passive_motion(GLint mx, GLint my);
GLvoid button_motion(GLint mx, GLint my);
GLvoid mouse_button(GLint btn, GLint state, GLint mx, GLint my);
enum {
ZOOM_IN_EVENT,
ZOOM_OUT_EVENT,
ANIMATE_EVENT,
LINES_EVENT,
FULL_EVENT
};
private:
inline Input() {;}
static Input m_instance;
Point oldPoint;
void calcAngle(GLfloat *newMatrix, GLfloat angle, Point& a);
void scalePoint(Point& p, GLint mx, GLint my);
};
#endif

41
CS4451/proj5/Makefile Normal file
View File

@@ -0,0 +1,41 @@
CC = g++
#OPT = -Wno-deprecated -O3 -DSHOW_FPS
OPT = -Wno-deprecated -O3 -DSCENELIST
LIBS = -L/usr/X11R6/lib -lglut -lGLU -lGL -lXmu -lXi -lX11 -lm
SRC = main.cpp FileReader.cpp Renderer.cpp Input.cpp Subdivision.cpp
OBJ = main.o FileReader.o Renderer.o Input.o Subdivision.o
INCS = -I/usr/X11R6/include
INC = FileReader.h Renderer.h Input.h Subdivision.h structs.h utils.h cwrappers.h
TARGET = proj5
MISC = Makefile
all: $(TARGET)
$(TARGET) : $(OBJ) $(MISC)
$(CC) $(OPT) -o $(TARGET) $(INCS) $(OBJ) $(LIBS)
%.o : %.cpp $(MISC) $(INC)
$(CC) $(OPT) $(INCS) -c -o $@ $<
clean:
rm -f $(OBJ) $(TARGET)
#all : proj1
#proj1 : proj1.o functions.o image.o ray.o
# $(CC) $(OPT) -o proj1 proj1.o functions.o $(LIBS)
#proj1.o : proj1.c defs.h
# $(CC) $(OPT) -c proj1.c
#functions.o: functions.cpp defs.h functions.h
# $(CC) $(OPT) -c functions.cpp
#image.o: image.cpp defs.h
# $(CC) $(OPT) -c image.cpp
#clean:
# rm *.o proj1

View File

@@ -0,0 +1,15 @@
<html>
<head>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<pre>
<table width=100% bgcolor=#CFCFE5><tr> <td> <font face=arial size=+3>
Build Log
</font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>
<h3>------- Build started: Project: proj5, Configuration: Release|Win32 -------
</h3>
</pre></table><table width=100% bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
Command Lines
</font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>proj5 - up-to-date.</pre></table><table width=100% height=20 bgcolor=#CFCFE5><tr><td><font face=arial size=+2>
</font></table></body></html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

441
CS4451/proj5/Renderer.cpp Normal file
View File

@@ -0,0 +1,441 @@
#include "Renderer.h"
#include "structs.h"
#include "utils.h"
#include "cwrappers.h"
#include "Input.h"
#include <GL/glut.h>
//Initialize static member
Renderer Renderer::m_instance;
void Renderer::init(int* argc, char** argv) {
this->windowID = init_glut(argc,argv);
this->init_opengl();
//Generate Subdivision
clock_t start = clock();
for (int i = 0; i < atoi(argv[1]); i++) {
Subdivision::getInstance()->performSubdivision(*(argv[2]));
}
std::cout << "Subdivision time: "
<< (clock()-start)/(float)CLOCKS_PER_SEC << " seconds.\n";
std::cout << "Generating Normals..";
this->generateNormals();
std::cout << "Done.\nGenerating Scene..";
this->create_scene();
std::cout << "Done.\n";
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glGetFloatv(GL_MODELVIEW_MATRIX,currModelTransform);
glPopMatrix();
std::cout << "Total time: "
<< (clock()-start)/(float)CLOCKS_PER_SEC << " seconds.\n";
std::cout << "Final number of vertices : " << (int) points->size() << std::endl;
std::cout << "Final number of triangles : " << (int) triangles->size() << std::endl;
}
//Calculate the normals for each triangle
void Renderer::generateNormals() {
/* Generate normals for triangles and Vertices */
Vector tempNormal;
Point a1a2, a1a3;
Point a1, a2, a3;
std::vector<Triangle>::iterator t_iter;
for (t_iter = triangles->begin(); t_iter != triangles->end(); t_iter++) {
a1 = points->at(t_iter->a1);
a2 = points->at(t_iter->a2);
a3 = points->at(t_iter->a3);
a1a2 = a2 - a1;
a1a3 = a3 - a1;
cross(tempNormal,a1a2,a1a3);
tempNormal.i *= -1;
tempNormal.j *= -1;
tempNormal.k *= -1;
/* Store the normal for the triangle */
t_iter->normal = tempNormal;
}
}
void Renderer::init_opengl()
{
// back-face culling on
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); // We want to cull the back
glFrontFace(GL_CW); // The vertices we get are clockwise
// automatically scale normals to unit length after transformation
glEnable(GL_NORMALIZE);
//Flat shading
glShadeModel(GL_FLAT);
// clear to BLACK
glClearColor(0.0, 0.0, 0.0, 1.0);
// Enable depth test
glEnable(GL_DEPTH_TEST);
}
GLint Renderer::init_glut(int* argc, char** argv)
{
int id;
glutInit(argc,argv);
/* size and placement hints to the window system */
glutInitWindowSize(vpd, vpd);
glutInitWindowPosition(10,10);
/* double buffered, RGB color mode */
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
/* create a GLUT window (not drawn until glutMainLoop() is entered) */
id = glutCreateWindow("cs4451 project 5: Subdivision fancyness!");
/* register callbacks */
/* window size changes */
glutReshapeFunc(reshape);
/* keypress handling when the current window has input focus */
glutKeyboardFunc(keyboard_event);
/* mouse event handling */
glutMouseFunc(mouse_button); /* button press/release */
glutMotionFunc(button_motion); /* mouse motion w/ button down */
glutPassiveMotionFunc(passive_motion); /* mouse motion with button up */
/* window obscured/revealed event handler */
glutVisibilityFunc(NULL);
/* handling of keyboard SHIFT, ALT, CTRL keys */
glutSpecialFunc(NULL);
/* what to do when mouse cursor enters/exits the current window */
glutEntryFunc(NULL);
/* what to do on each display loop iteration */
glutDisplayFunc(redraw);
/* Create the menu */
//Create the Zoom Menu
GLint menuID = glutCreateMenu(menu);
glutAddMenuEntry("Zoom in (w)",Input::ZOOM_IN_EVENT);
glutAddMenuEntry("Zoom out (s)",Input::ZOOM_OUT_EVENT);
glutAddMenuEntry("Animate (a)",Input::ANIMATE_EVENT);
glutAddMenuEntry("Lines Only (l)",Input::LINES_EVENT);
glutAddMenuEntry("Full Model (f)",Input::FULL_EVENT);
glutSetMenu(menuID);
glutAttachMenu(GLUT_RIGHT_BUTTON);
return id;
}
void Renderer::render() {
//Initialize
glutSetWindow(windowID);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* set the projection matrix */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(viewDist,1.0,15.0,25.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
init_lightsource();
glTranslatef(0,0,-20);
if (!animate) {
glMultMatrixf(currModelTransform);
} else {
glMultMatrixf(currModelTransform);
this->rotAngle1 += this->dAngle1;
this->rotAngle2 += this->dAngle2;
glRotatef(this->rotAngle1,1,2,3);
glRotatef(this->rotAngle2,-2,-1,0);
}
#ifdef SCENELIST
glCallList(this->sceneID);
#else
this->create_scene();
#endif
//Draw
glFlush();
glutSwapBuffers();
if (animate) { glutPostRedisplay(); }
}
void Renderer::window_resize(GLint vpw, GLint vph) {
glutSetWindow(this->windowID);
/* maintain a square viewport, not too small, not too big */
if( vpw < vph ) vpd = vph;
else vpd = vpw;
if( vpd < VPD_MIN ) vpd = VPD_MIN;
if( vpd > VPD_MAX ) vpd = VPD_MAX;
glViewport(0, 0, vpd, vpd);
glutReshapeWindow(vpd, vpd);
glutPostRedisplay();
}
void Renderer::set_material_properties(GLfloat r, GLfloat g, GLfloat b) {
GLfloat mat_specular[4] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_ambient_and_diffuse[4] = { 0.5, 0.5, 0.5, 1.0 };
GLfloat mat_shininess[1] = { 0.0 };
mat_specular[0] = mat_ambient_and_diffuse[0] = r;
mat_specular[1] = mat_ambient_and_diffuse[1] = g;
mat_specular[2] = mat_ambient_and_diffuse[2] = b;
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_ambient_and_diffuse);
}
void Renderer::init_lightsource()
{
GLfloat light_ambient[] = { .1, .1, .1, 1.0 };
GLfloat light_diffuse[] = { .7, .7, .7, 1.0 };
GLfloat light_specular[] = { 0, 0, 0, 1.0 };
GLfloat light_position[] = { 2, 2, 2, 0.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,1.0);
glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,0.0);
glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,0.0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
#ifdef SCENELIST
GLuint Renderer::init_sceneList() {
GLuint sceneList = glGenLists(1);
Point a1, a2, a3;
Vector tempNormal;
std::vector<Triangle>::iterator t_iter;
glNewList(sceneList,GL_COMPILE);
glBegin(GL_TRIANGLES);
for (t_iter = triangles->begin();
t_iter != triangles->end();
t_iter++)
{
a1 = points->at(t_iter->a1);
a2 = points->at(t_iter->a2);
a3 = points->at(t_iter->a3);
tempNormal = t_iter->normal;
glNormal3f(tempNormal.i, tempNormal.j, tempNormal.k);
glVertex3f(a1.x, a1.y, a1.z);
glVertex3f(a2.x, a2.y, a2.z);
glVertex3f(a3.x, a3.y, a3.z);
}
glEnd();
glEndList();
return sceneList;
}
GLvoid Renderer::create_scene() {
GLuint scene = this->init_sceneList();
GLuint sceneList = glGenLists(1);
glNewList(sceneList,GL_COMPILE);
set_material_properties(1.0,1.0,1.0);
Point Max;
Point Min;
Point Center;
std::vector<Point>::iterator p_iter;
p_iter = points->begin();
Max.x = Min.x = p_iter->x;
Max.y = Min.y = p_iter->y;
Max.z = Min.z = p_iter->z;
p_iter++;
for(; p_iter != points->end(); p_iter++)
{
if (p_iter->x > Max.x) {
Max.x = p_iter->x;
} else if (p_iter->x < Min.x) {
Min.x = p_iter->x;
}
if (p_iter->y > Max.y) {
Max.y = p_iter->y;
} else if (p_iter->y < Min.y) {
Min.y = p_iter->y;
}
if (p_iter->z > Max.z) {
Max.z = p_iter->z;
} else if (p_iter->z < Min.z) {
Min.z = p_iter->z;
}
}
Center.x = (Max.x + Min.x) / 2.;
Center.y = (Max.y + Min.y) / 2.;
Center.z = (Max.z + Min.z) / 2.;
float scaleX, scaleY, scaleZ;
scaleX = (Max.x - Min.x) / 2.;
scaleY = (Max.y - Min.y) / 2.;
scaleZ = (Max.z - Min.z) / 2.;
float scaleFactor;
scaleFactor = scaleX > scaleY ? scaleX : scaleY;
scaleFactor = scaleZ > scaleFactor ? scaleZ : scaleFactor;
scaleFactor = 1. / scaleFactor;
glPushMatrix();
glTranslatef(0.-(Center.x*scaleFactor),0.-(Center.y*scaleFactor),0.-(Center.z*scaleFactor));
glScalef(scaleFactor,scaleFactor,scaleFactor);
glCallList(scene);
glPopMatrix();
glEndList();
this->sceneID = sceneList;
}
#else
GLuint Renderer::init_sceneList() {
Point a1, a2, a3;
Vector tempNormal;
std::vector<Triangle>::iterator t_iter;
glBegin(GL_TRIANGLES);
for (t_iter = triangles->begin();
t_iter != triangles->end();
t_iter++)
{
a1 = points->at(t_iter->a1);
a2 = points->at(t_iter->a2);
a3 = points->at(t_iter->a3);
tempNormal = t_iter->normal;
glNormal3f(tempNormal.i, tempNormal.j, tempNormal.k);
glVertex3f(a1.x, a1.y, a1.z);
glVertex3f(a2.x, a2.y, a2.z);
glVertex3f(a3.x, a3.y, a3.z);
}
glEnd();
return 0;
}
GLvoid Renderer::create_scene() {
set_material_properties(1.0,1.0,1.0);
Point Max;
Point Min;
Point Center;
std::vector<Point>::iterator p_iter;
p_iter = points->begin();
Max.x = Min.x = p_iter->x;
Max.y = Min.y = p_iter->y;
Max.z = Min.z = p_iter->z;
p_iter++;
for(; p_iter != points->end(); p_iter++)
{
if (p_iter->x > Max.x) {
Max.x = p_iter->x;
} else if (p_iter->x < Min.x) {
Min.x = p_iter->x;
}
if (p_iter->y > Max.y) {
Max.y = p_iter->y;
} else if (p_iter->y < Min.y) {
Min.y = p_iter->y;
}
if (p_iter->z > Max.z) {
Max.z = p_iter->z;
} else if (p_iter->z < Min.z) {
Min.z = p_iter->z;
}
}
Center.x = (Max.x + Min.x) / 2.;
Center.y = (Max.y + Min.y) / 2.;
Center.z = (Max.z + Min.z) / 2.;
float scaleX, scaleY, scaleZ;
scaleX = (Max.x - Min.x) / 2.;
scaleY = (Max.y - Min.y) / 2.;
scaleZ = (Max.z - Min.z) / 2.;
float scaleFactor;
scaleFactor = scaleX > scaleY ? scaleX : scaleY;
scaleFactor = scaleZ > scaleFactor ? scaleZ : scaleFactor;
scaleFactor = 1. / scaleFactor;
glPushMatrix();
glTranslatef(0.-(Center.x*scaleFactor),0.-(Center.y*scaleFactor),0.-(Center.z*scaleFactor));
glScalef(scaleFactor,scaleFactor,scaleFactor);
this->init_sceneList();
glPopMatrix();
}
#endif

113
CS4451/proj5/Renderer.h Normal file
View File

@@ -0,0 +1,113 @@
#ifndef _RENDERER_H_
#define _RENDERER_H_
#include <vector>
#include <GL/glut.h>
#include <time.h>
#include <iostream>
#include "structs.h"
#include "Subdivision.h"
#define VPD_MIN 200
#define VPD_DEFAULT 800
#define VPD_MAX 1024
#define VIEWDIST_DEFAULT 8.0
#define VIEWDIST_MIN 0.0
#define VIEWDIST_MAX 16.0
class Renderer {
public:
//Members
static inline Renderer* getInstance() {
return & m_instance;
}
std::vector<Point> *points;
std::vector<Triangle> *triangles;
//Used for rotating the thing with the trackball
GLfloat currModelTransform[16];
//Initialization
void init(int *argc, char** argv);
//Accessors
inline int getVPD() {
return vpd;
}
inline float getViewDist() {
return this->viewDist;
}
//Modifiers
inline void multViewDist( float by ) {
if (dist == 79) {
return;
}
dist++;
this->viewDist *= by;
glutPostRedisplay();
}
inline void divViewDist( float by ) {
if (dist == 0) {
return;
}
dist--;
this->viewDist /= by;
glutPostRedisplay();
}
//View Handling
GLvoid window_resize(GLint vpw, GLint vph);
//Utility
void render();
bool animate;
private:
//Members
static Renderer m_instance;
int windowID;
int vpd;
GLuint sceneID;
GLfloat viewDist;
int dist;
//Constructor
inline Renderer() {
points = new std::vector<Point>;
triangles = new std::vector<Triangle>;
vpd = VPD_DEFAULT;
viewDist = VIEWDIST_DEFAULT;
animate = false;
rotAngle1 = rotAngle2 = 0;
dAngle1 = .57;
dAngle2 = .71;
dist = 62;
}
float rotAngle1, rotAngle2;
float dAngle1, dAngle2;
//Initialization
GLint init_glut(int *argc, char** argv);
void generateNormals();
void init_opengl();
//Methods
GLvoid set_material_properties(GLfloat r, GLfloat g, GLfloat b);
GLvoid init_lightsource();
GLuint init_sceneList();
GLvoid create_scene();
};
#endif

View File

@@ -0,0 +1,713 @@
#include "Subdivision.h"
#include "Renderer.h"
#include <vector>
#include <iostream>
#include <assert.h>
Subdivision Subdivision::m_instance;
void Subdivision::performSubdivision(char type)
{
//Step1
this->calculateVertexDegree();
//Step2
this->calculateIncidentTriangles();
//Step3
this->generateAdjacencyTable();
//Step4
this->generateLabels();
//Step5
this->generateNewVertices();
this->generateNewTriangles();
//Step 6
this->generateNewVertexCoords(type);
delete Renderer::getInstance()->triangles;
delete Renderer::getInstance()->points;
Renderer::getInstance()->triangles = newTriangles;
Renderer::getInstance()->points = newPoints;
newTriangles = NULL;
newPoints = NULL;
labels.clear();
adjacencies.clear();
pointDegrees.clear();
for (int i = 0; i < (int) Renderer::getInstance()->points->size(); i++) {
Renderer::getInstance()->points->at(i).incidentTriangles.clear();
}
}
/*
* Step 1
*/
void Subdivision::calculateVertexDegree()
{
std::vector<Point>::iterator p_iter = Renderer::getInstance()->points->begin();
//Allocate space for all the vertices, zero it out
for (; p_iter != Renderer::getInstance()->points->end(); p_iter++) {
pointDegrees.push_back(0);
}
std::vector<Triangle>::iterator t_iter = Renderer::getInstance()->triangles->begin();
//Calculate degrees for each vertex
for (; t_iter != Renderer::getInstance()->triangles->end(); t_iter++) {
pointDegrees[t_iter->a1]++;
pointDegrees[t_iter->a2]++;
pointDegrees[t_iter->a3]++;
}
//Display the degree of all vertices
/*for (unsigned int i = 0; i < pointDegrees.size(); i++) {
std::cout << "Index: " << i << ": "
<< pointDegrees[i] << std::endl;
}*/
}
/*
* Step 2
*/
void Subdivision::calculateIncidentTriangles()
{
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
std::vector<Point> * points = Renderer::getInstance()->points;
for (unsigned int i = 0; i < Renderer::getInstance()->triangles->size(); i++) {
points->at((*triangles)[i].a1).incidentTriangles.push_back(i);
points->at((*triangles)[i].a2).incidentTriangles.push_back(i);
points->at((*triangles)[i].a3).incidentTriangles.push_back(i);
}
//Display the incident triangles
/*std::vector<unsigned int>::iterator ui_iter;
for (unsigned int i = 0; i < points->size(); i++)
{
std::cout << "Incident Tris for Point: " << i << std::endl << " ";
ui_iter = (*points)[i].incidentTriangles.begin();
for (; ui_iter != (*points)[i].incidentTriangles.end(); ui_iter++)
{
std::cout << *ui_iter << " ";
}
std::cout << "\n";
}*/
}
/*
* Step 3
*/
void Subdivision::generateAdjacencyTable()
{
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
std::vector<Point> *points = Renderer::getInstance()->points;
std::vector<unsigned int>::iterator ui_iter;
int a1,a2,a3;
Adjacency tris;
for (unsigned int i = 0; i < triangles->size(); i++) {
a1 = (*triangles)[i].a1;
a2 = (*triangles)[i].a2;
a3 = (*triangles)[i].a3;
//Find the adjacent tri to a1 -- a2 a3
ui_iter = points->at(a2).incidentTriangles.begin();
for ( ; ui_iter != points->at(a2).incidentTriangles.end(); ui_iter++) {
if ( *ui_iter != i && (*triangles)[*ui_iter].contains(a3) ) {
tris.a1 = *ui_iter;
break;
}
}
//Find the adjacent tri to a2 -- a3 a1
ui_iter = points->at(a3).incidentTriangles.begin();
for ( ; ui_iter != points->at(a3).incidentTriangles.end(); ui_iter++) {
if ( *ui_iter != i && (*triangles)[*ui_iter].contains(a1) ) {
tris.a2 = *ui_iter;
break;
}
}
//Find the adjacent tri to a3 -- a1 a2
ui_iter = points->at(a1).incidentTriangles.begin();
for ( ; ui_iter != points->at(a1).incidentTriangles.end(); ui_iter++) {
if ( *ui_iter != i && (*triangles)[*ui_iter].contains(a2) ) {
tris.a3 = *ui_iter;
break;
}
}
//Add to Adjacency Table
this->adjacencies.push_back(tris);
}
/*std::vector<Adjacency>::iterator adj_iter = this->adjacencies.begin();
for (int i = 0; adj_iter != this->adjacencies.end(); adj_iter++, i++) {
std::cout << "Adjacency " << i << ": "
<< adj_iter->a1 << " " << adj_iter->a2
<< " " << adj_iter->a3 << std::endl;
}*/
}
/*
* Step 4
*/
void Subdivision::applyToAdjacent(Triangle& tdest,
int tdest_index,
int edgeVertex1,
int edgeVertex2, int ui_current)
{
switch (tdest.indexOf(edgeVertex1,edgeVertex2)) {
case 1:
labels.at(tdest_index).a1 = ui_current;
break;
case 2:
labels.at(tdest_index).a2 = ui_current;
break;
case 3:
labels.at(tdest_index).a3 = ui_current;
break;
default:
assert(1 != 1);
break;
}
}
void Subdivision::generateLabels() {
Adjacency a;
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
unsigned int tri_index;
std::vector<Adjacency>::iterator adj_iter = this->adjacencies.begin();
int ui_current = 0;
a.a1 = a.a2 = a.a3 = -1;
//Set all to negative 1
for (; adj_iter != this->adjacencies.end(); adj_iter++) {
this->labels.push_back(a);
}
//Assign edge numbers
for (tri_index = 0; tri_index < triangles->size(); tri_index++)
{
if (labels.at(tri_index).a1 == -1) {
//Set the opposite edge to this value
labels.at(tri_index).a1 = ui_current;
//get the adjacent Triangle
int adjTri = adjacencies.at(tri_index).a1;
Triangle &tdest = triangles->at(adjTri);
Triangle &tsrc = triangles->at(tri_index);
this->applyToAdjacent(tdest,adjTri,tsrc.a2,tsrc.a3,ui_current);
ui_current++;
}
if (labels.at(tri_index).a2 == -1) {
//Set the opposite edge to this value
labels.at(tri_index).a2 = ui_current;
//get the adjacent Triangle
int adjTri = adjacencies.at(tri_index).a2;
Triangle &tdest = triangles->at(adjTri);
Triangle &tsrc = triangles->at(tri_index);
this->applyToAdjacent(tdest,adjTri,tsrc.a1,tsrc.a3,ui_current);
ui_current++;
}
if (labels.at(tri_index).a3 == -1) {
//Set the opposite edge to this value
labels.at(tri_index).a3 = ui_current;
//get the adjacent Triangle
int adjTri = adjacencies.at(tri_index).a3;
Triangle &tdest = triangles->at(adjTri);
Triangle &tsrc = triangles->at(tri_index);
this->applyToAdjacent(tdest,adjTri,tsrc.a1,tsrc.a2,ui_current);
ui_current++;
}
}
/*std::vector<Adjacency>::iterator lab_iter = this->labels.begin();
for (; lab_iter != this->labels.end(); lab_iter++) {
std::cout << "Edge nums: " << lab_iter->a1 << " " << lab_iter->a2
<< " " << lab_iter->a3 << std::endl;
} */
}
/*
* Step 5
*/
void Subdivision::generateNewVertices() {
newPoints = new std::vector<Point>;
*newPoints = *(Renderer::getInstance()->points);
Point p;
p.x = p.y = p.z = 0;
//std::cout << (int)newPoints->size() << std::endl;
int numEdges = (3*(int)Renderer::getInstance()->triangles->size()) / 2;
for (int i = 0; i < numEdges; i++) {
newPoints->push_back(p);
}
//std::cout << (int) newPoints->size() << std::endl;
}
void Subdivision::generateNewTriangles() {
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
//std::vector<Triangle>::iterator t_iter;
unsigned int tri_index;
Triangle tTemp;
int numVertices = (int) Renderer::getInstance()->points->size();
newTriangles = new std::vector<Triangle>;
for (tri_index = 0; tri_index < triangles->size(); tri_index++) {
Triangle &current = (*triangles)[tri_index];
//Generate the first triangle -> a1, a1a2, a3a1
tTemp.a1 = current.a1;
tTemp.a2 = labels.at(tri_index).a3 + numVertices;
tTemp.a3 = labels.at(tri_index).a2 + numVertices;
newTriangles->push_back(tTemp);
//Generate the second triangle -> a1a2, a2a3, a3a1
tTemp.a1 = labels.at(tri_index).a3 + numVertices;
tTemp.a2 = labels.at(tri_index).a1 + numVertices;
tTemp.a3 = labels.at(tri_index).a2 + numVertices;
newTriangles->push_back(tTemp);
//Generate the third triangle -> a1a2, a2, a2a3
tTemp.a1 = labels.at(tri_index).a3 + numVertices;
tTemp.a2 = current.a2;
tTemp.a3 = labels.at(tri_index).a1 + numVertices;
newTriangles->push_back(tTemp);
//Generate the fourth triangle -> a1a3, a2a3, a3
tTemp.a1 = labels.at(tri_index).a2 + numVertices;
tTemp.a2 = labels.at(tri_index).a1 + numVertices;
tTemp.a3 = current.a3;
newTriangles->push_back(tTemp);
}
//std::cout << "new Triangles size: " << newTriangles.size() << std::endl;
}
/*
* Step 6
*/
void Subdivision::generateNewVertexCoords(char type) {
if (type == 'L') {
//this->splitTriangles();
this->loopSubdivide();
} else if (type == 'B') {
//this->splitTriangles();
this->butterflySubdivide();
} else {
this->splitTriangles();
}
}
Point Subdivision::pointOppositeTo(Triangle &t, int in1, int in2, std::vector<Point> *points) {
switch (t.indexOf(in1,in2)) {
case 1:
return points->at(t.a1);
case 2:
return points->at(t.a2);
case 3:
return points->at(t.a3);
default:
assert(0 != 0);
//Shut up compiler
Point p;
return p;
}
}
Point Subdivision::farOppositePoints(Triangle &tAdj, int in1, int in2) {
std::vector<Point> *points = Renderer::getInstance()->points;
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
Point temp;
unsigned int ui_num;
for (int i=0; i < (int) points->at(in1).incidentTriangles.size(); i++) {
if (triangles->at(points->at(in1).incidentTriangles[i]) == tAdj) {
ui_num = points->at(in1).incidentTriangles[i];
break;
}
}
switch (tAdj.indexOf(in1,in2)) {
case 1: //a2a3 = adjacent edge
temp = temp +
(pointOppositeTo(triangles->at(adjacencies.at(ui_num).a2),tAdj.a1,tAdj.a3,points)
* this->bfly_edge_far_weight);
temp = temp +
(pointOppositeTo(triangles->at(adjacencies.at(ui_num).a3),tAdj.a1,tAdj.a2,points)
* this->bfly_edge_far_weight);
break;
case 2: //a1a3 = adjacent edge
temp = temp +
(pointOppositeTo(triangles->at(adjacencies.at(ui_num).a1),tAdj.a2,tAdj.a3,points)
* this->bfly_edge_far_weight);
temp = temp +
(pointOppositeTo(triangles->at(adjacencies.at(ui_num).a3),tAdj.a2,tAdj.a1,points)
* this->bfly_edge_far_weight);
break;
case 3: //a1a2 = adjacent edge
temp = temp +
(pointOppositeTo(triangles->at(adjacencies.at(ui_num).a1),tAdj.a2,tAdj.a3,points)
* this->bfly_edge_far_weight);
temp = temp +
(pointOppositeTo(triangles->at(adjacencies.at(ui_num).a2),tAdj.a1,tAdj.a3,points)
* this->bfly_edge_far_weight);
break;
default:
assert(0 != 0);
break;
}
return temp;
}
void Subdivision::butterflySubdivide() {
std::vector<Point> *points = Renderer::getInstance()->points;
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
//Copy the old point locations
for (unsigned int p_index = 0; p_index < (unsigned int) points->size(); p_index++) {
newPoints->at(p_index) = points->at(p_index);
}
unsigned int ui_edge = 0; //Current edge we be using
for (unsigned int ui = 0; ui < labels.size(); ui++) {
Adjacency &a = labels.at(ui);
if (a.a1 == ui_edge) {
Point Q;
Triangle &t = triangles->at(ui);
Triangle tAdj = triangles->at(adjacencies.at(ui).a1);
//Adjacent Edges
Q = points->at(t.a2) + points->at(t.a3);
Q = Q * this->bfly_edge_adjacent_weight;
//Opposite Edges
Q = Q + (points->at(t.a1) * this->bfly_edge_opposite_weight);
Q = Q +
(pointOppositeTo(tAdj,t.a2,t.a3,points)
* this->bfly_edge_opposite_weight);
//Far Edges
//a1a2
Q = Q +
(pointOppositeTo(triangles->at(adjacencies.at(ui).a3),t.a1,t.a2,points)
* this->bfly_edge_far_weight);
//a1a3
Q = Q +
(pointOppositeTo(triangles->at(adjacencies.at(ui).a2),t.a1,t.a3,points)
* this->bfly_edge_far_weight);
//opposite Triangle
Q = Q + farOppositePoints(tAdj,t.a2,t.a3);
newPoints->at(ui_edge + points->size()) = Q;
ui_edge++;
}
if (a.a2 == ui_edge) {
Point Q;
Triangle &t = triangles->at(ui);
Triangle tAdj = triangles->at(adjacencies.at(ui).a2);
//Adjacent Edges
Q = points->at(t.a1) + points->at(t.a3);
Q = Q * this->bfly_edge_adjacent_weight;
//Opposite Edges
Q = Q + (points->at(t.a2) * this->bfly_edge_opposite_weight);
Q = Q +
(pointOppositeTo(tAdj,t.a1,t.a3,points)
* this->bfly_edge_opposite_weight);
//Far Edges
//a1a2
Q = Q +
(pointOppositeTo(triangles->at(adjacencies.at(ui).a3),t.a1,t.a2,points)
* this->bfly_edge_far_weight);
//a1a3
Q = Q +
(pointOppositeTo(triangles->at(adjacencies.at(ui).a1),t.a2,t.a3,points)
* this->bfly_edge_far_weight);
//opposite Triangle
Q = Q + farOppositePoints(tAdj,t.a1,t.a3);
newPoints->at(ui_edge + points->size()) = Q;
ui_edge++;
}
if (a.a3 == ui_edge) {
Point Q;
Triangle &t = triangles->at(ui);
Triangle tAdj = triangles->at(adjacencies.at(ui).a3);
//Adjacent Edges
Q = points->at(t.a1) + points->at(t.a2);
Q = Q * this->bfly_edge_adjacent_weight;
//Opposite Edges
Q = Q + (points->at(t.a3) * this->bfly_edge_opposite_weight);
Q = Q +
(pointOppositeTo(tAdj,t.a1,t.a2,points)
* this->bfly_edge_opposite_weight);
//Far Edges
//a1a2
Q = Q +
(pointOppositeTo(triangles->at(adjacencies.at(ui).a2),t.a1,t.a3,points)
* this->bfly_edge_far_weight);
//a1a3
Q = Q +
(pointOppositeTo(triangles->at(adjacencies.at(ui).a1),t.a2,t.a3,points)
* this->bfly_edge_far_weight);
//opposite Triangle
Q = Q + farOppositePoints(tAdj,t.a1,t.a2);
newPoints->at(ui_edge + points->size()) = Q;
ui_edge++;
}
}
//this->splitTriangles();
}
void Subdivision::loopSubdivide() {
std::vector<Point> *points = Renderer::getInstance()->points;
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
//Traverse all points and generate their new locations
for (unsigned int p_index = 0; p_index < points->size(); p_index++) {
Point &p = points->at(p_index);
Point temp;
for (unsigned int ui = 0; ui < p.incidentTriangles.size(); ui++) {
Triangle t = triangles->at(p.incidentTriangles[ui]);
temp += points->at(t.a1);
temp += points->at(t.a2);
temp += points->at(t.a3);
//Subtract off self -- is this faster than using a bunch of if's?
//Probably, since there would be at least one false if (or one true)
//And that would piss off the pipeline
temp = temp - p;
}
//All points were counted twice
temp = temp / 2.;
//Use point Degrees to figure out next step
if (pointDegrees.at(p_index) == 3) {
//std::cout << "DEGREE THREE!!!!\n\n";
temp = temp * this->d3_loop_neighbor_weight;
temp += p * this->d3_loop_center_weight;
} else {
temp = temp * this->dn_loop_neighbor_weight(pointDegrees.at(p_index));
temp += p * this->dn_loop_center_weight;
}
newPoints->at(p_index) = temp;
/*std::cout << "Old: ";
p.printMe();
std::cout << "\nNew: ";
temp.printMe();
std::cout << "\n";*/
}
/* Do the calculations for edge vertex locations */
//Calculate the number of edges
unsigned int ui_edge = 0;
/*
* TODO: REFACTOR!!!!
*/
for (unsigned int ui = 0; ui < labels.size(); ui++) {
Adjacency &a = labels.at(ui);
if (a.a1 == ui_edge) {
Point Q;
Triangle &t = triangles->at(ui);
Triangle &tAdj = triangles->at(adjacencies.at(ui).a1);
//Add the edge points
Q = points->at(t.a2) + points->at(t.a3);
Q = Q * this->loop_edge_adjacent_weight;
//Add the opposite points
Q = Q + (points->at(t.a1) * this->loop_edge_opposite_weight);
switch (tAdj.indexOf(t.a2, t.a3)) {
case 1:
Q = Q + (points->at(tAdj.a1) * this->loop_edge_opposite_weight);
break;
case 2:
Q = Q + (points->at(tAdj.a2) * this->loop_edge_opposite_weight);
break;
case 3:
Q = Q + (points->at(tAdj.a3) * this->loop_edge_opposite_weight);
break;
default:
assert(0 != 0);
break;
}
newPoints->at(ui_edge + points->size()) = Q;
ui_edge++;
}
if (a.a2 == ui_edge) {
Point Q;
Triangle &t = triangles->at(ui);
Triangle &tAdj = triangles->at(adjacencies.at(ui).a2);
//Add the edge points
Q = points->at(t.a1) + points->at(t.a3);
Q = Q * this->loop_edge_adjacent_weight;
//Add the opposite points
Q = Q + (points->at(t.a2) * this->loop_edge_opposite_weight);
switch (tAdj.indexOf(t.a1, t.a3)) {
case 1:
Q = Q + (points->at(tAdj.a1) * this->loop_edge_opposite_weight);
break;
case 2:
Q = Q + (points->at(tAdj.a2) * this->loop_edge_opposite_weight);
break;
case 3:
Q = Q + (points->at(tAdj.a3) * this->loop_edge_opposite_weight);
break;
default:
assert(0 != 0);
break;
}
newPoints->at(ui_edge + points->size()) = Q;
ui_edge++;
}
if (a.a3 == ui_edge) {
Point Q;
Triangle &t = triangles->at(ui);
Triangle &tAdj = triangles->at(adjacencies.at(ui).a3);
//Add the edge points
Q = points->at(t.a1) + points->at(t.a2);
Q = Q * this->loop_edge_adjacent_weight;
//Add the opposite points
Q = Q + (points->at(t.a3) * this->loop_edge_opposite_weight);
switch (tAdj.indexOf(t.a1, t.a2)) {
case 1:
Q = Q + (points->at(tAdj.a1) * this->loop_edge_opposite_weight);
break;
case 2:
Q = Q + (points->at(tAdj.a2) * this->loop_edge_opposite_weight);
break;
case 3:
Q = Q + (points->at(tAdj.a3) * this->loop_edge_opposite_weight);
break;
default:
assert(0 != 0);
break;
}
newPoints->at(ui_edge + points->size()) = Q;
ui_edge++;
}
}
}
void Subdivision::splitTriangles() {
std::vector<Triangle> *triangles = Renderer::getInstance()->triangles;
std::vector<Point> *points = Renderer::getInstance()->points;
int numVertices = (int) Renderer::getInstance()->points->size();
Point* p;
Triangle tCurr;
for (int tri_index = 0; tri_index < (int)triangles->size(); tri_index++) {
tCurr = triangles->at(tri_index);
/*std::cout << labels.at(tri_index).a1+numVertices << std::endl;
std::cout << (int) newPoints->size() << std::endl;*/
//a2a3
p = &(newPoints->at(labels.at(tri_index).a1+numVertices));
p->x = (points->at(tCurr.a2).x + points->at(tCurr.a3).x) / 2.;
p->y = (points->at(tCurr.a2).y + points->at(tCurr.a3).y) / 2.;
p->z = (points->at(tCurr.a2).z + points->at(tCurr.a3).z) / 2.;
//a1a3
p = &(newPoints->at(labels.at(tri_index).a2+numVertices));
p->x = (points->at(tCurr.a1).x + points->at(tCurr.a3).x) / 2.;
p->y = (points->at(tCurr.a1).y + points->at(tCurr.a3).y) / 2.;
p->z = (points->at(tCurr.a1).z + points->at(tCurr.a3).z) / 2.;
//a1a2
p = &(newPoints->at(labels.at(tri_index).a3+numVertices));
p->x = (points->at(tCurr.a2).x + points->at(tCurr.a1).x) / 2.;
p->y = (points->at(tCurr.a2).y + points->at(tCurr.a1).y) / 2.;
p->z = (points->at(tCurr.a2).z + points->at(tCurr.a1).z) / 2.;
}
}

View File

@@ -0,0 +1,86 @@
#ifndef _SUBDIVISION_H_
#define _SUBDIVISION_H_
#include <vector>
#include "structs.h"
class Subdivision {
public:
static inline Subdivision* getInstance() {
return & m_instance;
}
void performSubdivision(char type);
private:
static Subdivision m_instance;
std::vector<Adjacency> adjacencies;
std::vector<Adjacency> labels;
std::vector<int> pointDegrees;
std::vector<Point> *newPoints;
std::vector<Triangle> *newTriangles;
inline Subdivision() {
d3_loop_center_weight = 7. / 16;
d3_loop_neighbor_weight = 3. /16;
dn_loop_center_weight = 5. / 8;
loop_edge_adjacent_weight = 3. / 8;
loop_edge_opposite_weight = 1. / 8;
bfly_edge_adjacent_weight = .5;
bfly_edge_opposite_weight = 1. / 8;
bfly_edge_far_weight = -1 / 16.;
}
float d3_loop_center_weight;
float d3_loop_neighbor_weight;
float dn_loop_center_weight;
inline float dn_loop_neighbor_weight(int n) {
return (float) ( 3. / (8 * n) );
}
float loop_edge_adjacent_weight;
float loop_edge_opposite_weight;
float bfly_edge_adjacent_weight;
float bfly_edge_opposite_weight;
float bfly_edge_far_weight;
//Step 1
void calculateVertexDegree();
//Step 2
void calculateIncidentTriangles();
//Step 3
void generateAdjacencyTable();
//Step 4
void generateLabels();
void applyToAdjacent(Triangle& tdest,
int tdest_index,
int edgeVertex1,
int edgeVertex2,
int ui_current);
//Step 5
void generateNewVertices();
void generateNewTriangles();
//Step 6
void generateNewVertexCoords(char type);
void splitTriangles();
void loopSubdivide();
void butterflySubdivide();
Point pointOppositeTo(Triangle &t, int in1, int in2, std::vector<Point> *points);
Point farOppositePoints(Triangle &tAdj, int in1, int in2);
};
#endif

44
CS4451/proj5/cwrappers.h Normal file
View File

@@ -0,0 +1,44 @@
#ifndef _CWRAPPERS_H_
#define _CWRAPPERS_H_
#include <GL/glut.h>
#include "Renderer.h"
#include "Input.h"
inline GLvoid reshape(GLint vpw, GLint vph)
{
Renderer::getInstance()->window_resize(vpw,vph);
}
inline GLvoid redraw()
{
Renderer::getInstance()->render();
}
inline GLvoid keyboard_event(GLubyte key, GLint x, GLint y)
{
Input::getInstance()->keyboard_event(key,x,y);
}
inline GLvoid menu( int value )
{
Input::getInstance()->menu(value);
}
inline GLvoid passive_motion(GLint mx, GLint my)
{
Input::getInstance()->passive_motion(mx,my);
}
inline GLvoid button_motion(GLint mx, GLint my)
{
Input::getInstance()->button_motion(mx,my);
}
inline GLvoid mouse_button(GLint btn, GLint state, GLint mx, GLint my)
{
Input::getInstance()->mouse_button(btn,state,mx,my);
}
#endif

BIN
CS4451/proj5/implsub.pdf Normal file

Binary file not shown.

View File

@@ -0,0 +1,305 @@
200 102
38 59 37
67 66 65
61 60 62
66 67 63
71 70 72
1 61 62
63 67 65
10 71 72
64 65 66
66 63 64
59 5 37
70 69 72
1 62 60
70 71 10
3 60 61
60 3 2
5 36 37
59 38 9
38 37 36
9 5 59
1 60 2
36 9 38
69 10 72
63 65 14
61 1 3
8 36 5
68 10 69
70 13 69
13 70 10
12 68 69
65 64 14
2 3 7
4 1 2
9 36 11
13 12 69
5 9 6
63 0 64
8 11 36
5 6 8
3 1 4
40 14 64
40 64 0
39 0 63
10 15 13
63 14 39
16 3 4
68 12 17
3 16 7
68 15 10
14 40 19
11 21 9
18 14 19
39 14 18
12 13 15
7 4 2
16 41 7
40 0 42
20 12 15
43 99 97
16 4 99
16 99 43
99 11 8
42 19 40
4 11 99
98 43 97
21 6 9
11 4 7
11 7 21
6 46 8
43 98 26
43 41 16
45 41 43
0 39 18
6 21 46
98 97 100
101 42 0
20 17 12
0 18 44
21 7 47
97 99 24
8 46 22
22 99 8
24 100 97
24 99 22
50 26 98
101 0 44
68 96 15
26 45 43
17 98 100
19 42 29
17 96 68
20 15 49
41 45 48
98 17 50
41 47 7
100 101 96
96 17 100
101 100 42
44 96 101
44 18 23
21 47 51
28 19 29
100 29 42
100 24 25
100 25 29
22 46 52
15 96 49
20 50 17
22 27 24
47 41 48
48 45 57
54 50 20
18 19 53
45 26 57
26 50 54
46 21 55
34 51 47
48 34 47
22 52 27
21 51 55
24 27 25
44 49 96
20 49 32
53 23 18
56 32 49
54 20 32
19 28 53
54 57 26
49 44 23
55 52 46
49 23 56
57 91 48
34 48 35
25 27 95
52 95 27
53 31 23
91 35 48
56 23 31
28 29 94
51 30 55
55 58 52
25 94 29
92 52 58
57 54 33
92 95 52
25 95 94
57 33 91
54 32 93
33 92 91
93 33 54
94 53 28
33 95 92
51 73 30
94 31 53
32 56 31
55 30 58
79 84 76
81 76 84
91 92 88
51 34 73
88 92 58
32 31 93
94 93 31
33 94 95
35 82 34
33 93 94
73 34 82
75 79 76
35 91 88
76 81 77
75 76 73
79 75 86
77 73 76
35 88 83
84 79 86
58 30 85
73 82 75
80 77 81
75 74 89
58 85 88
75 89 86
84 87 81
73 77 78
80 81 87
82 74 75
30 73 78
78 77 80
86 87 84
78 85 30
82 35 83
85 83 88
86 89 90
87 86 90
87 78 80
89 74 90
82 83 74
87 83 85
87 85 78
90 74 83
83 87 90
0.001926000000000 -0.065671000000000 -0.019318000000000
0.029802000000000 0.007896000000000 -0.059000000000000
0.025658000000000 0.018419000000000 -0.048434000000000
0.032273000000000 0.016543000000000 -0.047934000000000
0.020041000000000 0.018210000000000 -0.018727000000000
-0.005331000000000 0.030845000000000 -0.059167000000000
-0.004469000000000 0.031253000000000 -0.027697000000000
0.027391000000000 0.032304000000000 -0.016363000000000
-0.002236000000000 0.020906000000000 -0.019026000000000
0.000277000000000 0.034612000000000 -0.043518000000000
0.031962000000000 -0.064345000000000 -0.052523000000000
0.004143000000000 0.026454000000000 -0.017892000000000
0.037533000000000 -0.056506000000000 -0.026456000000000
0.031617000000000 -0.065487000000000 -0.026642000000000
-0.003393000000000 -0.084820000000000 -0.032925000000000
0.028729000000000 -0.058611000000000 -0.012976000000000
0.027148000000000 0.016034000000000 -0.018526000000000
0.034187000000000 -0.039048000000000 -0.006113000000000
-0.002488000000000 -0.073122000000000 -0.008808000000000
-0.009182000000000 -0.067228000000000 -0.006423000000000
0.039122000000000 -0.054029000000000 -0.007808000000000
-0.001995000000000 0.039140000000000 -0.011489000000000
-0.004523000000000 0.013925000000000 0.000237000000000
0.014736000000000 -0.072402000000000 0.019563000000000
-0.011617000000000 -0.018180000000000 -0.003958000000000
-0.008154000000000 -0.035398000000000 0.015753000000000
0.039077000000000 -0.014257000000000 -0.003369000000000
-0.011372000000000 -0.012497000000000 0.009510000000000
-0.010797000000000 -0.060778000000000 0.020167000000000
-0.012781000000000 -0.047691000000000 0.001208000000000
-0.001094000000000 0.044418000000000 0.028756000000000
0.020568000000000 -0.066207000000000 0.031441000000000
0.041192000000000 -0.054855000000000 0.026135000000000
0.024573000000000 -0.018167000000000 0.031181000000000
0.019066000000000 0.049396000000000 0.020386000000000
0.023587000000000 0.044156000000000 0.030348000000000
-0.000432000000000 0.029087000000000 -0.051580000000000
-0.001091000000000 0.033108000000000 -0.068145000000000
0.001896000000000 0.040836000000000 -0.075762000000000
0.000390000000000 -0.083276000000000 -0.022060000000000
-0.005399000000000 -0.070654000000000 -0.026878000000000
0.033204000000000 0.027171000000000 -0.013514000000000
-0.007184000000000 -0.053863000000000 -0.006609000000000
0.019645000000000 0.005121000000000 -0.017129000000000
0.008714000000000 -0.069505000000000 0.004164000000000
0.030466000000000 0.014162000000000 -0.000446000000000
-0.012491000000000 0.030472000000000 -0.004288000000000
0.017827000000000 0.041716000000000 -0.004739000000000
0.034873000000000 0.038763000000000 0.006909000000000
0.032540000000000 -0.068954000000000 0.006480000000000
0.034125000000000 -0.031162000000000 0.000936000000000
0.005043000000000 0.048459000000000 0.015479000000000
-0.005202000000000 0.012106000000000 0.017762000000000
0.000592000000000 -0.071142000000000 0.024146000000000
0.038253000000000 -0.031036000000000 0.022029000000000
-0.009868000000000 0.036450000000000 0.021186000000000
0.031767000000000 -0.069724000000000 0.023324000000000
0.031844000000000 0.010155000000000 0.017073000000000
0.004129000000000 0.020288000000000 0.036198000000000
-0.007303000000000 0.043736000000000 -0.074767000000000
0.029260000000000 0.020775000000000 -0.073221000000000
0.035529000000000 0.016009000000000 -0.073442000000000
0.026595000000000 0.011314000000000 -0.075735000000000
0.000586000000000 -0.084948000000000 -0.062774000000000
-0.004328000000000 -0.083647000000000 -0.054654000000000
-0.004840000000000 -0.089908000000000 -0.061785000000000
-0.007709000000000 -0.076820000000000 -0.075736000000000
-0.002420000000000 -0.086772000000000 -0.075367000000000
0.029542000000000 -0.045283000000000 -0.014816000000000
0.034798000000000 -0.073656000000000 -0.057595000000000
0.028516000000000 -0.065601000000000 -0.065629000000000
0.029007000000000 -0.056727000000000 -0.073736000000000
0.037335000000000 -0.066528000000000 -0.073631000000000
-0.002773000000000 0.063228000000000 0.038561000000000
-0.003254000000000 0.078394000000000 0.066331000000000
-0.006424000000000 0.079858000000000 0.042047000000000
-0.024407000000000 0.078132000000000 0.038887000000000
-0.018261000000000 0.064083000000000 0.042628000000000
-0.014002000000000 0.064094000000000 0.065795000000000
-0.031467000000000 0.091518000000000 0.036266000000000
-0.024905000000000 0.068442000000000 0.057596000000000
-0.040341000000000 0.082534000000000 0.038735000000000
0.013356000000000 0.061931000000000 0.050220000000000
0.010872000000000 0.054885000000000 0.066238000000000
-0.042298000000000 0.090477000000000 0.036757000000000
0.005569000000000 0.043062000000000 0.061048000000000
-0.027687000000000 0.089466000000000 0.045685000000000
-0.016615000000000 0.069989000000000 0.071044000000000
0.015905000000000 0.021768000000000 0.041957000000000
-0.013571000000000 0.087706000000000 0.057797000000000
-0.007342000000000 0.082596000000000 0.071021000000000
0.028805000000000 0.020390000000000 0.027752000000000
0.010653000000000 -0.000458000000000 0.028642000000000
0.029651000000000 -0.040471000000000 0.037911000000000
-0.002741000000000 -0.045120000000000 0.034797000000000
0.002586000000000 -0.021464000000000 0.029749000000000
0.023171000000000 -0.059029000000000 -0.003902000000000
0.004252000000000 -0.009860000000000 -0.019292000000000
0.016917000000000 -0.028267000000000 -0.013144000000000
0.006963000000000 0.013345000000000 -0.018159000000000
-0.000513000000000 -0.038562000000000 -0.001963000000000
-0.000204000000000 -0.056523000000000 -0.007615000000000

17
CS4451/proj5/inputs/oct.t Normal file
View File

@@ -0,0 +1,17 @@
8 6
0 1 4
1 0 5
1 2 4
2 1 5
2 3 4
3 2 5
3 0 4
0 3 5
0.000000000000000 0.000000000000000 0.000000000000000
1.000000000000000 0.000000000000000 0.000000000000000
1.000000000000000 -1.000000000000000 0.000000000000000
0.000000000000000 -1.000000000000000 0.000000000000000
0.500000000000000 -0.500000000000000 0.700000000000000
0.500000000000000 -0.500000000000000 -0.700000000000000

View File

@@ -0,0 +1,155 @@
100 52
41 22 23
16 13 22
13 23 22
41 39 22
39 28 16
16 22 39
13 17 23
26 23 17
41 23 26
48 39 41
13 16 11
41 51 48
16 20 11
39 18 28
20 16 28
30 18 39
20 28 18
40 41 26
26 17 24
11 17 13
24 40 26
46 39 48
51 41 40
48 50 42
48 51 50
48 42 46
9 17 11
51 49 50
39 46 30
30 46 42
9 24 17
49 47 50
27 9 20
42 33 30
30 33 18
20 9 11
49 51 40
49 40 47
20 18 27
27 12 9
33 27 18
50 45 42
34 40 24
33 42 27
27 42 45
24 9 10
50 47 45
45 47 36
44 27 45
43 47 40
43 36 47
43 40 34
10 4 24
25 12 27
37 44 45
34 24 4
36 37 45
43 34 38
14 9 12
38 36 43
27 44 25
9 14 10
31 37 36
25 14 12
34 4 21
38 34 21
44 37 31
36 38 31
25 44 14
31 14 44
10 14 8
32 38 21
38 32 31
21 4 6
2 4 10
10 8 2
29 14 31
31 32 29
21 35 32
21 6 19
21 19 35
14 29 8
6 7 19
35 19 32
19 29 32
4 0 6
1 7 6
0 1 6
29 15 8
2 0 4
19 15 29
15 19 7
2 8 5
8 15 5
7 5 15
5 7 3
5 3 2
0 3 1
7 1 3
0 2 3
-0.021951000000000 -0.016694000000000 0.027905000000000
-0.020198000000000 -0.021979000000000 0.029941000000000
-0.022048000000000 -0.010323000000000 0.028502000000000
-0.018652000000000 -0.011968000000000 0.033606000000000
-0.012795000000000 -0.010887000000000 0.007858000000000
-0.019359000000000 -0.006999000000000 0.029273000000000
-0.016275000000000 -0.021142000000000 0.020488000000000
-0.012658000000000 -0.013692000000000 0.023804000000000
-0.014449000000000 -0.001947000000000 0.019472000000000
-0.014937000000000 0.000715000000000 -0.005343000000000
-0.014235000000000 -0.005827000000000 0.005842000000000
-0.013733000000000 0.004487000000000 -0.018713000000000
-0.011305000000000 0.008280000000000 -0.001332000000000
-0.008974000000000 0.001282000000000 -0.027154000000000
-0.009435000000000 0.004336000000000 0.009717000000000
-0.013284000000000 -0.006364000000000 0.024100000000000
-0.007325000000000 0.008503000000000 -0.031026000000000
-0.007950000000000 -0.006156000000000 -0.020615000000000
-0.006549000000000 0.016976000000000 -0.014838000000000
0.001239000000000 -0.007360000000000 0.024309000000000
-0.011387000000000 0.011393000000000 -0.016977000000000
-0.003354000000000 -0.013007000000000 0.009711000000000
-0.004892000000000 0.004200000000000 -0.033160000000000
-0.001664000000000 -0.001422000000000 -0.030350000000000
-0.005717000000000 -0.009583000000000 -0.011158000000000
-0.005496000000000 0.011131000000000 0.003930000000000
-0.000552000000000 -0.007258000000000 -0.022104000000000
-0.001127000000000 0.012910000000000 -0.003557000000000
-0.005674000000000 0.016719000000000 -0.024038000000000
-0.001166000000000 -0.000291000000000 0.019900000000000
0.001313000000000 0.020897000000000 -0.018427000000000
-0.001636000000000 0.004378000000000 0.008829000000000
0.001752000000000 -0.002747000000000 0.012574000000000
0.004311000000000 0.018079000000000 -0.007519000000000
0.002517000000000 -0.014361000000000 -0.000203000000000
0.003537000000000 -0.006581000000000 0.018294000000000
0.010460000000000 0.003291000000000 0.000250000000000
0.009770000000000 0.007930000000000 0.002336000000000
0.004406000000000 -0.003393000000000 0.005758000000000
0.004690000000000 0.021876000000000 -0.022650000000000
0.004609000000000 -0.008838000000000 -0.007867000000000
0.011135000000000 -0.000695000000000 -0.028700000000000
0.011466000000000 0.016269000000000 -0.013559000000000
0.010775000000000 -0.004032000000000 0.000901000000000
0.004151000000000 0.010628000000000 0.004766000000000
0.010072000000000 0.008833000000000 -0.003327000000000
0.015157000000000 0.020215000000000 -0.016786000000000
0.010608000000000 0.001630000000000 -0.007987000000000
0.014215000000000 0.012952000000000 -0.021438000000000
0.018468000000000 0.003488000000000 -0.016777000000000
0.015407000000000 0.009964000000000 -0.016026000000000
0.022221000000000 0.004842000000000 -0.020612000000000

7685
CS4451/proj5/inputs/shape.t Normal file

File diff suppressed because it is too large Load Diff

51
CS4451/proj5/inputs/tt.t Normal file
View File

@@ -0,0 +1,51 @@
32 16
11 15 14
9 11 14
8 12 13
10 8 13
9 14 12
8 9 12
10 13 15
11 10 15
1 11 9
3 1 9
2 8 10
0 2 10
3 9 8
2 3 8
0 10 11
1 0 11
5 1 3
7 5 3
6 2 0
4 6 0
7 3 2
6 7 2
4 0 1
5 4 1
14 5 7
12 14 7
13 6 4
15 13 4
12 7 6
13 12 6
15 4 5
14 15 5
-15.000000000000000 0.000000000000000 -5.000000000000000
-15.000000000000000 0.000000000000000 5.000000000000000
-5.000000000000000 0.000000000000000 -5.000000000000000
-5.000000000000000 0.000000000000000 5.000000000000000
-0.000000000000000 -16.532814999999999 -2.705981000000000
-0.000000000000000 -12.705981000000000 6.532815000000000
-0.000000000000000 -7.294019000000000 -6.532815000000000
-0.000000000000000 -3.467185000000000 2.705981000000000
0.000000000000000 3.467185000000000 -2.705981000000000
0.000000000000000 7.294019000000000 6.532815000000000
0.000000000000000 12.705981000000000 -6.532815000000000
0.000000000000000 16.532814999999999 2.705981000000000
2.928932000000000 0.000000000000000 0.000000000000000
10.000000000000000 0.000000000000000 -7.071068000000000
10.000000000000000 0.000000000000000 7.071068000000000
17.071068000000000 0.000000000000000 0.000000000000000

58
CS4451/proj5/main.cpp Normal file
View File

@@ -0,0 +1,58 @@
#include <iostream>
#include "FileReader.h"
#include "Renderer.h"
#include <GL/glut.h>
//Print the File Read in in the same format as it was read in
void printFile() {
std::cout << (unsigned int)Renderer::getInstance()->triangles->size() << " "
<< (unsigned int)Renderer::getInstance()->points->size() << std::endl << std::endl;
std::vector<Triangle>::iterator t_iter = Renderer::getInstance()->triangles->begin();
for (;t_iter != Renderer::getInstance()->triangles->end(); t_iter++) {
std::cout << t_iter->a1 << " " << t_iter->a2 << " " << t_iter->a3 << std::endl;
}
std::cout << "\n";
std::vector<Point>::iterator p_iter = Renderer::getInstance()->points->begin();
for (; p_iter != Renderer::getInstance()->points->end(); p_iter++) {
std::cout << p_iter->x << " " << p_iter->y << " " << p_iter->z << std::endl;
}
}
int main(int argc, char** argv) {
if (argc < 4) {
std::cout << "Usage: \n"
<< " ./project4 number_of_subdivisions kind_of_subdivision input_file_name\n"
<< " number_of_subdivisions integer >= 0\n"
<< " kind_of_subdivision: 'B' for Butterfly, 'L' for Loop\n"
<< " Anything else just splits triangles into 4.\n"
;
return 0;
}
if (*argv[2] == 'b' || *argv[2] == 'B') {
*argv[2] = 'B';
std::cout << "Using Butterfly Subdivision " << atoi(argv[1]) << " times.\n";
} else if (*argv[2] == 'l' || *argv[2] == 'L') {
*argv[2] = 'L';
std::cout << "Using Loop Subdivision. " << atoi(argv[1]) << " times.\n";
} else {
std::cout << "Splitting triangles into 4 " << atoi(argv[1]) << " times.\n";
}
FileReader::getInstance()->readFile(argv[3]);
Renderer::getInstance()->init(&argc,argv);
glutMainLoop();
return 0;
}

BIN
CS4451/proj5/proj5.ncb Normal file

Binary file not shown.

BIN
CS4451/proj5/proj5.pdf Normal file

Binary file not shown.

21
CS4451/proj5/proj5.sln Normal file
View File

@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proj5", "proj5.vcproj", "{544685C3-2A51-4DD1-A71B-F7C5656E3E4A}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{544685C3-2A51-4DD1-A71B-F7C5656E3E4A}.Debug.ActiveCfg = Debug|Win32
{544685C3-2A51-4DD1-A71B-F7C5656E3E4A}.Debug.Build.0 = Debug|Win32
{544685C3-2A51-4DD1-A71B-F7C5656E3E4A}.Release.ActiveCfg = Release|Win32
{544685C3-2A51-4DD1-A71B-F7C5656E3E4A}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

BIN
CS4451/proj5/proj5.suo Normal file

Binary file not shown.

BIN
CS4451/proj5/proj5.tar Normal file

Binary file not shown.

165
CS4451/proj5/proj5.vcproj Normal file
View File

@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="proj5"
ProjectGUID="{544685C3-2A51-4DD1-A71B-F7C5656E3E4A}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/proj5.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/proj5.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/proj5.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\FileReader.cpp">
</File>
<File
RelativePath=".\Input.cpp">
</File>
<File
RelativePath=".\main.cpp">
</File>
<File
RelativePath=".\Renderer.cpp">
</File>
<File
RelativePath=".\Subdivision.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\cwrappers.h">
</File>
<File
RelativePath=".\FileReader.h">
</File>
<File
RelativePath=".\Input.h">
</File>
<File
RelativePath=".\Renderer.h">
</File>
<File
RelativePath=".\structs.h">
</File>
<File
RelativePath=".\Subdivision.h">
</File>
<File
RelativePath=".\utils.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

150
CS4451/proj5/structs.h Normal file
View File

@@ -0,0 +1,150 @@
#ifndef _STRUCTS_H_
#define _STRUCTS_H_
#include <math.h>
#include <iostream>
#include <vector>
#include <assert.h>
typedef struct Vector {
float i;
float j;
float k;
inline float magnitude() {
return sqrt(pow(i,2)+pow(j,2)+pow(k,2));
}
inline static void normalize(Vector* dest, Vector src) {
float m = src.magnitude();
dest->i = src.i / m;
dest->j = src.j / m;
dest->k = src.k / m;
}
} Vector;
typedef struct Point {
float x;
float y;
float z;
std::vector<unsigned int> incidentTriangles;
Point() {
x = y = z = 0;
}
inline void printMe() {
std::cout << "x: " << x << " y: " << y << " z: " << z;
}
inline Point operator- (Point a) {
Point temp;
temp.x = x - a.x;
temp.y = y - a.y;
temp.z = z - a.z;
return temp;
}
inline float magnitude() {
return sqrt(pow(x,2)+pow(y,2)+pow(z,2));
}
inline static void normalize(Point* dest, Point src) {
float m = src.magnitude();
dest->x = src.x / m;
dest->y = src.y / m;
dest->z = src.z / m;
}
inline Point operator+ (Point p) {
Point t;
t.x = x + p.x;
t.y = y + p.y;
t.z = z + p.z;
return t;
}
inline void operator+= (Point p) {
x += p.x;
y += p.y;
z += p.z;
}
inline void operator+= (int i) {
x += i;
y += i;
z += i;
}
inline Point operator* (Point p) {
Point t;
t.x = x * p.x;
t.y = y * p.y;
t.z = z * p.z;
return t;
}
inline Point operator* (float f) {
Point t;
t.x = x * f;
t.y = y * f;
t.z = z * f;
return t;
}
inline Point operator/ (float f) {
Point t;
t.x = x / f;
t.y = y / f;
t.z = z / f;
return t;
}
} Point;
typedef struct Triangle {
Vector normal;
int a1;
int a2;
int a3;
inline bool contains(int a) {
return (a == a1 || a == a2 || a == a3);
}
inline int indexOf(int n1, int n2) {
if ((a1 == n1 || a1 == n2) && (a2 == n1 || a2 == n2)) {
return 3;
} else if ((a2 == n1 || a2 == n2) && (a3 == n1 || a3 == n2)) {
return 1;
} else if ((a3 == n1 || a3 == n2) && (a1 == n1 || a1 == n2)) {
return 2;
} else {
return -1;
}
}
inline bool operator== (Triangle t) {
return (a1 == t.a1) && (a2 == t.a2) && (a3 == t.a3);
}
} Triangle;
typedef struct Adjacency {
int a1;
int a2;
int a3;
inline bool contains(int i) {
if (a1 == i || a2 == i || a3 == i) {
return true;
}
}
inline void push(int i, int in1, int in2) {
if (a1 != in1 && a1 != in2) {
a1 = i;
} else if (a2 != in1 && a2 != in2) {
a2 = i;
} else if (a3 != in1 && a3 != in2) {
a3 = i;
}
#ifdef _DEBUG
else {
assert(NULL != NULL);
}
#endif
}
} Adjacency;
#endif

40
CS4451/proj5/subd.htm Normal file
View File

@@ -0,0 +1,40 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0070)http://www.cc.gatech.edu/classes/AY2005/cs4451a_spring/proj5/subd.html -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2900.2627" name=GENERATOR></HEAD>
<BODY>Here are a few images of models and the results of the Loop and butterfly
subdivision. Note that the Loop subdivision surfaces will generally appear
smooth but may shrink a little bit. The butterfly subdivision will not shrink,
but will be of poorer quality, especially if there are a lot of vertices of low
degree and high degree in the mesh (Butterfly is smooth only for degrees between
4 and 7). Other reasonable input files are the pawn, pig and shark from project
2. <BR><BR>RESULTS FOR <A
href="http://www.cc.gatech.edu/classes/AY2005/cs4451a_spring/proj5/horse200.t">HORSE200</A>:<BR><BR>Original:<BR><IMG
src="subd_files/horse.jpg"><BR><BR>Loop iterated 4 times:<BR><IMG
src="subd_files/horsel4.jpg"><BR><BR>Butterfly iterated 4 times:<BR><IMG
src="subd_files/horseb4.jpg"><BR><BR>
<HR SIZE=10>
RESULTS FOR <A
href="http://www.cc.gatech.edu/classes/AY2005/cs4451a_spring/proj5/rabbit100.t">RABBIT100</A>:<BR><BR>Original:<BR><IMG
src="subd_files/rabbit.jpg"><BR><BR>Loop iterated 4 times:<BR><IMG
src="subd_files/rabbitl4.jpg"><BR><BR>Butterfly iterated 4 times:<BR><IMG
src="subd_files/rabbitb4.jpg"><BR><BR>
<HR SIZE=10>
RESULTS FOR <A
href="http://www.cc.gatech.edu/classes/AY2005/cs4451a_spring/proj5/oct.t">OCTAHEDRON</A>:<BR><BR>Original:<BR><IMG
src="subd_files/oct.jpg"><BR><BR>Loop iterated 4 times:<BR><IMG
src="subd_files/octl4.jpg"><BR><BR>Butterfly iterated 4 times:<BR><IMG
src="subd_files/octb4.jpg"><BR><BR>
<HR SIZE=10>
RESULTS FOR <A
href="http://www.cc.gatech.edu/classes/AY2005/cs4451a_spring/proj5/tt.t">SMALL_TORUS</A><A>:<BR><BR>Original:<BR><IMG
src="subd_files/tt.jpg"><BR><BR>Loop iterated 4 times:<BR><IMG
src="subd_files/ttl4.jpg"><BR><BR>Butterfly iterated 4 times:<BR><IMG
src="subd_files/ttb4.jpg"><BR><BR></A>
<HR SIZE=10>
<A>RESULTS FOR </A><A
href="http://www.cc.gatech.edu/classes/AY2005/cs4451a_spring/proj5/shape.t">SHAPE</A><A>:<BR><BR>Original:<BR><IMG
src="subd_files/shape.jpg"><BR><BR>Loop iterated 2 times:<BR><IMG
src="subd_files/shapel2.jpg"><BR><BR>Butterfly iterated 2 times:<BR><IMG
src="subd_files/shapeb2.jpg"><BR><BR></A></BODY></HTML>

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

30
CS4451/proj5/utils.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef _UTILS_H_
#define _UTILS_H_
#include <GL/glut.h>
#include <math.h>
#include "structs.h"
inline void cross(Vector& dest, Point& a, Point& b) {
dest.i = ( (a.y*b.z) - (a.z*b.y) ); //i
dest.j = ( (a.z*b.x) - (a.x*b.z) ); //j
dest.k = ( (a.x*b.y) - (a.y*b.x) ); //k
}
inline void cross(Point& dest, Point& a, Point& b) {
dest.x = ( (a.y*b.z) - (a.z*b.y) ); //i
dest.y = ( (a.z*b.x) - (a.x*b.z) ); //j
dest.z = ( (a.x*b.y) - (a.y*b.x) ); //k
}
inline GLfloat dot(Vector &a, Vector &b) {
return (a.i*b.i)+(a.j*b.j)+(a.k*b.k);
}
inline GLfloat dot(Point &a, Point &b) {
return (a.x*b.x)+(a.y*b.y)+(a.z*b.z);
}
#endif