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

ofMesh - newfaces push_back to insert a list #7772

Merged
merged 5 commits into from May 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 25 additions & 21 deletions libs/openFrameworks/3d/ofMesh.inl
Expand Up @@ -2137,9 +2137,9 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
ofMesh_<V,N,C,T> sphere;

/// Step 1 : Generate icosahedron
const float sqrt5 = sqrt(5.0f);
const float sqrt5 = std::sqrt(5.0f);
const float phi = (1.0f + sqrt5) * 0.5f;
const float invnorm = 1/sqrt(phi*phi+1);
const float invnorm = 1/std::sqrt(phi*phi+1);


// FIXME: addvertices XAXA
Expand All @@ -2156,7 +2156,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
sphere.addVertex(invnorm * V(-1, -phi,0));//10
sphere.addVertex(invnorm * V( 1, -phi,0));//11

ofIndexType firstFaces[] = {
ofIndexType firstFaces[] = {
0,1,2,
0,3,1,
0,4,5,
Expand Down Expand Up @@ -2198,29 +2198,33 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
auto i1 = faces[i*3];
auto i2 = faces[i*3+1];
auto i3 = faces[i*3+2];
auto i12 = vertices.size();
auto i23 = i12+1;
auto i13 = i12+2;
auto i12 = static_cast<ofIndexType>(vertices.size());
auto i23 = static_cast<ofIndexType>(i12 + 1);
auto i13 = static_cast<ofIndexType>(i12 + 2);
auto v1 = vertices[i1];
auto v2 = vertices[i2];
auto v3 = vertices[i3];
//make 1 vertice at the center of each edge and project it onto the sphere
vertices.push_back(glm::normalize(toGlm(v1+v2)));
vertices.push_back(glm::normalize(toGlm(v2+v3)));
vertices.push_back(glm::normalize(toGlm(v1+v3)));
vertices.insert(vertices.end(), {
glm::normalize(toGlm(v1+v2)),
glm::normalize(toGlm(v2+v3)),
glm::normalize(toGlm(v1+v3)),
});
//now recreate indices
newFaces.push_back(i1);
newFaces.push_back(i12);
newFaces.push_back(i13);
newFaces.push_back(i2);
newFaces.push_back(i23);
newFaces.push_back(i12);
newFaces.push_back(i3);
newFaces.push_back(i13);
newFaces.push_back(i23);
newFaces.push_back(i12);
newFaces.push_back(i23);
newFaces.push_back(i13);
newFaces.insert(newFaces.end(), {
i1,
i12,
i13,
i2,
i23,
i12,
i3,
i13,
i23,
i12,
i23,
i13
});
}
faces.swap(newFaces);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/openFrameworks/math/ofMath.cpp
Expand Up @@ -86,12 +86,12 @@ float ofMap(float value, float inputMin, float inputMax, float outputMin, float

//--------------------------------------------------
float ofDist(float x1, float y1, float x2, float y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
return std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//--------------------------------------------------
float ofDist(float x1, float y1, float z1, float x2, float y2, float z2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
return std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
}

//--------------------------------------------------
Expand Down
30 changes: 15 additions & 15 deletions libs/openFrameworks/math/ofMatrix4x4.cpp
Expand Up @@ -220,7 +220,7 @@ ofQuaternion ofMatrix4x4::getRotate() const
QZ = tq[3];
}

s = sqrt(0.25/tq[j]);
s = std::sqrt(0.25f/tq[j]);
QW *= s;
QX *= s;
QY *= s;
Expand All @@ -239,10 +239,10 @@ ofQuaternion ofMatrix4x4::getRotate() const
ofQuaternion q;

// From http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
QW = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] + _mat[1][1] + _mat[2][2] ) );
QX = 0.5 * sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] - _mat[1][1] - _mat[2][2] ) );
QY = 0.5 * sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] + _mat[1][1] - _mat[2][2] ) );
QZ = 0.5 * sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] - _mat[1][1] + _mat[2][2] ) );
QW = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] + _mat[1][1] + _mat[2][2] ) );
QX = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 + _mat[0][0] - _mat[1][1] - _mat[2][2] ) );
QY = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] + _mat[1][1] - _mat[2][2] ) );
QZ = 0.5 * std::sqrt( osg::maximum( 0.0, 1.0 - _mat[0][0] - _mat[1][1] + _mat[2][2] ) );

#if 0
// Robert Osfield, June 7th 2007, arggg this new implementation produces many many errors, so have to revert to sign(..) orignal below.
Expand Down Expand Up @@ -516,7 +516,7 @@ void ofMatrix4x4::makeOrthoNormalOf(const ofMatrix4x4& rhs)

