示例#1
0
void GwfStreamWriter::writePair(SCgObject *obj)
{
    QString type = mTypeAlias2GWFType[obj->typeAlias()].mid(0,3);
    if(type=="arc")
        writeStartElement(type);
    else
        writeStartElement("pair");
    writeObjectAttributes(obj);
    SCgPair* pair = static_cast<SCgPair*>(obj);
    SCgObject* b = pair->getBeginObject();
    SCgObject* e = pair->getEndObject();
    writeAttribute("id_b", QString::number(b->id()));
    writeAttribute("id_e", QString::number(e->id()));

    writePosition(b,"b_x","b_y");
    writePosition(e,"e_x","e_y");

    writeAttribute("dotBBalance", QString::number(pair->getBeginDot()));
    writeAttribute("dotEBalance", QString::number(pair->getEndDot()));
    QVector<QPointF> points = pair->scenePoints();
    points.pop_back();
    points.pop_front();
    writePoints(points);
    writeEndElement();
}
示例#2
0
QVector<int> WireCreator::traceBackDE(int point)
{
    QVector<int> path;
    int lastPoint=-1;
    int currPoint=point;
    int nextPoint=point;
    while(forks.indexOf(currPoint)==-1|| path.length()==0){
        currPoint=nextPoint;
        for(auto edge: edges){
            if(currPoint==edge.first&&edge.second!=lastPoint){
                lastPoint=currPoint;
                nextPoint=edge.second;
                break;
            }
            if(currPoint==edge.second&&edge.first!=lastPoint){
                lastPoint=currPoint;
                nextPoint=edge.first;
                break;
            }
        }
    path.push_back(currPoint);
    }
    path.pop_front();
    return path;
}
// 获取下一时刻所有目标的状态
std::vector<State> TargetDataReader::getNextStates()
{
    std::vector<State> re;
    QVector<QString> *dv;
    QString line;
    if (allDataVector.at(0)->size() > 0) {
//        QString line = dataVector.front();
//        State s = createStateFromLine(line);
//        if (re.size() == 0) {
//            re.push_back(s);
//            dataVector.pop_front();
//        } else {
//            State preState = re.back();
//            if (preState.getTime() == s.getTime()) {
//                re.push_back(s);
//                dataVector.pop_front();
//            }
//        }
        for(int i = 0; i < allDataVector.size();i++)
        {
            dv = allDataVector[i];
            if(dv->size() > 0){
                line = dv->front();
                State s = createStateFromLine(line);
                re.push_back(s);
                dv->pop_front();
            }
        }
    }
    return re;
}
示例#4
0
void Scene::render()
{
    for(int i = -CWIDTH / 2; i < CWIDTH / 2; i ++)
    {
        qDebug() << i;
        for(int j = -CHEIGHT / 2; j < CHEIGHT / 2; j ++)
        {
            QVector<Ray*> rSeq = camera->pixelLight(i, j);
            int s = rSeq.size();
            Intensity rgb(0, 0, 0);
            while(!rSeq.empty())
            {
                Ray* tmp = rSeq.front();

                rgb = rgb + (1.0 / s) * getIntensity(tmp);
                rSeq.pop_front();
                if(tmp != NULL)
                {
                    delete tmp;
                    tmp = NULL;
                }
            }
            pixels[i + CWIDTH / 2][j + CHEIGHT / 2] = rgb.toRGB();

        }

    }
}
void LivewireCalculator::DrawTrace(uint x, uint y, QPainter &g) const
{
	const uint w = this->_weights->GetReducedWidth(), scale = this->_weights->GetScale(), s2 = scale / 2;
	if (this->_visited.Get(x /= scale, y /= scale)) // The endpoint has been solved, so we can actually draw the livewire
	{
		// Get every point from end to start by looping through the trace data
		QVector<QPoint> pts;
		uint I = x + y * w;
		do
		{
			QPoint p = QPoint((x = I % w) * scale + s2, (y = I / w) * scale + s2);
			pts.push_back(p);
			pts.push_back(p);
		}
		while ((I = this->_trace.Get(x, y)) != UINT_MAX);

		// Draw the points
		if (pts.size() >= 4)
		{
			pts.pop_back();
			pts.pop_front();
			g.drawLines(pts);
		}
	}
}
示例#6
0
void CPUWidget::paintEvent(QPaintEvent *){
    QPainter p(this);
    //p.drawLine(0,0,450,100);
    //Qt::SolidLine,Qt::DashLine,Qt::DotLine,Qt::DashDotLine,Qt::DashDotDotLine
    QPen pen = p.pen();
    pen.setColor(Qt::black);
    pen.setWidth(2);
    p.setPen(pen);
    p.drawRect(0,0,450,100);
    pen.setWidth(1);
    pen.setStyle(Qt::DotLine);
    p.setPen(pen);
    p.drawLine(0,25,450,25);
    p.drawLine(0,50,450,50);
    p.drawLine(0,75,450,75);
    pen.setStyle(Qt::SolidLine);
    pen.setColor(Qt::red);
    pen.setWidth(2);
    p.setPen(pen);
    while (vcpu.size()>46) vcpu.pop_front();
    int cx = 45;
    for (int i=vcpu.size()-1;i>0;i--){
        p.drawLine(cx*10,100-(int)(vcpu[i]*100),cx*10-10,100-(int)(vcpu[i-1]*100));
        cx--;
    }

}
void FileUploader::download(const QString &rootPath, const QVector<mtp::ObjectId> &objectIds)
{
	_model->moveToThread(&_workerThread);
	_total = 0;

	mtp::ObjectId currentParentId = _model->parentObjectId();

	QVector<QPair<QString, mtp::ObjectId> > input;
	for(auto id : objectIds)
		input.push_back(qMakePair(rootPath, id));

	QVector<QPair<QString, mtp::ObjectId> > files;
	while(!input.empty())
	{
		QString prefix = input.front().first;
		mtp::ObjectId id = input.front().second;
		input.pop_front();

		MtpObjectsModel::ObjectInfo oi = _model->getInfoById(id);
		if (oi.Format == mtp::ObjectFormat::Association)
		{
			//enumerate here
			QString dirPath = prefix + "/" + oi.Filename;
			mtp::SessionPtr session = _model->session();
			mtp::msg::ObjectHandles handles = session->GetObjectHandles(mtp::Session::AllStorages, mtp::ObjectFormat::Any, id);
			qDebug() << "found " << handles.ObjectHandles.size() << " objects in " << dirPath;
			for(mtp::ObjectId id : handles.ObjectHandles)
				input.push_back(qMakePair(dirPath, id));
		}
		else
		{
			_total += oi.Size;
			files.push_back(qMakePair(prefix + "/" + oi.Filename, id));
		}
	}

	qDebug() << "downloading " << files.size() << " file(s), " << _total << " bytes";
	_startedAt = QDateTime::currentDateTime();
	_aborted = false;
	if (_total < 1)
		_total = 1;

	for(const auto & file : files)
	{
		if (_aborted)
			break;
		emit executeCommand(new DownloadFile(file.first, file.second));
	}
	emit executeCommand(new FinishQueue(currentParentId));
}
示例#8
0
float Scene::getSourceRay(int i, Point* p)
{
    Point* oi1 = sources.at(i)->getOrigin();
    Ray sourceRay(*oi1, *p - *oi1, 0);
    float f1 = distance(oi1, p);
    int s1 = models.size();
    int k1 = 0;
    for(k1 = 0; k1 < s1; k1 ++)
    {
        float s = models.at(k1)->intersection(sourceRay);
        if((s > THRE * 10) && (f1 - s > THRE * 10)) break;
    }
    if(k1 == s1) return 1;

    int cnt = 0;
    QVector<Point *> org = sources.at(i)->sampleOrigin();
    int size = org.size();
    for(int j = 0; j < size; j ++)
    {
        Point* oi = org.at(j);
        Point op = *p - *oi;
        Ray sourceRay(*oi, op, 0);
        float f = distance(oi, p);
        int s = models.size();
        int k = 0;
        for(k = 0; k < s; k ++)
        {
            float s = models.at(k)->intersection(sourceRay);
            if((s > THRE * 10) && (f - s > THRE * 10)) break;
        }
        if(k == s) cnt ++;
    }
    while(!org.empty())
    {
        Point* first = org.front();
        if(first != NULL)
        {
            delete first;
            first = NULL;
        }
        org.pop_front();
    }
    return qMin(2 * cnt / (size + 0.0), 1.0);
}
示例#9
0
QPair<T, T> confint(const QVector<T> &vecin) {
	long double avg = 0.0;
	long double stddev = 0.0;
	QVector<T> vec = vecin;
	qSort(vec.begin(), vec.end());
	for (int i=0;i<vec.count() / 20;++i) {
		vec.pop_front();
		vec.pop_back();
	}

	foreach(T v, vec)
		avg += v;
	avg /= vec.count();

	foreach(T v, vec)
		stddev += (v-avg)*(v-avg);
	stddev = sqrtl(stddev / vec.count());
	return QPair<T,T>(static_cast<T>(avg), static_cast<T>(1.96 * stddev));
}
示例#10
0
	void SeparateTabBar::UpdateComputedWidths () const
	{
		const auto cnt = count ();
		ComputedWidths_.resize (cnt);

		const auto maxTabWidth = width () / 4;

		struct TabInfo
		{
			int Idx_;
			int WidthHint_;
		};
		QVector<TabInfo> infos;
		for (int i = 0; i < cnt - 1; ++i)
			infos.push_back ({ i, std::min (QTabBar::tabSizeHint (i).width (), maxTabWidth) });
		std::sort (infos.begin (), infos.end (),
				[] (const TabInfo& l, const TabInfo& r) { return l.WidthHint_ < r.WidthHint_; });

		const auto hspace = std::max (style ()->pixelMetric (QStyle::PM_TabBarTabHSpace), 10);
		const auto btnWidth = AddTabButton_ ? AddTabButton_->sizeHint ().width () + hspace : 30;

		auto remainder = width () - btnWidth;

		while (!infos.isEmpty ())
		{
			auto currentMax = remainder / infos.size ();
			if (infos.front ().WidthHint_ > currentMax)
				break;

			const auto& info = infos.front ();
			remainder -= info.WidthHint_;
			ComputedWidths_ [info.Idx_] = info.WidthHint_;
			infos.pop_front ();
		}

		if (infos.isEmpty ())
			return;

		const auto uniform = remainder / infos.size ();
		for (const auto& info : infos)
			ComputedWidths_ [info.Idx_] = uniform;
	}
