void QuatJulia::generate() { /// eval at uniform grid int i, j, k; const float grid = 1.f / (float)m_numGrid; const Vector3F origin(-.5f+grid * .5f, -.5f+grid * .5f, -.5f+grid * .5f); int n = 0; for(k=0; k<m_numGrid; ++k ) { for(j=0; j<m_numGrid; ++j ) { for(i=0; i<m_numGrid; ++i ) { Vector3F sample = origin + Vector3F(grid * i, grid * j, grid * k); if( evalAt( sample*3.2f ) > 0.f ) { n++; cvx::Sphere sp; sample *= m_scaling; sp.set(sample, .001f); m_tree->insert((const float *)&sample, sp); } } } } m_tree->finishInsert(); }
void DifferenceJob::run() { for(int y = y1; y < y2; y++) for(int x = x1; x < x2; x++) (*dst)[y][x] = evalAt(x,y); /* warning: thread-unsafe! */ if(progress_done) progress((*progress_done) += progress_step); }
void PolyModel::findMinimum(double mins[], double maxs[]) { const double learnRate = 0.001; const int numRestarts = 50; double *width = new double[numVars]; for (int i=0; i<numVars; i++) { assert (mins[i] <= maxs[i]); width[i] = maxs[i] - mins[i]; } double *pos = new double[numVars]; double *step = new double[numVars]; double valAtPos; argMin = new double[numVars]; double lowestVal; bool lowestValValid = false; for (int i=0; i<numRestarts; i++) { for (int j=0; j<numVars; j++) pos[j] = Param::DRand(mins[j], maxs[j]); valAtPos = evalAt(pos); bool done = false; while (!done) { for (int j=0; j<numVars; j++) { step[j] = -(derivAt(pos, j) * learnRate * width[j]); } for (int j=0; j<numVars; j++) { pos[j] += step[j]; if (pos[j] < mins[j]) pos[j] = mins[j]; else if (pos[j] > maxs[j]) pos[j] = maxs[j]; } double valAtLastPos = valAtPos; valAtPos = evalAt(pos); if (valAtPos >= valAtLastPos) done = true; } if (!lowestValValid || valAtPos < lowestVal) { for (int j=0; j<numVars; j++) argMin[j] = pos[j]; lowestVal = valAtPos; lowestValValid = true; } } minimumKnown = true; minimum = lowestVal; delete[] width; delete[] pos; delete[] step; }