// Copyright 2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "Iterator.ih"
#include "IteratorContextShared.h"
#include "IteratorShared.h"

struct IntervalIteratorContext;
struct ValueRanges;
struct Volume;

typedef void (*uniform IterateIntervalFunc)(
    const int *uniform imask,
    void *uniform _self,
    void *uniform _interval,
    const uniform ValueRanges &valueRanges,
    const uniform bool elementaryCellIteration,
    uniform int *uniform _result);

/*
 * Your interval iterator should inherit from this (first member) to make it
 * usable with the default hit iterator.
 */
struct DefaultHitIteratorIntervalIterator
{
  uniform IntervalIteratorShared super;

  IterateIntervalFunc iterate;
  uniform bool elementaryCellIterationSupported;
};

/*
 * Default iterators share this state as they represent iteration along
 * a ray.
 */
struct DefaultIntervalIterator
{
  uniform DefaultHitIteratorIntervalIterator super;

  uniform box1f valueRange;  // value range of the full volume
  float nominalIntervalLength;

  box1f boundingBoxTRange;
  Interval currentInterval;
};

struct DefaultHitIterator
{
  uniform HitIteratorShared super;

  vec3f origin;
  vec3f direction;
  float time;

  // The interval iterator that we use.
  void *uniform intervalIteratorState;

  // Current iteration state.
  Interval currentInterval;

  // For the last hit: t + epsilon.
  float lastHitOffsetT;
};
