Saturday, March 19, 2011

Projecting a point on a Bézier curve

Hi All my readers.

In this post I'd like to show how to perform the projection of a point to rational cubic Bézier curve.

In fact, this procedure may not seem very useful for everyone. In the end, is there any sense to do Bézier curves in problems of geometric programming problems? However, if someone of the readers of this post had heard about such concepts as BSpline or NURBS, I am sure that this post will show them not only interesting but useful too.

Therefore, I will ask my readers to take my word - namely, any BSpline or NURBS-curve can be converted into one (or a series) of Bézier curves. Yes, do not be surprised. It is true. Therefore, knowing how to treat the problem with Bézier curves will always have the opportunity to consider the problems associated with BSpline or NURBS curves in a similar way.

Consider the rational Bézier curve of order 3. We will talk specifically about the Bézier curve of that order.

Rational Bézier curve of order 3 define by:


Denote a point that is projected onto this curve as G;

Next, we use one of the properties of Bézier curves: namely “the transfer of all control points of a Bézier curve by the same vector does not affect the shape of the curve" and give the origin of the system coordinates of the Bézier curve to a point G.

Thus, in view of transfer of control points of the curve, then we will use the following change of variables:

Give the equation of a Bézier curve to a polynomial form:


Make the following change of:



then the equation of a Bézier curve takes the form:


Define the derivative of this equation:


After the algebraic manipulations, we obtain the following equation:


where


Now we can return to the equation of determining the projection of a point on a Bézier curve.
Required equation has the form:

Or:


Now we can obtain a polynomial equation, whose solution will give us the answer to the question "Where are projected onto a point on a Bézier curve?"


where:


There are many ways to solve polynomial equations. In the case of this problem I used the «Bairstow-Newton» method, which allows us to be given up to find the real and complex roots of polynomial equations. This method worked well in terms of both speed and accuracy of search results.

After receiving the results of solving polynomial equations, only one correct result from the list of solutions is necessary to choose.

To do it, consider the following factors:


  1. «Bairstow-Newton» method allows us to find as real as imaginary roots. Thus, the roots of polynomial equations, which contain the imaginary part, cannot be useful.
  2. Since the domain of definition of a Bézier curve lies between the values [0..1], those are real roots, which are not included in this area are not correct.
  3. Because of solutions of polynomial equations obtained several real roots, then choose follows the root, which corresponds to the minimum distance between a point on the Bézier curve and the projected point.
  4. If resulting solutions of polynomial equations obtained several real roots, and the distance between corresponding points on the Bézier curve and the projected point are equal, then this situation should be considered as a special (exceptional). For example if the projected point on the circle from the center of this circle.


Also, you should noticed that the described method is limited in its application. Thus, in the case of projecting a point to a non-rational Bézier curve, (when all the weights [w] are equal), then the coefficients a, b and c are equal to zero, and the polynomial equation transformed into the identity 0 = 0. Such a way before using the method described above should be checked for equality of weights with each other (or the vanishing of the coefficients [a],[b],[c]).

In fact, the case of projecting a point on a non-rational Bézier curve is a lot easier than projecting on a rational Bézier curve. Using similar steps, we can see that the degree of the polynomial equation of the projection points to a non-rational cubic Bézier curve is a fifth degree (rather than the tenth, as in the case of a rational curve).

Okay. For those experienced programmers who do not know why the computer was invented, I will cite the results of similar work for a non-rational Bézier curves of third order.

The equation of the non-rational cubic Bézier curve is:


Transfer the origin of the coordinates of the curve of the projected point:

Let:


And then a polynomial equation takes the form:

where:


Printable version of this post you can download here.


That's it.
Now you can enjoy the programming.

Thanks.

Friday, March 18, 2011

A bit about math and programming

Hi all of readers.


Often, programmers are faced with various mathematical problems. An example of such problems may be determining whether the choice of object to which your mouse, or sorting a list of numbers.

In most cases, available to programmers are prepared software libraries that provide various functions to facilitate the implementation of mathematical tasks.

Experienced programmers know about these libraries and use the appropriate functions provided by these libraries. But sometimes even experienced programmers will find themselves on an equal footing with inexperienced programmers, when none of the available libraries do not have the necessary functions to solve another math problem. In such cases, a paradoxical situation, when an experienced programmer can decide the outcome of which would be less effective than the decision taken by an inexperienced programmer.

Experienced programmer sits down to solve a mathematical problem as an ordinary skilled programmer. It can take one of the technologies of software development, or to create elements of the working process with the experience of architects and testers. The main mistake the experienced programmer in this situation is that to solve a mathematical problem he will try to come up not as a mathematician, but as a programmer (even if an experienced programmer).

