Class DataManager
Manager where all datasets, key data, and variables live. This class makes the connection between Datasets and RawDatasets. This class is useful for obtaining any KeyData and Variables needed to apply to Data Impressions.
Namespace: IVLab.ABREngine
Assembly: IVLab.ABREngine.Runtime.dll
Syntax
public class DataManager
Examples
When constructing a custom dataset, you can load it directly into the engine and access its imported contents via the KeyData object returned by ImportRawDataset(RawDataset).
public class DataManagerExample : MonoBehaviour
{
void Start()
{
// Generate 100 random points with "data" values
List<Vector3> points = new List<Vector3>();
List<float> dataValues = new List<float>();
for (int i = 0; i < 100; i++)
{
points.Add(Random.insideUnitSphere);
dataValues.Add(i);
}
// Create some bounds
Bounds b = new Bounds(Vector3.zero, Vector3.one);
// Create a dictionary to name the scalar values
Dictionary<string, List<float>> scalarVars = new Dictionary<string, List<float>> {{ "someData", dataValues }};
// Create an ABR-formatted dataset
RawDataset abrPoints = RawDatasetAdapter.PointsToPoints(points, b, scalarVars, null);
// AND, import these data to ABR
KeyData pointsKD = ABREngine.Instance.Data.ImportRawDataset(abrPoints);
// From here, we can access the keyData, scalarVariables, and vectorVariables
Debug.Log(pointsKD); // the key data (point geometry) we just imported
Debug.Log(pointsKD.GetScalarVariables().Length); // length of 1
Debug.Log(pointsKD.GetScalarVariables()[0]); // the 'someData' variable we declared above
Debug.Log(pointsKD.GetVectorVariables().Length); // length of 0 -- we didn't declare any vector vars here.
}
}
Additionally, the actual raw data can be loaded from the data manager. Generally this is not necessary, simply using the high-level variables above in conjunction with Data Impressions is usually sufficient.
RawDataset rds = null;
if (ABREngine.Instance.Data.TryGetRawDataset("Test/Test/KeyData/Example", out rds))
{
float[] var = rds.GetScalarArray("ExampleVar");
}
Constructors
| Improve this Doc View SourceDataManager(string)
Manager where all datasets, key data, and variables live. This class makes the connection between Datasets and RawDatasets. This class is useful for obtaining any KeyData and Variables needed to apply to Data Impressions.
Declaration
public DataManager(string datasetPath)
Parameters
Type | Name | Description |
---|---|---|
string | datasetPath |
Examples
When constructing a custom dataset, you can load it directly into the engine and access its imported contents via the KeyData object returned by ImportRawDataset(RawDataset).
public class DataManagerExample : MonoBehaviour
{
void Start()
{
// Generate 100 random points with "data" values
List<Vector3> points = new List<Vector3>();
List<float> dataValues = new List<float>();
for (int i = 0; i < 100; i++)
{
points.Add(Random.insideUnitSphere);
dataValues.Add(i);
}
// Create some bounds
Bounds b = new Bounds(Vector3.zero, Vector3.one);
// Create a dictionary to name the scalar values
Dictionary<string, List<float>> scalarVars = new Dictionary<string, List<float>> {{ "someData", dataValues }};
// Create an ABR-formatted dataset
RawDataset abrPoints = RawDatasetAdapter.PointsToPoints(points, b, scalarVars, null);
// AND, import these data to ABR
KeyData pointsKD = ABREngine.Instance.Data.ImportRawDataset(abrPoints);
// From here, we can access the keyData, scalarVariables, and vectorVariables
Debug.Log(pointsKD); // the key data (point geometry) we just imported
Debug.Log(pointsKD.GetScalarVariables().Length); // length of 1
Debug.Log(pointsKD.GetScalarVariables()[0]); // the 'someData' variable we declared above
Debug.Log(pointsKD.GetVectorVariables().Length); // length of 0 -- we didn't declare any vector vars here.
}
}
Additionally, the actual raw data can be loaded from the data manager. Generally this is not necessary, simply using the high-level variables above in conjunction with Data Impressions is usually sufficient.
RawDataset rds = null;
if (ABREngine.Instance.Data.TryGetRawDataset("Test/Test/KeyData/Example", out rds))
{
float[] var = rds.GetScalarArray("ExampleVar");
}
Methods
| Improve this Doc View SourceCacheRawDataset(string, RawDataset)
Save a copy of a RawDataset into the media folder.
Declaration
public void CacheRawDataset(string dataPath, RawDataset rds)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | |
RawDataset | rds |
CacheRawDataset(string, in string, in byte[])
Save a copy of the RawDataset described by json
and data
to the
media folder.
Declaration
public void CacheRawDataset(string dataPath, in string json, in byte[] data)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | |
string | json | |
byte[] | data |
GetAllKeyData()
Gets ALL the key data that have been loaded into the ABREngine, regardless of dataset.
Declaration
public List<KeyData> GetAllKeyData()
Returns
Type | Description |
---|---|
List<KeyData> | List of currently loaded KeyData |
GetDatasets()
Retrieve all datasets that are currently loaded into the ABR Engine
Declaration
public List<Dataset> GetDatasets()
Returns
Type | Description |
---|---|
List<Dataset> | List of currently loaded Datasets |
GetKeyData(string)
Gets key data with a particular path
Declaration
public KeyData GetKeyData(string keyDataPath)
Parameters
Type | Name | Description |
---|---|---|
string | keyDataPath |
Returns
Type | Description |
---|---|
KeyData |
ImportRawDataset(RawDataset)
Import a raw dataset into ABR. This method makes the dataset available as a key data object and makes all of its scalar and vector variables available across ABR.
Declaration
public KeyData ImportRawDataset(RawDataset importing)
Parameters
Type | Name | Description |
---|---|---|
RawDataset | importing |
Returns
Type | Description |
---|---|
KeyData | Returns the Key Data and variables that were just imported to this data path. |
ImportRawDataset(string, RawDataset)
Import a raw dataset into ABR. This method makes the dataset available as a key data object and makes all of its scalar and vector variables available across ABR.
Declaration
public KeyData ImportRawDataset(string dataPath, RawDataset importing)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | |
RawDataset | importing |
Returns
Type | Description |
---|---|
KeyData | Returns the Key Data and variables that were just imported to this data path. |
LoadData(string)
Attempt to load the data described in dataPath
from any available
resource, including a Resources folder, the The Media Folder, or a HTTP web resource.
Declaration
public KeyData LoadData(string dataPath)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | Data path to load. If loading from the media directory, you can use the relative path inside that folder (but exclude the .bin/.json extension) |
Returns
Type | Description |
---|---|
KeyData | Returns the KeyData object if the dataset was found, |
LoadRawDataset(string)
Load a raw dataset into a RawDataset object by its data path and return the rawdataset after it has been successfully imported.
Declaration
public RawDataset LoadRawDataset(string dataPath)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | Data path to load. If loading from the media directory, you can use the relative path inside that folder (but exclude the .bin/.json extension) |
Returns
Type | Description |
---|---|
RawDataset | Returns the actual RawDataset if the dataset was found, |
Examples
If you're working with a pre-existing dataset (i.e., one that already exists in ABR raw data format in your media folder), you can use LoadRawDataset(string) to obtain a RawDataset.
// Load from a .bin/.json file pair in the datasets folder in the
// media directory. Most of the time when you're fetching an existing
// dataset, this is what you'll want to do. Just make sure the
// dataset actually exists in the media folder!
// Or, load from a Resources directory in Unity.
// You can also load an ABR raw dataset from a web resource. This requires setting up an ABR data server.
RawDataset ds1 = ABREngine.Instance.Data.LoadRawDataset("Test/Test/KeyData/Example");
|
Improve this Doc
View Source
LoadRawDataset<T>(string)
Load a raw dataset into a RawDataset object by its data path and return the rawdataset after it has been successfully imported.
Declaration
[Obsolete("It is recommended to use `LoadData` or `LoadRawDataset` instead of this method.")]
public RawDataset LoadRawDataset<T>(string dataPath) where T : IDataLoader, new()
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | Data path to load. If loading from the media directory, you can use the relative path inside that folder (but exclude the .bin/.json extension) |
Returns
Type | Description |
---|---|
RawDataset | Returns the actual RawDataset if the dataset was found, |
Type Parameters
Name | Description |
---|---|
T | Any IDataLoader type |
Examples
If you're working with a pre-existing dataset (i.e., one that already exists in ABR raw data format in your media folder), you can use LoadRawDataset(string) to obtain a RawDataset.
// Load from a .bin/.json file pair in the datasets folder in the
// media directory. Most of the time when you're fetching an existing
// dataset, this is what you'll want to do. Just make sure the
// dataset actually exists in the media folder!
RawDataset ds1 = ABREngine.Instance.Data.LoadRawDataset<MediaDataLoader>("Test/Test/KeyData/Example");
// You can also load an ABR raw dataset from a web resource. This requires setting up an ABR data server.
RawDataset ds2 = ABREngine.Instance.Data.LoadRawDataset<HttpDataLoader>("Test/Test/KeyData/Example");
|
Improve this Doc
View Source
TryGetDataset(string, out Dataset)
Attempt to get a lightweight dataset by its data path.
Declaration
public bool TryGetDataset(string dataPath, out Dataset dataset)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | |
Dataset | dataset |
Returns
Type | Description |
---|---|
bool | Returns true if the dataset was found, and populates the |
TryGetRawDataset(string, out RawDataset)
Attempt to get a RawDataset at a particular data path.
Declaration
public bool TryGetRawDataset(string dataPath, out RawDataset dataset)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | |
RawDataset | dataset |
Returns
Type | Description |
---|---|
bool | Returns true if the raw dataset was found, false if not, and
populates the |
UnloadRawDataset(string)
Entirely remove a RawDataset from ABR memory.
Declaration
public void UnloadRawDataset(string dataPath)
Parameters
Type | Name | Description |
---|---|---|
string | dataPath | The data path / key data to be unloaded |
Remarks
This method does not check if the dataset is currently in use, so utilize this method with care!