Hi

I need to write data which I have successfully read in from a text file, to a new file. The original text file contains data for many objects. The read in data is stored using stl vectors in 3 nested objects: Structure, Polygon and Point i.e. a Structure contains >=2 Polygons which in turn comprises >=3 Points. Attached are the .h and .cpp files since they are quite large (planROI.cpp in particular).

Everything was going swimmingly (printing read in values to screen with std::cout) until I tried to write the data out to file.

There are no compilation errors, but when I execute the program the vectors go out of range giving the following error message:

terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check


Found 1 PTV(s)
PTV0: "PTV"
Opened file : /home/mark/PTV0.txt


Inspecting the files you will see that I have also tried overloading the ostream << operator for the objects. This did not help.

I know this is a rather vague description of my problem, but I am a bit of a loss to explain this at the moment. I suspect the problem lies with the use of the constructors and member functions to populate the stl vectors that the Structure and Polygon objects contain.

Thanks in anticipation


Mark

Attachments
/*
 * Includes.h
 *
 *  Created on: 16 Aug 2010
 *      Author: mark
 */

#ifndef INCLUDES_H_
#define INCLUDES_H_

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include "planROI.h"
#include <GL/glut.h>


#endif /* INCLUDES_H_ */
/*
 * planROI.cpp
 *
 *  Created on: 16 Aug 2010
 *      Author: mark
 */

#include "Includes.h"
#include <sstream>
//#include <cstdlib>
Point::Point():x(0.0),y(0.0),z(0.0),radius(0.0){

}

Point::Point(float x, float y, float z):x(x), y(y), z(z),radius (0.0){

}

Point::Point(const Point &p){
	x=p.x;
	y=p.y;
	z=p.z;
	radius=p.radius;

}

void Point::getPoint(){
	std::cout << x << " " << y << " " << z << "\n";
	return;
}

std::ostream& operator<< (std::ostream &out,Point &p)
{
	out << p.x << " " << p.y << " " << p.z << "\n";
	return out;
}

Point::~Point(){
	x=y=z=radius=0.0;
}



Polygon::Polygon():numPoints(0){
	polygonPoints.clear();
}

Polygon::Polygon(const int nP):numPoints(nP){


}

Polygon::~Polygon(){

	if (!polygonPoints.empty()){
		polygonPoints.clear();
	}
}

triangle::triangle(){
	v[0]=v[1]=v[2]=0;

}

triangle::triangle(int v0, int v1, int v2){
	v[0]=v0;
	v[1]=v1;
	v[2]=v2;
}

triangle::triangle(const triangle &t){
	for (int curT=0;curT!=3;curT++)
	{
		v[curT]=t.v[curT];
	}
}

void triangle::getTriangle(){

	for (int curT=0;curT!=3;curT++)
	{
		std::cout << v[curT] << " ";
	}
	std::cout << "\n";

}

std::ostream& operator<< (std::ostream &out,triangle &t)
{
	out << t.v[0] << t.v[1] << t.v[2] << "\n";
	return out;
}

triangle::~triangle(){
	v[0]=v[1]=v[2]=0;
}

Mesh::Mesh():numTriangles(0){
	faces.clear();
}

Mesh::Mesh(int nP):numTriangles(nP)
{
/*	for (int curFace=0;curFace!=numFaces;curFace++){
		faces.push_back(Face(vertex1,vertex2,vertex3));
	}*/
}

Mesh::Mesh(int nP, int nT):numMeshPoints(nP),numTriangles(nT){

}

std::ostream& operator<< (std::ostream &out,Mesh &m)

{
	if ((m.numMeshPoints<=0)||(m.numTriangles<=0)){
		out << "\nInvalid mesh: " << m.numMeshPoints << " mesh points and " << m.numTriangles << " faces!\n";
//		return out;
	}

	else
	{
	out << "#Surface mesh#\n";
	out << "#Number of vertices, faces\n";
	out << m.numMeshPoints << " " << m.numTriangles << "\n";

		for (int curMeshPoint=0;curMeshPoint!=m.numMeshPoints;curMeshPoint++)

		{
			out << m.MeshPoints.at(curMeshPoint);
		}

		for (int curTriangle=0;curTriangle!=m.numTriangles;curTriangle++)

		{
			out << m.faces.at(curTriangle);
		}

	}
	return out;

}

