/* Copyright (c) 2010, Cryst. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Cryst nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include void ***alloc3D( void *data, int sizeOfUnit, int lx, int ly, int lz ) /** 連続したボクセルデータを、lx,ly,lz の配列としてアクセス出来るように初期化 void *data: 3Dデータ(ボクセルデータ)の格納場所 原点からX軸方向のデータが LX個 連続して格納されている。この並びで LY個のデータが配置され、1画面(2D) 分のデータが格納されている。この塊が、LZ個並んで全ボクセルデータが 記録されている。 int sizeOfUnit: 1ボクセルを構成するデータのバイト数 int lx: X軸方向のボクセル数 int ly: Y軸方向のボクセル数 int lz: Z軸方向のボクセル数 */ { register void ***d ; // 作業用の一時変数 if ( (data==NULL) || (sizeOfUnit<1) || (lx<1) || (ly<1) || (lz<1) ) return NULL ; if ((d=(void ***)malloc((lz*ly+lz)*sizeof(void *))) == NULL) {// インデックス領域 return NULL ; // インデックス領域の確保に失敗 } else { // 確保したメモリー上に、配列アクセス用のインデックスを初期化 register int i, s=sizeOfUnit, llx=lx, lly=ly, llz=lz, lyz=lly*llz ; register void **area=(void **)&d[llz], *base=data ; for( i=0; i