FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
XF_LineSetHierarchicalRegularized.cpp
#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/grid/types/LineSet.hpp>
#include <fiber/grid/types/RefinedFragmentSkeleton.hpp>
#include <fiber/grid/types/RegularlyFragmentedGrid.hpp>
#include <memcore/Console.hpp>
using namespace Fiber;
using namespace Eagle::PhysicalSpace;
int main()
{
Finit();
Grid&GridOfFragmentedLines = BP[0.0]["HierarchicalLineSetRegular"];
RefPtr<Chart> myChart = GridOfFragmentedLines.makeCartesianChart();
const unsigned MaxLevel = 4;
for(unsigned Level = 1; Level< MaxLevel; Level++)
{
unsigned NFragsPerDim = 1<<(Level-1);
MultiIndex<3> NFrags = { NFragsPerDim,NFragsPerDim,NFragsPerDim };
string FragmentNamePrefix = "LineFragmentL" + std::to_string(Level) + "#";
Coordinates = new RegularlyFragmentedField<3>( NFrags, FragmentNamePrefix ),
Connectivity = new RegularlyFragmentedField<3>( NFrags, FragmentNamePrefix );
double CellSize = 0.25/NFragsPerDim; // the more fragments the smaller the cellsize
string FragmentPrefix = "LineFragmentL" + std::to_string(Level) + "#";
for(unsigned Z = 0; Z<NFragsPerDim; Z++)
for(unsigned Y = 0; Y<NFragsPerDim; Y++)
for(unsigned X = 0; X<NFragsPerDim; X++)
{
MultiIndex<3> FragID = { X,Y,Z };
//
// Coordinates
//
{
Ref<LineSet::CoordsMemArray_t> CoordsArray( 1024 );
std::vector<point>&Crds = CoordsArray->myChunk()->get_vector();
int some_int = 0;
for(auto&P : Crds)
{
P.x() = double( some_int%32 + X* 37.0)/NFragsPerDim;
P.y() = double( (some_int/ 8)%32 + Y* 43.0)/NFragsPerDim;
P.z() = 0.6*double( (some_int/64)%32 + Z* 39.0)/NFragsPerDim;
some_int++;
}
auto&VertexFrag =
(*Coordinates)[ FragID ] = new CreativeArray( CoordsArray );
Coordinates->own( VertexFrag );
*VertexFrag << "CellSize" << CellSize;
}
//
// Connectivity
//
{
Ref<LineSet::LinesetArray_t> LinesetArray(32);
MultiArray<1, std::vector<LineSet::LineIndex_t> >&LineIndices = *LinesetArray;
//
// Put vertex indices into LineIndices array.
// The following code will define 32 lines,
// each constructed by 32 vertices, so 32*32=1024 points.
//
for(index_t j=0; j<32; j++)
{
std::vector<LineSet::LineIndex_t>&E = LineIndices[ j ];
E.resize(32);
for(index_t i=0; i<32; i++)
{
E[i] = i + j*32;
}
}
auto&C=Connectivity[ FragID ] = new CreativeArray( LinesetArray );
Connectivity->own(C);
}
}
SkeletonID VertexSkeletonID = SkeletonID::refinedSkeleton( SkeletonID(1) , Level),
ConnectivitySkeletonID = SkeletonID::refinedSkeleton(LineSet::PerLineSkeletonID(), Level);
Verbose(0) << " Vertices: " << VertexSkeletonID << " Connectivity: " << ConnectivitySkeletonID;
Skeleton&TheVertices = GridOfFragmentedLines[ VertexSkeletonID ];
Representation&TheCartesianVertices = TheVertices[myChart];
TheCartesianVertices.setPositions( Coordinates );
Skeleton&TheLineset = GridOfFragmentedLines[ ConnectivitySkeletonID ];
Representation&LinesAsVertices = TheLineset[ TheVertices ];
LinesAsVertices.setPositions( Connectivity );
createRegularlyFragmentedSkeleton( GridOfFragmentedLines, TheLineset);
}
Verbose(0) << " ----------- Setting up hierarchy ------------- ";
for(unsigned Level = 1; Level< MaxLevel-1; Level++)
{
ParentVertexSkeletonID = SkeletonID::refinedSkeleton( SkeletonID(1) , Level ),
ParentConnectivitySkeletonID = SkeletonID::refinedSkeleton(LineSet::PerLineSkeletonID(), Level ),
ChildVertexSkeletonID = SkeletonID::refinedSkeleton( SkeletonID(1) , Level+1),
ChildConnectivitySkeletonID = SkeletonID::refinedSkeleton(LineSet::PerLineSkeletonID(), Level+1);
ParentConnectivity(GridOfFragmentedLines, ParentConnectivitySkeletonID, ParentVertexSkeletonID),
ChildConnectivity (GridOfFragmentedLines, ChildConnectivitySkeletonID , ChildVertexSkeletonID );
Assert( ParentConnectivity );
Assert( ChildConnectivity );
ParentConnectivityField = ParentConnectivity.getParentChildMapping(),
ChildConnectivityField = ChildConnectivity.getParentChildMapping();
Assert( ParentConnectivityField );
Assert( ChildConnectivityField );
Verbose(0) << " Setting up parental relationship for " << ParentConnectivitySkeletonID << " --> " << ChildConnectivitySkeletonID;
//
// Three-dimensional layout of fragment relationships
//
unsigned NFragsPerDim = 1<<(Level-1);
DynamicSize theFragmentRefinementLayout(3, NFragsPerDim);
Refinement = RefinedFragmentSkeleton::create(GridOfFragmentedLines,
ParentConnectivitySkeletonID,
ChildConnectivitySkeletonID,
theFragmentRefinementLayout);
for(unsigned Z = 0; Z<NFragsPerDim; Z++)
for(unsigned Y = 0; Y<NFragsPerDim; Y++)
for(unsigned X = 0; X<NFragsPerDim; X++)
{
MultiIndex<3> ParentFragmentIndex = { X,Y,Z };
RefPtr<FragmentID> ParentFragmentID = ParentConnectivityField->getFragmentID( ParentFragmentIndex );
Assert(ParentFragmentID);
for(unsigned ZZ = 2*Z; ZZ<2*Z+2; ZZ++)
for(unsigned YY = 2*Y; YY<2*Y+2; YY++)
for(unsigned XX = 2*X; XX<2*X+2; XX++)
{
MultiIndex<3> ChildFragmentIndex = {XX,YY,ZZ};
RefPtr<FragmentID> ChildFragmentID = ChildConnectivityField->getFragmentID( ChildFragmentIndex );
Assert( ChildFragmentID );
ChildFragments.push_back( ChildFragmentID );
}
Refinement.setFragmentMappingArray(ParentFragmentID, ChildFragments,
-42 ); // RefinementFragmentDims argument is unusued in "new" layout.
}
}
if (!BP.save("LineSetHierarchicalRegularized.f5"))
Console() << " Could not create file LineSetHierarchicalRegularized.f5 , is it already opened by another program?";
return 0;
}
constexpr void push_back(const value_type &__x)
constexpr void resize(size_type __new_size)
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
A helper class that keeps objects in memory all time.
Definition CreativeArray.hpp:25
A class describing an n-dimensional space at runtime.
Definition field/DynamicSize.hpp:29
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
RefPtr< Chart > makeCartesianChart(const string &name={}, uint16_t epsg_code=0)
Create a cartesian chart here, if not existent yet.
Definition Grid.cpp:114
Definition MultiArray.hpp:371
A recursively defined multidimensional index.
Definition MultiIndex.hpp:331
A relative representation from the fragments of one one Skeleton to the fragments of another Skeleton...
Definition RefinedFragmentSkeleton.hpp:19
bool setFragmentMappingArray(const RefPtr< FragmentID > &ParentFragmentID, const FragmentMapping_t &ChildFragments, int RefinementFragmentDims)
Set a number of child fragment ID's for a given parent fragment ID.
Definition RefinedFragmentSkeleton.cpp:277
A convenience class for optimized handling of fields that are fragmented in a regular manner (n-dimen...
Definition RegularlyFragmentedField.hpp:27
A Representation is a set of Field objects, each of them accessed via some FieldID identifier.
Definition Representation.hpp:101
bool setPositions(const RefPtr< Field > &P)
Set the positional component of this Representation object.
Definition Representation.cpp:519
Identifier for Skeletons within a Grid.
Definition SkeletonID.hpp:24
A Skeleton is a set of Representation object, each of them accessed by an Representer object.
Definition Skeleton.hpp:102
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
string to_string(const Eagle::FixedArray< ElementType, N > &A, const char *OpenBrace="{", const char *CloseBrace="}", const char *Separator=",")
A relative representation from one Skeleton to another Skeleton where elements of one Skeleton are re...
Definition RelativeRepresentation.hpp:19