Skip to content

Commit

Permalink
Too many updates to list
Browse files Browse the repository at this point in the history
  • Loading branch information
Wassim Jabi committed Jun 14, 2022
1 parent 1846b11 commit b4a8083
Show file tree
Hide file tree
Showing 304 changed files with 4,761 additions and 42 deletions.
95 changes: 82 additions & 13 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
bl_info = {
"name": "Topologic",
"author": "Wassim Jabi",
"version": (0, 8, 1, 6),
"blender": (3, 1, 0),
"version": (0, 8, 1, 7),
"blender": (3, 2, 0),
"location": "Node Editor",
"category": "Node",
"description": "Topologic",
Expand Down Expand Up @@ -256,7 +256,8 @@ def nodes_index():
("Topologic.MatrixByScaling", "SvMatrixByScaling"),
("Topologic.MatrixByTranslation", "SvMatrixByTranslation"),
("Topologic.MatrixMultiply", "SvMatrixMultiply"),
("Topologic.Run", "SvTopologicRun")]
("Topologic.Run", "SvTopologicRun"),
("Topologic.InstallDependencies", "SvTopologicInstallDependencies")]

visgraphNodes = [("Topologic.GraphVisibilityGraph", "SvGraphVisibilityGraph")]
numpyNodes = [("Topologic.TopologyRemoveCoplanarFaces", "SvTopologyRemoveCoplanarFaces"),
Expand All @@ -266,7 +267,6 @@ def nodes_index():
("Topologic.IFCClashDetection", "SvIFCClashDetection"),
("Topologic.IFCConnectBuildingElements", "SvIFCConnectBuildingElements"),
("Topologic.IFCCreateSpaces", "SvIFCCreateSpaces"),
("Topologic.IFCExportToHBJSON", "SvIFCExportToHBJSON"),
("Topologic.IFCReadFile", "SvIFCReadFile"),
("Topologic.IFCWriteFile", "SvIFCWriteFile"),
("Topologic.TopologyByImportedIFC", "SvTopologyByImportedIFC")]
Expand Down Expand Up @@ -319,10 +319,23 @@ def nodes_index():
("Topologic.SpeckleStreamByID", "SvSpeckleStreamByID"),
("Topologic.SpeckleStreamByURL", "SvSpeckleStreamByURL"),
("Topologic.SpeckleStreamsByClient", "SvSpeckleStreamsByClient")]
dglNodes = [("Topologic.DGLAccuracy", "SvDGLAccuracy"),
("Topologic.DGLClassifierByFilePath", "SvDGLClassifierByFilePath"),
("Topologic.DGLDatasetByDGLGraphs", "SvDGLDatasetByDGLGraphs"),
("Topologic.DGLDatasetBySamples", "SvDGLDatasetBySamples"),
("Topologic.DGLGraphByGraph", "SvDGLGraphByGraph"),
("Topologic.DGLGraphByImportedCSV", "SvDGLGraphByImportedCSV"),
("Topologic.DGLGraphByImportedDGCNN", "SvDGLGraphByImportedDGCNN"),
("Topologic.DGLHyperparameters", "SvDGLHyperparameters"),
("Topologic.DGLOptimizer", "SvDGLOptimizer"),
("Topologic.DGLPredict", "SvDGLPredict"),
("Topologic.DGLTrainClassifier", "SvDGLTrainClassifier")]
hullNodes = [("Topologic.TopologyConvexHull", "SvTopologyConvexHull")]
homemakerNodes = [("Topologic.HMIFCByCellComplex", "SvHMIFCByCellComplex"),
("Topologic.HMBlenderBIMByIFC", "SvHMBlenderBIMByIFC")]
pandasNodes = [("Topologic.GraphExportToCSV", "SvGraphExportToCSV")]
plotlyNodes = [("Topologic.DGLPlot", "SvDGLPlot")]
ifchoneybeeNodes = [("Topologic.IFCExportToHBJSON", "SvIFCExportToHBJSON")]
osifcNodes = [("Topologic.EnergyModelByImportedIFC", "SvEnergyModelByImportedIFC")]
osifc = 0

