Exemplo n.º 1
0
  // We create packets and directly fill each zBuffer tile. Note that we
  // really store t values
  void TaskRayTraceHiZ::run(size_t taskID)
  {
    const uint32 taskX = taskID % this->taskXNum;
    const uint32 taskY = taskID / this->taskXNum;
    const uint32 startX = taskX * this->width;
    const uint32 startY = taskY * this->height;
    const uint32 endX = startX + this->width;
    const uint32 endY = startY + this->height;
    uint32 tileY = startY / HiZ::Tile::height;

    for (uint32 y = startY; y < endY; y += RayPacket::height, ++tileY) {
      uint32 tileX = startX / HiZ::Tile::width;
      for (uint32 x = startX; x < endX; x += RayPacket::width, ++tileX) {
        RayPacket pckt;
        PacketHit hit;
        gen.generate(pckt, x, y);
        intersector->traverse(pckt, hit);
        ssef zmin(inf), zmax(neg_inf);
        const uint32 tileID = tileX + tileY * zBuffer->tileXNum;
        PF_ASSERT(tileID < zBuffer->tileNum);
        HiZ::Tile &tile = zBuffer->tiles[tileID];
        for (uint32 chunkID = 0; chunkID < HiZ::Tile::chunkNum; ++chunkID) {
          //const ssef t = hit.t[chunkID];
          const ssef t = hit.t[chunkID] *dot(sse3f(view.x,view.y,view.z), pckt.dir[chunkID]);
          tile.z[chunkID] = t;
          zmin = min(zmin, t);
          zmax = max(zmax, t);
        }
        tile.zmin = reduce_min(zmin)[0];
        tile.zmax = reduce_max(zmax)[0];
      }
    }
  }
