Point operator-(const Point & p) { return Point(_x - p.x(), _y - p.y()); }
//This function should have been provided in class Points, but there isn't one. inline bool operator == (const Point& a, const Point& b) { return a.x() == b.x() && a.y() == b.y(); }
void Renderer::drawTexture(Texture* texture, const Point& pos, const Point& src, const Size& srcSize) { drawTexture(texture, pos.x(), pos.y(), src.x(), src.y(), (unsigned int)srcSize.width(), (unsigned int)srcSize.height()); }
void InsideInsertionBasic::execute(){ Triangle* T = this->confp->triangle(); Point* p = this->confp->points().at(0); Vertex* P = this->confp->mesh()->createAndAddVertex(p->x(), p->y()); Triangle *t0, *t1, *t2, *A, *B, *C; Vertex *v0, *v1, *v2; int i0, i1, i2; switch(this->confp->includeCase()){ case Constant::INCLUDED: t0 = T->getNeighbour(0); t1 = T->getNeighbour(1); t2 = T->getNeighbour(2); v0 = T->getVertex(0); v1 = T->getVertex(1); v2 = T->getVertex(2); A = this->confp->mesh()->createAndAddTriangle(v0, v1, P); B = this->confp->mesh()->createAndAddTriangle(P, v1, v2); C = this->confp->mesh()->createAndAddTriangle(v0, P, v2); A->setNeighbours(B, C, t2); B->setNeighbours(t0, C, A); C->setNeighbours(B, t1, A); if(t0 != 0) t0->replaceNeighbour(T, B); if(t1 != 0) t1->replaceNeighbour(T, C); if(t2 != 0) t2->replaceNeighbour(T, A); this->confp->mesh()->removeAndDeleteTriangle(T); break; case Constant::BORDER_INCLUDED: i0 = this->confp->edges().at(0); i1 = (i0+1)%3; i2 = (i1+1)%3; t0 = T->getNeighbour(i0); t1 = T->getNeighbour(i1); t2 = T->getNeighbour(i2); v0 = T->getVertex(i0); v1 = T->getVertex(i1); v2 = T->getVertex(i2); A = this->confp->mesh()->createAndAddTriangle(v0, v1, P); B = this->confp->mesh()->createAndAddTriangle(v0, P, v2); if(t0 == 0){ A->setNeighbours(0, B, t2); B->setNeighbours(0, t1, A); if(t1 != 0) t1->replaceNeighbour(T, B); if(t2 != 0) t2->replaceNeighbour(T, A); this->confp->mesh()->removeAndDeleteTriangle(T); } else{ int j2 = t0->getIndex(v1); int j0 = (j2+1)%3; int j1 = (j0+1)%3; Vertex* b0 = t0->getVertex(j0); Vertex* b1 = t0->getVertex(j1); Vertex* b2 = t0->getVertex(j2); //Triangle* l0 = t0->getNeighbour(j0); Triangle* l1 = t0->getNeighbour(j1); Triangle* l2 = t0->getNeighbour(j2); Triangle* C = this->confp->mesh()->createAndAddTriangle(b0, b1, P); Triangle* D = this->confp->mesh()->createAndAddTriangle(b0, P, b2); A->setNeighbours(D, B, t2); B->setNeighbours(C, t1, A); C->setNeighbours(B, D, l2); D->setNeighbours(A, l1, C); if(t1 != 0) t1->replaceNeighbour(T, B); if(t2 != 0) t2->replaceNeighbour(T, A); if(l1 != 0) l1->replaceNeighbour(t0, D); if(l2 != 0) l2->replaceNeighbour(t0, C); this->confp->mesh()->removeAndDeleteTriangle(T); this->confp->mesh()->removeAndDeleteTriangle(t0); } break; case Constant::NOT_INCLUDED: case Constant::CORNER_INCLUDED: default: break; } this->confp->mesh()->setSelectedTriangle(0); }
void FieldPainter::drawFeatureRR (const FieldFeatureInfo &feat, const AbsCoord &robot) { save(); setPen(Qt::NoPen); setBrush(QBrush("red")); translateRR(feat.rr, robot); QPen p; switch (feat.type) { case FieldFeatureInfo::fFieldLinePoint: { save(); setPen("blue"); p = pen(); p.setWidth(25); setPen(p); setBrush(QBrush("blue")); for (uint16_t i = 0; i < feat.fieldlinepoints.size(); i++) { Point p = feat.fieldlinepoints[i].rrp; drawPoint (QPoint(p.x(),p.y())); } restore(); } break; case FieldFeatureInfo::fCorner: setPen("black"); p = pen(); p.setWidth(50); setPen(p); save(); rotate(RAD2DEG(M_PI_4)); drawRect(25, 25, -300, -50); restore(); save(); rotate(RAD2DEG(-M_PI_4)); drawRect(25, 25, -300, -50); restore(); break; case FieldFeatureInfo::fTJunction: setPen("black"); p = pen(); p.setWidth(50); setPen(p); drawRect(-25, -300, 50, 600); drawRect(0, 25, -300, -50); break; case FieldFeatureInfo::fPenaltySpot: setPen("black"); p = pen(); p.setWidth(50); setPen(p); setBrush(Qt::NoBrush); drawEllipse (QPoint(-30,-30), 60,60); break; case FieldFeatureInfo::fCentreCircle: setPen("red"); p = pen(); p.setWidth(50); setPen(p); setBrush(Qt::NoBrush); drawEllipse (QPoint(0, 0), CENTER_CIRCLE_DIAMETER / 2, CENTER_CIRCLE_DIAMETER / 2); break; case FieldFeatureInfo::fLine: { save(); setPen("red"); p = pen(); p.setWidth(50); setPen(p); setBrush(QBrush("red")); drawLine(feat.line.p1.x(), feat.line.p1.y(), feat.line.p2.x(), feat.line.p2.y()); restore(); break; } case FieldFeatureInfo::fParallelLines: { save(); setPen("black"); p = pen(); p.setWidth(75); setPen(p); setBrush(QBrush("black")); drawLine(feat.parallellines.l1.p1.x(), feat.parallellines.l1.p1.y(), feat.parallellines.l1.p2.x(), feat.parallellines.l1.p2.y()); drawLine(feat.parallellines.l2.p1.x(), feat.parallellines.l2.p1.y(), feat.parallellines.l2.p2.x(), feat.parallellines.l2.p2.y()); restore(); break; } default: break; } restore(); }
void Cluster::getPointList(ostringstream& oss) { for(vector<Point*>::iterator it = _p_vect.begin() ; it != _p_vect.end() ; ++it) { Point* p = *it; oss << "(" << p->x() << "," << p->y() << ")"; } }
Point Transform::operator()(const Point& point) const { return Point( a[0] * point.x() + a[1] * point.y() + a[2], a[3] * point.x() + a[4] * point.y() + a[5] ); }
void Decorator::basicText(Picture& dstpic, const Point& pos, const std::string& text, NColor color) { stringColor( dstpic.surface(), pos.x(), pos.y(), text.c_str(), color.color ); dstpic.update(); }
//CHECK IF A POINT P2 LIES TO THE LEFT/RIGHT/ON THE LINE JOINING TWO OTHER POINTS P0 and P1 inline float orient( Point P0, Point P1, Point P2 ) { return (P1.x() - P0.x()) * (P2.y() - P0.y()) - (P2.x() - P0.x()) * (P1.y() - P0.y()); } // End of orient
void DA::incrementCurrentOffset() { #ifdef __DEBUG_DA_PUBLIC__ assert(m_bIamActive); #endif // if it is the first element, simply return the stored offset ... if ( m_uiCurrent == (m_uiElementBegin-1)) { m_ptCurrentOffset = m_ptOffset; return; } #ifdef __DEBUG_DA_PUBLIC__ if ( m_ucpOctLevels[m_uiCurrent] & ot::TreeNode::BOUNDARY ) { std::cerr << RED"ERROR, Boundary eleme in incre Curr offset"NRM << std::endl; assert(false); } #endif unsigned char d = (m_ucpOctLevels[m_uiCurrent] & ot::TreeNode::MAX_LEVEL ); unsigned int len = (unsigned int)(1u<<( m_uiMaxDepth - d ) ); unsigned int len_par = (unsigned int)(1u<<( m_uiMaxDepth - d +1 ) ); unsigned int i,j,k; i = m_ptCurrentOffset.xint(); j = m_ptCurrentOffset.yint(); k = m_ptCurrentOffset.zint(); i %= len_par; j %= len_par; k %= len_par; i /= len; j /= len; k /= len; unsigned int childNum = 4*k + 2*j + i; Point p = m_ptCurrentOffset; Point p2; switch (childNum) { case 7: p2.x() = p.x() -len; p2.y() = p.y() - len; p2.z() = p.z() -len; p2 = getNextOffset(p2, d-1); break; case 0: p2.x() = p.x() +len; p2.y() = p.y(); p2.z() = p.z(); break; case 1: p2.x() = p.x() -len; p2.y() = p.y() +len; p2.z() = p.z(); break; case 2: p2.x() = p.x() +len; p2.y() = p.y(); p2.z() = p.z(); break; case 3: p2.x() = p.x() -len; p2.y() = p.y() - len; p2.z() = p.z() +len; break; case 4: p2.x() = p.x() +len; p2.y() = p.y(); p2.z() = p.z(); break; case 5: p2.x() = p.x() -len; p2.y() = p.y()+len; p2.z() = p.z(); break; case 6: p2.x() = p.x() +len; p2.y() = p.y(); p2.z() = p.z(); break; default: std::cerr << "Wrong child number in " << __func__ << std::endl; assert(false); break; } // switch (childNum) m_ptCurrentOffset = p2; }
void Decorator::drawLine( Picture& dstpic, const Point& p1, const Point& p2, NColor color) { if( dstpic.isValid() ) lineColor( dstpic.surface(), p1.x(), p1.y(), p2.x(), p2.y(), color.rgba() ); }
bool operator==(const Point & p) { return (fabs(_x - p.x()) <= EPS) && (fabs(_y - p.y()) <= EPS); }
double operator*(const Point & p) { return _x * p.x() + _y * p.y(); }
double operator^(const Point & p) { return _x * p.y() - _y * p.x(); }
void MAS::Widget::MsgMousemove(const Point& d) { GetParent()->HandleEvent(*this, MSG_MOUSEMOVE, d.x(), d.y()); }
/// Copy Constructor Point(const Point& p) : std::pair<double,double>(p.x(),p.y()) { }
void MAS::Widget::Place(const Point& p, bool normalized) { x(p.x(),normalized); y(p.y(),normalized); }
double Point::dot(Point const & p)const { return this->x()*p.x()+this->y()*p.y(); }
// {{{ Map::exists() bool Map::exists(const Point& p) const { // check for map boundaries return ( ( p.y() < data_->tiles.size() ) && ( p.x() < data_->tiles[p.y()].size() ) ); }
Point(const Point & p): m_x(p.x()), m_y(p.y()) { }
/** * \brief Create an affine transform from angle translation and scale factor */ Transform::Transform(double angle, const Point& translation, double scale) { a[0] = scale * cos(angle); a[1] = -scale * sin(angle); a[3] = scale * sin(angle); a[4] = scale * cos(angle); a[2] = translation.x(); a[5] = translation.y(); }
void MapObject::set_position(Point<int16_t> position) { int16_t x = position.x(); int16_t y = position.y(); set_position(x, y); }
void PipBoy::init() { if (_initialized) return; State::init(); setModal(true); setFullscreen(true); Game::getInstance()->mouse()->pushState(Input::Mouse::Cursor::BIG_ARROW); // Background auto background = new UI::Image("art/intrface/pip.frm"); Point backgroundPos = Point((Game::getInstance()->renderer()->size() - background->size()) / 2); int backgroundX = backgroundPos.x(); int backgroundY = backgroundPos.y(); background->setPosition(backgroundPos); // Buttons auto alarmButton = new UI::ImageButton(UI::ImageButton::Type::PIPBOY_ALARM_BUTTON, backgroundX+124, backgroundY+13); auto statusButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+340); auto automapsButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+394); auto archivesButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+423); auto closeButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+448); closeButton->mouseClickHandler().add(std::bind(&PipBoy::onCloseButtonClick, this, std::placeholders::_1)); // Date and time // Date auto day = new UI::SmallCounter(backgroundPos + Point(21, 17)); day->setLength(2); day->setNumber(Game::getInstance()->gameTime()->day()); day->setColor(UI::SmallCounter::Color::WHITE); day->setType(UI::SmallCounter::Type::UNSIGNED); auto month = new UI::MonthCounter( static_cast<UI::MonthCounter::Month>(Game::getInstance()->gameTime()->month()), backgroundPos + Point(46, 18) ); auto year = new UI::SmallCounter(backgroundPos + Point(84, 17)); year->setLength(4); year->setNumber(Game::getInstance()->gameTime()->year()); year->setColor(UI::SmallCounter::Color::WHITE); year->setType(UI::SmallCounter::Type::UNSIGNED); // Time auto time = new UI::SmallCounter(backgroundPos + Point(160, 17)); time->setLength(4); time->setNumber((Game::getInstance()->gameTime()->hours() * 100) + Game::getInstance()->gameTime()->minutes()); time->setColor(UI::SmallCounter::Color::WHITE); time->setType(UI::SmallCounter::Type::UNSIGNED); addUI(background); addUI(alarmButton); addUI(statusButton); addUI(automapsButton); addUI(archivesButton); addUI(day); addUI(month); addUI(year); addUI(time); addUI(closeButton); }
double inline dist(const Point& a, const Point& b) { return sqrt(pow(b.x() - a.x(),2) + pow(b.y() - a.y(),2)); }
void WaitLongOperation::recordMouseCursorPosition() { Point location = machine_.system().event().getCursorPos(); *x_ = location.x(); *y_ = location.y(); }
VolMagick::Volume signedDistanceFunction(const boost::shared_ptr<Geometry>& geom, const VolMagick::Dimension& dim, const VolMagick::BoundingBox& bbox) { int dimx = dim[0], dimy = dim[1], dimz = dim[2]; // read the annotated input file and Mesh mesh; cerr << "Reading input mesh "; read_labeled_mesh(mesh, geom); cerr << "done." << endl; // build a bounding box around the input and store the // origin, span etc. // vector<double> bbox; // construct_bbox(mesh, bbox); VolMagick::BoundingBox box(bbox); if(box.isNull()) { geom->GetReadyToDrawWire(); //make sure we have calculated extents for this geometry already box[0] = geom->m_Min[0]; box[1] = geom->m_Min[1]; box[2] = geom->m_Min[2]; box[3] = geom->m_Max[0]; box[4] = geom->m_Max[1]; box[5] = geom->m_Max[2]; } // construct a kd-tree of all the non-isolated mesh_vertices. vector<VECTOR3> points; vector<Point> pts; for(int i = 0; i < mesh.get_nv(); i ++) { if( mesh.vert_list[i].iso() ) continue; Point p = mesh.vert_list[i].point(); pts.push_back(p); points.push_back(VECTOR3(CGAL::to_double(p.x()), CGAL::to_double(p.y()), CGAL::to_double(p.z()))); } KdTree kd_tree(points, 20); kd_tree.setNOfNeighbours(1); // Now perform a reconstruction to build a tetrahedralized solid // with in-out marked. Triangulation triang; recon(pts, triang); // assign weight to each triangle. vector<double> weights; // assign_sdf_weight(mesh, weights); // comment out for uniform weight. VolMagick::Volume vol; cerr << "SDF " << endl; try { vol.dimension(VolMagick::Dimension(dimx,dimy,dimz)); vol.voxelType(VolMagick::Float); vol.boundingBox(box); for(unsigned int k=0; k<vol.ZDim(); k++) { for(unsigned int j=0; j<vol.YDim(); j++) { for(unsigned int i=0; i<vol.XDim(); i++) { double x = vol.XMin() + i*vol.XSpan(); double y = vol.YMin() + j*vol.YSpan(); double z = vol.ZMin() + k*vol.ZSpan(); double fn_val = sdf(Point(x,y,z), mesh, weights, kd_tree, triang); vol(i,j,k, fn_val); } } fprintf(stderr, "%5.2f %%\r", (float(k)/float(vol.ZDim()-1))*100.0); } vol.desc("multi_sdf"); } catch(VolMagick::Exception &e) { cerr << e.what() << endl; } catch(std::exception &e) { cerr << e.what() << endl; } cerr << endl << "done." << endl; return vol; }
//The Manhattan distance of two points. inline int dist (const Point& a, const Point& b) { return abs(a.x() - b.x()) + abs(a.y() - b.y()); }
void operator() (Point& p) { p.x() = multX*(p.x()-minX); p.y() = multY*(p.y()-minY); }
void KDPhotonsTree::InitTree(const Photons &photons, const size_t index, const Photons::iterator begin, const Photons::iterator end, const size_t depth) { const size_t dist_it = end - begin; if(dist_it < 0) { throw Error("initializing KD tree error"); } if(dist_it < 1) { if(index < m_numberOfPhotons && begin != photons.end())m_treeArray[index] = TreeElement(*begin, ST_NON_EXIST); return; } if(dist_it == 1) { if(index < m_numberOfPhotons)m_treeArray[index] = TreeElement(*begin, ST_LEAF); return; } Point min( GLOBAL_PROPERTIES::INFINITY, GLOBAL_PROPERTIES::INFINITY, GLOBAL_PROPERTIES::INFINITY); Point max(-GLOBAL_PROPERTIES::INFINITY, -GLOBAL_PROPERTIES::INFINITY, -GLOBAL_PROPERTIES::INFINITY); for(Photons::iterator it = begin; it != end; it++) { if(it->position.x() < min.x()) min.x(it->position.x()); if(it->position.y() < min.y()) min.y(it->position.y()); if(it->position.z() < min.z()) min.z(it->position.z()); if(it->position.x() > max.x()) max.x(it->position.x()); if(it->position.y() > max.y()) max.y(it->position.y()); if(it->position.z() > max.z()) max.z(it->position.z()); } Point distPoint = max - min; Split_type split = (distPoint.x() >= distPoint.y() && distPoint.x() >= distPoint.z()) ? ST_X_COORD : ( (distPoint.y() >= distPoint.z()) ? ST_Y_COORD : ST_Z_COORD ); std::sort(begin, end, split == ST_X_COORD ? x_comp_func : (split == ST_Y_COORD ? y_comp_func : z_comp_func) ); const Photons::iterator middle = begin + ((end - begin)/2); if(((index << 1) | 1) < m_numberOfPhotons) { m_treeArray[index] = TreeElement(*middle, split); if(depth < m_logOfNumberOfThreads) { // Need to split to two threads (create extra one) ///////////////////////////////////////////////////////////// // parallelization ///////////////////////////////////////////////////////////// DWORD tID; HANDLE handle; PhotonsTreeBuildThreadArguments *arguments = new PhotonsTreeBuildThreadArguments(*this, photons, (index << 1), begin, middle, depth+1); handle = CreateThread( NULL, 0, ThreadBuildFunc, (LPVOID)arguments, 0, &tID); ///////////////////////////////////////////////////////////// // Complete second part of tree itself InitTree(photons, (index << 1) | 1, middle+1, end , depth+1); // wait for sibling thread to finish his work WaitForSingleObject(handle, INFINITE); } else { InitTree(photons, (index << 1) , begin , middle, depth+1); InitTree(photons, (index << 1) | 1, middle+1, end , depth+1); } } else { m_treeArray[index] = TreeElement(*middle, ST_LEAF); } }
Point operator+(const Point & p) { return Point(_x + p.x(), _y + p.y()); }