void DisplayDirector::FindSelection() { //*** be_app->HideCursor(); View* view = WindowView(); BPoint point; BPoint lastPoint(-1000000, -1000000); bool scrolling = false; for (;; lastPoint = point) { // get & check mouse state int buttons = view->GetMouseButtons(); if (buttons == 0) break; point = view->GetMousePoint(); bool autoscrolling = Autoscroll(point); if (point == lastPoint && !autoscrolling && !scrolling) { view->MouseTrackingPause(); continue; } // move the selection StartRefreshCycle(); BPoint docPoint = ViewToDoc(point); FindSelectionContext context(docPoint.x, docPoint.y); Selection* newSelection = docDisplayNode->BlockFindSelection(&context); SetSelection(newSelection); scrolling = DoScrollStep(); FinishRefreshCycle(); ClearDeletedSelections(); } //*** be_app->ShowCursor(); //*** didn't work }
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 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 } }
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 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; } } }
/*! \internal \brief Records point to list with timestamp. \param point Point to be recorded. \param time Time to be recorded. \return Nothing. */ void HbPointRecorder::record(qreal point, const QTime &time) { // Empty list always accepts first point without tests. if ( !isEmpty() ) { // No point to record a point, if timestamp is less or equal with previous. if ( lastTime().msecsTo(time) == 0 ) { DEBUG() << "Ignoring point, because no difference in time stamps."; return; } // Don't tolerate points, which are too close to previously recorded point. if ( qAbs(lastPoint() - point) < mThreshold ) { DEBUG() << "Ignoring point, because it is withing threshold of previous point"; return; } } // In case the list contains two or more points, direction can be // determined. Each new point added needs to be checked for direction // change. if ( length() > 1 ) { // Clear list, on direction change. Leave the last recorded point // to the list, as it can be considered as first point for new direction. if ( dirChanged( point ) ) { HbPointTime temp = last(); clear(); append(temp); } } // Finally check, if the position has changed. Don't record point, when no position // change. if ( isEmpty() || point != lastPoint() ) { // Add point and time to list. append(HbPointTime(point, time)); } else { DEBUG() << "Ignoring point, because it equals previous."; } }
void IntonationWidget::smoothPoints(QPainter& painter) { if (intonationPointList_.size() < 2U) return; for (unsigned int i = 0, end = intonationPointList_.size() - 1; i < end; ++i) { const auto& point1 = intonationPointList_[i]; const auto& point2 = intonationPointList_[i + 1]; double x1 = point1.absoluteTime(); double y1 = point1.semitone(); double m1 = point1.slope(); double x2 = point2.absoluteTime(); double y2 = point2.semitone(); double m2 = point2.slope(); double x12 = x1 * x1; double x13 = x12 * x1; double x22 = x2 * x2; double x23 = x22 * x2; double denominator = x2 - x1; denominator = denominator * denominator * denominator; double d = (-(y2 * x13) + 3.0 * y2 * x12 * x2 + m2 * x13 * x2 + m1 * x12 * x22 - m2 * x12 * x22 - 3.0 * x1 * y1 * x22 - m1 * x1 * x23 + y1 * x23) / denominator; double c = (-(m2 * x13) - 6.0 * y2 * x1 * x2 - 2.0 * m1 * x12 * x2 - m2 * x12 * x2 + 6.0 * x1 * y1 * x2 + m1 * x1 * x22 + 2.0 * m2 * x1 * x22 + m1 * x23) / denominator; double b = (3.0 * y2 * x1 + m1 * x12 + 2.0 * m2 * x12 - 3.0 * x1 * y1 + 3.0 * x2 * y2 + m1 * x1 * x2 - m2 * x1 * x2 - 3.0 * y1 * x2 - 2.0 * m1 * x22 - m2 * x22) / denominator; double a = (-2.0 * y2 - m1 * x1 - m2 * x1 + 2.0 * y1 + m1 * x2 + m2 * x2) / denominator; QPointF prevPoint(0.5 + timeToX(x1), 0.5 + valueToY(y1)); for (unsigned int j = static_cast<unsigned int>(x1); j <= static_cast<unsigned int>(x2); j += SMOOTH_POINTS_X_INCREMENT) { double x = j; double y = x * (x * (x * a + b) + c) + d; QPointF currPoint(0.5 + timeToX(x), 0.5 + valueToY(y)); painter.drawLine(prevPoint, currPoint); prevPoint = currPoint; } QPointF lastPoint(0.5 + timeToX(x2), 0.5 + valueToY(y2)); painter.drawLine(prevPoint, lastPoint); } }
void Telemetry::drawAsGraph(sf::RenderWindow& window, const sf::FloatRect& position, const sf::Color& color) { if (dataPoints.size() < 2) { return; } float maxUp = position.top; //d float minUp = position.top + position.height; //c float leftSide = position.left; float maxData = maxBound; //b float minData = minBound; //a if (automaticBoundsDetection) { minData = std::min_element(dataPoints.begin(), dataPoints.end(), [](const sf::Vector2f& lhs, const sf::Vector2f& rhs) { return lhs.y < rhs.y; })->y; maxData = std::max_element(dataPoints.begin(), dataPoints.end(), [](const sf::Vector2f& lhs, const sf::Vector2f& rhs) { return lhs.y < rhs.y; })->y; } if ( minData - maxData == 0.0 ) { return; } auto it = dataPoints.begin(); if (scrolling) { auto firstPositionToDraw = dataPoints.back().x - position.width / horizontalScaling; it = std::find_if(dataPoints.begin(), dataPoints.end(), [firstPositionToDraw](const sf::Vector2f& value) { return value.x >= firstPositionToDraw; }); if (it == dataPoints.end()) { // this should never happen return; } } auto startingPoint = it->x; sf::Vector2f lastPoint(leftSide, (-maxData*minUp + minData*maxUp + (minUp - maxUp)*it->y) / (minData - maxData)); for ( ++it; it != dataPoints.end(); ++it ) { sf::Vector2f currentPoint( leftSide + (it->x - startingPoint) * horizontalScaling, (-maxData*minUp + minData*maxUp + (minUp - maxUp)*it->y) / (minData - maxData)); drawLine(window, lastPoint, currentPoint, color); lastPoint = currentPoint; } }
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 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; } } } }
bool TaskSegmentation::run(int procType, int tid) { cv::Mat inputImage = this->bgr->getData(); cv::Mat outMask; uint64_t t1 = Util::ClockGetTimeProfile(); std::string imageName = this->bgr->getInputFileName(); std::cout << "TaskSegmentationFileName: " << imageName << std::endl; std::cout << "TaskSegmentation to be executed: " << otsuRatio << ":" << curvatureWeight << ":" << sizeThld << ":" << sizeUpperThld << ":" << mpp << ":" << mskernel << ":" << levelSetNumberOfIteration << ":" << declumpingType << std::endl; if (inputImage.rows > 0) outMask = ImagenomicAnalytics::TileAnalysis::processTileCV(inputImage, otsuRatio, curvatureWeight, sizeThld, sizeUpperThld, mpp, mskernel, // levelSetNumberOfIteration); levelSetNumberOfIteration, declumpingType); else std::cout << "Segmentation: input data NULL" << std::endl; this->mask->setData(outMask); uint64_t t2 = Util::ClockGetTimeProfile(); this->executionTime[0] = (int) t2 - t1; // Execution Time //std::cout << "Task Segmentation image name: " << imageName << std::endl; std::string key("image"); std::size_t found = imageName.rfind(key); std::string lastPoint("."); std::size_t lastPointFound = imageName.rfind(lastPoint); std::string result; if (found != std::string::npos) result = imageName.substr(found + key.size(), lastPointFound - (found + key.size())); std::cout << "###IMAGE: " << result << endl; this->executionTime[1] = atoi(result.c_str()); std::cout << "Task Segmentation time elapsed: " << this->executionTime[0] << std::endl; std::cout << "Task Segmentation image: " << this->executionTime[1] << std::endl; std::cout << "Task Segmentation executed: " << otsuRatio << ":" << curvatureWeight << ":" << sizeThld << ":" << sizeUpperThld << ":" << mpp << ":" << mskernel << ":" << levelSetNumberOfIteration << ":" << declumpingType << std::endl; }
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); } } } }
int addStudent(Student * student, int code, char * name) { if (findCode(student, code) == 0) { Student * p = lastPoint(student); if (student->name == "" && student->code == 0 && student->next == 0) { p->code = code; p->name = name; p->next = 0; } else { p->next = malloc(sizeof(Student)); p->next->code = code; p->next->name = name; p->next->next = 0; } return 0; } else { return -1; } }
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 } }
GList * EraseableStroke::getStroke(Stroke * original) { XOJ_CHECK_TYPE(EraseableStroke); GList * list = NULL; Stroke * s = NULL; Point lastPoint(NAN, NAN); for (GList * l = this->parts->data; l != NULL; l = l->next) { EraseableStrokePart * p = (EraseableStrokePart *) l->data; GList * points = p->getPoints(); if (g_list_length(points) < 2) { continue; } Point a = *((Point *) g_list_first(points)->data); Point b = *((Point *) g_list_last(points)->data); a.z = p->width; if (!lastPoint.equalsPos(a) || s == NULL) { if (s) { s->addPoint(lastPoint); } s = new Stroke(); s->setColor(original->getColor()); s->setToolType(original->getToolType()); s->setWidth(original->getWidth()); list = g_list_append(list, s); } s->addPoint(a); lastPoint = b; } if (s) { s->addPoint(lastPoint); } return list; }
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 deleteStudent(Student * student, Student * p) { if (p == student) { if (student->next != 0) { p = p->next; student->name = student->next->name; student->code = student->next->code; student->next = student->next->next; free(p); } else { student->name = ""; student->code = 0; student->next = 0; } } else if (p == lastPoint(student)) { PreNode(student, p)->next = 0; free(p); } else if(p != 0) { PreNode(student, p)->next = ForNode(student, p); free(p); } }
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 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 Printlines::makeLines(const vector<Poly> polys, const vector<Poly> *clippolys, Vector2d &startPoint, bool displace_startpoint, double minspeed, double maxspeed, double movespeed, // mm/s double linewidth, double linewidthratio, double optratio, double maxArcAngle, bool linelengthsort, double AOmindistance, double AOspeed, double AOamount, double AOrepushratio) { uint count = polys.size(); if (polys.size()==0) return; int nvindex=-1; int npindex=-1; uint nindex; vector<bool> done(count); // polys not yet handled for(size_t q=0;q<count;q++) done[q]=false; uint ndone=0; double pdist, nstdist; //double nlength; double lastavlength = -1; while (ndone < count) { if (linelengthsort && npindex>=0) lastavlength = polys[npindex].averageLinelengthSq(); nstdist = 1000000; for(size_t q=0; q<count; q++) { // find nearest polygon if (polys[q].size() == 0) {done[q] = true; ndone++;} if (!done[q]) { pdist = 1000000; nindex = polys[q].nearestDistanceSqTo(startPoint,pdist); if (pdist<nstdist){ npindex = q; // index of nearest poly in polysleft nstdist = pdist; // distance of nearest poly nvindex = nindex; // nearest point in nearest poly } } } // find next nearest polygon, but with similar line length if (linelengthsort && lastavlength > 0) { double minavlengthdiff = 10000000; for(size_t q=0; q<count; q++) { if (!done[q]) { nindex = polys[q].nearestDistanceSqTo(startPoint,pdist); if ( pdist < 400 ){ // nearer than 20mm // || //(nstdist==0 && pdist < 10000*linewidth*linewidth) ) { double avlength = polys[q].averageLinelengthSq(); double avldiff = abs(avlength-lastavlength); if (avldiff < minavlengthdiff) { //cerr << npindex << " : " <<avlength << " - " <<avldiff << endl; minavlengthdiff = avldiff; npindex = q; nvindex = nindex; } } } } } if (displace_startpoint && ndone==0) // displace first point nvindex = (nvindex+1)%polys[npindex].size(); if (npindex >= 0 && npindex >=0) { addPoly(polys[npindex], nvindex, maxspeed, movespeed); done[npindex]=true; ndone++; } if (lines.size()>0) startPoint = lastPoint(); } if (count == 0) return; setZ(polys.back().getZ()); clipMovements(clippolys, linewidth/2.); optimize(minspeed, maxspeed, movespeed, linewidth, linewidthratio, optratio, maxArcAngle, AOmindistance, AOspeed, AOamount, AOrepushratio); }
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]; } } }
string OCV::trackAndEval(Mat &threshold, Mat &canvas){ //~ Mat temp; //~ threshold.copyTo(temp); //these two vectors needed for output of findContours vector< vector<Point> > contours; vector<Vec4i> hierarchy; //find contours of filtered image using openCV findContours function findContours(threshold, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); //use moments method to find our filtered object string retValue = ""; double area; int numObjects = hierarchy.size(); if (debounceCounter) debounceCounter--; if (numObjects > 0) { //if number of objects greater than MAX_NUM_OBJECTS we have a noisy filter if (numObjects==1){ Moments moment = moments((Mat)contours[0]); area = moment.m00; Point lastPoint( moment.m10/area, // x moment.m01/area // y ); drawObject(area, lastPoint, canvas); // Evaluate in which position of the grid the point is // state machine // TODO CHECk bounding rectangles and contour to evaluate it. Use the layout form PNG image! // expression limits switch (trackState) { case TrackStt::NO_TRACK: cout << "TrackStt::NO_TRACK" << endl; case TrackStt::UNARMED: if (lastPoint.x > EXP_HORI_L) { trackState = TrackStt::EXPRESSION; //~ cout << "Next state TrackStt::EXPRESSION" << endl; } else if (lastPoint.y > BUTT_VER_T && lastPoint.y < BUTT_VER_B) { trackState = TrackStt::ARMED; cout << "Next state TrackStt::ARMED" << endl; } else { trackState = TrackStt::UNARMED; } break; case TrackStt::ARMED: if (lastPoint.x > EXP_HORI_L && lastPoint.x < EXP_HORI_R) { trackState = TrackStt::EXPRESSION; } else if (lastPoint.y > BUTT_VER_B) { trackState = TrackStt::DEBOUNCING; debounceCounter = debouceFrames; if (lastPoint.x > B1_HORI_L && lastPoint.x < B1_HORI_R) { cout << "1" << endl; retValue = "1"; } else if (lastPoint.x > B2_HORI_L && lastPoint.x < B2_HORI_R) { cout << "2" << endl; retValue = "2"; } else if (lastPoint.x > B3_HORI_L && lastPoint.x < B3_HORI_R) { cout << "3" << endl; retValue = "3"; } else if (lastPoint.x > B4_HORI_L && lastPoint.x < B4_HORI_R) { cout << "4" << endl; retValue = "4"; } } else if (lastPoint.y < BUTT_VER_T) { trackState = TrackStt::DEBOUNCING; debounceCounter = debouceFrames; if (lastPoint.x > B5_HORI_L && lastPoint.x < B5_HORI_R) { cout << "5" << endl; retValue = "5"; } else if (lastPoint.x > B6_HORI_L && lastPoint.x < B6_HORI_R) { cout << "6" << endl; retValue = "6"; } } break; case TrackStt::DEBOUNCING: //~ cout << "DEBOUNCING" << endl; if (debounceCounter==0) trackState = TrackStt::UNARMED; break; case TrackStt::EXPRESSION: if (lastPoint.x < EXP_HORI_L) { trackState = TrackStt::UNARMED; } else{ // TODO make a previous level comparition int expLevel; if (lastPoint.y > EXP_VER_B) expLevel = 0; else if (lastPoint.y < EXP_VER_T) expLevel = expressionDiv-1; else { float ylevel = (float)(lastPoint.y-EXP_VER_T)/(float)(EXP_VER_RANGE); expLevel = (int)((float)(expressionDiv-1)*(1.0 - ylevel)); } if (expLevel!=lastExLevel) { cout << "Expression level:" << expLevel << endl; retValue = "X"+to_string(expLevel); lastExLevel = expLevel; } } break; default: break; } return retValue; } else { if (trackState!=TrackStt::DEBOUNCING) trackState = TrackStt::NO_TRACK; //void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false ) putText(canvas, "More than one object detected!", Point(2, FRAME_HEIGHT-10), 1, 0.7, Scalar(0,0,255), 1); cout << "More than one object detected! Next state is TrackStt::NO_TRACK" << endl; } } if (trackState!=TrackStt::DEBOUNCING) trackState = TrackStt::NO_TRACK; return retValue; }
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; } }
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); } }
// this works in only x/y plane bool Pathfinding::bresenhamPath(const Position& origin, const Position& target) { int xd[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int yd[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int x, x0, x1, delta_x, step_x; int y, y0, y1, delta_y, step_y; int z, z0, z1, delta_z, step_z; int swap_xy, swap_xz; int drift_xy, drift_xz; int cx, cy, cz; Position lastPoint(origin); int dir; int lastTUCost = -1; Position nextPoint; //start and end points x0 = origin.x; x1 = target.x; y0 = origin.y; y1 = target.y; z0 = origin.z; z1 = target.z; //'steep' xy Line, make longest delta x plane swap_xy = abs(y1 - y0) > abs(x1 - x0); if (swap_xy) { std::swap(x0, y0); std::swap(x1, y1); } //do same for xz swap_xz = abs(z1 - z0) > abs(x1 - x0); if (swap_xz) { std::swap(x0, z0); std::swap(x1, z1); } //delta is Length in each plane delta_x = abs(x1 - x0); delta_y = abs(y1 - y0); delta_z = abs(z1 - z0); //drift controls when to step in 'shallow' planes //starting value keeps Line centred drift_xy = (delta_x / 2); drift_xz = (delta_x / 2); //direction of line step_x = 1; if (x0 > x1) { step_x = -1; } step_y = 1; if (y0 > y1) { step_y = -1; } step_z = 1; if (z0 > z1) { step_z = -1; } //starting point y = y0; z = z0; //step through longest delta (which we have swapped to x) for (x = x0; x != (x1+step_x); x += step_x) { //copy position cx = x; cy = y; cz = z; //unswap (in reverse) if (swap_xz) std::swap(cx, cz); if (swap_xy) std::swap(cx, cy); if (x != x0 || y != y0 || z != z0) { Position realNextPoint = Position(cx, cy, cz); nextPoint = realNextPoint; // get direction for (dir = 0; dir < 8; ++dir) { if (xd[dir] == cx-lastPoint.x && yd[dir] == cy-lastPoint.y) break; } int tuCost = getTUCost(lastPoint, dir, &nextPoint, _unit); if (nextPoint == realNextPoint && tuCost < 255 && (tuCost == lastTUCost || (dir&1 && tuCost == lastTUCost*1.5) || (!(dir&1) && tuCost*1.5 == lastTUCost) || lastTUCost == -1) && !isBlocked(_save->getTile(lastPoint), _save->getTile(nextPoint), dir)) { _path.push_back(dir); } else { return false; } lastTUCost = tuCost; lastPoint = Position(cx, cy, cz); } //update progress in other planes drift_xy = drift_xy - delta_y; drift_xz = drift_xz - delta_z; //step in y plane if (drift_xy < 0) { y = y + step_y; drift_xy = drift_xy + delta_x; } //same in z if (drift_xz < 0) { z = z + step_z; drift_xz = drift_xz + delta_x; } } return true; }
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; } }