static NodeOutput* _readTimestep(float t, bool isVector, bool hasStatus, QTextStream& stream, int nodeCount, int elemCount, QVector<int>& nodeIDToIndex) { NodeOutput* o = new NodeOutput; o->init(nodeCount, elemCount, isVector); o->time = t / 3600.; QRegExp reSpaces("\\s+"); if (hasStatus) { // only for new format char* active = o->active.data(); for (int i = 0; i < elemCount; ++i) { active[i] = stream.readLine().toInt(); } } else memset(o->active.data(), 1, elemCount); // there is no status flag -> everything is active float* values = o->values.data(); NodeOutput::float2D* valuesV = o->valuesV.data(); for (int i = 0; i < nodeIDToIndex.count(); ++i) { QStringList tsItems = stream.readLine().split(reSpaces, QString::SkipEmptyParts); int index = nodeIDToIndex[i]; if (index < 0) continue; // node ID that does not exist in the mesh if (isVector) { NodeOutput::float2D v; if (tsItems.count() >= 2) // BASEMENT files with vectors have 3 columns { v.x = tsItems[0].toFloat(); v.y = tsItems[1].toFloat(); } else { qDebug("Crayfish: invalid timestep line"); v.x = v.y = 0; } valuesV[index] = v; values[index] = v.length(); // Determine the magnitude } else { if (tsItems.count() >= 1) values[index] = tsItems[0].toFloat(); else { qDebug("Crayfish: invalid timestep line"); values[index] = 0; } } } return o; }
void ColorNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { SetColorOperation *operation = new SetColorOperation(); NodeOutput *output = this->getOutputSocket(0); float col[4]; output->getEditorValueColor(col); operation->setChannels(col); converter.addOperation(operation); converter.mapOutputSocket(output, operation->getOutputSocket()); }
void SocketBufferNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { NodeOutput *output = this->getOutputSocket(0); NodeInput *input = this->getInputSocket(0); DataType datatype = output->getDataType(); WriteBufferOperation *writeOperation = new WriteBufferOperation(datatype); ReadBufferOperation *readOperation = new ReadBufferOperation(datatype); readOperation->setMemoryProxy(writeOperation->getMemoryProxy()); converter.addOperation(writeOperation); converter.addOperation(readOperation); converter.mapInputSocket(input, writeOperation->getInputSocket(0)); converter.mapOutputSocket(output, readOperation->getOutputSocket()); }
static void addStaticDataset(QVector<float>& vals, const QString& name, const DataSet::Type type, const QString& datFileName, Mesh* mesh) { int nelem = mesh->elements().size(); int nnodes = mesh->nodes().size(); NodeOutput* o = new NodeOutput; o->init(nnodes, nelem, false); o->time = 0.0; o->values = vals; if (type == DataSet::Bed) { memset(o->active.data(), 1, nelem); // All cells active } else { activateElements(o, mesh); } DataSet* ds = new DataSet(datFileName); ds->setType(type); ds->setName(name, false); ds->setIsTimeVarying(false); ds->addOutput(o); // takes ownership of the Output ds->updateZRange(); mesh->addDataSet(ds); }
void RenderLayersNode::testRenderLink(NodeConverter &converter, const CompositorContext &context, Render *re) const { Scene *scene = (Scene *)this->getbNode()->id; const short layerId = this->getbNode()->custom1; RenderResult *rr = RE_AcquireResultRead(re); if (rr == NULL) { missingRenderLink(converter); return; } SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&scene->r.layers, layerId); if (srl == NULL) { missingRenderLink(converter); return; } RenderLayer *rl = RE_GetRenderLayer(rr, srl->name); if (rl == NULL) { missingRenderLink(converter); return; } const int num_outputs = this->getNumberOfOutputSockets(); for (int i = 0; i < num_outputs; i++) { NodeOutput *output = this->getOutputSocket(i); NodeImageLayer *storage = (NodeImageLayer *)output->getbNodeSocket()->storage; RenderPass *rpass = (RenderPass *)BLI_findstring( &rl->passes, storage->pass_name, offsetof(RenderPass, name)); if (rpass == NULL) { missingSocketLink(converter, output); continue; } RenderLayersProg *operation; bool is_preview; if (STREQ(rpass->name, RE_PASSNAME_COMBINED) && STREQ(output->getbNodeSocket()->name, "Alpha")) { operation = new RenderLayersAlphaProg(rpass->name, COM_DT_VALUE, rpass->channels); is_preview = false; } else if (STREQ(rpass->name, RE_PASSNAME_Z)) { operation = new RenderLayersDepthProg(rpass->name, COM_DT_VALUE, rpass->channels); is_preview = false; } else { DataType type; switch (rpass->channels) { case 4: type = COM_DT_COLOR; break; case 3: type = COM_DT_VECTOR; break; case 1: type = COM_DT_VALUE; break; default: BLI_assert(!"Unexpected number of channels for pass"); type = COM_DT_VALUE; break; } operation = new RenderLayersProg(rpass->name, type, rpass->channels); is_preview = STREQ(output->getbNodeSocket()->name, "Image"); } testSocketLink(converter, context, output, operation, scene, layerId, is_preview); } }
void ImageNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { /// Image output NodeOutput *outputImage = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); Image *image = (Image *)editorNode->id; ImageUser *imageuser = (ImageUser *)editorNode->storage; int framenumber = context.getFramenumber(); int numberOfOutputs = this->getNumberOfOutputSockets(); bool outputStraightAlpha = (editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT) != 0; BKE_image_user_frame_calc(imageuser, context.getFramenumber(), 0); /* force a load, we assume iuser index will be set OK anyway */ if (image && image->type == IMA_TYPE_MULTILAYER) { bool is_multilayer_ok = false; ImBuf *ibuf = BKE_image_acquire_ibuf(image, imageuser, NULL); if (image->rr) { RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer); if (rl) { NodeOutput *socket; int index; is_multilayer_ok = true; for (index = 0; index < numberOfOutputs; index++) { NodeOperation *operation = NULL; socket = this->getOutputSocket(index); bNodeSocket *bnodeSocket = socket->getbNodeSocket(); /* Passes in the file can differ from passes stored in sockets (#36755). * Look up the correct file pass using the socket identifier instead. */ #if 0 NodeImageLayer *storage = (NodeImageLayer *)bnodeSocket->storage;*/ int passindex = storage->pass_index;*/ RenderPass *rpass = (RenderPass *)BLI_findlink(&rl->passes, passindex); #endif int passindex; RenderPass *rpass; for (rpass = (RenderPass *)rl->passes.first, passindex = 0; rpass; rpass = rpass->next, ++passindex) if (STREQ(rpass->name, bnodeSocket->identifier)) break; if (rpass) { imageuser->pass = passindex; switch (rpass->channels) { case 1: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, passindex, COM_DT_VALUE); break; /* using image operations for both 3 and 4 channels (RGB and RGBA respectively) */ /* XXX any way to detect actual vector images? */ case 3: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, passindex, COM_DT_VECTOR); break; case 4: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, passindex, COM_DT_COLOR); break; default: /* dummy operation is added below */ break; } if (index == 0 && operation) { converter.addPreview(operation->getOutputSocket()); } } /* incase we can't load the layer */ if (operation == NULL) converter.setInvalidOutput(getOutputSocket(index)); } } }
static void parseTIMDEPFile(const QString& datFileName, Mesh* mesh, const QVector<float>& elevations) {\ // TIMDEP.OUT // this file is optional, so if not present, reading is skipped // time (separate line) // For every node: // FLO2D: node number (indexed from 1), depth, velocity, velocity x, velocity y // FLO2DPro: node number (indexed from 1), depth, velocity, velocity x, velocity y, water surface elevation QFileInfo fi(datFileName); QFile inFile(fi.dir().filePath("TIMDEP.OUT")); if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in(&inFile); int nnodes = mesh->nodes().size(); int nelems = mesh->elements().size(); int ntimes = 0; float time = 0.0; int node_inx = 0; DataSet* depthDs = new DataSet(datFileName); depthDs->setType(DataSet::Scalar); depthDs->setName("Depth"); DataSet* waterLevelDs = new DataSet(datFileName); waterLevelDs->setType(DataSet::Scalar); waterLevelDs->setName("Water Level"); DataSet* flowDs = new DataSet(datFileName); flowDs->setType(DataSet::Vector); flowDs->setName("Velocity"); NodeOutput* flowOutput = 0; NodeOutput* depthOutput = 0; NodeOutput* waterLevelOutput = 0; while (!in.atEnd()) { QString line = in.readLine(); QStringList lineParts = line.split(" ", QString::SkipEmptyParts); if (lineParts.size() == 1) { time = line.toFloat(); ntimes++; if (depthOutput) addOutput(depthDs, depthOutput, mesh); if (flowOutput) addOutput(flowDs, flowOutput, mesh); if (waterLevelOutput) addOutput(waterLevelDs, waterLevelOutput, mesh); depthOutput = new NodeOutput; flowOutput = new NodeOutput; waterLevelOutput = new NodeOutput; depthOutput->init(nnodes, nelems, false); //scalar flowOutput->init(nnodes, nelems, true); //vector waterLevelOutput->init(nnodes, nelems, false); //scalar depthOutput->time = time; flowOutput->time = time; waterLevelOutput->time = time; node_inx = 0; } else if ((lineParts.size() == 5) || (lineParts.size() == 6)) { // new node for time if (!depthOutput || !flowOutput || !waterLevelOutput) throw LoadStatus::Err_UnknownFormat; if (node_inx == nnodes) throw LoadStatus::Err_IncompatibleMesh; flowOutput->values[node_inx] = getFloat(lineParts[2]); flowOutput->valuesV[node_inx].x = getFloat(lineParts[3]); flowOutput->valuesV[node_inx].y = getFloat(lineParts[4]); float depth = getFloat(lineParts[1]); depthOutput->values[node_inx] = depth; if (!is_nodata(depth)) depth += elevations[node_inx]; waterLevelOutput->values[node_inx] = depth; node_inx ++; } else { throw LoadStatus::Err_UnknownFormat; } } if (depthOutput) addOutput(depthDs, depthOutput, mesh); if (flowOutput) addOutput(flowDs, flowOutput, mesh); if (waterLevelOutput) addOutput(waterLevelDs, waterLevelOutput, mesh); depthDs->setIsTimeVarying(ntimes>1); flowDs->setIsTimeVarying(ntimes>1); waterLevelDs->setIsTimeVarying(ntimes>1); depthDs->updateZRange(); flowDs->updateZRange(); waterLevelDs->updateZRange(); mesh->addDataSet(depthDs); mesh->addDataSet(flowDs); mesh->addDataSet(waterLevelDs); }
void ImageNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { /// Image output NodeOutput *outputImage = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); Image *image = (Image *)editorNode->id; ImageUser *imageuser = (ImageUser *)editorNode->storage; int framenumber = context.getFramenumber(); int numberOfOutputs = this->getNumberOfOutputSockets(); bool outputStraightAlpha = (editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT) != 0; BKE_image_user_frame_calc(imageuser, context.getFramenumber(), 0); /* force a load, we assume iuser index will be set OK anyway */ if (image && image->type == IMA_TYPE_MULTILAYER) { bool is_multilayer_ok = false; ImBuf *ibuf = BKE_image_acquire_ibuf(image, imageuser, NULL); if (image->rr) { RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer); if (rl) { NodeOutput *socket; int index; is_multilayer_ok = true; for (index = 0; index < numberOfOutputs; index++) { NodeOperation *operation = NULL; socket = this->getOutputSocket(index); bNodeSocket *bnodeSocket = socket->getbNodeSocket(); RenderPass *rpass = (RenderPass *)BLI_findstring(&rl->passes, bnodeSocket->identifier, offsetof(RenderPass, internal_name)); int view = 0; /* Passes in the file can differ from passes stored in sockets (#36755). * Look up the correct file pass using the socket identifier instead. */ #if 0 NodeImageLayer *storage = (NodeImageLayer *)bnodeSocket->storage;*/ int passindex = storage->pass_index;*/ RenderPass *rpass = (RenderPass *)BLI_findlink(&rl->passes, passindex); #endif /* returns the image view to use for the current active view */ if (BLI_listbase_count_ex(&image->rr->views, 2) > 1) { const int view_image = imageuser->view; const bool is_allview = (view_image == 0); /* if view selected == All (0) */ if (is_allview) { /* heuristic to match image name with scene names * check if the view name exists in the image */ view = BLI_findstringindex(&image->rr->views, context.getViewName(), offsetof(RenderView, name)); if (view == -1) view = 0; } else { view = view_image - 1; } } if (rpass) { switch (rpass->channels) { case 1: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, rpass->passtype, view, COM_DT_VALUE); break; /* using image operations for both 3 and 4 channels (RGB and RGBA respectively) */ /* XXX any way to detect actual vector images? */ case 3: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, rpass->passtype, view, COM_DT_VECTOR); break; case 4: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, rpass->passtype, view, COM_DT_COLOR); break; default: /* dummy operation is added below */ break; } if (index == 0 && operation) { converter.addPreview(operation->getOutputSocket()); } if (rpass->passtype == SCE_PASS_COMBINED) { BLI_assert(operation != NULL); BLI_assert(index < numberOfOutputs - 1); NodeOutput *outputSocket = this->getOutputSocket(index + 1); SeparateChannelOperation *separate_operation; separate_operation = new SeparateChannelOperation(); separate_operation->setChannel(3); converter.addOperation(separate_operation); converter.addLink(operation->getOutputSocket(), separate_operation->getInputSocket(0)); converter.mapOutputSocket(outputSocket, separate_operation->getOutputSocket()); index++; } } /* incase we can't load the layer */ if (operation == NULL) converter.setInvalidOutput(getOutputSocket(index)); } } }