Forum

Author Topic: exportModel of pdf export not zoomed properly in cli mode  (Read 2566 times)

BenjaminG

  • Newbie
  • *
  • Posts: 16
    • View Profile
exportModel of pdf export not zoomed properly in cli mode
« on: October 12, 2018, 12:23:45 PM »
Hi,

When trying to export a pdf using the exportModel() in python my PDF are completely zoomed out, and in certain case, so much we don’t even see it.

This happens only in headless mode; if I add –gui, the PDF is correctly zoomed (this is not a solution since I work on Linux without a screen through putty)

I though together a fast test case under windows to show the behavior Download

Thank you for your help.
« Last Edit: November 21, 2018, 12:35:35 PM by BenjaminG »

BenjaminG

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: exportModel of pdf export not zoomed properly in cli mode
« Reply #1 on: November 21, 2018, 12:34:15 PM »
Isn't there at least a workaround in order to make it work?

BenjaminG

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: exportModel of pdf export not zoomed properly in cli mode
« Reply #2 on: December 28, 2018, 12:46:36 AM »
Since I really needed to correct this I fiddle a bit and found a workaround, I’m posting it here in case someone have the same problem.

The way it work is modifying the generated PDF and correcting the /C2W and /CO lines with correct value (the result is not the same as what PhotoScan do in gui mode but for my use its sufficient).


Code: [Select]
import os
import math
import PhotoScan


def correct_pdf(in_file):

    chunk = PhotoScan.app.document.chunk

    # Matrice de transformation
    T = chunk.transform.matrix

    # take the center of the region as the center of rotation
    view_center = list(T.mulp(chunk.region.center))

    # take the bigest size au the box as the view space
    max_size = max(T.mulp(chunk.region.size))

    # calculate de viewpoint distance with 30° fov (PDF default)
    CO = (max_size / 2) / math.tan(math.radians(30/2))

    # calculate the center of the viewpoint
    C2W = view_center
    view_center[2] += CO

    # open the saved PDF and create a new one PDF
    old_file = open(in_file, 'rb')
    new_file = open(in_file + '.newpdf', 'wb')
    for line in old_file:
        # line for 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'))
        # Line for CO
        elif line.startswith(b'/CO'):
            new_file.write(('/CO ' + str(round(CO, 5)) + '\n').encode('utf-8'))
        # rest of the file
        else:
            new_file.write(line)

    old_file.close()
    new_file.close()

    # Replace old pdf by new one
    os.remove(in_file)
    os.rename(in_file + '.newpdf', in_file)