Exemplo n.º 2
0
void Instance::transformBoundingBox()
{
    auto b = i->getBoundingBox();
    
    BoundingBox bb;
    
    for(int i = 0; i <= RayTracer::getInstance()->maxTime; ++i)
    {
        std::set<double> x,y,z;
        
        auto m = makeMatrices(i);
        
        auto p = Vector(b.xmin(i),0,0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(b.xmax(i),0,0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,b.ymin(i),0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,b.ymax(i),0);
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,0,b.zmin(i));
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
        
        p = Vector(0,0,b.zmax(i));
        p = transformLoc(m.first, p);
        x.insert(p.x);
        y.insert(p.y);
        z.insert(p.z);
               
        bb.xmin.addFrame(i, *x.begin());
        bb.xmax.addFrame(i, *x.rbegin());
        bb.ymin.addFrame(i, *y.begin());
        bb.ymax.addFrame(i, *y.rbegin());
        bb.zmin.addFrame(i, *z.begin());
        bb.zmax.addFrame(i, *z.rbegin());
    }
    bbox = bb;
}
Exemplo n.º 3
0
qreal GraphicsScene::zmin()
{
 qreal mValue = zmax();
 QList<QGraphicsItem *> items = QGraphicsScene::items();
     for (int o=0;o<items.size();o++) {
       mValue = qMin(items[o]->zValue(),mValue);
    }
 return mValue;
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------------------------------------------------------------
// called when we want to draw the 3D data in our app.
//------------------------------------------------------------------------------------------------------------------------------------
void draw3D()
{
	const float DEG_TO_RAD = PI / 180.0f;
	const Vec3 xAxis(1.0f, 0, 0);
	const Vec3 yAxis(0, 1.0f, 0);

	translate(0, 0, -g_zoom);
	translate(g_tx, g_ty, 0);
	rotate(g_rotx * DEG_TO_RAD, xAxis);
	rotate(g_roty * DEG_TO_RAD, yAxis);

	// draw the grid on the floor
	setColour(0.25f, 0.25f, 0.25f);
	for(float i = -10.0f; i <= 10.1f; i += 1.0f)
	{
		Vec3 zmin(i, 0, -10);
		Vec3 zmax(i, 0,  10);
		Vec3 xmin(-10, 0, i);
		Vec3 xmax(10, 0, i);
		drawLine(xmin, xmax);
		drawLine(zmin, zmax);
	}
}
int tester()
{
//description
  std::vector<std::string> neutrals;
  std::vector<std::string> ions;
  neutrals.push_back("N2");
  neutrals.push_back("CH4");
  neutrals.push_back("C2H");
//ionic system contains neutral system
  ions = neutrals;
  ions.push_back("N2+");
  Scalar MN(14.008L), MC(12.011), MH(1.008L);
  Scalar MN2 = 2.L*MN , MCH4 = MC + 4.L*MH, MC2H = 2.L * MC + MH;
  std::vector<Scalar> Mm;
  Mm.push_back(MN2);
  Mm.push_back(MCH4);
  Mm.push_back(MC2H);

//densities
  std::vector<Scalar> molar_frac;
  molar_frac.push_back(0.95999L);
  molar_frac.push_back(0.04000L);
  molar_frac.push_back(0.00001L);
  molar_frac.push_back(0.L);
  Scalar dens_tot(1e12L);

//hard sphere radius
  std::vector<Scalar> hard_sphere_radius;
  hard_sphere_radius.push_back(2.0675e-8L * 1e-2L); //N2  in cm -> m
  hard_sphere_radius.push_back(2.3482e-8L * 1e-2L); //CH4 in cm -> m
  hard_sphere_radius.push_back(0.L); //C2H

//zenith angle
//not necessary

//photon flux
//not necessary

////cross-section
//not necessary

//altitudes
  Scalar zmin(600.),zmax(1400.),zstep(10.);

//binary diffusion
  Scalar bCN1(1.04e-5 * 1e-4),bCN2(1.76); //cm2 -> m2
  Planet::DiffusionType CN_model(Planet::DiffusionType::Wakeham);
  Scalar bCC1(5.73e16 * 1e-4),bCC2(0.5); //cm2 -> m2
  Planet::DiffusionType CC_model(Planet::DiffusionType::Wilson);
  Scalar bNN1(0.1783 * 1e-4),bNN2(1.81); //cm2 -> m2
  Planet::DiffusionType NN_model(Planet::DiffusionType::Massman);

/************************
 * first level
 ************************/

//altitude
  Planet::Altitude<Scalar,std::vector<Scalar> > altitude(zmin,zmax,zstep);

//neutrals
  Antioch::ChemicalMixture<Scalar> neutral_species(neutrals); 

//ions
  Antioch::ChemicalMixture<Scalar> ionic_species(ions); 

//chapman
//not needed

//binary diffusion
  Planet::BinaryDiffusion<Scalar> N2N2(   Antioch::Species::N2,  Antioch::Species::N2 , bNN1, bNN2, NN_model);
  Planet::BinaryDiffusion<Scalar> N2CH4(  Antioch::Species::N2,  Antioch::Species::CH4, bCN1, bCN2, CN_model);
  Planet::BinaryDiffusion<Scalar> CH4CH4( Antioch::Species::CH4, Antioch::Species::CH4, bCC1, bCC2, CC_model);
  Planet::BinaryDiffusion<Scalar> N2C2H( Antioch::Species::N2, Antioch::Species::C2H);
  Planet::BinaryDiffusion<Scalar> CH4C2H( Antioch::Species::CH4, Antioch::Species::C2H);
  std::vector<std::vector<Planet::BinaryDiffusion<Scalar> > > bin_diff_coeff;
  bin_diff_coeff.resize(2);
  bin_diff_coeff[0].push_back(N2N2);
  bin_diff_coeff[0].push_back(N2CH4);
  bin_diff_coeff[0].push_back(N2C2H);
  bin_diff_coeff[1].push_back(N2CH4);
  bin_diff_coeff[1].push_back(CH4CH4);
  bin_diff_coeff[1].push_back(CH4C2H);


/************************
 * second level
 ************************/

//temperature
  std::vector<Scalar> T0,Tz;
  read_temperature<Scalar>(T0,Tz,"input/temperature.dat");
  std::vector<Scalar> neutral_temperature;
  linear_interpolation(T0,Tz,altitude.altitudes(),neutral_temperature);
  Planet::AtmosphericTemperature<Scalar, std::vector<Scalar> > temperature(neutral_temperature, neutral_temperature, altitude);

//photon opacity
//not needed

//reaction sets
//not needed

/************************
 * third level
 ************************/

//atmospheric mixture
  Planet::AtmosphericMixture<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > composition(neutral_species, ionic_species, altitude, temperature);
  composition.init_composition(molar_frac,dens_tot);
  composition.set_hard_sphere_radius(hard_sphere_radius);
  composition.initialize();

//kinetics evaluators
//not needed

/************************
 * fourth level
 ************************/

//photon evaluator
//not needed

//molecular diffusion
  Planet::MolecularDiffusionEvaluator<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > molecular_diffusion(bin_diff_coeff,
                                                                                                                          composition,
                                                                                                                          altitude,
                                                                                                                          temperature);
  molecular_diffusion.make_molecular_diffusion();

//eddy diffusion
//not needed

/************************
 * checks
 ************************/

  molar_frac.pop_back();//get the ion outta here
  Scalar Matm(0.L);
  for(unsigned int s = 0; s < molar_frac.size(); s++)
  {
     Matm += molar_frac[s] * composition.neutral_composition().M(s);
  }
  Matm *= 1e-3L; //to kg

  std::vector<std::vector<Scalar> > densities;
  calculate_densities(densities, dens_tot, molar_frac, zmin,zmax,zstep, temperature.neutral_temperature(), Mm);
//N2, CH4, C2H
  std::vector<std::vector<Scalar> > Dij;
  Dij.resize(2);
  Dij[0].resize(3,0.L);
  Dij[1].resize(3,0.L);

  int return_flag(0);
  for(unsigned int iz = 0; iz < altitude.altitudes().size(); iz++)
  {
      Scalar P = pressure(composition.total_density()[iz],temperature.neutral_temperature()[iz]);
      Scalar T = temperature.neutral_temperature()[iz];
      Dij[0][0] = binary_coefficient(T,P,bNN1,bNN2); //N2 N2
      Dij[1][1] = binary_coefficient(T,P,bCC1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCC2 + Scalar(1.L)) 
                                              * Planet::Constants::Universal::kb<Scalar>()
                                              / Planet::Constants::Convention::P_normal<Scalar>(),bCC2 + Scalar(1.L)); //CH4 CH4
      Dij[0][1] = binary_coefficient(T,P,bCN1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCN2),bCN2); //N2 CH4
      Dij[0][2] = binary_coefficient(Dij[0][0],Mm[0],Mm[2]); //N2 C2H
      Dij[1][2] = binary_coefficient(Dij[1][1],Mm[1],Mm[2]); //CH4 C2H
      Dij[1][0] = Dij[0][1]; //CH4 N2
      for(unsigned int s = 0; s < molar_frac.size(); s++)
      {
        Scalar tmp(0.L);
        Scalar M_diff(0.L);
        for(unsigned int medium = 0; medium < 2; medium++)
        {
           if(s == medium)continue;
           tmp += densities[medium][iz]/Dij[medium][s];
        }
        Scalar Ds = (barometry(zmin,altitude.altitudes()[iz],neutral_temperature[iz],Matm,dens_tot) - densities[s][iz]) / tmp;
        for(unsigned int j = 0; j < molar_frac.size(); j++)
        {
           if(s == j)continue;
           M_diff += composition.total_density()[iz] * composition.neutral_molar_fraction()[j][iz] * composition.neutral_composition().M(j);
        }
        M_diff /= Scalar(molar_frac.size() - 1);
        Scalar Dtilde = Ds / (Scalar(1.L) - composition.neutral_molar_fraction()[s][iz] * (Scalar(1.L) - composition.neutral_composition().M(s)/M_diff));

        return_flag = return_flag ||
                      check_test(Dtilde,molecular_diffusion.Dtilde()[s][iz],"D tilde of species at altitude");

      }
      return_flag = return_flag ||
                    check_test(Dij[0][0],molecular_diffusion.binary_coefficient(0,0,T,P),"binary molecular coefficient N2 N2 at altitude") || 
                    check_test(Dij[0][1],molecular_diffusion.binary_coefficient(0,1,T,P),"binary molecular coefficient N2 CH4 at altitude") || 
                    check_test(Dij[0][2],molecular_diffusion.binary_coefficient(0,2,T,P),"binary molecular coefficient N2 C2H at altitude") || 
                    check_test(Dij[1][1],molecular_diffusion.binary_coefficient(1,1,T,P),"binary molecular coefficient CH4 CH4 at altitude") || 
                    check_test(Dij[1][2],molecular_diffusion.binary_coefficient(1,2,T,P),"binary molecular coefficient CH4 C2H at altitude");
  }

  return return_flag;
}
 int maxDepth(TreeNode *root) {
     if (root == NULL)
         return 0;
     else
         return 1 + zmax(maxDepth(root->left), maxDepth(root->right));
 }
