index page
0001: //////////////////////////////////////////////////
0002: //
0003: //  This file is to be used for point process analysis
0004: //
0005: //      Copyright  October 2001 by TAKENAKA, A.
0006: 
0007: #include <iostream>
0008: #include <fstream>
0009: #include <strstream>
0010: 
0011: #include "pointlist.h"
0012: 
0013: ///////////////////////////////////////////////
0014: //
0015: 
0016: PointList::PointList(void)
0017:   :
0018:   AreaSize(0, 0)
0019: {}
0020: 
0021: ///////////////////////////////////////////////
0022: //
0023: 
0024: void PointList::load (const char* fileName)
0025: {
0026:     const int bufSize = 256;
0027:     char lineBuf[bufSize];
0028: 
0029:     double x, y;
0030: 
0031:     std::ifstream ifs(fileName);
0032: 
0033:     if (fileName != NULL && !ifs) {
0034:         std::cerr << "Failed to open " << fileName << std::endl;
0035:         return;
0036:     }
0037: 
0038:     bool area_loaded = false;
0039: 
0040:     while (1){
0041: 
0042:         if (ifs)  {
0043:             ifs.getline(lineBuf, bufSize);
0044:             if (ifs.eof() == true) {
0045:                 return;
0046:             }
0047:         }
0048:         else {
0049:             std::cin.getline(lineBuf, bufSize);
0050:             if (std::cin.eof() == true) {
0051:                 return;
0052:             }
0053:         }
0054: 
0055:         if (strlen(lineBuf) == 0) {  //  Skip blank line
0056:             continue;
0057:         }
0058: 
0059:         if (lineBuf[0] == char('#')) {  //  Comment line.
0060:             continue;
0061:         }
0062: 
0063:         std::istrstream istr(lineBuf,strlen(lineBuf));
0064:         istr >> x >> y;
0065: 
0066:         if (!area_loaded) { // First record specifies area size.
0067:             AreaSize = XY (x, y);
0068:             area_loaded = true;
0069:         }
0070: 
0071:         else {             // The rest are Point Data.
0072: 
0073:           // Points out of the given range is omitted.
0074:             if (x > AreaSize.X || y > AreaSize.Y) {
0075:                 std::cerr << "Point (" << x << "," << y << ") "
0076:                           << "Out of area [ "
0077:                           << double(AreaSize.X)  << ","
0078:                           << double(AreaSize.Y)  << "]" << std::endl;
0079:             }
0080:             else {
0081:                 push_back(XY(x, y));
0082:             }
0083:         }
0084:     }
0085: }
0086: 
0087: ///////////////////////////////////////////////
0088: //
0089: 
0090: const XY& PointList::getAreaSize(void) const
0091: {
0092:     return AreaSize;
0093: }

Back to Top of this Page