Exemplo n.º 1
0
const std::vector<unsigned int> gl_retained_mesh::add_faces( const std::vector<unsigned int>& faceIndices ) {
	unsigned int currIndex = 0, currFace = m_numFaces;
	std::vector< std::vector<unsigned int> > toAdd;
	std::vector<unsigned int> addedFaces;

	// Go through each face
	while( currIndex < faceIndices.size() ) {
		const unsigned int numIndicesForFace = num_verts_for_next_face( currFace );
		std::vector<unsigned int> indices( numIndicesForFace );

		if( numIndicesForFace > static_cast<unsigned int>( faceIndices.size() ) - currIndex )
			throw std::exception( "gl_retained_mesh.add_faces: Failed to add faces because incorrect number of indices were found in faceIndices parameter." );

		memcpy( &indices[0], &faceIndices[currIndex], numIndicesForFace * sizeof( unsigned int ) );

		check_face( indices );

		currIndex += numIndicesForFace;
		++currFace;
		toAdd.push_back( indices );
	}

	// Add the faces to mesh
	for( std::vector< std::vector<unsigned int> >::const_iterator it = toAdd.begin(); it != toAdd.end(); ++it ) {
		addedFaces.push_back( m_numFaces );

		insert_face( *it );
	}

	return addedFaces;
}
Exemplo n.º 2
0
const unsigned int gl_retained_mesh::add_face( const std::vector<unsigned int>& faceIndices ) {
	std::vector<unsigned int> indices( 0 );
	unsigned int faceNumber = m_numFaces;
	
	// Throw an exception if the incorrect number of faces are passed as the parameter. There are two cases:
	//   1) If there are currently no faces in the mesh, throw an exception if the number of indices passed is not the correct number of 
	//		indices for the first face.
	//   2) If there are currently faces in the mesh, throw an exception if the number of indices passed is not the correct number of indices
	//		for each subsequent face.
	if( ( m_indices.size() == 0 &&  faceIndices.size() != get_num_verts_for_init_face( m_primitiveType )  ) 
		|| ( m_indices.size() != 0 && faceIndices.size() != get_num_verts_for_next_face( m_primitiveType ) ) ) {
		throw std::runtime_error( "gl_retained_mesh.add_faces: Failed to add faces to the mesh because an incorrect number of indices(" + 
			boost::lexical_cast<std::string>( faceIndices.size() ) + ") where passed to the function." );
	}

	check_face( faceIndices );
	insert_face( faceIndices );

	return faceNumber;
}
Exemplo n.º 3
0
void deWall(point_set *P, face_list *AFL, simplex_list *SL, Axis ax, int rec_level) {

  face *f;
  face_list AFLa, AFL1, AFL2;

  plane alpha;
  simplex *t;
  point_set P1, P2;

  uniform_grid UG;
  int i = 0;

  initialize_face_list(&AFLa, P->size/4);
  initialize_face_list(&AFL1, P->size/4);
  initialize_face_list(&AFL2, P->size/4);

  if (P->size > MIN_UG_SIZE) {
    if (!createUniformGrid(P,&UG)){
      printf("Could not create uniform grid :/\n");
      return;
    }
  }

  if (!pointset_partition(P,&alpha,ax,&P1,&P2)) 
    return;

  /* Simple Wall Construction */

  if (AFL->size == 0){
    if (make_first_simplex(P,&t)){
      for(i = 0; i < 3; i++) 
        insert_face(t->face[i],AFL);	
      insert_simplex(t,SL,P);
    }
  }

  // Dividing the faces in 3 lists
  while (extract_face(&f,AFL)){
    if (rec_level < MAX_REC_LEVEL){	
      switch (intersect(f,&alpha)) {
        case  0: insert_face(f, &AFLa); break;
        case -1: insert_face(f, &AFL1); break;
        case  1: insert_face(f, &AFL2); break;
      }
    } else {
      insert_face(f, &AFLa); 
    }
  }		

  // Building the wall for the faces in the middle
  while(AFLa.size > 0){
    extract_face(&f,&AFLa);
    int make_simp = 0;
    if (P->size > MIN_UG_SIZE)
      make_simp = make_simplex_ug(f, P, &t, &UG);
    else
      make_simp = make_simplex(f, P, &t);
    if (make_simp){ 
      if (insert_simplex(t,SL,P)){
        for(i = 0; i < 3; i++){                
          if (!equal_face(t->face[i], f)){ 	
            if (rec_level < MAX_REC_LEVEL){				        
              switch (intersect(t->face[i],&alpha)) {
                case  0: update_face(t->face[i], &AFLa); break;
                case -1: update_face(t->face[i], &AFL1); break;
                case  1: update_face(t->face[i], &AFL2); break;
              }
            } else {
              update_face(t->face[i], &AFLa); break;
            }
          }  
        }               
      }
      // Alocated in build_simplex function   
      free(t);
      // Allocated in build_simplex function
      free(f);
    }		
  }

  /* Recursive Triangulation */
  rec_level++;
  // Deciding to use parallel or serial version
  if (P->size < LIMIT_OMP){
    if (AFL1.size > 0 && P1.size > 0)
      deWall(&P1, &AFL1, SL, invert_axis(ax), rec_level);
    if (AFL2.size > 0 && P2.size > 0)
      deWall(&P2, &AFL2, SL, invert_axis(ax), rec_level);		
  } else {
#pragma omp task
    if (AFL1.size > 0 && P1.size > 0)
      deWall(&P1, &AFL1, SL, invert_axis(ax), rec_level);
#pragma omp task
    if (AFL2.size > 0 && P2.size > 0)
      deWall(&P2, &AFL2, SL, invert_axis(ax), rec_level);  
  }
}