Exemple #1
0
inline void
FinalSnapshot
( const Matrix<Real>& estimates,
  const Matrix<Int>& itCounts, 
        SnapshotCtrl& snapCtrl )
{
    DEBUG_ONLY(CSE cse("pspec::FinalSnapshot"));
    auto logMap = []( Real alpha ) { return Log(alpha); };
    if( snapCtrl.realSize != 0 && snapCtrl.imagSize != 0 )
    {
        const bool numSave = ( snapCtrl.numSaveFreq >= 0 );
        const bool imgSave = ( snapCtrl.imgSaveFreq >= 0 );
        const bool imgDisp = ( snapCtrl.imgDispFreq >= 0 );
        Matrix<Real> estMap;
        Matrix<Int> itCountMap;
        if( numSave || imgSave || imgDisp )
        {
            ReshapeIntoGrid
            ( snapCtrl.realSize, snapCtrl.imagSize, estimates, estMap );
            if( snapCtrl.itCounts )
                ReshapeIntoGrid
                ( snapCtrl.realSize, snapCtrl.imagSize, itCounts, itCountMap );
        }
        if( numSave )
        {
            string base = snapCtrl.numBase;
            Write( estMap, base, snapCtrl.numFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, base+"_counts", snapCtrl.numFormat );
        }
        if( imgSave || imgDisp )
            EntrywiseMap( estMap, function<Real(Real)>(logMap) );
        if( imgSave )
        {
            string base = snapCtrl.imgBase;
            Write( estMap, base, snapCtrl.imgFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, base+"_counts", snapCtrl.imgFormat );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Write( estMap, base+"_discrete", snapCtrl.imgFormat );
            SetColorMap( colorMap );
        }
        if( imgDisp )
        {
            string base = snapCtrl.imgBase;
            Display( estMap, base );       
            if( snapCtrl.itCounts )
                Display( itCountMap, base+"_counts" );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Display( estMap, base+"_discrete" );
            SetColorMap( colorMap );
        }
    }
}
Exemple #2
0
void FinalSnapshot
( const DistMatrix<Real,VR,STAR>& estimates,
  const DistMatrix<Int, VR,STAR>& itCounts,
        SnapshotCtrl& snapCtrl )
{
    EL_DEBUG_CSE
    auto logMap = []( const Real& alpha ) { return Log(alpha); };
    if( snapCtrl.realSize != 0 && snapCtrl.imagSize != 0 )
    {
        const bool numSave = ( snapCtrl.numSaveFreq >= 0 );
        const bool imgSave = ( snapCtrl.imgSaveFreq >= 0 );
        const bool imgDisp = ( snapCtrl.imgDispFreq >= 0 );
        DistMatrix<Real> estMap(estimates.Grid());
        DistMatrix<Int> itCountMap(itCounts.Grid());
        if( numSave || imgSave || imgDisp )
        {
            ReshapeIntoGrid
            ( snapCtrl.realSize, snapCtrl.imagSize, estimates, estMap );
            if( snapCtrl.itCounts )
                ReshapeIntoGrid
                ( snapCtrl.realSize, snapCtrl.imagSize, itCounts, itCountMap );
        }
        if( numSave )
        {
            string base = snapCtrl.numBase;
            Write( estMap, base, snapCtrl.numFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, base+"_counts", snapCtrl.numFormat );
        }
        if( imgSave || imgDisp )
            EntrywiseMap( estMap, MakeFunction(logMap) );
        if( imgSave )
        {
            string base = snapCtrl.imgBase;
            Write( estMap, base, snapCtrl.imgFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, base+"_counts", snapCtrl.imgFormat );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Write( estMap, base+"_discrete", snapCtrl.imgFormat );
            SetColorMap( colorMap );
        }
        if( imgDisp )
        {
            string base = snapCtrl.imgBase;
            Display( estMap, base );
            if( snapCtrl.itCounts )
                Display( itCountMap, base+"_counts" );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Display( estMap, base+"_discrete" );
            SetColorMap( colorMap );
        }
    }
}
Exemple #3
0
/* ****************************************************************** */
void WritePPM (double ***Vdbl, char *var_name, char *filename, 
                Grid *grid)

