Exemple #1
0
void MainWindow::openDefaultiTunes()
{
    QString fileName;
    QFile nameFile("libraryName.mln");
    if(nameFile.open(QFile::ReadOnly | QFile::Text))
    {
        fileName = nameFile.readLine();
        nameFile.close();
    }
    else
    {
        nameFile.close();
        return;
    }

    QFile file(fileName);
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::warning(this, tr("Music Collection"),
                             tr("Cannot read file %1:\n%2.")
                             .arg(fileName)
                             .arg(file.errorString()));
        return;
    }

    statusBar()->showMessage(tr("Parsing iTunes Library......"));

    _library->empty();
    if ( Parser::parse( file, _library ) ) {
        statusBar()->showMessage(tr("File loaded"), 2000);
        qDebug() << "Library updated";
        emit libraryUpdated();
    }

}
Exemple #2
0
/*
 * ---------------------------------------------------------
 * Slots
 * ---------------------------------------------------------
 */
void MainWindow::openiTunesLibrary() {


    QString fileName =
        QFileDialog::getOpenFileName(this, tr("Open iTunes Library File"),
                                     QDir::currentPath(),
                                     tr("iTunes XML Library File(*.xml)"));
    if (fileName.isEmpty())
        return;


    QFile file(fileName);
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::warning(this, tr("Music Collection"),
                             tr("Cannot read file %1:\n%2.")
                             .arg(fileName)
                             .arg(file.errorString()));
        return;
    }

    statusBar()->showMessage(tr("Parsing iTunes Library......"));

    _library->empty();
    if ( Parser::parse( file, _library ) ) {
        statusBar()->showMessage(tr("File loaded"), 2000);
        qDebug() << "Library updated";

        //output the iTunes library location for easy loading later
        QFile nameFile("libraryName.mln");
        nameFile.open(QFile::ReadWrite | QFile::Truncate);
        nameFile.write(fileName.toStdString().c_str());

        emit libraryUpdated();
    }
}
Exemple #3
0
void STMPETest::runTest()
{
    QFile nameFile(ACCEL_PATH "name");

    testInfo("Reading STMPE name");

    if (!nameFile.open(QIODevice::ReadOnly)) {
        testError("Unable to open device name");
        return;
    }

    /* We must trim whitespace, since toInt() will fail otherwise, and the value
     * contains a trailing \n character.
     */
    QString name = nameFile.readAll().trimmed();

    if (name != "stmpe811")
        testError(QString("Error: Expected name of 'stmpe811', got name of '%1'").arg(name));
    else
        testInfo(QString("Got expected name of '%1'").arg(name));
}
void Spooler::Run()
{
    ushort numOfFillBytes = sizeof (float) - sizeof (bool);
    ushort shiftBuf = sizeof (bool) + numOfFillBytes + sizeof (float);
    ushort shiftUserTime = sizeof (bool) + numOfFillBytes;
    struct sched_param sp;
    ushort properInSize = _inSize - shiftBuf;
    Total total;
    int smRxPacketsFd;
    int smCounterRxPacketsFd;
    int smWaitForWritingFd;
    uchar *smRxPacketsAddr;
    uint *smCounterRxPacketsAddr;
    bool *smWaitForWritingAddr;
    const uint RxPacketsBufSize = _inSize * MULTI_RX_PACKET;

    smRxPacketsFd = shm_open(SM_RX_PACKETS_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);

    if (smRxPacketsFd < 0)
    {
        perror("Invoke shm_open() at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    if (ftruncate(smRxPacketsFd, RxPacketsBufSize) < 0)
    {
        perror("Invoke ftruncate() at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    smCounterRxPacketsFd = shm_open(SM_COUNTER_RX_PACKETS_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);

    if (smCounterRxPacketsFd < 0)
    {
        perror("Invoke shm_open() for counter at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    if (ftruncate(smCounterRxPacketsFd, sizeof (uint)) < 0)
    {
        perror("Invoke ftruncate() on smCounterRxPacketsFd at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    smWaitForWritingFd = shm_open(SM_CYCLE_TIME_RX_PACKET_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);

    if (smWaitForWritingFd < 0)
    {
        perror("Invoke shm_open() for smWaitForWritingFd at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    if (ftruncate(smWaitForWritingFd, sizeof (bool)) < 0)
    {
        perror("Invoke ftruncate() on smWaitForWritingFd at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    smRxPacketsAddr = (uchar *)mmap(NULL, RxPacketsBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, smRxPacketsFd, 0);

    if (smRxPacketsAddr == MAP_FAILED)
    {
        perror("Invoke mmap() at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    smCounterRxPacketsAddr = (uint *)mmap(NULL, sizeof (uint), PROT_READ | PROT_WRITE, MAP_SHARED, smCounterRxPacketsFd, 0);

    if (smCounterRxPacketsAddr == MAP_FAILED)
    {
        perror("Invoke mmap() at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    smWaitForWritingAddr = (bool *)mmap(NULL, sizeof (bool), PROT_READ | PROT_WRITE, MAP_SHARED, smWaitForWritingFd, 0);

    if (smWaitForWritingAddr == MAP_FAILED)
    {
        perror("Invoke mmap() at Spooler::Run() failed");

        exit(EXIT_FAILURE);
    }

    *smCounterRxPacketsAddr = 0;
    *smWaitForWritingAddr = true;

#ifdef DEBUGPRINT
    cout << "smWaitForWritingAddr start with" << *smWaitForWritingAddr << endl;
#endif

    uchar *currentPositionInRxPacketsBuf = smRxPacketsAddr;
    bool **ackPacket = (bool **)&currentPositionInRxPacketsBuf;
    float *userTime = (float *)currentPositionInRxPacketsBuf;

    for (ushort i = 0; i < MULTI_RX_PACKET; ++i) // główna pętla programu pomiarowego
    {
        currentPositionInRxPacketsBuf = (smRxPacketsAddr + (i * _inSize));

        **ackPacket = true; //(i % MULTI_RX_PACKET);
    }

    int fd = -1;

    if (_prefixFile[_prefixFile.length() - 1] != '/')
    {
        _prefixFile += '/';
    }

    ostringstream nameFile("./");
    nameFile << _prefixFile << "_" << _outSize << "_" << properInSize << "_x" << _howManyTimes << ".bin";

    if (_isOverwrite == false)
    {
        if (creat(nameFile.str().c_str(), S_IRWXU) < 0)
        {
            perror("Invoke creat() failed");

            exit(EXIT_FAILURE);
        }
    }

    fd = ::open(nameFile.str().c_str(), O_WRONLY); //  | O_SYNC | O_RSYNC | O_DSYNC

    if (fd < 0)
    {
        perror("Invoke open() failed");

        exit(EXIT_FAILURE);
    }

    FILE *file = ::fdopen(fd, "w");

    if (file == NULL)
    {
        perror("Invoke fdopen() failed");

        exit(EXIT_FAILURE);
    }

    switch(fork())
    {
    case -1:
    {
        perror("Invoke fork() failed");

        exit(EXIT_FAILURE);
    }
    case 0:  // child
    {
        ushort lastFrameNumber = 0;

        struct timespec waitForRxPacket = { 0, 10000 }; // napewno wiekszy niz 10 us na Friendlyarm

#ifdef DEBUGPRINT
        cout << "Child started" << endl;
#endif

        if (_policy != SCHED_OTHER)
        {
            if (setpriority(PRIO_PROCESS, 0, 0) < 0)
            {
                perror("Invoke setpriority() at child failed");
            }

            sp.__sched_priority = sched_get_priority_min(SCHED_OTHER);

            if (sched_setscheduler(getpid(), SCHED_OTHER, &sp) < 0)
            {
                perror("Invoke sched_setscheduler() at child failed");
            }
        }

        *smWaitForWritingAddr = false;
        uint i;

        for (i = 0; i < _howManyTimes; ++i)
        {
            while (!(i < (*(smCounterRxPacketsAddr))))
            {
#ifdef DEBUGPRINT
                cout << "Invoke nanosleep() in Rx packet =  " << properInSize << endl;
                cout << "Counter = " << (*(smCounterRxPacketsAddr)) << endl;
                cout << "Iteracja child read " << i << endl;
#endif

                if (nanosleep(&waitForRxPacket, NULL))
                {
                    perror("Invoke nanosleep() failed in child");
                }
            }

#ifdef DEBUGPRINT
            cout << "smWaitForWritingAddr in child =  " << *smWaitForWritingAddr << endl;
            cout << "Roznica = " << ((*(smCounterRxPacketsAddr)) - i) << endl;
#endif


#ifdef DEBUGPRINT
            cout << "Counter = " << (*(smCounterRxPacketsAddr)) << endl;
#endif

            //            currentIndex = (i % MULTI_RX_PACKET);
            currentPositionInRxPacketsBuf = (smRxPacketsAddr + (_inSize * (i % MULTI_RX_PACKET)));

            if (::write(fd, (const void *)currentPositionInRxPacketsBuf,
                        _inSize) < 0)
            {
                perror("Invoke write() to file failed in child");

                exit(EXIT_FAILURE);
            }

            //            ackPacket = (bool *)(currentPositionInRxPacketsBuf + sizeof (float));
            **ackPacket = true;
        }

        if (::close(fd) < 0)
        {
            perror("Closing binary write file descriptor failed in child");

            exit(EXIT_FAILURE);
        }

        fd = ::open(nameFile.str().c_str(), O_RDONLY); //

        if (fd < 0)
        {
            perror("Invoke oen() failed");

            exit(EXIT_FAILURE);
        }

        ostringstream nameFileMatlab("./");
        nameFileMatlab << _prefixFile << "data_" << _outSize << "_" << properInSize << "_x" << _howManyTimes << ".m";

        ofstream outFileMatlab(nameFileMatlab.str().c_str(), ios_base::binary | ios_base::out);

        if (!outFileMatlab.is_open())
        {
            cerr << "Couldn't open file to write matlab totals" << endl;

            exit(EXIT_FAILURE);
        }

        userTime = (float *)(smRxPacketsAddr + shiftUserTime);
        uchar *totalCard = (smRxPacketsAddr + shiftBuf);

        double sumDt = 0;
        double sumUserDt = 0;

        outFileMatlab << "dane.rozmiarWysylanegoPakietu = " << _outSize << ";" << endl;
        outFileMatlab << "dane.rozmiarOdbieranegoPakietu = " << properInSize << ";" << endl;
        outFileMatlab << "dane.wartosci = [" << endl;


        for (i = 0; i < 2; ++i) // read 2 initializing packets with error measurement
        {
#ifdef DEBUGPRINT
            cout << "Iteracja write " << i << endl;
#endif

            if (::read(fd, (void *)smRxPacketsAddr, _inSize) < 0)
            {
                perror("Invoke read() on binary file failed in child");

                exit(EXIT_FAILURE);
            }

            // TODO: Fault aligned
            total.userDt = *userTime;
            total.frameNumber = totalCard[0] + (totalCard[1] * UCHAR_RANGED); // %dFrameNum=DT
            total.dt = totalCard[4] + (totalCard[5] * UCHAR_RANGED); // %pktCnt

#ifdef DEBUGPRINT
            cout << total.frameNumber << ", " << total.userDt << ", " << total.dt << ";" << endl;
#endif

            lastFrameNumber = total.frameNumber;
            total.frameNumber = i;
            outFileMatlab << total.frameNumber << ", " << total.userDt << ", " << total.dt << ";" << endl;
            sumDt += total.dt;
            sumUserDt += total.userDt;
        }

        for ( ; i < _howManyTimes; ++i)
        {
#ifdef DEBUGPRINT
            cout << "Iteracja write " << i << endl;
#endif

            if (::read(fd, (void *)smRxPacketsAddr, _inSize) < 0)
            {
                perror("Invoke read() on binary file failed in child");

                exit(EXIT_FAILURE);
            }

            total.userDt = *userTime;

            total.frameNumber = totalCard[0] + (totalCard[1] * UCHAR_RANGED); // %dFrameNum=DT

            total.dt = totalCard[4] + (totalCard[5] * UCHAR_RANGED); // %pktCnt

#ifdef DEBUGPRINT
            cout << total.frameNumber << ", " << total.userDt << ", " << total.dt << ";" << endl;
#endif

            // %sprawdzenie ciaglosci numeracji pakietow
            if ((total.frameNumber - lastFrameNumber) != 1)
            {
                cout << "Iteration [" << i << "]" << endl;
                cout << "Current framenumber [" << total.frameNumber << "]" << endl;
                cout << "LastFrameNumber [" << lastFrameNumber << "]" << endl;
                throw UsbWrapException("Discontinuity in the reception of packets");
            }

            lastFrameNumber = total.frameNumber;

            total.frameNumber = i;

            outFileMatlab << total.frameNumber << ", " << total.userDt << ", " << total.dt << ";" << endl;

            sumDt += total.dt;
            sumUserDt += total.userDt;
        }

        outFileMatlab << "];" << endl;
        outFileMatlab << "dane.sumDT = " << sumDt << ";" << endl;
        outFileMatlab << "dane.sumUserDT = " << sumUserDt << ";" << endl;
        outFileMatlab << "dane.srednia = " << (sumDt / _howManyTimes) << ";" << endl;
        outFileMatlab << "dane.sredniaUser = "******";" << endl;
        outFileMatlab << "dane.ileRazy = " << _howManyTimes << ";" << endl;
        outFileMatlab << "dane.nazwa = '" << _outSize << "/" << properInSize << "/x" << _howManyTimes << "';" << endl;

        outFileMatlab.close();

        if (::close(fd) < 0)
        {
            perror("Closing binary write file descriptor failed in child");

            exit(EXIT_FAILURE);
        }

        if (_isOverwrite == true)
        {
            if (::remove(nameFile.str().c_str()) < 0)
            {
                perror("Removing binary file with totals failed in child");
            }
        }

#ifdef DEBUGPRINT
        cout << "Return child" << endl;
#endif
        if (::close(smRxPacketsFd) < 0)
        {
            perror("Invoke close() for SM_RX_PACKETS_PATH failed in child");
        }

        if (::close(smCounterRxPacketsFd) < 0)
        {
            perror("Invoke close() for SM_COUNTER_RX_PACKETS_PATH failed in child");
        }

        if (shm_unlink(SM_RX_PACKETS_PATH) < 0)
        {
            perror("Invoke shm_unlink() for SM_RX_PACKETS_PATH failed in child");
        }

        if (shm_unlink(SM_COUNTER_RX_PACKETS_PATH) < 0)
        {
            perror("Invoke shm_unlink() for SM_COUNTER_RX_PACKETS_PATH failed in child");
        }

        if (shm_unlink(SM_CYCLE_TIME_RX_PACKET_PATH) < 0)
        {
            perror("Invoke shm_unlink() for SM_CYCLE_TIME_RX_PACKET_PATH failed in child");
        }

        exit(EXIT_SUCCESS);
    }
    default: // parent
    {
#ifdef DEBUGPRINT
        cout << "Parent started" << endl;
#endif

        if (_policy != SCHED_OTHER)
        {
            if (setpriority(PRIO_PROCESS, 0, -20) < 0)
            {
                perror("Invoke setpriority() at parent failed");
            }

            sp.__sched_priority = sched_get_priority_max(_policy) - 1;

            if (sched_setscheduler(getpid(), _policy, &sp) < 0)
            {
                perror("Invoke sched_setscheduler() at parent failed");
            }
        }

        struct timespec waitForWriting = { 0, 10000 };

        timespec previousTime = { 0, 0 }, currentTime = { 0, 0 };

        while ((*smWaitForWritingAddr) == true)
        {
#ifdef DEBUGPRINT
            cout << "smWaitForWritingAddr in parentbefore loop = " << (*smWaitForWritingAddr) << endl;
#endif
            if (nanosleep(&waitForWriting, NULL) < 0)
            {
                perror("Invoke nanosleep() failed in parent");
            }
        }

        if (clock_gettime(CLOCK_REALTIME, &previousTime) < 0)
        {
            perror("Invoke start clock_gettime() failed");

            exit(EXIT_FAILURE);
        }

        for (ushort i = 0; i < _howManyTimes; ++i) // główna pętla programu pomiarowego
        {
#ifdef DEBUGPRINT
            cout << "Iteration in loop write:  " << i << endl;
#endif

            if (clock_gettime(CLOCK_REALTIME, &currentTime) < 0)
            {
                perror("Invoke stop clock_gettime() failed");

                exit(EXIT_FAILURE);
            }

            //            currentIndex = (i % MULTI_RX_PACKET);
            currentPositionInRxPacketsBuf = smRxPacketsAddr + ((i % MULTI_RX_PACKET) * _inSize);

#ifdef DEBUGPRINT
            cout << "After  currentPositionInRxPacketsBuf = smRxPacketsAddr + (currentIndex * _inSize);" << endl;
#endif

            //            while ((**ackPacket).ack != currentIndex)
            while (**ackPacket == false)
            {
#ifdef DEBUGPRINT
                cout << "(**ackPacket).ack == false in parent " << endl;
#endif
                if (nanosleep(&waitForWriting, NULL) < 0)
                {
                    perror("Invoke nanosleep() failed in parent");
                }
            }

            DebugingPacket(_transmittedPacket, _outSize);

            _usb->Send(_transmittedPacket, _outSize);

            _usb->Receive(currentPositionInRxPacketsBuf + shiftBuf, properInSize);

            **ackPacket = false;

            DebugingPacket((currentPositionInRxPacketsBuf + sizeof (bool) + sizeof (float)), properInSize);

            userTime = (float *)(currentPositionInRxPacketsBuf + shiftUserTime);

            *userTime = (float( currentTime.tv_sec - previousTime.tv_sec ) * 1000)
                    + (float( currentTime.tv_nsec - previousTime.tv_nsec ) / 1000000);

            ++(*smCounterRxPacketsAddr);

#ifdef DEBUGPRINT
            cout << "Counter in parent = " << (*(smCounterRxPacketsAddr)) << endl;
            cout << "Iteration in loop parent write:  " << i << endl;
#endif

            previousTime.tv_sec = currentTime.tv_sec;
            previousTime.tv_nsec = currentTime.tv_nsec;
        }

#ifdef DEBUGPRINT
        cout << "End for() loop in Parent" << endl;
#endif

        ClearArray(_transmittedPacket, _outSize);

        // %reset dlugosci - bo teraz znamy biezacy rozmiar stream
        _transmittedPacket[_outSize - 1] = 'a';
        _transmittedPacket[0] = 0x02;
        // %tutaj: wysylamy bufor dlugosci streamOUTsize !!!!
        _transmittedPacket[4] = _outSize % UCHAR_RANGED;
        _transmittedPacket[5] = (_outSize - (_outSize % UCHAR_RANGED)) /  UCHAR_RANGED;
        // nastawy
        _transmittedPacket[8] = DEFAULT_OUT_SIZE % UCHAR_RANGED;
        _transmittedPacket[9] = (DEFAULT_OUT_SIZE - (DEFAULT_OUT_SIZE % UCHAR_RANGED)) / UCHAR_RANGED;

        _transmittedPacket[10] = DEFAULT_IN_SIZE % UCHAR_RANGED;
        _transmittedPacket[11] = (DEFAULT_IN_SIZE - (DEFAULT_IN_SIZE % UCHAR_RANGED)) / UCHAR_RANGED;

        //DebugingPacket(_transmittedPacket, _outSize);

        _usb->Send(_transmittedPacket, _outSize);

        ClearArray(_receivedPacket, _inSize);

        _usb->Receive(_receivedPacket, DEFAULT_IN_SIZE);

        if (_receivedPacket != NULL)
        {
            delete [] _receivedPacket;
            _receivedPacket = NULL;
        }

        if (_transmittedPacket != NULL)
        {
            delete [] _transmittedPacket;
            _transmittedPacket = NULL;
        }

        wait(NULL);

        return;
    }
    }
}
Exemple #5
0
int main() {
    std::ios::sync_with_stdio(false);
    std::ifstream nameFile("data/images.txt");
    std::vector<std::string> names(TEST_SIZE);
    for (int i = 0; i < TEST_SIZE; ++i) {
        std::getline(nameFile, names[i]);
    }
    nameFile.close();

    auto rgbHist10Tree = ImageTree<double, RGB_HIST_10_DIMENSION>::fromFile("data/RGB_Hist_10.txt");
    auto hsvHist10Tree = ImageTree<double, HSV_HIST_10_DIMENSION>::fromFile("data/HSV_Hist_10.txt");
    auto rgbHist20Tree = ImageTree<double, RGB_HIST_20_DIMENSION>::fromFile("data/RGB_Hist_20.txt");
    auto hsvHist20Tree = ImageTree<double, HSV_HIST_20_DIMENSION>::fromFile("data/HSV_Hist_20.txt");
    auto rgbHist10TreeST = ImageTree<double, RGB_HIST_10_DIMENSION>::fromFile("data/RGB_Hist_10_St.txt");
    auto hsvHist10TreeST = ImageTree<double, HSV_HIST_10_DIMENSION>::fromFile("data/HSV_Hist_10_St.txt");
    auto rgbHist20TreeST = ImageTree<double, RGB_HIST_20_DIMENSION>::fromFile("data/RGB_Hist_20_St.txt");
    auto hsvHist20TreeST = ImageTree<double, HSV_HIST_20_DIMENSION>::fromFile("data/HSV_Hist_20_St.txt");
    auto colorMomentTree = ImageTree<double, COLOR_MOMENT_DIMENSION>::fromFile("data/Color_Moment.txt");

    std::ifstream rgbHist10File("data/RGB_Hist_10.txt");
    std::ifstream hsvHist10File("data/HSV_Hist_10.txt");
    std::ifstream rgbHist20File("data/RGB_Hist_20.txt");
    std::ifstream hsvHist20File("data/HSV_Hist_20.txt");
    std::ifstream rgbHist10FileST("data/RGB_Hist_10_St.txt");
    std::ifstream hsvHist10FileST("data/HSV_Hist_10_St.txt");
    std::ifstream rgbHist20FileST("data/RGB_Hist_20_St.txt");
    std::ifstream hsvHist20FileST("data/HSV_Hist_20_St.txt");
    std::ifstream colorMomentFile("data/Color_Moment.txt");

    long rgbHist10Sum = 0;
    long hsvHist10Sum = 0;
    long rgbHist20Sum = 0;
    long hsvHist20Sum = 0;
    long rgbHist10SumST = 0;
    long hsvHist10SumST = 0;
    long rgbHist20SumST = 0;
    long hsvHist20SumST = 0;
    long colorMomentSum = 0;

    int rgbHist10Times = 0;
    int hsvHist10Times = 0;
    int rgbHist20Times = 0;
    int hsvHist20Times = 0;
    int rgbHist10TimesST = 0;
    int hsvHist10TimesST = 0;
    int rgbHist20TimesST = 0;
    int hsvHist20TimesST = 0;
    int colorMomentTimes = 0;

    std::vector<std::string> rgbHist10Lines(TEST_SIZE);
    std::vector<std::string> hsvHist10Lines(TEST_SIZE);
    std::vector<std::string> rgbHist20Lines(TEST_SIZE);
    std::vector<std::string> hsvHist20Lines(TEST_SIZE);
    std::vector<std::string> rgbHist10LinesST(TEST_SIZE);
    std::vector<std::string> hsvHist10LinesST(TEST_SIZE);
    std::vector<std::string> rgbHist20LinesST(TEST_SIZE);
    std::vector<std::string> hsvHist20LinesST(TEST_SIZE);
    std::vector<std::string> colorMomentLines(TEST_SIZE);

    for (int i = 0; i < TEST_SIZE; ++i) {
        std::getline(rgbHist10File, rgbHist10Lines[i]);
        std::getline(hsvHist10File, hsvHist10Lines[i]);
        std::getline(rgbHist20File, rgbHist20Lines[i]);
        std::getline(hsvHist20File, hsvHist20Lines[i]);
        std::getline(rgbHist10FileST, rgbHist10LinesST[i]);
        std::getline(hsvHist10FileST, hsvHist10LinesST[i]);
        std::getline(rgbHist20FileST, rgbHist20LinesST[i]);
        std::getline(hsvHist20FileST, hsvHist20LinesST[i]);
        std::getline(colorMomentFile, colorMomentLines[i]);

        std::stringstream rgbHist10Sline(rgbHist10Lines[i]);
        std::stringstream hsvHist10Sline(hsvHist10Lines[i]);
        std::stringstream rgbHist20Sline(rgbHist20Lines[i]);
        std::stringstream hsvHist20Sline(hsvHist20Lines[i]);
        std::stringstream rgbHist10SlineST(rgbHist10LinesST[i]);
        std::stringstream hsvHist10SlineST(hsvHist10LinesST[i]);
        std::stringstream rgbHist20SlineST(rgbHist20LinesST[i]);
        std::stringstream hsvHist20SlineST(hsvHist20LinesST[i]);
        std::stringstream colorMomentSline(colorMomentLines[i]);

        std::array<double, RGB_HIST_10_DIMENSION> rgbHist10Data;
        std::array<double, HSV_HIST_10_DIMENSION> hsvHist10Data;
        std::array<double, RGB_HIST_20_DIMENSION> rgbHist20Data;
        std::array<double, HSV_HIST_20_DIMENSION> hsvHist20Data;
        std::array<double, RGB_HIST_10_DIMENSION> rgbHist10DataST;
        std::array<double, HSV_HIST_10_DIMENSION> hsvHist10DataST;
        std::array<double, RGB_HIST_20_DIMENSION> rgbHist20DataST;
        std::array<double, HSV_HIST_20_DIMENSION> hsvHist20DataST;
        std::array<double, COLOR_MOMENT_DIMENSION> colorMomentData;

        for (int j = 0; j < RGB_HIST_10_DIMENSION; ++j) {
            rgbHist10Sline >> rgbHist10Data[j];
        }

        for (int j = 0; j < RGB_HIST_10_DIMENSION; ++j) {
            hsvHist10Sline >> hsvHist10Data[j];
        }
        for (int j = 0; j < RGB_HIST_20_DIMENSION; ++j) {
            rgbHist20Sline >> rgbHist20Data[j];
        }

        for (int j = 0; j < RGB_HIST_20_DIMENSION; ++j) {
            hsvHist20Sline >> hsvHist20Data[j];
        }

        for (int j = 0; j < RGB_HIST_10_DIMENSION; ++j) {
            rgbHist10SlineST >> rgbHist10DataST[j];
        }

        for (int j = 0; j < RGB_HIST_10_DIMENSION; ++j) {
            hsvHist10SlineST >> hsvHist10DataST[j];
        }

        for (int j = 0; j < RGB_HIST_20_DIMENSION; ++j) {
            rgbHist20SlineST >> rgbHist20DataST[j];
        }

        for (int j = 0; j < RGB_HIST_20_DIMENSION; ++j) {
            hsvHist20SlineST >> hsvHist20DataST[j];
        }

        for (int j = 0; j < COLOR_MOMENT_DIMENSION; ++j) {
            colorMomentSline >> colorMomentData[j];
        }

        Image<double, RGB_HIST_10_DIMENSION> rgbHist10Img(names[i], rgbHist10Data);
        Image<double, HSV_HIST_10_DIMENSION> hsvHist10Img(names[i], hsvHist10Data);
        Image<double, RGB_HIST_20_DIMENSION> rgbHist20Img(names[i], rgbHist20Data);
        Image<double, HSV_HIST_20_DIMENSION> hsvHist20Img(names[i], hsvHist20Data);
        Image<double, RGB_HIST_10_DIMENSION> rgbHist10ImgST(names[i], rgbHist10DataST);
        Image<double, HSV_HIST_10_DIMENSION> hsvHist10ImgST(names[i], hsvHist10DataST);
        Image<double, RGB_HIST_20_DIMENSION> rgbHist20ImgST(names[i], rgbHist20DataST);
        Image<double, HSV_HIST_20_DIMENSION> hsvHist20ImgST(names[i], hsvHist20DataST);
        Image<double, COLOR_MOMENT_DIMENSION> colorMomentImg(names[i], colorMomentData);

        rgbHist10Tree.search(rgbHist10Data);
        rgbHist10Times += rgbHist10Tree.queryTimes;
        std::vector<Image<double, RGB_HIST_10_DIMENSION>> rgbHist10Results = rgbHist10Tree.getResults();
        rgbHist10Sum += std::count(rgbHist10Results.begin(), rgbHist10Results.end(), rgbHist10Img);

        hsvHist10Tree.search(hsvHist10Data);
        hsvHist10Times += hsvHist10Tree.queryTimes;
        std::vector<Image<double, HSV_HIST_10_DIMENSION>> hsvHist10Results = hsvHist10Tree.getResults();
        hsvHist10Sum += std::count(hsvHist10Results.begin(), hsvHist10Results.end(), hsvHist10Img);

        rgbHist20Tree.search(rgbHist20Data);
        rgbHist20Times += rgbHist20Tree.queryTimes;
        std::vector<Image<double, RGB_HIST_20_DIMENSION>> rgbHist20Results = rgbHist20Tree.getResults();
        rgbHist20Sum += std::count(rgbHist20Results.begin(), rgbHist20Results.end(), rgbHist20Img);

        hsvHist20Tree.search(hsvHist20Data);
        hsvHist20Times += hsvHist20Tree.queryTimes;
        std::vector<Image<double, HSV_HIST_20_DIMENSION>> hsvHist20Results = hsvHist20Tree.getResults();
        hsvHist20Sum += std::count(hsvHist20Results.begin(), hsvHist20Results.end(), hsvHist20Img);

        rgbHist10TreeST.search(rgbHist10DataST);
        rgbHist10TimesST += rgbHist10TreeST.queryTimes;
        std::vector<Image<double, RGB_HIST_10_DIMENSION>> rgbHist10ResultsST = rgbHist10TreeST.getResults();
        rgbHist10SumST += std::count(rgbHist10ResultsST.begin(), rgbHist10ResultsST.end(), rgbHist10ImgST);

        hsvHist10TreeST.search(hsvHist10DataST);
        hsvHist10TimesST += hsvHist10TreeST.queryTimes;
        std::vector<Image<double, HSV_HIST_10_DIMENSION>> hsvHist10ResultsST = hsvHist10TreeST.getResults();
        hsvHist10SumST += std::count(hsvHist10ResultsST.begin(), hsvHist10ResultsST.end(), hsvHist10ImgST);

        rgbHist20TreeST.search(rgbHist20DataST);
        rgbHist20TimesST += rgbHist20TreeST.queryTimes;
        std::vector<Image<double, RGB_HIST_20_DIMENSION>> rgbHist20ResultsST = rgbHist20TreeST.getResults();
        rgbHist20SumST += std::count(rgbHist20ResultsST.begin(), rgbHist20ResultsST.end(), rgbHist20ImgST);

        hsvHist20TreeST.search(hsvHist20DataST);
        hsvHist20TimesST += hsvHist20TreeST.queryTimes;
        std::vector<Image<double, HSV_HIST_20_DIMENSION>> hsvHist20ResultsST = hsvHist20TreeST.getResults();
        hsvHist20SumST += std::count(hsvHist20ResultsST.begin(), hsvHist20ResultsST.end(), hsvHist20ImgST);

        colorMomentTree.search(colorMomentData);
        colorMomentTimes += colorMomentTree.queryTimes;
        std::vector<Image<double, COLOR_MOMENT_DIMENSION>> colorMomentResults = colorMomentTree.getResults();
        colorMomentSum += std::count(colorMomentResults.begin(), colorMomentResults.end(), colorMomentImg);
    }

    std::cout << "RGB Hist 10d: " << (double)rgbHist10Sum / TEST_SIZE * 10 << " in " << rgbHist10Times << " times." << std::endl;
    std::cout << "HSV Hist 10d: " << (double)hsvHist10Sum / TEST_SIZE * 10 << " in " << hsvHist10Times << " times." << std::endl;
    std::cout << "RGB Hist 20d: " << (double)rgbHist20Sum / TEST_SIZE * 10 << " in " << rgbHist20Times << " times." << std::endl;
    std::cout << "HSV Hist 20d: " << (double)hsvHist20Sum / TEST_SIZE * 10 << " in " << hsvHist20Times << " times." << std::endl;
    std::cout << "RGB ST Hist 10d: " << (double)rgbHist10SumST / TEST_SIZE * 10 << " in " << rgbHist10TimesST << " times." << std::endl;
    std::cout << "HSV ST Hist 10d: " << (double)hsvHist10SumST / TEST_SIZE * 10 << " in " << hsvHist10TimesST << " times." << std::endl;
    std::cout << "RGB ST Hist 20d: " << (double)rgbHist20SumST / TEST_SIZE * 10 << " in " << rgbHist20TimesST << " times." << std::endl;
    std::cout << "HSV ST Hist 20d: " << (double)hsvHist20SumST / TEST_SIZE * 10 << " in " << hsvHist20TimesST << " times." << std::endl;
    std::cout << "Color Moment 9d: " << (double)colorMomentSum / TEST_SIZE * 10 << " in " << colorMomentTimes << " times." << std::endl;

    rgbHist10File.close();
    hsvHist10File.close();
    rgbHist20File.close();
    hsvHist20File.close();
    rgbHist10FileST.close();
    hsvHist10FileST.close();
    rgbHist20FileST.close();
    hsvHist20FileST.close();
    colorMomentFile.close();
}
void Spooler::Run()
{
    //    timeval stopTimer;
    //    timeval startTimer;                             //   %start pomiaru czasu
    int pfd[2];
    ssize_t numRead;
    Total total;
    ushort totalStructSize = sizeof (Total);
    struct pollfd readPoll;


    
    if (pipe(pfd) == -1)
    {
        perror("Invoke pipe() failed");
    }
    
    switch(fork())
    {
    case -1:
    {
        perror("Invoke fork() failed");

        exit(EXIT_FAILURE);
    }
    case 0:  // child
    {
        ushort lastFrameNumber = 0;

        if (close(pfd[1]) == -1)
        {
            perror("Closing write file descriptor failed in child");
        }

        memset (&readPoll, 0, sizeof(readPoll)); // not necessary, but I am paranoid

        // first slot for readfd polled for input
        readPoll.fd = pfd[0];
        readPoll.events = POLLIN;
        readPoll.revents = 0;

        // do the poll(2) syscall with a 100 millisecond timeout
        int retPoll = poll(&readPoll, 1, 100);

        if (retPoll > 0) {
           if (readPoll.revents & POLLIN) {
              /* read from readfd,
                 since you can read from it without being blocked */
           }
        }
        else if (retPoll == 0) {
           /* the poll has timed out, nothing can be read or written */
        }
        else {
           /* the poll failed */
            perror("Invoke poll() failed");
        }

        ostringstream nameFile("./");
        nameFile << _prefixFile << "_" << _outSize << "_" << _inSize << "_x" << _howManyTimes << ".m";
        
        ofstream outFile(nameFile.str().c_str(), ios_base::binary | ios_base::out | ios_base::out);
        
        if (!outFile.is_open())
        {
            cerr << "Couldn't open file to write" << endl;
            
            exit(EXIT_FAILURE);
        }
        
        
        outFile << "dane.rozmiarWysylanegoPakietu = " << _outSize << ";" << endl;
        outFile << "dane.rozmiarOdbieranegoPakietu = " << _inSize << ";" << endl;
        outFile << "dane.wartosci = [" << endl;

        int i = 0;

        // Niewystarczy tylko raz?
        for (; i < 2; ++i)
        {
            numRead = read(pfd[0], &total, totalStructSize);

            if (numRead < 1)
            {
                if (numRead == -1)
                {
                    perror("Invoke read() failed in child");
                }

                if (numRead == 0)
                {
                    continue;
                }
            }

            lastFrameNumber = total.frameNumber;
#ifdef DEBUGPRINT
            cout << "Framenumber = " << total.frameNumber << endl;
#endif
            outFile << lastFrameNumber << ", " << total.dt << ";" << endl;
        }

        for (; i < _howManyTimes; ++i)
        {
            for (;;)
            {
                numRead = read(pfd[0], &total, totalStructSize);
                
                if (numRead < 1)
                {
                    if (numRead == -1)
                    {
                        perror("Invoke read() failed in child");
                    }
                    
                    if (numRead == 0)
                    {
                        continue;
                    }
                }
                
                break;
            }
#ifdef DEBUGPRINT
            cout << "Iteracja write " << i << endl;
            cout << "Framenumber = " << total.frameNumber << endl;
#endif

            // %sprawdzenie ciaglosci numeracji pakietow
            if ((total.frameNumber - lastFrameNumber) != 1)
            {
                throw UsbWrapException("Discontinuity in the reception of packets");
            }

            lastFrameNumber = total.frameNumber;
            
            outFile << i << ", " << total.dt << ";" << endl;
        }

        _sum = 0 ;

        for (ushort i = 0; i < _howManyTimes; i++)
        {
            _sum +=  _dt[i];
        }

        _mean =  _sum/_howManyTimes;
        
        outFile << "];" << endl;
        outFile << "dane.ileRazy = " << _howManyTimes << ";" << endl;
        outFile << "dane.sumDT = " << _sum << ";" << endl;
        outFile << "dane.sredniaDT = " << _mean << ";" << endl;
        outFile << "dane.nazwa = '" << _outSize << "_" << _inSize << "_x" << _howManyTimes << "';" << endl;
        
        outFile.close();
        
        if (close(pfd[0]) == -1)
        {
        	perror("Closing read file descriptor failed in child");
        }
        
#ifdef DEBUGPRINT
        cout << "Return child" << endl;
#endif

        exit(EXIT_SUCCESS);
    }
    default: // parent
    {
        
        if (close(pfd[0]) == -1)
        {
        	perror("Closing read file descriptor failed in parent");
        }
        
        timespec dtStart = { 0, 0 }, dtStop = { 0, 0 };
        
        for (ushort i = 0; i < _howManyTimes; ++i) // główna pętla programu pomiarowego
        {
#ifdef DEBUGPRINT
            cout << "Iteration in loop write:  " << i << endl;
#endif
            //DebugingPacket(_transmittedPacket, _outSize);
            
            //        if (gettimeofday(&startTimer, NULL))
            //        {
            //            perror("gettimeofday()");
            //        }
            
            clock_gettime(CLOCK_REALTIME, &dtStart);
            
            _usb->Send(_transmittedPacket, _outSize);
            
            //        %byc moze tutaj lepiej jest wstawic jakiekolwiek opoznienie, aby nie
            //                %za szybko wchodzic w fread
            //                %for(ii=1:5*330000)  %zachowuje sie addytywnie dla r=0
            //                %end
            
            ClearArray(_receivedPacket, _inSize);
            
            _usb->Receive(_receivedPacket, _inSize);
            
            clock_gettime(CLOCK_REALTIME, &dtStop);
            
            // DebugingPacket(_receivedPacket, _inSize);
            
            //        if (gettimeofday(&stopTimer, NULL))
            //        {
            //            perror("gettimeofday()");
            //        }
            
            //        _elapsedTime[i] = ((stopTimer.tv_sec - startTimer.tv_sec) * 1000) + ((stopTimer.tv_usec - startTimer.tv_usec) / 1000);
            
            total.frameNumber = _receivedPacket[0] + (_receivedPacket[1] * UCHAR_RANGED); // %dFrameNum=DT
            total.dt = _receivedPacket[4] + (_receivedPacket[5] * UCHAR_RANGED); // %pktCnt
            
            if (write(pfd[1], &total, totalStructSize) != totalStructSize)
            {
                perror("parent - partial/failed write");
                exit(EXIT_FAILURE);
            }
        }
        
        cout << "End for" << endl;
        
        ClearArray(_transmittedPacket, _outSize);
        
        // %reset dlugosci - bo teraz znamy biezacy rozmiar stream
        _transmittedPacket[_outSize - 1] = 'a';
        _transmittedPacket[0] = 0x02;
        // %tutaj: wysylamy bufor dlugosci streamOUTsize !!!!
        _transmittedPacket[4] = _outSize % UCHAR_RANGED;
        _transmittedPacket[5] = (_outSize - (_outSize % UCHAR_RANGED)) /  UCHAR_RANGED;
        // nastawy
        _transmittedPacket[8] = DEFAULT_OUT_SIZE % UCHAR_RANGED;
        _transmittedPacket[9] = (DEFAULT_OUT_SIZE - (DEFAULT_OUT_SIZE % UCHAR_RANGED)) / UCHAR_RANGED;
        
        _transmittedPacket[10] = DEFAULT_IN_SIZE % UCHAR_RANGED;
        _transmittedPacket[11] = (DEFAULT_IN_SIZE - (DEFAULT_IN_SIZE % UCHAR_RANGED)) / UCHAR_RANGED;
        
        //DebugingPacket(_transmittedPacket, _outSize);
        
        _usb->Send(_transmittedPacket, _outSize);

        ClearArray(_receivedPacket, _inSize);
        
        _usb->Receive(_receivedPacket, DEFAULT_IN_SIZE);
        
        //DebugingPacket(_receivedPacket, _inSize);
        
        //    ushort currentOutSize = _receivedPacket[16] + (UCHAR_RANGED * _receivedPacket[17]);
        //    ushort currentInSize = _receivedPacket[18] + (UCHAR_RANGED * _receivedPacket[19]);
        
        if (_receivedPacket != NULL)
        {
            delete [] _receivedPacket;
            _receivedPacket = NULL;
        }
        
        if (_transmittedPacket != NULL)
        {
            delete [] _transmittedPacket;
            _transmittedPacket = NULL;
        }
        
        wait(NULL);

        if (close(pfd[1]) == -1)
        {
        	perror("Closing write file descriptor failed in parent");
        }
        
        return;
    }
    }
}
Exemple #7
0
int FixUsersCommand::Execute() {
  LOG << "Runnning FixUsersCommand::Execute";

  initStatusDat(config()->config()->datadir());
  File userFile(config()->config()->datadir(), USER_LST);
	if (!userFile.Exists()) {
    LOG << userFile.full_pathname() << " does not exist.";
    return 1;
	}

	UserManager userMgr(config()->config()->datadir(), sizeof(userrec), 
      config()->config()->config()->maxusers);
  LOG << "Checking USER.LST... found " << userMgr.GetNumberOfUserRecords() << " user records.";
  LOG << "TBD: Check for trashed user recs.";
	if (userMgr.GetNumberOfUserRecords() > config()->config()->config()->maxusers) {
    LOG << "Might be too many.";
    if (!arg("exp").as_bool()) {
      return 1;
    }
	} else {
    LOG << "Reasonable number.";
	}

	std::vector<smalrec> smallrecords;
	std::set<std::string> names;

  const int num_user_records = userMgr.GetNumberOfUserRecords();
	for(int i = 1; i <= num_user_records; i++) {
		User user;
		userMgr.ReadUser(&user, i);
		user.FixUp();
		userMgr.WriteUser(&user, i);
		if (!user.IsUserDeleted() && !user.IsUserInactive()) {
			smalrec sr = { 0 };
			strcpy((char*) sr.name, user.GetName());
			sr.number = static_cast<uint16_t>(i);
			std::string namestring((char*) sr.name);
			if (names.find(namestring) == names.end()) {
				smallrecords.push_back(sr);
				names.insert(namestring);
        if (arg("verbose").as_bool()) {
          LOG << "Keeping user: "******" #" << sr.number ;
        }
			} else {
				LOG << "[skipping duplicate user: "******" #" << sr.number << "]";
			}
		}
	};

	std::sort(smallrecords.begin(), smallrecords.end(), [](const smalrec& a, const smalrec& b) -> bool {
		int equal = strcmp((char*)a.name, (char*)b.name);

		// Sort by user number if names match.
		if (equal == 0) {
			return a.number < b.number;
		}

		// Otherwise sort by name comparison.
		return equal < 0;
	});

	printf("size=%lu %lu\n", smallrecords.size(), sizeof(smalrec) * smallrecords.size());
  LOG << "Checking NAMES.LST";
	File nameFile(config()->config()->datadir(), NAMES_LST);
	if (!nameFile.Exists()) {
    LOG << nameFile.full_pathname() << " does not exist, regenerating with "
         << smallrecords.size() << " names";
		nameFile.Open(File::modeCreateFile | File::modeBinary | File::modeWriteOnly);
		nameFile.Write(&smallrecords[0], sizeof(smalrec) * smallrecords.size());
		nameFile.Close();
	} else {
		if (nameFile.Open(File::modeReadOnly | File::modeBinary)) {
			long size = nameFile.GetLength();
      uint16_t recs = static_cast<uint16_t>(size / sizeof(smalrec));
			if (recs != status.users) {
				status.users = recs;
        LOG << "STATUS.DAT contained an incorrect user count.";
			} else {
        LOG << "STATUS.DAT matches expected user count of " << status.users << " users.";
			}
		}
		nameFile.Close();
	}
  return 0;
}
Exemple #8
0
int FixUsersCommand::Execute() {
    std::cout << "Runnning FixUsersCommand::Execute" << std::endl;
    	File userFile(syscfg.datadir, USER_LST);
	if(!userFile.Exists()) {
		Print(NOK, true, "%s does not exist.", userFile.full_pathname().c_str());
		giveUp();
	}

	WUserManager userMgr;
	userMgr.InitializeUserManager(syscfg.datadir, sizeof(userrec), syscfg.maxusers);
	Print(OK, true, "Checking USER.LST... found %d user records.", userMgr.GetNumberOfUserRecords());

	Print(OK, true, "TBD: Check for trashed user recs.");
	if(userMgr.GetNumberOfUserRecords() > syscfg.maxusers) {
		Print(OK, true, "Might be too many.");
			maybeGiveUp();
	} else {
		Print(OK, true, "Reasonable number.");
	}

	std::vector<smalrec> smallrecords;
	std::set<std::string> names;

  const int num_user_records = userMgr.GetNumberOfUserRecords();
	for(int i = 1; i <= num_user_records; i++) {
		WUser user;
		userMgr.ReadUser(&user, i);
		user.FixUp();
		userMgr.WriteUser(&user, i);
		if (!user.IsUserDeleted() && !user.IsUserInactive()) {
			smalrec sr = { 0 };
			strcpy((char*) sr.name, user.GetName());
			sr.number = static_cast<unsigned short>(i);
			std::string namestring((char*) sr.name);
			if (names.find(namestring) == names.end()) {
				smallrecords.push_back(sr);
				names.insert(namestring);
        const std::string msg = StringPrintf("Keeping user: %s #%d", sr.name, sr.number);
        Print(OK, true, msg.c_str());
			}
			else {
				std::cout << "[skipping duplicate user: "******" #" << sr.number << "]";
			}
		}
	};

	std::sort(smallrecords.begin(), smallrecords.end(), [](const smalrec& a, const smalrec& b) -> bool {
		int equal = strcmp((char*)a.name, (char*)b.name);

		// Sort by user number if names match.
		if (equal == 0) {
			return a.number < b.number;
		}

		// Otherwise sort by name comparison.
		return equal < 0;
	});

	printf("size=%lu %lu\n", smallrecords.size(), sizeof(smalrec) * smallrecords.size());

	Print(OK, true, "Checking NAMES.LST");
	File nameFile(syscfg.datadir, NAMES_LST);
	if(!nameFile.Exists()) {
		Print(NOK, true, "%s does not exist, regenerating with %d names", nameFile.full_pathname().c_str(),
			smallrecords.size());
		nameFile.Close();
		nameFile.Open(File::modeCreateFile | File::modeBinary | File::modeWriteOnly);
		nameFile.Write(&smallrecords[0], sizeof(smalrec) * smallrecords.size());
		nameFile.Close();

	} else {
		if(nameFile.Open(File::modeReadOnly | File::modeBinary)) {
			unsigned long size = nameFile.GetLength();
			unsigned short recs = static_cast<unsigned short>(size / sizeof(smalrec));
			if (recs != status.users) {
				status.users = recs;
				Print(NOK, true, "STATUS.DAT contained an incorrect user count.");
			} else {
				Print(OK, true, "STATUS.DAT matches expected user count of %d users.", status.users);
			}
		}
		nameFile.Close();
	}
    return 0;
}
bool ContractionHierarchies::Preprocess( IImporter* importer, QString dir )
{
	QString filename = fileInDirectory( dir, "Contraction Hierarchies" );

	std::vector< IImporter::RoutingNode > inputNodes;
	std::vector< IImporter::RoutingEdge > inputEdges;

	if ( !importer->GetRoutingNodes( &inputNodes ) )
		return false;
	if ( !importer->GetRoutingEdges( &inputEdges ) )
		return false;

	unsigned numEdges = inputEdges.size();
	unsigned numNodes = inputNodes.size();

	Contractor* contractor = new Contractor( numNodes, inputEdges );
	std::vector< IImporter::RoutingEdge >().swap( inputEdges );
	contractor->Run();

	std::vector< Contractor::Witness > witnessList;
	contractor->GetWitnessList( witnessList );

	std::vector< ContractionCleanup::Edge > contractedEdges;
	std::vector< ContractionCleanup::Edge > contractedLoops;
	contractor->GetEdges( &contractedEdges );
	contractor->GetLoops( &contractedLoops );
	delete contractor;

	ContractionCleanup* cleanup = new ContractionCleanup( inputNodes.size(), contractedEdges, contractedLoops, witnessList );
	std::vector< ContractionCleanup::Edge >().swap( contractedEdges );
	std::vector< ContractionCleanup::Edge >().swap( contractedLoops );
	std::vector< Contractor::Witness >().swap( witnessList );
	cleanup->Run();

	std::vector< CompressedGraph::Edge > edges;
	std::vector< NodeID > map;
	cleanup->GetData( &edges, &map );
	delete cleanup;

	{
		std::vector< unsigned > edgeIDs( numEdges );
		for ( unsigned edge = 0; edge < edges.size(); edge++ ) {
			if ( edges[edge].data.shortcut )
				continue;
			unsigned id = 0;
			unsigned otherEdge = edge;
			while ( true ) {
				if ( otherEdge == 0 )
					break;
				otherEdge--;
				if ( edges[otherEdge].source != edges[edge].source )
					break;
				if ( edges[otherEdge].target != edges[edge].target )
					continue;
				if ( edges[otherEdge].data.shortcut )
					continue;
				id++;
			}
			edgeIDs[edges[edge].data.id] = id;
		}
		importer->SetEdgeIDMap( edgeIDs );
	}

	std::vector< IRouter::Node > nodes( numNodes );
	for ( std::vector< IImporter::RoutingNode >::const_iterator i = inputNodes.begin(), iend = inputNodes.end(); i != iend; i++ )
		nodes[map[i - inputNodes.begin()]].coordinate = i->coordinate;
	std::vector< IImporter::RoutingNode >().swap( inputNodes );

	std::vector< IRouter::Node > pathNodes;
	{
		std::vector< IImporter::RoutingNode > edgePaths;
		if ( !importer->GetRoutingEdgePaths( &edgePaths ) )
			return false;
		pathNodes.resize( edgePaths.size() );
		for ( unsigned i = 0; i < edgePaths.size(); i++ )
			pathNodes[i].coordinate = edgePaths[i].coordinate;
	}

	if ( !importer->GetRoutingEdges( &inputEdges ) )
		return false;

	{
		std::vector< QString > inputNames;
		if ( !importer->GetRoutingWayNames( &inputNames ) )
			return false;

		QFile nameFile( filename + "_names" );
		if ( !openQFile( &nameFile, QIODevice::WriteOnly ) )
			return false;

		std::vector< unsigned > nameMap( inputNames.size() );
		for ( unsigned name = 0; name < inputNames.size(); name++ ) {
			nameMap[name] = nameFile.pos();
			QByteArray buffer = inputNames[name].toUtf8();
			buffer.push_back( ( char ) 0 );
			nameFile.write( buffer );
		}

		nameFile.close();
		nameFile.open( QIODevice::ReadOnly );
		const char* test = ( const char* ) nameFile.map( 0, nameFile.size() );
		for ( unsigned name = 0; name < inputNames.size(); name++ ) {
			QString testName = QString::fromUtf8( test + nameMap[name] );
			assert( testName == inputNames[name] );
		}

		for ( unsigned edge = 0; edge < numEdges; edge++ )
			inputEdges[edge].nameID = nameMap[inputEdges[edge].nameID];
	}

	{
		std::vector< QString > inputTypes;
		if ( !importer->GetRoutingWayTypes( &inputTypes ) )
			return false;

		QFile typeFile( filename + "_types" );
		if ( !openQFile( &typeFile, QIODevice::WriteOnly ) )
			return false;

		QStringList typeList;
		for ( unsigned type = 0; type < inputTypes.size(); type++ )
			typeList.push_back( inputTypes[type] );

		typeFile.write( typeList.join( ";" ).toUtf8() );
	}

	for ( std::vector< IImporter::RoutingEdge >::iterator i = inputEdges.begin(), iend = inputEdges.end(); i != iend; i++ ) {
		i->source = map[i->source];
		i->target = map[i->target];
	}

	CompressedGraphBuilder* builder = new CompressedGraphBuilder( 1u << m_settings.blockSize, nodes, edges, inputEdges, pathNodes );
	if ( !builder->run( filename, &map ) )
		return false;
	delete builder;

	importer->SetIDMap( map );

	return true;
}