Forum

Author Topic: How to position object on zero point?  (Read 17888 times)

Alexx

  • Newbie
  • *
  • Posts: 17
    • View Profile
How to position object on zero point?
« on: June 26, 2018, 11:52:24 PM »
Hello,

another thing I never solved:
How can I position my object after cropping at the zero point? (including all aligned cameras hopefully)
They are after import in Maya or ZBrush always randomly somewher in space...

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15744
    • View Profile
Re: How to position object on zero point?
« Reply #1 on: June 27, 2018, 05:02:26 PM »
Hello Alexx,

The position of the model in space can be performed using one of the following approaches:
- setting the coordinate system (Professional edition only) by using the coordinate information for cameras and/or markers,
- using Python scripting (also available in Professional edition only) to perform additional transformation to the complete alignment results (including all the chunk contents: cameras, point clouds, mesh, etc.) that would move the model's origin to the user-defined location (for example, to the coordinate system origin),
- using Rotate Object and Move Object tools to modify the model location and orientation in space. If you turn on "show grid" option in the Model menu you'll be able to move the model to the origin of the coordinate system that is in the center of the shown grid. Make sure, however, that the cell units are set to "meters" in the Appearance (Model) tab of PhotoScan Preferences dialog.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Jay

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to position object on zero point?
« Reply #2 on: February 16, 2023, 07:52:30 AM »
Hello Alexx,

The position of the model in space can be performed using one of the following approaches:
- setting the coordinate system (Professional edition only) by using the coordinate information for cameras and/or markers,
- using Python scripting (also available in Professional edition only) to perform additional transformation to the complete alignment results (including all the chunk contents: cameras, point clouds, mesh, etc.) that would move the model's origin to the user-defined location (for example, to the coordinate system origin),
- using Rotate Object and Move Object tools to modify the model location and orientation in space. If you turn on "show grid" option in the Model menu you'll be able to move the model to the origin of the coordinate system that is in the center of the shown grid. Make sure, however, that the cell units are set to "meters" in the Appearance (Model) tab of PhotoScan Preferences dialog.

Hey how to move the model's origin to coordinate system origin via Python?  I was trying to do this after crop the model, but didn't find crs or transform inside Model class

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15744
    • View Profile
Re: How to position object on zero point?
« Reply #3 on: February 16, 2023, 01:03:14 PM »
Hello Jay,

Is the project (chunk) referenced in local or geographic coordinates?

Mesh model doesn't have its own coordinate system, so it is following chunk.crs and chunk.transform. Therefore to move the model's origin you need to modify chunk.transform.matrix, so that its translation component (last column of the matrix) points to the desired origin location.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Jay

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to position object on zero point?
« Reply #4 on: February 21, 2023, 01:11:33 PM »
Hello Jay,

Is the project (chunk) referenced in local or geographic coordinates?

Mesh model doesn't have its own coordinate system, so it is following chunk.crs and chunk.transform. Therefore to move the model's origin you need to modify chunk.transform.matrix, so that its translation component (last column of the matrix) points to the desired origin location.

Oh sorry, I just notice this message.   I got it, but if the model don't have its own coordinate system, is it follow the chunk.crs completely?  Cause i saw there is some distance between center of the model and center of the chunk, is it possible to move center of the model to the center of the chunk?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15744
    • View Profile
Re: How to position object on zero point?
« Reply #5 on: February 21, 2023, 09:53:54 PM »
Hello Jay,

Can you please check, if the following code fits your needs: the center of the model and center of origin are moved to (0,0,0) point. Center of the model is calculated rather roughly, but should be fine for most cases.

Code: [Select]
import Metashape

def model_to_region_center(chunk):
model = chunk.model
if not model:
print("No model in chunk, script aborted")
return 0
vertices = model.vertices
T = chunk.transform.matrix
s = chunk.transform.matrix.scale()
step = int(min(1E4, len(vertices)) / 1E4) + 1

sum = Metashape.Vector([0,0,0])
N = 0
for i in range(0, len(vertices), step):
sum += vertices[i].coord
N += 1
avg = sum / N
chunk.region.center = avg

M = Metashape.Matrix().Diag([s,s,s,1])
origin = (-1) * M.mulp(chunk.region.center)
chunk.transform.matrix = Metashape.Matrix().Translation(origin) * (s * Metashape.Matrix().Rotation(T.rotation()))
return 1

chunk = Metashape.app.document.chunk
model_to_region_center(chunk)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Jay

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to position object on zero point?
« Reply #6 on: February 22, 2023, 06:32:11 AM »
Hello Jay,

Can you please check, if the following code fits your needs: the center of the model and center of origin are moved to (0,0,0) point. Center of the model is calculated rather roughly, but should be fine for most cases.

Code: [Select]
import Metashape

def model_to_region_center(chunk):
model = chunk.model
if not model:
print("No model in chunk, script aborted")
return 0
vertices = model.vertices
T = chunk.transform.matrix
s = chunk.transform.matrix.scale()
step = int(min(1E4, len(vertices)) / 1E4) + 1

sum = Metashape.Vector([0,0,0])
N = 0
for i in range(0, len(vertices), step):
sum += vertices[i].coord
N += 1
avg = sum / N
chunk.region.center = avg

M = Metashape.Matrix().Diag([s,s,s,1])
origin = (-1) * M.mulp(chunk.region.center)
chunk.transform.matrix = Metashape.Matrix().Translation(origin) * (s * Metashape.Matrix().Rotation(T.rotation()))
return 1

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

Hello Alexey,
     Thanks a lot for your help , it works after combine this function and the function i used before.
« Last Edit: February 22, 2023, 06:51:28 AM by Jay »