Ejemplo n.º 1
0
PropertyMap FileProperties::asMap() const
{
    PropertyMap dataMap;

    PropertyVector dataVector(asVector());
    for(PropertyVector::const_iterator it = dataVector.begin(); it != dataVector.end(); ++it)
    {
        dataMap.insert(std::make_pair(it->first, it->second));
    }

    return dataMap;
}
Ejemplo n.º 2
0
void QPCurve::appendData(const QVector<float> &data)
{
    QVector<QPointF> dataVector(data.size());

    int id = m_data.size();

    for (int i = 0; i < data.size(); ++i, ++id) {
        dataVector[i] = QPointF(id, data[i]);
    }

    appendData(dataVector);
}
Ejemplo n.º 3
0
String LoggingCanvas::stringForText(const void* text, size_t byteLength, const SkPaint& paint)
{
    SkPaint::TextEncoding encoding = paint.getTextEncoding();
    switch (encoding) {
    case SkPaint::kUTF8_TextEncoding:
    case SkPaint::kUTF16_TextEncoding:
    case SkPaint::kUTF32_TextEncoding:
        return stringForUTFText(text, byteLength, encoding);
    case SkPaint::kGlyphID_TextEncoding: {
        WTF::Vector<SkUnichar> dataVector(byteLength / 2);
        SkUnichar* textData = dataVector.data();
        paint.glyphsToUnichars(static_cast<const uint16_t*>(text), byteLength / 2, textData);
        return WTF::UTF32LittleEndianEncoding().decode(reinterpret_cast<const char*>(textData), byteLength * 2);
    }
    default:
        ASSERT_NOT_REACHED();
        return "?";
    }
}
Ejemplo n.º 4
0
void
VisualMap::write2json(Json::Value& v) const
{
	Json::Value dataVector(Json::arrayValue);
	v["type"] = "visual_map";
	v["width"] = width;
	v["height"] = height;

	v["finish"] = finish;
	v["win"] = win;
        v["score"] = score;

	for(unsigned i=0; i < world.size(); i++) {
		Json::Value pv;
		world[i]->write2json(pv);
		dataVector.append( pv );
	}

	v["data"] = dataVector;



}
Ejemplo n.º 5
0
	void CalibratePassbandAction::calibrate(TimeFrequencyData& data) const
	{
		const size_t height = data.ImageHeight();
		std::vector<num_t> stddev(_steps);
		for(size_t step=0; step!=_steps; ++step)
		{
			const size_t startY = step*height/_steps, endY = (step+1)*height/_steps;
			std::vector<num_t> dataVector((1+endY-startY) * data.ImageWidth() * data.ImageCount());
			std::vector<num_t>::iterator vecIter = dataVector.begin();
			const Mask2DCPtr maskPtr = data.GetSingleMask();
			const Mask2D &mask = *maskPtr;
			for(size_t i=0; i!=data.ImageCount(); ++i)
			{
				const Image2D &image = *data.GetImage(i);
				for(size_t y=startY; y!=endY; ++y)
				{
					const num_t *inputPtr = image.ValuePtr(0, y);
					const bool *maskPtr = mask.ValuePtr(0, y);
					for(size_t x=0; x!=image.Width(); ++x)
					{
						if(!*maskPtr && std::isfinite(*inputPtr))
						{
							*vecIter = *inputPtr;
							++vecIter;
						}
						++inputPtr;
						++maskPtr;
					}
				}
			}
			dataVector.resize(vecIter - dataVector.begin());
			
			num_t mean;
			ThresholdTools::WinsorizedMeanAndStdDev<num_t>(dataVector, mean, stddev[step]);
		}
			
		for(size_t i=0; i!=data.ImageCount(); ++i)
		{
			const Image2D &image = *data.GetImage(i);
			Image2D *destImage = Image2D::CreateUnsetImage(image.Width(), image.Height());
			for(size_t step=0; step!=_steps; ++step)
			{
				const size_t startY = step*height/_steps, endY = (step+1)*height/_steps;
				float correctionFactor;
				if(stddev[step] == 0.0)
					correctionFactor = 0.0;
				else
					correctionFactor = 1.0 / stddev[step];
				const __m128 corrFact4 = _mm_set_ps(correctionFactor, correctionFactor, correctionFactor, correctionFactor);
				
				for(size_t y=startY; y!=endY; ++y)
				{
					const float *inputPtr = image.ValuePtr(0, y);
					float *destPtr = destImage->ValuePtr(0, y);
					
					for(size_t x=0;x<image.Width();x+=4)
					{
						_mm_store_ps(destPtr, _mm_mul_ps(corrFact4, _mm_load_ps(inputPtr)));
						inputPtr += 4;
						destPtr += 4;
					}
				}
			}
			data.SetImage(i, Image2DPtr(destImage));
		}
	}
