Example #1
0
//@function     testing function
void testor(void)
{

    qDebug() << LEFT(2);
    qDebug() << RIGHT(2);
    qDebug() << PARENT(5);
    qDebug() << PARENT(6);

    QList<QPoint> openlist;
    openlist.push_back(QPoint(1,0));
    openlist.push_back(QPoint(0,1));
    openlist.push_back(QPoint(2,1));
    openlist.push_back(QPoint(2,3));
    openlist.push_back(QPoint(1,1));

    for (int i =0; i< openlist.size(); i++)
        qDebug() << openlist.at(i);

    for (int i=0; i< openlist.size(); i++)
    {
        for(int j=i+1; j< openlist.size(); j++)
        {
            if (openlist.at(i).x()>openlist.at(j).x())
                openlist.swap(i,j);
            else if ((openlist.at(i).x()==openlist.at(j).x()) && openlist.at(i).y()>openlist.at(j).y())
                openlist.swap(i,j);

        }
    }
    qDebug() << "-----------------";
    for (int i =0; i< openlist.size(); i++)
        qDebug() << openlist.at(i);

}
Example #2
0
void MReportDataAdapter::BubbleSort(QList<EventInfo *> &list)
{
    for (int i = 0; i < list.count(); i++)
    {
        for (int j = 0; j < list.count() - 1 - i; j++)
        {
            if (list.at(j)->magnitude < list.at(j+1)->magnitude)
            {
                list.swap(j, j+1);
            }
        }
    }
}
Example #3
0
/*!
    \internal
*/
bool QImageReaderPrivate::initHandler()
{
    // check some preconditions
    if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) {
        imageReaderError = QImageReader::DeviceError;
        errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Invalid device"));
        return false;
    }

    // probe the file extension
    if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) {
        QList<QByteArray> extensions = QImageReader::supportedImageFormats();
        if (!format.isEmpty()) {
            // Try the most probable extension first
            int currentFormatIndex = extensions.indexOf(format.toLower());
            if (currentFormatIndex > 0)
                extensions.swap(0, currentFormatIndex);
        }

        int currentExtension = 0;

        QFile *file = static_cast<QFile *>(device);
        QString fileName = file->fileName();

        do {
            file->setFileName(fileName + QLatin1Char('.')
                    + QString::fromLatin1(extensions.at(currentExtension++).constData()));
            file->open(QIODevice::ReadOnly);
        } while (!file->isOpen() && currentExtension < extensions.size());

        if (!device->isOpen()) {
            imageReaderError = QImageReader::FileNotFoundError;
            errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "File not found"));
            file->setFileName(fileName); // restore the old file name
            return false;
        }
    }

    // assign a handler
    if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
        imageReaderError = QImageReader::UnsupportedFormatError;
        errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
        return false;
    }
    return true;
}
Example #4
0
void VListCF::determineChildren()
{
	// Get the single items from the list of composite items.
	QList< Item* > items = extractSingleItems();

	// Inserts elements that are not yet visualized and adjusts the order to match that in 'nodes'.
	for (int i = 0; i < node()->size(); ++i)
	{
		if (i >= items.size() ) items.append( renderer()->render(this, node()->at<Node>(i)));	// This node is new
		else if ( items[i]->node() == node()->at<Node>(i) )	continue;	// This node is already there
		else
		{
			// This node might appear somewhere ahead, we should look for it
			bool found = false;
			for (int k = i + 1; k<items.size(); ++k)
			{
				if ( items[k]->node() == node()->at<Node>(i) )
				{
					// We found this node, swap the visualizations
					items.swap(i, k);
					found = true;
					break;
				}
			}

			// The node was not found, insert a visualization here
			if (!found ) items.insert(i, renderer()->render(this, node()->at<Node>(i)));
		}
	}

	// Remove excess items
	while (items.size() > node()->size()) items.removeLast();

	// Convert the single items list back to a list of composite items.
	buildCompositeItems(items);
}
Example #5
0
// Triangulate a no convex polygon
void glc::triangulatePolygon(QList<GLuint>* pIndexList, const QList<float>& bulkList)
{
	int size= pIndexList->size();
	if (polygonIsConvex(pIndexList, bulkList))
	{
		QList<GLuint> indexList(*pIndexList);
		pIndexList->clear();
		for (int i= 0; i < size - 2; ++i)
		{
			pIndexList->append(indexList.at(0));
			pIndexList->append(indexList.at(i + 1));
			pIndexList->append(indexList.at(i + 2));
		}
	}
	else
	{
		// Get the polygon vertice
		QList<GLC_Point3d> originPoints;
		QHash<int, int> indexMap;

		QList<int> face;
		GLC_Point3d currentPoint;
		int delta= 0;
		for (int i= 0; i < size; ++i)
		{
			const int currentIndex= pIndexList->at(i);
			currentPoint= GLC_Point3d(bulkList.at(currentIndex * 3), bulkList.at(currentIndex * 3 + 1), bulkList.at(currentIndex * 3 + 2));
			if (!originPoints.contains(currentPoint))
			{
				originPoints.append(GLC_Point3d(bulkList.at(currentIndex * 3), bulkList.at(currentIndex * 3 + 1), bulkList.at(currentIndex * 3 + 2)));
				indexMap.insert(i - delta, currentIndex);
				face.append(i - delta);
			}
			else
			{
				qDebug() << "Multi points";
				++delta;
			}
		}
		// Values of PindexList must be reset
		pIndexList->clear();

		// Update size
		size= size - delta;

		// Check new size
		if (size < 3) return;

		//-------------- Change frame to mach polygon plane
			// Compute face normal
			const GLC_Point3d point1(originPoints[0]);
			const GLC_Point3d point2(originPoints[1]);
			const GLC_Point3d point3(originPoints[2]);

			const GLC_Vector3d edge1(point2 - point1);
			const GLC_Vector3d edge2(point3 - point2);

			GLC_Vector3d polygonPlaneNormal(edge1 ^ edge2);
			polygonPlaneNormal.normalize();

			// Create the transformation matrix
			GLC_Matrix4x4 transformation;

			GLC_Vector3d rotationAxis(polygonPlaneNormal ^ Z_AXIS);
			if (!rotationAxis.isNull())
			{
				const double angle= acos(polygonPlaneNormal * Z_AXIS);
				transformation.setMatRot(rotationAxis, angle);
			}

			QList<GLC_Point2d> polygon;
			// Transform polygon vertexs
			for (int i=0; i < size; ++i)
			{
				originPoints[i]= transformation * originPoints[i];
				// Create 2d vector
				polygon << originPoints[i].toVector2d(Z_AXIS);
			}
			// Create the index
			QList<int> index= face;

			const bool faceIsCounterclockwise= isCounterclockwiseOrdered(polygon);

			if(!faceIsCounterclockwise)
			{
				//qDebug() << "face Is Not Counterclockwise";
				const int max= size / 2;
				for (int i= 0; i < max; ++i)
				{
					polygon.swap(i, size - 1 -i);
					int temp= face[i];
					face[i]= face[size - 1 - i];
					face[size - 1 - i]= temp;
				}
			}

            QList<int> tList;
			triangulate(polygon, index, tList);
			size= tList.size();
			for (int i= 0; i < size; i+= 3)
			{
				// Avoid normal problem
				if (faceIsCounterclockwise)
				{
					pIndexList->append(indexMap.value(face[tList[i]]));
					pIndexList->append(indexMap.value(face[tList[i + 1]]));
					pIndexList->append(indexMap.value(face[tList[i + 2]]));
				}
				else
				{
					pIndexList->append(indexMap.value(face[tList[i + 2]]));
					pIndexList->append(indexMap.value(face[tList[i + 1]]));
					pIndexList->append(indexMap.value(face[tList[i]]));
				}
			}
			Q_ASSERT(size == pIndexList->size());
	}

}
void MainWindow::search()
{
    QTime time;
    time.start();
    QRgb rgb;

    QImage img=ui->widget_2->getImage();
    for(int i=0;i<128;i++)
        for(int j=0;j<128;j++)
        {
            rgb=img.pixel(i,j);
            yiq[0][i][j].setColor(rgb);
        }
    //YIQ **Pyiq=(YIQ**)yiq,**Pyiqh=(YIQ**)yiqh;
    //Now we need Haar 7 times
    for(int l=6;l>=0;l--)
    {
        int n=1<<l;
        int rule=0,rule1=1;
        //if(rule) rule1=0;
        double norm=sqrt(2<<(l-1));
        if(!norm) norm=1;
        for(int i=0;i<n;i++)
            for(int j=0;j<2*n;j++)
            {
                yiq[rule1][i][j].setColor(( yiq[rule][2*i][j].Y + yiq[rule][2*i+1][j].Y )/2,
                                     ( yiq[rule][2*i][j].I + yiq[rule][2*i+1][j].I )/2,
                                     ( yiq[rule][2*i][j].Q + yiq[rule][2*i+1][j].Q )/2);
                yiq[rule1][i+n][j].setColor(( yiq[rule][2*i][j].Y - yiq[rule][2*i+1][j].Y )/norm,
                                     ( yiq[rule][2*i][j].I - yiq[rule][2*i+1][j].I )/norm,
                                     ( yiq[rule][2*i][j].Q - yiq[rule][2*i+1][j].Q )/norm);

            }


        for(int i=0;i<2*n;i++)
            for(int j=0;j<n;j++)
            {
                yiq[rule][i][j].setColor(( yiq[rule1][i][2*j].Y + yiq[rule1][i][2*j+1].Y )/2,
                                     ( yiq[rule1][i][2*j].I + yiq[rule1][i][2*j+1].I )/2,
                                     ( yiq[rule1][i][2*j].Q + yiq[rule1][i][2*j+1].Q )/2);
                yiq[rule][i][j+n].setColor(( yiq[rule1][i][2*j].Y - yiq[rule1][i][2*j+1].Y )/norm,
                                     ( yiq[rule1][i][2*j].I - yiq[rule1][i][2*j+1].I )/norm,
                                     ( yiq[rule1][i][2*j].Q - yiq[rule1][i][2*j+1].Q )/norm);

            }

    }
    //______________________Now I need to sort results for 60 koefs__________________
    SortArray sArray[3];
    sArray[0].n=0;
    sArray[1].n=0;
    sArray[2].n=0;
    sArray[0].nmax=0;
    sArray[1].nmax=0;
    sArray[2].nmax=0;

                       //means to be 128
    for(int i=0;i<k;i++)
        for(int j=0;j<k;j++)
        {
            if(i!=0 && j!=0)
            {
                if(yiq[0][i][j].Y != 0)
                {
                    sArray[0].points[sArray[0].n].V = fabs(yiq[0][i][j].Y);
                    sArray[0].points[sArray[0].n].X = i;
                    sArray[0].points[sArray[0].n].Y = j;
                    if(sArray[0].points[sArray[0].nmax].V <fabs(yiq[0][i][j].Y)) sArray[0].nmax=sArray[0].n;
                    sArray[0].n++;
                }
                if(yiq[0][i][j].I != 0)
                {
                    sArray[1].points[sArray[1].n].V = fabs(yiq[0][i][j].I);
                    sArray[1].points[sArray[1].n].X = i;
                    sArray[1].points[sArray[1].n].Y = j;
                    if(sArray[1].points[sArray[1].nmax].V <fabs(yiq[0][i][j].I)) sArray[1].nmax=sArray[1].n;
                    sArray[1].n++;
                }
                if(yiq[0][i][j].Q != 0)
                {
                    sArray[2].points[sArray[2].n].V = fabs(yiq[0][i][j].Q);
                    sArray[2].points[sArray[2].n].X = i;
                    sArray[2].points[sArray[2].n].Y = j;
                    if(sArray[2].points[sArray[2].nmax].V <fabs(yiq[0][i][j].Q)) sArray[2].nmax=sArray[2].n;
                    sArray[2].n++;
                }
            }
        }

    //_____________________ Only for Debuging ______________________
    //____________________________________________
    /*QPixmap* haarPixmap=new QPixmap(128,128);

    QPainter painter(haarPixmap);
    for(int i=0;i<128;i++)
        for(int j=0; j<128 ; j++)
        {
            painter.setPen(QColor(yiq[0][i][j].getR(), yiq[0][i][j].getG(), yiq[0][i][j].getB()));
            painter.drawPoint(i,j);
        }
    ui->widget_2->setImage(haarPixmap->toImage());*/
    //_____________________________________________

    PointInfo cap;
    int nY=(sArray[0].n>20)?20:sArray[0].n;
    int nI=(sArray[1].n>20)?20:sArray[1].n;
    int nQ=(sArray[2].n>20)?20:sArray[2].n;
    if(nY)
    {
        for(int k=0;k<=nY;k++)
        {
        cap.V=sArray[0].points[k].V;
        cap.X=sArray[0].points[k].X;
        cap.Y=sArray[0].points[k].Y;
        sArray[0].points[k].V=sArray[0].points[sArray[0].nmax].V;
        sArray[0].points[k].X=sArray[0].points[sArray[0].nmax].X;
        sArray[0].points[k].Y=sArray[0].points[sArray[0].nmax].Y;
        sArray[0].points[sArray[0].nmax].V=cap.V;
        sArray[0].points[sArray[0].nmax].X=cap.X;
        sArray[0].points[sArray[0].nmax].Y=cap.Y;
        sArray[0].nmax=k+1;
        for(int i=k+1 ; i < sArray[0].n ; i++)
            if(sArray[0].points[sArray[0].nmax].V < sArray[0].points[i].V)
                sArray[0].nmax=i;
        }
    }
    if(nI)
    {
        for(int k=0;k<=nI;k++)
        {
        cap.V=sArray[1].points[k].V;
        cap.X=sArray[1].points[k].X;
        cap.Y=sArray[1].points[k].Y;
        sArray[1].points[k].V=sArray[1].points[sArray[1].nmax].V;
        sArray[1].points[k].X=sArray[1].points[sArray[1].nmax].X;
        sArray[1].points[k].Y=sArray[1].points[sArray[1].nmax].Y;
        sArray[1].points[sArray[1].nmax].V=cap.V;
        sArray[1].points[sArray[1].nmax].X=cap.X;
        sArray[1].points[sArray[1].nmax].Y=cap.Y;
        sArray[1].nmax=k+1;
        for(int i=k+1 ; i < sArray[1].n ; i++)
            if(sArray[1].points[sArray[1].nmax].V < sArray[1].points[i].V)
                sArray[1].nmax=i;
        }
    }
    if(nQ)
    {
        for(int k=0;k<=nQ;k++)
        {
        cap.V=sArray[2].points[k].V;
        cap.X=sArray[2].points[k].X;
        cap.Y=sArray[2].points[k].Y;
        sArray[2].points[k].V=sArray[2].points[sArray[2].nmax].V;
        sArray[2].points[k].X=sArray[2].points[sArray[2].nmax].X;
        sArray[2].points[k].Y=sArray[2].points[sArray[2].nmax].Y;
        sArray[2].points[sArray[2].nmax].V=cap.V;
        sArray[2].points[sArray[2].nmax].X=cap.X;
        sArray[2].points[sArray[2].nmax].Y=cap.Y;
        sArray[2].nmax=k+1;
        for(int i=k+1 ; i < sArray[2].n ; i++)
            if(sArray[2].points[sArray[2].nmax].V < sArray[2].points[i].V)
                sArray[2].nmax=i;
        }
    }
    //qDebug()<<time.elapsed();
    //_______________ Ok now we have 60 main points, lets transform it in sign______________
    Sign sign[3];
    for(int i=0;i<nY;i++)
    {
        sign[0].points[i].V = (yiq[0][sArray[0].points[i].X][sArray[0].points[i].Y].Y > 0) ? 1 : -1;
        sign[0].points[i].X = sArray[0].points[i].X;
        sign[0].points[i].Y = sArray[0].points[i].Y;
    }
    for(int i=0;i<nI;i++)
    {
        sign[1].points[i].V = (yiq[0][sArray[1].points[i].X][sArray[1].points[i].Y].I > 0) ? 1 : -1;
        sign[1].points[i].X = sArray[1].points[i].X;
        sign[1].points[i].Y = sArray[1].points[i].Y;
    }
    for(int i=0;i<nQ;i++)
    {
        sign[2].points[i].V = (yiq[0][sArray[2].points[i].X][sArray[2].points[i].Y].Q > 0) ? 1 : -1;
        sign[2].points[i].X = sArray[2].points[i].X;
        sign[2].points[i].Y = sArray[2].points[i].Y;
    }
    qDebug()<<time.elapsed();

    QSqlQuery q;
    QSqlQuery qY,qI,qQ;




    q.exec(QLatin1String("SELECT id,bigPath,smallPath,Y,I,Q FROM images"));
    QList< QPair < int,double > > list; //list of weight
    //QList< QPair < int,double > > listShot; //list of shots
    //______________________________________________________________________

    while(q.next())
    {
        int id=q.value(0).toInt();
        list<< qMakePair(id, w0*(fabs(q.value(3).toInt()-yiq[0][0][0].Y)+fabs(q.value(4).toInt()-yiq[0][0][0].I)
                                +fabs(q.value(5).toInt()-yiq[0][0][0].Q)));


        //listShot<< qMakePair(id, 0.0);
        //_________________________________________________________________

    }
    qY.prepare(QLatin1String("SELECT x,y,sign,imageId FROM Y WHERE x=:x AND y=:y AND sign=:sign "));
    for(int i=0;i<nY;i++)
    {
        /*qY.addBindValue(sign[0].points[i].X);
        qY.addBindValue(sign[0].points[i].Y);
        qY.addBindValue(sign[0].points[i].V);*/

        qY.bindValue(":x",sign[0].points[i].X);
        qY.bindValue(":y",sign[0].points[i].Y);
        qY.bindValue(":sign",sign[0].points[i].V);

        qY.exec();
        //showError(qY.lastError());

        while(qY.next())
        {
            for(int j=0;j<list.size();j++)
            {
                if(list.at(j).first == qY.value(3).toInt())
                {
                    int bin=(log(sign[0].points[i].X)/log(2) > log(sign[0].points[i].Y)/log(2))? floor(log(sign[0].points[i].X)/log(2)) : floor(log(sign[0].points[i].Y)/log(2));
                    bin=(bin > 5) ? 5 : bin;
                    list[j]= qMakePair(list.at(j).first, list.at(j).second - w[0][bin]);
                    //listShot[j]= qMakePair(listShot.at(j).first, listShot.at(j).second + 1);
                    //_____________________________________________________________________
                    break;
                }
            }
        }
    }
    qI.prepare(QLatin1String("SELECT x,y,sign,imageId FROM I WHERE x=:x AND y=:y AND sign=:sign "));

    for(int i=0;i<nI;i++)
    {
        /*qI.addBindValue(sign[1].points[i].X);
        qI.addBindValue(sign[1].points[i].Y);
        qI.addBindValue(sign[1].points[i].V);*/

        qY.bindValue(":x",sign[1].points[i].X);
        qY.bindValue(":y",sign[1].points[i].Y);
        qY.bindValue(":sign",sign[1].points[i].V);

        qI.exec();

        while(qI.next())
        {
            for(int j=0;j<list.size();j++)
            {
                if(list.at(j).first == qI.value(3).toInt())
                {
                    int bin=(log(sign[1].points[i].X)/log(2) > log(sign[1].points[i].Y)/log(2))? floor(log(sign[1].points[i].X)/log(2)) : floor(log(sign[1].points[i].Y)/log(2));
                    bin=(bin > 5) ? 5 : bin;
                    list[j]= qMakePair(list.at(j).first, list.at(j).second - w[1][bin]);
                    //listShot[j]= qMakePair(listShot.at(j).first, listShot.at(j).second + 1);
                    //__________________________________________________________________
                    break;
                }
            }
        }
    }
       qQ.prepare(QLatin1String("SELECT x,y,sign,imageId FROM Q WHERE x=:x AND y=:y AND sign=:sign "));
    for(int i=0;i<nQ;i++)
    {
        /*qQ.addBindValue(sign[2].points[i].X);
        qQ.addBindValue(sign[2].points[i].Y);
        qQ.addBindValue(sign[2].points[i].V);*/

        qY.bindValue(":x",sign[2].points[i].X);
        qY.bindValue(":y",sign[2].points[i].Y);
        qY.bindValue(":sign",sign[2].points[i].V);

        qQ.exec();

        while(qQ.next())
        {
            for(int j=0;j<list.size();j++)
            {
                if(list.at(j).first == qQ.value(3).toInt())
                {
                    int bin=(log(sign[2].points[i].X)/log(2) > log(sign[2].points[i].Y)/log(2))? floor(log(sign[2].points[i].X)/log(2)) : floor(log(sign[2].points[i].Y)/log(2));
                    bin=(bin > 5) ? 5 : bin;
                    list[j]= qMakePair(list.at(j).first, list.at(j).second - w[2][bin]);
                    //listShot[j]= qMakePair(listShot.at(j).first, listShot.at(j).second + 1);
                    //____________________________________________________________________
                    break;
                }
            }
        }
    }
    qDebug()<<time.elapsed();

    if(!list.isEmpty()){
        for(int j=0;j<24;j++)
        {
            double min=list.at(j).second;
            int mini=j;
            for(int i=j;i<list.size();i++)
            {
                if(list.at(i).second < min)
                {
                    min = list.at(i).second;
                    mini = i;
                }
            }
            list.swap(j,mini);
        }
    }
    ui->widget_2->timer->stop();

    //__________________________________________________________
    /*for(int j=0;j<24;j++)
    {
        double max=listShot.at(j).second;
        int maxi=j;
        for(int i=j;i<listShot.size();i++)
        {
            if(listShot.at(i).second > max)
            {
                max = listShot.at(i).second;
                maxi = i;
            }
        }
        listShot.swap(j,maxi);
    }*/
    //___________________________________________________________
    if(!list.isEmpty()) ui->widget->updateRes(list);
    int some;
}