コード例 #1
0
int main(int argc, char* argv[]){

	print_mesh("mesh.html");

    return 0;
    
}
コード例 #2
0
size_t assimp_load_meshes2(const aiScene *scene, triangle_meshes2_array& meshes)
{
	std::ofstream ofs("mesh_debug.txt");
	
	for (size_t i = 0; i < scene->mNumMeshes; ++i)
	{
		size_t num_tris = scene->mMeshes[i]->mNumFaces; 
		size_t num_verts = scene->mMeshes[i]->mNumVertices;
		bool has_normals = scene->mMeshes[i]->HasNormals(); 
		bool has_uvs = scene->mMeshes[i]->HasTextureCoords(0); 

		verts_pos_array pos_array[3]; 
		verts_normal_array normals_array[3];
		verts_uv_array uvs_array[3]; 

		for (size_t j = 0; j < 3; ++j)
		{
			pos_array[j].reset(new point3f[num_tris]);
			if (has_normals)
				normals_array[j].reset(new normal3f[num_tris]);
			if (has_uvs)
				uvs_array[j].reset(new vector3f[num_tris]); 
		}
		
		// Extract triangles data
		aiMesh *ai_mesh = scene->mMeshes[i]; 
		for (size_t f = 0; f < ai_mesh->mNumFaces; ++f)
		{
			aiFace face = ai_mesh->mFaces[f]; 
			
			// Only Triangles!
			assert(face.mNumIndices == 3);
			
			// Add the triangle
			for (size_t t = 0; t < 3; ++t)
			{
				// WARNING: Do not transform the vertices here. This *will* lead to
				// rounding errors that would destroy the triangle connectivity.
				pos_array[t][f] = *(point3f*)&ai_mesh->mVertices[face.mIndices[t]]; 
				
				if (has_normals)
					normals_array[t][f] = *(normal3f*)&ai_mesh->mNormals[face.mIndices[t]]; 
				
				if (has_uvs)
					uvs_array[t][f] = *(vector3f*)&ai_mesh->mTextureCoords[face.mIndices[t]]; 
			}
		}

		triangle_mesh2_ptr mesh = triangle_mesh2_ptr(new c_triangle_mesh2(pos_array, normals_array, uvs_array, num_tris, num_verts));
		meshes.push_back(mesh); 

		print_mesh(ofs, mesh);
	}

	return scene->mNumMeshes;
}
コード例 #3
0
ファイル: dr_main.c プロジェクト: uppatispr/trilinos-official
/* This function determines which input file type is being used,
 * and calls the appropriate read function. If a new type of input
 * file is added to the driver, then a section needs to be added for
 * it here.
 *---------------------------------------------------------------------------*/
