void Document::insertKeyframe(int layer, int index, Keyframe* keyframe) { std::vector<Keyframe*>& keyframes_ = layers_[layer]->keyframes; keyframes_.insert(keyframes_.begin() + index, keyframe); keyframe->ref(); createLinks(); }
void Document::eraseKeyframe(int layer, int index) { std::vector<Keyframe*>& keyframes_ = layers_[layer]->keyframes; keyframes_[index]->unref(); keyframes_.erase(keyframes_.begin() + index); createLinks(); }
void Document::removeSpriteInstance(int layer, int frame, SpriteInstance* instance) { Keyframe* keyframe = getKeyframe(layer, frame); if (keyframe == NULL) return; keyframe->removeSprite(instance); createLinks(); }
void Document::setSpriteInstances(int layer, int frame, const std::vector<SpriteInstance*>& instances) { Keyframe* keyframe = getKeyframe(layer, frame); if (keyframe == NULL) return; for (std::size_t i = 0; i < instances.size(); ++i) instances[i]->ref(); for (std::size_t i = 0; i < keyframe->sprites.size(); ++i) keyframe->sprites[i]->unref(); keyframe->sprites = instances; createLinks(); }
std::set<SpriteInstance*> Document::pasteClipboard(int layer, int frame, const std::vector<SpriteInstance*>& clipboard) { std::set<SpriteInstance*> newinstances; // ayni frame'de ayni SpriteInstance olmasina izin verme (for all instances instance->textureregion should be // different from each other) Keyframe* keyframe = getKeyframe(layer, frame); if (keyframe == NULL) return newinstances; if (clipboard.empty()) return newinstances; // printf("Document::pasteClipboard()"); for (std::size_t i = 0; i < clipboard.size(); ++i) { SpriteInstance* instance = clipboard[i]; bool found = false; for (std::size_t j = 0; j < keyframe->sprites.size(); ++j) { if (*instance == *keyframe->sprites[i]) { found = true; break; } } SpriteInstance* newinstance = new SpriteInstance(instance, found); // printf("%x-%x, ", clipboard[i], instance); addSpriteInstance(layer, frame, newinstance); newinstances.insert(newinstance); newinstance->unref(); } // printf("Document::pasteClipboard()\n"); createLinks(); return newinstances; }
void BeliefProp::initializeSolver (void) { const VarNodes& varNodes = fg.varNodes(); varsI_.reserve (varNodes.size()); for (size_t i = 0; i < varNodes.size(); i++) { varsI_.push_back (new SPNodeInfo()); } const FacNodes& facNodes = fg.facNodes(); facsI_.reserve (facNodes.size()); for (size_t i = 0; i < facNodes.size(); i++) { facsI_.push_back (new SPNodeInfo()); } createLinks(); for (size_t i = 0; i < links_.size(); i++) { FacNode* src = links_[i]->facNode(); VarNode* dst = links_[i]->varNode(); ninf (dst)->addBpLink (links_[i]); ninf (src)->addBpLink (links_[i]); } }
robot::robot(std::string filename,bool hideCollisionLinks,bool hideJoints,bool convexDecomposeNonConvexCollidables,bool createVisualIfNone,bool showConvexDecompositionDlg,bool centerAboveGround,bool makeModel,bool noSelfCollision,bool positionCtrl): filenameAndPath(filename) { printToConsole("URDF import operation started."); openFile(); readJoints(); readLinks(); readSensors(); createJoints(hideJoints,positionCtrl); createLinks(hideCollisionLinks,convexDecomposeNonConvexCollidables,createVisualIfNone,showConvexDecompositionDlg); createSensors(); std::vector<int> parentlessObjects; std::vector<int> allShapes; std::vector<int> allObjects; std::vector<int> allSensors; for (int i=0;i<int(vLinks.size());i++) { if (simGetObjectParent(vLinks[i]->nLinkVisual)==-1) parentlessObjects.push_back(vLinks[i]->nLinkVisual); allObjects.push_back(vLinks[i]->nLinkVisual); allShapes.push_back(vLinks[i]->nLinkVisual); if (vLinks[i]->nLinkCollision!=-1) { if (simGetObjectParent(vLinks[i]->nLinkCollision)==-1) parentlessObjects.push_back(vLinks[i]->nLinkCollision); allObjects.push_back(vLinks[i]->nLinkCollision); allShapes.push_back(vLinks[i]->nLinkCollision); } } for (int i=0;i<int(vJoints.size());i++) { if (vJoints[i]->nJoint!=-1) { if (simGetObjectParent(vJoints[i]->nJoint)==-1) parentlessObjects.push_back(vJoints[i]->nJoint); allObjects.push_back(vJoints[i]->nJoint); } } for (int i=0;i<int(vSensors.size());i++) { if (vSensors[i]->nSensor!=-1) { if (simGetObjectParent(vSensors[i]->nSensor)==-1) parentlessObjects.push_back(vSensors[i]->nSensor); allObjects.push_back(vSensors[i]->nSensor); allSensors.push_back(vSensors[i]->nSensor); } if (vSensors[i]->nSensorAux!=-1) { allObjects.push_back(vSensors[i]->nSensorAux); allSensors.push_back(vSensors[i]->nSensorAux); } } // If we want to alternate respondable mask: if (!noSelfCollision) { for (int i=0;i<int(parentlessObjects.size());i++) setLocalRespondableMaskCummulative_alternate(parentlessObjects[i],true); } // Now center the model: if (centerAboveGround) { bool firstValSet=false; C3Vector minV,maxV; for (int shNb=0;shNb<int(allShapes.size());shNb++) { float* vertices; int verticesSize; int* indices; int indicesSize; if (simGetShapeMesh(allShapes[shNb],&vertices,&verticesSize,&indices,&indicesSize,NULL)!=-1) { C7Vector tr; simGetObjectPosition(allShapes[shNb],-1,tr.X.data); C3Vector euler; simGetObjectOrientation(allShapes[shNb],-1,euler.data); tr.Q.setEulerAngles(euler); for (int i=0;i<verticesSize/3;i++) { C3Vector v(vertices+3*i); v*=tr; if (!firstValSet) { minV=v; maxV=v; firstValSet=true; } else { minV.keepMin(v); maxV.keepMax(v); } } simReleaseBuffer((char*)vertices); simReleaseBuffer((char*)indices); } } C3Vector shiftAmount((minV+maxV)*-0.5f); shiftAmount(2)+=(maxV(2)-minV(2))*0.5f; for (int i=0;i<int(parentlessObjects.size());i++) { C3Vector p; simGetObjectPosition(parentlessObjects[i],-1,p.data); p+=shiftAmount; simSetObjectPosition(parentlessObjects[i],-1,p.data); } } // Now create a model bounding box if that makes sense: if ((makeModel)&&(parentlessObjects.size()==1)) { int p=simGetModelProperty(parentlessObjects[0]); p|=sim_modelproperty_not_model; simSetModelProperty(parentlessObjects[0],p-sim_modelproperty_not_model); for (int i=0;i<int(allObjects.size());i++) { if (allObjects[i]!=parentlessObjects[0]) { int p=simGetObjectProperty(allObjects[i]); simSetObjectProperty(allObjects[i],p|sim_objectproperty_selectmodelbaseinstead); } } for (int i=0;i<int(allSensors.size());i++) { if (allSensors[i]!=parentlessObjects[0]) { int p=simGetObjectProperty(allSensors[i]); simSetObjectProperty(allSensors[i],p|sim_objectproperty_dontshowasinsidemodel); // sensors are usually large and it is ok if they do not appear as inside of the model bounding box! } } } // Now select all new objects: simRemoveObjectFromSelection(sim_handle_all,-1); for (int i=0;i<int(allObjects.size());i++) simAddObjectToSelection(sim_handle_single,allObjects[i]); printToConsole("URDF import operation finished.\n\n"); }
void StentModelSource::createStent(){ init(); createStentSimplexMesh(); createStruts(); createLinks(); }
int myCpioInstallArchive(gzFile stream, struct cpioFileMapping * mappings, int numMappings, cpioCallback cb, void * cbData, const char ** failedFile) { struct cpioHeader ch; struct ourfd fd; int rc = 0; int linkNum = 0; struct cpioFileMapping * map = NULL; struct cpioFileMapping needle; mode_t cpioMode; int olderr; struct cpioCallbackInfo cbInfo; struct hardLink * links = NULL; struct hardLink * li = NULL; fd.fd = stream; fd.pos = 0; *failedFile = NULL; do { if ((rc = getNextHeader(&fd, &ch, NULL))) { fprintf(stderr, _("error %d reading header: %s\n"), rc, myCpioStrerror(rc)); return CPIOERR_BAD_HEADER; } if (!strcmp(ch.path, TRAILER)) { free(ch.path); break; } if (mappings) { needle.archivePath = ch.path; map = bsearch(&needle, mappings, numMappings, sizeof(needle), myCpioFileMapCmp); } if (mappings && !map) { eatBytes(&fd, ch.size); } else { cpioMode = ch.mode; if (map) { if (map->mapFlags & CPIO_MAP_PATH) { free(ch.path); ch.path = strdup(map->fsPath); } if (map->mapFlags & CPIO_MAP_MODE) ch.mode = map->finalMode; if (map->mapFlags & CPIO_MAP_UID) ch.uid = map->finalUid; if (map->mapFlags & CPIO_MAP_GID) ch.gid = map->finalGid; } /* This won't get hard linked symlinks right, but I can't seem to create those anyway */ if (S_ISREG(ch.mode) && ch.nlink > 1) { li = links; for (li = links; li; li = li->next) { if (li->inode == ch.inode && li->dev == ch.dev) break; } if (!li) { li = malloc(sizeof(*li)); li->inode = ch.inode; li->dev = ch.dev; li->nlink = ch.nlink; li->linksLeft = ch.nlink; li->createdPath = -1; li->files = calloc(sizeof(char *), li->nlink); li->next = links; links = li; } for (linkNum = 0; linkNum < li->nlink; linkNum++) if (!li->files[linkNum]) break; li->files[linkNum] = strdup(ch.path); } if ((ch.nlink > 1) && S_ISREG(ch.mode) && !ch.size && li->createdPath == -1) { /* defer file creation */ } else if ((ch.nlink > 1) && S_ISREG(ch.mode) && (li->createdPath != -1)) { createLinks(li, failedFile); /* this only happens for cpio archives which contain hardlinks w/ the contents of each hardlink being listed (intead of the data being given just once. This shouldn't happen, but I've made it happen w/ buggy code, so what the heck? GNU cpio handles this well fwiw */ if (ch.size) eatBytes(&fd, ch.size); } else { rc = checkDirectory(ch.path); if (!rc) { if (S_ISREG(ch.mode)) rc = expandRegular(&fd, &ch, cb, cbData); else if (S_ISDIR(ch.mode)) rc = createDirectory(ch.path, 000); else if (S_ISLNK(ch.mode)) rc = expandSymlink(&fd, &ch); else if (S_ISFIFO(ch.mode)) rc = expandFifo(&fd, &ch); else if (S_ISCHR(ch.mode) || S_ISBLK(ch.mode)) rc = expandDevice(&fd, &ch); else if (S_ISSOCK(ch.mode)) { /* this mimicks cpio but probably isnt' right */ rc = expandFifo(&fd, &ch); } else { rc = CPIOERR_INTERNAL; } } if (!rc) rc = setInfo(&ch); if (S_ISREG(ch.mode) && ch.nlink > 1) { li->createdPath = linkNum; li->linksLeft--; rc = createLinks(li, failedFile); } } if (rc && !*failedFile) { *failedFile = strdup(ch.path); olderr = errno; unlink(ch.path); errno = olderr; } } padinfd(&fd, 4); if (!rc && cb) { cbInfo.file = ch.path; cbInfo.fileSize = ch.size; cbInfo.fileComplete = ch.size; cbInfo.bytesProcessed = fd.pos; cb(&cbInfo, cbData); } free(ch.path); } while (1 && !rc); li = links; while (li && !rc) { if (li->linksLeft) { if (li->createdPath == -1) rc = CPIOERR_INTERNAL; else rc = createLinks(li, failedFile); } freeLink(li); links = li; li = li->next; free(links); links = li; } li = links; /* if an error got us here links will still be eating some memory */ while (li) { freeLink(li); links = li; li = li->next; free(links); } return rc; }
objectMap_t buildConfig( SST::M5::M5* comp, std::string name, std::string configFile, SST::Params& params ) { objectMap_t objectMap; linkMap_t linkMap; DBGC( 2, "name=`%s` file=`%s`\n", name.c_str(), configFile.c_str() ); #if XML SST::SSTSDLModelDefinition sdl = SST::SSTSDLModelDefinition( configFile ); #else Config cfg(0,1); cfg.model_options = configFile; SST::SSTPythonModelDefinition sdl = SST::SSTPythonModelDefinition(SST_INSTALL_PREFIX "/libexec/xmlToPython.py", 0, &cfg); #endif SST::ConfigGraph& graph = *sdl.createConfigGraph(); Factory factory( comp ); SST::ConfigLinkMap_t::iterator lmIter; for ( lmIter = graph.getLinkMap().begin(); lmIter != graph.getLinkMap().end(); ++lmIter ) { SST::ConfigLink& tmp = (*lmIter); DBGC(2,"key=%ld name=%s\n",tmp.key(), tmp.name.c_str()); LinkInfo l0,l1; l0.compName = graph.getComponentMap()[ tmp.component[0] ].name.c_str(); l1.compName = graph.getComponentMap()[ tmp.component[1] ].name.c_str(); l0.portName = tmp.port[0]; l1.portName = tmp.port[1]; l0.portNum = 0; l1.portNum = 0; linkMap[ tmp.name ] = std::make_pair( l0, l1 ); } //printLinkMap( linkMap ); SST::ConfigComponentMap_t::iterator iter; for ( iter = graph.getComponentMap().begin(); iter != graph.getComponentMap().end(); ++iter ) { SST::ConfigComponent& tmp = (*iter); DBGC(2,"id=%d %s %s\n",tmp.id, tmp.name.c_str(), tmp.type.c_str()); SST::Params tmpParams = params.find_prefix_params( tmp.name + "." ); tmp.params.insert( tmpParams.begin(), tmpParams.end() ); tmp.params.enableVerify(false); Gem5Object_t* simObject = factory.createObject( name + "." + tmp.name, tmp.type, tmp.params ); objectMap[ tmp.name.c_str() ] = simObject; createLinks( *comp, *(Gem5Object_t*) simObject, tmp.params ); } connectAll( objectMap, linkMap ); return objectMap; }
int main(int argc, char *argv[]) { globalCost = 0; numWalks = 0; //curtime = time(NULL); //srand(curtime); srand(12212012); head = NULL; tail = NULL; char fname[84]; char dest[84]; char fileName[100]; char start[84]; int fcost; printf("Enter data file: "); scanf("%s", fileName); FILE *dataFile; dataFile = fopen(fileName, "r"); if (dataFile == NULL) { printf("cannot open file\n"); exit(0); } while(fscanf(dataFile, "%s", fname) != EOF) { if(!strcmp(fname, "STOP")) { break; } else { insert(fname); } } while(fscanf(dataFile, "%s %s %d", fname, dest, &fcost) != EOF) { if(!strcmp(fname, "STOP")) { break; } else { createLinks(fname, dest, fcost); } } fscanf(dataFile, "%s", start); int x; if(argc>1) { switch(atoi(argv[1])) { case 0: printf("\nDrunkard's Walk\n"); x = drunkWalk(start); break; case 1: printf("\nGreedy Walk\n"); x = greedy(start); break; case 2: printf("\nGenerous Walk\n"); x = generous(start); break; default: printf("\nNon-applicable argument\n0-Drunkard's Walk\n1-Greedy Walk\n2-Generous Walk\n"); break; } } else { printf("Need command line argument\n"); } //printForwardList(); //printBackwardList(); //printAll(); if(x!=0) { printf("\nYou started at %s\nYou're home and it only cost you %d!\n\n", start, globalCost); } else { printf("Please try again\n\n"); } fclose(dataFile); freeStuff(); }