Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MapleFile.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------+
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2002  Qgar Project, LORIA                             |
00004  |                                                                     |
00005  | This library is free software; you can redistribute it and/or       |
00006  | modify it under the terms of the GNU Lesser General Public          |
00007  | License version 2.1, as published by the Free Software Foundation.  |
00008  |                                                                     |
00009  | This library is distributed in the hope that it will be useful,     |
00010  | but WITHOUT ANY WARRANTY; without even the implied warranty of      |
00011  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                |
00012  | See the GNU Lesser General Public License for more details.         |
00013  |                                                                     |
00014  | The GNU Lesser General Public License is included in the file       |
00015  | LICENSE.LGPL, in the root directory of the Qgar packaging. See      |
00016  | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. |
00017  | To receive a paper copy, write to the Free Software Foundation,     |
00018  | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.       |
00019  |                                                                     |
00020  | Contact Project Qgar for any information:                           |
00021  |   LORIA - équipe Qgar                                               |
00022  |   B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France                |
00023  |   email: qgar-contact@loria.fr                                      |
00024  |   http://www.qgar.org/                                              |
00025  *---------------------------------------------------------------------*/
00026 
00027 
00028 /**
00029  * @file   MapleFile.C
00030  * @brief  Implementation of class qgar::MapleFile.
00031  *
00032  *         See file MapleFile.H for the interface.
00033  *
00034  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00035  * @date   Jul 3, 2001  09:29
00036  * @since  qgar 1.0
00037  */
00038 
00039 
00040 
00041 // QGAR
00042 #include <qgarlib/AbstractFile.H>
00043 #include <qgarlib/GenImage.H>
00044 #include <qgarlib/Histogram.H>
00045 #include <qgarlib/MapleFile.H>
00046 
00047 
00048 
00049 namespace qgar
00050 {
00051 
00052 
00053 // -------------------------------------------------------------------
00054 // C O N S T R U C T O R S 
00055 // -------------------------------------------------------------------
00056 
00057 
00058 // INITIALIZE FROM A GREY-LEVEL IMAGE.
00059 
00060 MapleFile::MapleFile(char* aFileName,
00061                      GreyLevelImage& aGlvImg,
00062                      int aTesselation)
00063 
00064   : AbstractFile(aFileName)
00065 
00066 {
00067   openWONLY(); // open file for writing
00068 
00069   int idx = 0; // WARNING: Used out of the first loop body
00070   int jdx = 0;
00071 
00072   for ( ; idx < (aGlvImg.height() / aTesselation) - 1 ; ++idx)
00073     {
00074       _fileStream << '[';
00075 
00076       for ( ; jdx < (aGlvImg.width() / aTesselation) - 1 ; ++jdx)
00077         {
00078           _fileStream << '[' << jdx << ", " << idx << ", "
00079                       << (int) aGlvImg.pixel(aTesselation * idx, aTesselation * jdx)
00080                       << "],";
00081         }
00082       _fileStream << '[' << jdx << ", " << idx << ", "
00083                   << (int) aGlvImg.pixel(aTesselation * idx, aTesselation * jdx)
00084                   << "]],";
00085     }
00086 
00087   _fileStream << '[';
00088 
00089   for (jdx = 0 ; jdx < (aGlvImg.width() / aTesselation) - 1 ; ++jdx)
00090     {
00091       _fileStream << '[' << jdx << ", " << idx << ", "
00092                   << (int) aGlvImg.pixel(aTesselation * idx, aTesselation * jdx)
00093                   << "],";
00094     }
00095  
00096  _fileStream << '[' << jdx << ", " << idx << ", "
00097               << (int) aGlvImg.pixel(aTesselation * idx, aTesselation * jdx)
00098               << "]]];" << std::endl;
00099 
00100   // footer
00101   _fileStream << "with(plots);surfdata(fich);" << std::endl;
00102 
00103   close();
00104 }
00105 
00106 
00107 // INITIALIZE FROM A FLOAT IMAGE
00108 
00109 MapleFile::MapleFile(char* aFileName,
00110                      FloatImage& aFloatImg,
00111                      int aTesselation)
00112 
00113   : AbstractFile(aFileName)
00114 
00115 {
00116   openWONLY();  // open file for writing
00117 
00118   int idx = 0; // WARNING: Used out of the first loop body
00119   int jdx = 0;
00120 
00121   for ( ; idx < (aFloatImg.height() / aTesselation) - 1 ; ++idx)
00122     {
00123       _fileStream << '[';
00124 
00125       for ( ; jdx < (aFloatImg.width() / aTesselation) - 1 ; ++jdx)
00126         {
00127           _fileStream << '[' << jdx << ", " << idx << ", "
00128                       << aFloatImg.pixel(aTesselation * idx, aTesselation * jdx)
00129                       << "],";
00130         }
00131         _fileStream << '[' << jdx << ", " << idx << ", "
00132                     << aFloatImg.pixel(aTesselation * idx, aTesselation * jdx)
00133                     << "]],";
00134     }
00135 
00136   _fileStream << '[';
00137 
00138   for (jdx = 0 ; jdx < (aFloatImg.width() / aTesselation) - 1 ; ++jdx)
00139     _fileStream << '[' << jdx << ", " << idx << ", "
00140                 << aFloatImg.pixel(aTesselation * idx, aTesselation * jdx)
00141                 << "],";
00142   _fileStream << '[' << jdx << ", " << idx << ", "
00143               << aFloatImg.pixel(aTesselation * idx, aTesselation * jdx)
00144               << "]]];" << std::endl;
00145 
00146   // footer
00147   _fileStream << "with(plots);surfdata(fich);" << std::endl;
00148 
00149   close();
00150 }
00151 
00152 
00153 // INITIALIZE FROM A HISTOGRAM
00154 
00155 MapleFile::MapleFile(char* aFileName, Histogram& aHistogram)
00156 
00157   : AbstractFile(aFileName)
00158 
00159 {
00160   openWONLY();  // open file for writing
00161 
00162   int  idx     = aHistogram.lowerBnd();
00163   int  max     = aHistogram.upperBnd();
00164   int  sRate   = aHistogram.samplingRate();
00165   bool notLast = true;
00166 
00167   // WARNING: As the sampling rate may not be equal to 1, it is not
00168   // possible to use a 'for' instruction from min index to max index.
00169   while (notLast)
00170     {
00171       _fileStream << '[' << idx << ", " << aHistogram[idx] << ']';
00172       idx += sRate;
00173       if (idx <= max)
00174         {
00175           _fileStream << ',';
00176         }
00177       else
00178         {
00179           notLast = false;
00180         }
00181     }
00182 
00183   // footer
00184   _fileStream << "];\nplot(fich);" << std::endl;
00185 
00186   close();
00187 }
00188 
00189 
00190 // -------------------------------------------------------------------
00191 // D E S T R U C T O R
00192 // -------------------------------------------------------------------
00193 
00194 
00195 // VIRTUAL DESTRUCTOR
00196 
00197 MapleFile::~MapleFile()
00198 {
00199   // VOID
00200 }
00201 
00202 
00203 // -------------------------------------------------------------------
00204 // I N P U T  /  O U T P U T 
00205 // -------------------------------------------------------------------
00206 
00207 
00208 // READ FILE HEADER
00209 
00210 void
00211 MapleFile::readHeader()
00212 {
00213   // VOID
00214 }
00215 
00216 
00217 // WRITE FILE HEADER
00218 
00219 void
00220 MapleFile::writeHeader()
00221 { 
00222   _fileStream << "fich :=[";
00223 }
00224 
00225 
00226 // WRITE FILE FOOTER
00227 
00228 void
00229 MapleFile::writeFooter()
00230 {
00231   // VOID
00232 }
00233 
00234 
00235 // -------------------------------------------------------------------
00236 
00237 } // namespace qgar