Beispiel #1
0
void KDTree::buildNode(std::vector<int> &objects, std::vector<AABoundingBox> &bounds, int depth,  AABoundingBox totalBounds)
{
    if(objects.size() <= m_maxPrims || depth == 0) {
        KDTreeLeafNode *leafNode = new KDTreeLeafNode(objects,this);
        m_nodes.push_back(leafNode);
    }
    else {
        int splitPosition;
        char axis = findSplitAxis(objects,bounds,totalBounds);
        KDTreeInteriorNode *interiorNode = new KDTreeInteriorNode(this);
        int numRetries = 0;
        while(numRetries < 3) {
            splitPosition = findSplitPos(objects,bounds,totalBounds,axis);
            if(splitPosition == -1) {
                numRetries++;
                axis = (axis+1)%3;
            }
            else {
                numRetries = 10;
            }
        }
        if(splitPosition == -1) {
            splitPosition = objects.size();
        }
        interiorNode->setDepth(depth);
        m_nodes.push_back(interiorNode);
        std::vector<int> lowerObjects;
        std::vector<int> upperObjects;
        AABoundingBox lowerBounds;
        AABoundingBox upperBounds;
        for (int i = 0; i < splitPosition; i++) {
            if(m_boundEdges[axis][i].m_start) {
                lowerObjects.push_back(m_boundEdges[axis][i].m_primNum);
                lowerBounds.extend(m_objects[m_boundEdges[axis][i].m_primNum]);
            }
        }
        for (int i = splitPosition+1; i < objects.size() * 2; i++) {
            if(!m_boundEdges[axis][i].m_start) {
                upperObjects.push_back(m_boundEdges[axis][i].m_primNum);
                upperBounds.extend(m_objects[m_boundEdges[axis][i].m_primNum]);
            }
        }
        int nextDepth = depth-1;
        interiorNode->setAxis(axis);
        interiorNode->setPosition(m_boundEdges[axis][splitPosition].m_pos);
        interiorNode->setLowerChildIndex(m_nodes.size());
        buildNode(lowerObjects,bounds,nextDepth,lowerBounds);
        interiorNode->setUpperChildIndex(m_nodes.size());
        buildNode(upperObjects,bounds,nextDepth,upperBounds);
    }
}
Beispiel #2
0
void BallTree<_Scalar>::buildNode(Node& node, std::vector<int>& indices, AxisAlignedBoxType aabb, int level)
{
	Scalar avgradius = 0.;
	for (std::vector<int>::const_iterator it=indices.begin(), end=indices.end() ; it!=end ; ++it)
			avgradius += mRadii[*it];
	avgradius = mRadiusScale * avgradius / Scalar(indices.size());
	VectorType diag = aabb.max - aabb.min;
	if  (int(indices.size())<mTargetCellSize
		|| avgradius*0.9 > std::max(std::max(diag.X(), diag.Y()), diag.Z())
		|| int(level)>=mMaxTreeDepth)
	{
		node.leaf = true;
		node.size = indices.size();
		node.indices = new unsigned int[node.size];
		for (unsigned int i=0 ; i<node.size ; ++i)
			node.indices[i] = indices[i];
		return;
	}
	unsigned int dim = vcg::MaxCoeffId(diag);
	node.dim = dim;
	node.splitValue = Scalar(0.5*(aabb.max[dim] + aabb.min[dim]));
  node.leaf = 0;

	AxisAlignedBoxType aabbLeft=aabb, aabbRight=aabb;
	aabbLeft.max[dim] = node.splitValue;
	aabbRight.min[dim] = node.splitValue;

	std::vector<int> iLeft, iRight;
	split(indices, aabbLeft, aabbRight, iLeft,iRight);

	// we don't need the index list anymore
	indices.clear();

	{
		// left child
		//mNodes.resize(mNodes.size()+1);
		Node* pChild = new Node();
		node.children[0] = pChild;
		buildNode(*pChild, iLeft, aabbLeft, level+1);
	}

	{
		// right child
		//mNodes.resize(mNodes.size()+1);
		Node* pChild = new Node();
		node.children[1] = pChild;
		buildNode(*pChild, iRight, aabbRight, level+1);
	}
}
Beispiel #3
0
//}}}1
//{{{1 private functions
void Scene::buildScene(Json::Value node) {
    Json::Value cam = node["camera"];
    buildCamera(cam);

    Json::Value lights = node["lights"];
    for(int i=0; i<lights.size(); i++) {
        buildLight(lights[i]);
    }

    Json::Value models = node["models"];
    for(int i=0; i<models.size(); i++) {
        buildNode(models[i]);
    }

    if(node.isMember("instances")) {
        Json::Value instances = node["instances"];
        for(int i=0; i<instances.size(); i++) {
            buildInstance(instances[i]);
        }
    }

    Json::Value anims = node["animations"];
    for(int i=0; i<anims.size(); i++) {
        buildAnimation(anims[i]);
    }

    mat4 wm = LookAt(eye, at, up);
    setWorldMatrix(LookAt(eye, at, up));
    printf("set init world matrix\n");
}
Beispiel #4
0
void BVH::buildBVH( SplitMethod i_method, const BVHItems &i_items )
{
    if ( i_items.empty() )
    {
        return;
    }
    
    m_nodes.reserve( i_items.size() );
    m_items.reserve( i_items.size() );
    
    const size_t itemCount = i_items.size();
    BVHItems buildItems;
    buildItems.reserve( itemCount );
    
    for ( size_t i = 0; i < itemCount; i++ )
    {
        BVHItem internalItem = i_items[ i ];
        internalItem.index = i;
        
        // Add to list
        buildItems.push_back( internalItem );
    }
    
    buildNode( i_method, buildItems, 0, itemCount );
}
Beispiel #5
0
int FlameGraph::buildNode(const QModelIndex &parentIndex, QObject *parentObject, int depth)
{
    qreal position = 0;
    qreal skipped = 0;
    qreal parentSize = m_model->data(parentIndex, m_sizeRole).toReal();
    QQuickItem *parentItem = qobject_cast<QQuickItem *>(parentObject);
    QQmlContext *context = qmlContext(this);
    int rowCount = m_model->rowCount(parentIndex);
    int childrenDepth = depth;
    for (int row = 0; row < rowCount; ++row) {
        QModelIndex childIndex = m_model->index(row, 0, parentIndex);
        qreal size = m_model->data(childIndex, m_sizeRole).toReal();
        if (size / m_model->data(QModelIndex(), m_sizeRole).toReal() < m_sizeThreshold) {
            skipped += size;
            continue;
        }

        QObject *childObject = appendChild(parentObject, parentItem, context, childIndex,
                                           position / parentSize, size / parentSize);
        position += size;
        childrenDepth = qMax(childrenDepth, buildNode(childIndex, childObject, depth + 1));
    }

    if (skipped > 0) {
        appendChild(parentObject, parentItem, context, QModelIndex(), position / parentSize,
                    skipped / parentSize);
        childrenDepth = qMax(childrenDepth, depth + 1);
    }

    return childrenDepth;
}
Beispiel #6
0
/*
 * Class:     org_xmlsoft_Node
 * Method:    previousImpl
 * Signature: ()Lrath/libxml/Node;
 */
