8. 結果の保存

この章では、ParaView で可視化結果を保存するさまざまな方法について説明します。視覚化プロセスを通して生成される結果には、イメージとレンダリング結果、フィルタによって生成されたデータセット、他のレンダリングアプリケーションに読み込むためのシーン表現、およびアニメーションから生成されたムービーが含まれます。

8.1. データセットの保存

You can save the dataset produced by any pipeline module in ParaView, including sources, readers, and filters. To save the dataset in paraview, begin by selecting the pipeline module in the Pipeline Browser to make it the active source. For modules with multiple output ports, select the output port producing the dataset of interest. To save the dataset, use the File > Save Data menu or the pqSave button in the Main Controls toolbar. You can also use the keyboard shortcut CTRL + S (or + S). The Save File dialog (図 8.1) will allow you to select the filename and the file format. The available list of file formats depends on the type of the dataset you are trying to save.

../_images/SaveFileDialog.png

図 8.1 paraviewSave File ダイアログ

使用するファイル名とファイル形式を受け入れると、paraviewConfigure Writer ダイアログボックスを表示できます( 図 8.2 )。このダイアログでは、書き込みプロセスをさらにカスタマイズできます。このダイアログに表示されるプロパティは、選択したファイル形式によって異なり、 Write All Time Steps を使用できるか、出力ファイルに書き込む属性を選択できます。

../_images/ConfigureWriterDialogCSV.png

図 8.2 データセットをcsvファイルとして保存するときに表示される paraviewConfigure Writer ダイアログ

pvpython でも、以下のようにデータセットを保存できます。

# Saving the data using the default properties for
# the used writer, if any.
>>> SaveData("sample.csv", source)

# the second argument is optional, and refers to the pipeline module
# to write the data from. If none is specified the active source is used.

# To pass parameters to configure the writer
>>> SaveData("sample.csv", source,
             Precision=2,
             FieldAssociation='Cells')

pvpython は、paraview と同様に、ファイル拡張子と書き込み対象として選択されたデータセットタイプに基づいてライターを選択します。確かに、ライターが利用できるオプションを見つけるのは難しいかもしれません。最善の方法は、paraviewPythonトレース 機能を使用して、生成されたサンプルスクリプトをリファレンスとして使用することです( 1.6.2 章)。実行時の問題を回避するには、トレース時にPythonスクリプトで使用するのと同じ種類のデータセットと同じファイルフォーマットを使用してください。

8.2. レンダリングされた結果の保存

結果をレンダリングするビュー(これには、 SpreadSheet View)は、標準イメージ形式(PNG、JPEG、TIFF、BMP、PPM)のいずれかでのイメージ(またはスクリーンショット)の保存をサポートしています。 一部のビューでは、PDF、X3D、VRMLなどの複数のフォーマットでの結果のエクスポートもサポートしています。

8.2.1. スクリーンショットの保存

paraview のビューからレンダリングイメージを保存するには、File > Save Screenshot メニューオプションを使用します。選択すると、ファイルダイアログが表示され、スクリーンショットを保存するファイルパスと形式を選択できます。イメージファイルを選択すると、 Save Screenshot Options ダイアログ (図 8.3) が表示されます。このダイアログボックスでは、どのイメージをどのように保存するかを制御するさまざまなパラメータを選択できます。

../_images/SaveScreenshotOptions.png

図 8.3 paraview に保存するスクリーンショットをカスタマイズするために使用する Save Screenshot Options ダイアログ

If your visualization setup only has one view the active tab, then you'll be presented with options shown in (図 8.3). The available options are as follows.

  • Image Resolution : ターゲットイメージの解像度をピクセル単位で指定します。デフォルトでは、現在のビュー寸法に設定されています。必要に応じて変更できます。解像度が現在の解像度より大きい場合、ParaViewは、タイル表示( tiling )を使用して、複数のステージでイメージ全体をレンダリングします。信頼できる結果を得るには、現在の縦横比を表示します。Tools > Lock View Size Custom を使用すると、ビューサイズを適切なアスペクト比にロックできます。

  • Font Scaling : 現在の解像度よりも大きな解像度が指定された場合、フォントの拡大/縮小方法を制御できます。Default Scale fonts proportionally は、アスペクト比が維持される限り、WYSIWYGを達成しようとします。これは、画面より高いDPI(またはPPI)表示を目的とした画像の保存に適しています。 Do not scale fonts を使用すると、フォントの拡大縮小を回避し、ピクセル単位のサイズを現在画面に表示されているサイズと同じに保つことができます。これは、同じピクセル解像度の大きなディスプレイを対象としたイメージを保存する場合に適しています。

  • Override Color Palette : このドロップダウンを使用して、スクリーンショットを保存するためだけにカラーパレットを変更することもできます。

  • Stereo Mode : このオプションでは、サポートされているステレオモードのいずれかを使用してイメージを保存できます。

  • Transparent Background : ファイル形式がサポートしている場合は、このオプションをチェックして、現在の背景色ではなく透明な背景色でイメージを保存できます。

  • Format : ファイル保存ダイアログで選択したファイル形式を表示します。

