Vector2i EvolutionGraphWidget::hitDot( const Vector2f& p )//sequence selected
{
	Vector2i hit = Vector2i(-1,-1) ;
	float f;

	Vector2f pmin = Vector2f(m_xRange.x, m_yRange.x); //相对坐标的范围
	Vector2f pmax = Vector2f(m_xRange.y, m_yRange.y);

	float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_arryNumFeature[0]+1);
	float m_xTimeSpacing=(pmax.x - pmin.x)/float(m_timeNum+1);

	Vector2f sHit = Vector2f(p.x,  static_cast<float>(height()) - p.y); //世界坐标 妥妥滴


	//////////////////////////////////////////////////////////////////////////
	/*Vector2f(event->x(), event->y())

	Vector2f sHit = Vector2f(event->x(), static_cast<float>(height()) - event->y());
	Vector2f hit = stow(sHit);

	Vector2f sp = wtos(Vector2f(key->getIntensity(), key->getColor().a / 255.0));

	if (sHit.x > sp.x - m_iPointSize && sHit.x < sp.x + m_iPointSize &&
		sHit.y > sp.y - m_iPointSize && sHit.y < sp.y + m_iPointSize) {
			m_pSelectedKey = key;
	}*/
	//////////////////////////////////////////////////////////////////////////

	//cout<<"sHit:"<<sHit;
	for (int i=0; i <m_timeNum; ++i) 
	{
		f=pmin.x+m_xTimeSpacing*(i+1);
		Vector2f p = wtos(  Vector2f(  f ,0.0  )   );

		if (  abs(sHit.x - p.x) < m_iPointSize) {  
			//cout<<"p:"<<p;
			hit.x = i ;
			break;
		}

	}

	for (int j=0; j <m_timeNum; ++j) 
	{
		f=pmin.y+m_yTimeSpacing*(j+1);
		Vector2f p = wtos(  Vector2f(0.0  ,  f )   );

		if (  abs(sHit.y - p.y) < m_iPointSize) {  
			//cout<<"p:"<<p;
			hit.y = j ;
			break;
		}

	}


	return hit;
}
Exemple #2
0
Fichier : run.c Projet : 8l/cmm
static void
sched(void)
{
	char *flags;
	Job *j;
	Bufblock *buf;
	int slot;
	Node *n;
	Envy *e;

	if(jobs == 0){
		usage();
		return;
	}
	j = jobs;
	jobs = j->next;
	if(DEBUG(D_EXEC))
		printf("firing up job for target %s\n", wtos(j->t, ' '));
	slot = nextslot();
	events[slot].job = j;
	buf = newbuf();
	e = buildenv(j, slot);
	shprint(j->r->recipe, e, buf);
	if(!tflag && (nflag || !(j->r->attr&QUIET)))
		Bwrite(&bout, buf->start, (long)strlen(buf->start));
	freebuf(buf);
	if(nflag||tflag){
		for(n = j->n; n; n = n->next){
			if(tflag){
				if(!(n->flags&VIRTUAL))
					touch(n->name);
				else if(explain)
					Bprint(&bout, "no touch of virtual '%s'\n", n->name);
			}
			n->time = time((long *)0);
			MADESET(n, MADE);
		}
	} else {
		if(DEBUG(D_EXEC))
			printf("recipe='%s'", j->r->recipe);/**/
		Bflush(&bout);
		if(j->r->attr&NOMINUSE)
			flags = 0;
		else
			flags = "-e";
		events[slot].pid = execsh(flags, j->r->recipe, 0, e);
		usage();
		nrunning++;
		if(DEBUG(D_EXEC))
			printf("pid for target %s = %d\n", wtos(j->t, ' '), events[slot].pid);
	}
}
int EvolutionGraphWidget::hitLine( const Vector2f& p )//sequence selected
{
	int hit = -1;
	float f;
	
	Vector2f pmin = Vector2f(m_xRange.x, m_yRange.x); //相对坐标的范围
	Vector2f pmax = Vector2f(m_xRange.y, m_yRange.y);

	float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_pathNum+1);

	Vector2f sHit = Vector2f(p.x,  static_cast<float>(height()) - p.y); //世界坐标 妥妥滴



	for (int i=0; i <m_pathNum; ++i) 
	{
		f=pmin.y+m_yTimeSpacing*(i+1);
		Vector2f p = wtos(  Vector2f(0.0  ,  f )   );

		if (  abs(sHit.y - p.y) < 10) {  
			hit = i ;
			break;
		}

	}
	
	return hit;
}
Exemple #4
0
char *
exportenv(Envy *e)
{
    int i, n;
    char *buf, *v;

    buf = 0;
    n = 0;
    for(i = 0; e->name; e++, i++) {
        /* word separator is shell-dependent */
        if(e->values)
            v = wtos(e->values, IWS);
        else
            v = "";
        buf = Realloc(buf, n+strlen(e->name)+1+strlen(v)+1);

        n += sprint(buf+n, "%s=%s", e->name, v);
        n++;	/* skip over null */
        if(e->values)
            free(v);
    }
    /* final null */
    buf = Realloc(buf, n+1);
    buf[n] = 0;

    return buf;
}
void EvolutionGraphWidget::resizeEvent( QResizeEvent* event )
{
	QWidget::resizeEvent(event);
	//m_pHistogramPainter->resize(width(), height());

	////////////////////////////////////////////////////////////////////////////
	//Vector2f sp = wtos(Vector2f(0.f, 0.f));
	//Vector2f ep = wtos(Vector2f(1.f, 1.f));
	//m_colorBar->move(int(sp.x), int(ep.y - 15));
	//m_colorBar->resize(ep.x - sp.x, 25);
	////////////////////////////////////////////////////////////////////////////

	m_gridSpacing = Vector2f(m_xRange.y, m_yRange.y);
	// refine gridSpacing_ as good as possible
	Vector2f cellSize = wtos(m_gridSpacing) - wtos(Vector2f(m_xRange.x, m_yRange.x));
	//计算格子数目
	m_gridSpacingNum.x = cellSize.x * (0.04);/* * (0.04)*/
	m_gridSpacingNum.y = cellSize.y * (0.04);
}
Exemple #6
0
/*
 *	done on child side of fork, so parent's env is not affected
 *	and we don't care about freeing memory because we're going
 *	to exec immediately after this.
 */