static int read_mesh(
  int Proc,
  int Num_Proc,
  PROB_INFO_PTR prob,
  PARIO_INFO_PTR pio_info,
  MESH_INFO_PTR mesh)
{
#ifdef DEBUG_READ_MESH
  int i, tpins, the, tverts, pins, he, verts;
#endif
/* local declarations */
/*-----------------------------Execution Begins------------------------------*/
  if (pio_info->file_type == CHACO_FILE) {
    if (!read_chaco_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_chaco_mesh\n");
        return 0;
    }
  }
  else if (pio_info->file_type == NEMESIS_FILE) {
    if (!read_exoII_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_exoII_mesh\n");
        return 0;
    }
  }
  else if (pio_info->file_type == HYPERGRAPH_FILE) {
    if (!read_hypergraph_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_hypergraph_file\n");
        return 0;
    }
  }
  else if (pio_info->file_type == MATRIXMARKET_FILE) {
    if (!read_mm_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_mm_file\n");
        return 0;
    }
    mm_cleanup(mesh);
  }
  else if (pio_info->file_type == MATRIXMARKET_PLUS_FILE) {
    if (!read_mtxplus_file(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from read_mtxplus_file\n");
        return 0;
    }
    /* KDDKDD 3/26/10:  
     * Eventually, we should do cleanup here to address bug 3346.
     * but doing so will change the answer files.
     * mm_cleanup(mesh);
     */
  }
  else if (pio_info->file_type == NO_FILE_POINTS) {
    if (!create_random_input(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from create_random_input\n");
        return 0;
    }
  }
  else if (pio_info->file_type == NO_FILE_TRIANGLES) {
    if (!create_random_triangles(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from create_random_triangles\n");
        return 0;
    }
  }
  else if (pio_info->file_type == NO_FILE_GRAPH) {
    if (!create_a_graph(Proc, Num_Proc, prob, pio_info, mesh)) {
        Gen_Error(0, "fatal: Error returned from create_a_graph\n");
        return 0;
    }
  }
  else {
    Gen_Error(0, "fatal: Invalid file type.\n");
    return 0;
  }

#ifdef DEBUG_READ_MESH
  for (i=0; i<Num_Proc; i++){
    if (i == Proc){
      printf("Process %d:\n",i);
      print_mesh(Proc, mesh, &pins, &he, &verts);
    }
    MPI_Barrier(MPI_COMM_WORLD);
  }
  MPI_Reduce(&pins, &tpins, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  MPI_Reduce(&he, &the, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  MPI_Reduce(&verts, &tverts, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  if (Proc == 0){
    if (mesh->format == ZOLTAN_COMPRESSED_EDGE){
      printf("Total pins %d, total vertices %d, total rows %d\n",
                 tpins, tverts, the);
    }
    else{
      printf("Total pins %d, total vertices %d, total columns %d\n",
                 tpins, tverts, the);
    }
  }
#endif
  return 1;
}
コード例 #4
0
ファイル: fem.c プロジェクト: marcoheisig/numpde05
void fem(size_t n, double errors[2], double (*fn_f)(double, double),
         double (*fn_g)(unsigned char, double, double),
         double (*fn_u)(double, double))
{
  mesh m;
  crs_matrix mat;
  double * u, * rhs;
  double local_stiffness[3][3];
  double local_load[3];
  size_t elem;

  /* 1. Allocate and generate mesh */
  get_mesh(&m, n);

#ifdef PRINT_DEBUG
  print_mesh(&m);
#endif

  /* 2. Allocate the linear system */
  init_matrix(&mat, &m);

  u = (double *) malloc(sizeof(double) * m.n_vertices);
  if (u == NULL) err_exit("Allocation of solution vector failed!");
  memset(u, 0, sizeof(double) * m.n_vertices);

  rhs = (double *) malloc(sizeof(double) * m.n_vertices);
  if (rhs == NULL)
    err_exit("Allocation of right hand side failed!");
  memset(rhs, 0, sizeof(double) * m.n_vertices);

  /* 3. Assemble the matrix */
  for (elem = 0; elem <  m.n_triangles; ++elem)
  {
    /* Compute local stiffness and load */
    get_local_stiffness(local_stiffness, &m, elem);
    get_local_load(local_load, &m, elem, fn_f);

#ifdef PRINT_DEBUG
    print_local_stiffness(local_stiffness);
    print_local_load(local_load);
#endif

    /* insert into global matrix and rhs */
    assemble_local2global_stiffness(local_stiffness, &mat, &m, elem);
    assemble_local2global_load(local_load, rhs, &m, elem);
  }

#ifdef PRINT_DEBUG
  printf("Matrix after assembly:\n");
  print_matrix(&mat);
  printf("rhs after assembly:\n");
  for(size_t i = 0; i < m.n_vertices; ++i) {
      printf("%5.2f\n", rhs[i]);
  }
  printf("\n");
#endif

  /* 4. Apply boundary conditions */
  apply_dbc(&mat, rhs, &m, fn_g);

#ifdef PRINT_DEBUG
  printf("Matrix after application of BCs:\n");
  print_matrix(&mat);
  printf("rhs after application of BCs:\n");
  for(size_t i = 0; i < m.n_vertices; ++i) {
      printf("%5.2f\n", rhs[i]);
  }
  printf("\n");
#endif

  /* 5. Solve the linear system */
  solve(&mat, u, rhs);

  /* 6. Evaluate error */
  errors[0] = l2_norm(u, &m, fn_u);
  errors[1] = inf_norm(u, &m, fn_u);

  /* free allocated resources */
  free(u);
  free(rhs);
  rhs = NULL;
  free_matrix(&mat);
  free_mesh(&m);
}