圧縮レベルなどのオプションが異なるフォーマットの場合、フォーマット固有のオプションが Save Screenshot Options ダイアログに表示されます。PNG形式には、0(圧縮なし)から9(最大圧縮)の範囲の Compression Level オプションがあります。JPEG形式のオプションは、0から100の範囲の Quality と、プログレッシブJPEGとしてファイルを保存できる Progressive です。TIFFファイル形式には、 NonePackBits 、および Deflate の値を指定できる Compression オプションがあります。BMPファイル形式にはオプションはありません。

アクティブなタブに複数のビューがある場合、図 8.4 に示すように、Save Screenshot Options ダイアログにはさらにいくつかのオプションがあります。

../_images/SaveScreenshotOptionsMultiView.png

図 8.4 アクティブなタブに複数のビューがある場合に、Save Screenshot Options ダイアログの追加オプションが使用できます。

  • Save All Views : これをチェックすると、アクティブなタブのすべてのビューがUIとまったく同じレイアウトで保存されます。チェックしないと、アクティブビューのみが保存されます。

  • Separator Options : 生成されたイメージのビュー間に描画されるセパレータを制御します。 Separator Width は、 Separator Color と同様にピクセル単位で指定できます。

スクリーンショットを pvpython に保存するには、SaveScreenshot を使います。

# Save a screenshot from a specific view.
>>> myview = GetActiveView()
>>> SaveScreenshot("aview.png", myview)

# Save all views in a tab
>>> layout = GetLayout()
>>> SaveScreenshot("allviews.png", layout)

# To save a specific target resolution, rather than using the
# the current view (or layout) size, and override the color palette.
>>> SaveScreenshot("aviewResolution.png", myview,
        ImageResolution=[1500, 1500],
        OverrideColorPalette="Black Background")

いつものように、paraviewPythonトレース を使用して、特定のスクリーンショットイメージの保存に使用するメソッドの正確な形式をトレースできます。

8.2.2. シーンのエクスポート

When available, you can export a visualization in a view in several of the supported formats using the File > Export Scene... menu option in paraview. For a Render View (or similar), the available formats include Cinema Database, EPS, PDF, PS, SVG, POV, VRML, WebGL, X3D, and X3DB. On selecting a file as which to export, paraview may pop up an Export Options dialog that allows you to set up parameters for the exporter, similar to saving datasets ( 8.1 章).

また、pvpython からエクスポートする場合は、次のような形式になります(繰り返しますが、Pythonトレース を使って正しい形式を見つけるのが一番簡単です)。

>>> myview = GetActiveView()
>>> ExportView('/tmp/sample.svg', view=myview,
               Plottitle='ParaView GL2PS Export',
               Compressoutputfile=1)
# the arguments after 'view' depend on the exporter selected.

8.3. アニメーションの保存

../_images/SaveAnimationOptions.png

図 8.5 アニメーションの保存をカスタマイズするために使用する、paraviewSave Animation Options ダイアログ

To save an animation as a series of images or a video file, you use the File > Save Animation menu option. This raises a file save dialog where you choose where to save the file and which format to use. The available file formats include AVI (on Windows and Linux), MP4 (on Windows only), and Ogg video formats, as well as image formats such PNG, JPEG, and TIFF. If saving an animation as image frames, ParaView will generate a series of image files sequentially numbered using the frame number as a suffix to the specified filename.

After selecting the file and format, the Save Animation Options dialog (図 8.5) is displayed. This dialog is nearly a clone of the Save Screenshot Options dialog (図 8.3), including, optionally, the extra multiview options from 図 8.4, with additional format-specific compression options and a few animation-specific parameters. These are as follows:

  • Frame Rate: When saving the animation as a video file (AVI or Ogg) rather than a series of images, this lets you specify the frame rate for the generated video. It has no effect when saving as a series of images.

  • Frame Stride: Defines how many timesteps to jump forward after recording a screenshot of the current timestep.

  • Frame Window: If you didn't want to save out the full animation, instead limit to a specific window, you can use this to specify the range of frames to save. If you are generating a animation from a temporal dataset with timesteps, the frame generally corresponds to the timestep number.

アニメーションを pvpython に保存するには、SaveAnimation を使います。この関数の引数は SaveScreenshot と同じですが、アニメーション固有のオプションのパラメータが追加されています。