JNIEXPORT jobject JNICALL Java_org_xmlsoft_Node_previousImpl
  (JNIEnv *env, jobject obj) {
    xmlNode *node = findNode(env, obj);
    if (node->prev==NULL )
        return NULL;
    return buildNode(env, node->prev, DOC(obj));
}
Beispiel #7
0
nodePaths buildTree(RST* root, int** instance, int** mst, int mst_length){
    //Please note point 0 on Path* is xTraversal and 1 is yTravesal
    int index=0;
    nodePaths* childPaths = malloc(sizeof(nodePaths)*7);
    nodePaths nodePath;
    for(int i=0; i< mst_length; i++){
        if(mst[i][0] == root->index){
            //this must contain a child
            RST* child = buildNode(root, mst[i][1],NULL, mst[i][2], 0);
            root->child[root->indegree] = child;
            root->indegree++;
            index++;
            childPaths[index] = buildTree(child, instance, mst, mst_length);
        }
    }
    // if(index>0){
    //     int maxIndex = findMaxOverlap(childPaths, index);
    // }
    Path* currentPaths= malloc(sizeof(int)*2*3);
    // int* nodeA = instance[MST[index][0]];
    // int* node = instance[MST[index][1]];

    currentPaths[0] = buildPath(instance[root->index], instance[root->parent->index], 0);
    currentPaths[1] = buildPath(instance[root->index], instance[root->parent->index], 1);
    nodePath.paths = currentPaths;
    nodePath.index = root->index;
    return nodePath;
};
Beispiel #8
0
/*
 * Class:     org_xmlsoft_Node
 * Method:    getParentImpl
 * Signature: ()Lrath/libxml/Node;
 */
