public: void markCell(Cell* cell){ if(!isBorder(cell)) return; cell->setMark(getMark()); for(int axis=0; axis<3; axis++){ for(int dir=0; dir<2; dir++){ if(axis == td->getSwAxis() && dir == 1 - td->getSwDirection()) continue; cell->getSide(axis, dir)->setMark(getMark()); } for(int irib=0; irib<4; irib++){ Rib* rib = cell->getRib(axis, irib); if(axis == td->getSwAxis()){ rib->setMark(getMark()); } else if(axis == (td->getSwAxis() + 1)%3){ if(td->getSwDirection() == Cell::FORWARD_SIDE){ if(irib == Cell::ur || irib == Cell::dr) rib->setMark(getMark()); } else if(td->getSwDirection() == Cell::BACKWARD_SIDE){ if(irib == Cell::ul || irib == Cell::dl) rib->setMark(getMark()); } } else if(axis == (td->getSwAxis() + 2)%3){ if(td->getSwDirection() == Cell::FORWARD_SIDE){ if(irib == Cell::ur || irib == Cell::ul) rib->setMark(getMark()); } else if(td->getSwDirection() == Cell::BACKWARD_SIDE){ if(irib == Cell::dr || irib == Cell::dl) rib->setMark(getMark()); } } } } }
//-------------------------------------------------------------- void ofApp::draw(){ // voronoi.draw(); // Or feel free to draw the voronoi diagram yourself: cells = voronoi.getCells(); ofRectangle bounds = voronoi.getBounds(); // Draw bounds // ofSetColor(220); // ofRect(bounds); // ofSetColor(180, 0, 0); _img.setFromPixels(cam.getPixels().getData(), 340, 350, OF_IMAGE_COLOR); for(int i=0; i<cells.size(); i++) { // Draw cell borders ofBeginShape(); for(int j=0; j<cells[i].pts.size(); j++) { ofPoint lastPt = cells[i].pts[cells[i].pts.size()-1]; if(j > 0) { lastPt = cells[i].pts[j-1]; } ofPoint thisPt = cells[i].pts[j]; if(!isBorder(lastPt) || !isBorder(thisPt)) { ofLine(lastPt, thisPt); } ofSetColor( _img.getColor(lastPt.x * 0.5, lastPt.y * 0.5) ); ofVertex(lastPt); } ofEndShape(); // Draw cell points // ofSetColor(180, 0, 0); // ofFill(); // ofCircle(cells[i].pt, 2); } }
void ShowSubdiv(HWND hw) { HDC dc = GetDC (hw); u32 CB = RGB(255,0,0); for (int z=0; z<dimZ; z++) { for (int x=0; x<dimX; x++) { Texel& T = texels[z*dimX+x]; if (T.N) { pixel (dc,x,z,RGB(127,127,127)); vertex& N = *T.N; int _x=x*3,_y=z*3; if (isBorder(N,0)) { // left SetPixel(dc,_x,_y+0,CB); SetPixel(dc,_x,_y+1,CB); SetPixel(dc,_x,_y+2,CB); } if (isBorder(N,1)) { // fwd SetPixel(dc,_x+0,_y,CB); SetPixel(dc,_x+1,_y,CB); SetPixel(dc,_x+2,_y,CB); } if (isBorder(N,2)) { // right SetPixel(dc,_x+2,_y+0,CB); SetPixel(dc,_x+2,_y+1,CB); SetPixel(dc,_x+2,_y+2,CB); } if (isBorder(N,3)) { // back SetPixel(dc,_x+0,_y+2,CB); SetPixel(dc,_x+1,_y+2,CB); SetPixel(dc,_x+2,_y+2,CB); } } else { pixel (dc,x,z,RGB(0,127,0)); } } } ReleaseDC (hw, dc); }
bool Board::isWall(int x, int y) { if (isBorder(x, y)) { // If we can teleport, the borders are // not collidable - we'll just walk through them. return (this->style == Board::SOLID); } return (this->board->at(x, y)); }
public: void markCell(Cell* cell){ if(!isBorder(cell)) return; cell->setMark(getMark()); for(int axis=0; axis<3; axis++){ for(int dir=0; dir<2; dir++){ Side* side = cell->getSide(axis, dir); if(isBorder(side->getBCell()) && isBorder(side->getFCell())) side->setMark(getMark()); } for(int irib=0; irib<4; irib++){ Rib* rib = cell->getRib(axis, irib); /* if((rib->getCell(Cell::ur) == NULL || isBorder(rib->getCell(Cell::ur))) && (rib->getCell(Cell::ul) == NULL || isBorder(rib->getCell(Cell::ul))) && (rib->getCell(Cell::dl) == NULL || isBorder(rib->getCell(Cell::dl))) && (rib->getCell(Cell::dr) == NULL || isBorder(rib->getCell(Cell::dr))) ) */ rib->setMark(getMark()); } } }
static void fillBitmap(BBitmap &bitmap) { int32 height = bitmap.Bounds().IntegerHeight()+1; int32 width = bitmap.Bounds().IntegerWidth()+1; for (int32 y = 0; y < height; y ++) { for (int32 x = 0; x < width; x ++) { char *pixel = (char*)bitmap.Bits(); pixel += bitmap.BytesPerRow() * y + 4 * x; if (isBorder(x, y, width, height)) { // fill with green pixel[0] = 255; pixel[1] = 0; pixel[2] = 255; pixel[3] = 0; } else { // fill with blue pixel[0] = 255; pixel[1] = 0; pixel[2] = 0; pixel[3] = 255; } } } }
void calcArea() { static Point ps[MAX_N_BORDER]; int cnt = 0; if (qt - qh <= 2) { puts("0.0"); return; } for (int i = qh; i < qt; ++i) { int next = i + 1 == qt ? qh : i + 1; ps[cnt++] = isBorder(que[i], que[next]); } double area = 0; for (int i = 0; i < cnt; ++i) { area += ps[i].det(ps[(i + 1) % cnt]); } area /= 2; area = fabsl(area); cout.setf(ios::fixed); cout.precision(1); cout << area << endl; }
public: int getBorderMark(Cell* cell){ if(!isBorder(cell)) return NULL; return getMark(); };
bool check(const Border&a, const Border&b, const Border&me) { Point is = isBorder(a, b); return crossOp(me.p1,me.p2,is) > 0; }