[brlcad-commits] SF.net SVN: brlcad:[32850] brlcad/trunk
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <br...@us...> - 2008-10-06 11:09:57
|
Revision: 32850 http://brlcad.svn.sourceforge.net/brlcad/?rev=32850&view=rev Author: brlcad Date: 2008-10-06 11:08:53 +0000 (Mon, 06 Oct 2008) Log Message: ----------- stub in initial functionality for supporting points that optionally have per-point color, scale, and normal data while remaining a memory-compact representation using exactly no more than necessary (allowing datasets only limited by the size of available memory). don't yet implement support for reading in or using the extra data just yet, but the container is there now. later might also want to add support for allowing binunif as the data source. Modified Paths: -------------- brlcad/trunk/include/rtgeom.h brlcad/trunk/src/librt/primitives/pnts/pnts.c brlcad/trunk/src/mged/typein.c Modified: brlcad/trunk/include/rtgeom.h =================================================================== --- brlcad/trunk/include/rtgeom.h 2008-10-06 10:48:50 UTC (rev 32849) +++ brlcad/trunk/include/rtgeom.h 2008-10-06 11:08:53 UTC (rev 32850) @@ -560,16 +560,69 @@ * ID_PNTS */ +typedef enum { + PNT_TYPE_PNT = 0, + PNT_TYPE_COL = 0+1, + PNT_TYPE_SCA = 0+2, + PNT_TYPE_NRM = 0+4, + PNT_TYPE_COL_SCA = 0+1+2, + PNT_TYPE_COL_NRM = 0+1+4, + PNT_TYPE_SCA_NRM = 0+2+4, + PNT_TYPE_COL_SCA_NRM = 0+1+2+4 +} rt_pnt_type; + struct pnt { struct bu_list l; point_t v; }; +struct pnt_color { + struct bu_list l; + point_t v; + struct bu_color c; +}; +struct pnt_scale { + struct bu_list l; + point_t v; + fastf_t s; +}; +struct pnt_normal { + struct bu_list l; + point_t v; + vect_t n; +}; +struct pnt_color_scale { + struct bu_list l; + point_t v; + struct bu_color c; + fastf_t s; +}; +struct pnt_color_normal { + struct bu_list l; + point_t v; + struct bu_color c; + vect_t n; +}; +struct pnt_scale_normal { + struct bu_list l; + point_t v; + fastf_t s; + vect_t n; +}; +struct pnt_color_scale_normal { + struct bu_list l; + point_t v; + struct bu_color c; + fastf_t s; + vect_t n; +}; + struct rt_pnts_internal { long magic; - unsigned long numPoints; - double weight; - struct pnt *vList; + double scale; + rt_pnt_type type; + unsigned long count; + void *point; }; #define RT_PNTS_CK_MAGIC(_p) BU_CKMAG(_p, RT_PNTS_INTERNAL_MAGIC, "rt_pnts_internal") Modified: brlcad/trunk/src/librt/primitives/pnts/pnts.c =================================================================== --- brlcad/trunk/src/librt/primitives/pnts/pnts.c 2008-10-06 10:48:50 UTC (rev 32849) +++ brlcad/trunk/src/librt/primitives/pnts/pnts.c 2008-10-06 11:08:53 UTC (rev 32850) @@ -31,20 +31,20 @@ #include "rtgeom.h" #include "vmath.h" -/* length of axes segments plotted for points with zero weight */ +/* length of axes segments plotted for points with zero scale */ #define SEG_LENGTH .1 /** * R T _ P N T S _ E X P O R T 5 * * Export a pnts collection from the internal structure - * to the database format: numPoints, weight, points + * to the database format: numPoints, scale, points */ int rt_pnts_export5(struct bu_external *external, const struct rt_db_internal *internal, double local2mm, const struct db_i *db) { - int i, numPointsBytes, weightBytes, pointBytes; + int i, numPointsBytes, scaleBytes, pointBytes; unsigned long numPoints; struct rt_pnts_internal *pnts; register struct pnt *point; @@ -58,27 +58,28 @@ pnts = (struct rt_pnts_internal *) internal->idb_ptr; RT_PNTS_CK_MAGIC(pnts); - numPoints = pnts->numPoints; + numPoints = pnts->count; /* allocate enough space in buffer for the external format: - * unsigned long numPoints, double weight, point doubles + * unsigned long numPoints, double scale, point doubles */ numPointsBytes = sizeof(long); - weightBytes = SIZEOF_NETWORK_DOUBLE; - pointBytes = pnts->numPoints * ELEMENTS_PER_PT * SIZEOF_NETWORK_DOUBLE; + scaleBytes = SIZEOF_NETWORK_DOUBLE; + pointBytes = pnts->count * ELEMENTS_PER_PT * SIZEOF_NETWORK_DOUBLE; - external->ext_nbytes = numPointsBytes + weightBytes + pointBytes; + external->ext_nbytes = numPointsBytes + scaleBytes + pointBytes; external->ext_buf = (genptr_t) bu_malloc(external->ext_nbytes, "pnts external"); - /* place numPoints and weight at beginning of buffer */ + /* place numPoints and scale at beginning of buffer */ (void) bu_plong((unsigned char *) external->ext_buf, numPoints); - htond((unsigned char *)external->ext_buf + numPointsBytes, (unsigned char *)&pnts->weight, 1); + htond((unsigned char *)external->ext_buf + numPointsBytes, (unsigned char *)&pnts->scale, 1); if (numPoints > 0) { - head = &pnts->vList->l; + struct pnt *point = (struct pnt *)&pnts->point; + head = &point->l; points = (fastf_t *) bu_malloc(pointBytes, "rt_pnts_export5: points"); @@ -87,8 +88,8 @@ VSCALE(&points[i], point->v, local2mm); } - /* place scaled points after numPoints and weight in the buffer */ - htond((unsigned char *) external->ext_buf + numPointsBytes + weightBytes, + /* place scaled points after numPoints and scale in the buffer */ + htond((unsigned char *) external->ext_buf + numPointsBytes + scaleBytes, (unsigned char *) points, ELEMENTS_PER_PT * numPoints); bu_free((genptr_t) points, "rt_pnts_export5: points"); @@ -107,10 +108,11 @@ rt_pnts_import5(struct rt_db_internal *internal, const struct bu_external *external, register const fastf_t *mat, const struct db_i *db) { - int i, numPointsBytes, weightBytes, pointBytes; + int i, numPointsBytes, scaleBytes, pointBytes; unsigned long numPoints; struct rt_pnts_internal*pnts; struct pnt *point; + struct pnt *headPoint; fastf_t *pt; RT_CK_DB_INTERNAL(internal); @@ -125,17 +127,18 @@ /* initialize internal structure */ pnts = (struct rt_pnts_internal *) internal->idb_ptr; pnts->magic = RT_PNTS_INTERNAL_MAGIC; - BU_GETSTRUCT(pnts->vList, pnt); - BU_LIST_INIT(&pnts->vList->l); + BU_GETSTRUCT(pnts->point, pnt); + headPoint = (struct pnt *)pnts->point; + BU_LIST_INIT(&headPoint->l); /* pull internal members from buffer */ numPointsBytes = sizeof(long); - weightBytes = SIZEOF_NETWORK_DOUBLE; + scaleBytes = SIZEOF_NETWORK_DOUBLE; - numPoints = pnts->numPoints = bu_glong((unsigned char *) external->ext_buf); + numPoints = pnts->count = bu_glong((unsigned char *) external->ext_buf); pointBytes = numPoints * ELEMENTS_PER_PT * SIZEOF_NETWORK_DOUBLE; - ntohd((unsigned char *)&pnts->weight, (unsigned char *)external->ext_buf + numPointsBytes, 1); + ntohd((unsigned char *)&pnts->scale, (unsigned char *)external->ext_buf + numPointsBytes, 1); if (numPoints > 0) { @@ -143,7 +146,7 @@ /* pull points from buffer */ ntohd((unsigned char *) pt, (unsigned char *) external->ext_buf + numPointsBytes + - weightBytes, ELEMENTS_PER_PT * numPoints); + scaleBytes, ELEMENTS_PER_PT * numPoints); if (mat == NULL) { @@ -152,11 +155,12 @@ /* make point_t's from doubles and place in bu_list */ for (i = 0; i < numPoints * ELEMENTS_PER_PT; i += 3) { + BU_GETSTRUCT(point, pnt); MAT4X3PNT(point->v, mat, &pt[i]); - BU_LIST_PUSH(&(pnts->vList->l), &point->l); + BU_LIST_PUSH(&(headPoint->l), &point->l); } bu_free((genptr_t) pt, "rt_pnts_import5: pt"); @@ -203,7 +207,7 @@ struct rt_db_internal db; struct rt_ell_internal ell; struct pnt *point; - double weight, vCoord, hCoord; + double scale, vCoord, hCoord; point_t a, b; RT_CK_DB_INTERNAL(internal); @@ -211,14 +215,15 @@ pnts = (struct rt_pnts_internal *) internal->idb_ptr; RT_PNTS_CK_MAGIC(pnts); - if (pnts->numPoints > 0) { - head = &pnts->vList->l; - weight = pnts->weight; + if (pnts->count > 0) { + point = (struct pnt *)pnts->point; + head = &point->l; + scale = pnts->scale; } else { return 0; } - if (weight > 0) { + if (scale > 0) { /* set local database */ db.idb_magic = RT_DB_INTERNAL_MAGIC; db.idb_major_type = ID_ELL; @@ -227,9 +232,9 @@ /* set local ell for the pnts collection */ ell.magic = RT_ELL_INTERNAL_MAGIC; - VSET(ell.a, weight, 0, 0); - VSET(ell.b, 0, weight, 0); - VSET(ell.c, 0, 0, weight); + VSET(ell.a, scale, 0, 0); + VSET(ell.b, 0, scale, 0); + VSET(ell.c, 0, 0, scale); /* give rt_ell_plot a sphere representation of each point */ for(BU_LIST_FOR(point, pnt, head)) { Modified: brlcad/trunk/src/mged/typein.c =================================================================== --- brlcad/trunk/src/mged/typein.c 2008-10-06 10:48:50 UTC (rev 32849) +++ brlcad/trunk/src/mged/typein.c 2008-10-06 11:08:53 UTC (rev 32850) @@ -2905,10 +2905,11 @@ int pnts_in(int argc, char **argv, struct rt_db_internal *intern, char **prompt) { int i, j; - double weight; + double scale; unsigned long numPoints; struct rt_pnts_internal *pnts; struct pnt *point; + struct pnt *headPoint; struct bu_vls tmpVls; CHECK_DBI_NULL; @@ -2927,19 +2928,19 @@ numPoints = atol(argv[3]); - /* prompt for weight of points if not entered */ + /* prompt for scale of points if not entered */ if (argc < 5) { Tcl_AppendResult(interp, MORE_ARGS_STR, prompt[1], (char *)NULL); return CMD_MORE; } - /* validate weight */ + /* validate scale */ if (atof(argv[4]) < 0) { - Tcl_AppendResult(interp, "Weight must be nonnegative!\n", (char *)NULL); + Tcl_AppendResult(interp, "Scale must be nonnegative!\n", (char *)NULL); return CMD_BAD; } - weight = atof(argv[4]); + scale = atof(argv[4]); /* set database structure */ intern->idb_major_type = DB5_MAJORTYPE_BRLCAD; @@ -2950,10 +2951,12 @@ /* set internal structure */ pnts = (struct rt_pnts_internal *) intern->idb_ptr; pnts->magic = RT_PNTS_INTERNAL_MAGIC; - pnts->numPoints = numPoints; - pnts->weight = weight; - BU_GETSTRUCT(pnts->vList, pnt); - BU_LIST_INIT(&(pnts->vList->l)); + pnts->scale = scale; + pnts->type = PNT_TYPE_PNT; + pnts->count = numPoints; + headPoint = pnts->point; + BU_GETSTRUCT(headPoint, pnt); /* empty list head */ + BU_LIST_INIT(&(headPoint->l)); /* prompt for X, Y, Z of points */ if (argc < 5 + (numPoints * ELEMENTS_PER_PT)) { @@ -2979,7 +2982,7 @@ point->v[Y] = strtod(argv[i + 1], NULL) * local2base; point->v[Z] = strtod(argv[i + 2], NULL) * local2base; - BU_LIST_PUSH(&(pnts->vList->l), &(point->l)); + BU_LIST_PUSH(&(headPoint->l), &(point->l)); } return CMD_OK; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |