Given a polyhedron that was generated by a convex hull, my task is to use a black box optimization algorithm to find a translation transform that when applied to a specific set of points of the polyhedron, an objective function is minimized.
Obviously, one approach is to regenerate the convex hull for every generated translation. However, convex hull computation is slow, and also we know a-priori that only a subset of the convex hull's points need to be modified to minimize the objective function. So I thought, I'd generate the convex hull once, use std::transform to modify a subset of the polyhedron's points, and then compute the objective function. Something like this: set<int> specificSetOfPoints; . . // Store the index of the points of interest in the set defined above . void compute(Vector translate) { // Clone the polyhedron -- cHull is the pre-computed convex hull Polyhedron currPoly = Polyhedron(cHull); int index = -1; std::transform(currPoly.points_begin(), currPoly.points_end(), currPoly.points_begin(), [this, &translate, &index](Polyhedron::Point_3& p) { index++; // Does this point belong to the specific set of points? if (this->specificSetOfPoints.count(index)) return Polyhedron::Point_3(p.x() + translate.x(), p.y() + translate.y(), p.z() + translate.z()); // Do nothing return Polyhedron::Point_3(p.x(), p.y(), p.z()); }); float objective = objectiveFunction(currPoly); } However, the above code results in different objective function values compared to the case where I recompute the convex hull every compute() call. Is there an easy way to apply the translation trasnform to a subset of the points of the polyhedron object? Thanks in advance : ) |
Anyone...?
I feel there is an easy way to transform the vertices of a polyhedron in-place, and I'm missing it... There is vertex.point.transform() but, it returns a new point, and I'm not sure if I can modify the original vertex with this transformed point... :( |
You can do vertex_handle->point() = vertex_handle->point().transform(...) since vertex.point() returns a reference type. On Fri, Dec 2, 2016 at 3:21 PM, SirM2X <[hidden email]> wrote: Anyone...? |
Thanks for your response...
Although that works, it gives me the exact results as the one which I posted the pseudocode for... Somehow I have a feeling that once the points are assigned, the polygon's faces are not updated, or are messed up somehow. |
Maybe if you get the vertex from the HalfedgeDS object using a Modifier_base class instead of from the polyhedron? On Fri, Dec 2, 2016 at 3:54 PM, SirM2X <[hidden email]> wrote: Thanks for your response... |
Free forum by Nabble | Edit this page |