Forum

Author Topic: Set updateregion as a function of a scalebar size  (Read 6680 times)

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Set updateregion as a function of a scalebar size
« on: November 10, 2015, 01:56:23 PM »
Hi everyone,

I'm trying to do something fairly simple: set the update region in my project as a function of a scalebar size instead of using standard integers as these give different results for each project.
The syntax I'm using is this:

Code: [Select]
updateregion.size = [ab.distance*10,ab.distance*5,ab.distance*5]
The scalebar size is set previously as such:

Code: [Select]
for camera in chunk.cameras:
        if camera.label == '101.jpg':
            c1 = camera
        if camera.label == '102.jpg':
            c2 = camera
   
    ab = chunk.addScalebar(c1, c2)
    ab.reference.distance = 0.366

This doesn't seem to work, the script breaks down at this step yet it works if I use standard sizes like this for the updateregion:

Code: [Select]
updateregion.size = [12,4,4]
Am I just using the wrong syntax in "ab.distance*10" ? I've been over the documentation for this and I can't figure this out.

Thanks!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15472
    • View Profile
Re: Set updateregion as a function of a scalebar size
« Reply #1 on: November 10, 2015, 02:19:27 PM »
Hello stephan,

The size of the bounding box (chunk.region) is defined in the internal coordinate system, not in the local or geographic coordinates. 

Possibly the easier way is no get the distance between the corresponding markers (it is already in the internal coordinates):
Code: [Select]
dist = chunk.markers[0].position - chunk.markers[1].position
dist = dist.norm()
newreg = chunk.region
newreg.size = PhotoScan.Vector([dist, dist,dist])

Alternatively you can calculate the scale factor to be applied to the real-world distance when trying to use ab.reference.distance:

Code: [Select]
import math

T = chunk.transform.matrix
v_t = T.mulp(PhotoScan.Vector([0,0,0])

if chunk.crs:
m = chunk.crs.localframe(v_t)
else:
m = PhotoScan.Matrix().diag([1,1,1,1])

m = m * T
s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 2) #scale factor


dist = ab.reference.distance
newregion = chunk.region
newregion.size = PhotoScan.Vector([dist, dist, dist]) / s
chunk.region = newregion
Best regards,
Alexey Pasumansky,
Agisoft LLC

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Set updateregion as a function of a scalebar size
« Reply #2 on: November 10, 2015, 11:50:07 PM »
Hi Alexey,

Thanks for the quick reply!

I'm trying to implement the second solution that you proposed as my cameras that I'm using to define the scalebar don't have markers attached, however I get a syntax error here:
Code: [Select]
if chunk.crs:
                ^
SyntaxError: invalid syntax

Would this be due to another part of my code ?

Thanks!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15472
    • View Profile
Re: Set updateregion as a function of a scalebar size
« Reply #3 on: November 11, 2015, 01:33:28 AM »
Hello stephan,

In the previous line (where v_t is assigned) I have forgotten closing parentheses.
Best regards,
Alexey Pasumansky,
Agisoft LLC

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Set updateregion as a function of a scalebar size
« Reply #4 on: November 25, 2015, 01:11:11 AM »
Hi Alexey,

I can't get the scaling to work so I'm trying to add markers to use the first system that you suggested, but I only get one marker added to the scene when I use this code:

Code: [Select]
    chunk.addMarker()
    m = chunk.markers[0]
    m.position = c1.center
   
    chunk.addMarker()
    u = chunk.markers[1]
    u.position = c6.center
   

    newregion = chunk.region
    newregion.center = PhotoScan.Vector([x,y,z])
    dist = chunk.markers[1].position - chunk.markers[0].position
    dist = dist.norm()
    newregion.size = PhotoScan.Vector([dist, dist,dist])

Do you have any idea what I'm doing wrong?

thanks!