Revision: 76818
http://sourceforge.net/p/brlcad/code/76818
Author: starseeker
Date: 2020-08-17 15:19:51 +0000 (Mon, 17 Aug 2020)
Log Message:
-----------
Expose point inside/outside testing using the raytracer via the pnts command.
Not documented yet, needs more testing.
Modified Paths:
--------------
brlcad/trunk/include/analyze/pnts.h
brlcad/trunk/src/libanalyze/pnt_inside.c
brlcad/trunk/src/libanalyze/polygonizer.c
brlcad/trunk/src/libged/pnts/pnts.cpp
brlcad/trunk/src/libged/pnts_util.c
brlcad/trunk/src/libged/pnts_util.h
Modified: brlcad/trunk/include/analyze/pnts.h
===================================================================
--- brlcad/trunk/include/analyze/pnts.h 2020-08-17 13:08:40 UTC (rev 76817)
+++ brlcad/trunk/include/analyze/pnts.h 2020-08-17 15:19:51 UTC (rev 76818)
@@ -70,7 +70,7 @@
* Given an application structure and a test point, use ray sampling to
determine
* if the point is inside (on or within) or outside the volume described.
*/
-ANALYZE_EXPORT int analyze_pnt_in_vol(point_t *p, struct application *ap);
+ANALYZE_EXPORT int analyze_pnt_in_vol(point_t *p, struct application *ap, int
on_is_in);
__END_DECLS
Modified: brlcad/trunk/src/libanalyze/pnt_inside.c
===================================================================
--- brlcad/trunk/src/libanalyze/pnt_inside.c 2020-08-17 13:08:40 UTC (rev
76817)
+++ brlcad/trunk/src/libanalyze/pnt_inside.c 2020-08-17 15:19:51 UTC (rev
76818)
@@ -60,6 +60,10 @@
(*ret) = -1;
}
+ if (NEAR_ZERO(part->pt_inhit->hit_dist, VUNITIZE_TOL)) {
+ (*ret) = 1;
+ }
+
return 0;
}
@@ -70,7 +74,7 @@
}
int
-analyze_pnt_in_vol(point_t *p, struct application *ap)
+analyze_pnt_in_vol(point_t *p, struct application *ap, int on_is_in)
{
int i;
int fret = 1;
@@ -126,7 +130,13 @@
(void)rt_shootray(ap);
for (i = 0; i < 6; i++) {
- if (dir_results[i] < 0) fret = -1;
+ if (on_is_in) {
+ if (dir_results[i] != 0)
+ fret = -1;
+ } else {
+ if (dir_results[i] < 0)
+ fret = -1;
+ }
}
/* restore application */
Modified: brlcad/trunk/src/libanalyze/polygonizer.c
===================================================================
--- brlcad/trunk/src/libanalyze/polygonizer.c 2020-08-17 13:08:40 UTC (rev
76817)
+++ brlcad/trunk/src/libanalyze/polygonizer.c 2020-08-17 15:19:51 UTC (rev
76818)
@@ -631,7 +631,7 @@
pnt_in_out(point_t *p, void *d)
{
struct application *ap = (struct application *)d;
- return analyze_pnt_in_vol(p, ap);
+ return analyze_pnt_in_vol(p, ap, 0);
}
/**** An Implicit Surface Polygonizer ****/
Modified: brlcad/trunk/src/libged/pnts/pnts.cpp
===================================================================
--- brlcad/trunk/src/libged/pnts/pnts.cpp 2020-08-17 13:08:40 UTC (rev
76817)
+++ brlcad/trunk/src/libged/pnts/pnts.cpp 2020-08-17 15:19:51 UTC (rev
76818)
@@ -48,6 +48,234 @@
#include "../pnts_util.h"
}
+static int
+_pnts_inside_obj(struct ged *gedp, int argc, const char **argv)
+{
+ int ret = GED_OK;
+ unsigned long pntcnt = 0;
+ struct directory *dp = RT_DIR_NULL;
+ int print_help = 0;
+ int report_outside = 0;
+ int opt_ret = 0;
+ const char *usage = "Usage: pnts inside [options] <test_pnts_obj>
<test_vol_obj> <output_pnts_obj>\n\n";
+ struct bu_opt_desc d[3];
+ BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help and
exit");
+ BU_OPT(d[1], "R", "reverse", "", NULL, &report_outside, "Report points
outside volume.");
+ BU_OPT_NULL(d[2]);
+
+ if (!gedp)
+ return GED_ERROR;
+
+ argc-=(argc>0); argv+=(argc>0); /* skip command name argv[0] */
+
+ /* must be wanting help */
+ if (argc < 1) {
+ _ged_cmd_help(gedp, usage, d);
+ return GED_OK;
+ }
+
+ /* parse standard options */
+ opt_ret = bu_opt_parse(NULL, argc, argv, d);
+
+ if (print_help) {
+ _ged_cmd_help(gedp, usage, d);
+ return GED_OK;
+ }
+
+ /* adjust argc to match the leftovers of the options parsing */
+ argc = opt_ret;
+
+ if (argc != 3) {
+ _ged_cmd_help(gedp, usage, d);
+ return GED_ERROR;
+ }
+
+ const char *test_pnts_obj = argv[0];
+ const char *vol_obj = argv[1];
+ const char *output_pnts_obj = argv[2];
+ struct pnt *pstd, *pstdl = NULL;
+ struct pnt_color *pc, *pcl = NULL;
+ struct pnt_scale *ps, *psl = NULL;
+ struct pnt_normal *pn, *pnl = NULL;
+ struct pnt_color_scale *pcs, *pcsl = NULL;
+ struct pnt_color_normal *pcn, *pcnl = NULL;
+ struct pnt_scale_normal *psn, *psnl = NULL;
+ struct pnt_color_scale_normal *pcsn, *pcsnl = NULL;
+ void *npnt = NULL;
+ int iostat = 0;
+ struct rt_db_internal internal;
+ struct rt_pnts_internal *opnts = NULL;
+
+ /* Sanity */
+ GED_CHECK_EXISTS(gedp, output_pnts_obj, LOOKUP_QUIET, GED_ERROR);
+
+ /* get objs */
+ struct directory *test_pnts_dp = RT_DIR_NULL;
+ GED_DB_LOOKUP(gedp, test_pnts_dp, test_pnts_obj, LOOKUP_NOISY, GED_ERROR &
GED_QUIET);
+ struct directory *test_vol_dp = RT_DIR_NULL;
+ GED_DB_LOOKUP(gedp, test_vol_dp, vol_obj, LOOKUP_NOISY, GED_ERROR &
GED_QUIET);
+
+ /* For the test points, we need to introspect the object's data */
+ struct rt_db_internal tpnts_intern;
+ GED_DB_GET_INTERNAL(gedp, &tpnts_intern, test_pnts_dp, bn_mat_identity,
&rt_uniresource, GED_ERROR);
+ if (tpnts_intern.idb_major_type != DB5_MAJORTYPE_BRLCAD ||
tpnts_intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_PNTS) {
+ bu_vls_printf(gedp->ged_result_str, "pnts inside: %s is not a pnts
object!", test_pnts_obj);
+ rt_db_free_internal(&tpnts_intern);
+ return GED_ERROR;
+ }
+ struct rt_pnts_internal *pnts = (struct rt_pnts_internal
*)tpnts_intern.idb_ptr;
+ RT_PNTS_CK_MAGIC(pnts);
+
+
+ /* For the vol object, we need to raytrace it */
+ struct application *ap;
+ struct resource *resp;
+ struct rt_i *rtip;
+ size_t ncpus;
+ BU_GET(ap, struct application);
+ RT_APPLICATION_INIT(ap);
+ BU_GET(resp, struct resource);
+ rtip = rt_new_rti(gedp->ged_wdbp->dbip);
+ rt_init_resource(resp, 0, rtip);
+ ap->a_rt_i = rtip;
+ ap->a_resource = resp;
+ ap->a_onehit = 1;
+ ap->a_hit = NULL;
+ ap->a_miss = NULL;
+ ap->a_overlap = NULL;
+ ap->a_logoverlap = rt_silent_logoverlap;
+ if ((rt_gettree(rtip, vol_obj) < 0)) {
+ ret = GED_ERROR;
+ goto pnts_internal_memfree;
+ }
+ ncpus = bu_avail_cpus();
+ rt_prep_parallel(rtip, ncpus);
+
+ /* For the output, make a new pnts object */
+ RT_DB_INTERNAL_INIT(&internal);
+ internal.idb_major_type = DB5_MAJORTYPE_BRLCAD;
+ internal.idb_type = ID_PNTS;
+ internal.idb_meth = &OBJ[ID_PNTS];
+ BU_ALLOC(internal.idb_ptr, struct rt_pnts_internal);
+ opnts = (struct rt_pnts_internal *) internal.idb_ptr;
+ opnts->magic = RT_PNTS_INTERNAL_MAGIC;
+ opnts->scale = pnts->scale;
+ opnts->type = pnts->type;
+ opnts->point = _ged_pnts_new_pnt(pnts->type);
+ _ged_pnts_init_head_pnt(opnts);
+
+ switch(pnts->type) {
+ case RT_PNT_TYPE_PNT:
+ pstdl = (struct pnt *)pnts->point;
+ for (BU_LIST_FOR(pstd, pnt, &(pstdl->l))) {
+ iostat = analyze_pnt_in_vol(&(pstd->v), ap, 1);
+ if ((!report_outside && iostat == -1) || (report_outside &&
iostat != -1)) {
+ npnt = _ged_pnts_dup((void *)pstd, RT_PNT_TYPE_PNT);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ case RT_PNT_TYPE_COL:
+ pcl = (struct pnt_color *)pnts->point;
+ for (BU_LIST_FOR(pc, pnt_color, &(pcl->l))) {
+ iostat = analyze_pnt_in_vol(&(pc->v), ap, 1);
+ if ((!report_outside && iostat == -1) || (report_outside &&
iostat != -1)) {
+ npnt = _ged_pnts_dup((void *)pc, RT_PNT_TYPE_COL);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ case RT_PNT_TYPE_SCA:
+ psl = (struct pnt_scale *)pnts->point;
+ for (BU_LIST_FOR(ps, pnt_scale, &(psl->l))) {
+ iostat = analyze_pnt_in_vol(&(ps->v), ap, 1);
+ if ((!report_outside && iostat == -1) || (report_outside &&
iostat != -1)) {
+ npnt = _ged_pnts_dup((void *)ps, RT_PNT_TYPE_SCA);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ case RT_PNT_TYPE_NRM:
+ pnl = (struct pnt_normal *)pnts->point;
+ for (BU_LIST_FOR(pn, pnt_normal, &(pnl->l))) {
+ iostat = analyze_pnt_in_vol(&(pn->v), ap, 1);
+ if ((!report_outside && iostat == -1) || (report_outside &&
iostat != -1)) {
+ npnt = _ged_pnts_dup((void *)pn, RT_PNT_TYPE_NRM);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ case RT_PNT_TYPE_COL_SCA:
+ pcsl = (struct pnt_color_scale *)pnts->point;
+ for (BU_LIST_FOR(pcs, pnt_color_scale, &(pcsl->l))) {
+ iostat = analyze_pnt_in_vol(&(pcs->v), ap, 1);
+ if ((!report_outside && iostat == -1) || (report_outside &&
iostat != -1)) {
+ npnt = _ged_pnts_dup((void *)pcs, RT_PNT_TYPE_COL_SCA);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ case RT_PNT_TYPE_COL_NRM:
+ pcnl = (struct pnt_color_normal *)pnts->point;
+ for (BU_LIST_FOR(pcn, pnt_color_normal, &(pcnl->l))) {
+ iostat = analyze_pnt_in_vol(&(pcn->v), ap, 1);
+ if ((!report_outside && iostat == -1) || (report_outside &&
iostat != -1)) {
+ npnt = _ged_pnts_dup((void *)pcn, RT_PNT_TYPE_COL_NRM);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ case RT_PNT_TYPE_SCA_NRM:
+ psnl = (struct pnt_scale_normal *)pnts->point;
+ for (BU_LIST_FOR(psn, pnt_scale_normal, &(psnl->l))) {
+ iostat = analyze_pnt_in_vol(&(psn->v), ap, 1);
+ if ((!report_outside && iostat == -1) || (report_outside &&
iostat != -1)) {
+ npnt = _ged_pnts_dup((void *)psn, RT_PNT_TYPE_SCA_NRM);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ case RT_PNT_TYPE_COL_SCA_NRM:
+ pcsnl = (struct pnt_color_scale_normal *)pnts->point;
+ for (BU_LIST_FOR(pcsn, pnt_color_scale_normal, &(pcsnl->l))) {
+ iostat = analyze_pnt_in_vol(&(pcsn->v), ap, 1);
+ if (iostat == 1 || (report_outside && iostat != 1)) {
+ npnt = _ged_pnts_dup((void *)pcsn, RT_PNT_TYPE_COL_SCA_NRM);
+ _ged_pnts_add(opnts, npnt);
+ pntcnt++;
+ }
+ }
+ break;
+ default:
+ bu_vls_printf(gedp->ged_result_str, "Unknown point type in object,
aborting\n");
+ ret = GED_ERROR;
+ goto pnts_internal_memfree;
+ };
+
+ opnts->count = pntcnt;
+ GED_DB_DIRADD(gedp, dp, output_pnts_obj, RT_DIR_PHONY_ADDR, 0,
RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR);
+ GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR);
+
+ bu_vls_printf(gedp->ged_result_str, "Generated pnts object %s with %ld
matching points", output_pnts_obj, pntcnt);
+
+pnts_internal_memfree:
+ rt_db_free_internal(&tpnts_intern);
+ rt_clean_resource(rtip, resp);
+ rt_free_rti(rtip);
+ BU_PUT(resp, struct resource);
+ BU_PUT(ap, struct appliation);
+
+ return ret;
+}
+
+
HIDDEN void
_pnt_to_tri(point_t *p, vect_t *n, struct rt_bot_internal *bot_ip, fastf_t
scale, unsigned long pntcnt)
{
@@ -1163,7 +1391,7 @@
int opt_ret = 0;
int opt_argc = argc;
struct bu_opt_desc d[2];
- const char * const pnt_subcommands[] = {"gen", "read", "tri", "wn",
"write", NULL};
+ const char * const pnt_subcommands[] = {"gen", "inside", "read", "tri",
"wn", "write", NULL};
const char * const *subcmd;
BU_OPT(d[0], "h", "help", "", NULL, &print_help, "Print help
and exit");
@@ -1221,6 +1449,9 @@
}
len = strlen(argv[0]);
+
+ if (bu_strncmp(argv[0], "inside", len) == 0) return _pnts_inside_obj(gedp,
argc, argv);
+
if (bu_strncmp(argv[0], "tri", len) == 0) return _pnts_to_bot(gedp, argc,
argv);
if (bu_strncmp(argv[0], "gen", len) == 0) return _obj_to_pnts(gedp, argc,
argv);
Modified: brlcad/trunk/src/libged/pnts_util.c
===================================================================
--- brlcad/trunk/src/libged/pnts_util.c 2020-08-17 13:08:40 UTC (rev 76817)
+++ brlcad/trunk/src/libged/pnts_util.c 2020-08-17 15:19:51 UTC (rev 76818)
@@ -392,6 +392,91 @@
}
}
+void *
+_ged_pnts_dup(void *point, rt_pnt_type type)
+{
+ void *npnt = NULL;
+ struct pnt *pstd, *pstdnew = NULL;
+ struct pnt_color *pc, *pcnew = NULL;
+ struct pnt_scale *ps, *psnew = NULL;
+ struct pnt_normal *pn, *pnnew = NULL;
+ struct pnt_color_scale *pcs, *pcsnew = NULL;
+ struct pnt_color_normal *pcn, *pcnnew = NULL;
+ struct pnt_scale_normal *psn, *psnnew = NULL;
+ struct pnt_color_scale_normal *pcsn, *pcsnnew = NULL;
+
+ switch (type) {
+ case RT_PNT_TYPE_PNT:
+ pstd = (struct pnt *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ pstdnew = (struct pnt *)npnt;
+ VMOVE(pstdnew->v, pstd->v);
+ break;
+ case RT_PNT_TYPE_COL:
+ pc = (struct pnt_color *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ pcnew = (struct pnt_color *)npnt;
+ VMOVE(pcnew->v, pc->v);
+ pcnew->c.buc_rgb[0] = pc->c.buc_rgb[0];
+ pcnew->c.buc_rgb[1] = pc->c.buc_rgb[1];
+ pcnew->c.buc_rgb[2] = pc->c.buc_rgb[2];
+ break;
+ case RT_PNT_TYPE_SCA:
+ ps = (struct pnt_scale *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ psnew = (struct pnt_scale *)npnt;
+ VMOVE(psnew->v, ps->v);
+ psnew->s = ps->s;
+ break;
+ case RT_PNT_TYPE_NRM:
+ pn = (struct pnt_normal *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ pnnew = (struct pnt_normal *)npnt;
+ VMOVE(pnnew->v, pn->v);
+ VMOVE(pnnew->n, pn->n);
+ break;
+ case RT_PNT_TYPE_COL_SCA:
+ pcs = (struct pnt_color_scale *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ pcsnew = (struct pnt_color_scale *)npnt;
+ VMOVE(pcsnew->v, pcs->v);
+ pcsnew->c.buc_rgb[0] = pcs->c.buc_rgb[0];
+ pcsnew->c.buc_rgb[1] = pcs->c.buc_rgb[1];
+ pcsnew->c.buc_rgb[2] = pcs->c.buc_rgb[2];
+ pcsnew->s = pcs->s;
+ break;
+ case RT_PNT_TYPE_COL_NRM:
+ pcn = (struct pnt_color_normal *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ pcnnew = (struct pnt_color_normal *)npnt;
+ VMOVE(pcnnew->v, pcn->v);
+ VMOVE(pcnnew->n, pcn->n);
+ break;
+ case RT_PNT_TYPE_SCA_NRM:
+ psn = (struct pnt_scale_normal *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ psnnew = (struct pnt_scale_normal *)npnt;
+ VMOVE(psnnew->v, psn->v);
+ psnnew->s = psn->s;
+ VMOVE(psnnew->n, psn->n);
+ break;
+ case RT_PNT_TYPE_COL_SCA_NRM:
+ pcsn = (struct pnt_color_scale_normal *)point;
+ npnt = _ged_pnts_new_pnt(type);
+ pcsnnew = (struct pnt_color_scale_normal *)npnt;
+ VMOVE(pcsnnew->v, pcsn->v);
+ pcsnnew->c.buc_rgb[0] = pcsn->c.buc_rgb[0];
+ pcsnnew->c.buc_rgb[1] = pcsn->c.buc_rgb[1];
+ pcsnnew->c.buc_rgb[2] = pcsn->c.buc_rgb[2];
+ pcsnnew->s = pcsn->s;
+ VMOVE(pcsnnew->n, pcsn->n);
+ break;
+ default:
+ break;
+ }
+ return npnt;
+}
+
/*
* Local Variables:
* tab-width: 8
Modified: brlcad/trunk/src/libged/pnts_util.h
===================================================================
--- brlcad/trunk/src/libged/pnts_util.h 2020-08-17 13:08:40 UTC (rev 76817)
+++ brlcad/trunk/src/libged/pnts_util.h 2020-08-17 15:19:51 UTC (rev 76818)
@@ -60,6 +60,8 @@
GED_EXPORT extern void _ged_pnts_add(struct rt_pnts_internal *pnts, void
*point);
+GED_EXPORT extern void * _ged_pnts_dup(void *point, rt_pnt_type t);
+
__END_DECLS
#endif //LIBGED_PNT_GED_PRIVATE_H
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits