Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • e31fa09
  • /
  • src
  • /
  • external
  • /
  • ArcSim
  • /
  • referenceshape.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:7ebcb5cbc9f94ce8a4a8736532c7941263434c53
directory badge
swh:1:dir:70754d5bbbcb118b85e3fd43533ce31be60ab86b

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
referenceshape.cpp
#include "referenceshape.hpp"

using namespace std;

ReferenceSphere::ReferenceSphere(const Vec3& _center, double _radius) : center(_center), radius(_radius) {
}

// assume mesh is a discretized sphere; find center and radius using LSQ
ReferenceSphere::ReferenceSphere(const Mesh& mesh) {
    Mat3x3 M(0);
    Vec3 b(0);
    for (size_t i=0; i<mesh.nodes.size(); i++) {
        Vec3 pi = mesh.nodes[i]->x;
        for (size_t j=0; j<mesh.nodes.size(); j++) {
            Vec3 pj = mesh.nodes[j]->x;
            for (int k=0; k<3; k++) M.col(k) += pi[k]*(pj-pi);
            b += 0.5*pi*(norm2(pj)-norm2(pi));
        }
    }
    center = M.inv() * b;
    double R2 = 0;
    for (size_t i=0; i<mesh.nodes.size(); i++) {
        R2 += norm2(center - mesh.nodes[i]->x);
    }
    radius = sqrt(R2/mesh.nodes.size());    
}

Vec3 ReferenceSphere::closest_point(const Vec3& p) {
    return center + radius * normalize(p - center);
}

bool ReferenceSphere::raycast(Vec3& p, const Vec3& dir) {
    p = normalize(p-center) * radius + center;
    return true;
}

ReferenceLinear::ReferenceLinear(const Mesh& mesh) {    
}


Vec3 ReferenceLinear::closest_point(const Vec3& p) {
    return p;
}

bool ReferenceLinear::raycast(Vec3& p, const Vec3& dir) {
    return true;
}

ReferenceMesh::ReferenceMesh(const Mesh& mesh, const string& filename) {  
    cout << "Reference mesh lookup not implemented here." << endl;
    exit(1);
}

Vec3 ReferenceMesh::closest_point(const Vec3& p) {
    return p;
}

bool ReferenceMesh::raycast(Vec3& p, const Vec3& dir) {
    return false;
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API