int POLYGON::Stitch( bool isCCW, POLYGON& aPolygon, TRANSFORM& aTransform, VRMLMAT& aMaterial, bool reuseMaterial, std::ofstream& aVRMLFile, int aTabDepth ) { int i, j, k; if( !valid ) { ERRBLURB; cerr << "invoked without prior invocation of Calc()\n"; return -1; } if( nv < 3 ) { ERRBLURB; cerr << "invalid number of vertices (" << nv << "); range is 3 .. 360\n"; return -1; } double* r2x = NULL; double* r2y = NULL; double* r2z = NULL; int rv = aPolygon.GetVertices( &r2x, &r2y, &r2z ); if( rv != nv ) { ERRBLURB; cerr << "points in second ring (" << rv << ") do not match points in this ring (" << nv << ")\n"; return -1; } if( aTabDepth < 0 ) aTabDepth = 0; if( aTabDepth > 4 ) aTabDepth = 4; double* lx; double* ly; double* lz; // allocate memory lx = new double[nv * 2]; if( lx == NULL ) { ERRBLURB; cerr << "could not allocate points for intermediate calculations\n"; return -1; } ly = new double[nv * 2]; if( ly == NULL ) { ERRBLURB; cerr << "could not allocate points for intermediate calculations\n"; delete [] lx; return -1; } lz = new double[nv * 2]; if( lz == NULL ) { ERRBLURB; cerr << "could not allocate points for intermediate calculations\n"; delete [] lx; delete [] ly; return -1; } for( i = 0; i < nv; ++i ) { lx[i] = x[i]; ly[i] = y[i]; lz[i] = z[i]; lx[i + nv] = r2x[i]; ly[i + nv] = r2y[i]; lz[i + nv] = r2z[i]; } // perform transforms aTransform.Transform( lx, ly, lz, nv * 2 ); // set up VRML Shape SetupShape( aMaterial, reuseMaterial, aVRMLFile, aTabDepth ); // enumerate vertices WriteCoord( lx, ly, lz, nv * 2, aVRMLFile, aTabDepth + 1 ); // enumerate facets SetupCoordIndex( aVRMLFile, aTabDepth + 1 ); string fmt( (aTabDepth + 1) * 4, ' ' ); aVRMLFile << fmt << " "; if( isCCW ) k = 1; else k = -1; for( i = 0; i < nv - 1; ++i ) { j = i + k; if( j >= nv ) j -= nv; if( j < 0 ) j += nv; aVRMLFile << " " << i << "," << j << "," << j + nv << "," << i + nv << ",-1,"; if( !( (i + 1) % 4 ) ) aVRMLFile << "\n" << fmt << " "; } j = i + k; if( j >= nv ) j -= nv; if( j < 0 ) j += nv; aVRMLFile << " " << i << "," << j << "," << j + nv << "," << i + nv << ",-1\n"; CloseCoordIndex( aVRMLFile, aTabDepth + 1 ); delete [] lx; delete [] ly; delete [] lz; return CloseShape( aVRMLFile, aTabDepth ); }