巨大的点数组到可读文件

时间:2022-04-01 12:41:21

I have to huge array of 2D-points and some small associated data to file. File will be used by third person and user would like to use this file as input to his program. So user needs to parse file's contents in his program.

我需要大量的2D点和一些小的相关数据来存档。文件将由第三人使用,用户希望将此文件用作其程序的输入。因此用户需要在他的程序中解析文件的内容。

I'd like to use file format that is kind of readable and self-documenting like XML. But using XML for this will make the file at least 3 times larger.

我想使用像XML一样可读和自我文档化的文件格式。但是使用XML会使文件至少大3倍。

So is there a common way to write such data so that users could easily understand it?

那么有没有一种常用的方法来编写这样的数据,以便用户可以轻松地理解它?

Note that there is a couple of entries of additional data that are more complex than 2D-points.

请注意,有两个附加数据条目比2D点更复杂。

Any suggestions will be appreciated.

任何建议将不胜感激。

EDIT: The question is not how to parse file but how to write file so that it could be parsed intuitively.

编辑:问题不是如何解析文件,而是如何编写文件,以便可以直观地解析它。

EDIT 2: To be more specific: I'm writing simple emulator of 3D-scene with N points and N cameras, so for each time moment I need to store 2D-projection of each point for each camera. Of course, camera position and orientation need to be stored in the same file.

编辑2:更具体一点:我正在编写具有N点和N个摄像头的3D场景的简单模拟器,因此每次我需要为每个摄像机存储每个点的2D投影。当然,摄像机的位置和方向需要存储在同一个文件中。

1 个解决方案

#1


1  

You can read line by line and use a regex to check whether there is a 2D coordinate or other kind of information on that line, and use it in your program.

您可以逐行阅读并使用正则表达式检查该行上是否存在2D坐标或其他类型的信息,并在程序中使用它。


EDIT:

编辑:

I would suggest an input file like the following:

我建议输入文件如下:

2
c 1
p (x,y)
o 180
8
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
c 2
p (x,y)
o 270
2
(x,y)
(x,y)

Where:

哪里:

  • The first number is the number of camera's
  • 第一个数字是相机的数量
  • For each camera there is:
    • The camera id
    • 相机ID
    • The coordinates of the camera
    • 相机的坐标
    • The number of points for that camera
    • 该相机的点数
    • The coordinates
    • 该坐标
  • 对于每个摄像机,有:摄像机ID摄像机的坐标摄像机的点数坐标

It should be easy to read this, because you define the number of points per camera. With StringTokenizer (in Java at least), you can easily split the strings, to get the data you want.

它应该很容易理解,因为你定义了每个摄像机的点数。使用StringTokenizer(至少在Java中),您可以轻松地拆分字符串,以获取所需的数据。

#1


1  

You can read line by line and use a regex to check whether there is a 2D coordinate or other kind of information on that line, and use it in your program.

您可以逐行阅读并使用正则表达式检查该行上是否存在2D坐标或其他类型的信息,并在程序中使用它。


EDIT:

编辑:

I would suggest an input file like the following:

我建议输入文件如下:

2
c 1
p (x,y)
o 180
8
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
(x,y)
c 2
p (x,y)
o 270
2
(x,y)
(x,y)

Where:

哪里:

  • The first number is the number of camera's
  • 第一个数字是相机的数量
  • For each camera there is:
    • The camera id
    • 相机ID
    • The coordinates of the camera
    • 相机的坐标
    • The number of points for that camera
    • 该相机的点数
    • The coordinates
    • 该坐标
  • 对于每个摄像机,有:摄像机ID摄像机的坐标摄像机的点数坐标

It should be easy to read this, because you define the number of points per camera. With StringTokenizer (in Java at least), you can easily split the strings, to get the data you want.

它应该很容易理解,因为你定义了每个摄像机的点数。使用StringTokenizer(至少在Java中),您可以轻松地拆分字符串,以获取所需的数据。