Fish - FiberLib for VISH 0.3
Fish - The Fiber Bundle API for the Vish Visualization Shell
021_CreateMultiBundlesAndSave.cpp File Reference

[← Previous Example] [Next Example → 022_ComplexMultiBinding.cpp ]. More...

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <fiber/bundle/StorageTransformations.hpp>
#include <random>
#include <filesystem>
#include <chrono>
#include <thread>

Classes

struct  MyStorageTransformations

Macros

#define NumberOfBundles   1
#define array_size   1e3
#define NumberOfFragments   1

Functions

void createData ()
bool myLoad (const string InFile, const string OutFile, const bool IsBindTo)
int main ()

Variables

std::random_device rd
std::mt19937 e2 (rd())
std::uniform_real_distribution dist (50, 100)

Detailed Description

[← Previous Example] [Next Example → 022_ComplexMultiBinding.cpp ].

In FiberLib Tutorial

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <fiber/bundle/StorageTransformations.hpp>
#include <random>
#include <filesystem>
#include <chrono>
#include <thread>
using namespace Fiber;
using namespace std;
using namespace Eagle::PhysicalSpace;
#define NumberOfBundles 1
#define array_size 1e3
#define NumberOfFragments 1
std::mt19937 e2(rd());
namespace fs = std::filesystem;
// ######################################################
// LOAD
//#######################################################
{
};
// ######################################################
// LOAD
//#######################################################
void createData()
{
const uint32_t BPNr = 0;
BundlePtr BP=new Bundle();
Representation&R = BP[0.0]["myGrid"].makeCartesianRepresentation(3);
RefPtr<Field> F = R[FIBER_POSITIONS];
const uint32_t FragNr = 0;
RefPtr<MemArray<1,point> > DataPtr = new MemArray<1,point>( array_size );
for (uint32_t i = 0; i <DataPtr->nElements(); i++)
DataPtr[i] = {dist(e2),dist(e2),dist(e2)} ;
RefPtr<FragmentID> FragID =F->makeFragmentID("Frag" + to_string(FragNr) );
F->setPersistentData(DataPtr,FragID);
BP.save("File" + to_string(BPNr)+ ".f5",nullptr);
}
// ######################################################
// LOAD
//#######################################################
bool myLoad(const string InFile, const string OutFile, const bool IsBindTo)
{
uint32_t BPNr = 0;
bool success;
Ref<LoaderParameters> LP( InFile + to_string(BPNr)+ ".f5" );
BundlePtr BP=new Bundle();
if (IsBindTo) BP->bindToNew(OutFile + to_string(BPNr)+ ".f5");
Bundle::load( success, LP, BP );
if (!success)
{
std::cerr << "Error: CANNOT load file because of "
<< LP->load_failure
<< endl;
return false;
}
if (!IsBindTo) BP->save(OutFile + to_string(BPNr)+ ".f5",nullptr);
return true;
}
// ######################################################
// LOAD
//#######################################################
int main()
{
// Initialize I/O layers
Finit();
createData();
if (!myLoad("File" , "OtherFile" , false))
{
std::cerr << "Error: CANNOT load file!" << endl;
return 42;
}
// myLoad("File" , "OtherFile" , true);
// myLoad("OtherFile", "OtherOtherFile" , false); // without this function call no broken pipe
unlink("File0.f5");
perror("File0.f5");
// std::error_code ec;
// fs::remove("File0.f5", ec); if (ec) std::cerr << "Error: File0.f5 - " << ec.message() << "\n";
// fs::remove("OtherFile0.f5", ec); if (ec) std::cerr << "Error: OtherFile0.f5 - " << ec.message() << "\n";
// fs::remove("OtherOtherFile0.f5", ec); if (ec) std::cerr << "Error: OtherOtherFile0.f5 -" << ec.message() << "\n";
return 0;
}
int main()
Demonstrates minimal usage of the FiberLib Create Bundle, insert a time slice, and safe it to a file.
Definition 010-SimpleSave.cpp:13
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cerr
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
int save(const string &url, const RefPtr< LoaderProgress > &SaveProgress=nullptr, const RefPtrStorageTransformations &ST=nullptr)
Definition Bundle.cpp:1142
The main entity holding all information.
Definition Bundle.hpp:173
static RefPtr< Bundle > load(bool &success, const RefPtr< LoaderParameters > &ld, const RefPtr< Bundle > &B=nullptr)
Load a Bundle object or append new data to an existing Bundle.
Definition Bundle.cpp:139
Class for N-dimensional MultiArrays with MemCore memory management.
Definition MemArray.hpp:34
A Representation is a set of Field objects, each of them accessed via some FieldID identifier.
Definition Representation.hpp:101
Definition StorageTransformations.hpp:18
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
STL namespace.
Definition 021_CreateMultiBundlesAndSave.cpp:35