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

[← Previous Example] [Next Example → 033-CellTensor.cpp ]. More...

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

Typedefs

using rgb16 = Eagle::rgb16_t

Functions

int main ()
 Bind a bundle to a file and add data to it later.

Detailed Description

[← Previous Example] [Next Example → 033-CellTensor.cpp ].

In FiberLib Tutorial

#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <eagle/ColorSpace.hpp>
#include <fiber/fiberop/Range.hpp>
#include <fiber/baseop/ExpandBBox.hpp>
#include <memcore/Timer.hpp>
#include <memcore/Console.hpp>
using namespace Fiber;
using namespace Eagle::PhysicalSpace;
using rgb16 = Eagle::rgb16_t;
/**@brief Bind a bundle to a file and add data to it later.
Demonstrating how to bind a Bundle to a file, then
adding data to it later on. In contrast, when saving
a Bundle to a file then data are added first and saved
in the end. The workflow with the binding feature is
just other way round - bind first, then add data.
The actual dataset is a set of points with a scalar field on them.
*/
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();
unlink("outfile.f5");
Assert(!BP->isBound());
//
// 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->bindTo("outfile.f5");
Verbose(0) << "Bundle Binder: " << BP->getBinder();
Assert(BP->isBound());
Representation&myCartesianRepresentation = BP[1.0]["DemoGrid"].makeCartesianRepresentation(3);
//
// Define the size of the grid to be used hereforth
//
const MultiIndex<3> GridDims = MIndex(210,130,170);
//
// Create a coordinate field and fill it with values
//
RefPtr<Field>&Positions = myCartesianRepresentation[ FIBER_POSITIONS ];
{
//
// Creates a MemArray with a file-write creator, defining
// the type of the creator at this state.
//
ArrayRef<point, 3> Coordinates(GridDims);
for(auto I : GridDims)
{
point&P = Coordinates[ I ];
P.x() = I[0]*0.83;
P.y() = I[1]*0.04*I[1];
P.z() = I[2]*0.01*I[2]*I[1];
}
if (auto CoordinateCreator = Positions->createCreator(Coordinates) )
{
CoordinateCreator->touch();
MemCore::Timer CoordRangeTimer;
RefPtr<BoundingBox> Range = ComputeBBox( Coordinates );
Console() << "Time to compute the bounding box of " << GridDims << " coordinates is " << CoordRangeTimer.secs()*1000.0 << "ms: " << *Range;
#if FIBEROPERATIONS_RANGE_HPP >= 20241206
CoordRangeTimer.restart();
auto Range2 = DataRange<point>::retrieve( *CoordinateCreator );
Console() << "Time to compute the range of " << GridDims << " coordinates is " << CoordRangeTimer.secs()*1000.0 << "ms: " << *Range2;
CoordRangeTimer.restart();
auto Range3 = DataRange<point>::retrieve( *CoordinateCreator );
Console() << "Time to retrieve the range of " << GridDims << " coordinates is " << CoordRangeTimer.secs()*1000.0 << "ms.";
#endif
}
}
//
// Define a scalar field called "values" and set numbers
// to it using some formula based on the indices, just to
// get something non-trivial here.
//
{
RefPtr<Field>&Values = myCartesianRepresentation["values"];
ArrayRef<double, 3> GridValues(GridDims);
for(MultiIndex<3> I : GridDims)
{
double& value = GridValues[ I ];
value = (I[0]*0.3)*(I[0]*0.3) +
(I[1]*0.2)*(I[0]*0.2) -
(I[2]*0.1)*(I[2]*0.1);
}
if (auto
ValueCreator = Values->createCreator(GridValues) )
{
ValueCreator->touch();
MemCore::Timer RangeTimer;
#if FIBEROPERATIONS_RANGE_HPP < 20241206
auto Range = DataRange<double>::get( *ValueCreator );
Console() << "Time to compute the range of " << GridDims << " double values is " << RangeTimer.secs()*1000.0 << "ms.";
#else
auto Range = DataRange<double>::retrieve( *ValueCreator );
Console() << "Time to compute the range of " << GridDims << " double values is " << RangeTimer.secs()*1000.0 << "ms: "
<< *Range;
RangeTimer.restart();
auto Range2 = DataRange<double>::retrieve( *ValueCreator );
Console() << "Time to retrieve the range of " << GridDims << " double values is " << RangeTimer.secs()*1000.0 << "ms.";
#endif
}
}
{
RefPtr<Field>&Values = myCartesianRepresentation["colors"];
ArrayRef<rgb16, 3> GridValues(GridDims);
for(MultiIndex<3> I : GridDims)
{
auto& value = GridValues[ I ];
value.r() = I[0]*0x10000 / GridDims[0];
value.g() = I[1]*0x10000 / GridDims[1];
value.b() = I[2]*0x10000 / GridDims[2];
}
if (auto
ValueCreator = Values->createCreator(GridValues) )
{
ValueCreator->touch();
MemCore::Timer RangeTimer;
#if FIBEROPERATIONS_RANGE_HPP >= 20241206
auto Range = DataRange<rgb16>::retrieve( *ValueCreator, false );
Console() << "Time to compute the range of " << GridDims << " rgb values is " << RangeTimer.secs()*1000.0 << "ms: "
<< *Range
;
RangeTimer.restart();
auto Range2 = DataRange<rgb16>::retrieve( *ValueCreator, false );
Console() << "Time to retrieve the range of " << GridDims << " rgb values is " << RangeTimer.secs()*1000.0 << "ms.";
Assert( ValueCreator->getAttribute("Range" ) );
#endif
}
#if FIBEROPERATIONS_RANGE_HPP >= 20241206
DataRange<rgb16>::retrieve(*Values, false);
auto Range = Values->getAttribute("Range");
#endif
}
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
An array reference class, which is a convenience class for reference pointers to multidimensional mem...
Definition ArrayRef.hpp:28
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
A multidimensional index that is automatically a lower-dimensional index via recursion.
Definition MultiIndex.hpp:449
A Representation is a set of Field objects, each of them accessed via some FieldID identifier.
Definition Representation.hpp:101
double secs() const noexcept
StrongPtr< Object, ObjectBase > RefPtr
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
RefPtr< BoundingBox > ComputeBBox(const RefPtr< MemBase > &CoordBase)
Compute the bounding box from a given mem array of coordinates.
Definition ExpandBBox.cpp:27
Class for ranges of types, such as minimum/maximum.
Definition Range.hpp:379
static RefPtr< DataRange > retrieve(CreativeArrayBase &CAB, bool AsynchRequest=false, bool AvoidDataLoading=false, const RefPtr< MemBase > &PossibleData=nullptr)
Provide a data range on a given CreativeArrayBase from the attribute, if such exists and is older tha...
Definition Range.hpp:880

Function Documentation

◆ main()

int main ( )

Bind a bundle to a file and add data to it later.

Demonstrating how to bind a Bundle to a file, then adding data to it later on. In contrast, when saving a Bundle to a file then data are added first and saved in the end. The workflow with the binding feature is just other way round - bind first, then add data.

The actual dataset is a set of points with a scalar field on them.

References Fiber::ComputeBBox(), Fiber::DataRange< Type >::retrieve(), and MemCore::Timer::secs().