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

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

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

Author
werner
#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;
namespace
{
class TransparentSurface : public VSkeletonRenderObject
{
public:
struct MyState : State, TriangularSurface
{
using TriangularSurface::operator=;
};
RefPtr<State> newState() const override
{
return new MyState();
}
SurfaceBackColor;
TypedSlot<double> Transparency;
TransparentSurface(const string&name, int, const RefPtr<VCreationPreferences>&VP)
, SurfaceColor(this, "color", Color(1.,.1,1., 1.0),0)
, SurfaceBackColor(this, "backcolor", Color(.0, 1.,1.0, 1.0),0)
, Transparency(this, "opacity", 0.5, 0)
{}
bool renderGL(VGLRenderContext&Context) const override;
bool update(VRequest&R, double precision) override;
static string createChildname(const string&parent_name)
{
return "TransparentSurface(" + parent_name + ")";
}
};
bool TransparentSurface::update(VRequest&Context, double precision)
{
RefPtr<MyState> S = myState(Context);
RefPtr<Grid> G = findMostRecentGrid( Context );
if (!G)
{
return setStatusError(Context, "No Grid found.");
}
*S = G;
if (!*S)
return setStatusError(Context, "No surface available.");
setBoundingBall(Context, getBoundingBox( S->CoordField ) );
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 TransparentSurface::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(">>>>> TransparentSurface: RENDER cells for t=%ld, %lu Triangles\n",
// myState->CellField->time_value(), Cells->nElements() );
RefPtr<Field> Tmp = Surface.getTriangleBaryCenters();
BaryCenters = Tmp->getCreator();
//
// VBO Access via GLCache, retrieve and re-use or generate new VBO
//
const string VBOKey = "";
RefPtr<ValueSet> V;// = ScaleFactor(Context);
unsigned ViewCacheSize = 1;
try
{
myVBO = Context( *Surface )( typeid(*this) )( V )(VERTEXBUFFER(), VBOKey);
// Call the VBO if it's there and all ready to go.
if (myVBO
&& !myVBO->isOlderThan( *Surface.CellField)
&& !myVBO->isOlderThan( *Surface.CoordField) )
{
if (RefPtr<TriangleRenderer> TR = myVBO->getRenderer() )
{
assert( TR->MyElementSorter );
TR->CurrentIBO = TR->sortByDepth(Context, BaryCenters, ViewCacheSize );
if (myVBO->call() )
{
return true;
}
}
}
}
catch(const GLCacheError&Err)
{}
if (!myVBO)
myVBO = Context[*Surface][ typeid(*this) ][ V ]( VERTEXBUFFER(), VBOKey);
myVBO->clear();
//
// Loading fields as vertex arrays and append them to the VBO.
//
using namespace Eagle::PhysicalSpace;
myVBO->append( new TypedVertexArray<point3>( myState->getCoords()->myChunk() ) );
if (RefPtr<TriangularSurface::NormalVectorArray_t> VertexNormals = Surface.getNormals() )
{
myVBO->append( new TypedNormalArray<bivector3>( VertexNormals->myChunk() ));
}
RefPtr<TriangleRenderer> TR = new TriangleRenderer(myState->getCoords(), myState->CellField->getData() );
TR->MyElementSorter = new GL::TypedElementSorter<TriangleCell>(myState->CellField->getCreator() );
TR->CurrentIBO = TR->sortByDepth(Context, BaryCenters, ViewCacheSize );
myVBO->setRenderer( TR );
myVBO->call();
return true;
}
//
// Object Creation
//
{
static SkeletonExistence InspectionProperty()
{
return SkeletonExistence( TriangularSurface::ID() );
}
};
using namespace Panthalassa;
/*
This module is outdated because it uses GLVish instead of the
Anemonia API, based on retina/TriangleRenderer .
*/
// MyTransparentSurfaceCreator("Display/TransparentSurface", ObjectQuality::MATURE);
MyTransparentSurfaceCreator( Category("Display") / VIdentifier("TransparentSurface"), ObjectQuality::OUTDATED);
} // anon namespace
namespace
{
using namespace Panthalassa;
MyCreator( Category( "Display" ) + VIdentifier( "TransparentSurface" ) + Application( "General" ) +
Description( "Show a transparent surface." ) +
Help( "todo" ) +
Url( "http://vish.fiberbundle.net/wiki" ),
ObjectQuality::OUTDATED );
}
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
A concrete Grid Property which looks for the existence of a Skeleton of the specified dimension and i...
Definition BundleProperty.hpp:76
Base class for objects that render information given on the triangle of a Grid.
Definition TriangleRenderer.hpp:22
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