JNIEXPORT jobject JNICALL Java_org_xmlsoft_Node_getParentImpl
(JNIEnv *env, jobject obj) {
    xmlNode *node = findNode(env, obj);
//    if( node->parent!=NULL && node->parent->type==XML_DOCUMENT_NODE) {
//    
//    }
    return buildNode(env, node->parent, DOC(obj));
}
void AngelScriptReferenceDialog::buildNode(QTreeWidgetItem* tnode, RefNode* node) {
    QLabel* sub = new QLabel(node->name().c_str(), owner_);
    sub->setFont(getFormatting(node->hint()));
    sub->setStyleSheet("margin: 5px 5px 5px 5px");
    auto subNode = addItem(tnode, sub);
    contents_[size_t(subNode)] = node->content();
    for(auto &data: node->children()) {
        buildNode(subNode, data);
    }
}
Beispiel #10
0
/*
 * Class:     org_xmlsoft_Node
 * Method:    addPrevSiblingImpl
 * Signature: (Lrath/libxml/Node;)Lrath/libxml/Node;
 */
JNIEXPORT jobject JNICALL Java_org_xmlsoft_Node_addPrevSiblingImpl
(JNIEnv *env, jobject obj, jobject toAdd) {
    xmlNode *node = findNode(env, obj);
    xmlNode *nodeToAdd = findNode(env, toAdd);
    jobject jdoc = (*env)->GetObjectField(env, obj, fieldNodeDocument);
    xmlNode *nodeAdded = xmlAddPrevSibling(node, nodeToAdd);
    jobject ret = buildNode(env, nodeAdded, jdoc);
    (*env)->DeleteLocalRef(env, jdoc);
    return ret;
}
Beispiel #11
0
/*
 * Class:     org_xmlsoft_Node
 * Method:    addChildImpl
 * Signature: (Lrath/libxml/Node;)Lrath/libxml/Node;
 */
