示例#1
0
A2(PUBLIC, OSErr, ufsPBOpenWD, WDPBPtr, pb, BOOLEAN, a)	/* INTERNAL */
{
    OSErr err;
    ParamBlockRec newpb;
    struct stat sbuf;
    char *pathname, *filename, *endname;
    VCBExtra *vcbp;
    LONGINT dirid;

    newpb.ioParam.ioNamePtr = pb->ioNamePtr;
    newpb.ioParam.ioVRefNum = pb->ioVRefNum;

    err = ROMlib_nami(&newpb, Cx(pb->ioWDDirID), NoIndex, &pathname, &filename,
						 &endname, TRUE, &vcbp, &sbuf);
    if (err == noErr) {
        LONGINT l;

	ROMlib_automount (pathname);
        vcbp = (VCBExtra *) ROMlib_vcbbybiggestunixname (pathname);
	if (S_ISDIR (sbuf.st_mode))
	    dirid = ST_INO (sbuf);
	else
	    dirid = Cx(pb->ioWDDirID);
	if (dirid == vcbp->u.ufs.ino)
	    dirid = 2;
	l = dirid;
	if (S_ISDIR (sbuf.st_mode))
	  ROMlib_dbm_store (vcbp, pathname, &l, TRUE);
	free (pathname);
	err = ROMlib_mkwd(pb, (VCB *) vcbp, dirid, Cx(pb->ioWDProcID));
    }
    return err;
}
示例#2
0
bool DrawingTouch::update(QBrush *color)
{
    bool wasVisible = false;
    if (ellipse) {
        wasVisible = ellipse->isVisible();
        ellipse->setVisible(TrackingId() >= 0);
    }
    else {
        ellipse = scene->addEllipse(QRectF(Cx() - radius, Cy() - radius,
                                           2 * radius, 2 * radius));
    }
    if (TrackingId() >= 0) {
        QRectF rect = ellipse->rect();
        rect.moveCenter(QPointF(Cx(), Cy()));
        ellipse->setRect(rect);
        ellipse->setPen(Pressed() ? pressedPen : releasedPen);
        if (!wasVisible) {
            ellipse->setBrush(*color);
            ellipse->show();
            return true;
        }
   }

    return false;
}
示例#3
0
文件: ger.hpp 项目: TRIQS/triqs
  typename std::enable_if<is_blas_lapack_type<typename VTX::value_type>::value && have_same_value_type<VTX, VTY, MT>::value>::type
  ger(typename VTX::value_type alpha, VTX const &X, VTY const &Y, MT &A) {
    static_assert(is_amv_value_or_view_class<MT>::value, "ger : A must be a matrix or a matrix_view");
    if ((first_dim(A) != Y.size()) || (second_dim(A) != X.size()))
      TRIQS_RUNTIME_ERROR << "Dimension mismatch in ger : A : " << get_shape(A()) << " while X : " << get_shape(X()) << " and Y : " << get_shape(Y());
    const_qcache<VTX> Cx(X); // mettre la condition a la main
    const_qcache<VTY> Cy(Y); // mettre la condition a la main
    reflexive_qcache<MT> Ca(A);
    if (Ca().memory_layout_is_c()) // tA += alpha y tx
      f77::ger(get_n_rows(Ca()), get_n_cols(Ca()), alpha, Cy().data_start(), Cy().stride(), Cx().data_start(), Cx().stride(), Ca().data_start(),
               get_ld(Ca()));
    else
      f77::ger(get_n_rows(Ca()), get_n_cols(Ca()), alpha, Cx().data_start(), Cx().stride(), Cy().data_start(), Cy().stride(), Ca().data_start(),
               get_ld(Ca()));

    /* std::cerr << " Meme labout  C"<< Ca().memory_layout_is_c()  << "  "<<A.memory_layout_is_c()<<std::endl ;
   std::cerr<< " has_contiguous_data(A) : "<< has_contiguous_data(A) << std::endl;
   std::cerr<< Ca()<< std::endl;
   std::cerr<< Ca()(0,0) <<  "  "<< Ca()(1,0) <<  "  "<< Ca()(0,1) <<  "  "<< Ca()(1,1) <<  "  "<< std::endl;
   std::cerr<< Ca().data_start()[0]<< "  "<< Ca().data_start()[1]<< "  "<< Ca().data_start()[2]<< "  " << Ca().data_start()[3]<< "  "<<std::endl;

   std::cerr<< A<< std::endl;
   std::cerr<< A(0,0) <<  "  "<< A(1,0) <<  "  "<< A(0,1) <<  "  "<< A(1,1) <<  "  "<< std::endl;
   std::cerr<< A.data_start()[0]<< "  "<< A.data_start()[1]<< "  "<< A.data_start()[2]<< "  " << A.data_start()[3]<< "  "<<std::endl;
*/
  }
