void CountRelief(int interior, int *nb_vert, int *nb_seg) { tLine *curLine; tRingListHead *curHead; *nb_vert = *nb_seg = 0; if (Root == NULL) { return; } if (interior) { curHead = &InteriorList; } else { curHead = &ExteriorList; } curLine = GF_TAILQ_FIRST(curHead); while (curLine != NULL) { ssgBranch *br = curLine->branch->getParent(0); ssgBranch *br2 = new ssgBranch(); br2->addKid(br); ssgFlatten(br); curLine->branch = br2; countRec((ssgEntity *)curLine->branch, nb_vert, nb_seg); curLine = GF_TAILQ_NEXT(curLine, link); } }
static void countRec(ssgEntity *e, int *nb_vert, int *nb_seg) { if (e->isAKindOf(_SSG_TYPE_BRANCH)) { ssgBranch *br = (ssgBranch *)e; for (int i = 0; i < br->getNumKids(); i++) { countRec(br->getKid(i), nb_vert, nb_seg); } } else { if (e->isAKindOf(_SSG_TYPE_VTXTABLE)) { ssgVtxTable *vt = (ssgVtxTable *)e; *nb_vert += vt->getNumVertices(); *nb_seg += vt->getNumLines(); } } }
int main(int argc, char **argv) { cwp_String prefix=NULL; /* Common prefix to build the SPS filenames. */ cwp_String Rname=NULL; /* file name for R file */ int numR=0; /* number of receiver points */ FILE *fpR=NULL; /* file pointer for R file */ cwp_String Sname=NULL; /* file name for S file */ FILE *fpS=NULL; /* file pointer for S file */ int numS=0; /* number of source points */ cwp_String Xname=NULL; /* file name for X file */ FILE *fpX=NULL; /* file pointer for X file */ int numX=0; /* number of relation points entries */ /* WARNING: a record can have more than */ /* one relation entry. E.g. 3D*/ int rev; /* SPS revision to process */ int RC; /* Return code from functions */ int i; /* Just the "i". */ float scalco; /* scale factor */ float scalel; /* scale factor */ float temp; /* temporary float value */ double Xcdp; /* CDP X Coordinate */ double Ycdp; /* CDP Y Coordinate */ float ibin; /* Inline bin size/cdp interval */ //float xbin; /* Xline bin size/ Not used */ float dt; /* sample spacing - I don't need, just check */ //int nt; /* number of points on input trace */ cwp_Bool seismic; /* is this seismic data? */ // File control int oldfldr; // fldr for last trace processed int oldskip; // still skipping the same fldr? int curx; // relation entry control int curtrl; // keeping track of current trace (in case of skip) int idxR; // Index of receiver station entry int idxS; // Index of shot point entry float recsta; // receiver station //float srcsta; // source point station int nproct = 0; // number of processed traces //int nprocf = 0; // number of processed files /* Initialize */ initargs(argc, argv); requestdoc(1); /* Verbose run? */ if (!getparint("verbose", &verbose)) verbose=0; /* get SPS revision to process */ if (!getparint("rev", &rev)) rev=2; /* get inline bin interval */ if (!getparfloat("ibin", &ibin)) ibin=0.; /* lets prepare the geometry informations */ /* ========================================== */ /* Lets try to get common prefix. =========== */ /* ========================================== */ getparstring("prefix", &prefix); // if ( prefix == NULL ) Who cares? /* ========================================== */ /* Receiver points information ============== */ /* ========================================== */ getparstring("rps", &Rname); if ( Rname == NULL ) { if ( prefix == NULL ) err("**** Missing required parameter 'rps=', see self-doc"); // I have a prefix and need build this file name. Rname = calloc(strlen(prefix)+2,sizeof(cwp_String)); if ( Rname == NULL ) err("**** Unable to allocate memory for R-File name."); strcpy(Rname,prefix); strcat(Rname,".r"); } if (verbose) warn("Receiver file: %s",Rname); fpR = efopen(Rname, "r"); if ( fpR == NULL ) err("**** Error opening the receiver information file"); numR = countRec(fpR, 'R'); warn("Found %d receiver points entries.",numR); if ( numR == 0 ) err("**** No receiver point information found!!"); // Allocate area for the receiver informations // calloc zero out memory. RecInfo = calloc(numR,sizeof(struct PointInfo)); if ( RecInfo == NULL ){ err("**** Unable to allocate memory for Receiver Point Informations!!"); } // Get all Receiver Points info into memory RC = getPoints(fpR, 'R', rev, RecInfo); if ( RC != numR) { warn("Short read for Receiver Point Informations!"); warn("Read %d receiver points entries instead of expected%d.",RC,numR); } if (verbose) { warn("Stored: %d Receiver Point Informations.",RC); for (i=0; i<RC; i++) warn("R %10.2f,%10.2f,%4.1f,%10.2lf,%10.2lf,%5.1f", RecInfo[i].Line, RecInfo[i].Point, RecInfo[i].PDepth, RecInfo[i].X, RecInfo[i].Y, RecInfo[i].Elev); } /* ========================================== */ /* Source points information ================ */ /* ========================================== */ getparstring("sps", &Sname); if ( Sname == NULL ) { if ( prefix == NULL ) err("**** Missing required parameter 'sps=', see self-doc"); // I have a prefix and need build this file name. Sname = calloc(strlen(prefix)+2,sizeof(cwp_String)); if ( Sname == NULL ) err("**** Unable to allocate memory for S-File name."); strcpy(Sname,prefix); strcat(Sname,".s"); } if (verbose) warn("Source file: %s",Sname); fpS = efopen(Sname, "r"); if ( fpS == NULL ) err("**** Error opening the source information file"); numS = countRec(fpS, 'S'); warn("Found %d source points entries.",numS); if ( numS == 0 ) err("**** No source point information found!!"); // Allocate area for the Source informations // calloc zero out memory. SrcInfo = calloc(numS,sizeof(struct PointInfo)); if ( SrcInfo == NULL ){ err("**** Unable to allocate memory for Source Point Informations!!"); } // Get all Source Point info into memory RC = getPoints(fpS, 'S', rev, SrcInfo); if ( RC != numS) { warn("Short read for Source Point Informations!"); warn("Read %d source point entries instead of expected%d.",RC,numS); } if (verbose) { warn("Stored: %d Source Point Informations.",RC); for (i=0; i<RC; i++) warn("S %10.2f,%10.2f,%4.1f,%10.2lf,%10.2lf,%5.1f", SrcInfo[i].Line, SrcInfo[i].Point, SrcInfo[i].PDepth, SrcInfo[i].X, SrcInfo[i].Y, SrcInfo[i].Elev); } /* ------------------------------------------ */ /* ========================================== */ /* Relation (records) information =========== */ /* ========================================== */ getparstring("xps", &Xname); if ( Xname == NULL ) { if ( prefix == NULL ) err("**** Missing required parameter 'xps=', see self-doc"); // I have a prefix and need build this file name. Xname = calloc(strlen(prefix)+2,sizeof(cwp_String)); if ( Xname == NULL ) err("**** Unable to allocate memory for X-File name."); strcpy(Xname,prefix); strcat(Xname,".x"); } if (verbose) warn("Relation file: %s",Xname); fpX = efopen(Xname, "r"); if ( fpX == NULL ) err("**** Error opening the relation information file"); numX = countRec(fpX, 'X'); warn("Found %d relation information entries.",numX); if ( numX == 0 ) err("**** No relation information found!!"); // Allocate area for the Register informations // calloc zero out memory. FileInfo = calloc(numX,sizeof(struct RegInfo)); if ( FileInfo == NULL ){ err("**** Unable to allocate memory for Registers Informations!!"); } // Get all Record info into memory RC = getFiles(fpX, rev, FileInfo); if ( RC != numX) { warn("Short read for File Informations!"); warn("Read %d file entries instead of expected%d.",RC,numX); } if (verbose) { warn("Stored: %d Register Information entries.",RC); for (i=0; i<RC; i++) warn("X %4d,%1d,%9.1f,%9.1f,%4d,%4d,%1d,%9.1f,%9.1f,%10.1f,%1d", FileInfo[i].Num, FileInfo[i].Inc, FileInfo[i].SLine, FileInfo[i].SPoint, FileInfo[i].FChan, FileInfo[i].TChan, FileInfo[i].IncChan, FileInfo[i].RLine, FileInfo[i].FRecv, FileInfo[i].TRecv, FileInfo[i].RInc); } /* ------------------------------------------ */ /* ========================================== */ /* ========================================== */ /* ========================================== */ /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); seismic = ISSEISMIC(tr.trid); if (seismic) { if (verbose) warn("input is seismic data, trid=%d",tr.trid); // dt = ((double) tr.dt)/1000000.0; // Don't use dt } else { if (verbose) warn("input is not seismic data, trid=%d",tr.trid); // dt = tr.d1; // Don't use dt } /* error trapping so that the user can have a default value of dt */ if (!(dt || getparfloat("dt", &dt))) { // dt = .004; // Don't use dt warn("WARNING: neither dt nor d1 are set, nor is dt getparred!"); warn("WARNING: It is not used, just checked!!"); } //nt = tr.ns; oldfldr = 0; // fldr for last trace processed oldskip = 0; // still skipping the same fldr? curx = -1; // relation entry control curtrl = 0; // keeping tracl of current trace (in case of skip) /* ------------------------------------------ */ /* ========================================== */ /* ====== Main loop over traces =========== */ /* ========================================== */ do { if (tr.fldr != oldfldr) { // Ok, we have a new fldr. // Advance relation entry? if (curx+1 < numX && tr.fldr == FileInfo[curx+1].Num) { curx++; if ( curx == numX ) break; // No more relation available. // fprintf(stderr,"==> 1-curx %d\n",curx); // Debug // Process this one if ( verbose ) warn("** processing fldr=%d",tr.fldr); oldfldr = tr.fldr; //fprintf(stderr,"==> New file %d: %d\n",curx,tr.fldr); // Debug } else { // skip until the next file is found if ( tr.fldr != oldskip ) { // Skipping new fldr! if ( curx+1 == numX) { curx++; break; // No more relation available } warn("** skipping fldr=%d, looking for %d", tr.fldr,FileInfo[curx+1].Num); oldskip = tr.fldr; } continue; } } // (tr.fldr != oldfldr) // Ok, we are processing current fldr // Is this channel within range? if ( tr.tracf < FileInfo[curx].FChan ) { // skip this one warn("** skipping fldr=%d, tracf=%d, looking for tracf=%d ", tr.fldr,tr.tracf,FileInfo[curx].FChan); continue; } else if ( tr.tracf > FileInfo[curx].TChan ) { // <FIXME> still unsure if ( curx+1 == numX) { // Is there any more relation info? curx++; // Signal the end of table break; // Exit, no more relation available } if ( tr.fldr == FileInfo[curx+1].Num ) { // Is there more info? do { // Advance the register info curx++; if ( tr.tracf >= FileInfo[curx].FChan && // If chan ok, tr.tracf <= FileInfo[curx].TChan) { // exit loop break; // Found it } } while (tr.fldr == FileInfo[curx+1].Num); // Why did I get here? // do we have a new fldr? if ( tr.tracf < FileInfo[curx].FChan || tr.tracf > FileInfo[curx].TChan) { // Ok, we have a new fldr. // skip this trace, look for a new file continue; } } } // Ok, seems that we are good to process this one. // Lets update the header // We will keep fldr and trcf untoutched // But will update tracl curtrl++; tr.tracl = curtrl; if ( tr.ep == 0 ) // Only if zeroed out, keep otherwise tr.ep = FileInfo[curx].SPoint; // No fractionary sp so far. tr.cdp = 0; // not updating it yet // This computes the receiver station // <FIXME> Not sure if this use of IncChan is correct. :( // It should group each IncChan channels in a single station // for multicomponent data. recsta = FileInfo[curx].FRecv + (FileInfo[curx].TRecv-FileInfo[curx].FRecv) * ((tr.tracf-FileInfo[curx].FChan)/FileInfo[curx].IncChan)/ (FileInfo[curx].TChan-FileInfo[curx].FChan); // Get the index of the point at corresponding point structure idxR = GetPointIndex(RecInfo, numR, recsta,FileInfo[curx].RLine); idxS = GetPointIndex(SrcInfo, numS, FileInfo[curx].SPoint, FileInfo[curx].SLine); // <FIXME> - Take care for information not available! // if ( idx[[R|S] < 0 ) { failed! Skip trace/file! } // Avoid division by zero. if ( tr.scalel == 0 ) tr.scalel = 1; if ( tr.scalco == 0 ) tr.scalco = 1; // The scale factor scalel = 1./tr.scalel; scalco = 1./tr.scalco; if ( tr.scalel < 0 ) scalel = -tr.scalel; if ( tr.scalco < 0 ) scalco = -tr.scalco; // Source coordinates tr.sx = SrcInfo[idxS].X * scalco; tr.sy = SrcInfo[idxS].Y * scalco; // Receiver coordinates tr.gx = RecInfo[idxR].X * scalco; tr.gy = RecInfo[idxR].Y * scalco; if ( ibin != 0 ) { // compute CDP number // CDP Position (where to store?) Xcdp = (RecInfo[idxR].X+SrcInfo[idxS].X)/2.; Ycdp = (RecInfo[idxR].Y+SrcInfo[idxS].Y)/2.; // First try for cdp computation. // (may work for 2D straight lines) // temp = sqrt(pow(Xcdp-RecInfo[0].X,2) + pow(Ycdp-RecInfo[0].Y,2)); tr.cdp = 100.5 + temp / ibin; // 100 is just arbitrary // .5 if for rounding :P // Debug: print cdp# Xcdp Ycdp //fprintf(stderr,"cdp %5d %10.2f %10.2f\n",tr.cdp,Xcdp,Ycdp); } // Elevations tr.gelev = RecInfo[idxR].Elev * scalel; tr.selev = SrcInfo[idxS].Elev * scalel; tr.sdepth = SrcInfo[idxS].PDepth * scalel; // Offset - The offset signal is just an educated guess. :/ tr.offset = sqrt(pow(SrcInfo[idxS].X-RecInfo[idxR].X,2) + pow(SrcInfo[idxS].Y-RecInfo[idxR].Y,2)); if ( SrcInfo[idxS].Point > RecInfo[idxR].Point ) tr.offset = -tr.offset; // Assuming all coordinates in UTM projection tr.counit = 1; tr.sstat = SrcInfo[idxS].StaCor; tr.gstat = RecInfo[idxR].StaCor; puttr(&tr); nproct++; // count processed traces } while (gettr(&tr)); /* ========================================== */ /* ========= End of Main loop ============== */ /* ========================================== */ /* ------------------------------------------ */ if ( curx >= numX ) { warn("*** Last record processed -> fldr %d ***",oldfldr); warn("*** Records after this were discarded ***"); } warn("*** %d traces processed...",nproct); return(CWP_Exit()); }