Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Draw stuff [SOLVED]
Re: Draw stuff [message #13935 is a reply to message #13903] |
Fri, 01 February 2008 23:41   |
Indio
Messages: 8 Registered: January 2008 Location: Hungary
|
Promising Member |
|
|
That's it. I have done some selections, only the important parts of the source are here.
MainWindow.h :
#include "Segmentation.h"
#include <CtrlLib/CtrlLib.h>
class Segmentation; // forward class declaration
class MainWindow : public TopWindow {
public:
typedef MainWindow CLASSNAME;
MainWindow( );
void OpenImage( );
ImageCtrl inImgctrl;
ImageCtrl outImgctrl;
Splitter h, v, v1, v2;
Button a;
One < StreamRaster > r;
Segmentation *segmentation;
};
MainWindow.cpp :
#include "MainWindow.h"
using namespace Upp;
//----------------------------
MainWindow::MainWindow( )
{
segmentation = NULL;
segmentation = new Segmentation( );
Title("Statistical Segmentation").Zoomable().Sizeable();
SetRect(0, 0, 900, 800);
h.Horz(a, v);
v.Vert(v1, v2 );
Add(h.SizePos());
v1.Add(inImgctrl);
}
//-----------------------------
void MainWindow::OpenImage( )
{
String fileName = "";
FileSel fs;
// If user selects a file to open, returns true
if ( fs.Type( "bitmap", "*.bmp").ExecuteOpen("Choose the image file to open") )
{
fileName = ~fs; // fileName contains the file name
if ( fileName != "" )
{
inImgctrl.SetImage( Null ); // maybe not necessary
FileIn in( fileName );
r = StreamRaster::OpenAny( in );
Image img = StreamRaster::LoadFileAny(~fileName);
if ( !r )
{
return; // invalid input
}
...
if ( segmentation->LoadImage( r ) )
{
outImgctrl.SetImage( segmentation->ib );
}
}
}
}
Segmentation.h :
#include "MainWindow.h"
#include <CtrlLib/CtrlLib.h>
class Segmentation {
public:
typedef Segmentation CLASSNAME;
Segmentation( );
// Does the evolution
bool Iteration( );
// Called from MainWindow, generates the matrix of the image
bool LoadImage( One < StreamRaster > streamRaster );
ImageBuffer ib;
// contains the intensities of the input image
int **picture;
protected:
void Init( One < StreamRaster > streamRaster );
};
Segmentation.cpp :
Segmentation::Segmentation( )
{
imageHeight = -1;
imageWidth = -1;
picture = NULL;
}
//----------------------------------
bool Segmentation::LoadImage( One < StreamRaster > r )
{
imageHeight = r->GetHeight();
imageWidth = r->GetWidth();
Init( r );
if ( (imageHeight != -1) && (imageWidth != -1) )
return true;
else
return false;
}
//-----------------------------------
void Segmentation::Init( One < StreamRaster > r )
{
// memory allocations
picture = new int* [imageWidth];
for ( int i = 0; i < imageWidth; i++ )
picture[i] = new int[imageHeight]; // the image intensities
// image -> matrix
for(int i = 0; i < imageHeight; i++) {
RasterLine l = r->GetLine(i);
for(int j = 0; j < imageWidth; j++) {
picture[i][j] = l[j].b;
}
}
...
// matrix -> image
ib(imageHeight, imageWidth);
for(int y = 0; y < imageWidth; y++) {
RGBA *l = ib[y];
for(int x = 0; x < imageHeight; x++) {
l->a = 255;
l->r = picture[y][x];
l->g = picture[y][x];
l->b = picture[y][x];
l++;
}
}
//Premultiply(ib);
}
I hope this is enough. Thanks!
[Updated on: Fri, 01 February 2008 23:42] Report message to a moderator
|
|
|
 |
|
Draw stuff [SOLVED]
By: Indio on Fri, 01 February 2008 05:21
|
 |
|
Re: Draw stuff
By: mrjt on Fri, 01 February 2008 11:19
|
 |
|
Re: Draw stuff
By: Indio on Fri, 01 February 2008 16:09
|
 |
|
Re: Draw stuff
By: mrjt on Fri, 01 February 2008 16:44
|
 |
|
Re: Draw stuff
By: Indio on Fri, 01 February 2008 21:38
|
 |
|
Re: Draw stuff
By: mirek on Fri, 01 February 2008 22:42
|
 |
|
Re: Draw stuff
By: Indio on Fri, 01 February 2008 23:41
|
 |
|
Re: Draw stuff
By: mrjt on Tue, 05 February 2008 11:03
|
 |
|
Re: Draw stuff
By: Indio on Tue, 05 February 2008 23:03
|
 |
|
Re: Draw stuff
By: Indio on Fri, 08 February 2008 16:02
|
 |
|
Re: Draw stuff
By: mrjt on Fri, 08 February 2008 17:00
|
 |
|
Re: Draw stuff
By: Indio on Fri, 08 February 2008 18:09
|
Goto Forum:
Current Time: Thu Aug 21 08:02:03 CEST 2025
Total time taken to generate the page: 0.04570 seconds
|