Forum

Author Topic: How do I center my scene on 0,0,0?  (Read 4016 times)

stijntje44@hotmail.com

  • Newbie
  • *
  • Posts: 7
    • View Profile
How do I center my scene on 0,0,0?
« on: April 23, 2019, 05:19:23 PM »
No matter what I do I can't seem to figure this out.


I want to center my scene at 0,0,0 based on location of Markers. I have the marker location, but I can't figure out how to change the scene, I can change the region, but that's about it.


Is there a function that can be used to adjust the rotation and transform of the entire scene, or do I have to apply a matrix multiplication to all individual cameras in the scene?

Any help would be greatly appreciated.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How do I center my scene on 0,0,0?
« Reply #1 on: April 23, 2019, 06:14:04 PM »
Hello stijntje44,

Do you mean that you wish to translate the origin of the coordinate system to the selected marker, keeping the scale and orientation of the original model?
Best regards,
Alexey Pasumansky,
Agisoft LLC

stijntje44@hotmail.com

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How do I center my scene on 0,0,0?
« Reply #2 on: April 24, 2019, 09:28:56 AM »
Hello stijntje44,

Do you mean that you wish to translate the origin of the coordinate system to the selected marker, keeping the scale and orientation of the original model?

Indeed, I probably want to change orientation and scale as well, but I figured I'd start with the position, and once I had that figured out, the rest could probably be derived from there, I did some research into how to translate coordinates from one coordinate system to another via matrix calculation but I have no Idea how to actually implement it in agisoft.

I don't know if there is a function that can be used to simple remap the entire coordinate system, or if I have to change the positions and rotations of each camera within the current coordinate system.
Either way, I don't know which function to use.

Any help would be greatly appreciated.

(ps, I want to use the average of two markers as 0,0,0, I have the coordinates, I just don't know how to implement them).

Update: So far I've been able to adjust the location of all cameras individually but doing so makes the entire scene unusable it seems (markers are lost, dense cloud generation results in zero resolution align cameras resets them back to the original position)
« Last Edit: April 24, 2019, 02:11:13 PM by stijntje44@hotmail.com »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How do I center my scene on 0,0,0?
« Reply #3 on: May 11, 2019, 09:49:47 PM »
Hello stijntje44,

Please check, if the following script works as desired:
Code: [Select]
import Metashape

def move_origin(chunk):

T = chunk.transform.matrix
markers = list()
for m in chunk.markers:
if m.selected:
markers.append(m)

if len(markers) != 2:
print("You need to select two markers only.")
return 0

m1 = markers[0]
m2 = markers[1]
if not m1.position:
print("Marker location is not defined.")
return 0
if not m2.position:
print("Marker location is not defined.")
return 0
origin = (m1.position + m2.position) * 0.5

origin = (-1) * T.mulp(origin)
origin = T.rotation() * origin
chunk.transform.matrix = Metashape.Matrix().Translation(origin) * Metashape.Matrix().Rotation(T.rotation())


print("Script finished")
print(chunk.transform.matrix.mulp(origin))
return 1


chunk = Metashape.app.document.chunk
move_origin(chunk)

The script assumes that the chunk is not georeferenced and on run the local coordinate system origin is moved to the point that is in between of the two selected markers.
Best regards,
Alexey Pasumansky,
Agisoft LLC

stijntje44@hotmail.com

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How do I center my scene on 0,0,0?
« Reply #4 on: May 16, 2019, 12:21:50 PM »
Hi Alexy, thank you for your help.

I eventually managed to shift the position of my scene by subtracting the average location of my markers from the transform matrix.

I also eventually managed to properly orient my scene by calculating the appropriate 3x3 matrix and plugging that into the transform matrix.

However, when I do both, the position is once again wrong and I have no idea why. I've tried doing is sequentially, I've tried getting the old position vector and transforming the coordinates to my new coordinate matrix but not a single combination I can come up with seems to work.

how do you simultaneously adjust the rotation and the translation, and which coordinates are required for the translation? (the coordinates of the 0.0.0 position prior to rotating, the coordinates of the 0.0.0 position AFTER the rotation, or something else?)

Note: if I ONLY input the iM rotation values, the scene is properly oriented. If I ONLY input the locAvg values, the scene is properly positioned. I've tried with locAvg, and with locAvg2 (and also with a locAvg calculated from the regular, non-inversed version of my rotation matrix).


    #Transform locAvg to new matrix coordinates:
    locAvg2 = Metashape.Vector((0, 0, 0))

    locAvg2[0] = locAvg[0] * iM[0, 0] + locAvg[1] * iM[0, 1] + locAvg[2] * iM[0,2]
    locAvg2[1] = locAvg[0] * iM[1, 0] + locAvg[1] * iM[1, 1] + locAvg[2] * iM[1, 2]
    locAvg2[2] = locAvg[0] * iM[2, 0] + locAvg[1] * iM[2, 1] + locAvg[2] * iM[2, 2]

    #Determine adjustment matrix
    chunkAdjust = Metashape.Matrix([[iM[0,0], iM[0,1], iM[0,2], - locAvg[0]],
                                                              [iM[1,0], iM[1,1], iM[1,2], - locAvg[1]],
                                                              [iM[2,0], iM[2,1], iM[2,2], - locAvg[2]],
                                                              [0.0, 0.0, 0.0, 1.0]])

    chunk.transform.matrix = chunkAdjust

    #Other ways to apply new matrix
    #chunk.transform.matrix = Metashape.Matrix().Translation(locAvg) * chunkAdjust
    #chunk.transform.matrix = Metashape.Matrix().Translation(locAvg) * Metashape.Matrix().Rotation(chunkAdjust.rotation())

    chunk.updateTransform()



« Last Edit: May 16, 2019, 12:24:49 PM by stijntje44@hotmail.com »