int polyOverlap(Point p, Poly * pp, Point q, Poly * qp) { Point op, cp; Point oq, cq; /* translate bounding boxes */ addPt(&op, p, pp->origin); addPt(&cp, p, pp->corner); addPt(&oq, q, qp->origin); addPt(&cq, q, qp->corner); /* If bounding boxes don't overlap, done */ if (!pintersect(op, cp, oq, cq)) return 0; if (ISBOX(pp) && ISBOX(qp)) return 1; if (ISCIRCLE(pp) && ISCIRCLE(qp)) { double d = (pp->corner.x - pp->origin.x + qp->corner.x - qp->origin.x); double dx = p.x - q.x; double dy = p.y - q.y; if ((dx * dx + dy * dy) > (d * d) / 4.0) return 0; else return 1; } if (tp1 == NULL) { tp1 = N_GNEW(maxcnt, Point); tp2 = N_GNEW(maxcnt, Point); } transCopy(pp->verts, pp->nverts, p, tp1); transCopy(qp->verts, qp->nverts, q, tp2); return (edgesIntersect(tp1, tp2, pp->nverts, qp->nverts) || (inBox(*tp1, oq, cq) && inPoly(tp2, qp->nverts, *tp1)) || (inBox(*tp2, op, cp) && inPoly(tp1, pp->nverts, *tp2))); }
cMesh::cMesh(const std::string & Filename, bool doAdjacence) { PlyFile * thePlyFile; int nelems; char **elist; int file_type; float version; int nprops; int num_elems; char *elem_name; thePlyFile = ply_open_for_reading( const_cast<char *>(Filename.c_str()), &nelems, &elist, &file_type, &version); ELISE_ASSERT(thePlyFile != NULL, "cMesh3D.cpp: cMesh::cMesh, cannot open ply file for reading"); for (int i = 0; i < nelems; i++) { elem_name = elist[i]; ply_get_element_description (thePlyFile, elem_name, &num_elems, &nprops); //printf ("element %s %d\n", elem_name, num_elems); if (equal_strings ("vertex", elem_name)) { ply_get_property (thePlyFile, elem_name, &props[0]); ply_get_property (thePlyFile, elem_name, &props[1]); ply_get_property (thePlyFile, elem_name, &props[2]); for (int j = 0; j < num_elems; j++) { sVertex *vert = (sVertex *) malloc (sizeof(sVertex)); ply_get_element (thePlyFile, vert); //ajout du point addPt(Pt3dr(vert->x, vert->y, vert->z)); //printf ("vertex: %g %g %g\n", vert->x, vert->y, vert->z); } } else if (equal_strings ("face", elem_name)) { ply_get_property ( thePlyFile, elem_name, &face_props[0]); for (int j = 0; j < num_elems; j++) { sFace *theFace = (sFace *) malloc (sizeof (sFace)); ply_get_element (thePlyFile, theFace); vector <int> vIndx; for (int aK =0; aK < theFace->nverts; ++aK) vIndx.push_back(theFace->verts[aK]); //ajout du triangle addTriangle(cTriangle(this, vIndx, j)); } } } if (doAdjacence) //remplissage du graphe d'adjacence { int cpt; int id0a, id1a, id2a; int id0b, id1b, id2b; int idc0, idc1; //index des sommets communs id0a = id1a = id2a = idc0 = idc1 = -1; id0b = id1b = id2b = -2; for (int aK = 0; aK < getFacesNumber(); ++aK) { mTriangles[aK].getVertexesIndexes(id0a, id1a, id2a); for (int bK=aK; bK < getFacesNumber(); ++bK) { mTriangles[bK].getVertexesIndexes(id0b, id1b, id2b); cpt = 0; if((id0b == id0a)||(id1b == id0a)||(id2b == id0a)) {cpt++; idc0 = id0a;} if((id0b == id1a)||(id1b == id1a)||(id2b == id1a)) { if (cpt) idc1 = id1a; else idc0 = id1a; cpt++; } if((id0b == id2a)||(id1b == id2a)||(id2b == id2a)) { if (cpt) idc1 = id2a; else idc0 = id2a; cpt++; } if (cpt == 2) { #ifdef _DEBUG printf ("found adjacent triangles : %d %d - vertex : %d %d\n", aK, bK, idc0, idc1); #endif addEdge(cEdge(aK, bK, idc0, idc1)); int idx = getEdgesNumber() - 1; //cout << "adding edge " << idx << endl; mTriangles[aK].addEdge(idx); mTriangles[bK].addEdge(idx); } } } } ply_close (thePlyFile); }