示例#1
0
文件: main.c 项目: hrsalles/kohonen
void init (void) {
    glViewport(0, 0, imgGetWidth(image), imgGetHeight(image));

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, imgGetWidth(image), 0, imgGetHeight(image));
    glMatrixMode(GL_MODELVIEW);
}
/* function called when the canvas is exposed in the screen.  self is the iuphandle of the canvas */
int repaint_cb(Ihandle *self) 
{
  int x,y;
  IupGLMakeCurrent(self);                /* all OpenGL primitives will be directed to this canvas */
  glClearColor(0.3f, 0.3f, 0.3f, 1.0f);  /* dark grey color in the RGBA mode A is the alpha channel (ignore) */
  glClear(GL_COLOR_BUFFER_BIT);          /* clear the color buffer */

  if (gc.image!=NULL) 
  {
	  int h = imgGetHeight(gc.image);
	  int w = imgGetWidth(gc.image);
	  /* assing to each pixel of the canvas the color of the corresponding pixel in the image */
	  glBegin(GL_POINTS);   
	  for (y=0;y<h;y++) {
		  for (x=0;x<w;x++) {
			  float r,g,b;
			  imgGetPixel3f(gc.image,x,y,&r,&g,&b); /* gets the RGB value the pixel (x,y) */ 
			  glColor3f(r,g,b);        /* define a current color in OpenGL */
			  glVertex2i(x,y);         /* paint the pixel */
		  }

	  }
	  glEnd();
  }
  IupGLSwapBuffers(self);  /* change the back buffer with the front buffer */
  return IUP_DEFAULT; /* returns the control to the main loop */
}
示例#3
0
Environment::Environment(float initialPheromone, float minimumPheromone, float evaporationRate, Image* attributeImage, DirectionalField* directionalField) :
_evaporationRate(evaporationRate), _initialPheromone(initialPheromone), _minimumPheromone(minimumPheromone)
{
    _maximumPheromone = MAX_PHEROMONE;
    construct( imgGetHeight( attributeImage ), imgGetWidth( attributeImage ) );
    computeImageMatrix( attributeImage );
    clearFeromone();
    _directionalField = directionalField;
}
示例#4
0
Environment::Environment( float initialPheromone, float minimumPheromone, float evaporationRate, Image* image ):
_evaporationRate(evaporationRate), _initialPheromone(initialPheromone), _minimumPheromone(minimumPheromone)
{
    _maximumPheromone = MAX_PHEROMONE;
    construct( imgGetHeight( image ), imgGetWidth( image ) );
    computeImageMatrix( image );
    clearFeromone();
    _directionalField = new DirectionalField( image, Parameters::dirOpenKernelRadius, Parameters::dirCloseKernelRadius );
    _directionalField->debugImages();
}
示例#5
0
void Colony::addAntInImage( Image* probabilityImage )
{
    float* probabilities = imgGetData( probabilityImage );
    int pixel = Ant::pickIndex( probabilities, _environment->getWidth()*_environment->getHeight() );
    int width = imgGetWidth( probabilityImage );
    Point chosenPoint( pixel % width, pixel / width );
    Ant* ant = new Ant( chosenPoint, _environment );
    ant->setStepLength( STEP_LENGTH );
    ant->setPheromoneWeight( PHEROMONE_WEIGHT );
    ant->setVisibilityWeight( VISIBILITY_WEIGHT );
    _ants.push_back( ant );
}
示例#6
0
void Colony::spawnAnt( int a )
{
    //chooses new spawn point for ant number "a"
    int nGammaImages = _probabilityDistributions.size();
    Image* probabilityImage = _probabilityDistributions[a % nGammaImages];
    float* probabilities = imgGetData( probabilityImage );
    int pixel = Ant::pickIndex( probabilities, _environment->getWidth()*_environment->getHeight() );
    int width = imgGetWidth( probabilityImage );
    int chosenX = pixel % width;
    int chosenY = pixel / width;
    
    //teleports the ant there
    _ants[a]->setPosition( chosenX, chosenY );
    _ants[a]->eraseMemory();
}
示例#7
0
Image* Colony::generateProbabilityImage( Image* input )
{
    if (imgGetDimColorSpace( input ) != 1) return 0;
    
    Image* output = imgCopy( input );
    float* data = imgGetData( output );
    int size = imgGetWidth( output ) * imgGetHeight( output );
    float sum = 0;
    for (int i = 0; i < size; ++i)
    {
        sum += data[i];
    }
    for (int i = 0; i < size; ++i)
    {
        data[i] /= sum;
    }
    
    return output;
}
示例#8
0
/* - Callback de repaint do canvas  */
int repaint_cb(Ihandle *self)
{
	int w,h;
	int x,y;
	Color rgb;

	if (yc==0){  /* e' a primeira vez: limpa o canvas */
		IupGLMakeCurrent(self);
		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glClear(GL_COLOR_BUFFER_BIT);
		IupGLSwapBuffers(self);  /* change the back buffer with the front buffer */
		glFlush();
	}

	if (yc!=height) { /* esta callback so'desenha depois que o algoritmo termina a imagem */
		return IUP_DEFAULT; 
	}

	w = imgGetWidth(image);
	h = imgGetHeight(image);
	IupGLMakeCurrent(self);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	glBegin(GL_POINTS);
	for (y=0;y<h;y++) {
		for (x=0; x<w; x++) {
			rgb = imageGetPixel(image, x, y);
			glColor3f((float)rgb.red,(float)rgb.green,(float)rgb.blue);
			glVertex2i(x,y);
		}
	}
	glEnd();

	IupGLSwapBuffers(self);  /* change the back buffer with the front buffer */

	glFlush();
	return IUP_DEFAULT; /* retorna o controle para o gerenciador de eventos */
} 
示例#9
0
Color matGetDiffuse( Material* material, Vector textureCoordinate )
{
	int x;
	int y;
	int width;
	int height;

	if( material->texture == NULL )
	{
		return material->diffuseColor;
	}

	width = imgGetWidth(material->texture);
	height = imgGetHeight(material->texture);

	//imageGetDimensions( material->texture, &width, &height );
	
	x = ( (int)( textureCoordinate.x * ( width - 1 ) ) % width );
	y = ( (int)( textureCoordinate.y * ( height - 1 ) ) % height );

	return imageGetPixel( material->texture, x, y );
}
示例#10
0
文件: main.c 项目: hrsalles/kohonen
int main (int argc, char* argv[]) {
    unsigned char threshold;
    image = imgLoadJPG("images/atlas5.jpg");

    if (image) {
        glutInit(&argc, argv);

        glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE);
        glutInitWindowSize(imgGetWidth(image), imgGetHeight(image));

        threshold = imgGetOtsuThreshold(image);

        imgThresholded(image, threshold);

        glutCreateWindow("Image view");
        glutDisplayFunc(main_display);

        init();
        glutMainLoop();
    } else printf("Error opening the image!\n");

    return 0;
}
示例#11
0
int load_cb(void)
{
	char* file_name = IupSelectFile("File Selection","*.bmp","Load a BMP file");
    if (!file_name) {
        IupSetfAttribute(gc.msgbar, "TITLE", "Selection failed"); 
		return IUP_DEFAULT;
	}

	if (gc.image!=NULL) imgDestroy(gc.image);
   
	gc.image=imgReadBMP(file_name);  /* loads the image */
	if (gc.image!=NULL) {
	   gc.width = imgGetWidth(gc.image);
	   gc.height = imgGetHeight(gc.image);
	   IupCanvasResize(gc.canvas,gc.dialog,gc.width,gc.height);
	   repaint_cb(gc.canvas);
       IupSetfAttribute(gc.msgbar, "TITLE", "%s", strip_path_from_filename(file_name));

	} else
	   IupSetfAttribute(gc.msgbar, "TITLE", "Can't open %s", strip_path_from_filename(file_name)); 

	return IUP_DEFAULT;
}
示例#12
0
Image* Colony::generateProbabilityImage( Image* input )
{
    if (imgGetDimColorSpace( input ) != 1) return 0;
    
    Image* output = imgCopy( input );
    float* data = imgGetData( output );
    int size = imgGetWidth( output ) * imgGetHeight( output );
    float sum = 0;
    for (int i = 0; i < size; ++i)
    {
//        if (isnan(data[i]))
//        {
//            printf( "Cannot generate probability image, NAN detected! on pixel %d\n", i );
//        }
        sum += data[i];
    }
    for (int i = 0; i < size; ++i)
    {
        data[i] /= sum;
    }
    
    return output;
}