Meshlabserver: How to convert STL to PLY and unify vertices? - mesh

I have several .stl files that I would like to convert to .ply by calling meshlabserver from the command line. When I go the straightforward way
> meshlabserver -i cube-binary.stl -o cube.ply
(where cube.stl is a sample file given below with 12 faces), the resulting mesh has 12 faces and 36 vertices. This means that no unification of repeated vertices has happened, although that was the very reason why I wanted to go for .ply instead of .stl.
Now, I assume that it is not possible for the same reason it was impossible make the vertex unification default in the Meshlab GUI (I asked about it some time ago, although it later turned out that such a question had already existed). But maybe someone knows some trick? Browsing through possible filters after -om, I did not find a solution.
The behaviour was tested with Meshlab 2016 on Open SUSE and with Meshlab v1.3.2_64bit on Ubuntu.
The sample file
(also created by Meshlab)
solid vcg
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex 5.000000e-01 5.000000e-01 5.000000e-01
vertex -5.000000e-01 5.000000e-01 5.000000e-01
vertex 5.000000e-01 -5.000000e-01 5.000000e-01
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex -5.000000e-01 -5.000000e-01 5.000000e-01
vertex 5.000000e-01 -5.000000e-01 5.000000e-01
vertex -5.000000e-01 5.000000e-01 5.000000e-01
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex 5.000000e-01 5.000000e-01 5.000000e-01
vertex 5.000000e-01 -5.000000e-01 5.000000e-01
vertex 5.000000e-01 5.000000e-01 -5.000000e-01
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex 5.000000e-01 -5.000000e-01 -5.000000e-01
vertex 5.000000e-01 5.000000e-01 -5.000000e-01
vertex 5.000000e-01 -5.000000e-01 5.000000e-01
endloop
endfacet
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex 5.000000e-01 5.000000e-01 5.000000e-01
vertex 5.000000e-01 5.000000e-01 -5.000000e-01
vertex -5.000000e-01 5.000000e-01 5.000000e-01
endloop
endfacet
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex -5.000000e-01 5.000000e-01 -5.000000e-01
vertex -5.000000e-01 5.000000e-01 5.000000e-01
vertex 5.000000e-01 5.000000e-01 -5.000000e-01
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex -5.000000e-01 -5.000000e-01 -5.000000e-01
vertex -5.000000e-01 5.000000e-01 -5.000000e-01
vertex 5.000000e-01 -5.000000e-01 -5.000000e-01
endloop
endfacet
facet normal -0.000000e+00 -0.000000e+00 -1.000000e+00
outer loop
vertex 5.000000e-01 5.000000e-01 -5.000000e-01
vertex 5.000000e-01 -5.000000e-01 -5.000000e-01
vertex -5.000000e-01 5.000000e-01 -5.000000e-01
endloop
endfacet
facet normal 0.000000e+00 -1.000000e+00 0.000000e+00
outer loop
vertex -5.000000e-01 -5.000000e-01 -5.000000e-01
vertex 5.000000e-01 -5.000000e-01 -5.000000e-01
vertex -5.000000e-01 -5.000000e-01 5.000000e-01
endloop
endfacet
facet normal -0.000000e+00 -1.000000e+00 -0.000000e+00
outer loop
vertex 5.000000e-01 -5.000000e-01 5.000000e-01
vertex -5.000000e-01 -5.000000e-01 5.000000e-01
vertex 5.000000e-01 -5.000000e-01 -5.000000e-01
endloop
endfacet
facet normal -1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex -5.000000e-01 -5.000000e-01 -5.000000e-01
vertex -5.000000e-01 -5.000000e-01 5.000000e-01
vertex -5.000000e-01 5.000000e-01 -5.000000e-01
endloop
endfacet
facet normal -1.000000e+00 -0.000000e+00 -0.000000e+00
outer loop
vertex -5.000000e-01 5.000000e-01 5.000000e-01
vertex -5.000000e-01 5.000000e-01 -5.000000e-01
vertex -5.000000e-01 -5.000000e-01 5.000000e-01
endloop
endfacet
endsolid vcg

