From 36b9b0a0b803adbfff16a795708b589985e8df2a Mon Sep 17 00:00:00 2001 From: William Joye Date: Mon, 18 Mar 2019 16:20:56 -0400 Subject: thread contour --- tksao/frame/context.C | 12 +++++++++++ tksao/frame/fvcontour.C | 55 ++++++++++++++++++++++++++++++------------------- tksao/frame/fvcontour.h | 4 +++- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/tksao/frame/context.C b/tksao/frame/context.C index 3d797ae..4dc7abf 100644 --- a/tksao/frame/context.C +++ b/tksao/frame/context.C @@ -404,6 +404,10 @@ void Context::contourCreateFV(const char* color, int width, int dash, if (rr) internalError("Unable to Join Thread"); + fvcontour_.append(targ[ii].lcl); + + if (targ[ii].lcl) + delete targ[ii].lcl; if (targ[ii].kernel) delete [] targ[ii].kernel; if (targ[ii].src) @@ -423,6 +427,10 @@ void Context::contourCreateFV(const char* color, int width, int dash, if (rr) internalError("Unable to Join Thread"); + fvcontour_.append(targ[ii].lcl); + + if (targ[ii].lcl) + delete targ[ii].lcl; if (targ[ii].kernel) delete [] targ[ii].kernel; if (targ[ii].src) @@ -2691,6 +2699,10 @@ void Context::updateContours() if (rr) internalError("Unable to Join Thread"); + fvcontour_.append(targ[0].lcl); + + if (targ[0].lcl) + delete targ[0].lcl; if (targ[0].kernel) delete [] targ[0].kernel; if (targ[0].src) diff --git a/tksao/frame/fvcontour.C b/tksao/frame/fvcontour.C index f23bdaf..27a31c0 100644 --- a/tksao/frame/fvcontour.C +++ b/tksao/frame/fvcontour.C @@ -22,12 +22,12 @@ static const char* methodName_[] = { enum Edge {TOP, RIGHT, BOTTOM, LEFT, NONE}; -static void build(long xdim, long ydim, double *image, Matrix* mx, - FVContour* fv); +static void build(long xdim, long ydim, double *image, Matrix& mx, + FVContour* fv, List* lcl); static void trace(long xdim, long ydim, double cntr, long xCell, long yCell, int side, double** rows, char* usedGrid, - Matrix* mx, ContourLevel* cl); + 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 @@ -164,6 +164,14 @@ const char* FVContour::methodName() return methodName_[method_]; } +void FVContour::append(List *lcl) +{ + while (lcl->head()) { + ContourLevel* ncl = lcl->extract(); + lcontourlevel_.append(ncl); + } +} + void FVContour::append(FitsImage* fits, pthread_t* thread, void* targ) { if (smooth_ == 1) @@ -182,7 +190,7 @@ void FVContour::append(FitsImage* fits, pthread_t* thread, void* targ) static void* fvUnityThread(void*vv) { t_fvcontour_arg* tt = (t_fvcontour_arg*)vv; - build(tt->width, tt->height, tt->dest, tt->mm, tt->fv); + build(tt->width, tt->height, tt->dest, tt->mm, tt->fv, tt->lcl); return NULL; } @@ -219,15 +227,16 @@ void FVContour::unity(FitsImage* fits, pthread_t* thread, void* 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->xmin = 0; + tt->xmax = 0; + tt->ymin = 0; + tt->ymax = 0; tt->width = width; tt->height = height; tt->r = 0; - tt->mm = &mm; + tt->mm = mm; tt->fv = this; + tt->lcl = new List; int result = pthread_create(thread, NULL, fvUnityThread, targ); if (result) @@ -240,7 +249,7 @@ static void* fvSmoothThread(void*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); + build(tt->width, tt->height, tt->dest, tt->mm, tt->fv, tt->lcl); return NULL; } @@ -296,8 +305,9 @@ void FVContour::smooth(FitsImage* fits, pthread_t* thread, void* targ) tt->width = width; tt->height = height; tt->r = r; - tt->mm = &mm; + tt->mm = mm; tt->fv = this; + tt->lcl = new List; int result = pthread_create(thread, NULL, fvSmoothThread, targ); if (result) @@ -307,7 +317,7 @@ void FVContour::smooth(FitsImage* fits, pthread_t* thread, void* targ) static void* fvBlockThread(void*vv) { t_fvcontour_arg* tt = (t_fvcontour_arg*)vv; - build(tt->width, tt->height, tt->dest, tt->mm, tt->fv); + build(tt->width, tt->height, tt->dest, tt->mm, tt->fv, tt->lcl); return NULL; } @@ -377,22 +387,24 @@ void FVContour::block(FitsImage* fits, pthread_t* thread, void* 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->xmin = 0; + tt->xmax = 0; + tt->ymin = 0; + tt->ymax = 0; tt->width = w2; tt->height = h2; tt->r = 0; - tt->mm = &mm; + tt->mm = mm; tt->fv = this; + tt->lcl = new List; 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, List* lcl) { long nelem = xdim*ydim; char* usedGrid = new char[nelem]; @@ -441,7 +453,8 @@ void build(long xdim, long ydim, double *image, Matrix* mx, FVContour* fv) trace(xdim, ydim, cntour, ii, jj, TOP, rows, usedGrid, mx, cl); if (!cl->lcontour().isEmpty()) - fv->lcontourlevel().append(cl); + lcl->append(cl); + // fv->lcontourlevel().append(cl); } delete [] usedGrid; @@ -451,7 +464,7 @@ void build(long xdim, long ydim, double *image, Matrix* mx, FVContour* fv) void trace(long xdim, long ydim, double cntr, long xCell, long yCell, int side, double** rows, char* usedGrid, - Matrix* mx, ContourLevel* cl) + Matrix& mx, ContourLevel* cl) { long ii = xCell; long jj = yCell; @@ -546,7 +559,7 @@ void trace(long xdim, long ydim, double cntr, done = 1; } - cc->lvertex().append(new Vertex(Vector(X+.5,Y+.5) * (*mx))); + cc->lvertex().append(new Vertex(Vector(X+.5,Y+.5) * mx)); } if (!cc->lvertex().isEmpty()) diff --git a/tksao/frame/fvcontour.h b/tksao/frame/fvcontour.h index 47710d7..dcd6897 100644 --- a/tksao/frame/fvcontour.h +++ b/tksao/frame/fvcontour.h @@ -23,8 +23,9 @@ typedef struct { int width; int height; int r; - Matrix* mm; + Matrix mm; FVContour* fv; + List* lcl; } t_fvcontour_arg; class FVContour { @@ -66,6 +67,7 @@ public: void update(FitsImage*); void update(FitsImage*, FrScale*); + void append(List*); void append(FitsImage*, pthread_t* thread, void* targ); int isEmpty() {return lcontourlevel_.isEmpty();} -- cgit v0.12