Modifying Soft Selection [SOLVED]

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

 
Thread Tools Display Modes
  07 July 2018
Modifying Soft Selection [SOLVED]

Hi.
Is there anything I can do to speed up setting nonzero values?
The goal is to have soft-selection without actual selection.


(
gc();t2=timestamp();hf = heapfree
with redraw off (
 
 delete objects
 obj = plane widthSegments:90 lengthSegments:90 width:100 length:100 isselected:on
 convertToPoly obj
 obj.useSoftSel = on
 fsel = #{}
 for f=1 to polyop.getNumFaces obj where (abs (polyop.getFaceCenter obj f).y) < 5 do fsel[f] = true
 polyop.setFaceSelection obj fsel
 subObjectLevel = 4
 redrawViews()
 
 
 getData = polyop.getVDataValue
 setData = polyop.setVDataValue

 ssZero = #{}
 ssNonZero = #()
 
 t1=timestamp()
 for i = 1 to polyop.getNumVerts obj do 
 (
  f = getData obj 1 i
  
  case of 
  (
   (f > 0.999) : ssZero[i] = true
   (f < 0.001) : ssZero[i] = true
   default : ssNonZero[i] = f   
  )

 )
 format "Get values % sec\n" ((timestamp() - t1)/1000 as float)
 
 obj.useSoftSel = off
 
 t1=timestamp()
 setData obj 1 ssZero 0.0
 format "Set zeroes % sec\n" ((timestamp() - t1)/1000 as float)
 
 t1=timestamp()
 for i = 1 to polyop.getNumVerts obj where ssNonZero[i] != undefined do setData obj 1 i ssNonZero[i]
 format "Set nonzeroes % sec\n" ((timestamp() - t1)/1000 as float)
 
 t1=timestamp()
 update obj
 format "Updating % sec\n" ((timestamp() - t1)/1000 as float)
 
 polyop.setFaceSelection obj #{}
)
redrawViews()
format "Time: %sec. Mem: %\n" ((timestamp()-t2)/1000 as float) (hf-heapfree)
)

Quote: Get values 0.018 sec
Set zeroes 0.0 sec
Set nonzeroes 0.441 sec
Updating 0.0 sec


and the updated version which works fast enough
The trick was to group indexes by value and then set value for the whole group. Sure it introduces some error to initial values but it is acceptable.


(gc();t2=timestamp();hf = heapfree
with redraw off (
 
 delete objects
 obj = plane widthSegments:90 lengthSegments:90 width:100 length:100 isselected:on
 convertToPoly obj
 obj.useSoftSel = on
 fsel = #{}
 for f=1 to polyop.getNumFaces obj where (abs (polyop.getFaceCenter obj f).y) < 5 do fsel[f] = true
 polyop.setFaceSelection obj fsel
 subObjectLevel = 4
 redrawViews()
 
 disableRefMsgs()
 getData = polyop.getVDataValue
 setData = polyop.setVDataValue

 fractions = 40
 step = 1.0 / fractions
 
 ssZero = #{}
 ssNonZero = for i=1 to fractions collect #{}

 t1=timestamp()
 for i = 1 to polyop.getNumVerts obj do 
 (
  f = getData obj 1 i
  
  case of 
  (
   (f < 0.001) : ssZero[i] = true
   (f > 0.999) : ssZero[i] = true   
   default : ssNonZero[1 + int (f / step)][i] = true   
  )

 )
 format "Get values % sec\n" ((timestamp() - t1)/1000 as float)
 
 obj.useSoftSel = off
 
 t1=timestamp()
 setData obj 1 ssZero 0.0
 format "Set zeroes % sec\n" ((timestamp() - t1)/1000 as float)
 
 
 t1=timestamp()
 for i=1 to fractions do setData obj 1 ssNonZero[i] (step*i)
 format "Set nonzeroes % sec\n" ((timestamp() - t1)/1000 as float)
 
 t1=timestamp()
 update obj
 format "Updating % sec\n" ((timestamp() - t1)/1000 as float)
 enableRefMsgs()
 polyop.setFaceSelection obj #{}
)
redrawViews()
format "Time: %sec. Mem: %\n" ((timestamp()-t2)/1000 as float) (hf-heapfree)
)

Quote: Get values 0.023 sec
Set zeroes 0.001 sec
Set nonzeroes 0.004 sec
Updating 0.0 sec

Last edited by Serejah : 07 July 2018 at 01:17 PM.
 
  07 July 2018
Just an observation, in 2019.1 it doesn't seem there's a significant difference between the two:

Get values 0.015 sec
Set zeroes 0.0 sec
Set nonzeroes 0.003 sec
Updating 0.0 sec
Time: 0.163sec. Mem: 1340L

vs.

Get values 0.016 sec
Set zeroes 0.001 sec
Set nonzeroes 0.005 sec
Updating 0.001 sec
Time: 0.165sec. Mem: 4268L
__________________
Scripts :: linkedin
 
  07 July 2018
Thanks.
Tested it in 2017 and the difference remains. Guess all versions up to 2018 will behave the same in that matter.
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:43 PM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.