예제 #1
0
void FPCamera::Reset(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
{
	glm::vec3 eyePt(eyeX, eyeY, eyeZ);
	glm::vec3 centerPt(centerX, centerY, centerZ);
	glm::vec3 upVec(upX, upY, upZ);
	Reset(eyePt, centerPt, upVec);
}
예제 #2
0
void GLWidget::InitCurve()
{
    _points.clear();
    AVector centerPt(this->_img_width / 2, this->_img_height / 2);

    float addValue = (M_PI * 2.0 / (float)16);
    for(float a = 0.0; a < M_PI * 2.0; a += addValue)
    {
        float xPt = centerPt.x + 10 * sin(a);
        float yPt = centerPt.y + 10 * cos(a);
        _points.push_back(AVector(xPt, yPt));
    }
}
예제 #3
0
void GLWidget::CreateCurve()
{
    _points.clear();

    AVector centerPt(this->_img_width / 2, this->_img_height / 2);

	float addValue = (3.14159 * 2.0 / _slice);
	for (float a = 0.0; a < 3.14159 * 2.0; a += addValue)
    {
        float xPt = centerPt.x + 10 * sin(a);
        float yPt = centerPt.y + 10 * cos(a);
        _points.push_back(AVector(xPt, yPt));
    }
}
예제 #4
0
Acad::ErrorStatus
AcDbXmlPoly::xmlOut(
    AcDbObject* pObj,
    AcDbXmlOutFiler* pFiler)
{
    Acad::ErrorStatus es = eOk;

    AsdkPoly* pPoly = AsdkPoly::cast(pObj);
    if (!pPoly)
        return eInvalidInput;

    AcUtXMLDOMNode* pNode = NULL;
    AcUtXMLDOMElement* pElement = NULL;
    AcUtXMLDOMAttribute* pAttribute = NULL;

    try {
        es = pFiler->pushNode(L"asdk:Poly", MY_SCHEMA, pNode);
        if (es != eOk)
            throw es;

        pElement = new AcUtXMLDOMElement(pNode);
        if (pElement == NULL)
            throw eOutOfMemory;

        es = superXmlOut(pObj, pFiler);
        if (es != eOk)
            throw es;

        es = pFiler->appendAttribute(pPoly->numSides(), L"numSides", 
            pElement);
        if (es != eOk)
            throw es;

        AcUtString name=pPoly->name();
        es = pFiler->appendAttribute(name, L"name", pElement);
        if (es != eOk)
            throw es;

        AcGePoint2d pt2d = pPoly->center();
        AcGePoint3d centerPt(pt2d.x, pt2d.y, pPoly->elevation());

        // Convert the point from ECS to WCS
        acdbEcs2Wcs(asDblArray(centerPt), asDblArray(centerPt),
            asDblArray(pPoly->normal()), true);

        es = pFiler->writePoint(L"dxml:CenterPoint", centerPt);
        if (es != eOk)
            throw es;

        pt2d = pPoly->startPoint();
        AcGePoint3d startPt(pt2d.x, pt2d.y, pPoly->elevation());
        // Convert the point from ECS to WCS
        acdbEcs2Wcs(asDblArray(startPt), asDblArray(startPt),
            asDblArray(pPoly->normal()), true);

        es = pFiler->writePoint(L"dxml:StartPoint", startPt);
        if (es != eOk)
            throw es;

        es = pFiler->writeNormalVector(pPoly->normal());
        if (es != eOk)
            throw es;

        es = pFiler->writeHardPointerId(L"acdb:TextStyleTableRecordId", 
            pPoly->styleId());
        if (es != eOk)
            throw es;

        es = pFiler->popNode();
        if (es != eOk)
            throw es;
    }

    catch (Acad::ErrorStatus thrownEs) {
        es = thrownEs;
    }

    if (pAttribute)
        delete pAttribute;
    if (pElement)
        delete pElement;
    if (pNode && pNode != pFiler->getCurrentNode())
        delete pNode;

    return es;
}
예제 #5
0
static void addXLabels(Agraph_t * gp)
{
    Agnode_t *np;
    Agedge_t *ep;
    int cnt, i, n_objs, n_lbls;
    int n_nlbls = 0;		/* # of unset node xlabels */
    int n_elbls = 0;		/* # of unset edge labels or xlabels */
    int n_set_lbls = 0;		/* # of set xlabels and edge labels */
    int n_clbls = 0;		/* # of set cluster labels */
    boxf bb;
    pointf ur;
    textlabel_t* lp;
    label_params_t params;
    object_t* objs;
    xlabel_t* lbls;
    object_t* objp;
    xlabel_t* xlp;
    Agsym_t* force;
    int et = EDGE_TYPE(gp);

    if (!(GD_has_labels(gp) & NODE_XLABEL) &&
	!(GD_has_labels(gp) & EDGE_XLABEL) &&
	!(GD_has_labels(gp) & TAIL_LABEL) &&
	!(GD_has_labels(gp) & HEAD_LABEL) &&
	(!(GD_has_labels(gp) & EDGE_LABEL) || EdgeLabelsDone))
	return;

    for (np = agfstnode(gp); np; np = agnxtnode(gp, np)) {
	if (ND_xlabel(np)) {
	    if (ND_xlabel(np)->set)
		n_set_lbls++;
	    else
		n_nlbls++;
	}
	for (ep = agfstout(gp, np); ep; ep = agnxtout(gp, ep)) {
	    if (ED_xlabel(ep)) {
		if (ED_xlabel(ep)->set)
		    n_set_lbls++;
		else if (HAVE_EDGE(ep))
		    n_elbls++;
	    }
	    if (ED_head_label(ep)) {
		if (ED_head_label(ep)->set)
		    n_set_lbls++;
		else if (HAVE_EDGE(ep))
		    n_elbls++;
	    }
	    if (ED_tail_label(ep)) {
		if (ED_tail_label(ep)->set)
		    n_set_lbls++;
		else if (HAVE_EDGE(ep))
		    n_elbls++;
	    }
	    if (ED_label(ep)) {
		if (ED_label(ep)->set)
		    n_set_lbls++;
		else if (HAVE_EDGE(ep))
		    n_elbls++;
	    }
	}
    }
    if (GD_has_labels(gp) & GRAPH_LABEL)
	n_clbls = countClusterLabels (gp);

    /* A label for each unpositioned external label */
    n_lbls = n_nlbls + n_elbls;
    if (n_lbls == 0) return;

    /* An object for each node, each positioned external label, any cluster label, 
     * and all unset edge labels and xlabels.
     */
    n_objs = agnnodes(gp) + n_set_lbls + n_clbls + n_elbls;
    objp = objs = N_NEW(n_objs, object_t);
    xlp = lbls = N_NEW(n_lbls, xlabel_t);
    bb.LL = pointfof(INT_MAX, INT_MAX);
    bb.UR = pointfof(-INT_MAX, -INT_MAX);

    for (np = agfstnode(gp); np; np = agnxtnode(gp, np)) {

	bb = addNodeObj (np, objp, bb);
	if ((lp = ND_xlabel(np))) {
	    if (lp->set) {
		objp++;
		bb = addLabelObj (lp, objp, bb);
	    }
	    else {
		addXLabel (lp, objp, xlp, 0, ur); 
		xlp++;
	    }
	}
	objp++;
	for (ep = agfstout(gp, np); ep; ep = agnxtout(gp, ep)) {
	    if ((lp = ED_label(ep))) {
		if (lp->set) {
		    bb = addLabelObj (lp, objp, bb);
		}
		else if (HAVE_EDGE(ep)) {
		    addXLabel (lp, objp, xlp, 1, edgeMidpoint(gp, ep)); 
		    xlp++;
		}
		else {
		    agerr(AGWARN, "no position for edge with label %s",
			    ED_label(ep)->text);
		    continue;
		}
	        objp++;
	    }
	    if ((lp = ED_tail_label(ep))) {
		if (lp->set) {
		    bb = addLabelObj (lp, objp, bb);
		}
		else if (HAVE_EDGE(ep)) {
		    addXLabel (lp, objp, xlp, 1, edgeTailpoint(ep)); 
		    xlp++;
		}
		else {
		    agerr(AGWARN, "no position for edge with tail label %s",
			    ED_tail_label(ep)->text);
		    continue;
		}
		objp++;
	    }
	    if ((lp = ED_head_label(ep))) {
		if (lp->set) {
		    bb = addLabelObj (lp, objp, bb);
		}
		else if (HAVE_EDGE(ep)) {
		    addXLabel (lp, objp, xlp, 1, edgeHeadpoint(ep)); 
		    xlp++;
		}
		else {
		    agerr(AGWARN, "no position for edge with head label %s",
			    ED_head_label(ep)->text);
		    continue;
		}
		objp++;
	    }
	    if ((lp = ED_xlabel(ep))) {
		if (lp->set) {
		    bb = addLabelObj (lp, objp, bb);
		}
		else if (HAVE_EDGE(ep)) {
		    addXLabel (lp, objp, xlp, 1, edgeMidpoint(gp, ep)); 
		    xlp++;
		}
		else {
		    agerr(AGWARN, "no position for edge with xlabel %s",
			    ED_xlabel(ep)->text);
		    continue;
		}
		objp++;
	    }
	}
    }
    if (n_clbls) {
	cinfo_t info;
	info.bb = bb;
	info.objp = objp;
	info = addClusterObj (gp, info);
	bb = info.bb;
    }

    force = agfindgraphattr(gp, "forcelabels");

    params.force = late_bool(gp, force, TRUE);
    params.bb = bb;
    placeLabels(objs, n_objs, lbls, n_lbls, &params);
    if (Verbose)
	printData(objs, n_objs, lbls, n_lbls, &params);

    xlp = lbls;
    cnt = 0;
    for (i = 0; i < n_lbls; i++) {
	if (xlp->set) {
	    cnt++;
	    lp = (textlabel_t *) (xlp->lbl);
	    lp->set = 1;
	    lp->pos = centerPt(xlp);
	    updateBB (gp, lp);
	}
	xlp++;
    }
    if (Verbose)
	fprintf (stderr, "%d out of %d labels positioned.\n", cnt, n_lbls);
    else if (cnt != n_lbls)
	agerr(AGWARN, "%d out of %d exterior labels positioned.\n", cnt, n_lbls);
    free(objs);
    free(lbls);
}
예제 #6
0
void CScanView::onDrawSelf(CDCHandle dc)
{
    CDC memDC;
    CBitmap memBitmap;
    memDC.CreateCompatibleDC(dc);
    CRect clientRECT;
    this->GetClientRect(&clientRECT);

    memBitmap.CreateCompatibleBitmap(dc,clientRECT.Width() , clientRECT.Height());
    HBITMAP oldBitmap = memDC.SelectBitmap(memBitmap);

    HPEN oldPen = memDC.SelectStockPen(DC_PEN);
   
    HBRUSH oldBrush = memDC.SelectStockBrush(NULL_BRUSH);
    HFONT  oldFont  = memDC.SelectFont(stdfont);

    memDC.SetBkMode(0);
    memDC.SetTextColor(RGB(90, 90, 90));
    memDC.SetTextAlign(TA_CENTER | TA_BASELINE);

    memDC.SetDCPenColor(RGB(60,60,60));

    CPoint centerPt(clientRECT.Width()/2, clientRECT.Height()/2);
    const int maxPixelR = min(clientRECT.Width(), clientRECT.Height())/2 - DEF_MARGIN;
    const float distScale = (float)maxPixelR/_current_display_range;

    char txtBuffer[100];

    // plot rings
    for (int angle = 0; angle<360; angle += 30) {
        float rad = (float)(angle*PI/180.0);

        float endptX = sin(rad)*(maxPixelR+DEF_MARGIN/2) + centerPt.x;
        float endptY = centerPt.y - cos(rad)*(maxPixelR+DEF_MARGIN/2);

        memDC.MoveTo(centerPt);
        memDC.LineTo((int)endptX, (int)endptY);

        sprintf(txtBuffer, "%d", angle);
        memDC.TextOutA((int)endptX, (int)endptY, txtBuffer);

    }

    for (int plotR = maxPixelR; plotR>0; plotR-=DISP_RING_ABS_DIST)
    {
        memDC.Ellipse(centerPt.x-plotR, centerPt.y-plotR,
            centerPt.x+plotR, centerPt.y+plotR);

        sprintf(txtBuffer, "%.1f", (float)plotR/distScale);
        memDC.TextOutA(centerPt.x, centerPt.y-plotR, txtBuffer);
    }

    memDC.SelectStockBrush(DC_BRUSH);
    memDC.SelectStockPen(NULL_PEN);

    int picked_point = 0;
    float min_picked_dangle = 100;

    for (int pos =0; pos < (int)_scan_data.size(); ++pos) {
        float distPixel = _scan_data[pos].dist*distScale;
        float rad = (float)(_scan_data[pos].angle*PI/180.0);
        float endptX = sin(rad)*(distPixel) + centerPt.x;
        float endptY = centerPt.y - cos(rad)*(distPixel);

        float dangle = fabs(rad - _mouse_angle);

        if (dangle<min_picked_dangle) {
            min_picked_dangle = dangle;
            picked_point = pos;
        }

        int brightness = (_scan_data[pos].quality<<1) + 128;
        if (brightness>255) brightness=255;

        memDC.FillSolidRect((int)endptX-1,(int)endptY-1, 2, 2,RGB(0,brightness,brightness));
    }

    memDC.SelectFont(bigfont);

    memDC.SetTextAlign(TA_LEFT | TA_BASELINE);
    memDC.SetTextColor(RGB(255,255,255));

    sprintf(txtBuffer, "%.1f Hz (%d RPM)", _scan_speed, (int)(_scan_speed*60));
    memDC.TextOutA(DEF_MARGIN, DEF_MARGIN + 40, txtBuffer);

    if ((int)_scan_data.size() > picked_point) {
        float distPixel = _scan_data[picked_point].dist*distScale;
        float rad = (float)(_scan_data[picked_point].angle*PI/180.0);
        float endptX = sin(rad)*(distPixel) + centerPt.x;
        float endptY = centerPt.y - cos(rad)*(distPixel);


        memDC.SetDCPenColor(RGB(129,10,16));
        memDC.SelectStockPen(DC_PEN);
        memDC.MoveTo(centerPt.x,centerPt.y);
        memDC.LineTo((int)endptX,(int)endptY);
        memDC.SelectStockPen(NULL_PEN);

        memDC.FillSolidRect((int)endptX-1,(int)endptY-1, 2, 2,RGB(255,0,0));

        memDC.SetTextColor(RGB(255,0,0));
        sprintf(txtBuffer, "Current: %.2f Deg: %.2f", _scan_data[picked_point].dist,  _scan_data[picked_point].angle);
        memDC.TextOutA(DEF_MARGIN, DEF_MARGIN + 20, txtBuffer);
    }

    dc.BitBlt(0, 0, clientRECT.Width(), clientRECT.Height()
        , memDC, 0, 0, SRCCOPY);

    memDC.SelectFont(oldFont);
    memDC.SelectBrush(oldBrush);
    memDC.SelectPen(oldPen);
    memDC.SelectBitmap(oldBitmap);

    
}
/*------------------------------------------------------------------------------
| DrawingArea::button1Up                                                       |
|                                                                              |
| Handle button 1 up events.  This indicates a data points final location.     |
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1Up( const IPoint& point )
{
  if ( drawState() == drawing )
  {
    switch (currentObj)
    {
      case move:
      break;
      case eraser:
      break;
      case stylecan:
      break;
      case line:
        ((IGLine*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case freehand:
        ((IGPolygon*)iGraphic)->addPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case rectangle:
      {
        IRectangle rc(((IGRectangle*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGRectangle*)iGraphic)->setEnclosingRect( rc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case ellipse:
      {
        IRectangle rc(((IGEllipse*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGEllipse*)iGraphic)->setEnclosingRect( rc );

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case polyline:
      case polygon:
        previousPt = point;
        ((IGPolyline*)iGraphic)->setPoint(
                         ((IGPolyline*)iGraphic)->numberOfPoints()-1, point );
        setDrawState( waitingForInput );
      break;
      case arc:
      if ( pointCount == 2 )
      {
        ((IG3PointArc*)iGraphic)->setIntermediatePoint( point );
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), previousPt );
        tempLine.drawOn( gc );
        tempLine.setEndingPoint( point );
        tempLine.drawOn( gc );
        setDrawState( waitingForInput );
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );
        ((IG3PointArc*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case pie:
      case chord:
      if ( pointCount == 2 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        setDrawState( waitingForInput );
        IPoint centerPt(((IGPie*)iGraphic)->enclosingRect().center());

        ((IGPie*)iGraphic)->setStartAngle( angleFromPoints( centerPt, point ));

        unsigned a(abs(centerPt.x()) - abs(point.x()));
        unsigned b(abs(centerPt.y()) - abs(point.y()));

        unsigned long radius((unsigned long)sqrtl(a*a + b*b));

        ((IGPie*)iGraphic)->setEnclosingRect(
           ((IGPie*)iGraphic)->enclosingRect().expandBy(radius));
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );

        double sweep(angleFromPoints(
                              ((IGPie*)iGraphic)->enclosingRect().center(), point ));

        if ( sweep < ((IGPie*)iGraphic)->startAngle() )
          ((IGPie*)iGraphic)->setSweepAngle( 360.0 -
                                ( ((IGPie*)iGraphic)->startAngle() - sweep ));
        else
          ((IGPie*)iGraphic)->setSweepAngle( sweep -
                                            ((IGPie*)iGraphic)->startAngle());

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case text:
      {
        IString input;

        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          input = reslib.loadString( STRING_SAMPLE1 );
        else if ((point.y() % 5)==1)
          input = reslib.loadString( STRING_SAMPLE3 );
        else if ((point.y() % 5)==3)
          input = reslib.loadString( STRING_SAMPLE4 );
        else
          input = reslib.loadString( STRING_SAMPLE2 );

        IGString* text = new IGString( input.x2c(), point, currentFont());
//      IGString* text = new IGString( "Doodle", point, currentFont());
        text->rotateBy( 10.0, point );
        text->setGraphicBundle( currentBundle );
        text->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *text );
      }
      break;
      case bitmap:
      {
        IGBitmap *bmp;
//      if (bitmapFileName().length() > 0)
//      {
//        bmp = new IGBitmap(bitmapFileName());
//      }

        // Select a bitmap to load
        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE1 ));
        else if ((point.y() % 5)==1)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE3 ));
        else if ((point.y() % 5)==3)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE4 ));
        else
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE2 ));

        bmp->moveTo( point );
        bmp->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *bmp );
      }
      break;
    } /* endswitch */
  } /* endif */
  else  // not drawing
  {
    switch (currentObj)
    {
      case move:
        if (moveGraphic && capturePointer)
        {
          moveRect.translateBy( point - previousPt );
          moveRect.drawOn( gc );
          moveRect.resetTransformMatrix();
          this->refresh( moveRect.boundingRect(gc).expandBy(2) );
          moveGraphic->translateBy( point - startingPt );
          moveGraphic->drawOn( gc );
          moveGraphic = 0;
          capturePointer(false);
        }
      break;
    }
  }
  return *this;
}