Forum

Author Topic: Chunk.smoothModel()  (Read 6866 times)

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Chunk.smoothModel()
« on: March 12, 2014, 12:19:42 AM »
In the PhotoScan Python Reference manual I have seen that starting from the PhotoScan version 1.0.0 it was introduced a new tool for smoothing meshes, using Laplacian smoothing algorithm.
Chunk.smoothModel().
It would be very useful to have this tool directly in the menus of Photoscan, otherwise I wish to use this tool on the elaborated meshes, also with the 4D models. Please Alexey, could you suggest how to write the python code to do this?
Thank you very much.
LMG


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Chunk.smoothModel()
« Reply #1 on: March 12, 2014, 12:51:16 AM »
Hello LMG,

We'll consider the possibility of Smooth Model implementation in GUI. To apply smoothing to all the frames in the chunk you need to use list of integers (each one of them is the number of frame to be processed):
Code: [Select]
frame_list = list()
frame_list.extend(range(0, chunk.frame_count))
chunk.smoothModel(3, frame_list)

Actually, you can create a custom menu item by youself. If you wish we can assist you and post the complete code of the script that adds the smoothModel operation as menu item and allows to select if smoothing is to be applied to the single frame, all frames in the active chunk or entire workspace.
Best regards,
Alexey Pasumansky,
Agisoft LLC

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Chunk.smoothModel()
« Reply #2 on: March 12, 2014, 08:23:00 PM »
Thank you Alexey.
I will be very grateful if you could assist me in creating a custom menu item to smooth the models, and post the complete code of the script that adds the smoothModel operation as menu item, allowing to select if smoothing is to be applied to the single frame, all frames in the active chunk or entire workspace.
I hope that you will write this code very soon.
LMG

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Chunk.smoothModel()
« Reply #3 on: March 12, 2014, 08:48:00 PM »
Hello LMG,

We'll consider the possibility of Smooth Model implementation in GUI. To apply smoothing to all the frames in the chunk you need to use list of integers (each one of them is the number of frame to be processed):
Code: [Select]
frame_list = list()
frame_list.extend(range(0, chunk.frame_count))
chunk.smoothModel(3, frame_list)

Actually, you can create a custom menu item by youself. If you wish we can assist you and post the complete code of the script that adds the smoothModel operation as menu item and allows to select if smoothing is to be applied to the single frame, all frames in the active chunk or entire workspace.

I have tried to use your code as a Python script on a 44 frames chunk without any result, and the log on the console is:
Smoothing mesh...
Finished processing in 0 sec (exit code 0)

Why?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Chunk.smoothModel()
« Reply #4 on: March 12, 2014, 09:28:54 PM »
Hello LMG,

And have you assigned chunk variable as chunk = PhotoScan.app.document.activeChunk?
Best regards,
Alexey Pasumansky,
Agisoft LLC

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Chunk.smoothModel()
« Reply #5 on: March 12, 2014, 10:49:19 PM »
Thank you very much: I have now assigned chunk variable as chunk = photoScan.app.document.activeChunk and the script works.

gatsri

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Chunk.smoothModel()
« Reply #6 on: April 15, 2014, 01:03:14 PM »
Alex, can you please poste the code for a custom menu item with the smooth Chunk.smoothModel() command?
That would be verry great and helpful. Im new in Python...  :P :o

Thanks a lot!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Chunk.smoothModel()
« Reply #7 on: April 15, 2014, 01:20:34 PM »
Hello ristag,

It should be something like the following:

Code: [Select]
import PhotoScan

def main():

doc = PhotoScan.app.document
chunk = doc.activeChunk

if chunk.model:
x = PhotoScan.app.getInt("Input number of smoothing steps:", 3)
chunk.smoothModel(x)
print("Smoothing by script finished.")
return 1
else:
print("No model. Script aborted.")
return 0

PhotoScan.app.addMenuItem("Custom menu/Smooth model", main)

You need to run it one via Run Script menu and the menu item will remain there until PhotoScan window is closed. Alternatively you can put this script to autostart folder and it will appear in any PhotoScan window opened.

Note that the script will work only for active chunk, so it you work with multiple chunks let me know and I'll include modifications to script.
Best regards,
Alexey Pasumansky,
Agisoft LLC

gatsri

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Chunk.smoothModel()
« Reply #8 on: April 15, 2014, 02:31:51 PM »
Thank you verry much!
Works perfect!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Chunk.smoothModel()
« Reply #9 on: November 18, 2015, 08:07:16 PM »
Hello ristag,

Smooth Mesh command is now implemented in Tools Menu for both Standard and Professional editions.
Best regards,
Alexey Pasumansky,
Agisoft LLC