<Source Index
|
<PPA-L top page
pointlist.cpp
//////////////////////////////////////////////////
//
// This file is to be used for point process analysis
//
// Copyright October 2001 by TAKENAKA, A.
#include <iostream>
#include <fstream>
#include <strstream>
#include "pointlist.h"
///////////////////////////////////////////////
//
PointList::PointList(void)
:
AreaSize(0, 0)
{}
///////////////////////////////////////////////
//
void PointList::load (const char* fileName)
{
const int bufSize = 256;
char lineBuf[bufSize];
double x, y;
std::ifstream ifs(fileName);
if (!ifs) {
std::cerr << "Failed to open " << fileName << std::endl;
return;
}
bool area_loaded = false;
while (1){
ifs.getline(lineBuf, bufSize);
if (ifs.eof() == true) {
std::cerr << size() << " points loaded from <"
<< fileName << ">" << std::endl;
return;
}
if (strlen(lineBuf) == 0) { // Skip blank line
continue;
}
if (lineBuf[0] == char('#')) { // Comment line.
continue;
}
std::istrstream istr(lineBuf,strlen(lineBuf));
istr >> x >> y;
if (!area_loaded) { // First record specifies area size.
AreaSize = XY (x, y);
area_loaded = true;
}
else { // The rest are Point Data.
// Points out of the given range is omitted.
if (x > AreaSize.X || y > AreaSize.Y) {
std::cerr << "Point (" << x << "," << y << ") "
<< "Out of area [ "
<< double(AreaSize.X) << ","
<< double(AreaSize.Y) << "]" << std::endl;
}
else {
push_back(XY(x, y));
}
}
}
}
///////////////////////////////////////////////
//
const XY& PointList::getAreaSize(void) const
{
return AreaSize;
}