Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8ec410d
WIP towards a flag compound ray eye representation
sebsjames Nov 20, 2025
92671b4
More WIP
sebsjames Nov 21, 2025
aa31435
runtime radius modification
sebsjames Nov 21, 2025
3e75dd0
WIP towards a 2D compound ray projections
sebsjames Nov 21, 2025
915c782
puts rays and sphere inside EyeVisual. reinitColours needs work
sebsjames Nov 21, 2025
de7e46a
Working towards multiple projections
sebsjames Nov 22, 2025
3c4df19
Bug fix. Works for one projection; not so well for two
sebsjames Nov 22, 2025
faaa791
Debugging, not progress
sebsjames Nov 24, 2025
369fd45
Some progress, moving to laptop
sebsjames Nov 24, 2025
ea4836c
Sorted
sebsjames Nov 24, 2025
8c83ace
Tidy up before defining ranges of ommatidia to show for a projection
sebsjames Nov 24, 2025
ce4628d
Now have a portion of each projection showing. Quite neat
sebsjames Nov 24, 2025
85e93a9
Bug fix on reinitColours for multiple projections
sebsjames Nov 25, 2025
bbf1bb0
Prepare to be able to do cylindrical projections
sebsjames Nov 25, 2025
9554cca
WIP on spherical projection displays
sebsjames Nov 25, 2025
578ccec
A spherical projection visual
sebsjames Nov 25, 2025
85e9be2
Adds spherical projections to healpix.cpp
sebsjames Nov 26, 2025
a77bd58
Corrections to spherical projections
sebsjames Nov 26, 2025
013d36e
WIP on coord systems
sebsjames Nov 26, 2025
fea1e79
Shows xyz directions on the healpix and on the projections
sebsjames Nov 26, 2025
b1a2ba5
Healpix and 2D projections are good.
sebsjames Nov 27, 2025
1af90cd
Just whitespace
sebsjames Nov 27, 2025
717a762
Latest maths
sebsjames Nov 27, 2025
393a766
Switch to main maths
sebsjames Nov 27, 2025
eee4438
Changed API in sm::maths
sebsjames Nov 27, 2025
5371a98
Changed API in sm::maths
sebsjames Nov 27, 2025
090a60b
Some more C++-ification
sebsjames Nov 28, 2025
3dca72b
It's necessary to use double precision in jcvoronoi to avoid bugs
sebsjames Nov 28, 2025
f737150
Corrected rotation of coords for CompoundRay
sebsjames Nov 29, 2025
a63aa2c
More C++ification of jc_voronoi
sebsjames Nov 29, 2025
c241a50
Pull some more API into the jc::voronoi class
sebsjames Nov 29, 2025
756baee
Get everything building with the new voronoi scheme
sebsjames Nov 29, 2025
275d20a
Stage 1 refactoring. T and jcv_edge
sebsjames Nov 29, 2025
e926fa8
More refcatoring
sebsjames Nov 29, 2025
8caf065
Completes refactoring
sebsjames Nov 29, 2025
e5d7104
diagram should just be a nonpointer member
sebsjames Nov 29, 2025
3d6db8f
Adds the loop sanity count to avoid getting bitten in the future
sebsjames Nov 29, 2025
861513c
Merge branch 'dev/flat_cray' of github.com:sebsjames/mathplot into de…
sebsjames Dec 1, 2025
3523855
Enforce house style
sebsjames Dec 1, 2025
b550b4d
Restore original about message
sebsjames Dec 1, 2025
4e08d06
Restore changes in SphereVisual
sebsjames Dec 1, 2025
93db686
Tidyup
sebsjames Dec 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,7 @@ endif()

add_executable(show_boundingboxes show_boundingboxes.cpp)
target_link_libraries(show_boundingboxes OpenGL::GL glfw Freetype::Freetype)

# if have compound-ray header
add_executable(cray_eye cray_eye.cpp)
target_link_libraries(cray_eye OpenGL::GL glfw Freetype::Freetype)
80 changes: 80 additions & 0 deletions examples/cray_eye.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* A compound ray eye viewer
*
* Demonstrating use of mplot::compoundray::EyeVisual
*/

#include <iostream>
#include <string>
#include <memory>

#include <sm/vec>
#include <sm/vvec>

#include <mplot/Visual.h>
#include <mplot/ColourMap.h>
#include <mplot/SphereVisual.h>
#include <mplot/VectorVisual.h>
#include <mplot/compoundray/EyeVisual.h>

int main (int argc, char** argv)
{
std::string eyefile = "";
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " path/to/eyefile.eye [projection sphere radius]\n";
return -1;
} else {
eyefile = std::string (argv[1]);
}

float psrad = 0.6f;

[[maybe_unused]] float cx = 0.5f;
if (argc > 2) { cx = std::atof (argv[2]); }

auto v = mplot::Visual<>(1024, 768, "mplot::compoundray::EyeVisual");

