예제 #1
0
		GLProgram *GLProgramManager::CreateProgram(const std::string &name) {
			SPADES_MARK_FUNCTION();

			SPLog("Loading GLSL program '%s'", name.c_str());
			std::string text = FileManager::ReadAllBytes(name.c_str());
			std::vector<std::string> lines = SplitIntoLines(text);

			GLProgram *p = new GLProgram(device, name);

			for (size_t i = 0; i < lines.size(); i++) {
				std::string text = TrimSpaces(lines[i]);
				if (text.empty())
					break;

				if (text == "*shadow*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, false);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadow-lite*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, false, true);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadow-variance*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, true);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*dlight*") {
					std::vector<GLShader *> shaders = GLDynamicLightShader::RegisterShader(this);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadowmap*") {
					std::vector<GLShader *> shaders = GLShadowMapShader::RegisterShader(this);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text[0] == '*') {
					SPRaise("Unknown special shader: %s", text.c_str());
				} else if (text[0] == '#') {
					continue;
				}
				GLShader *s = CreateShader(text);

				p->Attach(s);
			}

			Stopwatch sw;
			p->Link();
			SPLog("Successfully linked GLSL program '%s' in %.3fms", name.c_str(),
			      sw.GetTime() * 1000.);
			// p->Validate();
			return p;
		}
예제 #2
0
	void playback_exact_CSpace_R3()
	{
		C2A_Model* P = NULL;
		C2A_Model* Q = NULL;
		readObjFile(P, "../data/models/CupSpoon/Cup.obj");
		readObjFile(Q, "../data/models/CupSpoon/Spoon.obj");

		P->ComputeRadius();
		Q->ComputeRadius();

		Collider3D collider(P, Q);

		C2A_Model* CSpace;
		readObjFile(CSpace, "../data/cupspoon.obj");

		std::vector<ContactSpaceSampleData> contactspace_samples;
		std::ifstream in("space_test_3d.txt");
		asciiReader(in, contactspace_samples);

		std::ofstream timing_file("timing_exact_R3.txt");
		std::ofstream PD_file("PD_exact_R3.txt");

		for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
		{
			std::cout << i << std::endl;
			DataVector q_col(6);
			DataVector q(3);
			for(std::size_t j = 0; j < 3; ++j)
				q[j] = contactspace_samples[i].v[j];

			for(std::size_t j = 0; j < 6; ++j)
				q_col[j] = contactspace_samples[i].v[j];


			boost::timer t;
			//aTimer.Reset();
			aTimer.Start();
			std::pair<DataVector, double> pd_result;
			if(!collider.isCollide(q_col)) 
			{
				pd_result.second = 0;
			}
			else
			{
				pd_result = Minkowski_Cspace_3D::Exact_PD_R3(q, CSpace);
			}
			aTimer.Stop();
			PD_file << pd_result.second << " ";	
			//timing_file << t.elapsed() << " ";
			timing_file << aTimer.GetTime() * 1000 << " ";

			
			timing_file.flush();
			PD_file.flush();
		}
	}
예제 #3
0
void doPerfTest(int n_runs)
{
  printf("Running perf test (%d runs)...\n", n_runs);

  if(n_runs == 0) return;

  buildProjectionMatrix();
  resetDepthBuffer();
  piko_pipe.prepare();
  piko_pipe.run_single();

  Stopwatch mywatch;

  mywatch.Reset();
  for(int run = 0; run < n_runs; run++)
  {
    buildProjectionMatrix();
    resetDepthBuffer();
    piko_pipe.prepare();
  }
  float prepTime = mywatch.GetTime();

  mywatch.Reset();
  for(int run = 0; run < n_runs; run++)
  {
    buildProjectionMatrix();
    resetDepthBuffer();
    piko_pipe.prepare();
    piko_pipe.run_single();
  }
  float fullrunTime = mywatch.GetTime();

  float total_time_to_ms = 1000.0f / (float) n_runs;

  printf("Prep time     = %0.2f ms\n", total_time_to_ms * (prepTime));
  printf("Full run time = %0.2f ms\n", total_time_to_ms * (fullrunTime));
  printf("Raster time   = %0.2f ms\n", total_time_to_ms * (fullrunTime - prepTime));
}
예제 #4
0
		GLShader *GLProgramManager::CreateShader(const std::string &name) {
			SPADES_MARK_FUNCTION();

			SPLog("Loading GLSL shader '%s'", name.c_str());
			std::string text = FileManager::ReadAllBytes(name.c_str());
			GLShader::Type type;

			if (name.find(".fs") != std::string::npos)
				type = GLShader::FragmentShader;
			else if (name.find(".vs") != std::string::npos)
				type = GLShader::VertexShader;
			else if (name.find(".gs") != std::string::npos)
				type = GLShader::GeometryShader;
			else
				SPRaise("Failed to determine the type of a shader: %s", name.c_str());

			GLShader *s = new GLShader(device, type);

			std::string finalSource;

			if (settings.r_hdr) {
				finalSource += "#define USE_HDR 1\n";
				finalSource += "#define LINEAR_FRAMEBUFFER 1\n";
			} else {
				finalSource += "#define USE_HDR 0\n";
				finalSource += "#define LINEAR_FRAMEBUFFER 0\n";
			}
			if (settings.r_fogShadow) {
				finalSource += "#define USE_VOLUMETRIC_FOG 1\n";
			} else {
				finalSource += "#define USE_VOLUMETRIC_FOG 0\n";
			}

			if (settings.r_ssao) {
				finalSource += "#define USE_SSAO 1\n";
			} else {
				finalSource += "#define USE_SSAO 0\n";
			}

			finalSource += text;

			s->AddSource(finalSource);

			Stopwatch sw;
			s->Compile();
			SPLog("Successfully compiled GLSL program '%s' in %.3fms", name.c_str(), // should this be "program" or "shader"?
			      sw.GetTime() * 1000.);
			return s;
		}