/*
 *
 *
 *
 *
 ******************************************************************** */
{
  int  ic, ir;
  FILE *fl;
  char header[512];
  Image *ppm;

  ppm = GetImage (var_name);
  SetColorMap (ppm->r, ppm->g, ppm->b, ppm->colormap);
  GetSlice (Vdbl, ppm, grid);
  if (prank != 0) return;

  sprintf (header,"P6\n%d %d\n255\n", ppm->ncol, ppm->nrow);
  fl  = fopen (filename,"w");
  fprintf(fl,"%s",header);
  for (ir = 0; ir < ppm->nrow; ir++){
    fwrite (ppm->rgb[ir], sizeof(RGB), ppm->ncol, fl);
  } 
  fclose(fl);
}
Exemple #4
0
void
AlienTalkSegue (COUNT wait_track)
{
	// this skips any talk segues that follow an aborted one
	if ((GLOBAL (CurrentActivity) & CHECK_ABORT) || TalkingFinished)
		return;

	if (!pCurInputState->Initialized)
	{
		InitSpeechGraphics ();
		SetColorMap (GetColorMapAddress (CommData.AlienColorMap));
		SetContext (AnimContext);
		DrawAlienFrame (NULL, 0, TRUE);
		UpdateSpeechGraphics ();
		CommIntroTransition ();
		
		pCurInputState->Initialized = TRUE;

		PlayMusic (CommData.AlienSong, TRUE, 1);
		SetMusicVolume (BACKGROUND_VOL);

		InitCommAnimations ();

		LastActivity &= ~CHECK_LOAD;
	}
	
	TalkingFinished = TalkSegue (wait_track);
	if (TalkingFinished && !VolasPackPresent)
		FadeMusic (FOREGROUND_VOL, ONE_SECOND);
}
Exemple #5
0
static void
animatePowerLines (MENU_STATE *pMS)
{
	static STAMP s; 
	static COLORMAP ColorMap;
	static TimeCount NextTime = 0;
	TimeCount Now = GetTimeCounter ();

	if (pMS)
	{	// Init animation
		s.origin.x = 0;
		s.origin.y = 0;
		s.frame = SetAbsFrameIndex (pMS->ModuleFrame, 24);
		ColorMap = SetAbsColorMapIndex (pMS->CurString, 0);
	}

	if (Now >= NextTime || pMS)
	{
		NextTime = Now + (ONE_SECOND / HANGAR_ANIM_RATE);

		SetColorMap (GetColorMapAddress (ColorMap));
		DrawStamp (&s);
		// Advance colomap cycle
		ColorMap = SetRelColorMapIndex (ColorMap, 1);
	}
}
	void CColorAnimImp::SetEditCtrlData( void* ctrldata )
	{
		if (ctrldata)
		{
			m_pCtrlData = static_cast<ECtrlData*>(ctrldata);
			SetColorMap(m_pCtrlData->m_eDataType, m_pCtrlData->m_pData);
			CCtrlBase::Update();
		}
		else
			m_pCtrlData = NULL;
	}
Exemple #7
0
static void
finish_colormap_xform (int which)
{
	SetColorMap (XFormControl.TaskControl[which].CMapPtr);
	XFormControl.TaskControl[which].CMapIndex = -1;
	// check Highest ptr
	if (which == XFormControl.Highest)
	{
		do
			--which;
		while (which >= 0 && XFormControl.TaskControl[which].CMapIndex == -1);
		
		XFormControl.Highest = which;
	}
}
Exemple #8
0
static int
hangar_anim_func (void *data)
{
	DWORD TimeIn;
	STAMP s;
	Task task = (Task) data;
	COLORMAP ColorMap;
	RECT ClipRect;
	
	if (!pMenuState->CurString)
	{
		FinishTask (task);
		return -1;
	}
	s.origin.x = s.origin.y = 0;
	s.frame = SetAbsFrameIndex (pMenuState->CurFrame, 24);
	ClipRect = pMenuState->flash_rect1;
	ColorMap = SetAbsColorMapIndex (pMenuState->CurString, 0);
	
	TimeIn = GetTimeCounter ();
	while (!Task_ReadState (task, TASK_EXIT))
	{
		CONTEXT OldContext;
		RECT OldClipRect;

		LockMutex (GraphicsLock);
		OldContext = SetContext (ScreenContext);
		GetContextClipRect (&OldClipRect);
		SetContextClipRect (&ClipRect);

		ColorMap = SetRelColorMapIndex (ColorMap, 1);
		SetColorMap (GetColorMapAddress (ColorMap));
		DrawStamp (&s);
		
		SetContextClipRect (&OldClipRect);
		SetContext (OldContext);
		UnlockMutex (GraphicsLock);
		
		SleepThreadUntil (TimeIn + ONE_SECOND / HANGAR_ANIM_RATE);
		TimeIn = GetTimeCounter ();
	}

	FinishTask (task);
	return 0;
}
Exemple #9
0
static void InitMaterials(void)
{
    static float ambient[] = {0.1, 0.1, 0.1, 1.0};
    static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
    static float position[] = {90.0, 90.0, 150.0, 0.0};
    static float front_mat_shininess[] = {60.0};
    static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
    static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
    static float back_mat_shininess[] = {60.0};
    static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
    static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
    static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
    static float lmodel_twoside[] = {GL_TRUE};

    glMatrixMode(GL_PROJECTION);
    gluPerspective(90.0, 1.0, 0.5, 10.0);

    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, position);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
    glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
    glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
    glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
    glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
    if (rgb) {
	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
    }

    if (rgb) {
	glEnable(GL_COLOR_MATERIAL);
    } else {
	SetColorMap();
    }
}
Exemple #10
0
/* ****************************************************************** */
void WritePNG (double ***Vdbl, char *var_name, char *filename, 
                Grid *grid)
