int S57_touch(_S57_geo *geoA, _S57_geo *geoB) // TRUE if A touch B else FALSE { unsigned int nptA; double *pptA; unsigned int nptB; double *pptB; return_if_null(geoA); return_if_null(geoB); if (FALSE == S57_getGeoData(geoA, 0, &nptA, &pptA)) return FALSE; if (FALSE == S57_getGeoData(geoB, 0, &nptB, &pptB)) return FALSE; // FIXME: work only for point in poly not point in line if (LINES_T == S57_getObjtype(geoB)) { PRINTF("FIXME: geoB is a LINES_T .. this algo break on that type\n"); return FALSE; } for (guint i=0; i<nptA; ++i, pptA+=3) { if (TRUE == S57_isPtInside(nptB, pptB, pptA[0], pptA[1], TRUE)) return TRUE; } return FALSE; }
GString *S57_getAttVal(_S57_geo *geoData, const char *att_name) // return attribute string value or NULL if: // 1- attribute name abscent // 2- its a mandatory attribute but its value is not define (EMPTY_NUMBER_MARKER) { return_if_null(geoData); return_if_null(att_name); //GString *att = (GString*) g_datalist_get_data(&geoData->attribs, att_name); //GString *att = (GString*) g_dataset_id_get_data(&geoData->attribs, g_quark_try_string(att_name)); GQuark q = g_quark_from_string(att_name); //GQuark q = g_quark_from_static_string(att_name); GString *att = (GString*) g_datalist_id_get_data(&geoData->attribs, q); if (NULL!=att && (0==g_strcmp0(att->str, EMPTY_NUMBER_MARKER))) { //PRINTF("NOTE: mandatory attribute (%s) with ommited value\n", att_name); return NULL; } // display this NOTE once (because of to many warning) static int silent = FALSE; if (!silent && NULL!=att && 0==att->len) { PRINTF("NOTE: attribute (%s) has no value [obj:%s]\n", att_name, geoData->name->str); PRINTF(" (this msg will not repeat)\n"); silent = TRUE; return NULL; } return att; }
cchar *S57_getName(_S57_geo *geoData) { return_if_null(geoData); return_if_null(geoData->name); return geoData->name->str; }
S57_geo *S57_ogrLoadObject(const char *objname, void *feature) { return_if_null(objname); return_if_null(feature); // debug //PRINTF("DEBUG: start loading object (%s:%X)\n", objname, feature); S57_geo *geoData = _ogrLoadObject(objname, feature, NULL); if (NULL == geoData) return NULL; if (0 != strcmp(WORLD_BASENM, objname)) { S57_setName(geoData, objname); } _setAtt(geoData, feature); // debug //if (207 == S57_getGeoID(geoData)) { // S57_dumpData(geoData, FALSE); //} //PRINTF("DEBUG: finish loading object (%s)\n", objname); return geoData; }
S57_geo *S57_setAREAS(guint ringnbr, guint *ringxyznbr, geocoord **ringxyz) { return_if_null(ringxyznbr); return_if_null(ringxyz); _S57_geo *geoData = g_new0(_S57_geo, 1); //_S57_geo *geoData = g_try_new0(_S57_geo, 1); if (NULL == geoData) g_assert(0); geoData->id = _id++; geoData->obj_t = AREAS_T; geoData->ringnbr = ringnbr; geoData->ringxyznbr = ringxyznbr; geoData->ringxyz = ringxyz; geoData->rect.x1 = INFINITY; geoData->rect.y1 = INFINITY; geoData->rect.x2 = -INFINITY; geoData->rect.y2 = -INFINITY; geoData->scamin = INFINITY; #ifdef S52_USE_WORLD geoData->nextPoly = NULL; #endif return geoData; }
int S57_setName(_S57_geo *geoData, const char *name) // NOTE: this is a S57 object name .. UTF-16 or UTF-8 // use g_string to handle that { return_if_null(geoData); return_if_null(name); geoData->name = g_string_new(name); return TRUE; }
int S57_addPrimVertex(_S57_prim *prim, vertex_t *ptr) // add one xyz coord (3 vertex_t) { return_if_null(prim); return_if_null(ptr); //g_array_append_val(prim->vertex, *ptr); g_array_append_vals(prim->vertex, ptr, 1); return TRUE; }
static int _setExtent(S57_geo *geoData, OGRGeometryH geometry) { return_if_null(geoData); return_if_null(geometry); OGREnvelope envelope; OGR_G_GetEnvelope(geometry, &envelope); S57_setExt(geoData, envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY); return TRUE; }
guint S57_setGeoSize(_S57_geo *geo, guint size) { return_if_null(geo); if ((POINT_T==geo->obj_t) && (size > 1)) { PRINTF("ERROR: POINT_T size\n"); g_assert(0); } if ((LINES_T==geo->obj_t) && (size > geo->linexyznbr)) { PRINTF("ERROR: LINES_T size\n"); g_assert(0); } if ((AREAS_T==geo->obj_t) && (size > geo->ringxyznbr[0])) { PRINTF("ERROR: AREAS_T size\n"); g_assert(0); } if (_META_T == geo->obj_t) { PRINTF("ERROR: object type invalid (%i)\n", geo->obj_t); g_assert(0); return FALSE; } return geo->dataSize = size; }
int S57_isPtInside(int npt, double *xyz, double x, double y, int close) // return TRUE if inside else FALSE { int c = 0; pt3 *v = (pt3 *)xyz; return_if_null(xyz); if (TRUE == close) { for (int i=0; i<npt-1; ++i) { pt3 p1 = v[i]; pt3 p2 = v[i+1]; if ( ((p1.y>y) != (p2.y>y)) && (x < (p2.x-p1.x) * (y-p1.y) / (p2.y-p1.y) + p1.x) ) c = !c; } } else { for (int i=0, j=npt-1; i<npt; j=i++) { pt3 p1 = v[i]; pt3 p2 = v[j]; if ( ((p1.y>y) != (p2.y>y)) && (x < (p2.x-p1.x) * (y-p1.y) / (p2.y-p1.y) + p1.x) ) c = !c; } } // debug //PRINTF("npt: %i inside: %s\n", npt, (c==1)?"TRUE":"FALSE"); return c; }
int S57_setRelationship(_S57_geo *geo, _S57_geo *geoRel) { return_if_null(geo); return_if_null(geoRel); if (NULL == geo->relation) { geo->relation = geoRel; } else { // FIXME: ENC_ROOT/US3NY21M/US3NY21M.000 has multiple relation for the same object PRINTF("WARNING: 'geo->relation' allready in use ..\n"); g_assert(0); return FALSE; } return TRUE; }
S57_geo *S57_setPOINT(geocoord *xyz) { return_if_null(xyz); _S57_geo *geoData = g_new0(_S57_geo, 1); //_S57_geo *geoData = g_try_new0(_S57_geo, 1); if (NULL == geoData) g_assert(0); geoData->id = _id++; geoData->obj_t = POINT_T; geoData->pointxyz = xyz; geoData->rect.x1 = INFINITY; geoData->rect.y1 = INFINITY; geoData->rect.x2 = -INFINITY; geoData->rect.y2 = -INFINITY; geoData->scamin = INFINITY; #ifdef S52_USE_WORLD geoData->nextPoly = NULL; #endif return geoData; }
void* threadpool_excute_task(void *arg) { int index = 0; void *tmp_arg = NULL; threadpool_t *tpool; tpool = (threadpool_t*)arg; return_if_null(tpool); threadpool_task_func_t task_func; while(1) { pthread_mutex_lock(&tpool->mutex_queue); index = tpool->task_queue->head; if(index == tpool->task_queue->tail) { pthread_mutex_unlock(&tpool->mutex_queue); pthread_mutex_lock(&tpool->mutex_cond); pthread_cond_wait(&tpool->cond, &tpool->mutex_cond); //等待线程调度 pthread_mutex_unlock(&tpool->mutex_cond); } else { task_func = tpool->task_queue->task_func[index]; tmp_arg = tpool->task_queue->arg[index]; tpool->task_queue->head = (index+1) % tpool->max_thr_num; pthread_mutex_unlock(&tpool->mutex_queue); task_func(tmp_arg); printf("process end"); } } }
S57_geo *S57_setLINES(guint xyznbr, geocoord *xyz) { _S57_geo *geoData = g_new0(_S57_geo, 1); //_S57_geo *geoData = g_try_new0(_S57_geo, 1); if (NULL == geoData) g_assert(0); return_if_null(geoData); geoData->id = _id++; geoData->obj_t = LINES_T; geoData->linexyznbr = xyznbr; geoData->linexyz = xyz; geoData->rect.x1 = INFINITY; geoData->rect.y1 = INFINITY; geoData->rect.x2 = -INFINITY; geoData->rect.y2 = -INFINITY; geoData->scamin = INFINITY; #ifdef S52_USE_WORLD geoData->nextPoly = NULL; #endif return geoData; }
int S57_setTouchLIGHTS(_S57_geo *geo, S57_geo *touch) { return_if_null(geo); geo->touch.LIGHTS = touch; return TRUE; }
int S57_highlightOFF(_S57_geo *geo) { return_if_null(geo); geo->highlight = FALSE; return TRUE; }
S57_prim *S57_initPrimGeo(_S57_geo *geoData) { return_if_null(geoData); geoData->prim = S57_initPrim(geoData->prim); return geoData->prim; }
int S57_setTouchTOPMAR(_S57_geo *geo, S57_geo *touch) { return_if_null(geo); geo->touch.TOPMAR = touch; return TRUE; }
int S57_getNextCentroid(_S57_geo *geo, double *x, double *y) { return_if_null(geo); return_if_null(geo->centroid); if (geo->centroidIdx < geo->centroid->len) { pt2 pt = g_array_index(geo->centroid, pt2, geo->centroidIdx); *x = pt.x; *y = pt.y; ++geo->centroidIdx; return TRUE; } return FALSE; }
int S57_setTouchDEPVAL(_S57_geo *geo, S57_geo *touch) { return_if_null(geo); geo->touch.DEPVAL = touch; return TRUE; }
gboolean S57_setSup(_S57_geo *geoData, gboolean sup) { return_if_null(geoData); geoData->sup = sup; return geoData->sup; }
double S57_setScamin(_S57_geo *geo, double scamin) { return_if_null(geo); geo->scamin = scamin; return geo->scamin; }
int S57_setPrimDList (_S57_prim *prim, guint DList) { return_if_null(prim); prim->DList = DList; return TRUE; }
int S57_highlightON (_S57_geo *geo) { return_if_null(geo); geo->highlight = TRUE; return TRUE; }
S57_geo *S57_setGeoLink(_S57_geo *geoData, _S57_geo *link) { return_if_null(geoData); geoData->link = link; return geoData; }
int S57_addCentroid(_S57_geo *geo, double x, double y) { return_if_null(geo); pt2 pt = {x, y}; g_array_append_val(geo->centroid, pt); return TRUE; }
// experimental S57_geo *S57_setGeoLine(_S57_geo *geoData, guint xyznbr, geocoord *xyz) { return_if_null(geoData); geoData->obj_t = LINES_T; // because some Edge objet default to _META_T when no geo yet geoData->linexyznbr = xyznbr; geoData->linexyz = xyz; return geoData; }
S57_geo *S57_donePrimGeo(_S57_geo *geoData) { return_if_null(geoData); if (NULL != geoData->prim) { S57_donePrim(geoData->prim); geoData->prim = NULL; } return NULL; }
S57_geo *S57_setNextPoly(_S57_geo *geoData, _S57_geo *nextPoly) { return_if_null(geoData); if (NULL != geoData->nextPoly) nextPoly->nextPoly = geoData->nextPoly; geoData->nextPoly = nextPoly; return geoData; }
int S57_getExt(_S57_geo *geoData, double *x1, double *y1, double *x2, double *y2) // assume: extent canonical { return_if_null(geoData); *x1 = geoData->rect.x1; // W *y1 = geoData->rect.y1; // S *x2 = geoData->rect.x2; // E *y2 = geoData->rect.y2; // N return TRUE; }