FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
EvolutionSurface.cpp

Render a triangular surface transparently.

Render a triangular surface transparently. Display a triangular surface as transparent object using depth-sorting.

Author
sandeeb
#include <ocean/GLvish/VGLRenderObject.hpp>
#include <ocean/GLvish/BoundingBox.hpp>
#include <ocean/GLvish/ArrayTypes.hpp>
#include <ocean/GLvish/colors.hpp>
#include <ocean/shrimp/VObjectStatus.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <field/Cell.hpp>
#include <GL/fiberGL.hpp>
#include <baseop/ExpandBBox.hpp>
#include <eye/retina/VSkeletonRenderObject.hpp>
#include <grid/types/TriangularSurface.hpp>
#include <bundle/BundleProperty.hpp>
#include <bone/GridActor.hpp>
#include <GL/PartialElementRenderer.hpp>
using namespace Wizt;
using namespace Fiber;
using namespace Eagle;
using namespace Fiber;
namespace
{
class EvolutionSurface : public VSkeletonRenderObject
{
public:
struct MyState : State, Fiber::TriangularSurface
{
};
RefPtr<State> newState() const override
{
return new MyState();
}
struct EvolutionSurfaceIterator: EvolutionIterator<Grid>
{
double startTime;
double skip; //MR should better be a uint
int counter;
double pastTime;
EvolutionSurfaceIterator(vector<Fiber::TriangularSurface> *surfaces, double time, double past_time,double skipSteps)
: startTime(time)
, grid(surfaces)
, skip(skipSteps)
, counter(0)
, pastTime(past_time)
{}
bool apply(double time, GridID&id, Grid&G) override
{
{
return false;
}
// MR should be something like ( counter % skip == 0), such that only everth nth surface is drawn
if( counter==skip )
{
RefPtr<Grid> *newGrid = new RefPtr<Grid>(&G);
grid->push_back(*newGrid);
}
counter ++;
if(counter > skip)
{
counter = 0;
}
return true;
}
};
SurfaceBackColor;
TypedSlot<double> Transparency;
TypedSlot<double> SkipSteps;
EvolutionSurface(const string&name, int, const RefPtr<VCreationPreferences>&VP)
, SurfaceColor(this, "color", {1.,.1,1., 1.0},0)
, SurfaceBackColor(this, "backcolor", {.0, 1.,1.0, 1.0},0)
, Transparency(this, "opacity", 0.5, 0)
, PastTime(this, "pastTime", 1)
, SkipSteps(this, "skipSteps", 1)
{
PastTime.setProperty("max", 100.0);
SkipSteps.setProperty("max", 100.0);
}
bool renderGL(VGLRenderContext&Context) const override;
bool update(VRequest&R, double precision) override;
static string createChildname(const string&parent_name)
{
return "EvolutionSurface(" + parent_name + ")";
}
};
bool EvolutionSurface::update(VRequest&Context, double precision)
{
RefPtr<MyState> S = myState(Context);
GridSelector GS = getGridSelector(Context);
RefPtr<Grid> G = findMostRecentGrid( Context );
if (!G)
{
return setStatusError(Context, "No Grid found.");
}
S->TriangularSurface::operator=(G);
if (!*S)
return setStatusError(Context, "No surface available.");
setBoundingBall(Context, getBoundingBox( S->CoordField ) );
if (BundlePtr B = GS.getBundle() )
{
S->gridEvolution.clear();
double pastTime = 0.0;
double skipSteps = 0.0;
double t = getTime(Context, B);
EvolutionSurfaceIterator iterator(&(S->gridEvolution), t, pastTime, skipSteps);
B->iterateBackward(t, SelectedGridName, iterator, false);
S->gridEvolution.push_back(G);
}
return setStatusInfo(Context, "Surface ready to render.");
}
{
, Cells(TriangleCells)
{
assert( Cells->getTypedStorage() );
const std::vector<TriangleCell>&Cls = Cells->getTypedStorage()->get_vector();
this->CurrentIBO = new IndexBuffer<TriangleCell>( Cls );
draw_mode = GL_TRIANGLES;
}
void prefix() override
{
glEnable(GL_DEPTH_TEST); // see depth buffer
glDepthMask(GL_FALSE); // but don't write to it
}
void postfix() override
{
}
};
bool EvolutionSurface::renderGL(VGLRenderContext&Context) const
{
RefPtr<MyState> myState = getState(Context);
if (!myState)
return false;
if (!Surface)
return false;
if (!Surface.CoordField)
{
printf("Did not find coordinates :( \n");
return false;
}
if (!Surface.CellField)
{
printf("Did not find triangles :( \n");
return false;
}
//
// Generic OpenGL section, these settings affect all VBO's rendered later
//
glMaterial( GL::FRONT_AND_BACK, GL::AMBIENT , Color( 0,0,.01,0) );
glMaterial( GL::FRONT_AND_BACK, GL::SPECULAR, Color( 0.5,0.5,.53, 0) );
glMaterial( GL::FRONT_AND_BACK, GL::EMISSION, Color( 0., 0.,0., 0) );
glColor4f(1,0,0, 0.5);
// glColorMaterial( GL_FRONT_AND_BACK, GL_DIFFUSE);
// glEnable( GL_COLOR_MATERIAL );
rgba_float_t SurfColor( 1,0,0,0.5 );
double Alpha = 0.5;
SurfColor[3] = Alpha;
SurfBackColor[3] = Alpha;
// glEnable( GL_DEPTH_TEST );
// glEnable( GL_MULTISAMPLE_ARB );
// glEnable( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB );
// glColor4f( 1,0,0,.8);
// glMaterial( GL::FRONT, GL::DIFFUSE, makeColor( 1., 0.,0., 0.3) );
// glMaterial( GL::BACK , GL::DIFFUSE, makeColor( .3, 1.,0., 0.3) );
// printf(">>>>> EvolutionSurface: RENDER cells for t=%ld, %lu Triangles\n",
// myState->CellField->time_value(), Cells->nElements() );
RefPtr<Field> Tmp = Surface.getTriangleBaryCenters();
BaryCenters = Tmp->getCreator();
std::ostringstream stream;
for(unsigned i=0; i<myState->gridEvolution.size(); i++)
{
stream<<i;
//
// VBO Access via GLCache, retrieve and re-use or generate new VBO
//
//const string VBOKey = "";
RefPtr<ValueSet> V;// = ScaleFactor(Context);
// RefPtr<TriangleRenderer> MyTriangleRenderer;
unsigned ViewCacheSize = 1;
try
{
myVBO = Context( *Surface )( typeid(*this) )( V )(VERTEXBUFFER(), stream.str());
// Call the VBO if it's there and all ready to go.
if (myVBO
&& !myVBO->isOlderThan( *Surface.CellField)
&& !myVBO->isOlderThan( *Surface.CoordField) )
{
for(unsigned j=i; j<myState->gridEvolution.size()&&myVBO; j++)
{
if ( RefPtr<TriangleRenderer> TR = myVBO->getRenderer() )
{
assert( TR->MyElementSorter );
TR->CurrentIBO = TR->sortByDepth(Context, BaryCenters, ViewCacheSize );
myVBO->call();
}
stream<<j+1;
myVBO = Context( *Surface )( typeid(*this) )( V )(VERTEXBUFFER(), stream.str());
}
return true;
}
}
catch(const GLCacheError&Err)
{}
if (!myVBO)
myVBO = Context[*Surface][ typeid(*this) ][ V ]( VERTEXBUFFER(), stream.str());
myVBO->clear();
//
// Loading fields as vertex arrays and append them to the VBO.
//
using namespace Eagle::PhysicalSpace;
myVBO->append( new TypedVertexArray<point3>( myState->gridEvolution[i].getCoords()->myChunk() ) );
if (RefPtr<TriangularSurface::NormalVectorArray_t> VertexNormals = Surface.getNormals() )
{
myVBO->append( new TypedNormalArray<bivector3>( VertexNormals->myChunk() ));
}
RefPtr<TriangleRenderer> TR = new TriangleRenderer(myState->gridEvolution[i].getCoords(), myState->gridEvolution[i].CellField->getData() );
TR->MyElementSorter = new GL::TypedElementSorter<TriangleCell>(myState->gridEvolution[i].CellField->getCreator() );
TR->CurrentIBO = TR->sortByDepth(Context, BaryCenters, ViewCacheSize );
myVBO->setRenderer( TR );
myVBO->call();
}
return true;
}
} // anon namespace
namespace
{
using namespace Panthalassa;
MyCreator( Category( "Display" ) + VIdentifier( "EvolutionSurface" ) + Application( "General,HydroVish" ) +
Description( "Show time evolution of a triangular surface" ) +
Help( "todo" ) +
Url( "http://ahm.co.at/wiki/en" ),
ObjectQuality::EXPERIMENTAL );
}
_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply(_Tp __func(_Tp)) const
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
A grid identifier.
Definition GridID.hpp:29
Context information to select a grid from within a bundle.
Definition GridSelector.hpp:26
const Fiber::BundlePtr & getBundle() const
Provide the original bundle of from where the Grid was selected.
Definition GridSelector.hpp:115
const string & getGridname() const
Name of the selected grid (member function)
Definition GridSelector.hpp:39
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
Base class for objects that render information given on the triangle of a Grid.
Definition TriangleRenderer.hpp:22
bool setProperty(const string &theName, const Type &theValue) const
virtual void postfix()
virtual void prefix()
Base class for objects rendering skeletons of a fiber bundle.
Definition VSkeletonRenderObject.hpp:21
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
std::nullptr_t NullPtr
note: cannot derive from FloatingSkeletonRenderer as long as independent base class TriangleRenderer ...
TRANSPARENT_OBJECT
Definition Lytica.hpp:7
Definition GridInspector.hpp:13
A triangular surface stored on a Grid.
Definition TriangularSurface.hpp:43
Base class to draw a selection of elements as OpenGL points.
Definition PartialElementRenderer.hpp:85