Skip to content

Instantly share code, notes, and snippets.

View Tehsurfer's full-sized avatar

Jesse Khorasanee Tehsurfer

View GitHub Profile
@Tehsurfer
Tehsurfer / moveNodeToMesh.py
Last active October 24, 2018 01:49
Opencmiss mesh solver for a defined direction
def moveNode(region, nodekey, plane_normal=[0, 1, 0], cache=none):
# moveNode uses dot products combined with opencmiss' evaluateMeshLocation function to solve where a point lies along a given normal (line in 3D).
# usage: Please not that this solver assumes that the user knows where the solution should be in one dimension,
# for example: Where is the closest mesh point at x=0 (normal=[1,0,0]) starting at [1,3,2]?
# Inputs:
# region: the region you wish to solve in (must contain a mesh and a the node you wish to move)
# nodekey: identifier of the node we wish to project onto the mesh
# plane_normal: the direction we wish to project the node onto the mesh
@Tehsurfer
Tehsurfer / generateGridPoints4.py
Created October 29, 2018 01:45
A function that takes in four points in 3D space on a plane and creates a grid between them
def generateGridPoints4(pointsList, number_on_side, plane_normal):
# We generate our grid points by having 4 points that we assign weightings to
# based on how far we are away from them.
# INPUTS:
# pointsList : a list of four points defined in any 3D space.
# number_on_side : the number of nodes we have on each side of our array (ie 8 nodes if we have a 64 point grid).
# plane_normal : the normal of the plane we are creating points in. EG [0,0,1] for the x,y plane.
# OUTPUTS:
@Tehsurfer
Tehsurfer / click4points.py
Created October 29, 2018 01:54
Modify your meshgeneratorwidget.py to record grid points
def init(self)
self._ui.sceneviewer_widget.grid = []
def keyReleaseEvent(self, event):
if self._marker_mode_active:
self._marker_mode_active = False
self._ui.sceneviewer_widget._model = self._plane_model
self._ui.sceneviewer_widget._calculatePointOnPlane = None
self._ui.sceneviewer_widget.mousePressEvent = self._original_mousePressEvent
if len(self._ui.sceneviewer_widget.grid) is 4:
@Tehsurfer
Tehsurfer / meshprojection.py
Last active October 31, 2018 00:12
A class for creating grids and projecting them onto the heart.
"""
Created on 30 MOct, 2018 from mapclientplugins.meshgeneratorstep.
@author: Jesse Khorasanee
"""
import numpy as np
from opencmiss.zinc.field import Field
from opencmiss.zinc.glyph import Glyph
from opencmiss.zinc.graphics import Graphics
def _calculatePointOnPlane(self, x, y):
from opencmiss.utils.maths.algorithms import calculateLinePlaneIntersection
far_plane_point = self.unproject(x, -y, -1.0)
near_plane_point = self.unproject(x, -y, 1.0)
plane_point, plane_offset, plane_normal = self._model.getPlaneDescription()
point_on_plane = calculateLinePlaneIntersection(near_plane_point, far_plane_point, plane_point, plane_normal)
if len(self.grid) < 4:
self.grid.append(point_on_plane)
else:
@Tehsurfer
Tehsurfer / json_to_csv_functions.py
Last active November 20, 2018 00:34
A few functions for loading .json and writing it to OpenCOR and general csv
import csv, json, sys
import numpy as np
#if we are using utf-8 files, uncomment the next line
# sys.setdefaultencoding("UTF-8") #set the encode to utf8
def load_json(filename):
with open(filename) as f:
data = json.load(f)
return data
import json
import numpy as np
count = 0
indexlist = []
above12 = []
filename = "C:\\Users\jkho021\Projects\SPARC\mapclient\src\mapclient\ecgDataExtended2.json"
data = {}
with open(filename) as f:
data['cache'] = json.load(f)
@Tehsurfer
Tehsurfer / routes.py
Last active November 29, 2018 09:46
a placeholder for routes.py
from flask import jsonify
from flask import request
from blackfynn import Blackfynn
import urllib2
from service.app import app
from service.config import Config
import json
import csv
import numpy as np
@Tehsurfer
Tehsurfer / strains.py
Created January 17, 2019 22:30
Strains calculation (xyz comparing by index)
def getPortData(self, index):
"""
Add your code here that will return the appropriate objects for this step.
The index is the index of the port in the port list. If there is only one
provides port for this step then the index can be ignored.
:param index: Index of the port to return.
"""
# Data can be pasted here to send to other steps for testing, or grabbed from a file if we have larger data
xl = np.array([3,4,0])
xi = xl/np.linalg.norm(xi)
yl = np.array([4,3,0])
norm = np.cross(yl,xi)
zi = norm/np.linalg.norm(norm)
yi = np.cross(zi,xi)
yi = yi/np.linalg.norm(yi)
#Transormation Matrix TM
TM = np.vstack([xi,yi,zi]).T