示例#4
0
A1(PUBLIC, OSErr, ROMlib_seteof, fcbrec *, fp)	/* INTERNAL */
{
    ULONGINT leof, peof, curloc;
    LONGINT fd;
    Single_descriptor d;
    Single_ID idwanted;
    INTEGER i;
    OSErr err;

    fd = fp->fcfd;
    leof = Cx(fp->fcleof);
    err = noErr;
    if (fd == fp->hiddenfd) {	/* mixed file */
	idwanted = IDWANTED(fp);
	if (getsetentry(Get, fd, idwanted, &d, &peof)) {
	    if (leof > peof) {
		gui_assert(0);	/* TODO: We need to move stuff around.
			 	   There are many things we could do */
	    } else if (leof < peof) {
		d.length = CL(leof);
		getsetentry(Set, fd, idwanted, &d, NULL);
	    }
	} else
	  {
	    err = fsDSIntErr;
	    warning_unexpected ("getsetentry (Get, %d, %d) failed", fd,
				idwanted);
	  }
	
    } else {			/* pure file */
	peof = Cx(fp->fcPLen);
	if (leof > peof)
	    writebyteat(fd, leof-1);
	else if (leof < peof) {
	    curloc = lseek(fd, 0L, L_INCR);
	    ftruncate(fd, leof);
	    if (curloc > leof)
		lseek(fd, leof, L_SET);
	}
	peof = leof;
    }
    if (err == noErr) {
	for (i = 0; i < NFCB; i++) {
	    if (ROMlib_fcblocks[i].fdfnum == fp->fdfnum &&
				     ROMlib_fcblocks[i].fcvptr == fp->fcvptr &&
				     (ROMlib_fcblocks[i].fcflags & fcfisres) ==
						    (fp->fcflags & fcfisres)) {
		ROMlib_fcblocks[i].fcleof  = CL(leof);
		ROMlib_fcblocks[i].fcPLen = CL(peof);
	    }
	}
    }
    fs_err_hook (err);
    return err;
}
示例#5
0
A5(PRIVATE, BOOLEAN, getsetentry, GetOrSetType, gors, LONGINT, fd,
   Single_ID, sid, Single_descriptor *, savesdp,
   ULONGINT *, lengthp)
{
    LONGINT saveloc;
    struct defaulthead *dfp;
    INTEGER nread;
    Single_descriptor *sdp;
    char buf[OURBSIZE];
    BOOLEAN retval;
    INTEGER n;

    retval = FALSE;
    saveloc = lseek(fd, 0L, L_INCR);
    lseek(fd, 0L, L_SET);
    nread = read(fd, buf, sizeof(buf));
    dfp = (struct defaulthead *) buf;
    if (nread >= (int) sizeof(struct defaulthead)
	&& (dfp->head.magic == CLC(SINGLEMAGIC)
	    || dfp->head.magic == CLC(DOUBLEMAGIC)
	    || dfp->head.magic == SINGLEMAGIC
	    || dfp->head.magic == DOUBLEMAGIC)) {
	n = MIN(Cx(dfp->head.nentries),
		((nread - (int) sizeof(Single_header)) /
		 (int) sizeof(Single_descriptor)));
	for (sdp = dfp->desc; --n >= 0 && Cx(sdp->id) != sid; ++sdp)
	    ;
	if (n >= 0) {
	    switch (gors) {
	    case Get:
		*savesdp = *sdp;
		if (n == 0) {
		    if (lengthp)
			*lengthp = 0x7FFFFFFF;	/* unlimited */
		} else
		    if (lengthp)
			*lengthp = CL(sdp[1].offset) - CL(sdp[0].offset);
		break;
	    case Set:
		*sdp = *savesdp;
		lseek(fd, 0L, L_SET);
		write(fd, buf, nread);
		break;
	    default:
		gui_assert(0);
		break;
	    }
	    retval = TRUE;
	}
    }
    lseek(fd, saveloc, L_SET);
    return retval;
}
示例#6
0
文件: scrap.c 项目: LarBob/executor
P3(PUBLIC pascal trap, LONGINT, PutScrap, LONGINT, len, ResType, rest, Ptr, p)
{
    OSErr retval;
    LONGINT l, swappedlen;
    INTEGER f;

    LONGINT *lp;

    if (Cx(ScrapState) < 0) {
        retval = ZeroScrap();
	if (retval != noErr)
/*-->*/	    return(retval);
    }
#if defined(X) || defined(NEXTSTEP) || defined (SDL)
    PutScrapX(rest, len, (char *) p, CW (ScrapCount));
#endif /* defined(X) */
    if (Cx(ScrapState) == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
/*-->*/     return(retval);
        SetFPos(f, fsFromStart, (LONGINT)Cx(ScrapSize));
        l = 4;
	rest = CL(rest);
        FSWriteAll(f, &l, (Ptr) &rest);
        l = 4;
	swappedlen = CL(len);
        FSWriteAll(f, &l, (Ptr) &swappedlen);
        l = len = (len + 1) & -2L;
        FSWriteAll(f, &len, p);
        FSClose(f);
    } else {
        SetHandleSize(MR(ScrapHandle), (Size)Cx(ScrapSize) + 8);
	if (MemErr != noErr)
/*-->*/	    return CW(MemErr);
	/* alignment stuff */
        lp = (LONGINT *)((char *)STARH(MR(ScrapHandle)) + Cx(ScrapSize));
        *lp++ = CL(rest);
        *lp++ = CL(len);
        len = (len + 1) & -2L;
        PtrAndHand(p, MR(ScrapHandle), (Size)len);
    }
    ScrapSize = CL(CL(ScrapSize) + 8 + len);
    return noErr;
}
示例#7
0
int main()
{
	deque<Pow> all(99*99,0);
	
	Cx(99)Cy(99)
		all[x*99+y] = Pow(x+2,y+2);
	
	sort(all.begin(),all.end());
	all.assign(all.begin(),unique(all.begin(),all.end()));
	
	cout<<all.size()<<endl;
}
示例#8
0
文件: scrap.c 项目: LarBob/executor
P0(PUBLIC pascal trap, LONGINT, UnloadScrap)
{
    OSErr retval;
    INTEGER f;
    LONGINT l = Cx(ScrapSize);
    
    if (Cx(ScrapState) > 0) {
        retval = cropen(&f);
        if (retval != noErr)
/*-->*/     return(retval);
        HLock(MR(ScrapHandle));
        retval = FSWriteAll(f, &l, STARH(MR(ScrapHandle)));
        HUnlock(MR(ScrapHandle));
        if (retval != noErr)
/*-->*/     return(retval);
        retval = FSClose(f);
        if (retval != noErr)
/*-->*/     return(retval);
        ScrapState = 0;
    }
    return noErr;
}
示例#9
0
int main()
{
	int count = 0;
	C(wordsCount)
	{
		int sum = 0;
		Cx(words[i].size())
			sum += words[i][x]-'A'+1;
		
		if (isTriangleNum(sum))
			count++;
	}
	cout<<count<<endl;
}
示例#10
0
A5(PRIVATE, BOOLEAN, getsetpiece, GetOrSetType, gors, LONGINT, fd,
		       Single_descriptor *, sdp, char *, bufp, LONGINT, length)
{
    LONGINT saveloc;
    BOOLEAN retval;

    saveloc = lseek(fd, 0L, L_INCR);
    lseek(fd, Cx(sdp->offset), L_SET);
    switch (gors) {
    case Get:
	retval =  read(fd, bufp, length) == length;
	break;
    case Set:
	retval = write(fd, bufp, length) == length;
	break;
    default:
	retval = FALSE;
	gui_assert(0);
	break;
    }
    lseek(fd, saveloc, L_SET);
    return retval;
}
示例#11
0
文件: scrap.c 项目: LarBob/executor
P0(PUBLIC pascal trap, PScrapStuff, InfoScrap)
{
    if (Cx(ScrapState) < 0)
        ZeroScrap();
    return((PScrapStuff)&ScrapSize);
}
示例#12
0
文件: scrap.c 项目: LarBob/executor
P3(PUBLIC pascal trap, LONGINT, GetScrap, Handle, h, ResType, rest,
								LONGINT *, off)
{
    OSErr retval;
    LONGINT l = 0, incr, s, ltoread, restlen[2];
    unsigned char *p;
    int found;
    INTEGER f;
    Handle temph;

#if !defined (LETGCCWAIL)
    s = 0;
#endif /* LETGCCWAIL */
    if (h)
	temph = 0;
    else {
	temph = NewHandle((Size) 0);
	h = temph;
    }
    
#if defined(X) || defined(NEXTSTEP) || defined (SDL)
    s = GetScrapX(rest, (char **) h);
    if (s >= 0) {
        *off = 0;	/* ack... could mess people up */
/*-->*/ RETURN(s);
    }
#endif /* defined(X) */
    if (Cx(ScrapState) < 0) {
        retval = ZeroScrap();
	if (retval != noErr)
/*-->*/	    RETURN(retval);
    }
    if (ScrapState == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
/*-->*/     RETURN(retval);
        found = FALSE;
        while (l < Cx(ScrapSize)  && !found) {
            ltoread = 8;
            FSReadAll(f, &ltoread, (Ptr) restlen);
	    s = CL(restlen[1]);
            if (rest == CL(restlen[0]))
                found = TRUE;
            else {
                incr = (8 + s + 1) & ~1L;
                l += incr;
                SetFPos(f, fsFromMark, incr);
            }
        }
        if (l >= Cx(ScrapSize)) {
            FSClose(f);
/*-->*/     RETURN(noTypeErr);
        }
        ReallocHandle(h, s);
	if (MemErr != noErr)
/*-->*/	    RETURN(CW(MemErr));
        HLock(h);
        ltoread = s;
        FSReadAll(f, &ltoread, STARH(h));
        HUnlock(h);
        FSClose(f);
    } else {
        HLock(MR(ScrapHandle));
        p = MR(*(unsigned char **)MR(ScrapHandle));
#if 1 || !defined(QUADALIGN)
        while (l < Cx(ScrapSize) && rest != CL(*(LONGINT *)p))
	  {
	    s = CL (*((LONGINT *) p + 1));
            incr = (8 + s + 1) & ~1L;
            l += incr;
            p += incr;
	  }
        if (l >= Cx(ScrapSize))
	  {
	    HUnlock(MR(ScrapHandle));
/*-->*/     RETURN(noTypeErr);
	  }
	s = CL (*((LONGINT *)p + 1));
#else /* QUADALIGN */
        while (l < Cx(ScrapSize) && rest != SNAGLONG(p)) {
            incr = 8 + ((s = SNAGLONG(p + sizeof(LONGINT))) + 1) & -2L;
            l += incr;
            p += incr;
        }
        if (l >= Cx(ScrapSize))
	  {
	    HUnlock(MR(ScrapHandle));
/*-->*/     RETURN(noTypeErr);
	  }
	s = *((LONGINT *)p + 1);
#endif /* QUADALIGN */
        PtrToXHand((Ptr) (p+8), h, s);
        HUnlock(MR(ScrapHandle));
    }
    *off = CL(l+8);
    RETURN(s);
}
示例#13
0
文件: syserr.c 项目: nobled/executor
P1(PUBLIC pascal, void, SysError, short, errorcode)
{
    GrafPort alertport;
    Region viscliprgn;
    HIDDEN_RgnPtr rp;
    Rect r;
    struct adef *ap;
    char quickbytes[grafSize];
    INTEGER offsetx, offsety;
    Rect main_gd_rect;

#if defined (BINCOMPAT)
    LONGINT tmpa5;
#endif /* BINCOMPAT */

    main_gd_rect = PIXMAP_BOUNDS (GD_PMAP (MR (MainDevice)));

    if (!DSAlertTab) {
#if defined (CLIFF_CENTERING_ALGORITHM)
        DSAlertTab = CL((Ptr) &myalerttab);
        DSAlertRect.top    = CWC(64);
        DSAlertRect.left   = CWC(32);
        DSAlertRect.bottom = CWC(190);
        DSAlertRect.right  = CWC(480);
#else
        INTEGER screen_width = CW (main_gd_rect.right);
        INTEGER screen_height = CW (main_gd_rect.bottom);

        DSAlertTab = RM((Ptr) &myalerttab);
        DSAlertRect.top    = CW((screen_height - 126) / 3);
        DSAlertRect.left   = CW((screen_width - 448) / 2);
        DSAlertRect.bottom = CW(CW(DSAlertRect.top) + 126);
        DSAlertRect.right  = CW(CW(DSAlertRect.left) + 448);
#endif

        offsetx = CW (DSAlertRect.left) - 32;
        offsety = CW (DSAlertRect.top) - 64;
    }
    else {
        offsetx = offsety = 0;
    }

    /* IM-362 */
    /* 1. Save registers and Stack Pointer */
    /*	  NOT DONE YET... signal handlers sort of do that anyway */

    /* 2. Store errorcode in DSErrCode */
    DSErrCode = CW(errorcode);

    /* 3. If no Cx(DSAlertTab), bitch */
    if (!DSAlertTab) {
        write(2, "This machine thinks its a sadmac\n",
              sizeof("This machine thinks its a sadmac\n")-1);
        exit(255);
    }

    /* 4. Allocate and re-initialize QuickDraw */
#if defined (BINCOMPAT)
    a5 = (LONGINT) (long) US_TO_SYN68K (&tmpa5);
    CurrentA5 = (Ptr) (long) CL(a5);
#endif /* BINCOMPAT */
    InitGraf((Ptr) quickbytes + sizeof(quickbytes) - 4);
    ROMlib_initport(&alertport);
    SetPort(&alertport);
    InitCursor();
    rp.p = RM(&viscliprgn);
    alertport.visRgn = alertport.clipRgn = RM(&rp);
    viscliprgn.rgnSize = CWC(10);
#if 0 && !defined(MSDOS)
    viscliprgn.rgnBBox = DSAlertRect;
#else
    viscliprgn.rgnBBox = main_gd_rect;
#endif

    /* 5, 6. Draw alert box if the errorcode is >= 0 */
    TRAPBEGIN();
    if (errorcode < 0)
        errorcode = -errorcode;
    else {
        r = DSAlertRect;
        FillRect(&r, white);
#if defined (OLDSTYLEALERT)
        r.right = CW(CW(r.right) - (2));
        r.bottom = CW(CW(r.bottom) - (2));
        FrameRect(&r);
        PenSize(2, 2);
        MoveTo(CW(r.left)+2, CW(r.bottom));
        LineTo(CW(r.right), CW(r.bottom));
        LineTo(CW(r.right), CW(r.top)+2);
        PenSize(1, 1);
#else /* OLDSTYLEALERT */
        FrameRect(&r);
        InsetRect(&r, 3, 3);
        PenSize(2, 2);
        FrameRect(&r);
        PenSize(1, 1);
#endif /* OLDSTYLEALERT */
    }

    /* find appropriate entry */

    ap = (struct adef *) findid(errorcode);
    if (!ap)
        ap = (struct adef *) ((INTEGER *) MR(DSAlertTab) + 1);

    /* 7. text strings */
    drawtextstring(CW(ap->primetextid), offsetx, offsety);
    drawtextstring(CW(ap->secondtextid), offsetx, offsety);

    /* 8. icon */
    drawicon(CW(ap->iconid), offsetx, offsety);

    /* 9. TODO: figure out what to do with the proc ... */

    /* 10, 11, 12, 13. check for non-zero button id */
    /* #warning We blow off ResumeProc until we can properly handle it */
    if (ap->buttonid)
        dobuttons(/* CL(ResumeProc) ? Cx(ap->buttonid) + 1 : */ Cx(ap->buttonid),
                offsetx, offsety, false);

    TRAPEND();
}
示例#14
0
文件: syserr.c 项目: nobled/executor
A4(PRIVATE, void, dobuttons, INTEGER, id, INTEGER, offsetx,
   INTEGER, offsety, BOOLEAN, demo_button_p)
{
    struct bdef *bp;
    struct sdef *sp;
    struct pdef *pp;
    int i;
    EventRecord evt;
    int done;
    int tcnt, twid;
    Point p;
#define BILLBUTTONS /*  */
#if defined (BILLBUTTONS)
    INTEGER h, v;
#endif /* BILLBUTTONS */
    char *textp;

    if ((bp = (struct bdef *) findid(id))) {
        for (i = 0; i < Cx(bp->nbut); i++) {

            /* Offset buttons; this hack is to center the splash screen
             * on non-512x342 root windows...yuck!
             */

            C_OffsetRect (&bp->buts[i].butloc, offsetx, offsety);
            if ((sp = (struct sdef *)findid(CW(bp->buts[i].butstrid)))) {
                if (demo_button_p && sp->text[0] == 'O' && sp->text[1] == 'K')
                    textp = "Demo";
                else
                    textp = sp->text;
                tcnt = strlen(textp);
                twid = TextWidth((Ptr) textp, 0, tcnt);
                MoveTo((CW(bp->buts[i].butloc.left)  +
                        CW(bp->buts[i].butloc.right) - twid) / 2,
                       (CW(bp->buts[i].butloc.top)   +
                        CW(bp->buts[i].butloc.bottom)) / 2 + 4);
                DrawText((Ptr) textp, 0, tcnt);
            }
#if defined (BILLBUTTONS)
            h = CW(bp->buts[i].butloc.right) - CW(bp->buts[i].butloc.left);
            v = (CW(bp->buts[i].butloc.bottom) - CW(bp->buts[i].butloc.top))/2;
            if (h > v)
                h = v;
            if (!(ROMlib_options & ROMLIB_RECT_SCREEN_BIT))
                FrameRoundRect(&bp->buts[i].butloc, h, v);
            else
                FrameRect(&bp->buts[i].butloc);
#else /* BILLBUTTONS */
            if (!(ROMlib_options & ROMLIB_RECT_SCREEN_BIT))
                FrameRoundRect(&bp->buts[i].butloc, 10, 10);
            else
                FrameRect(&bp->buts[i].butloc);
#endif /* BILLBUTTONS */
        }

        for (done = 0; !done;) {
            C_GetNextEvent(mDownMask|keyDownMask, &evt);
            if (evt.what == CWC(mouseDown) || evt.what == CWC(keyDown)) {
                p.h = CW(evt.where.h);
                p.v = CW(evt.where.v);
                for (i = 0; !done && i < CW(bp->nbut); i++) {
                    if (PtInRect(p, &bp->buts[i].butloc) ||
                            ((evt.what == CWC(keyDown)) &&
                             (((CL(evt.message) & charCodeMask) == '\r') ||
                              ((CL(evt.message) & charCodeMask) == NUMPAD_ENTER)))
                       ) {
                        if ((pp = (struct pdef *)
                                  findid(CW(bp->buts[i].butprocid))))
                            /* NOTE:  we will have to do a better
                                  job here sometime */
                            (*(void (*)(void))MR(pp->proc))();
                        done = 1;
                    }
                }
                if (!done)
                    SysBeep(1);
            }
        }
        if (evt.what == CWC(mouseDown))
            while (!C_GetNextEvent(mUpMask, &evt))
                ;

        /* Move all buttons back. */
        for (i = 0; i < Cx(bp->nbut); i++)
            C_OffsetRect (&bp->buts[i].butloc, -offsetx, -offsety);
    }
}
/* readonly attribute nsIDOMSVGAnimatedLength cx; */
NS_IMETHODIMP SVGRadialGradientElement::GetCx(nsIDOMSVGAnimatedLength * *aCx)
{
  *aCx = Cx().get();
  return NS_OK;
}
示例#16
0
bool File::load_binarySTL(vector<Triangle> &triangles,
			  uint max_triangles, bool readnormals)
{
    ifstream file;
    ustring filename = _file->get_path();
    file.open(filename.c_str(), ifstream::in | ifstream::binary);

    if(file.fail()) {
      cerr << _("Error: Unable to open stl file - ") << filename << endl;
      return false;
    }
    // cerr << "loading bin " << filename << endl;

    /* Binary STL files have a meaningless 80 byte header
     * followed by the number of triangles */
    file.seekg(80, ios_base::beg);
    unsigned int num_triangles;
    unsigned char buffer[4];
    file.read(reinterpret_cast <char *> (buffer), 4);
    // Read platform independent 32-bit little-endian int.
    num_triangles = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24;

    uint step = 1;
    if (max_triangles > 0 && max_triangles < num_triangles) {
      step = ceil(num_triangles/max_triangles);
      triangles.reserve(max_triangles);
    } else
      triangles.reserve(num_triangles);

    uint i = 0;
    for(; i < num_triangles; i+=step)
    {
      if (step>1)
	file.seekg(84 + 50*i, ios_base::beg);

      double a,b,c;
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d N(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Ax(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Bx(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Cx(a,b,c);

        if (file.eof()) {
            cerr << _("Unexpected EOF reading STL file - ") << filename << endl;
            break;
        }

        /* attribute byte count - sometimes contains face color
            information but is useless for our purposes */
        unsigned short byte_count;
        file.read(reinterpret_cast <char *> (buffer), 2);
	byte_count = buffer[0] | buffer[1] << 8;
	// Repress unused variable warning.
	(void)&byte_count;

	Triangle T = Triangle(Ax,Bx,Cx);
	if (readnormals)
	  if (T.Normal.dot(N) < 0) T.invertNormal();

	// cout << "bin triangle "<< N << ":\n\t" << Ax << "/\n\t"<<Bx << "/\n\t"<<Cx << endl;
        triangles.push_back(T);
    }
    file.close();

    return true;
    // cerr << "Read " << i << " triangles of " << num_triangles << " from file" << endl;
}
示例#17
0
/* Loads an binary STL file by filename
 * Returns 0 on success and -1 on failure */
int Shape::loadBinarySTL(string filename) {

    // if(getFileType(filename) != BINARY_STL) {
    //     return -1;
    // }

    triangles.clear();
    Min.x = Min.y = Min.z = numeric_limits<double>::infinity();
    Max.x = Max.y = Max.z = -numeric_limits<double>::infinity();

    ifstream file;
    file.open(filename.c_str());

    if(file.fail()) {
      cerr << _("Error: Unable to open stl file - ") << filename << endl;
      return -1;
    }

    /* Binary STL files have a meaningless 80 byte header
     * followed by the number of triangles */
    file.seekg(80, ios_base::beg);
    unsigned int num_triangles;
    unsigned char buffer[4];
    file.read(reinterpret_cast <char *> (buffer), 4);
    // Read platform independent 32-bit little-endian int.
    num_triangles = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24;
    triangles.reserve(num_triangles);

    for(uint i = 0; i < num_triangles; i++)
    {
        double a,b,c;
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d N(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Ax(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Bx(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Cx(a,b,c);

	// done in Triangle
        /* Recalculate normal vector - can't trust an STL file! */
        // Vector3d AA=Cx-Ax;
        // Vector3d BB=Cx-Bx;
	// N = AA.cross(BB).getNormalized();

        /* attribute byte count - sometimes contains face color
            information but is useless for our purposes */
        unsigned short byte_count;
        file.read(reinterpret_cast <char *> (buffer), 2);
	byte_count = buffer[0] | buffer[1] << 8;
	// Repress unused variable warning.
	(void)&byte_count;

        Triangle T(Ax,Bx,Cx);

	//cout << "bin triangle "<< N << ":\n\t" << Ax << "/\n\t"<<Bx << "/\n\t"<<Cx << endl;

        triangles.push_back(T);
    }
    file.close();
    CenterAroundXY();
    scale_factor = 1.0;
    scale_factor_x=scale_factor_y=scale_factor_z = 1.0;
    double vol = volume();
    if (vol < 0) {
      invertNormals();
      vol = -vol;
    }
    cout << _("Shape has volume ") << vol << " mm^3"<<endl;
    return 0;
}
示例#18
0
A2(PUBLIC, OSErr, ufsPBCatMove, CMovePBPtr, pb,		/* INTERNAL */
						     BOOLEAN, a)
{
    return ROMlib_PBMoveOrRename((ParmBlkPtr) pb, a, Cx(pb->ioDirID),
			      Cx(pb->ioNewDirID), (char *) MR(pb->ioNewName), CatMove);
}
示例#19
0
bool Reference::recalculateStationHeadingCurvature()
{
    if (this->numOfPoints <= 1) { return false; }

    // Recalculate s
    for(int i = 0; i < this->numOfPoints ; i++) {
        if(i == 0) { this->s[0] = 0; }
        else {
            double ds = hypot(this->x[i] - this->x[i-1], this->y[i] - this->y[i-1]);
            this->s[i] = this->s[i-1] + ds;
        }
    }

    // Recalculate theta, k and dk
    if(this->numOfPoints < NUM_FIT_FRONT + NUM_FIT_BACK + 1) {
        int i = 0;
        for( i = 0; i < this->numOfPoints; i++) {
            if(i == this->numOfPoints - 1) {
                this->theta[i] = this->theta[i-1];
                this->k[i] = 0;
                break;
            }
            this->theta[i] = atan2(this->y[i+1] - this->y[i], this->x[i+1] - this->x[i]);
            this->k[i] = 0;
        }
    }
    else {
        for(int i = 0; i < this->numOfPoints; i++) {
            int id0 = (i-NUM_FIT_FRONT >= 0) ? (i-NUM_FIT_FRONT):(0);
            int id1 = (i+NUM_FIT_BACK < this->numOfPoints) ? (i+NUM_FIT_BACK):(this->numOfPoints-1);
            double si, xi, yi, /*ei,*/ chisq;

            gsl_matrix *S, *cov;
            gsl_vector *x, *y, *w, *cx, *cy;

            int n = id1-id0+1;
            S = gsl_matrix_alloc (n, 3);
            x = gsl_vector_alloc (n);
            y = gsl_vector_alloc (n);
            w = gsl_vector_alloc (n);

            cx = gsl_vector_alloc (3);
            cy = gsl_vector_alloc (3);
            cov = gsl_matrix_alloc (3, 3);

            for (int j = 0; j < n; j++) {
                si = this->s[id0+j];
                xi = this->x[id0+j];
                yi = this->y[id0+j];

                gsl_matrix_set (S, j, 0, 1.0);
                gsl_matrix_set (S, j, 1, si);
                gsl_matrix_set (S, j, 2, si*si);

                gsl_vector_set (x, j, xi);
                gsl_vector_set (y, j, yi);
                gsl_vector_set (w, j, 1.0);
            }

            gsl_multifit_linear_workspace * work = gsl_multifit_linear_alloc (n, 3);
            gsl_multifit_wlinear (S, w, x, cx, cov, &chisq, work);
            gsl_multifit_linear_free (work);

            work = gsl_multifit_linear_alloc (n, 3);
            gsl_multifit_wlinear (S, w, y, cy, cov, &chisq, work);
            gsl_multifit_linear_free (work);

#define Cx(i) (gsl_vector_get(cx,(i)))
#define Cy(i) (gsl_vector_get(cy,(i)))

            double s_ = this->s[i];
            //        double x_ = Cx(2) * s_ * s_ + Cx(1) * s_ + Cx(0);
            double xd_ = 2 * Cx(2) * s_ + Cx(1);
            double xdd_ = 2 * Cx(2);
            //        double y_ = Cy(2) * s_ * s_ + Cy(1) * s_ + Cy(0);
            double yd_ = 2 * Cy(2) * s_ + Cy(1);
            double ydd_ = 2 * Cy(2);

            this->theta[i] = atan2(yd_, xd_);
            this->k[i] = (xd_ * ydd_ - yd_ * xdd_)
                    / ( sqrt( (xd_*xd_ + yd_*yd_)*(xd_*xd_ + yd_*yd_)*(xd_*xd_ + yd_*yd_) ) );

            gsl_matrix_free(S);
            gsl_vector_free (x);
            gsl_vector_free (y);
            gsl_vector_free (w);

            gsl_vector_free (cx);
            gsl_vector_free (cy);
            gsl_matrix_free (cov);
        }
    }

    return true;
}
示例#20
0
文件: tms36xx.c 项目: cdrr/MAME_hack
	G(3),	0,		0,		0,		0,		0,
	C(3),	0,		0,		0,		0,		0,
	G(3),	0,		0,		0,		0,		0,
	C(3),	0,		0,		0,		0,		0,
	G(3),	0,		0,		0,		0,		0,
	C(3),	0,		0,		0,		0,		0,
	G(3),	0,		0,		0,		0,		0,
};

/*
 * Fuer Elise, Beethoven
 * (Excuse my non-existent musical skill, Mr. B ;-)
 */
static int tune2[96*6] = {
	D(3),	D(4),	D(5),	0,		0,		0,
	Cx(3),	Cx(4),	Cx(5),	0,		0,		0,
	D(3),	D(4),	D(5),	0,		0,		0,
	Cx(3),	Cx(4),	Cx(5),	0,		0,		0,
	D(3),	D(4),	D(5),	0,		0,		0,
	A(2),	A(3),	A(4),	0,		0,		0,
	C(3),	C(4),	C(5),	0,		0,		0,
	Ax(2),	Ax(3),	Ax(4),	0,		0,		0,
	G(2),	G(3),	G(4),	0,		0,		0,
	D(1),	D(2),	D(3),	0,		0,		0,
	G(1),	G(2),	G(3),	0,		0,		0,
	Ax(1),	Ax(2),	Ax(3),	0,		0,		0,

	D(2),	D(3),	D(4),	0,		0,		0,
	G(2),	G(3),	G(4),	0,		0,		0,
	A(2),	A(3),	A(4),	0,		0,		0,
	D(1),	D(2),	D(3),	0,		0,		0,
示例#21
-1
文件: scrap.c 项目: LarBob/executor
A0(PUBLIC, LONGINT, ROMlib_ZeroScrap)
{
    OSErr retval;
    INTEGER f;
    THz saveZone;
    
    if (Cx(ScrapState) < 0) {
        ScrapCount = 0;
	saveZone = TheZone;
	TheZone = SysZone;
        ScrapHandle = RM(NewHandle((Size)0));
	TheZone = saveZone;
        ScrapState = CWC (1);
        ScrapName = RM((StringPtr) "\016Clipboard File");
    } else if (Cx(ScrapState) == 0) {
        retval = cropen(&f);
        if (retval != noErr)
            return retval;
        retval = SetEOF(f, (LONGINT)0);
        if (retval != noErr)
            return retval;
        FSClose(f);
    } else if (Cx(ScrapState) > 0)
        SetHandleSize(MR(ScrapHandle), (Size)0);
    ScrapSize = 0;
    ScrapCount = CW(CW(ScrapCount) + 1);
    return noErr;
}
示例#22
-1
文件: scrap.c 项目: LarBob/executor
P0(PUBLIC pascal trap, LONGINT, LoadScrap)
{
    OSErr retval;
    INTEGER f;
    LONGINT l = Cx(ScrapSize);
    
    if (ScrapState == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
            return(retval);

        HUnlock(MR(ScrapHandle));
        ReallocHandle(MR(ScrapHandle), (Size)Cx(ScrapSize));
	if (MemErr != noErr)
/*-->*/	    return Cx(MemErr);
        HLock(MR(ScrapHandle));
        retval = FSReadAll(f, &l, STARH(MR(ScrapHandle)));
        HUnlock(MR(ScrapHandle));
        if (retval != noErr)
            return(retval);
        SetEOF(f, (LONGINT) 0);
        FSClose(f);
        ScrapState = CWC (1);
    }
    return(Cx(ScrapState) > 0 ? noErr : noScrapErr);
}