void Surf1D:: eval(int jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg >= 0 && (jg < firstPoint() - 2 || jg > lastPoint() + 2)) return; // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); doublereal *xb, *rb; r[0] = x[0] - m_temp; diag[0] = 0; int nc; if (m_flow_right) { rb = r + 1; xb = x + 1; rb[2] = xb[2] - x[0]; // specified T } if (m_flow_left) { nc = m_flow_left->nComponents(); rb = r - nc; xb = x - nc; rb[2] = xb[2] - x[0]; // specified T } }
bool Game::playerOutOfTrack( size_t num ) { Coordinates playersPreviousCoordinates = players[num].getPreviousPosition(); Coordinates playersCoordinates = players[num].getPosition(); int minX = std::min( playersPreviousCoordinates.x, playersCoordinates.x ), maxX = std::max( playersPreviousCoordinates.x, playersCoordinates.x ), minY = std::min( playersPreviousCoordinates.y, playersCoordinates.y ), maxY = std::max( playersPreviousCoordinates.y, playersCoordinates.y ); Coordinates realCoordinates( playersCoordinates.x * 10 + 5, playersCoordinates.y * 10 + 5 ), realPreviousCoordinates( playersPreviousCoordinates.x * 10 + 5, playersPreviousCoordinates.y * 10 + 5 ); for( int i = minX; i <= maxX; ++i ) { for( int j = minY; j <= maxY; ++j ) { if( map.isEmpty( i, j ) ) { continue; } Coordinates firstPoint( i * 10, j * 10 ), secondPoint( ( i + 1 ) * 10, j * 10 ), thirdPoint( ( i + 1 ) * 10, ( j + 1 ) * 10 ), fourthPoint( i * 10, ( j + 1 ) * 10 ); if( isIntersects( realPreviousCoordinates, realCoordinates, firstPoint, secondPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, secondPoint, thirdPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, thirdPoint, fourthPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, fourthPoint, firstPoint ) ) { return true; } } } return false; }
void CPowerupManager::handleWalls( CPlayer& player, std::set<CPlayer*>& crashedPlayers ) { CCoordinates playersPreviousCoordinates = player.GetPreviousPosition( ); CCoordinates playersCoordinates = player.GetPosition(); for( auto powerup : powerups ) { CCoordinates realCoordinates( playersCoordinates.y * 10 + 5, playersCoordinates.x * 10 + 5 ), realPreviousCoordinates( playersPreviousCoordinates.y * 10 + 5, playersPreviousCoordinates.x * 10 + 5 ); if( powerup.second != WALL ) { continue; } CCoordinates firstPoint( powerup.first.y * 10, powerup.first.x * 10 ), secondPoint( (powerup.first.y + 1) * 10, powerup.first.x * 10 ), thirdPoint( (powerup.first.y + 1) * 10, (powerup.first.x + 1) * 10 ), fourthPoint( powerup.first.y * 10, (powerup.first.x + 1) * 10 ); if( isIntersects( realPreviousCoordinates, realCoordinates, firstPoint, secondPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, secondPoint, thirdPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, thirdPoint, fourthPoint ) || isIntersects( realPreviousCoordinates, realCoordinates, fourthPoint, firstPoint ) ) { powerups.erase( powerup.first ); crashedPlayers.insert( &player ); return; } } }
bool Map::hasBarrierOnPath(int xFirst, int yFirst, int xSecond, int ySecond) const { int minX = std::min( xFirst, xSecond ), maxX = std::max( xFirst, xSecond ), minY = std::min( yFirst, ySecond ), maxY = std::max( yFirst, ySecond ); std::pair<int, int> prevCoordinates = std::make_pair( xFirst * 10 + 5, yFirst * 10 + 5 ); std::pair<int, int> curCoordinates = std::make_pair( xSecond * 10 + 5, ySecond * 10 + 5 ); for( int i = minX; i <= maxX; ++i ) { for( int j = minY; j <= maxY; ++j ) { if( cells[j][i] == 0 ) { continue; } std::pair<int, int> firstPoint( i * 10, j * 10 ), secondPoint( (i + 1) * 10, j * 10 ), thirdPoint( (i + 1) * 10, (j + 1) * 10 ), fourthPoint( i * 10, (j + 1) * 10 ); if( isIntersects( prevCoordinates, curCoordinates, firstPoint, secondPoint ) || isIntersects( prevCoordinates, curCoordinates, secondPoint, thirdPoint ) || isIntersects( prevCoordinates, curCoordinates, thirdPoint, fourthPoint ) || isIntersects( prevCoordinates, curCoordinates, fourthPoint, firstPoint ) ) { return true; } } } if( wrongFinishLineIntersection( xFirst, yFirst, xSecond, ySecond ) ) { return true; } return false; }
void Surf1D::eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); r[0] = x[0] - m_temp; diag[0] = 0; if (m_flow_right) { double* rb = r + 1; double* xb = x + 1; rb[2] = xb[2] - x[0]; // specified T } if (m_flow_left) { size_t nc = m_flow_left->nComponents(); double* rb = r - nc; double* xb = x - nc; rb[2] = xb[2] - x[0]; // specified T } }
void OutletRes1D:: eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); doublereal* xb, *rb; integer* db; // drive dummy component to zero r[0] = x[0]; diag[0] = 0; size_t nc, k; if (m_flow_right) { nc = m_flow_right->nComponents(); xb = x + 1; rb = r + 1; db = diag + 1; // this seems wrong... // zero Lambda rb[0] = xb[3]; // zero gradient for T rb[2] = xb[2] - xb[2 + nc]; // specified mass fractions for (k = 4; k < nc; k++) { rb[k] = xb[k] - m_yres[k-4]; } } if (m_flow_left) { nc = m_flow_left->nComponents(); xb = x - nc; rb = r - nc; db = diag - nc; if (!m_flow_left->fixed_mdot()) { ; } else { rb[0] = xb[3]; // zero Lambda } rb[2] = xb[2] - m_temp; //xb[2] - xb[2 - nc]; // zero dT/dz for (k = 5; k < nc; k++) { rb[k] = xb[k] - m_yres[k-4]; // fixed Y db[k] = 0; } } }
void Domain1D:: eval(size_t jg, doublereal* xg, doublereal* rg, integer* mask, doublereal rdt) { if (jg != npos && (jg + 1 < firstPoint() || jg > lastPoint() + 1)) { return; } // if evaluating a Jacobian, compute the steady-state residual if (jg != npos) { rdt = 0.0; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* rsd = rg + loc(); integer* diag = mask + loc(); size_t jmin, jmax, jpt, j, i; jpt = jg - firstPoint(); if (jg == npos) { // evaluate all points jmin = 0; jmax = m_points - 1; } else { // evaluate points for Jacobian jmin = std::max<size_t>(jpt, 1) - 1; jmax = std::min(jpt+1,m_points-1); } for (j = jmin; j <= jmax; j++) { if (j == 0 || j == m_points - 1) { for (i = 0; i < m_nv; i++) { rsd[index(i,j)] = residual(x,i,j); diag[index(i,j)] = 0; } } else { for (i = 0; i < m_nv; i++) { rsd[index(i,j)] = residual(x,i,j) - timeDerivativeFlag(i)*rdt*(value(x,i,j) - prevSoln(i,j)); diag[index(i,j)] = timeDerivativeFlag(i); } } } }
void Outlet1D:: eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); doublereal* xb, *rb; integer* db; r[0] = x[0]; diag[0] = 0; size_t nc, k; if (m_flow_right) { nc = m_flow_right->nComponents(); xb = x + 1; rb = r + 1; db = diag + 1; rb[0] = xb[3]; rb[2] = xb[2] - xb[2 + nc]; for (k = 4; k < nc; k++) { //if (m_flow_right->doSpecies(k-4)) { rb[k] = xb[k] - xb[k + nc]; //} } } if (m_flow_left) { nc = m_flow_left->nComponents(); xb = x - nc; rb = r - nc; db = diag - nc; // zero Lambda if (!m_flow_left->fixed_mdot()) { ; // rb[0] = xb[0] - xb[0-nc]; //zero U gradient } else { rb[0] = xb[3]; // zero Lambda } rb[2] = xb[2] - xb[2 - nc]; // zero T gradient for (k = 5; k < nc; k++) { rb[k] = xb[k] - xb[k - nc]; // zero mass fraction gradient db[k] = 0; } } }
void Empty1D:: eval(int jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg >= 0 && (jg < firstPoint() - 2 || jg > lastPoint() + 2)) return; // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); // integer *db; r[0] = x[0]; diag[0] = 0; }
void TestSnapStrategy::testExtensionSnap() { //bool ExtensionSnapStrategy::snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) ExtensionSnapStrategy toTest; const QPointF paramMousePos; MockShapeController fakeShapeControllerBase; MockCanvas fakeKoCanvasBase(&fakeShapeControllerBase); KoSnapGuide aKoSnapGuide(&fakeKoCanvasBase); KoSnapProxy paramProxy(&aKoSnapGuide); qreal paramSnapDistance = 0; bool didSnap = toTest.snap(paramMousePos, ¶mProxy, paramSnapDistance); QVERIFY(!didSnap); //Second test case - testing the snap by providing ShapeManager with a shape that has snap points and a path //fakeShapeOne needs at least one subpath that is open in order to change the values of minDistances //which in turn opens the path where it is possible to get a true bool value back from the snap function // KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex); in KoPathShape needs to be called ExtensionSnapStrategy toTestTwo; const QPointF paramMousePosTwo; MockShapeController fakeShapeControllerBaseTwo; MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo); KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager(); KoPathShape fakeShapeOne; QList<QPointF> firstSnapPointList; firstSnapPointList.push_back(QPointF(1,2)); firstSnapPointList.push_back(QPointF(2,2)); firstSnapPointList.push_back(QPointF(3,2)); firstSnapPointList.push_back(QPointF(4,2)); qreal paramSnapDistanceTwo = 4; fakeShapeOne.snapData().setSnapPoints(firstSnapPointList); fakeShapeOne.isVisible(true); QPointF firstPoint(0,2); QPointF secondPoint(1,2); QPointF thirdPoint(2,3); QPointF fourthPoint(3,4); fakeShapeOne.moveTo(firstPoint); fakeShapeOne.lineTo(secondPoint); fakeShapeOne.lineTo(thirdPoint); fakeShapeOne.lineTo(fourthPoint); fakeShapeManager->addShape(&fakeShapeOne); KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo); KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo); bool didSnapTwo = toTest.snap(paramMousePosTwo, ¶mProxyTwo, paramSnapDistanceTwo); QVERIFY(didSnapTwo); }
void Empty1D::eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); r[0] = x[0]; diag[0] = 0; }
void Outlet1D::eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); r[0] = x[0]; diag[0] = 0; if (m_flow_right) { size_t nc = m_flow_right->nComponents(); double* xb = x + 1; double* rb = r + 1; rb[0] = xb[3]; rb[2] = xb[2] - xb[2 + nc]; for (size_t k = 4; k < nc; k++) { rb[k] = xb[k] - xb[k + nc]; } } if (m_flow_left) { size_t nc = m_flow_left->nComponents(); double* xb = x - nc; double* rb = r - nc; int* db = diag - nc; // zero Lambda if (m_flow_left->fixed_mdot()) { rb[0] = xb[3]; } rb[2] = xb[2] - xb[2 - nc]; // zero T gradient size_t kSkip = 4 + m_flow_left->rightExcessSpecies(); for (size_t k = 4; k < nc; k++) { if (k != kSkip) { rb[k] = xb[k] - xb[k - nc]; // zero mass fraction gradient db[k] = 0; } } } }
void TestSnapStrategy::testExtensionDecoration() { //Tests the decoration is exercised by providing it with path //fakeShapeOne needs at least one subpath that is open in order to change the values of minDistances //which in turn opens the path where it is possible to get a true bool value back from the snap function // KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex); in KoPathShape needs to be called ExtensionSnapStrategy toTestTwo; const QPointF paramMousePosTwo; MockShapeController fakeShapeControllerBaseTwo; MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo); KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager(); KoPathShape fakeShapeOne; QList<QPointF> firstSnapPointList; firstSnapPointList.push_back(QPointF(1,2)); firstSnapPointList.push_back(QPointF(2,2)); firstSnapPointList.push_back(QPointF(3,2)); firstSnapPointList.push_back(QPointF(4,2)); qreal paramSnapDistanceTwo = 4; fakeShapeOne.snapData().setSnapPoints(firstSnapPointList); fakeShapeOne.isVisible(true); QPointF firstPoint(0,2); QPointF secondPoint(1,2); QPointF thirdPoint(2,3); QPointF fourthPoint(3,4); fakeShapeOne.moveTo(firstPoint); fakeShapeOne.lineTo(secondPoint); fakeShapeOne.lineTo(thirdPoint); fakeShapeOne.lineTo(fourthPoint); fakeShapeManager->addShape(&fakeShapeOne); KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo); KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo); toTestTwo.snap(paramMousePosTwo, ¶mProxyTwo, paramSnapDistanceTwo); const KoViewConverter aConverter; QPainterPath resultingDecoration = toTestTwo.decoration(aConverter); QPointF resultDecorationLastPoint = resultingDecoration.currentPosition(); QVERIFY( resultDecorationLastPoint == QPointF(0,2) ); }
void Symm1D:: eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2< firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); doublereal* xb, *rb; integer* db; r[0] = x[0]; diag[0] = 0; size_t nc; if (m_flow_right) { nc = m_flow_right->nComponents(); xb = x + 1; rb = r + 1; db = diag + 1; db[1] = 0; db[2] = 0; rb[1] = xb[1] - xb[1 + nc]; // zero dV/dz rb[2] = xb[2] - xb[2 + nc]; // zero dT/dz } if (m_flow_left) { nc = m_flow_left->nComponents(); xb = x - nc; rb = r - nc; db = diag - nc; db[1] = 0; db[2] = 0; rb[1] = xb[1] - xb[1 - nc]; // zero dV/dz rb[2] = xb[2] - xb[2 - nc]; // zero dT/dz } }
void UBEditableGraphicsPolygonItem::setClosed(bool closed) { mClosed = closed; QPainterPath painterPath = path(); if (closed) { painterPath.closeSubpath(); // Automatically add a last point, identic to the first point. } else { // if last point and first point are the same, remove the last one, in order to open the path. int nbElements = painterPath.elementCount(); if ( nbElements > 1) { QPainterPath::Element firstElement = painterPath.elementAt(0); QPainterPath::Element lastElement = painterPath.elementAt(nbElements - 1); QPointF firstPoint(firstElement.x, firstElement.y); QPointF lastPoint(lastElement.x, lastElement.y); if (firstPoint == lastPoint) { // Rebuild the path, excluding the last point. QPainterPath newPainterPath(firstPoint); for(int iElement=1; iElement<nbElements - 1; iElement++) { newPainterPath.lineTo(painterPath.elementAt(iElement)); } painterPath = newPainterPath; } } } setPath(painterPath); mIsInCreationMode = false; }
void BlockLocalizer::FindRight() { cv::Point firstPoint(uppoints[uppoints.size() - 1].x, uppoints[uppoints.size() - 1].y + 100); //先查找第一个点 if (1 == 1) { int x = -1; int startX = img.cols - 1; while (x == -1 && startX > firstPoint.x - RANGE_DEFAULT) { x = getXOnRow(cv::Point(startX, firstPoint.y), RANGE_DEFAULT, false); startX -= RANGE_DEFAULT / 2; } if (x == -1) return; else firstPoint.x = x; } rightpoints.push_back(firstPoint); int centerX = firstPoint.x; int lastX = firstPoint.x; int range = RANGE_DEFAULT; bool needReFind = false;//对该行是否需要扩大range重新搜索 int notfoundCount = 0;//未找到点次数 //扫描其他点,左往右 for (int y = firstPoint.y + ROW_SPAN; (y) < img.rows; y += ROW_SPAN) { int x = getXOnRow(cv::Point(centerX, y), range, false); if (x >= 0) { rightpoints.push_back(cv::Point(x, y)); //匀速模型预测下一个点的y坐标 centerX = x + x - lastX; if (lastX < 0) lastX = 0; if (lastX >= img.cols) lastX = img.cols - 1; lastX = x; if (!needReFind) needReFind = true; if (range > RANGE_MINI) range -= (RANGE_DEFAULT - RANGE_MINI) / 3; if (range < RANGE_MINI) range = RANGE_MINI; } else if (needReFind)//是否要重新扫描改行 { range = RANGE_DEFAULT; y -= ROW_SPAN; needReFind = false; } else { notfoundCount++; if (notfoundCount >= 3) break; } if ((y + ROW_SPAN) >= img.rows && y != (img.rows - 1))// y = img.rows - ROW_SPAN - 1; } std::sort(rightpoints.begin(), rightpoints.end(), ORDER_BY_Y_ASC); std::unique(rightpoints.begin(), rightpoints.end()); #ifdef BL_OUTPUT_DEBUG_INFO //debug绘图 for (int i = 0; i < rightpoints.size(); i++) { cv::circle(drowDebugDetectLR, rightpoints[i], 1, cv::Scalar(255, 255, 0), -1); } #endif //needReFind = 0; }
void Inlet1D::eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); // residual equations for the two local variables r[0] = m_mdot - x[0]; // Temperature r[1] = m_temp - x[1]; // both are algebraic constraints diag[0] = 0; diag[1] = 0; // if it is a left inlet, then the flow solution vector // starts 2 to the right in the global solution vector if (m_ilr == LeftInlet) { double* xb = x + 2; double* rb = r + 2; // The first flow residual is for u. This, however, is not modified by // the inlet, since this is set within the flow domain from the // continuity equation. // spreading rate. The flow domain sets this to V(0), // so for finite spreading rate subtract m_V0. rb[1] -= m_V0; // The third flow residual is for T, where it is set to T(0). Subtract // the local temperature to hold the flow T to the inlet T. rb[2] -= x[1]; // The flow domain sets this to -rho*u. Add mdot to specify the mass // flow rate. rb[3] += x[0]; // add the convective term to the species residual equations for (size_t k = 0; k < m_nsp; k++) { if (k != m_flow_right->leftExcessSpecies()) { rb[4+k] += x[0]*m_yin[k]; } } // if the flow is a freely-propagating flame, mdot is not specified. // Set mdot equal to rho*u, and also set lambda to zero. if (!m_flow->fixed_mdot()) { m_mdot = m_flow->density(0)*xb[0]; r[0] = m_mdot - x[0]; rb[3] = xb[3]; } } else { // right inlet. size_t boffset = m_flow->nComponents(); double* rb = r - boffset; rb[1] -= m_V0; rb[2] -= x[1]; // T rb[0] += x[0]; // u for (size_t k = 0; k < m_nsp; k++) { if (k != m_flow_left->rightExcessSpecies()) { rb[4+k] += x[0]*m_yin[k]; } } } }
void Circle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); if (alpha == 0.0) { return; // do nothing if our alpha is 0, we're not visible } const float FULL_CIRCLE = 360.0f; const float SLICES = 180.0f; // The amount of segment to create the circle const float SLICE_ANGLE = FULL_CIRCLE / SLICES; //const int slices = 15; xColor color = getColor(); const float MAX_COLOR = 255.0f; glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glDisable(GL_LIGHTING); glm::vec3 position = getPosition(); glm::vec3 center = getCenter(); glm::vec2 dimensions = getDimensions(); glm::quat rotation = getRotation(); float glowLevel = getGlowLevel(); Glower* glower = NULL; if (glowLevel > 0.0f) { glower = new Glower(glowLevel); } glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glPushMatrix(); glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, 1.0f); // Create the circle in the coordinates origin float outerRadius = getOuterRadius(); float innerRadius = getInnerRadius(); // only used in solid case float startAt = getStartAt(); float endAt = getEndAt(); glLineWidth(_lineWidth); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getIsSolid()) { glBegin(GL_QUAD_STRIP); float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); glVertex2f(firstInnerPoint.x, firstInnerPoint.y); glVertex2f(firstOuterPoint.x, firstOuterPoint.y); while (angle < endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); glVertex2f(thisOuterPoint.x, thisOuterPoint.y); glVertex2f(thisInnerPoint.x, thisInnerPoint.y); angle += SLICE_ANGLE; } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); glVertex2f(lastOuterPoint.x, lastOuterPoint.y); glVertex2f(lastInnerPoint.x, lastInnerPoint.y); glEnd(); } else { if (getIsDashedLine()) { glBegin(GL_LINES); } else { glBegin(GL_LINE_STRIP); } float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); glVertex2f(firstPoint.x, firstPoint.y); while (angle < endAt) { angle += SLICE_ANGLE; angleInRadians = glm::radians(angle); glm::vec2 thisPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); glVertex2f(thisPoint.x, thisPoint.y); if (getIsDashedLine()) { angle += SLICE_ANGLE / 2.0f; // short gap angleInRadians = glm::radians(angle); glm::vec2 dashStartPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); glVertex2f(dashStartPoint.x, dashStartPoint.y); } } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); glVertex2f(lastOuterPoint.x, lastOuterPoint.y); glEnd(); } // draw our tick marks // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getHasTickMarks()) { glBegin(GL_LINES); // draw our major tick marks if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) { xColor color = getMajorTickMarksColor(); glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); float tickMarkAngle = getMajorTickMarksAngle(); float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMajorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); glVertex2f(thisPointA.x, thisPointA.y); glVertex2f(thisPointB.x, thisPointB.y); angle += tickMarkAngle; } } // draw our minor tick marks if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) { xColor color = getMinorTickMarksColor(); glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); float tickMarkAngle = getMinorTickMarksAngle(); float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMinorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); glVertex2f(thisPointA.x, thisPointA.y); glVertex2f(thisPointB.x, thisPointB.y); angle += tickMarkAngle; } } glEnd(); } glPopMatrix(); glPopMatrix(); if (glower) { delete glower; } }
std::vector<IntrestingPoint> DescriptorConstructor::orientPoints(std::vector<IntrestingPoint> inputPoints) { std::vector<IntrestingPoint> orientPoints; for(int index = 0; index < inputPoints.size(); index++) { const int localBinCount = 36; double localBinSize = 360.0 / localBinCount; int radius = 8; radius *= inputPoints.at(index).getSigma(); double localBin[localBinCount]; std::fill(std::begin (localBin), std::end (localBin), 0); for(int i = -radius; i < radius; i++){ for(int j = -radius; j < radius; j++){ //В пределах ? if(ImageUtils::getDistance((double)i,0.0,(double)j,0.0) < sqrt(pow(radius,2) + pow(radius,2))){ //Направление Фи double localPfi = directionFi.getPixel(inputPoints.at(index).getX() + i, inputPoints.at(index).getY() + j); //Номер корзины int binNumber = (localPfi / localBinSize + 0.5); //Раскидываем по корзинам double localBinCenter = (double)binNumber * localBinSize + localBinSize / 2.0; int relatedBin; if(localPfi < localBinCenter) relatedBin = binNumber - 1; else relatedBin = binNumber + 1; double thisCenterDistance = abs(localBinCenter - localPfi); double relatedCenterDistance = localBinSize - thisCenterDistance; localBin[binNumber] += level.getPixel(inputPoints.at(index).getX() + i, inputPoints.at(index).getY() + j) * (1 - thisCenterDistance / localBinSize); localBin[relatedBin] += level.getPixel(inputPoints.at(index).getX() + i, inputPoints.at(index).getY() + j) * (1 - relatedCenterDistance / localBinSize); } } } double firstMaxValue = -1; int firstMaxValueIndex = -1; double secondMaxValue = -1; int secondMaxValueIndex = -1; //Нашли первую и вторую максимальную for(int i = 0; i < localBinCount; i++){ if(localBin[i] > firstMaxValue){ secondMaxValue = firstMaxValue; secondMaxValueIndex = firstMaxValueIndex; firstMaxValue = localBin[i]; firstMaxValueIndex = i; } else { if(localBin[i] > secondMaxValue){ secondMaxValue = localBin[i]; secondMaxValueIndex = i; } } } //добавили первую IntrestingPoint firstPoint(inputPoints.at(index)); firstPoint.setAngle((double)firstMaxValueIndex * localBinSize); orientPoints.push_back(firstPoint); // printf("IP MAX FIRST %d\n", firstMaxValueIndex); //если вторая >= 0.8 от первой, то добваляем то же if(secondMaxValue >= (firstMaxValue * 0.8)) { IntrestingPoint secondPoint(inputPoints.at(index)); secondPoint.setAngle((double)secondMaxValueIndex * localBinSize); orientPoints.push_back(secondPoint); // printf("IP MAX SECOND %d\n", secondMaxValueIndex); } } return orientPoints; }
void ReactingSurf1D:: eval(int jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg >= 0 && (jg < firstPoint() - 2 || jg > lastPoint() + 2)) return; // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); doublereal *xb, *rb; // specified surface temp r[0] = x[0] - m_temp; // set the coverages doublereal sum = 0.0; int k; for (k = 0; k < m_nsp; k++) { m_work[k] = x[k+1]; sum += x[k+1]; } m_sphase->setTemperature(x[0]); m_sphase->setCoverages(DATA_PTR(m_work)); //m_kin->advanceCoverages(1.0); //m_sphase->getCoverages(m_fixed_cov.begin()); // set the left gas state to the adjacent point int leftloc = 0, rightloc = 0; int pnt = 0; if (m_flow_left) { leftloc = m_flow_left->loc(); pnt = m_flow_left->nPoints() - 1; m_flow_left->setGas(xg + leftloc, pnt); } if (m_flow_right) { rightloc = m_flow_right->loc(); m_flow_right->setGas(xg + rightloc, 0); } m_kin->getNetProductionRates(DATA_PTR(m_work)); doublereal rs0 = 1.0/m_sphase->siteDensity(); //scale(m_work.begin(), m_work.end(), m_work.begin(), m_mult[0]); // bool enabled = true; int ioffset = m_kin->kineticsSpeciesIndex(0, m_surfindex); if (m_enabled) { doublereal maxx = -1.0; int imx = -1; for (k = 0; k < m_nsp; k++) { r[k+1] = m_work[k + ioffset] * m_sphase->size(k) * rs0; r[k+1] -= rdt*(x[k+1] - prevSoln(k+1,0)); diag[k+1] = 1; if (x[k+1] > maxx) { maxx = x[k+1]; imx = k+1; } } r[1] = 1.0 - sum; diag[1] = 0; } else { for (k = 0; k < m_nsp; k++) { r[k+1] = x[k+1] - m_fixed_cov[k]; diag[k+1] = 0; } } if (m_flow_right) { rb = r + 1; xb = x + 1; rb[2] = xb[2] - x[0]; // specified T } int nc; if (m_flow_left) { nc = m_flow_left->nComponents(); const doublereal* mwleft = DATA_PTR(m_phase_left->molecularWeights()); rb =r - nc; xb = x - nc; rb[2] = xb[2] - x[0]; // specified T for (int nl = 1; nl < m_left_nsp; nl++) { rb[4+nl] += m_work[nl]*mwleft[nl]; } } }
void TestSnapStrategy::testExtensionDirection() { /* TEST CASE 0 Supposed to return null */ ExtensionSnapStrategy toTestOne; KoPathShape uninitiatedPathShape; KoPathPoint::PointProperties normal = KoPathPoint::Normal; const QPointF initiatedPoint0(0,0); KoPathPoint initiatedPoint(&uninitiatedPathShape, initiatedPoint0, normal); QMatrix initiatedMatrixParam(1,1,1,1,1,1); const QTransform initiatedMatrix(initiatedMatrixParam); QPointF direction2 = toTestOne.extensionDirection( &initiatedPoint, initiatedMatrix); QVERIFY(direction2.isNull()); /* TEST CASE 1 tests a point that: - is the first in a subpath, - does not have the firstSubpath property set, - it has no activeControlPoint1, - is has no previous point = expected returning an empty QPointF */ ExtensionSnapStrategy toTestTwo; QPointF expectedPointTwo(0,0); KoPathShape shapeOne; QPointF firstPoint(0,1); QPointF secondPoint(1,2); QPointF thirdPoint(2,3); QPointF fourthPoint(3,4); shapeOne.moveTo(firstPoint); shapeOne.lineTo(secondPoint); shapeOne.lineTo(thirdPoint); shapeOne.lineTo(fourthPoint); QPointF paramPositionTwo(0,1); KoPathPoint paramPointTwo; paramPointTwo.setPoint(paramPositionTwo); paramPointTwo.setParent(&shapeOne); const QTransform paramTransMatrix(1,2,3,4,5,6); QPointF directionTwo = toTestTwo.extensionDirection( ¶mPointTwo, paramTransMatrix); QCOMPARE(directionTwo, expectedPointTwo); /* TEST CASE 2 tests a point that: - is the second in a subpath, - does not have the firstSubpath property set, - it has no activeControlPoint1, - is has a previous point = expected returning an */ ExtensionSnapStrategy toTestThree; QPointF expectedPointThree(0,0); QPointF paramPositionThree(1,1); KoPathPoint paramPointThree; paramPointThree.setPoint(paramPositionThree); paramPointThree.setParent(&shapeOne); QPointF directionThree = toTestThree.extensionDirection( ¶mPointThree, paramTransMatrix); QCOMPARE(directionThree, expectedPointThree); }
void Circle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); if (alpha == 0.0f) { return; // do nothing if our alpha is 0, we're not visible } bool geometryChanged = _dirty; _dirty = false; const float FULL_CIRCLE = 360.0f; const float SLICES = 180.0f; // The amount of segment to create the circle const float SLICE_ANGLE = FULL_CIRCLE / SLICES; const float MAX_COLOR = 255.0f; auto geometryCache = DependencyManager::get<GeometryCache>(); Q_ASSERT(args->_batch); auto& batch = *args->_batch; if (args->_pipeline) { batch.setPipeline(args->_pipeline->pipeline); } // FIXME: THe line width of _lineWidth is not supported anymore, we ll need a workaround auto transform = getTransform(); transform.postScale(glm::vec3(getDimensions(), 1.0f)); batch.setModelTransform(transform); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getIsSolid()) { if (!_quadVerticesID) { _quadVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> points; QVector<glm::vec4> colors; float pulseLevel = updatePulse(); vec4 pulseModifier = vec4(1); if (_alphaPulse != 0.0f) { pulseModifier.a = (_alphaPulse >= 0.0f) ? pulseLevel : (1.0f - pulseLevel); } if (_colorPulse != 0.0f) { float pulseValue = (_colorPulse >= 0.0f) ? pulseLevel : (1.0f - pulseLevel); pulseModifier = vec4(vec3(pulseValue), pulseModifier.a); } vec4 innerStartColor = vec4(toGlm(_innerStartColor), _innerStartAlpha) * pulseModifier; vec4 outerStartColor = vec4(toGlm(_outerStartColor), _outerStartAlpha) * pulseModifier; vec4 innerEndColor = vec4(toGlm(_innerEndColor), _innerEndAlpha) * pulseModifier; vec4 outerEndColor = vec4(toGlm(_outerEndColor), _outerEndAlpha) * pulseModifier; if (_innerRadius <= 0) { _solidPrimitive = gpu::TRIANGLE_FAN; points << vec2(); colors << innerStartColor; for (float angle = _startAt; angle <= _endAt; angle += SLICE_ANGLE) { float range = (angle - _startAt) / (_endAt - _startAt); float angleRadians = glm::radians(angle); points << glm::vec2(cosf(angleRadians) * _outerRadius, sinf(angleRadians) * _outerRadius); colors << glm::mix(outerStartColor, outerEndColor, range); } } else { _solidPrimitive = gpu::TRIANGLE_STRIP; for (float angle = _startAt; angle <= _endAt; angle += SLICE_ANGLE) { float range = (angle - _startAt) / (_endAt - _startAt); float angleRadians = glm::radians(angle); points << glm::vec2(cosf(angleRadians) * _innerRadius, sinf(angleRadians) * _innerRadius); colors << glm::mix(innerStartColor, innerEndColor, range); points << glm::vec2(cosf(angleRadians) * _outerRadius, sinf(angleRadians) * _outerRadius); colors << glm::mix(outerStartColor, outerEndColor, range); } } geometryCache->updateVertices(_quadVerticesID, points, colors); } geometryCache->renderVertices(batch, _solidPrimitive, _quadVerticesID); } else { if (!_lineVerticesID) { _lineVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> points; float angle = _startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstPoint(cosf(angleInRadians) * _outerRadius, sinf(angleInRadians) * _outerRadius); points << firstPoint; while (angle < _endAt) { angle += SLICE_ANGLE; angleInRadians = glm::radians(angle); glm::vec2 thisPoint(cosf(angleInRadians) * _outerRadius, sinf(angleInRadians) * _outerRadius); points << thisPoint; if (getIsDashedLine()) { angle += SLICE_ANGLE / 2.0f; // short gap angleInRadians = glm::radians(angle); glm::vec2 dashStartPoint(cosf(angleInRadians) * _outerRadius, sinf(angleInRadians) * _outerRadius); points << dashStartPoint; } } // get the last slice portion.... angle = _endAt; angleInRadians = glm::radians(angle); glm::vec2 lastPoint(cosf(angleInRadians) * _outerRadius, sinf(angleInRadians) * _outerRadius); points << lastPoint; geometryCache->updateVertices(_lineVerticesID, points, vec4(toGlm(getColor()), getAlpha())); } if (getIsDashedLine()) { geometryCache->renderVertices(batch, gpu::LINES, _lineVerticesID); } else { geometryCache->renderVertices(batch, gpu::LINE_STRIP, _lineVerticesID); } } // draw our tick marks // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getHasTickMarks()) { if (_majorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _majorTicksVerticesID = geometryCache->allocateID(); } if (_minorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _minorTicksVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> majorPoints; QVector<glm::vec2> minorPoints; // draw our major tick marks if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) { float tickMarkAngle = getMajorTickMarksAngle(); float angle = _startAt - fmodf(_startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMajorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? _innerRadius : _outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= _endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cosf(angleInRadians) * startRadius, sinf(angleInRadians) * startRadius); glm::vec2 thisPointB(cosf(angleInRadians) * endRadius, sinf(angleInRadians) * endRadius); majorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } // draw our minor tick marks if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) { float tickMarkAngle = getMinorTickMarksAngle(); float angle = _startAt - fmodf(_startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMinorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? _innerRadius : _outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= _endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cosf(angleInRadians) * startRadius, sinf(angleInRadians) * startRadius); glm::vec2 thisPointB(cosf(angleInRadians) * endRadius, sinf(angleInRadians) * endRadius); minorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } xColor majorColorX = getMajorTickMarksColor(); glm::vec4 majorColor(majorColorX.red / MAX_COLOR, majorColorX.green / MAX_COLOR, majorColorX.blue / MAX_COLOR, alpha); geometryCache->updateVertices(_majorTicksVerticesID, majorPoints, majorColor); xColor minorColorX = getMinorTickMarksColor(); glm::vec4 minorColor(minorColorX.red / MAX_COLOR, minorColorX.green / MAX_COLOR, minorColorX.blue / MAX_COLOR, alpha); geometryCache->updateVertices(_minorTicksVerticesID, minorPoints, minorColor); } geometryCache->renderVertices(batch, gpu::LINES, _majorTicksVerticesID); geometryCache->renderVertices(batch, gpu::LINES, _minorTicksVerticesID); } }
void Circle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); if (alpha == 0.0) { return; // do nothing if our alpha is 0, we're not visible } // Create the circle in the coordinates origin float outerRadius = getOuterRadius(); float innerRadius = getInnerRadius(); // only used in solid case float startAt = getStartAt(); float endAt = getEndAt(); bool geometryChanged = (startAt != _lastStartAt || endAt != _lastEndAt || innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius); const float FULL_CIRCLE = 360.0f; const float SLICES = 180.0f; // The amount of segment to create the circle const float SLICE_ANGLE = FULL_CIRCLE / SLICES; //const int slices = 15; xColor color = getColor(); const float MAX_COLOR = 255.0f; glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glDisable(GL_LIGHTING); glm::vec3 position = getPosition(); glm::vec3 center = getCenter(); glm::vec2 dimensions = getDimensions(); glm::quat rotation = getRotation(); float glowLevel = getGlowLevel(); Glower* glower = NULL; if (glowLevel > 0.0f) { glower = new Glower(glowLevel); } glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glPushMatrix(); glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, 1.0f); glLineWidth(_lineWidth); auto geometryCache = DependencyManager::get<GeometryCache>(); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getIsSolid()) { if (_quadVerticesID == GeometryCache::UNKNOWN_ID) { _quadVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> points; float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << firstInnerPoint << firstOuterPoint; while (angle < endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << thisOuterPoint << thisInnerPoint; angle += SLICE_ANGLE; } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << lastOuterPoint << lastInnerPoint; geometryCache->updateVertices(_quadVerticesID, points); } geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID); } else { if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { _lineVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> points; float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << firstPoint; while (angle < endAt) { angle += SLICE_ANGLE; angleInRadians = glm::radians(angle); glm::vec2 thisPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << thisPoint; if (getIsDashedLine()) { angle += SLICE_ANGLE / 2.0f; // short gap angleInRadians = glm::radians(angle); glm::vec2 dashStartPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << dashStartPoint; } } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << lastPoint; geometryCache->updateVertices(_lineVerticesID, points); } if (getIsDashedLine()) { geometryCache->renderVertices(GL_LINES, _lineVerticesID); } else { geometryCache->renderVertices(GL_LINE_STRIP, _lineVerticesID); } } // draw our tick marks // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getHasTickMarks()) { if (_majorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _majorTicksVerticesID = geometryCache->allocateID(); } if (_minorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _minorTicksVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> majorPoints; QVector<glm::vec2> minorPoints; // draw our major tick marks if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) { float tickMarkAngle = getMajorTickMarksAngle(); float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMajorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); majorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } // draw our minor tick marks if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) { float tickMarkAngle = getMinorTickMarksAngle(); float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMinorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); minorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } geometryCache->updateVertices(_majorTicksVerticesID, majorPoints); geometryCache->updateVertices(_minorTicksVerticesID, minorPoints); } xColor majorColor = getMajorTickMarksColor(); glColor4f(majorColor.red / MAX_COLOR, majorColor.green / MAX_COLOR, majorColor.blue / MAX_COLOR, alpha); geometryCache->renderVertices(GL_LINES, _majorTicksVerticesID); xColor minorColor = getMinorTickMarksColor(); glColor4f(minorColor.red / MAX_COLOR, minorColor.green / MAX_COLOR, minorColor.blue / MAX_COLOR, alpha); geometryCache->renderVertices(GL_LINES, _minorTicksVerticesID); } glPopMatrix(); glPopMatrix(); if (geometryChanged) { _lastStartAt = startAt; _lastEndAt = endAt; _lastInnerRadius = innerRadius; _lastOuterRadius = outerRadius; } if (glower) { delete glower; } }
void ReactingSurf1D::eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt) { if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) { return; } // start of local part of global arrays doublereal* x = xg + loc(); doublereal* r = rg + loc(); integer* diag = diagg + loc(); // specified surface temp r[0] = x[0] - m_temp; // set the coverages doublereal sum = 0.0; for (size_t k = 0; k < m_nsp; k++) { m_work[k] = x[k+1]; sum += x[k+1]; } m_sphase->setTemperature(x[0]); m_sphase->setCoveragesNoNorm(m_work.data()); // set the left gas state to the adjacent point size_t leftloc = 0, rightloc = 0; size_t pnt = 0; if (m_flow_left) { leftloc = m_flow_left->loc(); pnt = m_flow_left->nPoints() - 1; m_flow_left->setGas(xg + leftloc, pnt); } if (m_flow_right) { rightloc = m_flow_right->loc(); m_flow_right->setGas(xg + rightloc, 0); } m_kin->getNetProductionRates(m_work.data()); doublereal rs0 = 1.0/m_sphase->siteDensity(); size_t ioffset = m_kin->kineticsSpeciesIndex(0, m_surfindex); if (m_enabled) { doublereal maxx = -1.0; for (size_t k = 0; k < m_nsp; k++) { r[k+1] = m_work[k + ioffset] * m_sphase->size(k) * rs0; r[k+1] -= rdt*(x[k+1] - prevSoln(k+1,0)); diag[k+1] = 1; maxx = std::max(x[k+1], maxx); } r[1] = 1.0 - sum; diag[1] = 0; } else { for (size_t k = 0; k < m_nsp; k++) { r[k+1] = x[k+1] - m_fixed_cov[k]; diag[k+1] = 0; } } if (m_flow_right) { double* rb = r + 1; double* xb = x + 1; rb[2] = xb[2] - x[0]; // specified T } if (m_flow_left) { size_t nc = m_flow_left->nComponents(); const vector_fp& mwleft = m_phase_left->molecularWeights(); double* rb = r - nc; double* xb = x - nc; rb[2] = xb[2] - x[0]; // specified T size_t nSkip = m_flow_left->rightExcessSpecies(); for (size_t nl = 0; nl < m_left_nsp; nl++) { if (nl != nSkip) { rb[4+nl] += m_work[nl]*mwleft[nl]; } } } }
void BlockLocalizer::FindDown() { cv::Point firstPoint(leftpoints[leftpoints.size() - 1].x + 100, leftpoints[leftpoints.size() - 1].y); //先查找第一个点 if (1 == 1) { int y = -1; int startY = img.rows - 1; startY = (firstPoint.y + ROW_SPAN * 2) < startY ? (firstPoint.y - ROW_SPAN * 2) : startY; while (y == -1 && startY > firstPoint.y - RANGE_DEFAULT) { y = getYOnLine(cv::Point(firstPoint.x, startY), RANGE_DEFAULT, false); startY -= RANGE_DEFAULT / 2; } if (y == -1) return; else firstPoint.y = y; } downpoints.push_back(firstPoint); int centerY = firstPoint.y; int lastY = firstPoint.y; int range = RANGE_DEFAULT; bool needReFind = false;//对该行是否需要扩大range重新搜索 int notfoundCount = 0;//未找到点次数 //扫描其他点,左往右 for (int x = firstPoint.x; (x + COL_SPAN) < img.cols; x += COL_SPAN) { int y = getYOnLine(cv::Point(x, centerY), range, false); if (y >= 0) { downpoints.push_back(cv::Point(x, y)); //匀速模型预测下一个点的y坐标 centerY = y + y - lastY; if (centerY < 0) centerY = 0; if (centerY >= img.rows) centerY = img.rows - 1; lastY = y; if (!needReFind) needReFind = true; if (range > RANGE_MINI) range -= (RANGE_DEFAULT - RANGE_MINI) / 3; if (range < RANGE_MINI) range = RANGE_MINI; } else if (needReFind)//是否要重新扫描改行 { range = RANGE_DEFAULT; x -= COL_SPAN; needReFind = false; } else { notfoundCount++; if (notfoundCount >= 3) break; } } std::sort(downpoints.begin(), downpoints.end(), ORDER_BY_X_ASC); std::unique(downpoints.begin(), downpoints.end()); #ifdef BL_OUTPUT_DEBUG_INFO //debug绘图 for (int i = 0; i < downpoints.size(); i++) { cv::circle(drowDebugDetectUD, downpoints[i], 4, cv::Scalar(255, 255, 0), -1); } #endif }
void BlockLocalizer::FindUp() { cv::Point firstPoint(2048,0); //先查找第一个点 if (1 == 1) { int y = -1; int startY = 0; while (y == -1 && startY < img.rows /2) { y = getYOnLine(cv::Point(firstPoint.x, startY), RANGE_DEFAULT); startY += RANGE_DEFAULT / 2; } if (y == -1) return; else firstPoint.y = y; } uppoints.push_back(firstPoint); int centerY = firstPoint.y; int lastY = firstPoint.y; int range = RANGE_DEFAULT; bool needReFind = false;//对该行是否需要扩大range重新搜索 //扫描其他点,左往右 for (int x = 2048 + COL_SPAN; x < img.cols; x += COL_SPAN) { int y = getYOnLine(cv::Point(x, centerY), range); if (y >= 0) { uppoints.push_back(cv::Point(x, y)); //匀速模型预测下一个点的y坐标 centerY = y + y - lastY; if (centerY < 0) centerY = 0; if (centerY >= img.rows) centerY = img.rows - 1; lastY = y; if (!needReFind) needReFind = true; if (range > RANGE_MINI) range -= (RANGE_DEFAULT - RANGE_MINI) /3; if (range < RANGE_MINI) range = RANGE_MINI; } else { if (needReFind)//是否要重新扫描改行 { range = RANGE_DEFAULT; x -= COL_SPAN; needReFind = false; } } } centerY = firstPoint.y; lastY = firstPoint.y; range = RANGE_DEFAULT; needReFind = false; int notfoundCount = 0;//未找到点次数 //扫描其他点,右往左 for (int x = 2048 - COL_SPAN; x > 0; x -= COL_SPAN) { int y = getYOnLine(cv::Point(x, centerY), range); if (y >= 0) { uppoints.push_back(cv::Point(x, y)); //匀速模型预测下一个点的y坐标 centerY = y + y - lastY; lastY = y; if (!needReFind) needReFind = true; if (range > RANGE_MINI) range -= (RANGE_DEFAULT - RANGE_MINI) / 3; if (range < RANGE_MINI) range = RANGE_MINI; } else if (needReFind)//是否要重新扫描改行 { range = RANGE_DEFAULT; x += COL_SPAN; needReFind = false; } else { notfoundCount++; if (notfoundCount >= 3) break; } } std::sort(uppoints.begin(), uppoints.end(), ORDER_BY_X_ASC); std::unique(uppoints.begin(), uppoints.end()); #ifdef BL_OUTPUT_DEBUG_INFO //debug绘图 for (int i = 0; i < uppoints.size(); i++) { cv::circle(drowDebugDetectUD, uppoints[i], 4, cv::Scalar(255, 255, 0), -1); } #endif needReFind = 0; }
void Circle3DOverlay::render(RenderArgs* args) { if (!_visible) { return; // do nothing if we're not visible } float alpha = getAlpha(); if (alpha == 0.0f) { return; // do nothing if our alpha is 0, we're not visible } // Create the circle in the coordinates origin float outerRadius = getOuterRadius(); float innerRadius = getInnerRadius(); // only used in solid case float startAt = getStartAt(); float endAt = getEndAt(); bool geometryChanged = (startAt != _lastStartAt || endAt != _lastEndAt || innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius); const float FULL_CIRCLE = 360.0f; const float SLICES = 180.0f; // The amount of segment to create the circle const float SLICE_ANGLE = FULL_CIRCLE / SLICES; //const int slices = 15; xColor colorX = getColor(); const float MAX_COLOR = 255.0f; glm::vec4 color(colorX.red / MAX_COLOR, colorX.green / MAX_COLOR, colorX.blue / MAX_COLOR, alpha); bool colorChanged = colorX.red != _lastColor.red || colorX.green != _lastColor.green || colorX.blue != _lastColor.blue; _lastColor = colorX; auto geometryCache = DependencyManager::get<GeometryCache>(); Q_ASSERT(args->_batch); auto& batch = *args->_batch; batch._glLineWidth(_lineWidth); auto transform = _transform; transform.postScale(glm::vec3(getDimensions(), 1.0f)); batch.setModelTransform(transform); DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch, false, false); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getIsSolid()) { if (_quadVerticesID == GeometryCache::UNKNOWN_ID) { _quadVerticesID = geometryCache->allocateID(); } if (geometryChanged || colorChanged) { QVector<glm::vec2> points; float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 mostRecentInnerPoint(cosf(angleInRadians) * innerRadius, sinf(angleInRadians) * innerRadius); glm::vec2 mostRecentOuterPoint(cosf(angleInRadians) * outerRadius, sinf(angleInRadians) * outerRadius); while (angle < endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisInnerPoint(cosf(angleInRadians) * innerRadius, sinf(angleInRadians) * innerRadius); glm::vec2 thisOuterPoint(cosf(angleInRadians) * outerRadius, sinf(angleInRadians) * outerRadius); points << mostRecentInnerPoint << mostRecentOuterPoint << thisOuterPoint; // first triangle points << mostRecentInnerPoint << thisInnerPoint << thisOuterPoint; // second triangle angle += SLICE_ANGLE; mostRecentInnerPoint = thisInnerPoint; mostRecentOuterPoint = thisOuterPoint; } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastInnerPoint(cosf(angleInRadians) * innerRadius, sinf(angleInRadians) * innerRadius); glm::vec2 lastOuterPoint(cosf(angleInRadians) * outerRadius, sinf(angleInRadians) * outerRadius); points << mostRecentInnerPoint << mostRecentOuterPoint << lastOuterPoint; // first triangle points << mostRecentInnerPoint << lastInnerPoint << lastOuterPoint; // second triangle geometryCache->updateVertices(_quadVerticesID, points, color); } geometryCache->renderVertices(batch, gpu::TRIANGLES, _quadVerticesID); } else { if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { _lineVerticesID = geometryCache->allocateID(); } if (geometryChanged || colorChanged) { QVector<glm::vec2> points; float angle = startAt; float angleInRadians = glm::radians(angle); glm::vec2 firstPoint(cosf(angleInRadians) * outerRadius, sinf(angleInRadians) * outerRadius); points << firstPoint; while (angle < endAt) { angle += SLICE_ANGLE; angleInRadians = glm::radians(angle); glm::vec2 thisPoint(cosf(angleInRadians) * outerRadius, sinf(angleInRadians) * outerRadius); points << thisPoint; if (getIsDashedLine()) { angle += SLICE_ANGLE / 2.0f; // short gap angleInRadians = glm::radians(angle); glm::vec2 dashStartPoint(cosf(angleInRadians) * outerRadius, sinf(angleInRadians) * outerRadius); points << dashStartPoint; } } // get the last slice portion.... angle = endAt; angleInRadians = glm::radians(angle); glm::vec2 lastPoint(cosf(angleInRadians) * outerRadius, sinf(angleInRadians) * outerRadius); points << lastPoint; geometryCache->updateVertices(_lineVerticesID, points, color); } if (getIsDashedLine()) { geometryCache->renderVertices(batch, gpu::LINES, _lineVerticesID); } else { geometryCache->renderVertices(batch, gpu::LINE_STRIP, _lineVerticesID); } } // draw our tick marks // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getHasTickMarks()) { if (_majorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _majorTicksVerticesID = geometryCache->allocateID(); } if (_minorTicksVerticesID == GeometryCache::UNKNOWN_ID) { _minorTicksVerticesID = geometryCache->allocateID(); } if (geometryChanged) { QVector<glm::vec2> majorPoints; QVector<glm::vec2> minorPoints; // draw our major tick marks if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) { float tickMarkAngle = getMajorTickMarksAngle(); float angle = startAt - fmodf(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMajorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cosf(angleInRadians) * startRadius, sinf(angleInRadians) * startRadius); glm::vec2 thisPointB(cosf(angleInRadians) * endRadius, sinf(angleInRadians) * endRadius); majorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } // draw our minor tick marks if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) { float tickMarkAngle = getMinorTickMarksAngle(); float angle = startAt - fmodf(startAt, tickMarkAngle) + tickMarkAngle; float angleInRadians = glm::radians(angle); float tickMarkLength = getMinorTickMarksLength(); float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; float endRadius = startRadius + tickMarkLength; while (angle <= endAt) { angleInRadians = glm::radians(angle); glm::vec2 thisPointA(cosf(angleInRadians) * startRadius, sinf(angleInRadians) * startRadius); glm::vec2 thisPointB(cosf(angleInRadians) * endRadius, sinf(angleInRadians) * endRadius); minorPoints << thisPointA << thisPointB; angle += tickMarkAngle; } } xColor majorColorX = getMajorTickMarksColor(); glm::vec4 majorColor(majorColorX.red / MAX_COLOR, majorColorX.green / MAX_COLOR, majorColorX.blue / MAX_COLOR, alpha); geometryCache->updateVertices(_majorTicksVerticesID, majorPoints, majorColor); xColor minorColorX = getMinorTickMarksColor(); glm::vec4 minorColor(minorColorX.red / MAX_COLOR, minorColorX.green / MAX_COLOR, minorColorX.blue / MAX_COLOR, alpha); geometryCache->updateVertices(_minorTicksVerticesID, minorPoints, minorColor); } geometryCache->renderVertices(batch, gpu::LINES, _majorTicksVerticesID); geometryCache->renderVertices(batch, gpu::LINES, _minorTicksVerticesID); } if (geometryChanged) { _lastStartAt = startAt; _lastEndAt = endAt; _lastInnerRadius = innerRadius; _lastOuterRadius = outerRadius; } }
std::list<Blob> BlobDetection::Invoke(Image &img) { std::list<Blob> blobList; Point firstPoint(0, -1); Point secondPoint(-1, -1); Point thirdPoint(-1, 0); Point fourthPoint(-1, 1); Point _checkPoints[4]; _checkPoints[0] = firstPoint; _checkPoints[1] = secondPoint; _checkPoints[2] = thirdPoint; _checkPoints[3] = fourthPoint; int height = img.GetHeight(); int width = img.GetWidth(); int **ary = new int*[height]; for(int i = 0; i < height; ++i) { ary[i] = new int[width]; for(int z = 0; z < width; z++) { ary[i][z] = 0; } } int labelIndex = 0; bool neighbourFound = false; int smallestNeighbourLabel = 0; for(int y = 0; y< height; y++) { for(int x = 0; x < width; x++) { if(img.GetPixelBlue(x,y) == 255 && img.GetPixelGreen(x,y) == 255 && img.GetPixelRed(x,y) == 255) { ary[y][x] = 1; //For every pixel check pixels around it. for(int listIndex = 0; listIndex < 4; listIndex++) { int _x = x + _checkPoints[listIndex].getX(); int _y = y + _checkPoints[listIndex].getY(); if(_x > 0 && _y > 0 && ary[_y][_x] > 0) { neighbourFound = true; if(smallestNeighbourLabel == 0 || ary[_y][_x] < smallestNeighbourLabel) { smallestNeighbourLabel = ary[_y][_x]; } } } if(neighbourFound == false) { ary[y][x] = labelIndex++; } else { ary[y][x] = smallestNeighbourLabel; } neighbourFound = false; smallestNeighbourLabel = 0; } } } int *labelColors = new int[labelIndex]; for(int a = 0; a <labelIndex; a++) { labelColors[a] = rand() % 200 + 50; } for(int yy = 0; yy < height; yy++){ for(int xx =0; xx < width; xx++) { if(ary[yy][xx] > 0) { img.SetPixel(xx,yy, labelColors[ary[yy][xx]] << 24 | 0 << 16 | labelColors[ary[yy][xx]] << 8); } } } //newImg.SaveImageToFile("ppp_"); img.SaveImageToFile("changed"); return blobList; }