Expand Down Expand Up @@ -362,13 +375,24 @@ def nodes_index():
try:
import openstudio
import honeybee
from honeybee.model import Model
import honeybee_energy
import honeybee_radiance
import ladybug
import json
coreNodes = coreNodes+honeybeeNodes
except:
print("Topologic - Warning: Could not import ladybug/honeybee/json so Honeybee nodes are not available.")
try:
import honeybee
import honeybee_energy
from honeybee.model import Model
import ifcopenshell
import numpy
import scipy
coreNodes = coreNodes+ifchoneybeeNodes
except:
print("Topologic - Warning: Could not import honeybee/ifcopenshell/numpy/scipy so IFCHoneybee nodes are not available.")
try:
import py2neo
coreNodes = coreNodes+neo4jNodes
Expand All @@ -378,12 +402,31 @@ def nodes_index():
coreNodes = coreNodes+osifcNodes
else:
print("Topologic - Warning: Could not import either openstudio/ifcopenshell so some related nodes that require both to be installed are not available.")

try:
import specklepy
import bpy_speckle
coreNodes = coreNodes+speckleNodes
except:
print("Topologic - Warning: Could not import speckle so Speckle are not available.")

try:
import numpy
import scipy
import pandas
import torch
import networkx
import tqdm
import sklearn
import dgl
coreNodes = coreNodes+dglNodes
except:
print("Topologic - Warning: Could not import numpy/scipy/pandas/torch/networkx/dgl/tqdm/sklearn so DGL nodes are not available.")
try:
import plotly
coreNodes = coreNodes+plotlyNodes
except:
print("Topologic - Warning: Could not import plotly so plot-related nodes are not available.")
try:
import numpy
import scipy
Expand All @@ -393,7 +436,6 @@ def nodes_index():
try:
import ifcopenshell
from blenderbim.bim import import_ifc
import molior
coreNodes = coreNodes+homemakerNodes
except:
print("Topologic - Warning: Could not import ifcopenshell/molior so Homemaker nodes are not available.")
Expand Down Expand Up @@ -463,17 +505,18 @@ def get_categories(self):

topologic_menu_classes = []

class NODEVIEW_MT_AddTPSubcategoryAbout(bpy.types.Menu):
bl_label = "TPSubcategoryAbout"
bl_idname = 'NODEVIEW_MT_AddTPSubcategoryAbout'
class NODEVIEW_MT_AddTPSubcategoryUtilities(bpy.types.Menu):
bl_label = "TPSubcategoryUtilities"
bl_idname = 'NODEVIEW_MT_AddTPSubcategoryUtilities'

def draw(self, context):
layout = self.layout
layout_draw_categories(self.layout, self.bl_label, [
['SvTopologicVersion'],
['SvTopologicInstallDependencies'],
])

make_class('TPSubcategoryAbout', 'Topologic @ About')
make_class('TPSubcategoryUtilities', 'Topologic @ Utilities')

class NODEVIEW_MT_AddTPSubcategoryVertex(bpy.types.Menu):
bl_label = "TPSubcategoryVertex"
Expand Down Expand Up @@ -964,6 +1007,29 @@ def draw(self, context):

make_class('TPSubcategorySpeckle', 'Topologic @ Speckle')

class NODEVIEW_MT_AddTPSubcategoryDGL(bpy.types.Menu):
bl_label = "TPSubcategoryDGL"
bl_idname = 'NODEVIEW_MT_AddTPSubcategoryDGL'

def draw(self, context):
layout = self.layout
layout_draw_categories(self.layout, self.bl_label, [
['SvDGLAccuracy'],
['SvDGLClassifierByFilePath'],
['SvDGLDatasetByDGLGraphs'],
['SvDGLDatasetBySamples'],
['SvDGLGraphByGraph'],
['SvDGLGraphByImportedCSV'],
['SvDGLGraphByImportedDGCNN'],
['SvDGLHyperparameters'],
['SvDGLOptimizer'],
['SvDGLPlot'],
['SvDGLPredict'],
['SvDGLTrainClassifier'],
])

make_class('TPSubcategoryDGL', 'Topologic @ DGL')

class NODEVIEW_MT_AddTPSubcategoryHomemaker(bpy.types.Menu):
bl_label = "TPSubcategoryHomemaker"
bl_idname = 'NODEVIEW_MT_AddTPSubcategoryHomemaker'
Expand Down Expand Up @@ -992,7 +1058,7 @@ def draw(self, context):
['@ CellComplex'],
['@ Cluster'],
['@ Topology'],
['@ Aperture'],
['@ Aperture'],
['@ Color'],
['@ Context'],
['@ Dictionary'],
Expand All @@ -1004,8 +1070,9 @@ def draw(self, context):
['@ Blockchain'],
['@ Neo4j'],
['@ Speckle'],
['@ DGL'],
['@ Homemaker'],
['@ About'],
['@ Utilities'],
])

