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. When the ray buffer is large and the rays of interest are relatively few in number, the typical loop structure using GetLastRay and GetPreviousRay can be inefficient and time consuming. A new command, GetLastFilteredRay has been added that takes a T_RAYFILTEROP array as an argument. When GetLastFilteredRay is used, the GetPreviousRay command will return the previous ray in the buffer that meets the T_RAYFILTEROP requirements. In this way, the ray criteria check is offloaded to FRED instead of being written explicitly by the user and can result in much more efficient calculation time when ray buffer loops are required. When GetLastFilteredRay is called, the commands GetNextRay and GetPreviousRay continue to use the filter stack provided to GetLastFilteredRay until either GetFirstRay or GetLastRay is called. Once GetFirstRay or GetLastRay is called, the commands GetNextRay and GetPreviousRay will stop returning filtered rays.
Depending on the number of rays traced, it may be necessary to dimension ray index and ray counter variables as data type Huge_ instead of Long. Please see Multi-threaded Raytracing for more information.
Syntax success = GetLastFilteredRay( curRay, tRayFilter(), tRay )
Parameters success (Boolean) Return value indicating whether the function call was successful in getting the last filtered ray.
curRay As Long (or Huge_) After the function executes, this argument contains the value of the last filtered ray.
tRayFilter() As T_RAYFILTEROP Array of T_RAYFILTEROP structures that define the ray selection filter criteria for the rays whose T_RAY data will be returned by subsequent calls of GetNextRay and GetPreviousRay.
tRay As T_RAY After the function executes, this argument contains the basic ray data of the last filtered ray.
Example The example code below demonstrates a custom function that leverages the GetLastFilteredRay 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.
Function DoCalcByFilterLoopReverse( ByVal in_filter As Variant ) As Variant
Dim tRay As T_RAY Dim success As Boolean Dim curRay As Long Dim spow As Double
success = GetLastFilteredRay( curRay, in_filter, tRay ) While success spow += tRay.power success = GetPreviousRay( curRay, tRay ) Wend
Print "Power = " & Chr(9) & spow
End Function
See Also
|