JNIEXPORT jobject JNICALL Java_org_xmlsoft_Node_addChildImpl
(JNIEnv *env, jobject obj, jobject toAdd) {
    xmlNode *node = findNode(env, obj);
    
    xmlNode *attached = xmlAddChild(node, findNode(env, toAdd));
    jobject jdoc = (*env)->GetObjectField(env, obj, fieldNodeDocument);
    jobject jattached = buildNode(env, attached, jdoc);
    (*env)->DeleteLocalRef(env, jdoc);
    return jattached;
}
void DefaultSCgObjectBuilder::buildObjects(const AbstractSCgObjectBuilder::TypeToObjectsMap& objects)
{
    SCgObjectInfo* info;
    // parse nodes
    foreach(info, objects[SCgNode::Type])
        buildNode(static_cast<SCgNodeInfo*>(info));
    // parse pairs
    foreach(info, objects[SCgPair::Type])
        buildPair(static_cast<SCgPairInfo*>(info));
    // parse buses
    foreach(info, objects[SCgBus::Type])
        buildBus(static_cast<SCgBusInfo*>(info));
    // parse contours
    foreach(info, objects[SCgContour::Type])
        buildContour(static_cast<SCgContourInfo*>(info));

    // set parents relation
    ParentChildMap::iterator parentIt;
    for (parentIt = mParentChild.begin(); parentIt != mParentChild.end(); parentIt++)
    {
        if (!mId2SCgObj.contains(parentIt.value()))
            continue;

        SCgObject *parent = mId2SCgObj[parentIt.value()];
        SCgObject *child = mId2SCgObj[parentIt.key()];

        child->setParentItem(parent);
    }

    // holds true, if there are errors while setting begin and end objects.
    bool isConnectedDuty = false;
    // set begin and end objects for pairs
    foreach(SCgObjectInfo* info, objects[SCgPair::Type])
    {
        SCgPairInfo* pairInfo = static_cast<SCgPairInfo*>(info);
        SCgPair *pair = static_cast<SCgPair*>(mId2SCgObj[pairInfo->id()]);

        // we can't build pair without begin or end objects
        if (!mId2SCgObj.contains(pairInfo->beginObjectId()) ||
            !mId2SCgObj.contains(pairInfo->endObjectId()))
        {
            mErrors.append(QObject::tr("Can't find begin or end object for pair id=\"%1\"")
                                            .arg(pairInfo->id()));
            mId2SCgObj.remove(pairInfo->id());
            isConnectedDuty = true;
            delete pair;
            continue;
        }

        SCgObject *begObject = mId2SCgObj[pairInfo->beginObjectId()];
        SCgObject *endObject = mId2SCgObj[pairInfo->endObjectId()];

        pair->setBeginObject(begObject);
        pair->setEndObject(endObject);
    }
Beispiel #13
0
void Playtree::buildTree()
{
    clear();
    playlist_Lock( m_pPlaylist );

    for( int i = 0; i < m_pPlaylist->p_root->i_children; i++ )
    {
        buildNode( m_pPlaylist->p_root->pp_children[i], *this );
    }

    playlist_Unlock( m_pPlaylist );
}
Beispiel #14
0
void buildList(LinkedList * myList, int total, FILE * fin, void * (*buildData)(FILE * in)){
	Node * prev = (*myList).head;
	Node * cur;
	for(int i = 0; i < total; i++)
	{
		cur = buildNode(fin, buildData);
		(*prev).next = cur;
		(*cur).prev = prev;
		prev = cur;
		(*myList).size++;
	}

}
Beispiel #15
0
void FlameGraph::rebuild()
{
    qDeleteAll(childItems());
    childItems().clear();
    m_depth = 0;

    if (!m_model) {
        emit depthChanged(m_depth);
        return;
    }

    m_depth = buildNode(QModelIndex(), this, 0);
    emit depthChanged(m_depth);
}
void AngelScriptReferenceDialog::buildTree() {
    auto refParser = model_.refParser();
    auto topLevelData = refParser->getData();
    for(auto &data: topLevelData) {
        QLabel* top = new QLabel(data->name().c_str(), owner_);
        top->setFont(getFormatting(data->hint()));
        auto topNode = addTopItem(top);
        contents_[size_t(topNode)] = data->content();

        for(auto &subData: data->children())
            buildNode(topNode, subData);
    }

}
Beispiel #17
0
void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )
{
    UString *pName = new UString( getIntf(), pNode->p_input->psz_name );
    Iterator it = rTree.add(
        pNode->i_id, UStringPtr( pName ), false,
        playlist_CurrentPlayingItem(m_pPlaylist) == pNode,
        false, pNode->i_flags & PLAYLIST_RO_FLAG );
    m_allItems[pNode->i_id] = &*it;

    for( int i = 0; i < pNode->i_children; i++ )
    {
        buildNode( pNode->pp_children[i], *it );
    }
}
Beispiel #18
0
jobject     buildNodeSet(JNIEnv *env, xmlNodeSet *nodeset, jobject document) {
    int i;
    jobject jnodeset = (*env)->NewObject(env, classNodeset, methodNodesetNew, (jlong)nodeset);
    if( nodeset==NULL )
        return jnodeset;

    (*env)->SetIntField(env, jnodeset, fieldNodesetSize, (jint)nodeset->nodeNr);

    if(!xmlXPathNodeSetIsEmpty(nodeset)) {
        for(i=0; i<nodeset->nodeNr; i++) {
            jobject node = buildNode(env, nodeset->nodeTab[i], document);
            (*env)->CallNonvirtualVoidMethod(env, jnodeset, classNodeset, methodNodesetAddNode, node);
        }
    }
    return jnodeset;
}
Beispiel #19
0
void BallTree<_Scalar>::rebuild(void)
{
		delete mRootNode;

		mRootNode = new Node();
		IndexArray indices(mPoints.size());
		AxisAlignedBoxType aabb;
		aabb.Set(mPoints[0]);
		for (unsigned int i=0 ; i<mPoints.size() ; ++i)
		{
				indices[i] = i;
				aabb.Add(mPoints[i],mRadii[i]*mRadiusScale);
//				aabb.min = Min(aabb.min, CwiseAdd(mPoints[i], -mRadii[i]*mRadiusScale));
//				aabb.max = Max(aabb.max, CwiseAdd(mPoints[i],  mRadii[i]*mRadiusScale));
		}
		buildNode(*mRootNode, indices, aabb, 0);

		mTreeIsUptodate = true;
}
Beispiel #20
0
		/**
		 * Private method which is used to recursivly build OctTree nodes starting from root.
		 * @param	parent is pointer to new node parent.
		 */
		void OctTree::buildNode(OctNode* parent)
		{
			if(condition == MINENTITY && parent->entities.size() > 1)
			{
				Vector3D position;
				position.set(parent->position.x()+parent->size.x()*0.5f,parent->position.y()+parent->size.y()*0.5f,parent->position.z()+parent->size.z()*0.5f);
				createNodeChildren(parent,position,0);
				buildNode(parent->children[0]);

				position.set(parent->position.x()-parent->size.x()*0.5f,parent->position.y()-parent->size.y()*0.5f,parent->position.z()-parent->size.z()*0.5f);
				createNodeChildren(parent,position,1);
				buildNode(parent->children[1]);

				position.set(parent->position.x()+parent->size.x()*0.5f,parent->position.y()+parent->size.y()*0.5f,parent->position.z()-parent->size.z()*0.5f);
				createNodeChildren(parent,position,2);
				buildNode(parent->children[2]);

				position.set(parent->position.x()+parent->size.x()*0.5f,parent->position.y()-parent->size.y()*0.5f,parent->position.z()+parent->size.z()*0.5f);
				createNodeChildren(parent,position,3);
				buildNode(parent->children[3]);

				position.set(parent->position.x()-parent->size.x()*0.5f,parent->position.y()+parent->size.y()*0.5f,parent->position.z()+parent->size.z()*0.5f);
				createNodeChildren(parent,position,4);
				buildNode(parent->children[4]);

				position.set(parent->position.x()-parent->size.x()*0.5f,parent->position.y()-parent->size.y()*0.5f,parent->position.z()+parent->size.z()*0.5f);
				createNodeChildren(parent,position,5);
				buildNode(parent->children[5]);

				position.set(parent->position.x()+parent->size.x()*0.5f,parent->position.y()-parent->size.y()*0.5f,parent->position.z()-parent->size.z()*0.5f);
				createNodeChildren(parent,position,6);
				buildNode(parent->children[6]);

				position.set(parent->position.x()-parent->size.x()*0.5f,parent->position.y()+parent->size.y()*0.5f,parent->position.z()-parent->size.z()*0.5f);
				createNodeChildren(parent,position,7);
				buildNode(parent->children[7]);
			}
		}
