Fish - FiberLib for VISH 0.3
Fish - The Fiber Bundle API for the Vish Visualization Shell
Classes | Macros | Functions | Variables
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)
{
bool success;
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;
}
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
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.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
std::string to_string(const span< char > &s)
STL namespace.
Definition 021_CreateMultiBundlesAndSave.cpp:35