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 #ifndef __SIM_GasAdd_h__ 00029 #define __SIM_GasAdd_h__ 00030 00031 #include <GAS/GAS_SubSolver.h> 00032 #include <GAS/GAS_Utils.h> 00033 00034 namespace HDK_Sample { 00035 00036 /// A simple field manipulation class that will add fields 00037 /// together. 00038 class SIM_GasAdd : public GAS_SubSolver 00039 { 00040 public: 00041 /// These macros are used to create the accessors 00042 /// getFieldDstName and getFieldSrcName functions we'll use 00043 /// to access our data options. 00044 GET_DATA_FUNC_S(GAS_NAME_FIELDDEST, FieldDstName); 00045 GET_DATA_FUNC_S(GAS_NAME_FIELDSOURCE, FieldSrcName); 00046 00047 protected: 00048 explicit SIM_GasAdd(const SIM_DataFactory *factory); 00049 virtual ~SIM_GasAdd(); 00050 00051 /// Used to determine if the field is complicated enough to justify 00052 /// the overhead of multithreading. 00053 bool shouldMultiThread(const SIM_RawField *field) const 00054 { return field->field()->numTiles() > 1; } 00055 00056 /// The overloaded callback that GAS_SubSolver will invoke to 00057 /// perform our actual computation. We are giving a single object 00058 /// at a time to work on. 00059 virtual bool solveGasSubclass(SIM_Engine &engine, 00060 SIM_Object *obj, 00061 SIM_Time time, 00062 SIM_Time timestep); 00063 00064 /// Add two raw fields together. Use UT_ThreadedAlgorithm's macros 00065 /// to define the addFields method that will invoke addFieldPartial() 00066 /// on each worker thread. 00067 THREADED_METHOD2(SIM_GasAdd, shouldMultiThread(dst), 00068 addFields, 00069 SIM_RawField *, dst, 00070 const SIM_RawField *, src); 00071 00072 void addFieldsPartial(SIM_RawField *dst, const SIM_RawField *src, const UT_JobInfo &info); 00073 00074 private: 00075 /// We define this to be a DOP_Auto node which means we do not 00076 /// need to implement a DOP_Node derivative for this data. Instead, 00077 /// this description is used to define the interface. 00078 static const SIM_DopDescription *getDopDescription(); 00079 00080 /// These macros are necessary to bind our node to the factory and 00081 /// ensure useful constants like BaseClass are defined. 00082 DECLARE_STANDARD_GETCASTTOTYPE(); 00083 DECLARE_DATAFACTORY(SIM_GasAdd, 00084 GAS_SubSolver, 00085 "Gas Add", 00086 getDopDescription()); 00087 }; 00088 00089 } // End HDK_Sample namespace 00090 00091 #endif 00092
1.5.9