void BasicHDT::loadTriplesFromHDTs(const char** fileNames, size_t numFiles, const char* baseUri, ProgressListener* listener) { // Generate Triples ModifiableTriples* triplesList = new TriplesList(spec); //ModifiableTriples *triplesList = new TriplesKyoto(spec); //ModifiableTriples *triplesList = new TripleListDisk(); StopWatch st; IntermediateListener iListener(listener); try { NOTIFY(listener, "Loading Triples", 0, 100); iListener.setRange(0, 60); triplesList->startProcessing(&iListener); TriplesLoader tripLoader(dictionary, triplesList, &iListener); // FIXME: Import from files uint64_t totalOriginalSize=0; BasicHDT hdt; for(size_t i=0;i<numFiles;i++) { const char *fileName = fileNames[i]; cout << endl << "Load triples from " << fileName << endl; hdt.mapHDT(fileName); Dictionary *dict = hdt.getDictionary(); // Create mapping arrays unsigned int nsubjects = dict->getNsubjects(); LogSequence2 subjectMap(bits(dictionary->getNsubjects()), nsubjects); subjectMap.resize(nsubjects); for(unsigned int i=0;i<nsubjects;i++) { string str = dict->idToString(i+1, SUBJECT); unsigned int newid = dictionary->stringToId(str, SUBJECT); subjectMap.set(i, newid); } unsigned int npredicates = dict->getNpredicates(); LogSequence2 predicateMap(bits(dictionary->getNpredicates()), npredicates); predicateMap.resize(npredicates); for(unsigned int i=0;i<npredicates;i++) { string str = dict->idToString(i+1, PREDICATE); unsigned int newid = dictionary->stringToId(str, PREDICATE); predicateMap.set(i, newid); } unsigned int nobjects = dict->getNobjects(); LogSequence2 objectMap(bits(dictionary->getNobjects()), nobjects); objectMap.resize(nobjects); for(unsigned int i=0;i<nobjects;i++) { string str = dict->idToString(i+1, OBJECT); unsigned int newid = dictionary->stringToId(str, OBJECT); objectMap.set(i, newid); } totalOriginalSize += hdt.getHeader()->getPropertyLong("_:statistics", HDTVocabulary::ORIGINAL_SIZE.c_str()); size_t numtriples = hdt.getTriples()->getNumberOfElements(); IteratorTripleID *it = hdt.getTriples()->searchAll(); TripleID newTid; char str[100]; long long int j = 0; while(it->hasNext()) { TripleID *tid = it->next(); newTid.setAll( (unsigned int)subjectMap.get(tid->getSubject()-1), (unsigned int)predicateMap.get(tid->getPredicate()-1), (unsigned int)objectMap.get(tid->getObject()-1) ); triplesList->insert(newTid); if ((listener != NULL) && (j % 100000) == 0) { sprintf(str, "%lld triples added.", j); listener->notifyProgress((j*100)/numtriples, str); } j++; } delete it; } triplesList->stopProcessing(&iListener); // SORT & Duplicates TripleComponentOrder order = parseOrder(spec.get("triplesOrder").c_str()); if (order == Unknown) { order = SPO; } iListener.setRange(80, 85); triplesList->sort(order, &iListener); iListener.setRange(85, 90); triplesList->removeDuplicates(&iListener); header->insert("_:statistics", HDTVocabulary::ORIGINAL_SIZE, totalOriginalSize); } catch (const char *e) { cout << "Catch exception triples" << e << endl; delete triplesList; throw e; } catch (char *e) { cout << "Catch exception triples" << e << endl; delete triplesList; throw e; } if (triples->getType() == triplesList->getType()) { delete triples; triples = triplesList; } else { iListener.setRange(90, 100); try { triples->load(*triplesList, &iListener); } catch (const char* e) { delete triplesList; throw e; } delete triplesList; } //cout << triples->getNumberOfElements() << " triples added in " << st << endl << endl; }
static int bit(u32 rw, int bit) { return bits(rw, bit, bit); }
void ScanForInvariants(BLOCK *b) { BLOCKLIST *bl = b->succ; QUAD *head = b->head; b->preWalk = current++; while (head != b->tail->fwd) { QUAD *next = head->fwd; if (!head->ignoreMe && head->dc.opcode != i_label && head->dc.opcode != i_assnblock) { if (head->dc.opcode == i_phi) { LOOP *parent = head->block->inclusiveLoopParent; struct _phiblock *pb; if (!parent->invariantPhiList) { LOOP *last = parent->parent; while (last && !last->invariantPhiList) last = last->parent; parent->invariantPhiList = allocbit(tempCount); if (last) memcpy(bits(parent->invariantPhiList), bits(last->invariantPhiList), ((tempCount) + (BITINTBITS-1))/BITINTBITS * sizeof(BITINT)); } pb = head->dc.v.phi->temps; while (pb) { setbit(parent->invariantPhiList, pb->Tn); pb = pb->next; } setbit(parent->invariantPhiList, head->dc.v.phi->T0); } else if ((head->temps & TEMP_ANS) && head->ans->mode == i_direct && head->ans->size < ISZ_FLOAT) { tempInfo[head->ans->offset->v.sp->value.i]->blockDefines = b; if (!tempInfo[head->ans->offset->v.sp->value.i]->inductionLoop && ( head->temps & (TEMP_LEFT | TEMP_RIGHT))) { BOOLEAN canMove = TRUE; BLOCK *pbl = NULL, *pbr = NULL; if ((head->temps & TEMP_LEFT) && head->dc.left->mode == i_direct) { pbl = tempInfo[head->dc.left->offset->v.sp->value.i]->blockDefines; } else if (head->dc.left->mode != i_immed) canMove = FALSE; if ((head->temps & TEMP_RIGHT) && head->dc.right->mode == i_direct) { pbr = tempInfo[head->dc.right->offset->v.sp->value.i]->blockDefines; } else if (head->dc.right && head->dc.right->mode != i_immed) canMove = FALSE; if (canMove) canMove = InvariantPhiUsing(head); if (canMove) if (pbl && pbl->preWalk != b->preWalk && pbl->nesting == b->nesting && (!pbr || (pbr->preWalk != b->preWalk && pbr->nesting == b->nesting))) MoveExpression(b, head, pbl, pbr); } /* else if (head->dc.opcode == i_assn && head->dc.left->mode == i_immed) { if (!isarithmeticconst(head->dc.left->offset)) { LOOP *lp = b->loopParent; if (lp) { BLOCK *b1 = lp->entry; if (b1) { b1 = blockArray[b1->idom]; if (b1 && b1 != b) { // MoveTo(b1, b, head); } } } } } */ } } head = next; } while (bl) { if (!bl->block->preWalk) { ScanForInvariants(bl->block); } bl = bl->next; } }
int main(int argc, char * const argv[]) { //GArgs args(argc, argv, "hg:c:s:t:o:p:help;genomic-fasta=COV=PID=seq=out=disable-flag;test="); GArgs args(argc, argv, opts); fprintf(stderr, "Command line was:\n"); args.printCmdLine(stderr); args.printError(USAGE, true); //if (args.getOpt('h') || args.getOpt("help")) if (args.getOpt(OPT_HELP)) { GMessage("%s\n", USAGE); exit(1); } if (args.getOpt(OPT_NUM)) { GStr snum(args.getOpt(OPT_NUM)); int num=snum.asInt(); char* numstr=commaprintnum(num); GMessage("Number %d written with commas: %s\n", num, numstr); GFREE(numstr); } //--- GHash<GVec<int> > ends; /* testGPVec(); //exit(0); //uint pos=3; //GStr spos((int)pos); //GVec<int> *ev=ends[spos.chars()]; GPVec<Gint> v; int r(5); int rr=v.Add(new Gint(3)); //if (rr<0) { // GMessage("Error adding 0! (code %d)\n",rr); // } v.Add(new Gint(r)); v.Add(new Gint(2)); v.Add(new Gint(1)); v.Add(new Gint(4)); rr=v.Add(new Gint(0)); v[rr]->v=-1; v.Sort(cmpGint); GMessage("collection has %d elements:\n",v.Count()); for (int i=0;i<v.Count();i++) { GMessage("v[%d]=%d;\n",i,v[i]->v); } exit(0); */ //--- int numopts=args.startOpt(); if (numopts) GMessage("#### Recognized %d option arguments:\n", numopts); int optcode=0; while ((optcode=args.nextCode())) { char* r=args.getOpt(optcode); GMessage("%14s\t= %s\n", args.getOptName(optcode), (r[0]==0)?"True":r); } int numargs=args.startNonOpt(); if (numargs>0) { GMessage("\n#### Found %d non-option arguments given:\n", numargs); char* a=NULL; while ((a=args.nextNonOpt())) { GMessage("%s\n",a); } } GStr s=args.getOpt('t'); if (!s.is_empty()) { GStr token; GMessage("Tokens in \"%s\" :\n",s.chars()); s.startTokenize(";,: \t"); int c=1; while (s.nextToken(token)) { GMessage("token %2d : \"%s\"\n",c,token.chars()); c++; } } if (args.getOpt(OPT_BITVEC)) { uint numbits=4156888234; GBitVec bits(numbits); GMessage(">>> -- BitVec(%u) created (size=%u, mem=%lu) -- \n", numbits, bits.size(), bits.getMemorySize()); bits[405523342]=true; GMessage(" memory size: %lu , size()=%u, count()=%d \n", bits.getMemorySize(), bits.size(), bits.count()); /* //GMessage(">>> -- Start BitVec Test -- \n"); if (bits[1092]) bitError(1092); bits.resize(2049); if (bits[2048]) bitError(2048); bits[2048]=true; if (!bits[2048]) bitError(2048); bits.resize(4097); if (!bits[2048]) bitError(2048); if (bits[4096]) bitError(4096); bits[4096]=true; if (!bits[4096]) bitError(4096); GBitVec bits2(64); Gswap(bits, bits2); if (!bits2[2048]) bitError(2048); if (!bits2[4096]) bitError(4096); */ //GMessage("<<< -- End BitVec Test (size: %d, count: %d, bits2 size=%d, count=%d) --\n", /// bits.size(), bits.count(), bits2.size(), bits2.count()); } }
void Image::_load(string sFilename) { errlog << "Load " << sFilename << endl; //image format FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; //pointer to the image, once loaded FIBITMAP *dib(0); //pointer to the image data BYTE* bits(0); //image width and height unsigned int width(0), height(0); //check the file signature and deduce its format fif = FreeImage_GetFileType(sFilename.c_str(), 0); //if still unknown, try to guess the file format from the file extension if(fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(sFilename.c_str()); //if still unkown, return failure if(fif == FIF_UNKNOWN) { errlog << "Unknown image type for file " << sFilename << endl; return; } //check that the plugin has reading capabilities and load the file if(FreeImage_FIFSupportsReading(fif)) dib = FreeImage_Load(fif, sFilename.c_str()); else errlog << "File " << sFilename << " doesn't support reading." << endl; //if the image failed to load, return failure if(!dib) { errlog << "Error loading image " << sFilename.c_str() << endl; return; } //retrieve the image data //get the image width and height width = FreeImage_GetWidth(dib); height = FreeImage_GetHeight(dib); int mode, modeflip; if(FreeImage_GetBPP(dib) == 24) // RGB 24bit { #ifdef __BIG_ENDIAN__ mode = GL_RGB; modeflip = GL_RGB; #else mode = GL_RGB; modeflip = GL_BGR; #endif } else if(FreeImage_GetBPP(dib) == 32) // RGBA 32bit { #ifdef __BIG_ENDIAN__ mode = GL_RGBA; modeflip = GL_RGBA; #else mode = GL_RGBA; modeflip = GL_BGRA; #endif } bits = FreeImage_GetBits(dib); //if this somehow one of these failed (they shouldn't), return failure if((bits == 0) || (width == 0) || (height == 0)) { errlog << "Something went terribly horribly wrong with getting image bits; just sit and wait for the singularity" << endl; return; } //generate an OpenGL texture ID for this texture m_iWidth = width; m_iHeight = height; glGenTextures(1, &m_hTex); //bind to the new texture ID glBindTexture(GL_TEXTURE_2D, m_hTex); //store the texture data for OpenGL use #ifdef __BIG_ENDIAN__ m_iRealWidth = power_of_two(width); m_iRealHeight = power_of_two(height); FIBITMAP *bitmap2 = FreeImage_Allocate(m_iRealWidth, m_iRealHeight, FreeImage_GetBPP(dib)); FreeImage_FlipVertical(dib); FreeImage_Paste(bitmap2, dib, 0, 0, 255); FreeImage_FlipVertical(bitmap2); bits = FreeImage_GetBits(bitmap2); glTexImage2D(GL_TEXTURE_2D, 0, mode, m_iRealWidth, m_iRealHeight, 0, modeflip, GL_UNSIGNED_BYTE, bits); FreeImage_Unload(bitmap2); #else glTexImage2D(GL_TEXTURE_2D, 0, mode, width, height, 0, modeflip, GL_UNSIGNED_BYTE, bits); #endif if(g_imageBlur) { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); } else //If you want things pixellated { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); } //Free FreeImage's copy of the data FreeImage_Unload(dib); }
perm2 createPerm2(unsigned int *elems, unsigned int nelems, unsigned int t, static_bitsequence_builder * bmb) {//if uints is set to true the given array is of uints using 32 bits each perm2 P; unsigned int *b, *baux, nextelem, i, j, bptr, aux, antbptr,nbwdptrs, elem,nbits, firstelem, cyclesize; auxbwd2 *auxbwdptr; P = new struct sperm2; P->elems = elems; P->nelems = nelems; P->nbits = bits(nelems-1); nbits = bits(nelems-1); P->t = t; if (t==1) { P->bwdptrs = new unsigned int[uint_len(nelems,nbits)]; for(unsigned int m=0;m<uint_len(nelems,nbits);m++) P->bwdptrs[m]=0; assert(P->bwdptrs!=NULL); P->nbwdptrs = nelems; for (i=0; i<nelems; i++) { unsigned int bg = elems[i]; assert(bg<nelems); set_field(P->bwdptrs, nbits, bg, i); } P->bmap = NULL; } else { auxbwdptr = new auxbwd2[(t+((int)ceil((double)nelems/t)))]; assert(auxbwdptr!=NULL); b = new unsigned int[uint_len(nelems,1)]; for(i=0;i<uint_len(nelems,1);i++) b[i]=0; assert(b!=NULL); baux = new unsigned int[uint_len(nelems,1)]; for(i=0;i<uint_len(nelems,1);i++) baux[i] = 0; assert(baux!=NULL); nbwdptrs = 0; for (i = 0; i < nelems; i++) { if (bitget(baux,i) == 0) { nextelem = j = bptr = antbptr = i; aux = 0; bitset(baux, j); cyclesize = 0; firstelem = j; while ((elem=elems[j]) != nextelem) {//P->elems[j] j = elem; bitset(baux, j); aux++; if (aux >= t) { auxbwdptr[nbwdptrs].key = j; auxbwdptr[nbwdptrs++].pointer = bptr; antbptr = bptr; bptr = j; aux = 0; bitset(b, j); } cyclesize++; } if (cyclesize >= t) { auxbwdptr[nbwdptrs].key = nextelem; auxbwdptr[nbwdptrs++].pointer = bptr; bitset(b, nextelem); } } } qsort(auxbwdptr, nbwdptrs, sizeof(auxbwd2), &compare2); aux = uint_len(nbwdptrs,P->nbits); P->bwdptrs = new unsigned int[aux]; assert(P->bwdptrs!=NULL); for(i=0;i<aux;i++) P->bwdptrs[i] = 0; P->nbwdptrs = nbwdptrs; for (i = 0; i < nbwdptrs; i++) { set_field(P->bwdptrs, nbits, i, auxbwdptr[i].pointer); //if(i<5) // printf(" %d ",get_field(P->bwdptrs,nbits,i)); } //printf("\n"); P->bmap = bmb->build(b, nelems); //delete [] P->bmap; delete [] b; delete [] (baux); delete [] (auxbwdptr); } return P; }
entity* entityManager::loadEntity(string fileName) { string data; entity* newObj = new entity(simConfig); //now load each of THOSE files, this time creating an entity based on their data ifstream objectFile; objectFile.open(fileName); int line = 0; //tracks what stage of file loading we are in //objectFile>>data; getline(objectFile, data); //if it failed to open, skip over this file if(!objectFile.good()) { cout<<"Failed to load object! "<<fileName<<endl; delete newObj; return NULL; } while(objectFile.good()) { if(line>=10) // all objects past number 8 should be moons { //create a new entity for our shiny new object entity* newMoon = loadEntity(data); if(newMoon!=NULL) { //add them to the object list newMoon->next = head; head = newMoon; entityCount++; //newMoon->next = newObj->children; //newObj->children = newMoon; newMoon->parent = newObj; } } else { switch(line) { case 0: newObj->name = data; cout<<"Object name: "<<data<<endl; break; case 2: newObj->orbitalPeriod = atof(data.c_str()); break; case 3: newObj->rotationPeriod = atof(data.c_str()); break; case 4: newObj->semimajorAxis = atof(data.c_str()); break; case 5: newObj->diameter = atof(data.c_str()); break; case 6: newObj->tilt = atof(data.c_str()); break; case 7: newObj->orbitTilt = atof(data.c_str()); break; case 8: newObj->rotationPeriod *= atoi(data.c_str()); break; case 9://check if we need a camera of this object if(atoi(data.c_str()) == 1) { Camera* newCamera = new Camera(newObj); if(simConfig->presetCameras == NULL) simConfig->presetCameras = newCamera; else { Camera* iterator = simConfig->presetCameras; while(iterator->next!=NULL) iterator = iterator->next; iterator->next = newCamera; } cout<<"New camera created for "<<newObj->name<<"!"<<endl; } break; case 1: cout<<"Model file path: "<<data<<endl; //oh god monster code section//open the file const aiScene* scene = import.ReadFile("../bin/models/"+data+newObj->name+".obj", aiProcess_Triangulate); if(scene != NULL) { //iterate across the meshes in the scene for(unsigned int mIndex = 0; mIndex < scene->mNumMeshes; mIndex++) { aiMesh* m = scene->mMeshes[mIndex]; //iterate across faces in the mesh for(unsigned int fIndex = 0; fIndex < m->mNumFaces; fIndex++) { aiFace* f = &(m->mFaces[fIndex]); //iterate across indices in the face for(unsigned int iIndex = 0; iIndex < f->mNumIndices; iIndex++) { const int index = f->mIndices[iIndex]; //push each vertex onto the entity vertices Vertex v; v.position[0] = m->mVertices[index].x; v.position[1] = m->mVertices[index].y; v.position[2] = m->mVertices[index].z; //get the material aiMaterial* material = scene->mMaterials[m->mMaterialIndex]; aiColor3D color (0.f,0.f,0.f); material->Get(AI_MATKEY_COLOR_DIFFUSE,color); if(m->HasTextureCoords(0)) { aiVector3D textureCoord = m->mTextureCoords[0][index]; v.uv[0] = textureCoord.x; v.uv[1] = textureCoord.y; } else { v.uv[0] = 0.0f; v.uv[1] = 0.0f; } newObj->vertices.push_back(v); } } //get texture file name aiString fname; char newname[512]; string textPath = "../bin/models/" + data; strcpy(newname, textPath.c_str()); scene->mMaterials[m->mMaterialIndex]->GetTexture(aiTextureType_DIFFUSE, 0, &fname); //add mat name to end of it strcat(newname, fname.data); //give it its texture newObj->texID = simConfig->texCount; simConfig->texCount++; FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; BYTE * bits(0); FIBITMAP * dib(0); fif = FreeImage_GetFileType(newname, 0); //if still unknown, try to guess the file format from the file extension if(fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(newname); if(fif == FIF_UNKNOWN) cout<<"WE DON'T KNOW WHAT FIF THIS IS!"<<endl; if(FreeImage_FIFSupportsReading(fif)) dib = FreeImage_Load(fif, newname, 0); else cout<<"Bad texture file format!"<<endl; if(!dib) { cout<<"Dib failed to load! Are your file paths set up properly?? "<<newname<<endl; } bits = FreeImage_GetBits(dib); //get the image width and height newObj->texWidth = FreeImage_GetWidth(dib); newObj->texHeight = FreeImage_GetHeight(dib); cout<<"Texture "<<newname<<" image size: "<<newObj->texWidth<<"px by "<<newObj->texHeight<<"px"<<endl; //if this somehow one of these failed (they shouldn't), return failure //generate an OpenGL texture ID for this texture glGenTextures(1, &newObj->texID); glBindTexture( GL_TEXTURE_2D, newObj->texID); //store the texture data for OpenGL use glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, newObj->texWidth, newObj->texHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, bits); FreeImage_Unload(dib); } } break; } } line++; objectFile>>data; } objectFile.close(); return newObj; }