Mesh::~Mesh(){
	numTriangles=numMeshPoints=0;
	if (!faces.empty()) faces.clear();
	if (!MeshPoints.empty()) MeshPoints.clear();
}

Structure::Structure():name(),numPolygons(0){
	isPTV=isOAR=false;

	polygons.clear();
}

/*Structure::Structure(const Structure &s){
	std::cout<< "\nCopy constructor called\n";
	isPTV=s.isPTV;
	isOAR=s.isOAR;
	name=s.name;
	numPolygons=s.numPolygons;
	if (!s.polygons.empty())
	{
		for (int curPolygon=0;curPolygon!=s.numPolygons;curPolygon++)

		{
			polygons.push_back(Polygon(s.polygons.at(curPolygon).numPoints));
			for (int curPoint=0;curPoint!=s.polygons.at(curPolygon).numPoints;curPoint++)
			{
				polygons.at(curPolygon).polygonPoints.at(curPoint)=s.polygons.at(curPolygon).polygonPoints.at(curPoint);
			}
		}
	}
	else return;
}*/


Structure::Structure(const std::string structureName, const int numPoly, const bool ptv):name(structureName), numPolygons(numPoly), isPTV(ptv), isOAR(!ptv){

/*	for (int curPolygon=1;curPolygon!=numPolygons;curPolygon++){
		polygons.push_back(Polygon(numPoly));
	}*/


}

Structure::Structure(const std::string structureName, const bool ptv):name(structureName),isPTV(ptv), isOAR(!ptv){

}

Structure::~Structure(){

	isPTV=isOAR=false;
	if(!polygons.empty()){
		polygons.clear();
	}
	name.clear();

}

void Structure::setPolygons(const int p){
	numPolygons=p;
/*	for (int curPolygon=1;curPolygon!=numPolygons;curPolygon++){
			polygons.push_back(Polygon(numPoly));
	}*/

}

std::ostream& operator<< (std::ostream &out,Structure &s){
	out << "#" << s.name << "\n";
	out << "# IsPTV: " << s.isPTV << "\n";
	out << "# IsOAR: " << s.isOAR << "\n";
	for (int curPoly=0;curPoly!=s.polygons.size();curPoly++)
	{
		for (int curPoint;curPoint!=s.polygons.at(curPoly).numPoints;curPoint++)
		{
			out << s.polygons.at(curPoly).polygonPoints.at(curPoint);
		}
	}
	return out;
}

void Structure::writeFile(std::ofstream &fileOut){
	fileOut << "#" << this->name << "\n";
		fileOut << "# IsPTV: " << this->isPTV << "\n";
		fileOut << "# IsOAR: " << this->isOAR << "\n";
		std::cout<< "\nStructure \"" << this->name << "\" has " << this->polygons.size()-1 << " polygons!\n";
		for (int curPoly=0;curPoly!=this->polygons.size();curPoly++)
		{
			std::cout << "\nPolygon " << curPoly << " has " << this->polygons.at(curPoly).polygonPoints.size() << " points\n";
			for (int curPoint;curPoint!=this->polygons.at(curPoly).polygonPoints.size();curPoint++)
			{
//				std::cout << curPoint << " ";
//				fileOut << this->polygons.at(curPoly).polygonPoints.at(curPoint);
//				fileOut << this->polygons.at(curPoly).polygonPoints.at(curPoint).x << " " << this->polygons.at(curPoly).polygonPoints.at(curPoint).y <<" "<<
//						this->polygons.at(curPoly).polygonPoints.at(curPoint).z << "\n";
			}
		}
//		return out;
}

/*roiHeader::roiHeader(){



}*/

p3RoiFile::p3RoiFile(){

}

