void PbfElementIterator::_next() { if (_blobIndex < (int)_blobs.size()) { _reader->parseBlob(_blobs[_blobIndex++], _in.get(), _map); const NodeMap& nodes = _map->getNodeMap(); for (NodeMap::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { _addElement(_map->getNode(it->first)); } const WayMap& ways = _map->getWays(); for (WayMap::const_iterator it = ways.begin(); it != ways.end(); ++it) { _addElement(_map->getWay(it->first)); } const RelationMap& relations = _map->getRelationMap(); for (RelationMap::const_iterator it = relations.begin(); it != relations.end(); ++it) { _addElement(_map->getRelation(it->first)); } _map->clear(); } }
bool Screen::_addFrame(shared_ptr<JsonObject> entry) { if (entry) { bool valid = true; std::string type = extractValue<std::string>(entry->getValue("type"), &valid); Point pos = extractValue<Point>(entry->getValue("pos"), &valid); Point size = extractValue<Point>(entry->getValue("size")); std::string title = extractValue<std::string>(entry->getValue("title")); if (valid) { if (type.compare("Container") != 0 && type.compare("ObjectInfo") != 0) { auto frame = make_shared<UIFrame>(pos, size, _res, title); auto subElems = std::dynamic_pointer_cast<JsonTValue<std::vector<shared_ptr<JsonValue>>>>(entry->getValue("elements")); if (subElems) { auto children = subElems->getValue(); for (auto tmp : children) { _addElement(std::dynamic_pointer_cast<JsonObject>(tmp), frame.get()); } } _frames.push_back(frame); return true; } } } return false; }
AXmlElement& AXmlElement::addElement(const AString& path, const AEmittable& object, AXmlElement::Encoding encoding, bool overwrite, bool insertIntoFront) { AXmlElement *p = _addElement(path, overwrite, insertIntoFront); AASSERT(this, p); //a_Emit to rope ARope value; object.emit(value); p->addData(value, encoding); return *p; }
void VertexArray::finalize() { if(_data3.size()){ std::set<ElementData<3>, ElementDataLessThan<3> >::iterator it = _data3.begin(); for(; it != _data3.end(); it++){ for(int i = 0; i < 3; i++){ _addVertex(it->x(i), it->y(i), it->z(i)); _addNormal(it->nx(i), it->ny(i), it->nz(i)); _addColor(it->r(i), it->g(i), it->b(i), it->a(i)); _addElement(it->ele()); } } _data3.clear(); } _barycenters.clear(); }
void VertexArray::add(double *x, double *y, double *z, SVector3 *n, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a, MElement *ele, bool unique, bool boundary) { int npe = getNumVerticesPerElement(); if(boundary && npe == 3){ ElementData<3> e(x, y, z, n, r, g, b, a, ele); ElementDataLessThan<3>::tolerance = (float)(CTX::instance()->lc * 1.e-12); std::set<ElementData<3>, ElementDataLessThan<3> >::iterator it = _data3.find(e); if(it == _data3.end()) _data3.insert(e); else _data3.erase(it); return; } // enabling this will reduce memory and rendering time; but will increase the // time it takes to create the vertex array #if 0 if(unique){ Barycenter pc(0.0F, 0.0F, 0.0F); for(int i = 0; i < npe; i++) pc += Barycenter(x[i], y[i], z[i]); BarycenterLessThan::tolerance = (float)(CTX::instance()->lc * 1.e-12); if(_barycenters.find(pc) != _barycenters.end()) return; _barycenters.insert(pc); } #endif for(int i = 0; i < npe; i++){ _addVertex((float)x[i], (float)y[i], (float)z[i]); if(n) _addNormal((float)n[i].x(), (float)n[i].y(), (float)n[i].z()); if(r && g && b && a) _addColor(r[i], g[i], b[i], a[i]); _addElement(ele); } }
Screen::Screen(shared_ptr<ResourceCtl> res, const JsonObject& entry) { _res = res; bool status = true; _backColor = extractWithDefault<ALLEGRO_COLOR>(entry.getValue("backColor"), al_map_rgb(12, 41, 17)); _isMapScreen = extractWithDefault<bool>(entry.getValue("map"), false); std::string name = extractValue<std::string>(entry.getValue("name")); auto framePtr = std::dynamic_pointer_cast<JsonTValue<std::vector<shared_ptr<JsonValue>>>>(entry.getValue("frames")); auto elemPtr = std::dynamic_pointer_cast<JsonTValue<std::vector<shared_ptr<JsonValue>>>>(entry.getValue("elements")); if (framePtr) { auto frameArr = framePtr->getValue(); for (auto tmp : frameArr) { _addFrame(std::dynamic_pointer_cast<JsonObject>(tmp)); } } if (elemPtr) { auto elemArr = elemPtr->getValue(); for (auto tmp : elemArr) { _addElement(std::dynamic_pointer_cast<JsonObject>(tmp)); } } }
AXmlElement& AXmlElement::addElement(const AString& path, bool insertIntoFront) { AXmlElement *p = _addElement(path, false, insertIntoFront); AASSERT(this, p); return *p; }
AXmlElement& AXmlElement::overwriteElement(const AString& path) { AXmlElement *p = _addElement(path, true, false); AASSERT(this, p); return *p; }
void AXmlElement::setBool(const AString& path, bool value) { _addElement(path, true)->setData(value ? AConstant::ASTRING_TRUE : AConstant::ASTRING_FALSE); }
void AXmlElement::setSize_t(const AString& path, size_t value) { _addElement(path, true)->setData(value); }
void AXmlElement::setInt(const AString& path, int value) { _addElement(path, true)->setData(value); }
void AXmlElement::setString(const AString& path, const AString& value, AXmlElement::Encoding encoding) { _addElement(path, true)->setData(value, encoding); }
void GMSH_LevelsetPlugin::_cutAndAddElements(PViewData *vdata, PViewData *wdata, int ent, int ele, int vstep, int wstep, double x[8], double y[8], double z[8], double levels[8], double scalarValues[8], PViewDataList* out) { int stepmin = vstep, stepmax = vstep + 1, otherstep = wstep; if(stepmin < 0){ stepmin = vdata->getFirstNonEmptyTimeStep(); stepmax = vdata->getNumTimeSteps(); } if(wstep < 0) otherstep = wdata->getFirstNonEmptyTimeStep(); int numNodes = vdata->getNumNodes(stepmin, ent, ele); int numEdges = vdata->getNumEdges(stepmin, ent, ele); int numComp = wdata->getNumComponents(otherstep, ent, ele); int type = vdata->getType(stepmin, ent, ele); // decompose the element into simplices for(int simplex = 0; simplex < numSimplexDec(type); simplex++){ int n[4], ep[12], nsn, nse; getSimplexDec(numNodes, numEdges, type, simplex, n[0], n[1], n[2], n[3], nsn, nse); // loop over time steps for(int step = stepmin; step < stepmax; step++){ // check which edges cut the iso and interpolate the value if(wstep < 0) otherstep = step; if(!wdata->hasTimeStep(otherstep)) continue; int np = 0; double xp[12], yp[12], zp[12], valp[12][9]; for(int i = 0; i < nse; i++){ int n0 = exn[nse][i][0], n1 = exn[nse][i][1]; if(levels[n[n0]] * levels[n[n1]] <= 0.) { double c = InterpolateIso(x, y, z, levels, 0., n[n0], n[n1], &xp[np], &yp[np], &zp[np]); for(int comp = 0; comp < numComp; comp++){ double v0, v1; wdata->getValue(otherstep, ent, ele, n[n0], comp, v0); wdata->getValue(otherstep, ent, ele, n[n1], comp, v1); valp[np][comp] = v0 + c * (v1 - v0); } ep[np++] = i + 1; } } // remove identical nodes (this can happen if an edge actually // belongs to the zero levelset, i.e., if levels[] * levels[] == 0) if(np > 1) removeIdenticalNodes(&np, numComp, xp, yp, zp, valp, ep); // if there are no cuts and we extract the volume, save the full // element if it is on the correct side of the levelset if(np <= 1 && _extractVolume){ bool add = true; for(int nod = 0; nod < nsn; nod++){ if((_extractVolume < 0. && levels[n[nod]] > 0.) || (_extractVolume > 0. && levels[n[nod]] < 0.)){ add = false; break; } } if(add){ for(int nod = 0; nod < nsn; nod++){ xp[nod] = x[n[nod]]; yp[nod] = y[n[nod]]; zp[nod] = z[n[nod]]; for(int comp = 0; comp < numComp; comp++) wdata->getValue(otherstep, ent, ele, n[nod], comp, valp[nod][comp]); } _addElement(nsn, nse, numComp, xp, yp, zp, valp, out, step == stepmin); } continue; } // discard invalid cases if(numEdges > 4 && np < 3) // 3D input should only lead to 2D output continue; else if(numEdges > 1 && np < 2) // 2D input should only lead to 1D output continue; else if(np < 1 || np > 4) // can't deal with this continue; // avoid "butterflies" if(np == 4) reorderQuad(numComp, xp, yp, zp, valp, ep); // orient the triangles and the quads to get the normals right if(!_extractVolume && (np == 3 || np == 4)) { // compute invertion test only once for spatially-fixed views if(step == stepmin || !_valueIndependent) { double v1[3] = {xp[2] - xp[0], yp[2] - yp[0], zp[2] - zp[0]}; double v2[3] = {xp[1] - xp[0], yp[1] - yp[0], zp[1] - zp[0]}; double gr[3], normal[3]; prodve(v1, v2, normal); switch (_orientation) { case MAP: gradSimplex(x, y, z, scalarValues, gr); prosca(gr, normal, &_invert); break; case PLANE: prosca(normal, _ref, &_invert); break; case SPHERE: gr[0] = xp[0] - _ref[0]; gr[1] = yp[0] - _ref[1]; gr[2] = zp[0] - _ref[2]; prosca(gr, normal, &_invert); case NONE: default: break; } } if(_invert > 0.) { double xpi[12], ypi[12], zpi[12], valpi[12][9]; int epi[12]; for(int k = 0; k < np; k++) affect(xpi, ypi, zpi, valpi, epi, k, xp, yp, zp, valp, ep, k, numComp); for(int k = 0; k < np; k++) affect(xp, yp, zp, valp, ep, k, xpi, ypi, zpi, valpi, epi, np - k - 1, numComp); } } // if we extract volumes, add the nodes on the chosen side // (FIXME: when cutting 2D views, the elts can have the wrong // orientation) if(_extractVolume){ int nbCut = np; for(int nod = 0; nod < nsn; nod++){ if((_extractVolume < 0. && levels[n[nod]] < 0.) || (_extractVolume > 0. && levels[n[nod]] > 0.)){ xp[np] = x[n[nod]]; yp[np] = y[n[nod]]; zp[np] = z[n[nod]]; for(int comp = 0; comp < numComp; comp++) wdata->getValue(otherstep, ent, ele, n[nod], comp, valp[np][comp]); ep[np] = -(nod + 1); // store node num! np++; } } removeIdenticalNodes(&np, numComp, xp, yp, zp, valp, ep); if(np == 4 && numEdges <= 4) reorderQuad(numComp, xp, yp, zp, valp, ep); if(np == 6) reorderPrism(numComp, xp, yp, zp, valp, ep, nbCut); if(np > 8) // can't deal with this continue; } // finally, add the new element _addElement(np, numEdges, numComp, xp, yp, zp, valp, out, step == stepmin); } if(vstep < 0){ for(int i = stepmin; i < stepmax; i++) { out->Time.push_back(vdata->getTime(i)); } } } }