I would like to remind all the programmers, the computer was not invented to solve mathematical problems, and to facilitate their decisions. If someone from the programmer does not know what I would like here to say that most of the algorithms that are programmed for computers that were discovered long before the invention of computers themselves. Work Chebyshev, to quickly implement the integration were open to them in the 19 st century. Work of Bernstein laid the foundations of the modern theory of splines were performed in the early 20 th century.

I'm not trying to say that in modern mathematics does not make new discoveries. Pierre Bézier and Paul de Faget de Casteljau continued development the theory of of splines in the mid of 20 th century . Carl de Boor, Edwin Catmull, Jim Clark, not only continue to develop the theory of splines, and are co-owners and animation studios creating computer graphics and animation. There are still many people who continue the development of mathematics.

But. These people do not rely on the power of modern processors. These people rely on the knowledge. Own knowledge and expertise of their predecessors. They will not allow self to assume that if some iterative algorithm implies the existence of the loop, and to exclude the probability of calculations error, just add the extra 200 iterations of this loop. Although 300 would be better. Probably better.

We have to admit that over the past few decades, the software industry is "rejuvenated". Among the students already there is a perception that programming - it's easy money. It is impossible not to agree that working at a construction site on a lot harder than to exercise the creative mind of a teenager at the time of programming. Surfing the net and not so tired as on construction sites, and moral satisfaction from showing their own creativity encouraged. Can you imagine what would have happened if the pavers brick walls of multistory buildings showed their creativity when laid another brick to the building? And with all this, the work of programmers costs not less than the work of the builders. It is obvious that in this situation as soon as the young man learned the basics of operating system it goes work to the IT-company. Getting a job, a young man begins to realize that his job is already claimed by another 5 connoisseurs of operating systems. And not to be dismissed from the company, a young man starts studying modern technology programming. Extreme Programming, Agaile, etc. Yes, this man becomes an experienced programmer, and it will not be replaced by another expert of operating systems.

It turns out that an experienced programmer is completely helpless against the objectives for which the computer was invented.

I suspect that now you want to tell me - "... the computer is intended not only for mathematical problems, and quite an experienced programmer would be useful for architectural design of client-server applications ...". And here I agree with you. Yes, an experienced programmer will use special patterns of application design. In his hands, fully justified and Extreme Programming and Agile. But. Please spend a little experiment. When you meet an experienced programmer, ask him - if he knew any planning theory of the critical path? Theory of the shortest path? Are there any known examples of problems that have no algorithmic solution? If your interlocutors know at least one of the above questions, then you're in luck. And you'll find that experienced programmers on a lot less than you thought. At the same few, how many skilled mathematicians less than people who know the multiplication table.

Thanks a lot.

Surface Reconstruction Tool for Blender3d. Version 1.2

I salute All and want to congratulate all about end of the winter and to warm spring.

And to continue the good news...

Since the first release passed one and a half months. During this time, people who seemed interesting our product, give us many valuable recommendations. We have accumulated information and return to continue the work.

And now, after six weeks of work, we're giving users a new version of Surface Reconstruction Tool.

Among the improvements that we've added a new version of Surface Reconstruction Tool includes:


  1. To the library was included ability to specify the 3DM format version, where user can save the results. By default, Blender-script saves the 3DM-file is the third version of the format (instead of version 4 as it was before). This allows you to open saved 3DM-files using as application Ayam as native Rhino3d.
  2. Approximation spline surfaces have become more sophisticated and effective. This will significantly reduce the volume of storage space required to represent the approximating surfaces.
  3. For the new version of the library were developed, implemented and tested more sophisticated mathematical algorithms. In particular, it was identified and corrected the defect projection curves on the spline surface with a curved space of parameters, and also developed a fast and reliable analytical algorithm for projecting points on the spline curves. In general, these improvements have accelerated the algorithm several times.

As for the first version of the library, access interface to new version processed through a Python-script for the application Blender3d version 2.49. Ie to start using Surface Reconstruction Tool, Blender's users should download and install our package.

I am sure that our implementation of the library Surface Reconstruction Tool will not only interesting for its current users, but will be in demand for many new users.

We all means try to make our product useful and continue to ask all users to leave their wishes regarding the direction of its development and improvement.


For Download a latest version and more info about installation of Surface Reconstruction Tool, please go to the main post.


Thanks a lot and waiting for your feedbacks.

Thursday, February 3, 2011

Release of Surface Reconstruction Tool for Blender3d

Hi all.

Recently, in our professional activity we had to get acquainted with the Blender3d application. This acquaintance was not only enjoyable for us but also very productive. We were pleasantly surprised as by capabilities of modeling in Blender3d as by flexibility of programming scripts with help of Python API.
And then there is nothing to be surprised. Those promotions, which provide by developers and animators Blender-community, cannot remain unnoticed. I'm sure many of you have seen or heard of animated films like Elephant Dreams, Big bug Bunny, Sintel.
We have released our first own software. At this moment it is Windows supports only, because in our profession, the main platform is Windows. But if our product will be of interest and for UNIX/MAC-users, we will release it for these platforms too.

