示例#1
0
void DaviesCotton()
{
  TThread::Initialize(); // call this first when you use the multi-thread mode

  AOpticsManager* manager = new AOpticsManager("manager", "Davies-Cotton System");
  // Ignore Fresnel reflection in the camera window
  manager->DisableFresnelReflection(kTRUE);
  // Make the OpenGL objects more smooth
  manager->SetNsegments(50);
  // Make the world of 40-m cube
  TGeoBBox* boxWorld = new TGeoBBox("boxWorld", 20*m, 20*m, 20*m);
  AOpticalComponent* world = new AOpticalComponent("world", boxWorld);
  manager->SetTopVolume(world);

  AddMirrors(world);
  AddCamera(world);
  AddMasts(world);
  manager->CloseGeometry(); // finalize the geometry construction
  manager->SetMultiThread(kTRUE); // enable multi threading
  manager->SetMaxThreads(8); // 8 threads

  TCanvas* can = new TCanvas("can3D", "can3D", 800, 800);
  world->Draw("ogl");

  RayTrace(manager, can);
}
示例#2
0
文件: engine.cpp 项目: rtshadow/miscs
void Engine::Render(const Camera* c, PixelBuff &p) const
{
	//just doing tracing for each pixel
	for(unsigned int i=0;i<p.Width();++i)
		for(unsigned int j=0;j<p.Height();++j)
		{
			Ray r=c->GetRay(i,j);
			p.Set(i,j,RayTrace(r,TRACINGDPT));
		}
}
示例#3
0
	void LaserSensorModel::weightParticle( Particle& particle, 
											const SensorData& data )
	{
		if(!data.hasScan){
			return;
		}
		
		// get the laser ranges we expect to see for this particle
		std::vector<double> zhat = RayTrace( particle, data );

// 		lastTraces.push_back( zhat );
		
		// If the ray tracing is infeasible (signalled by empty return), we set the particle weight to zero
		if( zhat.empty() ) {
			particle.setW( 0 );
			return;
		}

// 		double cumProb = 0;
		double cumProb = 1; // initialize the cumulative probability of all the laser probabilities for this particle
					
		// find out what the probability of seeing the laser from this position is
		std::vector<double> probs(numPoints);
		for( unsigned int s = 0; s < numPoints; s++ ) {

			double rTrue = data.points[s*laserSubsample];
			double rEst = zhat[s];
			
			double indivProb = CalculateGaussian( rEst, rTrue )
							+ CalculateUniform( rTrue )
							+ CalculateExponential( rTrue )
							+ CalculateMaxRange( rTrue );

			probs[s] = indivProb;
			
			// find the probability of the real laser measurement under this distribution, and mulitply it into the cumulative
// 			cumProb = cumProb * indivProb;
// 			cumProb += indivProb;

// 			std::cout << "rEst: " << rEst << ", rTrue: " << rTrue << std::endl;
// 			std::cout << "indivProb: " << indivProb << ", cumProb: " << cumProb << std::endl;
			
		} // end find-cumlative-probability-of-every-laser-beam-for-this-particle

		std::sort( probs.begin(), probs.end() );
		for( unsigned int i = numProbsToSkip; i < numPoints; i++ ) {
			cumProb = cumProb * probs[i];
		}
// 		for( unsigned int i = 0; i < probs.size(); i++ ) {
// 			cumProb += probs[i];
// 		}
	
		particle.setW( cumProb * particle.getW() ); // update the particle weight
				
	}// end LaserSensorModel::weightParticle
