Пример #1
0
void
considerLocStillEvent()
{ if ( !loc_still_posted )
  { unsigned long now = mclock();

    if ( now - host_last_time < (unsigned long)loc_still_time )
    { DEBUG(NAME_locStill, Cprintf("TimeDiff = %d (ignored)\n", now - host_last_time));
      return;
    }

    if ( !pceMTTryLock(LOCK_PCE) )
      return;
    if ( instanceOfObject(last_window, ClassWindow) &&
	 !onFlag(last_window, F_FREED|F_FREEING) &&
	 valInt(last_x) > 0 && valInt(last_y) > 0 )
    { ServiceMode(is_service_window(last_window),
		  { AnswerMark mark;
		    EventObj e;

		    markAnswerStack(mark);
		    e = newObject(ClassEvent,
				  NAME_locStill, last_window,
				  last_x, last_y, last_buttons,
				  toInt(last_time + now - host_last_time), EAV);
		    addCodeReference(e);
		    postNamedEvent(e, (Graphical) last_window, DEFAULT, NAME_postEvent);
		    delCodeReference(e);
		    freeableObj(e);
		    rewindAnswerStack(mark, NIL);
		  })
    }
Пример #2
0
static status
initialiseEvent(EventObj e, Name id, Any window,
		Int x, Int y, Int bts, Int time)
{ unsigned long t = valInt(time);

  initialiseProgramObject(e);

  if ( notNil(EVENT->value) )
  { EventObj parent = EVENT->value;

    if ( isDefault(x) )      x      = parent->x;
    if ( isDefault(y) )      y      = parent->y;
    if ( isDefault(bts) )    bts    = parent->buttons;
    if ( isDefault(window) ) window = parent->window;
    if ( isDefault(time) )   t      = max(last_time, parent->time);
  } else
  { if ( isDefault(x) )      x      = last_x;
    if ( isDefault(y) )      y      = last_y;
    if ( isDefault(bts) )    bts    = last_buttons;
    if ( isDefault(window) ) window = last_window;
    if ( isDefault(time) )   t      = last_time;
  }

  host_last_time = mclock();
  last_time      = t;
  last_buttons   = bts;			/* save these values */
  last_x         = x;
  last_y         = y;

  assign(e, window,	window);
  assign(e, receiver,	window);
  assign(e, id,		id);
  assign(e, x,		x);
  assign(e, y,		y);
  assign(e, buttons,	bts);
  e->time = t;

  if ( isDownEvent(e) )
  { int clt = CLICK_TYPE_single;
    int px  = valInt(x);
    int py  = valInt(y);

    DEBUG(NAME_multiclick, Cprintf("t: %ld (%ld), x: %d (%d), y: %d (%d) --> ",
				   t, last_down_time, px, last_down_x,
				   py, last_down_y));

    if ( (valInt(e->buttons) & CLICK_TYPE_mask) == CLICK_TYPE_double )
    { switch( last_click_type )
      { case CLICK_TYPE_single:	clt = CLICK_TYPE_double; break;
	case CLICK_TYPE_double:	clt = CLICK_TYPE_triple; break;
	default:		clt = CLICK_TYPE_single; break;
      }
      e->buttons = toInt(valInt(e->buttons) & ~CLICK_TYPE_mask);
    } else
    { if ( (t - last_down_time) < multi_click_time &&
	   abs(last_down_x - px) <= multi_click_diff &&
	   abs(last_down_y - py) <= multi_click_diff &&
	   (valInt(last_down_bts)&BUTTON_mask) == (valInt(bts)&BUTTON_mask) &&
	   last_window == window )
      { switch( last_click_type )
	{ case CLICK_TYPE_single:	clt = CLICK_TYPE_double; break;
	  case CLICK_TYPE_double:	clt = CLICK_TYPE_triple; break;
	}
      }
    }

    last_click_type = clt;
    assign(e, buttons, toInt(valInt(e->buttons) | clt));

    DEBUG(NAME_multiclick, Cprintf("%s\n", strName(getMulticlickEvent(e))));

    last_down_bts     = bts;
    last_down_time    = t;
    last_down_x       = px;
    last_down_y       = py;
  } else if ( isUpEvent(e) )
  { assign(e, buttons, toInt(valInt(e->buttons) | last_click_type));
  }

  if ( !onFlag(window, F_FREED|F_FREEING) )
    last_window = window;

  if ( loc_still_posted )
  { if ( isAEvent(e, NAME_locMove) )
    { DEBUG(NAME_locStill, Cprintf("Re-enabled loc-still on %s\n", pp(e->id)));
      loc_still_posted = FALSE;
    }
  } else if ( isAEvent(e, NAME_area) ||
	      isAEvent(e, NAME_deactivateKeyboardFocus) )
  { DEBUG(NAME_locStill, Cprintf("Disabled loc-still on %s\n", pp(e->id)));
    loc_still_posted = TRUE;
  }

  succeed;
}
Пример #3
0
void Frame()
{
  long starttime,stoptime,exectime,i;

  Init_Options();

  printf("*****Entering init_decomposition with num_nodes = %ld\n",num_nodes);
  fflush(stdout);

  Init_Decomposition();

  printf("*****Exited init_decomposition with num_nodes = %ld\n",num_nodes);
  fflush(stdout);



  Global = (struct GlobalMemory *)NU_MALLOC(sizeof(struct GlobalMemory),0);
  BARINIT(Global->SlaveBarrier, num_nodes);
  BARINIT(Global->TimeBarrier, num_nodes);
  LOCKINIT(Global->IndexLock);
  LOCKINIT(Global->CountLock);
  ALOCKINIT(Global->QLock,MAX_NUMPROC+1);

  /* load dataset from file to each node */
#ifndef RENDER_ONLY
  CLOCK(starttime);
  Load_Map(filename);
  CLOCK(stoptime);
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to load map:  %lu ms\n", exectime);
#endif

  CLOCK(starttime);
#ifndef RENDER_ONLY
  Compute_Normal();
#ifdef PREPROCESS
  Store_Normal(filename);
#endif
#else
  Load_Normal(filename);
#endif
  CLOCK(stoptime);
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to compute normal:  %lu ms\n", exectime);

  CLOCK(starttime);
#ifndef RENDER_ONLY
  Compute_Opacity();
#ifdef PREPROCESS
  Store_Opacity(filename);
#endif
#else
  Load_Opacity(filename);
#endif
  CLOCK(stoptime);
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to compute opacity:  %lu ms\n", exectime);

  Compute_Pre_View();
  shd_length = LOOKUP_SIZE;
  Allocate_Shading_Table(&shd_address,shd_length);
  /* allocate space for image */
  image_len[X] = frust_len;
  image_len[Y] = frust_len;
  image_length = image_len[X] * image_len[Y];
  Allocate_Image(&image_address,image_length);

  if (num_nodes == 1) {
    block_xlen = image_len[X];
    block_ylen = image_len[Y];
    num_blocks = 1;
    num_xblocks = 1;
    num_yblocks = 1;
    image_block = image_address;
  }
  else {
    num_xblocks = ROUNDUP((float)image_len[X]/(float)block_xlen);
    num_yblocks = ROUNDUP((float)image_len[Y]/(float)block_ylen);
    num_blocks = num_xblocks * num_yblocks;
    Lallocate_Image(&image_block,block_xlen*block_ylen);
  }

  CLOCK(starttime);
#ifndef RENDER_ONLY
  Compute_Octree();
#ifdef PREPROCESS
  Store_Octree(filename);
#endif
#else
  Load_Octree(filename);
#endif
  CLOCK(stoptime);
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to compute octree:  %lu ms\n", exectime);

#ifdef PREPROCESS
  return;
#endif

  if (adaptive) {
    printf("1.\n");
    for (i=0; i<NI; i++) {
      mask_image_len[i] = image_len[i];
    }
    mask_image_length = image_length;
    Allocate_MImage(&mask_image_address, mask_image_length);
    if (num_nodes == 1)
      mask_image_block = (PIXEL *)mask_image_address;
    else
      Lallocate_Image(&mask_image_block, block_xlen*block_ylen);
    printf("2.\n");
  }

#ifndef RENDER_ONLY
  Deallocate_Map(&map_address);
#endif

  Global->Index = NODE0;

  printf("\nRendering...\n");
  printf("node\tframe\ttime\titime\trays\thrays\tsamples trilirped\n");

  CREATE(Render_Loop, num_nodes);
}
Пример #4
0
EXTERN_ENV

#include "anl.h"

Ray_Trace(int my_node)
{
    int outx,outy,outz;
    int i,j;
    unsigned int starttime,stoptime,exectime,exectime1;
    int pid;
    char cmd[FILENAME_STRING_SIZE];


    /* Assumptions made by ray tracer:                                   */
    /*   o Frustrum clipping is performed.                               */
    /*     All viewing frustums will be handled correctly.               */
    /*   o Contributions are obtained only from nearest 8 neighbors.     */
    /*     If downsizing was specified, some input voxels will be        */
    /*     unsampled, but upsizing may be specified and will be          */
    /*     handled correctly.                                            */

    /* Compute inverse Jacobian matrix from                              */
    /* coordinates of output map unit voxel in object space,             */
    /* then make a copy of object space d{x,y,z} per image space dz,     */
    /* which controls number of ray samples per object space voxel       */
    /* (i.e. Z-sampling rate), to allow recomputation per region.        */
    for (i=0; i<NM; i++) {
        invjacobian[X][i] = uout_invvertex[0][0][1][i] -
                            uout_invvertex[0][0][0][i];
        invjacobian[Y][i] = uout_invvertex[0][1][0][i] -
                            uout_invvertex[0][0][0][i];
        invjacobian[Z][i] = uout_invvertex[1][0][0][i] -
                            uout_invvertex[0][0][0][i];
    }

    /* Compute multiplicative inverse of inverse Jacobian matrix.        */
    /* If any Jacobian is zero, compute no inverse for that element.     */
    /* This test must be repeated before access to any inverse element.  */
    for (i=0; i<NM; i++) {
        for (j=0; j<NM; j++) {
            if (ABS(invjacobian[i][j]) > SMALL)
                invinvjacobian[i][j] = 1.0 / invjacobian[i][j];
        }
    }

    num_rays_traced = 0;
    num_traced_rays_hit_volume = 0;
    num_samples_trilirped = 0;

    /* Invoke adaptive or non-adaptive ray tracer                          */
    if (adaptive) {

        BARRIER(Global->TimeBarrier,num_nodes);

        CLOCK(starttime);
        Pre_Shade(my_node);

        LOCK(Global->CountLock);
        Global->Counter--;
        UNLOCK(Global->CountLock);
        while (Global->Counter);

        Ray_Trace_Adaptively(my_node);

        CLOCK(stoptime);

        BARRIER(Global->TimeBarrier,num_nodes);

        mclock(stoptime,starttime,&exectime);

        /* If adaptively ray tracing and highest sampling size is greater    */
        /* than lowest size for volume data if polygon list exists or        */
        /* display pixel size if it does not, recursively interpolate to     */
        /* fill in any missing samples down to lowest size for volume data.  */

        if (highest_sampling_boxlen > 1) {

            BARRIER(Global->TimeBarrier,num_nodes);

            CLOCK(starttime);
            Interpolate_Recursively(my_node);

            CLOCK(stoptime);

            BARRIER(Global->TimeBarrier,num_nodes);

            mclock(stoptime,starttime,&exectime1);
        }
    }
    else {

        BARRIER(Global->TimeBarrier,num_nodes);

        CLOCK(starttime);

        Pre_Shade(my_node);

        LOCK(Global->CountLock);
        Global->Counter--;
        UNLOCK(Global->CountLock);
        while (Global->Counter);

        Ray_Trace_Non_Adaptively(my_node);

        CLOCK(stoptime);

        BARRIER(Global->TimeBarrier,num_nodes);

        mclock(stoptime,starttime,&exectime);
        exectime1 = 0;
    }

    LOCK(Global->CountLock);
    printf("%3d\t%3d\t%6u\t%6u\t%6d\t%6d\t%8d\n",my_node,frame,exectime,
           exectime1,num_rays_traced,num_traced_rays_hit_volume,
           num_samples_trilirped);

    UNLOCK(Global->CountLock);

    BARRIER(Global->TimeBarrier,num_nodes);
}
Пример #5
0
void Frame()
{
  long starttime,stoptime,exectime,i;

  Init_Options();

  printf("*****Entering init_decomposition with num_nodes = %ld\n",num_nodes);
  fflush(stdout);

  Init_Decomposition();

  printf("*****Exited init_decomposition with num_nodes = %ld\n",num_nodes);
  fflush(stdout);



//  Global = (struct GlobalMemory *)valloc(sizeof(struct GlobalMemory));;

  posix_memalign(&Global, sizeof(struct GlobalMemory *), sizeof(struct GlobalMemory));
  {
#line 120
	unsigned long	Error;
#line 120

#line 120
	Error = pthread_mutex_init(&(Global->SlaveBarrier).mutex, NULL);
#line 120
	if (Error != 0) {
#line 120
		printf("Error while initializing barrier.\n");
#line 120
		exit(-1);
#line 120
	}
#line 120

#line 120
	Error = pthread_cond_init(&(Global->SlaveBarrier).cv, NULL);
#line 120
	if (Error != 0) {
#line 120
		printf("Error while initializing barrier.\n");
#line 120
		pthread_mutex_destroy(&(Global->SlaveBarrier).mutex);
#line 120
		exit(-1);
#line 120
	}
#line 120

#line 120
	(Global->SlaveBarrier).counter = 0;
#line 120
	(Global->SlaveBarrier).cycle = 0;
#line 120
};
  {
#line 121
	unsigned long	Error;
#line 121

#line 121
	Error = pthread_mutex_init(&(Global->TimeBarrier).mutex, NULL);
#line 121
	if (Error != 0) {
#line 121
		printf("Error while initializing barrier.\n");
#line 121
		exit(-1);
#line 121
	}
#line 121

#line 121
	Error = pthread_cond_init(&(Global->TimeBarrier).cv, NULL);
#line 121
	if (Error != 0) {
#line 121
		printf("Error while initializing barrier.\n");
#line 121
		pthread_mutex_destroy(&(Global->TimeBarrier).mutex);
#line 121
		exit(-1);
#line 121
	}
#line 121

#line 121
	(Global->TimeBarrier).counter = 0;
#line 121
	(Global->TimeBarrier).cycle = 0;
#line 121
};
  {pthread_mutex_init(&(Global->IndexLock), NULL);};
  {pthread_mutex_init(&(Global->CountLock), NULL);};
  {
#line 124
	unsigned long	i, Error;
#line 124

#line 124
	for (i = 0; i < MAX_NUMPROC+1; i++) {
#line 124
		Error = pthread_mutex_init(&Global->QLock[i], NULL);
#line 124
		if (Error != 0) {
#line 124
			printf("Error while initializing array of locks.\n");
#line 124
			exit(-1);
#line 124
		}
#line 124
	}
#line 124
};

  /* load dataset from file to each node */
#ifndef RENDER_ONLY
  {
#line 128
	struct timeval	FullTime;
#line 128

#line 128
	gettimeofday(&FullTime, NULL);
#line 128
	(starttime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 128
};
  Load_Map(filename);
  {
#line 130
	struct timeval	FullTime;
#line 130

#line 130
	gettimeofday(&FullTime, NULL);
#line 130
	(stoptime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 130
};
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to load map:  %lu ms\n", exectime);
#endif

  {
#line 135
	struct timeval	FullTime;
#line 135

#line 135
	gettimeofday(&FullTime, NULL);
#line 135
	(starttime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 135
};
#ifndef RENDER_ONLY
  Compute_Normal();
#ifdef PREPROCESS
  Store_Normal(filename);
#endif
#else
  Load_Normal(filename);
#endif
  {
#line 144
	struct timeval	FullTime;
#line 144

#line 144
	gettimeofday(&FullTime, NULL);
#line 144
	(stoptime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 144
};
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to compute normal:  %lu ms\n", exectime);

  {
#line 148
	struct timeval	FullTime;
#line 148

#line 148
	gettimeofday(&FullTime, NULL);
#line 148
	(starttime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 148
};
#ifndef RENDER_ONLY
  Compute_Opacity();
#ifdef PREPROCESS
  Store_Opacity(filename);
#endif
#else
  Load_Opacity(filename);
#endif
  {
#line 157
	struct timeval	FullTime;
#line 157

#line 157
	gettimeofday(&FullTime, NULL);
#line 157
	(stoptime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 157
};
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to compute opacity:  %lu ms\n", exectime);

  Compute_Pre_View();
  shd_length = LOOKUP_SIZE;
  Allocate_Shading_Table(&shd_address,shd_length);
  /* allocate space for image */
  image_len[X] = frust_len;
  image_len[Y] = frust_len;
  image_length = image_len[X] * image_len[Y];
  Allocate_Image(&image_address,image_length);

  if (num_nodes == 1) {
    block_xlen = image_len[X];
    block_ylen = image_len[Y];
    num_blocks = 1;
    num_xblocks = 1;
    num_yblocks = 1;
    image_block = image_address;
  }
  else {
    num_xblocks = ROUNDUP((float)image_len[X]/(float)block_xlen);
    num_yblocks = ROUNDUP((float)image_len[Y]/(float)block_ylen);
    num_blocks = num_xblocks * num_yblocks;
    Lallocate_Image(&image_block,block_xlen*block_ylen);
  }

  {
#line 185
	struct timeval	FullTime;
#line 185

#line 185
	gettimeofday(&FullTime, NULL);
#line 185
	(starttime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 185
};
#ifndef RENDER_ONLY
  Compute_Octree();
#ifdef PREPROCESS
  Store_Octree(filename);
#endif
#else
  Load_Octree(filename);
#endif
  {
#line 194
	struct timeval	FullTime;
#line 194

#line 194
	gettimeofday(&FullTime, NULL);
#line 194
	(stoptime) = (unsigned long)(FullTime.tv_usec + FullTime.tv_sec * 1000000);
#line 194
};
  mclock(stoptime,starttime,&exectime);
  printf("wall clock execution time to compute octree:  %lu ms\n", exectime);

#ifdef PREPROCESS
  return;
#endif

  if (adaptive) {
    printf("1.\n");
    for (i=0; i<NI; i++) {
      mask_image_len[i] = image_len[i];
    }
    mask_image_length = image_length;
    Allocate_MImage(&mask_image_address, mask_image_length);
    if (num_nodes == 1)
      mask_image_block = (PIXEL *)mask_image_address;
    else
      Lallocate_Image(&mask_image_block, block_xlen*block_ylen);
    printf("2.\n");
  }

#ifndef RENDER_ONLY
  Deallocate_Map(&map_address);
#endif

  Global->Index = NODE0;

  printf("\nRendering...\n");
  printf("node\tframe\ttime\titime\trays\thrays\tsamples trilirped\n");

  {
#line 225
	long	i, Error;
#line 225

#line 225
	for (i = 0; i < (num_nodes) - 1; i++) {
#line 225
		Error = pthread_create(&PThreadTable[i], NULL, (void * (*)(void *))(Render_Loop), NULL);
#line 225
		if (Error != 0) {
#line 225
			printf("Error in pthread_create().\n");
#line 225
			exit(-1);
#line 225
		}
#line 225
	}
#line 225

#line 225
	Render_Loop();
#line 225
};
}