Program Listing for File surface.h

Return to documentation for file (source/plot_types/surface.h)

/*
 * scatter.h ScatterPlot data class
 *
 * Author:              Tom Clark  (thclark@github)
 *
 * Copyright (c) 2017-9 T Clark. All Rights Reserved.
 *
 */

#ifndef CPPLOT_SURFACE_H
#define CPPLOT_SURFACE_H

#include <vector>
#include <string.h>
#include <Eigen/Dense>
#include <nlohmann/json.hpp>

#include "eigen.h"
#include "exceptions.h"


namespace cpplot {

enum ColorScale {
   Blackbody,
   Bluered,
   Blues,
   Earth,
   Electric,
   Greens,
   Greys,
   Hot,
   Jet,
   Picnic,
   Portland,
   Rainbow,
   RdBu,
   Reds,
   Viridis,
   YlGnBu,
   YYlOrRd
};
const std::vector<std::string> colour_names = {
    "Blackbody",
    "Bluered",
    "Blues",
    "Earth",
    "Electric",
    "Greens",
    "Greys",
    "Hot",
    "Jet",
    "Picnic",
    "Portland",
    "Rainbow",
    "RdBu",
    "Reds",
    "Viridis",
    "YlGnBu",
    "YlOrRd"
};

void to_json(nlohmann::json& j, const ColorScale& c) {
    j["colorscale"] = colour_names[c];
}


class SurfacePlot {

public:

    ColorScale colorscale = YlGnBu;
    Eigen::ArrayXXd x;
    Eigen::ArrayXXd y;
    Eigen::ArrayXXd z;
    std::string type = "surface";
    std::string name = "";

    SurfacePlot() {
        x = Eigen::RowVectorXd::LinSpaced(3, -1.5, 0.6).replicate(3,1).array();
        y = Eigen::VectorXd::LinSpaced(3, -1.26, 1.26).replicate(1,3).array();
        z = x.pow(2) + y;
    };

};


void to_json(nlohmann::json& j, const SurfacePlot& p) {

    nlohmann::json x;
    nlohmann::json y;
    nlohmann::json z;
    to_json(x, p.x);
    to_json(y, p.y);
    to_json(z, p.z);
    j["x"] = x;
    j["y"] = y;
    j["z"] = z;
    to_json(j, p.colorscale);
    j["type"] = p.type;
    if (!p.name.empty()) {
        j["name"] = p.name;
    }
}


} // end namespace

#endif //CPPLOT_SURFACE_H