Exemplo n.º 1
0
//------------------------------------------------------------------------------
void calc_specular(GzRender *render, GzCoord N_orig, GzColor col, bool mulByK) {
    // N is already sent here after transformation
    GzCoord N = {0.0f,0.0f,0.0f};
    normalizeVector(N_orig, N);
    
    GzCoord AccumulatedSpecResult = {0.0f, 0.0f, 0.0f};
 
    for(int i = 0; i < render->numlights; i++)
    {
        float (*ls)[3] = static_cast<float (*)[3]>(render->lights[i]);
        GzCoord ls_L_orig = {ls[0][0], ls[0][1], ls[0][2]};       
        GzCoord E = {0, 0, -1};        
        
        GzCoord ls_L = {0.0f,0.0f,0.0f};
        normalizeVector(ls_L_orig, ls_L);   
        


        if (!shouldCalcLight(N, ls_L, E, N))
            continue;
        
        
        
        float N_dot_L = vectorDotProduct(N, ls_L);
        GzCoord left = {0.0f,0.0f,0.0f};
        scalarMultiply(N, N_dot_L * 2.0f, left);
        GzCoord R_orig = {0.0f,0.0f,0.0f};
        subtractVector(left, ls_L, R_orig);
        GzCoord R = {0.0f,0.0f,0.0f};
        normalizeVector(R_orig, R);
        
        GzCoord ls_intensity = {ls[1][0], ls[1][1], ls[1][2]};
        
        
        GzCoord localResult = {0.0f,0.0f,0.0f};
        
        float RdotE = vectorDotProduct(R,E);
        if (RdotE < 0) RdotE = 0;
        if (RdotE > 1) RdotE = 1;
        
        scalarMultiply(ls_intensity, 
                       powf(RdotE, render->spec), 
                       localResult);
        
        addVectors(localResult, AccumulatedSpecResult, AccumulatedSpecResult);        
    }
    
     
    if(mulByK)
        vectorMulElementByElement(render->Ks, AccumulatedSpecResult, col);
    else
    {
        col[RED]   = AccumulatedSpecResult[RED];
        col[GREEN] = AccumulatedSpecResult[GREEN];
        col[BLUE]  = AccumulatedSpecResult[BLUE];
        
    }
}
Exemplo n.º 2
0
// Shifted Schwefel’s problem 1.2: F2 from [43]
double f2(double *x) {
	double f = 0;
	double z[n];
	subtractVector(x, O, z);
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= i; j++)
			f += z[j] * z[j];
	
	return f;
}
Exemplo n.º 3
0
// Shifted rotated Rastrigin’s function: F10 from [43]
double f9(double *x) {
	double f = 0;
	double z[n];
	double tmp[n];
	subtractVector(x, O, tmp);
	multiplyMatrix(tmp, A, z);
	
	for (int i = 0; i < n; i++)
		f += z[i]*z[i] - 10*cos(2 * M_PI * z[i]) + 10;
	
	return f;
}
Exemplo n.º 4
0
// Shifted rotated Weierstrass function: F11 from [43]
double f19(double *x) {
	double f = 0;
	double a = 0.5;
	double b = 3.0;
	double z[n];
	double tmp[n];
	int kmax = 20;
	
	subtractVector(x, O, tmp);
	multiplyMatrix(tmp, A, z);
	f = weierstrass(z);
	for (int k = 0; k <= kmax; k++)
		f -= n * pow(a, k) * cos(2 * M_PI * pow(b, k) * 0.5);
	
	return f;
}
/** Add a list of spectra (detector IDs) to the output table workspace.
  * If a detector is masked in input MaskTableWorkspace, then it will not be
 * added to a new row
  * @param outws :: table workspace to write
  * @param maskeddetids :: vector of detector IDs of which detectors masked
  * @param xmin :: minumim x
  * @param xmax :: maximum x
  * @param prevmaskedids :: vector of previous masked detector IDs
  */
void ExtractMaskToTable::addToTableWorkspace(TableWorkspace_sptr outws,
                                             vector<detid_t> maskeddetids,
                                             double xmin, double xmax,
                                             vector<detid_t> prevmaskedids) {
  // Sort vector of detectors ID
  size_t numdetids = maskeddetids.size();
  if (numdetids == 0) {
    stringstream warnss;
    warnss << "Attempting to add an empty vector of masked detectors IDs to "
              "output workspace.  Operation failed.";
    g_log.warning(warnss.str());
    return;
  } else {
    sort(maskeddetids.begin(), maskeddetids.end());
  }

  // Exclude previously masked detectors IDs from masked detectors IDs
  if (prevmaskedids.size() > 0) {
    sort(prevmaskedids.begin(), prevmaskedids.end());
    maskeddetids = subtractVector(maskeddetids, prevmaskedids);
    numdetids = maskeddetids.size();
  } else {
    g_log.debug() << "[DB] There is no previously masked detectors."
                  << ".\n";
  }

  if (numdetids == 0) {
    // I don't know what should be done here
    throw std::runtime_error("Empty detector ID list");
  }

  // Convert vector to string
  stringstream spectralist;
  detid_t previd = maskeddetids[0];
  detid_t headid = maskeddetids[0];
  for (size_t i = 1; i < numdetids; ++i) {
    detid_t tmpid = maskeddetids[i];
    if (tmpid == previd + 1) {
      // Continuous ID
      previd = tmpid;
    } else if (tmpid > previd + 1) {
      // Skipped ID: make a pair
      if (previd == headid) {
        // Single item
        spectralist << " " << headid << ", ";
      } else {
        // Multiple items
        spectralist << " " << headid << "-" << previd << ", ";
      }

      // New head
      headid = tmpid;
      previd = tmpid;
    } else {
      g_log.error() << "Current ID = " << tmpid << ", Previous ID = " << previd
                    << ", Head ID = " << headid << ".\n";
      throw runtime_error("Impossible!  Programming logic error!");
    }
  } // ENDFOR (i)

  // Last one
  if (previd == headid)
    spectralist << " " << headid;
  else
    spectralist << " " << headid << "-" << previd;

  // Add to table workspace
  string specliststr = spectralist.str();
  TableRow newrow = outws->appendRow();
  newrow << xmin << xmax << specliststr;

  return;
}
Exemplo n.º 6
0
// Shifted Rastrigin’s function: F9 from [43]
double f8(double *x) {
	double z[n];
	subtractVector(x, O, z);
	
	return rastrigins(z);
}
Exemplo n.º 7
0
// Shifted sphere function: F1 from [43]
double f1(double *x) {
	double z[n];
	subtractVector(x, O, z);
	
	return sphere(z);
}