BRL-CAD
sketch.c File Reference
#include "common.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include "bnetwork.h"
#include "tcl.h"
#include "bu/debug.h"
#include "bu/cv.h"
#include "vmath.h"
#include "db.h"
#include "nmg.h"
#include "rtgeom.h"
#include "raytrace.h"
#include "nurb.h"
#include "../../librt_private.h"
Include dependency graph for sketch.c:

Go to the source code of this file.

Functions

fastf_t rt_cnurb_par_edge (const struct edge_g_cnurb *crv, fastf_t epsilon)
 
void get_indices (void *seg, int *start, int *end)
 
int rt_check_curve (const struct rt_curve *crv, const struct rt_sketch_internal *skt, int noisy)
 
int rt_sketch_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 
void rt_sketch_print (const struct soltab *stp)
 
int rt_sketch_shot (struct soltab *stp, struct xray *rp, struct application *ap, struct seg *seghead)
 
void rt_sketch_norm (struct hit *hitp, struct soltab *stp, struct xray *rp)
 
void rt_sketch_curve (struct curvature *cvp, struct hit *hitp, struct soltab *stp)
 
void rt_sketch_uv (struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp)
 
void rt_sketch_free (struct soltab *stp)
 
int rt_sketch_contains (struct rt_sketch_internal *sk, point2d_t pt)
 
void rt_sketch_bounds (struct rt_sketch_internal *sk, fastf_t *bounds)
 
int rt_sketch_degree (struct rt_sketch_internal *sk)
 
int seg_to_vlist (struct bu_list *vhead, const struct rt_tess_tol *ttol, fastf_t *V, fastf_t *u_vec, fastf_t *v_vec, struct rt_sketch_internal *sketch_ip, void *seg)
 
int curve_to_vlist (struct bu_list *vhead, const struct rt_tess_tol *ttol, fastf_t *V, fastf_t *u_vec, fastf_t *v_vec, struct rt_sketch_internal *sketch_ip, struct rt_curve *crv)
 
int rt_sketch_plot (struct bu_list *vhead, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol, const struct rt_view_info *info)
 
void rt_sketch_centroid (point_t *cent, const struct rt_db_internal *ip)
 
int rt_sketch_tess (struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol)
 
