From bec428dc4f661d7a4e66cf044ee25be57e56ef19 Mon Sep 17 00:00:00 2001 From: William Joye Date: Sat, 16 Mar 2019 15:29:24 -0400 Subject: thread contour --- tksao/frame/context.C | 31 ++++++++++-- tksao/frame/fvcontour.C | 132 ++++++++++++++++++++++++++++++------------------ tksao/frame/fvcontour.h | 12 ++--- 3 files changed, 111 insertions(+), 64 deletions(-) diff --git a/tksao/frame/context.C b/tksao/frame/context.C index 0fed0ac..e21fa78 100644 --- a/tksao/frame/context.C +++ b/tksao/frame/context.C @@ -396,9 +396,10 @@ void Context::contourCreateFV(const char* color, int width, int dash, int cnt =0; while (ptr) { fvcontour_.append(ptr, &thread_[cnt], &targ[cnt]); - /* + cnt++; - if (cnt == parent_->nthreads_) { + // if (cnt == parent_->nthreads_) { + if (cnt == 1) { for (int ii=0; iinextMosaic(); } - /* + for (int ii=0; iiwidth, tt->height, tt->dest, tt->mm, tt->fv); + return NULL; +} + +void FVContour::unity(FitsImage* fits, pthread_t* thread, void* targ) { FitsBound* params = fits->getDataParams(((Base*)parent_)->currentContext->secMode()); @@ -191,13 +196,13 @@ void FVContour::unity(FitsImage* fits) // blank img long size = width*height; - double* img = new double[size]; - if (!img) { + double* dest = new double[size]; + if (!dest) { internalError("FVContour could not allocate enough memory"); return; } for (long ii=0; iigetValueDouble(kk); if (isfinite(vv)) - img[kk] = vv; + dest[kk] = vv; } } CLEARSIGBUS // contours - build(width, height, img, &mm, this); - delete [] img; + t_fvcontour_arg* tt = (t_fvcontour_arg*)targ; + tt->kernel = NULL; + tt->src = NULL; + tt->dest = dest; + tt->xmin = params->xmin; + tt->xmax = params->xmax; + tt->ymin = params->ymin; + tt->ymax = params->ymax; + tt->width = width; + tt->height = height; + tt->r = 0; + tt->mm = &mm; + tt->fv = this; + + int result = pthread_create(thread, NULL, fvUnityThread, targ); + if (result) + internalError("Unable to Create Thread"); +} + +static void* fvSmoothThread(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); + build(tt->width, tt->height, tt->dest, tt->mm, tt->fv); + return NULL; } -void FVContour::nobin(FitsImage* fits, pthread_t* thread, void* targ) +void FVContour::smooth(FitsImage* fits, pthread_t* thread, void* targ) { FitsBound* params = fits->getDataParams(((Base*)parent_)->currentContext->secMode()); @@ -227,21 +257,16 @@ void FVContour::nobin(FitsImage* fits, pthread_t* thread, void* targ) // blank img long size = width*height; - double* img = new double[size]; - if (!img) { + double* dest = new double[size]; + if (!dest) { internalError("FVContour could not allocate enough memory"); return; } for (long ii=0; iikernel = kernel; tt->src = src; - tt->dest = img; + tt->dest = dest; tt->xmin = params->xmin; tt->xmax = params->xmax; tt->ymin = params->ymin; @@ -271,33 +300,22 @@ void FVContour::nobin(FitsImage* fits, pthread_t* thread, void* targ) tt->width = width; tt->height = height; tt->r = r; - tt->mm = &mm; tt->fv = this; - // 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(tt->width, tt->height, tt->dest, tt->mm, tt->fv); - - delete [] src; - delete [] img; - delete [] kernel; + int result = pthread_create(thread, NULL, fvSmoothThread, targ); + if (result) + internalError("Unable to Create Thread"); } -/* -void* fvcontourThread(void*vv) +static void* fvBlockThread(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); + build(tt->width, tt->height, tt->dest, tt->mm, tt->fv); return NULL; } -*/ -void FVContour::bin(FitsImage* fits) + +void FVContour::block(FitsImage* fits, pthread_t* thread, void* targ) { FitsBound* params = fits->getDataParams(((Base*)parent_)->currentContext->secMode()); @@ -316,11 +334,11 @@ void FVContour::bin(FitsImage* fits) Matrix n = m.invert(); double* mm = m.mm(); - double* img = new double[w2 * h2]; + double* dest = new double[w2 * h2]; { for (long jj=0; jjgetValueDouble(jj*width + ii); if (isfinite(v)) { if (count[kk]) - img[kk] += v; + dest[kk] += v; else - img[kk] = v; + dest[kk] = v; count[kk]++; } @@ -349,19 +367,33 @@ void FVContour::bin(FitsImage* fits) for (long kk=0; kkdataToRef; - build(w2, h2, img, &w, this); - delete [] img; + t_fvcontour_arg* tt = (t_fvcontour_arg*)targ; + tt->kernel = NULL; + tt->src = NULL; + tt->dest = dest; + tt->xmin = params->xmin; + tt->xmax = params->xmax; + tt->ymin = params->ymin; + tt->ymax = params->ymax; + tt->width = w2; + tt->height = h2; + tt->r = 0; + tt->mm = &w; + tt->fv = this; + + int result = pthread_create(thread, NULL, fvBlockThread, targ); + if (result) + internalError("Unable to Create Thread"); } -void build(long xdim, long ydim, double *image, Matrix* mx, - FVContour* fv) +void build(long xdim, long ydim, double *image, Matrix* mx, FVContour* fv) { long nelem = xdim*ydim; char* usedGrid = new char[nelem]; diff --git a/tksao/frame/fvcontour.h b/tksao/frame/fvcontour.h index 7f37066..47710d7 100644 --- a/tksao/frame/fvcontour.h +++ b/tksao/frame/fvcontour.h @@ -50,15 +50,9 @@ class FVContour { InverseScale* scale_; void buildScale(FitsImage* fits); - void unity(FitsImage*); - void bin(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*); - */ + void unity(FitsImage*, pthread_t* thread, void* targ); + void smooth(FitsImage*, pthread_t* thread, void* targ); + void block(FitsImage*, pthread_t* thread, void* targ); public: FVContour(); -- cgit v0.12