p3RoiFile::p3RoiFile(char* inputFileName, char* PTVprefix, char* OARprefix):inputROI(inputFileName),prefixPTV(PTVprefix),prefixOAR(OARprefix),
//p3RoiFile::p3RoiFile(char *arguments[]):inputROI(arguments[1]),prefixPTV(arguments[2]),prefixOAR(arguments[3]),curLineNumber(0),
																	 insidePTV(false),insideOAR(false)
{
	roiHeaderStart="roi={";
	roiName="           name:";
	roiHeaderStop="};";
	surfaceMesh="surface_mesh={";
	std::string PTVout,OARout;
	std::stringstream intToString;

	int numPoints,surfaceMeshPoints,surfaceMeshTriangles;
	float coord[3];
	std::cout << "\nInside p3Roi constructor\n";
	std::cout << prefixPTV << " " << prefixOAR << "\n";

	if(!inputROI.is_open()){
		std::cerr << "\nCannot open file \"" << inputFileName << "\". Make sure it exists and that the specified path is correct!\n";
		exit(EXIT_FAILURE);
	}

	while(getline(inputROI,curLine)){
		curLineNumber++;
		if((curLine[0]!='#')&&(curLine[0]!='/'))
		{

			if (curLine.size()>=6)
			{
			// Look for each roi header string
			if (curLine.compare(1,6,roiHeaderStart)==0)
			{
				//Now get next line which contains roi name
				getline(inputROI,curLine);
				curLineNumber++;

				std::string temp=curLine.substr(17);
				std::cout << "Found structure \"" << temp << "\"\n";

				// store roi name in string array roiNames
				roiNames.push_back(temp);


				//check if temp string matches prefixPTV string

				if ((temp.compare(0,prefixPTV.size(),prefixPTV)==0)&&(temp.size()==prefixPTV.size()))
				{
					std::cout << "\nFound PTV \"" << temp << "\" at line " << curLineNumber << "\n";
					insidePTV=true;
					numPoints=0;
					PTV.push_back(Structure(temp,1));
					this->parseStructure(PTV.back());
				}


				//check if temp string matches prefixOAR string

				if ((temp.compare(0,prefixOAR.size(),prefixOAR)==0)&&(temp.size()==prefixOAR.size()))
				{
					std::cout << "\nFound OAR \"" << temp << "\" at line " << curLineNumber << "\n";
					insideOAR=true;
					numPoints=0;
					OAR.push_back(Structure(temp,1));
					this->parseStructure(OAR.back());
				}
				else;

			} // end of find roi header comparison

			else;
		}
		else;


		}
		else;

	} // end of while block

	std::cout << "\n\nFound " << PTV.size() << " PTV(s)\n";

	for (int curPTV=0;curPTV!=PTV.size();curPTV++){
		std::cout << "PTV" << curPTV << ": \"" << PTV.at(curPTV).name << "\"";

		// create file name from structure name
		PTVout="/home/mark/";
		PTVout+=PTV.at(curPTV).name;

		intToString << curPTV;
		PTVout+=intToString.str();

		PTVout+=".structure";
		std::ofstream PTVfile(PTVout.c_str());

		std::cout << "\nOpened file : " << PTVout << "\n";

		for (int curPoly=0;curPoly!=PTV.at(curPTV).polygons.size();curPTV++)
		{
			PTVfile << "#Polygon "<< curPoly << "(" << PTV.at(curPTV).polygons.size()-1 << ")\n";
			for (int curPoint=0;curPoint!=PTV.at(curPTV).polygons.at(curPoly).polygonPoints.size();curPoint++)
			{
				PTVfile << PTV.at(curPTV).polygons.at(curPoly).polygonPoints.at(curPoint).x << " " <<
						PTV.at(curPTV).polygons.at(curPoly).polygonPoints.at(curPoint).y << " " <<
						PTV.at(curPTV).polygons.at(curPoly).polygonPoints.at(curPoint).z<< "\n";
			}
		}
		PTVfile << "\n#End of file\n";

//		PTVfile << PTV.at(curPTV);
		PTVfile.close();
		PTVout.clear();
		intToString.clear();


	}

	std::cout << "\n\nFound " << OAR.size() << " OAR(s)\n";

	for (int curOAR=0;curOAR!=OAR.size();curOAR++){
		std::cout << "OAR" << curOAR << ": \"" << OAR.at(curOAR).name << "\"";

		OARout="/home/mark/";
		OARout+=OAR.at(curOAR).name;

		intToString << curOAR;
		OARout+=intToString.str();

		OARout+=".structure";
		std::ofstream OARfile(OARout.c_str());
		std::cout << "\nOpened file : " << OARout << "\n";

//		OARfile << OAR.at(curOAR);
		OARfile.close();
		OARout.clear();
		intToString.clear();
	}

}




