From 05feae0692243293baac74ee38aa54a0eb52891e Mon Sep 17 00:00:00 2001 From: William Joye Date: Sat, 16 Mar 2019 13:38:10 -0400 Subject: thread contour --- tksao/frame/context.C | 62 ++++++++++++++++----- tksao/frame/fitsanalysis.C | 12 ++++- tksao/frame/fitsimage.h | 12 +++++ tksao/frame/fvcontour.C | 131 +++++++++++++++++++++++++++++---------------- tksao/frame/fvcontour.h | 20 +++++-- tksao/util/convolve.C | 8 --- tksao/util/convolve.h | 13 ----- 7 files changed, 173 insertions(+), 85 deletions(-) diff --git a/tksao/frame/context.C b/tksao/frame/context.C index 4fe3245..0fed0ac 100644 --- a/tksao/frame/context.C +++ b/tksao/frame/context.C @@ -116,7 +116,7 @@ void Context::analysis() if (thread_) delete [] thread_; thread_ = new pthread_t[parent_->nthreads_]; - t_convolve_arg* targ = new t_convolve_arg[parent_->nthreads_]; + t_smooth_arg* targ = new t_smooth_arg[parent_->nthreads_]; int cnt =0; FitsImage* ptr = fits; @@ -382,21 +382,59 @@ void Context::contourCreateFV(const char* color, int width, int dash, fr.setLow(low); fr.setHigh(high); - if (!isMosaic()) { - if (cfits) - fvcontour_.create(parent_, cfits, &fr, color, width, dash, method, numlevel, smooth, level); - } - else { - if (fits) { - fvcontour_.create(parent_, fits, &fr, color, width, dash, method, numlevel, smooth, level); + FitsImage* ptr = isMosaic() ? fits : cfits; + if (!ptr) + return; + + if (thread_) + delete [] thread_; + thread_ = new pthread_t[parent_->nthreads_]; + t_fvcontour_arg* targ = new t_fvcontour_arg[parent_->nthreads_]; + + fvcontour_.create(parent_, ptr, &fr, + color, width, dash, method, numlevel, smooth, level); + int cnt =0; + while (ptr) { + fvcontour_.append(ptr, &thread_[cnt], &targ[cnt]); + /* + cnt++; + if (cnt == parent_->nthreads_) { + for (int ii=0; iinextMosaic(); - while (ptr) { - fvcontour_.append(ptr); - ptr = ptr->nextMosaic(); + if (targ[ii].kernel) + delete [] targ[ii].kernel; + if (targ[ii].src) + delete [] targ[ii].src; + if (targ[ii].dest) + delete [] targ[ii].dest; } + cnt =0; } + */ + ptr = ptr->nextMosaic(); + } + + /* + for (int ii=0; iikernel, tt->src, tt->dest, + tt->xmin, tt->ymin, tt->xmax, tt->ymax, tt->width, tt->r); + return NULL; +} + void FitsImage::smooth(pthread_t* thread, void* targ) { FitsBound* params = getDataParams(context_->secMode()); @@ -78,7 +86,7 @@ void FitsImage::smooth(pthread_t* thread, void* targ) } // convolve - t_convolve_arg* tt = (t_convolve_arg*)targ; + t_smooth_arg* tt = (t_smooth_arg*)targ; tt->kernel = kernel; tt->src = src; tt->dest = dest; @@ -89,7 +97,7 @@ void FitsImage::smooth(pthread_t* thread, void* targ) tt->width = width; tt->r = context_->smoothRadius(); - int result = pthread_create(thread, NULL, convolveThread, targ); + int result = pthread_create(thread, NULL, smoothThread, targ); if (result) internalError("Unable to Create Thread"); } diff --git a/tksao/frame/fitsimage.h b/tksao/frame/fitsimage.h index 76680c3..82b8f6e 100644 --- a/tksao/frame/fitsimage.h +++ b/tksao/frame/fitsimage.h @@ -18,6 +18,18 @@ #define MULTWCSA 28 typedef struct { + double* kernel; + double* src; + double* dest; + int xmin; + int ymin; + int xmax; + int ymax; + int width; + int r; +} t_smooth_arg; + +typedef struct { FitsFile* base; FitsData* basedata; FitsFile* block; diff --git a/tksao/frame/fvcontour.C b/tksao/frame/fvcontour.C index 1c980df..218b16e 100644 --- a/tksao/frame/fvcontour.C +++ b/tksao/frame/fvcontour.C @@ -20,6 +20,17 @@ static const char* methodName_[] = { "block" }; +enum Edge {TOP, RIGHT, BOTTOM, LEFT, NONE}; + +static void build(long xdim, long ydim, double *image, Matrix& mx, + Base* parent, List* lcontourlevel, + InverseScale* scale, + char* colorName, int lineWidth, int dash, int* dlist); +static void trace(long xdim, long ydim, double cntr, + long xCell, long yCell, int side, + double** rows, char* usedGrid, + Matrix& mx, ContourLevel* cl); + // It is a modified version of contour code found in Fv 2.4 // Fv may be obtained from the HEASARC (High Energy Astrophysics Science // Archive Research Center) FTOOLS Web site at: @@ -91,8 +102,6 @@ void FVContour::create(Base* pp, FitsImage* fits, FrScale* fr, } else buildScale(fits); - - append(fits); } void FVContour::buildScale(FitsImage* fits) @@ -151,7 +160,7 @@ void FVContour::update(FitsImage* fits) break; } - append(fits); + // append(fits); } const char* FVContour::methodName() @@ -159,14 +168,14 @@ const char* FVContour::methodName() return methodName_[method_]; } -void FVContour::append(FitsImage* fits) +void FVContour::append(FitsImage* fits, pthread_t* thread, void* targ) { if (smooth_ == 1) unity(fits); else switch (method_) { case SMOOTH: - nobin(fits); + nobin(fits, thread, targ); break; case BLOCK: bin(fits); @@ -205,11 +214,12 @@ void FVContour::unity(FitsImage* fits) CLEARSIGBUS // contours - build(width, height, img, fits->dataToRef); + build(width, height, img, fits->dataToRef, parent_, &lcontourlevel_, scale_, + colorName_, lineWidth_, dash_, dlist_); delete [] img; } -void FVContour::nobin(FitsImage* fits) +void FVContour::nobin(FitsImage* fits, pthread_t* thread, void* targ) { FitsBound* params = fits->getDataParams(((Base*)parent_)->currentContext->secMode()); @@ -250,17 +260,42 @@ void FVContour::nobin(FitsImage* fits) } CLEARSIGBUS - ::convolve(kernel, src, img, - params->xmin, params->ymin, params->xmax, params->ymax, - width, r); + // convolve + t_fvcontour_arg* tt = (t_fvcontour_arg*)targ; + tt->kernel = kernel; + tt->src = src; + tt->dest = img; + tt->xmin = params->xmin; + tt->xmax = params->xmax; + tt->ymin = params->ymin; + tt->ymax = params->ymax; + tt->width = width; + tt->r = r; + + // int result = pthread_create(thread, NULL, FVContourThread, targ); + // if (result) + // internalError("Unable to Create Thread"); + + convolve(tt->kernel, tt->src, tt->dest, + tt->xmin, tt->ymin, tt->xmax, tt->ymax, + tt->width, tt->r); + build(width, height, img, fits->dataToRef, parent_, &lcontourlevel_, scale_, + colorName_, lineWidth_, dash_, dlist_); + delete [] src; - delete [] kernel; - - // contours - build(width, height, img, fits->dataToRef); delete [] img; + delete [] kernel; } +/* +void* fvcontourThread(void*vv) +{ + t_fvcontour_arg* tt = (t_fvcontour_arg*)vv; + convolve(tt->kernel, tt->src, tt->dest, + tt->xmin, tt->ymin, tt->xmax, tt->ymax, tt->width, tt->r); + return NULL; +} +*/ void FVContour::bin(FitsImage* fits) { FitsBound* params = @@ -320,11 +355,16 @@ void FVContour::bin(FitsImage* fits) // contours Matrix w = n * fits->dataToRef; - build(w2, h2, img, w); + build(w2, h2, img, w, + parent_, &lcontourlevel_, scale_, + colorName_, lineWidth_, dash_, dlist_); delete [] img; } -void FVContour::build(long xdim, long ydim, double *image, Matrix& mx) +void build(long xdim, long ydim, double *image, Matrix& mx, + Base* parent, List* lcontourlevel, + InverseScale* scale, + char* colorName, int lineWidth, int dash, int* dlist) { long nelem = xdim*ydim; char* usedGrid = new char[nelem]; @@ -333,11 +373,11 @@ void FVContour::build(long xdim, long ydim, double *image, Matrix& mx) for (long jj=0; jjsize(); c++) { - double cntour = scale_->level(c); + for (long c=0; csize(); c++) { + double cntour = scale->level(c); - ContourLevel* cl =new ContourLevel(parent_, cntour, colorName_, lineWidth_, - dash_, dlist_); + ContourLevel* cl =new ContourLevel(parent, cntour, colorName, lineWidth, + dash, dlist); memset(usedGrid,0,nelem); // Search outer edge @@ -346,22 +386,22 @@ void FVContour::build(long xdim, long ydim, double *image, Matrix& mx) // Search top for (jj=0, ii=0; ii=0; ii--) if (rows[jj][ii+1]=0; jj--) if (rows[jj+1][ii]lcontour().isEmpty()) - lcontourlevel_.append(cl); + lcontourlevel->append(cl); } delete [] usedGrid; delete [] rows; } -void FVContour::trace(long xdim, long ydim, double cntr, - long xCell, long yCell, int side, - double** rows, char* usedGrid, - Matrix& mx, ContourLevel* cl) +void trace(long xdim, long ydim, double cntr, + long xCell, long yCell, int side, + double** rows, char* usedGrid, + Matrix& mx, ContourLevel* cl) { long ii = xCell; long jj = yCell; @@ -404,19 +444,19 @@ void FVContour::trace(long xdim, long ydim, double cntr, if (init) { init = 0; switch (side) { - case top: + case TOP: X = (cntr-a) / (b-a) + ii; Y = jj; break; - case right: + case RIGHT: X = ii+1; Y = (cntr-b) / (c-b) + jj; break; - case bottom: + case BOTTOM: X = (cntr-c) / (d-c) + ii; Y = jj+1; break; - case left: + case LEFT: X = ii; Y = (cntr-a) / (d-a) + jj; break; @@ -424,15 +464,15 @@ void FVContour::trace(long xdim, long ydim, double cntr, } else { - if (side==top) + if (side==TOP) usedGrid[jj*xdim + ii] = 1; do { - if (++side == none) - side = top; + if (++side == NONE) + side = TOP; switch (side) { - case top: + case TOP: if (a>=cntr && cntr>b) { flag = 1; X = (cntr-a) / (b-a) + ii; @@ -440,7 +480,7 @@ void FVContour::trace(long xdim, long ydim, double cntr, jj--; } break; - case right: + case RIGHT: if( b>=cntr && cntr>c ) { flag = 1; X = ii+1; @@ -448,7 +488,7 @@ void FVContour::trace(long xdim, long ydim, double cntr, ii++; } break; - case bottom: + case BOTTOM: if( c>=cntr && cntr>d ) { flag = 1; X = (cntr-d) / (c-d) + ii; @@ -456,7 +496,7 @@ void FVContour::trace(long xdim, long ydim, double cntr, jj++; } break; - case left: + case LEFT: if( d>=cntr && cntr>a ) { flag = 1; X = ii; @@ -467,10 +507,10 @@ void FVContour::trace(long xdim, long ydim, double cntr, } } while (!flag); - if (++side == none) - side = top; - if (++side == none) - side = top; + if (++side == NONE) + side = TOP; + if (++side == NONE) + side = TOP; if (ii==xCell && jj==yCell && side==origSide) done = 1; if (ii<0 || ii>=xdim-1 || jj<0 || jj>=ydim-1) @@ -485,4 +525,3 @@ void FVContour::trace(long xdim, long ydim, double cntr, else delete cc; } - diff --git a/tksao/frame/fvcontour.h b/tksao/frame/fvcontour.h index 79f4384..ed8b879 100644 --- a/tksao/frame/fvcontour.h +++ b/tksao/frame/fvcontour.h @@ -10,13 +10,23 @@ #include "frscale.h" #include "inversescale.h" +typedef struct { + double* kernel; + double* src; + double* dest; + int xmin; + int ymin; + int xmax; + int ymax; + int width; + int r; +} t_fvcontour_arg; + class FVContour { public: enum Method {SMOOTH, BLOCK}; private: - enum {top, right, bottom, left, none}; - Base* parent_; List lcontourlevel_; @@ -37,11 +47,13 @@ class FVContour { void buildScale(FitsImage* fits); void unity(FitsImage*); void bin(FitsImage*); - void nobin(FitsImage*); + void nobin(FitsImage*, pthread_t* thread, void* targ); + /* void build(long xdim, long ydim, double *image, Matrix&); void trace(long xdim, long ydim, double cntr, long xCell, long yCell, int side, double** rows, char* useGrid, Matrix&, ContourLevel*); + */ public: FVContour(); @@ -56,7 +68,7 @@ public: void update(FitsImage*); void update(FitsImage*, FrScale*); - void append(FitsImage*); + void append(FitsImage*, pthread_t* thread, void* targ); int isEmpty() {return lcontourlevel_.isEmpty();} diff --git a/tksao/util/convolve.C b/tksao/util/convolve.C index 4ba83fa..d09a69e 100644 --- a/tksao/util/convolve.C +++ b/tksao/util/convolve.C @@ -83,14 +83,6 @@ double* gaussian(int k, double ss) return kernel; } -void* convolveThread(void* vv) -{ - t_convolve_arg* tt = (t_convolve_arg*)vv; - convolve(tt->kernel, tt->src, tt->dest, - tt->xmin, tt->ymin, tt->xmax, tt->ymax, tt->width, tt->r); - return NULL; -} - double* elliptic(int k, int rm, double ss, double sm, double aa) { int kk = 2*k+1; diff --git a/tksao/util/convolve.h b/tksao/util/convolve.h index d8d240c..637cf97 100644 --- a/tksao/util/convolve.h +++ b/tksao/util/convolve.h @@ -5,24 +5,11 @@ #ifndef __convolve_h__ #define __convolve_h__ -typedef struct { - double* kernel; - double* src; - double* dest; - int xmin; - int ymin; - int xmax; - int ymax; - int width; - int r; -} t_convolve_arg; - double* boxcar(int r); double* tophat(int r); double* gaussian(int r, double sigma); double* elliptic(int r, int m, double ss, double sm, double aa); -void* convolveThread(void* vv); void* convolve(double* kernel, double* src, double* dest, int xmin, int ymin, int xmax, int ymax, int width, int k); -- cgit v0.12