diff --git a/examples/healpix.cpp b/examples/healpix.cpp index 98e6be93..0aa94cc0 100644 --- a/examples/healpix.cpp +++ b/examples/healpix.cpp @@ -16,6 +16,7 @@ int main (int argc, char** argv) auto hpv = std::make_unique> (morph::vec{0,0,0}); v.bindmodel (hpv); + hpv->indicate_axes = true; hpv->set_order (ord); hpv->cm.setType (morph::ColourMapType::Plasma); diff --git a/morph/CoordArrows.h b/morph/CoordArrows.h index ed8912f1..f4fb513d 100644 --- a/morph/CoordArrows.h +++ b/morph/CoordArrows.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace morph { @@ -146,9 +147,9 @@ namespace morph { //! The colours of the arrows, and of the centre sphere std::array centresphere_col = {1.0f, 1.0f, 1.0f}; - std::array x_axis_col = {1.0f, 0.0f, 0.0f}; // Red - std::array y_axis_col = {0.0f, 1.0f, 0.0f}; // Green - std::array z_axis_col = {0.0f, 0.0f, 1.0f}; // Blue + std::array x_axis_col = morph::colour::crimson; + std::array y_axis_col = morph::colour::springgreen2; + std::array z_axis_col = morph::colour::blue2; std::string x_label = "X"; std::string y_label = "Y"; diff --git a/morph/HealpixVisual.h b/morph/HealpixVisual.h index 4011e9fc..296086f5 100644 --- a/morph/HealpixVisual.h +++ b/morph/HealpixVisual.h @@ -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 scaled_data (this->pixeldata); if (this->colourScale.do_autoscale == true) { this->colourScale.reset(); } @@ -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 @@ -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 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; } @@ -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' diff --git a/morph/VisualModel.h b/morph/VisualModel.h index ea2c13e2..0c91c16c 100644 --- a/morph/VisualModel.h +++ b/morph/VisualModel.h @@ -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 get_mv_offset() { return this->mv_offset; } //! Return the number of elements in this->indices std::size_t indices_size() { return this->indices.size(); }