Ejemplo n.º 6
0
    void NewSearcher::searchBauds()
    {
        bool found = false;
        uint32_t baud = 0;

        for(size_t index = 0; index < TestBaudrates.size(); ++index)
        {
            // Create the serial port
            m_port = new NewSerialPort(m_portList[0], TestBaudrates[index]);

            try
            {
                // Attempt to open the port
                m_port->open();
                m_port->start();
            }
            catch (std::exception e)
            {
                // We don't care what happened.  Simply continue.
                m_port->stop();
                m_port->close();
                delete m_port;
                m_port = NULL;
                continue;
            }

            // create message buffer
            char dataBuffer[] = "$VNRRG,01*XX\r\n";
    		std::vector<char> dataVector(dataBuffer, dataBuffer + sizeof(dataBuffer));

            // search for response for half a second
            Stopwatch stopwatch;

            while((stopwatch.elapsedMs() < 100.0) && !found)
            {
                m_port->write(dataVector);

                // Look for a response packet
                while(m_port->hasPacket() && !found && (stopwatch.elapsedMs() < 100))
                {
                    // Process the packet
                    protocol::uart::Packet* packet = m_port->getNextPacket();
                    if(packet->isResponse())
                    {
                        if(packet->datastr().compare(0, 9, dataBuffer, 9) == 0)
                        {
                            // this is our response
                            found = true;
                            baud = TestBaudrates[index];
                        }
                    }
					// The packet has been spent; clean it up
					delete packet;
                }
            }

            // Clean up
            m_port->stop();
            m_port->close();
            delete m_port;
            m_port = NULL;

            // if we have a resonpse then break else continue
            if ( found )
            {
                // We have a sensor; record the port and baud
                m_validPorts.push_back(std::pair<std::string, uint32_t>(m_portList[0], TestBaudrates[index]));

                break;
            }
        }
    }
int doWork(MPI_Datatype* ResultMpiType,const int k){

    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    int MAX_RESULT_SIZE = k;

    char msg[MAX_MSG_SIZE];
    float cmpData[SEARCH_VECTOR_SIZE];
    double times[2];
    MPI_Status status;
    Timing parserTime;
    Timing searchTime;
    Timing workWallTime;

    workWallTime.start();
    std::chrono::duration<double> read_time_elapse;

    MPI_Recv(cmpData,
        SEARCH_VECTOR_SIZE,
        MPI_FLOAT,
        0,
        MPI_ANY_TAG,
        MPI_COMM_WORLD,
        &status);

    if(status.MPI_TAG != SEARCH_VECTOR){
        std::cout<< rank << " recieved terminate signal" << std::endl;
            return 0;
    }


    while (1) {
        // Receive a message from the master
        MPI_Recv(msg,           /* message buffer */
            MAX_MSG_SIZE,     /* buffer size */
            MPI_CHAR,       /* data item is an integer */
            0,              /* Receive from master */
            MPI_ANY_TAG,
                MPI_COMM_WORLD,     /* default communicator */
                &status);


        // Check if we have been terminated by the master
        // exit from the worker loop
        if (status.MPI_TAG == TERMINATE) {
            std::cout<< rank << " recieved terminate signal" << std::endl;
            return 0;
        }


        std::shared_ptr<MapString_t> nameMap(new MapString_t);
        std::vector<result_t> results;
        std::shared_ptr<std::vector<float>> dataVector(new std::vector<float>);
        Parser p(nameMap,dataVector);

        parserTime.start();
        if(!p.parse_file(msg,&read_time_elapse)){
            std::cerr<<"could not parse file: "<<msg<<std::endl;
            return 0;
        }
        parserTime.end();
        searchTime.start();
        int lineLength = p.get_line_length();
        int index = 0;
        for(auto& file : *nameMap){
            results.push_back(result_t());
            results.at(index).distance = findDist(lineLength,
                dataVector,file.second,cmpData);
            strcpy(results.at(index).fileName,file.first.c_str());
            index++;
        }


        std::sort(results.begin(),results.end(),resultPairSort);


        results.resize(MAX_RESULT_SIZE);

        searchTime.end();

        MPI_Send(results.data(),           /* message buffer */
             MAX_RESULT_SIZE,         /* buffer size */
             *ResultMpiType,              /* data item is an integer */
             0,                     /* destination process rank, the master */
             RESULTS,             /* user chosen message tag */
             MPI_COMM_WORLD);

        workWallTime.end();

        //add the times to an array to be sent to the master
        times[0] = parserTime.get_elapse();
        times[1] = searchTime.get_elapse();
        times[2] = workWallTime.get_elapse();

        //send out the timing results to be compiled
        MPI_Send(times,
            NUM_TIME_RESULTS,
            MPI_DOUBLE,
            0,
            TIMING,
            MPI_COMM_WORLD);

    }







    return 0;

}