示例#11
0
void GwfStreamWriter::writeBus(SCgObject *obj)
{
    writeStartElement("bus");
    writeObjectAttributes(obj);
    SCgBus* bus = static_cast<SCgBus*>(obj);

    writeAttribute("owner", QString::number(bus->owner()->id()));

    QVector<QPointF> points = bus->scenePoints();
    writeAttribute("b_x", QString::number(points.first().x()));
    writeAttribute("b_y", QString::number(points.first().y()));
    writeAttribute("e_x", QString::number(points.last().x()));
    writeAttribute("e_y", QString::number(points.last().y()));

    // do not save begin and end points
    points.pop_back();
    points.pop_front();
    writePoints(points);

    writeEndElement();
}
void QFilterData::getWaveData(const QString &strFileName, QVector<float> &leftArm,
							  QVector<float> &leftAnkle,
							  QVector<float> &rightArm,
							  QVector<float> &rightAnkle, QVector<int> &arrMapValue, int &nLeftUT, int &nRightUT)
{
	QVector<int> vectOriginal[4];

	// 第一步:读取文件
	QFile file(strFileName);

	if(!file.exists())
	{
		return;
	}

	QVector<int> arrPressure;
	if(file.open(QFile::ReadOnly | QFile::Text))
	{
		QTextStream in(&file);
		while(!in.atEnd())
		{
			QStringList strValue = in.readLine().remove("\r\n").split("; ");

			if(strValue.size() < 4)
			{
				continue;
			}
			int nLeftAnkle = strValue.at(0).toInt();
			int nRightAnkle = strValue.at(1).toInt();
			int nLeftArm = strValue.at(2).toInt();
			int nRightArm = strValue.at(3).toInt();

			if(arrPressure.size() >= 84000)
			{
				for(int i = 0; i<4; ++i)
				{
					arrPressure.pop_front();
				}
			}

			arrPressure.append(nRightArm);
			arrPressure.append(nLeftArm);
			arrPressure.append(nRightAnkle);
			arrPressure.append(nLeftAnkle);


			//QVector<float> arrFiltered =  _filterOrignal(arrTemp);
			//for(int i = 0; i<4; ++i)
			//{
			//	//qDebug()<<"index Filtered: "<<i<<"\t"<<vectOrignal.at(i+j*4);
			//	m_arrFiltedData[i].append(arrFiltered.at(i));
			//}

			//for(int i = 0; i<4; ++i)
			//{

			//	arrPressure[i].append(arrTemp.at(i));
			//}
		}
	}
	file.close();

	for(int i = 0; i<arrPressure.size(); i += 4)
	{
		qDebug()<<arrPressure.at(i)<<"\t"<<arrPressure.at(i+1)<<"\t"<<arrPressure.at(i+2)<<"\t"<<arrPressure.at(i+3);
	}
	QVector<float> vectFilter = _filterOrignal(arrPressure);
	for(int i = 0; i<vectFilter.size();i += 4)
	{
		qDebug()<<vectFilter.at(i)<<"\t"<<vectFilter.at(i+1)<<"\t"<<vectFilter.at(i+2)<<"\t"<<vectFilter.at(i+3);
	}

	//double dDest = 0.0f;
	//for(int i = 0; i<vectFilter.size();i += 4)
	//{
	//	ButterworthLowpassFilter0100SixthOrder(vectFilter.at(i), dDest);
	//	qDebug()<<vectFilter.at(i)<<"\t"<<dDest;
	//}
	_filterSecond(vectFilter);

	for(int i = 0; i<vectFilter.size();i += 4)
	{
		qDebug()<<vectFilter.at(i)<<"\t"<<vectFilter.at(i+1)<<"\t"<<vectFilter.at(i+2)<<"\t"<<vectFilter.at(i+3);
	}

	_saveFiltedPressure(vectFilter);
	//// 滤波处理
	for(int i = 0; i <4; ++i)
	{
		//m_arrFiltedData[i].append();
		//_filterSecond(m_arrFiltedData[i]);
		//// 丢掉前1000个点
		m_arrFiltedData[i].remove(0, 1000);
	}

	QVector<int> arrValley[4];
	_getValleyPeak(arrValley);

	//double dDest = 0.0;
	//for(int i = 0; i<m_arrFiltedData[0].size(); ++i)
	//{
	//	ButterworthLowpassFilter0100SixthOrder(m_arrFiltedData[0].at(i), dDest);
	//	qDebug()<<m_arrFiltedData[0].at(i)<<"\t"<<dDest;
	//}

 // // static int n = 8;
 // // static int nCount = 8/4;
 // // static double s = 800;
 // // static double f1 = 30;
 // // static double f2 = 300;
 // // static double a = cos(M_PI*(f1+f2)/s)/cos(M_PI*(f1-f2)/s);
 // // static double a2 = a*a;
 // // static double b = tan(M_PI*(f1-f2)/s);
 // // static double b2 = b*b;
 // // static double r;

 // // static double *A = (double *)malloc(nCount*sizeof(double));
 // // static double *d1 = (double *)malloc(nCount*sizeof(double));
 // // static double *d2 = (double *)malloc(nCount*sizeof(double));
 // // static double *d3 = (double *)malloc(nCount*sizeof(double));
 // // static double *d4 = (double *)malloc(nCount*sizeof(double));
 // // static double *w0 = (double *)calloc(nCount, sizeof(double));
 // // static double *w1 = (double *)calloc(nCount, sizeof(double));
 // // static double *w2 = (double *)calloc(nCount, sizeof(double));
 // // static double *w3 = (double *)calloc(nCount, sizeof(double));
 // // static double *w4 = (double *)calloc(nCount, sizeof(double));
 // // static bool bInit = false;

 // //if(!bInit)
 // //{
	// // bInit = true;
	// // for(int i=0; i<nCount; ++i)
	// // {
	//	//  r = sin(M_PI*(2.0*i+1.0)/(4.0*nCount));
	//	//  s = b2 + 2.0*b*r + 1.0;
	//	//  A[i] = b2/s;
	//	//  d1[i] = 4.0*a*(1.0+b*r)/s;
	//	//  d2[i] = 2.0*(b2-2.0*a2-1.0)/s;
	//	//  d3[i] = 4.0*a*(1.0-b*r)/s;
	//	//  d4[i] = -(b2 - 2.0*b*r + 1.0)/s;
	// // }
 // //}

 // 
	////for(int j = 0; j <arrPressure[0].size(); ++j)
	////{
	////	//ButterworthLowpassFilter0100SixthOrder(arrPressure[0].at(i), dDest);
	////	dDest = arrPressure[0].at(j);
	////	for(int i=0; i<nCount; ++i)
	////	{
	////		w0[i] = d1[i]*w1[i] + d2[i]*w2[i]+ d3[i]*w3[i]+ d4[i]*w4[i] + dDest;
	////		dDest = A[i]*(w0[i] - 2.0*w2[i] + w4[i]);
	////		w4[i] = w3[i];
	////		w3[i] = w2[i];
	////		w2[i] = w1[i];
	////		w1[i] = w0[i];
	////	}
	////	qDebug()<<arrPressure[0].at(j)<<"\t"<<dDest;
	////	//qDebug()<<arrPressure[0].at(i)<<"\t"<<arrPressure[1].at(i)<<"\t"<<arrPressure[2].at(i)<<"\t"<<arrPressure[3].at(i);
	////}

	////for(int i = 1000; i <arrPressure[0].size(); ++i)
	////{
	////	qDebug()<<arrPressure[0].at(i)<<"\t"<<arrPressure[1].at(i)<<"\t"<<arrPressure[2].at(i)<<"\t"<<arrPressure[3].at(i);
	////}

	//for(int j = 0 ; j<m_arrFiltedData[0].size();++j)
	//{
	//	qDebug()<<m_arrFiltedData[0].at(j)<<"\t"<<m_arrFiltedData[1].at(j)<<"\t"<<m_arrFiltedData[2].at(j)<<"\t"<<m_arrFiltedData[3].at(j);
	//}

	for(int j = 0; j < m_arrSloped[0].size(); ++j)
	{
		qDebug()<<m_arrSloped[0].at(j)<<"\t"<<m_arrSloped[1].at(j)<<"\t"<<m_arrSloped[2].at(j)<<"\t"<<m_arrSloped[3].at(j);		
	}

	for(int i = 0; i<4; ++i)
	{
		for(int j = 0; j <arrValley[i].size();++j)
		{
			qDebug()<<arrValley[i].at(j);
		}
	}

	//// 计算MAP值
	arrMapValue.append(_computeMap(arrValley));
	////arrMapValue.append(_computeMap(vectOriginal[1]));
	////arrMapValue.append(_computeMap(vectOriginal[2]));
	////arrMapValue.append(_computeMap(vectOriginal[3]));

	// 第二步:处理获得的四肢数据
	//QVector<int> leftAnkleIndex = getSlopeIndex(vectOriginal[0]);
	//for(int i = 0; i<vectOriginal[0].size(); ++i)
	//{
	//	qDebug()<<vectOriginal[0].at(i);
	//}
	nLeftUT = _getUTTime(arrValley[3], 3);
	//leftAnkle.append(dealOriginalData(vectOriginal[0], leftAnkleIndex, 0));

	//QVector<int> rightAnkleIndex = getSlopeIndex(vectOriginal[1]);
	////for(int i = 0; i<vectOriginal[1].size(); ++i)
	////{
	////	qDebug()<<vectOriginal[1].at(i);
	////}
	nRightUT = _getUTTime(arrValley[2], 2);
	////for(int i=0; i < rightAnkleIndex.size(); ++i)
	////{
	////	qDebug()<<rightAnkleIndex.at(i);
	////}
	//rightAnkle.append(dealOriginalData(vectOriginal[1], rightAnkleIndex, 1));
	////for(int i=0; i < rightAnkle.size(); ++i)
	////{
	////	qDebug()<<rightAnkle.at(i);
	////}
	////getUTTime(rightAnkle);

	//QVector<int> leftArmIndex = getSlopeIndex(vectOriginal[2]);
	//leftArm.append(dealOriginalData(vectOriginal[2], leftArmIndex, 2));

	//QVector<int> rightArmIndex = getSlopeIndex(vectOriginal[3]);
	//rightArm.append(dealOriginalData(vectOriginal[3], rightArmIndex, 3));

	for(int i = 0; i<4; ++i)
	{
		if(arrValley[i].size()>=2)
		{
			// 步骤4: 如果新的波谷,则解析波形数据
			_dealPlusWave(arrValley[i], i);
		}
	}

	rightArm.append(m_arrDrawValue[0]);
	leftArm.append(m_arrDrawValue[1]);
	rightAnkle.append(m_arrDrawValue[2]);
	leftAnkle.append(m_arrDrawValue[3]);
}