Ejemplo n.º 1
0
// BUG: this duplicates the code above
boost::uint32_t Cache::readBufferImpl(PointBuffer& data)
{
    const boost::uint32_t cacheBlockSize = m_filter.getCacheBlockSize();

    const boost::uint64_t currentPointIndex = getIndex();

    // for now, we only read from the cache if they are asking for one point
    // (this avoids the problem of an N-point request needing more than one
    // cached block to satisfy it)
    if (data.getCapacity() != 1)
    {
        const boost::uint32_t numRead = getPrevIterator().read(data);

        // if they asked for a full block and we got a full block,
        // and the block we got is properly aligned and not already cached,
        // then let's cache it!
        const bool isCacheable = (data.getCapacity() == cacheBlockSize) &&
                                 (numRead == cacheBlockSize) &&
                                 (currentPointIndex % cacheBlockSize == 0);
        if (isCacheable && (m_filter.lookupInCache(currentPointIndex) == NULL))
        {
            m_filter.addToCache(currentPointIndex, data);
        }

        m_filter.updateStats(numRead, data.getCapacity());

        return numRead;
    }

    // they asked for just one point -- first, check Mister Cache
    const PointBuffer* block = m_filter.lookupInCache(currentPointIndex);
    if (block != NULL)
    {
        // A hit! A palpable hit!
        data.copyPointFast(0,  currentPointIndex % cacheBlockSize, *block);

        m_filter.updateStats(0, 1);

        return 1;
    }

    // Not in the cache, so do a normal read :-(
    const boost::uint32_t numRead = getPrevIterator().read(data);
    m_filter.updateStats(numRead, numRead);

    return numRead;
}
Ejemplo n.º 2
0
// append all points from src buffer to end of dst buffer, based on the our bounds
boost::uint32_t Crop::processBuffer(PointBuffer& dstData, const PointBuffer& srcData) const
{
    const Schema& schema = dstData.getSchema();

    const Bounds<double>& bounds = this->getBounds();

    boost::uint32_t numSrcPoints = srcData.getNumPoints();
    boost::uint32_t dstIndex = dstData.getNumPoints();

    boost::uint32_t numPointsAdded = 0;

    boost::optional<Dimension const&> dimX = schema.getDimension("X");
    boost::optional<Dimension const&> dimY = schema.getDimension("Y");
    boost::optional<Dimension const&> dimZ = schema.getDimension("Z");

    for (boost::uint32_t srcIndex=0; srcIndex<numSrcPoints; srcIndex++)
    {
        // need to scale the values
        double x(0.0);
        double y(0.0);
        double z(0.0);
        
        if (dimX->getInterpretation() == dimension::SignedInteger )
        {
            boost::int32_t xi = srcData.getField<boost::int32_t>(*dimX, srcIndex);
            boost::int32_t yi = srcData.getField<boost::int32_t>(*dimY, srcIndex);
            boost::int32_t zi = srcData.getField<boost::int32_t>(*dimZ, srcIndex);

            x = dimX->applyScaling(xi);
            y = dimY->applyScaling(yi);
            z = dimZ->applyScaling(zi);
            
        }
        else if (dimX->getInterpretation() == dimension::UnsignedInteger)
        {
            boost::uint32_t xi = srcData.getField<boost::uint32_t>(*dimX, srcIndex);
            boost::uint32_t yi = srcData.getField<boost::uint32_t>(*dimY, srcIndex);
            boost::uint32_t zi = srcData.getField<boost::uint32_t>(*dimZ, srcIndex);

            x = dimX->applyScaling(xi);
            y = dimY->applyScaling(yi);
            z = dimZ->applyScaling(zi);
            
        } else
        {
            x = srcData.getField<double>(*dimX, srcIndex);
            y = srcData.getField<double>(*dimY, srcIndex);
            z = srcData.getField<double>(*dimZ, srcIndex);

        }
     
        Vector<double> point(x,y,z);
    
        if (bounds.contains(point))
        {
            dstData.copyPointFast(dstIndex, srcIndex, srcData);
            dstData.setNumPoints(dstIndex+1);
            ++dstIndex;
            ++numPointsAdded;
        }
    }

    assert(dstIndex <= dstData.getCapacity());

    return numPointsAdded;
}