Beispiel #21
0
void KDTree::build(std::vector<Triangle *> objects)
{
    for (int a = 0; a < 3; a++) {
        m_min[a] = FLT_MAX;
        m_max[a] = -FLT_MAX;
    }
    m_maxDepth = int(8+1.3f*log(objects.size()));
    m_maxPrims = 15;
    for(int i=0; i<objects.size(); i++) {
        m_objects.push_back(objects[i]);
    }
    float min[3], max[3];
    std::vector<AABoundingBox> bounds;
    for(int i =0; i<m_objects.size(); i++) {
        AABoundingBox b;
        b.extend(m_objects[i]);
        b.getBounds(min,max);
        bounds.push_back(b);
        for (int a = 0; a < 3; a++) {
            m_min[a] = min[a] < m_min[a] ? min[a] : m_min[a];
            m_max[a] = max[a] > m_max[a] ? max[a] : m_max[a];
        }
    }
    m_bounds = new AABoundingBox();
    m_bounds->setMin(m_min);
    m_bounds->setMax(m_max);
    std::vector<int> overlappingObjects;
    for(int i=0; i<m_objects.size(); i++) {
        overlappingObjects.push_back(i);
    }
    for(int i=0; i<3; i++) {
        m_boundEdges[i] = new BoundEdge[2*m_objects.size()];
    }
    std::cout << "started building tree!\n";
    buildNode(overlappingObjects,bounds,m_maxDepth,*m_bounds);
    std::cout << "tree built!\n";
}
Beispiel #22
0
/*
 * Class:     org_xmlsoft_Node
 * Method:    getLastImpl
 * Signature: ()Lrath/libxml/Node;
 */