int rt_sketch_import4 (struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
 
int rt_sketch_export4 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_sketch_import5 (struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
 
int rt_sketch_export5 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_sketch_describe (struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
 
void rt_curve_free (struct rt_curve *crv)
 
void rt_sketch_ifree (struct rt_db_internal *ip)
 
void rt_copy_curve (struct rt_curve *crv_out, const struct rt_curve *crv_in)
 
struct rt_sketch_internal * rt_copy_sketch (const struct rt_sketch_internal *sketch_ip)
 
int curve_to_tcl_list (struct bu_vls *vls, struct rt_curve *crv)
 
int rt_sketch_form (struct bu_vls *logstr, const struct rt_functab *ftp)
 
int rt_sketch_get (struct bu_vls *logstr, const struct rt_db_internal *intern, const char *attr)
 
int get_tcl_curve (Tcl_Interp *interp, struct rt_curve *crv, Tcl_Obj *seg_list)
 
int rt_sketch_adjust (struct bu_vls *logstr, struct rt_db_internal *intern, int argc, const char **argv)
 
int rt_sketch_params (struct pc_pc_set *ps, const struct rt_db_internal *ip)
 
void rt_curve_reverse_segment (uint32_t *lng)
 
void rt_curve_order_segments (struct rt_curve *crv)
 

Detailed Description

Provide support for 2D sketches.

Definition in file sketch.c.

Function Documentation

fastf_t rt_cnurb_par_edge ( const struct edge_g_cnurb *  crv,
fastf_t  epsilon 
)

Calculate the maximum edge length (in parameter space) that will keep the curve approximation within epsilon of the true curve

This is a temporary guess until legitimate code can be found

returns: -1.0 if the curve is a straight line maximum parameter increment otherwise

Definition at line 154 of file nurb_tess.c.

References bu_bomb(), bu_log(), MAX_FASTF, rt_nurb_c_diff(), rt_nurb_free_cnurb(), and ZERO.

Referenced by seg_to_vlist().

Here is the call graph for this function:

int rt_sketch_prep ( struct soltab stp,
struct rt_db_internal ip,
struct rt_i rtip 
)

Given a pointer to a GED database record, and a transformation matrix, determine if this is a valid SKETCH, and if so, precompute various terms of the formula.

Returns - 0 SKETCH is OK !0 Error in description

Implicit return - A struct sketch_specific is created, and its address is stored in stp->st_specific for use by sketch_shot().

Definition at line 136 of file sketch.c.

References RT_CK_DB_INTERNAL, RT_CK_RTI, RT_CK_SOLTAB, and soltab::st_specific.

void rt_sketch_print ( const struct soltab stp)

Definition at line 150 of file sketch.c.

References RT_CK_SOLTAB.

int rt_sketch_shot ( struct soltab stp,
struct xray rp,
struct application ap,
struct seg seghead 
)

Intersect a ray with a sketch. If an intersection occurs, a struct seg will be acquired and filled in.

Returns - 0 MISS >0 HIT

Definition at line 165 of file sketch.c.

References RT_CK_APPLICATION, RT_CK_RAY, and RT_CK_SOLTAB.

void rt_sketch_norm ( struct hit hitp,
struct soltab stp,
struct xray rp 
)

Given ONE ray distance, return the normal and entry/exit point.

Definition at line 186 of file sketch.c.

References hit::hit_dist, hit::hit_point, xray::r_dir, xray::r_pt, RT_CK_HIT, RT_CK_RAY, and RT_CK_SOLTAB.

void rt_sketch_curve ( struct curvature cvp,
struct hit hitp,
struct soltab stp 
)

Return the curvature of the sketch.

Definition at line 203 of file sketch.c.

References bn_vec_ortho(), curvature::crv_c1, curvature::crv_c2, curvature::crv_pdir, hit::hit_normal, RT_CK_HIT, and RT_CK_SOLTAB.

Here is the call graph for this function:

void rt_sketch_uv ( struct application ap,
struct soltab stp,
struct hit hitp,
struct uvcoord uvp 
)

For a hit on the surface of an sketch, return the (u, v) coordinates of the hit point, 0 <= u, v <= 1.

u = azimuth, v = elevation

Definition at line 225 of file sketch.c.

References RT_CK_APPLICATION, RT_CK_HIT, and RT_CK_SOLTAB.

void rt_sketch_free ( struct soltab stp)

Definition at line 236 of file sketch.c.

References RT_CK_SOLTAB.

int rt_sketch_contains ( struct rt_sketch_internal *  sk,
point2d_t  pt 
)

Definition at line 253 of file sketch.c.

References bu_log(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, FMAX, FMIN, X, and Y.

Referenced by rt_revolve_shot().

Here is the call graph for this function:

void rt_sketch_bounds ( struct rt_sketch_internal *  sk,
fastf_t bounds 
)

Definition at line 355 of file sketch.c.

References bu_log(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, FMAX, FMIN, X, and Y.

Referenced by rt_revolve_bbox(), and rt_revolve_prep().

Here is the call graph for this function:

int rt_sketch_degree ( struct rt_sketch_internal *  sk)

Definition at line 428 of file sketch.c.

References bu_log(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, and CURVE_NURB_MAGIC.

Here is the call graph for this function:

int seg_to_vlist ( struct bu_list vhead,
const struct rt_tess_tol ttol,
fastf_t V,
fastf_t u_vec,
fastf_t v_vec,
struct rt_sketch_internal *  sketch_ip,
void *  seg 
)
int curve_to_vlist ( struct bu_list vhead,
const struct rt_tess_tol ttol,
fastf_t V,
fastf_t u_vec,
fastf_t v_vec,
struct rt_sketch_internal *  sketch_ip,
struct rt_curve *  crv 
)

Definition at line 861 of file sketch.c.

References BU_CK_LIST_HEAD, bu_debug, BU_DEBUG_MEM_CHECK, bu_log(), bu_mem_barriercheck(), and seg_to_vlist().

Referenced by rt_sketch_plot().

Here is the call graph for this function:

int rt_sketch_plot ( struct bu_list vhead,
struct rt_db_internal ip,
const struct rt_tess_tol ttol,
const struct bn_tol tol,
const struct rt_view_info info 
)

Definition at line 887 of file sketch.c.

References BU_CK_LIST_HEAD, bu_log(), curve_to_vlist(), rt_db_internal::idb_ptr, and RT_CK_DB_INTERNAL.

Here is the call graph for this function:

int rt_sketch_tess ( struct nmgregion **  r,
struct model *  m,
struct rt_db_internal ip,
const struct rt_tess_tol ttol,
const struct bn_tol tol 
)

Returns - -1 failure 0 OK. *r points to nmgregion that holds this tessellation.

Definition at line 1090 of file sketch.c.

References RT_CK_DB_INTERNAL.

int rt_sketch_import4 ( struct rt_db_internal ip,
const struct bu_external ep,
const fastf_t mat,
const struct db_i dbip 
)

Import an SKETCH from the database format to the internal format. Apply modeling transformations as well.

Definition at line 1103 of file sketch.c.

References bn_mat_identity, BU_ALLOC, bu_bomb(), bu_calloc(), BU_CK_EXTERNAL, bu_cv_ntohd(), bu_debug, BU_DEBUG_MEM_CHECK, bu_free(), bu_log(), bu_malloc(), bu_mem_barriercheck(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, bu_external::ext_buf, ID_SKETCH, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, if(), magic, OBJ, RT_CK_DB_INTERNAL, RT_CK_DBI, RT_SKETCH_INTERNAL_MAGIC, SIZEOF_NETWORK_DOUBLE, SIZEOF_NETWORK_LONG, OSL::Strings::v, X, and Y.

Here is the call graph for this function:

int rt_sketch_export4 ( struct bu_external ep,
const struct rt_db_internal ip,
double  local2mm,
const struct db_i dbip 
)

The name is added by the caller, in the usual place.

Definition at line 1295 of file sketch.c.

References bu_bomb(), bu_calloc(), BU_CK_EXTERNAL, bu_cv_htond(), bu_debug, BU_DEBUG_MEM_CHECK, bu_free(), bu_log(), bu_malloc(), bu_mem_barriercheck(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, bu_external::ext_buf, bu_external::ext_nbytes, ID_SKETCH, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, RT_CK_DBI, SIZEOF_NETWORK_DOUBLE, and SIZEOF_NETWORK_LONG.

Here is the call graph for this function:

int rt_sketch_import5 ( struct rt_db_internal ip,
const struct bu_external ep,
const fastf_t mat,
const struct db_i dbip 
)

Import an SKETCH from the database format to the internal format. Apply modeling transformations as well.

Definition at line 1497 of file sketch.c.

References bn_mat_identity, BU_ALLOC, bu_bomb(), bu_calloc(), BU_CK_EXTERNAL, bu_cv_ntohd(), bu_debug, BU_DEBUG_MEM_CHECK, bu_free(), bu_log(), bu_malloc(), bu_mem_barriercheck(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, bu_external::ext_buf, ID_SKETCH, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, if(), magic, OBJ, RT_CK_DB_INTERNAL, RT_CK_DBI, RT_SKETCH_INTERNAL_MAGIC, SIZEOF_NETWORK_DOUBLE, SIZEOF_NETWORK_LONG, OSL::Strings::v, X, and Y.

Here is the call graph for this function:

int rt_sketch_export5 ( struct bu_external ep,
const struct rt_db_internal ip,
double  local2mm,
const struct db_i dbip 
)

The name is added by the caller, in the usual place.

Definition at line 1686 of file sketch.c.

References bu_bomb(), BU_CK_EXTERNAL, bu_cv_htond(), bu_debug, BU_DEBUG_MEM_CHECK, bu_free(), bu_log(), bu_malloc(), bu_mem_barriercheck(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, bu_external::ext_buf, bu_external::ext_nbytes, ID_SKETCH, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, RT_CK_DBI, SIZEOF_NETWORK_DOUBLE, and SIZEOF_NETWORK_LONG.

Here is the call graph for this function:

int rt_sketch_describe ( struct bu_vls str,
const struct rt_db_internal ip,
int  verbose,
double  mm2local 
)

Make human-readable formatted presentation of this solid. First line describes type of solid. Additional lines are indented one tab, and give parameter values.

Definition at line 1899 of file sketch.c.

References bu_bomb(), bu_vls_strcat(), CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, rt_db_internal::idb_ptr, if(), OSL::Strings::u, and OSL::Strings::v.

Here is the call graph for this function:

void rt_sketch_ifree ( struct rt_db_internal ip)

Free the storage associated with the rt_db_internal version of this solid.

Definition at line 2142 of file sketch.c.

References bu_debug, BU_DEBUG_MEM_CHECK, bu_free(), bu_log(), bu_mem_barriercheck(), rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, and rt_curve_free().

Here is the call graph for this function:

int rt_sketch_form ( struct bu_vls logstr,
const struct rt_functab ftp 
)

Definition at line 2340 of file sketch.c.

References BRLCAD_OK, BU_CK_VLS, bu_vls_printf(), and RT_CK_FUNCTAB.

Here is the call graph for this function:

int rt_sketch_get ( struct bu_vls logstr,
const struct rt_db_internal intern,
const char *  attr 
)

Definition at line 2352 of file sketch.c.

References BRLCAD_ERROR, BRLCAD_OK, BU_CK_VLS, BU_STR_EQUAL, bu_vls_printf(), bu_vls_strcat(), bu_vls_strcpy(), curve_to_tcl_list(), rt_db_internal::idb_ptr, and V3ARGS.

Here is the call graph for this function:

int get_tcl_curve ( Tcl_Interp *  interp,
struct rt_curve *  crv,
Tcl_Obj *  seg_list 
)

Definition at line 2407 of file sketch.c.

References BU_ALLOC, bu_calloc(), BU_STR_EQUAL, CURVE_BEZIER_MAGIC, CURVE_CARC_MAGIC, CURVE_LSEG_MAGIC, CURVE_NURB_MAGIC, tcl_obj_to_fastf_array(), and tcl_obj_to_int_array().

Referenced by rt_sketch_adjust().

Here is the call graph for this function:

int rt_sketch_adjust ( struct bu_vls logstr,
struct rt_db_internal intern,
int  argc,
const char **  argv 
)

Definition at line 2590 of file sketch.c.

References BRLCAD_ERROR, brlcad_interp, BRLCAD_OK, bu_free(), BU_STR_EQUAL, bu_strdup, bu_vls_printf(), get_tcl_curve(), rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, and tcl_list_to_fastf_array().

Here is the call graph for this function:

int rt_sketch_params ( struct pc_pc_set ps,
const struct rt_db_internal ip 
)

Definition at line 2699 of file sketch.c.

References RT_CK_DB_INTERNAL.