Exemple #1
0
void loadScene(std::string file) {
    
    //store variables and set stuff at the end
    int width, height;
    std::string fname = "output.bmp";
    
    int curvecount;
    vector<vect*> curves;
    
    std::ifstream inpfile(file.c_str());
    if(!inpfile.is_open()) {
        std::cout << "Unable to open file" << std::endl;
    } else {
        std::string line;
        //MatrixStack mst;
        
        while(inpfile.good()) {
            std::vector<std::string> splitline;
            std::string buf;
            
            std::getline(inpfile,line);
            std::stringstream ss(line);
            
            while (ss >> buf) {
                splitline.push_back(buf);
            }
            //Ignore blank lines
            if(splitline.size() == 0) {
                continue;
            }
            
            //Ignore comments
            if(splitline[0][0] == '#') {
                continue;
            }
            else if(splitline.size() == 1) {
                curvecount = atoi(splitline[0].c_str());
            }
            //Vertices
            else if(splitline.size() == 12) {
                vect p1 = vect(atof(splitline[0].c_str()), atof(splitline[1].c_str()), atof(splitline[2].c_str()), 1);
                vect p2 = vect(atof(splitline[3].c_str()), atof(splitline[4].c_str()), atof(splitline[5].c_str()), 1);
                vect p3 = vect(atof(splitline[6].c_str()), atof(splitline[7].c_str()), atof(splitline[8].c_str()), 1);
                vect p4 = vect(atof(splitline[9].c_str()), atof(splitline[10].c_str()), atof(splitline[11].c_str()), 1);
                vect curve[4] = {p1, p2, p3, p4};
                curves.push_back(curve);
            }
            else {
                std::cerr << "Unknown command: " << splitline[0] << std::endl;
            }
        }
        
        inpfile.close();
    }
    
}
Exemple #2
0
void loadOBJ(vector<Triangle*>& triangles, vector<Vertex*>& vertices, \
    vector<Edge *>& edges, \
    string fname)
{
  vector<vec3> verts;
  vector<vec3> normals;
  vector<vec3> rawFaces;
  vector<vec3> rawFacesNormals;

  ifstream inpfile(fname.c_str());
  if (!inpfile.is_open()) {
    cout << "Unable to open file" << endl;
  } else {
    string line;
    while(!getline(inpfile,line).eof()) {
    //while(inpfile.good()) {
      vector<string> splitline;
      string buf;

     
      stringstream ss(line);
      while (ss >> buf) {
        splitline.push_back(buf);
      }

      //Ignore blank lines
      if(splitline.size() == 0) {
        continue;
      }
      //Vertex
      if (splitline[0][0] == 'v') {
        //Vertex normal
        if (splitline[0].length() > 1 && splitline[0][1] == 'n'){
          normals.push_back(vec3(atof(splitline[1].c_str()),
                atof(splitline[2].c_str()),atof(splitline[3].c_str())));
        } else {
          verts.push_back(vec3(atof(splitline[1].c_str()),
                atof(splitline[2].c_str()),atof(splitline[3].c_str())));
        }
      } 
      //Face
      else if (splitline[0][0] == 'f') {
        int v1, v2, v3;
        int n1, n2, n3;
        //find "type"
        int numSlash = 0;
        for (int i=0; i<splitline[1].length(); i++) {
          if(splitline[1][i] == '/')
            numSlash++;
        }
        //cout << numSlash << endl;
        if (numSlash == 0) {
          sscanf(line.c_str(), "f %d %d %d", &v1, &v2, &v3);
          rawFaces.push_back(vec3(v1-1,v2-1,v3-1));
        } else if (numSlash == 1) {
          sscanf(line.c_str(), "f %d/%*d %d/%*d %d/%*d", &v1, &v2, &v3);
          rawFaces.push_back(vec3(v1-1,v2-1,v3-1));
        } else if (numSlash == 2) {
          sscanf(line.c_str(), "f %d//%d %d//%d %d//%d", &v1, &n1, &v2, &n2, &v3, &n3);
          rawFaces.push_back(vec3(v1-1,v2-1,v3-1));
          rawFacesNormals.push_back(vec3(n1-1,n2-1,n3-1));
        } else {
          cout << "Too many slashses in f" << endl;
        }

      }
    }
    inpfile.close();

    vector<Vertex *> newVertices;
    vector<Triangle *> newTriangles;

    for(vector<vec3>::iterator v = verts.begin(); v != verts.end(); ++ v) {
      vec3 worldPos = *v;
      //do transformations here for lack of better place to do them
      worldPos = 0.3 * worldPos;
      worldPos -= vec3(0,0.3,0);

      Vertex * newVert = new Vertex(worldPos, vec2(worldPos[0], worldPos[1]));


      newVert->pinned = true;
      newVert->mass = 1;
      newVertices.push_back(newVert);
    }
    for(int i=0; i<rawFaces.size(); i++) {
      vec3 rawFace = rawFaces[i];
      Triangle * newTri = new Triangle(newVertices[floor(rawFace[0])], 
          newVertices[rawFace[1]], newVertices[rawFace[2]]);
      newTri->simulate = false;
      if(i < rawFacesNormals.size()) {
        vec3 rawFacesNormal = rawFacesNormals[i];
        newTri->vertices[0]->norm = normals[rawFacesNormal[0]];
        newTri->vertices[1]->norm = normals[rawFacesNormal[1]];
        newTri->vertices[2]->norm = normals[rawFacesNormal[2]];
      }
      newTriangles.push_back(newTri);
    }
    vertices.resize(vertices.size() + newVertices.size());
    copy(newVertices.begin(), newVertices.end(), vertices.rbegin());

    triangles.resize(triangles.size() + newTriangles.size());
    copy(newTriangles.begin(), newTriangles.end(), triangles.rbegin());
  }

}
Exemple #3
0
// AVS
// completelly rewrited to support new conceptions
int TMapLoader::Load(const char * filename, const char * szActiveEmul) {
	char buf[256];
	int bufLen;
	
	ifstream inpfile(filename);
	KeyTrans.DeleteAllDefs();
	Charmap.init();
	
	// it is an array for store [...] ... [end ...] parts from file
	stringArray SA(0,0,sizeof(string));
	int AllOk = 0;
	
	while ( inpfile ) {
		
		getline(inpfile, buf, 255);
		bufLen = strlen(buf);
		if ( !bufLen ) continue;
		
		if ( buf[0] == '[' && buf[bufLen-1] == ']' ) {
			// is a part splitter [...]
			string temps(buf);
			
			if (!normalizeSplitter(temps)) {
				printm(0, FALSE, MSG_KEYUNEXPLINE, temps.c_str());
				AllOk = 0;
				break;
			};
			// if a comment
			if ( stricmp(temps.c_str(),"[comment]") == 0 ) {
#ifdef KEYDEBUG
				printit(temps.c_str());
#endif
				if ( !getLongComment(inpfile, buf, sizeof(buf)) ) {
					printm(0, FALSE, MSG_KEYUNEXPEOF);
					break;
				};
#ifdef KEYDEBUG
				printit("\r          \r");
#endif
				continue;
			};
			
			
			string back = temps;
			// prepare line for make it as [end ...]
			// and check it
			if ( strnicmp(back.c_str(), "[global]", 8) == 0 ) {} // do nothing
			else if ( strnicmp(back.c_str(), "[keymap", 7) == 0 ) {
				// DJGPP also uses erase rather than remove (Paul Brannan 6/23/98)
#ifndef __BORLANDC__
				back.erase(7);
#else
				back.remove(7);
#endif
				back += "]";
			}
			else if ( strnicmp(back.c_str(), "[charmap", 8) == 0 ) {
				// Paul Brannan 6/23/98
#ifndef __BORLANDC__
				back.erase(8);
#else
				back.remove(8);
#endif
				back += "]";
			}
			else if ( strnicmp(back.c_str(), "[config", 7) == 0 ) {
				// Paul Brannan 6/23/98
#ifndef __BORLANDC__
				back.erase(7);
#else
				back.remove(7);
#endif
				back += "]";
			}
			else {
				//        cerr << "Unexpected token " << back << endl;
				printm(0, FALSE, MSG_KEYUNEXPTOK, back.c_str());
				break;
			};
			
			back.insert(1,"END "); // now it looks like [END ...]
#ifdef KEYDEBUG
			printit(temps.c_str());
#endif
			
			int ok = 0;
			// fetch it to temps
			while ( 1 ) {
				getline(inpfile, buf, sizeof(buf));
				bufLen = strlen(buf);
				if ( !bufLen ) break;
				if ( buf[0] == '[' && buf[bufLen-1] == ']' ) {
					string t(buf);
					if ( !normalizeSplitter(t) ) break;
					
					if ( stricmp(t.c_str(),back.c_str()) == 0 ) {
						ok = 1;
						break;
					};
					
					// AVS 31.12.97 fix [comment] block inside another block
					if ( stricmp(t.c_str(),"[comment]") == 0 &&
						getLongComment(inpfile, buf, sizeof(buf)) ) continue;
					
					break;
				};
				temps += "\n";
				temps += buf;
			};
			if ( !ok ) {
				//         cerr << "Unexpected end of file or token" << endl;
				printm(0, FALSE, MSG_KEYUNEXP);
				AllOk = 0;
				break;
			};
#ifdef KEYDEBUG
			printit("\r                                                                      \r");
#endif
			AllOk = SA.Add(temps);;
			if ( !AllOk ) break;
		} else {
			//       cerr << "Unexpected line '" << buf << "'\n";
			printm(0, FALSE, MSG_KEYUNEXPLINE, buf);
			AllOk = 0;
			break;
		};
	};
	
	inpfile.close();
	
	if ( !AllOk ) return 0;
	
	// now all file are in SA, comments are stripped
	
	int i = LookForPart(SA, "global", "");
	if ( i == INT_MAX ) {
		//     cerr << "No [GLOBAL] definition!" << endl;
		printm(0, FALSE, MSG_KEYNOGLOBAL);
		return 0;
	};
	if ( !LoadGlobal(SA[i]) ) {
		return 0;
	};
	
	// look for need configuration
	i = LookForPart(SA, "config", szActiveEmul);
	if ( i == INT_MAX ) {
		//     cerr << "No [CONFIG " << szActiveEmul << "]\n";
		printm(0, FALSE, MSG_KEYNOCONFIG, szActiveEmul);
		return 0;
	};
	//  cerr << "use configuration: " << szActiveEmul << endl;
	printm(0, FALSE, MSG_KEYUSECONFIG, szActiveEmul);
	BOOL hadKeys = FALSE;
	
	string config = SA[i];
	// parse it
	while ( config.length() ) {
		buf[0] = 0;
		getline(config,buf,sizeof(buf));
		bufLen = strlen(buf);
		if ( !bufLen || (buf[0] == '[' && buf[bufLen-1] == ']') ) continue;
		if ( strnicmp(buf,"keymap",6) == 0 ) {
			string orig(buf);
			printit("\t"); printit(buf); printit("\n");
			char * mapdef = strtok(buf,":");
			char * switchKey = strtok(NULL,"\n");
			
			if ( !KeyTrans.mapArray.IsEmpty() && switchKey == NULL ) {
				//            cerr << "no switch Key for '" << mapdef
				//                 << "'" << endl;
				printm(0, FALSE, MSG_KEYNOSWKEY, mapdef);
				break;
			};
			if ( KeyTrans.mapArray.IsEmpty() ) {
				if ( switchKey != NULL ) { // create default keymap
					//               cerr << "You cannot define switch key for default keymap -> ignored"
					//                    << endl;
					printm(0, FALSE, MSG_KEYCANNOTDEF);
				};
				TKeyDef empty;
				KeyTrans.mapArray.Add(KeyMap(string(mapdef)));
				KeyTrans.switchMap(empty); // set it as current keymap
				KeyTrans.mainKeyMap = KeyTrans.currentKeyMap;
			}
			else {
				string keydef(switchKey);
				keydef += " !*!*!*"; // just for check
				WORD vk_code;
				DWORD control;
				switchKey = ParseKeyDef(keydef.c_str(),vk_code,control);
				if ( switchKey != NULL ) {
					TKeyDef swi(NULL,control,vk_code);
					if ( KeyTrans.switchMap(swi) > 0 ) {
						//                  cerr << "Duplicate switching key\n";
						printm(0, FALSE, MSG_KEYDUPSWKEY);
						break;
					};
					KeyTrans.mapArray.Add(KeyMap(swi, orig));
					KeyTrans.switchMap(swi); // set it as current keymap
				}
			};
			mapdef+=7; // 'keymap '
			// now load defined keymaps to current
			while ((mapdef != NULL)&&
				(mapdef = strtok(mapdef,TOKEN_DELIMITERS)) != NULL ) {
				i = LookForPart(SA,"keymap",mapdef);
				if ( i == INT_MAX ) {
					//               cerr << "Unknown KEYMAP " << mapdef << endl;
					printm(0, FALSE, MSG_KEYUNKNOWNMAP, mapdef);
				} else {
					mapdef = strtok(NULL,"\n"); // strtok is used in LoadKeyMap
					// so - save pointer!
					hadKeys = LoadKeyMap(SA[i]); // load it
				};
			};
			
		}
		else if ( strnicmp(buf,"charmap",7) == 0 ) {
			printit("\t"); printit(buf); printit("\n");
			char * mapdef = buf + 8;// 'charmap '
			int SuccesLoaded = 0;
			// now load defined charmaps to current
			while ((mapdef != NULL)&&
				(mapdef = strtok(mapdef,TOKEN_DELIMITERS)) != NULL ) {
				i = LookForPart(SA,"charmap",mapdef);
				if ( i == INT_MAX ) {
					//               cerr << "Unknown KEYMAP " << mapdef << endl;
					printm(0, FALSE, MSG_KEYUNKNOWNMAP, mapdef);
				} else {
					mapdef = strtok(NULL,"\n"); // strtok is used in LoadKeyMap
					// so - save pointer!
					if (LoadCharMap(SA[i])) // load it
						SuccesLoaded++;
				};
			};
			if (!SuccesLoaded) {
				//            cerr << "No charmaps loaded\n";
				printm(0, FALSE, MSG_KEYNOCHARMAPS);
				Charmap.init();
			};
			/*         strtok(buf," ");
			
			  char* name = strtok(NULL," ");
			  if ( name == NULL ) {
			  cerr << "No name for CHARMAP" << endl;
			  } else {
			  i = LookForPart(SA,"charmap", name);
			  if ( i == INT_MAX ) {
			  cerr << "Unknown CHARMAP " << name << endl;
			  } else {
			  LoadCharMap(SA[i]);
			  };
			  };
			*/
		}
		else {
			//        cerr << "unexpected token in " << szActiveEmul << endl;
			printm(0, FALSE, MSG_KEYUNEXPTOKIN, szActiveEmul);
		}
	}

	if ( hadKeys) {
		TKeyDef empty;
		KeyTrans.switchMap(empty); // switch to default
		KeyTrans.mainKeyMap = KeyTrans.currentKeyMap; // save it's number
		//     cerr << "There are " << (KeyTrans.mapArray.GetItemsInContainer()) << " maps\n";
		char s[12]; // good enough for a long int (32-bit)
		itoa(KeyTrans.mapArray.GetItemsInContainer(), s, 10);
		printm(0, FALSE, MSG_KEYNUMMAPS, s);
		return 1;
	};
	return 0;
}
int main( int argc, const char* argv[])
{
	if (argc <= 1 || std::strcmp( argv[1], "-h") == 0 || std::strcmp( argv[1], "--help") == 0)
	{
		printUsage( argc, argv);
		return 0;
	}
	else if (argc < 5)
	{
		std::cerr << "ERROR too few parameters" << std::endl;
		printUsage( argc, argv);
		return 1;
	}
	else if (argc > 5)
	{
		std::cerr << "ERROR too many parameters" << std::endl;
		printUsage( argc, argv);
		return 1;
	}
	try
	{
		g_errorhnd = strus::createErrorBuffer_standard( 0, 2);
		if (!g_errorhnd)
		{
			throw std::runtime_error("failed to create error buffer object");
		}
		std::string inpfile( argv[1]);
		std::string tagfile( argv[2]);
		std::string outfile( argv[3]);
		std::string expfile( argv[4]);

		std::auto_ptr<strus::SegmenterInterface> segmenter( strus::createSegmenter_textwolf( g_errorhnd));
		if (!segmenter.get()) throw std::runtime_error("failed to create segmenter");
		std::auto_ptr<strus::SegmenterInstanceInterface> segmenterInstance( segmenter->createInstance());
		if (!segmenterInstance.get()) throw std::runtime_error("failed to create segmenter instance");

		std::string tagsrc;
		unsigned int ec;
		ec = strus::readFile( tagfile, tagsrc);
		if (ec) throw std::runtime_error( std::string("error reading markup file ") + tagfile + ": " + ::strerror(ec));
		std::vector<MarkupDescription> markups = parseMarkupDescriptions( tagsrc);

		std::string inpsrc;
		ec = strus::readFile( inpfile, inpsrc);
		if (ec) throw std::runtime_error( std::string("error reading markup file ") + inpfile + ": " + ::strerror(ec));
		std::auto_ptr<strus::DocumentClassDetectorInterface> detector( strus::createDetector_std( g_errorhnd));
		if (!detector.get()) throw std::runtime_error("failed to create document class detector");
		strus::analyzer::DocumentClass dclass;
		if (!detector->detect( dclass, inpsrc.c_str(), inpsrc.size())) throw std::runtime_error("failed to detect document class of input source");

		std::ostringstream outstr;
		std::auto_ptr<strus::SegmenterMarkupContextInterface> segmenterMarkupContext( segmenterInstance->createMarkupContext( dclass, inpsrc));
		if (!segmenterMarkupContext.get()) throw std::runtime_error("failed to create markup segmenter context");
		strus::SegmenterPosition segpos = 0;
		const char* segment;
		std::size_t segmentsize;
		outstr << "Input document:" << std::endl;
		while (segmenterMarkupContext->getNext( segpos, segment, segmentsize))
		{
			outstr << segpos << ": " << segmenterMarkupContext->tagName( segpos) << " " << segmenterMarkupContext->tagLevel( segpos) << std::endl;
		}
		std::vector<MarkupDescription>::const_iterator mi = markups.begin(), me = markups.end();
		for (; mi != me; ++mi)
		{
#ifdef STRUS_LOWLEVEL_DEBUG
			std::cout << "MARKUP " << mi->position << ": " << mi->type << " " << mi->name << "'" << mi->value << "'" << std::endl;
#endif
			if (mi->type == '>')
			{
				segmenterMarkupContext->putOpenTag( mi->position, mi->offset, mi->name);
			}
			else if (mi->type == '<')
			{
				segmenterMarkupContext->putCloseTag( mi->position, mi->offset, mi->name);
			}
			else if (mi->type == '@')
			{
				segmenterMarkupContext->putAttribute( mi->position, mi->offset, mi->name, mi->value);
			}
			else
			{
				throw std::runtime_error("unknown type in markup description");
			}
		}
		outstr << std::endl << "Output document:" << std::endl;
		outstr << segmenterMarkupContext->getContent() << std::endl;

		if (g_errorhnd->hasError())
		{
			throw std::runtime_error( g_errorhnd->fetchError());
		}
		std::cout << outstr.str();

		ec = strus::writeFile( outfile, outstr.str());
		if (ec) throw std::runtime_error( std::string("error writing output file ") + outfile + ": " + ::strerror(ec));

		std::string expsrc;
		ec = strus::readFile( expfile, expsrc);
		if (ec) throw std::runtime_error( std::string("error reading expected file ") + expfile + ": " + ::strerror(ec));

		if (outstr.str() != expsrc)
		{
			throw std::runtime_error("output not as expected");
		}
		std::cerr << "OK" << std::endl;

		delete g_errorhnd;
		return 0;
	}
	catch (const std::bad_alloc&)
	{
		std::ostringstream msg;
		if (g_errorhnd->hasError())
		{
			msg << "(" << g_errorhnd->fetchError() << ")";
		}
		std::cerr << "ERROR memory allocation error" << msg.str() << std::endl;
	}
	catch (const std::runtime_error& e)
	{
		std::ostringstream msg;
		if (g_errorhnd->hasError())
		{
			msg << "(" << g_errorhnd->fetchError() << ")";
		}
		std::cerr << "ERROR " << e.what() << msg.str() << std::endl;
	}
	catch (const std::exception& e)
	{
		std::ostringstream msg;
		if (g_errorhnd->hasError())
		{
			msg << "(" << g_errorhnd->fetchError() << ")";
		}
		std::cerr << "EXCEPTION " << e.what() << msg.str() << std::endl;
	}
	if (g_errorhnd)
	{
		delete g_errorhnd;
	}
	return -1;
}
Exemple #5
0
int main(int argc, char *argv[]) {
  // Start stopwatch
  double start = clock();
  
  // Parsing command line for input file name:
  std::string file = std::string(argv[1]);
  
  // Initialize/Declare everything!
  float windowW = 0;
  float windowH = 0;
  unsigned int maxDepth = 0;
  Camera c;
  unsigned int shapeNum = 0;
  BRDF brdf;
  float a1 = 1.0f;
  float a2 = 0.0f;
  float a3 = 0.0f;

  // Initialize Containers
  std::vector< std::vector<float> > vertices;
  std::vector< std::vector<float> > trinormvertices;
  std::vector< std::vector<float> > trinormnormals; 
  std::vector<Shape *> shapes0;
  std::vector<Shape> shapes1;
  std::vector<Sphere> spheres1;
  std::vector<Triangle> triangles1;
  std::vector<TriNormal> trinormals1;
  std::vector<DirectionalLight> DLs1;
  std::vector<PointLight> PLs1;
  std::vector<DirectionalLight *> DLs0;
  std::vector<PointLight *> PLs0;

  //stack of 4x4 matrix transformations
  std::stack<mat4> transforms; //transf
  //push the idendity 4x4 matrix
  transforms.push(identity3D()); //transf






  
  std::string fname = "output.bmp";

  std::ifstream inpfile(file.c_str());
  if(!inpfile.is_open()) {
    std::cout << "Unable to open file" << std::endl;
  } else {
    std::string line;
    // MatrixStack mst;

    while(inpfile.good()) {
      std::vector<std::string> splitline;
      std::string buf;

      std::getline(inpfile,line);
      std::stringstream ss(line);

      while (ss >> buf) {
        splitline.push_back(buf);
      }
      // Ignore blank lines
      if(splitline.size() == 0) {
        continue;
      }

      // Ignore comments
      if(splitline[0][0] == '#') {
        continue;
      }

      // Valid commands:
      // size width height
      //  must be first command of file, controls image size
      else if(!splitline[0].compare("size")) {
        windowW = atoi(splitline[1].c_str());
	c.w = windowW;
        c.h = windowH = atoi(splitline[2].c_str());
      }
      // maxdepth depth
      //  max # of bounces for ray (default 5)
      else if(!splitline[0].compare("maxdepth")) {
        maxDepth = atoi(splitline[1].c_str());
      }
      // output filename
      //  output file to write image to 
      else if(!splitline[0].compare("output")) {
        fname = splitline[1];
      }

      // camera lookfromx lookfromy lookfromz lookatx lookaty lookatz upx upy upz fov
      //  specifies the camera in the standard way, as in homework 2.
      else if (!splitline[0].compare("camera")) {
        c.lookFrom.at(0) = atof(splitline[1].c_str());
      	c.lookFrom.at(1) = atof(splitline[2].c_str());
      	c.lookFrom.at(2) = atof(splitline[3].c_str());
      	c.lookAt.at(0) = atof(splitline[4].c_str());
      	c.lookAt.at(1) = atof(splitline[5].c_str());
      	c.lookAt.at(2) = atof(splitline[6].c_str());
              c.upDir.at(0) = atof(splitline[7].c_str());
      	c.upDir.at(1) = atof(splitline[8].c_str());
      	c.upDir.at(2) = atof(splitline[9].c_str());
      	c.fov = atof(splitline[10].c_str());
      }

      // sphere x y z radius
      //  Defines a sphere with a given position and radius.
      else if(!splitline[0].compare("sphere")) {
      	Shape shape(shapeNum);
      	Sphere s(atof(splitline[1].c_str()),
            		 atof(splitline[2].c_str()),
            		 atof(splitline[3].c_str()),
            		 atof(splitline[4].c_str()),
            		 brdf, shapeNum++, transforms.top());
      	spheres1.push_back(s);
      	shape.brdf = brdf;
      	shapes1.push_back(shape);
        //   STORE CURRENT TOP OF MATRIX STACK
      }

      // Ignore these, unused
      else if(!splitline[0].compare("maxverts")) {
        continue;
      }
      else if(!splitline[0].compare("maxvertsnorms")) {
        continue;
      }
      
      //vertex x y z
      //  Defines a vertex at the given location.
      //  The vertex is put into a pile, starting to be numbered at 0.
      else if(!splitline[0].compare("vertex")) {
      	std::vector<float> p(3, 0.0f);
      	p.at(0) = atof(splitline[1].c_str());
      	p.at(1) = atof(splitline[2].c_str());
      	p.at(2) = atof(splitline[3].c_str());
      	vertices.push_back(p);
	
        // Create a new vertex with these 3 values, store in some array
      }
      //vertexnormal x y z nx ny nz
      //  Similar to the above, but define a surface normal with each vertex.
      //  The vertex and vertexnormal set of vertices are completely independent
      //  (as are maxverts and maxvertnorms).
      else if(!splitline[0].compare("vertexnormal")) {
      	std::vector<float> p(6, 0.0f);
      	std::vector<float> n(6, 0.0f);
      	p.at(0) = atof(splitline[1].c_str());
      	p.at(1) = atof(splitline[2].c_str());
      	p.at(2) = atof(splitline[3].c_str());
      	n.at(3) = atof(splitline[4].c_str());
      	n.at(4) = atof(splitline[5].c_str());
      	n.at(5) = atof(splitline[6].c_str());
      	trinormvertices.push_back(p);
      	trinormnormals.push_back(n);
      }
      //tri v1 v2 v3
      //  Create a triangle out of the vertices involved (which have previously 
      //  been specified with the vertex command). The vertices are assumed to 
      //  be specified in counter-clockwise order. Your code should internally 
      //  compute a face normal for this triangle.
      else if(!splitline[0].compare("tri")) {
      	Shape shape(shapeNum);
      	// std::vector<float> *v1 = &vertices.at(atoi(splitline[1].c_str()));
      	// std::vector<float> *v2 = &vertices.at(atoi(splitline[2].c_str()));
      	// std::vector<float> *v3 = &vertices.at(atoi(splitline[3].c_str()));

        //original code:
        //std::vector<float> *v1 = &vertices.at(atoi(splitline[1].c_str()));
        //std::vector<float> *v2 = &vertices.at(atoi(splitline[2].c_str()));
        //std::vector<float> *v3 = &vertices.at(atoi(splitline[3].c_str()));

        //casting each of the three 3D vertice vectors into 4D vectors:
        std::vector<float> *v1 = &vertices.at(atoi(splitline[1].c_str()));
        std::vector<float> *v2 = &vertices.at(atoi(splitline[2].c_str()));
        std::vector<float> *v3 = &vertices.at(atoi(splitline[3].c_str()));

        //new component is set by default to 1.0
        //e.g., casted 4D vector of v1 looks like: v1(v1.x, v1.y, v1.z, 1.0)
        //vec4 v1_4D = vec4((*v1)[0], *&(v1->at(1)), v1->at(2));
        vec3 v1_3d = vec3((float) v1->at(0), (float) v1->at(1), (float) v1->at(2));
        vec3 v2_3d = vec3((float) v2->at(0), (float) v2->at(1), (float) v2->at(2));
        vec3 v3_3d = vec3((float) v3->at(0), (float) v3->at(1), (float) v3->at(2));

        vec4 v1_4D = vec4(v1_3d);
        vec4 v2_4D = vec4(v2_3d);
        vec4 v3_4D = vec4(v3_3d);

        //transforming the vertices by multiplying the transformation
        //matrix by the 4D vertex vector:
        //algebra3 notes about casting down from 4D to 3D: When casting to a lower dimension,
        //the vector is homogenized in the lower dimension. E.g., if a 4d {X,Y,Z,W}
        //is cast to 3d, the resulting vector is {X/W, Y/W, Z/W}.
        vec3 v1_3D = vec3(transforms.top() * v1_4D);
        vec3 v2_3D = vec3(transforms.top() * v2_4D);
        vec3 v3_3D = vec3(transforms.top() * v3_4D);

        //converting each vec3 into a vector<float>:
	std::vector<float> *vv1 = new std::vector<float>(3, 0.0f);
	std::vector<float> *vv2 = new std::vector<float>(3, 0.0f);
	std::vector<float> *vv3 = new std::vector<float>(3, 0.0f);
	
        vv1->at(0) = v1_3D[0];
        vv1->at(1) = v1_3D[1];
        vv1->at(2) = v1_3D[2];

        vv2->at(0) = v2_3D[0];
        vv2->at(1) = v2_3D[1];
        vv2->at(2) = v2_3D[2];

        vv3->at(0) = v3_3D[0];
        vv3->at(1) = v3_3D[1];
        vv3->at(2) = v3_3D[2];

	
        
        //Finally, pushing the transformed vertices into the triangles container:
      	Triangle t(vv1, vv2, vv3, brdf, shapeNum++);
      	triangles1.push_back(t);
      	shape.brdf = brdf;
      	shapes1.push_back(shape);
        //   STORE CURRENT TOP OF MATRIX
      }
      //trinormal v1 v2 v3
      //  Same as above but for vertices specified with normals.
      //  In this case, each vertex has an associated normal, 
      //  and when doing shading, you should interpolate the normals 
      //  for intermediate points on the triangle.
      else if(!splitline[0].compare("trinormal")) {
      	Shape shape(shapeNum);
      	std::vector<float> *v1 = &trinormvertices.at(atoi(splitline[1].c_str()));
      	std::vector<float> *v2 = &trinormvertices.at(atoi(splitline[2].c_str()));
      	std::vector<float> *v3 = &trinormvertices.at(atoi(splitline[3].c_str()));
      	std::vector<float> *n1 = &trinormnormals.at(atoi(splitline[1].c_str()));
      	std::vector<float> *n2 = &trinormnormals.at(atoi(splitline[2].c_str()));
      	std::vector<float> *n3 = &trinormnormals.at(atoi(splitline[3].c_str()));
      	TriNormal t(v1, v2, v3, n1, n2, n3, brdf, shapeNum++);
      	trinormals1.push_back(t);
      	shape.brdf = brdf;
      	shapes1.push_back(shape);
        //   STORE CURRENT TOP OF MATRIX STACK
      }

      //Translate x y z
      //  A translation 3-vector
      else if(!splitline[0].compare("translate")) {
        float x, y, z;
        x = atof(splitline[1].c_str());
        y = atof(splitline[2].c_str());
        z = atof(splitline[3].c_str());

        //creating translation vector, v:
        vec3 v = vec3(x, y, z);

        //getting the top (i.e. latest) matrix on the stack, and doing a translation3D transform:
        mat4 vTranslated = translation3D(v);
        mat4 transMat = transforms.top() * vTranslated;

        //updating the top of the matrix stack:
        transforms.pop();
        transforms.push(transMat);
      }
      //rotate x y z angle
      //  Rotate by angle (in degrees) about the given axis as in OpenGL.
      else if(!splitline[0].compare("rotate")) {
        float x, y, z, angle;
        x = atof(splitline[1].c_str());
        y = atof(splitline[2].c_str());
        z = atof(splitline[3].c_str());

        //angle of rotation IN DEGREES
        angle = atof(splitline[4].c_str());

        //creating the axis of rotation vector, axis:
        vec3 axis = vec3(x, y, z);

        //getting the top (i.e.latest) matrix on the stack, and doing a rotation3D transform using DEGREES:
        mat4 rotatedV = rotation3D(axis, angle);
        mat4 rotMat = transforms.top() * rotatedV;

        //updating the top of the matrix stack:
        transforms.pop();
        transforms.push(rotMat);
      }
      //scale x y z
      //  Scale by the corresponding amount in each axis (a non-uniform scaling).
      else if(!splitline[0].compare("scale")) {
        float x, y, z;
        x = atof(splitline[1].c_str());
        y = atof(splitline[2].c_str());
        z = atof(splitline[3].c_str());

        //creating the scaling vector, scaleV
        vec3 scaleV = vec3(x, y, z);

        //getting the top (i.e.latest) matrix on the stack, and doing a scaling3D transform
        mat4 scaledV = scaling3D(scaleV);
        mat4 scaleMat = transforms.top() * scaledV;

        //updating the top of the matrix stack:
        transforms.pop();
        transforms.push(scaleMat);
      }
      //pushTransform
      //  Push the current modeling transform on the stack as in OpenGL. 
      //  You might want to do pushTransform immediately after setting 
      //   the camera to preserve the “identity” transformation.
      else if(!splitline[0].compare("pushTransform")) {
        transforms.push(transforms.top());
      }
      //popTransform
      //  Pop the current transform from the stack as in OpenGL. 
      //  The sequence of popTransform and pushTransform can be used if 
      //  desired before every primitive to reset the transformation 
      //  (assuming the initial camera transformation is on the stack as 
      //  discussed above).
      else if(!splitline[0].compare("popTransform")) {
        if (transforms.size() == 1) {
          std::cout << "No more matrices." << std::endl;
        } else {
          transforms.pop();
        }
      }

      //directional x y z r g b
      //  The direction to the light source, and the color, as in OpenGL.
      else if(!splitline[0].compare("directional")) {
        //original DO NOT DELETE
	      // DLs1.push_back(*new DirectionalLight (atof(splitline[1].c_str()),
					  //    atof(splitline[2].c_str()),
					  //    atof(splitline[3].c_str()),
					  //    atof(splitline[4].c_str()),
					  //    atof(splitline[5].c_str()),
					  //    atof(splitline[6].c_str())));

        vec3 dir = vec3(atof(splitline[1].c_str()), atof(splitline[2].c_str()), atof(splitline[3].c_str()));
        vec3 rgb = vec3(atof(splitline[4].c_str()), atof(splitline[5].c_str()), atof(splitline[6].c_str()));

        //lizzie comment: vec3(const vec4& v, int dropAxis); <- casts v4 to v3
        dir = vec3(transforms.top() * vec4(dir, 0), 3);

        DLs1.push_back(*new DirectionalLight(dir[0], dir[1], dir[2], rgb[0], rgb[1], rgb[2]));

      }
      //point x y z r g b
      //  The location of a point source and the color, as in OpenGL.
      else if(!splitline[0].compare("point")) {
        //original code DO NOT DELETE
	     // PLs1.push_back(*new PointLight (atof(splitline[1].c_str()),
				  //      atof(splitline[2].c_str()),
				  //      atof(splitline[3].c_str()),
				  //      atof(splitline[4].c_str()),
				  //      atof(splitline[5].c_str()),
				  //      atof(splitline[6].c_str()), a1, a2, a3));
        vec3 loc = vec3(atof(splitline[1].c_str()), atof(splitline[2].c_str()), atof(splitline[3].c_str()));
        vec3 rgb = vec3(atof(splitline[4].c_str()), atof(splitline[5].c_str()), atof(splitline[6].c_str()));

        //lizzie comment: vec3(const vec4& v, int dropAxis); <- casts v4 to v3
        loc = vec3(transforms.top() * vec4(loc, 1));

        PLs1.push_back(*new PointLight(loc[0], loc[1], loc[2], rgb[0], rgb[1], rgb[2], a1, a2, a3));
      }
      //attenuation const linear quadratic
      //  Sets the constant, linear and quadratic attenuations 
      //  (default 1,0,0) as in OpenGL.
      else if(!splitline[0].compare("attenuation")) {
        a1 = atof(splitline[1].c_str());
        a2 = atof(splitline[2].c_str());
        a3 = atof(splitline[3].c_str());
      }
      //ambient r g b
      //  The global ambient color to be added for each object 
      //  (default is .2,.2,.2), set in BRDF constructor
      else if(!splitline[0].compare("ambient")) {
        brdf.ka.at(0) = atof(splitline[1].c_str());
        brdf.ka.at(1) = atof(splitline[2].c_str());
        brdf.ka.at(2) = atof(splitline[3].c_str());
      }
      //diffuse r g b
      //  specifies the diffuse color of the surface.
      else if(!splitline[0].compare("diffuse")) {
        brdf.kd.at(0) = atof(splitline[1].c_str());
        brdf.kd.at(1) = atof(splitline[2].c_str());
        brdf.kd.at(2) = atof(splitline[3].c_str());
      }
      //specular r g b 
      //  specifies the specular color of the surface.
      else if(!splitline[0].compare("specular")) {
        brdf.ks.at(0) = atof(splitline[1].c_str());
        brdf.ks.at(1) = atof(splitline[2].c_str());
        brdf.ks.at(2) = atof(splitline[3].c_str());
      }
      //shininess s
      //  specifies the shininess of the surface.
      else if(!splitline[0].compare("shininess")) {
	brdf.s = atof(splitline[1].c_str());
      }
      //emission r g b
      //  gives the emissive color of the surface.
      else if(!splitline[0].compare("emission")) {
        brdf.ke.at(0) = atof(splitline[1].c_str());
        brdf.ke.at(1) = atof(splitline[2].c_str());
        brdf.ke.at(2) = atof(splitline[3].c_str());
      } else {
        std::cerr << "Unknown command: " << splitline[0] << std::endl;
      }
    }

    inpfile.close();
  }

  // BEGIN SHIT
  c.setD();			// set camera d
  c.setULRD();			// set camera ULRD
  Film f(windowW, windowH);
  RayTracer rt(&c);
  Sampler s(&c, &rt, &f);
  // Create iterators for containers
  unsigned int sphCount = 0;
  unsigned int triCount = 0;
  unsigned int tnCount = 0;
  // Set up shapes0, the finalized container
  for (unsigned int i = 0; i < shapes1.size(); i++) {
    if (sphCount < spheres1.size() && spheres1[sphCount].num == i) {
      shapes1[i].sph = &spheres1[sphCount++];
      shapes0.push_back(&shapes1[i]);
    } else if (triCount < triangles1.size() && triangles1[triCount].num == i) {
      shapes1[i].tri = &triangles1[triCount++];
      shapes0.push_back(&shapes1[i]);
    } else if (tnCount < trinormals1.size() && trinormals1[tnCount].num == i) {
      shapes1[i].tn = &trinormals1[tnCount++];
      shapes0.push_back(&shapes1[i]);
    } else {
      printf("container maker not working");
      std::exit(1);
    }
  }
  for (unsigned int i = 0; i < PLs1.size(); i++) {
    PLs0.push_back(&PLs1[i]);
  }
  for (unsigned int i = 0; i < DLs1.size(); i++) {
    DLs0.push_back(&DLs1[i]);
  }
  
  rt.shapes = &shapes0;
  rt.DLs = &DLs0;
  rt.PLs = &PLs0;
  
  // GOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  render(windowW, windowH, maxDepth, fname, &s);
  double total = (clock() - start) / 1000000;
  if (total > 3599) {
    std::cout<<"Time taken: " << total / 3600 << " hours\n";
  } else if (total > 59) {
    std::cout<<"Time taken: " << total/60 << " minutes\n";
  } else {
    std::cout<<"Time taken: " << total << " seconds\n";
  }
}