if(!equivalent((double)x_colMag, 1.0) && !equivalent((double)x_colMag, 0.0))
{
x_colMag = sqrt(x_colMag);
x_colMag = std::sqrt(x_colMag);
_mat[0][0] = rhs._mat[0][0] / x_colMag;
_mat[1][0] = rhs._mat[1][0] / x_colMag;
_mat[2][0] = rhs._mat[2][0] / x_colMag;
Expand All @@ -530,7 +530,7 @@ void ofMatrix4x4::makeOrthoNormalOf(const ofMatrix4x4& rhs)

if(!equivalent((double)y_colMag, 1.0) && !equivalent((double)y_colMag, 0.0))
{
y_colMag = sqrt(y_colMag);
y_colMag = std::sqrt(y_colMag);
_mat[0][1] = rhs._mat[0][1] / y_colMag;
_mat[1][1] = rhs._mat[1][1] / y_colMag;
_mat[2][1] = rhs._mat[2][1] / y_colMag;
Expand All @@ -544,7 +544,7 @@ void ofMatrix4x4::makeOrthoNormalOf(const ofMatrix4x4& rhs)

if(!equivalent((double)z_colMag, 1.0) && !equivalent((double)z_colMag, 0.0))
{
z_colMag = sqrt(z_colMag);
z_colMag = std::sqrt(z_colMag);
_mat[0][2] = rhs._mat[0][2] / z_colMag;
_mat[1][2] = rhs._mat[1][2] / z_colMag;
_mat[2][2] = rhs._mat[2][2] / z_colMag;
Expand Down Expand Up @@ -1056,10 +1056,10 @@ void adjoint_transpose(_HMatrix M, _HMatrix MadjT)
/** Setup u for Household reflection to zero all v components but first **/
void make_reflector(double *v, double *u)
{
double s = sqrt(vdot(v, v));
double s = std::sqrt(vdot(v, v));
u[0] = v[0]; u[1] = v[1];
u[2] = v[2] + ((v[2]<0.0) ? -s : s);
s = sqrt(2.0/vdot(u, u));
s = std::sqrt(2.0/vdot(u, u));
u[0] = u[0]*s; u[1] = u[1]*s; u[2] = u[2]*s;
}

Expand Down Expand Up @@ -1116,10 +1116,10 @@ void do_rank2(_HMatrix M, _HMatrix MadjT, _HMatrix Q)
make_reflector(v2, v2); reflect_rows(M, v2);
w = M[0][0]; x = M[0][1]; y = M[1][0]; z = M[1][1];
if (w*z>x*y) {
c = z+w; s = y-x; d = sqrt(c*c+s*s); c = c/d; s = s/d;
c = z+w; s = y-x; d = std::sqrt(c*c+s*s); c = c/d; s = s/d;
Q[0][0] = Q[1][1] = c; Q[0][1] = -(Q[1][0] = s);
} else {
c = z-w; s = y+x; d = sqrt(c*c+s*s); c = c/d; s = s/d;
c = z-w; s = y+x; d = std::sqrt(c*c+s*s); c = c/d; s = s/d;
Q[0][0] = -(Q[1][1] = c); Q[0][1] = Q[1][0] = s;
}
Q[0][2] = Q[2][0] = Q[1][2] = Q[2][1] = 0.0; Q[2][2] = 1.0;
Expand Down Expand Up @@ -1155,7 +1155,7 @@ ofQuaternion quatFromMatrix(_HMatrix mat)
tr = mat[X][X] + mat[Y][Y]+ mat[Z][Z];
if (tr >= 0.0)
{
s = sqrt(tr + mat[W][W]);
s = std::sqrt(tr + mat[W][W]);
qu.w() = s*0.5;
s = 0.5 / s;
qu.x() = (mat[Z][Y] - mat[Y][Z]) * s;
Expand Down Expand Up @@ -1219,7 +1219,7 @@ double polarDecomp( _HMatrix M, _HMatrix Q, _HMatrix S)
MadjT_one = norm_one(MadjTk);
MadjT_inf = norm_inf(MadjTk);

gamma = sqrt(sqrt((MadjT_one*MadjT_inf)/(M_one*M_inf))/std::abs(det));
gamma = std::sqrt(std::sqrt((MadjT_one*MadjT_inf)/(M_one*M_inf))/std::abs(det));
g1 = gamma*0.5;
g2 = 0.5/(gamma*det);
matrixCopy(Ek,=,Mk,3);
Expand Down Expand Up @@ -1392,7 +1392,7 @@ ofQuaternion snuggle(ofQuaternion q, HVect *k)
}

qp = Qt_Mul(q, p);
t = sqrt(mag[win]+0.5);
t = std::sqrt(mag[win]+0.5);
p = Qt_Mul(p, Qt_(0.0,0.0,-qp.z()/t,qp.w()/t));
p = Qt_Mul(qtoz, Qt_Conj(p));
}
Expand Down
14 changes: 7 additions & 7 deletions libs/openFrameworks/math/ofQuaternion.cpp
Expand Up @@ -93,7 +93,7 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
float fromLen;
// normalize only when necessary, epsilon test
if ((fromLen2 < 1.0 - 1e-7) || (fromLen2 > 1.0 + 1e-7)) {
fromLen = sqrt(fromLen2);
fromLen = std::sqrt(fromLen2);
sourceVector /= fromLen;
} else fromLen = 1.0;

Expand All @@ -104,7 +104,7 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
// re-use fromLen for case of mapping 2 vectors of the same length
if ((toLen2 > fromLen2 - 1e-7) && (toLen2 < fromLen2 + 1e-7)) {
toLen = fromLen;
} else toLen = sqrt(toLen2);
} else toLen = std::sqrt(toLen2);
targetVector /= toLen;
}

