Skip to content

Commit

Permalink
add annotation example #8
Browse files Browse the repository at this point in the history
  • Loading branch information
DaisukeMiyamoto committed Jan 26, 2017
1 parent a461afb commit 774455a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
14 changes: 14 additions & 0 deletions examples/make_annotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
import os
import swc2vtk

inputfile = 'swc/200000.swc'
output_dir = '/home/nebula/work/paraview/test_annotation20170126/'
if not os.path.isdir(output_dir):
os.mkdir(output_dir)

vtkgen = swc2vtk.VtkGenerator()
vtkgen.add_swc(inputfile)
vtkgen.add_mark((219.430427, 70.454784, 61.439942), size=10)
vtkgen.write_vtk(os.path.join(output_dir, '200000.vtk'))
vtkgen.write_annotation_vtk(os.path.join(output_dir, '200000_ano.vtk'))
27 changes: 4 additions & 23 deletions swc2vtk/vtkgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,6 @@ def add_cylinder(self, pos_x=0, pos_y=0, pos_z=0, radius=1.0, height=1.0, rot_y=
self.point_list.extend(local_point_list)
self.cell_list.extend(local_cell_list)

# @staticmethod
# def add_sphere(x=0, y=0, z=0, size=1.0, data=0.0, point_start=0):
# # point_start = len(self.point_list)
#
# local_cell_list, local_point_list = swc2vtk.GenPrimitives.sphere()
#
# for cell in local_cell_list:
# cell['points'] = [i + point_start for i in cell['points']]
# cell['data'] = data
#
# # scale
# local_point_list = np.array([ v*[size, size, size] for v in local_point_list])
# # move
# local_point_list = np.array([ v+[x, y, z] for v in local_point_list])
#
# # self.point_list.extend(local_point_list)
# # self.cell_list.extend(local_cell_list)
# return local_cell_list, local_point_list

def add_cylinder_p2p(self, pos1=(0, 0, 0), pos2=(2, 0, 0), size=1.0, data=0, radius_ratio=1.0):
pos1 = np.array(pos1)
pos2 = np.array(pos2)
Expand Down Expand Up @@ -281,18 +262,18 @@ def add_datafile(self, datafilename):
def clear_datafile(self):
self.datafile_list = []

def add_mark(self, pos=(0, 0, 0), data=0.0):
def add_mark(self, pos=(0, 0, 0), size=1.0, data=0.0):
self.annotation_cell_list, self.annotation_point_list = \
swc2vtk.GenPrimitives.sphere(pos, data, len(self.annotation_cell_list))
swc2vtk.GenPrimitives.sphere(pos, size=size, data=data, point_start=len(self.annotation_cell_list))

def add_synapse(self, pre_swc_index, pre_swc_compartment, post_swc_index, post_swc_compartment, diam=0.2):
pass

def write_annotation_vtk(self, filename):
with open(filename, 'w') as wfile:
wfile.write(self.header)
wfile.write(self.annotation_point_list)
wfile.write(self.annotation_cell_list)
wfile.write(self._point2text(self.annotation_point_list))
wfile.write(self._cell2text(self.annotation_cell_list))

def write_swc(self, filename, swc_index=0, comment='swc2vtk'):
swc = self.swc_list[swc_index]
Expand Down

0 comments on commit 774455a

Please sign in to comment.