Exemple #1
0
void App::onInit() {
	tick();

    message("Loading...");
	renderDevice->setSwapBuffersAutomatically(true);

	m_world = new World(m_worldScene);

    // Create one random number generator per thread
    m_rng.resize(GThread::numCores());
    for (int i = 0; i < m_rng.size(); ++i) {
        //m_rng[i].reset(0xF018A4D2 ^ i, false);
		//m_rng[i].reset(uint32(System::time()) ^ i);
    }
	Array<Plane,10> clipPlanes;
	float a,b,c,d;

    showRenderingStats = false;
    createDeveloperHUD();
    developerWindow->setVisible(false);
    developerWindow->cameraControlWindow->setVisible(false);
    m_debugCamera->filmSettings().setAntialiasingEnabled(false);
	m_debugCamera->filmSettings().setAntialiasingHighQuality(false);
	m_debugCamera->filmSettings().setBloomStrength(0.0f);
	m_debugCamera->setFrame(m_world->frame);
	m_debugCamera->setFieldOfView(m_world->FOVDeg*pi()/180.0,FOVDirection::VERTICAL);
	m_debugCamera->getClipPlanes(Rect2D(Vector2(window()->width(),window()->height())),clipPlanes);

	clipPlanes[0].getEquation(a,b,c,d);
	m_focalPlane = Plane::fromEquation(-a,-b,-c,-(d-(m_world->focalDist)));	
	
    makeGUI();
    // Force re-render on first frame
    m_prevCFrame = CFrame(Matrix3::zero());
	float time = tock("Loading scene");

	//Initialize StatsData class 
	m_featureData.init(m_imgWidth,m_imgHeight,m_sampleBudget,m_samplesPerIteration);
	//Initialize filter with the features data pointers;
	m_CBFilter.init(&m_featureData);
}
Exemple #2
0
void App::pathTraceImage() {
	tick();    

	for (int i = 0; i < m_rng.size(); ++i)
		m_rng[i].reset(uint32(System::time()) ^ i);
	
	GThread::runConcurrently2D(Point2int32(0, 0), Point2int32(m_imgWidth, m_imgHeight), this, &App::samplePixel);
	
	float sampleAvg = m_featureData.getSamplesPerPixelAvg();
	m_featureData.substractFromSampleBudget(sampleAvg);

	
	char numStr[20];
	sprintf(numStr,"%2.2f",sampleAvg);
	m_sampleCountPtrString.setValue(String(numStr));

	

	// Post-processing
	shared_ptr<Texture> src = Texture::fromImage("Source", m_featureData.getImageMean(CBFilter::FT_COLOR));
	if (m_result) {
		m_result->resize(m_imgWidth, m_imgHeight);
	}
	
	m_film->exposeAndRender(renderDevice, m_debugCamera->filmSettings(), src, m_result);

	for (int j = 0; j < CBFilter::FT_SIZE; j++) {
		m_featureTextures[j][MEAN] = Texture::fromImage(m_featureNames[j]+String(" mean"),m_featureData.getImageMean(j,j == CBFilter::FT_DEPTH));
		m_featureTextures[j][VAR] = Texture::fromImage(m_featureNames[j]+String(" variance"),m_featureData.getImageVar(j,false));
		for (int k = 0 ; k < 2 ; k++)
		{
			m_textureBox[j][k]->setTexture(m_featureTextures[j][k]);
			m_textureBox[j][k]->zoomToFit();
		}	
	}
	
	tock("Path tracing");
}
main(int argc, char *argv[])
{
  int *iterations;
  void SOR(vec_ptr v, int *iterations);
  void SOR_blocked(vec_ptr v, int *iterations, int b);

  long int i, j;
  long int block_size;
  uint64_t acc;
  long int MAXSIZE = N;

  // declare and initialize the vector structure
  vec_ptr v0 = new_vec(MAXSIZE);
  iterations = (int *) malloc(sizeof(int));

  //Get blocked SOR data
  for(i=1000; i<=N; i+=1000) {
    //long int this_size = i - ((i-2)%IDEAL_BLOCK);
    long int this_size = i;
    acc=0;
    for(j=0; j<ITERS; j++) {
      fprintf(stderr, "\n(%d %d)", this_size, j);
      init_vector_rand(v0, this_size);
      set_vec_length(v0, this_size);
      tick();
      SOR(v0, iterations);
      //SOR_blocked(v0, iterations, IDEAL_BLOCK);
      tock();
      acc += get_execution_time();
    }
    //length, time(ns)
    printf("%d, %lld\n", this_size, acc/ ITERS + 0.5);
  }

  printf("\n");
  
}
Exemple #4
0
int main(int argc, char **argv)
{

	int new_ae_socket;
		
	OpenSSL_add_all_algorithms();

        if (argc != 2)
        {
		printf("Usage: ./%s AE_ip_address\n", argv[0]);
		exit(1);
	}

	AE_ip_addr = argv[1];

	new_ae_socket = connect_to_ae();
	
	Testmode = 1;
	tick();
	ProcessWAPIProtocol(new_ae_socket);
	tock();

	return 0;
}
Exemple #5
0
/**
 * Sleeps for the given number of time steps, then subtracts
 * the given value from the environment variable WHALE,
 * then prints an updated shrimp line about the new value of WHALE.
 */
void tock_and_subtract(int wait_time, int subtr, char process[]){
    int status = 0;
    tock(wait_time);
    subtract_from_var(WHALE, subtr);
    print_shrimp_line(process);
}
int main(int argc,char * argv[]) {
    // Initialize the MPI and Epetra communicators
    MPI::Init ( argc, argv );
    Epetra_MpiComm EpetraComm(MPI_COMM_WORLD );
    const int p = MPI::COMM_WORLD.Get_size();
    const int id = MPI::COMM_WORLD.Get_rank();

    for(auto it : timeNames){
    	accumulatedTimes[it.first] = 0.0;
    }

    // Get all input parameters
    // Input file name should have been the last argument specified
    Teuchos::RCP<Teuchos::ParameterList> masterParams = rcp(new Teuchos::ParameterList());
    std::string inputFileName = argv[argc-1];
    Teuchos::Ptr<Teuchos::ParameterList> mpPointer(masterParams.get());
    Teuchos::updateParametersFromXmlFile(inputFileName, mpPointer);

    //Create data object(s)
	tick(INITIALIZE_ALL);
    PrimaryNS::Data myData( masterParams, EpetraComm, p , id);
	std::cout << "Initialized: " << id << " of " << p << std::endl;
	tock(INITIALIZE_ALL);

		bool oldIsValid(integrityCheckOnNew(myData));
		if(id == 0){
			if(oldIsValid) std::cout << "Old code passes model evaluation integrity check." << std::endl;
			else std::cout << "Old code does not pass model evaluation integrity check." << std::endl;
		}

		bool newIsValid(integrityCheckOnOld(myData));
		if(id == 0){
			if(newIsValid) std::cout << "New code passes model evaluation integrity check." << std::endl;
			else std::cout << "New code does not pass model evaluation integrity check." << std::endl;
		}

		if(oldIsValid and newIsValid){
			tick(OLD_GATHER);
			oldGatherTest(myData);
			tock(OLD_GATHER);

			tick(NEW_GATHER);
			newGatherTest(myData);
			tock(NEW_GATHER);

			tick(OLD_SCATTER);
			oldScatterTest(myData);
			tock(OLD_SCATTER);

			tick(NEW_SCATTER);
			newScatterTest(myData);
			tock(NEW_SCATTER);

			tick(OLD_KERNEL);
			oldKernelEvaluateTest(myData);
			tock(OLD_KERNEL);

			tick(NEW_KERNEL);
			newKernelEvalauteTest(myData);
			tock(NEW_KERNEL);

			tick(OLD_FULL);
			oldFullTest(myData);
			tock(OLD_FULL);

			tick(NEW_FULL);
			newFullTest(myData);
			tock(OLD_FULL);

			finaliseTimes();

			reportAverageTimes(EpetraComm);
		}
		else{
			std::cout << "Rank: " << id << ", part 2 of the test cannot proceed." << std::endl;
		}


    MPI::Finalize();

    return 0;
}
Exemple #7
0
void IndexWriter::write() {
  tick();
  writePST();
  tock();
}
Exemple #8
0
int
main(int argc,char **argv)
{
	/* read query from stdin, expect name of indexes in argv[1] */
	static FILE *fa, *fb, *fc;
	char nma[PATH_MAX], nmb[PATH_MAX], nmc[PATH_MAX],
	     *qitem[100], *rprog = NULL;
	char nmd[PATH_MAX], grepquery[256];
	static char oldname[30] ;
	static int was =0;
	/* these pointers are unions of pointer to int and pointer to long */
	long *hpt = 0;
	unsigned *master =0;
	int falseflg, nhash, nitem, nfound = 0, frtbl, kk;

	/* special wart for refpart: default is tags only */

	falseflg = 0;

	while (argc > 1 && argv[1][0] == '-')
	{
		switch(argv[1][1])
		{
		case 'a': /* all output, incl. false drops */
			falseflg = 1; 
			break;
		case 'r':
			argc--; 
			argv++;
			rprog = argv[1];
			break;
		case 'F': /* put out full text */
			full = setfrom(argv[1][2]);
			break;
		case 'T': /* put out tags */
			tags = setfrom(argv[1][2]);
			break;
		case 'i': /* input in argument string */
			argc--; 
			argv++;
			sinput = argv[1];
			break;
		case 's': /*text output to string */
		case 'o':
			argc--; 
			argv++;
			soutput = argv[1];
			if ((intptr_t) argv[2]<16000)
			{
				soutlen = (intptr_t)argv[2];
				argc--; 
				argv++;
			}
			break;
		case 't': /*tag output to string */
			argc--; 
			argv++;
			tagout = argv[1];
			break;
		case 'l': /* length of internal lists */
			argc--; 
			argv++;
			lmaster = atoi(argv[1]);
			break;
		case 'g': /* suppress fgrep search on old files */
			keepold = 0;
			break;
		case 'C': /* coordination level */
			colevel = atoi(argv[1]+2);
# if D1
			fprintf(stderr, "colevel set to %d\n",colevel);
# endif
			break;
		case 'P': /* print term freqs */
			prfreqs=1; 
			break;
		case 'm':
			measure=1; 
			break;
		}
		argc--; 
		argv++;
	}
	if(argc < 2)
		exit(1);
	strcpy (nma, todir(argv[1]));
	if (was == 0 || strcmp (oldname, nma) !=0)
	{
		strcpy (oldname,nma);
		strcpy (nmb, nma); 
		strcpy (nmc, nmb); 
		strcpy(nmd,nma);
		strcat (nma, ".ia");
		strcat (nmb, ".ib");
		strcat (nmc, ".ic");
		strcat (nmd, ".id");
		if (was)
		{
			fclose(fa); 
			fclose(fb); 
			fclose(fc);
		}

		fa = fopen(nma, "r");
		if (fa==NULL)
		{
			strcpy(*fgnamp++ = calloc(strlen(oldname)+2,1), oldname);
			fb=NULL;
			goto search;
		}
		fb = fopen(nmb, "r");
		fc = fopen(nmc, "r");
		was =1;
		if (fb== NULL || fc ==NULL)
		{
			err("Index incomplete %s", nmb);
			exit(1);
		}
		indexdate = gdate(fb);
		fd = fopen(nmd, "r");
	}
	fseek (fa, 0, SEEK_SET);
	fread (&nhash, sizeof(nhash), 1, fa);
	fread (&iflong, sizeof(iflong), 1, fa);
	if(master==0)
		master = calloc (lmaster, iflong? sizeof(long): sizeof(unsigned));
	hpt = calloc(nhash, sizeof(*hpt));
	kk=fread( hpt, sizeof(*hpt), nhash, fa);
# if D1
	fprintf(stderr,"read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash);
# endif
	assert (kk==nhash);
	hfreq = calloc(nhash, sizeof(*hfreq));
	assert (hfreq != NULL);
	frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa);
	hfrflg = (frtbl == nhash);
# if D1
	fprintf(stderr, "read freqs %d\n", frtbl);
# endif

search:
	while (1)
	{
		nitem = getq(qitem);
		if (measure) tick();
		if (nitem==0) continue;
		if (nitem < 0) break;
		if (tagout) tagout[0]=0;
		if (fb!=NULL)
		{
			nfound = doquery(hpt, nhash, fb, nitem, qitem, master);
# if D1
			fprintf(stderr,"after doquery nfound %d\n", nfound);
# endif
			fgnamp=fgnames;
			if (falseflg == 0)
				nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full);
# if D1
			fprintf(stderr,"after baddrop nfound %d\n", nfound);
# endif
		}
		if (fgnamp>fgnames)
		{
			char **fgp, tgbuff[100];
			int k;
# if D1
			fprintf(stderr, "were %d bad files\n", fgnamp-fgnames);
# endif
			memset(tgbuff, 0, sizeof (tgbuff));
			grepquery[0]=0;
			for(k=0; k<nitem; k++)
			{
				strcat(grepquery, " ");
				strcat(grepquery, qitem[k]);
			}
# if D1
			fprintf(stderr, "grepquery %s\n",grepquery);
# endif
			for(fgp=fgnames; fgp<fgnamp; fgp++)
			{
# if D1
				fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery);
# endif
				makefgrep(*fgp);
# if D1
				fprintf(stderr, "grepmade\n");
# endif
				if (tagout==0)
					tagout=tgbuff;
				grepcall(grepquery, tagout, *fgp);
# if D1
				fprintf(stderr, "tagout now /%s/\n", tagout);
# endif
				if (full)
				{
					int nout;
					char *bout;
					char *tagp;
					char *oldtagp;
					tagp = tagout;
					while (*tagp) {
						oldtagp = tagp;
						while (*tagp && (*tagp != '\n')) 
							tagp++;
						if (*tagp) 
							tagp++;
				                nout = findline(oldtagp, &bout, 1000, 0L);
						if (nout > 0)
						{
							fputs(bout, stdout);
							free(bout); 
						}
					}
				}
			}
		}
		if (tags)
			result (master, nfound >tags ? tags: nfound, fc);
		if (measure) tock();
	}
	/* NOTREACHED */
	return 0;
}
Exemple #9
0
void ProcessWAPIProtocol(int new_asue_socket)
{
	char *userID = "2";
	int asu_socket;
	int auth_result=FALSE;

	EAP_auth_active eap_auth_active_packet;
	EAP_access_auth_requ eap_access_auth_requ_packet;
	EAP_access_auth_resp eap_access_auth_resp_packet;

	EAP_certificate_auth_requ eap_certificate_auth_requ_packet;//New code
	EAP_certificate_auth_resp eap_certificate_auth_resp_packet;//New code
	
	Testmode = 1;
	tick();

	//1) ProcessWAPIProtocolAuthActive,send to asue
	if(annotation == 1)
		printf("\n***\n 1) 认证激活分组(网络硬盘录像机->摄像机): \n");
	else if(annotation == 2)
		printf("\n***\n 1) ProcessWAPIProtocolAuthActive: \n");

	memset((BYTE *)&eap_auth_active_packet, 0, sizeof(eap_auth_active_packet));
	eap_auth_active_packet.eap_header.code=1;
	eap_auth_active_packet.eap_header.identifier=0;
	eap_auth_active_packet.eap_header.length=sizeof(eap_auth_active_packet);
	eap_auth_active_packet.eap_header.type=192;

	ProcessWAPIProtocolAuthActive(userID, &eap_auth_active_packet.auth_active_packet);
	send_to_peer(new_asue_socket, (BYTE *)&eap_auth_active_packet, sizeof(eap_auth_active_packet));

	//2) ProcessWAPIProtocolAccessAuthRequest, recv from asue
	if (annotation == 1)
		printf("\n***\n 2) 接入认证请求分组(摄像机->网络硬盘录像机,网络硬盘录像机处理该分组): \n");
	else if (annotation == 2)
		printf("\n***\n 2) HandleWAPIProtocolAccessAuthRequest: \n");
	if (annotation == 2)
		printf("recv auth active packet from ASUE...\n");

	memset((BYTE *)&eap_access_auth_requ_packet, 0, sizeof(EAP_access_auth_requ));
	recv_from_peer(new_asue_socket, (BYTE *)&eap_access_auth_requ_packet, sizeof(eap_access_auth_requ_packet));
	//verify access_auth_requ_packet
	HandleWAPIProtocolAccessAuthRequest(userID, &eap_auth_active_packet.auth_active_packet, &eap_access_auth_requ_packet.access_auth_requ_packet);

	//3) ProcessWAPIProtocolCertAuthRequest, send to asu
	if (annotation == 1)
		printf("\n***\n 网络硬盘录像机开始连接认证服务器: \n");
	else if (annotation == 2)
		printf("\n***\n Connect to asu.\n");
    asu_socket = connect_to_asu();
	if (annotation == 1)
		printf("\n***\n 网络硬盘录像机连接认证服务器成功! \n");

	if (annotation == 1)
		printf("\n***\n 3) 证书认证请求分组(网络硬盘录像机->认证服务器): \n");
	else if (annotation == 2)
		printf("\n***\n 3) ProcessWAPIProtocolCertAuthRequest: \n");
	//stop for keyboard
	//getchar();
	
	memset((BYTE *)&eap_certificate_auth_requ_packet, 0, sizeof(eap_certificate_auth_requ_packet));//New code
	eap_certificate_auth_requ_packet.eap_header.code=1;//New code
	eap_certificate_auth_requ_packet.eap_header.identifier=2;//New code
	eap_certificate_auth_requ_packet.eap_header.length=sizeof(eap_certificate_auth_requ_packet);//New code
	eap_certificate_auth_requ_packet.eap_header.type=192;//New code
	

	ProcessWAPIProtocolCertAuthRequest(userID, &eap_access_auth_requ_packet.access_auth_requ_packet,&eap_certificate_auth_requ_packet.certificate_auth_requ_packet);
	send_to_peer(asu_socket,(BYTE *)&eap_certificate_auth_requ_packet, sizeof(eap_certificate_auth_requ_packet));

	//4) ProcessWAPIProtocolCertAuthResp, recv from asu
	if (annotation == 1)
		printf("\n***\n 4) 证书认证响应分组(认证服务器->网络硬盘录像机,认证服务器处理该分组): \n");
	else if (annotation == 2)
	{
		printf("\n***\n 4) HandleWAPIProtocolCertAuthResp: \n");
		printf("recv Cert Auth Resp packet from ASU...\n");
	}

	recv_from_peer(asu_socket, (BYTE *)&eap_certificate_auth_resp_packet, sizeof(eap_certificate_auth_resp_packet));
	memset((BYTE *)&eap_access_auth_resp_packet, 0, sizeof(eap_access_auth_resp_packet));

	//该函数的主要工作是查看证书验证结果,并填充接入认证响应分组
	auth_result = HandleProcessWAPIProtocolCertAuthResp(userID,&eap_certificate_auth_requ_packet.certificate_auth_requ_packet, &eap_certificate_auth_resp_packet.certificate_auth_resp_packet,&eap_access_auth_resp_packet.access_auth_resp_packet);

	//5) ProcessWAPIProtocolAccessAuthResp, send to asue
	if (annotation == 1)
		printf("\n***\n 5) 证书认证响应分组(认证服务器->网络硬盘录像机,网络硬盘录像机处理该分组): \n");
	else if (annotation == 2)
		printf("\n***\n 5) ProcessWAPIProtocolAccessAuthResp: \n");

	//stop for keyboard
	//getchar();


	eap_access_auth_resp_packet.eap_header.code=1;
	eap_access_auth_resp_packet.eap_header.identifier=1;
	eap_access_auth_resp_packet.eap_header.length=sizeof(eap_auth_active_packet);
	eap_access_auth_resp_packet.eap_header.type=192;

	ProcessWAPIProtocolAccessAuthResp(userID, &eap_access_auth_requ_packet.access_auth_requ_packet, &eap_access_auth_resp_packet.access_auth_resp_packet);
	send_to_peer(new_asue_socket, (BYTE *)&eap_access_auth_resp_packet, sizeof(eap_access_auth_resp_packet));

	tock();
	// pid is global variable

	//run ffmpeg
	if(auth_result){
		if(pid < 0){
			char abuf[INET_ADDRSTRLEN];
			struct sockaddr_in asueaddr;
			socklen_t length = sizeof(asueaddr);
			getpeername(new_asue_socket, (struct sockaddr*) &asueaddr, &length);
			inet_ntop(AF_INET, &asueaddr.sin_addr, abuf, INET_ADDRSTRLEN);
			printf("\n");
			char *ffmpeg_prog_dir="";//"/home/yaoyao/ffmpeg_sources/ffmpeg/";
			char ffmpeg_cmd[256];
			//snprintf(ffmpeg_cmd,255,"%sffmpeg -debug ts -i rtsp://%s:8557/PSIA/Streaming/channels/2?videoCodecType=H.264 -vcodec copy -an http://localhost:8090/feed1.ffm",ffmpeg_prog_dir, abuf);
			snprintf(ffmpeg_cmd, 255,
			"%sffmpeg -debug ts -i rtsp://192.168.115.40:8557/PSIA/Streaming/channels/2?videoCodecType=H.264 -vcodec copy -an http://localhost:8090/feed1.ffm >/dev/null 2>/dev/null",
			ffmpeg_prog_dir);
			
			printf("%s", ffmpeg_cmd);
			printf("\n");

			if((pid = fork()) < 0){
				perror("fork()");
			}else if(pid == 0){
				if(execl("/bin/sh", "sh", "-c", ffmpeg_cmd, (char *)0) < 0){
					perror("execl failed");
				}
				pid++;
			}else{}
		}
	}
	else{
		//int status;
		printf("kill %d\n",pid);
		kill(pid,SIGABRT);
		wait(NULL);
		pid++;
		printf("kill %d\n",pid);
		kill(pid,SIGABRT);
		wait(NULL);
		
		pid = -1;
	}

}
//Gets a tock representing the current time
tock Tock_GetTock()
{
    return tock(timer.elapsed());
}
Exemple #11
0
void Stopwatch::computeOverhead() {
    cycleOverhead = 0;
    tick();
    tock();
    cycleOverhead = elapsedCycles();
}
int main(int argc, char** argv) {
  //Precompute FFT coefficients
  Wkn_fft = precompute_fft_coefficients();
  Wkn_ifft = precompute_ifft_coefficients();
  
  // Declare local variables
  int i, j, n;

  // Read in data
  // 1. allocate buffer space for the data. Holds Nx * Ny * Nf complex numbers.
  // 2. pass the filename and buffer to read_data which will read the file
  //    into the buffer.
  printf("Reading Data ...\n");
  tick();
  complex* s = (complex*)safe_malloc(Nx * Ny * Nf * sizeof(complex),
                         "Failed to allocate memory for radar data.");  
  read_data(s, "scene_4.dat");
  tock();

  // Perform a single 2D FFT for each frequency
  // Each element s[i,j,n] is located at s[i * Ny * Nf + j * Nf + n]
  // Thus x-stride = Ny*Nf, y-stride = Nf, and z-stride = 1
  // and each xy plane starts at s + 0 * Ny * Nf + 0 * Nf + n
  printf("Performing FFT\n");
  tick();
  for(n=0; n<Nf; n++)
    fft_2d(s + n, Nx, Ny, Ny*Nf, Nf);
  tock();

  // Multiply each element in the frequency-domain signal by the
  // downward continuation phase operator.
  // 1. for each element (i,j,n) in the signal matrix
  //      i in 0 ... Nx, j in 0 ... Ny, n in 0 ... Nf
  // 2.   compute kx, ky, and k
  //        kx = 2*pi/Dx * i/Nx          if i < Nx/2,
  //             2*pi/Dx * (i-Nx)/Nx     otherwise
  //        ky = 2*pi/Dy * j/Ny          if j < Ny/2,
  //             2*pi/Dy * (j-Ny)/Ny     otherwise
  //        w  = 2*pi*(f0 + n*Df)
  //        k  = w/c
  //
  // 3.   compute kz
  //        kz = sqrt(4 * k^2 - kx^2 - ky^2 )
  // 4.   compute the phase delay
  //        phi = exp(j * kz * z0)
  // 5.   multiply the signal with the phase delay
  //        where s(i,j,k) = s[i * Ny * Nf + j * Nf + n]
  printf("Performing Downward Continuation.\n");
  tick();
  for(i=0; i<Nx; i++)
    for(j=0; j<Ny; j++)
      for(n=0; n<Nf; n++){
        float kx = i < Nx/2 ?
          2*pi/Dx * i/Nx :
          2*pi/Dx * (i - Nx)/Nx;
        float ky = j < Ny/2 ?
          2*pi/Dy * j/Ny :
          2*pi/Dy * (j - Ny)/Ny;
        
        float w = 2*pi*(f0 + n*Df);
        float k = w/c_speed;
        float kz = sqrt(4*k*k - kx*kx - ky*ky);
        
        complex phi = c_jexp(kz * z0);
        s[i * Ny * Nf + j * Nf + n] = c_mult(s[i * Ny * Nf + j * Nf + n], phi);        
      }
  tock();

  // Calculate the range of the Stolt interpolation indices.
  // The minimum angular frequency, w_min = 2*pi * f0
  // The maximum angular frequency, w_max = 2*pi * (f0 + (N - 1)*Df)
  // From which the
  //   minimum wavenumber, k_min = w_min / c
  //   maximum wavenumber, k_max = w_max / c
  // The maximum wavenumber in the x direction, kx_max = 2*pi/Dx * 0.5 * (Nx-1)/Nx
  // The maximum wavenumber in the y direction, ky_max = 2*pi/Dy * 0.5 * (Ny-1)/Ny
  // The minimum wavenumbers in the x and y direction are assumed to be 0
  // From which the
  //   minimum wavenumber in the z direction, kz_min = sqrt(4*k_min^2 - kx_max^2 - ky_max^2)
  //   maximum wavenumber in the z direction, kz_max = sqrt(4*k_max^2 - 0 - 0)
  float w_min = 2*pi * f0;
  float w_max = 2*pi * (f0 + (Nf - 1)*Df);
  float k_min = w_min / c_speed;
  float k_max = w_max / c_speed;
  float kx_max = 2*pi/Dx * 0.5 * (Nx-1)/Nx;
  float ky_max = 2*pi/Dy * 0.5 * (Ny-1)/Ny;
  float kz_min = sqrt(4*k_min*k_min - kx_max*kx_max - ky_max*ky_max);
  float kz_max = sqrt(4*k_max*k_max);

  // Perform Stolt Interpolation
  // 1. for each step in the x direction, i in 0 ... Nx
  //    and each step in the y direction, j in 0 ... Ny
  // 2.   compute kx, and ky as per step 2. above
  // 3.   create float buffer of size Nf for storing the interpolation indices, n_interp
  // 4.   for each step in frequency, n in 0 ... Nf
  //         compute kz = kz_min + (kz_max - kz_min) * n/(Nf - 1)
  // 4.      compute desired k = 0.5 * sqrt(kx^2 + ky^2 + kz^2)
  // 5.      which corresponds to the interpolated array element
  //            n_interp[n] = (c*k/(2*pi) - f0)/Df
  // 6.   resample this line in s on interpolated indices n_interp
  //         s[i,j,n] is at s[i * Ny * Nf + j * Nf + n] thus this line
  //           starts at s + i * Ny * Nf + j * Nf + 0, has length Nf, and has stride 1
  printf("Performing Stolt Interpolation.\n");
  tick();
  for(i=0; i<Nx; i++)
    for(j=0; j<Ny; j++){
      float kx = i < Nx/2 ?
        2*pi/Dx * i/Nx :
        2*pi/Dx * (i - Nx)/Nx;
      float ky = j < Ny/2 ?
        2*pi/Dy * j/Ny :
        2*pi/Dy * (j - Ny)/Ny;

      float n_interp[Nf];
      for(n=0; n<Nf; n++){
        float kz = kz_min + (kz_max - kz_min) * n/(Nf - 1);
        float k = 0.5 * sqrt(kx*kx + ky*ky + kz*kz);
        n_interp[n] = (c_speed*k/(2*pi) - f0)/Df;
      }
      
      resample_1d(s + i*Ny*Nf + j*Nf, Nf, 1, n_interp);
    }
  tock();

  // Perform a 3D IFFT on the signal
  // Each element s[i,j,n] is located at s[i * Ny * Nf + j * Nf + n]
  // Thus x-stride = Ny*Nf, y-stride = Nf, and z-stride = 1
  printf("Performing IFFT.\n");
  tick();
  ifft_3d(s, Nx, Ny, Nf, Ny*Nf, Nf, 1);
  tock();

  // End the simulation by writing out the computed signal and write it out to a file.
  // Pass the computed matrix and a output filename to write_data()
  printf("Writing data ...\n");
  tick();
  write_data(s, "scene_4.out");
  tock();
  printf("Done.\n");

  // Free all the temporary memory
  free(s);
}
Exemple #13
0
bool Timer::ticketytock(){
	bool done = tock();
	tick(); 
	return done; 
}