Microflow 3D  v1.0
VDBWriter.h
Go to the documentation of this file.
1 // ==============================================================================================
2 // Microflow 3D, http://www.microflow.pwr.edu.pl/
3 // Created by Roman Szafran on 26.03.19.
4 // Copyright (c) 2019 Wroclaw University of Science and Technology.
5 // Distributed under the Apache License, Version 2.0. You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0 or see accompanying file license.txt.
7 // Redistributions of source code must retain the above copyright and license notice.
8 // ==============================================================================================
9 
10 #pragma once
11 
12 #include <iostream>
13 #include <openvdb/openvdb.h>
14 
15 namespace MF {
16  namespace RW {
17 
20  template <class T_VDBGridType> // T_VDBGridType = <openvdb::FloatGrid::Ptr>, <openvdb::Int32Grid::Ptr>, <openvdb::DoubleGrid::Ptr> etc.
21  class VDBWriter {
22  public:
23  VDBWriter(const std::shared_ptr<T_VDBGridType>& Grid_Ptr, const std::string &FileName) {
24  std::string FileNameExt = FileName + ".vdb";
25  // Writing the openvdb grid to a file.
26  // Create a VDB file object.
27  openvdb::io::File file(FileNameExt);
28  // Add the grid pointer to a container.
29  openvdb::GridPtrVec grids;
30  grids.push_back(Grid_Ptr);
31  // Write out the contents of the container.
32  file.write(grids);
33  file.close();
34  std::cout << "Grid was saved successfully in VDB file: ----> " << FileNameExt << std::endl;
35  };
36 
37  ~VDBWriter() = default;
38 
39  // T_VDBGridType = <openvdb::FloatGrid::Ptr>, <openvdb::Int32Grid::Ptr>, <openvdb::DoubleGrid::Ptr> etc.
40  static std::shared_ptr<MF::RW::VDBWriter<T_VDBGridType>> New(const std::shared_ptr<T_VDBGridType>& Grid_Ptr, const std::string &FileName) {
41  auto VDBWriter_Ptr = std::make_shared<MF::RW::VDBWriter<T_VDBGridType>>(Grid_Ptr, FileName);
42  return VDBWriter_Ptr;
43  };
44  };
45  } /* namespace RW */
46 } /* namespase MF */
~VDBWriter()=default
VDBWriter(const std::shared_ptr< T_VDBGridType > &Grid_Ptr, const std::string &FileName)
Definition: VDBWriter.h:23
static std::shared_ptr< MF::RW::VDBWriter< T_VDBGridType > > New(const std::shared_ptr< T_VDBGridType > &Grid_Ptr, const std::string &FileName)
Definition: VDBWriter.h:40
The VDBWriter class provides a write interface for OpenVDB grid.
Definition: VDBWriter.h:21