Navigation: Scripting Reference Manual > Functions & Subroutines > CopyFilteredRaysBufferToBuffer

 

CopyFilteredRaysBufferToBuffer

 

Contact Us: fredsupport@photonengr.com

 

Description

Many scripts contain a loop over the ray buffer to identify rays with specific characteristics (ex. rays on a given surface) and then extract information about those rays.  Some scripts are structured to leverage multiple ray buffers by creating a custom ray buffer that contains only rays known to be of interest.  In this way, the efficiency of analyses can be improved by virtue of the fact that all rays in the buffer are known to be contributers to the result.  Previously, the custom ray buffer would be constructed by adding the buffer and then looping over the rays and copying the ray data into the new buffer.  When there are many rays and a relatively small number of those rays are of interest, the standard ray buffer loop structure to copy ray data into the new custom buffer can be inefficient.  The CopyFilteredRaysBufferToBuffer command addresses this inefficiency by moving all of the rays that meet a specific set of filter requirements in one bulk operation rather than forcing the user to move the rays one by one in a loop.

 

 

Syntax

CopyFilteredRaysBufferToBuffer( tRayFilter(), srcBuf, dstBuf, append )

 

 

Parameters

tRayFilter() As T_RAYFILTEROP

Array of T_RAYFILTEROP structures that define the ray selection filter criteria for the rays that will be copied to the new buffer.

 

srcBuf As Long

Ray buffer ID of the source buffer containing the rays that will be filtered and copied from.

 

dstBuf As Long

Ray buffer ID of the destination buffer that the filtered rays will be copied to.

 

append As Boolean

This argument specifies whether the copied rays will be appended to the destination buffer or whether they will overwrite the existing contents of the destination buffer.

 

 

Example

The example code below demonstrates a custom function that leverages the CopyFilteredRaysBufferToBuffer concept.  In this example, the argument being passed in, in_filter, is constructed elsewhere in the Main subroutine and would be dimensioned as Dim tFilter(N) As T_RAYFILTEROP.  The value of N depends on the number of ray filter requirements being used.  Note that a new buffer is constructed at the start of the function and the new buffer is where the filtered rays are deposited.  After the filtered ray copy operation is performed, we switch to the new ray buffer and loop the rays.  Note, however, that the ray loop in the new buffer is 100% efficient because the ray filter criteria was applied when we copied the rays to the new buffer.

 

Function DoCalcByFilterBuffer( ByVal in_filter As Variant ) As Variant

 

    Dim curBuf As Long, newBuf As Long

    newBuf  = AddRayBuffer()

    curBuf  = GetActiveRayBufferIndex()

 

    CopyFilteredRaysBufferToBuffer( in_filter, curBuf, newBuf, False )

 

    SetActiveRayBufferIndex( newBuf )

 

    Dim tRay As T_RAY

    Dim success As Boolean

    Dim curRay As Long

    Dim spow As Double

 

    success = GetFirstRay( curRay, tRay )

    While success

        spow   += tRay.power

        success = GetNextRay( curRay, tRay )

    Wend

    Print "Power = " & Chr(9) & spow

 

    SetActiveRayBufferIndex( curBuf )

    DeleteRayBuffer( newBuf )

 

End Function

 

 

 

See Also

Ray Data Script Commands

Raytrace/Ray Buffer Script Commands

T_RAYFILTEROP

 

 

 

 

 

Copyright © Photon Engineering, LLC