void
exportenv(Envy *e, Shell *sh)
{
	int i;
	char **p;
	static char buf[16384];

	p = 0;
	for(i = 0; e->name; e++, i++) {
		p = (char**) Realloc(p, (i+2)*sizeof(char*));
		if(e->values)
			snprint(buf, sizeof buf, "%s=%s", e->name,  wtos(e->values, sh->iws));
		else
			snprint(buf, sizeof buf, "%s=", e->name);
		p[i] = strdup(buf);
	}
	p[i] = 0;
	environ = p;
}
void HistogramPainter::paintEvent(QPaintEvent* event) {
    event->accept();

    if (cache_ == 0 || cache_->rect() != rect()) {
        delete cache_;
        cache_ = new QPixmap(rect().size());
        cache_->fill(Qt::transparent);

        QPainter paint(cache_);

        // put origin in lower lefthand corner
        QMatrix m;
        m.translate(0.0, static_cast<float>(height())-1);
        m.scale(1.f, -1.f);
        paint.setMatrix(m);
        paint.setMatrixEnabled(true);

        if (histogram_) {
            // draw histogram
            paint.setPen(Qt::NoPen);
            paint.setBrush(QColor(200, 0, 0, 120));
            paint.setRenderHint(QPainter::Antialiasing, true);

            int histogramWidth = static_cast<int>(histogram_->getBucketCount());
            tgt::vec2 p;

            QPointF* points = new QPointF[histogramWidth + 2];
            int count = 0;

            for (int x=0; x < histogramWidth; ++x) {
                float xpos = static_cast<float>(x) / histogramWidth;
                // Do some simple clipping here, as the automatic clipping of drawPolygon()
                // gets very slow if lots of polygons have to be clipped away, e.g. when
                // zooming to small part of the histogram.
                if (xpos >= xRange_[0] && xpos <= xRange_[1]) {
                    float value = histogram_->getLogNormalized(x);
                    p = wtos(tgt::vec2(xpos, value * (yRange_[1] - yRange_[0]) + yRange_[0]));

                    // optimization: if the y-coord has not changed from the two last points
                    // then just update the last point's x-coord to the current one
                    if( (count >= 2 ) && (points[count - 2].ry() == p.y) && (points[count - 1].ry() == p.y) && (count >= 2) ){
                        points[count - 1].rx() = p.x;
                    } else {
                        points[count].rx() = p.x;
                        points[count].ry() = p.y;
                        count++;
                    }
                }
            }

            // Qt can't handle polygons that have more than 65536 points
            // so we have to split the polygon
            bool needSplit = false;
            if (count > 65536 - 2) { // 16 bit dataset
                needSplit = true;
                count = 65536 - 2; // 2 points needed for closing the polygon
            }

            if (count > 0) {
                // move x coordinate of first and last points to prevent vertical holes caused
                // by clipping
                points[0].rx() = wtos(tgt::vec2(xRange_[0], 0.f)).x;
                if (count < histogramWidth - 2) // only when last point was actually clipped
                    points[count - 1].rx() = wtos(tgt::vec2(xRange_[1], 0.f)).x;

                // needed for a closed polygon
                p = wtos(tgt::vec2(0.f, yRange_[0]));
                points[count].rx() = points[count - 1].rx();
                points[count].ry() = p.y;
                count++;
                p = wtos(tgt::vec2(0.f, yRange_[0]));
                points[count].rx() = points[0].rx();
                points[count].ry() = p.y;
                count++;

                paint.drawPolygon(points, count);
            }

            // draw last points when splitting is needed
            if (needSplit && false) {
                delete[] points;
                points = new QPointF[5];
                count = 0;
                for (int x=histogramWidth - 2; x < histogramWidth; ++x) {
                    float xpos = static_cast<float>(x) / histogramWidth;
                    if (xpos >= xRange_[0] && xpos <= xRange_[1]) {
                        float value = histogram_->getLogNormalized(x);
                        p = wtos(tgt::vec2(xpos, value * (yRange_[1] - yRange_[0]) + yRange_[0]));
                        points[x-histogramWidth+3].rx() = p.x;
                        points[x-histogramWidth+3].ry() = p.y;
                        count++;
                    }
                }
                if (count > 0) {
                    // move x coordinate of last point to prevent vertical holes caused by clipping
                    points[count - 1].rx() = wtos(tgt::vec2(xRange_[1], 0.f)).x;

                    // needed for a closed polygon
                    p = wtos(tgt::vec2(0.f, yRange_[0]));
                    points[count].rx() = points[count - 1].rx();
                    points[count].ry() = p.y;
                    count++;
                    p = wtos(tgt::vec2(0, yRange_[0]));
                    points[count].rx() = points[0].rx();
                    points[count].ry() = p.y;
                    count++;

                    paint.drawPolygon(points, 5);
                }
            }
            delete[] points;
        }
    }

    QPainter paint(this);
    paint.drawPixmap(0, 0, *cache_);
}
void EvolutionGraphWidget::paintEvent( QPaintEvent* event )
{

	if (!m_keyColletion && dataLoad)
		return;
	event->accept();
	QPainter paint(this);

	QMatrix m;
	m.translate(0.0, static_cast<float>(height())-1);
	m.scale(1.f, -1.f);
	paint.setMatrix(m);

	paint.setMatrixEnabled(true);
	paint.setRenderHint(QPainter::Antialiasing, false);
	paint.setPen(Qt::NoPen);
	paint.setBrush(QColor(40,40,40));  //0.156863, 0.156863, 0.156863
	paint.drawRect(0, 0, width() - 1, height() - 1);

	//////////////////////////////////////////////////////////////////////////
	// draw path
	paint.setPen(QColor(220, 220, 220));
	paint.setRenderHint(QPainter::Antialiasing, false);

	Vector2f pmin = Vector2f(m_xRange.x, m_yRange.x); //相对坐标的范围   m_xRange(0.f, 1.f), m_yRange(0.f, 1.f)
	Vector2f pmax = Vector2f(m_xRange.y, m_yRange.y);
	int xgridNum = m_gridSpacingNum.x;
	int ygridNum = m_gridSpacingNum.y;
	m_gridSpacing.x = (pmax.x - pmin.x) / (m_timeNum+1);  //xgridNum
	m_gridSpacing.y = (pmax.y - pmin.y) / ygridNum;

	float fx,fy;
	int h,hy;
	float m_xTimeSpacing=(pmax.x - pmin.x)/float(m_timeNum+1);


	//////////////////////////////////////////////////////////////////////////
	//draw grid
	// draw grid
	paint.setPen(QColor(70, 70, 70));
	paint.setRenderHint(QPainter::Antialiasing, false);

	int num = 0;
	for (float f=pmin.x; f<pmax.x-m_xTimeSpacing*0.5; f+=m_xTimeSpacing, ++num) 
	{
		Vector2f p = wtos(Vector2f(f, 0.f));
		Vector2f a = wtos(Vector2f(0.f, 0.f));
		Vector2f b = wtos(Vector2f(0.f, 1.f));   //width() - m_iPadding

		paint.drawLine(QPointF(p.x, a.y),QPointF(p.x, b.y));

		paint.scale(-1.f, 1.f);
		paint.rotate(180.f);
		QString strval = QString::number((int)(num));
		paint.setPen(Qt::gray);
		if (num % 2 == 0)
			paint.drawText(static_cast<int>(p.x ), static_cast<int>(-0.7 * (m_iBottomSpace)),  strval);
		else
			paint.drawText(static_cast<int>(p.x ), static_cast<int>(-0.45 * (m_iBottomSpace)),  strval);
		paint.setPen(QColor(70, 70, 70));
		paint.rotate(180.f);
		paint.scale(-1.f, 1.f);
	}
	paint.setPen(QColor(220, 220, 220));
	//for (float f=pmin.y; f<pmax.y+m_gridSpacing.y*0.5; f+=m_gridSpacing.y) 
	//{
	//	Vector2f p = wtos(Vector2f(0.f, f));
	//	Vector2f a = wtos(Vector2f(0.f, 0.f));
	//	Vector2f b = wtos(Vector2f(1.f, 0.f));
	//	paint.drawLine(QPointF(a.x, p.y),
	//		QPointF(b.x, p.y));
	//}

	//float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_arryNumFeature[]+1);

	//// 绘制路径  line
	//for (fy=m_yTimeSpacing,hy=0;hy<m_pathNum;++hy,fy+=m_yTimeSpacing)
	//{
	//
	//	//cout<<"cluster end:"<<*(pathInfo[hy].end()-1)<<endl;
	//	fx=pmin.x+m_xTimeSpacing*startID;// here is the difference
	//
	//	Vector2f y = wtos(Vector2f(1.f, fy));
	//	paint.setPen(QColor(113,189,232));

	//	paint.drawLine(QPointF(a.x, y.y), QPointF(a.y, y.y));

	//}
	//
	//cout<<"m_curTimeStep"<<m_curTimeStep<<endl;

	//////////////////////////////////////////////////////////////////////////
	//draw graph edge
	float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_arryNumFeature[0]+1);
	fx=m_xTimeSpacing;
	for (int timeStep=0; timeStep<m_timeNum;fx+=m_xTimeSpacing,timeStep++)
	{
		
		fy=m_yTimeSpacing;
		Vector2f node1X = wtos(Vector2f(fx, 0.f));	
		Vector2f node2X = wtos(Vector2f(fx+m_xTimeSpacing, 0.f));	

		m_keyColletion=m_keyColletionFull[timeStep];
		int edgeSum=0;
		//std::cout<<"i:"<<timeStep<<"m_arryNumFeature:"<<int(m_arryNumFeature[timeStep+1])<<std::endl;
		//std::cout<<"i:"<<timeStep<<"m_keyColletion:"<<int(m_keyColletion->getNumKeys())<<std::endl;
		for (int yNum=0;yNum<m_arryNumFeature[timeStep+1];fy+=m_yTimeSpacing,yNum++)
		{
			Vector2f node1Y = wtos(Vector2f(1.f, fy));

			edgeSum=dag.graph[timeStep][yNum].edgeSum;
			struct edgenode *p;
		
			p=dag.graph[timeStep][yNum].first;
			while (p!=NULL)
			{
				Vector2i nodeIndex=p->no;
				Vector2f node2Y = wtos(Vector2f(0.0, m_yTimeSpacing+ nodeIndex.y*m_yTimeSpacing));	
								
				paint.setPen(QColor(70, 70, 70));
				
				paint.drawLine(QPointF(node1X.x, node1Y.y), QPointF(node2X.x, node2Y.y));

				p=p->next;
			}			
		}
	}

	//////////////////////////////////////////////////////////////////////////
	//draw new add edge
	//m_newAddEdge


	//////////////////////////////////////////////////////////////////////////
	//draw path
	// 绘制路径  line
	fx=m_xTimeSpacing;
	fy=m_yTimeSpacing;
	for (int i=0;i<dag.m_pathInfo.size();i++)
	{
		vector<Vector2i> onePahth=dag.m_pathInfo[i];

		for (int j=0;j<onePahth.size()-1;j++)// 一条路径的长度
		{
			float x1=  fx + m_xTimeSpacing * onePahth[j].x; 
			float x2=  fx + m_xTimeSpacing * onePahth[j+1].x;

			float y1= fy + m_yTimeSpacing * onePahth[j].y; 
			float y2= fy + m_yTimeSpacing * onePahth[j+1].y; 

			Vector2f node1 = Vector2f( x1 ,y1);
			Vector2f node2 = Vector2f( x2 ,y2);

			node1 = wtos( node1 ) ;
			node2 = wtos( node2 );
			paint.setPen(QColor(220,220,220));

			paint.drawLine(QPointF(node1.x, node1.y), QPointF(node2.x, node2.y));

		}
	}
	


	//////////////////////////////////////////////////////////////////////////
	//draw marker
	fx=m_xTimeSpacing;
	for (int timeStep=0; timeStep<m_timeNum;fx+=m_xTimeSpacing,timeStep++)
	{
		
		float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_arryNumFeature[0]+1);
		fy=m_yTimeSpacing;
		Vector2f p = wtos(Vector2f(fx, 0.f));	

		m_keyColletion=m_keyColletionFull[timeStep];

		//std::cout<<"i:"<<timeStep<<"m_arryNumFeature:"<<int(m_arryNumFeature[timeStep+1])<<std::endl;
		//std::cout<<"i:"<<timeStep<<"m_keyColletion:"<<int(m_keyColletion->getNumKeys())<<std::endl;
		for (int yNum=0;yNum<m_arryNumFeature[timeStep+1];fy+=m_yTimeSpacing,yNum++)
		{
			TFMappingKey *key = m_keyColletion->getKey(yNum);			

			int props;
			props = MARKER_NORMAL;
			if (key == m_pSelectedKey)
			{
				//std::cout<<"i:"<<timeStep<<"yNum:"<<yNum<<"key:"<<key<<"m_pSelectedKey:"<<m_pSelectedKey<<::endl;
				props |= MARKER_SELECTED;
			}

			Vector2f y = wtos(Vector2f(1.f, fy));
			drawMarker(paint, key->getColor(),Vector2f(p.x, y.y),props);    //  key->getColor()
		}
		

	}


	//////////////////////////////////////////////////////////////////////////
	//draw  a  square  to show a feature's attribute
	paint.setPen(Qt::gray);
	paint.setBrush(QColor(40,40,40));  //0.156863, 0.156863, 0.156863
	
	Vector2f bottom=wtos(Vector2f(0.7f, 0.8f));
	Vector2f top=wtos(Vector2f(1.f, 1.f));	

	paint.drawRect(bottom.x, bottom.y, (width() - m_iPadding)*0.27, (height() - m_iPadding)*0.17);  //xy wh
	 
	//paint.scale(-1.f, 1.f);
	//paint.rotate(180.f);
	
	QString m_FeatureNo;
	QString m_CentroidText;
	QString m_VolumeText;
	QString m_MassText;

	vector <QString> attribute;
	m_FeatureNo.sprintf("%s %d %d ","Feature index: ",m_curTimeStep,m_clusterNumSelected);
	m_CentroidText.sprintf("%s %.0lf  %.0lf  %.0lf ","Centroid: ",	
		dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].centroid.x,
		dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].centroid.y,
		dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].centroid.z);//
	m_VolumeText.sprintf("%s %.0lf ","Volume: ",	dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].volume);//0);//
	m_MassText.sprintf("%s %.0lf","Mass: ",	dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].mass);//);//

	attribute.push_back(m_FeatureNo);
	attribute.push_back(m_CentroidText);
	attribute.push_back(m_VolumeText);
	attribute.push_back(m_MassText);

	paint.setPen(Qt::gray);
	paint.setBrush(Qt::NoBrush);
	float yWide=(height() - m_iPadding)*0.17 /6.0;
	paint.scale(-1.f, 1.f);
	paint.rotate(180.f);
	for (int i=0;i<4;i++)
	{
		//x is the same   // y   yBase+i*wide;
		float x=bottom.x;
		float y=bottom.y+float(i+1)*yWide;
		paint.drawText( x+1.5f * m_iPadding,-y,attribute[i]);
	}
	paint.rotate(180.f);
	paint.scale(-1.f, 1.f);