def register():
Expand Down Expand Up @@ -1041,8 +1108,9 @@ def register():
bpy.utils.register_class(NODEVIEW_MT_AddTPSubcategoryBlockchain)
bpy.utils.register_class(NODEVIEW_MT_AddTPSubcategoryNeo4j)
bpy.utils.register_class(NODEVIEW_MT_AddTPSubcategorySpeckle)
bpy.utils.register_class(NODEVIEW_MT_AddTPSubcategoryDGL)
bpy.utils.register_class(NODEVIEW_MT_AddTPSubcategoryHomemaker)
bpy.utils.register_class(NODEVIEW_MT_AddTPSubcategoryAbout)
bpy.utils.register_class(NODEVIEW_MT_AddTPSubcategoryUtilities)
menu = make_menu()
menu_category_provider = SvExCategoryProvider("TOPOLOGIC", menu)
register_extra_category_provider(menu_category_provider)
Expand Down Expand Up @@ -1082,8 +1150,9 @@ def unregister():
bpy.utils.unregister_class(NODEVIEW_MT_AddTPSubcategoryBlockchain)
bpy.utils.unregister_class(NODEVIEW_MT_AddTPSubcategoryNeo4j)
bpy.utils.unregister_class(NODEVIEW_MT_AddTPSubcategorySpeckle)
bpy.utils.unregister_class(NODEVIEW_MT_AddTPSubcategoryDGL)
bpy.utils.unregister_class(NODEVIEW_MT_AddTPSubcategoryHomemaker)
bpy.utils.unregister_class(NODEVIEW_MT_AddTPSubcategoryAbout)
bpy.utils.unregister_class(NODEVIEW_MT_AddTPSubcategoryUtilities)
#sockets.unregister()
#icons.unregister()
#settings.unregister()
20 changes: 10 additions & 10 deletions nodes/Topologic/CellComplexDecompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,25 @@ def processItem(item):
return9 = []
return10 = []
if len(externalVerticalFaces) > 0:
return1 = topologic.Cluster.ByTopologies(flatten(externalVerticalFaces))
return1 = flatten(externalVerticalFaces)
if len(internalVerticalFaces) > 0:
return2 = topologic.Cluster.ByTopologies(flatten(internalVerticalFaces))
return2 = flatten(internalVerticalFaces)
if len(topHorizontalFaces) > 0:
return3 = topologic.Cluster.ByTopologies(flatten(topHorizontalFaces))
return3 = flatten(topHorizontalFaces)
if len(bottomHorizontalFaces) > 0:
return4 = topologic.Cluster.ByTopologies(flatten(bottomHorizontalFaces))
return4 = flatten(bottomHorizontalFaces)
if len(internalHorizontalFaces) > 0:
return5 = topologic.Cluster.ByTopologies(flatten(internalHorizontalFaces))
return5 = flatten(internalHorizontalFaces)
if len(externalVerticalApertures) > 0:
return6 = topologic.Cluster.ByTopologies(flatten(externalVerticalApertures))
return6 = flatten(externalVerticalApertures)
if len(internalVerticalApertures) > 0:
return7 = topologic.Cluster.ByTopologies(flatten(internalVerticalApertures))
return7 = flatten(internalVerticalApertures)
if len(topHorizontalApertures) > 0:
return8 = topologic.Cluster.ByTopologies(flatten(topHorizontalApertures))
return8 = flatten(topHorizontalApertures)
if len(bottomHorizontalApertures) > 0:
return9 = topologic.Cluster.ByTopologies(flatten(bottomHorizontalApertures))
return9 = flatten(bottomHorizontalApertures)
if len(internalHorizontalApertures) > 0:
return10 = topologic.Cluster.ByTopologies(flatten(internalHorizontalApertures))
return10 = flatten(internalHorizontalApertures)

return [return1, return2, return3, return4, return5, return6, return7, return8, return9, return10]

Expand Down
93 changes: 93 additions & 0 deletions nodes/Topologic/DGLAccuracy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import sys
sys.path.append(r"D:\Anaconda3\envs\py310\Lib\site-packages")
import bpy
from bpy.props import IntProperty, FloatProperty, StringProperty, BoolProperty, EnumProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode

import dgl
import pickle
import topologic
from dgl.data import DGLDataset
import torch
import numpy as np

from . import Replication

def processItem(item):
dgl_labels, dgl_predictions = item

num_correct = 0
for i in range(len(dgl_predictions)):
if dgl_predictions[i] == dgl_labels[i]:
num_correct = num_correct + 1
size = len(dgl_predictions)
return [size, num_correct, len(dgl_predictions)- num_correct, num_correct / len(dgl_predictions)]