JNIEXPORT jobject JNICALL Java_org_xmlsoft_Node_getLastImpl
  (JNIEnv *env, jobject obj) {
    xmlNode *node = findNode(env, obj);
    return buildNode(env, node->last, DOC(obj));
}
Beispiel #23
0
void BVH::buildNode( SplitMethod i_method, BVHItems &i_buildItems, size_t i_start, size_t i_end )
{
    Bounds3f bounds;
    Bounds3f centerBounds;
    
    // Save the index for later access of the node
    size_t nodeIndex = m_nodes.size();
    
    // Push back a node, we will initialize it later
    m_nodes.push_back( BVHNode() );
    
    // Calculate bounds
    for ( size_t i = i_start; i < i_end; i++ )
    {
        const BVHItem &item = i_buildItems[ i ];
        bounds = boundsUnion( bounds, item.bounds );
        centerBounds = boundsUnion( centerBounds, item.center );
    }
        
    size_t count = i_end - i_start;
    
    // Create a leaf
    if ( count == 1 )
    {
        m_nodes[ nodeIndex ].initLeaf( bounds, m_items.size(), 1 );
        m_items.push_back( i_buildItems[ i_start ] );
    }
    // Split
    else
    {
        int dim = static_cast< int >( bounds.maximumExtent() );
        
        const vec3f &min = centerBounds.getMin();
        const vec3f &max = centerBounds.getMax();

        // Cannot split, create leaf items
        if ( min[ dim ] == max[ dim ] )
        {
            m_nodes[ nodeIndex ].initLeaf( bounds, m_items.size(), count );

            for ( size_t i = i_start; i < i_end; i++ )
            {
                m_items.push_back( i_buildItems[ i ] );
            }
        }
        // Split by method
        else
        {
            size_t mid = ( i_start + i_end ) / 2.0;
            
            switch ( i_method ) {
                case SplitMethod::MIDDLE:
                {
                    // Split the items at the midpoint of the axis
                    float dimMid = ( centerBounds.getMin()[ dim ] + centerBounds.getMax()[ dim ] ) / 2.0;
                    BVHItem* midPtr = std::partition(
                        &i_buildItems[ i_start ],
                        &i_buildItems[ i_end - 1 ] + 1,
                        [ dim, dimMid ]( const BVHItem &item ) {
                            return item.center[ dim ] < dimMid;
                        } );
                    mid = midPtr - &i_buildItems[0];
                    
                    // Continue onto splitting equally if failed
                    if ( mid != i_start && mid != i_end )
                    {
                        break;
                    }
                }
                case SplitMethod::EQUAL:
                default:
                {
                    // Reset mid in case we are defaulting to equal splitting
                    mid = ( i_start + i_end ) / 2.0;

                    // Split into equal sized subsets
                    std::nth_element(
                        &i_buildItems[ i_start ],
                        &i_buildItems[ mid ],
                        &i_buildItems[ i_end - 1 ] + 1,
                        [ dim ]( const BVHItem &i0, const BVHItem &i1 ) {
                            return i0.center[ dim ] < i1.center[ dim ];
                        } );
                    
                    break;
                }
            }
            
            // Build left tree
            buildNode( i_method, i_buildItems, i_start, mid );
            
            size_t offset = m_nodes.size();
            
            // Build right tree
            buildNode( i_method, i_buildItems, mid, i_end );
            
            // Initialize the interior node
            m_nodes[ nodeIndex ].initInterior( bounds, offset, dim );
        }
    }
}
Beispiel #24
0
		/**
		 * Method is used to examine scene and create OctTree.
		 */
		void OctTree::buildOctTree()
		{
			buildRootNode();
			buildNode(root);
		}
Beispiel #25
0
// int totalDistance(RST* root);
// Must check for errors in instance, if so output error to console.
// If option output is given, output file to a text
// If option output is not given output to screen
int main(int argc, char** argv){
    char* filename = NULL;
    char** lines;
    Plane plane;
    char* options = NULL;
    bool correctFile = true;
    int** MST = NULL;
    int* degrees;
    //initiallize rand() with current time
    srand(time(NULL));

    // Cheching for arguments, if they are greater than or equal to two, assume
    // their are options and a filename being passed in trying to be passed in.
    if(argc >= 2){
        filename = getFilename(argv, argc);
        options = getOption(argv, argc);
    }

    // Grab Data
    if (filename == NULL){
        plane = getParameters();
        plane.instance_size = plane.NUM_PT;
    } else {
        lines = readFile(filename);

        // Check to see if a file was succesffully parsed
        if(lines == NULL){
            printf("File not found\n");
            printf("Exiting...\n");
            return -1;
        }
        plane.generation = getGeneration(filename);
        plane = getFileParameters(lines);
        correctFile = checkFile(plane);
        free(lines);
    }

    // Ensure instances is of the correct size;
    if(!correctFile){
        printf("File is corrupt, the instance file does not match specification\n");
        return -2;
    }


    if(filename != NULL){
    // If we opened up a file, the Plane instance is all ready generated for us.
        printPlane(plane, filename, options);
        if(plane.instance_size > 1){
            MST = prims(plane);
            printMST(MST,plane.instance_size, filename, options);

            degrees = nodeDegree(MST, plane.instance_size-1);
        } else {
            printf("Can not generate MST, insufficient nodes \n");
        }
    } else {
        while(plane.generation < plane.total_gen){
    // If not we need to generate instances for the number of planes required
            plane.instance = genInstance(plane.NUM_PT, plane.MAX_X, plane.MAX_Y);
            printPlane(plane, NULL, options);
            filename = genFilename(plane.NUM_PT, plane.generation);
            if(plane.instance_size > 1){
                MST = prims(plane);
                printMST(MST,plane.instance_size, filename, options);
                degrees = nodeDegree(MST, plane.instance_size-1);
            } else {
                printf("Can not generate MST, insufficient nodes \n");
            }
            plane.generation++;
        }
    }

    RST* root;
    int rootIndex = findRoot(MST, plane.instance_size-1);
    printf("Root index %i\n", rootIndex);
    root = buildNode(NULL, rootIndex, NULL, 0, 0 );
    buildTree(root, plane.instance, MST, plane.instance_size-1);

    // Need to create code to free plane.instance and and sub arrays of instance
    printList(root,0);
    //printf("Overlap is %i\n", maxOverlap(root));
    //printf("Distance is %i\n", totalDistance(root));
    freeMST(MST, plane.instance_size-1);
    freePlane(&plane);
    freeRST(root);


    // need to free MST
    return 0;
}
Beispiel #26
0
/*
 * Class:     org_xmlsoft_Node
 * Method:    childrenImpl
 * Signature: ()Lrath/libxml/Node;
 */
JNIEXPORT jobject JNICALL Java_org_xmlsoft_Node_childrenImpl
(JNIEnv *env, jobject obj) {
    xmlNode *node = findNode(env, obj);
    xmlNode *children = node->children;
    return buildNode(env, children, DOC(obj));
}