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 - read
00039 
00040 This sample application reads all fields found in a given .f3d file and
00041 prints their types, names and attributes.
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 #include <Field3D/InitIO.h>
00054 #include <Field3D/Field3DFile.h>
00055 
00056 //----------------------------------------------------------------------------//
00057 
00058 using namespace std;
00059 
00060 using namespace Field3D;
00061 
00062 //----------------------------------------------------------------------------//
00063 
00064 template <typename Data_T>
00065 void readLayersAndPrintInfo(Field3DInputFile &in, const std::string &name)
00066 {
00067   typedef FIELD3D_VEC3_T<Data_T> VecData_T;
00068   typedef typename Field<Data_T>::Vec SFieldList;
00069   typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec VFieldList;
00070 
00071   // Note that both scalar and vector calls take the scalar type as argument
00072   SFieldList sFields = in.readScalarLayers<Data_T>(name);
00073   VFieldList vFields = in.readVectorLayers<Data_T>(name);
00074 
00075   // Print info about the found fields ---
00076 
00077   if (sFields.size() > 0) {
00078 
00079     for (typename SFieldList::const_iterator i = sFields.begin(); 
00080          i != sFields.end(); ++i) {
00081 
00082       if (field_dynamic_cast<DenseField<Data_T> >(*i)) {
00083         cout << "  DenseField" << endl;
00084       }
00085       else if (field_dynamic_cast<SparseField<Data_T> >(*i)) {
00086         cout << "  SparseField" << endl;
00087       }
00088 
00089       cout << "    Name:      " << (**i).name << endl;
00090       cout << "    Attribute: " << (**i).attribute << endl;
00091 
00092     }
00093 
00094   } else {
00095     cout << "  Found no scalar fields" << endl;
00096   }
00097 
00098   if (vFields.size() > 0) {
00099 
00100     for (typename VFieldList::const_iterator i = vFields.begin(); 
00101          i != vFields.end(); ++i) {
00102 
00103       if (field_dynamic_cast<DenseField<VecData_T> >(*i)) {
00104         cout << "  DenseField" << endl;
00105       }
00106       else if (field_dynamic_cast<SparseField<VecData_T> >(*i)) {
00107         cout << "  SparseField" << endl;
00108       }
00109       else if (field_dynamic_cast<MACField<VecData_T> >(*i)) {
00110         cout << "  MACField" << endl;
00111       }
00112 
00113       cout << "    Name:      " << (**i).name << endl;
00114       cout << "    Attribute: " << (**i).attribute << endl;
00115 
00116     }
00117 
00118   } else {
00119     cout << "  Found no vector fields" << endl;
00120   }
00121 
00122 }
00123 
00124 //----------------------------------------------------------------------------//
00125 
00126 int main(int argc, char **argv)
00127 {
00128   typedef Field3D::half half;
00129 
00130   // Call initIO() to initialize standard I/O methods and load plugins ---
00131 
00132   Field3D::initIO();
00133 
00134   // Process command line ---
00135 
00136   if (argc < 2) {
00137     cout << "Usage: read <file> [name]" << endl;
00138     return 1;
00139   }
00140 
00141   string filename = string(argv[1]);
00142   string name;
00143 
00144   if (argc == 3) {
00145     name = string(argv[2]);
00146   }
00147 
00148   // Load file ---
00149 
00150   Field3DInputFile in;
00151   if (!in.open(filename)) {
00152     cout << "Aborting because of errors" << endl;
00153     return 1;
00154   }
00155 
00156   cout << "Reading <half> layers" << endl;
00157   readLayersAndPrintInfo<half>(in, name);
00158 
00159   cout << "Reading <float> layers" << endl;
00160   readLayersAndPrintInfo<float>(in, name);
00161 
00162   cout << "Reading <double> layers" << endl;
00163   readLayersAndPrintInfo<double>(in, name);
00164 
00165 }
00166 
00167 //----------------------------------------------------------------------------//
00168