Search code examples
meshlabpymeshlab

Determing accurate direction and distance of models in meshlab


I am working on a project where I need to evaluate models in various viewing directions and distances (zoom in/out) using MeshLab. I would greatly appreciate any assistance on how to determine the distance and direction of the model accurately.

If there are any transformation matrices for direction and distance of the model, please let me know how to find them in meshlab.


Solution

  • There is two transformation matrix that affect each model

    • The model matrix, which is one tranformation (rotation, translation, scale) per each mesh loaded in meshlab. It is initialised to the Identity Matrix every time you import a mesh in meshlab. You can set/read this matrix using the filter Matrix: Set/Copy Transformation or change it with any of the transformation filter.

    • The view matrix or camera matrix, which is the transformation applied to the camera, so it has effect on every modeld loaded in meshlab. This is the one you change when you drag the mouse on the screen. It gives the impression of being rotating the mesh in the screen, but in reality it is moving the camera in an orbit around the meshes loaded in the screen.

    I will assume that you are interested in the view matrix because you are refering to distances and zoom values, which is data related to the camera.

    The view matrix is changed every time we import a new mesh into our project, because meshlab move the camera to ensure every model in the project is visible in the screen. Of course, it is changed again when you click and drag the mouse in the render area.

    You can get the view matrix and every other configuration of the camera using the Menu Windows->Copy Camera Setting to Clipboard

    enter image description here

    The information of the camera will be written as a XML string to the clipboard. You can paste this screen into notepad or other text editor. The XML string has always this format

    <!DOCTYPE ViewState>
    <project>
     <VCGCamera PixelSizeMm="0.0369161 0.0369161" 
                BinaryData="0" 
                RotationMatrix="0.956861 -0.289892 -0.0194649 0 
                                0.0539982 0.111607  0.992284 0 
                               -0.285483 -0.950529  0.122446 0 
                                0 0 0 1 " 
                CameraType="1"
                CenterPx="408 345"
                TranslationVector="105.628 356.217 -59.6948 1"
                FocalMm="292.12616"
                ViewportPx="816 691"
                LensDistortion="0 0"/>
     <ViewSettings NearPlane="0.80000001" FarPlane="11.905772" TrackScale="0.10642788"/>
    </project>
    

    The information you are interested at can be extracted from this string. For example:

    • The 'distance' can be computed as the module of the camera TranslationVector (suppossing that your model is centered around the origin). If your model is not centered in the origin, just use the Compute geometric measures filter and compute the distance from the camera to your "favorite center". which could be the center of the bounding box, the center of mass, the vertices barycenter or the Thin shell (faces) barycenter.
    • The 'viewing direction' is given by the RotationMatrix matrix. If you want to compute the direction that camera is using, just product RotationMatrix by the vector "0 0 -1 0", or simply get the third column of the matrix and change the sign. In our example, the camera is looking in the direction of vector "0.0194649 -0.992284 0.122446"