Exemplo n.º 1
0
void OutputTraceChunks(GridMesh<TraceChunk> &traceChunks, const char *fileName) {
  //ofstream out("flow_0_data_chunks.txt");
  ofstream out(fileName);

  int rowStart,rowEnd,colStart, colEnd;      
  //      for (size_t bIx = 0; bIx < traceChunks.GetNumBin(); bIx++) {
  for (size_t bIx = 0; bIx < 1; bIx++) {
    traceChunks.GetBinCoords(bIx, rowStart, rowEnd, colStart, colEnd);
    TraceChunk &tc = traceChunks.GetItem(bIx);
    float sum = 0;
    for (int i = 0; i < tc.mTime.npts(); i++) {
      sum += tc.mTime.deltaFrameSeconds[i];
    }
    for (int row = rowStart; row < rowEnd; row++) {
      for (int col = colStart; col < colEnd; col++) {
        out << row << "\t" << col;
        for (size_t frame = 0; frame < tc.mDepth; frame++) {
          out << "\t" << tc.At(row, col, frame);
        }
        out << endl;
      }
    }
  }
  out.close();
}
Exemplo n.º 2
0
void HiKinectApp::update()
{
	if( mKinect.checkNewDepthFrame() ) {
		mDepthTexture = mKinect.getDepthImage();
		mDepthSurface = Surface32f( mKinect.getDepthImage() );
		mKinectReady = true;
		if ( !mKinectIR ) {
			mKinectIR = true;
			mKinect.setVideoInfrared( true );
		}
		
		ci::Surface captureSurface = Surface8u( mKinect.getDepthImage() );
		ci::Surface outputSurface = captureSurface;
		mContours->clear();
		mSilhouetteDetector->processSurface(&captureSurface, mContours, &outputSurface);
	}
	
	if( mKinect.checkNewColorFrame() )
		mColorTexture = mKinect.getVideoImage();
	
	if( mIsMouseDown ) // using small number instead of 0.0 because lights go black after a few seconds when going to 0.0f
		mDirectional -= ( mDirectional - 0.00001f ) * 0.1f;  
	else 
		mDirectional -= ( mDirectional - 1.0f ) * 0.1f;
	
	if (mKinectReady)
		mGridMesh.updateKinect(mKinect);
	else
		mGridMesh.update();
}
Exemplo n.º 3
0
void Traces::CalcReference(int rowStep, int colStep, GridMesh<std::vector<float> > &gridReference) {
  gridReference.Init(mRow, mCol, rowStep, colStep);
  int numBin = gridReference.GetNumBin();
  int rowStart = -1, rowEnd = -1, colStart = -1, colEnd = -1;
  for (int binIx = 0; binIx < numBin; binIx++) {
    gridReference.GetBinCoords(binIx, rowStart, rowEnd, colStart, colEnd);
    vector<float> &trace = gridReference.GetItem(binIx);
    CalcRegionReference(MaskEmpty, rowStart, rowEnd, colStart, colEnd, trace);
  }
}
Exemplo n.º 4
0
void OutputSigmaTmidEstimates(GridMesh<SigmaEst> &sigmaTMid, const char *fileName) {
  ofstream out(fileName);
  int rowStart,rowEnd,colStart, colEnd;      
  out << "rowStar" << "\t" << "rowEnd" << "\t" << "colStart" << "\t" << "colEnd" << "\t" << "sigma.t0.est" << "\t" << "tmidnuc.t0.est" << "\t" << "t0.est" << "\t" << "rate" <<endl;
  for (size_t bIx = 0; bIx < sigmaTMid.GetNumBin(); bIx++) {            
    sigmaTMid.GetBinCoords(bIx, rowStart, rowEnd, colStart, colEnd);
    SigmaEst &est = sigmaTMid.GetItem(bIx);
    out << rowStart << "\t" << rowEnd << "\t" << colStart << "\t" << colEnd << "\t" << est.mSigma << "\t" << est.mTMidNuc << "\t" << est.mT0 << "\t" << est.mRate << endl;
  }
  out.close();
}
Exemplo n.º 5
0
int TraceStoreCol::CalcMedianReference (size_t row, size_t col,
                           GridMesh<std::vector<float> > &regionMed,
                           std::vector<double> &dist,
                           std::vector<std::vector<float> *> &values,
                           std::vector<float> &reference) {
    int retVal = TraceStore::TS_OK;
    reference.resize(mFrames);
    std::fill(reference.begin(), reference.end(), 0.0);
    regionMed.GetClosestNeighbors (row, col, mUseMeshNeighbors, dist, values);
    int num_good = 0;
    size_t valSize = values.size();
    for (size_t i =0; i < valSize; i++) {
      if (values[i]->size() > 0) {
        num_good++;
      }
    }
    // try reaching a little farther if no good reference close by
    if (num_good == 0) {
      regionMed.GetClosestNeighbors (row, col, 2*mUseMeshNeighbors, dist, values);
    }
    size_t size = 0;
    double maxDist = 0;
    for (size_t i = 0; i < values.size(); i++) {
        size = max (values[i]->size(), size);
        maxDist = max(dist[i], maxDist);
    }
    reference.resize (size);
    std::fill (reference.begin(), reference.end(), 0.0);
    double distWeight = 0;
         valSize = values.size();

    for (size_t i = 0; i < valSize; i++) {
      if (values[i]->size()  == 0) {
        continue;
      }
      double w = TraceStore::WeightDist (dist[i], mRowRefStep); //1/sqrt(dist[i]+1);
      distWeight += w;
      size_t vSize = values[i]->size();
      for (size_t j = 0; j < vSize; j++) {
        reference[j] += w * values[i]->at (j);
      }
    }
    // Divide by our total weight to get weighted mean
    if (distWeight > 0)  {
      for (size_t i = 0; i < reference.size(); i++) {
        reference[i] /= distWeight;
      }
      retVal = TraceStore::TS_OK;
    }
    else {
      retVal = TraceStore::TS_BAD_DATA;
    }
    return retVal;
  }