예제 #5
0
	void playback_local_PD_R3()
	{
		std::ofstream timing_file("timing_local_PD_R3.txt");
		std::ofstream PD_file("PD_local_R3.txt");

		std::vector<C2A_Model*> P;
		std::vector<C2A_Model*> Q;

		readObjFiles(P, "../data/models/CupSpoon/cup_convex.obj");
		readObjFiles(Q, "../data/models/CupSpoon/spoon_convex.obj");


		std::vector<ContactSpaceSampleData> contactspace_samples;
		std::ifstream in("space_test_3d.txt");
		asciiReader(in, contactspace_samples);

		for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
		{
			std::cout << i << std::endl;
			DataVector q_col(6);
			DataVector q(3);
			for(std::size_t j = 0; j < 3; ++j)
				q[j] = contactspace_samples[i].v[j];

			for(std::size_t j = 0; j < 6; ++j)
				q_col[j] = contactspace_samples[i].v[j];

			boost::timer t;
			aTimer.Reset();
			aTimer.Start();
			double pd = Collider3D::PDt(P, Q, q_col);
			PD_file << pd << " ";	
			// timing_file << t.elapsed() << " ";
			timing_file << aTimer.GetTime() * 1000 << " ";

			
			timing_file.flush();
			PD_file.flush();
		}
	}
예제 #6
0
		GLShader *GLProgramManager::CreateShader(const std::string &name) {
			SPADES_MARK_FUNCTION();
			
			SPLog("Loading GLSL shader '%s'", name.c_str());
			std::string text = FileManager::ReadAllBytes(name.c_str());
			GLShader::Type type;
			
			if(name.find(".fs") != std::string::npos)
				type = GLShader::FragmentShader;
			else if(name.find(".vs") != std::string::npos)
				type = GLShader::VertexShader;
			else
				SPRaise("Failed to determine the type of a shader: %s",
						name.c_str());
			
			GLShader *s = new GLShader(device, type);
			s->AddSource(text);
			
			Stopwatch sw;
			s->Compile();
			SPLog("Successfully compiled GLSL program '%s' in %.3fms", name.c_str(),
				  sw.GetTime() * 1000.);
			return s;
		}
예제 #7
0
	void playback_R3()
	{
		C2A_Model* P = NULL;
		C2A_Model* Q = NULL;
		readObjFile(P, "../data/models/CupSpoon/Cup.obj");
		readObjFile(Q, "../data/models/CupSpoon/Spoon.obj");

		P->ComputeRadius();
		Q->ComputeRadius();

		Collider3D collider(P, Q);

		std::vector<ContactSpaceSampleData> contactspace_samples;
		std::ifstream in("space_test_3d.txt");
		asciiReader(in, contactspace_samples);

		ContactSpaceR3 contactspace(P, Q, 0.05 * (P->radius + Q->radius));
		std::ofstream scaler_file("scaler_3d_rotation_cupspoon.txt");
		scaler_file << contactspace.getScaler() << std::endl;
		std::vector<ContactSpaceSampleData> train_samples = contactspace.uniform_sample(100000);

		SVMLearner learner;
		learner.setDim(contactspace.active_data_dim());
		learner.setC(20);
		learner.setScaler(contactspace.getScaler());
		learner.setUseScaler(true);
		learner.setGamma(50); 

		learner.learn(train_samples, contactspace.active_data_dim());
		learner.save("model_R3.txt");

		// flann::HierarchicalClusteringIndex<ContactSpaceSE3Euler::DistanceType>* query_index = learner.constructIndexOfSupportVectorsForQuery<ContactSpaceSE3Euler, flann::HierarchicalClusteringIndex, flann::HierarchicalClusteringIndexParams>();

		std::vector<ContactSpaceSampleData> support_samples;
		learner.collectSupportVectors(support_samples);
		ExtendedModel<ContactSpaceR3, flann::Index> extended_model = 
			constructExtendedModelForModelDecisionBoundary<ContactSpaceR3, SVMLearner, flann::Index, flann::KDTreeIndexParams>(contactspace, learner, support_samples, 0.01, 50);


		std::ofstream timing_file("timing_APD_R3.txt");
		std::ofstream PD_file("PD_APD_R3.txt");

		for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
		{
			std::cout << i << std::endl;
			DataVector q_col(6);
			DataVector q(3);
			for(std::size_t j = 0; j < 3; ++j)
				q[j] = contactspace_samples[i].v[j];

			for(std::size_t j = 0; j < 6; ++j)
				q_col[j] = contactspace_samples[i].v[j];

			boost::timer t;
			aTimer.Reset();
			aTimer.Start();
			if(!collider.isCollide(q_col)) 
			{
				PD_file << 0 << " ";
			}
			else
			{
				QueryResult pd_result = PD_query(learner, contactspace, extended_model.index, extended_model.samples, q);
				PD_file << pd_result.PD << " ";
			}
			// timing_file << t.elapsed() << " ";
			timing_file << aTimer.GetTime() * 1000 << " ";

			
			timing_file.flush();
			PD_file.flush();
		}
	}
예제 #8
0
int main(int argc, char* argv[])
{
	string trainlistfile;
	string testlistfile;
	string modelfile;
	string rawfeaturefile;
	string resultpath;
	string kmeansfilepath;
	int maxComponent = 32;
	int cluster_num = 512;
	int feature_dimention = 128;
	if (argc == 1)
	{
		help();
		return -1;
	}
	for (int i = 1; i < argc;++i)
	{
		
		if (string(argv[i])=="--trainlist")
		{
			trainlistfile = argv[++i];
		}
		else if (string(argv[i]) == "--testlist")
		{
			testlistfile = argv[++i];
		}
		else if (string(argv[i]) == "--clusternum")
		{
			cluster_num = std::stoi(argv[++i]);
		}
		else if (string(argv[i]) == "--featuredim")
		{
			feature_dimention = std::stoi(argv[++i]);
		}
		else if (string(argv[i]) == "--modelfile")
		{
			modelfile = argv[++i];
		}
		else if (string(argv[i]) == "--rawfeature")
		{
			rawfeaturefile = argv[++i];
		}
		else if (string(argv[i])=="--resultpath")
		{
			resultpath = argv[++i];

		}
		else if (string(argv[i]) == "--maxComponent")
		{
			maxComponent = std::stoi(argv[++i]);

	}
		else if (string(argv[i]) == "--kmeansfilepath")
		{
			kmeansfilepath = argv[++i];

		}
	}
#ifdef kmeans_pca
	vlad::configure(256,128);
	PCA pca;
	vlad::loadPCAmodel("pca_model.yml",pca);
	cout<<pca.eigenvalues<<endl;
#endif
#ifdef kmeans
	vlad::getKmeansModel(cluster_num,feature_dimention,rawfeaturefile,resultpath);
#endif
#ifdef VLAD
	Stopwatch watch;
	watch.Start();
	vlad::GetVladFeatureFromSift(kmeansfilepath,testlistfile);
	watch.Stop();
	cout<<"getkmeans use "<<watch.GetTime()<<endl;
	getchar();
#endif
#ifdef ReduceMatrix
	ifstream rawfeature(rawfeaturefile.c_str());
	ofstream outPut(resultpath.c_str());
	string single_raw_fea;
	PCA pca;
	vlad::loadPCAmodel(modelfile, pca);
	while (getline(rawfeature,single_raw_fea))
	{
		vector<string> ww;
		cv::Mat rawfeature_mat = cv::Mat(1,LENGTH_OF_SINGLE_DATA, CV_32F);
		split_words(single_raw_fea, " ", ww);
		for (int j = 0; j < LENGTH_OF_SINGLE_DATA; ++j){
			rawfeature_mat.at<float>(0, j) = atof(ww[j].c_str());
		}
		cv::Mat matric_reduced;
		matric_reduced = pca.project(rawfeature_mat);
		for (int i=0;i<matric_reduced.cols;++i)
		{
			outPut<<matric_reduced.at<float>(0,i);
		}
		outPut <<endl;
        
	}
	rawfeature.close();
	outPut.close();
#else
#ifdef ALL



	    vlad::configure(cluster_num,feature_dimention);
		//vlad::getPCAmodel(trainlistfile,32);
    	vlad::ExitTheSiftFeature(trainlistfile);	
	   // vlad::GetVladFeature(testlistfile);
//	FV::GetGMMModel(32, 512);
	vector<float> feature{ 1, 1, 1, 1, 1, 1 };
	RootNormFeature(feature);
	Mat a = Mat::ones(4, 6,CV_32FC1);
	for (float a:feature)
	{
		cout << a << endl;
	}
	a.at<float>(0, 0) = 0;
	RootNormFeature(a);
	cout << a;
	getchar();
	/*Mat rawdata = Mat(1, 3, CV_32FC1);
	rawdata.setTo(1);
	cout << rawdata << endl;
	Mat result;
	Mat model = (Mat_<float>(3, 2) << 1, 1, 1, -1, -1, -1);
	encode2Binary(rawdata, model, result);
	cout << "work has been down"<< rawdata << endl << model << endl << result << endl;
	vector<float> rawdata2{ 1.0, 1.0, 1.0 };
	Mat result2;
	encode2Binary(rawdata2, model, result2);
	cout << result2 << endl;
	Mat model2 = (Mat_<uchar>(3, 2) << 1, 1, 1, 1, 1, 1);
	model2.assignTo(model2, CV_32FC1);
	cout << model2<<endl<<model2.type();
	for (int i = 0; i < 10;i++)
	{
		for (int i = 0; i < 10;i++)
		{
			cout << i << endl;
		}
	}*/
	//MethodTimeResume timetest("time.log");
	//timetest.test();
	//getchar();

	//vlad::getPCAmodel(trainlistfile, 32);
#endif
#endif // ReduceMatrix
	
}
예제 #9
0
/**
 * @fn Display()
 * @brief GLUT display callback.
 */ 
