C/C++ library with map()/mapto() function? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
What I'm searching for is a function which allows mapping a certain numeric value of a certain numeric range onto another. I did find a way to create this function manually, which has the basic calculation output = output_start + ((output_end - output_start) / (input_end - input_start)) * (input - input_start), however I find it rather bothersome to always create it myself, search through my old projects to find it or to create a header file only for this function.
I'd imagine it's such a basic function that it should be somewhere in the C/C++ Standard libraries or at least in one of the mainstream 3rd party libraries, however I couldn't find it.

You are looking for a linear transformation function, that for every number in the range [input_start, input_end] computes a number in the range [output_start, output_end] using a proportionality factor (i.e. (output_end - output_start) / (input_end - input_start) in order to cover the full range).
Unfortunately, this simple function doesn't exist in the standard library (e.g. neither in cmath nor numeric). Anyway, when using such a transformation, most frequently you'd like to compute the proportionality factor only once.
So the easiest way would be to create your own function for this. In C++ you could create a class, which computes the factor at construction.

Related

Implementation of scipy.signla.filtfilt in c++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 10 months ago.
Improve this question
I am trying to implement scipy.signal.filtfilt function in c++ and I am wondering if there is already an implementation available of this?
I know its a long time. but maybe you find this repository useful:
FiltFilt in C++
filtfilt applies an IIR filter twice, once going forward, once going backward. The nontrivial part is how to initialize the IIR filter at the boundaries.
As a starting point, look at how scipy.signal.filtfilt does it. Here is the code:
https://github.com/scipy/scipy/blob/master/scipy/signal/signaltools.py#L3870
You might also find it useful to look at the source code for Octave's filtfilt (M code):
https://sourceforge.net/p/octave/signal/ci/default/tree/inst/filtfilt.m
To reproduce filtfilt in C++, you need a C++ implementation of IIR filtering to take the role of scipy's lfilter plus some boundary handling logic. I don't know about an existing C++ implementation of filtfilt, but at least for the default method='pad' logic, the core computation seems simple enough to consider porting directly.
Scipy's filtfilt is similar to Matlab's filtfilt.
A question for MATLAB's filtfilt was previously asked
An implementation for the same was previously shared on Stackoverflow by #darien-pardinas
Do note I say similar because as mentioned by #paco-wong
The difference is in the default padding length. In matlab's filtfilt, it is 3*(max(len(a), len(b)) - 1), and in scipy's filtfilt, it is 3*max(len(a), len(b)).
So you will have to account for that

C++ library to obtain regular meshes from a 3D file format such as STL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
It seems there are some libraries including CGAL to generate meshes from a 2D or 3D model.
Question: In C++ environment, what is the best way to obtain a set of regular nodes to represent an object that is given by a 3d file format such as the STL?
To explain the question, let me provide an example. In a 2D case, a square can be represented by the set of '1's and the empty space can be by the set of '0's.
Is there any C++ library that can deal with this task?
00000000000000
00000111000000
00000111000000
00000111000000
00000000000000
Thank you in advance.
CGAL it self is already a very good option, if you can match the licenses (many modules are GPL or must pay a fee for proprietary use). This answer shows an example of use.
Another complete library is the Point Clouds Library (PCL) (license compatible with commercial). If your input data is ordered (like the one shown in the question) you can use the pcl::OrganizedFastMesh class.
If your data is un-ordered,
then a pcl::GreedyProjectionTriangulation may be better.
Finally, if using PCL, you can save your triangle mesh to STL using [pcl::io::savePolygonFileSTL](http://docs.pointclouds.org/1.7.0/group__io.html#ga3223bdca3003262efbd8c475d4ab7cc6].
As a final note, better than trying to find a library that exactly matches your input format, find a library that can generate the result you want and then accommodate your input and output to it through convertors. Of course, if your input doesn't provide the required data, such as normals, then you must either compute it previously or search for another method ;).

Boost library for human-readable fractional units [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Is there a boost library that supports us in converting doubles to (US style) fractional units, i.e. that converts
from (double) 2.56
to (string) '2 5/9' ?
The use case is to display the fractional number to the user whilst keeping the double representation internally. The fractional representation might very well be an approximation of the exact internal value.
Boost appears to have considered the problem and decided not to implement it.
I quote from the documentation for boost::rational
The library does not offer a conversion function from floating point to rational. A number of requests were received for such a conversion, but extensive discussions on the boost list reached the conclusion that there was no "best solution" to the problem. As there is no reason why a user of the library cannot write their own conversion function which suits their particular requirements, the decision was taken not to pick any one algorithm as "standard"…
All of this implies that we should be looking for some form of "nearest simple fraction". Algorithms to determine this sort of value do exist. However, not all applications want to work like this…
With these conflicting requirements, there is clearly no single solution which will satisfy all users. Furthermore, the algorithms involved are relatively complex and specialised, and are best implemented with a good understanding of the application requirements. All of these factors make such a function unsuitable for a general-purpose library such as this.
GP/Pari does implement a bestappr(X, B) function, which (in one of its incarnations) returns the best rational approximation of X whose denominator is less than B. (Thanks to #SLeske's answer to a similar question for the pointer.)
A Google search for "rational approximation of real numbers" yielded a number of other links, including this non-paywalled paper by Emilie Charriera and Lilian Buzera (and three cheers to Discrete Applied Mathematics for allowing open access.)

C++ Bessel function for complex numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I want to implement the Bessel functions of first and second kindDescription of bessel functions for complex numbers in C++. Now I am looking for possibilities to introduce them in my source code. Since math.h only contains bessel functions for real numbers, I would be interested in seeing any kind of possibility.
I haven't found that Boost is compatible with complex arguments (though it may a mistake on my part).
The FORTRAN code developed by D.E. Amos (the code used by MATLAB and others) is in the public domain and can be used by anybody. I have been developing a C++ interface to the library, extending it to the case of negative orders. You can check it out on GitHub.
The Boost library implements ordinary Bessel functions of the first and second kind and modified Bessel functions of the first and second kind for both real and complex numbers (see documentation about Bessel functions).
Don't try to reinvent the wheel, just use the Boost implementation which is far superior to anything you could write yourself.

C++ 2D Integration Libraries [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Can anyone point out a good C++ library that can do 2D numerical integration. It needs to be able to accept a 2D array of known values, and the spacing between the points can be assumed to be constant (for a start).
It is preferable that it have a license which allows modifying the code as needed.
It's actually a C library, but if the GPL licensing terms work for you try:
http://www.gnu.org/software/gsl/
You will want to check out the Monte Carlo integration options outlined here:
http://www.gnu.org/software/gsl/manual/html_node/Monte-Carlo-Integration.html
This Fortran library is easy to link to from C++ and is in public domain:
http://gams.nist.gov/cgi-bin/serve.cgi/Module/CMLIB/ADAPT/2967
It's single precision but it's quite easy to modify the sources (get "full sources" and go through every function) to switch to double precision.
http://itpp.sourceforge.net/current/
Try this. It can do what you ask for and more! And you can modify the code as much as you like.
I've read somewhere that you can extract libraries out of GNU Octave's code and use the C++ code in your own applications. I'm not sure if that's an easy task, but you can give it a try if you have the time.