Colors need to be specified as an array of rgb_float_t data for each vertex. If no such field is defined, then this surface module creates something artificial, which maps each vertex into its own specific color. Render a triangular surface transparently.
#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 <bone/FishField.hpp>
namespace
{
{
public:
{
string ColorFieldName;
using TriangularSurface::operator=;
};
RefPtr<State> newState() const override
{
return new MyState();
}
PolychromeSurface(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
, SurfaceColorField(this, "colorfield" )
, SurfaceColor(this, "color", {.8,.5,.1, 1.0},0)
, ScaleFactor(this, "colorization", 0.0, 1)
{}
bool update(
VRequest&R,
double precision)
override;
{
return "PolychromeSurface(" + parent_name + ")";
}
};
{
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.");
SurfaceColorField << Context >>
FS;
S->ColorFieldName =
FS();
setBoundingBall(
Context, getBoundingBox( S->CoordField ) );
return setStatusInfo(
Context,
"Surface ready to render.");
}
{
RefPtr<TriangularSurface::CellArray_t> Cells;
TriangleRenderer(const RefPtr<TriangularSurface::CellArray_t>&TriangleCells)
: Cells(TriangleCells)
{}
void prefix() override
{
glEnable(GL_NORMALIZE);
glDisable( GL_BLEND );
}
bool draw() override
{
GL::DrawElements( Triangles );
return true;
}
};
{
RefPtr<MyState> myState = getState(
Context);
if (!myState)
return false;
if (!Surface)
return false;
{
printf("Did not find coordinates :( \n");
return false;
}
{
printf("Did not find cells :( %s\n",
return false;
}
glEnable(GL_LIGHTING);
glMaterialf( GL_FRONT, GL_SHININESS, 3 );
glMaterialf( GL_BACK , GL_SHININESS, 50 );
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);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glColorMaterial( GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable( GL_COLOR_MATERIAL );
SurfaceColor << Context >> SurfColor;
glColor( SurfColor );
double colorscale = 1.0;
ScaleFactor << Context >> colorscale;
string VBOKey = "";
RefPtr<ValueSet> V;
if (Colors)
VBOKey += myState->ColorFieldName ;
else
RefPtr<VBO> myVBO;
try
{
if (myVBO
&& (Colors && !myVBO->isOlderThan( *Colors) ) )
{
if (RefPtr<TriangleRenderer> TR = myVBO->getRenderer() )
{
if (myVBO->call() )
{
return true;
}
}
}
}
{}
if (!myVBO)
assert( myVBO );
myVBO->clear();
if (RefPtr<TriangularSurface::NormalVectorArray_t> VertexNormals = Surface.
getNormals() )
{
}
if (Colors)
{
{
myVBO->append( newColorArray( colordata->myChunk() ));
}
}
else
{
index_t nVertices = Surface.
CartesianVertices->getPositions()->getData()->nElements();
for(index_t i=0; i<nVertices; i++)
{
float fi = i/(nVertices-1.0);
SurfaceColors[i] = {1-fi, 1-fi, fi, 1.0f};
}
RefPtr<TypedChunk<rgba_float_t> > colordata = SurfaceColors;
myVBO->append( newColorArray( colordata ) );
}
myVBO->setRenderer( new TriangleRenderer(myState->CellField->getData() ) );
myVBO->call();
return true;
}
struct GridInspector
{
{
}
};
}
An internal class that stores a couple of textual names.
Definition FieldSelector.hpp:18
Definition MultiArray.hpp:371
A concrete Grid Property which looks for the existence of a Skeleton of the specified dimension and i...
Definition BundleProperty.hpp:76
An intermediate class that allows to operate on the pure type information of some memory array.
Definition TypedArray.hpp:58
Base class for objects rendering skeletons of a fiber bundle.
Definition VSkeletonRenderObject.hpp:21
MEMCORE_API std::string Typename(const std::type_info &t)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
Wizt::VCreatorProperty< Wizt::VCreatorProperties::CATEGORY > Category
note: cannot derive from FloatingSkeletonRenderer as long as independent base class TriangleRenderer ...
virtual string createChildname(const string &parent_name) const
Definition fs/init.hpp:20
A triangular surface stored on a Grid.
Definition TriangularSurface.hpp:43
RefPtr< Field > CellField
Field for the triangle indices.
Definition TriangularSurface.hpp:66
static SkeletonID ID()
2D objects of index depth 1 .
Definition TriangularSurface.hpp:131
RefPtr< Field > CoordField
Field for the vertex coordinates.
Definition TriangularSurface.hpp:59
RefPtr< Representation > CartesianVertices
Collection of all fields given on vertices relative to cartesian coordinates.
Definition TriangularSurface.hpp:69