void processCell(Expression &expr, double x, double y, double xLen, double yLen, std::vector<sf::Vertex> &Curve) { double a, b, c, d; a = expr.evaluate(x, -y); b = expr.evaluate(x + xLen, -y); c = expr.evaluate(x + xLen, -y - yLen); d = expr.evaluate(x, -y - yLen); int num = ((a > 0.0) ? 1 : 0) + ((b > 0.0) ? 2 : 0) + ((c < 0.0) ? 4 : 0) + ((d > 0.0) ? 8 : 0); switch(num) { case 1: case 2: case 4: case 7: case 8: case 11: case 13: case 14: case 3: case 6: case 12: case 9: draw(num, x, y, xLen, yLen, a, b, c, d, Curve); // std::cout<<"["<<x<<","<<y<<","<<num<<"]\t"; break; case 5: case 10: std::cout << "Recursion Happens\n"; processCell(expr, x, y, xLen / 2, yLen / 2, Curve); processCell(expr, x + xLen / 2, y, xLen / 2, yLen / 2, Curve); processCell(expr, x + xLen / 2, y + yLen / 2, xLen / 2, yLen / 2, Curve); processCell(expr, x, y + xLen / 2, xLen / 2, yLen / 2, Curve); break; case 0: case 15: break; } }
/* Function that iterates through the matrix * Each thread locks the lines it's going to process * Calls the processCell funtion on each cell * board, the current board */ void iterateBoard(board_t* board){ int heightLength = board->height + 1; int widthLength = board->width + 1; size_t i, j; #pragma omp parallel private(i,j) shared(board) { #pragma omp for schedule(static, 1) for (i = 0; i < heightLength; ++i) { lockLine(i, board); } #pragma omp barrier #pragma omp for schedule(static, 1) for (i = 0; i < heightLength; ++i) { for (j = 0; j < widthLength; ++j) { processCell(i, j, board); } } } }
void plotFunc(Expression &expr, sf::RenderWindow& window) { std::vector<sf::Vertex> Curve; sf::View view = window.getView(); float Left = view.getCenter().x - view.getSize().x / 2; float Right = view.getCenter().x + view.getSize().x / 2; float Top = view.getCenter().y - view.getSize().y / 2; float Bottom = view.getCenter().y + view.getSize().y / 2; float xDel = xSep / 20, yDel = ySep / 20; Right += xDel; Bottom += yDel; for(double x = Left - fmod(Left, xDel) - xDel; x < Right ; x += xDel) { for(double y = Top - fmod(Top, yDel) - yDel; y > Bottom; y += yDel) { processCell(expr, x, y, xDel, yDel, Curve); // text.setPosition(x,y); // text.setScale(view.getSize().x/window.getSize().x,view.getSize().y/window.getSize().y); // text.setString(to_string(expr.evaluate(x,y))); // window.draw(text); } } window.draw(&Curve[0], Curve.size(), sf::Lines); }
void parse_item(bool capture, std::string pinName, AttributeList *attr) { while (tokval != "}" && !eof) { std::string paramname = tokval; validate_token(isId(tokval[0]), "name"); if (paramname == "default_intrinsic_fall" || paramname == "default_intrinsic_rise") { validate_token(tokval == ":", ":(paramname)"); if (capture) addAttr(attr, pinName, paramname, tokval); validate_token(isdigit(tokval[0]), "number"); } else if (paramname == "bus_type") { validate_token(tokval == ":", ":(bus_type)"); if (capture) addAttr(attr, pinName, paramname, tokval); validate_token(isId(tokval[0]), "name"); } else if (tokval == "(") { while (tokval == "(") { std::string paramstr = parseparam(); bool cell = paramname == "cell" && paramstr == options.cell; int ind = paramstr.find("["); if (capture && (paramname == "pin" || paramname == "bus")) { if (ind > 0 && paramstr[paramstr.length()-1] == ']') { std::string sub = paramstr.substr(ind+1); sub = sub.substr(0, sub.length()-1); paramstr = paramstr.substr(0, ind); capturePins[paramstr].pins[atol(sub.c_str())] = 1; } parse_item(true, paramstr, &capturePins[paramstr].attr); } else if (paramname == "type") { parse_item(true, "", &busInfo[paramstr].attr); } else parse_item(capture || cell, pinName, attr); //if (paramname == "cell") //printf("[%s:%d] paramname %s paramstr %s \n", __FUNCTION__, __LINE__, paramname.c_str(), paramstr.c_str()); if (cell) { processCell(); return; } paramname = tokval; if (!isId(tokval[0])) break; parsenext(); } } else { validate_token(tokval == ":", ":(other)"); if (capture && paramname != "timing_type") addAttr(attr, pinName, paramname, tokval); if (isdigit(tokval[0]) || isId(tokval[0]) || tokval[0] == '"') parsenext(); else validate_token(false, "number or name or string"); if (tokval != "}") validate_token(tokval == ";", ";"); } } validate_token(tokval == "}", "}"); }