Пример #1
0
AbstractFSNode *AmigaOSFilesystemNode::getParent() const {
	ENTER();

	if (isRootNode()) {
		debug(6, "Root node");
		LEAVE();
		return new AmigaOSFilesystemNode(*this);
	}

	BPTR pLock = _pFileLock;

	if (!_bIsDirectory) {
		assert(!pLock);
		pLock = IDOS->Lock((CONST_STRPTR)_sPath.c_str(), SHARED_LOCK);
		assert(pLock);
	}

	AmigaOSFilesystemNode *node;

	BPTR parentDir = IDOS->ParentDir( pLock );
	if (parentDir) {
		node = new AmigaOSFilesystemNode(parentDir);
		IDOS->UnLock(parentDir);
	} else
		node = new AmigaOSFilesystemNode();

	if (!_bIsDirectory) {
		IDOS->UnLock(pLock);
	}

	LEAVE();

	return node;
}
Пример #2
0
void SceneNode::updateWorldTransform()
{
	worldTransform_ = getLocalTransform();

	if (!isRootNode())
	{
		worldTransform_ = parentNode_->getWorldTransform() * worldTransform_;
	}

	dirty_ = false;
}
Пример #3
0
bool AmigaOSFilesystemNode::isWritable() const {
	if (!_bIsValid)
		return false;

	// Regular RWED protection flags are low-active or inverted, thus the negation.
	// Moreover, a pseudo root filesystem is never writable whatever
	// the protection says (Because of it's pseudo nature).
	bool writable = !(_nProt & EXDF_OTR_WRITE) && !isRootNode();

	return writable;
}
Пример #4
0
bool AmigaOSFilesystemNode::isReadable() const {
	if (!_bIsValid)
		return false;

	// Regular RWED protection flags are low-active or inverted, thus the negation.
	// Moreover, a pseudo root filesystem is readable whatever the
	// protection says.
	bool readable = !(_nProt & EXDF_OTR_READ) || isRootNode();

	return readable;
}
Пример #5
0
/*!
  \brief Returns whether the root node of the model is one of the anchestors of this node.

  Will return true also for the root node itself.
  */
bool ModelNode::isInHierarchy() const
{
    if (!isValid()) {
        Q_ASSERT_X(isValid(), Q_FUNC_INFO, "model node is invalid");
        throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
    }
    if (isRootNode())
        return true;
    if (!hasParentProperty())
        return false;
    return parentProperty().parentModelNode().isInHierarchy();
}
Пример #6
0
/**
 * Converts a the tree stored in the Node into Newick format.
 *
 * @memberof Node
 * @public
 * @param node The Node object to convert.
 * @return The Node and its children formatted in Newick format.
 */