//	paint.drawText(static_cast<int>(width() - 5.5f * m_iPadding), static_cast<int>(-1 * (origin.y - 0.8 * m_iBottomSpace)), m_CentroidText);
//paint.drawText(static_cast<int>(1.6f * m_iPadding), static_cast<int>(-1 * (height() - 1.85f * m_iPadding)), m_yAxisText);


	//////////////////////////////////////////////////////////////////////////
	// draw x and y axes
	paint.setRenderHint(QPainter::Antialiasing, true);
	paint.setPen(Qt::gray);
	paint.setBrush(Qt::gray);

	// draw axes independently from visible range
	float oldx0_ = m_xRange[0];
	float oldx1_ = m_xRange[1];
	m_xRange[0] = 0.f;
	m_xRange[1] = 1.f;

	Vector2f origin = wtos(Vector2f(0.f, 0.f));
	origin.x = floor(origin.x) + 0.5f;
	origin.y = floor(origin.y) + 0.5f;

	paint.setRenderHint(QPainter::Antialiasing, true);

	paint.drawLine(QPointF(m_iPadding, origin.y),
		QPointF(width() - m_iPadding, origin.y));

	paint.drawLine(QPointF(origin.x, m_iBottomSpace),
		QPointF(origin.x, height() - m_iPadding));


	//////////////////////////////////////////////////////////////////////////
	// draw arrows
	QPointF arrow[3];
	arrow[0] = QPointF(origin.x, height() - m_iPadding);
	arrow[1] = QPointF(origin.x + m_iArrowWidth, height() - m_iPadding - m_iArrowLength);
	arrow[2] = QPointF(origin.x - m_iArrowWidth, height() - m_iPadding - m_iArrowLength);

	paint.drawConvexPolygon(arrow, 3);

	arrow[0] = QPointF(width() - m_iPadding, origin.y);
	arrow[1] = QPointF(width() - m_iPadding - m_iArrowLength, origin.y - m_iArrowWidth);
	arrow[2] = QPointF(width() - m_iPadding - m_iArrowLength, origin.y + m_iArrowWidth);

	paint.drawConvexPolygon(arrow, 3);

	paint.scale(-1.f, 1.f);
	paint.rotate(180.f);
	paint.drawText(static_cast<int>(width() - 5.5f * m_iPadding), static_cast<int>(-1 * (origin.y - 0.8 * m_iBottomSpace)), m_xAxisText);
	paint.drawText(static_cast<int>(1.6f * m_iPadding), static_cast<int>(-1 * (height() - 1.85f * m_iPadding)), m_yAxisText);

	paint.rotate(180.f);
	paint.scale(-1.f, 1.f);

	m_xRange[0] = oldx0_;
	m_xRange[1] = oldx1_;


	paint.setRenderHint(QPainter::Antialiasing, false);

	paint.setPen(Qt::lightGray);
	paint.setBrush(Qt::NoBrush);
	paint.drawRect(0, 0, width() - 1, height() - 1);

	paint.setMatrixEnabled(false);
	//m_MoveSelected.clear();
	//m_sequenceSelected=-1;
	//setupTransfunc();
}
void HistogramPainter::paintEvent(QPaintEvent* event) {
    event->accept();

    if (cache_ == 0 || cache_->rect() != rect()) {
        delete cache_;
        cache_ = new QPixmap(rect().size());
        cache_->fill(Qt::transparent);

        QPainter paint(cache_);

        // put origin in lower lefthand corner
        QMatrix m;
        m.translate(0.0, static_cast<float>(height())-1);
        m.scale(1.f, -1.f);
        paint.setMatrix(m);
        paint.setMatrixEnabled(true);

        if (histogram_) {
            // draw histogram
            paint.setPen(Qt::NoPen);
            paint.setBrush(QColor(200, 0, 0, 120));
            paint.setRenderHint(QPainter::Antialiasing, true);

            int histogramWidth = static_cast<int>(histogram_->getNumBuckets());
            tgt::vec2 p;

            // Qt can't handle polygons that have more than 65536 points
            // so we have to split the polygon
            int maxSize = 65536; //max size of polygon
            std::vector<QPointF*> points;
            int vi = 0; //iterator in the points vector
            points.push_back(new QPointF[maxSize]);
            int count = 0;

            for (int x=0; x < histogramWidth; ++x) {
                float xpos = static_cast<float>(x) / histogramWidth;
                xpos = histogram_->getMinValue() + (histogram_->getMaxValue() - histogram_->getMinValue()) * xpos;
                // Do some simple clipping here, as the automatic clipping of drawPolygon()
                // gets very slow if lots of polygons have to be clipped away, e.g. when
                // zooming to small part of the histogram.
                if (xpos >= xRange_[0] && xpos <= xRange_[1]) {
                    //open new list, if old one is full
                    if( count == maxSize-2 ){
                        count = 0;
                        points.push_back(new QPointF[maxSize]);
                        vi++;
                        //copy last point to connect two polygons
                        points[vi][count].rx() = p.x;
                        points[vi][count].ry() = p.y;
                        count++;
                    }
                    float value = (yAxisLogarithmic_ ? histogram_->getBucketLogNormalized(x) : histogram_->getBucketNormalized(x));
                    p = wtos(tgt::vec2(xpos, value * (yRange_[1] - yRange_[0]) + yRange_[0]));

                    // optimization: if the y-coord has not changed from the two last points
                    // then just update the last point's x-coord to the current one
                    if( (count >= 2 ) && (points[vi][count - 2].ry() == p.y) && (points[vi][count - 1].ry() == p.y) && (count >= 2) ){
                        points[vi][count - 1].rx() = p.x;
                    } else {
                        points[vi][count].rx() = p.x;
                        points[vi][count].ry() = p.y;
                        count++;
                    }
                }
            }

            for(size_t i = 0; i < points.size(); ++i){
                if (count > 0) {
                    if (i == vi){
                        // needed for a closed polygon
                        p = wtos(tgt::vec2(0.f, yRange_[0]));
                        points[i][count].rx() = points[i][count -1].rx();
                        points[i][count].ry() = p.y;
                        count++;
                        points[i][count].rx() = points[i][0].rx();
                        points[i][count].ry() = p.y;
                        count++;

                        paint.drawPolygon(points[i], count);
                    } else {
                        // needed for a closed polygon
                        p = wtos(tgt::vec2(0.f, yRange_[0]));
                        points[i][maxSize - 2].rx() = points[i][maxSize - 3].rx();
                        points[i][maxSize - 2].ry() = p.y;
                        points[i][maxSize - 1].rx() = points[i][0].rx();
                        points[i][maxSize - 1].ry() = p.y;

                        paint.drawPolygon(points[i], maxSize);
                    }
                }
            }

            for (size_t i = 0; i < points.size(); ++i)
                delete[] points[i];
        }
    }

    QPainter paint(this);
    paint.drawPixmap(0, 0, *cache_);
}
Exemple #10
0
/* OPEN FILE
 * -----------------------------------------------------------------------------
 * Opens the file.
 */
