Skip to content

Commit

Permalink
Sampling outside grid in gLucifer should not halt run
Browse files Browse the repository at this point in the history
Catch the exception and print, but keep going
  • Loading branch information
OKaluza committed Mar 15, 2017
1 parent 1d6eeba commit 7b01150
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 50 deletions.
47 changes: 21 additions & 26 deletions libUnderworld/gLucifer/DrawingObjects/src/CrossSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,11 @@ void lucCrossSection_AllocateSampleData(void* drawingObject, int dims)
if (!self->values)
self->values = Memory_Alloc_3DArray( float, self->resolutionA, self->resolutionB, dims, "vertex values");

if (dims > self->fieldComponentCount)
{
for ( aIndex = 0 ; aIndex < self->resolutionA ; aIndex++ )
for ( bIndex = 0 ; bIndex < self->resolutionB ; bIndex++ )
for (d=self->fieldComponentCount; d<dims; d++)
self->values[aIndex][bIndex][d] = 0;
}
//Flag empty values with Infinity
for ( aIndex = 0 ; aIndex < self->resolutionA ; aIndex++ )
for ( bIndex = 0 ; bIndex < self->resolutionB ; bIndex++ )
for (d=0; d<dims; d++)
self->values[aIndex][bIndex][d] = HUGE_VAL;
}

void lucCrossSection_SampleField(void* drawingObject, Bool reverse)
Expand Down Expand Up @@ -522,27 +520,25 @@ void lucCrossSection_SampleField(void* drawingObject, Bool reverse)

/* Check cross section is within local space,
* if outside then skip to avoid wasting time attempting to sample */
/* This scales horrendously when mesh is irregular as we search for points that are not on the processor */
/* A local coord sampling routine, such as implemented for isosurfaces would help with this problem */
/*double TOL = 0.00000001; //((max[self->axis1] - min[self->axis1] + max[self->axis2] - min[self->axis2])/2.0) * 0.000001;
if (pos[I_AXIS] + TOL > localMin[I_AXIS] && pos[I_AXIS] - TOL < localMax[I_AXIS] &&
pos[J_AXIS] + TOL > localMin[J_AXIS] && pos[J_AXIS] - TOL < localMax[J_AXIS] &&
(fieldVariable->dim < 3 || (pos[K_AXIS] + TOL > localMin[K_AXIS] && pos[K_AXIS] - TOL < localMax[K_AXIS])))*/
/* Avoid by using onMesh sampling when mesh is irregular as searching for points that are not on the processor is costly */
if (pos[I_AXIS] > localMin[I_AXIS]-FLT_EPSILON && pos[I_AXIS] < localMax[I_AXIS]+FLT_EPSILON &&
pos[J_AXIS] > localMin[J_AXIS]-FLT_EPSILON && pos[J_AXIS] < localMax[J_AXIS]+FLT_EPSILON &&
(self->dim < 3 || (pos[K_AXIS] > localMin[K_AXIS]-FLT_EPSILON && pos[K_AXIS] < localMax[K_AXIS]+FLT_EPSILON)))
(self->dim < 3 || (pos[K_AXIS] > localMin[K_AXIS]-FLT_EPSILON && pos[K_AXIS] < localMax[K_AXIS]+FLT_EPSILON)))
{
const FunctionIO* output = debug_dynamic_cast<const FunctionIO*>(cppdata->func(globalCoord.get()));

/* Value found locally, save */
for (d=0; d<dims; d++)
self->values[aIndex][bIndex][d] = output->at<float>(d);
}
else
{
/* Flag not found */
for (d=0; d<dims; d++)
self->values[aIndex][bIndex][d] = HUGE_VAL;
try
{
const FunctionIO* output = debug_dynamic_cast<const FunctionIO*>(cppdata->func(globalCoord.get()));

/* Value found locally, save */
for (d=0; d<dims; d++)
self->values[aIndex][bIndex][d] = output->at<float>(d);
}
catch (std::exception& e)
{
//Not found
std::cerr << e.what() << std::endl;
/* Flag not found */
}
}

/* Copy vertex data */
Expand Down Expand Up @@ -613,7 +609,6 @@ void lucCrossSection_SampleMesh( void* drawingObject, Bool reverse)
Coord globalMin, globalMax, min, max;
Mesh* mesh = (Mesh*) self->mesh;