char * toString (Node * node) {
  char * newick;
  char * children;
  char * distance;
  char * buffer = malloc (NEWICK_BUFFER_SIZE * sizeof (char));
  /* Convert the distance attribute of this node to a string. */
  sprintf (buffer, "%f", node->distance);
  distance = strdup (buffer);
  /* Erase the buffer. */
  buffer[0] = '\0';
  /* Process this nodes children. */
  if (node->numChildren > 0) {
    size_t i;
    for (i = 0; i < node->numChildren; i++) {
      if (i != 0) {
        buffer = strcat (buffer, ",");
      }
      /* Process this child's subtree. */
      char * childTree = toString (node->children[i]);
      buffer = strcat (buffer, childTree);
      free (childTree);
    }
    children = malloc ((strlen (buffer) + 3) * sizeof (char));
    sprintf (children, "(%s)", buffer);
  }
  else {
    /* Node has no children, fill with an empty string (copy the empty buffer). */
    children = strdup (buffer);
  }
  /* Append a semi-colon to the end of the string if this is the root node. */
  size_t newickLength = strlen (children) + strlen (node->name) + strlen (distance);
  char * isRoot;
  if (isRootNode (node)) {
    isRoot = ";";
    newickLength ++;
  }
  else {
    isRoot = "";
  }
  /* Allocate memory for the Newick formatted tree. */
  newick = malloc ((newickLength + strlen (isRoot) + 2) * sizeof (char));
  sprintf (newick, "%s%s:%s%s", children, node->name, distance, isRoot);
  /* Free memory used by the buffer, children and distance strings. */
  free (buffer);
  free (children);
  free (distance);
  return newick;
}
Пример #7
0
bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
	ENTER();
	bool ret = false;

	// TODO: Honor the hidden flag
	// There is no such thing as a hidden flag in AmigaOS...

	if (!_bIsValid) {
		debug(6, "Invalid node");
		LEAVE();
		return false; // Empty list
	}

	if (!_bIsDirectory) {
		debug(6, "Not a directory");
		LEAVE();
		return false; // Empty list
	}

	if (isRootNode()) {
		debug(6, "Root node");
		LEAVE();
		myList = listVolumes();
		return true;
	}

	APTR context = IDOS->ObtainDirContextTags(  EX_FileLockInput,	_pFileLock,
												EX_DoCurrentDir,	TRUE,  /* for softlinks */
												EX_DataFields,		(EXF_NAME|EXF_LINK|EXF_TYPE),
												TAG_END);
	if (context) {
		struct ExamineData * pExd = NULL; // NB: No need to free the value after usage, everything will be dealt with by the DirContext release

		AmigaOSFilesystemNode *entry ;
		while ( (pExd = IDOS->ExamineDir(context)) ) {
			if (     (EXD_IS_FILE(pExd) && ( Common::FSNode::kListFilesOnly == mode ))
				||  (EXD_IS_DIRECTORY(pExd) && ( Common::FSNode::kListDirectoriesOnly == mode ))
				||  Common::FSNode::kListAll == mode
				)
			{
				BPTR pLock = IDOS->Lock( pExd->Name, SHARED_LOCK );
				if (pLock) {
					entry = new AmigaOSFilesystemNode( pLock, pExd->Name );
					if (entry) {
						myList.push_back(entry);
					}

					IDOS->UnLock(pLock);
				}
			}
		}

		if (ERROR_NO_MORE_ENTRIES != IDOS->IoErr() ) {
			debug(6, "An error occurred during ExamineDir");
			ret = false;
		} else {
			ret = true;
		}


		IDOS->ReleaseDirContext(context);
	} else {
		debug(6, "Unable to ObtainDirContext");
		ret = false;
	}

	LEAVE();

	return ret;
}
void OptimalNodeBasedEstimatorPhase::step(NodeBasedState& startState) {

    // skip already visited combinations
    std::size_t hash = std::hash<NodeBasedState>()(startState);
    if (visitedCombinations.find(hash) != visitedCombinations.end()) {
        numberOfStepsAvoided++;
        return;	// this combination has already been visited
    }
    visitedCombinations.insert(hash);

    numberOfStepsTaken++;
    ///XXX
    if(numberOfStepsTaken % 10000 == 0) {
        std::cout << numberOfStepsTaken << " steps taken ("
                  << numberOfStepsAvoided << " avoided) " << std::endl;
    }

#if USE_OPTIMIZED_ORDER
    // order the nodes by their weight, then start to replace the most expensive
    std::priority_queue<CgNodePtr, std::vector<CgNodePtr>, CalledMoreOften> pq;
    for (auto node : startState.nodeSet) {
        pq.push(node);
    }
    while (!pq.empty()) {
        auto node = pq.top();
        pq.pop();

#else
    for (auto node : startState.nodeSet) {
#endif

        if (node->isRootNode()) {
            continue;
        }

        auto parentNodes = node->getParentNodes();
        auto newState(startState);

#if DEBUG
        std::cout << "   " << "+ try switching " << *node	<< " for:  [";
        for (auto n : parentNodes) {
            std::cout << *n << ", ";
        }
        std::cout << "] ";
#endif

        if (!parentNodes.empty() && newState.validAfterExchange(node, parentNodes)) {
            unsigned long long costs = newState.getCosts();

            if (costs < optimalCosts) {

                ///XXX
                std::cout << "minimum: "
                          << optimalCosts*CgConfig::nanosPerInstrumentedCall/1e9 << " s" << std::endl;

                optimalCosts = costs;
                optimalInstrumentation = newState.nodeSet;
            }
#if DEBUG
            std::cout << "--> success" << std::endl;
#endif
            step(newState);

        } else {
#if DEBUG
            std::cout << "--> fail" << std::endl;
#endif
        }
    }
}

void OptimalNodeBasedEstimatorPhase::modifyGraph(CgNodePtr mainMethod) {

    findStartingState(mainMethod);

    step(stateStack.top());

    for (auto node : optimalInstrumentation) {
        node->setState(CgNodeState::INSTRUMENT_WITNESS);
    }
    mainMethod->setState(CgNodeState::NONE);	// main() is implicitly instrumented

}
Пример #9
0
void INode::renderTree(Context& ctx) const {
  for (size_t i = 0; i < _states.size(); i++) {
    // start point
    vec3 startpoint = ctx.getCurrentOrigin();

    // calculate end point of joint
    vec3 endpoint = _states[i]->getEndpoint(ctx);

    // draw the link
    //glBegin(GL_LINES);
    //  glColor3d(1.0, 1.0, 1.0);
    //  glVertex3d(startpoint[0], startpoint[1], startpoint[2]);
    //  glVertex3d(endpoint[0], endpoint[1], endpoint[2]);
    //glEnd();

    // calculate orthonormal basis for cylinder on joint
    vec3 u, v, n;
    _states[i]->getBasis(ctx, u, v, n);

    // check if basis is really orthonormal
    assert(double_equals(dot(u, v), 0));
    assert(double_equals(dot(u, n), 0));
    assert(double_equals(dot(v, n), 0));

    assert(double_equals(norm(u, 2), 1));
    assert(double_equals(norm(v, 2), 1));
    assert(double_equals(norm(n, 2), 1));

    //cout << "pos:" << endl << pos << endl;

    //cout << "u:" << endl << u << endl;
    //cout << "v:" << endl << v << endl;
    //cout << "n:" << endl << n << endl;

    vec3 x = makeVec3(1, 0, 0); 
    vec3 y = makeVec3(0, 1, 0);
    vec3 z = makeVec3(0, 0, 1);

    double ux = dot(x, u);
    double uy = dot(y, u);
    double uz = dot(z, u);

    double vx = dot(x, v);
    double vy = dot(y, v);
    double vz = dot(z, v);

    double nx = dot(x, n);
    double ny = dot(y, n);
    double nz = dot(z, n);

    // change of orthonormal basis from uvn -> xyz
    GLdouble m[16];
    m[0]  = ux;
    m[1]  = uy;
    m[2]  = uz;
    m[3]  = 0;
    
    m[4]  = vx; 
    m[5]  = vy;
    m[6]  = vz;
    m[7]  = 0;

    m[8]  = nx;
    m[9]  = ny;
    m[10] = nz;
    m[11] = 0;

    m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;

    mat44 A; 
    A << ux << vx << nx << 0 << endr 
      << uy << vy << ny << 0 << endr
      << uz << vz << nz << 0 << endr 
      << 0  << 0  << 0  << 1 << endr;

    //if (!double_equals(det(A), 1))
    //  cout << "A is: " << endl << A << endl;

    //cout << "det(A): " << det(A) << endl;
    const double dA = det(A);
    if (!double_equals(dA, 1)) {
      cerr << "ERROR: det(A) = " << dA << endl; 
      throw runtime_error("determinant not 1 for rotation matrix");
    }


    //cout << "--" << endl;
    //for (int iii = 0; iii < 16; iii++) {
    //  cout << m[iii] << endl;
    //}
    //cout << "--" << endl;

    if (isRootNode())
      glColor3d(0.0, 0.0, 0.8);
    else if (isFixed())
      glColor3d(0.0, 1.0, 1.0); 
    else
      glColor3d(0.0, 0.0, 1.0);

    glPushMatrix();
      glTranslated(startpoint[0], startpoint[1], startpoint[2]);
      if (isRootNode())
        glutSolidSphere(0.1, 20, 20);
      else
        glutSolidSphere(0.08, 20, 20);
    glPopMatrix();

    GLUquadricObj *quadric = gluNewQuadric();

    glPushMatrix();
      glColor3d(0.0, 1.0, 0.0);
      glTranslated(startpoint[0], startpoint[1], startpoint[2]);
      glMultMatrixd(m);
      gluCylinder(quadric, 0.05, 0.05, _states[i]->getLength(), 32, 32);
    glPopMatrix();

    gluDeleteQuadric(quadric);

    // recurse into child
    _states[i]->pushContext(ctx);
      _kids[i]->renderTree(ctx);
    ctx.popContext();
  }
}