Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started 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
-
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):
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.
-
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
-
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):
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?
-
Hello LMG,
And have you assigned chunk variable as chunk = PhotoScan.app.document.activeChunk?
-
Thank you very much: I have now assigned chunk variable as chunk = photoScan.app.document.activeChunk and the script works.
-
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!
-
Hello ristag,
It should be something like the following:
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.
-
Thank you verry much!
Works perfect!
-
Hello ristag,
Smooth Mesh command is now implemented in Tools Menu for both Standard and Professional editions.