Point p3RoiFile::readCoords(){
	float coord[3];
	for (int i=0;i!=2;i++)
	{
		coord[i]=0.0;
		getline(inputROI,curLine,' ');
	//								std::cout << curPoint << "." << i << " : " << curLine << "\n";
		coord[i]=atof(curLine.c_str());


	}
	coord[2]=0.0;
	getline(inputROI,curLine);
	coord[2]=atof(curLine.c_str());

	Point p1(coord[0],coord[1],coord[2]);

	return p1;


}

void p3RoiFile::setPTVCoords(){

}

void p3RoiFile::parseStructure(Structure &s){
	int numPoints,surfaceMeshPoints,surfaceMeshTriangles;
	// skip over rest of header info
					for(int skipLine=0;skipLine!=33;skipLine++)
					{

						getline(inputROI,curLine);
						curLineNumber++;
						//||(temp.compare(0,prefixOAR.size()-1,prefixOAR)==0)) ;
					}


					// get line containing number of polygons
					getline(inputROI,curLine);
//					std::cout << "\nNumber of curves line? \"" << curLine << "\"";
					curLineNumber++;
					int numCurves=atoi((curLine.substr(23,curLine.size()-24)).c_str());

					s.setPolygons(numCurves);

					std::cout << "\nExpect " << numCurves << " closed polygons for current PTV structure\n";

//TODO
					for (int curPoly=0;curPoly!=numCurves;curPoly++)
					{
						for (int skipLine=0;skipLine!=7;skipLine++)
						{
						getline(inputROI,curLine);
						if (skipLine<4) std::cout << "\"" << curLine << "\"\n";
						curLineNumber++;
						}
						getline(inputROI,curLine);
						curLineNumber++;
//
/*
 * planROI.h
 *
 *  Created on: 16 Aug 2010
 *      Author: mark
 */

#ifndef PLANROI_H_
#define PLANROI_H_

class Point;
class Polygon;
class triangle;
class Mesh;
class Structure;
class roiHeader;
class p3RoiFile;

#include <vector>
#include <iostream>
#include <fstream>
#include <cstring>


class Point{

public:
	float x,y,z,radius;
	Point();
	Point(float x, float y, float z);
	Point(const Point &p);
	void getPoint();
	friend std::ostream& operator<< (std::ostream &out,Point &p);
	~Point();
};

class Polygon{
public:
	int numPoints;
	std::vector<Point> polygonPoints;
	Polygon();
	Polygon(const int nP);
//	Polygon(const Polygon &copy);
	~Polygon();

};

class triangle{
public:
	int v[2];
	triangle();
	triangle(int v0, int v1, int v2);
	triangle(const triangle &t);
	void getTriangle();
	friend std::ostream& operator<< (std::ostream &out,triangle &t);
	~triangle();
};

class Mesh{
public:
	int numTriangles,numMeshPoints;
	std::vector<Point> MeshPoints;
	std::vector<triangle> faces;
	Mesh();
	Mesh(int nT);
	Mesh(int nP, int nT);
	// overload ostream operator to output mesh to file/screen
	friend std::ostream& operator<< (std::ostream &out,Mesh &m);
	~Mesh();
};


class Structure{
public:
	int numPolygons;
	bool isPTV,isOAR;
	std::string name;
	std::vector<Polygon> polygons;
	std::vector<Mesh> surface;

	Structure();
	// copy constructor
//	Structure(const Structure &s);
	// parametered constructors
	Structure(const std::string structureName, const int numPoly, const bool ptv);
	Structure(const std::string structureName, const bool ptv);
	//destructor
	~Structure();

	// member/ friend functions
	void setPolygons(const int p);
	friend std::ostream& operator<< (std::ostream &out,Structure &s);
	void writeFile(std::ofstream &fileOut);
};


class p3RoiFile{
public:
	int curLineNumber;
	int roiFound;
	bool insidePTV;
	bool insideOAR;
	std::vector<std::string> roiNames;
	std::vector<std::string> structureHeader;
	std::vector<Structure> PTV;
	std::vector<Structure> OAR;
	std::string curLine, filestamp, roiHeaderStart, roiName, roiHeaderStop,prefixPTV,prefixOAR,surfaceMesh;
	std::ifstream inputROI;
	p3RoiFile();

	p3RoiFile(char* inputFileName, char* PTVprefix, char* OARprefix);

	Point readCoords();
	triangle readTri();
	void parseStructure(Structure &s);
	void setPTVCoords();
	~p3RoiFile();
};

#endif /* PLANROI_H_ */
#Polygon 0(97)
-1.01562 -58.1813 -4.79995
-0.9375 -58.1813 -4.79995
-0.859375 -58.1813 -4.79995
-0.78125 -58.1813 -4.79995
-0.703125 -58.1813 -4.79995
-0.625 -58.1813 -4.79995
-0.546875 -58.1813 -4.79995
-0.46875 -58.1813 -4.79995
-0.390625 -58.1813 -4.79995
-0.3125 -58.1813 -4.79995
-0.234375 -58.1813 -4.79995
-0.15625 -58.1813 -4.79995
-0.078125 -58.1813 -4.79995
0 -58.1813 -4.79995
0.078125 -58.1813 -4.79995
0.15625 -58.1813 -4.79995
0.234375 -58.1813 -4.79995
0.3125 -58.1813 -4.79995
0.390625 -58.1813 -4.79995
0.46875 -58.1813 -4.79995
0.546875 -58.1813 -4.79995
0.625 -58.1813 -4.79995
0.703125 -58.1813 -4.79995
0.78125 -58.2594 -4.79995
0.859375 -58.2594 -4.79995
0.9375 -58.2594 -4.79995
1.01562 -58.2594 -4.79995
1.09375 -58.2594 -4.79995
1.17188 -58.2594 -4.79995
1.25 -58.3375 -4.79995
1.32812 -58.3375 -4.79995
1.40625 -58.3375 -4.79995
1.48438 -58.3375 -4.79995
1.5625 -58.4156 -4.79995
1.64062 -58.4156 -4.79995
1.71875 -58.4156 -4.79995
1.79688 -58.4156 -4.79995
1.875 -58.4938 -4.79995
1.95312 -58.4938 -4.79995
2.03125 -58.4938 -4.79995
2.10938 -58.5719 -4.79995
2.1875 -58.5719 -4.79995
2.26562 -58.5719 -4.79995
2.34375 -58.65 -4.79995
2.42188 -58.65 -4.79995
2.5 -58.7281 -4.79995
2.57812 -58.7281 -4.79995
2.65625 -58.8063 -4.79995
2.73438 -58.8063 -4.79995
2.8125 -58.8844 -4.79995
2.89062 -58.8844 -4.79995
2.96875 -58.9625 -4.79995
3.04688 -58.9625 -4.79995
3.125 -59.0406 -4.79995
3.20312 -59.0406 -4.79995
3.28125 -59.1188 -4.79995
3.35938 -59.1969 -4.79995
3.4375 -59.1969 -4.79995
3.51562 -59.275 -4.79995
3.59375 -59.3531 -4.79995
3.67188 -59.3531 -4.79995
3.75 -59.4313 -4.79995
3.82812 -59.5094 -4.79995
3.90625 -59.5875 -4.79995
3.98438 -59.5875 -4.79995
4.0625 -59.6656 -4.79995
4.14062 -59.7438 -4.79995
4.21875 -59.8219 -4.79995
4.29688 -59.9 -4.79995
4.375 -59.9781 -4.79995
4.45312 -60.0563 -4.79995
4.53125 -60.1344 -4.79995
4.60938 -60.2125 -4.79995
4.6875 -60.2906 -4.79995
4.76562 -60.3688 -4.79995
4.84375 -60.4469 -4.79995
4.92188 -60.525 -4.79995
4.92188 -60.6031 -4.79995
5 -60.6813 -4.79995
5.07812 -60.7594 -4.79995
5.15625 -60.8375 -4.79995
5.15625 -60.9156 -4.79995
5.23438 -60.9938 -4.79995
5.3125 -61.0719 -4.79995
5.3125 -61.15 -4.79995
5.39062 -61.2281 -4.79995
5.46875 -61.3063 -4.79995
5.46875 -61.3844 -4.79995
5.54688 -61.4625 -4.79995
5.54688 -61.5406 -4.79995
5.625 -61.6188 -4.79995
5.625 -61.6969 -4.79995
5.70312 -61.775 -4.79995
5.70312 -61.8531 -4.79995
5.78125 -61.9313 -4.79995
5.78125 -62.0094 -4.79995
5.85938 -62.0875 -4.79995
5.85938 -62.1656 -4.79995
5.9375 -62.2438 -4.79995
5.9375 -62.3219 -4.79995
5.9375 -62.4 -4.79995
6.01562 -62.4781 -4.79995
6.01562 -62.5563 -4.79995
6.01562 -62.6344 -4.79995
6.09375 -62.7125 -4.79995
6.09375 -62.7906 -4.79995
6.09375 -62.8688 -4.79995
6.09375 -62.9469 -4.79995
6.17188 -63.025 -4.79995
6.17188 -63.1031 -4.79995
6.17188 -63.1813 -4.79995
6.17188 -63.2594 -4.79995
6.25 -63.3375 -4.79995
6.25 -63.4156 -4.79995
6.25 -63.4938 -4.79995
6.25 -63.5719 -4.79995
6.25 -63.65 -4.79995
6.25 -63.7281 -4.79995
6.32812 -63.8063 -4.79995
6.32812 -63.8844 -4.79995
6.32812 -63.9625 -4.79995
6.32812 -64.0406 -4.79995
6.32812 -64.1188 -4.79995
6.32812 -64.1969 -4.79995
6.32812 -64.275 -4.79995
6.32812 -64.3531 -4.79995
6.32812 -64.4313 -4.79995
6.32812 -64.5094 -4.79995
6.32812 -64.5875 -4.79995
6.32812 -64.6656 -4.79995
6.32812 -64.7438 -4.79995
6.32812 -64.8219 -4.79995
6.32812 -64.9 -4.79995
6.32812 -64.9781 -4.79995
6.32812 -65.0563 -4.79995
6.32812 -65.1344 -4.79995
6.32812 -65.2125 -4.79995
6.32812 -65.2906 -4.79995
6.32812 -65.3688 -4.79995
6.32812 -65.4469 -4.79995
6.32812 -65.525 -4.79995
6.25 -65.6031 -4.79995
6.25 -65.6813 -4.79995
6.25 -65.7594 -4.79995
6.25 -65.8375 -4.79995
6.25 -65.9156 -4.79995
6.25 -65.9938 -4.79995
6.17188 -66.0719 -4.79995
6.17188 -66.15 -4.79995
6.17188 -66.2281 -4.79995
6.17188 -66.3063 -4.79995
6.09375 -66.3844 -4.79995
6.09375 -66.4625 -4.79995
6.09375 -66.5406 -4.79995
6.09375 -66.6188 -4.79995
6.01562 -66.6969 -4.79995
6.01562 -66.775 -4.79995
6.01562 -66.8531 -4.79995
5.9375 -66.9313 -4.79995
5.9375 -67.0094 -4.79995
5.9375 -67.0875 -4.79995
5.85938 -67.1656 -4.79995
5.85938 -67.2438 -4.79995
5.78125 -67.3219 -4.79995
5.78125 -67.4 -4.79995
5.70312 -67.4781 -4.79995
5.70312 -67.5563 -4.79995
5.625 -67.6344 -4.79995
5.625 -67.7125 -4.79995
5.54688 -67.7906 -4.79995
5.54688 -67.8688 -4.79995
5.46875 -67.9469 -4.79995
5.46875 -68.025 -4.79995
5.39062 -68.1031 -4.79995
5.3125 -68.1813 -4.79995
5.3125 -68.2594 -4.79995
5.23438 -68.3375 -4.79995
5.15625 -68.4156 -4.79995
5.15625 -68.4938 -4.79995
5.07812 -68.5719 -4.79995
5 -68.65 -4.79995
4.92188 -68.7281 -4.79995
4.92188 -68.8063 -4.79995
4.84375 -68.8844 -4.79995
4.76562 -68.9625 -4.79995
4.6875 -69.0406 -4.79995
4.60938 -69.1188 -4.79995
4.53125 -69.1969 -4.79995
4.45312 -69.275 -4.79995
4.375 -69.3531 -4.79995
4.29688 -69.4313 -4.79995
4.21875 -69.5094 -4.79995
4.14062 -69.5875 -4.79995
4.0625 -69.6656 -4.79995
3.98438 -69.7438 -4.79995
3.90625 -69.7438 -4.79995
3.82812 -69.8219 -4.79995
3.75 -69.9 -4.79995
3.67188 -69.9781 -4.79995
3.59375 -69.9781 -4.79995
3.51562 -70.0563 -4.79995
3.4375 -70.1344 -4.79995
3.35938 -70.1344 -4.79995
3.28125 -70.2125 -4.79995
3.20312 -70.2906 -4.79995
3.125 -70.2906 -4.79995
3.04688 -70.3688 -4.79995
2.96875 -70.3688 -4.79995
2.89062 -70.4469 -4.79995
2.8125 -70.4469 -4.79995
2.73438 -70.525 -4.79995
2.65625 -70.525 -4.79995
2.57812 -70.6031 -4.79995
2.5 -70.6031 -4.79995
2.42188 -70.6813 -4.79995
2.34375 -70.6813 -4.79995
2.26562 -70.7594 -4.79995
2.1875 -70.7594 -4.79995
2.10938 -70.7594 -4.79995
2.03125 -70.8375 -4.79995
1.95312 -70.8375 -4.79995
1.875 -70.8375 -4.79995
1.79688 -70.9156 -4.79995
1.71875 -70.9156 -4.79995
1.64062 -70.9156 -4.79995
1.5625 -70.9156 -4.79995
1.48438 -70.9938 -4.79995
1.40625 -70.9938 -4.79995
1.32812 -70.9938 -4.79995
1.25 -70.9938 -4.79995
1.17188 -71.0719 -4.79995
1.09375 -71.0719 -4.79995
1.01562 -71.0719 -4.79995
0.9375 -71.0719 -4.79995
0.859375 -71.0719 -4.79995
0.78125 -71.0719 -4.79995
0.703125 -71.15 -4.79995
0.625 -71.15 -4.79995
0.546875 -71.15 -4.79995
0.46875 -71.15 -4.79995
0.390625 -71.15 -4.79995
0.3125 -71.15 -4.79995
0.234375 -71.15 -4.79995
0.15625 -71.15 -4.79995
0.078125 -71.15 -4.79995
0 -71.15 -4.79995
-0.078125 -71.15 -4.79995
-0.15625 -71.15 -4.79995
-0.234375 -71.15 -4.79995
-0.3125 -71.15 -4.79995
-0.390625 -71.15 -4.79995
-0.46875 -71.15 -4.79995
-0.546875 -71.15 -4.79995
-0.625 -71.15 -4.79995
-0.703125 -71.15 -4.79995
-0.78125 -71.15 -4.79995
-0.859375 -71.15 -4.79995
-0.9375 -71.15 -4.79995
-1.01562 -71.15 -4.79995
-1.09375 -71.0719 -4.79995
-1.17188 -71.0719 -4.79995
-1.25 -71.0719 -4.79995
-1.32812 -71.0719 -4.79995
-1.40625 -71.0719 -4.79995
-1.48438 -71.0719 -4.79995
-1.5625 -70.9938 -4.79995
-1.64062 -70.9938 -4.79995
-1.71875 -70.9938 -4.79995
-1.79688 -70.9938 -4.79995
-1.875 -70.9156 -4.79995
-1.95312 -70.9156 -4.79995
-2.03125 -70.9156 -4.79995
-2.10938 -70.9156 -4.79995
-2.1875 -70.8375 -4.79995
-2.26562 -70.8375 -4.79995
-2.34375 -70.8375 -4.79995
-2.42188 -70.7594 -4.79995
-2.5 -70.7594 -4.79995
-2.57812 -70.7594 -4.79995
-2.65625 -70.6813 -4.79995
-2.73438 -70.6813 -4.79995
-2.8125 -70.6031 -4.79995
-2.89062 -70.6031 -4.79995
-2.96875 -70.525 -4.79995
-3.04688 -70.525 -4.79995
-3.125 -70.4469 -4.79995
-3.20312 -70.4469 -4.79995
-3.28125 -70.3688 -4.79995
-3.35938 -70.3688 -4.79995
-3.4375 -70.2906 -4.79995
-3.51562 -70.2906 -4.79995
-3.59375 -70.2125 -4.79995
-3.67188 -70.1344 -4.79995
-3.75 -70.1344 -4.79995
-3.82812 -70.0563 -4.79995
-3.90625 -69.9781 -4.79995
-3.98438 -69.9781 -4.79995
-4.0625 -69.9 -4.79995
-4.14062 -69.8219 -4.79995
-4.21875 -69.7438 -4.79995
-4.29688 -69.7438 -4.79995
-4.375 -69.6656 -4.79995
-4.45312 -69.5875 -4.79995
-4.53125 -69.5094 -4.79995
-4.60938 -69.4313 -4.79995
-4.6875 -69.3531 -4.79995
-4.76562 -69.275 -4.79995
-4.84375 -69.1969 -4.79995
-4.92188 -69.1188 -4.79995
-5 -69.0406 -4.79995
-5.07812 -68.9625 -4.79995
-5.15625 -68.8844 -4.79995
-5.23438 -68.8063 -4.79995
-5.23438 -68.7281 -4.79995
-5.3125 -68.65 -4.79995
-5.39062 -68.5719 -4.79995
-5.46875 -68.4938 -4.79995
-5.46875 -68.4156 -4.79995
-5.54688 -68.3375 -4.79995
-5.625 -68.2594 -4.79995
-5.625
/*
 * readROI.cpp
 *
 *  Created on: 16 Aug 2010
 *      Author: mark
 */
#include"Includes.h"


void Usage(int numArgs, char *arguments[]);

int main(int argc, char *argv[]){

//	std::string planRoiInput;



	char *ptvString="_PTV",*oarString="_OAR";

	if ((argc!=2)&&(argc!=3)&&(argc!=4)) {
		Usage(argc,argv);
		exit(EXIT_FAILURE);

	}


	if (argc==3) {
		ptvString=argv[2];

	}
	else if (argc==4)
	{
		ptvString=argv[2];
		oarString=argv[3];

	}


	p3RoiFile p3R(argv[1],ptvString,oarString);



	return 0;
}

void Usage(int numArgs, char *arguments[]){

	std::cout << "\nUsage:\n";
	std::cout << "1) p3 plan.roi to read in (default=plan.roi) \n";
	std::cout << "2) PTV prefix string (default=\"_PTV\")\n";
	std::cout << "3) OAR prefix string (default=\"_OAR\")\n";

	std::cout << "\nUser provided " << numArgs -1 << " arguments.";

	for (int curArg=1;curArg!=numArgs;curArg++){
		std::cout << "\n"<< curArg << ") \"" << arguments[curArg] << "\"";
	}

}

Hello Mark

I have seen your code, and there is small error

file planROI.cpp, line 231

for (int curPoint;curPoint!=this->polygons.at(curPoly).polygonPoints.size();curPoint++)

variable curPoint is not initialized!

'std::out_of_range' means you are accessing an element of the vector that does not exist.

Here is my suggestion. If the input is working properly, then hardcode some values for the input. Then post the shortest compilable code that demonstrates the problem (hopefully < 20 lines). This makes it very easy for us to see what is going on (without having to download 5 files and look through a bunch of code that likely doesn't have anything to do with the problem).

David

Hello Mark

I have seen your code, and there is small error

file planROI.cpp, line 231

for (int curPoint;curPoint!=this->polygons.at(curPoly).polygonPoints.size();curPoint++)

variable curPoint is not initialized!

Many thanks Alex!! The same error crept in at line 252 too!

This article has been dead for over six months. Start a new discussion instead.