bool mitk::PointSet::SwapPointPosition( PointIdentifier id, bool moveUpwards, int t ) { if(IndexExists(id, t) ) { PointType point = GetPoint(id,t); if(moveUpwards) { //up if(IndexExists(id-1,t)) { InsertPoint(id, GetPoint(id - 1, t), t); InsertPoint(id-1,point,t); this->Modified(); return true; } } else { //down if(IndexExists(id+1,t)) { InsertPoint(id, GetPoint(id + 1, t), t); InsertPoint(id+1,point,t); this->Modified(); return true; } } } return false; }
int CPointsCollection::EditPoint(int index, double x, double y, BOOL bRescan) { if (index<0 || index>=GetSize()) return -1; int ret; SSinglePoint ssp(x, y); //if bSortX not specified - just replace given point RemovePoint(index, FALSE); if (!bSortX) { InsertPoint(index, ssp.x, ssp.y, bRescan); ret = index; } else { int res; ret = AddPoint(&ssp, bRescan, &res); }; return ret; }
ISVertexItr InsertPoint(ISectTriangle* tri, VertexPos pos, Vec3d& vec, bool isMulti) { ISVertexItr output; if (pos == INNER) { if (!IsVertexExisted(tri, vec, output)) { ISVertexInfo info; info.pos = ZONE->mesh.add_vertex(vec); tri->vertices.push_front(info); output = tri->vertices.begin(); } } else if (pos <= EDGE_2) { auto mesh = tri->pMesh; auto ffItr = mesh->ff_begin(tri->face); switch (pos) { case CSG::EDGE_0: ffItr ++; ffItr ++; break; case CSG::EDGE_1: break; case CSG::EDGE_2: ffItr ++; break; default: assert(0); } ISectTriangle*& other = mesh->property(mesh->SurfacePropHandle, *ffItr); #ifdef _DEBUG_ auto fvItr = mesh->fv_begin(tri->face); if (pos == EDGE_1) fvItr++; if (pos == EDGE_2) {fvItr++; fvItr++;} auto f0 = *fvItr; fvItr = mesh->fv_begin(*ffItr); assert(*fvItr != f0); fvItr++; assert(*fvItr != f0); fvItr++; assert(*fvItr != f0); #endif if (!other) other = new ISectTriangle(mesh, *ffItr); output = InsertPoint(other, INNER, vec); return InsertPoint(tri, INNER, output); } else { // get the iterator of vertex #WR# switch (pos) { case CSG::VER_0: output = tri->corner[0]; break; case CSG::VER_1: output = tri->corner[1]; break; case CSG::VER_2: output = tri->corner[2]; break; } } return output; }
ISVertexItr InsertPoint(ISectTriangle* tri, VertexPos pos, ISVertexItr ref, bool isMulti) { // 追溯到最源头的迭代器 while (!ref->pos.is_valid()) ref = ref->next; Vec3d vec = ZONE->mesh.point(ref->pos); ISVertexItr output = ref; ISVertexInfo info; info.next = ref; if (pos == INNER) { if (!IsVertexExisted(tri, vec, output)) { tri->vertices.push_front(info); output = tri->vertices.begin(); } else { if (!output->pos.is_valid() || output->pos != ref->pos) { output->pos.reset(); output->next = ref; } } } else if (pos <= EDGE_2) { auto mesh = tri->pMesh; auto ffItr = mesh->ff_begin(tri->face); switch (pos) { case CSG::EDGE_0: ffItr ++; ffItr ++; break; case CSG::EDGE_1: break; case CSG::EDGE_2: ffItr ++; break; default: assert(0); } ISectTriangle*& other = mesh->property(mesh->SurfacePropHandle, *ffItr); if (!other) other = new ISectTriangle(mesh, *ffItr); InsertPoint(other, INNER, ref); return InsertPoint(tri, INNER, ref); } else { // get the iterator of vertex #WR# switch (pos) { case CSG::VER_0: if (tri->corner[0]->pos == ref->pos) break; tri->corner[0]->pos.reset(); tri->corner[0]->next = ref; output = tri->corner[0]; break; case CSG::VER_1: if (tri->corner[1]->pos == ref->pos) break; tri->corner[1]->pos.reset(); tri->corner[1]->next = ref; output = tri->corner[1]; break; case CSG::VER_2: if (tri->corner[2]->pos == ref->pos) break; tri->corner[2]->pos.reset(); tri->corner[2]->next = ref; output = tri->corner[2]; break; } } return output; }