Exemplo n.º 1
0
TFx *TExternalProgramFx::clone(bool recursive) const {
  TExternalProgramFx *fx =
      dynamic_cast<TExternalProgramFx *>(TExternFx::create(m_externFxName));
  assert(fx);
  // new TExternalProgramFx();
  // fx->setExecutable(m_executablePath, m_args);

  // copia della time region
  fx->setActiveTimeRegion(getActiveTimeRegion());
  // fx->m_imp->m_activeTimeRegion = m_imp->m_activeTimeRegion;

  fx->getParams()->copy(getParams());

  assert(getInputPortCount() == fx->getInputPortCount());

  // std::map<std::string, Port>::const_iterator j;
  // for(j=m_ports.begin(); j!=m_ports.end(); ++j)
  //  fx->addPort(j->first, j->second.m_ext, j->second.m_port != 0);

  // copia ricorsiva sulle porte
  if (recursive) {
    for (int i = 0; i < getInputPortCount(); ++i) {
      TFxPort *port = getInputPort(i);
      if (port->getFx())
        fx->connect(getInputPortName(i), port->getFx()->clone(true));
    }
  }

  // std::map<std::string, TParamP>::const_iterator j;
  // for(j=m_params.begin(); j!=m_params.end(); ++j)
  //  fx->addParam(j->first, j->second->clone());

  return fx;
}
Exemplo n.º 2
0
std::string Iwa_TiledParticlesFx::getAlias(double frame, const TRenderSettings &info) const
{
	std::string alias = getFxType();
	alias += "[";

	// alias degli effetti connessi alle porte di input separati da virgole
	// una porta non connessa da luogo a un alias vuoto (stringa vuota)
	for (int i = 0; i < getInputPortCount(); ++i) {
		TFxPort *port = getInputPort(i);
		if (port->isConnected()) {
			TRasterFxP ifx = port->getFx();
			assert(ifx);
			alias += ifx->getAlias(frame, info);
		}
		alias += ",";
	}

	std::string paramalias("");
	for (int i = 0; i < getParams()->getParamCount(); ++i) {
		TParam *param = getParams()->getParam(i);
		paramalias += param->getName() + "=" + param->getValueAlias(frame, 3);
	}

	return alias + toString(frame) + "," + toString(getIdentifier()) + paramalias + "]";
}
Exemplo n.º 3
0
std::string TGeometryFx::getAlias(double frame,
                                  const TRenderSettings &info) const {
  TGeometryFx *tthis = const_cast<TGeometryFx *>(this);
  TAffine affine     = tthis->getPlacement(frame);

  std::string alias = getFxType();
  alias += "[";

  // alias degli effetti connessi alle porte di input separati da virgole
  // una porta non connessa da luogo a un alias vuoto (stringa vuota)

  for (int i = 0; i < getInputPortCount(); ++i) {
    TFxPort *port = getInputPort(i);
    if (port->isConnected()) {
      TRasterFxP ifx = port->getFx();
      assert(ifx);
      alias += ifx->getAlias(frame, info);
    }
    alias += ",";
  }

  return alias +
         (areAlmostEqual(affine.a11, 0) ? "0" : ::to_string(affine.a11, 5)) +
         "," +
         (areAlmostEqual(affine.a12, 0) ? "0" : ::to_string(affine.a12, 5)) +
         "," +
         (areAlmostEqual(affine.a13, 0) ? "0" : ::to_string(affine.a13, 5)) +
         "," +
         (areAlmostEqual(affine.a21, 0) ? "0" : ::to_string(affine.a21, 5)) +
         "," +
         (areAlmostEqual(affine.a22, 0) ? "0" : ::to_string(affine.a22, 5)) +
         "," +
         (areAlmostEqual(affine.a23, 0) ? "0" : ::to_string(affine.a23, 5)) +
         "]";
}
Exemplo n.º 4
0
string TMacroFx::getAlias(double frame, const TRenderSettings &info) const
{
	string alias = getFxType();
	alias += "[";

	// alias degli effetti connessi alle porte di input separati da virgole
	// una porta non connessa da luogo a un alias vuoto (stringa vuota)
	int i;
	for (i = 0; i < getInputPortCount(); i++) {
		TFxPort *port = getInputPort(i);
		if (port->isConnected()) {
			TRasterFxP ifx = port->getFx();
			assert(ifx);
			alias += ifx->getAlias(frame, info);
		}
		alias += ",";
	}

	// alias dei valori dei parametri dell'effetto al frame dato
	for (int j = 0; j < (int)m_fxs.size(); j++) {
		alias += (j == 0) ? "(" : ",(";
		for (i = 0; i < m_fxs[j]->getParams()->getParamCount(); i++) {
			if (i > 0)
				alias += ",";
			TParam *param = m_fxs[j]->getParams()->getParam(i);
			alias += param->getName() + "=" + param->getValueAlias(frame, 2);
		}
		alias += ")";
	}

	alias += "]";
	return alias;
}
Exemplo n.º 5
0
std::vector<const TFx *> calculateSortedFxs(TRasterFxP rootFx) {
  std::map<const TFx *, std::set<const TFx *>> E; /* 辺の情報 */
  std::set<const TFx *> Sources; /* 入次数0のノード群 */

  std::queue<const TFx *> Q;
  Q.push(rootFx.getPointer());

  E[rootFx.getPointer()] = std::set<const TFx *>();

  while (!Q.empty()) {
    const TFx *vptr = Q.front();
    Q.pop();
    if (!vptr) {
      continue;
    }

    /* 繋がっている入力ポートの先の Fx を訪問する
入力ポートが無ければ終了 */
    int portCount = vptr->getInputPortCount();
    if (portCount < 1) {
      Sources.insert(vptr);
      continue;
    }
    for (int i = 0; i < portCount; i++) {
      TFxPort *port = vptr->getInputPort(i);
      if (!port) {
        continue;
      }
      TFxP u          = port->getFx();
      const TFx *uptr = u.getPointer();
      if (E.count(uptr) == 0) {
        E[uptr] = std::set<const TFx *>();
      }
      if (E[uptr].count(vptr) == 0) {
        E[uptr].insert(vptr);
      }
      Q.push(uptr);
    }
  }

  /* トポロジカルソート */
  std::set<const TFx *> visited;
  std::vector<const TFx *> L;
  std::function<void(const TFx *)> visit = [&visit, &visited, &E,
                                            &L](const TFx *fx) {
    if (visited.count(fx)) return;
    visited.insert(fx);
    auto edge = E[fx];
    for (auto i = edge.cbegin(); i != edge.cend(); i++) {
      visit(*i);
    }
    L.insert(L.begin(), fx);
  };
  for (auto i = E.cbegin(); i != E.cend(); i++) {
    visit(i->first);
  }
  return L;
}
Exemplo n.º 6
0
void SwatchCacheManager::setFx(const TFxP &fx)
{
	QMutexLocker locker(&m_mutex);

	//Update the fxs id data
	if (fx == TFxP()) {
		//Clear if no fx is set
		m_setFxId = 0;
		m_childrenFxIds.clear();
	} else {
		m_setFxId = fx->getIdentifier();
		m_childrenFxIds.clear();
		assert(m_setFxId != 0);

		TRasterFx *rfx = dynamic_cast<TRasterFx *>(fx.getPointer());
		assert(rfx);

		for (int i = 0; i < fx->getInputPortCount(); ++i) {
			//Fxs not allowing cache on the input port are skipped
			if (!rfx->allowUserCacheOnPort(i))
				continue;

			TFxPort *iport = fx->getInputPort(i);
			if (iport && iport->isConnected()) {
				TFx *child = iport->getFx();

				//In the zerary case, extract the actual fx
				TZeraryColumnFx *zcfx = dynamic_cast<TZeraryColumnFx *>(child);
				if (zcfx)
					child = zcfx->getZeraryFx();

				assert(child && child->getIdentifier() != 0);
				m_childrenFxIds.insert(child->getIdentifier());
			}
		}
	}

	//NOTE: Check if this should be avoided in some case...

	//Release the locks and clear the resources
	if (m_currEditedFxResult)
		m_currEditedFxResult->releaseLock();
	m_currEditedFxResult = TCacheResourceP();

	std::set<TCacheResourceP>::iterator it;
	for (it = m_swatchCacheContainer.begin(); it != m_swatchCacheContainer.end(); ++it)
		(*it)->releaseLock();
	m_swatchCacheContainer.clear();

#ifdef USE_SQLITE_HDPOOL
	TCacheResourcePool::instance()->releaseReferences("S");
#else
	for (it = m_genericCacheContainer.begin(); it != m_genericCacheContainer.end(); ++it)
		(*it)->releaseLock();
	m_genericCacheContainer.clear();
#endif
}
Exemplo n.º 7
0
TFx *TMacroFx::clone(bool recursive) const
{
	int n = m_fxs.size();
	vector<TFxP> clones(n);
	std::map<TFx *, int> table;
	std::map<TFx *, int>::iterator it;
	int i, rootIndex = -1;
	// nodi
	for (i = 0; i < n; ++i) {
		TFx *fx = m_fxs[i].getPointer();
		assert(fx);
		clones[i] = fx->clone(false);
		assert(table.count(fx) == 0);
		table[fx] = i;
		if (fx == m_root.getPointer())
			rootIndex = i;
		TFx *linkedFx = fx->getLinkedFx();
		if (linkedFx && table.find(linkedFx) != table.end())
			clones[i]->linkParams(clones[table[linkedFx]].getPointer());
	}
	assert(rootIndex >= 0);
	// connessioni
	for (i = 0; i < n; i++) {
		TFx *fx = m_fxs[i].getPointer();
		for (int j = 0; j < fx->getInputPortCount(); j++) {
			TFxPort *port = fx->getInputPort(j);
			TFx *inputFx = port->getFx();
			if (!inputFx)
				continue;
			it = table.find(inputFx);
			if (it == table.end()) {
				// il j-esimo input di fx e' esterno alla macro
				if (recursive)
					clones[i]->connect(fx->getInputPortName(j), inputFx->clone(true));
			} else {
				// il j-esimo input di fx e' interno alla macro
				clones[i]->connect(fx->getInputPortName(j), clones[it->second].getPointer());
			}
		}
	}

	//TFx *rootClone =
	//  const_cast<TMacroFx*>(this)->
	//  clone(m_root.getPointer(), recursive, visited, clones);

	TMacroFx *clone = TMacroFx::create(clones);
	clone->setName(getName());
	clone->setFxId(getFxId());

	//Copy the index of the passive cache manager.
	clone->getAttributes()->passiveCacheDataIdx() = getAttributes()->passiveCacheDataIdx();

	assert(clone->getRoot() == clones[rootIndex].getPointer());

	return clone;
}
Exemplo n.º 8
0
void TRasterFx::compute(TFlash &flash, int frame) {
  for (int i = getInputPortCount() - 1; i >= 0; i--) {
    TFxPort *port = getInputPort(i);

    if (port->isConnected() && !port->isaControlPort()) {
      flash.pushMatrix();
      ((TRasterFxP)(port->getFx()))->compute(flash, frame);
      flash.popMatrix();
    }
  }
}
Exemplo n.º 9
0
void MultimediaRenderer::Imp::addPostProcessingRecursive(TFxP fx, TFxP postProc)
{
	if (!postProc)
		return;

	int i, count = postProc->getInputPortCount();
	for (i = 0; i < count; ++i) {
		TFxPort *port = postProc->getInputPort(i);
		TFx *childFx = port->getFx();

		if (dynamic_cast<TXsheetFx *>(childFx))
			port->setFx(fx.getPointer());
		else
			addPostProcessingRecursive(fx, childFx);
	}
}
Exemplo n.º 10
0
void Iwa_TiledParticlesFx::doDryCompute(TRectD &rect, double frame, const TRenderSettings &info)
{
	Iwa_ParticlesManager *pc = Iwa_ParticlesManager::instance();
	unsigned long fxId = getIdentifier();
	int inputPortCount = getInputPortCount();

	int i,
		j,
		curr_frame = frame,					   /*- 現在のフレーム -*/
		startframe = startpos_val->getValue(); /*- Particesの開始フレーム -*/

	TRenderSettings infoOnInput(info);
	infoOnInput.m_affine = TAffine(); // Using the standard reference - indep. from cameras.
	infoOnInput.m_bpp = 64;			  // Control ports rendered at 32 bit - since not visible.

	for (i = startframe - 1; i <= curr_frame; ++i) {
		double frame = tmax(0, i);

		for (j = 0; j < inputPortCount; ++j) {
			TFxPort *port = getInputPort(j);
			std::string tmpName = getInputPortName(j);
			if (port->isConnected()) {
				TRasterFxP fx = port->getFx();

				// Now, consider that source ports work different than control ones
				QString portName = QString::fromStdString(tmpName);
				if (portName.startsWith("C")) {
					// Control ports are calculated from start to current frame, since
					// particle mechanics at current frame is influenced by previous ones
					// (and therefore by all previous control images).

					TRectD bbox;
					fx->getBBox(frame, bbox, infoOnInput);
					if (bbox == TConsts::infiniteRectD)
						bbox = info.m_affine.inv() * rect;
					fx->dryCompute(bbox, frame, infoOnInput);
				} else if (portName.startsWith("T")) {
					// Particles handle source ports caching procedures on its own.
				}
			}
		}
	}
}
Exemplo n.º 11
0
bool TMacroFx::isaLeaf(TFx *fx) const
{
	int count = fx->getInputPortCount();
	if (count == 0)
		return true;

	for (int i = 0; i < count; ++i) {
		TFxPort *port = fx->getInputPort(i);
		TFx *inputFx = port->getFx();
		if (inputFx) {
			if (std::find_if(m_fxs.begin(), m_fxs.end(), MatchesFx(inputFx)) == m_fxs.end()) {
				// il nodo di input non appartiene al macroFx
				return true;
			}
		} else {
			// la porta di input non e' connessa
			return true;
		}
	}

	// tutte le porte di input sono connesse verso nodi appartenenti al macroFx
	return false;
}
Exemplo n.º 12
0
Link FxSelection::getBoundingFxs(SchematicPort *inputPort,
                                 SchematicPort *outputPort) {
  Link boundingFxs;
  FxSchematicNode *inputNode =
      dynamic_cast<FxSchematicNode *>(outputPort->getNode());
  FxSchematicNode *outputNode =
      dynamic_cast<FxSchematicNode *>(inputPort->getNode());
  FxGroupNode *groupNode = dynamic_cast<FxGroupNode *>(inputNode);

  if (!inputNode || !outputNode ||
      (groupNode && groupNode->getOutputConnectionsCount() != 1))
    return boundingFxs;
  if (dynamic_cast<TXsheetFx *>(outputNode->getFx())) {
    if (!groupNode)
      boundingFxs.m_inputFx = inputNode->getFx();
    else {
      TFxSet *terminals =
          m_xshHandle->getXsheet()->getFxDag()->getTerminalFxs();
      QList<TFxP> roots = groupNode->getRootFxs();
      int i;
      for (i = 0; i < roots.size(); i++)
        if (terminals->containsFx(roots[i].getPointer())) {
          boundingFxs.m_inputFx = roots[i];
          break;
        }
    }
    boundingFxs.m_outputFx = outputNode->getFx();
    return boundingFxs;
  }

  if (outputNode->isA(eGroupedFx)) {
    // devo prima trovare l'effetto interno al gruppo al quale inputNode e'
    // linkato.
    FxGroupNode *groupNode = dynamic_cast<FxGroupNode *>(outputNode);
    assert(groupNode);
    QList<TFx *> fxs;
    TFx *inputFx = inputNode->getFx();
    int i;
    for (i = 0; i < inputFx->getOutputConnectionCount(); i++) {
      TFx *outputFx = inputFx->getOutputConnection(i)->getOwnerFx();
      if (!outputFx) continue;
      if (groupNode->contains(outputFx)) fxs.push_back(outputFx);
    }
    if (fxs.size() != 1)  // un nodo esterno al gruppo puo' essere linkato a
                          // piu' nodi interni al gruppo
      return boundingFxs;

    TFx *outputFx = fxs[0];
    // ho tovato l'effetto, ora devo trovare l'indice della porta a cui e'
    // linkato l'effetto in input
    for (i = 0; i < outputFx->getInputPortCount(); i++) {
      TFxPort *inputPort = outputFx->getInputPort(i);
      TFx *fx            = inputPort->getFx();
      if (fx == inputFx) break;
    }
    if (i >= outputFx->getInputPortCount()) return boundingFxs;
    boundingFxs.m_inputFx  = inputFx;
    boundingFxs.m_outputFx = outputFx;
    boundingFxs.m_index    = i;
    return boundingFxs;
  } else {
    bool found = false;
    int i, index = -1;
    for (i = 0; i < outputNode->getInputPortCount() && !found; i++) {
      FxSchematicPort *inputAppPort = outputNode->getInputPort(i);
      int j;
      for (j = 0; j < inputAppPort->getLinkCount(); j++) {
        FxSchematicNode *outputAppNode =
            dynamic_cast<FxSchematicNode *>(inputAppPort->getLinkedNode(j));
        if (!outputAppNode) continue;
        FxSchematicPort *outputAppPort = outputAppNode->getOutputPort();
        if (inputAppPort == inputPort && outputPort == outputAppPort) {
          found = true;
          index = i;
          break;
        }
      }
    }
    if (index == -1) return boundingFxs;
    TFx *inputFx           = inputNode->getFx();
    TFx *outputFx          = outputNode->getFx();
    boundingFxs.m_inputFx  = inputFx;
    boundingFxs.m_outputFx = outputFx;
    boundingFxs.m_index    = index;
    return boundingFxs;
  }
}
Exemplo n.º 13
0
bool TMacroFx::analyze(const vector<TFxP> &fxs,
					   TFxP &root,
					   vector<TFxP> &roots,
					   vector<TFxP> &leafs)
{
	if (fxs.size() == 1)
		return false;
	else {
		leafs.clear();
		roots.clear();
		std::vector<TFxP>::const_iterator it = fxs.begin();
		for (; it != fxs.end(); ++it) {
			TFxP fx = *it;
			int inputInternalConnection = 0;
			int inputExternalConnection = 0;
			int outputInternalConnection = 0;
			int outputExternalConnection = 0;

			int i;

			// calcola se ci sono connessioni in input dall'esterno
			// verso l'interno e/o internamente a orderedFxs
			int inputPortCount = fx->getInputPortCount();
			for (i = 0; i < inputPortCount; ++i) {
				TFxPort *inputPort = fx->getInputPort(i);
				TFx *inputPortFx = inputPort->getFx();
				if (inputPortFx) {
					if (std::find_if(fxs.begin(), fxs.end(), MatchesFx(inputPortFx)) != fxs.end())
						++inputInternalConnection;
					else
						++inputExternalConnection;
				}
			}

			// calcola se ci sono connessioni in output dall'interno
			// verso l'esterno e/o internamente a orderedFxs
			int outputPortCount = fx->getOutputConnectionCount();
			for (i = 0; i < outputPortCount; ++i) {
				TFxPort *outputPort = fx->getOutputConnection(i);
				TFx *outputFx = outputPort->getOwnerFx();
				if (outputFx) {
					if (std::find_if(fxs.begin(), fxs.end(), MatchesFx(outputFx)) != fxs.end())
						++outputInternalConnection;
					else
						++outputExternalConnection;
				}
			}

			// se fx e' una radice
			if ((outputExternalConnection > 0) ||
				(outputExternalConnection == 0 && outputInternalConnection == 0)) {
				root = fx;
				roots.push_back(fx);
			}

			// se fx e' una foglia
			if (inputExternalConnection > 0 || fx->getInputPortCount() == 0 ||
				(inputExternalConnection == 0 && inputInternalConnection < fx->getInputPortCount())) {
				leafs.push_back(fx);
			}
		}

		if (roots.size() != 1)
			return false;
		else {
			if (leafs.size() == 0)
				return false;
		}

		return true;
	}
}
Exemplo n.º 14
0
TMacroFx *TMacroFx::create(const vector<TFxP> &fxs)
{
	std::vector<TFxP> leafs;
	std::vector<TFxP> roots;
	TFxP root = 0;

	vector<TFxP> orederedFxs = sortFxs(fxs);

	// verifica che gli effetti selezionati siano idonei ad essere raccolti
	// in una macro. Ci deve essere un solo nodo terminale
	// (roots.size()==1, roots[0] == root) e uno o piu' nodi di ingresso
	// (assert leafs.size()>0)
	if (!analyze(orederedFxs, root, roots, leafs))
		return 0;

	// -----------------------------

	TMacroFx *macroFx = new TMacroFx;

	// tutti i nodi vengono spostati (e non copiati) nella macro stessa
	std::vector<TFxP>::const_iterator it = orederedFxs.begin();
	for (; it != orederedFxs.end(); ++it)
		macroFx->m_fxs.push_back(*it);

	// i nodi di ingresso vengono messi in collegamento con le
	// porte di ingresso della macro
	for (int i = 0; i < (int)leafs.size(); i++) {
		TFxP fx = leafs[i];
		int k = 0;
		int count = fx->getInputPortCount();
		for (; k < count; k++) {
			TFxPort *port = fx->getInputPort(k);
			string portName = fx->getInputPortName(k);
			string fxId = toString(fx->getFxId());
			portName += "_" + toString(macroFx->getInputPortCount()) + "_" + fxId;
			TFx *portFx = port->getFx();
			if (portFx) {
				// se la porta k-esima del nodo di ingresso i-esimo e' collegata
				// ad un effetto, la porta viene inserita solo se l'effetto non fa
				// gia' parte della macro
				if (std::find_if(orederedFxs.begin(), orederedFxs.end(), MatchesFx(portFx)) == orederedFxs.end())
					macroFx->addInputPort(portName, *port);
			} else
				macroFx->addInputPort(portName, *port);
		}
	}

	// le porte di uscita di root diventano le porte di uscita della macro
	int count = root->getOutputConnectionCount();
	int k = count - 1;
	for (; k >= 0; --k) {
		TFxPort *port = root->getOutputConnection(k);
		port->setFx(macroFx);
	}

	macroFx->setRoot(root.getPointer());

	// tutti i parametri delle funzioni figlie diventano parametri della macro
	collectParams(macroFx);
	return macroFx;
}