// We read the information from the eye file into a vector of Ommatidium objects. Ommatidium is
// defined in "cameras/CompoundEyeDataTypes.h" in compound ray, mplot::Ommatidium is a
// mplot/Seb's maths style equivalent. It contains 2 3D float vectors and two scalar floating point
// values.
auto ommatidia = std::make_unique<std::vector<mplot::compoundray::Ommatidium>>();
std::vector<std::array<float, 3>> ommatidiaColours;

// Read the eye file into ommatidia data structure. compound ray does this internally when we're
// using it, but for this example we instead make use of mplot::compoundray::readEye
if (mplot::compoundray::readEye (ommatidia.get(), eyefile) == nullptr) { std::cout << "Failed to read eye\n"; return -1; }

// Make some dummy data to demo the eye
sm::vvec<float> ommatidiaData;
ommatidiaData.linspace (0, 1, ommatidia->size());
// Colour it with a colour map
mplot::ColourMap cm (mplot::ColourMapType::Plasma);
ommatidiaColours.resize (ommatidia->size());
for (size_t i = 0; i < ommatidia->size(); ++i) {
ommatidiaColours[i] = cm.convert (ommatidiaData[i]);
}

auto eyevm = std::make_unique<mplot::compoundray::EyeVisual<>> (sm::vec<>{}, &ommatidiaColours, ommatidia.get());
v.bindmodel (eyevm);
eyevm->name = "Big Eye";
eyevm->show_cones = false;

auto ptype = mplot::compoundray::EyeVisual<>::projection_type::equirectangular; // mercator, equirectangular or cassini
sm::vec<> centre = { 0, 0, 0 };
sm::mat44<float> twod_tr;
twod_tr.translate (sm::vec<>{0,0,-2});
eyevm->add_spherical_projection (ptype, twod_tr, centre, psrad);

//centre = { cx, 0, 0 };
//eyevm->add_spherical_projection (ptype, twod_offset, centre, psrad, 780, 1560);

eyevm->show_sphere = true;
eyevm->show_rays = true;
eyevm->finalize();

[[maybe_unused]] auto ep = v.addVisualModel (eyevm);
ep->reinitColours();

v.keepOpen();
}
123 changes: 121 additions & 2 deletions examples/healpix.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/*
* Make a healpix visual, showing the NEST index in a colour map
*
* This program also demonstrates 2D spherical projections that are available in sm::geometry and
* the Visual class mplot::SphereProjectionVisual
*/
#include <cstdint>
#include <cstdlib>
#include <sstream>
#include <sm/vec>
#include <mplot/Visual.h>
#include <mplot/HealpixVisual.h>
#include <mplot/SphericalProjectionVisual.h>