The easiest way is to use a script that apply the Remove Duplicate Vertices filter.
Try saving this to a file named cleanVertex.mlx
<!DOCTYPE FilterScript>
<FilterScript>
<filter name="Remove Duplicate Vertices"/>
<filter name="Remove Unreferenced Vertices"/>
</FilterScript>
And then using the command:
> meshlabserver -i cube-binary.stl -o cube.ply -s cleanVertex.mlx

Related

Co-ordinates of point on circle with minimum cos/sin

A vehicle currently at a point U = (ux, uy) is moving counter-clockwise along a circle of radius R with speed s and direction d (i.e. tangent to the circle makes an angle d with the X-axis.) What position V = (vx, vy) will it be at in time t?
The center of the circle is not specified.
The way I see it, after time t it will travel st or an angle of st/R along the circle. But I am lost trying to compute V from this info.
I can first find the center C of the circle based on (ux, uy), R and d. And then find where vector CV points, and hence V. But that's a whole lot of cosines and sines. I am constrained by CPU, so maybe one sine/cos/tan is acceptable or one or two squares/square roots are acceptable.
This calls for a diagram, but alas I lack the skill.
I assume that the radius speed and time interval are such that the vehicle will not travel more than halfway round the circle in the time available.
Let V be the point the vehicle will be at t seconds after it is at U. Let the centre of the circle (whose coordinates will not be needed) be O. Then the length of the arc from U to V is
A = s*t
and so the angle subtended at O is
a = A/R radians.
The direction from U to V will be the same as the direction of the tangent to the circle at a point midway between U and V, ie
e = d + a/2
The distance from U to V is the length of the chord from U to V. The midpoint of the chord is the vertex of two congruent right angled triangles whose hypoteneuses have length R, and the angle at O is a/2. Therefor the length of the chord is
C = 2*R*sin( a/2)
Finally
V = U + C*(cos(e), sin(e))
You may also want the direction of the tangent at V. This is d+a.
Note that if you store the direction d as a unit vector rather than an angle you can save some sin & cos calls as the direction of the chord is then the direction d rotated through a/2, and the direction at V is d rotated through a.

Error in Gurobi for optimization?

sw: ampl
ampl: include Availability1.ampl
Gurobi 5.5.0: mipgap = 0.00000000000000000000000001
outlev = 1
Optimize a model with 68298 rows, 1934 columns and 28751 nonzeros
Presolve removed 1934 rows and 68298 columns
Presolve time: 0.02s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 9.9948451e-01 0.000000e+00 0.000000e+00 0s
179 9.9948451e-01 0.000000e+00 0.000000e+00 0s
Solved in 179 iterations and 0.06 seconds
Optimal objective 9.994845101e-01
Gurobi 5.5.0: optimal solution; objective 0.9994845101
179 simplex iterations
Above is my output: No error but is not the optimal answer.
What's the matter? I can't get the right answer. Please help me.

Convert SVG Elliptical arc into UibezierPath curve

Is it possible to generate a UIBezierPath Curve from an SVG elliptical Command A.
it would be great if we can give an example of UIbezier Curve (Cubic / Quadratic cureve) that corresponds to the following Command :
"M600,350 l 50,-25
a25,25 -30 0,1 50,-25 l 50,-25
a25,50 -30 0,1 50,-25 l 50,-25
a25,75 -30 0,1 50,-25 l 50,-25
a25,100 -30 0,1 50,-25 l 50,-25"
Thank you !

Conditions for smooth cubic bezier curve

