Commit 0982d95b authored by kirov's avatar kirov
Browse files

Further development.



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@26 45c4679d-1946-429d-baad-37912b19538b
parent e92ff84c
......@@ -2,6 +2,7 @@
#define FRAMEBUILDER_H
#include <vector>
#include "SizeUtils.h"
namespace lima {
......@@ -16,22 +17,23 @@ struct GaussPeak {
class FrameBuilder {
public:
int bin_X, bin_Y;
int width, height, depth;
std::vector<struct GaussPeak> peaks;
double inc;
int m_bin_X, m_bin_Y;
FrameDim m_frame_dim;
FrameBuilder();
FrameBuilder( int bin_X, int bin_Y, int width, int height, int depth,
std::vector<struct GaussPeak> &peaks );
FrameBuilder( int bin_X, int bin_Y, FrameDim &frame_dim,
std::vector<struct GaussPeak> &peaks, double grow_factor );
~FrameBuilder();
void getNextFrame( unsigned char *ptr );
unsigned long getFrameNr();
void resetFrameNr( int frame_nr=0 );
unsigned long getCurrFrameNr();
private:
unsigned long _frame_nr;
std::vector<struct GaussPeak> m_peaks;
double m_grow_factor;
unsigned long m_frame_nr;
int writeFrameData( unsigned char *ptr );
double dataXY( int x, int y );
......
......@@ -4,6 +4,7 @@
#include <sys/time.h>
#include <unistd.h>
#include "FrameBuilder.h"
#include "SizeUtils.h"
using namespace lima;
using namespace std;
......@@ -11,25 +12,26 @@ using namespace std;
FrameBuilder::FrameBuilder()
{
bin_X = 1;
bin_Y = 1;
width = height = 1024;
depth = 2;
m_bin_X = 1;
m_bin_Y = 1;
m_frame_dim = FrameDim(1024, 1024, Bpp16);
GaussPeak p={512, 512, 100, 1};
peaks.push_back(p);
this->_frame_nr = 0;
m_peaks.push_back(p);
m_grow_factor = 0.0;
m_frame_nr = 0;
}
FrameBuilder::FrameBuilder( int bin_X, int bin_Y,
int width, int height, int depth,
std::vector<struct GaussPeak> &peaks ):
bin_X(bin_X), bin_Y(bin_Y),
width(width), height(height), depth(depth),
peaks(peaks)
FrameDim &frame_dim,
std::vector<struct GaussPeak> &peaks,
double grow_factor ):
m_bin_X(bin_X), m_bin_Y(bin_Y),
m_frame_dim(frame_dim),
m_peaks(peaks),
m_grow_factor( grow_factor )
{
this->_frame_nr = 0;
m_frame_nr = 0;
}
......@@ -40,16 +42,26 @@ FrameBuilder::~FrameBuilder()
void FrameBuilder::resetFrameNr(int frame_nr)
{
this->_frame_nr = frame_nr;
m_frame_nr = frame_nr;
}
unsigned long FrameBuilder::getCurrFrameNr()
unsigned long FrameBuilder::getFrameNr()
{
return this->_frame_nr;
return m_frame_nr;
}
/*
FrameDim& FrameBuilder::getFrameDim() {
return m_frame_dim;
}
void FrameBuilder::setFrameDim(FrameDim &frame_dim) {
m_frame_dim = frame_dim;
}
*/
#define SGM_FWHM 0.42466090014400952136075141705144 // 1/(2*sqrt(2*ln(2)))
double gauss2D( double x, double y, double x0, double y0, double fwhm, double max )
......@@ -64,7 +76,7 @@ double FrameBuilder::dataXY( int x, int y )
double value=0.0;
vector<GaussPeak>::iterator p;
for( p = peaks.begin( ); p != peaks.end( ); ++p) {
for( p = m_peaks.begin( ); p != m_peaks.end( ); ++p) {
value += gauss2D(x, y, p->x0, p->y0, p->fwhm, p->max);
}
return value;
......@@ -80,7 +92,7 @@ int FrameBuilder::writeFrameData(unsigned char *ptr)
unsigned long *p4;
switch( depth ) {
switch( m_frame_dim.getDepth() ) {
case 1 :
p1 = (unsigned char *) ptr;
break;
......@@ -94,10 +106,10 @@ int FrameBuilder::writeFrameData(unsigned char *ptr)
return -1;
}
for( y=0; y<height; y++ ) {
for( x=0; x<width; x++ ) {
for( y=0; y<m_frame_dim.getSize().getHeight(); y++ ) {
for( x=0; x<m_frame_dim.getSize().getWidth(); x++ ) {
data = dataXY(x, y);
switch( depth ) {
switch( m_frame_dim.getDepth() ) {
case 1 :
*p1 = (unsigned char) (255.0 * data);
p1++;
......@@ -124,6 +136,6 @@ void FrameBuilder::getNextFrame( unsigned char *ptr )
if( ret < 0 ) {
// throw an exception
} else {
_frame_nr++;
m_frame_nr++;
}
}
......@@ -105,13 +105,13 @@ void Simulator::getExpTime(double& exp_time)
void Simulator::setBin(Bin bin)
{
m_frame_builder.bin_X = bin.getX();
m_frame_builder.bin_Y = bin.getY();
m_frame_builder.m_bin_X = bin.getX();
m_frame_builder.m_bin_Y = bin.getY();
}
void Simulator::getBin(Bin& bin)
{
bin = Bin(m_frame_builder.bin_X, m_frame_builder.bin_Y);
bin = Bin(m_frame_builder.m_bin_X, m_frame_builder.m_bin_Y);
}
Simulator::Status Simulator::getStatus()
......
......@@ -14,7 +14,7 @@ LDFLAGS = -pthread
all: clean test testsimulator
test: $(test-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(test-ext-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(test-ext-objs) $(std-objs)
testsimulator: $(testsimulator-objs)
$(CXX) $(LDFLAGS) -o $@ $+ $(testsimulator-ext-objs)
......
#include <vector>
#include <exception>
#include "FrameBuilder.h"
#include "BufferSave.h"
#include "SizeUtils.h"
#include "Exceptions.h"
using namespace std;
using namespace lima;
int main( void )
{
GaussPeak p[2]={{333, 512, 50, 1}, {666, 512, 100, 1}};
vector<GaussPeak> pv( p, p + sizeof(p)/sizeof(*p) );
FrameBuilder fb, fb2(1, 1, 1024, 1024, 2, pv);
FrameBuilder fb;
BufferSave bs("boza", FMT_EDF);
FrameInfoType finfo;
unsigned char *_buffer;
unsigned char *buffer;
FrameDim fd = fb.m_frame_dim;
_buffer = NULL;
buffer = NULL;
try {
int size = fb.width*fb.height*fb.depth;
_buffer = new unsigned char[size];
int size = fd.getSize().getWidth()*
fd.getSize().getHeight()*
fd.getDepth();
buffer = new unsigned char[size];
} catch( bad_alloc& ) {
/* ??? */
goto end;
}
for( int i=0; i<5; i++ ) {
fb.getNextFrame( _buffer );
fb.getNextFrame( buffer );
finfo.acq_frame_nb = fb.getCurrFrameNr();
finfo.frame_ptr = _buffer;
finfo.width = fb.width;
finfo.height = fb.height;
finfo.depth = fb.depth;
finfo.acq_frame_nb = fb.getFrameNr();
finfo.frame_ptr = buffer;
finfo.width = fd.getSize().getWidth();
finfo.height = fd.getSize().getHeight();
finfo.depth = fd.getDepth();
finfo.frame_time_stamp = 0; /* XXX */
bs.writeFrame(finfo);
}
if( _buffer )
delete[] _buffer;
end:
if( buffer )
delete[] buffer;
return 0;
}
......@@ -15,5 +15,13 @@ int main(int argc, char *argv[])
simu.stopAcq();
cout << "simu=" << simu << endl;
simu.setExpTime(5);
cout << "simu=" << simu << endl;
simu.startAcq();
cout << "simu=" << simu << endl;
simu.stopAcq();
cout << "simu=" << simu << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment