#include <bone/FishSlice.hpp>
#include <bone/FishGrid.hpp>
#include <bone/FishSkeleton.hpp>
#include <ocean/plankton/VCreator.hpp>
#include <ocean/GLvish/VGLRenderObject.hpp>
#include <ocean/GLvish/BoundingBox.hpp>
#include <ocean/eagle/PhysicalSpace.hpp>
#include <ocean/shrimp/VEnum.hpp>
#include <baseop/ExpandBBox.hpp>
#include <ocean/GLvish/GlossyTexture.hpp>
using namespace Wizt;
using namespace Fiber;
using namespace Eagle;
class DreiBein : public virtual VGLRenderObject,
public GlossyLines,
public virtual Fish<Slice>,
public virtual Fish<Grid>,
public virtual Fish<Skeleton>
{
public:
struct FieldState : State
{
RefPtr<BoundingBox> BBox;
};
override RefPtr<State> newState() const
{
return new FieldState();
}
TypedSlot<int> Thickness;
TypedSlot<VEnum> Options;
DreiBein(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
: VGLRenderObject(name, DEFAULT_OBJECT, VP)
, Fish<VObject>(this)
, GlossyLines(this)
, Thickness(this, "thickness", 50, 0)
, Options(this, "options", VEnum("shaded", "monochrome"), 1)
{}
override bool update(VRequest&R, double precision);
override void render(VGLRenderContext&Context) const;
};
bool DreiBein::update(VRequest&R, double precision)
{
RefPtr<FieldState> S = myState(R);
Info<Skeleton> Level = getRefinementLevel(0, R);
if (!Level.getSkeleton() )
{
printf("BoundingBox: update(): No level!\n");
if (S)
{
S->BBox = NullPtr();
}
return true;
}
RefPtr<Representation> LevelRep = Level.getCartesianRepresentation();
assert( LevelRep );
RefPtr<Field> Coords = LevelRep->Positions();
if (!Coords)
return setStatusError(R, "No Coordinates");
if (RefPtr<BoundingBox> BBox = getBoundingBox( Coords ) )
{
setBoundingBall(R, BBox);
S->BBox = BBox;
setBoundingBall(R, BBox);
return setStatusInfo(R, "Bounding box" + String( BBox ) );
}
else
return setStatusError(R, "No Bounding box");
}
void DreiBein::render(VGLRenderContext&Context) const
{
RefPtr<FieldState> myState = getState(Context);
if (!myState)
return;
RefPtr<BoundingBox> MyBBox = myState->BBox;
if (!MyBBox)
return;
if (MyBBox->empty() )
return;
using namespace Eagle::PhysicalSpace;
const point&Min = MyBBox->mincoord(),
&Max = MyBBox->maxcoord();
RefPtr<GlossyTexture> LineTexture;
VEnum opt;
Options << Context >> opt;
if (opt("shaded"))
LineTexture = getLineTexture( *myState, Context);
int width = 20;
Thickness << Context >> width;
glLineWidth(width/10.0);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glPointSize(width/10.0);
glDisable(GL_LIGHTING);
glEnable( GL_DEPTH_TEST );
glEnable ( GL_COLOR_MATERIAL );
point X( Max.x(), Min.y(), Min.z() ),
Y( Min.x(), Max.y(), Min.z() ),
Z( Min.x(), Min.y(), Max.z() );
{
GlossyTexture::Render LINERENDER( LineTexture, Context.CameraSettings, true );
glBegin(GL_LINES);
glColor3f( 1.0, 0.0, 0.0);
glTexCoord(bivector3(1,0,0) );
glVertex(Min);
glVertex(X);
glColor3f( 0.0, 1.0, 0.0);
glTexCoord(bivector3(0,1,0) );
glVertex(Min);
glVertex(Y);
glColor3f( 0.0, 0.0, 1.0);
glTexCoord(bivector3(0,0,1) );
glVertex(Min);
glVertex(Z);
glEnd();
}
}
static Ref<VCreator<DreiBein, AcceptList<Fiber::Grid> > >
myCreator("Display/Dreibein", ObjectQuality::MATURE);