Exemplo n.º 6
0
void BFReference::FilterForOutliers(Image &bfImg, Mask &mask, float iqrThreshold, int rowStep, int colStep) {
  const RawImage *raw = bfImg.GetImage();
  GridMesh<float> grid;
  grid.Init(raw->rows, raw->cols, rowStep, colStep);
  int numBin = grid.GetNumBin();
  int rowStart = -1, rowEnd = -1, colStart = -1, colEnd = -1;
  for (int binIx = 0; binIx < numBin; binIx++) {
    grid.GetBinCoords(binIx, rowStart, rowEnd, colStart, colEnd);
    FilterRegionOutliers(bfImg, mask, iqrThreshold, rowStart, rowEnd, colStart, colEnd);
  }
}
Exemplo n.º 7
0
void BFReference::FillInReference(std::vector<char> &wells, 
				  std::vector<float> &metric,
				  GridMesh<int> &grid,
				  double minQuantile,
				  double maxQuantile,
                                  int numWells) {
  int rStart = -1, rEnd = -1, cStart = -1, cEnd = -1;
  for (size_t bIx = 0; bIx < grid.GetNumBin(); bIx++) {
    grid.GetBinCoords(bIx, rStart, rEnd, cStart, cEnd);
    FillInRegionRef(rStart, rEnd, cStart, cEnd,
		    metric, minQuantile, maxQuantile,numWells, wells);
  }
} 
Exemplo n.º 8
0
void Traces::CalcIncorporationStartReference(int nRowStep, int nColStep, 
                                             GridMesh<SampleStats<float> > &grid) {
  grid.Init(mRow, mCol, nRowStep, nColStep);

  int numBin = grid.GetNumBin();
  int rowStart = -1, rowEnd = -1, colStart = -1, colEnd = -1;
  for (int binIx = 0; binIx < numBin; binIx++) {
    SampleStats<float> &startStat = grid.GetItem(binIx);
    grid.GetBinCoords(binIx, rowStart, rowEnd, colStart, colEnd);
    CalcIncorpBreakRegionStart(rowStart, rowEnd,
			       colStart, colEnd,
                               startStat);
  }
}
Exemplo n.º 9
0
void TraceChunkSerializer::ArrangeDataForWriting(GridMesh<TraceChunk> &dataMesh, struct FlowChunk *chunks) {

  if (dataMesh.GetNumBin() == 0) {
    return;
  }
  size_t maxSize = dataMesh.mBins[0].mDepth * dataMesh.mBins[0].mHeight * dataMesh.mBins[1].mWidth * 3;
  int8_t *compressed = new int8_t[maxSize];
  compressMicroSec = 0;
  for (size_t bIx = 0; bIx < dataMesh.GetNumBin(); bIx++) {
    TraceChunk &tc = dataMesh.GetItem(bIx);
    struct FlowChunk &fc = chunks[bIx];
    fc.CompressionType = mCompressor->GetCompressionType();
    fc.RowStart = tc.mRowStart;
    fc.ColStart = tc.mColStart;
    fc.FrameStart = tc.mFrameStart;
    fc.FrameStep = tc.mFrameStep;
    fc.ChipRow = tc.mChipRow;
    fc.ChipCol = tc.mChipCol;
    fc.ChipFrame = tc.mChipFrame;
    fc.StartDetailedTime = tc.mStartDetailedTime;
    fc.StopDetailedTime = tc.mStopDetailedTime;
    fc.LeftAvg = tc.mLeftAvg;
    fc.OrigFrames = tc.mOrigFrames;
    fc.T0 = tc.mT0;
    fc.Sigma = tc.mSigma;
    fc.TMidNuc = tc.mTMidNuc;
    fc.Height = tc.mHeight;
    fc.Width = tc.mWidth;
    fc.Depth = tc.mDepth;
    fc.BaseFrameRate = tc.mBaseFrameRate;
    size_t outsize;
    ClockTimer timer;
    mCompressor->Compress(tc, &compressed, &outsize, &maxSize);
    compressMicroSec += timer.GetMicroSec();
    //cout <<"Doing: " << fc.CompressionType << " Bytes per wells: " << outsize/(float) (tc.mHeight * tc.mWidth) <<" Compression ratio: "<< tc.mData.size()*2/(float)outsize << endl;
    fc.Data.p = (int8_t *)malloc(outsize*sizeof(int8_t));
    memcpy(fc.Data.p, compressed, outsize*sizeof(int8_t));
    fc.Data.len = outsize;
    if (0 == outsize) {
      cout << "How can there be zero blocks." << endl;
    }
    float * tmp = (float *)malloc(tc.mTimePoints.size() * sizeof(float));
    copy(tc.mTimePoints.begin(), tc.mTimePoints.end(), tmp);
    fc.DeltaFrame.p = tmp;
    fc.DeltaFrame.len = tc.mTimePoints.size() * sizeof(float);
  }
  delete [] compressed;
}
Exemplo n.º 10
0
bool Traces::CalcStartFrame(size_t row, size_t col, 
                            GridMesh<SampleStats<float> > &regionStart, float &start) {
  std::vector<double> dist(7);
  std::vector<SampleStats<float> *> values;
  bool allOk = false;
  regionStart.GetClosestNeighbors(row, col, mUseMeshNeighbors, dist, values);
  double distWeight = 0;
  double startX = 0;
  start = 0;
  for (size_t i = 0; i < values.size(); i++) {
    if (values[i]->GetCount() > 0) {
      double w = WeightDist(dist[i]); //1/sqrt(dist[i] + 1);
      distWeight += w;
      startX += w * values[i]->GetMean();
    }
  }

  if (distWeight > 0 && start >= 0) {
    start = startX / distWeight;
    if (startX >= 0 && isfinite(startX)) {
      allOk = true; 
    }
  }

  return allOk;
}
Exemplo n.º 11
0
void GenerateDataChunks(TraceConfig &config, T0Calc &t0, const struct RawImage *raw, 
                        int rowStep, int colStep, GridMesh<SigmaEst> &sigmaTMid,
                        GridMesh<TraceChunk> &mTraceChunks, Image &img) {
  mTraceChunks.Init(raw->rows, raw->cols, rowStep, colStep);
  int rowStart,rowEnd,colStart, colEnd;
  size_t frameStep = raw->rows * raw->cols;
  int16_t *frameBuff[raw->frames];
  for (int i = 0; i < raw->frames; i++) {
    frameBuff[i] = raw->image + (i * frameStep);
  }
  for (size_t bIx = 0; bIx < t0.GetNumRegions(); bIx++) {
    SigmaEst &est = sigmaTMid.GetItem(bIx);
    t0.GetRegionCoords(bIx, rowStart, rowEnd, colStart, colEnd);
    TraceChunk &chunk = mTraceChunks.GetItem(bIx);
    float t0Time = t0.GetT0(bIx);
    chunk.mSigma = est.mSigma;
    chunk.mTMidNuc = est.mTMidNuc;
    t0Time -= config.time_start_slop;
    chunk.mStartDetailedTime = config.start_detailed_time;
    chunk.mStopDetailedTime = config.stop_detailed_time;
    chunk.mLeftAvg = config.left_avg;
    chunk.mOrigFrames = raw->frames;
    chunk.mT0 = t0Time/raw->baseFrameRate;
    // Old style using t0 instead of tmid nuc
    chunk.mTime.SetUpTime(raw->uncompFrames, chunk.mT0, chunk.mStartDetailedTime, chunk.mStopDetailedTime, chunk.mLeftAvg);
    chunk.mBaseFrameRate = raw->baseFrameRate;
    chunk.mTimePoints.resize(chunk.mTime.mTimePoints.size());
    copy(chunk.mTime.mTimePoints.begin(), chunk.mTime.mTimePoints.end(), chunk.mTimePoints.begin());
    chunk.mTime.SetupConvertVfcTimeSegments(raw->frames, raw->timestamps, raw->baseFrameRate, raw->rows * raw->cols);
    //    if (bIx == t0.GetNumRegions() /2) {
      // cout << "Setup Frames: ";
      // float deltaFrame = 0;
      // for (int i = 0; i < chunk.mTime.npts(); i++) {
      //   deltaFrame += chunk.mTime.deltaFrame[i];
      //   cout << "\t" << deltaFrame;
      // }
      // cout << endl;
      // chunk.mTime.WriteLinearTransformation(raw->rows * raw->cols);
      //    }
    chunk.SetChipInfo(raw->rows, raw->cols, raw->frames);
    chunk.SetDimensions(rowStart, rowEnd-rowStart, colStart, colEnd-colStart, 0, chunk.mTime.npts());
    chunk.ZeroData();
    chunk.mTime.ConvertVfcSegmentsOpt(rowStart, rowEnd, colStart, colEnd, 
                                      raw->rows, raw->cols, raw->frames,
                                      frameBuff, &chunk.mData[0]);
  }
}
Exemplo n.º 12
0
void HiKinectApp::draw3D() {
	
	gl::setMatrices( mCamUI.getCamera() );
	if (mWireframe) gl::enableWireframe();
	else gl::disableWireframe();
	
	if (mLighting) {
		glEnable( GL_LIGHTING );
		glEnable( GL_LIGHT0 );
	}
//	GLfloat light_position[] = { mMousePos.x, mMousePos.y, -275.0f, 0.0f };
	GLfloat light_position[] = { 0, 0, 1.0f, 0.0f };
	glLightfv( GL_LIGHT0, GL_POSITION, light_position );
	if( DIFFUSE ){
		ci::ColorA color( CM_RGB, 1.0f, 1.0f, 1.0f, 1.0f );
		glMaterialfv( GL_FRONT, GL_DIFFUSE,	color );
	} else {
		glMaterialfv( GL_FRONT, GL_DIFFUSE,	no_mat );
	}
	
	if( AMBIENT )
		glMaterialfv( GL_FRONT, GL_AMBIENT,	mat_ambient );
	else
		glMaterialfv( GL_FRONT, GL_AMBIENT,	no_mat );
	
	if( SPECULAR ){
		glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
		glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );
	} else {
		glMaterialfv( GL_FRONT, GL_SPECULAR, no_mat );
		glMaterialfv( GL_FRONT, GL_SHININESS, no_shininess );
	}
	
	if( EMISSIVE )
		glMaterialfv( GL_FRONT, GL_EMISSION, mat_emission );
	else
		glMaterialfv( GL_FRONT, GL_EMISSION, no_mat );
	
	if (mDepthTexture)
		mDepthTexture.bind(0);
	mFbo.bindTexture(1);
	if (mColorTexture)
		mColorTexture.bind(2);
	
	mGridMesh.draw( lmap(mMousePos.x, 0.0f, (float)getWindowWidth(), 0.0f, 1.0f) );
	
	if (mLighting) {
		glDisable( GL_LIGHTING );
		glDisable( GL_LIGHT0 );
	}
	
	gl::disableWireframe();
}
Exemplo n.º 13
0
void TraceChunkSerializer::DecompressFromReading(const struct FlowChunk *chunks, GridMesh<TraceChunk> &dataMesh) {
  compressMicroSec = 0;
  for (size_t bIx = 0; bIx < dataMesh.GetNumBin(); bIx++) {
    TraceChunk &tc = dataMesh.GetItem(bIx);
    const struct FlowChunk &fc = chunks[bIx];
    if (mCompressor == NULL) {
      if (mDebugMsg) { cout << "Got compression type: " << chunks[bIx].CompressionType << endl;}
      mCompressor = CompressorFactory::MakeCompressor((TraceCompressor::CodeType)chunks[bIx].CompressionType);
    }
    ION_ASSERT(chunks[bIx].CompressionType == (size_t)mCompressor->GetCompressionType(), "Wrong compression type: " + ToStr(chunks[bIx].CompressionType) + " vs: " + ToStr(mCompressor->GetCompressionType()));
    tc.mRowStart = fc.RowStart;
    tc.mColStart = fc.ColStart;
    tc.mFrameStart = fc.FrameStart;
    tc.mFrameStep = fc.FrameStep;
    tc.mChipRow = fc.ChipRow;
    tc.mChipCol = fc.ChipCol;
    tc.mChipFrame = fc.ChipFrame;
    tc.mStartDetailedTime = fc.StartDetailedTime;
    tc.mStopDetailedTime = fc.StopDetailedTime;
    tc.mLeftAvg = fc.LeftAvg;
    tc.mOrigFrames = fc.OrigFrames;
    tc.mT0 = fc.T0;
    tc.mSigma = fc.Sigma;
    tc.mTMidNuc = fc.TMidNuc;
    tc.mHeight = fc.Height;
    tc.mWidth = fc.Width;
    tc.mDepth = fc.Depth;
    tc.mBaseFrameRate = fc.BaseFrameRate;
    size_t outsize = fc.Height * fc.Width * fc.Depth;
    tc.mData.resize(outsize);
    tc.mTimePoints.resize(tc.mDepth);
    float * tmp = (float *)fc.DeltaFrame.p;
    copy(tmp,tmp+fc.Depth, tc.mTimePoints.begin());
    ClockTimer timer;
    mCompressor->Decompress(tc, (int8_t *)fc.Data.p, fc.Data.len);
    compressMicroSec += timer.GetMicroSec();
    outsize = fc.Height * fc.Width * fc.Depth;
  }
}
Exemplo n.º 14
0
bool TraceChunkSerializer::Write(H5File &h5, GridMesh<TraceChunk> &dataMesh) {

  mNumChunks = dataMesh.GetNumBin();
  ClockTimer timer;
  mChunks = (struct FlowChunk *) malloc(sizeof(struct FlowChunk) * mNumChunks);
  ArrangeDataForWriting(dataMesh, mChunks);
  computeMicroSec = timer.GetMicroSec();
  hsize_t dims1[1];
  dims1[0] = mNumChunks;
  hid_t fcDataSpace = H5Screate_simple(1, dims1, NULL);
  hid_t charArrayType = H5Tvlen_create (H5T_NATIVE_CHAR);
  hid_t charArrayType2 = H5Tvlen_create (H5T_NATIVE_CHAR);
  hid_t fcType = H5Tcreate(H5T_COMPOUND, sizeof(struct FlowChunk));
  H5Tinsert(fcType, "CompressionType", HOFFSET(struct FlowChunk, CompressionType), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ChipRow", HOFFSET(struct FlowChunk, ChipRow), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ChipCol", HOFFSET(struct FlowChunk, ChipCol), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ChipFrame", HOFFSET(struct FlowChunk, ChipFrame), H5T_NATIVE_B64);
  H5Tinsert(fcType, "RowStart", HOFFSET(struct FlowChunk, RowStart), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ColStart", HOFFSET(struct FlowChunk, ColStart), H5T_NATIVE_B64);
  H5Tinsert(fcType, "FrameStart", HOFFSET(struct FlowChunk, FrameStart), H5T_NATIVE_B64);
  H5Tinsert(fcType, "FrameStep", HOFFSET(struct FlowChunk, FrameStep), H5T_NATIVE_B64);
  H5Tinsert(fcType, "Height", HOFFSET(struct FlowChunk, Height), H5T_NATIVE_B64);
  H5Tinsert(fcType, "Width", HOFFSET(struct FlowChunk, Width), H5T_NATIVE_B64);
  H5Tinsert(fcType, "Depth", HOFFSET(struct FlowChunk, Depth), H5T_NATIVE_B64);
  H5Tinsert(fcType, "OrigFrames", HOFFSET(struct FlowChunk, OrigFrames), H5T_NATIVE_B64);
  H5Tinsert(fcType, "StartDetailedTime", HOFFSET(struct FlowChunk, StartDetailedTime), H5T_NATIVE_INT);
  H5Tinsert(fcType, "StopDetailedTime", HOFFSET(struct FlowChunk, StopDetailedTime), H5T_NATIVE_INT);
  H5Tinsert(fcType, "LeftAvg", HOFFSET(struct FlowChunk, LeftAvg), H5T_NATIVE_INT);
  H5Tinsert(fcType, "T0", HOFFSET(struct FlowChunk, T0), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "Sigma", HOFFSET(struct FlowChunk, Sigma), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "TMidNuc", HOFFSET(struct FlowChunk, TMidNuc), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "BaseFrameRate", HOFFSET(struct FlowChunk, BaseFrameRate), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "DeltaFrame", HOFFSET(struct FlowChunk, DeltaFrame), charArrayType2);
  H5Tinsert(fcType, "Data", HOFFSET(struct FlowChunk, Data), charArrayType);
  timer.StartTimer();
  hid_t dataset = H5Dcreate2(h5.GetFileId(), "FlowChunk", fcType, fcDataSpace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  herr_t status = H5Dwrite(dataset, fcType, H5S_ALL, H5S_ALL, H5P_DEFAULT, mChunks);
  status = H5Dvlen_reclaim(fcType, fcDataSpace, H5P_DEFAULT, mChunks);
  //  //  delete [] mChunks;
  free(mChunks);
  mChunks = NULL;
  ION_ASSERT(status == 0, "Couldn't write dataset");
  H5Tclose(fcType);
  H5Tclose(charArrayType);
  H5Tclose(charArrayType2);
  H5Sclose(fcDataSpace);
  H5Dclose(dataset);
  ioMicroSec += timer.GetMicroSec();
  return status == 0;
}
Exemplo n.º 15
0
void HiKinectApp::setup()
{
	console() << "There are " << Kinect::getNumDevices() << " Kinects connected." << std::endl;
	
	mKinect = Kinect( Kinect::Device() );
	mKinectReady = false;
	mKinectIR = false;
	
	mNormalShader = gl::GlslProg( loadResource( "normal_vert.glsl" ), loadResource( "normal_frag.glsl" ) );
	mNormalStrength = 20.0f;
	
	gl::Fbo::Format format;
	mFbo = gl::Fbo( CAPTURE_WIDTH, CAPTURE_HEIGHT, format );
	
	mSilhouetteDetector = new SilhouetteDetector(640,480);
	mContours = new vector<vector<cv::Point> >();
	
	mDoNormalMap = false;
	
	mParams = params::InterfaceGl( "Parameters", Vec2i( 300, 200 ) );
	mParams.addParam( "NormalStrength", &mNormalStrength, "min=1.0 max=1000.0 step=1.0 keyIncr=z keyDecr=Z" );
	mParams.addParam( "Depth Scale", &mGridMesh.mDepthScale, "min=1.0 max=2000.0" );
	mParams.addParam( "Depth Offset", &mGridMesh.mDepthOffset, "min=0.0 max=1000.0" );
	mParams.addParam( "Shader Displacement", &mGridMesh.mShaderDisplacement );
	mParams.addParam( "Depth Max", &mGridMesh.mDepthMax, "min=0.0 max=1.0 step=0.01" );
	mParams.addParam( "Generate Normal Map", &mDoNormalMap );
	
	mGridMesh.init(160, 120, 640, 480, false, true);
	mIsMouseDown = false;
	mWireframe = true;
	
	DIFFUSE		= true;
	AMBIENT		= false;
	SPECULAR	= false;
	EMISSIVE	= false;
	
	mCamera.setEyePoint( Vec3f(0.0f, 0.0f, 750.0f));
	mCamera.setCenterOfInterestPoint( Vec3f::zero() );
	mCamera.setPerspective( 60, getWindowAspectRatio(), 1, 2000 );
	mCamUI.setCurrentCam( mCamera );
	
	gl::enableDepthWrite();
	gl::enableDepthRead();
}
Exemplo n.º 16
0
int Traces::CalcMedianReference(int row, int col, 
				GridMesh<std::vector<float> > &regionMed,
				std::vector<double> &dist,
				std::vector<std::vector<float> *> &values,
				std::vector<float> &reference) {
  int retVal = OK;
  // vector<float> &binVal = regionMed.GetItemByRowCol(row,col);
  // if (binVal.size() > 0) {
  //   reference.resize(binVal.size());
  //   copy(binVal.begin(), binVal.end(), reference.begin());
  //   return OK;
  // }
  regionMed.GetClosestNeighbors(row, col, mUseMeshNeighbors, dist, values);
  size_t size = 0;
  for (size_t i = 0; i < values.size(); i++) {
    size = max(values[i]->size(), size);
  }
  reference.resize(size);
  fill(reference.begin(), reference.end(), 0.0);
  double distWeight = 0;
  size_t valSize = values.size();
  for (size_t i = 0; i < valSize; i++) {
    if (values[i]->size()  == 0) {
      continue;
    }
    double w = WeightDist(dist[i]); //1/sqrt(dist[i]+1);
    distWeight += w;
    size_t vSize = values[i]->size();
    for (size_t j = 0; j < vSize; j++) {
      reference[j] += w * values[i]->at(j);
    }
  }
  // Divide by our total weight to get weighted mean
  if (distWeight > 0) {
    for (size_t i = 0; i < reference.size(); i++) {
      reference[i] /= distWeight;
    }
    retVal = OK;
  }
  else {
    retVal = BAD_DATA;
  }
  return retVal;
}
Exemplo n.º 17
0
bool TraceChunkSerializer::Read(H5File &h5, GridMesh<TraceChunk> &dataMesh) {
  hid_t dataset = H5Dopen2(h5.GetFileId(), "FlowChunk", H5P_DEFAULT);
  //    hid_t datatype  = H5Dget_type(dataset);     /* datatype handle */
  static pthread_once_t onceControl = PTHREAD_ONCE_INIT;
  int err = pthread_once(&onceControl, InitSdatReadSem);
  if (err != 0) { cout << "Error with pthread once." << endl; }               
  hid_t dataspace = H5Dget_space(dataset);
  int rank = H5Sget_simple_extent_ndims(dataspace);
  std::vector<hsize_t> dims;
  dims.resize(rank);
  int status = H5Sget_simple_extent_dims(dataspace, &dims[0], NULL);
  if (mChunks != NULL) {
    delete [] mChunks;
  }
  mChunks = new FlowChunk[dims[0]];
  mNumChunks = dims[0];
  hid_t fcDataSpace = H5Screate_simple(1, &dims[0], NULL);
  hid_t charArrayType = H5Tvlen_create (H5T_NATIVE_CHAR);
  hid_t charArrayType2 = H5Tvlen_create (H5T_NATIVE_CHAR);
  hid_t fcType = H5Tcreate(H5T_COMPOUND, sizeof(struct FlowChunk));
  H5Tinsert(fcType, "CompressionType", HOFFSET(struct FlowChunk, CompressionType), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ChipRow", HOFFSET(struct FlowChunk, ChipRow), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ChipCol", HOFFSET(struct FlowChunk, ChipCol), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ChipFrame", HOFFSET(struct FlowChunk, ChipFrame), H5T_NATIVE_B64);
  H5Tinsert(fcType, "RowStart", HOFFSET(struct FlowChunk, RowStart), H5T_NATIVE_B64);
  H5Tinsert(fcType, "ColStart", HOFFSET(struct FlowChunk, ColStart), H5T_NATIVE_B64);
  H5Tinsert(fcType, "FrameStart", HOFFSET(struct FlowChunk, FrameStart), H5T_NATIVE_B64);
  H5Tinsert(fcType, "FrameStep", HOFFSET(struct FlowChunk, FrameStep), H5T_NATIVE_B64);
  H5Tinsert(fcType, "Height", HOFFSET(struct FlowChunk, Height), H5T_NATIVE_B64);
  H5Tinsert(fcType, "Width", HOFFSET(struct FlowChunk, Width), H5T_NATIVE_B64);
  H5Tinsert(fcType, "Depth", HOFFSET(struct FlowChunk, Depth), H5T_NATIVE_B64);
  H5Tinsert(fcType, "OrigFrames", HOFFSET(struct FlowChunk, OrigFrames), H5T_NATIVE_B64);
  H5Tinsert(fcType, "StartDetailedTime", HOFFSET(struct FlowChunk, StartDetailedTime), H5T_NATIVE_INT);
  H5Tinsert(fcType, "StopDetailedTime", HOFFSET(struct FlowChunk, StopDetailedTime), H5T_NATIVE_INT);
  H5Tinsert(fcType, "LeftAvg", HOFFSET(struct FlowChunk, LeftAvg), H5T_NATIVE_INT);
  H5Tinsert(fcType, "T0", HOFFSET(struct FlowChunk, T0), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "Sigma", HOFFSET(struct FlowChunk, Sigma), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "TMidNuc", HOFFSET(struct FlowChunk, TMidNuc), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "BaseFrameRate", HOFFSET(struct FlowChunk, BaseFrameRate), H5T_NATIVE_FLOAT);
  H5Tinsert(fcType, "DeltaFrame", HOFFSET(struct FlowChunk, DeltaFrame), charArrayType2);
  H5Tinsert(fcType, "Data", HOFFSET(struct FlowChunk, Data), charArrayType);
  ClockTimer timer;
  IonImageSem::Take();
  status = H5Dread(dataset, fcType, H5S_ALL, H5S_ALL, H5P_DEFAULT, mChunks);
  IonImageSem::Give();
  ioMicroSec = timer.GetMicroSec();
  ION_ASSERT(status == 0, "Couldn' read dataset");
  timer.StartTimer();
  dataMesh.Init(mChunks[0].ChipRow, mChunks[0].ChipCol, mChunks[0].Height, mChunks[0].Width);
  ION_ASSERT(dataMesh.GetNumBin() == mNumChunks, "Didn't get number of chunks expected");
  DecompressFromReading(mChunks, dataMesh);
  computeMicroSec = timer.GetMicroSec();
  timer.StartTimer();
  status = H5Dvlen_reclaim(fcType, fcDataSpace, H5P_DEFAULT, mChunks);
  delete [] mChunks;
  mChunks = NULL;
  H5Tclose(fcType);
  H5Tclose(charArrayType);
  H5Tclose(charArrayType2);
  H5Sclose(fcDataSpace);
  H5Dclose(dataset);
  ioMicroSec += timer.GetMicroSec();
  return status == 0;
}
Exemplo n.º 18
0
int main(int argc, const char *argv[]) {
  OptArgs opts;  
  TraceConfig config;
  string inputDir;
  string outputDir;
  bool help;

  opts.ParseCmdLine(argc, argv);
  opts.GetOption(inputDir, "", '-', "source-dir");
  opts.GetOption(outputDir, "", '-', "output-dir");
  opts.GetOption(config.precision, "5", '-', "precision");
  opts.GetOption(config.numEvec, "7", '-', "num-evec");
  opts.GetOption(config.doDebug, "false", '-', "debug-files");
  opts.GetOption(config.compressionType, "delta", '-', "compression");
  opts.GetOption(config.numFlows, "-1", '-', "num-flows");
  opts.GetOption(config.numCores, "6", '-', "num-cores");
  opts.GetOption(config.errCon,"0",'-',"err-con");
  opts.GetOption(config.rankGood,"0",'-',"rank-good");
  opts.GetOption(config.pivot,"0",'-',"pivot");
  opts.GetOption(help, "false", 'h', "help");
  opts.GetOption(config.isThumbnail, "false", '-', "thumbnail");
  opts.GetOption(config.use_hard_est, "false",'-', "use-hard-est");
  opts.GetOption(config.t0_hard, "0", '-', "t0-hard");
  opts.GetOption(config.tmid_hard, "0", '-', "tmid-hard");
  opts.GetOption(config.sigma_hard, "0", '-', "sigma-hard");
  opts.GetOption(config.row_step, "100", '-', "row-step");
  opts.GetOption(config.col_step, "100", '-', "col-step");
  opts.GetOption(config.bg_param, "", '-', "region-param");
  opts.GetOption(config.grind_acq_0, "0", '-', "grind-acq0");
  if(help || inputDir.empty() || outputDir.empty()) {
    usage();
  }
  char *explog_path = NULL;
  explog_path = MakeExpLogPathFromDatDir(inputDir.c_str());
  int numFlows = config.numFlows;
  if (numFlows < 0) { 
    numFlows = GetTotalFlows(explog_path); 
  }

  // Check and setup our compression type
  TraceChunkSerializer serializer;
  serializer.SetRecklessAbandon(true);
  if (config.compressionType == "svd") {
    SvdDatCompress *dc = new SvdDatCompress(config.precision, config.numEvec);
    serializer.SetCompressor(dc);
    cout << "Doing lossy svd compression. (" << serializer.GetCompressionType() << ")" << endl;
  }
  // else if (config.compressionType == "svd+") {
  //   SvdDatCompressPlus *dc = new SvdDatCompressPlus();
  //   serializer.SetCompressor(dc);
  //   cout << "Doing lossy svd compression. (" << serializer.GetCompressionType() << ")" << endl;
  // }
  // else if (config.compressionType == "svd++") {
  //   SvdDatCompressPlusPlus *dc = new SvdDatCompressPlusPlus();
  //   if (config.errCon >0 )
  //     dc->SetErrCon(config.errCon);
  //   if (config.rankGood > 0 )
  //     dc->SetRankGood(config.rankGood);
  //   if (config.pivot > 0)
  //     dc->SetPivot(config.pivot);
  //   serializer.SetCompressor(dc);
  //   cout << "Doing lossy svd compression for good traces and delta for bad ones. (" << serializer.GetCompressionType() << ")" << endl;
  // }
  else if (config.compressionType == "delta") {
    VencoLossless *venco = new VencoLossless();
    serializer.SetCompressor(venco);
    cout << "Doing lossless delta compression. (" << serializer.GetCompressionType() << ")" << endl;
  }
  else if (config.compressionType == "delta-plain") {
    DeltaComp *delta = new DeltaComp();
    serializer.SetCompressor(delta);
    cout << "Doing lossless delta plain compression. (" << serializer.GetCompressionType() << ")" << endl;
  }
  else if (config.compressionType == "delta-plain-fst") {
    DeltaCompFst *delta = new DeltaCompFst();
    serializer.SetCompressor(delta);
    cout << "Doing lossless delta plain fast compression. (" << serializer.GetCompressionType() << ")" << endl;
  }
  else if (config.compressionType == "delta-plain-fst-smx") {
   DeltaCompFstSmX *delta = new DeltaCompFstSmX();
    serializer.SetCompressor(delta);
    cout << "Doing lossless delta plain fast compression. (" << serializer.GetCompressionType() << ")" << endl;
  }
  else if (config.compressionType == "none") {
    TraceCompressor *vanilla = new TraceNoCompress();
    serializer.SetCompressor(vanilla);
    cout << "Doing no compression. (" << serializer.GetCompressionType() << ")" << endl;
  }
  else {
    ION_ABORT("Don't recognize compression type: " + config.compressionType);
  }

  const char *id = GetChipId(explog_path);
  if (explog_path) free (explog_path);
  ChipIdDecoder::SetGlobalChipId(id);
  ImageTransformer::CalibrateChannelXTCorrection(inputDir.c_str(), "lsrowimage.dat");

  Image bfImg1;
  string bfFile = inputDir + "/beadfind_pre_0003.dat";
  bfImg1.LoadRaw(bfFile.c_str());
  const RawImage *bf1raw = bfImg1.GetImage(); 
  Mask mask(bf1raw->cols, bf1raw->rows);
  ImageTransformer::XTChannelCorrect(bfImg1.raw,bfImg1.results_folder);

  bfImg1.FilterForPinned (&mask, MaskEmpty, false);

  Image bfImg2;
  string bfFile2 = inputDir + "/beadfind_pre_0001.dat";
  bfImg2.LoadRaw(bfFile2.c_str());
  ImageTransformer::XTChannelCorrect(bfImg2.raw,bfImg1.results_folder);

  bfImg2.FilterForPinned (&mask, MaskEmpty, false);
  const RawImage *bf2raw = bfImg2.GetImage(); 


  GridMesh<T0Prior> t0Prior;
  T0Calc bfT0;
  /* Calc t0 and get prior. */
  cout << "Doing beadfind t0" << endl;
  GenerateBfT0Prior(config, bf1raw->image, bf1raw->baseFrameRate, bf1raw->rows, bf1raw->cols,
                    bf1raw->frames, bf1raw->timestamps,
                    config.row_step, config.col_step, &mask, bfT0, t0Prior);

  GridMesh<T0Prior> t0Prior2;
  T0Calc bfT02;
  GenerateBfT0Prior(config, bf2raw->image, bf2raw->baseFrameRate, bf2raw->rows, bf2raw->cols,
                    bf2raw->frames, bf2raw->timestamps,
                    config.row_step, config.col_step, &mask, bfT02, t0Prior2);

  SigmaTMidNucEstimation sigmaEst;
  sigmaEst.Init(config.rate_sigma_intercept, config.rate_sigma_slope, 
                config.t0_tmid_intercept, config.t0_tmid_slope, bf1raw->baseFrameRate);
  GridMesh<SigmaEst> sigmaTMid;
  bfImg1.Close();
  bfImg2.Close();

  // Calculate individual well t0 by looking at neighboring regions
  vector<float> wellT0;
  bfT0.CalcIndividualT0(wellT0, 0);
  vector<float> wellT02;
  bfT02.CalcIndividualT0(wellT02, 0);
  for (size_t i =0; i< wellT0.size();i++) {
    if (wellT0[i] > 0 && wellT02[i] > 0) {
      wellT0[i] = (wellT0[i] + wellT02[i])/2.0f;
    }
    else {
      wellT0[i] = max(wellT0[i], wellT02[i]);
    }
  }

  // Average the region level t0, should we do this first and then just do sinle well level?
  for (size_t bIx = 0; bIx < bfT0.GetNumRegions(); bIx++) {
    double t1 = bfT0.GetT0(bIx);
    double t2 = bfT02.GetT0(bIx);
    if (t1 > 0 && t2 > 0) {
      t1 = (t1 + t2)/2.0;
    }
    else {
      t1 = max(t1,t2);
    }
    bfT0.SetT0(bIx, t1);
  }

  // Single thread first dat
  for (size_t datIx = 0; datIx < 1; ++datIx) {
    cout << "Doing: " << datIx << endl;
    char buffer[2048];
    snprintf(buffer, sizeof(buffer), "%s/acq_%.4d.dat", inputDir.c_str(), (int) datIx);
    string datFile = buffer;
    /* Use prior to calculate t0 and slope. */
    Image datImg;
    T0Calc t0;
    datImg.LoadRaw(datFile.c_str());
    //    ImageTransformer::XTChannelCorrect(datImg.raw,datImg.results_folder);
    const RawImage *datRaw = datImg.GetImage(); 

    /* Estimate sigma and t_mid_nuc */
    if (datIx == 0) {
      cout << "Doing acquisition t0" << endl;

      GenerateAcqT0Prior(config, datRaw->image, datRaw->baseFrameRate, datRaw->rows, datRaw->cols,
                         datRaw->frames, datRaw->timestamps,
                         config.row_step, config.col_step, &mask, t0, t0Prior);
      
      ClockTimer timer;
      cout << "Estimating sigma." << endl;
      sigmaTMid.Init(datRaw->rows, datRaw->cols, config.row_step, config.col_step);
      for (size_t bIx = 0; bIx < t0.GetNumRegions(); bIx++) {
        t0.SetT0(bIx, bfT0.GetT0(bIx));
      }
      int neighbors = 2;
      if (config.isThumbnail) {
        cout << "Doing thumbnail version of slope." << endl;
        neighbors = 1;
      }
      EstimateSigmaValue(t0, sigmaEst, sigmaTMid, neighbors);
      timer.PrintMilliSeconds(cout,"Sigma Est took:");
      string sigmaFile = outputDir + "/sigma_tmid_est.txt";
      OutputSigmaTmidEstimates(sigmaTMid, sigmaFile.c_str());
    }

    /* For each region do shifting */
    ClockTimer timer;
    cout << "Shifting traces" << endl;
    timer.StartTimer();
    //    ShiftTraces(bfT0, wellT0, datRaw->frames, datRaw->baseFrameRate, datRaw->timestamps, datRaw->image);
    timer.PrintMilliSeconds(cout,"Shift took:");
    if (!config.bg_param.empty()) {
      DataCube<int> rowsCols;
      DataCube<float> tmidSigma;
      DataCube<float> fitTmidSigma;
      string path = config.bg_param + ":/region/region_location";
      if (!H5File::ReadDataCube(path, rowsCols)) {
        ION_ABORT("Couldn't read file: " + path);
      }
      path = config.bg_param + ":/region/region_init_param";
      if (!H5File::ReadDataCube(path, fitTmidSigma)) {
        ION_ABORT("Couldn't read file: " + path);
      }
      for (size_t i = 0; i < rowsCols.GetNumX(); i++) {
        int row = rowsCols.At(i,1,0);
        int col = rowsCols.At(i,0,0);
        SigmaEst &est = sigmaTMid.GetItemByRowCol(row, col);
        float tmid_est =  fitTmidSigma.At(i,0,0);
        float sigma_est = fitTmidSigma.At(i,1,0);
        est.mTMidNuc = tmid_est;
        est.mSigma = sigma_est;
      }
      string fitSigmaFile = outputDir + "/bg_fit_sigma_tmid_est.txt";
      OutputSigmaTmidEstimates(sigmaTMid, fitSigmaFile.c_str());

      // path = config.bg_param + ":/region/region_init_param";
      // if (!H5File::ReadMatrix(path, tmidSigma)) {
      //   ION_ABORT("Couldn't read file: " + path);
      // }
      // for (size_t i = 0; i < rowsCols.n_rows; i++) {
      //   int row = rowsCols.at(i,0);
      //   int col = rowsCols.at(i,1);
      //   SigmaEst &est = sigmaTMid.GetItemByRowCol(row, col);
      //   float tmid_est =  tmidSigma.at(i,0);
      //   float sigma_est = tmidSigma.at(i,1);
      //   est.mTMidNuc = tmid_est;
      //   est.mSigma = sigma_est;
      // }
      // string sigmaFile = outputDir + "/supplied_sigma_tmid_est.txt";
      // OutputSigmaTmidEstimates(sigmaTMid, sigmaFile.c_str());
    }
    else if (config.use_hard_est) {
      for (size_t i = 0; i < bfT0.GetNumRegions(); i++) {
        bfT0.SetT0(i,config.t0_hard * datRaw->baseFrameRate + config.time_start_slop);
      }
      for (size_t i = 0; i < sigmaTMid.GetNumBin(); i++) {
        SigmaEst &est = sigmaTMid.GetItem(i);
        est.mTMidNuc = config.tmid_hard;
        est.mSigma = config.sigma_hard;
        est.mT0 = config.t0_hard;
      }
    }
    /* Use t0 and sigma to get the time compression bkgModel wants. */
    cout << "Generating chunks" << endl;
    //    GridMesh<TraceChunk> traceChunks;
    SynchDat sdat;
    if (datIx == 0  && config.grind_acq_0 > 0) {
      int nTimes = config.grind_acq_0;
      timer.StartTimer();
      size_t processMicroSec = 0;
      size_t hdf5MicroSec = 0;
      size_t compressMicroSec = 0;
      size_t convertMicroSec = 0;
      for (int i = 0; i <nTimes; i++) {
        //GridMesh<TraceChunk> traceChunken;
        SynchDat sdatIn;
        AddMetaData(sdat, datRaw, datIx);
	ClockTimer convTimer;
        GenerateDataChunks(config, bfT0, datRaw, config.row_step, config.col_step, sigmaTMid, sdatIn.mChunks,datImg);
	convertMicroSec += convTimer.GetMicroSec();
        snprintf(buffer, sizeof(buffer), "%s/acq_%.4d.sdat", outputDir.c_str(), (int)datIx);
        serializer.Write(buffer, sdatIn);
	processMicroSec += serializer.computeMicroSec;
	hdf5MicroSec += serializer.ioMicroSec;
	compressMicroSec += serializer.compressMicroSec;
      }
      size_t usec = timer.GetMicroSec();
      cout << "Took: " << usec / 1.0e6 << " seconds, " << usec / (nTimes * 1.0f) << " usec per write." << endl;
      timer.PrintMilliSeconds(cout,"Chunks took:");
      cout << "Read took: " << processMicroSec / (1e3 * nTimes) << " milli seconds per sdat compute." << endl;
      cout << "Read took: " << hdf5MicroSec / (1e3 * nTimes) << " milli seconds per sdat hdf5." << endl;
      cout << "Read took: " << compressMicroSec / (1e3 * nTimes) << " milli seconds per sdat compressing." << endl;
      cout << "Read took: " << convertMicroSec / (1e3 * nTimes) << " milli seconds per sdat converting." << endl;
      exit(0);
    }
    else {
      timer.StartTimer();
      AddMetaData(sdat, datRaw, datIx);
      GenerateDataChunks(config, bfT0, datRaw, config.row_step, config.col_step, sigmaTMid, sdat.mChunks,datImg);
      timer.PrintMilliSeconds(cout,"Chunks took:");
        if (datIx == 0 && config.doDebug) {
          OutputTraceChunks(sdat.mChunks,"flow_0_data_chunks.txt");
        }
    }
    datImg.Close();    

    /* Serialize onto disk. */
    snprintf(buffer, sizeof(buffer), "%s/acq_%.4d.sdat", outputDir.c_str(), (int)datIx);
    serializer.Write(buffer, sdat);
    /* Read back in first flow for checking */
    if (datIx == 0) {
      TraceChunkSerializer readSerializer;
      readSerializer.SetRecklessAbandon(true);
      //      GridMesh<TraceChunk> traceChunksIn;  
      SynchDat sdatIn;
      readSerializer.Read(buffer, sdatIn);
      if (datIx == 0 && config.doDebug) {
        OutputTraceChunks(sdatIn.mChunks, "flow_0_data_chunks_read.txt");
      }
      SampleQuantiles<float> s(50000);
      SampleQuantiles<float> s2(50000);
      SampleQuantiles<float> sAbs(50000);
      SampleStats<double> ss;
      int diffCount = 0;
      for (size_t bIx = 0; bIx < sdatIn.mChunks.mBins.size(); bIx++) {
        if (sdatIn.mChunks.mBins[bIx].mT0 != sdat.mChunks.mBins[bIx].mT0) {
          cout << "Got: " << sdatIn.mChunks.mBins[bIx].mT0 << " vs: " << sdat.mChunks.mBins[bIx].mT0 << endl;
          exit(1);
        }
        for (size_t i = 0; i < sdatIn.mChunks.mBins[bIx].mData.size(); i++) {
          double diff = (double)sdatIn.mChunks.mBins[bIx].mData[i] - (double)sdat.mChunks.mBins[bIx].mData[i];
          if (!std::isfinite(diff)) {
            cout << "NaNs!!" << endl;
          }
          if (diffCount < 10 && fabs(diff) > .00001) { // != 0) {
            diffCount++;
            cout << "Bin: " << bIx << " well: " << i << " diff is: " << diff << endl;
          }
          s.AddValue(diff);
          sAbs.AddValue(fabs(diff));
          ss.AddValue(sqrt(diff * diff));
          s2.AddValue(sqrt(diff * diff));
        }
      }
      cout << "Median rms: " << s2.GetMedian()  << " Avg: " << ss.GetMean() << " diff: " << s.GetMedian() << endl;
      cout << "Abs(diff) Quantiles:" << endl;
      for (size_t i = 0; i <= 100; i+=10) {
        cout << i << "\t" << sAbs.GetQuantile(i/100.0) << endl;
      }
    }      
  }
  // do the next N flows multithreaded
  if (numFlows > 1) {
    PJobQueue jQueue (config.numCores, numFlows-1);  
    vector<CreateSDat> jobs(numFlows -1);
    // for (int i = 0; i < 4; i++) {
    //   char buffer[2048];
    //   snprintf(buffer, sizeof(buffer), "%s/beadfind_pre_%.4d.dat", inputDir.c_str(), (int) i);
    //   string input = buffer;
    //   snprintf(buffer, sizeof(buffer), "%s/beadfind_pre_%.4d.sdat", outputDir.c_str(), (int)i);
    //   string output = buffer;
    //   jobs[i].Init(&config, input, output, &wellT0, &bfT0, &sigmaTMid);
    //   jQueue.AddJob(jobs[i]);
    // }

    // jQueue.WaitUntilDone();
    for (int i = 1; i < numFlows; i++) {
      char buffer[2048];
      snprintf(buffer, sizeof(buffer), "%s/acq_%.4d.dat", inputDir.c_str(), (int) i);
      string input = buffer;
      snprintf(buffer, sizeof(buffer), "%s/acq_%.4d.sdat", outputDir.c_str(), (int)i);
      string output = buffer;
      jobs[i-1].Init(&config, input, output, &wellT0, &bfT0, &sigmaTMid, i);
      jQueue.AddJob(jobs[i-1]);
    }
    jQueue.WaitUntilDone();
  }
  /* Serialize into backbround models */
  cout << "Done." << endl;
}
Exemplo n.º 19
0
void BFReference::CalcSignalReference2(const std::string &datFile, const std::string &bgFile,
				      Mask &mask, int traceFrame) {
  Image bfImg;
  Image bfBkgImg;
  bfImg.SetImgLoadImmediate (false);
  bfBkgImg.SetImgLoadImmediate (false);
  bool loaded = bfImg.LoadRaw(datFile.c_str());
  bool bgLoaded = bfBkgImg.LoadRaw(bgFile.c_str());
  if (!loaded) {
    ION_ABORT("*Error* - No beadfind file found, did beadfind run? are files transferred?  (" + datFile + ")");
  }
  if (!bgLoaded) {
    ION_ABORT("*Error* - No beadfind background file found, did beadfind run? are files transferred?  (" + bgFile + ")");
  }
  const RawImage *raw = bfImg.GetImage();
  
  assert(raw->cols == GetNumCol());
  assert(raw->rows == GetNumRow());
  assert(raw->cols == mask.W());
  assert(raw->rows == mask.H());
  int StartFrame = bfImg.GetFrame(-663); //5
  int EndFrame = bfImg.GetFrame(350); //20
  int NNinnerx = 1, NNinnery = 1, NNouterx = 12, NNoutery = 8;
  cout << "DC start frame: " << StartFrame << " end frame: " << EndFrame << endl;
  bfImg.FilterForPinned(&mask, MaskEmpty, false);
  bfImg.XTChannelCorrect();
  // bfImg.XTChannelCorrect(&mask);
  Traces trace;  
  trace.Init(&bfImg, &mask, FRAMEZERO, FRAMELAST, FIRSTDCFRAME,LASTDCFRAME);
  bfImg.Normalize(StartFrame, EndFrame);
  if (mDoRegionalBgSub) {
     trace.SetMeshDist(0);
  }
  trace.CalcT0(true);
  if (mDoRegionalBgSub) {
    GridMesh<float> grid;
    grid.Init(raw->rows, raw->cols, mRegionYSize, mRegionXSize);
    int numBin = grid.GetNumBin();
    int rowStart = -1, rowEnd = -1, colStart = -1, colEnd = -1;
    for (int binIx = 0; binIx < numBin; binIx++) {
      cout << "BG Subtract Region: " << binIx << endl;
      grid.GetBinCoords(binIx, rowStart, rowEnd, colStart, colEnd);
      Region reg;
      reg.row = rowStart;
      reg.h = rowEnd - rowStart;
      reg.col = colStart;
      reg.w = colEnd - colStart;
      bfImg.BackgroundCorrectRegion(&mask, reg, MaskAll, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL);
    }
  }
  else {
    bfImg.BackgroundCorrect(&mask, MaskEmpty, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL);
  }
  int length = GetNumRow() * GetNumCol();
  mBfMetric.resize(length, std::numeric_limits<double>::signaling_NaN());
  for (int wIx = 0; wIx < length; wIx++) {
    if (mask[wIx] & MaskExclude || mask[wIx] & MaskPinned) 
      continue;
    int t0 = (int)trace.GetT0(wIx);
    mBfMetric[wIx] = 0;
    float zSum  = 0;
    int count = 0;
    for (int fIx = min(t0-20, 0); fIx < t0-10; fIx++) {
      zSum += bfImg.At(wIx,fIx);
      count ++;
    }
    for (int fIx = t0+3; fIx < t0+15; fIx++) {
      mBfMetric[wIx] += (bfImg.At(wIx,fIx) - (zSum / count));
    }
  }
  bfImg.Close();
  for (int i = 0; i < length; i++) {
    if (mask[i] & MaskExclude || mWells[i] == Exclude) {
      mWells[i] = Exclude;
    }
    else {
      mask[i] = MaskIgnore;
    }
  }
  cout << "Filling reference. " << endl;
  FillInReference(mWells, mBfMetric, mGrid, mMinQuantile, mMaxQuantile, mNumEmptiesPerRegion);
  for (int i = 0; i < length; i++) {
    if (mWells[i] == Reference) {
      mask[i] = MaskEmpty;
    }
  }
}
Exemplo n.º 20
0
void BFReference::CalcReference(const std::string &datFile, Mask &mask, std::vector<float> &metric) {
  Image bfImg;
  bfImg.SetImgLoadImmediate (false);
  bool loaded = bfImg.LoadRaw(datFile.c_str());
  if (!loaded) {
    ION_ABORT("*Error* - No beadfind file found, did beadfind run? are files transferred?  (" + datFile + ")");
  }

  const RawImage *raw = bfImg.GetImage();
  
  assert(raw->cols == GetNumCol());
  assert(raw->rows == GetNumRow());
  assert(raw->cols == mask.W());
  assert(raw->rows == mask.H());
  if (!mDebugFile.empty()) {
    DebugTraces(mDebugFile, mask, bfImg);
  }
  bfImg.FilterForPinned(&mask, MaskEmpty, false);
  // int StartFrame= bfImg.GetFrame((GetDcStart()*1000/15)-1000);
  // int EndFrame = bfImg.GetFrame((GetDcEnd()*1000/15)-1000);
  int StartFrame = bfImg.GetFrame(-663); //5
  int EndFrame = bfImg.GetFrame(350); //20
  cout << "DC start frame: " << StartFrame << " end frame: " << EndFrame << endl;
  bfImg.XTChannelCorrect();
  FilterForOutliers(bfImg, mask, mIqrOutlierMult, mRegionYSize, mRegionXSize);
  bfImg.Normalize(StartFrame, EndFrame);
  // bfImg.XTChannelCorrect(&mask);

  int NNinnerx = 1, NNinnery = 1, NNouterx = 12, NNoutery = 8;
  if (mDoRegionalBgSub) {
    GridMesh<float> grid;
    grid.Init(raw->rows, raw->cols, mRegionYSize, mRegionXSize);
    int numBin = grid.GetNumBin();
    int rowStart = -1, rowEnd = -1, colStart = -1, colEnd = -1;
    for (int binIx = 0; binIx < numBin; binIx++) {
      grid.GetBinCoords(binIx, rowStart, rowEnd, colStart, colEnd);
      Region reg;
      reg.row = rowStart;
      reg.h = rowEnd - rowStart;
      reg.col = colStart;
      reg.w = colEnd - colStart;
      bfImg.BackgroundCorrectRegion(&mask, reg, MaskAll, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL);
    }
  }
  else {
    bfImg.BackgroundCorrect(&mask, MaskEmpty, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL);
  }
  Region region;
  region.col = 0;
  region.row = 0;
  region.w = GetNumCol(); //mGrid.GetColStep();
  region.h = GetNumRow(); // mGrid.GetRowStep();

  int startFrame = bfImg.GetFrame(12); // frame 15 on uncompressed 314
  //  int endFrame = bfImg.GetFrame(raw->timestamps[bfImg.Ge]5300); // frame 77 or so
  int endFrame = bfImg.GetFrame(5000); // frame 77 or so
  bfImg.CalcBeadfindMetric_1(&mask, region, "pre", startFrame, endFrame);
  const double *results = bfImg.GetResults();

  int length = GetNumRow() * GetNumCol();
  metric.resize(length);
  copy(&results[0], &results[0] + (length), metric.begin());
  bfImg.Close();
}