|
Signed Distance Fields 1.0
|
Signed distance field construction tree. More...
#include <sdf.h>
Public Member Functions | |
| SDFTree (SDFNode *) | |
| Constructor. | |
| ~SDFTree () | |
| Destructor. | |
| void | ComputeCost (const Vector &) const |
| Compute the number of recursive calls needed to evaluate the field at a point. | |
| double | Value (const Vector &) const |
| Computes the signed distance to the surface. | |
| Vector | Gradient (const Vector &) const |
| Compute the gradient of the field. | |
| Vector | Normal (const Vector &) const |
| Compute the normal of the field. | |
| bool | Inside (const Vector &) const |
| Check if a point is inside or outside. | |
| Color | GetColor (const Vector &) const |
| Compute the color. | |
| double | K () const |
| Computes the Lipschitz constant of the construction tree. | |
| Box | GetBox () const |
| Get the bounding box of the construction tree. | |
| void | Union (SDFNode *) |
| Apply an union operator between the root and paremeter. | |
| void | Intersection (SDFNode *) |
| Apply an intersection operator between the root and paremeter. | |
| void | Difference (SDFNode *) |
| Apply a difference operator between the root and paremeter. | |
| void | SmoothDifference (SDFNode *, double) |
| Apply a smooth difference operator between the root and paremeter. | |
| void | SmoothUnion (SDFNode *, double) |
| Apply a smooth union operator between the root and paremeter. | |
| void | AddSphere (const Vector &, double, double) |
| Adds a sphere. | |
| bool | SphereTrace (const Ray &, const double &, const double &, const double &, double &, int &, const double &=0.001) const |
| Find the first intersection between a ray and the object. | |
| bool | Intersect (const Ray &, Vector &) const |
| Intersection with the construction tree, using sphere tracing. | |
| virtual int | Memory () const |
| Computes the memory used by the construction tree. | |
| int | Nodes () const |
| Returns the number of nodes in the tree. | |
| SDFNode * | Root () const |
| Returns the root of the tree. | |
| QString | TimingsGradientAnalytic (int) const |
| Computes the timings (in ms) for the analytic (if available) gradient function of the construction tree. | |
| QString | TimingsGradientNumerical (int) const |
| Computes the timings (in ms) for the numerical gradient function of the construction tree. | |
| QString | Timings (int) const |
| Computes the timings (in ms) for the field function of the construction tree. | |
| QString | Timings (Box, int) const |
| Compute the time taken to evaluate the tree at n random points. | |
| QString | GetShader (QVector< float > &floatData, bool materialShader=true, bool costShader=true, bool gradShader=true, bool log=true) const |
| Create the GLSL code of the tree. | |
| QString | GetShaderIndented (bool costShader=true, bool gradShader=true) const |
| create the GLSL code to render the SDF using sphereTracing.glsl | |
| QImage | photobox (int width=512, int height=512, int nb_sample=8192, QString defines="", bool auto_center=true, int *render_time=nullptr, bool log=true, int nb_bounce=3, float fov=50, float znear=0.1, float zfar=500, Matrix4 mat_v=Matrix4::Translate(Vector(0, 0, -4)) *Matrix4::Rotation(Vector(0.6, 0.4, 0)) *Matrix4::Rotation(Vector(-Math::Pi/2, 0, 0))) const |
| Render the construction tree with the GPU path tracer (photobox). | |
| QImage | photobox (QString defines="", Photobox_args args=Photobox_args()) const |
| Render the construction tree with the GPU path tracer (photobox), with all the parameters gathered in a structure. | |
| void | ImportJson (const QString &) |
| Replace the root by the node described in a JSON file. | |
| void | ExportJson (const QString &) |
| Write the tree in a JSON file, in a compact and indented form. | |
Static Public Member Functions | |
| static void | ResetCalls () |
| Reset the number of function calls. | |
| static int | Calls () |
| Returns the number of calls to Value(). | |
| static void | ResetrecursiveCalls () |
| Reset the recursive call property of the tree. | |
| static int | recursiveCalls () |
| Return the number of recursive calls counted by the ComputeCost*() functions since the last reset. | |
| static void | setComputeNbrecursiveCalls (bool computeRecCalls) |
| Set the static boolean computeNbrecursiveCalls to allow computation of nb of recursive call in the function Value. | |
| static SDFTree * | CreateCandlestick () |
| Create the procedural model of a candlestick. | |
| static SDFTree * | Chandelier () |
| Create the procedural model of a chandelier. | |
| static SDFTree * | Chandelier5 () |
| Create the procedural model of a second chandelier, four-fold symmetric and bounded by an envelope. | |
| static SDFNode * | Fountain () |
| Create the procedural model of a fountain. | |
| static SDFNode * | WineGlass () |
| Creates a wine glass: a rounded base, a stem made of smoothly blended spheres, and a cup obtained by revolving a quadric curve set. | |
| static SDFNode * | DesignTube () |
| Create the procedural model of a tube-shaped design object. | |
| static SDFNode * | CAD () |
| Create the procedural model of a mechanical part. | |
| static SDFNode * | Cad2 () |
| Create the procedural model of a second mechanical part. | |
| static SDFNode * | Lamp () |
| Create the procedural model of a lamp. | |
Protected Attributes | |
| SDFNode * | root = nullptr |
| Root node. | |
Static Protected Attributes | |
| static int | calls = 0 |
| Number of call to SDFTree::Value(). | |
Signed distance field construction tree.
Owns the root SDFNode and exposes evaluation, sphere-tracing, and GLSL code generation. Follows the same sign convention as SDFNode: negative inside the surface, positive outside.
|
explicit |
Constructor.
| r | Root node. |
| SDFTree::~SDFTree | ( | ) |
Destructor.
Recursively deletes the entire node hierarchy rooted at root. The tree takes ownership of the root node passed to its constructor; callers must not delete it manually nor share it with another owner.
| void SDFTree::AddSphere | ( | const Vector & | c, |
| double | r, | ||
| double | e ) |
Adds a sphere.
| c | Center. |
| r | Radius. |
| e | Energy. |
| void SDFTree::ComputeCost | ( | const Vector & | p | ) | const |
Compute the number of recursive calls needed to evaluate the field at a point.
The calls are added to the counter returned by recursiveCalls().
| p | Point. |
| void SDFTree::Difference | ( | SDFNode * | n | ) |
Apply a difference operator between the root and paremeter.
| n | node. |
| void SDFTree::ExportJson | ( | const QString & | path | ) |
Write the tree in a JSON file, in a compact and indented form.
| path | Path of the file. |
Compute the color.
Returns the default grey color of SDFNode::GetColor() if the tree is empty.
| p | Point. |
| QString SDFTree::GetShader | ( | QVector< float > & | floatData, |
| bool | materialShader = true, | ||
| bool | costShader = true, | ||
| bool | gradShader = true, | ||
| bool | log = true ) const |
Create the GLSL code of the tree.
| QString SDFTree::GetShaderIndented | ( | bool | costShader = true, |
| bool | gradShader = true ) const |
create the GLSL code to render the SDF using sphereTracing.glsl
| void SDFTree::ImportJson | ( | const QString & | path | ) |
Replace the root by the node described in a JSON file.
If the file does not exist or cannot be opened, a message is printed and the tree is left unchanged. Otherwise the previous root is deleted.
| path | Path of the file. |
| bool SDFTree::Inside | ( | const Vector & | p | ) | const |
Check if a point is inside or outside.
| p | Point. |
| void SDFTree::Intersection | ( | SDFNode * | n | ) |
Apply an intersection operator between the root and paremeter.
| n | node to be intersected with root. |
| QImage SDFTree::photobox | ( | int | width = 512, |
| int | height = 512, | ||
| int | nb_samples = 8192, | ||
| QString | defines = "", | ||
| bool | auto_center = true, | ||
| int * | render_time = nullptr, | ||
| bool | log = true, | ||
| int | nb_bounce = 3, | ||
| float | fov = 50, | ||
| float | znear = 0.1, | ||
| float | zfar = 500, | ||
| Matrix4 | mat_v = Matrix4::Translate(Vector(0, 0, -4)) * Matrix4::Rotation(Vector(0.6, 0.4, 0)) * Matrix4::Rotation(Vector(-Math::Pi / 2, 0, 0)) ) const |
Render the construction tree with the GPU path tracer (photobox).
The tree is converted into GLSL with GetShader(), then rendered by compute_photobox(), framed on the bounding box of the tree, see GetBox().
An OpenGL 4.5 context must be current, and the environment variable ARCHESLIBDIR must be set so that the shader LibSigned/LibSigned/Shaders/photobox.glsl can be found.
Example:
| width,height | Size of the image in pixels. |
| nb_samples | Number of samples per pixel; the rendering time is roughly proportional to it. |
| defines | GLSL code appended to the shader of the tree, typically #define directives such as "#define DISK\n" to show the iso-value disk (see photobox.glsl). |
| auto_center | If true, the bounding box of the tree is centered and scaled to fit the unit box, and the floor is placed at the bottom of the box; if false, the scene is rendered as is with the floor at z=-1. |
| render_time | If not null, receives the GPU rendering time in milliseconds. |
| log | If true, prints progress and timings on the standard output. |
| nb_bounce | Maximum number of light bounces. |
| fov | Vertical field of view, in degrees. |
| znear | Near plane distance. |
| zfar | Far plane distance. |
| mat_v | View matrix of the camera. |
| QImage SDFTree::photobox | ( | QString | defines = "", |
| Photobox_args | args = Photobox_args() ) const |
Render the construction tree with the GPU path tracer (photobox), with all the parameters gathered in a structure.
Contrary to the other overload, the framing uses Photobox_args::box and not the box of the tree: set it explicitly, for instance with args.box = GetBox();, otherwise the default unit box is used. This overload also gives access to cropping, see Photobox_args::crop_min and Photobox_args::crop_max.
| defines | GLSL code appended to the shader of the tree, typically #define directives. |
| args | Rendering parameters. |
| void SDFTree::SmoothDifference | ( | SDFNode * | n, |
| double | t ) |
Apply a smooth difference operator between the root and paremeter.
| n | node. |
| t | Smoothing radius. |
| void SDFTree::SmoothUnion | ( | SDFNode * | n, |
| double | t ) |
Apply a smooth union operator between the root and paremeter.
| n | node. |
| t | Smoothing radius. |
|
virtual |
Find the first intersection between a ray and the object.
| ray | The ray |
| k | Lipschitz constant. |
| a,b | Searching interval. |
| t | Returned intersection depth. |
| s | Returned step count. |
| epsilon | Minimum stepping distance. |
Reimplemented from AnalyticScalarField.
| QString SDFTree::Timings | ( | Box | bbox, |
| int | n ) const |
Compute the time taken to evaluate the tree at n random points.
| n | Number of calls. |
| bbox | Bounding box for the random points. |
| QString SDFTree::Timings | ( | int | n | ) | const |
Computes the timings (in ms) for the field function of the construction tree.
| n | Number of calls |
| QString SDFTree::TimingsGradientAnalytic | ( | int | n | ) | const |
Computes the timings (in ms) for the analytic (if available) gradient function of the construction tree.
| n | Number of calls |
| QString SDFTree::TimingsGradientNumerical | ( | int | n | ) | const |
Computes the timings (in ms) for the numerical gradient function of the construction tree.
| n | Number of calls |
| void SDFTree::Union | ( | SDFNode * | n | ) |
Apply an union operator between the root and paremeter.
| n | node to be unioned with root. |
|
virtual |
Computes the signed distance to the surface.
| p | Point. |
Reimplemented from AnalyticScalarField.