Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - johndt6

Pages: [1]
1
Python and Java API / Re: Resizing the region
« on: June 20, 2014, 06:52:02 PM »
Hello johndt6,

.activeChunk returns chunk variable or, in case of assignment, makes active the corresponding chunk, but could not be used for changing chunk contents.

So you should better use the following assignment:
Code: [Select]
chunk_orig = PhotoScan.app.document.activeChunk
chunk_orig.region = reg
Or to use chunk = PhotoScan.app.document.activeChunk from the beginning without using its duplicated copy.

Okay, thank you. I had just figured that out. I am now able to change the region, however, I am having trouble re-sizing it correctly. I wish to transform the region as follows:

1. Set the region to no rotation (so that it is square with the x, y, and z axes)
2. Set the size of the region to 2 meters wide on the X axis, 2 meters wide on the Z axis,
3 And, have the region extend 2.25 meters above the origin on the Y axis, and 5 centimeters below the origin on the Y axis.

My code to do so is as follows:
Code: [Select]
'''
Region resize test
'''

doc = PhotoScan.app.document

chunk = doc.activeChunk.copy()
reg = chunk.region

trans = chunk.transform

#<---- Rotation ---->
# Rotation matrix is equal to the identity matrix, because I want 0 Rotation, and Cos(0) = 1, Sin(0) = 0
rot_untransformed = PhotoScan.Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

rot_temp = trans * rot_untransformed  # This really isn't even necessary, as it is equal to 'trans'

# This is the scale factor. What does it do and why is it calculated in this way?
s = math.sqrt(rot_temp[0,0]**2 + rot_temp[0,1]**2 + rot_temp[0,2]**2)

R = PhotoScan.Matrix( [[rot_temp[0,0],rot_temp[0,1],rot_temp[0,2]], [rot_temp[1,0],rot_temp[1,1],rot_temp[1,2]], [rot_temp[2,0],rot_temp[2,1],rot_temp[2,2]]])

R = R * (1.0 / s)

#<---- Size ---->
geo_size = PhotoScan.Vector([2, 2.25 + .05, 2])
inter_size = trans.inv().mulp(geo_size)  # mulp function is found no where in the docs, from what I can find!


#<---- Center ---->
geo_cen = PhotoScan.Vector([0, ((2.25 + .05) / 2) - .05, 0])
inter_cen = trans.inv().mulp(geo_cen)


reg.rot = R.t()
reg.size = inter_size
reg.center = inter_cen

chunk.region = reg
PhotoScan.app.document.chunks.add(chunk)
PhotoScan.app.document.chunks.remove(PhotoScan.app.document.activeChunk)


This does not yield expected results. The X and Z axes form a rectangle not equal to 2 by 2 meters. The rotation is correct. The size of the Y axis is also not expected, nor is the center. The worst part is that the size of this box is different for each project. So I have a few questions:

What exactly is the transform matrix besides a magical 4x4 matrix. Am I transforming everything correctly?
I have no crs, so what is the native geographic location? I would assume it would be meters. Or perhaps it is arbitrary for each project?
What is the scale factor, and why is it determined that way? Does my code keep the same scale, or is it changing it unexpectedly.

My company has been scripting Agisoft for some time now, but have had to manually change the bounding box for each project because no one has been able to figure this out. I've been messing around with it for a few days with no success.

Thanks so much for your help Alexey!

2
Python and Java API / Resizing the region
« on: June 11, 2014, 06:22:29 PM »
Hello, I have recently begun Photoscan scripting and I am having trouble resizing the region through the script.

I have looked around the forums, and learned that in order to convert a vector from geograpic coordinates to the internal chunk coordinate system, I must use the transform matrix (I have no crs, so I don't have to worry about that). I run the following code:

Code: [Select]
'''
Region resize test
'''
import PhotoScan

doc = PhotoScan.app.document

chunk = doc.activeChunk.copy()
reg = chunk.region

print(reg.size, reg.center)

geo_size = PhotoScan.Vector([2, 2, 2, 1])
geo_cen = PhotoScan.Vector([0, 0, 0, 1])

trans = chunk.transform

inter_size = trans.inv() * geo_size
inter_size.size = 3

inter_cen = trans.inv() * geo_cen
inter_cen.size = 3

print(inter_size, inter_cen)

reg.size = inter_size
reg.center = inter_cen

print(reg.size, reg.center)

chunk.region = reg
PhotoScan.app.document.activeChunk = chunk.copy()

print(PhotoScan.app.document.activeChunk.region.size, PhotoScan.app.document.activeChunk.region.center)

and get the following output:

Code: [Select]
Vector([9.5782843002474, 6.393577422917392, 4.753930638638135]) Vector([-0.11697801952045438, -3.7556900242420745, 10.212026733309294])
Vector([-9.311766117668544, -12.952894025375354, 13.232803759861106]) Vector([0.15980629407120994, -0.3897937990467731, 13.243165534310934])
Vector([-9.311766117668544, -12.952894025375354, 13.232803759861106]) Vector([0.15980629407120994, -0.3897937990467731, 13.243165534310934])
Vector([9.5782843002474, 6.393577422917392, 4.753930638638135]) Vector([-0.11697801952045438, -3.7556900242420745, 10.212026733309294])

As you can see, the vectors for size and center seem to be correctly converted, and set in the region variable. However, for some reason,
Code: [Select]
PhotoScan.app.document.activeChunk = chunk.copy()does not change the activeChunk's region, and nor does:
Code: [Select]
PhotoScan.app.document.activeChunk = chunk
or
PhotoScan.app.document.activeChunk.region = reg

Thank you for your help

Pages: [1]