Expand All @@ -121,19 +121,19 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
// Then use it as quaternion axis with pi angle
// Trick is to realize one value at least is >0.6 for a normalized vector.
if (std::abs(sourceVector.x) < 0.6) {
const double norm = sqrt(1.0 - sourceVector.x * sourceVector.x);
const double norm = std::sqrt(1.0 - sourceVector.x * sourceVector.x);
_v.x = 0.0;
_v.y = sourceVector.z / norm;
_v.z = -sourceVector.y / norm;
_v.w = 0.0;
} else if (std::abs(sourceVector.y) < 0.6) {
const double norm = sqrt(1.0 - sourceVector.y * sourceVector.y);
const double norm = std::sqrt(1.0 - sourceVector.y * sourceVector.y);
_v.x = -sourceVector.z / norm;
_v.y = 0.0;
_v.z = sourceVector.x / norm;
_v.w = 0.0;
} else {
const double norm = sqrt(1.0 - sourceVector.z * sourceVector.z);
const double norm = std::sqrt(1.0 - sourceVector.z * sourceVector.z);
_v.x = sourceVector.y / norm;
_v.y = -sourceVector.x / norm;
_v.z = 0.0;
Expand All @@ -144,7 +144,7 @@ void ofQuaternion::makeRotate( const ofVec3f& from, const ofVec3f& to ) {
else {
// Find the shortest angle quaternion that transforms normalized vectors
// into one other. Formula is still valid when vectors are colinear
const double s = sqrt(0.5 * dotProdPlus1);
const double s = std::sqrt(0.5 * dotProdPlus1);
const ofVec3f tmp = sourceVector.getCrossed(targetVector) / (2.0 * s);
_v.x = tmp.x;
_v.y = tmp.y;
Expand Down Expand Up @@ -217,7 +217,7 @@ void ofQuaternion::getRotate( float& angle, ofVec3f& vec ) const {
// Won't give very meaningful results if the Quat is not associated
// with a rotation!
void ofQuaternion::getRotate( float& angle, float& x, float& y, float& z ) const {
float sinhalfangle = sqrt( _v.x * _v.x + _v.y * _v.y + _v.z * _v.z );
float sinhalfangle = std::sqrt( _v.x * _v.x + _v.y * _v.y + _v.z * _v.z );

angle = 2.0 * std::atan2( sinhalfangle, _v.w );
if (sinhalfangle) {
Expand Down
4 changes: 2 additions & 2 deletions libs/openFrameworks/math/ofQuaternion.h
Expand Up @@ -456,7 +456,7 @@ const ofQuaternion ofQuaternion::operator -() const {

//----------------------------------------
float ofQuaternion::length() const {
return sqrt(_v.x*_v.x + _v.y*_v.y + _v.z*_v.z + _v.w*_v.w);
return std::sqrt(_v.x*_v.x + _v.y*_v.y + _v.z*_v.z + _v.w*_v.w);
}


Expand Down Expand Up @@ -493,7 +493,7 @@ ofVec3f ofQuaternion::operator*(const ofVec3f& v) const {

void ofQuaternion::normalize(){
float len = _v.w*_v.w + _v.x*_v.x + _v.y*_v.y + _v.z*_v.z;
float factor = 1.0f / sqrt(len);
float factor = 1.0f / std::sqrt(len);
_v.x *= factor;
_v.y *= factor;
_v.z *= factor;
Expand Down
4 changes: 2 additions & 2 deletions libs/openFrameworks/sound/ofSoundBuffer.cpp
Expand Up @@ -540,7 +540,7 @@ float ofSoundBuffer::getRMSAmplitude() const {
for(size_t i = 0; i < buffer.size(); i++){
acc += buffer[i] * buffer[i];
}
return sqrt(acc / (double)buffer.size());
return std::sqrt(acc / (double)buffer.size());
}

float ofSoundBuffer::getRMSAmplitudeChannel(std::size_t channel) const {
Expand All @@ -553,7 +553,7 @@ float ofSoundBuffer::getRMSAmplitudeChannel(std::size_t channel) const {
float sample = getSample(i, channel);
acc += sample * sample;
}
return sqrt(acc / (double)getNumFrames());
return std::sqrt(acc / (double)getNumFrames());
}

void ofSoundBuffer::normalize(float level){
Expand Down