bool Value_Raw::put_Allocated( vuint32 inSize ) { vuint32 ByteSize = get_Allocated(); if( inSize == ByteSize ) { // Already allocated return true; } else if( inSize < ByteSize ) { if( TruncateTo(inSize) != inSize ) { return false; } } else { if( GrowBy(inSize - ByteSize) != inSize ) { return false; } } return true; }
void CArtifactsHandling::RemoveArtifacts() { int nNumNodes=m_lstArtifactSegments.size(); if(nNumNodes>1) ConcatenateArtifacts(); if(nNumNodes>0) ExtendDetectedArtifacts(); float fSlope,fFirstPoint,fLastPoint,fValue,fReturnValue,fAdjustedValue; float fBeginningOfArtifact,fEndOfArtifact; int nFirstPoint,nLastPoint,i; int nBegin=m_nBegin; int nEnd=m_nEnd; int nLag=0; int nArtifactType=0; float fMaxAmp=-10000.f; float fMinAmp=200.f; float nCutoff=3000./m_fSampleInterval; int nSize=m_lstArtifactSegments.size(); CArtifactSegmentDialog aDlg; list <structSegmentNode>::iterator pTemp; list <structSegmentNode>::iterator pTemp0; list <structSegmentNode>::iterator pTemp1; list <structSegmentNode>::iterator pTempI; int nIter=0; float fTime=0.f; pTemp=m_lstArtifactSegments.begin(); while(nIter<nSize) { nIter++; fFirstPoint=pTemp->fFirstPoint; fLastPoint=pTemp->fLastPoint; nFirstPoint=pTemp->nFirstPoint; fBeginningOfArtifact=0.001f*nFirstPoint*m_fSampleInterval; nLastPoint=pTemp->nLastPoint; fEndOfArtifact=0.001f*nLastPoint*m_fSampleInterval; nLag=nFirstPoint-nLastPoint-10; nArtifactType=pTemp->nArtifactType; bool bBurst; int nType1,nI0,nI1,nTemp1; switch(nArtifactType) { case -22: MakeBaseline(nFirstPoint, nLastPoint); break; case -52: //Remove a burst of small positive conductance; bBurst=false; nI0=pTemp->nFirstPoint; nLastPoint=pTemp->nLastPoint; pTemp1=pTemp; pTemp1++; nI1=pTemp1->nFirstPoint; nType1=pTemp1->nArtifactType; pTemp0=pTemp; while(nI1-nLastPoint<nCutoff&&nIter<nSize&&nType1==-52) { bBurst=true; pTemp++; nLastPoint=pTemp->nLastPoint; pTemp1=pTemp; pTemp1++; nI1=pTemp1->nFirstPoint; nTemp1=pTemp1->nArtifactType; nIter++; } if(bBurst) { fMaxAmp=-10000.; for(i=nI0;i<=nLastPoint;i++) { if(m_pfData[i]>fMaxAmp) fMaxAmp=m_pfData[i]; } if(fMaxAmp<=fMinAmp) MakeBaseline(nI0,nLastPoint); // for(pTempI=pTemp0;pTempI!=pTemp1;pTempI++) // { // nFirstPoint=pTempI->nFirstPoint; // nLastPoint=pTempI->nLastPoint; // fMaxAmp=-10000.; // for(i=nFirstPoint;i<=nLastPoint;i++) // { // if(m_pfData[i]>fMaxAmp) // fMaxAmp=m_pfData[i]; // } // if(fMaxAmp<=fMinAmp) // MakeBaseline(nI0,nLastPoint); // else break; // } // for(pTempI=pTemp1;pTempI!=pTemp0;pTempI--) // { // nFirstPoint=pTempI->nFirstPoint; // nLastPoint=pTempI->nLastPoint; // fMaxAmp=-10000.; // for(i=nFirstPoint;i<=nLastPoint;i++) // { // if(m_pfData[i]>fMaxAmp) // fMaxAmp=m_pfData[i]; // } // if(fMaxAmp<=fMinAmp) // MakeBaseline(nI0,nLastPoint); // else break; // } // } } break; case -62: //Remove a burst of small positive conductance; bBurst=false; nI0=pTemp->nFirstPoint; nLastPoint=pTemp->nLastPoint; pTemp1=pTemp; pTemp1++; nI1=pTemp1->nFirstPoint; nType1=pTemp1->nArtifactType; pTemp0=pTemp; while(nI1-nLastPoint<nCutoff&&nIter<nSize&&nType1==-52) { bBurst=true; pTemp++; nLastPoint=pTemp->nLastPoint; pTemp1=pTemp; pTemp1++; nI1=pTemp1->nFirstPoint; nTemp1=pTemp1->nArtifactType; nIter++; } fMaxAmp=-10000.; for(i=nI0;i<=nLastPoint;i++) { if(m_pfData[i]>fMaxAmp) fMaxAmp=m_pfData[i]; } if(fMaxAmp<=fMinAmp) MakeBaseline(nI0,nLastPoint); break; case -72: bBurst=false; nI0=pTemp->nFirstPoint; nLastPoint=pTemp->nLastPoint; pTemp1=pTemp; pTemp1++; nI1=pTemp1->nFirstPoint; nType1=pTemp1->nArtifactType; pTemp0=pTemp; while(nI1-nLastPoint<nCutoff&&nIter<nSize&&nType1==-52) { bBurst=true; pTemp++; nLastPoint=pTemp->nLastPoint; pTemp1=pTemp; pTemp1++; nI1=pTemp1->nFirstPoint; nTemp1=pTemp1->nArtifactType; nIter++; } fTime=0.001f*(nLastPoint-nI0)*m_fSampleInterval; if(fTime>6.) { fMaxAmp=-10000.; for(i=nI0;i<=nLastPoint;i++) { if(m_pfData[i]>fMaxAmp) fMaxAmp=m_pfData[i]; } if(fMaxAmp<=fMinAmp) MakeBaseline(nI0,nLastPoint); } break; default: if(m_bEntireTrace||nFirstPoint>=nBegin&&nLastPoint<=nEnd) { if(m_bDoNotConfirm) { // nFirstPoint=int(1000.f*fBeginningOfArtifact/m_fSampleInterval); // nLastPoint=int(1000.f*fEndOfArtifact/m_fSampleInterval); fSlope=(fLastPoint-fFirstPoint)/float(nLastPoint-nFirstPoint); for(i=nFirstPoint;i<nLastPoint;i++) { fValue=*(m_pfData+i); fReturnValue=fFirstPoint+fSlope*float(i-nFirstPoint); if(i+nLag<0) { fAdjustedValue=TruncateTo(fValue,fReturnValue,m_fRange); } else { fAdjustedValue=*(m_pfAdjustedData+i+nLag);; } *(m_pfAdjustedData+i)=fAdjustedValue; } } else { aDlg.SetParameters(fBeginningOfArtifact,fFirstPoint,fEndOfArtifact,fLastPoint,m_bDoNotConfirm); if(aDlg.DoModal()==IDOK) { aDlg.GetParameters(fBeginningOfArtifact,fFirstPoint,fEndOfArtifact,fLastPoint,m_bDoNotConfirm); nFirstPoint=int(1000.f*fBeginningOfArtifact/m_fSampleInterval); nLastPoint=int(1000.f*fEndOfArtifact/m_fSampleInterval); fSlope=(fLastPoint-fFirstPoint)/float(nLastPoint-nFirstPoint); for(i=nFirstPoint;i<nLastPoint;i++) { fValue=*(m_pfData+i); fReturnValue=fFirstPoint+fSlope*float(i-nFirstPoint); if(i+nLag<0) { fAdjustedValue=TruncateTo(fValue,fReturnValue,m_fRange); } else { fAdjustedValue=*(m_pfAdjustedData+i+nLag);; } *(m_pfAdjustedData+i)=fAdjustedValue; } } } } } pTemp++; } }