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

Display a set of lines as specified by the Edge skeleton of a grid.

Display a set of lines as specified by the Edge skeleton of a grid.Refinement levels and fragmented fields not implemented.

#include <bone/FishGrid.hpp>
#include <ocean/GLvish/VGLRenderObject.hpp>
#include <ocean/GLvish/BoundingBox.hpp>
#include <ocean/GLvish/GlossyTexture.hpp>
#include <eagle/PhysicalSpace.hpp>
#include <ocean/shrimp/TimeDependent.hpp>
#include <GL/fieldGL.hpp>
#include <GL/FieldBuffer.hpp>
#include <baseop/ExpandBBox.hpp>
#include <ocean/shrimp/VObjectStatus.hpp>
#include <grid/types/LineSet.hpp>
#include <bundle/BundleProperty.hpp>
#include <GL/LineSetRenderer.hpp>
#include <bone/GridActor.hpp>
using namespace Wizt;
using namespace Fiber;
using namespace Eagle;
namespace
{
{
public:
GlossyTexture::Parameters GlossyParameters;
struct FieldState : State
{
WeakPtr<Grid> theGridOfInterest;
};
RefPtr<State> newState() const override
{
return new FieldState();
}
TypedSlot<Grid> LineGrid;
TypedSlot<double> Thickness;
TypedSlot<int> WhichLine,
nLines;
GlossyLines(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
, GlossyParameters(this)
, LineGrid(this, "grid")
, Thickness(this, "thickness", 1.0)
, WhichLine(this, "lineid", -1, 1)
, nLines(this, "nlines", 1, 2)
{
Thickness.setProperty( "max", 10.0);
WhichLine.setProperty( "min", -1);
}
void setup(const CreationSlots_t&CreationSlots) override
{
setupTime(CreationSlots);
}
bool update(VRequest&R, double precision) override;
bool renderGL(VGLRenderContext&Context) const override;
static string createChildname(const string&parent_name)
{
return "GlossyLinesOf" + parent_name;
}
};
//
// Update function, is called whenever some input is changed
// It extracts the fields required for rendering and deposits them
// in the context-relative state object. This state object is
// available then during rendering.
//
bool GlossyLines::update(VRequest&Context, double precision)
{
// puts("\n\n************************************GlossyLines::update() enter\n");fflush(stdout);
double time = SI.getTime();
if (!SI.getGrid())
return setStatusError(Context,"No grid object found at T=" + String(time), false );
setBoundingBall( Context, getBoundingBox( *SI.getGrid() ) );
LineSet LS = SI.getGrid();
if (!LS)
{
return setStatusError(Context,"No line grid found at T=" + String(time), false );
}
S->theGridOfInterest = SI.getGrid();
index_t N = LS.NumberOfLines();
WhichLine.setProperty("max", int(N) ); // hm, should be context-relative...
nLines.setProperty("max", int(N) ); // hm, should be context-relative...
return setStatusInfo(Context, String(int(N)) + " Lines ready.");
}
/*
The render routine. Takes care of vertex buffer objects
and calls its render routines.
*/
bool GlossyLines::renderGL(VGLRenderContext&Context) const
{
if (!S) return false;
if (!S->theGridOfInterest)
return false;
// try to get a LineTexture object cached at the Status
try
{
LineTexture = Context( *S )( this ) ( GlossyValues ) ( TEXTURE() );
}
catch(const GLError&)
{
Verbose(0) << "Got an GL Exception...";
}
// if none is there, then create one
if (!LineTexture)
{
LineTexture = new GlossyTexture(0);
LineTexture->enlighten();
LineTexture->enlighten(GlossyParameters, Context);
GLCHECK( LineTexture->enlighten );
Context[ *S ][ this ][ GlossyValues ] ( TEXTURE() ) = LineTexture;
}
double width = 1.0;
if (width<=0.0) width=0.01;
glColor3f(.9,.4,.9);
glLineWidth(width);
// GLCHECK( glLineWidth(width) );
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glBlendFunc(GL_ONE, GL_ONE);
// glEnable( GL_BLEND );
{
// Enable the glossy texture for all subsequent OpenGL operations
GlossyTexture::Render LINERENDER( *LineTexture, Context.getCameraSettings() );
string VBOKey = ""; // fragment ID here in future extension
Intercube&CacheObject = *S->theGridOfInterest;
// try to get a VBO
try
{
}
catch(...){}
Verbose(0) << "glossy lines continue..." << myVBO;
LineSet LS(S->theGridOfInterest);
// if none, need to create one
if (!myVBO || !myVBO->getRenderer() ||
(LS.Coords && myVBO->isOlderThan( *LS.Coords) ) ||
(LS.LineIndices && myVBO->isOlderThan( *LS.LineIndices) ) )
{
RefPtr<MemBase> Pts = LS.Coords->getData();
if (!Pts)
return false;
RefPtr<BufferArray> VA = GL::FieldBufferVertexArray::create( Pts, true );
myVBO = Context[ CacheObject ][ typeid(*this) ][ myCacheableValues ] ( VERTEXBUFFER(), VBOKey );
myVBO->clear();
// printf("GlossyLines: VBO %p is %d yet, add %d vertices (%d points)\n",
// &*myVBO, myVBO->NumberOfElements(), VA->NumberOfElements(), Pts->nElements() );
myVBO->append(VA );
#if 1
if (RefPtr<LineSet::TangentialVector_t> TV = LS.getTangentialVectors() )
{
// printf("GlossyLines: %d vertices, add %d tangential vectors\n",
// Pts->nElements(), TV->nElements() );
assert( TV->nElements() == Pts->nElements() );
const int TextureUnit = 0;
myVBO->append( TCA );
// puts("appended tangential arrays");fflush(stdout);
}
// else puts("GlossyLines: NO Tangential Vectors Available :(");
#endif
myVBO->setRenderer( new GL::LineSetRenderer( S->theGridOfInterest ) );
}
// if (myVBO->isOlderThan( *S->theGridOfInterest ) ) {puts("GlossyLines: RENDERER is outdated!");}
RefPtr<GL::LineSetRenderer> R = myVBO->getRenderer();
if (!R)
{
puts("GlossyLines: Renderer Problem");
return false;
}
WhichLine << Context >> R->WhichOneOnly;
nLines << Context >> R->nLines;
// finally just call the VBO
myVBO->call();
}
return true;
}
//
// Object Creation
//
{
static SkeletonExistence InspectionProperty()
{
return SkeletonExistence( LineSet::ID() );
}
};
MyGlossyLinesCreator( "Display/GlossyLines", ObjectQuality::OUTDATED );
} // anon namespace
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Context information to select a grid from within a bundle.
Definition GridSelector.hpp:26
Info< Skeleton > getRefinementLevel(double time, int Level, int IndexDepth, const BundlePtr &SpaceTime=BundlePtr(NullPtr()))
Retrieve a skeleton for the given refinement level for the current time.
Definition GridSelector.cpp:14
A set of lines stored on a Grid.
Definition LineSet.hpp:55
A concrete Grid Property which looks for the existence of a Skeleton of the specified dimension and i...
Definition BundleProperty.hpp:76
bool setProperty(const string &theName, const Type &theValue) const
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 ...
DEFAULT_OBJECT
Definition Lytica.hpp:7
Definition GridInspector.hpp:13
Common base class for objects that render information given on line sets, merely for grouping purpose...
Definition eye/retina/LineSetRenderer.hpp:39