예제 #1
0
파일: model.cpp 프로젝트: punkkeks/ClanLib
int Model_Impl::count_vertices(const struct aiScene* sc, const struct aiNode* nd)
{
	int vertex_count = 0;
	unsigned int n = 0, t;

	// All meshes assigned to this node
	for (; n < nd->mNumMeshes; ++n)
	{
		const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
		int num_vertex = mesh->mNumFaces * 3;
		if (!num_vertex)
			continue;

		vertex_count += num_vertex;
		for (t = 0; t < mesh->mNumFaces; ++t)
		{
			if (mesh->mFaces[t].mNumIndices != 3)
					throw Exception("This example only supports triangles");
		}
	}

	// All children
	for (n = 0; n < nd->mNumChildren; ++n)
	{
		vertex_count += count_vertices(sc, nd->mChildren[n]);
	}

	return vertex_count;
}
예제 #2
0
inline void delete_edge( adjacency_list& g, vertex_id u, vertex_id v )
{
    assert( u < count_vertices( g ) );
    neighbors_t::iterator e = g[u].end(), p = std::find( g[u].begin(), e, v );
    if ( p != e )
        g[u].erase( p );
}
예제 #3
0
void Model_Impl::Load(CL_GraphicContext &gc, const char *filename, bool we_do_not_want_texures_on_this_object)
{
	generate_texture_coords = !we_do_not_want_texures_on_this_object;

	const struct aiScene* scene = aiImportFile(filename,aiProcessPreset_TargetRealtime_MaxQuality);
	if (!scene)
		throw CL_Exception("Cannot load a model");

	try
	{
		vbo_size = count_vertices(scene, scene->mRootNode);
		if (!vbo_size)
			throw CL_Exception("No vertices found in the model");
	
		vbo_positions = CL_VertexArrayBuffer(gc, vbo_size * sizeof(CL_Vec3f), cl_usage_static_draw);
		vbo_normals = CL_VertexArrayBuffer(gc, vbo_size * sizeof(CL_Vec3f), cl_usage_static_draw);
		if (generate_texture_coords)
			vbo_texcoords = CL_VertexArrayBuffer(gc, vbo_size * sizeof(CL_Vec2f), cl_usage_static_draw);
		insert_vbo(0, scene, scene->mRootNode);
	}catch(...)
	{
		aiReleaseImport(scene);
		throw;
	}

	aiReleaseImport(scene);
}
예제 #4
0
파일: glview.c 프로젝트: penma/dicraft
static void dumpVoxels() {
	short *vnbuf = NULL;
	vbo_vertcount = 0;

	binary_t i_1_2 = binary_like(im_slots[0]);
	binary_t i_1_n2 = binary_like(im_slots[0]);
	binary_t i_n1_2 = binary_like(im_slots[0]);
	memand2(i_1_2->voxels, im_slots[0]->voxels, im_slots[1]->voxels, im_slots[0]->size_z * im_slots[0]->off_z);
	memandnot2(i_1_n2->voxels, im_slots[0]->voxels, im_slots[1]->voxels, im_slots[0]->size_z * im_slots[0]->off_z);
	memandnot2(i_n1_2->voxels, im_slots[1]->voxels, im_slots[0]->voxels, im_slots[0]->size_z * im_slots[0]->off_z);

	int count_1_2, count_1_n2, count_n1_2;

	measure_once("VBO creation", "count", {
	count_1_2 = count_vertices(i_1_2);
	count_1_n2 = count_vertices(i_1_n2);
	count_n1_2 = count_vertices(i_n1_2);
	});
예제 #5
0
파일: map_bfs.cpp 프로젝트: boostpro/labs
// Read a graph from input in adjacency list form.
void read_adjacency_list( std::istream& input, graph& g )
{
    for ( std::string line; std::getline(input, line); )
    {
        vertex_id src = add_vertex( g );
        
        std::stringstream s(line);
        for ( int dst; s >> dst; )
        {
            // Make up an arbitrary weight
            edge_weight w = (1 + count_adj(g, src)) * 1.0 / count_vertices(g);
            add_edge( g, src, dst, w );
        }
    }
예제 #6
0
파일: model.cpp 프로젝트: punkkeks/ClanLib
void Model_Impl::Load(GraphicContext &gc, GraphicStore *gs, const char *filename)
{
	const struct aiScene* scene = aiImportFileExWithProperties(filename,aiProcessPreset_TargetRealtime_MaxQuality, NULL, gs->store);
	if (!scene)
		throw Exception("Cannot load a model");

	try
	{
		vbo_size = count_vertices(scene, scene->mRootNode);
		if (!vbo_size)
			throw Exception("No vertices found in the model");
	
		vbo_positions = VertexArrayVector<Vec3f>(gc, vbo_size);
		vbo_normals = VertexArrayVector<Vec3f>(gc, vbo_size);
		insert_vbo(gc, 0, scene, scene->mRootNode);
	}catch(...)
	{
		aiReleaseImport(scene);
		throw;
	}

	aiReleaseImport(scene);
}
예제 #7
0
파일: map_bfs.cpp 프로젝트: boostpro/labs
// A simple breadth-first search starting from u for vertex v.
// Returns true iff v is reachable from u.  Complexity: O(|V|+|E|)
bool bfs(graph const& g, vertex_id u, vertex_id v)
{
    std::vector<bool> visited( count_vertices( g ) );
    std::deque<vertex_id> q;
    q.push_back( u );

    while ( !q.empty() )
    {
        vertex_id const next = q.front();
        q.pop_front();
        if ( next == v )
            return true;
        
        if ( !visited[next] )
        {
            visited[next] = true;
            
            // This call works when neighbors_t is a set.  You'll need
            // to fix it up for map.
            std::copy( g[next].begin(), g[next].end(), std::back_inserter( q ) );
        }
    }
    return false;
}
예제 #8
0
// A simple breadth-first search starting from u for vertex v.
// Returns true iff v is reachable from u.  Complexity: O(|V|+|E|)
bool bfs(graph const& g, vertex_id u, vertex_id v)
{
    std::vector<bool> visited( count_vertices( g ) );
    std::deque<vertex_id> q;
    q.push_back( u );

    while ( !q.empty() )
    {
        vertex_id const next = q.front();
        q.pop_front();
        if ( next == v )
            return true;
        if ( !visited[next] )
        {
            visited[next] = true;
            
            std::transform( g[next].begin(), g[next].end(),
                            std::back_inserter( q ),
                            project1st()
                );
        }
    }
    return false;
}
예제 #9
0
inline void add_edge( adjacency_list& g, vertex_id u, vertex_id v )
{
    assert( u < count_vertices( g ) );
    g[u].insert( std::lower_bound( g[u].begin(), g[u].end(), v ), v );
}
예제 #10
0
// Write another function delete_self_loops( g ) that uses del_edge to
// delete all self-loops from the edge_list
inline void delete_self_loops( adjacency_list& g )
{
    for ( vertex_id u = 0, n = count_vertices( g ); u != n; ++u )
        delete_edge(g, u, u);
}
예제 #11
0
파일: map_bfs.cpp 프로젝트: boostpro/labs
// Add an edge in g from u to v with weight w
// Complexity: O( log(|V|) )
// Requires: u is a vertex in g, i.e. u < count_vertices( g )
inline void add_edge( graph& g, vertex_id u, vertex_id v, edge_weight w )
{
    assert( u < count_vertices( g ) );
    g[u].insert( std::make_pair( v, w ) );
}
예제 #12
0
// Write another function delete_self_loops( g ) that uses del_edge to
// delete all self-loops from the graph
inline void delete_self_loops( graph& g )
{
    for ( vertex_id u = 0, n = count_vertices( g ); u != n; ++u )
        delete_edge(g, u, u);
}
예제 #13
0
파일: readgml.c 프로젝트: posix4e/ecolab
void create_network(NETWORK *network)
{
  int i;
  int length;
  char *ptr;
  char *start,*stop;
  char line[LINELENGTH];
  char label[LINELENGTH];

  // Determine whether the network is directed

  network->directed = is_directed();

  // Count the vertices

  network->nvertices = count_vertices();

  // Make space for the vertices

  network->vertex = calloc(network->nvertices,sizeof(VERTEX));

  // Go through the file reading the details of each vertex one by one

  reset_buffer();
  for (i=0; i<network->nvertices; i++) {

    // Skip to next "node" entry

    do {
      next_line(line);
    } while (strstr(line,"node")==NULL);

    // Read in the details of this vertex

    do {

      // Look for ID

      ptr = strstr(line,"id");
      if (ptr!=NULL) sscanf(ptr,"id %i",&network->vertex[i].id);

      // Look for label

      ptr = (strstr(line,"label"));
      if (ptr!=NULL) {
	start = strchr(line,'"');
	if (start==NULL) {
	  sscanf(ptr,"label %s",&label);
	} else {
	  stop = strchr(++start,'"');
	  if (stop==NULL) length = strlen(line) - (start-line);
	  else length = stop - start;
	  strncpy(label,start,length);
	  label[length] = '\0';
	  network->vertex[i].label = malloc((length+1)*sizeof(char));
	  strcpy(network->vertex[i].label,label);
	}
      }

      // If we see a closing square bracket we are done

      if (strstr(line,"]")!=NULL) break;

    } while (next_line(line)==0);

  }

  // Sort the vertices in increasing order of their IDs so we can find them
  // quickly later

  qsort(network->vertex,network->nvertices,sizeof(VERTEX),(void*)cmpid);
}
예제 #14
0
/*
 * Parse the generator output. Find the generators which are vertices
 * (non-rays) add their corresponding inequalities to an output set.
 *
 * Returns a matrix where each row contains the x-coordinate of the vertex,
 * y-coordinate of the vertex, and 0-based index of the inequality which bounds
 * the polytope to the right of the vertex. output_size is set to the total
 * length of the ouptut.
 */
static double *list_extreme_vertices(const dd_MatrixPtr generators,
                                     const dd_SetFamilyPtr incidence,
                                     const size_t nrows,
                                     long lower_bound_index,
                                     /*OUT*/ size_t * output_size)
{
  assert(generators->rowsize > 0);
  assert(generators->colsize > 2);

  set_type cur_vert_set, next_vert_set, s;
  dd_rowrange i;
  long elem;
  size_t out_row = 0, r;

  size_t vertex_count = count_vertices(generators);

  /* Last vertex intersects with upper bound - not output */
  *output_size = 3 * (vertex_count - 1);
  double *output = (double *) malloc(sizeof(double) * (*output_size));

  /* Sorted indices into generators */
  size_t *indices = sort_generators(generators);

  assert(*output_size > 0);

  /* Loop over vertices in generators, extracting solutions
   *
   * For vertices 0..n_vertices-2, find the inequality incident to the vertex
   * also incident in the next vertex.
   */
  for (i = 0; i < vertex_count - 1; i++) {
    r = indices[i];

    assert(is_vertex(generators->matrix[r][0]));
    assert(is_vertex(generators->matrix[indices[i + 1]][0]));

    assert(out_row < vertex_count - 1);
    cur_vert_set = incidence->set[r];

    next_vert_set = incidence->set[indices[i + 1]];

    /* Sets should be same size */

    assert(cur_vert_set[0] == next_vert_set[0]);
    set_initialize(&s, cur_vert_set[0]);
    set_int(s, cur_vert_set, next_vert_set);

    /* Remove added index for first item */
    /*if (!i)*/
      /*set_delelem(s, lower_bound_index);*/

    /* Set may have > 1 solution if ~identical slopes and intercepts due to
     * rounding. */
    /*assert(set_card(s) == 1); */

    /* Only one item in the set */
    elem = set_first(s);
    set_free(s);

    /* Fill output row */
    int base = out_row * 3;
    output[base] = *generators->matrix[r][1];     /* x */
    output[base + 1] = *generators->matrix[r][2]; /* y */
    output[base + 2] = (double) (elem - 1);       /* ineq index, converted to 0-base */

    out_row++;
  }

  free(indices);

  return output;
}