BRL-CAD
pnts.c
Go to the documentation of this file.
1 /* P N T S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file primitives/pnts/pnts.c
21  *
22  * Collection of points.
23  *
24  */
25 
26 #include "common.h"
27 
28 /* system headers */
29 #include "bnetwork.h"
30 
31 /* common headers */
32 #include "bu/cv.h"
33 #include "bn.h"
34 
35 #include "raytrace.h"
36 #include "rtgeom.h"
37 #include "vmath.h"
38 
39 
40 extern int rt_ell_plot(struct bu_list *, struct rt_db_internal *, const struct rt_tess_tol *, const struct bn_tol *, const struct rt_view_info *);
41 
42 
43 HIDDEN unsigned char *
44 pnts_pack_double(unsigned char *buf, unsigned char *data, unsigned int count)
45 {
46  bu_cv_htond(buf, data, count);
47  buf += count * SIZEOF_NETWORK_DOUBLE;
48  return buf;
49 }
50 
51 
52 HIDDEN unsigned char *
53 pnts_unpack_double(unsigned char *buf, unsigned char *data, unsigned int count)
54 {
55  bu_cv_ntohd(data, buf, count);
56  buf += count * SIZEOF_NETWORK_DOUBLE;
57  return buf;
58 }
59 
60 /**
61  * Calculate a bounding box for a set of points
62  */
63 int
64 rt_pnts_bbox(struct rt_db_internal *ip, point_t *min, point_t *max, const struct bn_tol *UNUSED(tol)) {
65  struct rt_pnts_internal *pnts;
66  struct bu_list *head;
67  struct pnt *point;
68  point_t sph_min, sph_max;
69 
71  pnts = (struct rt_pnts_internal *)ip->idb_ptr;
72  RT_PNTS_CK_MAGIC(pnts);
73 
74  if (pnts->count > 0) {
75  point = (struct pnt *)pnts->point;
76  head = &point->l;
77  } else {
78  return 0;
79  }
80 
81  VSETALL((*min), INFINITY);
82  VSETALL((*max), -INFINITY);
83 
84  if (pnts->scale > 0) {
85  /* we're making spheres out of these, so the bbox
86  * has to take that into account */
87  for (BU_LIST_FOR(point, pnt, head)) {
88  sph_min[X] = point->v[X] - pnts->scale;
89  sph_max[X] = point->v[X] + pnts->scale;
90  sph_min[Y] = point->v[Y] - pnts->scale;
91  sph_max[Y] = point->v[Y] + pnts->scale;
92  sph_min[Z] = point->v[Z] - pnts->scale;
93  sph_max[Z] = point->v[Z] + pnts->scale;
94  VMINMAX((*min), (*max), sph_min);
95  VMINMAX((*min), (*max), sph_max);
96  }
97  } else {
98  for (BU_LIST_FOR(point, pnt, head)) {
99  VMINMAX((*min), (*max), point->v);
100  }
101  }
102  return 0;
103 }
104 
105 /**
106  * Export a pnts collection from the internal structure to the
107  * database format
108  */
109 int
110 rt_pnts_export5(struct bu_external *external, const struct rt_db_internal *internal, double local2mm, const struct db_i *dbip)
111 {
112  struct rt_pnts_internal *pnts = NULL;
113  unsigned long pointDataSize;
114  unsigned char *buf = NULL;
115 
116  /* must be double for import and export */
117  double scan;
118 
119  if (dbip) RT_CK_DBI(dbip);
120 
121  /* acquire internal pnts structure */
122  RT_CK_DB_INTERNAL(internal);
123  BU_CK_EXTERNAL(external);
124  external->ext_nbytes = 0;
125 
126  pnts = (struct rt_pnts_internal *) internal->idb_ptr;
127  RT_PNTS_CK_MAGIC(pnts);
128 
129  /* allocate enough for the header (scale + type + count) */
131  external->ext_buf = (uint8_t *) bu_calloc(sizeof(unsigned char), external->ext_nbytes, "pnts external");
132  buf = (unsigned char *)external->ext_buf;
133 
134  scan = pnts->scale; /* convert fastf_t to double */
135  bu_cv_htond(buf, (unsigned char *)&scan, 1);
136  buf += SIZEOF_NETWORK_DOUBLE;
137  *(uint16_t *)buf = htons((unsigned short)pnts->type);
138  buf += SIZEOF_NETWORK_SHORT;
139  *(uint32_t *)buf = htonl(pnts->count);
140  buf += SIZEOF_NETWORK_LONG;
141 
142  if (pnts->count <= 0) {
143  /* no points to stash, we're done */
144  return 0;
145  }
146 
147  /* figure out how much data there is for each point */
148  pointDataSize = 3; /* v */
149  if (pnts->type & RT_PNT_TYPE_COL) {
150  pointDataSize += 3; /* c */
151  }
152  if (pnts->type & RT_PNT_TYPE_SCA) {
153  pointDataSize += 1; /* s */
154  }
155  if (pnts->type & RT_PNT_TYPE_NRM) {
156  pointDataSize += 3; /* n */
157  }
158 
159  /* convert number of doubles to number of network bytes required to store doubles */
160  pointDataSize = pointDataSize * SIZEOF_NETWORK_DOUBLE;
161 
162  external->ext_buf = (uint8_t *)bu_realloc(external->ext_buf, external->ext_nbytes + (pnts->count * pointDataSize), "pnts external realloc");
163  buf = (unsigned char *)external->ext_buf + external->ext_nbytes;
164  external->ext_nbytes = external->ext_nbytes + (pnts->count * pointDataSize);
165 
166  /* get busy, serialize the point data depending on what type of point it is */
167  switch (pnts->type) {
168  case RT_PNT_TYPE_PNT: {
169  register struct pnt *point;
170 
171  for (BU_LIST_FOR(point, pnt, &(((struct pnt *)pnts->point)->l))) {
172  double v[3];
173 
174  /* pack v */
175  VSCALE(v, point->v, local2mm);
176  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
177  }
178 
179  break;
180  }
181  case RT_PNT_TYPE_COL: {
182  register struct pnt_color *point;
183 
184  for (BU_LIST_FOR(point, pnt_color, &(((struct pnt_color *)pnts->point)->l))) {
185  double v[3];
186  double c[3];
187  fastf_t cf[3];
188 
189  /* pack v */
190  VSCALE(v, point->v, local2mm);
191  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
192 
193  /* pack c */
194  bu_color_to_rgb_floats(&point->c, cf);
195  VMOVE(c, cf);
196  buf = pnts_pack_double(buf, (unsigned char *)c, 3);
197  }
198 
199  break;
200  }
201  case RT_PNT_TYPE_SCA: {
202  register struct pnt_scale *point;
203 
204  for (BU_LIST_FOR(point, pnt_scale, &(((struct pnt_scale *)pnts->point)->l))) {
205  double v[3];
206  double s[1];
207 
208  /* pack v */
209  VSCALE(v, point->v, local2mm);
210  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
211 
212  /* pack s */
213  s[0] = point->s * local2mm;
214  buf = pnts_pack_double(buf, (unsigned char *)s, 1);
215  }
216 
217  break;
218  }
219  case RT_PNT_TYPE_NRM: {
220  register struct pnt_normal *point;
221 
222  for (BU_LIST_FOR(point, pnt_normal, &(((struct pnt_normal *)pnts->point)->l))) {
223  double v[3];
224  double n[3];
225 
226  /* pack v */
227  VSCALE(v, point->v, local2mm);
228  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
229 
230  /* pack n */
231  VSCALE(n, point->n, local2mm);
232  buf = pnts_pack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
233  }
234 
235  break;
236  }
237  case RT_PNT_TYPE_COL_SCA: {
238  register struct pnt_color_scale *point;
239 
240  for (BU_LIST_FOR(point, pnt_color_scale, &(((struct pnt_color_scale *)pnts->point)->l))) {
241  double v[3];
242  double c[3];
243  fastf_t cf[3];
244  double s[1];
245 
246  /* pack v */
247  VSCALE(v, point->v, local2mm);
248  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
249 
250  /* pack c */
251  bu_color_to_rgb_floats(&point->c, cf);
252  VMOVE(c, cf);
253  buf = pnts_pack_double(buf, (unsigned char *)c, 3);
254 
255  /* pack s */
256  s[0] = point->s * local2mm;
257  buf = pnts_pack_double(buf, (unsigned char *)s, 1);
258  }
259 
260  break;
261  }
262  case RT_PNT_TYPE_COL_NRM: {
263  register struct pnt_color_normal *point;
264 
265  for (BU_LIST_FOR(point, pnt_color_normal, &(((struct pnt_color_normal *)pnts->point)->l))) {
266  double v[3];
267  double c[3];
268  fastf_t cf[3];
269  double n[3];
270 
271  /* pack v */
272  VSCALE(v, point->v, local2mm);
273  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
274 
275  /* pack c */
276  bu_color_to_rgb_floats(&point->c, cf);
277  VMOVE(c, cf);
278  buf = pnts_pack_double(buf, (unsigned char *)c, 3);
279 
280  /* pack n */
281  VSCALE(n, point->n, local2mm);
282  buf = pnts_pack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
283  }
284 
285  break;
286  }
287  case RT_PNT_TYPE_SCA_NRM: {
288  register struct pnt_scale_normal *point;
289 
290  for (BU_LIST_FOR(point, pnt_scale_normal, &(((struct pnt_scale_normal *)pnts->point)->l))) {
291  double v[3];
292  double s[1];
293  double n[3];
294 
295  /* pack v */
296  VSCALE(v, point->v, local2mm);
297  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
298 
299  /* pack s */
300  s[0] = point->s * local2mm;
301  buf = pnts_pack_double(buf, (unsigned char *)s, 1);
302 
303  /* pack n */
304  VSCALE(n, point->n, local2mm);
305  buf = pnts_pack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
306  }
307 
308  break;
309  }
310  case RT_PNT_TYPE_COL_SCA_NRM: {
311  register struct pnt_color_scale_normal *point;
312 
313  for (BU_LIST_FOR(point, pnt_color_scale_normal, &(((struct pnt_color_scale_normal *)pnts->point)->l))) {
314  double v[3];
315  double s[1];
316  double c[3];
317  fastf_t cf[3];
318  double n[3];
319 
320  /* pack v */
321  VSCALE(v, point->v, local2mm);
322  buf = pnts_pack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
323 
324  /* pack c */
325  bu_color_to_rgb_floats(&point->c, cf);
326  VMOVE(c, cf);
327  buf = pnts_pack_double(buf, (unsigned char *)c, 3);
328 
329  /* pack s */
330  s[0] = point->s * local2mm;
331  buf = pnts_pack_double(buf, (unsigned char *)s, 1);
332 
333  /* pack n */
334  VSCALE(n, point->n, local2mm);
335  buf = pnts_pack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
336  }
337 
338  break;
339  }
340  default:
341  bu_log("ERROR: unknown points primitive type (type=%d)\n", pnts->type);
342  return 0;
343  }
344 
345  return 0;
346 }
347 
348 
349 /**
350  * Import a pnts collection from the database format to the internal
351  * structure and apply modeling transformations.
352  */
353 int
354 rt_pnts_import5(struct rt_db_internal *internal, const struct bu_external *external, const fastf_t *mat, const struct db_i *dbip)
355 {
356  struct rt_pnts_internal *pnts = NULL;
357  struct bu_list *head = NULL;
358  unsigned char *buf = NULL;
359  unsigned long i;
360  uint16_t type;
361 
362  /* must be double for import and export */
363  double scan;
364 
365  if (dbip) RT_CK_DBI(dbip);
366 
367  RT_CK_DB_INTERNAL(internal);
368  BU_CK_EXTERNAL(external);
369  buf = (unsigned char *)external->ext_buf;
370 
371  /* initialize database structure */
372  internal->idb_major_type = DB5_MAJORTYPE_BRLCAD;
373  internal->idb_type = ID_PNTS;
374  internal->idb_meth = &OBJ[ID_PNTS];
375  BU_ALLOC(internal->idb_ptr, struct rt_pnts_internal);
376 
377  /* initialize internal structure */
378  pnts = (struct rt_pnts_internal *) internal->idb_ptr;
379  pnts->magic = RT_PNTS_INTERNAL_MAGIC;
380  pnts->point = NULL;
381 
382  /* unpack the header */
383  bu_cv_ntohd((unsigned char *)&scan, buf, 1);
384  pnts->scale = scan; /* convert double to fastf_t */
385  buf += SIZEOF_NETWORK_DOUBLE;
386  type = ntohs(*(uint16_t *)buf);
387  pnts->type = (rt_pnt_type)type; /* intentional enum coercion */
388  buf += SIZEOF_NETWORK_SHORT;
389  pnts->count = ntohl(*(uint32_t *)buf);
390  buf += SIZEOF_NETWORK_LONG;
391 
392  if (pnts->count <= 0) {
393  /* no points to read, we're done */
394  return 0;
395  }
396 
397  if (mat == NULL) {
398  mat = bn_mat_identity;
399  }
400 
401  /* get busy, deserialize the point data depending on what type of point it is */
402  switch (pnts->type) {
403  case RT_PNT_TYPE_PNT: {
404  register struct pnt *point;
405 
406  BU_ALLOC(point, struct pnt);
407  head = &point->l;
408  BU_LIST_INIT(head);
409  pnts->point = point;
410 
411  for (i = 0; i < pnts->count; i++) {
412  double v[3];
413 
414  BU_ALLOC(point, struct pnt);
415 
416  /* unpack v */
417  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
418  MAT4X3PNT(point->v, mat, v);
419 
420  BU_LIST_PUSH(head, &point->l);
421  }
422 
423  break;
424  }
425  case RT_PNT_TYPE_COL: {
426  register struct pnt_color *point;
427 
428  BU_ALLOC(point, struct pnt_color);
429  head = &point->l;
430  BU_LIST_INIT(head);
431  pnts->point = point;
432 
433  for (i = 0; i < pnts->count; i++) {
434  double v[3];
435  double c[3];
436  fastf_t cf[3];
437 
438  BU_ALLOC(point, struct pnt_color);
439 
440  /* unpack v */
441  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
442  MAT4X3PNT(point->v, mat, v);
443 
444  /* unpack c */
445  buf = pnts_unpack_double(buf, (unsigned char *)c, 3);
446  VMOVE(cf, c);
447  bu_color_from_rgb_floats(&point->c, cf);
448 
449  BU_LIST_PUSH(head, &point->l);
450  }
451 
452  break;
453  }
454  case RT_PNT_TYPE_SCA: {
455  register struct pnt_scale *point;
456 
457  BU_ALLOC(point, struct pnt_scale);
458  head = &point->l;
459  BU_LIST_INIT(head);
460  pnts->point = point;
461 
462  for (i = 0; i < pnts->count; i++) {
463  double v[3];
464  double s[1];
465 
466  BU_ALLOC(point, struct pnt_scale);
467 
468  /* unpack v */
469  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
470  MAT4X3PNT(point->v, mat, v);
471 
472  /* unpack s */
473  buf = pnts_unpack_double(buf, (unsigned char *)s, 1);
474  point->s = s[0];
475 
476  BU_LIST_PUSH(head, &point->l);
477  }
478 
479  break;
480  }
481  case RT_PNT_TYPE_NRM: {
482  register struct pnt_normal *point;
483 
484  BU_ALLOC(point, struct pnt_normal);
485  head = &point->l;
486  BU_LIST_INIT(head);
487  pnts->point = point;
488 
489  for (i = 0; i < pnts->count; i++) {
490  double v[3];
491  double n[3];
492 
493  BU_ALLOC(point, struct pnt_normal);
494 
495  /* unpack v */
496  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
497  MAT4X3PNT(point->v, mat, v);
498 
499  /* unpack n */
500  buf = pnts_unpack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
501  MAT4X3PNT(point->n, mat, n);
502 
503  BU_LIST_PUSH(head, &point->l);
504  }
505 
506  break;
507  }
508  case RT_PNT_TYPE_COL_SCA: {
509  register struct pnt_color_scale *point;
510 
511  BU_ALLOC(point, struct pnt_color_scale);
512  head = &point->l;
513  BU_LIST_INIT(head);
514  pnts->point = point;
515 
516  for (i = 0; i < pnts->count; i++) {
517  double v[3];
518  double c[3];
519  fastf_t cf[3];
520  double s[1];
521 
522  BU_ALLOC(point, struct pnt_color_scale);
523 
524  /* unpack v */
525  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
526  MAT4X3PNT(point->v, mat, v);
527 
528  /* unpack c */
529  buf = pnts_unpack_double(buf, (unsigned char *)c, 3);
530  VMOVE(cf, c);
531  bu_color_from_rgb_floats(&point->c, cf);
532 
533  /* unpack s */
534  buf = pnts_unpack_double(buf, (unsigned char *)s, 1);
535  point->s = s[0];
536 
537  BU_LIST_PUSH(head, &point->l);
538  }
539 
540  break;
541  }
542  case RT_PNT_TYPE_COL_NRM: {
543  register struct pnt_color_normal *point;
544 
545  BU_ALLOC(point, struct pnt_color_normal);
546  head = &point->l;
547  BU_LIST_INIT(head);
548  pnts->point = point;
549 
550  for (i = 0; i < pnts->count; i++) {
551  double v[3];
552  double c[3];
553  fastf_t cf[3];
554  double n[3];
555 
556  BU_ALLOC(point, struct pnt_color_normal);
557 
558  /* unpack v */
559  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
560  MAT4X3PNT(point->v, mat, v);
561 
562  /* unpack c */
563  buf = pnts_unpack_double(buf, (unsigned char *)c, 3);
564  VMOVE(cf, c);
565  bu_color_from_rgb_floats(&point->c, cf);
566 
567  /* unpack n */
568  buf = pnts_unpack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
569  MAT4X3PNT(point->n, mat, n);
570 
571  BU_LIST_PUSH(head, &point->l);
572  }
573 
574  break;
575  }
576  case RT_PNT_TYPE_SCA_NRM: {
577  register struct pnt_scale_normal *point;
578 
579  BU_ALLOC(point, struct pnt_scale_normal);
580  head = &point->l;
581  BU_LIST_INIT(head);
582  pnts->point = point;
583 
584  for (i = 0; i < pnts->count; i++) {
585  double v[3];
586  double s[1];
587  double n[3];
588 
589  BU_ALLOC(point, struct pnt_scale_normal);
590 
591  /* unpack v */
592  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
593  MAT4X3PNT(point->v, mat, v);
594 
595  /* unpack s */
596  buf = pnts_unpack_double(buf, (unsigned char *)s, 1);
597  point->s = s[0];
598 
599  /* unpack n */
600  buf = pnts_unpack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
601  MAT4X3PNT(point->n, mat, n);
602 
603  BU_LIST_PUSH(head, &point->l);
604  }
605 
606  break;
607  }
608  case RT_PNT_TYPE_COL_SCA_NRM: {
609  register struct pnt_color_scale_normal *point;
610 
611  BU_ALLOC(point, struct pnt_color_scale_normal);
612  head = &point->l;
613  BU_LIST_INIT(head);
614  pnts->point = point;
615 
616  for (i = 0; i < pnts->count; i++) {
617  double v[3];
618  double s[1];
619  double c[3];
620  fastf_t cf[3];
621  double n[3];
622 
623  BU_ALLOC(point, struct pnt_color_scale_normal);
624 
625  /* unpack v */
626  buf = pnts_unpack_double(buf, (unsigned char *)v, ELEMENTS_PER_POINT);
627  MAT4X3PNT(point->v, mat, v);
628 
629  /* unpack c */
630  buf = pnts_unpack_double(buf, (unsigned char *)c, 3);
631  VMOVE(cf, c);
632  bu_color_from_rgb_floats(&point->c, cf);
633 
634  /* unpack s */
635  buf = pnts_unpack_double(buf, (unsigned char *)s, 1);
636  point->s = s[0];
637 
638  /* unpack n */
639  buf = pnts_unpack_double(buf, (unsigned char *)n, ELEMENTS_PER_VECT);
640  MAT4X3PNT(point->n, mat, n);
641 
642  BU_LIST_PUSH(head, &point->l);
643  }
644 
645  break;
646  }
647  default:
648  bu_log("ERROR: unknown points primitive type (type=%d)\n", pnts->type);
649  return 0;
650  }
651 
652  return 0;
653 }
654 
655 
656 /**
657  * Free the storage associated with the rt_db_internal version of the
658  * collection. This uses type aliasing to iterate over the list of
659  * points as a bu_list instead of calling up a switching table for
660  * each point type.
661  */
662 void
663 rt_pnts_ifree(struct rt_db_internal *internal)
664 {
665  struct rt_pnts_internal *pnts;
666  register struct bu_list *point;
667 
668  RT_CK_DB_INTERNAL(internal);
669 
670  pnts = ((struct rt_pnts_internal *)(internal->idb_ptr));
671  RT_PNTS_CK_MAGIC(pnts);
672 
673  if (pnts->count == 0) {
674  return;
675  }
676 
677  /* since each point type has a bu_list as the first struct
678  * element, we can treat them all as 'pnt' structs in order to
679  * iterate over the bu_list and free them.
680  */
681  while (BU_LIST_WHILE(point, bu_list, &(((struct pnt *)pnts->point)->l))) {
682  BU_LIST_DEQUEUE(point);
683  bu_free(point, "free point");
684  }
685 
686  /* free the head point */
687  bu_free(pnts->point, "free head point");
688  pnts->point = NULL; /* sanity */
689 
690  /* free the internal container */
691  bu_free(internal->idb_ptr, "pnts ifree");
692  internal->idb_ptr = ((void *)0); /* sanity */
693 }
694 
695 
696 void
697 rt_pnts_print(register const struct soltab *stp)
698 {
699  register struct rt_pnts_internal *pnts;
700 
701  pnts = (struct rt_pnts_internal *)stp->st_specific;
702  RT_PNTS_CK_MAGIC(pnts);
703 
704  switch (pnts->type) {
705  case RT_PNT_TYPE_PNT: {
706  register struct pnt *point;
707  for (BU_LIST_FOR(point, pnt, &(((struct pnt *)pnts->point)->l))) {
708  }
709  }
710  case RT_PNT_TYPE_COL: {
711  register struct pnt_color *point;
712  for (BU_LIST_FOR(point, pnt_color, &(((struct pnt_color *)pnts->point)->l))) {
713  }
714  }
715  case RT_PNT_TYPE_SCA: {
716  register struct pnt_scale *point;
717  for (BU_LIST_FOR(point, pnt_scale, &(((struct pnt_scale *)pnts->point)->l))) {
718  }
719  }
720  case RT_PNT_TYPE_NRM: {
721  register struct pnt_normal *point;
722  for (BU_LIST_FOR(point, pnt_normal, &(((struct pnt_normal *)pnts->point)->l))) {
723  }
724  }
725  case RT_PNT_TYPE_COL_SCA: {
726  register struct pnt_color_scale *point;
727  for (BU_LIST_FOR(point, pnt_color_scale, &(((struct pnt_color_scale *)pnts->point)->l))) {
728  }
729  }
730  case RT_PNT_TYPE_COL_NRM: {
731  register struct pnt_color_normal *point;
732  for (BU_LIST_FOR(point, pnt_color_normal, &(((struct pnt_color_normal *)pnts->point)->l))) {
733  }
734  }
735  case RT_PNT_TYPE_SCA_NRM: {
736  register struct pnt_scale_normal *point;
737  for (BU_LIST_FOR(point, pnt_scale_normal, &(((struct pnt_scale_normal *)pnts->point)->l))) {
738  }
739  }
740  case RT_PNT_TYPE_COL_SCA_NRM: {
741  register struct pnt_color_scale_normal *point;
742  for (BU_LIST_FOR(point, pnt_color_scale_normal, &(((struct pnt_color_scale_normal *)pnts->point)->l))) {
743  }
744  }
745  default:
746  bu_log("ERROR: unknown points primitive type (type=%d)\n", pnts->type);
747  }
748 }
749 
750 
751 /**
752  * Plot pnts collection as axes or spheres.
753  */
754 int
755 rt_pnts_plot(struct bu_list *vhead, struct rt_db_internal *internal, const struct rt_tess_tol *ttol, const struct bn_tol *tol, const struct rt_view_info *UNUSED(info))
756 {
757  struct rt_pnts_internal *pnts;
758  struct bu_list *head;
759  struct rt_db_internal db;
760  struct rt_ell_internal ell;
761  struct pnt *point;
762  double scale;
763  point_t a, b;
764 
765  BU_CK_LIST_HEAD(vhead);
766  RT_CK_DB_INTERNAL(internal);
767 
768  pnts = (struct rt_pnts_internal *)internal->idb_ptr;
769  RT_PNTS_CK_MAGIC(pnts);
770 
771  if (pnts->count > 0) {
772  point = (struct pnt *)pnts->point;
773  head = &point->l;
774  scale = pnts->scale;
775  } else {
776  return 0;
777  }
778 
779  if (scale > 0) {
780  /* set local database */
782  db.idb_major_type = ID_ELL;
783  db.idb_ptr = &ell;
784 
785  /* set local ell for the pnts collection */
786  ell.magic = RT_ELL_INTERNAL_MAGIC;
787 
788  VSET(ell.a, scale, 0, 0);
789  VSET(ell.b, 0, scale, 0);
790  VSET(ell.c, 0, 0, scale);
791 
792  /* give rt_ell_plot a sphere representation of each point */
793  for (BU_LIST_FOR(point, pnt, head)) {
794  VMOVE(ell.v, point->v);
795  rt_ell_plot(vhead, &db, ttol, tol, NULL);
796  }
797  } else {
798  double vCoord, hCoord;
799  vCoord = hCoord = 1;
800 
801  for (BU_LIST_FOR(point, pnt, head)) {
802  /* draw first horizontal segment for this point */
803  VSET(a, point->v[X] - hCoord, point->v[Y], point->v[Z]);
804  VSET(b, point->v[X] + hCoord, point->v[Y], point->v[Z]);
805  RT_ADD_VLIST(vhead, a, BN_VLIST_LINE_MOVE);
806  RT_ADD_VLIST(vhead, b, BN_VLIST_LINE_DRAW);
807 
808  /* draw perpendicular horizontal segment */
809  VSET(a, point->v[X], point->v[Y] - hCoord, point->v[Z]);
810  VSET(b, point->v[X], point->v[Y] + hCoord, point->v[Z]);
811  RT_ADD_VLIST(vhead, a, BN_VLIST_LINE_MOVE);
812  RT_ADD_VLIST(vhead, b, BN_VLIST_LINE_DRAW);
813 
814  /* draw vertical segment */
815  VSET(a, point->v[X], point->v[Y], point->v[Z] - vCoord);
816  VSET(b, point->v[X], point->v[Y], point->v[Z] + vCoord);
817  RT_ADD_VLIST(vhead, a, BN_VLIST_LINE_MOVE);
818  RT_ADD_VLIST(vhead, b, BN_VLIST_LINE_DRAW);
819  }
820  }
821 
822  return 0;
823 }
824 
825 
826 /**
827  * Make human-readable formatted presentation of this primitive. First
828  * line describes type of solid. Additional lines are indented one
829  * tab, and give parameter values.
830  */
831 int
832 rt_pnts_describe(struct bu_vls *str, const struct rt_db_internal *intern, int verbose, double mm2local)
833 {
834  const struct rt_pnts_internal *pnts;
835  double defaultSize = 0.0;
836  unsigned long numPoints = 0;
837  unsigned long loop_counter = 0;
838 
839  char buf[256]= {0};
840  static const int BUF_SZ = 256;
841 
842  /* retrieve head record values */
843  pnts = (struct rt_pnts_internal *) intern->idb_ptr;
844  RT_PNTS_CK_MAGIC(pnts);
845 
846  defaultSize = pnts->scale;
847  numPoints = pnts->count;
848 
849  bu_vls_strcat(str, "Point Cloud (PNTS)\n");
850 
851  if (!verbose) {
852  return 1;
853  }
854 
855  snprintf(buf, BUF_SZ, "Total number of points: %lu\nDefault scale: %f\n", numPoints, defaultSize);
856  bu_vls_strcat(str, buf);
857 
858  if (pnts->count == 0) {
859  return 0;
860  }
861 
862  loop_counter = 1;
863  switch (pnts->type) {
864  case RT_PNT_TYPE_PNT: {
865  register struct pnt *point;
866  bu_vls_strcat(str, "point#, (point)\n");
867  for (BU_LIST_FOR(point, pnt, &(((struct pnt *)pnts->point)->l))) {
868  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f)\n",
869  (long unsigned)loop_counter,
870  point->v[X] * mm2local,
871  point->v[Y] * mm2local,
872  point->v[Z] * mm2local);
873  bu_vls_strcat(str, buf);
874  loop_counter++;
875  }
876  break;
877  }
878  case RT_PNT_TYPE_COL: {
879  register struct pnt_color *point;
880  bu_vls_strcat(str, "point#, (point), (color)\n");
881  for (BU_LIST_FOR(point, pnt_color, &(((struct pnt_color *)pnts->point)->l))) {
882  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f), (%f %f %f)\n",
883  (long unsigned)loop_counter,
884  point->v[X] * mm2local,
885  point->v[Y] * mm2local,
886  point->v[Z] * mm2local,
887  point->c.buc_rgb[0],
888  point->c.buc_rgb[1],
889  point->c.buc_rgb[2]);
890  bu_vls_strcat(str, buf);
891  loop_counter++;
892  }
893  break;
894  }
895  case RT_PNT_TYPE_SCA: {
896  register struct pnt_scale *point;
897  bu_vls_strcat(str, "point#, (point), (scale)\n");
898  for (BU_LIST_FOR(point, pnt_scale, &(((struct pnt_scale *)pnts->point)->l))) {
899  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f), (%f)\n",
900  (long unsigned)loop_counter,
901  point->v[X] * mm2local,
902  point->v[Y] * mm2local,
903  point->v[Z] * mm2local,
904  point->s);
905  bu_vls_strcat(str, buf);
906  loop_counter++;
907  }
908  break;
909  }
910  case RT_PNT_TYPE_NRM: {
911  register struct pnt_normal *point;
912  bu_vls_strcat(str, "point#, (point), (normal)\n");
913  for (BU_LIST_FOR(point, pnt_normal, &(((struct pnt_normal *)pnts->point)->l))) {
914  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f), (%f %f %f)\n",
915  (long unsigned)loop_counter,
916  point->v[X] * mm2local,
917  point->v[Y] * mm2local,
918  point->v[Z] * mm2local,
919  point->n[X],
920  point->n[Y],
921  point->n[Z]);
922  bu_vls_strcat(str, buf);
923  loop_counter++;
924  }
925  break;
926  }
927  case RT_PNT_TYPE_COL_SCA: {
928  register struct pnt_color_scale *point;
929  bu_vls_strcat(str, "point#, (point), (color), (scale)\n");
930  for (BU_LIST_FOR(point, pnt_color_scale, &(((struct pnt_color_scale *)pnts->point)->l))) {
931  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f), (%f %f %f), (%f)\n",
932  (long unsigned)loop_counter,
933  point->v[X] * mm2local,
934  point->v[Y] * mm2local,
935  point->v[Z] * mm2local,
936  point->c.buc_rgb[0],
937  point->c.buc_rgb[1],
938  point->c.buc_rgb[2],
939  point->s);
940  bu_vls_strcat(str, buf);
941  loop_counter++;
942  }
943  break;
944  }
945  case RT_PNT_TYPE_COL_NRM: {
946  register struct pnt_color_normal *point;
947  bu_vls_strcat(str, "point#, (point), (color), (normal)\n");
948  for (BU_LIST_FOR(point, pnt_color_normal, &(((struct pnt_color_normal *)pnts->point)->l))) {
949  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f), (%f %f %f), (%f %f %f)\n",
950  (long unsigned)loop_counter,
951  point->v[X] * mm2local,
952  point->v[Y] * mm2local,
953  point->v[Z] * mm2local,
954  point->c.buc_rgb[0],
955  point->c.buc_rgb[1],
956  point->c.buc_rgb[2],
957  point->n[X],
958  point->n[Y],
959  point->n[Z]);
960  bu_vls_strcat(str, buf);
961  loop_counter++;
962  }
963  break;
964  }
965  case RT_PNT_TYPE_SCA_NRM: {
966  register struct pnt_scale_normal *point;
967  bu_vls_strcat(str, "point#, (point), (scale), (normal)\n");
968  for (BU_LIST_FOR(point, pnt_scale_normal, &(((struct pnt_scale_normal *)pnts->point)->l))) {
969  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f), (%f), (%f %f %f)\n",
970  (long unsigned)loop_counter,
971  point->v[X] * mm2local,
972  point->v[Y] * mm2local,
973  point->v[Z] * mm2local,
974  point->s,
975  point->n[X],
976  point->n[Y],
977  point->n[Z]);
978  bu_vls_strcat(str, buf);
979  loop_counter++;
980  }
981  break;
982  }
983  case RT_PNT_TYPE_COL_SCA_NRM: {
984  register struct pnt_color_scale_normal *point;
985  bu_vls_strcat(str, "point#, (point), (color), (scale), (normal)\n");
986  for (BU_LIST_FOR(point, pnt_color_scale_normal, &(((struct pnt_color_scale_normal *)pnts->point)->l))) {
987  snprintf(buf, BUF_SZ, "%lu, \t (%f %f %f), (%f %f %f), (%f), (%f %f %f)\n",
988  (long unsigned)loop_counter,
989  point->v[X] * mm2local,
990  point->v[Y] * mm2local,
991  point->v[Z] * mm2local,
992  point->c.buc_rgb[0],
993  point->c.buc_rgb[1],
994  point->c.buc_rgb[2],
995  point->s,
996  point->n[X],
997  point->n[Y],
998  point->n[Z]);
999  bu_vls_strcat(str, buf);
1000  loop_counter++;
1001  }
1002  break;
1003  }
1004  default:
1005  bu_log("ERROR: unknown points primitive type (type=%d)\n", pnts->type);
1006  return 1;
1007  }
1008 
1009  return 0;
1010 }
1011 
1012 
1013 /*
1014  * Local Variables:
1015  * tab-width: 8
1016  * mode: C
1017  * indent-tabs-mode: t
1018  * c-file-style: "stroustrup"
1019  * End:
1020  * ex: shiftwidth=4 tabstop=8
1021  */
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
Definition: raytrace.h:800
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
#define SIZEOF_NETWORK_DOUBLE
Definition: cv.h:48
Definition: list.h:118
const mat_t bn_mat_identity
Matrix and vector functionality.
Definition: mat.c:46
if lu s
Definition: nmg_mod.c:3860
int rt_pnts_bbox(struct rt_db_internal *ip, point_t *min, point_t *max, const struct bn_tol *tol)
Definition: pnts.c:64
void bu_vls_strcat(struct bu_vls *vp, const char *s)
Definition: vls.c:368
#define VSET(a, b, c, d)
Definition: color.c:53
#define VSETALL(a, s)
Definition: color.c:54
#define SIZEOF_NETWORK_LONG
Definition: cv.h:46
void rt_pnts_ifree(struct rt_db_internal *internal)
Definition: pnts.c:663
Header file for the BRL-CAD common definitions.
HIDDEN unsigned char * pnts_unpack_double(unsigned char *buf, unsigned char *data, unsigned int count)
Definition: pnts.c:53
void bu_cv_htond(unsigned char *out, const unsigned char *in, size_t count)
#define HIDDEN
Definition: common.h:86
int rt_ell_plot(struct bu_list *, struct rt_db_internal *, const struct rt_tess_tol *, const struct bn_tol *, const struct rt_view_info *)
Definition: ell.c:793
#define RT_DB_INTERNAL_MAGIC
Definition: magic.h:158
int idb_major_type
Definition: raytrace.h:192
Definition: color.c:49
COMPLEX data[64]
Definition: fftest.c:34
#define RT_ADD_VLIST(hd, pnt, draw)
Definition: raytrace.h:1865
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
#define RT_ELL_INTERNAL_MAGIC
Definition: magic.h:91
int bu_color_to_rgb_floats(struct bu_color *cp, fastf_t *rgb)
Definition: color.c:220
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
#define BN_VLIST_LINE_MOVE
Definition: vlist.h:82
uint8_t * ext_buf
Definition: parse.h:216
int rt_pnts_import5(struct rt_db_internal *internal, const struct bu_external *external, const fastf_t *mat, const struct db_i *dbip)
Definition: pnts.c:354
#define BN_VLIST_LINE_DRAW
Definition: vlist.h:83
Coord * point
Definition: chull3d.cpp:52
void * bu_realloc(void *ptr, size_t siz, const char *str)
#define UNUSED(parameter)
Definition: common.h:239
Support for uniform tolerances.
Definition: tol.h:71
#define BU_LIST_WHILE(p, structure, hp)
Definition: list.h:410
uint32_t idb_magic
Definition: raytrace.h:191
int bu_color_from_rgb_floats(struct bu_color *cp, fastf_t *rgb)
Definition: color.c:235
HIDDEN unsigned char * pnts_pack_double(unsigned char *buf, unsigned char *data, unsigned int count)
Definition: pnts.c:44
#define BU_LIST_PUSH(hp, p)
Definition: list.h:246
#define RT_CK_DBI(_p)
Definition: raytrace.h:829
void rt_pnts_print(register const struct soltab *stp)
Definition: pnts.c:697
#define BU_LIST_INIT(_hp)
Definition: list.h:148
void * idb_ptr
Definition: raytrace.h:195
void bu_cv_ntohd(unsigned char *out, const unsigned char *in, size_t count)
const struct rt_functab OBJ[]
Definition: table.c:159
#define ID_PNTS
Collection of Points.
Definition: raytrace.h:512
void * st_specific
-> ID-specific (private) struct
Definition: raytrace.h:435
int rt_pnts_plot(struct bu_list *vhead, struct rt_db_internal *internal, const struct rt_tess_tol *ttol, const struct bn_tol *tol, const struct rt_view_info *info)
Definition: pnts.c:755
Definition: color.c:51
int rt_pnts_describe(struct bu_vls *str, const struct rt_db_internal *intern, int verbose, double mm2local)
Definition: pnts.c:832
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
#define BU_CK_LIST_HEAD(_p)
Definition: list.h:142
#define BU_CK_EXTERNAL(_p)
Definition: parse.h:224
#define BU_LIST_DEQUEUE(cur)
Definition: list.h:209
size_t ext_nbytes
Definition: parse.h:210
#define SIZEOF_NETWORK_SHORT
Definition: cv.h:45
HIDDEN void verbose(struct human_data_t *dude)
Definition: human.c:2008
Definition: vls.h:56
double fastf_t
Definition: defines.h:300
int rt_pnts_export5(struct bu_external *external, const struct rt_db_internal *internal, double local2mm, const struct db_i *dbip)
Definition: pnts.c:110
#define ID_ELL
Ellipsoid.
Definition: raytrace.h:461
Definition: color.c:50
#define RT_PNTS_INTERNAL_MAGIC
Definition: magic.h:114