예제 #1
0
	void test02_roughTransmittance() {
		RoughTransmittance rtr(MicrofacetDistribution::EBeckmann);
		ref<Random> random = new Random();

		for (int i=0; i<50; ++i) {
			Float alpha = std::pow(random->nextFloat(), (Float) 4.0f)*4;
			Float eta = 1 + std::pow(random->nextFloat(), (Float) 4.0f)*3;
			if (alpha < 1e-5)
				alpha = 1e-5f;
			if (eta < 1+1e-5)
				eta = 1+1e-5f;
			//eta = 1/eta;

			Float refD = computeDiffuseTransmittance("beckmann", eta, alpha);
			Float datD = rtr.evalDiffuse(alpha, eta);

			cout << "Testing " << i << "/50" << endl;
			if (std::abs(refD-datD) > 1e-3f) {
				cout << endl;
				cout << "eta = " << eta << endl;
				cout << "alpha = " << alpha << endl;
				cout << "diff=" << datD-refD << " (datD=" << datD << ", ref=" << refD << ")" << endl;
			}
		}

		Float avgErr = 0.0f;
		for (int i=0; i<1000; ++i) {
			Float cosTheta = random->nextFloat();
			Float alpha = std::pow(random->nextFloat(), (Float) 4.0f)*4;
			Float eta = 1 + std::pow(random->nextFloat(), (Float) 4.0f)*3;
			if (cosTheta < 1e-5)
				cosTheta = 1e-5f;
			if (alpha < 1e-5)
				alpha = 1e-5f;
			if (eta < 1+1e-5)
				eta = 1+1e-5f;
			//eta = 1/eta;

			Float ref = computeTransmittance("beckmann", eta, alpha, cosTheta);
			Float dat = rtr.eval(cosTheta, alpha, eta);

			if (i % 20 == 0)
				cout << "Testing " << i << "/1000" << endl;
			if (std::abs(ref-dat) > 1e-3f) {
				cout << endl;
				cout << "eta = " << eta << endl;
				cout << "alpha = " << alpha << endl;
				cout << "cosTheta = " << cosTheta << endl;
				cout << "diff=" << dat-ref << " (dat=" << dat << ", ref=" << ref << ")" << endl;
			}

			avgErr += ref-dat;
		}
		avgErr /= 1000;
		cout << "Avg error = " << avgErr << endl;
	}
int main()
{
#ifdef CGAL_LINKED_WITH_TBB
  typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

  // Regular T3
  typedef CGAL::Triangulation_data_structure_3< 
    CGAL::Regular_triangulation_vertex_base_3<K>, 
    CGAL::Regular_triangulation_cell_base_3<K>, 
    CGAL::Parallel_tag>                                       Tds;

  typedef CGAL::Regular_triangulation_3<K, Tds>               Rt;

  typedef Rt::Bare_point                                      Bare_point;
  typedef Rt::Weighted_point                                  Weighted_point;
  typedef Rt::Vertex_handle                                   Vertex_handle;

  const int NUM_INSERTED_POINTS = 5000;

  CGAL::Random_points_in_cube_3<Bare_point> rnd(1.);

  // Construction from a vector of 1,000,000 points
  std::vector<Weighted_point> V;
  V.reserve(NUM_INSERTED_POINTS);
  for (int i = 0; i != NUM_INSERTED_POINTS; ++i)
    V.push_back(Weighted_point(*rnd++));
  
  // Construct the locking data-structure, using the bounding-box of the points
  Rt::Lock_data_structure locking_ds(
    CGAL::Bbox_3(-1., -1., -1., 1., 1., 1.), 50);
  // Contruct the triangulation in parallel
  std::cerr << "Construction and insertion" << std::endl;
  Rt rtr(V.begin(), V.end(), &locking_ds);

  assert(rtr.is_valid());

  std::cerr << "Remove" << std::endl;
  // Remove the first 1/10 vertices
  std::vector<Vertex_handle> vertices_to_remove;
  Rt::Finite_vertices_iterator vit = rtr.finite_vertices_begin();
  for (int i = 0 ; i < NUM_INSERTED_POINTS/10 ; ++i)
    vertices_to_remove.push_back(vit++);
  // Parallel remove
  rtr.remove(vertices_to_remove.begin(), vertices_to_remove.end());
  
  assert(rtr.is_valid());

#endif //CGAL_LINKED_WITH_TBB

  return 0;
}
예제 #3
0
파일: sched.c 프로젝트: somodi/tp3
void proximo_tarea_reloj() {
	ca (*p)[80] = (ca (*)[80]) VIDEO; // magia
	int current = ((int)rtr()/8)-GDT_TASK1;
	unsigned char colors[5] = {Ctask1,Ctask2,Ctask3,Ctask4,Ctask5};
	if( 0 <= current && current <= 4 ) {
		p[19+current][0].c = reloj[ relojes[current] ];
		p[19+current][0].a = colors[current] | 0x7;
		relojes[current] = ( relojes[current]+1 ) % 4;
	}
	if( tareas[current] == 0 ) {
		p[19+current][0].c = 'x';
		p[19+current][0].a = 0x70;
	}
}
예제 #4
0
파일: sched.c 프로젝트: somodi/tp3
unsigned short proximo_indice() {
//REMOVE
	proximo_tarea_reloj();

	unsigned short current = rtr(); //<- 6 al 11
	int j,next,count=0;

	if(actual==-1) return 0; //GDT_IDLE*8; // si estoy en la idle y la actual es la idle, sigo en la idle.
	
	j = 0;
	for ( next = (actual + 1) % CANT_TAREAS; \
	      tareas[next] == 0 && j < CANT_TAREAS; \
	      next = (next + 1) % CANT_TAREAS) j++;

	for ( j=0 ; j<CANT_TAREAS ; j++ ) if(tareas[j]!=0) count++;

	// next    = proxima tarea a ser ejecutada
	// actual  = tarea anterior (puede que no este siendo ejecutada)
	// current = tarea que fue interrumpida
	// count   = cantidad de tareas validas
	
	if(current==GDT_IDLE*8) { // aca estoy corriendo la tarea idle
	  
		if( count == 0 ) {
			return 0;
		} else {
			actual = next;
			return tareas[next];
		}
		
	} else { // aca estoy corriendo una tarea
	  
		if( count == 0 ) {
			actual=-1;
			return GDT_IDLE*8;
		} else {
			if(current==tareas[next]) {
			  return 0;
			} else {
			  actual = next;
			  return tareas[next];
			}
		}
		
	}
	
	return 0; // la proxima tarea es la misma tarea (Aca no se puede llegar)
//REMOVE END
}
예제 #5
0
	void test04_roughTransmittanceFixedEtaFixedAlpha() {
		ref<Timer> timer = new Timer();
		RoughTransmittance rtr(MicrofacetDistribution::EBeckmann);
		Float eta = 1.5f;
		Float alpha = 0.2f;
		rtr.setEta(eta);
		rtr.setAlpha(alpha);
		cout << "Loading and projecting took " << timer->getMilliseconds() << " ms" << endl;

		ref<Random> random = new Random();

		Float refD = computeDiffuseTransmittance("beckmann", eta, alpha);
		Float datD = rtr.evalDiffuse(alpha, eta);

		if (std::abs(refD-datD) > 1e-3f) {
			cout << endl;
			cout << "alpha = " << alpha << endl;
			cout << "diff=" << datD-refD << " (datD=" << datD << ", ref=" << refD << ")" << endl;
		}

		Float avgErr = 0.0f;
		for (int i=0; i<1000; ++i) {
			Float cosTheta = random->nextFloat();
			if (cosTheta < 1e-5)
				cosTheta = 1e-5f;

			Float ref = computeTransmittance("beckmann", eta, alpha, cosTheta);
			Float dat = rtr.eval(cosTheta, alpha, eta);

			if (i % 20 == 0)
				cout << "Testing " << i << "/1000" << endl;
			if (std::abs(ref-dat) > 1e-3f) {
				cout << endl;
				cout << "eta = " << eta << endl;
				cout << "alpha = " << alpha << endl;
				cout << "cosTheta = " << cosTheta << endl;
				cout << "diff=" << dat-ref << " (dat=" << dat << ", ref=" << ref << ")" << endl;
			}

			avgErr += ref-dat;
		}
		avgErr /= 1000;
		cout << "Avg error = " << avgErr << endl;
	}