int main (int argc, char** argv)
{
Expand All @@ -25,7 +29,17 @@ int main (int argc, char** argv)
// scheme. If we fill it with sequential values, then the colour map will show the
// hierarchical nature of the HEALPix.
for (int64_t p = 0; p < hpv->n_pixels(); ++p) {
hpv->pixeldata[p] = static_cast<float>(p) / hpv->n_pixels();
hpv->pixeldata[p] = 0.5f * static_cast<float>(p) / hpv->n_pixels();
// Mark circles for the x, y and z axes to check they line up
hp::t_vec pv = hp::nest2vec (hpv->get_nside(), p);
auto v = sm::vec<double>({pv.x, pv.y, pv.z});
if (v.angle (sm::vec<double>::ux()) < 0.05) {
hpv->pixeldata[p] = 0.6;
} else if (v.angle (sm::vec<double>::uy()) < 0.05) {
hpv->pixeldata[p] = 0.8;
} else if (v.angle (sm::vec<double>::uz()) < 0.05) {
hpv->pixeldata[p] = 1.0;
}
}

std::stringstream ss;
Expand All @@ -37,7 +51,112 @@ int main (int argc, char** argv)

// Finalize and add
hpv->finalize();
v.addVisualModel (hpv);
auto hpvp = v.addVisualModel (hpv);

// Show some 2D projections, as well
sm::vvec<std::array<float, 3>> hpvcolours (hpvp->pixeldata.size(), mplot::colour::crimson);
sm::vvec<sm::vec<float, 2>> latlong (hpvp->pixeldata.size());
for (uint32_t i = 0; i < hpvp->pixeldata.size(); ++i) {

// ang.theta is co-latitude (and needs re-casting to be longitude), ang.phi is a longitude
hp::t_ang ang = hp::nest2ang (hpvp->get_nside(), i);

// ang.theta is pi for the South pole and 0 for the North pole
// latitude should be in range -pi/2 (S) < lat <= pi/2 (N)
float _lat = (sm::mathconst<float>::pi - ang.theta) - sm::mathconst<float>::pi_over_2;

latlong[i] = { _lat, static_cast<float>(ang.phi) };
hpvcolours[i] = hpvp->cm.convert (hpvp->pixeldata[i]);
}

// Add two-dimensional projections
auto spv = std::make_unique<mplot::SphericalProjectionVisual<float>> (sm::vec<float>{5,0,0});
v.bindmodel (spv);
spv->twodimensional (true);
spv->proj_type = sm::geometry::spherical_projection::type::mercator;
spv->latlong = latlong;
spv->lambda0 = 0.0f;
spv->colour = hpvcolours;
spv->finalize();
auto spvp = v.addVisualModel (spv);
auto ext = spvp->extents(); // Use VisualModel::extents() to help place the label
spvp->addLabel ("Mercator projection", sm::vec<>{ ext[0].min, ext[1].min - 0.16f, 0.0f }, mplot::TextFeatures(0.08f));

spv = std::make_unique<mplot::SphericalProjectionVisual<float>> (sm::vec<float>{13,0,0});
v.bindmodel (spv);
spv->twodimensional (true);
spv->proj_type = sm::geometry::spherical_projection::type::mercator;
spv->latlong = latlong;
spv->lambda0 = sm::mathconst<float>::pi_over_4;
spv->colour = hpvcolours;
spv->finalize();
spvp = v.addVisualModel (spv);
ext = spvp->extents(); // Use VisualModel::extents() to help place the label
std::stringstream ss1;
ss1 << "Mercator projection with "
<< mplot::unicode::toUtf8(mplot::unicode::lambda)
<< mplot::unicode::toUtf8(mplot::unicode::subs0)
<< " = " << mplot::unicode::toUtf8(mplot::unicode::pi) << "/4";
spvp->addLabel (ss1.str(),
sm::vec<>{ ext[0].min, ext[1].min - 0.16f, 0.0f }, mplot::TextFeatures(0.08f));

spv = std::make_unique<mplot::SphericalProjectionVisual<float>> (sm::vec<float>{-5,-4,0});
v.bindmodel (spv);
spv->twodimensional (true);
spv->proj_type = sm::geometry::spherical_projection::type::equirectangular;
spv->latlong = latlong;
spv->colour = hpvcolours;
spv->finalize();
spvp = v.addVisualModel (spv);
ext = spvp->extents();
spvp->addLabel ("Equirectangular projection", sm::vec<>{ ext[0].min, ext[1].min - 0.16f, 0.0f }, mplot::TextFeatures(0.08f));

spv = std::make_unique<mplot::SphericalProjectionVisual<float>> (sm::vec<float>{-5,-8,0});
v.bindmodel (spv);
spv->twodimensional (true);
spv->lambda0 = sm::mathconst<float>::pi_over_4;
//spv->phi0 = sm::mathconst<float>::pi_over_4; // Latitude offset
//spv->phi1 = sm::mathconst<float>::pi_over_4; // Longitude scaling
spv->proj_type = sm::geometry::spherical_projection::type::equirectangular;
spv->latlong = latlong;
spv->colour = hpvcolours;
spv->finalize();
spvp = v.addVisualModel (spv);
ext = spvp->extents();
std::stringstream ss2;
ss2 << "Equirectangular projection with "
<< mplot::unicode::toUtf8(mplot::unicode::lambda)
<< mplot::unicode::toUtf8(mplot::unicode::subs0)
<< " = " << mplot::unicode::toUtf8(mplot::unicode::pi) << "/4";
spvp->addLabel (ss2.str(), sm::vec<>{ ext[0].min, ext[1].min - 0.16f, 0.0f }, mplot::TextFeatures(0.08f));

spv = std::make_unique<mplot::SphericalProjectionVisual<float>> (sm::vec<float>{-9,3,0});
v.bindmodel (spv);
spv->twodimensional (true);
spv->proj_type = sm::geometry::spherical_projection::type::cassini;
spv->latlong = latlong;
spv->colour = hpvcolours;
spv->finalize();
spvp = v.addVisualModel (spv);
ext = spvp->extents();
spvp->addLabel ("Cassini projection", sm::vec<>{ ext[0].min, ext[1].min - 0.16f, 0.0f }, mplot::TextFeatures(0.08f));

spv = std::make_unique<mplot::SphericalProjectionVisual<float>> (sm::vec<float>{-4,3,0});
v.bindmodel (spv);
spv->twodimensional (true);
spv->lambda0 = sm::mathconst<float>::pi_over_4;
spv->proj_type = sm::geometry::spherical_projection::type::cassini;
spv->latlong = latlong;
spv->colour = hpvcolours;
spv->finalize();
spvp = v.addVisualModel (spv);
ext = spvp->extents();
std::stringstream ss3;
ss3 << "Cassini projection with "
<< mplot::unicode::toUtf8(mplot::unicode::lambda)
<< mplot::unicode::toUtf8(mplot::unicode::subs0)
<< " = " << mplot::unicode::toUtf8(mplot::unicode::pi) << "/4";
spvp->addLabel (ss3.str(), sm::vec<>{ ext[0].min, ext[1].min - 0.16f, 0.0f }, mplot::TextFeatures(0.08f));

v.keepOpen();
return 0;
Expand Down
Loading