📄 densitytable.cpp
字号:
// DensityTable.cpp : implementation file//////////////////////////////////////////////////////////////////////////// Title: Container of Block Information//////////////////////////////////////////////////////////////////////////// Author: H.W.Kye// 138-dong 417-ho Seoul National University// San 56-1 Shinlim-dong Kwanak-gu Seoul, Korea// Email. //// Date :// Update ://////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// include//////////////////////////////////////////////////////////////////////#include "StdAfx.h"#include <xmmintrin.h>#include <string.h>#include <malloc.h>#include <math.h>#include "Matrix4D.h"#include "DensityTable.h"//////////////////////////////////////////////////////////////////////// define//////////////////////////////////////////////////////////////////////static const int MIN_DENSITY=0;static const int MAX_DENSITY=4095;static const int CACHESIZE=32;//////////////////////////////////////////////////////////////////////// RxDensityTableRxDensityTable::RxDensityTable(){ m_pOpacityCorrectedTable = (__m128*)_mm_malloc(DENSITY_RANGE*16, CACHESIZE); memset(m_pOpacityCorrectedTable, 0, DENSITY_RANGE*16); m_pTable = m_pOpacityCorrectedTable; m_pPreIntegratedTable = (__m128*)_mm_malloc((DENSITY_RANGE+1)*16, CACHESIZE); memset(m_pPreIntegratedTable, 0, (DENSITY_RANGE+1)*16); m_pPreIntegratedTable++; // m_pPreIntegratedTable[-1]阑 静扁 困秦 m_SAT.CreateTable(MIN_DENSITY, MAX_DENSITY);}RxDensityTable::~RxDensityTable(){ m_pTable = NULL; _mm_free(m_pOpacityCorrectedTable); m_pPreIntegratedTable--; _mm_free(m_pPreIntegratedTable); m_SAT.DestroyTable();}void RxDensityTable::SetSpectrumTable(__m128 *pTable){ ASSERT(pTable); m_pTable = pTable; m_SAT.MakeTable(m_pTable);}// For Each Framevoid RxDensityTable::InitRendering(float fSpacing){ MakeOpacityCorrectedDensityTable(fSpacing); MakePreIntegratedTable();}void RxDensityTable::MakeOpacityCorrectedDensityTable(float fSpacing){ const __m128 v255 = _mm_set1_ps(255.0f); const __m128 vOne = _mm_set1_ps(1.0f); const __m128 vZero = _mm_setzero_ps(); float afOpacityCorrectionTable[256]; afOpacityCorrectionTable[0] = 0; for(int i=1; i<256; i+=1) { double alpha = i / 255.0; double alpha_corrected = 1 - pow((1-alpha), fSpacing); afOpacityCorrectionTable[i] = (float)__max(1, (alpha_corrected/alpha)); } memcpy(m_pOpacityCorrectedTable, m_pTable, DENSITY_RANGE*sizeof(__m128)); for(i=0; i<DENSITY_RANGE; i++) { int iDontCare = _mm_comieq_ss(m_pTable[i], vOne) | _mm_comieq_ss(m_pTable[i], vZero); if(!iDontCare) { int iAlpha = _mm_cvtss_si32(_mm_mul_ps(v255, m_pTable[i])); m_pOpacityCorrectedTable[i] = _mm_mul_ps( _mm_set1_ps(afOpacityCorrectionTable[iAlpha]), m_pTable[i]); } }}void RxDensityTable::MakePreIntegratedTable(){ __m128 vCurrent = _mm_setzero_ps(); m_pPreIntegratedTable[-1] = vCurrent; for(int i=0; i<DENSITY_RANGE; i++) { m_pPreIntegratedTable[i] = _mm_add_ps(m_pPreIntegratedTable[i-1], m_pOpacityCorrectedTable[i]); }}void RxDensityTable::operator = (const RxDensityTable &info){ m_pTable = info.m_pTable; memcpy(m_pOpacityCorrectedTable, info.m_pOpacityCorrectedTable, DENSITY_RANGE*16); memcpy((m_pPreIntegratedTable-1), (info.m_pPreIntegratedTable-1), (DENSITY_RANGE+1)*16);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -