开发者

What data format can be written from Java (Clojure) and read by Paraview?

开发者 https://www.devze.com 2023-03-30 16:58 出处:网络
I have some Clojure code that generates a regular 3D grid of data (voxels).I want to write this to a file that can be later read by Paraview (and, possibly, other analysis/visualisation programs).What

I have some Clojure code that generates a regular 3D grid of data (voxels). I want to write this to a file that can be later read by Paraview (and, possibly, other analysis/visualisation programs). What is the simplest way to do this? My main priority is simplicity, but I would also like this to also scale well, so that I can use it for large datasets. I do not need to handle anything more compl开发者_Go百科ex than a regular grid.


Paraview has a "raw" input format, which is simply a sequence of binary values, with X varying fastest, Z slowest. The following Clojure code will write a sequence of doubles in this format:

(defn write-doubles [voxels path]
  "write raw data stream - for paraview x must vary fastest."
  (let [out (java.io.DataOutputStream.
              (java.io.BufferedOutputStream.
                (java.io.FileOutputStream. path)))]
    (dorun (map (fn [v] (.writeDouble out v)) voxels))
    (.close out)))

You can then read this into Paraview by selecting the file (use a .raw extension) and entering the metadata (origin, step, range) for the axes. It's not a great solution - it would be better to have the metadata in the file too - but it's very simple. And it works.

[Note - DataOutputStream generates data in big-endian format]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号