int localcount = 0;

std::shared_ptr<MeshCoordinate> meshCoord = std::make_shared<MeshCoordinate>( self->mesh );
Expand Down
25 changes: 3 additions & 22 deletions libUnderworld/gLucifer/DrawingObjects/src/FieldSampler.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void* _lucFieldSampler_DefaultNew( Name name )
Stg_Component_InitialiseFunction* _initialise = _lucFieldSampler_Initialise;
Stg_Component_ExecuteFunction* _execute = _lucFieldSampler_Execute;
Stg_Component_DestroyFunction* _destroy = _lucFieldSampler_Destroy;
lucDrawingObject_SetupFunction* _setup = _lucFieldSampler_Setup;
lucDrawingObject_SetupFunction* _setup = _lucCrossSection_Setup;
lucDrawingObject_DrawFunction* _draw = _lucFieldSampler_Draw;
lucDrawingObject_CleanUpFunction* _cleanUp = lucDrawingObject_CleanUp;

Expand All @@ -90,7 +90,7 @@ void _lucFieldSampler_AssignFromXML( void* drawingObject, Stg_ComponentFactory*
/* Construct Parent */
_lucCrossSection_AssignFromXML( self, cf, data );

defaultRes = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolution", 0);
defaultRes = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolution", 32);
resolution[ I_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionX", defaultRes);
resolution[ J_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionY", defaultRes);
resolution[ K_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionZ", defaultRes);
Expand All @@ -107,29 +107,11 @@ void _lucFieldSampler_Build( void* drawingObject, void* data )
void _lucFieldSampler_Initialise( void* drawingObject, void* data )
{
_lucCrossSection_Initialise(drawingObject, data);


}

void _lucFieldSampler_Execute( void* drawingObject, void* data ) {}
void _lucFieldSampler_Destroy( void* drawingObject, void* data ) {}

void _lucFieldSampler_Setup( void* drawingObject, lucDatabase* database, void* _context )
{
_lucCrossSection_Setup(drawingObject, database, _context);

lucFieldSampler* self = (lucFieldSampler*)drawingObject;

if (self->dim == 2) self->resolution[K_AXIS] = 0;

/* Calculate number of samples */
if (self->onMesh)
self->total = self->dims[I_AXIS] * self->dims[J_AXIS] * self->dims[K_AXIS];
else
self->total = self->resolution[I_AXIS] * self->resolution[J_AXIS] * self->resolution[K_AXIS];

}

void lucFieldSampler_DrawSlice(void* drawingObject, lucDatabase* database)
{
lucFieldSampler* self = (lucFieldSampler*)drawingObject;
Expand Down Expand Up @@ -184,8 +166,7 @@ void _lucFieldSampler_Draw( void* drawingObject, lucDatabase* database, void* _c
{
lucFieldSampler* self = (lucFieldSampler*)drawingObject;
Dimension_Index dim = self->dim;

/*printf("(%s) (ONMESH %d) (ISSET %d) Resolution %d,%d,%d (el x/y/z %d,%d,%d)\n", self->name, self->onMesh, self->isSet, self->resolution[0], self->resolution[1], self->resolution[2], self->dims[I_AXIS], self->dims[J_AXIS], self->dims[K_AXIS]);*/
if (dim == 2) self->resolution[K_AXIS] = 0;

if (!self->onMesh)
{
Expand Down
2 changes: 0 additions & 2 deletions libUnderworld/gLucifer/DrawingObjects/src/FieldSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extern const Type lucFieldSampler_Type;
/* Virtual functions go here */ \
/* Other info */\
IJK resolution; \
Index total; \

struct lucFieldSampler
{
Expand Down Expand Up @@ -55,7 +54,6 @@ void _lucFieldSampler_Execute( void* drawingObject, void* data );
void _lucFieldSampler_Destroy( void* drawingObject, void* data ) ;

/* Drawing Object Implementations */
void _lucFieldSampler_Setup( void* drawingObject, lucDatabase* database, void* _context );
void _lucFieldSampler_Draw( void* drawingObject, lucDatabase* database, void* _context ) ;
#endif

0 comments on commit 7b01150

Please sign in to comment.