/** * See the derivations of ΔA in SonntagUpdate.h * * @see SonntagUpdate.h */ float SonntagUpdate::calculateDeltaActivity() { const float A = currentState->activity; const float V = calculateV(); const float thetaC = parameters[DECAY_COMPETITION]; const float thetaL = parameters[DECAY_LOSS]; const float thetaA = parameters[ACTIVATION_DAMPENING]; // allow for manual input (CSV, GUI, etc) float I; if (currentState->manual_input > 0) { I = currentState->manual_input; } else { I = calculateInput(); } // equation 4.6, pg79 const float deltaA = (pow(A, thetaA) + I * (1 - A)) * (1 - A) * V - ((pow(A, thetaL) + A * pow((1 - A), thetaC))) * (1 - V); // wolfram input, x=A, y=I (no V term): // (x + y*(1-x)) * (1-x) - (x^5 + x * (1-x)^9) from x = 0 to x = 1, y= 0 to y = 1 #ifdef DEBUG_UPDATES printf("current A: %f\n", A); printf("current I: %f\n", I); printf("V term: %f\n", V); printf("deltaA: %f\n", deltaA); #endif return deltaA; }
//***************************************** // SDL Functions //***************************************** void init() { //Initialise SDL. if(SDL_Init(SDL_INIT_VIDEO) < 0) exit(1); //Use double buffering (24-bit). SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); //Set vertical sync. //SDL_GL_SetSwapInterval(1); //Create window. if (SDL_SetVideoMode(800, 800, 32, SDL_OPENGL) == 0) exit(1); SDL_WM_SetCaption("Primitives", "Primitives"); //Set up orthographic camera. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2, 2, -2, 2, 2, -2); glMatrixMode(GL_MODELVIEW); //Set the clear color. glClearColor(0, 0, 0, 1); //Use the z-buffer. glEnable(GL_DEPTH_TEST); //Use vertex and colour arrays. glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); //Calculate the vertex and colour data. calculateV(); calculateC(); }
STImage *FieldMorph(STImage *image, const std::vector<Feature> &sourceFeatures, const std::vector<Feature> &targetFeatures, float t, float a, float b, float p) { int width = image->GetWidth(); int height = image->GetHeight(); STImage *result = new STImage(width, height, STColor4ub(255,255,255,255)); std::vector<Feature> interpolatedFeatures = interpolateFeatures(sourceFeatures, targetFeatures, t); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { STVector2 dispSum = STVector2(0, 0); float weightsum = 0; STPoint2 X = STPoint2(x, y); int numFeatures = sourceFeatures.size(); for (int i = 0; i < numFeatures; i++) { STPoint2 Pp = sourceFeatures[i].P; STPoint2 Qp = sourceFeatures[i].Q; STPoint2 P = interpolatedFeatures[i].P; STPoint2 Q = interpolatedFeatures[i].Q; float u = calculateU(X, P, Q); float v = calculateV(X, P, Q); STPoint2 Xp = calculateXp(Pp, Qp, u, v); STVector2 displacement = STVector2(Xp) - STVector2(X); float dist = calculateDistance(X, P, Q, u, v); float weight = calculateWeight(Q, P, a, b, p, dist); dispSum += displacement * weight; weightsum += weight; } STPoint2 Xprime = X + dispSum/weightsum; result->SetPixel(x, y, interpolatedColor(Xprime, image)); } } return result; }