Difference between revisions of "Project1F18"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
(Created page with "Homework Project 1 will go on-line by end of day Sept 28. If you want to get ready for it, get the starter code working in Microsoft Visual Studio and familiarize yourself wi...")
 
Line 1: Line 1:
Homework Project 1 will go on-line by end of day Sept 28.
+
==Homework Assignment 1: Rendering Point Clouds==
  
If you want to get ready for it, get the starter code working in Microsoft Visual Studio and familiarize yourself with its components.
+
In this project the goal is to read a number of 3D point positions from a file and render them onto the screen.
 +
 
 +
Besides becoming familiar with the linear algebra involved in rendering 3D scenes, this project will get you familiar with the tools and libraries that will be your friends throughout the quarter. These will include GLFW and GLew, as well as GLm.
 +
 
 +
==1. Getting Your Development Environment Ready (20 Points)==
 +
 
 +
We recommend that you start by getting your development software ready. More information on this is [[BasecodeCSE167F18 | here]].
 +
 
 +
==2. Reading 3D Points from Files (20 Points)==
 +
 
 +
A [http://en.wikipedia.org/wiki/Point_cloud point cloud] is a 3D collection of points, representing a 3D object. These point clouds are often acquired by laser scanning, but can also be acquired with the Microsoft Kinect and special software, or by processing a large number of photographs of an object and using Structure from Motion techniques (see [https://photosynth.net/ Microsoft Photosynth] or [http://www.123dapp.com/catch Autodesk 123D Catc]).
 +
 
 +
In this project we're going to render the points defined in OBJ files. Note that OBJ files are normally used to define polygonal models, but for now we're ignoring that and use the vertex definitions to render points, ignoring all connectivity data. OBJ files are 3D model files which store the shape of an object with a number of vertices, associated vertex normals, and connectivity information to form triangles. [http://en.wikipedia.org/wiki/Wavefront_.obj_file Wikipedia] has excellent information on the OBJ file format. The file format is an ASCII text format, which means that the files can be viewed and edited with a any text editor, such as Notepad.
 +
 
 +
Write a parser for the vertices and normals defined in OBJ files. It should be a simple 'for' loop in which you read each line from the file, for instance with the [http://www.cplusplus.com/reference/cstdio/fscanf/ fscanf] command. Your parser does not need to do any error handling - you can assume that the files do not contain errors. Add the parser to the starter code.
 +
 
 +
Use your parser to load the vertices from the following OBJ files and treat them as point clouds:
 +
 
 +
* [[Media:BunnyF14.zip|Bunny ]]
 +
* [http://www.calit2.net/~jschulze/tmp/DragonF14.zip Dragon]
 +
* [http://www.calit2.net/~jschulze/tmp/BearF14.zip Bear]
 +
 
 +
The files provided in this project only use the following three data types (other OBJ files may support more): v for vertex, vn for vertex normal, f for face.
 +
 
 +
The general format for vertex lines is:
 +
 
 +
v v_x v_y v_z r g b
 +
 
 +
Where v_x, v_y, v_z are the vertex x, y, and z coordinates and are strictly floats.
 +
 
 +
The values r, g, b define the color of the vertex, and are optional (i.e. they will be missing from most files). Like the vertex coordinates, they are strictly floats, and can only take on values between 0.0 and 1.0.
 +
 
 +
All values are delimited by a single whitespace character.
 +
 
 +
The general format for normal is the same as for vertices, minus the color info.
 +
 
 +
In summary:
 +
 
 +
* v: 'vertex': followed by six floating point numbers. The first three are for the vertex position (x,y,z coordinate), the next three are for the vertex color (red, green, blue) ranging from 0 to 1. Example: <br><pre>v 0.145852 0.104651 0.517576 0.2 0.8 0.4</pre>
 +
* vn: 'vertex normal': three floating point numbers, separated by white space. The numbers are for a vector which is used as the normal for a triangle. Example: <br><pre>vn -0.380694 3.839313 4.956321</pre>
 +
<!--
 +
* f: 'face': lists three sets of indices to vertices and normals, which are the three corners of a triangle. Example: <br><pre>f 31514//31514 31465//31465 31464//31464</pre>
 +
-->
 +
Lines starting with a '#' sign are comments and should be ignored.
 +
 
 +
In this homework assignment, you only need to parse for vertices and vertex normals, which are those lines of the file starting with a 'v' and 'vn'.
 +
 
 +
Write your parser so that it goes through the OBJ file, line by line. It should read in the first character of each line and based on it decide how to proceed, i.e., ignore all lines which do not start with a 'v' or 'vn'. The vertex definitions can be read with the [http://www.cplusplus.com/reference/cstdio/fscanf/ fscanf] command. Here is an example:
 +
 
 +
<pre>
 +
FILE* fp;    // file pointer
 +
float x,y,z;  // vertex coordinates
 +
float r,g,b;  // vertex color
 +
int c1,c2;    // characters read from file
 +
 
 +
fp = fopen("bunny.obj","rb");  // make the file name configurable so you can load other files
 +
if (fp==NULL) { cerr << "error loading file" << endl; exit(-1); }  // just in case the file can't be found or is corrupt
 +
 
 +
c1 = fgetc(fp);
 +
c2 = fgetc(fp);
 +
if (c1=='v') && (c2==' ')
 +
{
 +
  fscanf(fp, "%f %f %f %f %f %f", &x, &y, &z, &r, &g, &b);
 +
}
 +
 
 +
// read normal data accordingly
 +
 
 +
fclose(fp);  // make sure you don't forget to close the file when done
 +
</pre>
 +
 
 +
Load all three models in at startup.
 +
 
 +
'''Grading:'''
 +
* -5 for any errors in the parser
 +
 
 +
==Resizing the Model to Fit the Screen (25 Points)==
 +
 
 +
TBD
 +
 
 +
==Rendering the Points with OpenGL (25 Points)==
 +
 
 +
To display the vertices you loaded, use the provided starter code. It contains hooks for rendering points with OpenGL, which are ready for you to use. Change the Display callback and replace the call to render the cube to render the OBJ object - don't call cube.draw() but call the respective OBJ object's draw command.
 +
 
 +
Use function keys F1, F2 and F3 to display the three models, respectively. Only one 3D model should be displayed at a time. (4 points per model)
 +
 
 +
Just like the cube spins during display, make your OBJ models spin as well.
 +
 
 +
The points should be colored with normal coloring: use the vertex normals you parsed from the file, and map them into the range of zero to one. The x coordinate of the normal should map to red, y to green, z to blue. (4 points)
 +
 
 +
Use the glPointSize() command to allow the user to adjust the size of the points with the 'p' and 'P' keys (for smaller and larger points, respectively). (4 points)
 +
 
 +
'''Grading:'''
 +
* -3 if data sets load every time a function key is pressed.
 +
 
 +
==Extra Credit (10 Points)==
 +
 
 +
TBD
 +
<!--
 +
For extra credit, you can address one or both deficiencies of the algorithm so far, each will get you 5 points of extra credit.
 +
 
 +
1) Currently, all points are the same size in image space. However, in reality if the points were little squares, they would get rendered as smaller squares the farther they are from the viewer. Adjust the point size accordingly. Note that you will need to calculate the range of depths the points are mapped into before you render the model.
 +
 
 +
-->

Revision as of 10:09, 29 September 2018

Contents

Homework Assignment 1: Rendering Point Clouds

In this project the goal is to read a number of 3D point positions from a file and render them onto the screen.

Besides becoming familiar with the linear algebra involved in rendering 3D scenes, this project will get you familiar with the tools and libraries that will be your friends throughout the quarter. These will include GLFW and GLew, as well as GLm.

1. Getting Your Development Environment Ready (20 Points)

We recommend that you start by getting your development software ready. More information on this is here.

2. Reading 3D Points from Files (20 Points)

A point cloud is a 3D collection of points, representing a 3D object. These point clouds are often acquired by laser scanning, but can also be acquired with the Microsoft Kinect and special software, or by processing a large number of photographs of an object and using Structure from Motion techniques (see Microsoft Photosynth or Autodesk 123D Catc).

In this project we're going to render the points defined in OBJ files. Note that OBJ files are normally used to define polygonal models, but for now we're ignoring that and use the vertex definitions to render points, ignoring all connectivity data. OBJ files are 3D model files which store the shape of an object with a number of vertices, associated vertex normals, and connectivity information to form triangles. Wikipedia has excellent information on the OBJ file format. The file format is an ASCII text format, which means that the files can be viewed and edited with a any text editor, such as Notepad.

Write a parser for the vertices and normals defined in OBJ files. It should be a simple 'for' loop in which you read each line from the file, for instance with the fscanf command. Your parser does not need to do any error handling - you can assume that the files do not contain errors. Add the parser to the starter code.

Use your parser to load the vertices from the following OBJ files and treat them as point clouds:

The files provided in this project only use the following three data types (other OBJ files may support more): v for vertex, vn for vertex normal, f for face.

The general format for vertex lines is:

v v_x v_y v_z r g b

Where v_x, v_y, v_z are the vertex x, y, and z coordinates and are strictly floats.

The values r, g, b define the color of the vertex, and are optional (i.e. they will be missing from most files). Like the vertex coordinates, they are strictly floats, and can only take on values between 0.0 and 1.0.

All values are delimited by a single whitespace character.

The general format for normal is the same as for vertices, minus the color info.

In summary:

  • v: 'vertex': followed by six floating point numbers. The first three are for the vertex position (x,y,z coordinate), the next three are for the vertex color (red, green, blue) ranging from 0 to 1. Example:
    v 0.145852 0.104651 0.517576 0.2 0.8 0.4
  • vn: 'vertex normal': three floating point numbers, separated by white space. The numbers are for a vector which is used as the normal for a triangle. Example:
    vn -0.380694 3.839313 4.956321

Lines starting with a '#' sign are comments and should be ignored.

In this homework assignment, you only need to parse for vertices and vertex normals, which are those lines of the file starting with a 'v' and 'vn'.

Write your parser so that it goes through the OBJ file, line by line. It should read in the first character of each line and based on it decide how to proceed, i.e., ignore all lines which do not start with a 'v' or 'vn'. The vertex definitions can be read with the fscanf command. Here is an example:

FILE* fp;     // file pointer
float x,y,z;  // vertex coordinates
float r,g,b;  // vertex color
int c1,c2;    // characters read from file

fp = fopen("bunny.obj","rb");  // make the file name configurable so you can load other files
if (fp==NULL) { cerr << "error loading file" << endl; exit(-1); }  // just in case the file can't be found or is corrupt

c1 = fgetc(fp);
c2 = fgetc(fp);
if (c1=='v') && (c2==' ')
{
  fscanf(fp, "%f %f %f %f %f %f", &x, &y, &z, &r, &g, &b);
}

// read normal data accordingly

fclose(fp);   // make sure you don't forget to close the file when done

Load all three models in at startup.

Grading:

  • -5 for any errors in the parser

Resizing the Model to Fit the Screen (25 Points)

TBD

Rendering the Points with OpenGL (25 Points)

To display the vertices you loaded, use the provided starter code. It contains hooks for rendering points with OpenGL, which are ready for you to use. Change the Display callback and replace the call to render the cube to render the OBJ object - don't call cube.draw() but call the respective OBJ object's draw command.

Use function keys F1, F2 and F3 to display the three models, respectively. Only one 3D model should be displayed at a time. (4 points per model)

Just like the cube spins during display, make your OBJ models spin as well.

The points should be colored with normal coloring: use the vertex normals you parsed from the file, and map them into the range of zero to one. The x coordinate of the normal should map to red, y to green, z to blue. (4 points)

Use the glPointSize() command to allow the user to adjust the size of the points with the 'p' and 'P' keys (for smaller and larger points, respectively). (4 points)

Grading:

  • -3 if data sets load every time a function key is pressed.

Extra Credit (10 Points)

TBD