Problem with multiple indirection with nested classes

I am reading in data from a file consisting of a plurality of anatomical structures (10 < numStr < 50) defined by a number of contours (5 < numPlanes < 100), where each contour has a number of points (10 < numPoints[Plane j] < 400). To achieve this I have defined 3 classes: Point, Plane and Structure.

My problem arises when I try to write the data to file (to verify that it has been correctly read in).

Here is the Point class

1
2
3
4
5
6
7
8
class Point{
      public:
      int planeNum,pointNum,before,after;
        float x,y,z,r,x_0,y_0,distance; // r(z) is radius at point (x,y) in plane
        Point();
        Point (float x, float y, float z, float r); // insert float for radius
        ~Point();
};


... the Plane class ...

1
2
3
4
5
6
7
8
9
10
11
12
class Plane{
  	public:
  		friend class Point;
  		int numPoints;

  Point *pPoint;

  Plane();// Plane(CPP_Sequence *seqPlane, int numPoints);
  Plane(CPP_Sequence *seqPlane);
  ~Plane();

 };


and the Structure class...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Structure{
      public:
        friend class Plane;
      friend class Point;
      Point *pPoint;
      Plane **pPlane;
      int referenceNumber,numPlanes,controlPoints;


        string Name;

      Structure();
      Structure(CPP_Sequence *seq, int refNum);// constructor with structure of interest number (refNum)
      Structure(CPP_Sequence *seq);
      ~Structure();


The Plane constructor is called from within the Structure constructor for each plane j of Structure i. Each plane j calls the Point constructor for each point k in the contour. This works fine as I can write the data to the screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Plane::Plane(CPP_Sequence *seqPlane){

  CPP_Sequence *seqTemp3;

  char sBuff[32768];
  float minX,minY,maxX,maxY,midX,midY,deltaX,deltaY;
  int k;

  minX=minY=maxX=maxY=midX=midY=deltaX=deltaY=0.0f;

  Point *pPoint=NULL;



  seqPlane->item(0x30060042)->stringCopy(sBuff);

		numPoints=0;
		minX= maxX=minY= maxY=midX=midY=deltaX=deltaY=0.0f;

		if (strncmp(sBuff,"CLOSED_PLANAR",13)==0){
//			cout << "\n" << sBuff;
			numPoints=atoi(seqPlane->item(0x30060046)->stringCopy(sBuff));
//			cout << " Plane " <<  " contains " << numPoints << " points \n";
			pPoint = new Point[numPoints];
			if  (pPoint ==NULL){
			cout << "\nInsufficient memory for points\n";
			}

			cout << "Reading in " << numPoints << " points" << endl;
			seqPlane->item(0x30060050)->stringCopy(sBuff);

			for (k=0;k<numPoints;k++){

				if (k==0){
				pPoint[0].x = (float)atof(strtok(sBuff,"\\"));
				maxX = minX = pPoint[0].x;
				}


				else{
				pPoint[k].x = (float)atof(strtok(NULL,"\\"));
				}

				pPoint[k].y = (float)atof(strtok(NULL,"\\"));
				maxY = minY = pPoint[0].y;

				pPoint[k].z = (float)atof(strtok(NULL,"\\"));

				
			cout << "\nCoordinate " << k+1 << " is (" << pPoint[k].x << ", "<< pPoint[k].y << ", " << pPoint[k].z << ")";


			}

Here is a snippet from main in which I wish to write the point coordinates to file. I have tracked the problem down to line 19 below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ofstream fout(sBuff);

		cout << "\n\nWriting file \"" << sBuff << "\" for organ " << p->Name << endl;
		fout << "ROI Name = " << p->Name << endl;
		fout << "Reference Number = " << p->referenceNumber << endl << endl;

		fout << "Number of planes = " << p->numPlanes << endl << endl;

			cout << "Looping through planes ... \n";
			for (j=0;j<p->numPlanes; j++){

				fout << "\n\nPlane " << j+1 << " has " << p->pPlane[j]->numPoints << " points\n";
				fout << "k : ";

				for (k=0;k<p->pPlane[j]->numPoints;k++){

					fout << k+1 << " ";

					fout << "\n" << p->pPlane[j]->pPoint[k].x << endl;
				}
				fout << endl;
			}

The values of p->numPlanes and p->pPlane[j]->numPoints are correctly determined.
What is wrong with p->pPlane[j]->pPoint[k].x? I know that it has something to do with the . operator but am at a loss. Thanks for taking the time to read this.
Found offending line in code (line 11 of Plane::Plane(...) constructor above) and deleted it. It only took 7 hours to find...
Topic archived. No new replies allowed.