text: #pragma once
  
  #include <cgv/base/node.h>
  
  #include <density_estimation/state/density_estimator_state.h>
  #include <density_estimation/state/state_listener.h>
  #include <density_estimation/utility/estimation_procedure/estimation_procedure.h>
  #include <density_estimation/utility/interpolator/interpolator.h>
  
  #include <functional>
  
  class density_estimator_logic
    : public cgv::base::node
    , public state_listener
  {
  private:
    density_estimator_state_ptr state;
    stochastic_process_factory* stochastic_process_generator;
  
  public:
    density_estimator_logic(density_estimator_state_ptr state);
  
    bool load_ensemble_from_file(const std::string& file_path,
                                 std::string& error);
  
    bool load_ensemble_metadata_from_file(const std::string& file_path,
                                          std::string& error);
  
    void add_restriction_from_current_selection();
  
    void clear_restrictions();
  
    void estimate_pdfs();
  
    void estimate_conditional_pdfs();
  
    void compute_pdf_reference_densities();
  
    void compute_conditional_pdf_reference_densities();
  
    void compute_pdf_errors();
  
    void compute_conditional_pdf_errors();
  
  protected:
    void generate_sample_function_interpolators(
      std::vector<interpolator_ptr>& sample_function_interpolators);
  
    std::function<float(float, float)> generate_error_function();
  
    std::function<float(float*, float*, float, float)>
    generate_domain_error_aggregation_function();
  
    std::function<float(float*, float*, float, float)>
    generate_process_error_aggregation_function();
  
    estimation_procedure_ptr generate_estimation_procedure(
      std::vector<interpolator_ptr>& sample_function_interpolators,
      float density_scale_factor = 1.0f);
  
    void handle_modifications(unsigned modification_timestep) override;
  
    unsigned get_pdf_count();
  
    bool options_valid();
  };
  
  using density_estimator_logic_ptr = cgv::data::ref_ptr<density_estimator_logic>;
  