I have the start and end points and the values of the slope of the curve at those points.
Now I have to draw a "smooth 2D bezier curve" through the two given points.
Now how to locate the two control points to achieve this. Is there any way for it? I know that the control points must lie on the tangents at the respective start and end points.
Note:By "smooth curve", I meant that there should be no steep curves or turnings in the final plot.
It sounds like you have catmull-rom curve coordinates (two points, and their departure and arrival tangents), in which case https://pomax.github.io/bezierinfo/#catmullconv covers all the math necessary to convert those to Bezier coordinates. And if you don't care about the "how", just skip to the end of the section for the straight up conversion rules.
tl;dr version: rewrite your coordinates to Catmull form:
[P1, v1, v2, P2] -> [P1 - v1, P1, P2, P2 + v2]
Then we convert that to Bezier coordinates:
P1 <= P1
p2 <= P1 - (P2 - P1 - v1) / 6 * f
p3 <= P2 + (P2 + v2 - P1) / 6 * f
p4 <= P2
the f is a tension constant. Play around with that. It's usually 1, but it might not be depending on how strong those tangents were.
For a cubic Bezier curve defined by P0, P1, P2 and P3 where P0 and P3 are the start point and end point, its first derivative vector at t=0 and t=1 are
C'(t=0) = 3*(P1-P0)
C'(t=1) = 3*(P3-P2)
So, if you already know the slope at the start and end point, you can easily convert that to tangent vectors and find the control points P1 and P2. You do need to assign a proper magnitude for the first derivative vectors so that the final resulting curve does not have inflection point. But as long as you make sure the resulting control polygon formed by P0, P1, P2 and P3 are convex, then your cubic Bezier curve should be smooth and has no turnnings.

finding a minimum distance

I need to find a point or points on the given circle (or curve) which minimizes d0+d1? the radius and center of the curve are (0,0) and 'r' respectively and the coordinates of points A and B are known. Let say A=(x1,y1) and B=(x1,-y1) and r> sqrt(x1^2+y1^2) . C is unknown point of the circle which should minimize the length d0+d1
d0 - the distance between A to C on the circle
d1- the distance between B to C on the circle
point C moves along the circle. I need to find a point or points on the given circle (or curve) which minimizes d0+d1?
If the line AB intersects the circle, then C is that intersection point (note that there can be two intersection points and both give an equal distance d0+d1 !).
If AB does not intersect the circle, then C is the point on the circle intersecting an imaginary line from the point on the line AB closest to the circle center.
There are many articles online about how to find the point on a line closest to another point, and how to find the intersection between two lines, which would solve the second case. For the first case you can google "line circle intersection"
The general case is very complicated, but the special situation
A=(x1,y1) and B=(x1,-y1) and r > sqrt(x1^2+y1^2)
with a circle whose centre is the origin has enough symmetries to make the solution at least in some circumstances accessible. I'm assuming A ≠ B, (equivalently y1 ≠ 0), otherwise the problem is trivial for a circle.
Let dist(P,Q) be the Euclidean distance between the points P and Q. The (closed) line segment connecting A and B is the locus of points P with
dist(P,A) + dist(P,B) = dist(A,B)
For D > dist(A,B), the locus of points with
f(P) = dist(P,A) + dist(P,B) = D
is an ellipse E(D) whose foci are A and B. Let P be a point on the circle and D = f(P).
If the tangents to the circle and to the ellipse E(D) in the point P don't coincide, P is neither a local minimum nor a local maximum of f restricted to the circle.
If the tangents coincide, and the curvature of the circle is larger than the curvature of E(D) in P, then P is an isolated local maximum of f restricted to the circle.
If the tangents coincide, and the curvature of the circle is smaller than the curvature of E(D) in P, then P is an isolated local minimum of f restricted to the circle.
If the tangents coincide and the curvature of the circle is equal to the curvature of E(D) in P, then
P is an isolated local minimum of f restricted to the circle if dist(P,A) = dist(P,B),
P is neither a local maximum nor a local minimum of f restricted to the circle otherwise.
First, if x1 = 0, it is easily seen (in case it is not geometrically obvious) that the points on the circle minimising f are the points with x-coordinate 0, i.e. P1 = (0,r) and P2 = (0,-r). [That would even be true if r² ≤ x1² + y1².]
Now, suppose x1 ≠ 0, without loss of generality x1 > 0. Then it is obvious that a point P = (x,y) on the circle minimising f must have x > x1. By the symmetry of the situation, the point R = (r,0) must either be a local minimum or a local maximum of f restricted to the circle.
Computing the behaviour of f near R, one finds that R is a local minimum if and only if
r ≥ (x1² + y1²) / x1
Since R is a point of smallest curvature of E(f(R)) (and the tangents in R to E(f(R)) and the circle coincide), R is then also the global minimum.
If r < (x1² + y1²) / x1, then R is a local maximum of f restricted to the circle. Then f has two global minima on the circle, with the same x-coordinate. Unfortunately, I don't have a nice formula to compute them, so I can't offer a better way than an iterative search.