Forum

Author Topic: Python API inconsistent behavior of chunk attributes  (Read 3737 times)

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Python API inconsistent behavior of chunk attributes
« on: April 09, 2018, 12:44:05 PM »
In Photoscan 1.4.1, there is no way to reliably check if a given step has been done anymore.
When you create a new project you have point_cloud, dense_cloud, model, etc, set to None. When you run the alignment, other attributes are still None but once you run the camera optimization, dense_cloud and model are set to a null object of their respective type.

The issue now is that it is really cumbersome to check if the steps has been done as they are not guaranteed to be None if not and there is no attribute/method to check that condition. I guess this is due to the fact that chunks now hold a list of all those products, which also imply that we cannot remove a product by setting its attribute to None anymore.

Another weird behavior is that the list of products keeps null instances when they are cleared and new ones are added. In this project I have only one model and the orthomosaic was cleared.
Code: [Select]
chunk.models
Out[10]: 2018-04-09 11:24:55 [<Model 'empty'>, <Model '332650 faces, 167072 vertices'>]

chunk.elevations
Out[11]: 2018-04-09 11:25:06 [<Elevation '2977x1689'>]

chunk.orthomosaics
Out[12]: 2018-04-09 11:25:14 [<Orthomosaic ''>, <Orthomosaic ''>]


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Python API inconsistent behavior of chunk attributes
« Reply #1 on: April 09, 2018, 03:58:11 PM »
Hello Gall,

In the version 1.4.1 in PhotoScan it is possible to have multiple instances of the same class in the chunk (depth maps, dense clouds, meshes, elevations, tiled models, orthomsaics), so if you are using chunk.model = None assignment, it means that the active (default) model will become hidden.

If you need to remove the instance, you should use "clear" method now, for example:
Code: [Select]
chunk.orthomosaic.clear() #remove default orthomosaic

chunk.orthomosaics[0].clear() #remove the first orthomosaic in the list
Best regards,
Alexey Pasumansky,
Agisoft LLC

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Python API inconsistent behavior of chunk attributes
« Reply #2 on: April 09, 2018, 04:27:51 PM »
Hello Alexey,

that's what I now understand playing with it but, it might be a semantic issue, using clear() is not sufficient as it clears the instance but does not remove it (and this cleared instance will never be used again).
In my code sample I used chunk.model = None (for the optimize issue mentionned) and chunk.orthomosaic.clear() and the result is almost the same.

Besides the "no way to check if a step was done or not" issue I guess the correct way to clear such an instance is to use Chunk.remove(). I don't see the benefit of the clear() method if the instance is not reused, not removed and cannot be checked for being empty.

Dud3r

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Python API inconsistent behavior of chunk attributes
« Reply #3 on: April 10, 2018, 03:26:43 PM »
Besides the "no way to check if a step was done or not" issue

I have the same problem. How would I check in Version 1.4.1 if a workflow step was done? (Assuming I want only 1 dense cloud, 1 model, 1 dem, 1 ortho in my project).

Currently my workflow checks if the dense cloud was build by
Code: [Select]
chunk.dense_cloud is Noneand if a model was build by
Code: [Select]
chunk.model is Noneand if a DEM exists by
Code: [Select]
chunk.elevation is Noneand so on...

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Python API inconsistent behavior of chunk attributes
« Reply #4 on: April 10, 2018, 08:10:32 PM »
Hello,

The "empty" instances that are left after the chunk optimization are incorrect behavior - we will fix it in the 1.4.2 update. The "empty" instances (for models, for example) would be then only observed for multiframe chunks, to keep the proper order and indexing of multiple instances of the same kind for cases, when some frames do not have those instances reconstructed.


So now it should work in the following way:
Quote
chunk = PhotoScan.app.document.chunk
chunk.models
Out: 2018-04-10 20:05:24 [<Model '89910 faces, 45000 vertices'>, <Model '39388 faces, 19963 vertices'>]
#two model instances in the active chunk
chunk.model
Out: 2018-04-10 20:05:57 <Model '39388 faces, 19963 vertices'>
#active model is the second one
chunk.model = None
#deactivating the model - acts like no model in the chunk
chunk.models
Out: 2018-04-10 20:06:17 [<Model '89910 faces, 45000 vertices'>, <Model '39388 faces, 19963 vertices'>]
chunk.models[0].clear()
#removing the first model from the chunk
chunk.models
Out: 2018-04-10 20:07:29 [<Model '39388 faces, 19963 vertices'>]
#only the second original model is left.

In order to check, if there are any instances of a certain kind in the chunk, it is possible to use len(chunk.models).


The instance generated after the corresponding reconstruction phase is automatically set as active, so in 1.4.2 would be possible to check if there's an active model after reconstruction using "chunk.model is None".
« Last Edit: April 10, 2018, 08:18:15 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Python API inconsistent behavior of chunk attributes
« Reply #5 on: April 11, 2018, 10:36:46 AM »
This seems great. You should add a few words in the Python documentation to the respective "active attributes" to explain this behavior.