コード例 #1
0
void Containment::restore(KConfigGroup &group)
{
    /*
    #ifndef NDEBUG
    // qDebug() << "!!!!!!!!!!!!initConstraints" << group.name() << d->type;
    // qDebug() << "    location:" << group.readEntry("location", (int)d->location);
    // qDebug() << "    geom:" << group.readEntry("geometry", geometry());
    // qDebug() << "    formfactor:" << group.readEntry("formfactor", (int)d->formFactor);
    // qDebug() << "    screen:" << group.readEntry("screen", d->screen);
    #endif
    */
    setLocation((Plasma::Types::Location)group.readEntry("location", (int)d->location));
    setFormFactor((Plasma::Types::FormFactor)group.readEntry("formfactor", (int)d->formFactor));
    d->lastScreen = group.readEntry("lastScreen", d->lastScreen);

    setWallpaper(group.readEntry("wallpaperplugin", ContainmentPrivate::defaultWallpaper));

    d->activityId = group.readEntry("activityId", QString());

    flushPendingConstraintsEvents();
    restoreContents(group);
    setImmutability((Types::ImmutabilityType)group.readEntry("immutability", (int)Types::Mutable));

    if (isContainment()) {
        KConfigGroup cfg = KConfigGroup(corona()->config(), "ActionPlugins");
        cfg = KConfigGroup(&cfg, QString::number(containmentType()));

        //qDebug() << cfg.keyList();
        if (cfg.exists()) {
            foreach (const QString &key, cfg.keyList()) {
                //qDebug() << "loading" << key;
                setContainmentActions(key, cfg.readEntry(key, QString()));
            }
        } else { //shell defaults
コード例 #2
0
ファイル: radiosity.cpp プロジェクト: jonwrona/ACG-Final
void Radiosity::ComputeFormFactors() {
  assert (formfactors == NULL);
  assert (num_faces > 0);
  formfactors = new float[num_faces*num_faces];


  // =====================================
  // ASSIGNMENT:  COMPUTE THE FORM FACTORS
  // =====================================

  //cycle through every pair
  for (int i=0; i<num_faces; i++){
    for (int j=0; j<num_faces; j++){
      //a surface does not distribute any light to itself
      float form_factor=0.0;
      if (i==j){
        formfactors[i*num_faces+j]=0.0;
      }
      //check for occlusions...

      
      //here we actually have to calculate the form factor...
      else{
        for (int samples=0; samples<args->num_form_factor_samples; samples++){
          float phi_i, phi_j, Aj, r;
          glm::vec3 disp;
          
          Face* face_i=mesh->getFace(i);
          Face* face_j=mesh->getFace(j);
          glm::vec3 norm_i= glm::normalize(face_i->computeNormal());
          glm::vec3 norm_j= glm::normalize(face_j->computeNormal());
          //first compute the displacement vector between the two faces.
          //points from i to j

          //use below code when you want to trace from center to center

          //disp = face_i->computeCentroid()-face_j->computeCentroid();
          glm::vec3 face_j_point=face_j->RandomPoint();
          disp = face_i->RandomPoint()-face_j_point;
          Hit h;
          r = glm::length(disp);
          
          //if we are only taking one sample we want it from the center for consistency
          if (args->num_form_factor_samples==1){
            disp=face_i->computeCentroid()-face_j->computeCentroid();
            r = glm::length(disp);
            face_j_point=face_j->computeCentroid();
          }
          Ray ray(face_j_point, glm::normalize(disp));
          raytracer->CastRay(ray, h, true);
          //here we test for occlusion
          if ( args->num_shadow_samples>0 and !(h.getT()>r-0.001 and h.getT()<r+0.001) ){
            //setFormFactor(i,j, 0.0);
          }
          else{
          
            //std::cout<<"r is "<<r<<std::endl;
            disp = -glm::normalize(disp);
            //compute the rest of the constants
            phi_i = fabs(glm::dot(norm_i, disp));
            //std::cout<<"phi_i is "<<phi_i<<std::endl;
            disp = -disp;
            phi_j = fabs(glm::dot(norm_j, disp));
            //std::cout<<"phi_j is "<<phi_j<<std::endl;
            Aj = face_j->getArea();
            //std::cout<<"Aj is "<<Aj<<std::endl;
            //compute and enter the form factor
            //setFormFactor(i,j,(phi_i)*(phi_j)*Aj/(3.14159265359*r*r));
            form_factor+=(phi_i)*(phi_j)*Aj/(3.14159265359*r*r);
            // formfactors[i*num_faces+j]=10000000000000000.0*glm::cos(phi_i)*glm::cos(phi_j)*Aj/(3.14159265359*r*r);
          }
        }
      }
    setFormFactor(i,j,form_factor/(float(args->num_form_factor_samples)));

    }
    normalizeFormFactors(i);
  }
  #if 0
  std::cout<<"formfactors matrix is\n";
  for (int i=0; i<num_faces; i++){
    for(int j=0; j<num_faces;j++){
      std::cout<<formfactors[i*num_faces+j]<<' ';
    }
    std::cout<<'\n';
  }
  #endif

}
コード例 #3
0
void Radiosity::ComputeFormFactors() {
  assert (formfactors == NULL);
  assert (num_faces > 0);
  formfactors = new float[num_faces*num_faces];
    totalFormFactori = new float[num_faces];


  // =====================================
  // ASSIGNMENT:  COMPUTE THE FORM FACTORS
  // =====================================

    //use getRasterizedPrimitiveFace(int i) for the forms (maybe, apparently there are 0 of these)
    //use the original geometry for checking occlusion (possibly Face* getOriginalQuad(int i))
    /*printf("NumFormFactors: %d\tNumOriginalQuads: %d\tNumRasterizedPrimitiveFaces: %d\tNumPrimitiveFaces: %d\n", num_faces, mesh->numOriginalQuads(), mesh->numRasterizedPrimitiveFaces(), mesh->numPrimitives()); //14, 14, 0, 0  to  //56, 14, 0, 0
    
    Ray ray1(glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
    Ray ray2(glm::vec3(0, 0, 0), glm::vec3(1, 0, 0));
    
    printf("Angle: %f\n", ray1.getAngle(ray2));*/
    
    
    /*START SMALL (Like .5 or smaller and get larger) double until makes too large, then halve the distance until going too small, take the number before going too small, toss out the extras by directly going through vector and eliminating the n smallest*/
    
    for (int i = 0; i < num_faces; i++)
    {
        totalFormFactori[i] = 0;
        glm::vec3 point1 = mesh->getFace(i)->RandomPoint();
        glm::vec3 faceNormali = mesh->getFace(i)->computeNormal();
        
        //move the start point slightly off the surface to avoid self collision
        point1 += (float).001*glm::normalize(faceNormali);
        
        //float totalFormFactori = 0;
        for (int j = 0; j < num_faces; j++)
        {
            if (i == j)
            {
                setFormFactor(i, j, 0);
                continue;
            }
            glm::vec3 faceNormalj = mesh->getFace(j)->computeNormal();
            float formFactorTemp = 0;
            
            for (int k = 0; k<args->num_form_factor_samples; k++)
            {
                
                glm::vec3 point2 = mesh->getFace(j)->RandomPoint();
                
                //move the end point slightly off the surface to avoid self collision
                //point2 += (float).001*glm::normalize(faceNormalj);
                
                Ray r(point1, glm::normalize(point2-point1));
                
                Hit h;
                raytracer->CastRay(r,h,true);
                glm::vec3 hitPoint = r.pointAtParameter(h.getT());
                if (comparePoints(point2, hitPoint) == 0) //if the points are not roughly the same then we have occlusion
                {
                    continue;
                }
                
                                  //   cos(       ThetaI            )  *cos(        ThetaJ                 ) /
                formFactorTemp +=   ( (cos( r.getAngle( faceNormali ) )*cos( r.getAngle( -1.0f*faceNormalj ) ) ) /
                                  //  PI*R^2 /
                                    ( M_PI*glm::dot( point2-point1, point2-point1 ) ) )/
                                  // numFormFactors
                                    args->num_form_factor_samples;
                
                //printf("(cos(%f)*cos(%f)/3.1415*%f)/%d = %f\n", r.getAngle( faceNormali ), r.getAngle( -1.0f*faceNormalj ), glm::dot( point2-point1, point2-point1 ), args->num_form_factor_samples, ( (cos( r.getAngle( faceNormali ) )*cos( r.getAngle( -1.0f*faceNormalj ) ) ) / ( M_PI*glm::dot( point2-point1, point2-point1 ) ) )/args->num_form_factor_samples);
                //printf("Total Form Factor %d: %f\n", i, totalFormFactori[i]);
                //printf("JPoint: (%f %f %f)\tHitPoint: (%f %f %f)\tSame: %d\n", point2.x, point2.y, point2.z, hitPoint.x, hitPoint.y, hitPoint.z, comparePoints(point2, hitPoint));
                
            }
            
            //printf("FormFactor(%d, %d): %f\n", i, j, formFactorTemp);
            setFormFactor(i, j, formFactorTemp);
            totalFormFactori[i]+= formFactorTemp;
            
            //cast n rays from patch 1 to patch 2 and see how many are occluded
            //integrate point to point form factor Cos(thetaI)*Cos(thetaJ)/PI*|R|^2
            //this will use getFace[i].getRandomPoint()
            
            
            //for testing purposes we are gonna use the centers of the faces to start
            
        }
        //printf("Total Form Factor %d: %f\n", i, totalFormFactori[i]);
    }
    
    //SUM ALL UNDISTRIBUTED EVERY ITERATION***********************************************************************
    
    


}
コード例 #4
0
void Radiosity::ComputeFormFactors() {
  assert (formfactors == NULL);
  assert (num_faces > 0);
  formfactors = new float[num_faces*num_faces];


  // =====================================
  // ASSIGNMENT:  COMPUTE THE FORM FACTORS
  // =====================================

  //num_patches * num_patches = total number of subdivided areas for FF
  int num_patches = 9;

  //THIRD ATTEMPT
  for (int i = 0; i < num_faces; i++)
  {
	  float FFsum = 0;

	  for (int j = 0; j < num_faces; j++)
	  {
		  //std::cout << i << "\n";
		  //If it is the same face, FF = 0
		  if (i != j)
		  {
			  Face* iface = this->getMesh()->getFace(i);
			  Face* jface = this->getMesh()->getFace(j);
			  //Variables needed for subdivision of patches
			  //A is the starting corner of the patch, xvec is the length of one side of the patch
			  /*glm::vec3 iA, ixvec, iyvec;// , jA, jxvec, jyvec;
			  iA = (*iface)[0]->get();
			  ixvec = (*iface)[1]->get() - iA;
			  ixvec /= num_patches;
			  iyvec = (*iface)[3]->get() - iA;
			  iyvec /= num_patches;*/

			  //Normals of respective surfaces
			  glm::vec3 inormal = (*iface).computeNormal();
			  glm::vec3 jnormal = (*jface).computeNormal();

			  glm::vec3 ipoint = (*iface).computeCentroid();
			  glm::vec3 jpoint = (*jface).computeCentroid();
			  
			  //Ray from j to i
			  glm::vec3 ray = ipoint - jpoint;

			  float FFanswer = 0;

			  //Check for occlusion
			  Ray r(jpoint, ray);
			  Hit vhit = Hit();
			  raytracer->CastRay(r, vhit, false);
			  if (args->num_shadow_samples > 0 && vhit.getT() < glm::length(ray) * .95f)
			  {
				  //Occlusion
				  FFanswer = 0;
			  }
			  else
			  {
				  //Calculate Cos() for i and j, reversing the ray for i for angle calculation
				  float icos = glm::dot(inormal, -ray) / (glm::length(inormal) * glm::length(ray));
				  float jcos = glm::dot(jnormal, ray) / (glm::length(jnormal) * glm::length(ray));
				  //std::cout << glm::length(jnormal) << "\n";
				  //Calculate divisor for FF equation
				  float divisor = 3.14159 * glm::length(ray) * glm::length(ray);
				  FFanswer = (icos*jcos) / divisor;
				  FFanswer /= (*iface).getArea();
			  }
			  
			  FFsum += FFanswer;

			setFormFactor(i, j, FFanswer);
			  
			  
		  }
		  else
		  {
			  setFormFactor(i, j, 0);
			  //std::cout << "Face[" << i << "]: " << "0" << "\n";
		  }
		  
	  }
	  //std::cout << "Face[" << i << "] FFsum: " << FFsum << "\n";
	  float sumfix;
	  if (FFsum != 0)
	  {
		  sumfix = 1 / FFsum;
		  float Newsum = 0;
		  for (int j = 0; j < num_faces; j++)
		  {
			  float ff = getFormFactor(i, j);
			  ff *= sumfix;
			  //std::cout << ff << "\n";
			  setFormFactor(i, j, ff);
			  Newsum += ff;
		  }
		  //std::cout << "Face[" << i << "] Newsum: " << Newsum << "\n";
	  }
  }
}