Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds axes indicator to healpixvis #284

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions examples/healpix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ int main (int argc, char** argv)

auto hpv = std::make_unique<morph::HealpixVisual<float>> (morph::vec<float>{0,0,0});
v.bindmodel (hpv);
hpv->indicate_axes = true;
hpv->set_order (ord);
hpv->cm.setType (morph::ColourMapType::Plasma);

Expand Down
7 changes: 4 additions & 3 deletions morph/CoordArrows.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <morph/VisualModel.h>
#include <morph/mathconst.h>
#include <morph/VisualTextModel.h>
#include <morph/colour.h>
#include <array>

namespace morph {
Expand Down Expand Up @@ -146,9 +147,9 @@ namespace morph {

//! The colours of the arrows, and of the centre sphere
std::array<float, 3> centresphere_col = {1.0f, 1.0f, 1.0f};
std::array<float, 3> x_axis_col = {1.0f, 0.0f, 0.0f}; // Red
std::array<float, 3> y_axis_col = {0.0f, 1.0f, 0.0f}; // Green
std::array<float, 3> z_axis_col = {0.0f, 0.0f, 1.0f}; // Blue
std::array<float, 3> x_axis_col = morph::colour::crimson;
std::array<float, 3> y_axis_col = morph::colour::springgreen2;
std::array<float, 3> z_axis_col = morph::colour::blue2;

std::string x_label = "X";
std::string y_label = "Y";
Expand Down
37 changes: 35 additions & 2 deletions morph/HealpixVisual.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ namespace morph {

void updateColours()
{
this->vertexColors.clear(); // could potentially just replace values
size_t n_data = this->n_pixels();

if (this->vertexColors.size() < n_data * 3) {
throw std::runtime_error ("vertexColors is not big enough to updateColours()");
}

// Scale data
morph::vvec<float> scaled_data (this->pixeldata);
if (this->colourScale.do_autoscale == true) { this->colourScale.reset(); }
Expand All @@ -43,7 +47,9 @@ namespace morph {
// Re-colour
for (size_t i = 0u; i < n_data; ++i) {
auto c = this->cm.convert (scaled_data[i]);
this->vertex_push (c, this->vertexColors);
this->vertexColors[3*i] = c[0];
this->vertexColors[3*i+1] = c[1];
this->vertexColors[3*i+2] = c[2];
}

// Lastly, this call copies vertexColors (etc) into the OpenGL memory space
Expand Down Expand Up @@ -423,6 +429,30 @@ namespace morph {
if (this->k == 0) { return; }
this->healpix_triangles_by_nest();
if (this->show_spheres == true) { this->vertex_spheres(); }
if (this->indicate_axes == true) { this->draw_coordaxes(); }
}

// Draw a small set of coordinate arrows with origin at pixel 0
void draw_coordaxes()
{
morph::vec<float> vpf0 = {0, 0, this->r};

// draw tubes
float tlen = this->r * 0.1f;
float tlen2 = this->r * 0.05f;
float tthk = this->r * 0.005f;

this->computeCone (vpf0 + (this->uz * tthk/2),
vpf0 + (this->uz * tlen),
0.0f, morph::colour::blue2, tthk);

this->computeCone (vpf0 + this->ux * tthk * 1.1f + this->uz * tthk,
vpf0 + this->ux * tlen2 + this->uz * tthk,
0.0f, morph::colour::crimson, tthk/2);

this->computeCone (vpf0 + this->uy * tthk * 1.1f + this->uz * tthk,
vpf0 + this->uy * tlen2 + this->uz * tthk,
0.0f, morph::colour::springgreen2, tthk/2);
}

int64_t n_pixels() { return 12 * this->nside * this->nside; }
Expand Down Expand Up @@ -480,6 +510,9 @@ namespace morph {
// Show spheres at face locations? (mainly for debug)
bool show_face_spheres = false;

// Show a little coordinate axes set indicating directions?
bool indicate_axes = false;

private:
// How many sides for the healpix? This is a choice of the user. Default to 3.
int64_t k = 3; // k is the 'order'
Expand Down
2 changes: 2 additions & 0 deletions morph/VisualModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ namespace morph {

//! Get mv_offset in a json-friendly string
std::string translation_str() { return this->mv_offset.str_mat(); }
//! And a simple getter for mv_offset
vec<float> get_mv_offset() { return this->mv_offset; }

//! Return the number of elements in this->indices
std::size_t indices_size() { return this->indices.size(); }
Expand Down
Loading