Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: BenjaminG on April 03, 2018, 12:08:29 PM
-
Hi,
When exporting 3D PDF with exportModel() in headless mode (-r) the model is completely zoomed out. But when using gui mode (--gui) everything is correct.
When I look at the PhotoScan.app.viewpoint values I get when using -r mode:
viewpoint.center : Vector([0.0, 0.0, 186.60254037844388])
viewpoint.coo : Vector([0.0, 0.0, 0.0])
viewpoint.fov : 30.0
viewpoint.height : 100
viewpoint.width : 100
viewpoint.mag : 1.0
viewpoint.rot : Matrix([[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0]])
And when using --gui -r
viewpoint.center : Vector([-0.021930644007888106, -0.009145534891478346, 0.12193548540351035])
viewpoint.coo : Vector([-0.021930644007888106, -0.009145534891478346, -0.1705619312323125])
viewpoint.fov : 30.0
viewpoint.height : 577
viewpoint.width : 1283
viewpoint.mag : 3681.0467263858754
viewpoint.rot : Matrix([[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0]])
Then I tried modifying viewpoint:
new_viewpoint = PhotoScan.app.viewpoint
new_viewpoint.coo = PhotoScan.Vector([-0.021930644007888106, -0.009145534891478346, -0.1705619312323125])
new_viewpoint.fov = 30.0
new_viewpoint.mag = 3681.0467263858754
new_viewpoint.rot = PhotoScan.Matrix([[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0]])
PhotoScan.app.viewpoint = new_viewpoint
But it has been completely ignored.
What I'm trying to get is the default viewpoint automatically calculated just like in --gui mode.
Thanks.
-
Since I needed this feature I just made a workaround
Here it is if anyone have the same need:
def correct_pdf(in_file):
chunk = Metashape.app.document.chunk
chunk.resetRegion()
T = chunk.transform.matrix
# Center of region
view_center = list(T.mulp(chunk.region.center))
# get the region max size
max_size = max(T.mulp(chunk.region.size))
# Computre the distance to get a 30° view
CO = (max_size / 2) / math.tan(math.radians(30/2))
# Compute the center of the camera
C2W = view_center
view_center[2] += CO
# Open the PDF and create a new one
old_file = open(in_file, 'rb')
new_file = open(in_file + '.newpdf', 'wb')
for line in old_file:
# C2W
if line.startswith(b'/C2W'):
new_file.write(('/C2W [ -1 0 0 0 1 0 0 0 -1 ' +
str(round(C2W[0], 5)) + ' ' +
str(round(C2W[1], 5)) + ' ' +
str(round(C2W[2], 5)) + ' ]\n').encode('utf-8'))
# CO
elif line.startswith(b'/CO'):
new_file.write(('/CO ' + str(round(CO, 5)) + '\n').encode('utf-8'))
else:
new_file.write(line)
old_file.close()
new_file.close()