void Map::DigChannel(MapCoordinates Coordinates) { Dig(Coordinates); setCubeShape(Coordinates, DATA->getLabelIndex("TILESHAPE_EMPTY")); // reveal tiles around for(Direction DirectionType = COMPASS_DIRECTIONS_START; DirectionType < NUM_COMPASS_DIRECTIONS; ++DirectionType) { setCubeHidden(MapCoordinates(Coordinates, DirectionType), false); } Dig(MapCoordinates(Coordinates, DIRECTION_DOWN)); removeFace(Coordinates, DIRECTION_DOWN); }
void Mesh::collapse(Vertex* v1, Vertex* v2) { std::vector<Face*>::iterator i; for (i = v1->adjacentFaces().begin(); i != v1->adjacentFaces().end(); ++i){ Face* f = *i; if (f->hasVertex(v2)) { removeFace(f); // delete f; } } Vector3 position1 = v1->position(); int weight1 = v1->weight(); Vector3 position2 = v2->position(); int weight2 = v2->weight(); Vector3 newPosition = (position1 * weight1 + position2 * weight2) / (weight1 + weight2); v2->setPosition(newPosition); v2->setWeight(v1->weight() + v2->weight()); for (i = v1->adjacentFaces().begin(); i != v1->adjacentFaces().end(); ++i){ Face* f = *i; f->changeVertex(v1, v2); f->calculateNormal(); } std::vector<Vertex*>::iterator j; for (j = v1->adjacentVertices().begin(); j != v1->adjacentVertices().end(); ++j){ Vertex* v = *j; v->removeAdjacentVertex(v1); v->addAdjacentVertex(v2); Edge* e = getEdge(v1, v); if (e) { if (e->hasVertex(v2)) { removeEdge(e); //delete e; // FIXME: pointer being freed was not allocated } else { e->changeVertex(v1, v2); } } else { std::cerr << "missing edge" << v1->index() << "/" << v->index() << "\n"; } } }
bool Surface::collapse(Edge& e) { timespec t0,t1,t; clock_gettime(CLOCK_REALTIME,&t0); Point* p1 = e.p1; Point* p2 = e.p2; assert(p1); assert(p2); if(p1->faces.size() ==0 || p2->faces.size()==0) //Do not simplify boundary corners { //cerr << "*ERROR: EMPTY VERTEX.\n"; failed_collapses++; //cout << redtty << "failed.\n" << deftty; return false; } //Iterating faces vector<Face*> for_removal; //clock_gettime(CLOCK_REALTIME,&t0); for(vector<Face*>::iterator fit = p1->faces.begin(); fit!=p1->faces.end(); ++fit) { bool removeface = false; vector<Point*>::iterator auxp1; for(vector<Point*>::iterator pit = (*fit)->points.begin(); pit != (*fit)->points.end() ; ++pit) { if((*pit) == p2) { removeface = true; break; } else if ((*pit) == p1) { auxp1 = pit; } } if(removeface) //p1 and p2 share face, remove it. { for_removal.push_back((*fit)); } else //Swap p1 for p2 for this face { //Face is about to be modified. Checking intersection. Point3 p30((*fit)->points[0]->x,(*fit)->points[0]->y,(*fit)->points[0]->z); Point3 p31((*fit)->points[1]->x,(*fit)->points[1]->y,(*fit)->points[1]->z); Point3 p32((*fit)->points[2]->x,(*fit)->points[2]->y,(*fit)->points[2]->z); Triangle3 face(p30,p31,p32); for(face_vec_it fit2 = m_faces.begin(); fit2 != m_faces.end(); ++fit2) { Face* f = (*fit2); Point3 pf0(f->points[0]->x,f->points[0]->y,f->points[0]->z); Point3 pf1(f->points[1]->x,f->points[1]->y,f->points[1]->z); Point3 pf2(f->points[2]->x,f->points[2]->y,f->points[2]->z); Triangle3 face2(pf0,pf1,pf2); if(CGAL::do_intersect(face,face2)) { cerr << "***Faces " << (*fit)->id << " X " << f->id << endl; } } (*auxp1) = p2; p2->faces.push_back((*fit)); } } //cerr << "Removing faces: "; for(vector<Face*>::iterator it = for_removal.begin(); it != for_removal.end(); ++it) { //cerr << (*it)->id << " "; removeFace(*it); (*it)->removed = true; //delete (*it); } //Set position of p2 as midpoint between p1-p2 p2->x = e.placement->x; p2->y = e.placement->y; p2->z = e.placement->z; clock_gettime(CLOCK_REALTIME,&t1); t = diff(t0,t1); time_faces+= getNanoseconds(t); //TODO: more efficient to use std::remove_if clock_gettime(CLOCK_REALTIME,&t0); removeEdge(m_edges[e.id]); vector<Edge*> edges_to_remove; edge_vec_it eit = p1->to.begin(); //Remove double edges to while(eit != p1->to.end()) { Edge* e = (*eit); bool found = false; edge_vec_it it = p2->to.begin(); while(it != p2->to.end()) { Edge* e2 = (*it); if(e->p1->id == e2->p1->id) { //cerr << "Found " << e->id << " " << e->p1->id << " " << e->p2->id << endl; edges_to_remove.push_back(e); found = true; break; } it++; } if(!found) { e->p2 = p2; if(e->p1->id == e->p2->id) edges_to_remove.push_back(e); } eit++; } //Remove double edges from eit = p1->from.begin(); while(eit!=p1->from.end()) { Edge* e = (*eit); bool found = false; edge_vec_it it = p2->from.begin(); while(it != p2->from.end()) { Edge* e2 = (*it); if(e->p2->id == e2->p2->id) { //cerr << "Found from " << e->id << " " << e->p1->id << " " <<e->p2->id << endl; edges_to_remove.push_back(e); found =true; break; } it++; } if(!found) { e->p1=p2; if(e->p1->id == e->p2->id) edges_to_remove.push_back(e); } eit++; } eit = edges_to_remove.begin(); while(eit != edges_to_remove.end()) { removeEdge(*eit); eit++; } //Append p1 edges to p2 p2->to.insert(p2->to.end(), p1->to.begin(), p1->to.end()); p2->from.insert(p2->from.end(),p1->from.begin(), p1->from.end()); clock_gettime(CLOCK_REALTIME,&t1); t = diff(t0,t1); time_edges += getNanoseconds(t); //Can remove point p1 clock_gettime(CLOCK_REALTIME,&t0); removePoint(p1); clock_gettime(CLOCK_REALTIME,&t1); t = diff(t0,t1); time_point+=getNanoseconds(t); return true; }
void tetMeshExtractorOctree::createPolyMesh() { polyMeshGenModifier meshModifier ( mesh_ ); faceListPMG& faces = meshModifier.facesAccess(); cellListPMG& cells = meshModifier.cellsAccess(); meshModifier.boundariesAccess().setSize ( 0 ); meshModifier.procBoundariesAccess().setSize ( 0 ); const LongList<partTet>& tets = tetCreator_.tets(); VRWGraph pTets; pTets.reverseAddressing(mesh_.points().size(), tets); //- set the number of cells cells.setSize(tets.size()); //- all faces of tetrahedral cells faces.setSize(4*tets.size()); boolList removeFace(faces.size()); # ifdef USE_OMP # pragma omp parallel if( tets.size() > 1000 ) # endif { //- set face labels # ifdef USE_OMP # pragma omp for # endif forAll(removeFace, faceI) removeFace[faceI] = false; //- set sizes of cells and create all faces # ifdef USE_OMP # pragma omp for schedule(dynamic, 20) # endif forAll(tets, elmtI) { cells[elmtI].setSize(4); const partTet& elmt = tets[elmtI]; label faceI = 4 * elmtI; //- first face cells[elmtI][0] = faceI; face& f0 = faces[faceI]; f0.setSize(3); f0[0] = elmt.a(); f0[1] = elmt.c(); f0[2] = elmt.b(); ++faceI; //- second face cells[elmtI][1] = faceI; face& f1 = faces[faceI]; f1.setSize(3); f1[0] = elmt.a(); f1[1] = elmt.b(); f1[2] = elmt.d(); ++faceI; //- third face cells[elmtI][2] = faceI; face& f2 = faces[faceI]; f2.setSize ( 3 ); f2[0] = elmt.b(); f2[1] = elmt.c(); f2[2] = elmt.d(); ++faceI; //- fourth face cells[elmtI][3] = faceI; face& f3 = faces[faceI]; f3.setSize ( 3 ); f3[0] = elmt.c(); f3[1] = elmt.a(); f3[2] = elmt.d(); } # ifdef USE_OMP # pragma omp barrier # endif //- find duplicate faces # ifdef USE_OMP # pragma omp for schedule(dynamic, 20) # endif forAll(cells, cellI) { cell& c = cells[cellI]; forAll(c, fI) { const face& f = faces[c[fI]]; const label pointI = f[0]; forAllRow(pTets, pointI, ptI) { //- do not check cells with greater labels //- they cannot be face owners if( pTets(pointI, ptI) >= cellI ) continue; const cell& otherTet = cells[pTets(pointI, ptI)]; //- check faces created from a tet forAll(otherTet, ofI) { //- do not compare faces with greater labels //- they shall not be removed here if( otherTet[ofI] >= c[fI] ) continue; //- check if the faces are equal if( f == faces[otherTet[ofI]] ) { removeFace[c[fI]] = true; c[fI] = otherTet[ofI]; } } } } }
void Map::Dig(MapCoordinates Coordinates) { static int16_t FloorID = DATA->getLabelIndex("TILESHAPE_FLOOR"); static int16_t RoughWallID = DATA->getLabelIndex("SURFACETYPE_ROUGH_WALL"); static int16_t RoughFloorID = DATA->getLabelIndex("SURFACETYPE_ROUGH_FLOOR_1"); if (isCubeInited(Coordinates)) { if(isCubeSolid(Coordinates) || isCubeSloped(Coordinates)) { for(Direction DirectionType = AXIAL_DIRECTIONS_START; DirectionType < NUM_AXIAL_DIRECTIONS; ++DirectionType) { MapCoordinates ModifiedCoordinates = Coordinates; ModifiedCoordinates.TranslateMapCoordinates(DirectionType); if (DirectionType == DIRECTION_DOWN) { if (isCubeSolid(ModifiedCoordinates)) { Face* TargetFace = getFace(Coordinates, DirectionType); if (TargetFace == NULL) { TargetFace = addFace(Coordinates, DIRECTION_DOWN); } TargetFace->MaterialTypeID = getCubeMaterial(ModifiedCoordinates); TargetFace->NegativeAxisSurfaceTypeID = RoughFloorID; TargetFace->PositiveAxisSurfaceTypeID = RoughFloorID; } else { removeFace(Coordinates, DirectionType); } } else { if (isCubeSolid(ModifiedCoordinates)) { Face* TargetFace = getFace(Coordinates, DirectionType); if (TargetFace == NULL) { TargetFace = addFace(Coordinates, DirectionType); } TargetFace->MaterialTypeID = getCubeMaterial(ModifiedCoordinates); TargetFace->NegativeAxisSurfaceTypeID = getCubeSurfaceType(ModifiedCoordinates); TargetFace->PositiveAxisSurfaceTypeID = getCubeSurfaceType(ModifiedCoordinates); } else { removeFace(Coordinates, DirectionType); } } } setCubeHidden(Coordinates, false); setCubeShape(Coordinates, FloorID); setCubeMaterial(Coordinates, -1); } // reveal tiles around for(Direction DirectionType = COMPASS_DIRECTIONS_START; DirectionType < NUM_COMPASS_DIRECTIONS; ++DirectionType) { setCubeHidden(MapCoordinates(Coordinates, DirectionType), false); } } }