Forum

Author Topic: Set a region from point A to B  (Read 1585 times)

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Set a region from point A to B
« on: June 19, 2018, 12:39:49 PM »
Hi all
I'm looking for help , I have a probleme to set a region in my project from fixed points A to B, I have a text file with coordinates X,Y like this:
Code: [Select]
    {
        "Y": "131524.72623558177",
        "X": "600237.012492972"
    },
    {
        "Y": "131520.4597589273",
        "X": "600236.8305144551"
    },
    {
        "Y": "131516.19328227278",
        "X": "600236.6485359382"
    },
    {
        "Y": "131511.9268056183",
        "X": "600236.4665574214"
    }
What I'm looking for is to set a region box from 1st coordinates to 2nd (define by zone im my project to get the smallest parts) and do some stuff with , after get a 2nd region, from 2nd coordinates to 3rd (do some stuff with)etc etc
How to do it with python ?? to set my region ?? There is a lot infos over here http://www.agisoft.com/forum/index.php?topic=1886.15 or http://www.agisoft.com/forum/index.php?topic=2488.0
But I can't figured it out since few hours now  , how can I fix it ??? I've tried that but doesn't work at all ....
Code: [Select]
mySize = 4

#select the project
doc = PhotoScan.app.document

# Define: Map region
# MapRegionVec = [CenterX, CenterY, SizeX0, SizeY0, ZRotationDeg]
MapRegionVec = [coord_x, coord_y, mySize, mySize, 0.0]

#get the current chunk
chunk = doc.chunk

#create new region
newregion = PhotoScan.Region()

# Set region size
newregion.size = PhotoScan.Vector([MapRegionVec[2], MapRegionVec[3], chunk.region.size[2]])


# Set region rotation
# build rotation matrix in our coordinate system
RotZDeg = -MapRegionVec[4]
SinRotZ = math.sin(math.radians(RotZDeg))
CosRotZ = math.cos(math.radians(RotZDeg))
RotMat = PhotoScan.Matrix([[CosRotZ, -SinRotZ, 0, 0], [SinRotZ, CosRotZ, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

#  Rotate region bounding box
T = chunk.transform.matrix
v = PhotoScan.Vector([0, 0, 0, 1])
v_t = T * v
v_t.size = 3
m = chunk.crs.localframe(v_t)
m = m * T
m = RotMat * m
s = math.sqrt(m[0, 0] ** 2 + m[0, 1] ** 2 + m[0, 2] ** 2)  # scale factor
R = PhotoScan.Matrix([[m[0, 0], m[0, 1], m[0, 2]], [m[1, 0], m[1, 1], m[1, 2]], [m[2, 0], m[2, 1], m[2, 2]]])
R = R * (1. / s)
newregion.rot = R.t()

# Put newregion to chunk
chunk.region = newregion

I've tried to pout my region center to one of my markers points and thats works , but did we can define a region possition between 2 points as I asked at the beginning of my post ???
Code: [Select]

# Define: Region [CenterX, CenterY, CenterZ, SizeX, SizeY, ZRotationDeg]
MapRegionVec = [600225.8792,131360.0026,67.30138399999889, 173.8, 143.6, -25.0]



# Set region center:
newregion = PhotoScan.Region()
centerUTM = PhotoScan.Vector([MapRegionVec[0], MapRegionVec[1], MapRegionVec[2]])
centerGEO = chunk.crs.unproject(centerUTM)
centerLocal = chunk.crs.localframe(centerGEO)


#newregion.center = PhotoScan.Vector([0,0,0])
newregion.size = PhotoScan.Vector([150,150,90])
chunk.region = newregion


#newregion.size = PhotoScan.Vector([MapRegionVec[3], MapRegionVec[4], chunk.region.size[2]])

# Set region rotation
import math
SinRotZ= math.sin(math.radians(MapRegionVec[5]))
CosRotZ= math.cos(math.radians(MapRegionVec[5]))
newregion.rot = PhotoScan.Matrix( [[SinRotZ,-CosRotZ,0], [CosRotZ,SinRotZ,0], [0,0,1]] )


# put newregion to chunk
chunk.region = newregion


« Last Edit: June 19, 2018, 04:53:18 PM by magic »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Set a region from point A to B
« Reply #1 on: July 01, 2018, 07:02:04 PM »
Hello magic,

Can you please clarify, what task you are trying to solve?

Do you need to modify the size/orientation of the bounding box with your script or just move the working region (i.e. modify the center point of the bounding box)?
Best regards,
Alexey Pasumansky,
Agisoft LLC