git.haldean.org d / master render / main.cpp
master

Tree @master (Download .tar.gz)

main.cpp @masterraw · history · blame

#include <iostream>
#include <fstream>
#include <vector>
#include <Eigen/Dense>

typedef Eigen::Matrix3Xd SO3Set;
typedef Eigen::Vector3d SO3;
typedef size_t PointId;
typedef std::tuple<PointId, PointId, PointId> Triangle;

struct SO3Mesh
{
        SO3Set points;
        std::vector<Triangle> triangles;
};

bool InsideCircumcircle(
        SO3Mesh mesh, PointId t0, PointId t1, PointId t2, PointId p)
{
        Eigen::Matrix3d circ;
        Eigen::Vector3d A = mesh.points.row(t0);
        Eigen::Vector3d B = mesh.points.row(t1);
        Eigen::Vector3d C = mesh.points.row(t2);
        Eigen::Vector3d D = mesh.points.row(p);
        circ(0, 0) = A[0] - D[0];
        circ(0, 1) = A[1] - D[1];
        circ(0, 2) = A[0] * A[0] - D[0] * D[0] + A[1] * A[1] - D[1] * D[1];
        circ(1, 0) = B[0] - D[0];
        circ(1, 1) = B[1] - D[1];
        circ(1, 2) = B[0] * B[0] - D[0] * D[0] + B[1] * B[1] - D[1] * D[1];
        circ(2, 0) = C[0] - D[0];
        circ(2, 1) = C[1] - D[1];
        circ(2, 2) = C[0] * C[0] - D[0] * D[0] + C[1] * C[1] - D[1] * D[1];
        return circ.determinant() > 0;
}

void Triangulate(SO3Mesh &mesh)
{
        double theta_min, theta_max, phi_min, phi_max;
        double theta_range, phi_range;
        double theta_center, phi_center;
        double r_max;

        theta_min = mesh.points.col(0).minCoeff();
        theta_max = mesh.points.col(0).maxCoeff();
        phi_min = mesh.points.col(1).minCoeff();
        phi_max = mesh.points.col(1).maxCoeff();
        r_max = mesh.points.col(2).maxCoeff();

        theta_range = theta_max - theta_min;
        phi_range = phi_max - phi_min;

        theta_center = (theta_max + theta_min) / 2.;
        phi_center = (phi_max + phi_min) / 2.;

        /* add 3 fake points to form the supertriangle */
        PointId fpbase = mesh.points.cols();
        mesh.points.resize(Eigen::NoChange, fpbase + 3);

        mesh.points.col(fpbase + 0) = SO3(
                theta_min - 10 * theta_range,
                phi_min - phi_range,
                r_max);
        mesh.points.col(fpbase + 1) = SO3(
                theta_center,
                phi_max + 10 * phi_range,
                r_max);
        mesh.points.col(fpbase + 2) = SO3(
                theta_max + 10 * theta_range,
                phi_min - phi_range,
                r_max);

        std::vector<bool> ok;
        triangles.push_back(Triangle(fpbase, fpbase + 1, fpbase + 2));
        ok.push_back(false);

        for (PointId p = 0; p < fpbase; p++)
        {

        }
}

void ReadFile(SO3Set &res, std::istream &input)
{
        size_t r = 0;
        size_t n_cols = std::count(
                std::istreambuf_iterator<char>(input),
                std::istreambuf_iterator<char>(),
                '\n');
        input.seekg(0);
        res.resize(Eigen::NoChange, n_cols);
        std::string line;
        while (std::getline(input, line))
        {
                double theta, phi, r;
                sscanf(line.c_str(), "%lf %lf %lf", &theta, &phi, &r);
                res(0, r) = theta; res(1, r) = phi; res(2, r) = r;
                r++;
        }
        std::cout << "loaded points:" << std::endl << res << std::endl;
}

int main() {
        SO3Mesh mesh;
        std::ifstream infile("simple-points.lpf");
        ReadFile(mesh.points, infile);
        return 0;
}