replication = [("Default", "Default", "", 1),("Trim", "Trim", "", 2),("Iterate", "Iterate", "", 3),("Repeat", "Repeat", "", 4),("Interlace", "Interlace", "", 5)]

class SvDGLAccuracy(bpy.types.Node, SverchCustomTreeNode):
"""
Triggers: Topologic
Tooltip: Outputs the accuracy of the input predictions based on the input labels
"""
bl_idname = 'SvDGLAccuracy'
bl_label = 'DGL.Accuracy'
Replication: EnumProperty(name="Replication", description="Replication", default="Default", items=replication, update=updateNode)
LabelProp: IntProperty(name='Label', description='The actual label of the graph', default=0, update=updateNode)
PredictionProp: IntProperty(name='Prediction', description='The predicted label of the graph', default=0, update=updateNode)

def sv_init(self, context):
self.inputs.new('SvStringsSocket', 'Label').prop_name='LabelProp'
self.inputs.new('SvStringsSocket', 'Prediction').prop_name='PredictionProp'
self.outputs.new('SvStringsSocket', 'Size')
self.outputs.new('SvStringsSocket', 'Correct')
self.outputs.new('SvStringsSocket', 'Wrong')
self.outputs.new('SvStringsSocket', 'Accuracy')

def draw_buttons(self, context, layout):
layout.prop(self, "Replication",text="")

def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
if not any(socket.is_linked for socket in self.inputs):
self.outputs['Accuracy'].sv_set([])
return
labelList = self.inputs['Label'].sv_get(deepcopy=True)
predictionList = self.inputs['Prediction'].sv_get(deepcopy=True)
inputs = [labelList, predictionList]
if ((self.Replication) == "Default"):
inputs = Replication.iterate(inputs)
inputs = Replication.transposeList(inputs)
if ((self.Replication) == "Trim"):
inputs = Replication.trim(inputs)
inputs = Replication.transposeList(inputs)
elif ((self.Replication) == "Iterate"):
inputs = Replication.iterate(inputs)
inputs = Replication.transposeList(inputs)
elif ((self.Replication) == "Repeat"):
inputs = Replication.repeat(inputs)
inputs = Replication.transposeList(inputs)
elif ((self.Replication) == "Interlace"):
inputs = list(Replication.interlace(inputs))
sizeList = []
correctList = []
wrongList = []
accuracyList = []
for anInput in inputs:
size, correct, wrong, accuracy = processItem(anInput)
sizeList.append(size)
correctList.append(correct)
wrongList.append(wrong)
accuracyList.append(accuracy)
self.outputs['Size'].sv_set(sizeList)
self.outputs['Correct'].sv_set(correctList)
self.outputs['Wrong'].sv_set(wrongList)
self.outputs['Accuracy'].sv_set(accuracyList)

def register():
bpy.utils.register_class(SvDGLAccuracy)

def unregister():
bpy.utils.unregister_class(SvDGLAccuracy)
53 changes: 53 additions & 0 deletions nodes/Topologic/DGLClassifierByFilePath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import bpy
from bpy.props import IntProperty, FloatProperty, StringProperty, BoolProperty, EnumProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode

import torch
from . import Replication

def processItem(item):
"""
Parameters
----------
model_checkpoint_path : str
Path for the entire model
Returns
-------
The classifier model
"""
return torch.load(item)

class SvDGLClassifierByFilePath(bpy.types.Node, SverchCustomTreeNode):
"""
Triggers: Topologic
Tooltip: Outputs the model saved at the input file path
"""

bl_idname = 'SvDGLClassifierByFilePath'
bl_label = 'DGL.ClassifierByFilePath'
FilePathProp: StringProperty(name="File Path", description="Path from which to load the classifier.", update=updateNode)

def sv_init(self, context):
self.inputs.new('SvFilePathSocket', 'File Path').prop_name='FilePathProp'
self.outputs.new('SvStringsSocket', 'Classifier')

def process(self):
if not any(socket.is_linked for socket in self.outputs):
return

filePathList = self.inputs['File Path'].sv_get(deepcopy=True)
filePathList = Replication.flatten(filePathList)
outputs = []
for anInput in filePathList:
outputs.append(processItem(anInput))
self.outputs['Classifier'].sv_set(outputs)

def register():
bpy.utils.register_class(SvDGLClassifierByFilePath)

def unregister():
bpy.utils.unregister_class(SvDGLClassifierByFilePath)
Loading

0 comments on commit b4a8083

Please sign in to comment.