-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from ABRG-Models/dev/constexpr_geodesics_vec
Dev/constexpr geodesics vec. constexpr operator+, operator/ and renormalize in morph::vec seem to be safe.
- Loading branch information
Showing
13 changed files
with
439 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Visualize an Icosahedron using the Geodesic Visual that co-ops the unordered | ||
* constexpr geodesic function. | ||
*/ | ||
#include <morph/Visual.h> | ||
#include <morph/ColourMap.h> | ||
#include <morph/GeodesicVisualCE.h> | ||
#include <morph/vec.h> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <cmath> | ||
#include <array> | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
int main() | ||
{ | ||
int rtn = -1; | ||
|
||
morph::Visual v(1024, 768, "(constexpr) Geodesic Polyhedra"); | ||
v.showCoordArrows = true; | ||
v.lightingEffects (true); | ||
|
||
try { | ||
morph::vec<float, 3> offset = { 0.0, 0.0, 0.0 }; | ||
morph::vec<float, 3> step = { 2.2, 0.0, 0.0 }; | ||
|
||
auto gv1 = std::make_unique<morph::GeodesicVisualCE<float, 0>> (offset + step * 0, 0.9f); | ||
v.bindmodel (gv1); | ||
std::string lbl = std::string("iterations = 0"); | ||
gv1->addLabel (lbl, {0, -1, 0}, morph::TextFeatures(0.06f)); | ||
gv1->finalize(); | ||
v.addVisualModel (gv1); | ||
|
||
auto gv2 = std::make_unique<morph::GeodesicVisualCE<float, 1>> (offset + step * 1, 0.9f); | ||
v.bindmodel (gv2); | ||
lbl = std::string("iterations = 1"); | ||
gv2->addLabel (lbl, {0, -1, 0}, morph::TextFeatures(0.06f)); | ||
gv2->finalize(); | ||
v.addVisualModel (gv2); | ||
|
||
auto gv3 = std::make_unique<morph::GeodesicVisualCE<float, 2>> (offset + step * 2, 0.9f); | ||
v.bindmodel (gv3); | ||
lbl = std::string("iterations = 2"); | ||
gv3->addLabel (lbl, {0, -1, 0}, morph::TextFeatures(0.06f)); | ||
gv3->finalize(); | ||
v.addVisualModel (gv3); | ||
|
||
auto gv4 = std::make_unique<morph::GeodesicVisualCE<float, 3>> (offset + step * 3, 0.9f); | ||
v.bindmodel (gv4); | ||
lbl = std::string("iterations = 4"); | ||
gv4->addLabel (lbl, {0, -1, 0}, morph::TextFeatures(0.06f)); | ||
gv4->finalize(); | ||
v.addVisualModel (gv4); | ||
|
||
v.keepOpen(); | ||
|
||
} catch (const std::exception& e) { | ||
std::cerr << "Caught exception: " << e.what() << std::endl; | ||
rtn = -1; | ||
} | ||
|
||
return rtn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include <morph/vec.h> | ||
#include <morph/VisualModel.h> | ||
#include <morph/mathconst.h> | ||
#include <morph/Scale.h> | ||
#include <morph/ColourMap.h> | ||
#include <array> | ||
|
||
namespace morph { | ||
|
||
/*! | ||
* This class creates the vertices for an geodesic polyhedron in a 3D scene using | ||
* the constexpr function. | ||
* | ||
* \tparam T the type for the data to be visualized as face (or maybe vertex) colours | ||
* | ||
* \tparam glver The usual OpenGL version code; match this to everything else in | ||
* your program. | ||
*/ | ||
template<typename T, int iterations, int glver = morph::gl::version_4_1> | ||
class GeodesicVisualCE : public VisualModel<glver> | ||
{ | ||
public: | ||
GeodesicVisualCE() { this->init ({0.0, 0.0, 0.0}, 1.0f); } | ||
|
||
//! Initialise with offset, start and end coordinates, radius and a single colour. | ||
GeodesicVisualCE(const vec<float, 3> _offset, const float _radius) | ||
{ | ||
this->init (_offset, _radius); | ||
} | ||
|
||
~GeodesicVisualCE () {} | ||
|
||
void init (const vec<float, 3> _offset, const float _radius) | ||
{ | ||
// Set up... | ||
this->mv_offset = _offset; | ||
this->viewmatrix.translate (this->mv_offset); | ||
this->radius = _radius; | ||
} | ||
|
||
//! Initialize vertex buffer objects and vertex array object. | ||
void initializeVertices() | ||
{ | ||
this->vertexPositions.clear(); | ||
this->vertexNormals.clear(); | ||
this->vertexColors.clear(); | ||
this->indices.clear(); | ||
|
||
if (iterations > 5) { | ||
// Note odd necessity to stick in the 'template' keyword after this-> | ||
this->template computeSphereGeoFast<double, iterations> (this->idx, morph::vec<float, 3>({0,0,0}), | ||
this->colour, this->radius); | ||
} else { | ||
// computeSphereGeo F defaults to float | ||
this->template computeSphereGeoFast<float, iterations> (this->idx, morph::vec<float, 3>({0,0,0}), | ||
this->colour, this->radius); | ||
} | ||
} | ||
|
||
//! The radius of the geodesic | ||
float radius = 1.0f; | ||
//! Fixed colour. | ||
std::array<float, 3> colour = { 0.2f, 0.1f, 0.7f }; | ||
}; | ||
|
||
} // namespace morph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.