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 AddFilteredRaysFromCurrentBufferToNewBuffer 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 newBuf = AddFilteredRaysFromCurrentBufferToNewBuffer( tRayFilter() )
Parameters newBuf (Long) Return value indicating the ray buffer ID where the filtered rays were placed.
tRayFilter() As T_RAYFILTEROP Array of T_RAYFILTEROP structures that define the ray selection filter criteria for the rays that will be added to the new buffer.
Example The example code below demonstrates a custom function that leverages the AddFilteredRaysFromCurrentBufferToNewBuffer 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 when the AddFilteredRaysFromCurrentBufferToNewBuffer function is called, with the return value being the index of the newly created buffer. After the filtered ray buffer add 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 created the new buffer.
Function DoCalcByFilterBufferAdd( ByVal in_filter As Variant ) As Variant
Dim curBuf As Long, newBuf As Long curBuf = GetActiveRayBufferIndex() newBuf = AddFilteredRaysFromCurrentBufferToNewBuffer( in_filter )
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 )
Return Timer
End Function
See Also Raytrace/Ray Buffer Script Commands
|