Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: lmg on March 12, 2014, 12:19:42 AM

Title: Chunk.smoothModel()
Post by: lmg 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

Title: Re: Chunk.smoothModel()
Post by: Alexey Pasumansky 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.
Title: Re: Chunk.smoothModel()
Post by: lmg 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
Title: Re: Chunk.smoothModel()
Post by: lmg 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?
Title: Re: Chunk.smoothModel()
Post by: Alexey Pasumansky on March 12, 2014, 09:28:54 PM
Hello LMG,

And have you assigned chunk variable as chunk = PhotoScan.app.document.activeChunk?
Title: Re: Chunk.smoothModel()
Post by: lmg 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.
Title: Re: Chunk.smoothModel()
Post by: gatsri 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!
Title: Re: Chunk.smoothModel()
Post by: Alexey Pasumansky 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.
Title: Re: Chunk.smoothModel()
Post by: gatsri on April 15, 2014, 02:31:51 PM
Thank you verry much!
Works perfect!
Title: Re: Chunk.smoothModel()
Post by: Alexey Pasumansky 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.