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

https://github.com/brownvc/deep-synth
31 March 2020, 06:46:23 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • b800e11290b763b58e7d3b30329769a7b77cd12a
    No releases to show
  • 291f7df
  • /
  • deep-synth
  • /
  • data
  • /
  • object.py
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

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
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:e9b8f6eb776391a4a79f8cacb735c41244640f2b
origin badgedirectory badge
swh:1:dir:54a08d56a0b0dcf8d8570e9e94f242cb08cebac3
origin badgerevision badge
swh:1:rev:b800e11290b763b58e7d3b30329769a7b77cd12a
origin badgesnapshot badge
swh:1:snp:0f10b5007a9962ed82323ed2242cf08ba5544645

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
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: b800e11290b763b58e7d3b30329769a7b77cd12a authored by kwang-ether on 14 June 2019, 23:53:57 UTC
remove csv
Tip revision: b800e11
object.py
import pickle
import os
import numpy as np
from data import ObjectData
import utils

"""
Taking care of wavefront obj files
Convert to pickle for faster loading
Currently just geometric information.
Call this file once to create a pickled version of the objects
For faster loading in the future
"""

class Obj():
    """
    Standard vertex-face representation, triangulated
    Order: x, z, y
    """
    def __init__(self, modelId, houseId=None, from_source=False, is_room=False, mirror=False):
        """
        Parameters
        ----------
        modelId (string): name of the object to be loaded
        houseId (string, optional): If loading a room, specify which house does the room belong to
        from_source (bool, optional): If false, loads the pickled version of the object
            need to call object.py once to create the pickled version.
            does not apply for rooms
        mirror (bool, optional): If true, loads the mirroed version
        """
        if is_room: from_source = True  #Don't want to save rooms...
        data_dir = utils.get_data_root_dir()
        self.vertices = []
        self.faces = []
        if from_source:
            if is_room:
                path = f"{data_dir}/suncg_data/room/{houseId}/{modelId}.obj"
            else:
                path = f"{data_dir}/suncg_data/object/{modelId}/{modelId}.obj"
            with open(path,"r") as f:
                for line in f:
                    data = line.split()
                    if len(data) > 0:   
                        if data[0] == "v":
                            v = np.asarray([float(i) for i in data[1:4]]+[1])
                            self.vertices.append(v)
                        if data[0] == "f":
                            face = [int(i.split("/")[0])-1 for i in data[1:]]
                            if len(face) == 4:
                                self.faces.append([face[0],face[1],face[2]])
                                self.faces.append([face[0],face[2],face[3]])
                            elif len(face) == 3:
                                self.faces.append([face[0],face[1],face[2]])
                            else:
                                print(f"Found a face with {len(face)} edges!!!")

            self.vertices = np.asarray(self.vertices)
            data = ObjectData()
            if not is_room and data.get_alignment_matrix(modelId) is not None:
                self.transform(data.get_alignment_matrix(modelId))
        else:
            with open(f"{data_dir}/object/{modelId}/vertices.pkl", "rb") as f:
                self.vertices = pickle.load(f)
            with open(f"{data_dir}/object/{modelId}/faces.pkl", "rb") as f:
                self.faces = pickle.load(f)
        

        if mirror:
            t = np.asarray([[-1, 0, 0, 0], \
                            [0, 1, 0, 0], \
                            [0, 0, 1, 0], \
                            [0, 0, 0, 1]])
            self.transform(t)
            self.modelId = modelId+"_mirror"
        else:
            self.modelId = modelId
                
    def save(self):
        data_dir = utils.get_data_root_dir()
        dest_dir = f"{data_dir}/object/{self.modelId}"
        if not os.path.exists(dest_dir):
            os.makedirs(dest_dir)
        with open(f"{dest_dir}/vertices.pkl", "wb") as f:
            pickle.dump(self.vertices, f, pickle.HIGHEST_PROTOCOL)
        with open(f"{dest_dir}/faces.pkl", "wb") as f:
            pickle.dump(self.faces, f, pickle.HIGHEST_PROTOCOL)
                
    
    def transform(self, t):
        self.vertices = np.dot(self.vertices, t)
    
    def get_triangles(self):
        for face in self.faces:
            yield (self.vertices[face[0]][:3], \
                   self.vertices[face[1]][:3], \
                   self.vertices[face[2]][:3],)
    
    def xmax(self):
        return np.amax(self.vertices, axis = 0)[0]

    def xmin(self):
        return np.amin(self.vertices, axis = 0)[0]

    def ymax(self):
        return np.amax(self.vertices, axis = 0)[2]

    def ymin(self):
        return np.amin(self.vertices, axis = 0)[2]

    def zmax(self):
        return np.amax(self.vertices, axis = 0)[1]

    def zmin(self):
        return np.amin(self.vertices, axis = 0)[1]

def parse_objects():
    """
    parse .obj objects and save them to pickle files
    """
    data_dir = utils.get_data_root_dir()
    obj_dir = data_dir + "/suncg_data/object/"
    print("Parsing SUNCG object files...")
    l = len(os.listdir(obj_dir))
    for (i, modelId) in enumerate(os.listdir(obj_dir)):
        print(f"{i+1} of {l}...", end="\r")
        if not modelId in ["mgcube", ".DS_Store"]:
            o = Obj(modelId, from_source = True)
            o.save()
            o = Obj(modelId, from_source = True, mirror = True)
            o.save()
    print()

if __name__ == "__main__":
    parse_objects()



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