Microflow 3D  v1.0
VDBGridOperations.h
Go to the documentation of this file.
1 // ==============================================================================================
2 // Microflow 3D, http://www.microflow.pwr.edu.pl/
3 // Created by Roman Szafran on 03.05.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 
14 #include <openvdb/openvdb.h>
15 #include <openvdb/tools/MeshToVolume.h>
16 #include <openvdb/tools/ChangeBackground.h>
17 #include <openvdb/tools/LevelSetUtil.h>
18 #include <openvdb/tools/Composite.h>
19 
20 #include "STLReader.h"
21 #include "VDBWriter.h"
22 
23 namespace MF {
24  namespace GB {
26  template <typename T>
27  void setGridName(T VDBGridPtr, const std::string &GridName) { VDBGridPtr->setName(GridName); }
28 
30  template <typename T>
31  void insertMetaDataFloat(T VDBGridPtr, const std::string &MetaName, float value) { VDBGridPtr->insertMeta(MetaName, openvdb::FloatMetadata(value));}
32 
34  template <typename T>
35  void insertMetaDataInt(T VDBGridPtr, const std::string &MetaName, int32_t value) { VDBGridPtr->insertMeta(MetaName, openvdb::Int32Metadata(value));}
36 
38  template <typename T>
39  void insertMetaDataDouble(T VDBGridPtr, const std::string &MetaName, double value) {VDBGridPtr->insertMeta(MetaName, openvdb::DoubleMetadata(value)); }
40 
42  template <typename T>
43  void insertMetaDataString(T VDBGridPtr, const std::string &MetaName, const std::string &string) {VDBGridPtr->insertMeta(MetaName, openvdb::StringMetadata(string)); }
44 
46  template <typename T, typename T2>
47  const T2 &getMetaData(T VDBGridPtr, const std::string &MetaName) { return VDBGridPtr->template metaValue<T2>(MetaName); }
48 
50  template <typename T>
51  void setGridToFogVolume(T VDBGridPtr, bool voxelizeActiveTiles = true) {openvdb::tools::sdfToFogVolume(*VDBGridPtr);
52  if (voxelizeActiveTiles) VDBGridPtr->treePtr()->voxelizeActiveTiles();}
53 
55  template <typename T>
56  void setGridBackgroundValue(T VDBGridPtr, float value) { openvdb::tools::changeBackground(VDBGridPtr->tree(), value); }
57 
59  template <typename T>
60  openvdb::FloatGrid::Ptr getGridNewCopy(T VDBGridPtr) { return VDBGridPtr->deepCopy(); }
61 
63  template <typename T>
64  void VDBFileWrite(T VDBGridPtr, const std::string &FileName) {auto w = new MF::RW::VDBWriter<T>(VDBGridPtr, FileName); delete w;}
65 
69  inline void unionOfTwoGrids(const openvdb::FloatGrid::Ptr& gridA, const openvdb::FloatGrid::Ptr& gridB) { openvdb::tools::csgUnion(*gridA, *gridB); }
71  inline void intersectionOfTwoGrids(const openvdb::FloatGrid::Ptr& gridA, const openvdb::FloatGrid::Ptr& gridB) { openvdb::tools::csgIntersection(*gridA, *gridB); }
73  inline void differenceOfTwoGrids(const openvdb::FloatGrid::Ptr& gridA, const openvdb::FloatGrid::Ptr& gridB) { openvdb::tools::csgDifference(*gridA, *gridB); }
74 
75  } /* namespace GB */
76 } /* namespase MF */
77 
78 
void insertMetaDataFloat(T VDBGridPtr, const std::string &MetaName, float value)
Adds float metadata to a VDBGrid.
void insertMetaDataInt(T VDBGridPtr, const std::string &MetaName, int32_t value)
Adds integer metadata to a VDBGrid.
void differenceOfTwoGrids(const openvdb::FloatGrid::Ptr &gridA, const openvdb::FloatGrid::Ptr &gridB)
Difference of two VDBGrids.
void insertMetaDataDouble(T VDBGridPtr, const std::string &MetaName, double value)
Adds double metadata to a VDBGrid.
openvdb::FloatGrid::Ptr getGridNewCopy(T VDBGridPtr)
Copies of a VDBGrid.
void unionOfTwoGrids(const openvdb::FloatGrid::Ptr &gridA, const openvdb::FloatGrid::Ptr &gridB)
Union of two VDBGrids.
const T2 & getMetaData(T VDBGridPtr, const std::string &MetaName)
Returns from a VDBGrid the metadata of a MetaName.
void insertMetaDataString(T VDBGridPtr, const std::string &MetaName, const std::string &string)
Adds string metadata to a VDBGrid.
void setGridBackgroundValue(T VDBGridPtr, float value)
Sets the background value of a VDBGrid.
void VDBFileWrite(T VDBGridPtr, const std::string &FileName)
Writes to file a VDBGrid.
void intersectionOfTwoGrids(const openvdb::FloatGrid::Ptr &gridA, const openvdb::FloatGrid::Ptr &gridB)
Intersection of two VDBGrids.
The VDBWriter class provides a write interface for OpenVDB grid.
Definition: VDBWriter.h:21
void setGridToFogVolume(T VDBGridPtr, bool voxelizeActiveTiles=true)
Changes a VDBGrid type to a FogVolume.
void setGridName(T VDBGridPtr, const std::string &GridName)
Adds grid name to a VDBGrid.