static void open_file(FILE *inputfile) {
	FILE *asmfile = fopen("asm_convert", "w");

	FILE *parsefile;
//	printf("%d", fgetc(file));
    char **binary;
    char lastline[WORD_LEN+1];
    char line[WORD_LEN+1];
    char data[WORD_LEN+1];
    int row = 0;
    int col = 0;
//    char *line = NULL;
//    size_t len = 0;
//    ssize_t read;
    int r;
    int c;
    int plusone = 0;
    int rows = 0;
    if (inputfile) {
        while ((c = getc(inputfile)) != EOF) {
        	if (c < 128)
        		fprintf(asmfile, "%c", c);
//        	printf("%d\n",c);
        }
//            putchar(c);
        fclose(inputfile);
        fclose(asmfile);
    }
    printf("------------------------------\n");
    parsefile = fopen("asm_convert", "r");
//    if (parsefile) {
//        while ((c = getc(parsefile)) != EOF) {
////        	if (c < 128)
////        		fprintf(asmfile, "%c", c);
//        	printf("%d\n",c);
////            putchar(c);
//        }
//        fclose(inputfile);
//        fclose(asmfile);
//    }
//    if (true) return;
    binary = getAllInstructions(parsefile, &row, &col);
//    if (true) return;

    printf("%d %d\n", row, col);

//    while ((read = getline(&line, &len, )) != -1) {
//        printf("Retrieved line of length %zu :\n", read);
//        printf("%s", line);
//    }
    for (c = WORD_LEN; c < WORD_LEN * 2; c++) {
    	line[c-WORD_LEN] = binary[0][c];
    }
    line[WORD_LEN] = 0;
    printf("LINE:%s\n", line);
	LC2200->pc->pc = stow(line);
	printf("PC:%lu %s\n", LC2200->pc->pc, wtos(LC2200->pc->pc));
	for (c = 0; c < WORD_LEN ; c++) {
	    	lastline[c] = '1';
	    }
//	lastline = "11111111111111111111111111111111";
	lastline[WORD_LEN] = 0;
//    if (true) return;
    for (r = 1; r < row; r++) {
        for (c = 0; c < WORD_LEN; c++) {
        	line[c] = binary[r][c];
        }

        line[WORD_LEN] = 0;
//        line
//        if (stow(line) == stow(lastline)) plusone = 1;
//        else plusone = 0;
////    	LC2200->pc->pc = stow(line);
//        for (c = 0; c < WORD_LEN ; c++) {
//        	    	lastline[c] = bitt(wtos(stow(line) + plusone), c)+'0';
//        	    }
//
//        for (c = 0; c < WORD_LEN ; c++) {
//        	    	line[c] = bitt(lastline, c)+'0';
//        	    }
////        lastline = wtos(stow(line) + plusone);
//
        printf("LINE:%s\n", line);

        for (c = WORD_LEN; c < WORD_LEN * 2; c++) {
        	data[c-WORD_LEN] = binary[r][c];
        }
        data[WORD_LEN] = 0;
        printf("DATA:%s\n", data);
    	LC2200->mem->MEM[stow(line)+plusone] = stow(data);
    	printf("MEM:%lu %s\n", LC2200->mem->MEM[stow(line)+plusone], wtos(LC2200->mem->MEM[stow(line)+plusone]));
//    while(binary[rows] != NULL) {
    	printf("012345678901234567890123456789012345678901234567890123456789012345\n");
        printf("\nassembly instruction at row %d is %s\n", r, binary[r]);
        plusone++;
//        rows++;
    }
    LC2200->mem->MEM[stow(line)+plusone+1] =
    		stow("0111 0000 0000 0000 0000 0000 0000 0000"); //halt

    fclose(parsefile);
}
Exemple #11
0
void
parse(char *f, int fd, int varoverride)
{
    int hline;
    char *body;
    Word *head, *tail;
    int attr, set, pid;
    char *prog, *p;
    int newfd;
    Biobuf in;
    Bufblock *buf;

    if(fd < 0) {
        perror(f);
        Exit();
    }
    ipush();
    infile = strdup(f);
    mkinline = 1;
    Binit(&in, fd, OREAD);
    buf = newbuf();
    while(assline(&in, buf)) {
        hline = mkinline;
        switch(rhead(buf->start, &head, &tail, &attr, &prog))
        {
        case '<':
            p = wtos(tail, ' ');
            if(*p == 0) {
                SYNERR(-1);
                fprint(2, "missing include file name\n");
                Exit();
            }
            newfd = open(p, OREAD);
            if(newfd < 0) {
                fprint(2, "warning: skipping missing include file: ");
                perror(p);
            } else
                parse(p, newfd, 0);
            break;
        case '|':
            p = wtos(tail, ' ');
            if(*p == 0) {
                SYNERR(-1);
                fprint(2, "missing include program name\n");
                Exit();
            }
            execinit();
            pid=pipecmd(p, envy, &newfd);
            if(newfd < 0) {
                fprint(2, "warning: skipping missing program file: ");
                perror(p);
            } else
                parse(p, newfd, 0);
            while(waitup(-3, &pid) >= 0)
                ;
            if(pid != 0) {
                fprint(2, "bad include program status\n");
                Exit();
            }
            break;
        case ':':
            body = rbody(&in);
            addrules(head, tail, body, attr, hline, prog);
            break;
        case '=':
            if(head->next) {
                SYNERR(-1);
                fprint(2, "multiple vars on left side of assignment\n");
                Exit();
            }
            if(symlook(head->s, S_OVERRIDE, 0)) {
                set = varoverride;
            } else {
                set = 1;
                if(varoverride)
                    symlook(head->s, S_OVERRIDE, (void *)"");
            }
            if(set) {
                /*
                char *cp;
                dumpw("tail", tail);
                cp = wtos(tail, ' '); print("assign %s to %s\n", head->s, cp); free(cp);
                */
                setvar(head->s, (void *) tail);
                symlook(head->s, S_WESET, (void *)"");
            }
            if(attr)
                symlook(head->s, S_NOEXPORT, (void *)"");
            break;
        default:
            SYNERR(hline);
            fprint(2, "expected one of :<=\n");
            Exit();
            break;
        }
    }
    close(fd);
    freebuf(buf);
    ipop();
}
Exemple #12
0
 string Iconv::u8tos(const string& s) {
   return wtos(u8tow(s));
 }