FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
XF_LineSetHierarchical.cpp
#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/grid/types/LineSet.hpp>
#include <fiber/grid/types/RefinedFragmentSkeleton.hpp>
using namespace Fiber;
using namespace Eagle::PhysicalSpace;
string FragmentName(unsigned Level, unsigned X, unsigned Y, unsigned Z)
{
return "LineFragmentL" + std::to_string(Level) + "#" + std::to_string(X)
+ "x" + std::to_string(Y) + "x" + std::to_string(Z);
}
int main()
{
Finit();
Grid&GridOfFragmentedLines = BP[0.0]["HierarchicalLineSet"];
RefPtr<Chart> myChart = GridOfFragmentedLines.makeCartesianChart();
const unsigned MaxLevel = 4;
for(unsigned Level = 1; Level< MaxLevel; Level++)
{
RefPtr<Field> Coordinates = new Field(),
Connectivity = new Field();
unsigned NFragsPerDim = 1<<(Level-1);
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++)
{
string FragmentName = "LineFragmentL" + std::to_string(Level) + "#" + std::to_string(X)
+ "x" + std::to_string(Y) + "x" + std::to_string(Z);
Verbose(0) << "Level " << Level << " creating fragment " << FragmentName;
//
// 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->setPersistentDataByName( CoordsArray, FragmentName );
*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;
}
}
Connectivity->setPersistentDataByName( LinesetArray, FragmentName );
}
}
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 );
}
Verbose(0) << " ----------- Setting up hierarchy ------------- ";
for(unsigned Level = 1; Level< MaxLevel-1; Level++)
{
ParentConnectivitySkeletonID = SkeletonID::refinedSkeleton(LineSet::PerLineSkeletonID(), Level ),
ChildConnectivitySkeletonID = SkeletonID::refinedSkeleton(LineSet::PerLineSkeletonID(), Level+1);
Verbose(0) << " Setting up parental relationship for " << ParentConnectivitySkeletonID << " --> " << ChildConnectivitySkeletonID;
//
// Three-dimensional layout of fragment relationships
//
int NFragsPerDim = 1<<(Level-1);
DynamicSize theFragmentRefinementLayout(3, NFragsPerDim);
Refinement = RefinedFragmentSkeleton::create(GridOfFragmentedLines,
ParentConnectivitySkeletonID,
ChildConnectivitySkeletonID,
theFragmentRefinementLayout);
for(int Z = 0; Z<NFragsPerDim; Z++)
for(int Y = 0; Y<NFragsPerDim; Y++)
for(int X = 0; X<NFragsPerDim; X++)
{
string FragmentName = "LineFragmentL" + std::to_string(Level) + "#" + std::to_string(X)
+ "x" + std::to_string(Y) + "x" + std::to_string(Z);
Assert( Refinement.FragmentRefinement.ParentSkeleton );
Assert( Refinement.FragmentRefinement.ParentSkeleton->getFragmentIDCollection() );
RefPtr<FragmentID> ParentFragmentID = Refinement.getParentSkeleton()->findFragmentIDByName(FragmentName);
Assert(ParentFragmentID);
/*
if (!ParentFragmentID)
{
Verbose(0) << " Could not find " << FragmentName << " in level " << Level
<< " in " << Refinement.getParentSkeleton()->ID()
<< " with " << Refinement.getParentSkeleton()->getFragmentIDCollection();
continue;
}
*/
for(int ZZ = 2*Z; ZZ<2*Z+2; ZZ++)
for(int YY = 2*Y; YY<2*Y+2; YY++)
for(int XX = 2*X; XX<2*X+2; XX++)
{
string FragmentNameNextLevel = "LineFragmentL" + std::to_string(Level+1) + "#" + std::to_string(XX)
+ "x" + std::to_string(YY) + "x" + std::to_string(ZZ);
RefPtr<FragmentID> ChildFragmentID = Refinement.getChildSkeleton()->getFragmentIDCollection()->findFragmentIDByName(FragmentNameNextLevel);
Assert( ChildFragmentID );
ChildFragments.push_back( ChildFragmentID );
}
Refinement.setFragmentMappingArray(ParentFragmentID, ChildFragments,
-42 ); // RefinementFragmentDims argument is unusued in "new" layout.
}
}
BP.save("LineSetHierarchical.f5");
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 class describing an n-dimensional space at runtime.
Definition field/DynamicSize.hpp:29
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
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 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 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=",")