fredericjs/surfalize

Support for VMRL 2.0 Files

asuagar opened this issue · 4 comments

Hello,

I am trying to open a VMRL 2.0 file obtained using the Alicona3D software. Below is a sample of the file format. I have attempted to extract the first three columns and save them in an XYZ file. However, Surfalize performs a unique values check, resulting in an error (see the end of this message).

Could you please add support for this file format? If that is not possible, any assistance with the conversion would be greatly appreciated. I can upload an example file if needed.

Best regards,
Andrés

VMRL 2.0 sample

GPoint3DVector { 3819808 n {
-3591.501419 978.121132 -20.305523 0 0 0
-3589.487500 978.123848 -20.727313 0 0 0
-3587.458451 978.130277 -21.725382 0 0 0
-3585.463047 978.128451 -21.441953 0 0 0
-3583.436760 978.134202 -22.334820 0 0 0
-3581.434317 978.134103 -22.319514 0 0 0
...
}

ERROR

File C:\py310\lib\site-packages\surfalize\file\xyz.py:19, in read_xyz(filepath, read_image_layers, encoding)
     17 ny = y.size
     18 if nx * ny != raw_data.shape[0]:
---> 19     raise CorruptedFileError('Number of datapoints does not match expected size.')
     20 step_x = (x.max() - x.min()) / (nx) * 10**6
     21 step_y = (y.max() - y.min()) / (ny) * 10**6

CorruptedFileError: Number of datapoints does not match expected size.

Hi,

could you upload a full sample file of this format?

Hi,

This link contains a full sample and its corresponding image. Unfortunately, I do not have the "a3d" files.

Thanks and regards,
Andrés

Hi Andrés,

sorry for the late reply, I was on vacation. You file format seems very weird to me. Your datapoints do not lie on a regular grid. Why is that? What are we supposed to do with it? Should we interpolate them?
Also, what is the meaning of the 6 columns? I assume the first three are X, Y, Z, but what are the other ones? Is the the normal vector?

This is what I get when I interpolate the points onto a regular grid, is that correct?

grafik

This is the code I wrote to read and interpolate the file:

import numpy as np 
import pandas as pd
from scipy.interpolate import griddata
from surfalize import Surface

path = '1.txt'
with open(path) as file:
    header = file.readline()
    npoints = int(header.split(' ')[2])
df = pd.read_csv(path, delimiter=' ', skiprows=1, header=None, engine='c', nrows=npoints, usecols=[0, 1, 2])
points = df[[0, 1]].values
values = df[2].values
xmin, xmax = points[:,0].min(), points[:,0].max()
ymin, ymax = points[:,1].min(), points[:,1].max()
AR = (xmax - xmin) /  (ymax - ymin)
ny = int(np.sqrt(npoints / AR))
nx = int(ny * AR)
x, step_x = np.linspace(xmin, xmax, nx, retstep=True)
y, step_y = np.linspace(ymin, ymax, ny, retstep=True)
x, y = np.meshgrid(x, y)
data = griddata(points, values, (x, y))
surface = Surface(data, step_x, step_y)

Best
Frederic

Hello Frederic,

First of all, there's no need to apologize for your late reply. I'm grateful for your work.

I don’t have answers to all your questions. I believe the Alicona 3D solution is quite specific. It uses a subset of the VRML format to create a plain text version. There may be other software that can read it for visualization purpose.

I ran your code, and the xticks and yticks are correct. I consider the ticket closed. I could adapt your code to solve my problems.

Thank you very much for your help.