Field3D
main.cpp
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------//
00002 
00003 /*
00004  * Copyright (c) 2009 Sony Pictures Imageworks
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * Redistributions of source code must retain the above copyright
00013  * notice, this list of conditions and the following disclaimer.
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the
00017  * distribution.  Neither the name of Sony Pictures Imageworks nor the
00018  * names of its contributors may be used to endorse or promote
00019  * products derived from this software without specific prior written
00020  * permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00031  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00033  * OF THE POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 //----------------------------------------------------------------------------//
00037 
00038 /* Field3D examples - mixed types
00039 
00040 This sample application creates multiple fields and writes them all to 
00041 the same file. 
00042 
00043 */
00044 
00045 //----------------------------------------------------------------------------//
00046 
00047 #include <iostream>
00048 #include <string>
00049 
00050 #include <Field3D/DenseField.h>
00051 #include <Field3D/MACField.h>
00052 #include <Field3D/SparseField.h>
00053 
00054 #include <Field3D/InitIO.h>
00055 #include <Field3D/Field3DFile.h>
00056 
00057 #include <Field3D/Types.h>
00058 
00059 //----------------------------------------------------------------------------//
00060 
00061 using namespace std;
00062 
00063 using namespace Field3D;
00064 
00065 //----------------------------------------------------------------------------//
00066 
00067 int main(int argc, char **argv)
00068 {
00069   typedef Field3D::half half; 
00070 
00071   // Call initIO() to initialize standard I/O methods and load plugins ---
00072 
00073   Field3D::initIO();
00074 
00075   // Create a set of fields with different types and bit depths ---
00076 
00077   // ... First a DenseField<half>
00078 
00079   DenseField<half>::Ptr denseField(new DenseField<half>);
00080   denseField->name = "density_source";
00081   denseField->attribute = "density";
00082   denseField->setSize(V3i(50, 50, 50));
00083   denseField->clear(0.0f);
00084 
00085   // ... Then two SparseFields to make up a moving levelset
00086 
00087   SparseField<float>::Ptr sparseField(new SparseField<float>);
00088   sparseField->name = "character";
00089   sparseField->attribute = "levelset";
00090   sparseField->setSize(V3i(250, 250, 250));
00091   sparseField->clear(0.0f);
00092   
00093   SparseField<V3f>::Ptr sparseVField(new SparseField<V3f>);
00094   sparseVField->name = "character";
00095   sparseVField->attribute = "v";
00096   sparseVField->setSize(V3i(50, 50, 50));
00097   sparseVField->clear(V3f(0.0f));
00098 
00099   // ... Finally a MACField<V3f>, using the typedefs
00100 
00101   MACField3f::Ptr macField(new MACField3f);
00102   macField->name = "simulation";
00103   macField->attribute = "v";
00104   macField->setSize(V3i(120, 50, 100));
00105   macField->clear(V3f(0.0f));
00106   
00107   // Write the output ---
00108 
00109   Field3DOutputFile out;
00110   out.create("mixed_file.f3d");
00111   out.writeScalarLayer<half>(denseField); 
00112   out.writeScalarLayer<float>(sparseField); 
00113   out.writeVectorLayer<float>(sparseVField); 
00114   out.writeVectorLayer<float>(macField); 
00115 }
00116 
00117 //----------------------------------------------------------------------------//
00118