const Vertex* Shape::getVertex(const Coordinate &cCoordinate) const { //Go through all of the vertices contained for (std::vector<Vertex*>::const_iterator iter = internals().begin() ; iter != internals().end() ; iter++) { //And return the one that overlaps the coordinate if (**iter == cCoordinate) return (*iter); } //Otherwise dont return anything return NULL; }
void runLayer(Ptr<Layer> layer, const std::vector<Mat>& inputs, std::vector<Mat>& outputs) { std::vector<MatShape> inpShapes(inputs.size()); int ddepth = CV_32F; for (size_t i = 0; i < inputs.size(); ++i) { inpShapes[i] = shape(inputs[i]); if (i > 0 && ddepth != inputs[i].depth()) CV_Error(Error::StsNotImplemented, "Mixed input data types."); ddepth = inputs[i].depth(); } std::vector<MatShape> outShapes, internalShapes; layer->getMemoryShapes(inpShapes, 0, outShapes, internalShapes); std::vector<Mat> internals(internalShapes.size()); outputs.resize(outShapes.size()); for (size_t i = 0; i < outShapes.size(); ++i) outputs[i].create(outShapes[i], ddepth); for (size_t i = 0; i < internalShapes.size(); ++i) internals[i].create(internalShapes[i], ddepth); layer->finalize(inputs, outputs); layer->forward(inputs, outputs, internals); }
DWORD gm_receiver_c::notify_receivers(int ev, gmsgbase &par) { evlst_s &l = internals()(ev); if (l._curnext) return GMRBIT_FAIL; // recursive ev call! NOT supported for(;ASSERT(par.pass < 100, "100 iterations! vow vow");) { DWORD bits = 0; gm_receiver_c *f = l._gmer_first; for (; f;) { l._curnext = f->_gmer_next; bits |= f->event_happens(par); if (FLAG(bits, GMRBIT_ABORT)) { l._curnext = nullptr; return bits; } f = l._curnext; } if (!FLAG(bits, GMRBIT_CALLAGAIN)) { ASSERT( nullptr == l._curnext ); return bits; } ++par.pass; } return GMRBIT_FAIL; }
static CStrInternInternals* GetString(const char* str, size_t len) { // g_Strings is not thread-safe, so complain if anyone is using this // type in non-main threads. (If that's desired, g_Strings should be changed // to be thread-safe, preferably without sacrificing performance.) ENSURE(ThreadUtil::IsMainThread()); #if BOOST_VERSION >= 104200 StringsKeyProxy proxy = { str, len }; boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it = g_Strings.find(proxy, StringsKeyProxyHash(), StringsKeyProxyEq()); #else // Boost <= 1.41 doesn't support the new find(), so do a slightly less efficient lookup boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it = g_Strings.find(str); #endif if (it != g_Strings.end()) return it->second.get(); shared_ptr<CStrInternInternals> internals(new CStrInternInternals(str, len)); g_Strings.insert(std::make_pair(internals->data, internals)); return internals.get(); }
void gm_receiver_c::prepare( int evcnt ) { internals().prepare(evcnt); }
void gm_receiver_c::unsubscribe(int ev) { evlst_s &l = internals()(ev); if (l._curnext == this) l._curnext = _gmer_next; LIST_DEL(this, l._gmer_first, l._gmer_last, _gmer_prev, _gmer_next); }
gm_receiver_c::gm_receiver_c(int ev) { evlst_s &l = internals()(ev); LIST_ADD(this, l._gmer_first, l._gmer_last, _gmer_prev, _gmer_next); }
void PlanarDrawLayout::computeCoordinates(const Graph &G, ShellingOrder &order, NodeArray<int> &x, NodeArray<int> &y) { // let c_1,...,c_q be the the current contour, then // next[c_i] = c_i+1, prev[c_i] = c_i-1 NodeArray<node> next(G), prev(G); // upper[v] = w means x-coord. of v is relative to w // (abs. x-coord. of v = x[v] + abs. x-coord of w) NodeArray<node> upper(G,nullptr); // maximal rank of a neighbour NodeArray<int> maxNeighbour(G,0); // internal nodes (nodes not on contour) BoundedStack<node> internals(G.numberOfNodes()); for(node v : G.nodes) { for(adjEntry adj : v->adjEdges) { int r = order.rank(adj->twinNode()); if (r > maxNeighbour[v]) maxNeighbour[v] = r; } } // initialize contour with base const ShellingOrderSet &V1 = order[1]; node v1 = V1[1]; node v2 = V1[V1.len()]; node rightSide = v2; int i; for (i = 1; i <= V1.len(); ++i) { y[V1[i]] = 0; x[V1[i]] = (i == 1) ? 0 : 1; if (i < V1.len()) next[V1[i]] = V1[i+1]; if (i > 1) prev[V1[i]] = V1[i-1]; } prev[v1] = next[v2] = nullptr; // process shelling order from bottom to top for (int k = 2; k <= order.length(); k++) { // Referenz auf aktuelle Menge Vk (als Abk?rzung) const ShellingOrderSet &Vk = order[k]; // Vk = { z_1,...,z_l } int l = Vk.len(); node z1 = Vk[1]; node cl = Vk.left(); // left vertex node cr = Vk.right(); // right vertex bool isOuter; if (m_sideOptimization && cr == rightSide && maxNeighbour[cr] <= k) { isOuter = true; rightSide = Vk[l]; } else isOuter = false; // compute relative x-distance from c_i to cl for i = l+1, ..., r int sum = 0; for (node v = next[cl]; v != cr; v = next[v]) { sum += x[v]; x[v] = sum; } x[cr] += sum; int eps = (maxNeighbour [cl] <= k && k > 2) ? 0 : 1; int x_cr, y_z; if (m_sizeOptimization) { int yMax; if (isOuter) { yMax = max(y[cl]+1-eps, y[cr] + ((x[cr] == 1 && eps == 1) ? 1 : 0)); for (node v = next[cl]; v != cr; v = next[v]) { if (x[v] < x[cr]) { int y1 = (y[cr]-y[v])*(eps-x[cr])/(x[cr]-x[v])+y[cr]; if (y1 >= yMax) yMax = 1+y1; } } for (node v = cr; v != cl; v = prev[v]) { if (y[prev[v]] > y[v] && maxNeighbour[v] >= k) { if (yMax <= y[v] + x[v] - eps) { eps = 1; yMax = y[v] + x[v]; } break; } } x_cr = max(x[cr]-eps-l+1, (y[cr] == yMax) ? 1 : 0); y_z = yMax; } else { // yMax = max { y[c_i] | l <= i <= r } yMax = y[cl] - eps; for (node v = cr; v != cl; v = prev[v]) { if (y[v] > yMax) yMax = y[v]; } int offset = max (yMax-x[cr]+l+eps-y[cr], (y[prev[cr]] > y[cr]) ? 1 : 0); y_z = y[cr] + x[cr] + offset - l + 1 - eps; x_cr = y_z - y[cr]; } } else { y_z = y[cr] + x[cr] + 1 - eps; x_cr = y_z - y[cr]; } node alpha = cl; for (node v = next[cl]; maxNeighbour[v] <= k-1 && order.rank(v) <= order.rank(prev[v]); v = next[v]) { if (order.rank (v) < order.rank (alpha)) alpha = v; if (v == cr) break; } node beta = prev[cr]; for (node v = prev[cr]; maxNeighbour[v] <= k-1 && order.rank(v) <= order.rank(next[v]); v = prev[v]) { if (order.rank (v) <= order.rank (beta)) beta = v; if (v == cl) break; } for (i = 1; i <= l; ++i) { x[Vk[i]] = 1; y[Vk[i]] = y_z; } x[z1] = eps; for (node v = alpha; v != cl; v = prev [v]) { upper[v] = cl; internals.push (v); } for (node v = next [beta]; v != cr; v = next [v]) { upper[v] = cr; x [v] -= x[cr]; internals.push (v); } for (node v = beta; v != alpha; v = prev[v]) { upper[v] = z1; x [v] -= x[z1]; internals.push (v); } x[cr] = x_cr; // update contour after insertion of z_1,...,z_l for (i = 1; i <= l; i++) { if (i < l) next[Vk[i]] = Vk[i+1]; if (i > 1) prev[Vk[i]] = Vk[i-1]; } next [cl] = z1; next [Vk[l]] = cr; prev [cr] = Vk[l]; prev [z1] = cl; } // compute final x-coordinates for the nodes on the (final) contour int sum = 0; for (node v = v1; v != nullptr; v = next[v]) x [v] = (sum += x[v]); // compute final x-coordinates for the internal nodes while (!internals.empty()) { node v = internals.pop(); x[v] += x[upper[v]]; } }