00001 /* 00002 * Copyright (c) 2012 00003 * Side Effects Software Inc. All rights reserved. 00004 * 00005 * Redistribution and use of Houdini Development Kit samples in source and 00006 * binary forms, with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. The name of Side Effects Software may not be used to endorse or 00011 * promote products derived from this software without specific prior 00012 * written permission. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS 00015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00017 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00019 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00020 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00021 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00022 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00023 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 *---------------------------------------------------------------------------- 00026 */ 00027 00028 00029 #include <stdio.h> 00030 #include <iostream> 00031 #include <CMD/CMD_Args.h> 00032 #include <UT/UT_Assert.h> 00033 #include <GU/GU_Detail.h> 00034 #include <GU/GU_PrimVolume.h> 00035 00036 static void 00037 usage(const char *program) 00038 { 00039 cerr << "Usage: " << program << "\n"; 00040 } 00041 00042 static inline float 00043 sphereVal(int i, int j, int k, int xres, int yres, int zres) 00044 { 00045 float x, y, z; 00046 00047 x = 2.0F * (i-0.5F*xres+0.5F) / xres; 00048 y = 2.0F * (j-0.5F*yres+0.5F) / yres; 00049 z = 2.0F * (k-0.5F*zres+0.5F) / zres; 00050 return SYSsqrt(x*x + y*y + z*z) < 1.0F ? 1.0F : 0; 00051 } 00052 00053 // Generate a volume primitive with a resolution of 16x16x16. The volume 00054 // primitive will be dumped as binary output to standard output. 00055 // 00056 // Build using: 00057 // hcustom -s gengeovolume.C 00058 // 00059 // Example usage: 00060 // gengeovolume > volume.bgeo 00061 int 00062 main(int argc, char *argv[]) 00063 { 00064 CMD_Args args; 00065 GU_Detail gdp; 00066 GU_PrimVolume *volume; 00067 const int xres = 16; 00068 const int yres = 16; 00069 const int zres = 16; 00070 const int binary = 1; 00071 int i, j, k; 00072 00073 args.initialize(argc, argv); 00074 00075 if (args.argc() != 1) 00076 { 00077 usage(argv[0]); 00078 return 1; 00079 } 00080 00081 volume = (GU_PrimVolume *)GU_PrimVolume::build(&gdp); 00082 00083 // The COW handle will write data to the voxel array on destruction 00084 { 00085 UT_VoxelArrayWriteHandleF handle = volume->getVoxelWriteHandle(); 00086 00087 handle->size(xres, yres, zres); 00088 for (i = 0; i < xres; i++) 00089 for (j = 0; j < yres; j++) 00090 for (k = 0; k < zres; k++) 00091 handle->setValue(i, j, k, 00092 sphereVal(i, j, k, xres, yres, zres)); 00093 } 00094 00095 gdp.save(std::cout, binary, 0); 00096 return 0; 00097 }
1.5.9