Beispiel #1
0
/*!
 * Replaces the slice [sl] with a subarea from [llx] to [urx] - 1 in X and
 * [lly] to [ury] -1 in Y, inclusive.  For areas where      
 * there is no image data, the slice mean is used to fill only the first 
 * channel.  Returns -1 for memory error.
 */
int sliceBoxIn(Islice *sl, int llx, int lly, int urx, int ury)
{
  Islice *sout;

  sout = sliceBox(sl, llx, lly, urx, ury);
  if (!sout)
    return(-1);
  if (sl->data.b)
    free(sl->data.b);
  memcpy(sl, sout, sizeof(Islice));
  free(sout);
  return(0);
}
Beispiel #2
0
/*! 
 * \brief Build a tree node.
 */
void Octree::buildTreeNode( RCP_Node node )
{
    int error = 0;

    // Create the children.
    for ( int i = 0; i < 8; ++i )
    {
	node->children[i] = Teuchos::rcp( new OctreeNode );

	iMesh_createEntSet( d_mesh,
			    1,
			    &(node->children[i]->node_set),
			    &error );
	assert( iBase_SUCCESS == error );
    }

    // Create the new bounding boxes and assign them to the children.
    sliceBox( node );

    // Add the elements in the parent set to the child sets.
    std::vector<iBase_EntityHandle> root_list;
    int node_elements_allocated = 0;
    int node_elements_size = 0;
    iBase_EntityHandle *node_elements;
    iMesh_getEntities( d_mesh,
		       node->node_set,
		       d_entity_type,
		       d_entity_topology,
		       &node_elements,
		       &node_elements_allocated,
		       &node_elements_size,
		       &error );
    assert( iBase_SUCCESS == error );

    bool element_found = false;
    for (int n = 0; n < node_elements_size; ++n )
    {
	element_found = false;

	for ( int m = 0; m < 8; ++m )
	{
	    if ( !element_found )
	    {
		if ( isEntInBox( node->children[m]->bounding_box, 
				 node_elements[n] ) )
		{
		    iMesh_addEntToSet( d_mesh,
				       node_elements[n],
				       node->children[m]->node_set,
				       &error );
		    assert( iBase_SUCCESS == error );

		    if ( node != d_root_node )
		    {
			iMesh_rmvEntFromSet( d_mesh,
					     node_elements[n],
					     node->node_set,
					     &error );
			assert( iBase_SUCCESS == error );
		    }

		    element_found = true;
		}
	    }

	}

	if ( !element_found )
	{
	    root_list.push_back( node_elements[n] );
	}
    }

    free( node_elements );

    // Special case for the root node.
    if ( node == d_root_node )
    {
	iBase_EntitySetHandle new_root_set;
	iMesh_createEntSet( d_mesh,
			    1,
			    &new_root_set,
			    &error );
	assert( iBase_SUCCESS == error );

	iMesh_addEntArrToSet( d_mesh,
			      &root_list[0],
			      (int) root_list.size(),
			      new_root_set,
			      &error );
	assert( iBase_SUCCESS == error );

	node->node_set = new_root_set;
    }

    // See if we have any child entities.
    Teuchos::Tuple<int,8> num_child_ents;
    int total_child_ents = 0;
    for (int i = 0; i < 8; ++i )
    {
	iMesh_getNumOfTopo( d_mesh,
			    node->children[i]->node_set,
			    d_entity_topology,
			    &num_child_ents[i],
			    &error );
	assert( iBase_SUCCESS == error );

	total_child_ents += num_child_ents[i];
    }
    
    // Recurse.
    if ( total_child_ents == 0 )
    {
	node->is_leaf = true;
    }
    else
    {
	for (int i = 0; i < 8; ++i)
	{
	    if ( num_child_ents[i] == 0 )
	    {
		node->children[i]->is_leaf = true;
	    }
	    else 
	    {
		buildTreeNode( node->children[i] );
	    }
	}
    }
}