/// Read the Sintef legacy grid format ('topogeom'). void CpGrid::writeSintefLegacyFormat(const std::string& grid_prefix) const { std::string topofilename = grid_prefix + "-topo.dat"; { std::ofstream file(topofilename.c_str()); if (!file) { OPM_THROW(std::runtime_error, "Could not open file " << topofilename); } writeTopo(file, cell_to_face_, face_to_cell_, face_to_point_, cell_to_point_, allcorners_.size()); } std::string geomfilename = grid_prefix + "-geom.dat"; { std::ofstream file(geomfilename.c_str()); if (!file) { OPM_THROW(std::runtime_error, "Could not open file " << geomfilename); } writeGeom(file, geometry_, face_normals_); } std::string mapfilename = grid_prefix + "-map.dat"; { std::ofstream file(mapfilename.c_str()); if (!file) { OPM_THROW(std::runtime_error, "Could not open file " << mapfilename); } writeMap(file, *this); } std::string vtkfilename = grid_prefix + "-volumes.vtk"; { std::ofstream file(vtkfilename.c_str()); if (!file) { OPM_THROW(std::runtime_error, "Could not open file " << vtkfilename); } writeVtkVolumes(file, allcorners_, cell_to_point_); } }
int RobotMemory::findPath(int x, int y) { int value = 0; pathstart = owner->getPosition(); pathstop.x = x; pathstop.y = y; for (int i=0; i<columns; i++) for(int j=0; j<rows; j++) map2[i][j] = -1; setMem(pathstart->x,pathstart->y,value); writeMap(); while(!endofmap) { endofmap = true; value++; for(int i=0; i<columns; i++) { for(int j=0; j<rows; j++) { if(map2[i][j] == value - 1) { endofmap = false; if((i == pathstop.x) && (j == pathstop.y)) { //writeMap(); setPath(i,j); writeMap(); return 0; } setMem(i,j+1,value); setMem(i,j-1,value); setMem(i+1,j,value); setMem(i-1,j,value); } } } } TRACE("Sciezka nie odnaleziona\n"); return 1; }
void writeBrickLevel(Brick* brick_array[][bricksPerRow], int profile_number) { int map_array[maxRows][bricksPerRow] = {0}; int i, j = 0; for (i = 0; i < maxRows; i++) { for(j = 0; j < bricksPerRow; j++) { map_array[i][j] = brick_array[i][j]->health; // printf("health: %i \n", (brick_array[i][j].health)); } } printf("saving this level: \n"); // printIntArray(map_array); writeMap(map_array, profile_number, 1); }
int main(int argc, char * argv[]) { struct cmdlineInfo cmdline; FILE * ifP; xelval lmin, lmax; gray * lumamap; /* Luminosity map */ unsigned int * lumahist; /* Histogram of luminosity values */ int rows, cols; /* Rows, columns of input image */ xelval maxval; /* Maxval of input image */ int format; /* Format indicator (PBM/PGM/PPM) */ xel ** xels; /* Pixel array */ unsigned int pixelCount; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); xels = pnm_readpnm(ifP, &cols, &rows, &maxval, &format); pm_close(ifP); computeLuminosityHistogram(xels, rows, cols, maxval, format, cmdline.gray, &lumahist, &lmin, &lmax, &pixelCount); getMapping(cmdline.rmap, lumahist, maxval, pixelCount, &lumamap); if (cmdline.verbose) reportMap(lumahist, maxval, lumamap); remap(xels, cols, rows, maxval, format, !!cmdline.gray, lumamap); pnm_writepnm(stdout, xels, cols, rows, maxval, format, 0); if (cmdline.wmap) writeMap(cmdline.wmap, lumamap, maxval); pgm_freerow(lumamap); return 0; }
void HeightMapGen::generateHeightmap(unsigned short erosionIterations, float staggerValue) { fStaggerValue = staggerValue; iErosionIterations = erosionIterations; // NW corner *pHMBlocks = Random::getSingleton().getRand(5, 10); std::cout << "NW corner = " << *pHMBlocks << "\n"; // NE corner *(pHMBlocks + iFinalX) = Random::getSingleton().getRand(5, 10); std::cout << "NE corner = " << *(pHMBlocks + iFinalX) << "\n"; // SE corner *(pHMBlocks + iFinalX + iDimensions - 1) = Random::getSingleton().getRand(5, 10); std::cout << "SE corner = " << *(pHMBlocks + iFinalX + iDimensions - 1) << "\n"; // SW corner *(pHMBlocks + iDimensions - 1) = Random::getSingleton().getRand(5, 10); std::cout << "SW corner = " << *(pHMBlocks + iDimensions - 1) << "\n"; genQuadrant(0, 0, iFinalX, iDimensions - 1, 1, iQuadrants); //============================= // Set up the return value //============================= // A heightmap requires values ranging from 0 and 1. For now, everything is rated in proportion to the largest height // in the vector, so the highest point will be 1 and the lowest point will be 0 // Step 1 = Get the largest and smallest height long signed int iMaxHeight; long signed int iMinHeight; // Setting a default iMaxHeight and iMinHeight to the northwest corner iMaxHeight = *pHMBlocks; iMinHeight = *pHMBlocks; // Go through the blocks and find out what is the highest and what is the lowest block for(long unsigned int i = 0; i <= iFinalPoint; i++) { if(*(pHMBlocks + i) < iMinHeight) iMinHeight = *(pHMBlocks + i); if(*(pHMBlocks + i) > iMaxHeight) iMaxHeight = *(pHMBlocks + i); } // Advised for CPU optimisation short signed int iRelativeMaxHeight = iMaxHeight - iMinHeight; // Go through the blocks and scale them relative to the maximum or minimum // The percentage range can be found by first subtracting the miminum from the number // And then dividing that by iRelativeMaxHeight for(long unsigned int i = 0; i <= iFinalX + iDimensions - 1; i++) { // Scale it up to the point we want (by making it between 0 and 1 and then multiplying it by the range we want // Scaling disabled temporarily *(pHMBlocks + i) = ((*(pHMBlocks + i) - iMinHeight)/iRelativeMaxHeight); } //================= // Erosion //================= // Talos = The maximum angle allowed for slopes to be before thermal erosion begins taking place. // In most cases, we want this to be 4/N, where N = the number of blocks in the terrain set. // c = A variable I don't fully understand. // This uses Thermal Erosion // In the future, should probably modify it so that we can also have Rainfall erosion. // First we travel through all of the different HMBlocks and calculate the difference in height to // all of their neighbours, if they exist. // d1 = h - h1 // where h = the height of the inspected block, h1 = the height of the neigbouring block at position 1, and d1 // is the difference in height between inspected block 1 and the inspected block. // If the tile is higher than its neighbour, it will be positive, otherwise negative. // This erosion algorithm is very small once used once, so it must be run a lot, using the function erosionIterations. // This is a default for now but can be defined. // Use a for statement to call erodeBlock on every block in the array in order while(iErosionIterations > 0) { for(long unsigned int i = 0; i <= iFinalPoint; i++) erodeBlock(-0.5f, i); iErosionIterations--; } writeMap(); }
int main(int argc, const char * argv[]) { try { setlocale(LC_ALL, ""); std::locale loc; wordMap words; // Define vars std::string filename = "Erlrouter.txt"; char tempChar(0); std::string tempWord(""); int lineCounter(1); // Open file std::ifstream book(filename.c_str()); if(!book.is_open()) throw std::runtime_error("Die Datei \"" + filename + "\" konnte nicht geöffnet werden!"); /* Get line || get word std::string line(""); std::istream_iterator<std::string> iiter(book); std::istream_iterator<std::string> eos; for(int i = 0;i<=2;++i) std::cout << *iiter++ << std::endl; // Read word getline(book, line); std::cout << line << std::endl; */ // Go through file and read in char-by-char do { tempChar = book.get(); if(tempChar == '\n') lineCounter++; if(isspace(tempChar, loc)) { // Write word if(tempWord.length() > 0) { if(isNomen(tempWord)) { // We have a nomen! addWordToMap(words, *new Nomen(tempWord, lineCounter)); } else if(isAkronym(tempWord)) { // We have an acronym! addWordToMap(words, *new Akronym(tempWord, lineCounter)); } } tempWord = ""; } else if(isalpha(tempChar, loc)) { tempWord = tempWord + tempChar; } } while(book.good()); book.close(); // Close file printMap(words); // Write to Index.txt std::string outputFilename("Index.txt"); std::ofstream index(outputFilename.c_str()); writeMap(words, index); return 0; } catch(std::exception &e) { std::cerr << e.what() << std::endl; } catch(...) { std::cerr << "Ein unbekannter Fehler trat auf." << std::endl; } }
void MessageEncoder::writeApplicationProperties(const qpid::types::Variant::Map& properties, bool large) { writeMap(properties, &qpid::amqp::message::APPLICATION_PROPERTIES, large); }
void writeLevel(int map_array[][bricksPerRow], int profile_number) { writeMap(map_array, profile_number, 1); }
/* MapEditorWindow::saveMap * Saves the current map to its archive, or opens the 'save as' * dialog if it doesn't currently belong to one *******************************************************************/ bool MapEditorWindow::saveMap() { // Check for newly created map if (!mdesc_current.head) return saveMapAs(); // Write map to temp wad WadArchive* wad = writeMap(); if (!wad) return false; // Check for map archive Archive* tempwad = NULL; Archive::mapdesc_t map = mdesc_current; if (mdesc_current.archive && mdesc_current.head) { tempwad = new WadArchive(); tempwad->open(mdesc_current.head); vector<Archive::mapdesc_t> amaps = tempwad->detectMaps(); if (amaps.size() > 0) map = amaps[0]; else return false; } // Unlock current map entries lockMapEntries(false); // Delete current map entries ArchiveEntry* entry = map.end; Archive* archive = map.head->getParent(); while (entry && entry != map.head) { ArchiveEntry* prev = entry->prevEntry(); archive->removeEntry(entry); entry = prev; } // Create backup if (!backup_manager->writeBackup(map_data, map.head->getTopParent()->getFilename(false), map.head->getName(true))) LOG_MESSAGE(1, "Warning: Failed to backup map data"); // Add new map entries for (unsigned a = 1; a < wad->numEntries(); a++) entry = archive->addEntry(wad->getEntry(a), archive->entryIndex(map.head) + a, NULL, true); // Clean up delete wad; if (tempwad) { tempwad->save(); delete tempwad; } else { // Update map description mdesc_current.end = entry; } // Finish lockMapEntries(); editor.getMap().setOpenedTime(); return true; }
/* MapEditorWindow::handleAction * Handles the action [id]. Returns true if the action was handled, * false otherwise *******************************************************************/ bool MapEditorWindow::handleAction(string id) { // Don't handle actions if hidden if (!IsShown()) return false; // Map->Save if (id == "mapw_save") { // Save map if (saveMap()) { // Save archive Archive* a = currentMapDesc().head->getParent(); if (a && save_archive_with_map) a->save(); } return true; } // Map->Save As if (id == "mapw_saveas") { saveMapAs(); return true; } // Map->Restore Backup if (id == "mapw_backup") { if (mdesc_current.head) { Archive* data = backup_manager->openBackup(mdesc_current.head->getTopParent()->getFilename(false), mdesc_current.name); if (data) { vector<Archive::mapdesc_t> maps = data->detectMaps(); if (!maps.empty()) { editor.getMap().clearMap(); editor.openMap(maps[0]); loadMapScripts(maps[0]); } } } return true; } // Edit->Undo if (id == "mapw_undo") { editor.doUndo(); return true; } // Edit->Redo if (id == "mapw_redo") { editor.doRedo(); return true; } // Editor->Set Base Resource Archive if (id == "mapw_setbra") { wxDialog dialog_ebr(this, -1, "Edit Base Resource Archives", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER); BaseResourceArchivesPanel brap(&dialog_ebr); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(&brap, 1, wxEXPAND|wxALL, 4); sizer->Add(dialog_ebr.CreateButtonSizer(wxOK|wxCANCEL), 0, wxEXPAND|wxLEFT|wxRIGHT|wxDOWN, 4); dialog_ebr.SetSizer(sizer); dialog_ebr.Layout(); dialog_ebr.SetInitialSize(wxSize(500, 300)); dialog_ebr.CenterOnParent(); if (dialog_ebr.ShowModal() == wxID_OK) theArchiveManager->openBaseResource(brap.getSelectedPath()); return true; } // Editor->Preferences if (id == "mapw_preferences") { PreferencesDialog::openPreferences(this); return true; } // View->Item Properties if (id == "mapw_showproperties") { wxAuiManager* m_mgr = wxAuiManager::GetManager(this); wxAuiPaneInfo& p_inf = m_mgr->GetPane("item_props"); // Toggle window and focus p_inf.Show(!p_inf.IsShown()); map_canvas->SetFocus(); m_mgr->Update(); return true; } // View->Console else if (id == "mapw_showconsole") { wxAuiManager* m_mgr = wxAuiManager::GetManager(this); wxAuiPaneInfo& p_inf = m_mgr->GetPane("console"); // Toggle window and focus if (p_inf.IsShown()) { p_inf.Show(false); map_canvas->SetFocus(); } else { p_inf.Show(true); p_inf.window->SetFocus(); } p_inf.MinSize(200, 128); m_mgr->Update(); return true; } // View->Script Editor else if (id == "mapw_showscripteditor") { wxAuiManager* m_mgr = wxAuiManager::GetManager(this); wxAuiPaneInfo& p_inf = m_mgr->GetPane("script_editor"); // Toggle window and focus if (p_inf.IsShown()) { p_inf.Show(false); map_canvas->SetFocus(); } else if (!theGameConfiguration->scriptLanguage().IsEmpty()) { p_inf.Show(true); p_inf.window->SetFocus(); } p_inf.MinSize(200, 128); m_mgr->Update(); return true; } // View->Map Checks else if (id == "mapw_showchecks") { wxAuiManager* m_mgr = wxAuiManager::GetManager(this); wxAuiPaneInfo& p_inf = m_mgr->GetPane("map_checks"); // Toggle window and focus if (p_inf.IsShown()) { p_inf.Show(false); map_canvas->SetFocus(); } else { p_inf.Show(true); p_inf.window->SetFocus(); } //p_inf.MinSize(200, 128); m_mgr->Update(); return true; } // View->Undo History else if (id == "mapw_showundohistory") { wxAuiManager* m_mgr = wxAuiManager::GetManager(this); wxAuiPaneInfo& p_inf = m_mgr->GetPane("undo_history"); // Toggle window p_inf.Show(!p_inf.IsShown()); m_mgr->Update(); return true; } // Run Map else if (id == "mapw_run_map") { Archive* archive = NULL; if (mdesc_current.head) archive = mdesc_current.head->getParent(); RunDialog dlg(this, archive); if (dlg.ShowModal() == wxID_OK) { WadArchive* wad = writeMap(mdesc_current.name); if (wad) wad->save(appPath("sladetemp_run.wad", DIR_TEMP)); string command = dlg.getSelectedCommandLine(archive, mdesc_current.name, wad->getFilename()); if (!command.IsEmpty()) { // Set working directory string wd = wxGetCwd(); wxSetWorkingDirectory(dlg.getSelectedExeDir()); // Run wxExecute(command, wxEXEC_ASYNC); // Restore working directory wxSetWorkingDirectory(wd); } } return true; } return false; }
int main(int argc, char **argv) { G_gisinit(argv[0]); char *tmp, *token; char **ratio_str = NULL; int i, j; int id; double val; module = G_define_module(); module->keywords = _("vector, surveying, crossbones"); module->description = _("A GRASS version of Crossbones: Create simple 3D representations of skeletal assemblages."); file = G_define_standard_option(G_OPT_F_INPUT); file->description = _("Input ASCII file with point measurements"); file->required = YES; output = G_define_standard_option(G_OPT_V_OUTPUT); output->description = _("Name of output vector map"); output->required = YES; mode = G_define_option(); mode->key = "mode"; mode->description = _("3D Representation mode"); mode->type = TYPE_STRING; mode->required = NO; mode->multiple = NO; mode->options = "darts,lines,planes_h,planes_v,points,pyramids"; mode->answer = "pyramids"; delim = G_define_option(); delim->key = "delimiter"; delim->description = _("Field delimiter for ASCII input file (default: comma)"); delim->type = TYPE_STRING; delim->required = NO; delim->multiple = NO; delim->answer = ","; idcol = G_define_option(); idcol->key = "idcolumn"; idcol->description = _("Position of ID column in ASCII input file (leftmost = 1)"); idcol->type = TYPE_INTEGER; idcol->required = NO; idcol->multiple = NO; idcol->answer = "1"; xcol = G_define_option(); xcol->key = "xcolumn"; xcol->description = _("Position of X (Easting) column in ASCII input file (leftmost = 1)"); xcol->type = TYPE_DOUBLE; xcol->required = NO; xcol->multiple = NO; xcol->answer = "2"; ycol = G_define_option(); ycol->key = "ycolumn"; ycol->description = _("Position of Y (Northing) column in ASCII input file (leftmost = 1)"); ycol->type = TYPE_DOUBLE; ycol->required = NO; ycol->multiple = NO; ycol->answer = "3"; zcol = G_define_option(); zcol->key = "zcolumn"; zcol->description = _("Position of Z (Elevation) column in ASCII input file (leftmost = 1)"); zcol->type = TYPE_DOUBLE; zcol->required = NO; zcol->multiple = NO; zcol->answer = "4"; ratios = G_define_option(); ratios->key = "ratios"; ratios->description = _("List of length:1 ratios for specific bone IDs (boneID1=ratio, boneID2=ratio, ...)."); ratios->type = TYPE_STRING; ratios->required = NO; ratios->answer = "1=3.0,2=8.0,5=6.0,8=6.0,11=6.0,14=6.0"; if (G_parser(argc, argv)) exit(EXIT_FAILURE); if ( !strcmp (delim->answer, "tab") || !strcmp (delim->answer, "tabulator") ) { delimiter = G_malloc ( sizeof ( char ) * 2 ); sprintf ( delimiter, "\t"); } else { delimiter = delim->answer; } /* figure out ratios */ tmp = strdup ( ratios->answer ); i = 0; token = strtok ( tmp, "," ); while ( token != NULL ) { i ++; token = strtok ( NULL, "," ); } G_free ( tmp ); RATIO_VAL = G_malloc ( sizeof ( double ) * i ); RATIO_ID = G_malloc ( sizeof ( int ) * i ); ratio_str = G_malloc ( sizeof ( char* ) * i ); tmp = strdup ( ratios->answer ); i = 0; token = strtok ( tmp, "," ); while ( token != NULL ) { ratio_str[i] = strdup ( token ); i ++; token = strtok ( NULL, "," ); } G_free ( tmp ); NUM_RATIOS = 0; for ( j = 0; j < i; j ++ ) { tmp = strdup ( ratio_str[j] ); id = -1; val = -1.0; token = strtok ( tmp, "=" ); if ( token != NULL ) { id = atoi ( token ); } token = strtok ( NULL, "=" ); if ( token != NULL ) { val = atof ( token ); } if ( id > 0 && val > 0.0 ) { RATIO_ID[NUM_RATIOS] = id; RATIO_VAL[NUM_RATIOS] = val; NUM_RATIOS ++; } G_free ( tmp ); } for ( j = 0; j < i; j ++ ) { G_free ( ratio_str[j] ); } if ( ratio_str != NULL ) { G_free ( ratio_str ); } if ( DEBUG ) { fprintf ( stderr, "RATIOS: \n" ); for ( i = 0; i < NUM_RATIOS; i ++ ) { fprintf ( stderr, " %i = %.3f\n", RATIO_ID[i], RATIO_VAL[i] ); } } ID_COL_POS = atoi ( idcol->answer ); X_COL_POS = atoi ( xcol->answer ); Y_COL_POS = atoi ( ycol->answer ); Z_COL_POS = atoi ( zcol->answer ); if ( !strcmp ( mode->answer, "darts" ) ) { MODE = MODE_DARTS; } if ( !strcmp ( mode->answer, "lines" ) ) { MODE = MODE_LINES; } if ( !strcmp ( mode->answer, "planes_h" ) ) { MODE = MODE_PLANES_H; } if ( !strcmp ( mode->answer, "planes_v" ) ) { MODE = MODE_PLANES_V; } if ( !strcmp ( mode->answer, "points" ) ) { MODE = MODE_POINTS; } if ( !strcmp ( mode->answer, "pyramids" ) ) { MODE = MODE_PYRAMIDS; } /* read point coordinates */ createTable(); /* create a new array with only valid points */ validatePoints(); if ( DEBUG ) { fprintf ( stderr, " *** POINTS PROCESSING DONE ***\n " ); } /* /* write out the result vector map */ writeMap(); /* clean up */ freePts(); if ( DEBUG ) { fprintf ( stderr, " *** WRITING OUTPUT MAP DONE ***\n " ); } if ( RGB_MAPPER_COLOUR != NULL ) { G_free ( RGB_MAPPER_COLOUR ); } G_message ("DONE!\n"); exit(EXIT_SUCCESS); }
static void doSerialize(A2PWriter writer, A2PType expected, ATerm value){ DKISIndexedSet sharedValues = writer->valueSharingMap; int valueHash = hashValue(value); int valueId = DKISget(sharedValues, (void*) value, (void*) expected, valueHash); /* TODO: Fix sharing (check types). */ if(valueId != -1){ writeByteToBuffer(writer->buffer, PDB_SHARED_FLAG); printInteger(writer->buffer, valueId); return; } switch(expected->id){ case PDB_VALUE_TYPE_HEADER: serializeUntypedTerm(writer, value); break; case PDB_BOOL_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Boolean didn't have AT_APPL type.\n"); exit(1); } writeBool(writer, (ATermAppl) value); break; case PDB_INTEGER_TYPE_HEADER: if(ATgetType(value) != AT_INT){ fprintf(stderr, "Integer didn't have AT_INT type.\n"); exit(1); } writeInteger(writer, (ATermInt) value); break; case PDB_DOUBLE_TYPE_HEADER: if(ATgetType(value) != AT_REAL){ fprintf(stderr, "Double didn't have AT_REAL type.\n"); exit(1); } writeDouble(writer, (ATermReal) value); break; case PDB_STRING_TYPE_HEADER: if(ATgetType(value) != AT_APPL || ATisQuoted(ATgetAFun((ATermAppl) value)) == ATfalse){ fprintf(stderr, "String didn't have 'quoted' AT_APPL type.\n"); ATabort(""); exit(1); } writeString(writer, (ATermAppl) value); break; case PDB_SOURCE_LOCATION_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Source location didn't have AT_APPL type.\n"); exit(1); } writeSourceLocation(writer, (ATermAppl) value); break; case PDB_NODE_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Node didn't have AT_APPL type.\n"); exit(1); } { ATermList annotations = (ATermList) ATgetAnnotations(value); if(annotations == NULL){ writeNode(writer, expected, (ATermAppl) value); }else{ if(((A2PNodeType) expected->theType)->declaredAnnotations == NULL){ fprintf(stderr, "Node term has annotations, but none are declared.\n"); exit(1); } writeAnnotatedNode(writer, expected, (ATermAppl) value, annotations); } } break; case PDB_TUPLE_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Tuple didn't have AT_APPL type.\n"); exit(1); } writeTuple(writer, expected, (ATermAppl) value); break; case PDB_LIST_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "List didn't have AT_LIST type.\n"); exit(1); } writeList(writer, expected, (ATermList) value); break; case PDB_SET_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Set didn't have AT_LIST type.\n"); exit(1); } writeSet(writer, expected, (ATermList) value); break; case PDB_RELATION_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Relation didn't have AT_LIST type.\n"); exit(1); } writeRelation(writer, expected, (ATermList) value); break; case PDB_MAP_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Map didn't have AT_LIST type.\n"); exit(1); } writeMap(writer, expected, (ATermList) value); break; case PDB_CONSTRUCTOR_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Constructor didn't have AT_APPL type.\n"); exit(1); } { ATermList annotations = (ATermList) ATgetAnnotations(value); if(annotations == NULL){ writeConstructor(writer, expected, (ATermAppl) value); }else{ if(((A2PConstructorType) expected->theType)->declaredAnnotations == NULL){ fprintf(stderr, "Constructor term has annotations, but none are declared.\n"); exit(1); } writeAnnotatedConstructor(writer, expected, (ATermAppl) value, annotations); } } break; case PDB_ADT_TYPE_HEADER: writeADT(writer, expected, value); break; default: fprintf(stderr, "Unserializable type: %d\n.", expected->id); exit(1); } DKISstore(sharedValues, (void*) value, (void*) expected, valueHash); }
void TelegramCache::insert(const Message &msg) { const QString folderPath = getMessageFolder(TelegramTools::messagePeer(msg)); const QString filePath = folderPath + "/" + QString::number(msg.id()); writeMap(filePath, msg.toMap()); }
void TelegramCache::insertMe(const UserFull &user) { QDir().mkpath(p->path); writeMap(p->path + "/me", user.toMap()); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void DataContainerArrayProxy::writeJson(QJsonObject& json) const { json["Data Containers"] = writeMap(dataContainers); }
bool PathPlanning::defineGlobalPath(robot_control::defineGlobalPath::Request& req, robot_control::defineGlobalPath::Response& res){ /*ROS_INFO("calculating path from %d %d to %d %d", (int)TO_UNKNOWN_CELLS(req.x, req.cell_size) + UNKNOWN_CELL_BASE_X(req.cell_size), (int)TO_UNKNOWN_CELLS(req.y, req.cell_size) + UNKNOWN_CELL_BASE_Y(req.cell_size), (int)TO_UNKNOWN_CELLS(req.destiny_x, req.cell_size) + UNKNOWN_CELL_BASE_X(req.cell_size), (int)TO_UNKNOWN_CELLS(req.destiny_y, req.cell_size) + UNKNOWN_CELL_BASE_Y(req.cell_size)); */ vector<unsigned char> map = req.map; vector<Node*>* open_nodes = new vector<Node*>(); vector<Node*>* closed_nodes = new vector<Node*>(); vector<int> x_path, y_path; vector<Node*>::iterator it; Node* p_node = NULL; Node* current_node = NULL; Node* node = NULL; Node* end_node = NULL; int i, j; int F, G, H; // end position end_x = TO_UNKNOWN_CELLS(req.destiny_x, req.cell_size) + UNKNOWN_CELL_BASE_X(req.cell_size); end_y = TO_UNKNOWN_CELLS(req.destiny_y, req.cell_size) + UNKNOWN_CELL_BASE_Y(req.cell_size); // creating start and end nodes node = initNode(TO_UNKNOWN_CELLS(req.x, req.cell_size) + UNKNOWN_CELL_BASE_X(req.cell_size), TO_UNKNOWN_CELLS(req.y, req.cell_size) + UNKNOWN_CELL_BASE_Y(req.cell_size), 0, NULL); end_node = initNode(end_x, end_y, 0, NULL); // add start node to the open list open_nodes -> push_back(node); // while the end node isn't on the closed list while(find(closed_nodes, end_x, end_y) == closed_nodes -> end() && ros::ok()){ // sort the array sort(open_nodes -> begin(), open_nodes -> end(), cmpNodes); if(open_nodes -> empty()){ //ROS_INFO("Could not find path"); return false; } // put the node with the minimum F value on the closed list and remove it from the open list closed_nodes -> push_back(open_nodes -> front()); current_node = open_nodes -> front(); open_nodes -> erase(open_nodes -> begin()); // for all neighbours of the current node for(i = -1; i <= 1; i++){ for(j = -1; j <= 1; j++){ // if it isn't himself, the path is clear and it's not on the closed list if(IS_UNKNOWN_CELL_INSIDE(current_node -> x + i, current_node -> y + j, req.cell_size) && !(i == 0 && j == 0) && map.at(((current_node -> x + i) * TO_UNKNOWN_CELLS(length, req.cell_size)) + current_node -> y + j) < EMPTY_RANGE && find(closed_nodes, current_node -> x + i, current_node -> y + j) == closed_nodes -> end()){ it = find(open_nodes, current_node -> x + i, current_node -> y + j); // if the node isn't on the open list if(it == open_nodes -> end()){ // calculate G, H, F node = initNode(current_node -> x + i, current_node -> y + j, ((i == 0 || j == 0) ? ORTOGONAL_WEIGTH : DIAGONAL_WEIGTH) + current_node -> G, current_node); // add it to the open list open_nodes -> push_back(node); } // else if the node is already on the open list else{ node = (*it); // path from the current node to the node int aux_G = ((i == 0 || j == 0) ? ORTOGONAL_WEIGTH : DIAGONAL_WEIGTH) + current_node -> G; // if this path to the node is better than the old one, change it's settings if(node -> G > aux_G){ node -> parent = current_node; node -> G = aux_G; node -> H = (abs(current_node -> x + i - end_x) + (abs(current_node -> y + j - end_y))) * CTE; node -> F = node -> G + node -> H; } } } } } } ROS_INFO("Path found"); // get pointer to the end node (starting position) node = *(find(closed_nodes, end_x, end_y)); // go backwards until the starting node (destination position) while(node != NULL && ros::ok()){ // create and x y path x_path.push_back(node -> x); y_path.push_back(node -> y); // adding to the map for visualizing purposes map.at((node -> x * (TO_UNKNOWN_CELLS(length, req.cell_size))) + node -> y) = 'x'; node = node -> parent; } // erase unecessary nodes on the path defineLocalPath(&x_path, &y_path); vector<int>::iterator x, y; vector<int>::reverse_iterator _y; vector<int>::reverse_iterator _x; // adding to the map for visualizing purposes for(_x = x_path.rbegin(), _y = y_path.rbegin(); _x != x_path.rend(); _x++, _y++){ res.x_path.push_back(((*_x)*req.cell_size) - (MAP_LENGTH/2)); res.y_path.push_back(((*_y)*req.cell_size) - (MAP_WIDTH/2)); } for(x = x_path.begin(), y = y_path.begin(); x != x_path.end(); x++, y++) map.at(((*x) * (TO_UNKNOWN_CELLS(length, req.cell_size))) + (*y)) = 'X'; for(it = open_nodes -> begin(); it != open_nodes -> end(); it++) free((*it)); for(it = closed_nodes -> begin(); it != closed_nodes -> end(); it++) free((*it)); writeMap(map, req.cell_size); delete open_nodes; delete closed_nodes; return true; }