>>> SaveAnimation('animation.avi', GetActiveView(),
      FrameWindow = [1, 100],
      FrameRate = 1)

8.4. 状態の保存

表示設定によって生成された結果を保存するだけでなく、すべてのパイプラインモジュール、ビュー、レイアウト、およびそれらのプロパティを含む表示パイプライン自体の状態を保存できます。これは、Application State または単に state と呼ばれます。paraview では、File > Save State... メニューオプションを使用して状態を保存できます。逆に、保存した状態ファイルをロードするには、File > Load State... を使用します。

paraview に保存できる状態ファイルには、ParaView state file (*.pvsm)Python state file (*.py) の2種類があります。PVSMファイルは、XMLベースのテキストファイルで、人間が判読して機械で読み取ることができますが、初心者にとっては必ずしも人間に優しいとは限りません。ただし、状態ファイルを読んで意味を理解する予定がない場合は、PVSMがアプリケーション状態を保存する最も堅牢で信頼性の高い方法です。状態を保存してから手動で変更したい場合は、Pythonトレースを使用するとUIでPythonスクリプトとして実行するアクションをトレースできるため、Python状態ファイルを使用する方がよいでしょう。一方、Pythonの状態ファイルでは、アプリケーションの現在の状態全体がPythonスクリプトとして保存され、paraview または Python Shell で使用できます。

../_images/SaveStateDialog.png

図 8.6 paraviewSave State File ダイアログ

Stateファイルをロードするには、File > Load State... メニューを使用します。 Stateファイルをロードすると、現在の表示状態に影響することに注意してください。

../_images/LoadStateOptions.png

図 8.7 データファイルの検索オプションを表示する、paraviewLoad State Options ダイアログ

この方法でPVSMファイルをロードすると、データファイルを検索する場所を尋ねられます。使用可能なオプションは、 Use File Names From StateSearch files under specified directoryChoose File Names の3つです。 Use File Names From State を選択すると、ParaView は状態ファイルに保存されている絶対パスでデータを検索します。 Search files under specified directory を選択すると、ParaViewが状態ファイル内の絶対パスでファイルを検索する前にファイルを検索するディレクトリを参照するオプションが表示されます。デフォルトでは、コンピュータ間で状態ファイルを簡単に共有できるように、状態ファイルの場所が設定されます。 Choose File Names を選択すると、状態ファイル内のファイル名のリストが表示され、それぞれを個別にオーバーライドできます。

../_images/LoadStateOptionsDataDirectory.png

図 8.8 Search files under specified directory オプションを示す、paraviewLoad State Options ダイアログ

PVSM状態ファイルは、次のように pvpython に保存/ロードできます。

>>> from paraview.simple import *

# Save the PVSM state file. Currently, this doesn't support
# saving Python state files.
>>> SaveState("sample.pvsm")

# To load a PVSM state file.
>>> LoadState("sample.pvsm")

stateで使用されるすべてのデータファイルを特定のディレクトリのデータファイルに置換するには、次の形式を使用します。

>>> LoadState("sample.pvsm",
              data_directory="[directory path]",

              # optionally, restrict to specified directory
              restrict_to_data_directory=True)

状態ファイルで使用されているファイル名を明示的にオーバーライドする場合、関数シグネチャは少し複雑になります。Pythonトレース機能を使用して、特定の状態ファイルの関数呼び出しを生成する方が簡単な場合があります。次の形式になります。

>>> LoadState("sample.pvsm",
              filenames = [

                # a `dict` object for each reader in statefile to update.
                {
                  "name": "[reader name as shown in the pipeline browser]",

                  # if multiple readers have the same name, 'id' may be used
                  # instead of 'name' where the value is "id" used in the
                  # state file for this reader.

                  # filename properties and their overridden values for this
                  # reader, for example:
                  "FileName" : "foo.vtk",
                },

                # multiple such `dict`s can be specified.
              ])

# here's an example
>>> LoadState(statefile,
              filenames=[
                  {
                      'name' : 'can.ex2',
                      'FileName' : data_dir + 'can.ex2',
                  },
                  {
                      'name' : 'dataset',
                      'FileName' : data_dir + 'disk_out_ref.ex2',
                  },
                  {
                      'name' : 'timeseries',
                      'FileName' : [ data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0000.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0001.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0002.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0003.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0004.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0005.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0006.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0007.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0008.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0009.vtp',
                                     data_dir + 'dualSphereAnimation/dualSphereAnimation_P00T0010.vtp']
                  },
              ])

Did you know? :class: tip

Not all user interface settings are saved in ParaView state files. For example, the Show Plane and Show Outline and Intersection Edges settings in the Plane widget in the Slice and Clip filters are not saved because they are temporary interface state, not part of the data pipeline or display properties. end{didyouknow}

