Fish - FiberLib for VISH 0.3
Fish - The Fiber Bundle API for the Vish Visualization Shell
Typedefs | Functions
033-CellTensor.cpp File Reference

[← Previous Example] [Next Example → 040-FragmentedBinding.cpp ]. More...

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <fiber/field/UniformCartesianArray.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <eagle/ColorSpace.hpp>
#include <fiber/fiberop/Range.hpp>
#include <fiber/baseop/ExpandBBox.hpp>
#include <random>

Typedefs

using rgb16 = Eagle::rgb16_t
 

Functions

void makeUniformPointCloudFragment (RefPtr< Field > &Positions, const Eagle::BoundingBox &BBox, const MultiIndex< 3 > FragmentDims, const string &FragmentName, int PartialFactor)
 The CellTensor and its simpler version, the CellSize.
 
void CreateEquidistantPointCloud (BundlePtr &BP)
 Create a coordinate field with equidistantly distributed points to demonstrate functionality of the CellSize parameter.
 
void makeRandomPointCloudFragment (RefPtr< Field > &Positions, const Eagle::BoundingBox &BBox, const MultiIndex< 3 > FragmentDims, const string &FragmentName)
 
void CreateRandomPointCloud (BundlePtr &BP)
 
void makeRegularPointCloudFragment (RefPtr< Field > &Positions, const Eagle::BoundingBox &BBox, const MultiIndex< 3 > FragmentDims, const string &FragmentName)
 
void CreateRegularPointCloud (BundlePtr &BP)
 
int main ()
 

Detailed Description

[← Previous Example] [Next Example → 040-FragmentedBinding.cpp ].

