int OnChangeWindingOrder(domTriangles * triangles)
{
    unsigned int max_offset = getMaxOffset(triangles->getInput_array()) + 1;

    domUint count = triangles->getCount();

    domP * p = triangles->getP();
    if (p == NULL) return -1;									// Error check
    domListOfUInts & list_of_uint = p->getValue();

    domUint * temp_data = new domUint[max_offset];	// make temp data for temp vertex

    for (int i=0; i<count; i++) // for each triangle			// change winding order from v1,v2,v3 to v3,v2,v1
    {
        int v1_offset = i * 3 * max_offset;
//		int v2_offset = v1_offset + max_offset;					// v2 is unchanged
        int v3_offset = v1_offset + 2 * max_offset;

        for(unsigned int j=0; j<max_offset; j++)							// backup v1 to temp
            temp_data[j] = list_of_uint[v1_offset + j];

        for(unsigned int j=0; j<max_offset; j++)							// copy v3 to v1
            list_of_uint[v1_offset + j] = list_of_uint[v3_offset + j];

        for(unsigned int j=0; j<max_offset; j++)							// copy temp to v3
            list_of_uint[v3_offset + j] = temp_data[j];
    }

    return 0;
}
Beispiel #2
0
// Get the chunks for the specified reference id and start/end 0-based
// coordinates.
bool BamIndex::getChunksForRegion(int32_t refID, int32_t start, int32_t end, 
                                  SortedChunkList& chunkList)
{
    chunkList.clear();

    // If start is >= to end, there will be no sections, return no
    // regions.
    if((start >= end) && (end != -1))
    {
        std::cerr << "Warning, requesting region where start <= end, so "
                  << "no values will be returned.\n";
        return(false);
    }

    // Handle REF_ID_UNMAPPED.  This uses a default chunk which covers
    // from the max offset to the end of the file.
    if(refID == REF_ID_UNMAPPED)
    {
        Chunk refChunk;
        // The start of the unmapped region is the max offset found
        // in the index file.
        refChunk.chunk_beg = getMaxOffset();
        // The end of the unmapped region is the end of the file, so
        // set chunk end to the max value.
        refChunk.chunk_end = Chunk::MAX_CHUNK_VALUE;
        return(chunkList.insert(refChunk));
    }

    if((refID < 0) || (refID >= n_ref))
    {
        // The specified refID is out of range, return false.
        std::cerr << "Warning, requesting refID is out of range, so "
                  << "no values will be returned.\n";
        return(false);
    }

    const Reference* ref = &(myRefs[refID]);

    // Handle where start/end are defaults.    
    if(start == -1)
    {
        if(end == -1)
        {
            // This is whole chromosome, so take a shortcut.
            if(ref->maxChunkOffset == 0)
            {
                // No chunks for this region, but this is not an error.
                return(true);
            }
            Chunk refChunk;
            refChunk.chunk_beg = ref->minChunkOffset;
            refChunk.chunk_end = ref->maxChunkOffset;
            return(chunkList.insert(refChunk));
        }
        else
        {
            start = 0;
        }
    }
    if(end == -1)
    {
        // MAX_POSITION is inclusive, but end is exclusive, so add 1.
        end = MAX_POSITION + 1;
    }

    // Determine the minimum offset for the given start position.  This
    // is done by using the linear index for the specified start position.
    uint64_t minOffset = 0;
    getMinOffsetFromLinearIndex(refID, start, minOffset);

    bool binInRangeMap[MAX_NUM_BINS+1];
    
    getBinsForRegion(start, end, binInRangeMap);

    // Loop through the bins in the ref and if they are in the region, get the chunks.
    for(int i = 0; i < ref->n_bin; ++i)
    {
        const Bin* bin = &(ref->bins[i]);
        if(binInRangeMap[bin->bin] == false)
        {
            // This bin is not in the region, so check the next one.
            continue;
        }

        // Add each chunk in the bin to the map.
        for(int chunkIndex = 0; chunkIndex < bin->n_chunk; chunkIndex++)
        {
            // If the end of the chunk is less than the minimum offset
            // for the 16K block that starts our region, then no
            // records in this chunk will cross our region, so do
            // not add it to the chunks we need to use.
            if(bin->chunks[chunkIndex].chunk_end < minOffset)
            {
                continue;
            }
            // Add the chunk to the map.
            if(!chunkList.insert(bin->chunks[chunkIndex]))
            {
                // Failed to add to the map, return false.
                std::cerr << "Warning, Failed to add a chunk, so "
                          << "no values will be returned.\n";
                return(false);
            }
        }
    }

    // Now that all chunks have been added to the list,
    // handle overlapping chunks.
    return(chunkList.mergeOverlapping());
}