stereobuffer.cpp
资源名称:estereo2.zip [点击查看]
上传用户:fengshi120
上传日期:2014-07-17
资源大小:6155k
文件大小:4k
源码类别:
3D图形编程
开发平台:
C/C++
- /***************************************************************************
- *
- * Copyright 2000 by David Demirdjian. All rights reserved.
- *
- * Developed by David Demirdjian
- *
- * Permission to use, copy, or modify this software and its documentation
- * for educational and research purposes only and without fee is hereby
- * granted, provided that this copyright notice and the original authors's
- * names appear on all copies and supporting documentation. If individual
- * files are separated from this distribution directory structure, this
- * copyright notice must be included. For any other uses of this software,
- * in original or modified form, including but not limited to distribution
- * in whole or in part, specific prior permission must be obtained from
- * MIT. These programs shall not be used, rewritten, or adapted as the
- * basis of a commercial software or hardware product without first
- * obtaining appropriate licenses from David Demirdjian. The author makes
- * no representations about the suitability of this software for any purpose.
- * It is provided "as is" without express or implied warranty.
- *
- **************************************************************************/
- #include "stdafx.h"
- #include "stereoMatching.h"
- #include "processingMMX.h"
- #include <math.h>
- typedef unsigned char uchar;
- typedef unsigned short ushort;
- #define ALLOC_ALIGN_MEMORY(X, X_origin, type, size) (X_origin)=((type*)malloc((size)*sizeof(type)+127)); (X) = (type*)((((unsigned int)(X_origin))+127) & (~127));
- #define DELETENULL(object) if (object) {delete object;object = NULL;}
- #define FREENULL(object) if (object) {free(object); object = NULL;}
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- StereoBuffer::StereoBuffer()
- {
- Depth16_origin = NULL;
- imDepth_ref_origin = NULL;
- count_non_null_pixels_origin = NULL;
- corrScore_origin = NULL;
- corrScoreSec_origin = NULL;
- buffTemp_origin = NULL;
- bigBuffer16_origin = NULL;
- bigBuffer_origin = NULL;
- buff = NULL;
- buff16 = NULL;
- }
- StereoBuffer::~StereoBuffer()
- {
- deAlloc();
- }
- void StereoBuffer::setSize(int width, int height, int maxNbDepth)
- {
- //int f = pow(2, scale);
- this->width = width;
- this->height= height;
- this->maxNbDepth = 8*(1+(maxNbDepth-1)/8);
- }
- void StereoBuffer::alloc()
- {
- deAlloc();
- int siz = (8+width)*height;
- // stereo grow
- ALLOC_ALIGN_MEMORY(Depth16, Depth16_origin, ushort, siz);
- ALLOC_ALIGN_MEMORY(imDepth_ref, imDepth_ref_origin, uchar, siz);
- ALLOC_ALIGN_MEMORY(count_non_null_pixels, count_non_null_pixels_origin, uchar, siz);
- ALLOC_ALIGN_MEMORY(corrScore, corrScore_origin, uchar, siz);
- ALLOC_ALIGN_MEMORY(corrScoreSec, corrScoreSec_origin, uchar, siz);
- // initialization of buffers ... with 64 bits alignment
- ALLOC_ALIGN_MEMORY(buffTemp, buffTemp_origin, ushort, 2*siz)
- buffStep = width*height;
- ALLOC_ALIGN_MEMORY(bigBuffer, bigBuffer_origin, uchar, 2*buffStep*maxNbDepth);
- buff = new uchar*[maxNbDepth];
- for (int i=0; i<maxNbDepth; ++i) {
- buff[i] = bigBuffer+ i*buffStep;
- }
- allocTempBuffer16();
- }
- void StereoBuffer::deAlloc()
- {
- deAllocTempBuffer16();
- FREENULL(bigBuffer_origin);
- FREENULL(buffTemp_origin);
- if(buff) {
- delete[] buff;
- buff = NULL;
- }
- FREENULL(Depth16_origin);
- FREENULL(imDepth_ref_origin);
- FREENULL(count_non_null_pixels_origin);
- FREENULL(corrScore_origin);
- FREENULL(corrScoreSec_origin);
- }
- void StereoBuffer::allocTempBuffer16()
- {
- // ALLOC_ALIGN_MEMORY(bigBuffer16, bigBuffer16_origin, ushort, width*height*maxNbDepth);
- ALLOC_ALIGN_MEMORY(bigBuffer16, bigBuffer16_origin, ushort, (8+width)*height*maxNbDepth);
- buff16 = new ushort*[maxNbDepth];
- for (int i=0; i<maxNbDepth; ++i)
- buff16[i]= bigBuffer16+ i*(width*height);
- }
- void StereoBuffer::deAllocTempBuffer16()
- {
- FREENULL(bigBuffer16_origin);
- if(buff16)
- {
- delete[] buff16;
- buff16 = NULL;
- }
- }
- uchar* StereoBuffer::getCorrScores() const
- {
- return corrScore;
- }
- uchar* StereoBuffer::getCorrScores_Sec() const
- {
- return corrScoreSec;
- }