示例#4
0
int main(void) 
{
   // set up for random num generator
  	//srand ( time(NULL) );
    srand ( 0);

   Image img(WINDOW_WIDTH, WINDOW_HEIGHT);
   Camera* cam = CameraInit();
   PointLight* light = LightInit();
   Ray* r = new Ray();
	double aspectRatio = WINDOW_WIDTH; 
	aspectRatio /= WINDOW_HEIGHT;
  
  	//SCENE SET UP
  	// (floor)
   Plane* floor = new Plane();
   //floor->center = CreatePoint(0, -1 * WINDOW_HEIGHT / 2, -1 * WINDOW_WIDTH / 2);
   //floor->color = CreateColor(200, 200, 200);
   //floor->normal = CreatePoint(0, 0, -1 * WINDOW_WIDTH / 2);
   // (spheres)
   Sphere* spheres = CreateSpheres();

	// RAY TRACING
	//
   
	r->origin = cam->eye;
   r->direction = cam->lookAt;
   r->direction.x = -1 * aspectRatio * tan(FOV / 2);

   for (int i=0; i < WINDOW_WIDTH; i++) {
   	r->direction.y = tan(FOV / 2);
		for (int j=0; j < WINDOW_HEIGHT; j++) {
         //Looping over the Rays
     		img.pixel(i, j, RayTrace(r, spheres, floor, light));
      		
      	//printf("o: (%lf, %lf, %lf)   ", r.origin.x, r.origin.y, r.origin.z);
         //printf("d: (%lf, %lf, %lf)\n", r.direction.x, r.direction.y, r.direction.z);
      		
      	r->direction.y -= 2 * tan(FOV / 2) / WINDOW_HEIGHT;
		}
		r->direction.x += 2 * tan(FOV / 2) / WINDOW_HEIGHT;
  	}
  	
	// IMAGE OUTPUT
	//
  	// write the targa file to disk
  	img.WriteTga((char *)"vanilla.tga", true); 
  	// true to scale to max color, false to clamp to 1.0
} 
static bool IsThereAnObstacleAhead(
    const ACarlaWheeledVehicle &Vehicle,
    const float Speed,
    const FVector &Direction)
{
  const auto ForwardVector = Vehicle.GetVehicleOrientation();
  const auto VehicleBounds = Vehicle.GetVehicleBoundsExtent();

  const float Distance = std::max(50.0f, Speed * Speed); // why?

  const FVector StartCenter = Vehicle.GetActorLocation() + (ForwardVector * (250.0f + VehicleBounds.X / 2.0f)) + FVector(0.0f, 0.0f, 50.0f);
  const FVector EndCenter = StartCenter + Direction * (Distance + VehicleBounds.X / 2.0f);

  const FVector StartRight = StartCenter + (FVector(ForwardVector.Y, -ForwardVector.X, ForwardVector.Z) * 100.0f);
  const FVector EndRight = StartRight + Direction * (Distance + VehicleBounds.X / 2.0f);

  const FVector StartLeft = StartCenter + (FVector(-ForwardVector.Y, ForwardVector.X, ForwardVector.Z) * 100.0f);
  const FVector EndLeft = StartLeft + Direction * (Distance + VehicleBounds.X / 2.0f);

  return
      RayTrace(Vehicle, StartCenter, EndCenter) ||
      RayTrace(Vehicle, StartRight, EndRight) ||
      RayTrace(Vehicle, StartLeft, EndLeft);
}
示例#6
0
文件: main.C 项目: elau/graphite_pep
VOID	StartRayTrace()
	{
	INT	pid;			/* Our internal process id number.   */
	UINT	begin;
	UINT	end;

   THREAD_INIT_FREE();

	LOCK(gm->pidlock)
	pid = gm->pid++;
	UNLOCK(gm->pidlock)

	BARINCLUDE(gm->start);

	if ((pid == 0) ||  (dostats))
        CLOCK(begin);

	/* POSSIBLE ENHANCEMENT: Here's where one might lock processes down
	to processors if need be */

	InitWorkPool(pid);
	InitRayTreeStack(Display.maxlevel, pid);

	/*
	 *	Wait for all processes to be created, initialize their work
	 *	pools, and arrive at this point; then proceed.	This BARRIER
	 *	is absolutely required.  Read comments in PutJob before
	 *	moving this barrier.
	 */

	BARRIER(gm->start, gm->nprocs)

	/* POSSIBLE ENHANCEMENT:  Here's where one would RESET STATISTICS
	and TIMING if one wanted to measure only the parallel part */
   // Reset Models
   CarbonEnableModels();

	RayTrace(pid);


	if ((pid == 0) || (dostats)) {
          CLOCK(end);
          gm->partime[pid] = (end - begin) & 0x7FFFFFFF;
          if (pid == 0) gm->par_start_time = begin;
        }
	}
