ppm.h
Go to the documentation of this file.
00001 /*
00002  * PPM Image Format Reader
00003  * Code adapted from http://stackoverflow.com/questions/2693631/read-ppm-file-and-store-it-in-an-array-coded-with-c
00004  * 8/1/2012
00005  * License Unkown
00006  */
00007 
00008 #ifndef OMPL_VISUAL_TOOLS_PPM_
00009 #define OMPL_VISUAL_TOOLS_PPM_
00010 
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 
00014 namespace ompl_visual_tools
00015 {
00016 
00017 // *************************************************************************************************
00018 // PPMPixel Struct
00019 // *************************************************************************************************
00020 typedef struct {
00021   unsigned char red,green,blue;
00022 } PPMPixel;
00023 
00024 // *************************************************************************************************
00025 // PPMImage Struct
00026 // *************************************************************************************************
00027 class PPMImage
00028 {
00029 public:
00030   // Constructor
00031   PPMImage() :
00032     x(0), y(0), data(NULL)
00033   {
00034   }
00035 
00036   // Deconstructor
00037   ~PPMImage()
00038   {
00039     if( data != NULL )
00040       free(data);
00041   }
00042 
00043   // Convert coordinates to a id number
00044   unsigned int getID( unsigned int x_coord, unsigned int y_coord )
00045   {
00046     return y_coord * x + x_coord;
00047   }
00048 
00049   // Convert id to x
00050   unsigned int getX( unsigned int id )
00051   {
00052     return id % x;
00053   }
00054 
00055   // Convert id to y
00056   unsigned int getY( unsigned int id )
00057   {
00058     return id / x;
00059   }
00060 
00061   unsigned int getSize()
00062   {
00063     return x * y;
00064   }
00065 
00066   // Member variables
00067   unsigned int x, y;
00068   PPMPixel *data;
00069 };
00070 
00071 
00072 #define CREATOR "RPFELGUEIRAS"
00073 #define RGB_COMPONENT_COLOR 255
00074 
00075 // *************************************************************************************************
00076 // Read Function
00077 // *************************************************************************************************
00078 
00079 PPMImage *readPPM(const char *filename);
00080 
00081 
00082 } // namespace
00083 
00084 #endif
00085 
00086 


ompl_visual_tools
Author(s): Dave Coleman
autogenerated on Thu Feb 11 2016 23:58:14