Пример #1
0
void DynoTree::makeBranch(glm::vec3 pos, glm::vec3 dir, float len, float width, int lastRingIndex,bool swapTex)
{
  // Construct the two basis vectors for construction of points
  glm::vec3 basisA = glm::normalize(glm::cross(dir,glm::vec3(1,0,1)));
  glm::vec3 basisB = glm::normalize(glm::cross(dir,basisA));
  // If we need to make a bottom ring, do so
  if (lastRingIndex==-1)
    lastRingIndex = makeRing(pos,basisA,basisB,width,true);
  // Otherwise, and in addition, create the top ring
  int topRingIndex = makeRing(pos+dir*len,basisA,basisB,width*0.66f,swapTex);
	// Add in all the triangles
	makeTriangles(lastRingIndex,topRingIndex);
  // If the branch is thick enough, we can branch into two others
  if (width>0.05)
  {
    // Get a random direction
    glm::vec3 d = glm::sphericalRand(1.f);
    // Add it to this direction
    glm::vec3 newDirection = dir + d/1.8f;
    // Make a sub branch in that direction
    makeBranch(pos+dir*len,glm::normalize(newDirection),len/1.2f,width*2.f/5.f,-1,false);
    // Do it again
    d = glm::sphericalRand(1.f);
    newDirection = dir + d/2.8f;
    // Continue this branch
    makeBranch(pos+dir*len,glm::normalize(newDirection),len/1.2f,width*3.f/5.f,topRingIndex,!swapTex);
  }
  // If we are small enough, we can put leaves here
  if (width<0.3f)
    makeLeaves(pos,dir,len);
}
Пример #2
0
ILOBRANCHCALLBACK1(MyBranch, IloNumVarArray, vars) {
   if ( getBranchType() != BranchOnVariable )
      return;

   // Branch on var with largest objective coefficient
   // among those with largest infeasibility

   IloNumArray x;
   IloNumArray obj;
   IntegerFeasibilityArray feas;

   try {
      x    = IloNumArray(getEnv());
      obj  = IloNumArray(getEnv());
      feas = IntegerFeasibilityArray(getEnv());
      getValues(x, vars);
      getObjCoefs(obj, vars);
      getFeasibilities(feas, vars);

      IloInt bestj  = -1;
      IloNum maxinf = 0.0;
      IloNum maxobj = 0.0;
      IloInt cols = vars.getSize();
      for (IloInt j = 0; j < cols; j++) {
         if ( feas[j] == Infeasible ) {
            IloNum xj_inf = x[j] - IloFloor (x[j]);
            if ( xj_inf > 0.5 )
               xj_inf = 1.0 - xj_inf;
            if ( xj_inf >= maxinf                              &&
                 (xj_inf > maxinf || IloAbs (obj[j]) >= maxobj)  ) {
               bestj  = j;
               maxinf = xj_inf;
               maxobj = IloAbs (obj[j]);
            }
         }
      }

      if ( bestj >= 0 ) {
         makeBranch(vars[bestj], x[bestj], IloCplex::BranchUp,   getObjValue());
         makeBranch(vars[bestj], x[bestj], IloCplex::BranchDown, getObjValue());
      }
   }
   catch (...) {
      x.end();
      obj.end();
      feas.end();
      throw;
   }
   x.end();
   obj.end();
   feas.end();
}
Пример #3
0
bool XmlSettingsEntry::setString( const QString &xpath, const QString &str )
{
	QStringList xpsl;
	JQ_ASSERT(m_master);

	if( !splitXPath( xpath, xpsl ) ) {
		return false;
	}

	XmlSettingsEntry entry( makeBranch(xpsl) );

	if( entry.isInvalid() )
		return false;

	if( entry.type() == AbstractNode::Map ) {
		MapNode *mapNode = dynamic_cast<MapNode*>(entry.m_rootNode);
		if( mapNode->contains(__TEXT_PSEUDO_ELEMENT) ) {
			entry.m_rootNode = (*mapNode)[__TEXT_PSEUDO_ELEMENT];
		} else {
			entry.m_rootNode = new ScalarNode();
		}
	}

	JQ_ASSERT( entry.type() == AbstractNode::Scalar );

	dynamic_cast<ScalarNode*>(entry.m_rootNode)->setValue(str);
	m_master->m_modified = true;
	return true;
}
Пример #4
0
BOOL HUDPatchInJump(DWORD destination, BOOL linked = false) {
	setmemdm((LPVOID)HUDelems.BootToDashHelper_Jump, makeBranch(HUDelems.BootToDashHelper_Jump, (HUDelems.FamilySettings_LaunchStr) + 0x4, true));
	setmemdm((LPVOID)HUDelems.FamilySettings_LaunchStr, 0x4E800020);
	BYTE data[0x10];
	PatchInJump((PDWORD)data, (DWORD)destination, linked);
	memcpy((DWORD*)(HUDelems.FamilySettings_LaunchStr + 4), (LPCVOID)data, 0x10);
	return 1;
}
Пример #5
0
Long_t Plugin::copyBranch(const char *name)
{
  debug(10,"Plugin: Copying branch %s\n",name);
  TObject **p = new (TObject *);
  getBranchObject(name,p);
  makeBranch(name,p);
  return 0;
}
Пример #6
0
Long_t Plugin::copyBranch_gracefully(const char *name)
{
  debug(10,"Plugin: Copying branch %s 'gracefully'\n",name);
  TObject **p = new (TObject *);
  getBranchObject(name,p);
  if (*p)
    makeBranch(name,p);
  else
    debug(0, "Plugin: branch %s wasn't found - skipping it!\n", name);
  return 0;
}
Пример #7
0
/// Construct the triangles
void DynoTree::initialiseTriangles()
{
	// Begin the operation of setting up triangles
  // Reserve this many (experimentation showed these as good values
	clearTriangleData(3000,2000);
  // Now set these to 0 so that we don't pass too many to th object class.
  // These values will be incrimented by the makeBranch and makeLeaves methods
  numberOfPoints = 0;
  numberOfTriangles = 0;
  // Construct the trunk, 1m below the ground, going up.
  makeBranch(glm::vec3(0,-1,0),glm::vec3(0,1,0),3,1,-1,false);
	// And save
	pushTriangleData();
}
Пример #8
0
ILOBRANCHCALLBACK1(SOSbranch, IloSOS1Array, sos) {
    IloNumArray    x;
    IloNumVarArray var;

    try {
        IloInt i;
        x   = IloNumArray(getEnv());
        var = IloNumVarArray(getEnv());
        IloNum bestx = EPS;
        IloInt besti = -1;
        IloInt bestj = -1;
        IloInt num = sos.getSize();

        for (i = 0; i < num; i++) {
            if ( getFeasibility(sos[i]) == Infeasible ) {
                var.clear();
                sos[i].getVariables(var);
                getValues(x, var);
                IloInt n = var.getSize();
                for (IloInt j = 0; j < n; j++) {
                    IloNum inf = IloAbs(x[j] - IloRound(x[j]));
                    if ( inf > bestx ) {
                        bestx = inf;
                        besti = i;
                        bestj = j;
                    }
                }
            }
        }

        if ( besti >= 0 ) {
            IloCplex::BranchDirectionArray dir;
            IloNumArray                    val;
            try {
                dir = IloCplex::BranchDirectionArray(getEnv());
                val = IloNumArray(getEnv());
                var.clear();
                sos[besti].getVariables(var);
                IloInt n = var.getSize();
                for (IloInt j = 0; j < n; j++) {
                    if ( j != bestj ) {
                        dir.add(IloCplex::BranchDown);
                        val.add(0.0);
                    } else {
                        dir.add(IloCplex::BranchUp);
                        val.add(1.0);
                    }
                }
                makeBranch(var,        val, dir,                  getObjValue());
                makeBranch(var[bestj], 0.0, IloCplex::BranchDown, getObjValue());
            }
            catch (...) {
                dir.end();
                val.end();
                throw;
            }
            dir.end();
            val.end();
        }
    }
    catch (...) {
        var.end();
        x.end();
        throw;
    }

    var.end();
    x.end();
}