Exemplo n.º 7
0
//------------------------------------------------------------------------------------------------------------------------------------
// called when we want to draw the 3D data in our app.
//------------------------------------------------------------------------------------------------------------------------------------
void draw3D()
{
	// draw the grid on the floor
	setColour(0.25f, 0.25f, 0.25f);
	for(float i = -10.0f; i <= 10.1f; i += 1.0f)
	{
		Vec3 zmin(i, 0, -10);
		Vec3 zmax(i, 0,  10);
		Vec3 xmin(-10, 0, i);
		Vec3 xmax(10, 0, i);
		drawLine(xmin, xmax);
		drawLine(zmin, zmax);
	}

	// If using the GPU to compute the lighting (which is what you want to do!)
	if(!g_manualLighting)
	{
		// turn on lighting
		enableLighting();

		// set the diffuse material colour (this will be modulated by the effect of the lighting)
		setColour(1.0f, 1.0f, 1.0f);

		// draw the cube geometry
		drawPrimitives(g_pointsVN, 24, kQuads);

		// turn off lighting
		disableLighting();
	}
	else
	{
		// otherwise, compute the lighting manually. Don't ever do this in practice! It's insane! (But it may be useful for educational purposes)

		// The direction from the vertex to the light (effectively sunlight in this case!).
		Vec3 L(-0.6f, 1.0f, -0.2f);

		// make sure L has been normalised!
		L = normalize(L);

		// start drawing some quads
		begin(kQuads);

		// loop through each vertex normal
		for(int i = 0; i < 24; ++i)
		{
			// compute N.L
			// Make sure we clamp this to zero (so that we ignore any negative values).
			float N_dot_L = std::max(dot(L, g_pointsVN[i].n), 0.0f);

			// the ambient material colour (always gets added to the final colour)
			Vec3 Ka(0.2f, 0.2f, 0.2f);

			// the diffuse material colour
			Vec3 Kd(1.0f, 1.0f, 1.0f);

			// Compute the final colour
			Vec3 colour = Ka + (Kd * N_dot_L);

			// set the vertex colour 
			setColour(colour);

			// specify the vertex
			addVertex(g_pointsVN[i].v);
		}

		// finish drawing our quads
		end();
	}

	// if we are displaying normals
	if(g_displayNormals)
	{
		// make colour pink
		setColour(1.0f, 0.0f, 1.0f);

		// loop through each vertex
		for(int i = 0; i < 24; ++i)
		{
			// compute an offset (along the normal direction) from the vertex
			Vec3 pn = g_pointsVN[i].v + (g_pointsVN[i].n * 0.2f);

			// draw a line to show the normal
			drawLine(g_pointsVN[i].v, pn);
		}
	}
}