void Display()
{
  //g_timer.Reset();

  if (!g_bPause || g_bSingleStep)
  {
    g_bSingleStep = false;
     
    // set parameters that may have changed
    g_pFlo->SetViscosity(g_rViscosity);
    g_pFlo->EnablePressureClear(g_bClearPressure);
    g_pFlo->SetNumPoissonSteps(g_iNumPoissonSteps);
    g_pFlo->SetMassColor(g_rInkRGB);
    g_pFlo->SetInkLongevity(g_rInkLongevity);
    g_pFlo->SetTimeStep(g_rTimestep);
    g_pFlo->SetGridScale(g_rGridScale);
    g_pFlo->SetVorticityConfinementScale(g_rVCScale);
    
    if (g_displayMode == Flo::DISPLAY_VORTICITY || g_bComputeVorticity)
      g_pFlo->EnableVorticityComputation(true);
    else
      g_pFlo->EnableVorticityComputation(false);
    
	// For benchmarking...
    if (g_bTiming)
    {
      if (g_perfTimer.GetNumStarts() == 100)
      {
        g_bTiming = false;
        g_perfTimer.Stop();
        printf("Average iteration time: %f\n", g_perfTimer.GetAvgTime());
      }
      g_perfTimer.Start();
    }

	// Take a simulation timestep.
    g_pFlo->Update();
  }
  
  if (g_bDisplayFluid)
  {
	// Display the fluid.
	g_pFlo->Display(g_displayMode, g_bBilerp, g_bMakeTex, g_bArbitraryBC);
	  
	// Display user interface.
	if (g_bDisplaySliders)
	{
	  paramlist->Render(0, 0);
	}
	  
	glutSwapBuffers();
  }
  
  // Frame rate update
  g_iFrameCount++;
  
  if (g_timer.GetTime() > 0.5)
  {  
    char title[100];
    sprintf(title, "Flo Fluid Simulator: %f FPS", 
			g_iFrameCount / g_timer.GetTime());
    glutSetWindowTitle(title);

    g_iFrameCount = 0;
    g_timer.Reset();
  }

}