The main purpose of our product is one of the tasks of reverse engineering - surface reconstruction on the basis of the existing surface mesh. A detailed description of our product can be found here.
This product is a C/C++ programming library. At this moment, this library is integrated into Blender3d through Python-API scripting.
Based on the fact that Blender3d is open-source application, then our plug-in for it is free for all users of Blender3d.
Now this library is a pilot (beta) version. So all sorts of reviews/feedback from users is vital for its improvement.
If you are interested in our product or you wish to see in it any additional features, please leave your suggestions / comments on this or related posts. Detailed reports or official letters can be sent to info@jazzros.com

Download
Download the Windows-installer plug-in of "Surface Reconstruction Tool" for Blender3d:
Version
Download Link
1.1
Download Windows-install plug-in for Blender3d (version 2.49) (1.2 MB)
1.2
Download Windows-install plug-in for Blender3d (version 2.49) (1.3 MB)


Installation manual
  1. Prior to the installation plug-in "Surface Reconstructor" requires that the user's account was install Blender3d (ver. 2.49). Feature of the installation Blender3d is that Blender3d must be precisely installed, but not unpacked. (There are two versions of distributed Blender3d: installable and unpack).
  2. When you install Blender 2.49, you will be prompted to specify where you wish to install Blender's user data file. Please select second item: "Use the installation directory (ie. location chosen to install blender.exe)" instead of default first item.
  3. To successfully use the plug-in "Surface Reconstructor" there is no need to install Python. Everything needed contained in the installer.
  4. Before starting the installer should close all open instances of Blender3d.
  5. Uninstall the plugin should be performed through "Control panel / Install-Uninstall software"

On any questions installing and using plug-in "Surface Reconstructor" for Blender3d contact on via this blog or e-mail: info@jazzros.com.

I hope you enjoy our product and it will be useful in your work.

Thanks.
Oktay Radzhabov.

Wednesday, February 2, 2011

Surface Reconstruction Tool

Overview

Computer-aided geometric design and computer-aided manufacturing systems are used in numerous industries to design and create physical objects from digital models. However, the reverse problem, that of inferring a digital description from an existing physical object, has received much less attention. We refer to this problem as reverse-engineering or, more specifically, 3D scanning. There are various properties of a 3D object that one may be interested in recovering, including its shape, its color, and its material properties. Our solution addresses the problem of recovering 3D shape, also called surface reconstruction.

Decomposing a mesh into smaller pieces is helpful in many applications such as morphing, compression, simplification, 3D shape retrieval, collision detection, texture mapping and surface reconstruction. In general, decomposing a shape into appropriate simpler pieces is very useful in many areas of computation geometry and computer graphics.

A hard problem might become easier if only the objects at hand could be cut up into smaller and easier to handle sub-objects. In computational geometry, solid convex decomposition has been exhaustively investigated. Similarly, in image processing, image segmentation has been considered a fundamental problem, which is a necessary pre-processing step for many higher-level computer vision algorithms. The last few years have witnessed a growing interest in mesh decomposition for computer graphics applications.

Mesh decomposition benefits many applications. In metamorphosis, mesh decomposition is used for establishing a correspondence. Compression and simplification use decomposition for improving their compression rate. In 3D shape retrieval, a decomposition graph serves as a non-rigid invariant signature. In collision detection, decomposition facilitates the computation of bounding-volume hierarchies. In texture mapping, parameterization is applied to each component.

Several approaches have been discussed in the past for decomposing meshes. In convex decomposition schemes are proposed, where a patch is called convex if it lies entirely on the boundary of its convex hull. Convex decompositions are important for applications such as collision detection. However, small concavities in the objects result in over-segmentation, which might pose a problem for other applications. In watershed decomposition is described. In this case, a post-processing step resolves over-segmentation. One problem with the algorithm is the dependency on the exact triangulation of the model. Furthermore, the meaningful components, even planar ones, might get undesirably partitioned. Face clustering is proposed so that the clusters may be well approximated with planar elements. This algorithm is useful for simplification and radiosity, and less for applications seeking the meaningful components. Skeletonization and space sweep are used. Nice-looking results are achieved with this algorithm. However, smoothing effects might cause the disappearance of features for which it is impossible to get a decomposition. K-means based clustering algorithm is proposed. The meaningful components of the objects are found. However, the boundaries between the patches are often jagged and not always correct.

