bool deletePkgInfo(const char *name, const char *target, const char *process, bool globalScope) { Owned<IRemoteConnection> pkgSetsConn = querySDS().connect("/PackageSets/", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT); if (!pkgSetsConn) throw MakeStringException(PKG_NONE_DEFINED, "No package sets defined"); IPropertyTree* packageSets = pkgSetsConn->queryRoot(); StringBuffer pkgSetId; buildPkgSetId(pkgSetId, process); VStringBuffer pkgSet_xpath("PackageSet[@id='%s']", pkgSetId.str()); IPropertyTree *pkgSetRegistry = packageSets->queryPropTree(pkgSet_xpath.str()); if (!pkgSetRegistry) throw MakeStringException(PKG_TARGET_NOT_DEFINED, "No package sets defined for %s", process); StringBuffer lcTarget(target); target = lcTarget.toLowerCase().str(); StringBuffer lcName(name); name = lcName.toLowerCase().str(); Owned<IPropertyTree> mapEntry; StringBuffer xpath; if (!globalScope) { xpath.appendf("PackageMap[@id='%s::%s'][@querySet='%s']", target, name, target); mapEntry.setown(pkgSetRegistry->getPropTree(xpath.str())); } if (!mapEntry) { xpath.clear().appendf("PackageMap[@id='%s'][@querySet='%s']", name, target); mapEntry.setown(pkgSetRegistry->getPropTree(xpath.str())); if (!mapEntry) throw MakeStringException(PKG_DELETE_NOT_FOUND, "Unable to delete %s - information not found", lcName.str()); } StringAttr pmid(mapEntry->queryProp("@id")); pkgSetRegistry->removeTree(mapEntry); xpath.clear().appendf("PackageSet/PackageMap[@id='%s']", pmid.get()); if (!packageSets->hasProp(xpath)) { Owned<IRemoteConnection> pkgMapsConn = querySDS().connect("/PackageMaps/", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT); if (!pkgMapsConn) throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageMaps information from dali [/PackageMaps]"); IPropertyTree *pkgMaps = pkgMapsConn->queryRoot(); if (!pkgMaps) throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageMaps information from dali [/PackageMaps]"); IPropertyTree *mapTree = pkgMaps->queryPropTree(xpath.clear().appendf("PackageMap[@id='%s']", pmid.get()).str()); if (mapTree) pkgMaps->removeTree(mapTree); } return true; }
int main(int argc, char** argv) { try { std::wstring modelURL (L"http://models.cellml.org/workspace/hodgkin_huxley_1952/@@rawfile/949cd4d3/hodgkin_huxley_1952.cellml"); // Create a CellML Bootstrap and a model loader. ObjRef<iface::cellml_api::CellMLBootstrap> bootstrap(CreateCellMLBootstrap()); ObjRef<iface::cellml_api::DOMModelLoader> loader(bootstrap->modelLoader()); // Load a CellML model. ObjRef<iface::cellml_api::Model> hhModel (loader->loadFromURL(modelURL)); // Request a RDF/API capable RDF representation... ObjRef<iface::cellml_api::RDFRepresentation> rr(hhModel->getRDFRepresentation(L"http://www.cellml.org/RDF/API")); ObjRef<iface::rdf_api::RDFAPIRepresentation> rrHH(QueryInterface(rr)); // Retrieve the DataSource. Note: Changes to the data source are not pushed back // to the model until the source attribute is set on the rrHH again. ObjRef<iface::rdf_api::DataSource> dsHH(rrHH->source()); // Get the resource corresponding to the cmeta:id on the model. Note that // cmetaId can return the empty string, which you should check for in // production code, if there is no cmeta:id ObjRef<iface::rdf_api::URIReference> hhModelRef (dsHH->getURIReference(bootstrap->makeURLAbsolute(modelURL, L"#" + hhModel->cmetaId()))); #ifdef DUMP_ALL_TRIPLES_FIRST { ObjRef<iface::rdf_api::TripleSet> ts(dsHH->getAllTriples()); ObjRef<iface::rdf_api::TripleEnumerator> te(ts->enumerateTriples()); while (true) { ObjRef<iface::rdf_api::Triple> t(te->getNextTriple()); if (t == NULL) break; displayTriple(t); } } #endif ObjRef<iface::rdf_api::URIReference> pmid(dsHH->getURIReference(L"http://www.cellml.org/bqs/1.0#Pubmed_id")); // Note: Calls like this could fail with an exception if there was no pubmed ID - production code should check. ObjRef<iface::rdf_api::Triple> t(hhModelRef->getTripleOutOfByPredicate(pmid)); ObjRef<iface::rdf_api::Node> n(t->object()); ObjRef<iface::rdf_api::Literal> lPMID(QueryInterface(n)); if (lPMID != NULL) // It will be null if for some reason it isn't a literal... std::wcout << L"Model pubmed ID: " << lPMID->lexicalForm() << std::endl; ObjRef<iface::rdf_api::URIReference> bqsReference(dsHH->getURIReference(L"http://www.cellml.org/bqs/1.0#reference")); ObjRef<iface::rdf_api::TripleSet> ts(hhModelRef->getTriplesOutOfByPredicate(bqsReference)); ObjRef<iface::rdf_api::TripleEnumerator> te(ts->enumerateTriples()); while (true) { t = te->getNextTriple(); if (t == NULL) break; ObjRef<iface::rdf_api::Resource> r(QueryInterface(t->object())); if (r == NULL) continue; std::wcout << L"Found a resource description:" << std::endl; try { t = r->getTripleOutOfByPredicate(pmid); n = t->object(); lPMID = QueryInterface(n); if (lPMID != NULL) std::wcout << L" Reference pubmed ID: " << lPMID->lexicalForm() << std::endl; } catch(...) {} // Look up the subject... ObjRef<iface::rdf_api::URIReference> subject(dsHH->getURIReference(L"http://purl.org/dc/elements/1.1/subject")); ts = r->getTriplesOutOfByPredicate(subject); ObjRef<iface::rdf_api::TripleEnumerator> te2 = ts->enumerateTriples(); while (true) { t = te2->getNextTriple(); if (t == NULL) break; n = t->object(); r = QueryInterface(n); if (r == NULL) continue; std::wcout << " Subject:" << std::endl; ObjRef<iface::rdf_api::URIReference> subjectType(dsHH->getURIReference(L"http://www.cellml.org/bqs/1.0#subject_type")); ts = r->getTriplesOutOfByPredicate(subjectType); ObjRef<iface::rdf_api::TripleEnumerator> te3 = ts->enumerateTriples(); t = te3->getNextTriple(); if (t) { n = t->object(); ObjRef<iface::rdf_api::Literal> l(QueryInterface(n)); std::wcout << " Subject Type=" << l->lexicalForm() << std::endl; } ObjRef<iface::rdf_api::URIReference> value(dsHH->getURIReference(L"http://www.w3.org/1999/02/22-rdf-syntax-ns#value")); ts = r->getTriplesOutOfByPredicate(value); te3 = ts->enumerateTriples(); t = te3->getNextTriple(); if (t == NULL) continue; n = t->object(); r = QueryInterface(n); if (r == NULL) continue; ObjRef<iface::rdf_api::Container> cont(r->correspondingContainer()); // Add a new entry to the container first... ObjRef<iface::rdf_api::PlainLiteral> newPL(dsHH->getPlainLiteral(L"Newly created label", L"en")); cont->appendChild(newPL); // Delete any labels that match 'giant axon'... ObjRef<iface::rdf_api::NodeIterator> ni(cont->iterateChildren()); while (true) { ObjRef<iface::rdf_api::Node> n(ni->getNextNode()); if (n == NULL) break; ObjRef<iface::rdf_api::Literal> l(QueryInterface(n)); if (l == NULL) continue; if (l->lexicalForm() == L"giant axon") // The false means don't renumber immediately. This leaves the // container with gaps... cont->removeChild(l, false); } cont->renumberContainer(); // Remove the gaps. displayContainer(cont, L" "); } } } catch (iface::cellml_api::CellMLException&) { std::wcout << L"A CellMLException was raised. In production code, you would normally have more " << L"exception handlers to work out exactly where the problem occurred. This program " << L"avoids that for simplicity, to make the normal control flow easier to understand. " << L"The most likely cause is a network problem retrieving the hardcoded model URL." << std::endl; return 1; } catch (iface::rdf_api::RDFProcessingError&) { std::wcout << L"An RDFProcessingError was raised. In production code, you would normally have more " << L"exception handlers to work out exactly where the problem occurred. This program " << L"avoids that for simplicity, to make the normal control flow easier to understand." << std::endl; return 2; } return 0; }
void F2M::buildMesh(CorrPtr cp0, VertexPtr * v0s){ if (!cp0) return; CorrPtr cp00 = cp0; Vec3 n001(0,0,1); list<CorrPtr> que; //CorrPtr cp0 = que.front(); //que.pop_front(); bool exit = false; while(cp0 && !exit){ if (cp0->isTip()) exit = 1; //*/ VertexPtr * v1s = createVerts(cp0->P(), cp0->corr()->P()); v1s[0]->setN(-cp0->N()); v1s[5]->setN(-cp0->corr()->N()); v1s[1]->setN( ((v1s[0]->getN() + v1s[2]->getN())*0.5).normalize() ); v1s[4]->setN( ((v1s[3]->getN() + v1s[5]->getN())*0.5).normalize() ); if (exit){ Vec3 nz(0,0,1); v1s[2]->setN(v1s[0]->getP() - v1s[2]->getP()); v1s[3]->setN(v1s[1]->getP() - v1s[3]->getP()); } //_mesh->addQuad(vfirst, v0, v1, vlast); for(int i=0; i < _vnum-1; i++) _mesh->addQuad(v1s[i], v1s[i+1], v0s[i+1], v0s[i]); if (cp0->isSplit()){ //we just hit a joint list<VertexPtr> verts; /*for(int i=1; i<_vnum-1; i++) verts.push_back(v1s[_vnum-i-1]); */ for(int i=0; i<_vnum/2; i++){ VertexPtr tmp = v1s[i]; v1s[i] = v1s[_vnum-i-1]; v1s[_vnum-i-1] = tmp; } Vec3 pmid(0,0,0); int count = 0; for(CorrPtr cpi = cp0->nextCorr(); cpi && cpi!=cp0 && cpi!=cp0->corr(); cpi = cpi->corr()->nextCorr()){ pmid = pmid + cpi->P() + cpi->corr()->P(); count++; } pmid = pmid + cp0->P()+ cp0->corr()->P(); pmid = pmid / ( (count+1)*2.0 ); VertexPtr * vs0 = v1s; for(CorrPtr cpi = cp0->nextCorr(); cpi && cpi!=cp0 && cpi!=cp0->corr(); cpi = cpi->corr()->nextCorr()){ VertexPtr * vs = createVerts(cpi->P(), cpi->corr()->P()); vs[0]->setN(-cpi->N()); vs[5]->setN(-cpi->corr()->N()); vs[1]->setN( ((vs[0]->getN() + vs[2]->getN())*0.5).normalize() ); vs[4]->setN( ((vs[3]->getN() + vs[5]->getN())*0.5).normalize() ); buildMesh(cpi->nextCorr(), vs); /*for(int i=1; i<_vnum-1; i++) verts.push_back(vs[i]); */ if (vs0){ CPPtr cpmid = cpi->go(cpi->find(cpi->prevCorr()) / 2); Vec3 p0 = cpmid->P(); Vec3 p1 = p0 + (pmid - p0)*0.75; //(vs[_vnum/2-1]->getP() + vs0[_vnum/2]->getP())*0.5; VertexPtr * vs01 = createMidVerts(p0, p1); vs01[0]->setN(-cpmid->N()); vs01[1]->setN( ((vs01[0]->getN() + vs01[2]->getN())*0.5).normalize() ); int i = 0; for( ; i<_vnum/2-1; i++){ _mesh->addQuad(vs[i], vs[i+1], vs01[i+1], vs01[i]); _mesh->addQuad(vs01[i], vs01[i+1], vs0[_vnum-i-2], vs0[_vnum-i-1]); } i--; verts.push_back(vs0[_vnum-i-2]); verts.push_back(vs01[i+1]); verts.push_back(vs[i+1]); } vs0 = vs; } CPPtr cpmid = cp0->corr()->go(cp0->corr()->find(cp0->corr()->prevCorr()) / 2); Vec3 p0 = cpmid->P(); Vec3 p1 = p0 + (pmid - p0)*0.75;//(v1s[_vnum/2-1]->getP() + vs0[_vnum/2]->getP())*0.5; VertexPtr * vs01 = createMidVerts(p0, p1); vs01[0]->setN(-cpmid->N()); vs01[1]->setN( ((vs01[0]->getN() + vs01[2]->getN())*0.5).normalize() ); int i = 0; for( ; i<_vnum/2-1; i++){ _mesh->addQuad(v1s[i], v1s[i+1], vs01[i+1], vs01[i]); _mesh->addQuad(vs01[i], vs01[i+1], vs0[_vnum-i-2], vs0[_vnum-i-1]); } i--; verts.push_back(vs0[_vnum-i-2]); verts.push_back(vs01[i+1]); verts.push_back(v1s[i+1]); /*int i = 0; for( ; i<_vnum/2-1; i++) _mesh->addQuad(v1s[i], v1s[i+1], vs0[_vnum-i-2], vs0[_vnum-i-1]); i--; verts.push_back(vs0[_vnum-i-2]); verts.push_back(v1s[i+1]); /*FacePtr f = new Face(); _mesh->addFace(f); for (list<VertexPtr>::iterator it = verts.begin(); it != verts.end(); it++) f->addNextVertex(*it); */ //_mesh->addQuad(v1s[0], v1s[1], vs0[4], vs0[5]); //connect the middle Vec3 p; for (list<VertexPtr>::iterator it = verts.begin(); it != verts.end(); it++) p = p+(*it)->getP(); p = p / verts.size(); p.print(); VertexPtr midv = new Vertex(); midv->setP(p); Vec3 n; //midv->setN(Vec3(0,0,0.1)); VertexPtr v0 = 0; int ii =0; for (list<VertexPtr>::iterator it = verts.begin(); it != verts.end(); it++){ VertexPtr v1 = (*it); if (v0){ FacePtr f = new Face(); f->addNextVertex(midv); f->addNextVertex(v0); f->addNextVertex(v1); _mesh->addFace(f); } n = n + v1->getN(); v0 = v1; ii++; //if (ii==3) break; } midv->setN(n/verts.size()); midv->setN(Vec3(0,0,1)); FacePtr f = new Face(); f->addNextVertex(midv); f->addNextVertex(verts.back()); f->addNextVertex(verts.front()); _mesh->addFace(f);//*/ break; } v0s = v1s; cp0 = cp0->nextCorr(); }; if (!cp0 || !cp0->isTip()) return; cp0 = cp0->corr(); double a = cp0->find(cp0->corr())*STEP /(_vnum-1); CPPtr it = cp0; //reposition verticies for(int i = 1; i<_vnum-1; i++){ v0s[i]->setP(cp0->go(a*i)); Vec3 t = (it->go(a*i+STEP) - it->go(a*i-STEP)).normalize(); v0s[i]->setN( -(Eye::get()->N%t).normalize() ); //it = it->next(); } if (cp00->isTip()){ cp00 = cp00->corr(); double a = cp00->find(cp00->corr())*STEP /(_vnum-1); //reposition verticies for(int i = 1; i<_vnum-1; i++){ v0s[i]->setP(cp00->go(a*i)); Vec3 t = (it->go(a*i+STEP) - it->go(a*i-STEP)).normalize(); v0s[i]->setN( -(Eye::get()->N%t).normalize() ); //it = it->next(); } } /* VertexPtr* vs = new VertexPtr[_vnum-2]; for(int i=0; i<_vnum-2; i++) vs[i] = new Vertex(); vs[0]->setP(cp0->P()); vs[3]->setP(cp0->corr()->P()); Vec3 vn = (vs[3]->getP() - vs[0]->getP()); vs[1]->setP(vs[0]->getP()+vn*0.25); vs[2]->setP(vs[0]->getP()+vn*0.75); vs[0]->setN(Vec3(0,0,1)); vs[3]->setN(Vec3(0,0,1)); vs[1]->setN(-cp0->N()); vs[2]->setN(-cp0->corr()->N()); _mesh->addQuad(vs[0], vs[1], v0s[1], v0s[0]); _mesh->addQuad(vs[1], vs[2], v0s[3], v0s[2]); _mesh->addQuad(vs[2], vs[3], v0s[5], v0s[4]); _mesh->addTriangle(vs[1], v0s[2],v0s[1]); _mesh->addTriangle(vs[2], v0s[4],v0s[3]); //*/ }