예제 #6
0
int readConfig(wstring foldername)
{
	wstring dir = L"..\\..\\proj2-skeleton\\";
	dir += foldername;

	cout << "Opening directory: ";
	wcout << dir << endl;
	if (!SetCurrentDirectory((LPCWSTR)dir.c_str()))
	{
		MessageBox(NULL, (LPCWSTR)L"Unable to open directory", (LPCWSTR)name, MB_OK);
		return -1;
	}
	string line;
	line =".cfg";
	line.insert(0, &name);
	ifstream config(line);
	if (!config.is_open())
	{
		MessageBox(NULL, (LPCWSTR)L"Unable to open config file", (LPCWSTR)name, MB_OK);
		return -1;
	}
	while (getline(config, line))
	{
		char *context = NULL;
		char *tok = strtok_s(&line[0], " ", &context);
		// first tok name of other router.
		char newName = *tok;
		routingEntry newEntry;
		// next is cost.
		tok = strtok_s(NULL, " ", &context);
		newEntry.distance = atoi(tok);
		// next is port to
		tok = strtok_s(NULL, " ", &context);
		newEntry.portTo = atoi(tok);
		// finally is port from
		tok = strtok_s(NULL, " ", &context);
		newEntry.portFrom = atoi(tok);

		//ADDED: need to give next hop, since there are direclty connected to router, next hop should be the new router itself. 
		newEntry.nextHop = newName;

		// lastly, insert new entry into table
		table[newName] = newEntry;
		
	}
	config.close();
	// reading router file now.
	ifstream rtr("routers");
	if (!rtr.is_open())
	{
		MessageBox(NULL, (LPCWSTR)L"Unable to open config file", (LPCWSTR)name, MB_OK);
		return -1;
	}
	while (getline(rtr, line))
	{
		char *context = NULL;
		char *tok = strtok_s(&line[0], " ", &context);
		// first tok name of other router.
		char newName = *tok;
		tok = strtok_s(NULL, " ", &context);
		tok = strtok_s(NULL, " ", &context);

		table[newName].basePort = atoi(tok);
		if (newName == name)
		{
			table[name].distance = 0;
			table[name].nextHop = 0;
			table[name].portFrom = 0;
			table[name].portTo = 0;
		}
	}

	return 1;
}
예제 #7
0
void StaticGeometry::DrawBoundingBox(Graphics::Renderer *r, const Aabb &bb)
{
	vector3f min(bb.min.x, bb.min.y, bb.min.z);
	vector3f max(bb.max.x, bb.max.y, bb.max.z);
	vector3f fbl(min.x, min.y, min.z); //front bottom left
	vector3f fbr(max.x, min.y, min.z); //front bottom right
	vector3f ftl(min.x, max.y, min.z); //front top left
	vector3f ftr(max.x, max.y, min.z); //front top right
	vector3f rtl(min.x, max.y, max.z); //rear top left
	vector3f rtr(max.x, max.y, max.z); //rear top right
	vector3f rbl(min.x, min.y, max.z); //rear bottom left
	vector3f rbr(max.x, min.y, max.z); //rear bottom right

	Graphics::VertexArray *vts = new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE);
	Color c(Color::WHITE);
	//vertices
	vts->Add(fbl, c); //0
	vts->Add(fbr, c); //1
	vts->Add(ftl, c); //2
	vts->Add(ftr, c); //3

	vts->Add(rtl, c); //4
	vts->Add(rtr, c); //5
	vts->Add(rbl, c); //6
	vts->Add(rbr, c); //7

	RefCountedPtr<Graphics::Material> mat(Graphics::vtxColorMaterial);
	Graphics::Surface surf(Graphics::TRIANGLES, vts, mat);

	//indices
	std::vector<unsigned short> &ind = surf.GetIndices();
	//Front face
	ind.push_back(3);
	ind.push_back(1);
	ind.push_back(0);

	ind.push_back(0);
	ind.push_back(2);
	ind.push_back(3);

	//Rear face
	ind.push_back(7);
	ind.push_back(5);
	ind.push_back(6);

	ind.push_back(6);
	ind.push_back(5);
	ind.push_back(4);

	//Top face
	ind.push_back(4);
	ind.push_back(5);
	ind.push_back(3);

	ind.push_back(3);
	ind.push_back(2);
	ind.push_back(4);

	//bottom face
	ind.push_back(1);
	ind.push_back(7);
	ind.push_back(6);

	ind.push_back(6);
	ind.push_back(0);
	ind.push_back(1);

	//left face
	ind.push_back(0);
	ind.push_back(6);
	ind.push_back(4);

	ind.push_back(4);
	ind.push_back(2);
	ind.push_back(0);

	//right face
	ind.push_back(5);
	ind.push_back(7);
	ind.push_back(1);

	ind.push_back(1);
	ind.push_back(3);
	ind.push_back(5);

	r->SetWireFrameMode(true);
	r->DrawSurface(&surf);
	r->SetWireFrameMode(false);
}