void stl_open_merge(stl_file *stl, char *file) { int first_facet; first_facet = stl->stats.number_of_facets; stl_initialize(stl); stl_count_facets(stl, file); stl_reallocate(stl); stl_read(stl, first_facet, 0); }
void stl_open_merge(stl_file *stl, char *file_to_merge) { int num_facets_so_far; stl_type origStlType; FILE *origFp; stl_file stl_to_merge; if (stl->error) return; /* Record how many facets we have so far from the first file. We will start putting facets in the next position. Since we're 0-indexed, it'l be the same position. */ num_facets_so_far = stl->stats.number_of_facets; /* Record the file type we started with: */ origStlType=stl->stats.type; /* Record the file pointer too: */ origFp=stl->fp; /* Initialize the sturucture with zero stats, header info and sizes: */ stl_initialize(&stl_to_merge); stl_count_facets(&stl_to_merge, file_to_merge); /* Copy what we need to into stl so that we can read the file_to_merge directly into it using stl_read: Save the rest of the valuable info: */ stl->stats.type=stl_to_merge.stats.type; stl->fp=stl_to_merge.fp; /* Add the number of facets we already have in stl with what we we found in stl_to_merge but haven't read yet. */ stl->stats.number_of_facets=num_facets_so_far+stl_to_merge.stats.number_of_facets; /* Allocate enough room for stl->stats.number_of_facets facets and neighbors: */ stl_reallocate(stl); /* Read the file to merge directly into stl, adding it to what we have already. Start at num_facets_so_far, the index to the first unused facet. Also say that this isn't our first time so we should augment stats like min and max instead of erasing them. */ stl_read(stl, num_facets_so_far, 0); /* Restore the stl information we overwrote (for stl_read) so that it still accurately reflects the subject part: */ stl->stats.type=origStlType; stl->fp=origFp; }
void TriangleMesh::merge(const TriangleMesh* mesh) { // reset stats and metadata int number_of_facets = this->stl.stats.number_of_facets; stl_invalidate_shared_vertices(&this->stl); this->repaired = false; // update facet count and allocate more memory this->stl.stats.number_of_facets = number_of_facets + mesh->stl.stats.number_of_facets; this->stl.stats.original_num_facets = this->stl.stats.number_of_facets; stl_reallocate(&this->stl); // copy facets for (int i = 0; i < mesh->stl.stats.number_of_facets; i++) { this->stl.facet_start[number_of_facets + i] = mesh->stl.facet_start[i]; } // update size stl_get_size(&this->stl); }