/*
 *
 *
 *
 *
 ******************************************************************** */
{
  int ic, ir, i;
  png_structp     png_ptr;
  png_infop       info_ptr;
  int backgroundcolour_;
  int bit_depth_;
  int colortype_;
  int compressionlevel_;
  int  indx;
  double filegamma_;
  Image *png;
  unsigned char **image;
  FILE   *fp;
    
  png = GetImage (var_name);
  SetColorMap (png->r, png->g, png->b, png->colormap);
  GetSlice (Vdbl, png, grid);
  if (prank != 0) return;

  image = (png_bytepp)malloc(png->nrow*sizeof(png_bytep));
  for (ir = 0; ir < png->nrow; ir++) {
    image[ir] = (png_bytep)malloc(6*png->ncol*sizeof(png_byte));
  }

  for(ic = 0; ic < png->ncol; ic++){
  for(ir = 0; ir < png->nrow; ir++){
    i = 6*ic;
    image[ir][i]   = png->rgb[ir][ic].r;      /* -- red -- */
    image[ir][i+1] = 0;
    image[ir][i+2] = png->rgb[ir][ic].g;     /* -- green -- */
    image[ir][i+3] = 0;
    image[ir][i+4] = png->rgb[ir][ic].b;     /* -- blue -- */
    image[ir][i+5] = 0;
  }}


 /* -- write --- */

  compressionlevel_ = 6;
  backgroundcolour_ = 0;
  bit_depth_ = 16;
  filegamma_ = 0.;
  colortype_ = 2.; 

  fp = fopen(filename, "wb");
  if(fp == NULL){
    printf(" ! error opening file in writing data\n");
    exit(1);
  }

  png_ptr  = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  info_ptr = png_create_info_struct(png_ptr);
  png_init_io(png_ptr, fp);

   /*   if(compressionlevel_ != -2){ */
        png_set_compression_level(png_ptr, compressionlevel_);
   /* }
   else
     {
        png_set_compression_level(png_ptr, PNGWRITER_DEFAULT_COMPRESSION);
   }*/

  png_set_IHDR(png_ptr, info_ptr, png->ncol, png->nrow,
               bit_depth_, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
               PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

  if(filegamma_ < 1.0e-1){
    filegamma_ = 0.7;
  }

  png_set_gAMA(png_ptr, info_ptr, filegamma_);
  
   /*
   time_t          gmt;
   png_time        mod_time;
   png_text        text_ptr[5];
   time(&gmt);
   png_convert_from_time_t(&mod_time, gmt);
   png_set_tIME(png_ptr, info_ptr, &mod_time);
   */

  png_write_info(png_ptr, info_ptr);
  png_write_image(png_ptr, image); 
  png_write_end(png_ptr, info_ptr);
  png_destroy_write_struct(&png_ptr, &info_ptr);
  fclose(fp);

  free((char *) image[0]);
  free((char *) image);

}
Exemple #11
0
void Snapshot
( const Matrix<Int>& preimage,
  const Matrix<Real>& estimates,
  const Matrix<Int>& itCounts,
        Int numIts,
        bool deflate,
        SnapshotCtrl& snapCtrl )
{
    EL_DEBUG_CSE
    auto logMap = []( const Real& alpha ) { return Log(alpha); };
    if( snapCtrl.realSize != 0 && snapCtrl.imagSize != 0 )
    {
        const bool numSave =
            ( snapCtrl.numSaveFreq > 0 &&
              snapCtrl.numSaveCount >= snapCtrl.numSaveFreq );
        const bool imgSave =
            ( snapCtrl.imgSaveFreq > 0 &&
              snapCtrl.imgSaveCount >= snapCtrl.imgSaveFreq );
        const bool imgDisp =
            ( snapCtrl.imgDispFreq > 0 &&
              snapCtrl.imgDispCount >= snapCtrl.imgDispFreq );
        Matrix<Real> invNorms, estMap;
        Matrix<Int> itCountsReord, itCountMap;
        if( numSave || imgSave || imgDisp )
        {
            invNorms = estimates;
            if( deflate )
                RestoreOrdering( preimage, invNorms );
            ReshapeIntoGrid
            ( snapCtrl.realSize, snapCtrl.imagSize, invNorms, estMap );
            if( snapCtrl.itCounts )
            {
                itCountsReord = itCounts;
                if( deflate )
                    RestoreOrdering( preimage, itCountsReord );
                ReshapeIntoGrid
                ( snapCtrl.realSize, snapCtrl.imagSize, itCountsReord,
                  itCountMap );
            }
        }
        if( numSave )
        {
            auto title = BuildString( snapCtrl.numBase, "_", numIts );
            Write( estMap, title, snapCtrl.numFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, title+"_counts", snapCtrl.numFormat );
            snapCtrl.numSaveCount = 0;
        }
        if( imgSave || imgDisp )
            EntrywiseMap( estMap, MakeFunction(logMap) );
        if( imgSave )
        {
            auto title = BuildString( snapCtrl.imgBase, "_", numIts );
            Write( estMap, title, snapCtrl.imgFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, title+"_counts", snapCtrl.imgFormat );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Write( estMap, title+"_discrete", snapCtrl.imgFormat );
            SetColorMap( colorMap );
            snapCtrl.imgSaveCount = 0;
        }
        if( imgDisp )
        {
            auto title = BuildString( snapCtrl.imgBase, "_", numIts );
            Display( estMap, title );
            if( snapCtrl.itCounts )
                Display( itCountMap, title+"_counts" );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Display( estMap, title+"_discrete" );
            SetColorMap( colorMap );
            snapCtrl.imgDispCount = 0;
        }
    }
}
Exemple #12
0
inline void
Snapshot
( const Matrix<Int>& preimage, const Matrix<Real>& estimates, 
  const Matrix<Int>& itCounts,
  Int numIts, bool deflate, SnapshotCtrl& snapCtrl )
{
    DEBUG_ONLY(CallStackEntry cse("pspec::Snapshot"));
    if( snapCtrl.realSize != 0 && snapCtrl.imagSize != 0 )
    {
        const bool numSave = 
            ( snapCtrl.numSaveFreq > 0 && 
              snapCtrl.numSaveCount >= snapCtrl.numSaveFreq );
        const bool imgSave = 
            ( snapCtrl.imgSaveFreq > 0 && 
              snapCtrl.imgSaveCount >= snapCtrl.imgSaveFreq );
        const bool imgDisp = 
            ( snapCtrl.imgDispFreq > 0 &&
              snapCtrl.imgDispCount >= snapCtrl.imgDispFreq );
        Matrix<Real> invNorms, estMap;
        Matrix<Int> itCountsReord, itCountMap;
        if( numSave || imgSave || imgDisp )
        {
            invNorms = estimates;
            if( deflate )
                RestoreOrdering( preimage, invNorms );
            ReshapeIntoGrid
            ( snapCtrl.realSize, snapCtrl.imagSize, invNorms, estMap );
            if( snapCtrl.itCounts )
            {
                itCountsReord = itCounts;
                if( deflate )
                    RestoreOrdering( preimage, itCountsReord );
                ReshapeIntoGrid
                ( snapCtrl.realSize, snapCtrl.imagSize, itCountsReord, 
                  itCountMap );
            }
        }
        if( numSave )
        {
            std::ostringstream os;
            os << snapCtrl.numBase << "-" << numIts;
            Write( estMap, os.str(), snapCtrl.numFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, os.str()+"-counts", snapCtrl.numFormat );
            snapCtrl.numSaveCount = 0;
        }
        if( imgSave || imgDisp )
            EntrywiseMap( estMap, []( Real alpha ) { return Log(alpha); } );
        if( imgSave )
        {
            std::ostringstream os;
            os << snapCtrl.imgBase << "-" << numIts;
            Write( estMap, os.str(), snapCtrl.imgFormat );
            if( snapCtrl.itCounts )
                Write( itCountMap, os.str()+"-counts", snapCtrl.imgFormat );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Write( estMap, os.str()+"-discrete", snapCtrl.imgFormat );
            SetColorMap( colorMap );
            snapCtrl.imgSaveCount = 0;
        }
        if( imgDisp )
        {
            std::ostringstream os;
            os << snapCtrl.imgBase << "-" << numIts;
            Display( estMap, os.str() );       
            if( snapCtrl.itCounts )
                Display( itCountMap, os.str()+"-counts" );
            auto colorMap = GetColorMap();
            SetColorMap( GRAYSCALE_DISCRETE );
            Display( estMap, os.str()+"-discrete" );
            SetColorMap( colorMap );
            snapCtrl.imgDispCount = 0;
        }
    }
}
Exemple #13
0
 WhiteBlackMap::WhiteBlackMap() : DefaultColorMap("GreyScale")
 {
     SetColorMap(false, SC_ColorSpec(0.95, 0.95, 0.95), SC_ColorSpec(0.1,  0.1, 0.1));
 }
Exemple #14
0
 ColdHotMap::ColdHotMap() : DefaultColorMap("Cold->Hot")
 {
     SetColorMap(true, SC_ColorSpec(0.65,  1.0, 1.0), SC_ColorSpec(0.0,  1.0, 1.0));
 }