8.5. Extractors

8.1 章 and 8.2 章 are two ways of saving datasets and images using actions, i.e., you click a button (or in Python, invoke a function) and the results are saved out immediately. If, for example, you now want to generate the results for another timestep, you have to repeat all the actions. One way to avoid this is to put together a Python script to generate the data and image files and then use that as a macro. An easier way is to use extractors . Extractors are a type of pipeline module, similar to sources and filters, but behave more like writers. Similar to filters, they have inputs. Unlike sources or filters, however, they produce no output that can be consumed by another pipeline module. Instead, when activated, they generate files -- which we call extracts.

これらは単なるパイプラインモジュールであるため、これらを作成および設定するためのソースおよびフィルタとして同様のメカニズムを使用します。 これらを作成するには、Extractors メニューを使用します。 Pipeline Browser は、可視化に存在するすべてのextractorを表示します。 これらのいずれかを選択するには、Pipeline Browser でクリックします。この時点で、Properties パネルが更新され、選択したextractorでパラメータが表示されます。

extractorには、データ抽出とイメージ抽出の2種類があります。前者はソースおよびフィルタによって生成されたデータセットからファイルを生成し、後者はビューからのレンダリング結果を保存します。データextractorが作成されると、デフォルトではアクティブソースが入力(フィルタに似ています)として使用され、イメージextractorでは代わりにアクティブビューが使用されます。

8.5.1. Extractorプロパティ

../_images/ExtractGeneratorPropertiesPanel.png

図 8.9 Properties of an image extractor for PNG files.

You use the Properties panel view and change extractor properties. The available properties can be grouped into two major groups: first are Trigger properties which are common to all extractors, and the second are the Writer properties which are parameters specific to type of writer the extractor uses.

Trigger properties define when the extractor is activated i.e. under what conditions does the extractor produce extracts. Currently, we support time-based controls. You can select the Start Time Step, End Time Step or the Frequency at which to generate the results. Frequency is the number of timesteps per activation. To write every other timestep, set the Frequency to 2, to write every 3rd timestep, set it to 3, and so on.

Writer properties are specific to the writer. For data extractors, these will be similar to the writer properties shown in the Configure Writer dialog for the writer described in Section 8.1 章. For image extractors, they are similar to the Save Screenshot Options dialog described in Section 8.2.1 章. The Writer properties also lets you set a File Name . This is the file name to use to save the extracts. Since extractors are designed to generate a new extract every time they are activated, the File Name supports patterns that let you make the filename unique per activation. {timestep} or {time} in the filename are replaced by the timestep index and the time value for each activation. You add leading zeros (or other prefixes) to the numbers using a form such as {timestep:06d}. There the timestep will be padded with zeros if the number of digits is less than 6. You should not use absolute paths for specifying the filenames here. We will see how to select prefix to store these extracts under in the next section.

8.5.2. 抽出データの保存

../_images/SaveExtractsOptionsDialog.png

図 8.10 File > Save Extracts... で示される Save Extracts Options ダイアログ

Once the extractors have been setup, you can trigger the saving of extract using File > Save Extracts.... This will pop up the Save Extract Options dialog which lets you configure the extract generation. Extracts Output Directory specifies the root directories under which all extracts are saved. Check Generate Cinema Specification to generate a data.csv file under the chosen extracts output directory that summarizes the generated extracts. This can be then used with viewers provided by the Cinema Science project to explore the generated extracts. Frame Stride and Frame Window control the timesteps for which extracts are generated.

Ok をクリックすると、ParaViewは、 すべてのタイムステップ( VCR Controls )でアニメーションが実行され、トリガ条件に基づいて抽出ジェネレータがアクティブになり、抽出が生成されます。正常に完了すると、選択したルートディレクトリの下にファイルがあるはずです。

../_images/PythonStateOptionsDialog.png

図 8.11 File > Save State を使用してPython状態(state)ファイルを保存するときに表示される Python State Options

In addition to generating extracts using the GUI, you can use pvpython or pvbatch to generate extract offline. Thus is especially handy for HPC use-cases; you can setup your state using an interactive session and once done save out the state and schedule a non-interactive job for the potentially time-consuming extract generation stage. To do so, setup your visualization pipeline including the extractors as normal. Then, instead of using Save Extracts , use File > Save State... and save out a Python state file. The Python State Options dialog has a section similar to Save Extracts Options dialog for choosing Extracts Output Directory and Generate Cinema Specification. Click Ok to save the Python script. The Python script has a section near the end of the end as follows:

if __name__ == '__main__':
    # generate extracts
    SaveExtracts(ExtractsOutputDirectory='extracts')

これにより、pvbatch または pvpython を使用してスクリプトが実行されたときに、Pythonスクリプトが抽出を保存します。