Changeset 151 in flair-src for trunk/lib


Ignore:
Timestamp:
Mar 1, 2017, 3:38:42 PM (8 years ago)
Author:
Sanahuja Guillaume
Message:

add timestamp to simucamera producer

Location:
trunk/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/SimuCamera.cpp

    r150 r151  
    1919#include <FrameworkManager.h>
    2020#include <GroupBox.h>
    21 #include <SpinBox.h>
    22 //#include <cvimage.h>
    2321#include <SharedMem.h>
    2422#include <sstream>
     
    3230namespace sensor {
    3331
     32//control part
    3433SimuCamera::SimuCamera(string name,
    3534                       uint16_t width, uint16_t height, uint8_t channels,
     
    3736    : Thread(getFrameworkManager(), name, priority),
    3837      Camera(name, width, height, cvimage::Type::Format::BGR) {
    39 //  data_rate =
    40 //      new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 200, 1, 50);
    4138
    42   buf_size = width * height * channels;
     39  buf_size = width * height * channels+sizeof(Time);
    4340
    44   img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
    45   output->img->imageData = img->imageData;
     41  shmemReadBuf=(char*)malloc(buf_size);
     42  output->img->imageData = shmemReadBuf;
    4643
    4744  ostringstream dev_name;
     
    5047}
    5148
     49//simulation part
    5250SimuCamera::SimuCamera(const IODevice *parent, string name, uint16_t width,
    5351                       uint16_t height, uint8_t channels, uint32_t dev_id)
    5452    : Thread(parent, name, 0), Camera(parent,name) {
    55 //  data_rate = NULL;
    5653
     54  buf_size = width * height * channels+sizeof(Time);
     55 
    5756  ostringstream dev_name;
    5857  dev_name << "simu_cam_" << dev_id;
    5958  shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
    60                         width * height * channels, SharedMem::Type::producerConsumer);
     59                        buf_size, SharedMem::Type::producerConsumer);
     60  shmemReadBuf=NULL;
    6161}
    6262
     
    6464  SafeStop();
    6565  Join();
     66  if(shmemReadBuf!=NULL) delete shmemReadBuf;
    6667}
    6768
    6869void SimuCamera::Run(void) {
     70  Time time;
    6971//  if (data_rate == NULL) {
    7072//    Thread::Err("not applicable for simulation part.\n");
     
    8486    output->GetMutex();
    8587    //blocking read
    86     shmem->Read((char *)img->imageData, buf_size); // remplacer copie par
     88    shmem->Read(shmemReadBuf, buf_size); // remplacer copie par
    8789                                                   // échange de pointeur sur
    8890                                                   // double buffering
    8991    output->ReleaseMutex();
    90 
    91     output->SetDataTime(GetTime());
     92    memcpy(&time,shmemReadBuf+buf_size-sizeof(Time),sizeof(Time));
     93    output->SetDataTime(time);
    9294
    9395    ProcessUpdate(output);
  • trunk/lib/FlairSensorActuator/src/SimuCamera.h

    r144 r151  
    2121  namespace core {
    2222    class SharedMem;
    23   }
    24   namespace gui {
    25     class SpinBox;
    2623  }
    2724}
     
    9996  void UpdateFrom(const core::io_data *data){};
    10097
    101   gui::SpinBox *data_rate;
    10298  size_t buf_size;
    103   IplImage *img;
     99  char* shmemReadBuf;
    104100};
    105101} // end namespace sensor
  • trunk/lib/FlairSimulator/src/Model_impl.cpp

    r148 r151  
    204204
    205205  nodeOrientation.ToEuler(euler);
    206   ISceneNode::setRotation(Euler::ToDegree(1) *
    207                           vector3df(euler.roll, euler.pitch, euler.yaw));
     206  ISceneNode::setRotation(Euler::ToDegree(1) * vector3df(euler.roll,euler.pitch, euler.yaw));
    208207
    209208  if (position_init == false) {
  • trunk/lib/FlairSimulator/src/SimuCameraGL.cpp

    r147 r151  
    5959  index = 0;
    6060
    61   buffer = (char *)malloc(width * height * 3);
    62 
    6361  // user interface
    6462  Tab *setup_tab = new Tab(parent->GetTabWidget(), name);
     
    8684    glGenBuffersARB(PBO_COUNT, pboIds);
    8785    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[0]);
    88     glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, width * height * 3, 0,
     86    glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, width * height * 3+sizeof(Time), 0,
    8987                    GL_STREAM_READ_ARB);
    9088    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[1]);
    91     glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, width * height * 3, 0,
     89    glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, width * height * 3+sizeof(Time), 0,
    9290                    GL_STREAM_READ_ARB);
    9391
     
    9593  } else {
    9694    use_pbo = false;
     95    buffer = (char *)malloc(width * height * 3+sizeof(Time));
    9796    Thread::Warn("GL_ARB_pixel_buffer_object is not suppoorted\n");
    9897  }
     
    106105
    107106SimuCameraGL::~SimuCameraGL() {
    108   free(buffer);
    109 
    110107  if (use_pbo) {
    111108    glDeleteBuffersARB(PBO_COUNT, pboIds);
    112109    free(pboIds);
     110  } else {
     111    free(buffer);
    113112  }
    114113}
     
    151150    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
    152151    glReadPixels(x, y, width, height, GL_BGR, GL_UNSIGNED_BYTE, 0);
    153 
     152    Time time=GetTime();
    154153    // map the PBO that contain framebuffer pixels before processing it
    155154    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
     
    157156        GL_PIXEL_PACK_BUFFER_ARB, GL_READ_WRITE_ARB); // GL_READ_ONLY_ARB);
    158157    if (src) {
    159       putImage((char *)src);
     158      putImage((char *)src,time);
    160159      glUnmapBufferARB(
    161160          GL_PIXEL_PACK_BUFFER_ARB); // release pointer to the mapped buffer
     
    164163  } else {
    165164    glReadPixels(x, y, width, height, GL_BGR, GL_UNSIGNED_BYTE, buffer);
    166     putImage(buffer);
     165    putImage(buffer,GetTime());
    167166  }
    168167
     
    173172}
    174173
    175 void SimuCameraGL::putImage(char *buf) {
     174void SimuCameraGL::putImage(char *buf,Time imageTime) {
    176175  if (invert_pixel == true) {
    177176    // opengl images are horizontally flipped, so we have to fix that here.
     
    189188    delete[] tmpBuffer;
    190189  }
    191 
    192   shmem->Write(buf, width * height * 3);
     190  memcpy(buf+width * height * 3,&imageTime,sizeof(Time));
     191  shmem->Write(buf, width * height * 3+sizeof(Time));
    193192}
    194193
  • trunk/lib/FlairSimulator/src/SimuCameraGL.h

    r15 r151  
    6767                                  irr::scene::ISceneManager *newManager = 0);
    6868  void getImage(void);
    69   void putImage(char *pixels);
     69  void putImage(char *pixels,core::Time imageTime);
    7070  irr::scene::ICameraSceneNode *camera;
    7171  irr::scene::ISceneManager *smgr;
Note: See TracChangeset for help on using the changeset viewer.