BRL-CAD
bn_chull3d.c
Go to the documentation of this file.
1 /* B N _ C H U L L . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2013-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 
21 #include "common.h"
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "bu.h"
28 #include "vmath.h"
29 #include "bn.h"
30 
31 int
32 main(int UNUSED(argc), const char **UNUSED(argv))
33 {
34 
35  /* Cube */
36  {
37  int i = 0;
38  int retval = 0;
39  int fc = 0;
40  int vc = 0;
41  point_t *vert_array;
42  int *faces;
43  point_t *input_verts = (point_t *)bu_calloc(8, sizeof(point_t), "vertex array");
44  VSET(input_verts[0], -1000.0, 1000.0, 1000.0);
45  VSET(input_verts[1], 1000.0, -1000.0, 1000.0);
46  VSET(input_verts[2], 1000.0, 1000.0, 1000.0);
47  VSET(input_verts[3], -1000.0, -1000.0, 1000.0);
48  VSET(input_verts[4], 1000.0, 1000.0, -1000.0);
49  VSET(input_verts[5], -1000.0, -1000.0, -1000.0);
50  VSET(input_verts[6], -1000.0, 1000.0, -1000.0);
51  VSET(input_verts[7], 1000.0, -1000.0, -1000.0);
52 
53  retval = bn_3d_chull(&faces, &fc, &vert_array, &vc, (const point_t *)input_verts, 9);
54  bu_log("Test #001: Cube:\n");
55  bu_log(" Vertices:\n");
56  for(i = 0; i < vc; i++) {
57  point_t p1;
58  VMOVE(p1,vert_array[i]);
59  bu_log(" actual[%d]: %f, %f, %f\n", i, p1[0], p1[1], p1[2]);
60  }
61  bu_log(" Faces:\n");
62  for(i = 0; i < fc; i++) {
63  bu_log(" face %d: %d, %d, %d\n", i, faces[i*3], faces[i*3+1], faces[i*3+2]);
64  }
65  if (retval != 3) {return -1;} else {bu_log("Cube Test Passed!\n");}
66  }
67 
68  /* Cube with center point */
69  {
70  int i = 0;
71  int retval = 0;
72  int fc = 0;
73  int vc = 0;
74  point_t *vert_array;
75  int *faces;
76  point_t *input_verts = (point_t *)bu_calloc(9, sizeof(point_t), "vertex array");
77  VSET(input_verts[0], 0.0, 0.0, 0.0);
78  VSET(input_verts[1], 2.0, 0.0, 0.0);
79  VSET(input_verts[2], 2.0, 2.0, 0.0);
80  VSET(input_verts[3], 0.0, 2.0, 0.0);
81  VSET(input_verts[4], 0.0, 0.0, 2.0);
82  VSET(input_verts[5], 2.0, 0.0, 2.0);
83  VSET(input_verts[6], 2.0, 2.0, 2.0);
84  VSET(input_verts[7], 0.0, 2.0, 2.0);
85  VSET(input_verts[8], 1.0, 1.0, 1.0);
86 
87  retval = bn_3d_chull(&faces, &fc, &vert_array, &vc, (const point_t *)input_verts, 9);
88  bu_log("Test #002: Cube With Center Point:\n");
89  bu_log(" Vertices:\n");
90  for(i = 0; i < vc; i++) {
91  point_t p1;
92  VMOVE(p1,vert_array[i]);
93  bu_log(" actual[%d]: %f, %f, %f\n", i, p1[0], p1[1], p1[2]);
94  }
95  bu_log(" Faces:\n");
96  for(i = 0; i < fc; i++) {
97  bu_log(" face %d: %d, %d, %d\n", i, faces[i*3], faces[i*3+1], faces[i*3+2]);
98  }
99  if (retval != 3) {return -1;} else {bu_log("Cube With Center Point Test Passed!\n");}
100  }
101 
102  /* Flat triangles */
103  {
104  int i = 0;
105  int retval = 0;
106  int fc = 0;
107  int vc = 0;
108  point_t *vert_array;
109  int *faces;
110  point_t *input_verts = (point_t *)bu_calloc(5, sizeof(point_t), "vertex array");
111  VSET(input_verts[0], 0.0, 0.0, 0.0);
112  VSET(input_verts[1], 3.0, 3.0, 3.0);
113  VSET(input_verts[2], 1.0, 1.0, 1.0);
114  VSET(input_verts[3], 5.0, 1.0, 1.0);
115  VSET(input_verts[4], 2.0, 2.0, 2.0);
116 
117  retval = bn_3d_chull(&faces, &fc, &vert_array, &vc, (const point_t *)input_verts, 9);
118  bu_log("Test #003: Flat Triangles:\n");
119  bu_log(" Vertices:\n");
120  for(i = 0; i < vc; i++) {
121  point_t p1;
122  VMOVE(p1,vert_array[i]);
123  bu_log(" actual[%d]: %f, %f, %f\n", i, p1[0], p1[1], p1[2]);
124  }
125  if (retval != 2) {return -1;} else {bu_log("Flat Triangles Passed!\n");}
126  }
127 
128 
129 
130  return 0;
131 }
132 
133 
134 /** @} */
135 /*
136  * Local Variables:
137  * mode: C
138  * tab-width: 8
139  * indent-tabs-mode: t
140  * c-file-style: "stroustrup"
141  * End:
142  * ex: shiftwidth=4 tabstop=8
143  */
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int main(int argc, const char **argv)
Definition: bn_chull3d.c:32
#define VSET(a, b, c, d)
Definition: color.c:53
Header file for the BRL-CAD common definitions.
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
int bn_3d_chull(int **faces, int *num_faces, point_t **vertices, int *num_vertices, const point_t *input_points_3d, int num_input_pnts)
Find 3D point convex hull for unordered point sets.
Definition: chull3d.cpp:1265
#define UNUSED(parameter)
Definition: common.h:239