ZIntCuboid ZStackArray::getBoundBox() const { Cuboid_I box; getBoundBox(&box); return ZIntCuboid(box); }
ZStack* ZStroke2dArray::toStack() const { ZCuboid box = getBoundBox(); ZStack *stack = NULL; if (box.isValid()) { stack = new ZStack(GREY, box.toIntCuboid(), 1); for (const_iterator iter = begin(); iter != end(); ++iter) { const ZStroke2d *stroke = *iter; stroke->labelStack(stack); } } return stack; }
SEXP Rgraphviz_doLayout(SEXP graph, SEXP layoutType, SEXP size) { /* Will perform a Graphviz layout on a graph */ Agraph_t *g; SEXP slotTmp, nLayout, cPoints, bb; /* Extract the Agraph_t pointer from the S4 object */ PROTECT(slotTmp = GET_SLOT(graph, install("agraph"))); CHECK_Rgraphviz_graph(slotTmp); g = R_ExternalPtrAddr(slotTmp); if (size != R_NilValue) { agsafeset(g, "size", CHAR(STRING_ELT(size, 0)), NULL); } /* Call the appropriate Graphviz layout routine */ gvLayout(gvc, g, CHAR(STRING_ELT(layoutType, 0))); /* if (!isInteger(layoutType)) error("layoutType must be an integer value"); else { gvLayout(gvc, g, layouts[INTEGER(layoutType)[0]]); } */ /* Here we want to extract information for the resultant S4 object */ PROTECT(nLayout = getNodeLayouts(g)); PROTECT(bb = getBoundBox(g)); PROTECT(cPoints = getEdgeLocs(g)); SET_SLOT(graph, Rf_install("agraph"), slotTmp); SET_SLOT(graph,Rf_install("AgNode"), nLayout); SET_SLOT(graph,Rf_install("laidout"), Rgraphviz_ScalarLogicalFromRbool(TRUE)); SET_SLOT(graph,Rf_install("AgEdge"), cPoints); SET_SLOT(graph,Rf_install("boundBox"), bb); SET_SLOT(graph,Rf_install("fg"), Rgraphviz_ScalarStringOrNull(agget(g, "fgcolor"))); SET_SLOT(graph,Rf_install("bg"), Rgraphviz_ScalarStringOrNull(agget(g, "bgcolor"))); UNPROTECT(4); /* free gvc after rendering */ gvFreeLayout(gvc, g); return(graph); }
void triangle(Vec3i t0, Vec3i t1, Vec3i t2, Vec2i uv0, Vec2i uv1, Vec2i uv2, float intensity, int* zbuf, TGAImage& image) { if (isDegenerated(t0,t1,t2)) return; if (t0.y > t1.y) { std::swap(t0, t1); std::swap(uv0, uv1); } if (t0.y > t2.y) { std::swap(t0, t2); std::swap(uv0, uv2); } if (t1.y > t2.y) { std::swap(t1, t2); std::swap(uv1, uv2); } int* boundbox = getBoundBox(t0, t1, t2); Vec2i vertex(t1.x - t0.x, t1.y - t0.y); Vec2i tmpUv(uv1.x - uv0.x, uv1.y - uv0.y); for (int x = boundbox[0]; x <= boundbox[2]; x++) { for (int y = boundbox[1]; y <= boundbox[3]; y++) { if (insideTriangle(x, y, t0, t1, t2)) { int idx = x + y * width; int z = find_z(x, y, t0, t1, t2); Vec2i P(x, y), v(t0.x, t0.y); Vec2i s01(t1.x - t0.x, t1.y - t0.y), s02(t2.x - t0.x, t2.y - t0.y), sp0(t0.x - P.x, t0.y - P.y); Vec3i tmp1(s01.x, s02.x, sp0.x), tmp2(s01.y, s02.y, sp0.y); Vec3i tmp3 = tmp1 ^ tmp2; Vec3f res(tmp3.x, tmp3.y, tmp3.z); if (res.z != 0) { res = res * (1 / res.z); } else { continue; } Vec2f uvP = uv0 * (1 - res.x - res.y) + uv1 * res.x + uv2 * res.y; if (zbuf[idx] < z) { zbuf[idx] = z; TGAColor color = model->getDiffusive(uvP); image.set(x, y, TGAColor(color.r * intensity , color.g * intensity , color.b * intensity , 255)); } } } } delete[] boundbox; }