bobsta 0 Newbie Poster

Hi,

I use nested arrays of STL objects to generate a large number of objects (shapes representing projections of anatomical structures). I need to filter these into a tractable number based on certain properties that the objects possess: e.g. their geometric relationship to other objects and their functions (pair(int),order(int),left(bool))

A single arc objects contains a number of beams, at different viewing angles. Each beam object has a number of PTVOARPair objects representing the number of anatomical structures to be projected. Finally each PTVOARPair object contains a number of shapes derived by performing operations on the shapes of the projections of the anatomical structures.

extract from arc.cpp

if (!beams.empty())
			{
				if (this->isVMAT)
				{

					std::string aOutput=path;
					if (this->segmentOrders==3)
					{
					aOutput+="arcOutput0.arc";

					std::ofstream arcOutput(aOutput.c_str());

					arcOutput << this->zerothArcLeftSegments(arcOutput);

					arcOutput.close();
					aOutput.clear();
					}

					aOutput=path;
					aOutput+="arcOutput1.arc";
					std::ofstream arcOutput1(aOutput.c_str());
					if (arcOutput1.is_open())
					{
						// if writing three orders direction of subsequent arc must be reversed
						if (this->segmentOrders==3) arcOutput1 << this->firstArcLeftSegments(arcOutput1,true);
						else arcOutput1 << this->firstArcLeftSegments(arcOutput1,false);
						arcOutput1.close();
					}

					else if (!arcOutput1.is_open()) std::cerr << "\nCannot open file \"" << aOutput << "\"\n";
					aOutput.clear();

					aOutput=path;
					aOutput+="arcOutput2.arc";
					std::ofstream arcOutput2(aOutput.c_str());
					if (arcOutput2.is_open())
					{
						// if writing three orders direction of subsequent arc must be reversed
						if (this->segmentOrders==3) arcOutput2 << this->secondArcLeftSegments(arcOutput2,false);
						else arcOutput2 << this->secondArcLeftSegments(arcOutput2,true);
						arcOutput2.close();
					}
					else if (!arcOutput2.is_open()) std::cerr << "\nCannot open file \"" << aOutput << "\"\n";

				}

extract from beam.cpp

std::ostream & Beam::writePairOrder(std::ostream &out, int pair, int order, bool left)
{

	if (order==0)
	{
		for (int curCP=0;curCP!=this->structurePairs.at(pair).zerothSegments.size();curCP++)
		{
			if (this->structurePairs.at(pair).zerothSegments.at(curCP).isSet)
			{
			// NB std::ostream & operator << (std::ostream &, dicomCP &) checks whether dicomCP.isSet==true, iff true then returns out << CP, else false returns: out << "";
			out << this->structurePairs.at(pair).zerothSegments.at(curCP);
			break;
			}

		}
	}



	else if (order==1)
	{
		// if left ==true, write left segments
		if(left) out << this->structurePairs.at(pair).firstOrderLeft(out) << "\n";
		else if (!left) out << this->structurePairs.at(pair).firstOrderRight(out) << "\n";

	}

	else if (order==2)
	{
		// if left == true, write left segments
		if(left) out << this->structurePairs.at(pair).secondOrderLeft(out) << "\n";
		// else if left== false, write right segments
		else if (!left) out << this->structurePairs.at(pair).secondOrderRight(out) << "\n";

	}

	return out;

}

extract from PTVOARPair.cpp

std::ostream & PTVOARPair::firstOrderLeft(std::ostream &out)
{
	for (int curCP=0;curCP!=this->firstSegments.size();curCP++)
	{
//		if (firstSegments.at(curCP).isLeft) out << firstSegments.at(curCP).writeLeftSegment(out);
		if (firstSegments.at(curCP).isLeft) out << firstSegments.at(curCP);

		break;
	}
	return out;
}

std::ostream & PTVOARPair::firstOrderRight(std::ostream &out)
{
	for (int curCP=0;curCP!=this->firstSegments.size();curCP++)
	{

		if (firstSegments.at(curCP).isRight) out << firstSegments.at(curCP);

		break;
	}
	return out;
}

std::ostream & PTVOARPair::secondOrderLeft(std::ostream &out)
{
	for (int curCP=0;curCP!=this->secondSegments.size();curCP++)
	{

		if(secondSegments.at(curCP).isLeft) out << secondSegments.at(curCP);

		break;
	}
	return out;
}

std::ostream & PTVOARPair::secondOrderRight(std::ostream &out)
{
	for (int curCP=0;curCP!=this->secondSegments.size();curCP++)
	{

		if(secondSegments.at(curCP).isRight) out << secondSegments.at(curCP);
		break;
	}
	return out;
}

extract from dicomCP.cpp

std::ostream & operator << (std::ostream &out, dicomCP &cp)
{
	int currentCP=0;
	if (!cp.isSet)
	{

		out.clear();
		return out;
	}


	// only write those cps which are set and whose area >2.0 cm2 / numOpenLeafPairs >=3 see also Mask::sequenceMaskToMLCs



	else if (cp.isSet)
	{
	out << "#CP " << currentCP << "\t openLeafPairs = " << cp.getOpenLeafPairs() << "#\n";

	if (cp.twoStepOrder==0) out << "#Zeroth order: Area = " << cp.getCPArea() << "mm2#\n";
	else if (cp.twoStepOrder==1) out << "#First order : Area = " << cp.getCPArea();
	else if (cp.twoStepOrder==2) out << "#Second order : Area = " << cp.getCPArea();
	else;

	if ((cp.twoStepOrder>0)&&(cp.isLeft)) out << "mm2, left = " << cp.isLeft << "#\n";

	else if ((cp.twoStepOrder>0)&&(cp.isRight)) out << "mm2, right = " << cp.isRight << "#\n";

	out << "#Gantry#\n" << cp.gantry << "\n";
	out << "#Collimator#\n" << cp.collimator << "\n";
	out << "#Couch#\n" << cp.couch << "\n";

	out << "#Dose rate#\n" << cp.doseRate << "\n";

	out << "#Weight (MU_i/CumulativeMeterSet)#\n";

	out << cp.MUs << "\n";

	out << "#Leaf positions#\n";

	for (int curBeamlet=0;curBeamlet!=cp.beamlets.size();curBeamlet++)
	{


		out << cp.beamlets.at(curBeamlet) << "\n";
	}
	currentCP++;

	}
	return out;

}

The code compiles and runs but persists in printing out pointer addresses, which I suspect are to the ofstream objects (since within each file written the same pointer address appears, but different files have different addresses).

Is it possible that by using member functions in combination with ostream objects that the problem occurs? Any suggestions would be appreciated

M