00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include <iostream>
00030 #include <IMG3D/IMG3D_Manager.h>
00031 #include <UT/UT_Vector3.h>
00032 #include <UT/UT_BoundingBox.h>
00033 #include <UT/UT_Exit.h>
00034 #include <UT/UT_Options.h>
00035
00036 namespace HDK_Sample {
00037
00038 static void
00039 error(const char *msg)
00040 {
00041 fprintf(stderr, "Error: %s\n", msg);
00042 UT_Exit::exit( UT_Exit::EXIT_GENERIC_ERROR );
00043 }
00044
00045 static void
00046 i3dSphere(int nvalues,
00047 const UT_Vector3 *P,
00048 fpreal32 *result[],
00049 const char *names[],
00050 int sizes[],
00051 int for_aa)
00052 {
00053 fpreal32 *density;
00054 fpreal32 *color;
00055 int i;
00056 fpreal d;
00057
00058
00059 UT_ASSERT(!strcmp(names[0], "density") && sizes[0] == 1);
00060 UT_ASSERT(!strcmp(names[1], "color") && sizes[1] == 3);
00061 density = result[0];
00062 color = result[1];
00063
00064 for (i = 0; i < nvalues; i++)
00065 {
00066
00067 d = P[i].length() > 1 ? 0 : 1;
00068 *density = d;
00069 color[0] = d * SYSfit(P[i].x(), -1, 1, 0, 1);
00070 color[1] = d * SYSfit(P[i].y(), -1, 1, 0, 1);
00071 color[2] = d * SYSfit(P[i].z(), -1, 1, 0, 1);
00072
00073
00074 density += 1;
00075 color += 3;
00076 }
00077 }
00078
00079 }
00080
00081 using namespace HDK_Sample;
00082
00083 int
00084 main(int argc, char *argv[])
00085 {
00086 IMG3D_Manager fp;
00087 UT_BoundingBox bounds;
00088 const char *chnames[2] = { "density", "color" };
00089 int chsizes[2] = { 1, 3 };
00090
00091 printf("Generating sphere.i3d\n");
00092 bounds.initBounds(-1, -1, -1);
00093 bounds.enlargeBounds(1, 1, 1);
00094 if (!fp.createTexture("sphere.i3d", bounds, 10, 10, 10))
00095 error("Unable to createTexture()");
00096
00097 if (!fp.fillTexture(2, chnames, chsizes, i3dSphere, 1))
00098 error("Unable to fill the texture");
00099
00100 if (!fp.exportTag("software", "hdk_isosphere"))
00101 error("Unable to save software tag");
00102
00103 if (!fp.closeTexture())
00104 error("Unable to close texture");
00105
00106 return 0;
00107 }