示例#7
0
int main(int, char**){
	Image image(512, 512);
	RayTrace(&image);
	image.show("GLFW3+Libpng Image Window Demo");
}
//----------------------------------------------------------------------------
bool VolumeRenderer::OnPrecreate ()
{
    if (!WindowApplication2::OnPrecreate())
    {
        return false;
    }

#ifdef TEST_VR
    std::string imageName = Environment::GetPathR("Molecule.im");
    size_t length = strlen(imageName.c_str());
    char* filename = new1<char>(length + 1);
    strcpy(filename, imageName.c_str());
#else
    char* filename = 0;
    TheCommand->GetFilename(filename);
    if (!filename)
    {
        // Input filename must be specified on the command line.
        return false;
    }
#endif

    // Load image, must be 3D and pixels must be unsigned char.
    int numDimensions, numPixels, rtti, sizeOf;
    int* bounds = 0;
    char* data = 0;
    bool loaded = Lattice::LoadRaw(filename, numDimensions, bounds,
        numPixels, rtti, sizeOf, data);
    if (!loaded || numDimensions != 3 || rtti != Euchar::GetRTTI())
    {
        delete1(data);
        delete1(filename);
        return false;
    }

    ImageUChar3D* image = new0 ImageUChar3D(bounds[0], bounds[1], bounds[2],
        (Euchar*)data);

    // Get the maximum bound.
    int maxBound = image->GetBound(0);
    if (image->GetBound(1) > maxBound)
    {
        maxBound = image->GetBound(1);
    }
    if (image->GetBound(2) > maxBound)
    {
        maxBound = image->GetBound(2);
    }
    mBound = 2*maxBound;
    mHBound = (float)maxBound;

    mRT = new0 RayTrace(image, mGamma);
    delete0(image);

    // Resize application window.
    mWidth = mBound;
    mHeight = mBound;

    delete1(filename);
    delete1(bounds);
    return true;
}
示例#9
0
void disp(void){

	//clear all pixels:
	glClear(GL_COLOR_BUFFER_BIT);

	// RayTracing loop
	for (int i = 0; i < (viewport.xvmax - viewport.xvmin); i++)
	{
		for (int j = 0; j < (viewport.yvmax - viewport.yvmin); j++)
		{
			int intersection_object = -1; // negative to return false / no intersection

			// maximum positive double-precision floating-point number
			// found on Wikipedia (link: https://en.wikipedia.org/wiki/Double-precision_floating-point_format)
			double t = 0x7fefffffffffffff;

			Ray ray, shadow_ray, reflected_ray;
			Pixel pixel;
			Intersection intersection, current_intersection,
				shadow_ray_intersection, reflected_ray_intersection,
				current_reflected_intersection;
			double shadowAngle;

			bool bShadow = false;

			pixel.i = i;
			pixel.j = j;

			// initiate RayTrace
			RayTrace(&ray, &view_point, &viewport, &pixel,
				&camera, -focal_distance);

			// check if ray hits an object
			for (int i = 0; i < NUM_SPHERES; i++) {

				if (intersectionPoint(&ray, &sphere[i], &intersection)) {

					// there is an intersection between ray and object
					// calculate normal intersection
					normalIntersection(&sphere[i], &intersection, &ray);

					// if the intersection minimum is smaller than current infinity number
					if (intersection.tmin < t) {
						t = intersection.tmin; // found intersection
						intersection_object = i; // intersection sphere number
						copyIntersection(&current_intersection, &intersection); // copy intersection
					}
				}
			}

			// determine the pixel colour
			if (intersection_object > -1)
			{
				ShadowRayTrace( &shadow_ray, &intersection, &light );

				shadowAngle = shadow_ray.direction.dotproduct( intersection.normal );

				for (int i = 0; i < NUM_SPHERES; i++)
				{
					if (i != intersection_object)
					{
						if (intersectionPoint(&shadow_ray, &sphere[i], &shadow_ray_intersection) && (shadowAngle > 0.0))
							bShadow = true;
					}
				}

				if (bShadow) {
					// if object in shadow, add only ambiental light to the surface colour
					colour = shadow(&sphere[intersection_object].ka_rgb, ambient_light_intensity);
				}
				else {
					// the intersection renders normal colour
					colour = render(&current_intersection, &light, &view_point,
						&sphere[intersection_object].kd_rgb, &sphere[intersection_object].ks_rgb,
						&sphere[intersection_object].ka_rgb, sphere[intersection_object].shininess,
						light_intensity, ambient_light_intensity);
				}

				glColor3f(colour.x, colour.y, colour.z);
				glBegin(GL_POINTS);
					glVertex2i(i, j);
				glEnd();

				intersection_object = -1;
				bShadow = false;
			}
			else {
				// draw the pixel with background colour
				glColor3f(0.0, 0.0, 0.0);

				glBegin(GL_POINTS);
					glVertex2i(i, j);
				glEnd();

				intersection_object = -1;
				bShadow = false;
			}

			t = 0x7fefffffffffffff;
		}
	}

	glutSwapBuffers();
}