software/final/alf_car/src/slam/SlamMap.cpp
void SlamMap::createPgmMapFile(const nav_msgs::OccupancyGridConstPtr& map) {

    //std::string mapCounterStr = std::to_string(mapCounter_);
    //std::string mapdatafile = mapname_ + mapCounterStr +  ".pgm";
    std::string mapdatafile = mapname_ + ".pgm";
    ROS_INFO("Writing map occupancy data to %s", mapdatafile.c_str());

    FILE* out = fopen(mapdatafile.c_str(), "w");

    if (!out) {

        ROS_ERROR("Could not save map file to %s", mapdatafile.c_str());
        return;

    }

    fprintf(out, "P2\n%d %d 255\n",
            map->info.width,
            map->info.height);
    for(unsigned int y = 0; y < map->info.height; y++) {
        for(unsigned int x = 0; x < map->info.width; x++) {

            unsigned int i = x + (map->info.height -y -1) * map->info.width;

            if (map->data[i] >= 0 && map->data[i] <= threshold_free_) {

                //fputc(254, out);
                fprintf(out, "%d ",254);

            } else if (map->data[i] >= threshold_occupied_) {

                //fputc(000, out);
                fprintf(out, "%d ",0);

            } else {

                //fputc(205, out);
                fprintf(out, "%d ",205);

            }
        }
        fprintf(out, "\n");
    }

    fclose(out);

    ROS_INFO("DONE\n");
    mapCounter_++;
    setSaveMap(false);

}
/**
 * creates a pgm file to view the slam map
 *
 * @param map: const nav_msgs::OccupancyGridConstPtr reference to obtain the raw map data
 */
creates a pgm file to view the slam map
@param map: const nav_msgs::OccupancyGridConstPtr reference to obtain the raw map data
creates a pgm file to view the slam map @param map : const nav_msgs :: OccupancyGridConstPtr reference to obtain the raw map data
void SlamMap::createPgmMapFile(const nav_msgs::OccupancyGridConstPtr& map) {
    std::string mapdatafile = mapname_ + ".pgm";
    ROS_INFO("Writing map occupancy data to %s", mapdatafile.c_str());
    FILE* out = fopen(mapdatafile.c_str(), "w");
    if (!out) {
        ROS_ERROR("Could not save map file to %s", mapdatafile.c_str());
        return;
    }
    fprintf(out, "P2\n%d %d 255\n",
            map->info.width,
            map->info.height);
    for(unsigned int y = 0; y < map->info.height; y++) {
        for(unsigned int x = 0; x < map->info.width; x++) {
            unsigned int i = x + (map->info.height -y -1) * map->info.width;
            if (map->data[i] >= 0 && map->data[i] <= threshold_free_) {
                fprintf(out, "%d ",254);
            } else if (map->data[i] >= threshold_occupied_) {
                fprintf(out, "%d ",0);
            } else {
                fprintf(out, "%d ",205);
            }
        }
        fprintf(out, "\n");
    }
    fclose(out);
    ROS_INFO("DONE\n");
    mapCounter_++;
    setSaveMap(false);
}
void SlamMap :: createPgmMapFile ( const nav_msgs :: OccupancyGridConstPtr & map ) { std :: string mapdatafile = mapname_ + " " ; ROS_INFO ( " " , mapdatafile . c_str ( ) ) ; FILE * out = fopen ( mapdatafile . c_str ( ) , " " ) ; if ( ! out ) { ROS_ERROR ( " " , mapdatafile . c_str ( ) ) ; return ; } fprintf ( out , " \n \n " , map -> info . width , map -> info . height ) ; for ( unsigned int y = 0 ; y < map -> info . height ; y ++ ) { for ( unsigned int x = 0 ; x < map -> info . width ; x ++ ) { unsigned int i = x + ( map -> info . height - y - 1 ) * map -> info . width ; if ( map -> data [ i ] >= 0 && map -> data [ i ] <= threshold_free_ ) { fprintf ( out , " " , 254 ) ; } else if ( map -> data [ i ] >= threshold_occupied_ ) { fprintf ( out , " " , 0 ) ; } else { fprintf ( out , " " , 205 ) ; } } fprintf ( out , " \n " ) ; } fclose ( out ) ; ROS_INFO ( " \n " ) ; mapCounter_ ++ ; setSaveMap ( false ) ; }
creates a pgm file to view the slam map
 @param map: const nav_msgs::OccupancyGridConstPtr reference to obtain the raw map data
creates a pgm file to view the slam map @param map : const nav_msgs :: OccupancyGridConstPtr reference to obtain the raw map data
//std::string mapCounterStr = std::to_string(mapCounter_); //std::string mapdatafile = mapname_ + mapCounterStr +  ".pgm"; //fputc(254, out); //fputc(000, out); //fputc(205, out);