#include <bone/FishSlice.hpp>
#include <bone/FishGrid.hpp>
#include <bone/FComputeNormals.hpp>
#include <ocean/plankton/VModules.hpp>
#include <ocean/plankton/VCreator.hpp>
#include <ocean/plankton/VObject.hpp>
#include <ocean/plankton/VCotask.hpp>
using namespace Wizt;
using namespace Fiber;
using namespace Eagle;
class VComputeNormals : public virtual VObject,
public virtual Fish<Fiber::Slice>,
public virtual Fish<Fiber::Grid>,
public VCotask
{
public:
typedef FComputeNormalsTask FieldState;
BundleSlot myBundle() const
{
return TypedSlot<Fiber::BundlePtr>();
}
override RefPtr<State> newState() const
{
return new FieldState();
}
VComputeNormals(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
: VObject(name, p, VP)
, Fish<VObject>(this)
, VCotask(this)
{
}
override bool update(VRequest&R, double precision);
};
bool VComputeNormals::update(VRequest&R, double precision)
{
RefPtr<FieldState> S = getState(R);
RefPtr<Grid> G = this->Fish<Grid>::findMostRecentGrid( R );
if (!G)
{
printf("ComputeNormals: update(): No grid!\n");
if (S) S -> clear();
return true;
}
RefPtr<Field> NormalsField = (*G)("Normals");
if (NormalsField)
{
puts("already have normals");
return true;
}
RefPtr<Field> Coords = G->CartesianPositions();
if (!Coords)
{
puts("No coord field!");
if (S) S -> clear();
return true;
}
RefPtr<Representation> CellsAsVertices = G->CellsAsVertices(2);
if (!CellsAsVertices)
{
puts("VComputeNormals: No cells as vertices found");
return true;
}
S = myState(R);
assert(S);
S->CoordField = Coords;
S->CellField = CellsAsVertices->Positions();
S->VertexNormalField = (*G)( "Normals" );
execute( R, S );
return true;
}
static Ref<VCreator<VComputeNormals, AcceptList<Fiber::BundlePtr> > >
myCreator("Compute/Normals", ObjectQuality::MATURE);