From fdbc3ae2f19e579e82fa526b954bef23c7ee270b Mon Sep 17 00:00:00 2001 From: Mirko Bagnarol Date: Tue, 14 May 2019 11:32:43 +0200 Subject: [PATCH 1/2] Modified render.py to allow distinction of cells with different stiffness. Works with smooth option. --- LICENSE/jsoncpp | 55 --------------------- scripts/render.py | 118 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 94 insertions(+), 79 deletions(-) delete mode 100644 LICENSE/jsoncpp diff --git a/LICENSE/jsoncpp b/LICENSE/jsoncpp deleted file mode 100644 index ca2bfe1..0000000 --- a/LICENSE/jsoncpp +++ /dev/null @@ -1,55 +0,0 @@ -The JsonCpp library's source code, including accompanying documentation, -tests and demonstration applications, are licensed under the following -conditions... - -The author (Baptiste Lepilleur) explicitly disclaims copyright in all -jurisdictions which recognize such a disclaimer. In such jurisdictions, -this software is released into the Public Domain. - -In jurisdictions which do not recognize Public Domain property (e.g. Germany as of -2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is -released under the terms of the MIT License (see below). - -In jurisdictions which recognize Public Domain property, the user of this -software may choose to accept it either as 1) Public Domain, 2) under the -conditions of the MIT License (see below), or 3) under the terms of dual -Public Domain/MIT License conditions described here, as they choose. - -The MIT License is about as close to Public Domain as a license can get, and is -described in clear, concise terms at: - - http://en.wikipedia.org/wiki/MIT_License - -The full text of the MIT License follows: - -======================================================================== -Copyright (c) 2007-2010 Baptiste Lepilleur - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, copy, -modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -======================================================================== -(END LICENSE TEXT) - -The MIT license is compatible with both the GPL and commercial -software, affording one all of the rights of Public Domain with the -minor nuisance of being required to keep the above copyright notice -and license text in the source code. Note also that by accepting the -Public Domain "license" you can re-license your copy using whatever -license you like. diff --git a/scripts/render.py b/scripts/render.py index a1a0a1d..bb0975f 100644 --- a/scripts/render.py +++ b/scripts/render.py @@ -5,7 +5,9 @@ import argparse import numpy as np -sys.path.append("/home/pranav/dev/celldiv/scripts") +#Default: violet stiff (healthy), orange soft (ill) + +sys.path.append("/Users/Torsa_Legend/Desktop/ROBE TESI/Progr/scripts") import celldiv @@ -61,6 +63,10 @@ parser.add_argument("-cc", "--cell-color", type=int, nargs=3, required=False, default=[72, 38, 153], help="RGB values of cell color. From 0 to 255") + +parser.add_argument("-sc", "--softcell-color", type=int, nargs=3, required=False, + default=[153, 72, 38], + help="RGB values of color of cells with different stiffness, if present. From 0 to 255") parser.add_argument("-bc", "--background-color", type=int, nargs=3, required=False, default=[255,255,255], @@ -120,20 +126,36 @@ stopAt = args.num_frames -# Set material color -bpy.data.materials['Material'].diffuse_color = [ (1/255.0) * c for c in args.cell_color] -bpy.data.materials['Material'].specular_intensity = args.specular_intensity +bpy.context.scene.objects.active = bpy.data.objects['Cube'] +bpy.ops.object.delete() + +lamp = bpy.data.lamps['Lamp'] +lamp.energy = 5 # 10 is the max value for energy +lamp.type = 'SUN' # in ['POINT', 'SUN', 'SPOT', 'HEMI', 'AREA'] +lamp.distance = 100 + +#mio +math = bpy.data.materials.new("hm") +math.diffuse_color = [ (1.0/255.0)*c for c in args.cell_color] # it was (1.0/255.0)*c +math.specular_intensity = args.specular_intensity + +mats = bpy.data.materials.new("sm") +mats.diffuse_color = [ (1.0/255.0)*c for c in args.softcell_color] +mats.specular_intensity = args.specular_intensity + + + with celldiv.TrajHandle(filename) as th: frameCount = 1 try: for i in range(int(th.maxFrames/nSkip)): - + frameCount += 1 if frameCount > args.num_frames: break f = th.ReadFrame(inc=nSkip) - + if len(f) < minInd+1: print("Only ", len(f), "cells in frame ", th.currFrameNum, " skipping...") @@ -142,21 +164,49 @@ if len(args.inds) > 0: f = [f[a] for a in args.inds] - f = np.vstack(f) - # adjust to CoM - f -= np.mean(f, axis=0) - faces = [] - for mi in range(int(len(f)/192)): + f0=[] + f1=[] + if sum(th.currTypes) > 0.1: #there is at least one cell with nonzero index + for cc in range(len(th.currTypes)): + if (th.currTypes[cc]): + f1.append(f[cc]) + else: + f0.append(f[cc]) + + + if len(f0) > 0: + f=f0 + f = np.vstack(f) + faces = [] + for mi in range(int(len(f)/192)): for row in firstfaces: faces.append([(v+mi*192) for v in row]) - - - mesh = bpy.data.meshes.new('cellMesh') - ob = bpy.data.objects.new('cellObject', mesh) - - bpy.context.scene.objects.link(ob) - mesh.from_pydata(f, [], faces) - mesh.update() + mesh = bpy.data.meshes.new('cellMesh') + ob0 = bpy.data.objects.new('cellObject', mesh) + mat0 = bpy.data.materials['hm'] + ob0.data.materials.append(mat0) + + bpy.context.scene.objects.link(ob0) + mesh.from_pydata(f, [], faces) + mesh.update() + + + #Soft cells + if len(f1) > 0: + f=f1 + f = np.vstack(f) + faces = [] + for mi in range(int(len(f)/192)): + for row in firstfaces: + faces.append([(v+mi*192) for v in row]) + mesh1 = bpy.data.meshes.new('scellMesh') + ob1 = bpy.data.objects.new('scellObject', mesh1) + mat1 = bpy.data.materials['sm'] + ob1.data.materials.append(mat1) + + bpy.context.scene.objects.link(ob1) + mesh1.from_pydata(f, [], faces) + mesh1.update() if doSmooth: bpy.ops.object.select_by_type(type='MESH') @@ -165,16 +215,32 @@ bpy.ops.mesh.normals_make_consistent(inside=False) bpy.ops.object.editmode_toggle() bpy.ops.object.shade_smooth() - bpy.context.scene.objects.active = bpy.data.objects['Cube'] - bpy.ops.object.make_links_data(type='MATERIAL') # copy material from Cube + + bpy.ops.object.select_by_type(type='MESH') + bpy.context.scene.objects.active = bpy.data.objects['scellObject'] + bpy.ops.object.editmode_toggle() + bpy.ops.mesh.normals_make_consistent(inside=False) + bpy.ops.object.editmode_toggle() + bpy.ops.object.shade_smooth() + bpy.context.scene.objects.active = bpy.data.objects['cellObject'] bpy.ops.object.select_all(action='TOGGLE') bpy.ops.object.modifier_add(type='SUBSURF') + + bpy.context.scene.objects.active = bpy.data.objects['scellObject'] + bpy.ops.object.select_all(action='TOGGLE') + bpy.ops.object.modifier_add(type='SUBSURF') + + bpy.ops.object.select_by_type(type='MESH') bpy.context.scene.objects.active = bpy.data.objects['cellObject'] - bpy.context.scene.objects.active = bpy.data.objects['Cube'] - bpy.ops.object.make_links_data(type='MATERIAL') + + bpy.context.scene.objects.active = bpy.data.objects['scellObject'] + + #mia + bpy.ops.view3d.camera_to_view_selected() + bpy.ops.object.select_all(action='TOGGLE') imagename = basename + "%d.png" % frameCount @@ -183,7 +249,11 @@ bpy.ops.render.render(write_still=True) # render to file bpy.ops.object.select_pattern(pattern='cellObject') - bpy.ops.object.delete() # delete mesh... + bpy.ops.object.delete() # delete mesh... + + #roba mia + bpy.ops.object.select_pattern(pattern='scellObject') + bpy.ops.object.delete() except celldiv.IncompleteTrajectoryError: From f04b61101a9217489bd4824ab26a337105e73490 Mon Sep 17 00:00:00 2001 From: Mirko Bagnarol Date: Tue, 14 May 2019 12:12:44 +0200 Subject: [PATCH 2/2] Removed some comments --- scripts/render.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/render.py b/scripts/render.py index bb0975f..df2fe4f 100644 --- a/scripts/render.py +++ b/scripts/render.py @@ -136,7 +136,7 @@ #mio math = bpy.data.materials.new("hm") -math.diffuse_color = [ (1.0/255.0)*c for c in args.cell_color] # it was (1.0/255.0)*c +math.diffuse_color = [ (1.0/255.0)*c for c in args.cell_color] math.specular_intensity = args.specular_intensity mats = bpy.data.materials.new("sm") @@ -238,7 +238,7 @@ bpy.context.scene.objects.active = bpy.data.objects['scellObject'] - #mia + bpy.ops.view3d.camera_to_view_selected() bpy.ops.object.select_all(action='TOGGLE') @@ -251,7 +251,6 @@ bpy.ops.object.select_pattern(pattern='cellObject') bpy.ops.object.delete() # delete mesh... - #roba mia bpy.ops.object.select_pattern(pattern='scellObject') bpy.ops.object.delete()