Is there a function in CGAL that removes the holes from a alphashape? - cgal

Im trying to remove the holes from a alphashape to get a similar function as MATLABs boundary.m. The code Im using is basically the example from CGALs documentation.
Imageexample with alphashape to the left and boundary to the right:

Related

#NLConstraint with vectorized constraint JuMP/Julia

I am trying to solve a problem involving the equating of sums of exponentials.
This is how I would do it hardcoded:
#NLconstraint(m, exp(x[25])==exp(x[14])+exp(x[18]))
This works fine with the rest of the code. However, when I try to do it for an arbitrary set of equations like the above I get an error. Here's my code:
#NLconstraint(m,[k=1:length(LHSSum)],sum(exp.(LHSSum[k][i]) for i=1:length(LHSSum[k]))==sum(exp.(RHSSum[k][i]) for i=1:length(RHSSum[k])))
where LHSSum and RHSSum are arrays containing arrays of the elements that need to be exponentiated and then summed over. That is LHSSum[1]=[x[1],x[2],x[3],...,x[n]]. Where x[i] are variables of type JuMP.Variable. Note that length(LHSSum)=length(RHSSum).
The error returned is:
LoadError: exp is not defined for type Variable. Are you trying to build a nonlinear problem? Make sure you use #NLconstraint/#NLobjective.
So a simple solution would be to simply do all the exponentiating and summing outside of the #NLconstraint function, so the input would be a scalar. However, this too presents a problem since exp(x) is not defined since x is of type JuMP.variable, whereas exp expects something of type real. This is strange since I am able to calculate exponentials just fine when the function is called within an #NLconstraint(). I.e. when I code this line#NLconstraint(m,exp(x)==exp(z)+exp(y)) instead of the earlier line, no errors are thrown.
Another thing I thought to do would be a Taylor Series expansion, but this too presents a problem since it goes into #NLconstraint land for powers greater than 2, and then I get stuck with the same vectorization problem.
So I feel stuck, I feel like if JuMP would allow for the vectorized evaluation of #NLconstraint like it does for #constraint, this would not even be an issue. Another fix would be if JuMP implements it's own exp function to allow for the exponentiation of JuMP.Variable type. However, as it is I don't see a way to solve this problem in general using the JuMP framework. Do any of you have any solutions to this problem? Any clever workarounds that I am missing?
I'm confused why i isn't used in the expressions you wrote. Do you mean:
#NLconstraint(m, [k = 1:length(LHSSum)],
sum(exp(LHSSum[k][i]) for i in 1:length(LHSSum[k]))
==
sum(exp(RHSSum[k][i]) for i in 1:length(RHSSum[k])))

Combining a format string with a superscript and a subscript in pyplot when rendering text in a plot

I would like to include the equation for a "power-law" curve I am creating using pyplot. I have tried several variations of the following code:
ax.text(0.1,0.9,r'{0:}x$^{1:}$'.format(A,b))
of course the text renderer uses the curly brackets as well as the format statement. I have tried doubling the curly brackets to have
ax.text(0.1,0.9,r'{0:}x$^{{1:}}$'.format(A,b))
and even tripling them
ax.text(0.1,0.9,r'{0:}x$^{{{1:}}}$'.format(A,b))
I have also tried splitting the text into two lines
exponent = '{0:}$'.format(b)
ax.text(0.1,0.9,r'{0:}x$^'.format(A)+exponent)
none of these really make sense to me or to pyplot, but I can't seem to ask the right search question to get this to work. I have found answers that suggested splitting the line and using double curly brackets but nothing that will make this work. Is this possible?
EDIT:
Through further experimentation I have answered the question above which was a simplified version of the equation I wanted to put in the plot, so let me change this question slightly. To do what I wanted above I have found that:
ax.text(0.1,0.9,r'{0:}x$^{{ {1:} }}$'.format(A,b))
works. I don't know why I hadn't tried it earlier, but I have now. The problem is that I actually want a subscript on x as well. Given that the above works I would have thought that:
ax.text(0.1,0.9,r'{0:}x$^{{ {1:} }}_{{\rm map}}$
would work, but I get the following error:
Subscript/superscript sequence is too long. Use braces { } to remove
ambiguity. (at char 0), (line:1, col:1)
I cannot see where to add braces that will remove any ambiguity. Can anyone tell me what I need to do?
This works:
ax.text(0.1, 0.9, r'${0:}x^{{{1:}}}_{{\rm map}}$'.format(A, b))
The issue was that your x was outside of the mathmode ($...$).
With regards to the double curly braces, there is an easy explanation: When using the format function all single curly braces are matched with an argument to the format function (they can also be nested). Two subsequent curly braces are the defined way of getting one curly bracket after applying format. See the documentation for more information on this.

Splitting Nef polyhedra into discrete volumes for conversion to regular polyhedra

I am doing some boolean operation on Nef polyhedra converted from regular polyhedra. After doing the boolean operation I want to convert the resulting Nef polyhedra into regular polyhedra. However it seems that Nef polyhedra only support if the result is a single volume. Some boolean operations however result in multiple volumes. Is there a way to split the Nef polyhedron into into the discrete volumes it contains and convert these back to regular polyhedra separately? Alternatively is there some more appropriate approach?
I have found the Nef_polyhedron_3::Volume and the corresponding iterator, but i have not been able to identify a way to utilize these to split up the Nef Polyhedron.
Edit:
I finally got around to properly look at this. The code provided worked almost out of the box. I ran in to a few issues that were pretty easily solved. First, i implemented BuildPolyhedronFromShell outside the Nef_polyhedron class as i would like to keep my CGAl Implementation as clean as possible. It was however necessary to make Nef_polyhedron_3::Triangulation_handler2 public, as it is used in BuildPolyhedronFromShell.
Additionally the code initially create shells with inward facing normals. This was fixed by changing Halffacet_const_handle f = opposite_facet->twin(); to Halffacet_const_handle f = opposite_facet; I don't know if this solves the problem in the general case, but i works for the cases i tried.
Thank you for the help.

lucene highlighter: how can I get locations of fragments?

I know how to get relevant highlighted fragments together with some surrounding text using Lucene highlighter, namely, using
Highlighter highlighter = new Highlighter(scorer);
String[] fragments = highlighter.getBestFragments(stream, fieldContents, fragmentNumber);
But can I instead get pointers to these fragments in the original contents? In other words, I need to know where these fragments start and, if possible, end.
If you use the GetBestTextFragments method instead, you will get back an array of TextFragments. These have properties textStartPos and textEndPos.
(They are marked internal in Lucene.NET, which will require you to make some code changes to get access to them. I'm not sure about Java Lucene.)

What does setTextMatrix of contentByte class in iText do?

I am using iText and am very new to it. There have been several situations where I think I could have figured out the problem with my code if I knew what I was doing - I use examples without knowing the workings behind the code, and even as I look at the source I can't figure out what the programmer was thinking.
What does setTextMatrix of contentByteArray in iText do? And how do I figure out the parameter values I need?
For example:
cb.setTextMatrix(1, 0);
The input parameters are x,y coordinates in points, unless CTM scaling was defined.
0,0 would be the bottom left of the template you are referencing.
The position is the 'baseline' of the text, rather than the top or the bottom.
Transcribed from this source:
https://sourceforge.net/p/itext/mailman/message/12855218/
first parameter sets left margin, second parameter sets bottom margin.