1 #ifndef BNDSURFACE_INCLUDED
2 #define BNDSURFACE_INCLUDED
7 #include <ext/hash_map>
80 #define MAX_GRID_DIV 1023
104 bbmin = bbmax = node_array[0];
107 for(
unsigned int i=1;
i<numv;
i++)
111 if(v[0] < bbmin[0]) bbmin[0]=v[0];
112 if(v[1] < bbmin[1]) bbmin[1]=v[1];
113 if(v[2] < bbmin[2]) bbmin[2]=v[2];
115 if(v[0] > bbmax[0]) bbmax[0]=v[0];
116 if(v[1] > bbmax[1]) bbmax[1]=v[1];
117 if(v[2] > bbmax[2]) bbmax[2]=v[2];
123 MeshBndSurf():gSpace(NULL),node_array(NULL),tri_array(NULL),numv(0),numt(0){}
126 unsigned int nt):node_array(n),tri_array(t),numv(nv),numt(nt)
128 compute_bbox(bbmin, bbmax);
130 for(
unsigned int i=0;
i<nt; ++
i){
131 Point3D p(n[t[
i][0]][0], n[t[i][0]][1], n[t[i][0]][2]);
132 Point3D q(n[t[i][1]][0], n[t[i][1]][1], n[t[i][1]][2]);
133 Point3D r(n[t[i][2]][0], n[t[i][2]][1], n[t[i][2]][2]);
134 gSpace->insertRange(t[i], p,q,r);
140 delete [] node_array;
156 vector<Tri> * hitTri = gSpace->get_cell_range(a,b);
166 for(vector<Tri>::iterator it = hitTri->begin(); it !=hitTri->end(); it++)
171 v1[
j]=(node_array[cur[0]])[
j];
172 v2[
j]=(node_array[cur[1]])[
j];
173 v3[
j]=(node_array[cur[2]])[
j];
178 std::cerr <<
"XXXX Ray " << p <<
" to " << d
179 <<
" Tri " << std::endl;
180 std::cerr << node_array[cur[0]] << std::endl;
181 std::cerr << node_array[cur[1]] << std::endl;
182 std::cerr << node_array[cur[2]] << std::endl << std::endl;
187 std::cerr <<
"0000 Ray "<< p <<
" to" << d
188 <<
" Tri " << std::endl;
189 std::cerr << node_array[cur[0]] << std::endl;
190 std::cerr << node_array[cur[1]] << std::endl;
191 std::cerr << node_array[cur[2]] << std::endl << std::endl;
197 void initialize(
double * nodes,
int * triangles,
unsigned int nv,
unsigned int nt,
int divisions = 50)
204 cerr <<
"Grid divsisions on longest dimension must be less than or equal to "
210 if (node_array != NULL)
211 delete [] node_array;
213 node_array =
new Vec3D[numv];
214 for(
unsigned int i=0;
i<numv;
i++)
218 (node_array[
i])[
j]=nodes[
i*3+
j];
223 if (tri_array != NULL)
226 tri_array =
new Tri[numt];
227 for(
unsigned int i=0;
i<numt;
i++)
231 (tri_array[
i])[
j]=triangles[
i*3+
j];
235 compute_bbox(bbmin, bbmax);
240 for(
unsigned int i=0;
i<nt; ++
i)
242 Point3D p(node_array[tri_array[
i][0]][0], node_array[tri_array[i][0]][1], node_array[tri_array[i][0]][2]);
243 Point3D q(node_array[tri_array[i][1]][0], node_array[tri_array[i][1]][1], node_array[tri_array[i][1]][2]);
244 Point3D r(node_array[tri_array[i][2]][0], node_array[tri_array[i][2]][1], node_array[tri_array[i][2]][2]);
245 gSpace->insertRange(tri_array[i], p,q,r);
264 vector<Tri> * hitTri = gSpace->get_cell_range(a,b);
265 if(hitTri->size() == 0){
281 for(vector<Tri>::iterator it = hitTri->begin(); it !=hitTri->end(); it++)
286 v1[
j]=(node_array[cur[0]])[
j];
287 v2[
j]=(node_array[cur[1]])[
j];
288 v3[
j]=(node_array[cur[2]])[
j];
MeshBndSurf(Vec3D *n, Tri *t, unsigned int nv, unsigned int nt)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
void compute_bbox(Point3D &bbmin, Point3D &bbmax)
void initialize(double *nodes, int *triangles, unsigned int nv, unsigned int nt, int divisions=50)
bool rayIntersectsTriangle(double *p, double *d, double *v0, double *v1, double *v2, Vec3D &I)
bool intersection(const Vec3D &p, const Vec3D &d, Vec3D &x)
bool intersection(double *p, double *d, double *x)