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
00029
00030
00031
00032
00033
00034
00035
00036 #include <stdio.h>
00037 #include <fstream.h>
00038 #include <UT/UT_Math.h>
00039 #include <UT/UT_Vector3.h>
00040 #include <UT/UT_DSOVersion.h>
00041 #include <GU/GU_Detail.h>
00042 #include <PRM/PRM_Include.h>
00043 #include <PRM/PRM_SpareData.h>
00044 #include <OP/OP_Director.h>
00045 #include <OP/OP_OperatorTable.h>
00046 #include <TIL/TIL_CopResolver.h>
00047 #include <TIL/TIL_Raster.h>
00048
00049 #include "SOP_CopRaster.h"
00050
00051 using namespace HDK_Sample;
00052
00053 static PRM_Name copnames[] = {
00054 PRM_Name("usedisk", "Use Disk Image"),
00055 PRM_Name("copframe", "COP Frame"),
00056 PRM_Name("file", "File Name"),
00057 PRM_Name("copcolor", "Plane"),
00058 PRM_Name("coppath", "COP Path"),
00059 };
00060
00061 static PRM_Default copFrameDefault(0, "$F");
00062
00063
00064 static PRM_ChoiceList colorMenu((PRM_ChoiceListType)
00065 (PRM_CHOICELIST_EXCLUSIVE |
00066 PRM_CHOICELIST_REPLACE),
00067 &SOP_CopRaster::buildColorMenu);
00068
00069 static PRM_Default fileDef(0, "circle.pic");
00070 static PRM_Default colorDef(0, TIL_DEFAULT_COLOR_PLANE);
00071
00072 PRM_Template
00073 SOP_CopRaster::myTemplateList[] = {
00074 PRM_Template(PRM_TOGGLE, 1, &copnames[0], PRMoneDefaults),
00075 PRM_Template(PRM_STRING, PRM_TYPE_DYNAMIC_PATH, 1, &copnames[4],
00076 0, 0, 0, 0, &PRM_SpareData::cop2Path),
00077 PRM_Template(PRM_STRING, 1, &copnames[3], &colorDef, &colorMenu),
00078 PRM_Template(PRM_FLT_J, 1, &copnames[1], &copFrameDefault),
00079 PRM_Template(PRM_PICFILE, 1, &copnames[2], &fileDef,
00080 0, 0, 0, &PRM_SpareData::fileChooserModeRead),
00081
00082 PRM_Template()
00083 };
00084
00085 OP_Node *
00086 SOP_CopRaster::myConstructor(OP_Network *dad, const char *name, OP_Operator *op)
00087 {
00088 return new SOP_CopRaster(dad, name, op);
00089 }
00090
00091 SOP_CopRaster::SOP_CopRaster(OP_Network *dad, const char *name, OP_Operator *op)
00092 : SOP_Node(dad, name, op)
00093 {
00094 }
00095
00096 SOP_CopRaster::~SOP_CopRaster() {}
00097
00098 unsigned
00099 SOP_CopRaster::disableParms()
00100 {
00101 int state;
00102 int changed = 0;
00103
00104
00105 state = (USEDISK()) ? 0 : 1;
00106 changed = enableParm("coppath", state);
00107 changed += enableParm("copcolor", state);
00108 changed += enableParm("copframe", state);
00109 changed += enableParm("file", !state);
00110
00111 return changed;
00112 }
00113
00114
00115
00116
00117 void
00118 SOP_CopRaster::buildColorMenu(void *data, PRM_Name *theMenu, int theMaxSize,
00119 const PRM_SpareData *, PRM_Parm *)
00120 {
00121 SOP_CopRaster *me = (SOP_CopRaster *)data;
00122 UT_PtrArray<char *> items;
00123 UT_String relpath, fullpath, netpath, nodepath;
00124 int i, useflag = 0;
00125
00126 me->COPPATH(relpath, 0.0F);
00127 me->getFullCOP2Path(relpath, fullpath, useflag);
00128 me->splitCOP2Path(fullpath, netpath, nodepath);
00129
00130 TIL_CopResolver::buildColorMenu(netpath, nodepath, items);
00131
00132 for (i = 0; i < items.entries() && i < theMaxSize; i++)
00133 {
00134 theMenu[i].setToken( items(i) );
00135 theMenu[i].setLabel( items(i) );
00136
00137 free ( items(i) );
00138 }
00139 theMenu[i].setToken(0);
00140 }
00141
00142 void
00143 SOP_CopRaster::splitCOP2Path(const char *path, UT_String &net,
00144 UT_String &node)
00145 {
00146
00147 OP_Node *node_ptr, *parent_ptr;
00148 UT_String fullpath;
00149
00150 node_ptr = findNode(path);
00151 if (!node_ptr)
00152 {
00153 net = "";
00154 node = "";
00155 return;
00156 }
00157
00158 parent_ptr = node_ptr->getCreator();
00159 if (!parent_ptr)
00160 net = "";
00161 else
00162 parent_ptr->getFullPath(net);
00163
00164 node_ptr->getFullPath(fullpath);
00165 if (net.isstring())
00166 {
00167
00168 node.getRelativePath(net, fullpath);
00169 }
00170 else
00171 node.harden(fullpath);
00172 }
00173
00174
00175
00176
00177 int
00178 SOP_CopRaster::getFullCOP2Path(const char *relpath, UT_String &fullpath,
00179 int &flagdependent)
00180 {
00181 OP_Node *node;
00182
00183 fullpath = "";
00184 flagdependent = 0;
00185
00186 node = findNode(relpath);
00187 if (!node)
00188 return -1;
00189
00190 if (node->getOpTypeID() != COP2_OPTYPE_ID)
00191 {
00192
00193
00194 if (((OP_Network *)node)->getChildTypeID() == COP2_OPTYPE_ID)
00195 {
00196 node = ((OP_Network *)node)->getRenderNodePtr();
00197 flagdependent = 1;
00198 }
00199 }
00200
00201
00202 node = (OP_Node *) CAST_COP2NODE(node);
00203 if (!node)
00204 return -1;
00205
00206 node->getFullPath(fullpath);
00207
00208
00209 return 0;
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 int
00219 SOP_CopRaster::updateRaster(float t)
00220 {
00221 UT_String fname;
00222 int rcode;
00223
00224
00225
00226 myRaster.setRasterDepth(myRaster.UT_RASTER_8);
00227
00228 rcode = -1;
00229 if (USEDISK())
00230 {
00231
00232 FNAME(fname, t);
00233 if (myCurrentName == fname)
00234 {
00235 rcode = 0;
00236 }
00237 else
00238 {
00239 if (!myRaster.load(fname))
00240 {
00241 addCommonError(UT_CE_FILE_ERROR, (const char *)fname);
00242 rcode = -1;
00243 }
00244 else
00245 {
00246 myCurrentName.harden(fname);
00247 rcode = 1;
00248 }
00249 }
00250 }
00251 else
00252 {
00253 UT_String relpath, fullpath;
00254 OP_Node *cop = 0;
00255 int id, useflag = 0;
00256
00257
00258 TIL_CopResolver *cr = TIL_CopResolver::getResolver();
00259
00260
00261
00262 myCurrentName.harden("");
00263 COPPATH(relpath, t);
00264 getFullCOP2Path(relpath, fullpath, useflag);
00265
00266
00267
00268 id = TIL_CopResolver::getNodeId(fullpath);
00269 if (id >= 0)
00270 cop = OP_Node::lookupNode(id);
00271
00272 if (cop)
00273 {
00274 TIL_Raster *r = 0;
00275 float frame;
00276 UT_String cplane;
00277
00278
00279
00280
00281 addExtraInput(cop, OP_INTEREST_DATA);
00282
00283
00284
00285 if (useflag)
00286 addExtraInput(cop, OP_INTEREST_FLAG);
00287
00288 frame = COPFRAME(t);
00289 CPLANE(cplane, t);
00290
00291 r = cr->getNodeRaster(fullpath, cplane, TIL_NO_PLANE, true,
00292 (int)frame, TILE_INT8);
00293
00294
00295 if (r)
00296 {
00297 myRaster.size((short) r->getXres(), (short) r->getYres());
00298 memcpy(myRaster.getRaster(), r->getPixels(), r->getSize());
00299 rcode = 1;
00300 }
00301 else
00302 rcode = -1;
00303
00304
00305
00306
00307
00308 if (cop->flags().timeDep)
00309 flags().timeDep = 1;
00310 }
00311 else rcode = -1;
00312 }
00313 return rcode;
00314 }
00315
00316
00317
00318 OP_ERROR
00319 SOP_CopRaster::cookMySop(OP_Context &context)
00320 {
00321 int rstate;
00322 int x, y;
00323 int xres, yres;
00324 int coff;
00325 float t;
00326 GEO_Point *ppt;
00327 UT_Vector3 *clr;
00328 UT_RGBA *rgba;
00329
00330 t = context.myTime;
00331
00332
00333 rstate = updateRaster(t);
00334
00335 if (rstate >= 0)
00336 {
00337
00338 gdp->clearAndDestroy();
00339
00340
00341
00342
00343 checkInputChanged(0, -1, myDetailGroupPair, gdp, 0);
00344
00345
00346
00347 clearSelection(GU_SPoint);
00348
00349
00350 coff = gdp->addDiffuseAttribute(GEO_POINT_DICT);
00351
00352
00353 xres = myRaster.Xres();
00354 yres = myRaster.Yres();
00355 rgba = myRaster.getRaster();
00356
00357
00358 for (x = 0; x < xres; x++)
00359 {
00360 for (y = 0; y < yres; y++, rgba++)
00361 {
00362 ppt = gdp->appendPoint();
00363 ppt->getPos().assign((float)x/(float)xres,
00364 (float)y/(float)yres, 0, 1);
00365 clr = ppt->castAttribData<UT_Vector3>(coff);
00366 clr->assign(rgba->r, rgba->g, rgba->b);
00367 *clr *= 1.0F/255;
00368
00369
00370
00371
00372
00373
00374 select(*ppt, 1, 1);
00375 }
00376 }
00377 }
00378 return error();
00379 }
00380
00381 void
00382 newSopOperator(OP_OperatorTable *table)
00383 {
00384 OP_Operator *op;
00385
00386 op = new OP_Operator("hdk_copraster",
00387 "COP Raster",
00388 SOP_CopRaster::myConstructor,
00389 SOP_CopRaster::myTemplateList,
00390 0,
00391 0,
00392 0,
00393 OP_FLAG_GENERATOR);
00394
00395 table->addOperator(op);
00396 }