Modern industry is spending more and more efforts in the exploitation of 3D acquisition devices for diverse applications, including reverse engineering and medical imaging, while producers of precise acquisition tools such as recent laser scanners are focusing on improving the quality and flexibility of their products. As a consequence, we can now deal with huge volumes of rather precise data representing 3D shapes. In many contexts, however, it is important to understand the data acquired in order to fully exploit its potential. Unfortunately, in most cases the process of associating high level information to raw 3D data is hard to automate, and a time-consuming manual annotation work is required. In a reverse engineering scenario, for example, the user is typically required to track lines on the surface to subdivide it into simple regions which will be eventually approximated by fitting primitives. Sometimes such features can be detected automatically or semi-automatically, but in most cases the user is required to manually post-process the results to fill gaps or track features missed by the algorithm. In the case of free-form 3D models the approximating primitives are typically NURBS whose parameters are determined through an automatic fitting procedure. When the model is built by a given set of primitives, these primitives are typically fitted to the data.

Math Background

The goal of surface reconstruction can be stated as follows: Given a set of sample points (or surface-mesh) X assumed to lie on or near an unknown surface U, create a surface model S approximating U.

Our work examines the surface reconstruction problem in a general form that makes few assumptions about the sample X and the unknown surface U. In the general surface reconstruction problem we consider, the points X may be noisy, and no structure or other information is assumed within them. The surface U (assumed to be a manifold1) may have arbitrary topological type2, including boundaries, and may contain sharp features such the creases and corners present in the surface. Since the points X may be a noisy sampling, we do not attempt to interpolate them, but will instead find an approximating surface.

Of course, a surface reconstruction procedure cannot guarantee recovering U exactly, since it is only given information about U through a finite set of sample points. The reconstructed surface S should have the same topological type as U, and be everywhere close to U. In this work we will evaluate the reconstruction method by considering examples where the true underlying surface U is known and can be compared visually and quantitatively to the reconstruction.

Mesh hierarchical clustering

The algorithm proposed in our work is a variation of the hierarchical face clustering (HFC) method. The basic idea in the HFC approach is to merge neighboring triangles into representative clusters. Here a cluster is a connected set of triangles, not necessarily simply connected, which can be approximated by a simple primitive. For example, clusters are approximated by fitting planes computed through principal component analysis (PCA), and the cost of merging a set of triangles into a single representative cluster is the integral distance of its vertices from the fitting plane. The method produces a hierarchy which can be represented by a binary tree of clusters.

Approximation

Based on the existing binary tree of clusters, the library uses a recursive algorithm for approximating the clusters in the direction of reducing the size of the clusters.

With a pre-determined accuracy, the algorithm tries to approximate each cluster of each type of surface from the available list. If cluster can be approximated by surface, then the "division" of this cluster stops.

At this moment represented library has follow available list of approximation-surfaces:

Surface bounding

After receipt of parametric surfaces (approximating mesh’s clusters), they must be brought to the form when they are bounded by the curves connections between each other.

First, we tried to use the crossing surfaces for joint lines between adjacent surfaces. But this was not an effective solution. Therefore, at this stage of development, we decided to use the most simple in terms of implementation and effectiveness of the method of achieving a satisfactory outcome - to bounding the surfaces by polylines that were taken from clusters and projected onto a surfaces.

Blender-3d script

Based on represented library we have prepared the Python-script for work with Blender3d application. Now we deal with Blender3d version 2.49, but using another version should not be a problem.

Because Blender3d does not provide bounded surfaces we have prepared export geometry to the 3dm-file format version 4. It is a current native Rhino3d file format, besides there is free library OpenNURBS which provide access to it.

Script's logic. Step by step

  1. Script puts selected mesh from Blender3d to Library;
  2. Library reconstruct geometry surfaces
  3. Library export created surfaces to Rhino’s 3DM-file.


Start Blender

Import/Create some mesh


Mesh elements could be as triangles as quads.

Ensure that all neighbor mesh elements are connected via common vertices.


In Object-mode select required mesh-object (only one mesh-object could be processed in this version of library) and navigate to special script:

"File/Export/JAZZROS Surface Reconstructor".


Script will provide setup dialog where user could prepare and run process of surface reconstruction


Setup fields table

Field name

Description

Use Analytics

On/Off using of the analytic surfaces for approximation. Spline surfaces will be processed anyway. Default value is Off.

Approx Tolerance

Permissible error value between approximated mesh and surfaces. Default value calculated runtime and is a half of minimum edge’s length in the processed mesh.

Geometry Tolerance

Permissible error value of elementary geometric operations. Default value is 1.e-6.



Examples

Analytic surfaces

Spline surfaces


Conclusion

As a result of the research we have developed a software library that allows to perform surface reconstruction on the basis of the existing surface mesh. To perform this tasks, there are used methods of approximation of various types of surfaces, clustering of the surface mesh, curve projecting.

As an example, the use of the library, as well as to implement the possibility to test it, this library has been integrated into the application Blender3d.

More info and download Blender3d-addin You can here.