コード例 #1
0
ファイル: zhull.c プロジェクト: iem-projects/pd-iemmatrix
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);
}
コード例 #2
0
ファイル: XEVI.c プロジェクト: SvenDowideit/clearlinux
Status XeviGetVisualInfo(
    register Display *dpy,
    VisualID *visual,
    int n_visual,
    ExtendedVisualInfo **evi_return,
    int *n_info_return)
{
    XExtDisplayInfo *info = find_display (dpy);
    register xEVIGetVisualInfoReq *req;
    xEVIGetVisualInfoReply rep;
    int sz_info, sz_xInfo, sz_conflict, sz_xConflict;
    VisualID32 *temp_conflict, *temp_visual, *xConflictPtr;
    VisualID *conflict;
    xExtendedVisualInfo *temp_xInfo;
    XVisualInfo *vinfo;
    register ExtendedVisualInfo *infoPtr;
    register xExtendedVisualInfo *xInfoPtr;
    register int n_data, visualIndex, vinfoIndex;
    Bool isValid;
    XeviCheckExtension (dpy, info, 0);
    if (!n_info_return || !evi_return) {
	return BadValue;
    }
    *n_info_return = 0;
    *evi_return = NULL;
    vinfo = XGetVisualInfo(dpy, 0, NULL, &sz_info);
    if (!vinfo) {
	return BadValue;
    }
    if (!n_visual || !visual) {		/* copy the all visual */
    	temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * sz_info);
    	n_visual = 0;
        for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++)
	    if (notInList(temp_visual, n_visual, vinfo[vinfoIndex].visualid))
	        temp_visual[n_visual++] = vinfo[vinfoIndex].visualid;
    }
    else {	/* check if the visual is valid */
        for (visualIndex = 0; visualIndex < n_visual; visualIndex++) {
	    isValid = False;
            for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++) {
	        if (visual[visualIndex] == vinfo[vinfoIndex].visualid) {
		    isValid = True;
		    break;
	        }
	    }
	    if (!isValid) {
		XFree(vinfo);
	        return BadValue;
	    }
	}
	temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * n_visual);
        for (visualIndex = 0; visualIndex < n_visual; visualIndex++)
	    temp_visual[visualIndex] = visual[visualIndex];
    }
    XFree(vinfo);
    LockDisplay(dpy);
    GetReq(EVIGetVisualInfo, req);
    req->reqType = info->codes->major_opcode;
    req->xeviReqType = X_EVIGetVisualInfo;
    req->n_visual = n_visual;
    SetReqLen(req, n_visual, 1);
    Data(dpy, (char *)temp_visual, n_visual * sz_VisualID32);
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	Xfree(temp_visual);
	return BadAccess;
    }
    Xfree(temp_visual);
    if ((rep.n_info < 65536) && (rep.n_conflicts < 65536)) {
	sz_info = rep.n_info * sizeof(ExtendedVisualInfo);
	sz_xInfo = rep.n_info * sz_xExtendedVisualInfo;
	sz_conflict = rep.n_conflicts * sizeof(VisualID);
	sz_xConflict = rep.n_conflicts * sz_VisualID32;
	*evi_return = Xmalloc(sz_info + sz_conflict);
	temp_xInfo = Xmalloc(sz_xInfo);
	temp_conflict = Xmalloc(sz_xConflict);
    } else {
	sz_xInfo = sz_xConflict = 0;
	*evi_return = NULL;
	temp_xInfo = NULL;
	temp_conflict = NULL;
    }
    if (!*evi_return || !temp_xInfo || !temp_conflict) {
	_XEatDataWords(dpy, rep.length);
	UnlockDisplay(dpy);
	SyncHandle();
	if (*evi_return) {
	   Xfree(*evi_return);
	   *evi_return = NULL;
	}
	if (temp_xInfo)
	   Xfree(temp_xInfo);
	if (temp_conflict)
	   Xfree(temp_conflict);
	return BadAlloc;
    }
    _XRead(dpy, (char *)temp_xInfo, sz_xInfo);
    _XRead(dpy, (char *)temp_conflict, sz_xConflict);
    UnlockDisplay(dpy);
    SyncHandle();
    infoPtr = *evi_return;
    xInfoPtr = temp_xInfo;
    xConflictPtr = temp_conflict;
    n_data = rep.n_info;
    conflict = (VisualID *)(infoPtr + n_data);
    while (n_data-- > 0) {
	infoPtr->core_visual_id		= xInfoPtr->core_visual_id;
	infoPtr->screen			= xInfoPtr->screen;
	infoPtr->level			= xInfoPtr->level;
	infoPtr->transparency_type	= xInfoPtr->transparency_type;
	infoPtr->transparency_value	= xInfoPtr->transparency_value;
	infoPtr->min_hw_colormaps	= xInfoPtr->min_hw_colormaps;
	infoPtr->max_hw_colormaps	= xInfoPtr->max_hw_colormaps;
	infoPtr->num_colormap_conflicts = xInfoPtr->num_colormap_conflicts;
	infoPtr->colormap_conflicts	= conflict;
	conflict += infoPtr->num_colormap_conflicts;
	infoPtr++;
	xInfoPtr++;
    }
    n_data = rep.n_conflicts;
    conflict = (VisualID *)(infoPtr);
    while (n_data-- > 0)
       *conflict++ = *xConflictPtr++;
    Xfree(temp_xInfo);
    Xfree(temp_conflict);
    *n_info_return = rep.n_info;
    return Success;
}
コード例 #3
0
ファイル: PointerListTest.cpp プロジェクト: mmanley/Antares
void PointerListTest::BinarySearchIndexTest()
{
	_PointerList_ list;
	Initialize(list, 10);
	list.SortItems(Item::Compare);
	assert(IsSorted(list));
	
	Item notInListLow(NOT_USED_ID);
	Item notInListHigh(NOT_USED_ID_HIGH);
	gData = (void*)0x4711;
	
	for (int32 i = 0; i < 10; i ++) {
		Item* item = (Item*)list.ItemAt(i);
		assert(item != NULL);
		Value value(item->Value());

		int index = IndexOf(list, item->Value());
		int searchIndex;
		searchIndex = list.BinarySearchIndex(item, Item::Compare);
		assert(index == searchIndex);

		searchIndex = list.BinarySearchIndex(item, ::Compare, gData);
		assert(index == searchIndex);
		
		searchIndex = list.BinarySearchIndexByPredicate(&value, ValuePredicate);
		assert(index == searchIndex);

		// notInListLow
		searchIndex = list.BinarySearchIndex(&notInListLow, Item::Compare);
		assert(searchIndex == -1);

		searchIndex = list.BinarySearchIndex(&notInListLow, ::Compare, gData);
		assert(searchIndex == -1);
		
		value.value = notInListLow.Value();
		searchIndex = list.BinarySearchIndexByPredicate(&value, ValuePredicate);
		assert(searchIndex == -1);

		// notInListHigh
		searchIndex = list.BinarySearchIndex(&notInListHigh, Item::Compare);
		assert(searchIndex == -(list.CountItems()+1));

		searchIndex = list.BinarySearchIndex(&notInListHigh, ::Compare, gData);
		assert(searchIndex == -(list.CountItems()+1));
		
		value.value = notInListHigh.Value();
		searchIndex = list.BinarySearchIndexByPredicate(&value, ValuePredicate);
		assert(searchIndex == -(list.CountItems()+1));
	}

	MakeEmpty(list);
	
	for (int i = 0; i < 3; i ++) {
		list.AddItem(new Item(2 * i));
	}
	Item notInList(3);
	assert(IndexOf(list, 3) == -1);
	
	int index = list.BinarySearchIndex(&notInList, Item::Compare);
	assert (index == -3);
	
	index = list.BinarySearchIndex(&notInList, ::Compare, gData);
	assert (index == -3);
	
	Value value(notInList.Value());
	index = list.BinarySearchIndexByPredicate(&value, ValuePredicate);
	assert (index == -3);
		
	MakeEmpty(list);
}
コード例 #4
0
ファイル: zhull.c プロジェクト: iem-projects/pd-iemmatrix
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);
  }
}