In FiberLib Tutorial

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <fiber/field/UniformCartesianArray.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <eagle/ColorSpace.hpp>
#include <fiber/fiberop/Range.hpp>
#include <fiber/baseop/ExpandBBox.hpp>
#include <random>
using namespace Fiber;
using namespace Eagle::PhysicalSpace;
/**@brief The CellTensor and its simpler version, the CellSize.
Demonstrate creating point clouds with a variety of distributions
and the corresponding cell size or cell tensor.
The simple cell size as scalar value only works for equidistant
distributions. The cell tensor generalizes to also non-equidistant
distributions.
*/
const Eagle::BoundingBox&BBox,
const string &FragmentName,
)
{
//
// Creates a MemArray with a file-write creator, defining
// the type of the creator at this state.
//
auto CellVector = Distribution->cell_diagonal();
auto CellSize = CellVector[0];
index_t idx = 0;
for(auto I : FragmentDims)
{
idx = I.linear(FragmentDims);
point&P = Coordinates[ idx ];
P.x() = BBox.min()[0] + I[0] * CellVector[0];
P.y() = BBox.min()[1] + I[1] * CellVector[1];
P.z() = BBox.min()[2] + I[2] * CellVector[2];
if (++idx >= PointsPerFragment)
break;
}
auto myFragmentCreator = Positions->createCreator(Coordinates, FragmentName);
setCreatorRange( *myFragmentCreator, BBox.min(), BBox.max() );
(*myFragmentCreator) << "CellSize" << CellSize;
}
/**
Create a coordinate field with equidistantly distributed points
to demonstrate functionality of the CellSize parameter
AI test: post this function body into the AI of your choice and ask it why the last two fragments fail.
*/
{
RefPtr<Field>&Positions = BP[0.0]["EquidistantPointCloud"].makeCartesianRepresentation(3)[ FIBER_POSITIONS ];
/*
The next two fragments demonstrate square fragments which are halfway
filled with equidistantly distributed points. The uniform cell size parameter works.
*/
{
string FragmentName = "UniformSquarePartial-Coarse";
const MultiIndex<3> FragmentDims = MIndex(16,16,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, 0.0, 0.0}, point{0.0-1/16.0, 1.0, 0.0} };
makeUniformPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName, 2);
}
{
string FragmentName = "UniformSquarePartial-Fine";
const MultiIndex<3> FragmentDims = MIndex(32,32,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, 0.0, 0.0}, point{1.0, 1.0, 0.0} };
makeUniformPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName, 2);
}
/*
The next two fragments demonstrate rectangular fragments which are fully
filled with equidistantly distributed points. The uniform cell size parameter works.
*/
{
string FragmentName = "UniformRectangular-Coarse";
const MultiIndex<3> FragmentDims = MIndex(16, 8,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, -0.5, 0.0}, point{0.0-1./16, -0.0-1./16, 0.0} };
makeUniformPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName, 1);
}
{
string FragmentName = "UniformRectangular-Fine";
const MultiIndex<3> FragmentDims = MIndex(32,16,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, -0.5, 0.0}, point{1.0, -0.0-1./16, 0.0} };
makeUniformPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName, 1);
}
/*
The next two fragments demonstrate rectangular fragments which are fully
filled with non-uniformely distributed points.
The uniform cell size parameter does NOT work in this case.
*/
{
string FragmentName = "NotWorking:UniformCoarse";
const MultiIndex<3> FragmentDims = MIndex(16,16,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, -1.0, 0.0}, point{0.0-1/16.0, -0.5-1./16, 0.0} };
makeUniformPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName, 1);
}
{
string FragmentName = "NotWorking:UniformFine";
const MultiIndex<3> FragmentDims = MIndex(32,32,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, -1.0, 0.0}, point{1.0, -0.5-1./32, 0.0} };
makeUniformPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName, 1);
}
}
static double random_double(double min, double max)
{
static thread_local std::mt19937_64 rng(std::random_device{}());
return dist(rng);
}
void makeRandomPointCloudFragment(RefPtr<Field>&Positions,
const Eagle::BoundingBox&BBox,
const string &FragmentName)
{
//
// Creates a MemArray with a file-write creator, defining
// the type of the creator at this state.
//
auto CellVector = Distribution->cell_diagonal();
auto CellSize = CellVector[0];
for(auto I : FragmentDims)
{
index_t idx = I.linear(FragmentDims);
point&P = Coordinates[ idx ];
for(int i=0; i<3; i++)
P[i] = random_double(BBox.min()[i], BBox.max()[i] );
}
auto myFragmentCreator = Positions->createCreator(Coordinates, FragmentName);
setCreatorRange( *myFragmentCreator, BBox.min(), BBox.max() );
(*myFragmentCreator) << "CellSize" << CellSize;
}
void CreateRandomPointCloud(BundlePtr&BP)
{
RefPtr<Field>&Positions = BP[0.0]["RandomPointCloud"].makeCartesianRepresentation(3)[ FIBER_POSITIONS ];
/*
The next two fragments demonstrate square fragments which are halfway
filled with equidistantly distributed points. The uniform cell size parameter works.
*/
{
string FragmentName = "UniformSquarePartial-Coarse";
const MultiIndex<3> FragmentDims = MIndex(16,16,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, 0.0, 0.0}, point{0.0, 1.0, 0.0} };
makeRandomPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
{
string FragmentName = "UniformSquarePartial-Fine";
const MultiIndex<3> FragmentDims = MIndex(32,32,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, 0.0, 0.0}, point{1.0, 1.0, 0.0} };
makeRandomPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
/*
The next two fragments demonstrate rectangular fragments which are fully
filled with equidistantly distributed points. The uniform cell size parameter works.
*/
{
string FragmentName = "UniformRectangular-Coarse";
const MultiIndex<3> FragmentDims = MIndex(16, 8,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, -0.5, 0.0}, point{0.0, -0.0, 0.0} };
makeRandomPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
{
string FragmentName = "UniformRectangular-Fine";
const MultiIndex<3> FragmentDims = MIndex(32,16,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, -0.5, 0.0}, point{1.0, -0.0, 0.0} };
makeRandomPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
}
void makeRegularPointCloudFragment(RefPtr<Field>&Positions,
const Eagle::BoundingBox&BBox,
const string &FragmentName)
{
//
// Creates a MemArray with a file-write creator, defining
// the type of the creator at this state.
//
auto CellVector = Distribution->cell_diagonal();
for(auto I : FragmentDims)
{
index_t idx = I.linear(FragmentDims);
point&P = Coordinates[ idx ];
P.x() = BBox.min()[0] + I[0] * CellVector[0];
P.y() = BBox.min()[1] + I[1] * CellVector[1];
P.z() = BBox.min()[2] + I[2] * CellVector[2];
}
auto myFragmentCreator = Positions->createCreator(Coordinates, FragmentName);
setCreatorRange( *myFragmentCreator, BBox.min(), BBox.max() );
Eagle::metric33 CellTensor = {};
CellTensor(0,0) = 1./( CellVector[0]*CellVector[0] );
CellTensor(1,1) = 1./( CellVector[1]*CellVector[1] );
CellTensor(2,2) = 1./( CellVector[2]*CellVector[2] );
(*myFragmentCreator) << "CellTensor" << CellTensor;
}
void CreateRegularPointCloud(BundlePtr&BP)
{
RefPtr<Field>&Positions = BP[0.0]["RegularPointCloud"].makeCartesianRepresentation(3)[ FIBER_POSITIONS ];
/*
The next two fragments demonstrate square fragments which are halfway
filled with equidistantly distributed points. The uniform cell size parameter works.
*/
{
string FragmentName = "UniformSquarePartial-Coarse";
const MultiIndex<3> FragmentDims = MIndex(16,16,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, 0.0, 0.0}, point{0.0-1/16.0, 1.0, 0.0} };
makeRegularPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
{
string FragmentName = "UniformSquarePartial-Fine";
const MultiIndex<3> FragmentDims = MIndex(32,32,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, 0.0, 0.0}, point{1.0, 1.0, 0.0} };
makeRegularPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
/*
The next two fragments demonstrate rectangular fragments which are fully
filled with equidistantly distributed points. The uniform cell size parameter works.
*/
{
string FragmentName = "UniformRectangular-Coarse";
const MultiIndex<3> FragmentDims = MIndex(16, 8,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, -0.5, 0.0}, point{0.0-1./16, -0.0-1./16, 0.0} };
makeRegularPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
{
string FragmentName = "UniformRectangular-Fine";
const MultiIndex<3> FragmentDims = MIndex(32,16,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, -0.5, 0.0}, point{1.0, -0.0-1./16, 0.0} };
makeRegularPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
{
string FragmentName = "NotWorking:UniformCoarse";
const MultiIndex<3> FragmentDims = MIndex(16,16,1);
Ref<Eagle::BoundingBox> BBox{ point{-1.0, -1.0, 0.0}, point{0.0-1/16.0, -0.5-1./16, 0.0} };
makeRegularPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
{
string FragmentName = "NotWorking:UniformFine";
const MultiIndex<3> FragmentDims = MIndex(32,32,1);
Ref<Eagle::BoundingBox> BBox{ point{0.0, -1.0, 0.0}, point{1.0, -0.5-1./32, 0.0} };
makeRegularPointCloudFragment(Positions, *BBox, FragmentDims, FragmentName);
}
}
int main()
{
// Initialize I/O layers (only required for standalone binaries)
Finit();
//
// Create a bundle object with a grid at T=1.0, named "DemoGrid", in
// a three-dimensional cartesian representation, using the default
// coordinate system.
//
BundlePtr BP = new Bundle();
//
// Save the bundle to a file, even future data
// that are added to the bundle later. This feature
// is called "binding" a file to the Bundle.
//
BP->bindToNew("PointCloud.f5");
Verbose(0) << "Bundle Binder: " << BP->getBinder();
Assert(BP->isBound());
CreateRandomPointCloud(BP);
CreateRegularPointCloud(BP);
return 0;
}
void makeUniformPointCloudFragment(RefPtr< Field > &Positions, const Eagle::BoundingBox &BBox, const MultiIndex< 3 > FragmentDims, const string &FragmentName, int PartialFactor)
The CellTensor and its simpler version, the CellSize.
Definition 033-CellTensor.cpp:30
void CreateEquidistantPointCloud(BundlePtr &BP)
Create a coordinate field with equidistantly distributed points to demonstrate functionality of the C...
Definition 033-CellTensor.cpp:77
_Tp min() const
_Tp max() const
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
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
DomainVector< Vector< color16_t, 3 >, RGB > rgb16_t
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2

Function Documentation

◆ CreateEquidistantPointCloud()

void CreateEquidistantPointCloud ( BundlePtr BP)

Create a coordinate field with equidistantly distributed points to demonstrate functionality of the CellSize parameter.

AI test: post this function body into the AI of your choice and ask it why the last two fragments fail.

References makeUniformPointCloudFragment().

◆ makeUniformPointCloudFragment()

void makeUniformPointCloudFragment ( RefPtr< Field > &  Positions,
const Eagle::BoundingBox BBox,
const MultiIndex< 3 >  FragmentDims,
const string &  FragmentName,
int  PartialFactor 
)

The CellTensor and its simpler version, the CellSize.

Demonstrate creating point clouds with a variety of distributions and the corresponding cell size or cell tensor. The simple cell size as scalar value only works for equidistant distributions. The cell tensor generalizes to also non-equidistant distributions.

References Eagle::PhysicalSpace::AABB::max(), and Eagle::PhysicalSpace::AABB::min().

Referenced by CreateEquidistantPointCloud().