static void appendExteriorPoints(zhull_t *zh) { index_t i; vector_t center = initVector(0.0f,0.0f,0.0f); list_t facet_delete_list=emptyList(); facet_t *f; center=averageListedPoints(zh->pts,zh->used_pts); printf("central point\n"); printVector(center); printf("\n"); for (i=0; i<getLength(zh->facets); i++) { f=getFacetByIndex(zh->facets,i); printf("distance of plane %lu, d=%5.2f\n",(unsigned long)i, distancePointPlane(center,f->plane)); if (distancePointPlane(center,f->plane)>-0.5f) { appendToList(&facet_delete_list,entry_makePointer(f)); } } printList(facet_delete_list); removeFacetByPointerList(zh,facet_delete_list); freeList(&facet_delete_list); }
static void dividePointsBetweenNewFacets ( zhull_t * const zh, const list_t assoc, const list_t new_facets) { index_t i,j; facet_t *f; list_t point_inside_facet_list=emptyList(); float d; entry_t e; for (i=0; i<getLength(assoc); i++) { e=getEntry(assoc,i); int idx = entry_getIndex(&e); for (j=0; j<getLength(new_facets); j++) { f=getFacetByIndex(new_facets,j); d=distancePointPlane(getPoint(zh->pts,idx), f->plane); if (d>=TOL_OUTSIDEPOINT) { break; } else if (d>=TOL_INSIDEPOINT) { appendToList(&point_inside_facet_list,entry_makePointer(f)); } } if (d>=TOL_OUTSIDEPOINT) { appendToList(&(f->outsideset), e); if (notInList(entry_makePointer(f),zh->facets_with_outsidepoints)) { appendToList(&(zh->facets_with_outsidepoints),entry_makePointer(f)); } if (f->maxdistance<d) { f->maxdistance=d; f->farthest_outside_point=idx; } } else { if (getLength(point_inside_facet_list)>0) { for (j=0; j<getLength(point_inside_facet_list); j++) { f=getFacetByIndex(point_inside_facet_list,j); if (notInList(e,f->insideset)) { appendToList(&(f->insideset),e); } } appendListToList(&(zh->facets_with_insidepoints),point_inside_facet_list); uniquefyListEntries(&(zh->facets_with_insidepoints)); } } } freeList(&point_inside_facet_list); }
// // returns the projection of the given point on the normal and distance specified plane // math::Vec3f projectPointOnPlane( const math::Vec3f &normal, const float &distance, const math::Vec3f &point ) { return point - distancePointPlane( point, normal, distance )*normal; }
static void removeVisibleFacetsGetHorizonAndAvailablePoints( zhull_t * const zh, index_t point_index, facet_t *f, list_t *horizon_fcts, list_t *horizon_fcts_edges, list_t *other_horizon_edges, list_t *avail_points) { index_t j,k; facet_t *n; float d; list_t visible_fcts = emptyList(); list_t fcts_to_visit = emptyList(); list_t fcts_visited = emptyList(); // list_t list_for_printing = emptyList(); *avail_points = emptyList(); *horizon_fcts = emptyList(); *horizon_fcts_edges = emptyList(); *other_horizon_edges = emptyList(); d=distancePointPlane(getPoint(zh->pts,point_index),f->plane); // printf("distance %5.2f\n",d); appendToList(&fcts_to_visit,entry_makePointer(f)); if (d>=TOL_OUTSIDEPOINT) { while (getLength(fcts_to_visit)>0) { // visiting only visible facets // horizon: edges to invisible or coincident neighbors f=getFacetByIndex(fcts_to_visit,0); appendToList(&visible_fcts,entry_makePointer(f)); appendListToList(avail_points, f->outsideset); for (j=0; j<getLength(f->neighbors); j++) { n=getFacetByIndex(f->neighbors,j); d=distancePointPlane(getPoint(zh->pts,point_index),n->plane); if (d>=TOL_OUTSIDEPOINT) { // visit visible neighbors appendToList(&fcts_to_visit,entry_makePointer(n)); } else { // horizon: coincident or invisible neighbors k=findValueInList(getEntry(f->corners,(j+1)%getLength(f->corners)), n->corners); appendToList(horizon_fcts,entry_makePointer(n)); appendToList(horizon_fcts_edges,entry_makeIndex(k)); appendToList(other_horizon_edges,entry_makeIndex(getNumPoints(zh->pts))); } } removeValueFromList(&fcts_to_visit,entry_makePointer(f)); appendToList(&fcts_visited,entry_makePointer(f)); removeValueListFromList(&fcts_to_visit,fcts_visited); } // printf("removing facets\n"); // list_for_printing=findValueListInList(visible_fcts,zh->facets); // printList(list_for_printing); // freeList(&list_for_printing); removeFacetByPointerList(zh,visible_fcts); freeList(&visible_fcts); freeList(&fcts_to_visit); freeList(&fcts_visited); sortHorizonEdges(horizon_fcts, horizon_fcts_edges, other_horizon_edges); //printHorizonEdges(horizon_fcts,horizon_fcts_edges,other_horizon_edges); } else if (d>=TOL_INSIDEPOINT) { // all coincident surfaces shall be removed // horizon might not be defined by facets while (getLength(fcts_to_visit)>0) { f=getFacetByIndex(fcts_to_visit,0); appendToList(&visible_fcts,entry_makePointer(f)); appendListToList(avail_points, f->outsideset); appendListToList(avail_points, f->insideset); for (j=0; j<getLength(f->neighbors); j++) { n=getFacetByIndex(f->neighbors,j); d=distancePointPlane(getPoint(zh->pts,point_index),n->plane); if (d>=TOL_INSIDEPOINT) { // coincident facet if (notInList(entry_makePointer(n),visible_fcts)) { appendToList(&fcts_to_visit,entry_makePointer(n)); } if ((innerProduct(f->plane.normal,n->plane.normal)< -1.0f+TOL_DEGENERATE)&& (distancePointLineOnPlane(getPoint(zh->pts,point_index), getLine(zh,f,j), f->plane)<TOL_INSIDEPOINT)) { // coincident facets with opposite surface orientation // yield an edge to keep despite all facets will be removed // as soon as edge is invisible to point appendToList(horizon_fcts,entry_makePointer(0)); appendToList(other_horizon_edges, getEntry(f->corners,j)); appendToList(horizon_fcts_edges, getEntry(f->corners,(j+1)%getLength(f->corners))); } } else { // invisible facet forms horizon that persists k=findValueInList(getEntry(f->corners,(j+1)%getLength(f->corners)), n->corners); appendToList(horizon_fcts,entry_makePointer(n)); appendToList(horizon_fcts_edges,entry_makeIndex(k)); appendToList(other_horizon_edges,entry_makeIndex(getNumPoints(zh->pts))); } } removeValueFromList(&fcts_to_visit,entry_makePointer(f)); appendToList(&fcts_visited,entry_makePointer(f)); removeValueListFromList(&fcts_to_visit,fcts_visited); } // printf("removing facets\n"); // list_for_printing=findValueListInList(visible_fcts,zh->facets); // printList(list_for_printing); // freeList(&list_for_printing); removeFacetByPointerList(zh,visible_fcts); sortHorizonEdges(horizon_fcts, horizon_fcts_edges,other_horizon_edges); //printHorizonEdges(horizon_fcts,horizon_fcts_edges,other_horizon_edges); freeList(&visible_fcts); freeList(&fcts_to_visit); freeList(&fcts_visited); } }